Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 0e817ae
Merge: 8e24478 4c4b3f0
Author: Foivos <[email protected]>
Date:   Fri Jun 28 17:20:07 2024 +0300

    Merge remote-tracking branch 'origin/feat/address-audit-comments' into feat/address-audit-comments

commit 8e24478
Author: Foivos <[email protected]>
Date:   Fri Jun 28 17:19:29 2024 +0300

    sqush commits

commit 4c4b3f0
Author: Foivos <[email protected]>
Date:   Fri Jun 28 13:29:45 2024 +0300

    fix error

commit c167b14
Author: Foivos <[email protected]>
Date:   Fri Jun 28 13:09:16 2024 +0300

    add tests for checks

commit 92465cf
Author: Foivos <[email protected]>
Date:   Fri Jun 28 13:06:37 2024 +0300

    added additional check for setAxelarChainId

commit 6ff7928
Author: Foivos <[email protected]>
Date:   Thu Jun 27 17:57:29 2024 +0300

    forge fmt

commit c639f11
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:53:02 2024 +0300

    fix end to end tests

commit ad272af
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:31:47 2024 +0300

    fix more capitaliaztion

commit c45a2de
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:14:01 2024 +0300

    differnet import again

commit 8273c1a
Merge: 6eac1b9 1c0f731
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:13:06 2024 +0300

    Merge remote-tracking branch 'origin/main' into feat/address-audit-comments

commit 6eac1b9
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:11:50 2024 +0300

    try different import

commit 6aaf137
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:07:57 2024 +0300

    trying more stuff

commit 7bd8932
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:05:02 2024 +0300

    trying to fix CLI

commit f6e60a2
Author: Foivos <[email protected]>
Date:   Thu Jun 27 16:04:22 2024 +0300

    try a different import

commit 53b0e53
Author: Foivos <[email protected]>
Date:   Thu Jun 27 15:53:22 2024 +0300

    revert change

commit 4e576be
Author: Foivos <[email protected]>
Date:   Thu Jun 27 15:46:19 2024 +0300

    forge fmt

commit 2d6af58
Author: Foivos <[email protected]>
Date:   Thu Jun 27 15:44:06 2024 +0300

    fix import in test

commit 7eb17a4
Author: Foivos <[email protected]>
Date:   Wed Jun 26 20:39:14 2024 +0300

    remove confusing comment

commit 2c000b2
Author: Foivos <[email protected]>
Date:   Tue Jun 25 11:14:28 2024 +0300

    restrict use of setAxelarChainId

commit 56ff882
Author: Canh Trinh <[email protected]>
Date:   Mon Jun 24 15:17:03 2024 -0400

    Update test/axelar/AxelarTransceiver.t.sol

    Co-authored-by: Milap Sheth <[email protected]>

commit be34917
Author: Canh Trinh <[email protected]>
Date:   Mon Jun 24 15:15:19 2024 -0400

    Update test/axelar/AxelarTransceiver.t.sol

    Co-authored-by: Milap Sheth <[email protected]>

commit dd1288c
Author: Canh Trinh <[email protected]>
Date:   Mon Jun 24 15:14:47 2024 -0400

    Update src/axelar/AxelarTransceiver.sol

    Co-authored-by: Milap Sheth <[email protected]>

commit 2fa5cde
Author: Foivos <[email protected]>
Date:   Wed Jun 19 14:29:49 2024 +0300

    run fmt

commit d5159a5
Author: Foivos <[email protected]>
Date:   Wed Jun 19 14:16:09 2024 +0300

    Added better tests

commit f03f0eb
Author: Foivos <[email protected]>
Date:   Wed Jun 19 13:23:07 2024 +0300

    Add validation for setAxelarChainId

commit f4c441a
Author: Foivos <[email protected]>
Date:   Wed Jun 19 13:16:48 2024 +0300

    Add event to setAxelarChainId

commit 02eaea5
Merge: 43e425c d7a07d9
Author: Foivos <[email protected]>
Date:   Wed Jun 19 13:16:21 2024 +0300

    Merge branch 'feat/update-wormhole-examples-version' into feat/address-audit-comments

commit d7a07d9
Author: Foivos <[email protected]>
Date:   Thu Jun 13 14:55:07 2024 +0300

    forge fmt

commit 1ed9e1d
Author: Foivos <[email protected]>
Date:   Thu Jun 13 14:46:17 2024 +0300

    Fix axelar transceiver to include version

commit e642d8d
Author: Foivos <[email protected]>
Date:   Thu Jun 13 14:29:58 2024 +0300

    update wormhole-examples to new main

commit 1b6520a
Author: Foivos <[email protected]>
Date:   Tue Jun 11 18:19:43 2024 +0300

    added more destriptive error message

commit ef0dc87
Author: Foivos <[email protected]>
Date:   Tue Jun 11 16:21:12 2024 +0300

    forge fmt

commit 5b66ae8
Author: Foivos <[email protected]>
Date:   Tue Jun 11 16:20:53 2024 +0300

    added a constant for easy identification

commit 4c3e078
Author: Foivos <[email protected]>
Date:   Tue Jun 11 13:47:16 2024 +0300

    tests now prperly check for reverts

commit b8b2bb3
Author: Foivos <[email protected]>
Date:   Mon Jun 10 15:12:06 2024 +0300

    run forge fmt again

commit fc2dfea
Author: Foivos <[email protected]>
Date:   Mon Jun 10 15:02:58 2024 +0300

    run forge fmt

commit d8e46e4
Author: Foivos <[email protected]>
Date:   Mon Jun 10 15:01:57 2024 +0300

    remove unused var

commit 30c5c6d
Author: Foivos <[email protected]>
Date:   Mon Jun 10 14:58:57 2024 +0300

    try to fix CI again

commit 4b76355
Author: Foivos <[email protected]>
Date:   Mon Jun 10 14:56:57 2024 +0300

    try to fix CI

commit 69e5f40
Author: Foivos <[email protected]>
Date:   Sun Jun 9 22:57:40 2024 +0300

    update readme

commit fe2b441
Author: Foivos <[email protected]>
Date:   Sat Jun 8 20:59:02 2024 +0300

    added a fail test if the address is not trusted.

commit d07ebe0
Author: Foivos <[email protected]>
Date:   Sat Jun 8 20:54:16 2024 +0300

    Added a receiving token test

commit c1041cb
Author: Foivos <[email protected]>
Date:   Fri Jun 7 12:00:44 2024 +0300

    added a script to set remote siblings

commit ad9e213
Author: Milap Sheth <[email protected]>
Date:   Thu Jun 6 13:16:22 2024 -0400

    Update script/README.md

commit eebec31
Author: Milap Sheth <[email protected]>
Date:   Thu Jun 6 13:16:14 2024 -0400

    Update script/README.md

commit d839bd4
Author: Milap Sheth <[email protected]>
Date:   Thu Jun 6 13:06:25 2024 -0400

    Update src/axelar/AxelarTransceiver.sol

commit c482fcb
Author: Foivos <[email protected]>
Date:   Thu Jun 6 19:18:21 2024 +0300

    correct decoding of message

commit 6cda8f9
Author: Foivos <[email protected]>
Date:   Thu Jun 6 19:14:50 2024 +0300

    checking for immutable immutables

commit 985b915
Author: Foivos <[email protected]>
Date:   Thu Jun 6 19:10:30 2024 +0300

    remove unecesairy modifier

commit d9b4f6c
Author: Foivos <[email protected]>
Date:   Thu Jun 6 19:09:24 2024 +0300

    added some natspec

commit 709ff54
Author: Foivos <[email protected]>
Date:   Thu Jun 6 18:25:20 2024 +0300

    moved some errors

commit 4d98b15
Author: Foivos <[email protected]>
Date:   Thu Jun 6 14:07:38 2024 +0300

    add readme and rename dir

commit ac40e0d
Author: Foivos <[email protected]>
Date:   Thu Jun 6 14:03:48 2024 +0300

    update deployment script

commit f4fb0cb
Author: Foivos <[email protected]>
Date:   Wed Jun 5 18:04:51 2024 +0300

    added a deployment script

commit b446382
Author: Nikhil Suri <[email protected]>
Date:   Mon Jun 3 17:41:53 2024 -0700

    Fix CI and format

commit ca08e99
Author: Nikhil Suri <[email protected]>
Date:   Mon Jun 3 17:37:04 2024 -0700

    Fix OZ contracts issue

commit 01edb75
Author: Foivos <[email protected]>
Date:   Fri May 31 15:42:53 2024 +0300

    update tests a bit

commit ac31c4d
Author: Foivos <[email protected]>
Date:   Fri May 31 15:29:10 2024 +0300

    change some names

commit 1f25b44
Author: Foivos <[email protected]>
Date:   Fri May 31 15:28:39 2024 +0300

    Update src/axelar/AxelarTransceiver.sol

    Co-authored-by: Milap Sheth <[email protected]>

commit 9f42e32
Author: Foivos <[email protected]>
Date:   Fri May 31 15:28:16 2024 +0300

    Update src/axelar/AxelarTransceiver.sol

    Co-authored-by: Milap Sheth <[email protected]>

commit 9f2cd61
Author: Foivos <[email protected]>
Date:   Thu May 30 21:46:18 2024 +0300

    using payGas instead of payNativeGasForContractCall

commit a6d5211
Author: Foivos <[email protected]>
Date:   Thu May 30 21:37:53 2024 +0300

    using the gas service estimateGasFee

commit f3b02fe
Author: Foivos <[email protected]>
Date:   Thu May 30 21:26:00 2024 +0300

    fixed a naminginconsistency

commit 71f586f
Author: Foivos <[email protected]>
Date:   Thu May 30 21:23:57 2024 +0300

    some more comments addressed

commit 89ffcb6
Author: Foivos <[email protected]>
Date:   Thu May 30 21:01:00 2024 +0300

    remove cgp-solidity as it is unused

commit 72e05aa
Author: Foivos <[email protected]>
Date:   Thu May 30 20:59:33 2024 +0300

    address some comments

commit 5f75247
Author: Foivos <[email protected]>
Date:   Thu May 30 20:27:56 2024 +0300

    using axelar gmp executable

commit 23640f4
Author: Foivos <[email protected]>
Date:   Thu May 30 18:39:24 2024 +0300

    remove the proxy

commit 053d9fb
Merge: e4cbb67 c4361e7
Author: Foivos <[email protected]>
Date:   Thu May 30 18:35:57 2024 +0300

    Merge remote-tracking branch 'origin/main' into feat/axelar-transceiver

commit e4cbb67
Author: Foivos <[email protected]>
Date:   Thu May 30 18:27:22 2024 +0300

    Tests work

commit da28026
Author: Foivos <[email protected]>
Date:   Thu May 30 16:24:44 2024 +0300

    change oz to an older version

commit 356d603
Author: Foivos <[email protected]>
Date:   Wed May 29 18:16:28 2024 +0300

    rename storage_ to slot

commit 748b989
Author: Nikhil Suri <[email protected]>
Date:   Tue May 28 17:18:18 2024 -0700

    downgrade to oz v4.8.1

commit 32f2600
Author: Foivos <[email protected]>
Date:   Mon May 27 20:28:39 2024 +0300

    using Transceiver abstract contract

commit 490202f
Author: Foivos <[email protected]>
Date:   Fri May 24 16:51:52 2024 +0300

    fix the test

commit a228d68
Author: Foivos <[email protected]>
Date:   Fri May 24 16:02:45 2024 +0300

    added some tests

commit 96c4258
Author: Foivos <[email protected]>
Date:   Thu May 23 17:57:58 2024 +0300

    forge install: axelar-cgp-solidity

    v6.3.1

commit b31cda4
Author: Foivos <[email protected]>
Date:   Thu May 23 17:57:54 2024 +0300

    trying to add some tests

commit 62edca4
Author: Foivos <[email protected]>
Date:   Thu May 23 17:42:29 2024 +0300

    added a proxy as well

commit 06ed4c4
Author: Foivos <[email protected]>
Date:   Fri May 17 13:21:27 2024 +0300

    Added the rest of the files

commit cacecd0
Author: Foivos <[email protected]>
Date:   Fri May 17 13:16:19 2024 +0300

    add axelar tranceiver
  • Loading branch information
Foivos committed Jun 28, 2024
1 parent 1c0f731 commit 06fe10b
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/example-native-token-transfers
9 changes: 9 additions & 0 deletions src/axelar/AxelarTransceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,20 @@ contract AxelarTransceiver is IAxelarTransceiver, AxelarGMPExecutable, Transceiv
string calldata chainName,
string calldata transceiverAddress
) external virtual onlyOwner {
if (chainId == 0 || bytes(chainName).length == 0 || bytes(transceiverAddress).length == 0) {
revert InvalidChainIdParams();
}

AxelarTransceiverStorage storage slot = _storage();
if (bytes(slot.idToAxelarChainId[chainId]).length != 0) revert ChainIdAlreadySet(chainId);

if (slot.axelarChainIdToId[chainName] != 0) revert AxelarChainIdAlreadySet(chainName);
slot.idToAxelarChainId[chainId] = chainName;
slot.axelarChainIdToId[chainName] = chainId;
slot.idToTransceiverAddress[chainId] = transceiverAddress;
slot.transceiverAddressToId[transceiverAddress] = chainId;

emit AxelarChainIdSet(chainId, chainName, transceiverAddress);
}

/// @notice Fetch the delivery price for a given recipient chain transfer.
Expand Down
19 changes: 18 additions & 1 deletion src/axelar/interfaces/IAxelarTransceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ interface IAxelarTransceiver is ITransceiver {

/// @notice Chain Id passed is not valid.
/// @param chainId The wormhole chainId.
error InvalidChainId(uint16 chainId, string chainName, string destinationContract);
/// @param chainName The axelar chainName.
/// @param transceiverAddress The address of the Transceiver as a string.
error InvalidChainId(uint16 chainId, string chainName, string transceiverAddress);

/// @notice Chain Id passed is zero, or Axelar Chain Id or Transceiver Address were empty.
error InvalidChainIdParams();

/// @notice Chain Id is already being used.
error ChainIdAlreadySet(uint16 chainId);

/// @notice Axelar chain Id is already being used.
error AxelarChainIdAlreadySet(string axelarChainId);

/// @notice Emmited when a transceiver message is sent.
/// @param recipientChainId The wormhole chainId of the destination chain.
Expand All @@ -26,6 +37,12 @@ interface IAxelarTransceiver is ITransceiver {
bytes32 indexed refundAddress
);

/// @notice Emmited when the chain id is set.
/// @param chainId The wormhole chainId of the destination chain.
/// @param chainName The axelar chain name.
/// @param transceiverAddress The transceiver address as a string.
event AxelarChainIdSet(uint16 chainId, string chainName, string transceiverAddress);

/**
* Set the bridge manager contract address
* @param chainId The chainId of the chain. This is used to identify the chain in the EndpointManager.
Expand Down
64 changes: 53 additions & 11 deletions test/axelar/AxelarTransceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ import "forge-std/Test.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";

contract AxelarTransceiverTest is Test {
event ContractCall(
address indexed sender,
string destinationChain,
string destinationContractAddress,
bytes32 indexed payloadHash,
bytes payload
);

event AxelarChainIdSet(uint16 chainId, string chainName, string transceiverAddress);

address constant OWNER = address(1004);

uint64 constant RATE_LIMIT_DURATION = 0;
Expand All @@ -34,9 +44,6 @@ contract AxelarTransceiverTest is Test {
WstEthL2TokenHarness token;

function setUp() public {
string memory url = "https://ethereum-sepolia-rpc.publicnode.com";
vm.createSelectFork(url);

gateway = IAxelarGateway(new MockAxelarGateway());
gasService = IAxelarGasService(address(new MockAxelarGasService()));

Expand Down Expand Up @@ -75,12 +82,31 @@ contract AxelarTransceiverTest is Test {
string memory chainName = "chainName";
string memory axelarAddress = "axelarAddress";

vm.expectEmit(address(transceiver));
emit AxelarChainIdSet(chainId, chainName, axelarAddress);

vm.prank(OWNER);
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);
/*assertEq(transceiver.idToAxelarChainIds(chainId), chainName);
assertEq(transceiver.axelarChainIdToId(chainName),chainId);
assertEq(transceiver.idToAxelarAddress(chainId), axelarAddress);
assertEq(transceiver.axelarAddressToId(axelarAddress), chainId);*/
}

function test_setAxelarChainIdDuplicateChainId() public {
uint16 chainId = 1;
string memory chainName = "chainName";
string memory axelarAddress = "axelarAddress";

vm.expectEmit(address(transceiver));
emit AxelarChainIdSet(chainId, chainName, axelarAddress);

vm.prank(OWNER);
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);

vm.prank(OWNER);
vm.expectRevert(abi.encodeWithSignature("ChainIdAlreadySet(uint16)", chainId));
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);

vm.prank(OWNER);
vm.expectRevert(abi.encodeWithSignature("AxelarChainIdAlreadySet(string)", chainName));
transceiver.setAxelarChainId(chainId + 1, chainName, axelarAddress);
}

function test_setAxelarChainIdNotOwner() public {
Expand All @@ -101,11 +127,18 @@ contract AxelarTransceiverTest is Test {
bytes32 recipientNttManagerAddress = bytes32(uint256(1010));
bytes memory nttManagerMessage = bytes("nttManagerMessage");
bytes32 refundAddress = bytes32(uint256(1011));
bytes memory payload = abi.encode(manager, nttManagerMessage, recipientNttManagerAddress);
TransceiverStructs.TransceiverInstruction memory instruction =
TransceiverStructs.TransceiverInstruction(0, bytes(""));

vm.prank(OWNER);
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);

vm.expectEmit(address(gateway));
emit ContractCall(
address(transceiver), chainName, axelarAddress, keccak256(payload), payload
);

vm.prank(address(manager));
transceiver.sendMessage(
chainId, instruction, nttManagerMessage, recipientNttManagerAddress, refundAddress
Expand Down Expand Up @@ -167,6 +200,7 @@ contract AxelarTransceiverTest is Test {
uint16 chainId = 2;
string memory chainName = "chainName";
string memory axelarAddress = "axelarAddress";
bytes32 messageId = bytes32(uint256(25));
bytes32 recipientNttManagerAddress = bytes32(uint256(uint160(address(manager))));

bytes32 to = bytes32(uint256(1234));
Expand All @@ -184,9 +218,9 @@ contract AxelarTransceiverTest is Test {
bytes memory nttManagerMessage;
{
uint16 length = uint16(nttPayload.length);
bytes32 messageId = bytes32(uint256(0));
bytes32 nttMessageId = bytes32(uint256(0));
bytes32 sender = bytes32(uint256(1));
nttManagerMessage = abi.encodePacked(messageId, sender, length, nttPayload);
nttManagerMessage = abi.encodePacked(nttMessageId, sender, length, nttPayload);
}

bytes32 sourceNttManagerAddress = bytes32(uint256(1012));
Expand All @@ -201,21 +235,29 @@ contract AxelarTransceiverTest is Test {
token.setMinter(OWNER);
vm.prank(OWNER);
token.mint(address(manager), amount);
gateway.approveContractCall(messageId, chainName, axelarAddress, keccak256(payload));

transceiver.execute(bytes32(0), chainName, axelarAddress, payload);
transceiver.execute(messageId, chainName, axelarAddress, payload);

if (token.balanceOf(fromWormholeFormat(to)) != amount) revert("Amount Incorrect");

vm.prank(OWNER);
token.mint(address(manager), amount);
vm.expectRevert(abi.encodeWithSignature("NotApprovedByGateway()"));
transceiver.execute(bytes32(0), chainName, axelarAddress, payload);
}

function test_executeNotTrustedAddress() public {
string memory chainName = "chainName";
string memory axelarAddress = "axelarAddress";
bytes memory payload = bytes("");
bytes32 messageId = keccak256(bytes("message Id"));
gateway.approveContractCall(messageId, chainName, axelarAddress, keccak256(payload));
vm.expectRevert(
abi.encodeWithSignature(
"InvalidSibling(uint16,string,string)", 0, chainName, axelarAddress
)
);
transceiver.execute(bytes32(0), chainName, axelarAddress, payload);
transceiver.execute(messageId, chainName, axelarAddress, payload);
}
}
199 changes: 199 additions & 0 deletions test/axelar/AxelarTransceiverEndToEnd.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// SPDX-License-Identifier: Apache 2
pragma solidity >=0.8.8 <0.9.0;

import "../../src/axelar/AxelarTransceiver.sol";
import "./mock/MockGateway.sol";
import {MockAxelarGasService} from "./mock/MockGasService.sol";
import {TransceiverStructs} from
"@wormhole-foundation/native_token_transfer/libraries/TransceiverStructs.sol";
import {NttManager} from "@wormhole-foundation/native_token_transfer/NttManager/NttManager.sol";
import {INttManager} from "@wormhole-foundation/native_token_transfer/interfaces/INttManager.sol";
import {IManagerBase} from "@wormhole-foundation/native_token_transfer/interfaces/IManagerBase.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {WstEthL2Token} from "src/token/WstEthL2Token.sol";

import "forge-std/console.sol";
import "forge-std/Test.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";

contract AxelarTransceiverEndToEnd is Test {
address constant OWNER = address(1004);
uint64 constant RATE_LIMIT_DURATION = 0;
bool constant SKIP_RATE_LIMITING = true;

uint256 constant DEVNET_GUARDIAN_PK =
0xcfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0;

AxelarTransceiver sourceTransceiver;
IAxelarGateway gateway;
IAxelarGasService gasService;
NttManager sourceNttmanager;
WstEthL2Token sourceToken;
uint16 sourceChainId;

AxelarTransceiver recipientTransceiver;
NttManager recipientNttManager;
WstEthL2Token recipientToken;
uint16 recipientChainId;

function setUp() public {
gateway = IAxelarGateway(new MockAxelarGateway());
gasService = IAxelarGasService(address(new MockAxelarGasService()));
// Setup Source Infrastructure
sourceChainId = 1;
address tokenImplementaion = address(new WstEthL2Token());
sourceToken = WstEthL2Token(
address(
new ERC1967Proxy(
tokenImplementaion,
abi.encodeWithSelector(
WstEthL2Token.initialize.selector, "Source Token", "ST", OWNER
)
)
)
);
vm.prank(OWNER);
sourceToken.setMinter(OWNER);
address sourceManagerImplementation = address(
new NttManager(
address(sourceToken),
IManagerBase.Mode.LOCKING,
sourceChainId,
RATE_LIMIT_DURATION,
SKIP_RATE_LIMITING
)
);
sourceNttmanager = NttManager(address(new ERC1967Proxy(sourceManagerImplementation, "")));
sourceNttmanager.initialize();
sourceNttmanager.transferOwnership(OWNER);
address srcTransceiverImplementation = address(
new AxelarTransceiver(address(gateway), address(gasService), address(sourceNttmanager))
);
sourceTransceiver =
AxelarTransceiver(address(new ERC1967Proxy(srcTransceiverImplementation, "")));
sourceTransceiver.initialize();
vm.prank(OWNER);
sourceNttmanager.setTransceiver(address(sourceTransceiver));

// Setup Recipient Infrastructure
recipientChainId = 2;
recipientToken = WstEthL2Token(
address(
new ERC1967Proxy(
tokenImplementaion,
abi.encodeWithSelector(
WstEthL2Token.initialize.selector, "Source Token", "ST", OWNER
)
)
)
);
vm.prank(OWNER);
recipientToken.setMinter(OWNER);
address recipientManagerImplementation = address(
new NttManager(
address(recipientToken),
IManagerBase.Mode.LOCKING,
recipientChainId,
RATE_LIMIT_DURATION,
SKIP_RATE_LIMITING
)
);
recipientNttManager =
NttManager(address(new ERC1967Proxy(recipientManagerImplementation, "")));
recipientNttManager.initialize();
recipientNttManager.transferOwnership(OWNER);
address rcptTransceiverImplementation = address(
new AxelarTransceiver(
address(gateway), address(gasService), address(recipientNttManager)
)
);
recipientTransceiver =
AxelarTransceiver(address(new ERC1967Proxy(rcptTransceiverImplementation, "")));
recipientTransceiver.initialize();
vm.prank(OWNER);
recipientNttManager.setTransceiver(address(recipientTransceiver));

bytes32 sourceNttManagerAddress = bytes32(uint256(uint160(address(sourceNttmanager))));
bytes32 recipientNttManagerAddress = bytes32(uint256(uint160(address(recipientNttManager))));

// set peer ntt manager on source
vm.prank(OWNER);
sourceNttmanager.setPeer(recipientChainId, recipientNttManagerAddress, 18, 100000000);

// set peer ntt manager on recipient
vm.prank(OWNER);
recipientNttManager.setPeer(sourceChainId, sourceNttManagerAddress, 18, 100000000);

string memory sourceChainName = "srcChain";
string memory sourceAxelarAddress = "srcAxelar";

string memory recipientChainName = "recipientChain";
string memory recipientAxelarAddress = "recipientAxelar";

vm.prank(OWNER);
sourceTransceiver.setAxelarChainId(
recipientChainId, recipientChainName, recipientAxelarAddress
);

vm.prank(OWNER);
recipientTransceiver.setAxelarChainId(sourceChainId, sourceChainName, sourceAxelarAddress);

// token mint source
vm.prank(OWNER);
sourceToken.mint(address(sourceNttmanager), 10e6 ether);

vm.prank(OWNER);
recipientToken.mint(address(recipientNttManager), 10e6 ether);
}

function testAxelarTransceiverEndToEnd() public {
bytes32 refundAddress = bytes32(uint256(1011));
TransceiverStructs.TransceiverInstruction memory instruction =
TransceiverStructs.TransceiverInstruction(0, bytes(""));

// SEND MESSAGE ON SOURCE CHAIN
bytes32 to = bytes32(uint256(1234));
uint64 amount = 12345670000000000;
bytes memory nttPayload;
{
bytes4 prefix = TransceiverStructs.NTT_PREFIX;
uint8 decimals = 18;
bytes32 srcToken = bytes32(uint256(uint160(address(sourceToken))));
uint16 toChain = 2;
nttPayload = abi.encodePacked(prefix, decimals, amount, srcToken, to, toChain);
}

bytes memory nttManagerMessage;
{
uint16 length = uint16(nttPayload.length);
bytes32 nttMessageId = bytes32(uint256(0));
bytes32 sender = bytes32(uint256(1));
nttManagerMessage = abi.encodePacked(nttMessageId, sender, length, nttPayload);
}
bytes32 sourceNttManagerAddress = bytes32(uint256(uint160(address(sourceNttmanager))));
bytes32 recipientNttManagerAddress = bytes32(uint256(uint160(address(recipientNttManager))));

vm.prank(address(sourceNttmanager));
sourceTransceiver.sendMessage(
recipientChainId,
instruction,
nttManagerMessage,
recipientNttManagerAddress,
refundAddress
);

// EXECUTE ON RECIPIENT CHAIN
bytes memory payload =
abi.encode(sourceNttManagerAddress, nttManagerMessage, recipientNttManagerAddress);

string memory sourceChainName = "srcChain";
string memory sourceAxelarAddress = "srcAxelar";
bytes32 messageId = keccak256(bytes("message Id"));

gateway.approveContractCall(
messageId, sourceChainName, sourceAxelarAddress, keccak256(payload)
);
recipientTransceiver.execute(messageId, sourceChainName, sourceAxelarAddress, payload);
if (recipientToken.balanceOf(fromWormholeFormat(to)) != amount) revert("Amount Incorrect");
}
}
Loading

0 comments on commit 06fe10b

Please sign in to comment.