Skip to content

Commit

Permalink
TokenGateway Tests (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege authored Feb 29, 2024
1 parent dffb69a commit d2d79ae
Show file tree
Hide file tree
Showing 30 changed files with 652 additions and 239 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions docs/pages/network/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ docker run polytopelabs/hyperbridge:latest --chain=messier
You can install a prebuilt binary for the hyperbridge node with the following bash script

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

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

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

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

::::

## Running the node
## Running the node (Rococo)

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.
This is fine because the rococo testnet has no economic value.

```bash
hyperbridge --chain=messier --enable-offchain-indexing --base-path=$HOME/.hyperbridge --pruning-archive
hyperbridge --chain=gargantua --base-path=$HOME/.hyperbridge --pruning-archive -- --sync=fast-unsafe
```

## Running the node (Kusama)

Hyperbridge also currently exists on Kusama with a chainId of `messier` and paraId of `3340`

```bash
hyperbridge --chain=messier --base-path=$HOME/.hyperbridge --pruning-archive
```
2 changes: 2 additions & 0 deletions docs/pages/network/relayer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ delivery_endpoints = [

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.

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.

You can find the up-to-date contract addresses for the `Handler` & `IsmpHost` contracts [here](/evm/integration#gargantua-v2)

### Withdrawing Fees
Expand Down
64 changes: 63 additions & 1 deletion evm/abi/src/generated/evm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ pub mod evm_host {
),
},],
constant: ::core::option::Option::None,
state_mutability: ::ethers::core::abi::ethabi::StateMutability::NonPayable,
state_mutability: ::ethers::core::abi::ethabi::StateMutability::View,
},],
),
(
Expand Down Expand Up @@ -542,6 +542,22 @@ pub mod evm_host {
state_mutability: ::ethers::core::abi::ethabi::StateMutability::View,
},],
),
(
::std::borrow::ToOwned::to_owned("perByteFee"),
::std::vec![::ethers::core::abi::ethabi::Function {
name: ::std::borrow::ToOwned::to_owned("perByteFee"),
inputs: ::std::vec![],
outputs: ::std::vec![::ethers::core::abi::ethabi::Param {
name: ::std::string::String::new(),
kind: ::ethers::core::abi::ethabi::ParamType::Uint(256usize,),
internal_type: ::core::option::Option::Some(
::std::borrow::ToOwned::to_owned("uint256"),
),
},],
constant: ::core::option::Option::None,
state_mutability: ::ethers::core::abi::ethabi::StateMutability::View,
},],
),
(
::std::borrow::ToOwned::to_owned("requestCommitments"),
::std::vec![::ethers::core::abi::ethabi::Function {
Expand Down Expand Up @@ -1397,6 +1413,14 @@ pub mod evm_host {
.method_hash([86, 182, 85, 151], ())
.expect("method not found (this should never happen)")
}
///Calls the contract's `perByteFee` (0x641d729d) function
pub fn per_byte_fee(
&self,
) -> ::ethers::contract::builders::ContractCall<M, ::ethers::core::types::U256> {
self.0
.method_hash([100, 29, 114, 157], ())
.expect("method not found (this should never happen)")
}
///Calls the contract's `requestCommitments` (0x368bf464) function
pub fn request_commitments(
&self,
Expand Down Expand Up @@ -2148,6 +2172,20 @@ pub mod evm_host {
)]
#[ethcall(name = "latestStateMachineHeight", abi = "latestStateMachineHeight()")]
pub struct LatestStateMachineHeightCall;
///Container type for all input parameters for the `perByteFee` function with signature
/// `perByteFee()` and selector `0x641d729d`
#[derive(
Clone,
::ethers::contract::EthCall,
::ethers::contract::EthDisplay,
Default,
Debug,
PartialEq,
Eq,
Hash,
)]
#[ethcall(name = "perByteFee", abi = "perByteFee()")]
pub struct PerByteFeeCall;
///Container type for all input parameters for the `requestCommitments` function with signature
/// `requestCommitments(bytes32)` and selector `0x368bf464`
#[derive(
Expand Down Expand Up @@ -2462,6 +2500,7 @@ pub mod evm_host {
Host(HostCall),
HostParams(HostParamsCall),
LatestStateMachineHeight(LatestStateMachineHeightCall),
PerByteFee(PerByteFeeCall),
RequestCommitments(RequestCommitmentsCall),
RequestReceipts(RequestReceiptsCall),
ResponseCommitments(ResponseCommitmentsCall),
Expand Down Expand Up @@ -2572,6 +2611,9 @@ pub mod evm_host {
{
return Ok(Self::LatestStateMachineHeight(decoded));
}
if let Ok(decoded) = <PerByteFeeCall as ::ethers::core::abi::AbiDecode>::decode(data) {
return Ok(Self::PerByteFee(decoded));
}
if let Ok(decoded) =
<RequestCommitmentsCall as ::ethers::core::abi::AbiDecode>::decode(data)
{
Expand Down Expand Up @@ -2687,6 +2729,7 @@ pub mod evm_host {
Self::HostParams(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::LatestStateMachineHeight(element) =>
::ethers::core::abi::AbiEncode::encode(element),
Self::PerByteFee(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::RequestCommitments(element) =>
::ethers::core::abi::AbiEncode::encode(element),
Self::RequestReceipts(element) => ::ethers::core::abi::AbiEncode::encode(element),
Expand Down Expand Up @@ -2741,6 +2784,7 @@ pub mod evm_host {
Self::Host(element) => ::core::fmt::Display::fmt(element, f),
Self::HostParams(element) => ::core::fmt::Display::fmt(element, f),
Self::LatestStateMachineHeight(element) => ::core::fmt::Display::fmt(element, f),
Self::PerByteFee(element) => ::core::fmt::Display::fmt(element, f),
Self::RequestCommitments(element) => ::core::fmt::Display::fmt(element, f),
Self::RequestReceipts(element) => ::core::fmt::Display::fmt(element, f),
Self::ResponseCommitments(element) => ::core::fmt::Display::fmt(element, f),
Expand Down Expand Up @@ -2865,6 +2909,11 @@ pub mod evm_host {
Self::LatestStateMachineHeight(value)
}
}
impl ::core::convert::From<PerByteFeeCall> for EvmHostCalls {
fn from(value: PerByteFeeCall) -> Self {
Self::PerByteFee(value)
}
}
impl ::core::convert::From<RequestCommitmentsCall> for EvmHostCalls {
fn from(value: RequestCommitmentsCall) -> Self {
Self::RequestCommitments(value)
Expand Down Expand Up @@ -3098,6 +3147,19 @@ pub mod evm_host {
Hash,
)]
pub struct LatestStateMachineHeightReturn(pub ::ethers::core::types::U256);
///Container type for all return fields from the `perByteFee` function with signature
/// `perByteFee()` and selector `0x641d729d`
#[derive(
Clone,
::ethers::contract::EthAbiType,
::ethers::contract::EthAbiCodec,
Default,
Debug,
PartialEq,
Eq,
Hash,
)]
pub struct PerByteFeeReturn(pub ::ethers::core::types::U256);
///Container type for all return fields from the `requestCommitments` function with signature
/// `requestCommitments(bytes32)` and selector `0x368bf464`
#[derive(
Expand Down
68 changes: 59 additions & 9 deletions evm/abi/src/generated/host_manager.rs

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions evm/abi/src/generated/ping_module.rs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions evm/examples/CrossChainMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ pragma solidity 0.8.17;

import "ismp/IIsmpModule.sol";
import "ismp/IIsmpHost.sol";
import "ismp/IIsmp.sol";
import "ismp/Message.sol";
import "ismp/IDispatcher.sol";

struct CrossChainMessage {
bytes dest;
Expand Down Expand Up @@ -58,7 +59,7 @@ contract CrossChainMessenger is IIsmpModule {
gaslimit: 0,
fee: 0
});
IIsmp(host).dispatch(post);
IDispatcher(host).dispatch(post);
}

function onAccept(PostRequest memory request) external onlyIsmpHost {
Expand Down
13 changes: 7 additions & 6 deletions evm/examples/PingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pragma solidity 0.8.17;
import "ismp/IIsmpModule.sol";
import "ismp/IIsmpHost.sol";
import "ismp/StateMachine.sol";
import "ismp/IIsmp.sol";
import "ismp/Message.sol";
import "ismp/IDispatcher.sol";

struct PingMessage {
bytes dest;
Expand Down Expand Up @@ -72,7 +73,7 @@ contract PingModule is IIsmpModule {
gaslimit: response.gaslimit,
fee: 0
});
IIsmp(_host).dispatch(post);
IDispatcher(_host).dispatch(post);
return response.hash();
}

Expand All @@ -85,7 +86,7 @@ contract PingModule is IIsmpModule {
gaslimit: request.gaslimit,
fee: 0
});
IIsmp(_host).dispatch(post);
IDispatcher(_host).dispatch(post);
return request.hash();
}

Expand All @@ -98,7 +99,7 @@ contract PingModule is IIsmpModule {
gaslimit: request.gaslimit,
fee: 0
});
IIsmp(_host).dispatch(get);
IDispatcher(_host).dispatch(get);
return request.hash();
}

Expand All @@ -115,7 +116,7 @@ contract PingModule is IIsmpModule {
gaslimit: 0,
fee: pingMessage.fee
});
IIsmp(_host).dispatch(post);
IDispatcher(_host).dispatch(post);
}
}

Expand All @@ -129,7 +130,7 @@ contract PingModule is IIsmpModule {
gaslimit: 0,
fee: 0
});
IIsmp(_host).dispatch(post);
IDispatcher(_host).dispatch(post);
}

function onAccept(PostRequest memory request) external onlyIsmpHost {
Expand Down
2 changes: 1 addition & 1 deletion evm/lib/ismp-solidity
52 changes: 34 additions & 18 deletions evm/script/DeployGateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import "forge-std/Script.sol";
import "openzeppelin/utils/Strings.sol";
import {ERC6160Ext20} from "ERC6160/tokens/ERC6160Ext20.sol";

import {TokenGateway} from "../src/modules/TokenGateway.sol";
import {TokenGateway, Asset, InitParams} from "../src/modules/TokenGateway.sol";
import {TokenFaucet} from "../src/modules/TokenFaucet.sol";
import {PingModule} from "../examples/PingModule.sol";
import {CrossChainMessenger} from "../examples/CrossChainMessenger.sol";
import {StateMachine} from "ismp/StateMachine.sol";

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

address public SEPOLIA_HOST = 0x5b5F63C8f3985CaFE1CE53E6374f42AB60dE5a6B;
address public ARB_SEPOLIA_HOST = 0x43E136611Cf74E165116a47e6F9C58AFCc80Ec54;
address public OP_SEPOLIA_HOST = 0x0124f458900FCd101c4CE31A9772fD2c5e6d65BF;
address public BASE_SEPOLIA_HOST = 0x87825f839d95c6021c0e821917F93aDB299eD6F8;
address public SEPOLIA_HOST = 0x9DF353352b469782AB1B0F2CbBFEC41bF1FDbDb3;
address public ARB_SEPOLIA_HOST = 0x424e6971EB1C693cf4296d4bdb42aa0F32a0dd9e;
address public OP_SEPOLIA_HOST = 0x1B58A47e61Ca7604b634CBB00b4e275cCd7c9E95;
address public BASE_SEPOLIA_HOST = 0x4c876500A13cc3825D343b5Ac791d3A4913bF14f;
address public BSC_TESTNET_HOST = 0x022DDE07A21d8c553978b006D93CDe68ac83e677;

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

if (Strings.equal(host, "sepolia") || Strings.equal(host, "ethereum")) {
vm.createSelectFork("sepolia");
vm.startBroadcast(uint256(privateKey));
deployGateway(SEPOLIA_HOST, admin, uniRouter);
vm.stopBroadcast();
} else if (Strings.equal(host, "arbitrum-sepolia")) {
vm.createSelectFork("arbitrum-sepolia");
vm.startBroadcast(uint256(privateKey));
deployGateway(ARB_SEPOLIA_HOST, admin, uniRouter);
vm.stopBroadcast();
} else if (Strings.equal(host, "optimism-sepolia")) {
vm.createSelectFork("optimism-sepolia");
vm.startBroadcast(uint256(privateKey));
deployGateway(OP_SEPOLIA_HOST, admin, uniRouter);
vm.stopBroadcast();
} else if (Strings.equal(host, "base-sepolia")) {
vm.createSelectFork("base-sepolia");
vm.startBroadcast(uint256(privateKey));
deployGateway(BASE_SEPOLIA_HOST, admin, uniRouter);
vm.stopBroadcast();
} else if (Strings.equal(host, "bsc-testnet")) {
vm.startBroadcast(uint256(privateKey));
deployGateway(BSC_TESTNET_HOST, admin, uniRouter);
}
}

Expand All @@ -57,14 +54,33 @@ contract DeployScript is Script {
}

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

TokenGateway gateway = new TokenGateway{salt: salt}(admin);
gateway.initParams(host, uniRouter);
t.grantRole(MINTER_ROLE, address(gateway));
t.grantRole(BURNER_ROLE, address(gateway));

TokenFaucet faucet = new TokenFaucet{salt: salt}(address(t));
t.grantRole(MINTER_ROLE, address(faucet));

Asset[] memory assets = new Asset[](1);
assets[0] = Asset({
localIdentifier: keccak256("USD.h"),
foreignIdentifier: keccak256("USD.h"),
erc20: address(0),
erc6160: address(t)
});

gateway.init(
InitParams({
hyperbridge: StateMachine.kusama(paraId),
host: host,
uniswapV2Router: uniRouter,
protocolFeePercentage: 100, // 0.1
relayerFeePercentage: 300, // 0.3
assets: assets
})
);
}
}
6 changes: 4 additions & 2 deletions evm/script/DeployIsmp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {RococoVerifier} from "../src/consensus/verifiers/RococoVerifier.sol";
import {ZkBeefyV1} from "../src/consensus/ZkBeefy.sol";
import {BeefyV1} from "../src/consensus/BeefyV1.sol";
import {GovernableToken} from "../src/modules/GovernableToken.sol";
import {StateMachine} from "ismp/StateMachine.sol";

contract DeployScript is Script {
using strings for *;
Expand All @@ -48,8 +49,9 @@ contract DeployScript is Script {
HandlerV1 handler = new HandlerV1{salt: salt}();

// Host manager
HostManagerParams memory gParams = HostManagerParams({admin: admin, host: address(0), paraId: paraId});
HostManager manager = new HostManager{salt: salt}(gParams);
HostManager manager = new HostManager{salt: salt}(
HostManagerParams({admin: admin, host: address(0), hyperbridge: StateMachine.kusama(paraId)})
);

// EvmHost
HostParams memory params = HostParams({
Expand Down
Loading

0 comments on commit d2d79ae

Please sign in to comment.