Skip to content

Commit

Permalink
ISMP: Code freeze (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Aug 24, 2024
1 parent c12431c commit 558e0b9
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 441 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.

60 changes: 30 additions & 30 deletions docs/pages/developers/evm/contract-addresses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,57 @@ The current testnet environment for the Hyperbridge network.

### Ethereum Sepolia

| `IsmpHost` | [`0xF1c7a386325B7D22025D7542b28Ee881Cdf107b3`](https://sepolia.etherscan.io/address/0xF1c7a386325B7D22025D7542b28Ee881Cdf107b3) |
| `IsmpHost` | [`0x27B0c6960B792a8dCb01F0652bDE48015cd5f23e`](https://sepolia.etherscan.io/address/0x27B0c6960B792a8dCb01F0652bDE48015cd5f23e) |
|:------------|:-----|
| `HandlerV1` | [`0xeb1359a98765F7B46FAc4ef56A3f2514891f46Ee`](https://sepolia.etherscan.io/address/0xeb1359a98765F7B46FAc4ef56A3f2514891f46Ee) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia.etherscan.io/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia.etherscan.io/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia.etherscan.io/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia.etherscan.io/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
| `HandlerV1` | [`0xb8b5F80f6f58975970d9A5fb99407CF60A8FD3Ff`](https://sepolia.etherscan.io/address/0xb8b5F80f6f58975970d9A5fb99407CF60A8FD3Ff) |
| `PingModule` | [`0x42C6551d05eA47c46Fc7B01BBaaD37c466481361`](https://sepolia.etherscan.io/address/0x42C6551d05eA47c46Fc7B01BBaaD37c466481361) |
| `TokenGateway` | [`0x43B220ae10D0378f974af7F8E46326f9F7cF2cee`](https://sepolia.etherscan.io/address/0x43B220ae10D0378f974af7F8E46326f9F7cF2cee) |
| `TokenFaucet` | [`0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1`](https://sepolia.etherscan.io/address/0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1) |
| `FeeToken (USD.h)` | [`0x088f5218efbDfC73992b0906c5d35572DB2db845`](https://sepolia.etherscan.io/address/0x088f5218efbDfC73992b0906c5d35572DB2db845) |

### Arbitrum Sepolia


| `IsmpHost` | [`0x286e1FE1c323EE626bE802b13a5184b588eD14Cb`](https://sepolia.arbiscan.io/address/0x286e1FE1c323EE626bE802b13a5184b588eD14Cb) |
| `IsmpHost` | [`0xfd7E2b2ad0b29Ec817dC7d406881b225B81dbFCf`](https://sepolia.arbiscan.io/address/0xfd7E2b2ad0b29Ec817dC7d406881b225B81dbFCf) |
|:------------|:-----|
| `HandlerV1` | [`0x13c4e685DF2Bba9d2006db70F44d93bAE246Ea76`](https://sepolia.arbiscan.io/address/0x13c4e685DF2Bba9d2006db70F44d93bAE246Ea76) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia.arbiscan.io/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia.arbiscan.io/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia.arbiscan.io/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia.arbiscan.io/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
| `HandlerV1` | [`0xBCb07384915818F6E2fEA3d0e3c19EFa5bef823A`](https://sepolia.arbiscan.io/address/0xBCb07384915818F6E2fEA3d0e3c19EFa5bef823A) |
| `PingModule` | [`0x42C6551d05eA47c46Fc7B01BBaaD37c466481361`](https://sepolia.arbiscan.io/address/0x42C6551d05eA47c46Fc7B01BBaaD37c466481361) |
| `TokenGateway` | [`0x43B220ae10D0378f974af7F8E46326f9F7cF2cee`](https://sepolia.arbiscan.io/address/0x43B220ae10D0378f974af7F8E46326f9F7cF2cee) |
| `TokenFaucet` | [`0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1`](https://sepolia.arbiscan.io/address/0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1) |
| `FeeToken (USD.h)` | [`0x088f5218efbDfC73992b0906c5d35572DB2db845`](https://sepolia.arbiscan.io/address/0x088f5218efbDfC73992b0906c5d35572DB2db845) |

### Optimism Sepolia


| `IsmpHost` | [`0x625c531a56DB772CC36313d0A0114956aD8b56c2`](https://sepolia-optimism.etherscan.io/address/0x625c531a56DB772CC36313d0A0114956aD8b56c2) |
| `IsmpHost` | [`0x30e3af1747B155F37F935E0EC995De5EA4e67586`](https://sepolia-optimism.etherscan.io/address/0x30e3af1747B155F37F935E0EC995De5EA4e67586) |
|:------------|:-----|
| `HandlerV1` | [`0xd5cB7a7971Ec9455B90F65ee1d941D4e5b5e1ff0`](https://sepolia-optimism.etherscan.io/address/0xd5cB7a7971Ec9455B90F65ee1d941D4e5b5e1ff0) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia-optimism.etherscan.io/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia-optimism.etherscan.io/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia-optimism.etherscan.io/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia-optimism.etherscan.io/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
| `HandlerV1` | [`0x78ba8ea54a141b0f6e43070Bb9F9a303F7E05689`](https://sepolia-optimism.etherscan.io/address/0x78ba8ea54a141b0f6e43070Bb9F9a303F7E05689) |
| `PingModule` | [`0x42C6551d05eA47c46Fc7B01BBaaD37c466481361`](https://sepolia-optimism.etherscan.io/address/0x42C6551d05eA47c46Fc7B01BBaaD37c466481361) |
| `TokenGateway` | [`0x43B220ae10D0378f974af7F8E46326f9F7cF2cee`](https://sepolia-optimism.etherscan.io/address/0x43B220ae10D0378f974af7F8E46326f9F7cF2cee) |
| `TokenFaucet` | [`0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1`](https://sepolia-optimism.etherscan.io/address/0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1) |
| `FeeToken (USD.h)` | [`0x088f5218efbDfC73992b0906c5d35572DB2db845`](https://sepolia-optimism.etherscan.io/address/0x088f5218efbDfC73992b0906c5d35572DB2db845) |

### Base Sepolia


| `IsmpHost` | [`0xae9f490EE05588fDD857A078cFC1f5f30ae7185f`](https://sepolia.basescan.org/address/0xae9f490EE05588fDD857A078cFC1f5f30ae7185f) |
| `IsmpHost` | [`0x0D7037bd9CEAEF25e5215f808d309ADD0A65Cdb9`](https://sepolia.basescan.org/address/0x0D7037bd9CEAEF25e5215f808d309ADD0A65Cdb9) |
|:------------|:-----|
| `HandlerV1` | [`0x2C00a1A42666d42F981E19b633c8d0198149ed36`](https://sepolia.basescan.org/address/0x2C00a1A42666d42F981E19b633c8d0198149ed36) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia.basescan.org/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia.basescan.org/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia.basescan.org/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia.basescan.org/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
| `HandlerV1` | [`0x146662aF74f7332Ef3D91826B2F6DaCBf4459dB4`](https://sepolia.basescan.org/address/0x146662aF74f7332Ef3D91826B2F6DaCBf4459dB4) |
| `PingModule` | [`0x42C6551d05eA47c46Fc7B01BBaaD37c466481361`](https://sepolia.basescan.org/address/0x42C6551d05eA47c46Fc7B01BBaaD37c466481361) |
| `TokenGateway` | [`0x43B220ae10D0378f974af7F8E46326f9F7cF2cee`](https://sepolia.basescan.org/address/0x43B220ae10D0378f974af7F8E46326f9F7cF2cee) |
| `TokenFaucet` | [`0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1`](https://sepolia.basescan.org/address/0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1) |
| `FeeToken (USD.h)` | [`0x088f5218efbDfC73992b0906c5d35572DB2db845`](https://sepolia.basescan.org/address/0x088f5218efbDfC73992b0906c5d35572DB2db845) |

### Bsc Testnet


| `IsmpHost` | [`0xeB8977EDCdA5FaBDcDdEB39861Df25E8821a9e9b`](https://testnet.bscscan.com/address/0xeB8977EDCdA5FaBDcDdEB39861Df25E8821a9e9b) |
| `IsmpHost` | [`0x4cB0f5750f6fE14d4B86acA6fe126943bdA3c8c4`](https://testnet.bscscan.com/address/0x4cB0f5750f6fE14d4B86acA6fe126943bdA3c8c4) |
|:------------|:-----|
| `HandlerV1` | [`0x5A8B2dA2994dD818c6C3329E2c1d7cc52C863723`](https://testnet.bscscan.com/address/0x5A8B2dA2994dD818c6C3329E2c1d7cc52C863723) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://testnet.bscscan.com/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://testnet.bscscan.com/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://testnet.bscscan.com/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://testnet.bscscan.com/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
| `HandlerV1` | [`0x648e59B610630D06cdf5eBCb775b2d33f6BAbBb0`](https://testnet.bscscan.com/address/0x648e59B610630D06cdf5eBCb775b2d33f6BAbBb0) |
| `PingModule` | [`0x42C6551d05eA47c46Fc7B01BBaaD37c466481361`](https://testnet.bscscan.com/address/0x42C6551d05eA47c46Fc7B01BBaaD37c466481361) |
| `TokenGateway` | [`0x43B220ae10D0378f974af7F8E46326f9F7cF2cee`](https://testnet.bscscan.com/address/0x43B220ae10D0378f974af7F8E46326f9F7cF2cee) |
| `TokenFaucet` | [`0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1`](https://testnet.bscscan.com/address/0x6Ced0D49EBfe3dee51ccBE744464d18cbf549Ef1) |
| `FeeToken (USD.h)` | [`0x088f5218efbDfC73992b0906c5d35572DB2db845`](https://testnet.bscscan.com/address/0x088f5218efbDfC73992b0906c5d35572DB2db845) |

## Gargantua V2 (Paseo) (Deprecated)

Expand Down
37 changes: 24 additions & 13 deletions evm/abi/src/generated/ping_module.rs

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions evm/examples/PingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ struct PingMessage {
uint256 fee;
}

interface ITokenFaucet {
// drips the feeToken once per day
function drip(address) external;
}

contract PingModule is IIsmpModule {
using Message for PostResponse;
using Message for PostRequest;
Expand Down Expand Up @@ -59,7 +64,13 @@ contract PingModule is IIsmpModule {
_admin = admin;
}

function setIsmpHost(address hostAddr) public onlyAdmin {
function setIsmpHost(address hostAddr, address tokenFaucet) public onlyAdmin {
address feeToken = IIsmpHost(hostAddr).feeToken();
IERC20(feeToken).approve(hostAddr, type(uint256).max);
if (tokenFaucet != address(0)) {
ITokenFaucet(tokenFaucet).drip(feeToken);
}

_host = hostAddr;
}

Expand All @@ -79,7 +90,6 @@ contract PingModule is IIsmpModule {
uint256 fee = perByteFee * length;

IERC20(feeToken).transferFrom(msg.sender, address(this), fee);
IERC20(feeToken).approve(_host, fee);
DispatchPostResponse memory post = DispatchPostResponse({
request: response.request,
response: response.response,
Expand All @@ -97,8 +107,6 @@ contract PingModule is IIsmpModule {
uint256 fee = perByteFee * length;

IERC20(feeToken).transferFrom(msg.sender, address(this), fee);
IERC20(feeToken).approve(_host, fee);

DispatchPost memory post = DispatchPost({
body: request.body,
dest: request.dest,
Expand Down Expand Up @@ -132,7 +140,6 @@ contract PingModule is IIsmpModule {
uint256 fee = (pingMessage.fee + (perByteFee * length)) * pingMessage.count;

IERC20(feeToken).transferFrom(msg.sender, address(this), fee);
IERC20(feeToken).approve(_host, fee);

for (uint256 i = 0; i < pingMessage.count; i++) {
DispatchPost memory post = DispatchPost({
Expand Down
8 changes: 4 additions & 4 deletions evm/script/DeployIsmp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ contract DeployScript is BaseScript {
// set the host address on the host manager
manager.setIsmpHost(hostAddress);

// deploy the ping module as well
PingModule module = new PingModule{salt: salt}(admin);
module.setIsmpHost(hostAddress);

// deploy the call dispatcher
CallDispatcher dispatcher = new CallDispatcher{salt: salt}();

Expand Down Expand Up @@ -133,6 +129,10 @@ contract DeployScript is BaseScript {
TokenFaucet faucet = new TokenFaucet{salt: salt}();
feeToken.grantRole(MINTER_ROLE, address(faucet));

// deploy the ping module as well
PingModule module = new PingModule{salt: salt}(admin);
module.setIsmpHost(hostAddress, address(faucet));

AssetMetadata[] memory assets = new AssetMetadata[](1);
assets[0] = AssetMetadata({
erc20: address(0),
Expand Down
11 changes: 6 additions & 5 deletions evm/script/DeployPing.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ import {BaseScript} from "./BaseScript.sol";
contract DeployScript is BaseScript {
function run() external {
address admin = vm.envAddress("ADMIN");
address tokenFaucet = vm.envAddress("TOKEN_FAUCET");
bytes32 privateKey = vm.envBytes32("PRIVATE_KEY");
string memory host = vm.envString("HOST");

vm.startBroadcast(uint256(privateKey));
PingModule ping = new PingModule{salt: salt}(admin);

if (equal(host, "sepolia") || equal(host, "ethereum")) {
ping.setIsmpHost(SEPOLIA_HOST);
ping.setIsmpHost(SEPOLIA_HOST, tokenFaucet);
} else if (equal(host, "arbitrum-sepolia")) {
ping.setIsmpHost(ARB_SEPOLIA_HOST);
ping.setIsmpHost(ARB_SEPOLIA_HOST, tokenFaucet);
} else if (equal(host, "optimism-sepolia")) {
ping.setIsmpHost(OP_SEPOLIA_HOST);
ping.setIsmpHost(OP_SEPOLIA_HOST, tokenFaucet);
} else if (equal(host, "base-sepolia")) {
ping.setIsmpHost(BASE_SEPOLIA_HOST);
ping.setIsmpHost(BASE_SEPOLIA_HOST, tokenFaucet);
} else if (equal(host, "bsc-testnet")) {
ping.setIsmpHost(BSC_TESTNET_HOST);
ping.setIsmpHost(BSC_TESTNET_HOST, tokenFaucet);
}
vm.stopBroadcast();
}
Expand Down
8 changes: 8 additions & 0 deletions evm/script/batchDeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

declare -a arr=("sepolia" "arbitrum-sepolia" "optimism-sepolia" "base-sepolia" "bsc-testnet")

for i in "${arr[@]}"
do
"$(pwd)/script/deploy.sh" "$i" $1
done
11 changes: 10 additions & 1 deletion evm/test/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {ERC6160Ext20} from "@polytope-labs/erc6160/tokens/ERC6160Ext20.sol";
import {StateMachine} from "@polytope-labs/ismp-solidity/StateMachine.sol";
import {ERC20Token} from "./mocks/ERC20Token.sol";
import {MiniStaking} from "./mocks/MiniStakingContract.sol";
import {TokenFaucet} from "../src/modules/TokenFaucet.sol";

contract BaseTest is Test {
/// @notice The Id of Role required to mint token
Expand Down Expand Up @@ -89,8 +90,16 @@ contract BaseTest is Test {
});
host = new TestHost(params);

// and token faucet
TokenFaucet faucet = new TokenFaucet();
feeToken.grantRole(MINTER_ROLE, address(faucet));

testModule = new PingModule(address(this));
testModule.setIsmpHost(address(host));
uint256 oldTime = block.timestamp;
vm.warp(100_000);
testModule.setIsmpHost(address(host), address(faucet));
vm.warp(oldTime);

manager.setIsmpHost(address(host));
gateway = new TokenGateway(address(this));

Expand Down
3 changes: 2 additions & 1 deletion evm/test/MainnetForkBaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {StateMachine} from "@polytope-labs/ismp-solidity/StateMachine.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "../src/modules/TokenGateway.sol";
import {TokenFaucet} from "../src/modules/TokenFaucet.sol";

contract MainnetForkBaseTest is Test {
/// @notice The Id of Role required to mint token
Expand Down Expand Up @@ -99,7 +100,7 @@ contract MainnetForkBaseTest is Test {
host = new TestHost(params);

testModule = new PingModule(address(this));
testModule.setIsmpHost(address(host));
testModule.setIsmpHost(address(host), address(0));
manager.setIsmpHost(address(host));
gateway = new TokenGateway(address(this));
AssetMetadata[] memory assets = new AssetMetadata[](2);
Expand Down
2 changes: 1 addition & 1 deletion modules/hyperclient/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@polytope-labs/hyperclient",
"description": "The hyperclient is a library for managing (in-flight) ISMP requests",
"version": "0.4.3",
"version": "0.5.0",
"author": "Polytope Labs ([email protected])",
"license": "Apache-2.0",
"bugs": {
Expand Down
8 changes: 4 additions & 4 deletions modules/hyperclient/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ use ismp_solidity_abi::{
};
use std::sync::Arc;

const OP_HOST: H160 = H160(hex!("625c531a56DB772CC36313d0A0114956aD8b56c2"));
const SEPOLIA_HOST: H160 = H160(hex!("F1c7a386325B7D22025D7542b28Ee881Cdf107b3"));
const BSC_HOST: H160 = H160(hex!("eB8977EDCdA5FaBDcDdEB39861Df25E8821a9e9b"));
const PING_MODULE: H160 = H160(hex!("0A7175d240fe71C8AEa0D1D7467bF03C6E217C50"));
const OP_HOST: H160 = H160(hex!("30e3af1747B155F37F935E0EC995De5EA4e67586"));
const SEPOLIA_HOST: H160 = H160(hex!("27B0c6960B792a8dCb01F0652bDE48015cd5f23e"));
const BSC_HOST: H160 = H160(hex!("4cB0f5750f6fE14d4B86acA6fe126943bdA3c8c4"));
const PING_MODULE: H160 = H160(hex!("42C6551d05eA47c46Fc7B01BBaaD37c466481361"));

pub async fn subscribe_to_request_status() -> Result<(), anyhow::Error> {
tracing::info!("\n\n\n\nStarting request status subscription\n\n\n\n");
Expand Down
44 changes: 15 additions & 29 deletions modules/ismp/core/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,11 @@ pub enum StateMachine {
/// Kusama parachains
#[codec(index = 2)]
Kusama(u32),
/// We identify standalone state machines by their consensus state
/// Substrate-based standalone chain
#[codec(index = 3)]
Grandpa(ConsensusStateId),
/// State machines chains running on beefy consensus state
#[codec(index = 4)]
Beefy(ConsensusStateId),
#[codec(index = 5)]
Substrate(ConsensusStateId),
/// Tendermint chains
#[codec(index = 7)]
#[codec(index = 4)]
Tendermint(ConsensusStateId),
}

Expand All @@ -286,10 +282,9 @@ impl StateMachine {
/// Check if the state machine is substrate-based
pub fn is_substrate(&self) -> bool {
match self {
StateMachine::Polkadot(_) |
StateMachine::Kusama(_) |
StateMachine::Beefy(_) |
StateMachine::Grandpa(_) => true,
StateMachine::Polkadot(_) | StateMachine::Kusama(_) | StateMachine::Substrate(_) => {
true
},
_ => false,
}
}
Expand All @@ -303,11 +298,11 @@ impl Display for StateMachine {
},
StateMachine::Polkadot(id) => format!("POLKADOT-{id}"),
StateMachine::Kusama(id) => format!("KUSAMA-{id}"),
StateMachine::Grandpa(id) => {
format!("GRANDPA-{}", String::from_utf8(id.to_vec()).map_err(|_| core::fmt::Error)?)
},
StateMachine::Beefy(id) => {
format!("BEEFY-{}", String::from_utf8(id.to_vec()).map_err(|_| core::fmt::Error)?)
StateMachine::Substrate(id) => {
format!(
"SUBSTRATE-{}",
String::from_utf8(id.to_vec()).map_err(|_| core::fmt::Error)?
)
},
StateMachine::Tendermint(id) => format!(
"TNDRMINT-{}",
Expand Down Expand Up @@ -347,23 +342,14 @@ impl FromStr for StateMachine {
.ok_or_else(|| format!("invalid state machine: {name}"))?;
StateMachine::Kusama(id)
},
name if name.starts_with("GRANDPA-") => {
let name = name
.split('-')
.last()
.ok_or_else(|| format!("invalid state machine: {name}"))?;
let mut id = [0u8; 4];
id.copy_from_slice(name.as_bytes());
StateMachine::Grandpa(id)
},
name if name.starts_with("BEEFY-") => {
name if name.starts_with("SUBSTRATE-") => {
let name = name
.split('-')
.last()
.ok_or_else(|| format!("invalid state machine: {name}"))?;
let mut id = [0u8; 4];
id.copy_from_slice(name.as_bytes());
StateMachine::Beefy(id)
StateMachine::Substrate(id)
},
name if name.starts_with("TNDRMINT-") => {
let name = name
Expand All @@ -389,8 +375,8 @@ mod tests {

#[test]
fn state_machine_conversions() {
let grandpa = StateMachine::Grandpa(*b"hybr");
let beefy = StateMachine::Beefy(*b"hybr");
let grandpa = StateMachine::Substrate(*b"hybr");
let beefy = StateMachine::Tendermint(*b"hybr");

let grandpa_string = grandpa.to_string();
let beefy_string = beefy.to_string();
Expand Down
5 changes: 1 addition & 4 deletions modules/ismp/pallets/asset-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ where
ensure!(
!matches!(
request.source_chain(),
StateMachine::Kusama(_) |
StateMachine::Polkadot(_) |
StateMachine::Grandpa(_) |
StateMachine::Beefy(_)
StateMachine::Kusama(_) | StateMachine::Polkadot(_) | StateMachine::Substrate(_)
),
ismp::error::Error::ModuleDispatchError {
msg: "Token Gateway: Illegal source chain".to_string(),
Expand Down
Loading

0 comments on commit 558e0b9

Please sign in to comment.