-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDestinationChainSwapExecutable.sol
34 lines (26 loc) · 1.26 KB
/
DestinationChainSwapExecutable.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import { IAxelarExecutable } from '../../interfaces/IAxelarExecutable.sol';
import { IERC20 } from '../../interfaces/IERC20.sol';
import { DestinationChainTokenSwapper } from './DestinationChainTokenSwapper.sol';
contract DestinationChainSwapExecutable is IAxelarExecutable {
DestinationChainTokenSwapper swapper;
constructor(address gatewayAddress, address swapperAddress) IAxelarExecutable(gatewayAddress) {
swapper = DestinationChainTokenSwapper(swapperAddress);
}
function _executeWithToken(
string memory sourceChain,
string memory,
bytes calldata payload,
string memory tokenSymbolA,
uint256 amount
) internal override {
(string memory tokenSymbolB, string memory recipient) = abi.decode(payload, (string, string));
address tokenA = gateway.tokenAddresses(tokenSymbolA);
address tokenB = gateway.tokenAddresses(tokenSymbolB);
IERC20(tokenA).approve(address(swapper), amount);
uint256 convertedAmount = swapper.swap(tokenA, tokenB, amount, address(this));
IERC20(tokenB).approve(address(gateway), convertedAmount);
gateway.sendToken(sourceChain, recipient, tokenSymbolB, convertedAmount);
}
}