ExampleOUSD

ExampleOUSD

_ExampleOUSD is used to show how to use the IOCPRouter.

ExampleOUSD will set the router, remoteChainId, and swapToken variables in the constructor. And these variables will be immutable. ExampleOUSD will use the router to mint and redeem OmniTokens for the swapToken. ExampleOUSD will use the remoteChainId to mint and redeem OmniTokens on the remote chain.

The swapTokenToOUSD function is used to swap tokens for OUSD. The swapTokenToOUSD function will call the omniMint function on the router.

The swapOUSDToToken function is used to swap OUSD for tokens. The swapOUSDToToken function will call the omniRedeem function on the router._

router

contract IOCPRouter router

swapToken

contract IERC20 swapToken

remoteChainId

uint16 remoteChainId

constructor

constructor(address _router, uint16 _remoteChainId, address _swapToken) public

_constructor is used to set the router, remoteChainId, and swapToken variables.

The router variable is the address of the OCP Router. The remoteChainId variable is the chainId of the remote chain. The swapToken variable is the address of the token to swap. The router, remoteChainId, and swapToken variables are immutable._

Parameters

NameTypeDescription

_router

address

The address of the OCP Router.

_remoteChainId

uint16

The chainId of the remote chain.

_swapToken

address

The address of the token to swap.

SwapTokenToOUSD

event SwapTokenToOUSD(address from, address to, uint256 amountIn, bytes payload)

_swapTokenToOUSD is used to swap tokens for OUSD.

The swapTokenToOUSD function will call the omniMint function on the router._

Parameters

NameTypeDescription

from

address

The address to swap tokens from.

to

address

The address to mint OUSD to.

amountIn

uint256

The amount of tokens to swap.

payload

bytes

The payload to send to the remote chain.

SwapOUSDToToken

event SwapOUSDToToken(address from, address to, uint256 amountIn, bytes payload)

_swapOUSDToToken is used to swap OUSD for tokens.

The swapOUSDToToken function will call the omniRedeem function on the router._

Parameters

NameTypeDescription

from

address

The address to swap OUSD from.

to

address

The address to redeem the swapToken to.

amountIn

uint256

The amount of OUSD to swap.

payload

bytes

The payload to send to the remote chain.

swapTokenToOUSD

function swapTokenToOUSD(uint256 _amountIn, address _to) external

_swapTokenToOUSD is used to swap tokens for OUSD.

The swapTokenToOUSD function will call the omniMint function on the router. The omniMint function will mint OUSD for the swapToken to the address specified in the omniMint function. The omniMint function will mint OUSD for the swapToken using the convertRate function. Will emit a SwapTokenToOUSD event._

Parameters

NameTypeDescription

_amountIn

uint256

The amount of tokens to swap.

_to

address

The address to mint OUSD to.

swapOUSDToToken

function swapOUSDToToken(uint256 _amountIn, address _to) external

_swapOUSDToToken is used to swap OUSD for tokens.

The swapOUSDToToken function will call the omniRedeem function on the router. The omniRedeem function will redeem OUSD for the swapToken to the address specified in the omniRedeem function. The omniRedeem function will redeem OUSD for the swapToken using the convertRate function. Will emit a SwapOUSDToToken event._

Parameters

NameTypeDescription

_amountIn

uint256

The amount of OUSD to swap.

_to

address

The address to redeem the swapToken to.

Last updated