Contracts
Here is the Contract Application Binary Interface (ABI) of Mayan Swap Bridge.
MayanSwap.json
8KB
Code
In the below table you can find the deployed contract addresses of Swap Bridge:
Network | Wormhole Chain Id | Contract Address |
---|---|---|
Solana | 1 | 8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E |
Ethereum | 2 | 0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95 |
BSC | 4 | 0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95 |
Polygon | 5 | 0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95 |
Avalanche | 6 | 0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95 |
Arbitrum | 23 | 0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95 |
You don't need to interact with the Solana program unless you want to run your own relayer.
If the input token is not the native currency of network, to initiate a swap we need to first approve the Swap Bridge to spend that token on our behalf
tokenContract.approve(swapBridgeAddress, amountIn);
Then we can call the
swap
function:function swap(
RelayerFees memory relayerFees,
Recepient memory recepient,
bytes32 tokenOutAddr,
uint16 tokenOutChain,
Criteria memory criteria,
address tokenIn,
uint256 amountIn
) public payable returns (uint64 sequence)
In case the input token is the native currency of network we must call the
wrapAndSwapETH
function:function wrapAndSwapETH(
RelayerFees memory relayerFees,
Recepient memory recepient,
bytes32 tokenOutAddr,
uint16 tokenOutChain,
Criteria memory criteria
) public payable returns (uint64 sequence)
We are going over each parameter and understand what they mean:
struct RelayerFees {
uint64 swapFee;
uint64 redeemFee;
uint64 refundFee;
}
relayerFees
is a struct that contains the fees that user is willing to pay to relayers for transfering VAA messages, to get a fair value an ensure that relayer will transfer we can use Quote APIstruct Recepient {
bytes32 mayan;
bytes32 destAddr;
uint16 destChainId;
}
recepient
is a struct that holds the info about the destination.mayan
field should be filled with Solana program address of mayan which is 9N34KcQXfKjCQcyAXkuCoGgixfi1dj53LtsfFrcBdjNhdestAddr
field is the address of user's destination wallet.destChainId
is the Wormhole chain id of user's destination wallet.
tokenOutAddr: origin address of input token
tokenOutChain: origin Wormhole chain of output token
struct Criteria {
uint256 transferDeadline;
uint64 swapDeadline;
uint256 amountOutMin;
uint32 nonce;
}
transferDeadline
is the timestamp (in seconds) that shows the deadline of transaction on EVM and it must be based on EVM clock.swapDeadline
is the timestamp (in seconds) that shows deadline of swap on Solana and therefore it should be relative to Solana clock.amountOutMin
shows the minimum acceptable amount of ouput token after slippage.nonce
is a random number that can be used for batch processing of messages.
tokenIn: Contract address of input token (which we allowed token bridge to transfer
amountIn
in the first phase)
amountIn: Amount of input token which user is willing swap.
Last modified 21d ago