Skip to content

Commit

Permalink
make contract sizes smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Sep 16, 2024
1 parent 3c15d21 commit 9490f27
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
12 changes: 3 additions & 9 deletions interfaces/IConsensusClient.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

import {StateMachineHeight} from "./Message.sol";


// The state commiment identifies a commiment to some intermediate state in the state machine.
// This contains some metadata about the state machine like it's own timestamp at the time of this commitment.
struct StateCommitment {
Expand All @@ -12,15 +15,6 @@ struct StateCommitment {
bytes32 stateRoot;
}

// Identifies some state machine height. We allow for a state machine identifier here
// as some consensus clients may track multiple, concurrent state machines.
struct StateMachineHeight {
// the state machine identifier
uint256 stateMachineId;
// height of this state machine
uint256 height;
}

// An intermediate state in the series of state transitions undergone by a given state machine.
struct IntermediateState {
// the state machine identifier
Expand Down
9 changes: 8 additions & 1 deletion interfaces/IHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
pragma solidity ^0.8.17;

import {IIsmpHost} from "./IIsmpHost.sol";
import {PostRequestMessage, PostResponseMessage, GetResponseMessage, PostRequestTimeoutMessage, PostResponseTimeoutMessage, GetTimeoutMessage} from "./Message.sol";
import {
PostRequestMessage,
PostResponseMessage,
GetResponseMessage,
PostRequestTimeoutMessage,
PostResponseTimeoutMessage,
GetTimeoutMessage
} from "./Message.sol";

/*
* @title The Ismp Handler
Expand Down
12 changes: 5 additions & 7 deletions interfaces/IIsmpModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
pragma solidity ^0.8.17;

import {PostRequest, PostResponse, GetResponse, GetRequest} from "./Message.sol";
import {DispatchPost, DispatchPostResponse, DispatchGet} from "./IDispatcher.sol";
import {IIsmpHost} from "./IIsmpHost.sol";
import {DispatchPost, DispatchPostResponse, DispatchGet, IDispatcher} from "./IDispatcher.sol";

import {Context} from "@openzeppelin/contracts/utils/Context.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

struct IncomingPostRequest {
Expand Down Expand Up @@ -85,7 +83,7 @@ abstract contract BaseIsmpModule is IIsmpModule {
address hostAddr = host();
if (hostAddr != address(0)) {
// approve the host infintely
IERC20(IIsmpHost(hostAddr).feeToken()).approve(hostAddr, type(uint256).max);
IERC20(IDispatcher(hostAddr).feeToken()).approve(hostAddr, type(uint256).max);
}
}

Expand Down Expand Up @@ -123,17 +121,17 @@ abstract contract BaseIsmpModule is IIsmpModule {

// @dev returns the quoted fee for a dispatch
function quote(DispatchPost memory post) public view returns (uint256) {
return post.fee + (post.body.length * IIsmpHost(host()).perByteFee());
return post.fee + (post.body.length * IDispatcher(host()).perByteFee());
}

// @dev returns the quoted fee for a dispatch
function quote(DispatchPostResponse memory res) public view returns (uint256) {
return res.fee + (res.response.length * IIsmpHost(host()).perByteFee());
return res.fee + (res.response.length * IDispatcher(host()).perByteFee());
}

// @dev returns the quoted fee for a dispatch
function quote(DispatchGet memory get) public view returns (uint256) {
return get.fee + (get.context.length * IIsmpHost(host()).perByteFee());
return get.fee + (get.context.length * IDispatcher(host()).perByteFee());
}

function onAccept(IncomingPostRequest calldata) external virtual onlyHost {
Expand Down
10 changes: 9 additions & 1 deletion interfaces/Message.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

import {StateMachineHeight} from "./IConsensusClient.sol";
import {StorageValue} from "@polytope-labs/solidity-merkle-trees/src/Types.sol";

// Identifies some state machine height. We allow for a state machine identifier here
// as some consensus clients may track multiple, concurrent state machines.
struct StateMachineHeight {
// the state machine identifier
uint256 stateMachineId;
// height of this state machine
uint256 height;
}

struct PostRequest {
// the source state machine of this request
bytes source;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polytope-labs/ismp-solidity",
"version": "0.6.9",
"version": "0.7.0",
"description": "Hyperbridge Solidity SDK for the Interoperable state machine protocol",
"author": "Polytope Labs <[email protected]>",
"license": "Apache-2.0",
Expand Down

0 comments on commit 9490f27

Please sign in to comment.