Package Exports
- @axelar-network/axelar-cgp-solidity/info/mainnet.json
- @axelar-network/axelar-cgp-solidity/info/testnet.json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@axelar-network/axelar-cgp-solidity) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Axelar cross-chain gateway protocol solidity implementation
Protocol overview
Axelar is a decentralized interoperability network connecting all blockchains, assets and apps through a universal set of protocols and APIs. It is built on top off the Cosmos SDK. Users/Applications can use Axelar network to send tokens between any Cosmos and EVM chains. They can also send arbitrary messages between EVM chains.
Axelar network's decentralized validators confirm events emitted on EVM chains (such as deposit confirmation and message send), and sign off on commands submitted (by automated services) to the gateway smart contracts (such as minting token, and approving message on the destination).
See this doc for more design info.
Build
We recommend using the current Node.js LTS version for satisfying the hardhat compiler
Run in your terminal
npm ci
npm run build
npm run testExample flows
See Axelar examples for concrete examples.
Token transfer
- Setup: A wrapped version of Token
Ais deployed (AxelarGateway.deployToken()) on each non-native EVM chain as an ERC-20 token (BurnableMintableCappedERC20.sol). - Given the destination chain and address, Axelar network generates a deposit address (the address where
DepositHandler.solis deployed,BurnableMintableCappedERC20.depositAddress()) on source EVM chain. - User sends their token
Aat that address, and the deposit contract locks the token at the gateway (or burns them for wrapped tokens). - Axelar network validators confirm the deposit
Transferevent using their RPC nodes for the source chain (using majority voting). - Axelar network prepares a mint command, and validators sign off on it.
- Signed command is now submitted (via any external relayer) to the gateway contract on destination chain
AxelarGateway.execute(). - Gateway contract authenticates the command, and
mint's the specified amount of the wrapped TokenAto the destination address.
Token transfer via AxelarDepositService
- User wants to send wrapped token like WETH from chain A back to the chain B and to be received in native currency like Ether.
- The un-wrap deposit address is generated by calling
AxelarDepositService.addressForNativeUnwrap(). - The token transfer deposit address for specific transfer is generated by calling
AxelarDepositService.addressForTokenDeposit()with using the un-wrap address as a destination. - User sends the wrapped token to that address on the source chain A.
- Axelar microservice detects the token transfer to that address and calls
AxelarDepositService.sendTokenDeposit(). AxelarDepositServicedeploysDepositReceiverto that generated address which will callAxelarGateway.sendToken().- Axelar network prepares a mint command, and it gets executed on the destination chain gateway.
- Wrapped token gets minted to the un-wrap address on the destination chain B.
- Axelar microservice detects the token transfer to the un-wrap address and calls
AxelarDepositService.nativeUnwrap(). AxelarDepositServicedeploysDepositReceiverwhich will callIWETH9.withdraw()and transfer native currency to the recipient address.
Cross-chain smart contract call
- Setup:
- Destination contract implements the
IAxelarExecutable.solinterface to receive the message. - If sending a token, source contract needs to call
ERC20.approve()beforehand to allow the gateway contract to transfer the specifiedamounton behalf of the sender/source contract.
- Destination contract implements the
- Smart contract on source chain calls
AxelarGateway.callContractWithToken()with the destination chain/address,payloadand token. - An external service stores
payloadin a regular database, keyed by thehash(payload), that anyone can query by. - Similar to above, Axelar validators confirm the
ContractCallWithTokenevent. - Axelar network prepares an
AxelarGateway.approveContractCallWithMint()command, signed by the validators. - This is submitted to the gateway contract on the destination chain,
which records the approval of the
payload hashand emits the eventContractCallApprovedWithMint. - Any external relayer service listens to this event on the gateway contract, and calls the
IAxelarExecutable.executeWithToken()on the destination contract, with thepayloadand other data as params. executeWithTokenof the destination contract verifies that the contract call was indeed approved by callingAxelarGateway.validateContractCallAndMint()on the gateway contract.- As part of this, the gateway contract records that the destination address has validated the approval, to not allow a replay.
- The destination contract uses the
payloadfor it's own application.
References
Network resources: https://docs.axelar.dev/resources
Deployed contracts: https://docs.axelar.dev/resources/mainnet
General Message Passing Usage: https://docs.axelar.dev/dev/gmp
Example cross-chain token swap app: https://app.squidrouter.com
EVM module of the Axelar network that prepares commands for the gateway: https://github.com/axelarnetwork/axelar-core/blob/main/x/evm/keeper/msg_server.go