forked from axelarnetwork/axelar-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDistributionExecutable.sol
56 lines (50 loc) · 2.2 KB
/
DistributionExecutable.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import { AxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol';
contract DistributionExecutable is AxelarExecutable {
IAxelarGasService public immutable gasService;
constructor(address gateway_, address gasReceiver_) AxelarExecutable(gateway_) {
gasService = IAxelarGasService(gasReceiver_);
}
function sendToMany(
string memory destinationChain,
string memory destinationAddress,
address[] calldata destinationAddresses,
string memory symbol,
uint256 amount
) external payable {
address tokenAddress = gateway.tokenAddresses(symbol);
IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount);
IERC20(tokenAddress).approve(address(gateway), amount);
bytes memory payload = abi.encode(destinationAddresses);
if (msg.value > 0) {
gasService.payNativeGasForContractCallWithToken{ value: msg.value }(
address(this),
destinationChain,
destinationAddress,
payload,
symbol,
amount,
msg.sender
);
}
gateway.callContractWithToken(destinationChain, destinationAddress, payload, symbol, amount);
}
function _executeWithToken(
string calldata,
string calldata,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) internal override {
address[] memory recipients = abi.decode(payload, (address[]));
address tokenAddress = gateway.tokenAddresses(tokenSymbol);
uint256 sentAmount = amount / recipients.length;
for (uint256 i = 0; i < recipients.length; i++) {
IERC20(tokenAddress).transfer(recipients[i], sentAmount);
}
}
}