-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sample using AxelarGateway to send tokens between chains
- Loading branch information
Showing
4 changed files
with
252 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.16; | ||
pragma abicoder v2; | ||
|
||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol"; | ||
// import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "./interfaces/IAxelarGateway.sol"; | ||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; | ||
// import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; | ||
|
||
|
||
contract AxelarIntegration is Ownable, ReentrancyGuard { | ||
IAxelarGateway public axelarGateway; | ||
|
||
IERC20 private axlUSDC; | ||
|
||
constructor(address firstOwner, address _axelarGatewayAddress, address _axlUSDCAddress) Ownable(firstOwner) { | ||
axelarGateway = IAxelarGateway(_axelarGatewayAddress); | ||
axlUSDC = IERC20(_axlUSDCAddress); | ||
} | ||
|
||
function sendTokensToAnotherChain(string calldata destChain, string calldata destination, string memory symbol, uint256 amount) public nonReentrant onlyOwner { | ||
uint256 balance = axlUSDC.balanceOf(address(this)); | ||
require(balance >= amount, "amount > balance"); | ||
require(keccak256(bytes(symbol)) == keccak256(bytes("axlUSDC")), "only axlUSDC enabled"); | ||
|
||
// Polygon | ||
TransferHelper.safeApprove(address(axlUSDC), address(axelarGateway), amount); | ||
axelarGateway.sendToken(destChain, destination, symbol, amount); | ||
} | ||
|
||
function recoverToken(address _tokenAddress, address recipient, uint256 _amount) external nonReentrant onlyOwner { | ||
IERC20 _token = IERC20(_tokenAddress); | ||
uint256 balance = _token.balanceOf(address(this)); | ||
require(balance >= _amount, "_amount > balance"); | ||
|
||
TransferHelper.safeTransferFrom(_tokenAddress, address(this), recipient, _amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.9; | ||
|
||
interface IAxelarGateway { | ||
/**********\ | ||
|* Errors *| | ||
\**********/ | ||
|
||
error NotSelf(); | ||
error NotProxy(); | ||
error InvalidCodeHash(); | ||
error SetupFailed(); | ||
error InvalidAuthModule(); | ||
error InvalidTokenDeployer(); | ||
error InvalidAmount(); | ||
error InvalidChainId(); | ||
error InvalidCommands(); | ||
error TokenDoesNotExist(string symbol); | ||
error TokenAlreadyExists(string symbol); | ||
error TokenDeployFailed(string symbol); | ||
error TokenContractDoesNotExist(address token); | ||
error BurnFailed(string symbol); | ||
error MintFailed(string symbol); | ||
error InvalidSetMintLimitsParams(); | ||
error ExceedMintLimit(string symbol); | ||
|
||
/**********\ | ||
|* Events *| | ||
\**********/ | ||
|
||
event TokenSent(address indexed sender, string destinationChain, string destinationAddress, string symbol, uint256 amount); | ||
|
||
event ContractCall( | ||
address indexed sender, | ||
string destinationChain, | ||
string destinationContractAddress, | ||
bytes32 indexed payloadHash, | ||
bytes payload | ||
); | ||
|
||
event ContractCallWithToken( | ||
address indexed sender, | ||
string destinationChain, | ||
string destinationContractAddress, | ||
bytes32 indexed payloadHash, | ||
bytes payload, | ||
string symbol, | ||
uint256 amount | ||
); | ||
|
||
event Executed(bytes32 indexed commandId); | ||
|
||
event TokenDeployed(string symbol, address tokenAddresses); | ||
|
||
event ContractCallApproved( | ||
bytes32 indexed commandId, | ||
string sourceChain, | ||
string sourceAddress, | ||
address indexed contractAddress, | ||
bytes32 indexed payloadHash, | ||
bytes32 sourceTxHash, | ||
uint256 sourceEventIndex | ||
); | ||
|
||
event ContractCallApprovedWithMint( | ||
bytes32 indexed commandId, | ||
string sourceChain, | ||
string sourceAddress, | ||
address indexed contractAddress, | ||
bytes32 indexed payloadHash, | ||
string symbol, | ||
uint256 amount, | ||
bytes32 sourceTxHash, | ||
uint256 sourceEventIndex | ||
); | ||
|
||
event TokenMintLimitUpdated(string symbol, uint256 limit); | ||
|
||
event OperatorshipTransferred(bytes newOperatorsData); | ||
|
||
event Upgraded(address indexed implementation); | ||
|
||
/********************\ | ||
|* Public Functions *| | ||
\********************/ | ||
|
||
function sendToken( | ||
string calldata destinationChain, | ||
string calldata destinationAddress, | ||
string calldata symbol, | ||
uint256 amount | ||
) external; | ||
|
||
function callContract( | ||
string calldata destinationChain, | ||
string calldata contractAddress, | ||
bytes calldata payload | ||
) external; | ||
|
||
function callContractWithToken( | ||
string calldata destinationChain, | ||
string calldata contractAddress, | ||
bytes calldata payload, | ||
string calldata symbol, | ||
uint256 amount | ||
) external; | ||
|
||
function isContractCallApproved( | ||
bytes32 commandId, | ||
string calldata sourceChain, | ||
string calldata sourceAddress, | ||
address contractAddress, | ||
bytes32 payloadHash | ||
) external view returns (bool); | ||
|
||
function isContractCallAndMintApproved( | ||
bytes32 commandId, | ||
string calldata sourceChain, | ||
string calldata sourceAddress, | ||
address contractAddress, | ||
bytes32 payloadHash, | ||
string calldata symbol, | ||
uint256 amount | ||
) external view returns (bool); | ||
|
||
function validateContractCall( | ||
bytes32 commandId, | ||
string calldata sourceChain, | ||
string calldata sourceAddress, | ||
bytes32 payloadHash | ||
) external returns (bool); | ||
|
||
function validateContractCallAndMint( | ||
bytes32 commandId, | ||
string calldata sourceChain, | ||
string calldata sourceAddress, | ||
bytes32 payloadHash, | ||
string calldata symbol, | ||
uint256 amount | ||
) external returns (bool); | ||
|
||
/***********\ | ||
|* Getters *| | ||
\***********/ | ||
|
||
function authModule() external view returns (address); | ||
|
||
function tokenDeployer() external view returns (address); | ||
|
||
function tokenMintLimit(string memory symbol) external view returns (uint256); | ||
|
||
function tokenMintAmount(string memory symbol) external view returns (uint256); | ||
|
||
function allTokensFrozen() external view returns (bool); | ||
|
||
function implementation() external view returns (address); | ||
|
||
function tokenAddresses(string memory symbol) external view returns (address); | ||
|
||
function tokenFrozen(string memory symbol) external view returns (bool); | ||
|
||
function isCommandExecuted(bytes32 commandId) external view returns (bool); | ||
|
||
function adminEpoch() external view returns (uint256); | ||
|
||
function adminThreshold(uint256 epoch) external view returns (uint256); | ||
|
||
function admins(uint256 epoch) external view returns (address[] memory); | ||
|
||
/*******************\ | ||
|* Admin Functions *| | ||
\*******************/ | ||
|
||
function setTokenMintLimits(string[] calldata symbols, uint256[] calldata limits) external; | ||
|
||
function upgrade( | ||
address newImplementation, | ||
bytes32 newImplementationCodeHash, | ||
bytes calldata setupParams | ||
) external; | ||
|
||
/**********************\ | ||
|* External Functions *| | ||
\**********************/ | ||
|
||
function setup(bytes calldata params) external; | ||
|
||
function execute(bytes calldata input) external; | ||
} |