Skip to content

Commit

Permalink
Merge pull request #14 from skip-mev/axelar_execute_swap
Browse files Browse the repository at this point in the history
Axelar execute swap
  • Loading branch information
thal0x authored Oct 30, 2024
2 parents 53e7f36 + 701cca0 commit a95690a
Show file tree
Hide file tree
Showing 20 changed files with 1,747 additions and 213 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion AxelarHandler/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export PRIVATE_KEY=<key>
export RPC_URL=<url>
export RPC_MAINNET=<url>
12 changes: 0 additions & 12 deletions AxelarHandler/.gitmodules

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"transactions": [
{
"hash": null,
"transactionType": "CREATE2",
"contractName": "BytesLib",
"contractAddress": "0xbfb201a128d08c99a6228938415b02d20b6ec4ad",
"function": null,
"arguments": null,
"transaction": {
"from": "0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"gas": "0x27fab",
"input": "0x000000000000000000000000000000000000000000000000000000000000000061012b61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361060335760003560e01c8063593b79fe146038575b600080fd5b60676043366004607b565b604080516001600160a01b0392909216600560a21b18601483015260348201905290565b6040516072919060a9565b60405180910390f35b600060208284031215608c57600080fd5b81356001600160a01b038116811460a257600080fd5b9392505050565b600060208083528351808285015260005b8181101560d45785810183015185820160400152820160ba565b506000604082860101526040601f19601f830116850101925050509291505056fea26469706673582212202001b5e1dbec67ed81daef4e82e5dc66748bca332df0db2a80f4ac32bc7eda7664736f6c63430008120033",
"nonce": "0x0",
"chainId": "0x1"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [],
"libraries": [
"src/libraries/Path.sol:BytesLib:0xBfB201a128D08C99a6228938415B02D20b6Ec4ad"
],
"pending": [],
"returns": {},
"timestamp": 1723057712,
"chain": 1,
"commit": "502ef75"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"transactions": [
{
"hash": null,
"transactionType": "CREATE2",
"contractName": "BytesLib",
"contractAddress": "0xbfb201a128d08c99a6228938415b02d20b6ec4ad",
"function": null,
"arguments": null,
"transaction": {
"from": "0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"gas": "0x27fab",
"input": "0x000000000000000000000000000000000000000000000000000000000000000061012b61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361060335760003560e01c8063593b79fe146038575b600080fd5b60676043366004607b565b604080516001600160a01b0392909216600560a21b18601483015260348201905290565b6040516072919060a9565b60405180910390f35b600060208284031215608c57600080fd5b81356001600160a01b038116811460a257600080fd5b9392505050565b600060208083528351808285015260005b8181101560d45785810183015185820160400152820160ba565b506000604082860101526040601f19601f830116850101925050509291505056fea26469706673582212202001b5e1dbec67ed81daef4e82e5dc66748bca332df0db2a80f4ac32bc7eda7664736f6c63430008120033",
"nonce": "0x0",
"chainId": "0x1"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [],
"libraries": [
"src/libraries/Path.sol:BytesLib:0xBfB201a128D08C99a6228938415B02D20b6Ec4ad"
],
"pending": [],
"returns": {},
"timestamp": 1723057941,
"chain": 1,
"commit": "502ef75"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"transactions": [
{
"hash": null,
"transactionType": "CREATE2",
"contractName": "BytesLib",
"contractAddress": "0xbfb201a128d08c99a6228938415b02d20b6ec4ad",
"function": null,
"arguments": null,
"transaction": {
"from": "0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"gas": "0x27fab",
"input": "0x000000000000000000000000000000000000000000000000000000000000000061012b61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361060335760003560e01c8063593b79fe146038575b600080fd5b60676043366004607b565b604080516001600160a01b0392909216600560a21b18601483015260348201905290565b6040516072919060a9565b60405180910390f35b600060208284031215608c57600080fd5b81356001600160a01b038116811460a257600080fd5b9392505050565b600060208083528351808285015260005b8181101560d45785810183015185820160400152820160ba565b506000604082860101526040601f19601f830116850101925050509291505056fea26469706673582212202001b5e1dbec67ed81daef4e82e5dc66748bca332df0db2a80f4ac32bc7eda7664736f6c63430008120033",
"nonce": "0x0",
"chainId": "0x1"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [],
"libraries": [
"src/libraries/Path.sol:BytesLib:0xBfB201a128D08C99a6228938415B02D20b6Ec4ad"
],
"pending": [],
"returns": {},
"timestamp": 1723057941,
"chain": 1,
"commit": "502ef75"
}
3 changes: 3 additions & 0 deletions AxelarHandler/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
src = "src"
out = "out"
libs = ["lib"]
evm_version = "paris"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
[rpc_endpoints]
mainnet = "${RPC_MAINNET}"
2 changes: 1 addition & 1 deletion AxelarHandler/script/AxelarHandlerSetRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Script.sol";

import {AxelarHandler} from "src/AxelarHandler.sol";

contract AxelarHandlerUpgradeScript is Script {
contract AxelarHandlerSetRouterScript is Script {
AxelarHandler public handler;
address public router;

Expand Down
86 changes: 86 additions & 0 deletions AxelarHandler/script/SimulateExecuteWithToken.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "forge-std/Test.sol";
import {Environment} from "test/Environment.sol";
import {MockGateway} from "test/mocks/MockGateway.sol";
import {IERC20} from "forge-std/interfaces/IERC20.sol";

import {ERC1967Proxy} from "lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {AxelarHandler} from "src/AxelarHandler.sol";

contract SimulateExecuteWithToken is Script, Test {
AxelarHandler public handler;
Environment public env;
MockGateway public mockGateway;

function setUp() public {
vm.createSelectFork(vm.rpcUrl("mainnet"));

env = new Environment();
env.setEnv(block.chainid);

mockGateway = new MockGateway();

address gateway = address(mockGateway);
address gasService = env.gasService();
address swapRouter = env.swapRouter();
string memory wethSymbol = env.wethSymbol();

AxelarHandler handlerImpl = new AxelarHandler();
ERC1967Proxy handlerProxy = new ERC1967Proxy(
address(handlerImpl),
abi.encodeWithSignature("initialize(address,address,string)", gateway, gasService, wethSymbol)
);
handler = AxelarHandler(payable(address(handlerProxy)));

handler.setSwapRouter(swapRouter);
}

function run() public {
string memory tokenInputSymbol = "WETH";
address tokenIn = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address tokenOut = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; //USDC
address destination = 0x0000000000000000000000000000000000000048;
uint256 amountIn = 1 ether;
uint256 amountOutMin = 1_000 * 1e6;
bool unwrap = false;

mockGateway.saveTokenAddress(tokenInputSymbol, tokenIn);
deal(address(tokenIn), address(handler), amountIn);

bytes memory swapPayload = abi.encode(uint8(0), tokenOut, amountOutMin, abi.encode(uint24(3000), uint160(0)));
bytes memory payload = abi.encode(uint8(2), abi.encode(destination, unwrap, swapPayload));

console2.logBytes(payload);

console2.log("Token Out Destination Balance Before: %s", IERC20(tokenOut).balanceOf(destination));

handler.executeWithToken(
keccak256(abi.encodePacked("COMMAND_ID")), "osmosis-7", "mock_address", payload, tokenInputSymbol, amountIn
);

console2.log("Token Out Destination Balance After: %s", IERC20(tokenOut).balanceOf(destination));
}

function run(
bytes memory payload,
string memory tokenSymbol,
address token,
address tokenOut,
address destination,
uint256 amount
) public {
mockGateway.saveTokenAddress(tokenSymbol, token);
deal(address(token), address(handler), amount);

console2.log("Token Out Destination Balance Before: %s", IERC20(tokenOut).balanceOf(destination));

handler.executeWithToken(
keccak256(abi.encodePacked("COMMAND_ID")), "osmosis-7", "mock_address", payload, tokenSymbol, amount
);

console2.log("Token Out Destination Balance After: %s", IERC20(tokenOut).balanceOf(destination));
}
}
Loading

0 comments on commit a95690a

Please sign in to comment.