Skip to content

Commit d2d79ae

Browse files
authored
TokenGateway Tests (#104)
1 parent dffb69a commit d2d79ae

30 files changed

+652
-239
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pages/network/node.mdx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ docker run polytopelabs/hyperbridge:latest --chain=messier
2424
You can install a prebuilt binary for the hyperbridge node with the following bash script
2525

2626
```bash
27-
wget -q --show-progress https://github.com/polytope-labs/hyperbridge/releases/download/v0.3.2/hyperbridge-x86_64-unknown-linux-gnu.tar.gz
27+
wget -q --show-progress https://github.com/polytope-labs/hyperbridge/releases/download/v0.3.4/hyperbridge-x86_64-unknown-linux-gnu.tar.gz
2828
tar -xvzf hyperbridge-x86_64-unknown-linux-gnu.tar.gz
2929
# copy to $PATH
3030
cp hyperbridge-x86_64-unknown-linux-gnu/hyperbridge $HOME/.local/bin/
@@ -33,7 +33,7 @@ cp hyperbridge-x86_64-unknown-linux-gnu/hyperbridge $HOME/.local/bin/
3333
or a 1-liner shell script
3434

3535
```bash
36-
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/polytope-labs/hyperbridge/releases/download/v0.3.2/hyperbridge-installer.sh | sh
36+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/polytope-labs/hyperbridge/releases/download/v0.3.4/hyperbridge-installer.sh | sh
3737
```
3838

3939
## Building from source
@@ -101,7 +101,7 @@ Download a local copy of the repo and checkout the latest release tag
101101
```bash
102102
git clone https://github.com/polytope-labs/hyperbridge.git
103103
cd ./hyperbidge
104-
git checkout v0.3.2
104+
git checkout v0.3.4
105105
```
106106

107107
### Build the node
@@ -112,8 +112,19 @@ cargo build --release -p hyperbridge
112112

113113
::::
114114

115-
## Running the node
115+
## Running the node (Rococo)
116+
117+
Hyperbridge currently exists on the rococo testnet, with a chainId of `gargantua` and paraId of `4374`. You can sync the rococo in a few hours by appending a relay chain argument `--sync=fast-unsafe`. This tells the relay chain node to simply download it's blocks and not execute them. It'll also download the full latest state.
118+
This is fine because the rococo testnet has no economic value.
116119

117120
```bash
118-
hyperbridge --chain=messier --enable-offchain-indexing --base-path=$HOME/.hyperbridge --pruning-archive
121+
hyperbridge --chain=gargantua --base-path=$HOME/.hyperbridge --pruning-archive -- --sync=fast-unsafe
119122
```
123+
124+
## Running the node (Kusama)
125+
126+
Hyperbridge also currently exists on Kusama with a chainId of `messier` and paraId of `3340`
127+
128+
```bash
129+
hyperbridge --chain=messier --base-path=$HOME/.hyperbridge --pruning-archive
130+
```

docs/pages/network/relayer.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ delivery_endpoints = [
197197

198198
It is optional to provide the configuration option for any of the connected chains, The only consequence is your relayer will not deliver requests from the ommitted chain as it has no way of querying the associated fees for requests originating from this chain.
199199

200+
You can get the etherscan API key by following [this guide](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics) for the required network. Please note that since Ethereum and it's L2s all use Ether as the gas token. They can all share the same etherscan API key.
201+
200202
You can find the up-to-date contract addresses for the `Handler` & `IsmpHost` contracts [here](/evm/integration#gargantua-v2)
201203

202204
### Withdrawing Fees

evm/abi/src/generated/evm_host.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ pub mod evm_host {
493493
),
494494
},],
495495
constant: ::core::option::Option::None,
496-
state_mutability: ::ethers::core::abi::ethabi::StateMutability::NonPayable,
496+
state_mutability: ::ethers::core::abi::ethabi::StateMutability::View,
497497
},],
498498
),
499499
(
@@ -542,6 +542,22 @@ pub mod evm_host {
542542
state_mutability: ::ethers::core::abi::ethabi::StateMutability::View,
543543
},],
544544
),
545+
(
546+
::std::borrow::ToOwned::to_owned("perByteFee"),
547+
::std::vec![::ethers::core::abi::ethabi::Function {
548+
name: ::std::borrow::ToOwned::to_owned("perByteFee"),
549+
inputs: ::std::vec![],
550+
outputs: ::std::vec![::ethers::core::abi::ethabi::Param {
551+
name: ::std::string::String::new(),
552+
kind: ::ethers::core::abi::ethabi::ParamType::Uint(256usize,),
553+
internal_type: ::core::option::Option::Some(
554+
::std::borrow::ToOwned::to_owned("uint256"),
555+
),
556+
},],
557+
constant: ::core::option::Option::None,
558+
state_mutability: ::ethers::core::abi::ethabi::StateMutability::View,
559+
},],
560+
),
545561
(
546562
::std::borrow::ToOwned::to_owned("requestCommitments"),
547563
::std::vec![::ethers::core::abi::ethabi::Function {
@@ -1397,6 +1413,14 @@ pub mod evm_host {
13971413
.method_hash([86, 182, 85, 151], ())
13981414
.expect("method not found (this should never happen)")
13991415
}
1416+
///Calls the contract's `perByteFee` (0x641d729d) function
1417+
pub fn per_byte_fee(
1418+
&self,
1419+
) -> ::ethers::contract::builders::ContractCall<M, ::ethers::core::types::U256> {
1420+
self.0
1421+
.method_hash([100, 29, 114, 157], ())
1422+
.expect("method not found (this should never happen)")
1423+
}
14001424
///Calls the contract's `requestCommitments` (0x368bf464) function
14011425
pub fn request_commitments(
14021426
&self,
@@ -2148,6 +2172,20 @@ pub mod evm_host {
21482172
)]
21492173
#[ethcall(name = "latestStateMachineHeight", abi = "latestStateMachineHeight()")]
21502174
pub struct LatestStateMachineHeightCall;
2175+
///Container type for all input parameters for the `perByteFee` function with signature
2176+
/// `perByteFee()` and selector `0x641d729d`
2177+
#[derive(
2178+
Clone,
2179+
::ethers::contract::EthCall,
2180+
::ethers::contract::EthDisplay,
2181+
Default,
2182+
Debug,
2183+
PartialEq,
2184+
Eq,
2185+
Hash,
2186+
)]
2187+
#[ethcall(name = "perByteFee", abi = "perByteFee()")]
2188+
pub struct PerByteFeeCall;
21512189
///Container type for all input parameters for the `requestCommitments` function with signature
21522190
/// `requestCommitments(bytes32)` and selector `0x368bf464`
21532191
#[derive(
@@ -2462,6 +2500,7 @@ pub mod evm_host {
24622500
Host(HostCall),
24632501
HostParams(HostParamsCall),
24642502
LatestStateMachineHeight(LatestStateMachineHeightCall),
2503+
PerByteFee(PerByteFeeCall),
24652504
RequestCommitments(RequestCommitmentsCall),
24662505
RequestReceipts(RequestReceiptsCall),
24672506
ResponseCommitments(ResponseCommitmentsCall),
@@ -2572,6 +2611,9 @@ pub mod evm_host {
25722611
{
25732612
return Ok(Self::LatestStateMachineHeight(decoded));
25742613
}
2614+
if let Ok(decoded) = <PerByteFeeCall as ::ethers::core::abi::AbiDecode>::decode(data) {
2615+
return Ok(Self::PerByteFee(decoded));
2616+
}
25752617
if let Ok(decoded) =
25762618
<RequestCommitmentsCall as ::ethers::core::abi::AbiDecode>::decode(data)
25772619
{
@@ -2687,6 +2729,7 @@ pub mod evm_host {
26872729
Self::HostParams(element) => ::ethers::core::abi::AbiEncode::encode(element),
26882730
Self::LatestStateMachineHeight(element) =>
26892731
::ethers::core::abi::AbiEncode::encode(element),
2732+
Self::PerByteFee(element) => ::ethers::core::abi::AbiEncode::encode(element),
26902733
Self::RequestCommitments(element) =>
26912734
::ethers::core::abi::AbiEncode::encode(element),
26922735
Self::RequestReceipts(element) => ::ethers::core::abi::AbiEncode::encode(element),
@@ -2741,6 +2784,7 @@ pub mod evm_host {
27412784
Self::Host(element) => ::core::fmt::Display::fmt(element, f),
27422785
Self::HostParams(element) => ::core::fmt::Display::fmt(element, f),
27432786
Self::LatestStateMachineHeight(element) => ::core::fmt::Display::fmt(element, f),
2787+
Self::PerByteFee(element) => ::core::fmt::Display::fmt(element, f),
27442788
Self::RequestCommitments(element) => ::core::fmt::Display::fmt(element, f),
27452789
Self::RequestReceipts(element) => ::core::fmt::Display::fmt(element, f),
27462790
Self::ResponseCommitments(element) => ::core::fmt::Display::fmt(element, f),
@@ -2865,6 +2909,11 @@ pub mod evm_host {
28652909
Self::LatestStateMachineHeight(value)
28662910
}
28672911
}
2912+
impl ::core::convert::From<PerByteFeeCall> for EvmHostCalls {
2913+
fn from(value: PerByteFeeCall) -> Self {
2914+
Self::PerByteFee(value)
2915+
}
2916+
}
28682917
impl ::core::convert::From<RequestCommitmentsCall> for EvmHostCalls {
28692918
fn from(value: RequestCommitmentsCall) -> Self {
28702919
Self::RequestCommitments(value)
@@ -3098,6 +3147,19 @@ pub mod evm_host {
30983147
Hash,
30993148
)]
31003149
pub struct LatestStateMachineHeightReturn(pub ::ethers::core::types::U256);
3150+
///Container type for all return fields from the `perByteFee` function with signature
3151+
/// `perByteFee()` and selector `0x641d729d`
3152+
#[derive(
3153+
Clone,
3154+
::ethers::contract::EthAbiType,
3155+
::ethers::contract::EthAbiCodec,
3156+
Default,
3157+
Debug,
3158+
PartialEq,
3159+
Eq,
3160+
Hash,
3161+
)]
3162+
pub struct PerByteFeeReturn(pub ::ethers::core::types::U256);
31013163
///Container type for all return fields from the `requestCommitments` function with signature
31023164
/// `requestCommitments(bytes32)` and selector `0x368bf464`
31033165
#[derive(

evm/abi/src/generated/host_manager.rs

Lines changed: 59 additions & 9 deletions
Large diffs are not rendered by default.

evm/abi/src/generated/ping_module.rs

Lines changed: 50 additions & 0 deletions
Large diffs are not rendered by default.

evm/examples/CrossChainMessenger.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ pragma solidity 0.8.17;
55

66
import "ismp/IIsmpModule.sol";
77
import "ismp/IIsmpHost.sol";
8-
import "ismp/IIsmp.sol";
8+
import "ismp/Message.sol";
9+
import "ismp/IDispatcher.sol";
910

1011
struct CrossChainMessage {
1112
bytes dest;
@@ -58,7 +59,7 @@ contract CrossChainMessenger is IIsmpModule {
5859
gaslimit: 0,
5960
fee: 0
6061
});
61-
IIsmp(host).dispatch(post);
62+
IDispatcher(host).dispatch(post);
6263
}
6364

6465
function onAccept(PostRequest memory request) external onlyIsmpHost {

evm/examples/PingModule.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ pragma solidity 0.8.17;
66
import "ismp/IIsmpModule.sol";
77
import "ismp/IIsmpHost.sol";
88
import "ismp/StateMachine.sol";
9-
import "ismp/IIsmp.sol";
9+
import "ismp/Message.sol";
10+
import "ismp/IDispatcher.sol";
1011

1112
struct PingMessage {
1213
bytes dest;
@@ -72,7 +73,7 @@ contract PingModule is IIsmpModule {
7273
gaslimit: response.gaslimit,
7374
fee: 0
7475
});
75-
IIsmp(_host).dispatch(post);
76+
IDispatcher(_host).dispatch(post);
7677
return response.hash();
7778
}
7879

@@ -85,7 +86,7 @@ contract PingModule is IIsmpModule {
8586
gaslimit: request.gaslimit,
8687
fee: 0
8788
});
88-
IIsmp(_host).dispatch(post);
89+
IDispatcher(_host).dispatch(post);
8990
return request.hash();
9091
}
9192

@@ -98,7 +99,7 @@ contract PingModule is IIsmpModule {
9899
gaslimit: request.gaslimit,
99100
fee: 0
100101
});
101-
IIsmp(_host).dispatch(get);
102+
IDispatcher(_host).dispatch(get);
102103
return request.hash();
103104
}
104105

@@ -115,7 +116,7 @@ contract PingModule is IIsmpModule {
115116
gaslimit: 0,
116117
fee: pingMessage.fee
117118
});
118-
IIsmp(_host).dispatch(post);
119+
IDispatcher(_host).dispatch(post);
119120
}
120121
}
121122

@@ -129,7 +130,7 @@ contract PingModule is IIsmpModule {
129130
gaslimit: 0,
130131
fee: 0
131132
});
132-
IIsmp(_host).dispatch(post);
133+
IDispatcher(_host).dispatch(post);
133134
}
134135

135136
function onAccept(PostRequest memory request) external onlyIsmpHost {

evm/script/DeployGateway.s.sol

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ import "forge-std/Script.sol";
55
import "openzeppelin/utils/Strings.sol";
66
import {ERC6160Ext20} from "ERC6160/tokens/ERC6160Ext20.sol";
77

8-
import {TokenGateway} from "../src/modules/TokenGateway.sol";
8+
import {TokenGateway, Asset, InitParams} from "../src/modules/TokenGateway.sol";
99
import {TokenFaucet} from "../src/modules/TokenFaucet.sol";
1010
import {PingModule} from "../examples/PingModule.sol";
1111
import {CrossChainMessenger} from "../examples/CrossChainMessenger.sol";
12+
import {StateMachine} from "ismp/StateMachine.sol";
1213

1314
contract DeployScript is Script {
14-
bytes32 public salt = keccak256(bytes("gargantua-v0.0.7"));
15+
bytes32 public salt = keccak256(bytes(vm.envString("VERSION")));
1516

16-
address public SEPOLIA_HOST = 0x5b5F63C8f3985CaFE1CE53E6374f42AB60dE5a6B;
17-
address public ARB_SEPOLIA_HOST = 0x43E136611Cf74E165116a47e6F9C58AFCc80Ec54;
18-
address public OP_SEPOLIA_HOST = 0x0124f458900FCd101c4CE31A9772fD2c5e6d65BF;
19-
address public BASE_SEPOLIA_HOST = 0x87825f839d95c6021c0e821917F93aDB299eD6F8;
17+
address public SEPOLIA_HOST = 0x9DF353352b469782AB1B0F2CbBFEC41bF1FDbDb3;
18+
address public ARB_SEPOLIA_HOST = 0x424e6971EB1C693cf4296d4bdb42aa0F32a0dd9e;
19+
address public OP_SEPOLIA_HOST = 0x1B58A47e61Ca7604b634CBB00b4e275cCd7c9E95;
20+
address public BASE_SEPOLIA_HOST = 0x4c876500A13cc3825D343b5Ac791d3A4913bF14f;
21+
address public BSC_TESTNET_HOST = 0x022DDE07A21d8c553978b006D93CDe68ac83e677;
2022

2123
bytes32 public constant MINTER_ROLE = keccak256("MINTER ROLE");
2224
bytes32 public constant BURNER_ROLE = keccak256("BURNER ROLE");
@@ -25,29 +27,24 @@ contract DeployScript is Script {
2527
address admin = vm.envAddress("ADMIN");
2628
bytes32 privateKey = vm.envBytes32("PRIVATE_KEY");
2729
string memory host = vm.envString("HOST");
28-
address uniRouter = vm.envAddress("UNISWAP_V2_ROUTER_02");
29-
if (uniRouter == address(0)) revert("UNISWAP_V2_ROUTER_02 unset");
30+
// todo:
31+
address uniRouter = address(1);
3032

3133
if (Strings.equal(host, "sepolia") || Strings.equal(host, "ethereum")) {
32-
vm.createSelectFork("sepolia");
3334
vm.startBroadcast(uint256(privateKey));
3435
deployGateway(SEPOLIA_HOST, admin, uniRouter);
35-
vm.stopBroadcast();
3636
} else if (Strings.equal(host, "arbitrum-sepolia")) {
37-
vm.createSelectFork("arbitrum-sepolia");
3837
vm.startBroadcast(uint256(privateKey));
3938
deployGateway(ARB_SEPOLIA_HOST, admin, uniRouter);
40-
vm.stopBroadcast();
4139
} else if (Strings.equal(host, "optimism-sepolia")) {
42-
vm.createSelectFork("optimism-sepolia");
4340
vm.startBroadcast(uint256(privateKey));
4441
deployGateway(OP_SEPOLIA_HOST, admin, uniRouter);
45-
vm.stopBroadcast();
4642
} else if (Strings.equal(host, "base-sepolia")) {
47-
vm.createSelectFork("base-sepolia");
4843
vm.startBroadcast(uint256(privateKey));
4944
deployGateway(BASE_SEPOLIA_HOST, admin, uniRouter);
50-
vm.stopBroadcast();
45+
} else if (Strings.equal(host, "bsc-testnet")) {
46+
vm.startBroadcast(uint256(privateKey));
47+
deployGateway(BSC_TESTNET_HOST, admin, uniRouter);
5148
}
5249
}
5350

@@ -57,14 +54,33 @@ contract DeployScript is Script {
5754
}
5855

5956
function deployGateway(address host, address admin, address uniRouter) public {
60-
ERC6160Ext20 t = new ERC6160Ext20{salt: salt}(admin, "Hyperbridge Test Token", "CORE");
57+
uint256 paraId = vm.envUint("PARA_ID");
58+
ERC6160Ext20 t = new ERC6160Ext20{salt: salt}(admin, "Hyperbridge USD", "USD.h");
6159

6260
TokenGateway gateway = new TokenGateway{salt: salt}(admin);
63-
gateway.initParams(host, uniRouter);
6461
t.grantRole(MINTER_ROLE, address(gateway));
6562
t.grantRole(BURNER_ROLE, address(gateway));
6663

6764
TokenFaucet faucet = new TokenFaucet{salt: salt}(address(t));
6865
t.grantRole(MINTER_ROLE, address(faucet));
66+
67+
Asset[] memory assets = new Asset[](1);
68+
assets[0] = Asset({
69+
localIdentifier: keccak256("USD.h"),
70+
foreignIdentifier: keccak256("USD.h"),
71+
erc20: address(0),
72+
erc6160: address(t)
73+
});
74+
75+
gateway.init(
76+
InitParams({
77+
hyperbridge: StateMachine.kusama(paraId),
78+
host: host,
79+
uniswapV2Router: uniRouter,
80+
protocolFeePercentage: 100, // 0.1
81+
relayerFeePercentage: 300, // 0.3
82+
assets: assets
83+
})
84+
);
6985
}
7086
}

0 commit comments

Comments
 (0)