Skip to content

Commit c7411d2

Browse files
authored
fix[N02} Move all structs to the same place (#100)
Signed-off-by: chrismaree <christopher.maree@gmail.com>
1 parent 4320216 commit c7411d2

File tree

4 files changed

+70
-67
lines changed

4 files changed

+70
-67
lines changed

contracts/HubPool.sol

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,6 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
4141
using SafeERC20 for IERC20;
4242
using Address for address;
4343

44-
// A data worker can optimistically store several merkle roots on this contract by staking a bond and calling
45-
// proposeRootBundle. By staking a bond, the data worker is alleging that the merkle roots all
46-
// contain valid leaves that can be executed later to:
47-
// - Send funds from this contract to a SpokePool or vice versa
48-
// - Send funds from a SpokePool to Relayer as a refund for a relayed deposit
49-
// - Send funds from a SpokePool to a deposit recipient to fulfill a "slow" relay
50-
// Anyone can dispute this struct if the merkle roots contain invalid leaves before the
51-
// requestExpirationTimestamp. Once the expiration timestamp is passed, executeRootBundle to execute a leaf
52-
// from the poolRebalanceRoot on this contract and it will simultaneously publish the relayerRefundRoot and
53-
// slowRelayRoot to a SpokePool. The latter two roots, once published to the SpokePool, contain
54-
// leaves that can be executed on the SpokePool to pay relayers or recipients.
55-
struct RootBundle {
56-
// Contains leaves instructing this contract to send funds to SpokePools.
57-
bytes32 poolRebalanceRoot;
58-
// Relayer refund merkle root to be published to a SpokePool.
59-
bytes32 relayerRefundRoot;
60-
// Slow relay merkle root to be published to a SpokePool.
61-
bytes32 slowRelayRoot;
62-
// This is a 1D bitmap, with max size of 256 elements, limiting us to 256 chainsIds.
63-
uint256 claimedBitMap;
64-
// Proposer of this root bundle.
65-
address proposer;
66-
// Number of pool rebalance leaves to execute in the poolRebalanceRoot. After this number
67-
// of leaves are executed, a new root bundle can be proposed
68-
uint8 unclaimedPoolRebalanceLeafCount;
69-
// When root bundle challenge period passes and this root bundle becomes executable.
70-
uint32 requestExpirationTimestamp;
71-
}
72-
7344
// Only one root bundle can be stored at a time. Once all pool rebalance leaves are executed, a new proposal
7445
// can be submitted.
7546
RootBundle public rootBundleProposal;
@@ -85,30 +56,9 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
8556
// to 0x0 to disable a pool rebalance route and block executeRootBundle() from executing.
8657
mapping(bytes32 => address) private poolRebalanceRoutes;
8758

88-
struct PooledToken {
89-
// LP token given to LPs of a specific L1 token.
90-
address lpToken;
91-
// True if accepting new LP's.
92-
bool isEnabled;
93-
// Timestamp of last LP fee update.
94-
uint32 lastLpFeeUpdate;
95-
// Number of LP funds sent via pool rebalances to SpokePools and are expected to be sent
96-
// back later.
97-
int256 utilizedReserves;
98-
// Number of LP funds held in contract less utilized reserves.
99-
uint256 liquidReserves;
100-
// Number of LP funds reserved to pay out to LPs as fees.
101-
uint256 undistributedLpFees;
102-
}
103-
10459
// Mapping of L1 token addresses to the associated pool information.
10560
mapping(address => PooledToken) public pooledTokens;
10661

107-
// Helper contracts to facilitate cross chain actions between HubPool and SpokePool for a specific network.
108-
struct CrossChainContract {
109-
address adapter;
110-
address spokePool;
111-
}
11262
// Mapping of chainId to the associated adapter and spokePool contracts.
11363
mapping(uint256 => CrossChainContract) public crossChainContracts;
11464

@@ -590,8 +540,8 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
590540
* @param bundleEvaluationBlockNumbers should contain the latest block number for all chains, even if there are no
591541
* relays contained on some of them. The usage of this variable should be defined in an off chain UMIP.
592542
* @notice The caller of this function must approve this contract to spend bondAmount of bondToken.
593-
* @param poolRebalanceLeafCount Number of leaves contained in pool rebalance root. Max is the number of whitelisted chains.
594-
* @param poolRebalanceRoot Pool rebalance root containing leaves that will send tokens from this contract to a SpokePool.
543+
* @param poolRebalanceLeafCount Number of leaves contained in pool rebalance root. Max is # of whitelisted chains.
544+
* @param poolRebalanceRoot Pool rebalance root containing leaves that sends tokens from this contract to SpokePool.
595545
* @param relayerRefundRoot Relayer refund root to publish to SpokePool where a data worker can execute leaves to
596546
* refund relayers on their chosen refund chainId.
597547
* @param slowRelayRoot Slow relay root to publish to Spoke Pool where a data worker can execute leaves to

contracts/HubPoolInterface.sol

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ interface HubPoolInterface {
2323
// deposits in this bundle. If non-zero then it must be set on the SpokePool's RelayerRefundLeaf amountToReturn
2424
// as -1 * this value to indicate if funds are being sent from or to the SpokePool.
2525
int256[] netSendAmounts;
26-
// This is only here to be emitted in an event to track a running unpaid balance between the L2 pool and the L1 pool.
27-
// A positive number indicates that the HubPool owes the SpokePool funds. A negative number indicates that the
28-
// SpokePool owes the HubPool funds. See the comment above for the dynamics of this and netSendAmounts
26+
// This is only here to be emitted in an event to track a running unpaid balance between the L2 pool and the L1
27+
// pool. A positive number indicates that the HubPool owes the SpokePool funds. A negative number indicates that
28+
// the SpokePool owes the HubPool funds. See the comment above for the dynamics of this and netSendAmounts.
2929
int256[] runningBalances;
3030
// Used by data worker to mark which leaves should relay roots to SpokePools, and to otherwise organize leaves.
3131
// For example, each leaf should contain all the rebalance information for a single chain, but in the case where
@@ -42,6 +42,59 @@ interface HubPoolInterface {
4242
address[] l1Tokens;
4343
}
4444

45+
// A data worker can optimistically store several merkle roots on this contract by staking a bond and calling
46+
// proposeRootBundle. By staking a bond, the data worker is alleging that the merkle roots all contain valid leaves
47+
// that can be executed later to:
48+
// - Send funds from this contract to a SpokePool or vice versa
49+
// - Send funds from a SpokePool to Relayer as a refund for a relayed deposit
50+
// - Send funds from a SpokePool to a deposit recipient to fulfill a "slow" relay
51+
// Anyone can dispute this struct if the merkle roots contain invalid leaves before the
52+
// requestExpirationTimestamp. Once the expiration timestamp is passed, executeRootBundle to execute a leaf
53+
// from the poolRebalanceRoot on this contract and it will simultaneously publish the relayerRefundRoot and
54+
// slowRelayRoot to a SpokePool. The latter two roots, once published to the SpokePool, contain
55+
// leaves that can be executed on the SpokePool to pay relayers or recipients.
56+
struct RootBundle {
57+
// Contains leaves instructing this contract to send funds to SpokePools.
58+
bytes32 poolRebalanceRoot;
59+
// Relayer refund merkle root to be published to a SpokePool.
60+
bytes32 relayerRefundRoot;
61+
// Slow relay merkle root to be published to a SpokePool.
62+
bytes32 slowRelayRoot;
63+
// This is a 1D bitmap, with max size of 256 elements, limiting us to 256 chainsIds.
64+
uint256 claimedBitMap;
65+
// Proposer of this root bundle.
66+
address proposer;
67+
// Number of pool rebalance leaves to execute in the poolRebalanceRoot. After this number
68+
// of leaves are executed, a new root bundle can be proposed
69+
uint8 unclaimedPoolRebalanceLeafCount;
70+
// When root bundle challenge period passes and this root bundle becomes executable.
71+
uint32 requestExpirationTimestamp;
72+
}
73+
74+
// Each whitelisted L1 token has an associated pooledToken struct that contains all information used to track the
75+
// cumulative LP positions and if this token is enabled for deposits.
76+
struct PooledToken {
77+
// LP token given to LPs of a specific L1 token.
78+
address lpToken;
79+
// True if accepting new LP's.
80+
bool isEnabled;
81+
// Timestamp of last LP fee update.
82+
uint32 lastLpFeeUpdate;
83+
// Number of LP funds sent via pool rebalances to SpokePools and are expected to be sent
84+
// back later.
85+
int256 utilizedReserves;
86+
// Number of LP funds held in contract less utilized reserves.
87+
uint256 liquidReserves;
88+
// Number of LP funds reserved to pay out to LPs as fees.
89+
uint256 undistributedLpFees;
90+
}
91+
92+
// Helper contracts to facilitate cross chain actions between HubPool and SpokePool for a specific network.
93+
struct CrossChainContract {
94+
address adapter;
95+
address spokePool;
96+
}
97+
4598
function setPaused(bool pause) external;
4699

47100
function emergencyDeleteProposal() external;

contracts/SpokePool.sol

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ abstract contract SpokePool is SpokePoolInterface, Testable, Lockable, MultiCall
5050

5151
mapping(address => mapping(uint256 => bool)) public enabledDepositRoutes;
5252

53-
// Stores collection of merkle roots that can be published to this contract from the HubPool, which are referenced
54-
// by "data workers" via inclusion proofs to execute leaves in the roots.
55-
struct RootBundle {
56-
// Merkle root of slow relays that were not fully filled and whose recipient is still owed funds from the LP pool.
57-
bytes32 slowRelayRoot;
58-
// Merkle root of relayer refunds for successful relays.
59-
bytes32 relayerRefundRoot;
60-
// This is a 2D bitmap tracking which leaves in the relayer refund root have been claimed, with max size of
61-
// 256x256 leaves per root.
62-
mapping(uint256 => uint256) claimedBitmap;
63-
}
64-
6553
// This contract can store as many root bundles as the HubPool chooses to publish here.
6654
RootBundle[] public rootBundles;
6755

contracts/SpokePoolInterface.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ interface SpokePoolInterface {
4848
uint32 depositId;
4949
}
5050

51+
// Stores collection of merkle roots that can be published to this contract from the HubPool, which are referenced
52+
// by "data workers" via inclusion proofs to execute leaves in the roots.
53+
struct RootBundle {
54+
// Merkle root of slow relays that were not fully filled and whose recipient is still owed funds from the LP pool.
55+
bytes32 slowRelayRoot;
56+
// Merkle root of relayer refunds for successful relays.
57+
bytes32 relayerRefundRoot;
58+
// This is a 2D bitmap tracking which leaves in the relayer refund root have been claimed, with max size of
59+
// 256x256 leaves per root.
60+
mapping(uint256 => uint256) claimedBitmap;
61+
}
62+
5163
function setCrossDomainAdmin(address newCrossDomainAdmin) external;
5264

5365
function setHubPool(address newHubPool) external;

0 commit comments

Comments
 (0)