Skip to content

Commit 193a129

Browse files
Rahul MagantiRahul Maganti
Rahul Maganti
authored and
Rahul Maganti
committed
fix: remove NttTrimmer
1 parent c4a3737 commit 193a129

File tree

2 files changed

+18
-49
lines changed

2 files changed

+18
-49
lines changed

evm/src/NttManager.sol

+18-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import "./interfaces/INttManagerEvents.sol";
1818
import "./interfaces/INTTToken.sol";
1919
import "./interfaces/ITransceiver.sol";
2020
import "./TransceiverRegistry.sol";
21-
import "./NttTrimmer.sol";
21+
import "./libraries/TrimmedAmount.sol";
2222
import "./libraries/PausableOwnable.sol";
2323
import "./libraries/Implementation.sol";
2424

@@ -27,13 +27,14 @@ contract NttManager is
2727
INttManagerEvents,
2828
TransceiverRegistry,
2929
RateLimiter,
30-
NttTrimmer,
3130
ReentrancyGuardUpgradeable,
3231
PausableOwnable,
3332
Implementation
3433
{
3534
using BytesParsing for bytes;
3635
using SafeERC20 for IERC20;
36+
using TrimmedAmountLib for uint256;
37+
using TrimmedAmountLib for TrimmedAmount;
3738

3839
error RefundFailed(uint256 refundAmount);
3940
error CannotRenounceNttManagerOwnership(address owner);
@@ -179,7 +180,7 @@ contract NttManager is
179180
Mode _mode,
180181
uint16 _chainId,
181182
uint64 _rateLimitDuration
182-
) RateLimiter(_rateLimitDuration) NttTrimmer(_token) {
183+
) RateLimiter(_rateLimitDuration) {
183184
token = _token;
184185
mode = _mode;
185186
chainId = _chainId;
@@ -309,11 +310,11 @@ contract NttManager is
309310
}
310311

311312
function setOutboundLimit(uint256 limit) external onlyOwner {
312-
_setOutboundLimit(_nttTrimmer(limit));
313+
_setOutboundLimit(limit.trim(tokenDecimals()));
313314
}
314315

315316
function setInboundLimit(uint256 limit, uint16 chainId_) external onlyOwner {
316-
_setInboundLimit(_nttTrimmer(limit), chainId_);
317+
_setInboundLimit(limit.trim(tokenDecimals()), chainId_);
317318
}
318319

319320
function completeOutboundQueuedTransfer(uint64 messageSequence)
@@ -363,9 +364,9 @@ contract NttManager is
363364
function trimTransferAmount(uint256 amount) internal view returns (TrimmedAmount memory) {
364365
TrimmedAmount memory trimmedAmount;
365366
{
366-
trimmedAmount = _nttTrimmer(amount);
367+
trimmedAmount = amount.trim(tokenDecimals());
367368
// don't deposit dust that can not be bridged due to the decimal shift
368-
uint256 newAmount = _nttUntrim(trimmedAmount);
369+
uint256 newAmount = trimmedAmount.untrim(tokenDecimals());
369370
if (amount != newAmount) {
370371
revert TransferAmountHasDust(amount, amount - newAmount);
371372
}
@@ -557,7 +558,11 @@ contract NttManager is
557558
recipientChain, priceQuotes, instructions, enabledTransceivers, encodedNttManagerPayload
558559
);
559560

560-
emit TransferSent(recipient, _nttUntrim(amount), msg.value, recipientChain, seq);
561+
// push it on the stack again to avoid a stack too deep error
562+
TrimmedAmount memory amt = amount;
563+
uint16 destinationChain = recipientChain;
564+
565+
emit TransferSent(recipient, amt.untrim(tokenDecimals()), msg.value, destinationChain, seq);
561566

562567
// return the sequence number
563568
return sequence;
@@ -616,8 +621,8 @@ contract NttManager is
616621
if (nativeTokenTransfer.toChain != chainId) {
617622
revert InvalidTargetChain(nativeTokenTransfer.toChain, chainId);
618623
}
619-
620-
TrimmedAmount memory nativeTransferAmount = _nttFixDecimals(nativeTokenTransfer.amount);
624+
TrimmedAmount memory nativeTransferAmount =
625+
nativeTokenTransfer.amount.untrim(tokenDecimals()).trim(tokenDecimals());
621626

622627
address transferRecipient = fromWormholeFormat(nativeTokenTransfer.to);
623628

@@ -668,7 +673,7 @@ contract NttManager is
668673
) internal {
669674
// calculate proper amount of tokens to unlock/mint to recipient
670675
// untrim the amount
671-
uint256 untrimmedAmount = _nttUntrim(amount);
676+
uint256 untrimmedAmount = amount.untrim(tokenDecimals());
672677

673678
emit TransferRedeemed(digest);
674679

@@ -765,7 +770,8 @@ contract NttManager is
765770
}
766771

767772
function tokenDecimals() public view override(INttManager, RateLimiter) returns (uint8) {
768-
return tokenDecimals_;
773+
(, bytes memory queriedDecimals) = token.staticcall(abi.encodeWithSignature("decimals()"));
774+
return abi.decode(queriedDecimals, (uint8));
769775
}
770776

771777
/// ============== INVARIANTS =============================================

evm/src/NttTrimmer.sol

-37
This file was deleted.

0 commit comments

Comments
 (0)