Skip to main content
Version: 0.1.x-legacy

Contract

Functions#

getChainId#

  function getChainId(  ) public view override returns (uint256 _chainId)

Gets the chain id of this contract. If not specified during init, will use the block.chainId.

getStoredChainId#

  function getStoredChainId(  ) external view override returns (uint256)

Gets the chain id that this contract has stored.

addRouter#

  function addRouter(    address router  ) external override onlyOwner

Adds a router to the router list that can transact crosschain.

Parameters:#

NameTypeDescription
routeraddressThe router address to add

removeRouter#

  function removeRouter(    address router  ) external override onlyOwner

Removes a router from the router list that can transact crosschain.

Parameters:#

NameTypeDescription
routeraddressThe router address to remove

addAssetId#

  function addAssetId(    address assetId  ) external override onlyOwner

Adds an asset to the asset list that can be transferred

  • The asset address should be on the same chain as the contract.

Parameters:#

NameTypeDescription
assetIdaddressThe asset address to add to the list

removeAssetId#

  function removeAssetId(    address assetId  ) external override onlyOwner

Removes an asset from the asset list that can be transferred

  • The asset address should be on the same chain as the contract.

Parameters:#

NameTypeDescription
assetIdaddressThe asset address to remove from the list

addLiquidityFor#

  function addLiquidityFor(    uint256 amount,    address assetId,    address router  ) external payable override nonReentrant

Adds liquidity to a router.

Parameters:#

NameTypeDescription
amountuint256The amount of assetId to add as liquidity
assetIdaddressThe address (or address(0) for native asset) of the asset to add
routeraddressThe router to add liquidity

addLiquidity#

  function addLiquidity(    uint256 amount,    address assetId  ) external payable override nonReentrant

Adds liquidity to a router.

This function should be called from a router, since it passes msg.sender as a router to _addLiquidityForRouter.

Parameters:#

NameTypeDescription
amountuint256The amount of assetId to add as liquidity
assetIdaddressThe address (or address(0) for native asset) of the asset to add

removeLiquidity#

  function removeLiquidity(    uint256 amount,    address assetId,    address payable recipient  ) external override nonReentrant

Removes liquidity from a router.

This function should be called from a router.

Parameters:#

NameTypeDescription
amountuint256The amount of assetId to remove as liquidity
assetIdaddressThe address (or address(0) for native asset) of the asset to remove
recipientaddressThe address to transfer removed liquidity to

prepare#

  function prepare(    PrepareArgs calldata args  ) external payable override nonReentrant returns (TransactionData memory)

Creates a crosschain transaction.

When called on the sending chain, the user is expected to lock up funds. When called on the receiving chain, the router deducts the transfer amount from the available liquidity. The majority of the information about a given transfer does not change between chains, with three notable exceptions: amount, expiry, and preparedBlock. The amount and expiry are decremented between sending and receiving chains to provide an incentive for the router to complete the transaction and time for the router to fulfill the transaction on the sending chain after the unlocking signature is revealed, respectively.

Parameters:#

NameTypeDescription
argsstruct ITransactionManager.PrepareArgsThe parameters for crosschain transaction, encoded as PrepareArgs in calldata

Return Values:#

NameTypeDescription
struct ITransactionManager.TransactionDataThe transaction data

fulfill#

  function fulfill(    FulfillArgs calldata args  ) external override nonReentrant returns (TransactionData memory)

Completes a crosschain transaction.

When called on the receiving chain, the user reveals their signature on the transactionId and is sent the amount corresponding to the number of shares the router locked when calling prepare. The router then uses this signature to unlock the corresponding funds on the receiving chain, which are then added back to their available liquidity. The user includes a relayer fee since it is not assumed they will have gas on the receiving chain. This function must be called before the transaction expiry has elapsed.

Parameters:#

NameTypeDescription
argsstruct ITransactionManager.FulfillArgsThe parameters for completing a crosschain transaction, encoded as FulfillArgs in calldata

Return Values:#

NameTypeDescription
struct ITransactionManager.TransactionDataThe transaction data

cancel#

  function cancel(    CancelArgs calldata args  ) external override nonReentrant returns (TransactionData memory)

Cancels a crosschain transaction.

Any crosschain transaction can be cancelled after it has been created to prevent indefinite lock up of funds. After the transaction has expired, anyone can cancel it. Before the expiry, only the recipient of the funds on the given chain is able to cancel. On the sending chain, this means only the router is able to cancel before the expiry, while only the user can prematurely cancel on the receiving chain.

Parameters:#

NameTypeDescription
argsstruct ITransactionManager.CancelArgsThe parameters for canceling a crosschain transaction, encoded as CancelArgs in calldata

Return Values:#

NameTypeDescription
struct ITransactionManager.TransactionDataThe transaction data

_addLiquidityForRouter#

  function _addLiquidityForRouter(    uint256 amount,    address assetId,    address router  ) internal

Adds liquidity to a router. This is a helper function containing the logic to verify, and to add liquidity to a given router.

Parameters:#

NameTypeDescription
amountuint256The amount of assetId to add as liquidity
assetIdaddressThe address (or address(0) for native asset) of the asset to add
routeraddressThe router to add liquidity

transferAssetToContract#

  function transferAssetToContract(    address assetId,    uint256 specifiedAmount  ) internal returns (uint256)

This is a helper function to handle transferring funds from msg.sender to the transaction manager contract. It is used in prepare, _addLiquidityForRouter.

Parameters:#

NameTypeDescription
assetIdaddressThe address (or address(0) for native asset) of the asset to transfer
specifiedAmountuint256The amount of assetId to transfer

Return Values:#

NameTypeDescription
uint256The amount of the asset that has been transferred

recoverCancelSignature#

  function recoverCancelSignature(    bytes32 transactionId,    uint256 receivingChainId,    address receivingChainTxManagerAddress,    bytes calldata signature  ) internal pure returns (address)

This is a helper function to recover the signer address from the signature.

Parameters:#

NameTypeDescription
transactionIdbytes32The transaction identifier of the recovering transaction
receivingChainIduint256The receiving chain id
receivingChainTxManagerAddressaddressThe transaction manager address on the receiving chain
signaturebytesThe signature to recover the signer address from

Return Values:#

NameTypeDescription
addressThe signer address of the signature

recoverFulfillSignature#

  function recoverFulfillSignature(    bytes32 transactionId,    uint256 relayerFee,    uint256 receivingChainId,    address receivingChainTxManagerAddress,    bytes calldata signature  ) internal pure returns (address)

This is a helper function to recover the signer address from the signature.

Parameters:#

NameTypeDescription
transactionIdbytes32The transaction identifier of the recovering transaction
relayerFeeuint256The fee paid to the relayer for submitting the transaction for the user
receivingChainIduint256The receiving chain id
receivingChainTxManagerAddressaddressThe transaction manager address on the receiving chain
signaturebytesThe signature to recover the signer address from

Return Values:#

NameTypeDescription
addressThe signer address of the signature

recoverSignature#

  function recoverSignature(    bytes memory encodedPayload,    bytes calldata signature  ) internal pure returns (address)

This is a helper function to recover the signer address from the signature and the encodedPayload.

Parameters:#

NameTypeDescription
encodedPayloadbytesThe encoded payload that was signed
signaturebytesThe signature to recover the signer address from

Return Values:#

NameTypeDescription
addressThe signer address of the signature

hashInvariantTransactionData#

  function hashInvariantTransactionData(    TransactionData calldata txData  ) internal pure returns (bytes32)

This is a helper function to get the hash of only the invariant portions of a given crosschain transaction.

Parameters:#

NameTypeDescription
txDatastruct ITransactionManager.TransactionDataThe transaction data, encoded as TransactionData in calldata

Return Values:#

NameTypeDescription
bytes32The hash of the invariant transaction data

hashVariantTransactionData#

  function hashVariantTransactionData(    uint256 amount,    uint256 expiry,    uint256 preparedBlockNumber  ) internal pure returns (bytes32)

This is a helper function to get the hash of only the variant portions of a given crosschain transaction.

Parameters:#

NameTypeDescription
amountuint256The amount of the transaction
expiryuint256The expiry of the transaction
preparedBlockNumberuint256The prepared block number

Return Values:#

NameTypeDescription
bytes32The hash of the variant transaction data

_receivingChainFulfill#

  function _receivingChainFulfill(    TransactionData calldata txData,    uint256 relayerFee,    bytes calldata callData  ) internal returns (bool, bool, bytes memory)

This is a helper function to handle the receiving-chain fulfillment. This function should pay the relayer and either send funds to the specified address or execute the calldata. Returns a tuple of boolean, bytes indicating the success and return data of the external call.

Parameters:#

NameTypeDescription
txDatastruct ITransactionManager.TransactionDataThe transaction data, encoded as TransactionData in calldata
relayerFeeuint256The fee paid to the relayer for submitting the transaction for the user
callDatabytesThe prepared block number

Return Values:#

NameTypeDescription
boolThe result of calling the external call (false if it is simply sending funds)
boolTrue if it is external call and the txData.callTo is a contract
bytesThe return data of the external call