Skip to content

Commit

Permalink
Simplify fee model (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
casweeney authored Apr 13, 2024
1 parent f481e35 commit c122b1d
Show file tree
Hide file tree
Showing 30 changed files with 874 additions and 1,518 deletions.
76 changes: 38 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ on:
branches:
- main
pull_request_target:
types: [opened, synchronize]
types: [ opened, synchronize ]
pull_request:
branches:
- main

concurrency:
group: ci-${{ github.head_ref || github.ref_name }}
Expand All @@ -31,7 +34,7 @@ jobs:
if: github.event.pull_request.draft == false
strategy:
matrix:
crate: [messier-runtime, gargantua-runtime, nexus-runtime]
crate: [ messier-runtime, gargantua-runtime, nexus-runtime ]

steps:
- name: Get User Permission
Expand Down Expand Up @@ -255,39 +258,36 @@ jobs:

- uses: Swatinem/rust-cache@v2

- name: Run Parachain Devnet
run: |
# install polkadot binary
cd ../
mkdir -p polkadot-sdk/target/release
wget -O ./polkadot.tar.gz -q --show-progress 'https://dl.dropbox.com/scl/fi/onsvsex4w9vf5vghqe23j/polkadot.tar.gz?rlkey=17e3gq0n82v8hhar4nzlynruu&dl=0'
tar xvzf ./polkadot.tar.gz
mv bins/* polkadot-sdk/target/release
ls -la polkadot-sdk/target/release
# install hyperbridge binary
cd hyperbridge
# todo: revert after next release
cargo build -p hyperbridge --release
# mkdir -p target/release
# wget -q --show-progress https://github.com/polytope-labs/hyperbridge/releases/download/v0.2.0/hyperbridge-x86_64-unknown-linux-gnu.tar.gz
# tar xvzf ./hyperbridge-x86_64-unknown-linux-gnu.tar.gz
# mv ./hyperbridge-x86_64-unknown-linux-gnu/hyperbridge target/release
# install zombienet
wget -O ./zombienet -q --show-progress https://github.com/paritytech/zombienet/releases/download/v1.3.89/zombienet-linux-x64
sudo chmod +x ./zombienet
# spawn devnet
nohup ./zombienet spawn --provider native ./local-testnet.toml & disown
../wait_for_tcp_port_opening.sh localhost 9922
../wait_for_tcp_port_opening.sh localhost 9990
# - name: Beefy integration tests
# run: |
# cargo test -p ismp-solidity-tests -- --nocapture --ignored

- name: Xcm integration tests
run: |
cargo test -p pallet-ismp-testsuite --lib xcm_integration_test --features runtime-benchmarks -- --nocapture --ignored
- name: Run Parachain Devnet
run: |
# install polkadot binary
cd ../
mkdir -p polkadot-sdk/target/release
wget -O ./polkadot.tar.gz -q --show-progress 'https://dl.dropbox.com/scl/fi/onsvsex4w9vf5vghqe23j/polkadot.tar.gz?rlkey=17e3gq0n82v8hhar4nzlynruu&dl=0'
tar xvzf ./polkadot.tar.gz
mv bins/* polkadot-sdk/target/release
ls -la polkadot-sdk/target/release
# build hyperbridge binary
cd hyperbridge
cargo build -p hyperbridge --release
# install zombienet
wget -O ./zombienet -q --show-progress https://github.com/paritytech/zombienet/releases/download/v1.3.89/zombienet-linux-x64
sudo chmod +x ./zombienet
# spawn devnet
nohup ./zombienet spawn --provider native ./scripts/zombienet/local-testnet.toml & disown
./scripts/wait_for_tcp_port_opening.sh localhost 9922
./scripts/wait_for_tcp_port_opening.sh localhost 9990
# - name: Beefy integration tests
# run: |
# cargo test -p ismp-solidity-tests -- --nocapture --ignored

- name: Xcm integration tests
run: |
cargo test -p pallet-ismp-testsuite --lib xcm_integration_test --features runtime-benchmarks -- --nocapture --ignored
- name: Run Eth POS Devnet
run: |
Expand All @@ -301,9 +301,9 @@ jobs:
run: |
cargo test -p sync-committee-prover -- --nocapture --ignored
# - name: polygon pos integration tests
# run: |
# cargo test -p polygon-pos-prover -- --nocapture --ignored
# - name: polygon pos integration tests
# run: |
# cargo test -p polygon-pos-prover -- --nocapture --ignored

- name: Binance Smart Chain integration tests
run: |
Expand Down
864 changes: 341 additions & 523 deletions evm/abi/src/generated/evm_host.rs

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions evm/abi/src/generated/host_manager.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions evm/abi/src/generated/ping_module.rs

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions evm/examples/PingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "ismp/IIsmpHost.sol";
import "ismp/StateMachine.sol";
import "ismp/Message.sol";
import "ismp/IDispatcher.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";

struct PingMessage {
bytes dest;
Expand Down Expand Up @@ -77,6 +78,9 @@ contract PingModule is IIsmpModule {
}

function dispatch(PostRequest memory request) public returns (bytes32) {
uint256 perByteFee = IIsmpHost(_host).perByteFee();
IERC20(IIsmpHost(_host).feeToken()).transferFrom(msg.sender, address(this), perByteFee * request.body.length);

DispatchPost memory post = DispatchPost({
body: request.body,
dest: request.dest,
Expand All @@ -95,8 +99,7 @@ contract PingModule is IIsmpModule {
height: request.height,
keys: request.keys,
timeout: request.timeoutTimestamp,
fee: 0,
payer: tx.origin
sender: msg.sender
});

return IDispatcher(_host).dispatch(get);
Expand Down
3 changes: 3 additions & 0 deletions evm/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
src = "src"
out = "out"
libs = ["lib"]
solc-version = "0.8.17"
optimizer = true
#via-ir = true

[rpc_endpoints]
sepolia = "${SEPOLIA_RPC_URL}"
Expand Down
2 changes: 1 addition & 1 deletion evm/integration-tests/src/tests/get_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn test_get_response() -> Result<(), anyhow::Error> {
let (root, proof) = generate_proof(request_commitment, key.clone());

// create intermediate state
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(1) };
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(10) };
let consensus_proof = IntermediateState {
state_machine_id: height.state_machine_id,
height: height.height,
Expand Down
13 changes: 6 additions & 7 deletions evm/integration-tests/src/tests/host_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn test_host_manager_withdraw() -> Result<(), anyhow::Error> {

// create post request object
let post = Post {
source: StateMachine::Kusama(2000),
source: StateMachine::Polkadot(2000),
dest: StateMachine::Ethereum(Ethereum::ExecutionLayer),
nonce: 0,
from: contract.runner.sender.as_bytes().to_vec(),
Expand Down Expand Up @@ -56,7 +56,7 @@ async fn test_host_manager_unauthorized_request() -> Result<(), anyhow::Error> {
// create post request object
let post = Post {
// wrong source
source: StateMachine::Polkadot(2000),
source: StateMachine::Polkadot(1000),
dest: StateMachine::Ethereum(Ethereum::ExecutionLayer),
nonce: 0,
from: contract.runner.sender.as_bytes().to_vec(),
Expand All @@ -69,7 +69,7 @@ async fn test_host_manager_unauthorized_request() -> Result<(), anyhow::Error> {

// execute the test
let EvmError::Execution(error) = contract
.call::<_, ()>("HostManagerUnauthorizedRequest", (request.into_token(),))
.call::<_, ()>("HostManagerOnAccept", (request.into_token(),))
.await
.unwrap_err()
else {
Expand All @@ -95,8 +95,7 @@ async fn test_host_manager_insufficient_balance() -> Result<(), anyhow::Error> {

// create post request object
let post = Post {
// wrong source
source: StateMachine::Kusama(2000),
source: StateMachine::Polkadot(2000),
dest: StateMachine::Ethereum(Ethereum::ExecutionLayer),
nonce: 0,
from: contract.runner.sender.as_bytes().to_vec(),
Expand All @@ -109,7 +108,7 @@ async fn test_host_manager_insufficient_balance() -> Result<(), anyhow::Error> {

// execute the test
let EvmError::Execution(error) = contract
.call::<_, ()>("HostManagerUnauthorizedRequest", (request.into_token(),))
.call::<_, ()>("HostManagerOnAccept", (request.into_token(),))
.await
.unwrap_err()
else {
Expand All @@ -133,7 +132,7 @@ async fn test_host_manager_set_host_params() -> Result<(), anyhow::Error> {

// create post request object
let post = Post {
source: StateMachine::Kusama(2000),
source: StateMachine::Polkadot(2000),
dest: StateMachine::Ethereum(Ethereum::ExecutionLayer),
nonce: 0,
from: contract.runner.sender.as_bytes().to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion evm/integration-tests/src/tests/post_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn test_post_request_proof() -> Result<(), anyhow::Error> {
data: vec![],
};
let request = DataOrHash::Data(Leaf::Request(Request::Post(post.clone())));
let (overlay_root, proof, k_index) = initialize_mmr_tree(request, 1)?;
let (overlay_root, proof, k_index) = initialize_mmr_tree(request, 10)?;

// create intermediate state
let consensus_proof = IntermediateState {
Expand Down
10 changes: 5 additions & 5 deletions evm/integration-tests/src/tests/post_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn test_post_response_proof() -> Result<(), anyhow::Error> {
let multiproof = proof.proof_items().iter().map(|h| h.hash::<Keccak256>().0).collect();

// create intermediate state
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(1) };
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(10) };
let consensus_proof = IntermediateState {
state_machine_id: height.state_machine_id,
height: height.height,
Expand Down Expand Up @@ -123,7 +123,7 @@ async fn test_post_response_timeout() -> Result<(), anyhow::Error> {
data: vec![],
};
let request = DataOrHash::Data(Leaf::Request(Request::Post(post.clone())));
let (overlay_root, proof, k_index) = initialize_mmr_tree(request, 1)?;
let (overlay_root, proof, k_index) = initialize_mmr_tree(request, 10)?;

// create intermediate state 1
let consensus_proof_1 = IntermediateState {
Expand Down Expand Up @@ -155,7 +155,7 @@ async fn test_post_response_timeout() -> Result<(), anyhow::Error> {
utils::generate_non_membership_proof(storage_prefix, vec![key.clone()], false);

// create intermediate state
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(2) };
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(20) };
let consensus_proof_2 = IntermediateState {
state_machine_id: height.state_machine_id,
height: height.height,
Expand Down Expand Up @@ -212,7 +212,7 @@ async fn test_post_response_malicious_timeout() -> Result<(), anyhow::Error> {
data: vec![],
};
let request = DataOrHash::Data(Leaf::Request(Request::Post(post.clone())));
let (overlay_root, proof, k_index) = initialize_mmr_tree(request, 1)?;
let (overlay_root, proof, k_index) = initialize_mmr_tree(request, 10)?;

// create intermediate state 1
let consensus_proof_1 = IntermediateState {
Expand Down Expand Up @@ -244,7 +244,7 @@ async fn test_post_response_malicious_timeout() -> Result<(), anyhow::Error> {
utils::generate_non_membership_proof(storage_prefix, vec![key.clone()], true);

// create intermediate state
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(2) };
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(20) };
let consensus_proof_2 = IntermediateState {
state_machine_id: height.state_machine_id,
height: height.height,
Expand Down
2 changes: 1 addition & 1 deletion evm/integration-tests/src/tests/post_timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn test_post_timeout_proof() -> Result<(), anyhow::Error> {
assert!(result.get(&key).unwrap().is_none());

// create intermediate state
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(1) };
let height = StateMachineHeight { state_machine_id: U256::from(2000), height: U256::from(10) };
let consensus_proof = IntermediateState {
state_machine_id: height.state_machine_id,
height: height.height,
Expand Down
2 changes: 1 addition & 1 deletion evm/lib/ismp-solidity
30 changes: 20 additions & 10 deletions evm/script/DeployGateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import "forge-std/Script.sol";
import "openzeppelin/utils/Strings.sol";
import {ERC6160Ext20} from "ERC6160/tokens/ERC6160Ext20.sol";

import {TokenGateway, Asset, InitParams} from "../src/modules/TokenGateway.sol";
import {
TokenGateway, Asset, TokenGatewayParamsExt, TokenGatewayParams, AssetFees
} from "../src/modules/TokenGateway.sol";
import {TokenFaucet} from "../src/modules/TokenFaucet.sol";
import {PingModule} from "../examples/PingModule.sol";
import {CrossChainMessenger} from "../examples/CrossChainMessenger.sol";
Expand Down Expand Up @@ -69,17 +71,25 @@ contract DeployScript is Script {
feeToken.grantRole(BURNER_ROLE, address(gateway));

Asset[] memory assets = new Asset[](1);
assets[0] = Asset({identifier: keccak256("USD.h"), erc20: address(0), erc6160: address(feeToken)});
assets[0] = Asset({
identifier: keccak256("USD.h"),
erc20: address(0),
erc6160: address(feeToken),
fees: AssetFees({
protocolFeePercentage: 100, // 0.1
relayerFeePercentage: 300 // 0.3
})
});

gateway.init(
InitParams({
hyperbridge: StateMachine.kusama(paraId),
host: host,
uniswapV2Router: uniRouter,
protocolFeePercentage: 100, // 0.1
relayerFeePercentage: 300, // 0.3
assets: assets,
callDispatcher: callDispatcher
TokenGatewayParamsExt({
params: TokenGatewayParams({
hyperbridge: StateMachine.kusama(paraId),
host: host,
uniswapV2: uniRouter,
dispatcher: callDispatcher
}),
assets: assets
})
);
}
Expand Down
42 changes: 27 additions & 15 deletions evm/script/DeployIsmp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import "../src/hosts/Optimism.sol";
import "../src/hosts/Base.sol";

import {ERC6160Ext20} from "ERC6160/tokens/ERC6160Ext20.sol";
import {TokenGateway, Asset, InitParams} from "../src/modules/TokenGateway.sol";
import {
TokenGateway, Asset, TokenGatewayParamsExt, TokenGatewayParams, AssetFees
} from "../src/modules/TokenGateway.sol";
import {TokenFaucet} from "../src/modules/TokenFaucet.sol";

import {PingModule} from "../examples/PingModule.sol";
Expand Down Expand Up @@ -56,7 +58,10 @@ contract DeployScript is Script {
HandlerV1 handler = new HandlerV1{salt: salt}();

// Host manager
HostManager manager = new HostManager{salt: salt}(HostManagerParams({admin: admin, host: address(0)}));
HostManager manager =
new HostManager{salt: salt}(HostManagerParams({admin: admin, host: address(0), governorStateMachineId : paraId}));
uint256[] memory stateMachineWhitelist = new uint256[](1);
stateMachineWhitelist[0] = paraId;

// EvmHost
HostParams memory params = HostParams({
Expand All @@ -70,13 +75,12 @@ contract DeployScript is Script {
// for this test
challengePeriod: 0,
consensusClient: address(consensusClient),
lastUpdated: 0,
consensusUpdateTimestamp: 0,
consensusState: new bytes(0),
baseGetRequestFee: 5 * 1e17, // $0.50
perByteFee: 3 * 1e15, // $0.003/byte
feeTokenAddress: address(feeToken),
feeToken: address(feeToken),
latestStateMachineHeight: 0,
hyperbridge: StateMachine.kusama(paraId)
stateMachineWhitelist: stateMachineWhitelist
});

address hostAddress = initHost(params);
Expand Down Expand Up @@ -130,18 +134,26 @@ contract DeployScript is Script {
feeToken.grantRole(MINTER_ROLE, address(faucet));

Asset[] memory assets = new Asset[](1);
assets[0] = Asset({identifier: keccak256("USD.h"), erc20: address(0), erc6160: address(feeToken)});
assets[0] = Asset({
identifier: keccak256("USD.h"),
erc20: address(0),
erc6160: address(feeToken),
fees: AssetFees({
protocolFeePercentage: 100, // 0.1
relayerFeePercentage: 300 // 0.3
})
});

// initialize gateway
gateway.init(
InitParams({
hyperbridge: StateMachine.kusama(paraId),
host: hostAddress,
uniswapV2Router: address(1),
protocolFeePercentage: 100, // 0.1
relayerFeePercentage: 300, // 0.3
assets: assets,
callDispatcher: dispatcher
TokenGatewayParamsExt({
params: TokenGatewayParams({
hyperbridge: StateMachine.kusama(paraId),
host: hostAddress,
uniswapV2: address(1),
dispatcher: dispatcher
}),
assets: assets
})
);
}
Expand Down
Loading

0 comments on commit c122b1d

Please sign in to comment.