Skip to content

Commit 5fdd101

Browse files
committed
Copy types from ipc/contracts
1 parent 1594f26 commit 5fdd101

File tree

5 files changed

+176
-35
lines changed

5 files changed

+176
-35
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@
2828
[submodule "lib/solidity-cborutils"]
2929
path = lib/solidity-cborutils
3030
url = https://github.com/smartcontractkit/solidity-cborutils
31-
[submodule "lib/ipc"]
32-
path = lib/ipc
33-
url = https://github.com/consensus-shipyard/ipc

lib/ipc

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/token/AutoDeposit.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ pragma solidity ^0.8.26;
33

44
import {InterchainTokenExecutable} from "@axelar-network/interchain-token-service/contracts/executable/InterchainTokenExecutable.sol";
55
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6-
import {SubnetID} from "@ipc/contracts/contracts/structs/Subnet.sol";
7-
import {FvmAddress} from "@ipc/contracts/contracts/structs/FvmAddress.sol";
8-
import {IGateway} from "@ipc/contracts/contracts/interfaces/IGateway.sol";
6+
import {SubnetID} from "../types/CommonTypes.sol";
7+
import {FvmAddress} from "../types/CommonTypes.sol";
8+
import {IGatewayManagerFacet} from "./IGatewayManagerFacet.sol";
99

1010
/// @title AutoDeposit
1111
/// @notice Handles automatic token deposits from Axelar to IPC subnets
@@ -16,7 +16,7 @@ contract AutoDeposit is InterchainTokenExecutable {
1616

1717
SubnetID public recallSubnet;
1818
IERC20 public immutable RECALL_TOKEN;
19-
IGateway public immutable RECALL_GATEWAY;
19+
IGatewayManagerFacet public immutable RECALL_GATEWAY;
2020

2121
/// @notice Initializes the contract with required addresses and subnet ID
2222
/// @param subnet The subnet ID where tokens will be deposited
@@ -31,7 +31,7 @@ contract AutoDeposit is InterchainTokenExecutable {
3131
) InterchainTokenExecutable(interchainTokenService_) {
3232
recallSubnet = subnet;
3333
RECALL_TOKEN = IERC20(token);
34-
RECALL_GATEWAY = IGateway(gateway);
34+
RECALL_GATEWAY = IGatewayManagerFacet(gateway);
3535
}
3636

3737
/// @inheritdoc InterchainTokenExecutable

src/token/IGatewayManagerFacet.sol

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
3+
4+
import {BottomUpCheckpoint, BottomUpMsgBatch, IpcEnvelope, ParentFinality, SubnetID, FvmAddress, FullActivityRollup} from "../types/CommonTypes.sol";
5+
6+
/// @title Gateway interface
7+
/// @author LimeChain team
8+
interface IGatewayManagerFacet {
9+
/// @notice Register is called by subnet actors to put the required collateral
10+
/// and register the subnet to the hierarchy.
11+
function register(uint256 genesisCircSupply, uint256 collateral) external payable;
12+
13+
/// @notice AddStake adds stake to the collateral of a subnet.
14+
function addStake(uint256 amount) external payable;
15+
16+
/// @notice Release stake recovers some collateral of the subnet
17+
function releaseStake(uint256 amount) external;
18+
19+
/// @notice Kill propagates the kill signal from a subnet actor to unregister it from th
20+
/// hierarchy.
21+
function kill() external;
22+
23+
/// @notice commitCheckpoint propagates the commitment of a checkpoint from a child
24+
function commitCheckpoint(BottomUpCheckpoint calldata bottomUpCheckpoint) external;
25+
26+
/// @notice fund locks the received funds —denominated in the native coin— and moves the value down the hierarchy,
27+
/// crediting the funds to the specified address in the destination network.
28+
///
29+
/// This functions ends up minting supply in the subnet equal to the value of the transaction. It does so by
30+
/// committing the relevant top-down message, updating the top-down nonce along the way.
31+
///
32+
/// Calling this method on a subnet whose supply source is not 'native' will revert with UnexpectedAsset().
33+
function fund(SubnetID calldata subnetId, FvmAddress calldata to) external payable;
34+
35+
/// @notice fundWithToken locks the specified amount of tokens in the ERC20 contract linked to the subnet, and
36+
/// moves the value down the hierarchy, crediting the funds as native coins to the specified address
37+
/// in the destination network.
38+
///
39+
/// This method expects the caller to have approved the gateway to spend `amount` tokens on their behalf
40+
/// (usually done through IERC20#approve). Tokens are locked by calling IERC20#transferFrom(caller, address(this), amount).
41+
/// A failure in transferring tokens to the gateway will revert the call.
42+
///
43+
/// It's possible to call this method from an EOA or a contract. Regardless, it's recommended to approve strictly
44+
/// the amount that will subsequently be deposited into the subnet. Keeping outstanding approvals is not recommended.
45+
///
46+
/// Calling this method on a subnet whose supply source is not 'ERC20' will revert with UnexpectedAsset().
47+
function fundWithToken(SubnetID calldata subnetId, FvmAddress calldata to, uint256 amount) external;
48+
49+
/// @notice Release creates a new check message to release funds in parent chain
50+
///
51+
/// This function burns the funds that will be released in the current subnet
52+
/// and propagates a new checkpoint message to the parent chain to signal
53+
/// the amount of funds that can be released for a specific address.
54+
function release(FvmAddress calldata to) external payable;
55+
56+
/// @notice sendContractXnetMessage sends an arbitrary cross-message to other subnet in the hierarchy.
57+
// TODO: add the right comment and function name here.
58+
function sendContractXnetMessage(
59+
IpcEnvelope calldata envelope
60+
) external payable returns (IpcEnvelope memory committed);
61+
62+
/// @notice Propagates all the stored messages to destination subnet
63+
function propagateAll() external payable;
64+
65+
/// @notice commit the ipc parent finality into storage
66+
function commitParentFinality(ParentFinality calldata finality) external;
67+
68+
/// @notice creates a new bottom-up checkpoint
69+
function createBottomUpCheckpoint(
70+
BottomUpCheckpoint calldata checkpoint,
71+
bytes32 membershipRootHash,
72+
uint256 membershipWeight,
73+
FullActivityRollup calldata activity
74+
) external;
75+
}

src/types/CommonTypes.sol

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ struct SubnetID {
3838
address[] route;
3939
}
4040

41-
/// Namespace for consensus-level activity summaries.
42-
library Consensus {
43-
struct ValidatorData {
44-
/// @dev The validator whose activity we're reporting about, identified by the Ethereum address corresponding
45-
/// to its secp256k1 pubkey.
46-
address validator;
47-
/// @dev The number of blocks committed by this validator during the summarised period.
48-
uint64 blocksCommitted;
49-
}
41+
/// @notice The parent finality for IPC parent at certain height.
42+
struct ParentFinality {
43+
uint256 height;
44+
bytes32 blockHash;
5045
}
5146

5247
/// @notice A bottom-up checkpoint type.
@@ -69,25 +64,17 @@ struct BottomUpCheckpoint {
6964
CompressedActivityRollup activity;
7065
}
7166

72-
// Compressed representation of the activity summary that can be embedded in checkpoints to propagate up the hierarchy.
73-
struct CompressedActivityRollup {
74-
CompressedSummary consensus;
75-
}
76-
77-
// Aggregated stats for consensus-level activity.
78-
struct AggregatedStats {
79-
/// The total number of unique validators that have mined within this period.
80-
uint64 totalActiveValidators;
81-
/// The total number of blocks committed by all validators during this period.
82-
uint64 totalNumBlocksCommitted;
67+
/// @notice A batch of bottom-up messages for execution.
68+
struct BottomUpMsgBatch {
69+
SubnetID subnetID;
70+
uint256 blockHeight;
71+
IpcEnvelope[] msgs;
8372
}
8473

85-
// The compresed representation of the activity summary for consensus-level activity suitable for embedding in a
86-
// checkpoint.
87-
struct CompressedSummary {
88-
AggregatedStats stats;
89-
/// The commitment for the validator details, so that we don't have to transmit them in full.
90-
bytes32 dataRootCommitment;
74+
/// @notice Tracks information about the last batch executed.
75+
struct BottomUpMsgBatchInfo {
76+
uint256 blockHeight;
77+
bytes32 hash;
9178
}
9279

9380
/// @notice Type of cross-net messages currently supported
@@ -132,3 +119,86 @@ struct IpcEnvelope {
132119
/// @dev abi.encoded message
133120
bytes message;
134121
}
122+
123+
/// @notice Message format used for `Transfer` and `Call` messages.
124+
struct CallMsg {
125+
bytes method;
126+
bytes params;
127+
}
128+
129+
/// @notice Outcome type for cross message execution
130+
enum OutcomeType {
131+
Ok,
132+
SystemErr,
133+
ActorErr
134+
}
135+
136+
struct ResultMsg {
137+
bytes32 id;
138+
OutcomeType outcome;
139+
bytes ret;
140+
}
141+
142+
/// @notice Validator struct stored in the gateway.
143+
struct Validator {
144+
uint256 weight;
145+
address addr;
146+
bytes metadata;
147+
}
148+
149+
/// @notice Membership information stored in the gateway.
150+
struct Membership {
151+
Validator[] validators;
152+
uint64 configurationNumber;
153+
}
154+
155+
/// @notice Defines token representation in subnet
156+
struct Asset {
157+
AssetKind kind;
158+
address tokenAddress;
159+
}
160+
161+
/// @notice Token type used in the subnet
162+
enum AssetKind {
163+
Native,
164+
ERC20
165+
}
166+
167+
// Activity related structs
168+
struct FullActivityRollup {
169+
Consensus.FullSummary consensus;
170+
}
171+
172+
struct CompressedActivityRollup {
173+
Consensus.CompressedSummary consensus;
174+
}
175+
176+
/// Namespace for consensus-level activity summaries.
177+
library Consensus {
178+
type MerkleHash is bytes32;
179+
180+
struct AggregatedStats {
181+
uint64 totalActiveValidators;
182+
uint64 totalNumBlocksCommitted;
183+
}
184+
185+
struct FullSummary {
186+
AggregatedStats stats;
187+
ValidatorData[] data;
188+
}
189+
190+
struct CompressedSummary {
191+
AggregatedStats stats;
192+
MerkleHash dataRootCommitment;
193+
}
194+
195+
struct ValidatorData {
196+
address validator;
197+
uint64 blocksCommitted;
198+
}
199+
200+
struct ValidatorClaim {
201+
ValidatorData data;
202+
MerkleHash[] proof;
203+
}
204+
}

0 commit comments

Comments
 (0)