@@ -74,25 +74,29 @@ contract OriginalTokenBridge is TokenBridgeBase {
74
74
/// @dev Locks an ERC20 on the source chain and sends LZ message to the remote chain to mint a wrapped token
75
75
function bridge (address token , uint amountLD , address to , LzLib.CallParams calldata callParams , bytes memory adapterParams ) external payable nonReentrant {
76
76
require (supportedTokens[token], "OriginalTokenBridge: token is not supported " );
77
- amountLD = _removeDust (token, amountLD);
78
-
77
+
79
78
// Supports tokens with transfer fee
80
79
uint balanceBefore = IERC20 (token).balanceOf (address (this ));
81
80
IERC20 (token).safeTransferFrom (msg .sender , address (this ), amountLD);
82
81
uint balanceAfter = IERC20 (token).balanceOf (address (this ));
83
- amountLD = balanceAfter - balanceBefore;
82
+ (uint amountWithoutDustLD , uint dust ) = _removeDust (token, balanceAfter - balanceBefore);
83
+
84
+ // return dust to the sender
85
+ if (dust > 0 ) {
86
+ IERC20 (token).safeTransfer (msg .sender , dust);
87
+ }
84
88
85
- _bridge (token, amountLD , to, msg .value , callParams, adapterParams);
89
+ _bridge (token, amountWithoutDustLD , to, msg .value , callParams, adapterParams);
86
90
}
87
91
88
92
/// @notice Bridges ETH to the remote chain
89
93
/// @dev Locks WETH on the source chain and sends LZ message to the remote chain to mint a wrapped token
90
94
function bridgeETH (uint amountLD , address to , LzLib.CallParams calldata callParams , bytes memory adapterParams ) external payable nonReentrant {
91
95
require (supportedTokens[weth], "OriginalTokenBridge: token is not supported " );
92
96
require (msg .value >= amountLD, "OriginalTokenBridge: not enough value sent " );
93
- amountLD = _removeDust (weth, amountLD);
97
+ ( uint amountWithoutDustLD , ) = _removeDust (weth, amountLD);
94
98
IWETH (weth).deposit {value: amountLD}();
95
- _bridge (weth, amountLD, to, msg .value - amountLD , callParams, adapterParams);
99
+ _bridge (weth, amountLD, to, msg .value - amountWithoutDustLD , callParams, adapterParams);
96
100
}
97
101
98
102
function _bridge (address token , uint amountLD , address to , uint nativeFee , LzLib.CallParams calldata callParams , bytes memory adapterParams ) private {
@@ -153,8 +157,9 @@ contract OriginalTokenBridge is TokenBridgeBase {
153
157
return amountLD / LDtoSDConversionRate[token];
154
158
}
155
159
156
- function _removeDust (address token , uint amountLD ) internal view returns (uint ) {
157
- return _amountSDtoLD (token, _amountLDtoSD (token, amountLD));
160
+ function _removeDust (address token , uint amountLD ) internal view returns (uint amountWithoutDustLD , uint dust ) {
161
+ dust = amountLD % LDtoSDConversionRate[token];
162
+ amountWithoutDustLD = amountLD - dust;
158
163
}
159
164
160
165
/// @dev Allows receiving ETH when calling WETH.withdraw()
0 commit comments