File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,6 +55,9 @@ library TokenLib {
5555 /// @notice Thrown when the token pair is not registered.
5656 error WrappedSplRouteNotRegistered ();
5757
58+ /// @notice Thrown when the transfer amount is zero.
59+ error ZeroAmount ();
60+
5861 //////////////////////////////////////////////////////////////
5962 /// Events ///
6063 //////////////////////////////////////////////////////////////
@@ -121,6 +124,8 @@ library TokenLib {
121124 internal
122125 returns (SolanaTokenType tokenType )
123126 {
127+ require (transfer.remoteAmount > 0 , ZeroAmount ());
128+
124129 TokenLibStorage storage $ = getTokenLibStorage ();
125130 uint256 localAmount;
126131
@@ -168,6 +173,8 @@ library TokenLib {
168173
169174 // Convert back to remote amount and transfer the dust back to the sender.
170175 uint256 receivedRemoteAmount = receivedLocalAmount / scalar;
176+ require (receivedRemoteAmount > 0 , ZeroAmount ());
177+
171178 localAmount = receivedRemoteAmount * scalar;
172179 uint256 dust = receivedLocalAmount - localAmount;
173180 if (dust > 0 ) {
Original file line number Diff line number Diff line change @@ -305,6 +305,19 @@ contract TokenLibTest is CommonTest {
305305 bridge.bridgeToken {value: 1 ether }(transfer, emptyIxs);
306306 }
307307
308+ function test_initializeTransfer_revertsOnZeroAmount () public {
309+ Transfer memory transfer = Transfer ({
310+ localToken: address (mockToken),
311+ remoteToken: TEST_REMOTE_TOKEN,
312+ to: bytes32 (uint256 (uint160 (alice))),
313+ remoteAmount: 0
314+ });
315+
316+ vm.expectRevert (TokenLib.ZeroAmount.selector );
317+ Ix[] memory emptyIxs;
318+ bridge.bridgeToken (transfer, emptyIxs);
319+ }
320+
308321 //////////////////////////////////////////////////////////////
309322 /// Finalize Transfer Tests ///
310323 //////////////////////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments