Skip to content

Commit f6b24f3

Browse files
authored
Merge pull request #758 from movementlabsxyz/primata/remove-pool-balance
remove pool balance
2 parents a544bb0 + 7c8d9df commit f6b24f3

10 files changed

+18
-63
lines changed

protocol-units/bridge/contracts/script/DeployAtomicBridgeInitiatorMOVE.s.sol

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ contract AtomicBridgeInitiatorMOVEDeployer is Script {
1919
address public moveTokenAddress = address(0xC36ba8B8fD9EcbF36288b9B9B0ae9FC3E0645227);
2020
address public ownerAddress = address(0x5b97cdf756f6363A88706c376464180E008Bd88b);
2121
uint256 public timeLockDuration = 2 days; // 48 hours in seconds
22-
uint256 public initialPoolBalance = 1 ether; // Initial pool balance
2322
uint256 public minDelay = 2 days; // 2-day delay for governance timelock
2423

2524
// Safe addresses (replace these with actual safe addresses)
@@ -62,8 +61,7 @@ contract AtomicBridgeInitiatorMOVEDeployer is Script {
6261
atomicBridgeSignature,
6362
moveTokenAddress, // MOVE token address
6463
ownerAddress, // Owner of the contract
65-
timeLockDuration, // Timelock duration (48 hours)
66-
initialPoolBalance // Initial pool balance
64+
timeLockDuration // Timelock duration (48 hours)
6765
)
6866
);
6967

@@ -86,8 +84,7 @@ contract AtomicBridgeInitiatorMOVEDeployer is Script {
8684
atomicBridgeSignature,
8785
moveTokenAddress,
8886
ownerAddress,
89-
timeLockDuration,
90-
initialPoolBalance
87+
timeLockDuration
9188
)
9289
),
9390
bytes32(0),

protocol-units/bridge/contracts/src/AtomicBridgeCounterparty.sol

+1-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ contract AtomicBridgeCounterparty is IAtomicBridgeCounterparty, OwnableUpgradeab
5353
address recipient,
5454
uint256 amount
5555
) external onlyOwner returns (bool) {
56-
if (amount == 0) revert ZeroAmount();
57-
58-
if (atomicBridgeInitiator.poolBalance() < amount) revert InsufficientWethBalance();
59-
60-
// potentially mint some gas here for the recipient here. The recipient could be an account with gas already.
61-
56+
if (amount == 0) revert ZeroAmount();
6257
// The time lock is now based on the configurable duration
6358
uint256 timeLock = block.timestamp + counterpartyTimeLockDuration;
6459

protocol-units/bridge/contracts/src/AtomicBridgeCounterpartyMOVE.sol

+1-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ contract AtomicBridgeCounterpartyMOVE is IAtomicBridgeCounterpartyMOVE, OwnableU
5555
bytes32 hashLock,
5656
address recipient,
5757
uint256 amount
58-
) external onlyOwner returns (bool) {
58+
) external onlyOwner {
5959
if (amount == 0) revert ZeroAmount();
60-
if (atomicBridgeInitiatorMOVE.poolBalance() < amount) revert InsufficientMOVEBalance();
61-
6260
// The time lock is now based on the configurable duration
6361
uint256 timeLock = block.timestamp + counterpartyTimeLockDuration;
6462

@@ -72,7 +70,6 @@ contract AtomicBridgeCounterpartyMOVE is IAtomicBridgeCounterpartyMOVE, OwnableU
7270
});
7371

7472
emit BridgeTransferLocked(bridgeTransferId, recipient, amount, hashLock, counterpartyTimeLockDuration);
75-
return true;
7673
}
7774

7875
function completeBridgeTransfer(bytes32 bridgeTransferId, bytes32 preImage) external {

protocol-units/bridge/contracts/src/AtomicBridgeInitiator.sol

+2-15
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ contract AtomicBridgeInitiator is IAtomicBridgeInitiator, OwnableUpgradeable {
2323
// Mapping of bridge transfer ids to BridgeTransfer structs
2424
mapping(bytes32 => BridgeTransfer) public bridgeTransfers;
2525

26-
// Total WETH pool balance
27-
uint256 public poolBalance;
28-
2926
address public counterpartyAddress;
3027
IWETH9 public weth;
3128
uint256 private nonce;
@@ -34,18 +31,15 @@ contract AtomicBridgeInitiator is IAtomicBridgeInitiator, OwnableUpgradeable {
3431
uint256 public initiatorTimeLockDuration;
3532

3633
// Initialize the contract with WETH address, owner, custom time lock duration, and initial pool balance
37-
function initialize(address _weth, address owner, uint256 _timeLockDuration, uint256 _initialPoolBalance) public initializer {
38-
if (_weth == address(0)) {
34+
function initialize(address _weth, address owner, uint256 _timeLockDuration) public initializer {
35+
if (_weth == address(0) && owner == address(0)) {
3936
revert ZeroAddress();
4037
}
4138
weth = IWETH9(_weth);
4239
__Ownable_init(owner);
4340

4441
// Set the custom time lock duration
4542
initiatorTimeLockDuration = _timeLockDuration;
46-
47-
// Set the initial pool balance
48-
poolBalance = _initialPoolBalance;
4943
}
5044

5145
function setCounterpartyAddress(address _counterpartyAddress) external onlyOwner {
@@ -75,9 +69,6 @@ contract AtomicBridgeInitiator is IAtomicBridgeInitiator, OwnableUpgradeable {
7569
if (!weth.transferFrom(originator, address(this), wethAmount)) revert WETHTransferFailed();
7670
}
7771

78-
// Update the pool balance
79-
poolBalance += totalAmount;
80-
8172
// Generate a unique nonce to prevent replay attacks, and generate a transfer ID
8273
bridgeTransferId = keccak256(abi.encodePacked(originator, recipient, hashLock, initiatorTimeLockDuration, block.timestamp, nonce++));
8374

@@ -110,8 +101,6 @@ contract AtomicBridgeInitiator is IAtomicBridgeInitiator, OwnableUpgradeable {
110101
if (block.timestamp < bridgeTransfer.timeLock) revert TimeLockNotExpired();
111102
bridgeTransfer.state = MessageState.REFUNDED;
112103

113-
// Decrease pool balance and transfer WETH back to originator
114-
poolBalance -= bridgeTransfer.amount;
115104
if (!weth.transfer(bridgeTransfer.originator, bridgeTransfer.amount)) revert WETHTransferFailed();
116105

117106
emit BridgeTransferRefunded(bridgeTransferId);
@@ -120,8 +109,6 @@ contract AtomicBridgeInitiator is IAtomicBridgeInitiator, OwnableUpgradeable {
120109
// Counterparty contract to withdraw WETH for originator
121110
function withdrawWETH(address recipient, uint256 amount) external {
122111
if (msg.sender != counterpartyAddress) revert Unauthorized();
123-
if (poolBalance < amount) revert InsufficientWethBalance();
124-
poolBalance -= amount;
125112
if (!weth.transfer(recipient, amount)) revert WETHTransferFailed();
126113
}
127114
}

protocol-units/bridge/contracts/src/AtomicBridgeInitiatorMOVE.sol

+2-16
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ contract AtomicBridgeInitiatorMOVE is IAtomicBridgeInitiatorMOVE, OwnableUpgrade
2424
// Mapping of bridge transfer ids to BridgeTransfer structs
2525
mapping(bytes32 => BridgeTransfer) public bridgeTransfers;
2626

27-
// Total MOVE token pool balance
28-
uint256 public poolBalance;
29-
3027
address public counterpartyAddress;
3128
ERC20Upgradeable public moveToken;
3229
uint256 private nonce;
@@ -41,8 +38,7 @@ contract AtomicBridgeInitiatorMOVE is IAtomicBridgeInitiatorMOVE, OwnableUpgrade
4138
function initialize(
4239
address _moveToken,
4340
address owner,
44-
uint256 _timeLockDuration,
45-
uint256 _initialPoolBalance
41+
uint256 _timeLockDuration
4642
) public initializer {
4743
if (_moveToken == address(0) && owner == address(0)) {
4844
revert ZeroAddress();
@@ -55,9 +51,6 @@ contract AtomicBridgeInitiatorMOVE is IAtomicBridgeInitiatorMOVE, OwnableUpgrade
5551

5652
// Set the custom time lock duration
5753
initiatorTimeLockDuration = _timeLockDuration;
58-
59-
// Set the initial pool balance
60-
poolBalance = _initialPoolBalance;
6154
}
6255

6356
function setCounterpartyAddress(address _counterpartyAddress) external onlyOwner {
@@ -81,9 +74,6 @@ contract AtomicBridgeInitiatorMOVE is IAtomicBridgeInitiatorMOVE, OwnableUpgrade
8174
revert MOVETransferFailed();
8275
}
8376

84-
// Update the pool balance
85-
poolBalance += moveAmount;
86-
8777
// Generate a unique nonce to prevent replay attacks, and generate a transfer ID
8878
bridgeTransferId = keccak256(abi.encodePacked(originator, recipient, hashLock, initiatorTimeLockDuration, block.timestamp, nonce++));
8979

@@ -115,18 +105,14 @@ contract AtomicBridgeInitiatorMOVE is IAtomicBridgeInitiatorMOVE, OwnableUpgrade
115105
if (bridgeTransfer.state != MessageState.INITIALIZED) revert BridgeTransferStateNotInitialized();
116106
if (block.timestamp < bridgeTransfer.timeLock) revert TimeLockNotExpired();
117107
bridgeTransfer.state = MessageState.REFUNDED;
118-
119-
// Decrease pool balance and transfer MOVE tokens back to the originator
120-
poolBalance -= bridgeTransfer.amount;
108+
121109
if (!moveToken.transfer(bridgeTransfer.originator, bridgeTransfer.amount)) revert MOVETransferFailed();
122110

123111
emit BridgeTransferRefunded(bridgeTransferId);
124112
}
125113

126114
function withdrawMOVE(address recipient, uint256 amount) external {
127115
if (msg.sender != counterpartyAddress) revert Unauthorized();
128-
if (poolBalance < amount) revert InsufficientMOVEBalance();
129-
poolBalance -= amount;
130116
if (!moveToken.transfer(recipient, amount)) revert MOVETransferFailed();
131117
}
132118
}

protocol-units/bridge/contracts/src/IAtomicBridgeCounterpartyMOVE.sol

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ interface IAtomicBridgeCounterpartyMOVE {
3333
* @param hashLock The hash of the secret (HASH) that will unlock the funds
3434
* @param recipient The address to which to transfer the funds
3535
* @param amount The amount of WETH to lock
36-
* @return bool indicating successful lock
3736
*
3837
*/
3938
function lockBridgeTransfer(
@@ -42,7 +41,7 @@ interface IAtomicBridgeCounterpartyMOVE {
4241
bytes32 hashLock,
4342
address recipient,
4443
uint256 amount
45-
) external returns (bool);
44+
) external;
4645

4746
/**
4847
* @dev Completes the bridge transfer and withdraws WETH to the recipient

protocol-units/bridge/contracts/test/AtomicBridgeCounterparty.t.sol

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ contract AtomicBridgeCounterpartyTest is Test {
4545
address(atomicBridgeInitiatorImplementation),
4646
address(proxyAdmin),
4747
abi.encodeWithSignature(
48-
"initialize(address,address,uint256,uint256)",
48+
"initialize(address,address,uint256)",
4949
wethAddress,
5050
deployer,
51-
initiatorTimeLockDuration, // Set 48-hour time lock for the initiator
52-
0 ether // Initial pool balance
51+
initiatorTimeLockDuration // Set 48-hour time lock for the initiator
5352
)
5453
);
5554

protocol-units/bridge/contracts/test/AtomicBridgeCounterpartyMOVE.t.sol

+3-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ contract AtomicBridgeCounterpartyMOVETest is Test {
5858
address(atomicBridgeInitiatorMOVEImplementation),
5959
address(proxyAdmin),
6060
abi.encodeWithSignature(
61-
"initialize(address,address,uint256,uint256)",
61+
"initialize(address,address,uint256)",
6262
address(moveToken),
6363
deployer,
64-
initiatorTimeLockDuration,
65-
0 ether // Initial pool balance
64+
initiatorTimeLockDuration
6665
)
6766
);
6867
atomicBridgeInitiatorMOVE = AtomicBridgeInitiatorMOVE(address(proxy));
@@ -107,7 +106,7 @@ contract AtomicBridgeCounterpartyMOVETest is Test {
107106
vm.stopPrank();
108107

109108
vm.startPrank(deployer); // Only the owner (deployer) can call lockBridgeTransfer
110-
bool result = atomicBridgeCounterpartyMOVE.lockBridgeTransfer(
109+
atomicBridgeCounterpartyMOVE.lockBridgeTransfer(
111110
initiator,
112111
bridgeTransferId,
113112
hashLock,
@@ -125,7 +124,6 @@ contract AtomicBridgeCounterpartyMOVETest is Test {
125124
AtomicBridgeCounterpartyMOVE.MessageState pendingState
126125
) = atomicBridgeCounterpartyMOVE.bridgeTransfers(bridgeTransferId);
127126

128-
assert(result);
129127
assertEq(pendingInitiator, initiator);
130128
assertEq(pendingRecipient, recipient);
131129
assertEq(pendingAmount, amount);

protocol-units/bridge/contracts/test/AtomicBridgeInitiator.t.sol

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ contract AtomicBridgeInitiatorWethTest is Test {
2121
bytes32 public hashLock = keccak256(abi.encodePacked("secret"));
2222
uint256 public amount = 1 ether;
2323
uint256 public constant timeLockDuration = 48 * 60 * 60; // 48 hours in seconds
24-
uint256 public initialPoolBalance = 0 ether;
2524

2625
function setUp() public {
2726
// Sepolia WETH9 address
@@ -38,11 +37,10 @@ contract AtomicBridgeInitiatorWethTest is Test {
3837
address(atomicBridgeInitiatorImplementation),
3938
address(proxyAdmin),
4039
abi.encodeWithSignature(
41-
"initialize(address,address,uint256,uint256)",
40+
"initialize(address,address,uint256)",
4241
wethAddress,
4342
address(this),
44-
timeLockDuration,
45-
initialPoolBalance
43+
timeLockDuration
4644
)
4745
);
4846

protocol-units/bridge/contracts/test/AtomicBridgeInitiatorMOVE.t.sol

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ contract AtomicBridgeInitiatorMOVETest is Test {
4040
address(atomicBridgeInitiatorImplementation),
4141
address(proxyAdmin),
4242
abi.encodeWithSignature(
43-
"initialize(address,address,uint256,uint256)",
43+
"initialize(address,address,uint256)",
4444
address(moveToken),
4545
address(this),
46-
timeLockDuration,
47-
0 ether
46+
timeLockDuration
4847
)
4948
);
5049

0 commit comments

Comments
 (0)