@@ -13,12 +13,12 @@ import "./libraries/external/ReentrancyGuardUpgradeable.sol";
13
13
import "./libraries/EndpointStructs.sol " ;
14
14
import "./libraries/EndpointHelpers.sol " ;
15
15
import "./libraries/RateLimiter.sol " ;
16
- import "./libraries/NormalizedAmount.sol " ;
17
16
import "./interfaces/IManager.sol " ;
18
17
import "./interfaces/IManagerEvents.sol " ;
19
18
import "./interfaces/INTTToken.sol " ;
20
19
import "./Endpoint.sol " ;
21
20
import "./EndpointRegistry.sol " ;
21
+ import "./NttNormalizer.sol " ;
22
22
import "./libraries/PausableOwnable.sol " ;
23
23
24
24
// TODO: rename this (it's really the business logic)
@@ -27,13 +27,12 @@ abstract contract Manager is
27
27
IManagerEvents ,
28
28
EndpointRegistry ,
29
29
RateLimiter ,
30
+ NttNormalizer ,
30
31
ReentrancyGuardUpgradeable ,
31
32
PausableOwnable
32
33
{
33
34
using BytesParsing for bytes ;
34
35
using SafeERC20 for IERC20 ;
35
- using NormalizedAmountLib for uint256 ;
36
- using NormalizedAmountLib for NormalizedAmount;
37
36
38
37
error RefundFailed (uint256 refundAmount );
39
38
error CannotRenounceManagerOwnership (address owner );
@@ -100,7 +99,7 @@ abstract contract Manager is
100
99
Mode _mode ,
101
100
uint16 _chainId ,
102
101
uint64 _rateLimitDuration
103
- ) RateLimiter (_rateLimitDuration) {
102
+ ) RateLimiter (_rateLimitDuration) NttNormalizer (_token) {
104
103
token = _token;
105
104
mode = _mode;
106
105
chainId = _chainId;
@@ -163,15 +162,11 @@ abstract contract Manager is
163
162
}
164
163
165
164
function setOutboundLimit (uint256 limit ) external onlyOwner {
166
- uint8 decimals = _tokenDecimals ();
167
- NormalizedAmount memory normalized = NormalizedAmountLib.normalize (limit, decimals);
168
- _setOutboundLimit (normalized);
165
+ _setOutboundLimit (nttNormalize (limit));
169
166
}
170
167
171
168
function setInboundLimit (uint256 limit , uint16 chainId_ ) external onlyOwner {
172
- uint8 decimals = _tokenDecimals ();
173
- NormalizedAmount memory normalized = NormalizedAmountLib.normalize (limit, decimals);
174
- _setInboundLimit (normalized, chainId_);
169
+ _setInboundLimit (nttNormalize (limit), chainId_);
175
170
}
176
171
177
172
function completeOutboundQueuedTransfer (uint64 messageSequence )
@@ -225,12 +220,9 @@ abstract contract Manager is
225
220
{
226
221
NormalizedAmount memory normalizedAmount;
227
222
{
228
- // query tokens decimals
229
- uint8 decimals = _tokenDecimals ();
230
-
231
- normalizedAmount = amount.normalize (decimals);
223
+ normalizedAmount = nttNormalize (amount);
232
224
// don't deposit dust that can not be bridged due to the decimal shift
233
- uint256 newAmount = normalizedAmount. denormalize (decimals );
225
+ uint256 newAmount = nttDenormalize (normalizedAmount );
234
226
if (amount != newAmount) {
235
227
revert TransferAmountHasDust (amount, amount - newAmount);
236
228
}
@@ -420,7 +412,7 @@ abstract contract Manager is
420
412
recipientChain, priceQuotes, sortedInstructions, encodedManagerPayload
421
413
);
422
414
423
- emit TransferSent (recipient, amount. denormalize ( _tokenDecimals () ), recipientChain, sequence);
415
+ emit TransferSent (recipient, nttDenormalize (amount ), recipientChain, sequence);
424
416
425
417
// return the sequence number
426
418
return sequence;
@@ -481,7 +473,7 @@ abstract contract Manager is
481
473
revert InvalidTargetChain (nativeTokenTransfer.toChain, chainId);
482
474
}
483
475
484
- NormalizedAmount memory nativeTransferAmount = nativeTokenTransfer.amount;
476
+ NormalizedAmount memory nativeTransferAmount = nttFixDecimals ( nativeTokenTransfer.amount) ;
485
477
486
478
address transferRecipient = fromWormholeFormat (nativeTokenTransfer.to);
487
479
@@ -527,10 +519,8 @@ abstract contract Manager is
527
519
528
520
function _mintOrUnlockToRecipient (address recipient , NormalizedAmount memory amount ) internal {
529
521
// calculate proper amount of tokens to unlock/mint to recipient
530
- // query the decimals of the token contract that's tied to this manager
531
- // adjust the decimals of the amount in the nativeTokenTransfer payload accordingly
532
- uint8 decimals = _tokenDecimals ();
533
- uint256 denormalizedAmount = amount.denormalize (decimals);
522
+ // denormalize the amount
523
+ uint256 denormalizedAmount = nttDenormalize (amount);
534
524
535
525
if (mode == Mode.LOCKING) {
536
526
// unlock tokens to the specified recipient
@@ -585,7 +575,6 @@ abstract contract Manager is
585
575
}
586
576
587
577
function _tokenDecimals () internal view override returns (uint8 ) {
588
- (, bytes memory queriedDecimals ) = token.staticcall (abi.encodeWithSignature ("decimals() " ));
589
- return abi.decode (queriedDecimals, (uint8 ));
578
+ return tokenDecimals;
590
579
}
591
580
}
0 commit comments