22pragma solidity ^ 0.8.0 ;
33
44/**
5- * @title SharedDecimalsLib
5+ * @title OFTCoreMath
66 * @notice Copied from LZ implementation here:
77 * `https://github.com/LayerZero-Labs/devtools/blob/16daaee36fe802d11aa99b89c29bb74447354483/packages/oft-evm/contracts/OFTCore.sol#L364`
8- * Code was not modified beyond removing unrelated OFT/OApp concerns.
8+ * Code was not modified beyond adding `uint8 _sharedDecimals` to constructor args and substituting `sharedDecimals()` calls with it
99 */
10- abstract contract SharedDecimalsLib {
10+ abstract contract OFTCoreMath {
1111 error InvalidLocalDecimals ();
1212 error AmountSDOverflowed (uint256 amountSD );
1313
@@ -25,43 +25,15 @@ abstract contract SharedDecimalsLib {
2525 // @dev To preserve the dust that would otherwise be lost on that conversion,
2626 // we need to unify a denomination that can be represented on ALL chains inside of the OFT mesh
2727 uint256 public immutable decimalConversionRate;
28- uint8 internal immutable _sharedDecimals;
2928
3029 /**
3130 * @dev Constructor.
3231 * @param _localDecimals The decimals of the token on the local chain (this chain).
33- * @param _sharedDecimalsArg The shared decimals used by the OFT.
32+ * @param _sharedDecimals The shared decimals used by the OFT.
3433 */
35- constructor (uint8 _localDecimals , uint8 _sharedDecimalsArg ) {
36- _sharedDecimals = _sharedDecimalsArg;
37- if (_localDecimals < _sharedDecimalsArg) revert InvalidLocalDecimals ();
38- decimalConversionRate = 10 ** (_localDecimals - _sharedDecimalsArg);
39- }
40-
41- /**
42- * @dev Retrieves the shared decimals of the OFT.
43- * @return The shared decimals of the OFT.
44- *
45- * @dev Sets an implicit cap on the amount of tokens, over uint64.max() will need some sort of outbound cap / totalSupply cap
46- * Lowest common decimal denominator between chains.
47- * Defaults to 6 decimal places to provide up to 18,446,744,073,709.551615 units (max uint64).
48- * For tokens exceeding this totalSupply(), they will need to override the sharedDecimals function with something smaller.
49- * ie. 4 sharedDecimals would be 1,844,674,407,370,955.1615
50- */
51- function sharedDecimals () public view virtual returns (uint8 ) {
52- return _sharedDecimals;
53- }
54-
55- /**
56- * @dev Internal function to remove dust from the given local decimal amount.
57- * @param _amountLD The amount in local decimals.
58- * @return amountLD The amount after removing dust.
59- *
60- * @dev Prevents the loss of dust when moving amounts between chains with different decimals.
61- * @dev eg. uint(123) with a conversion rate of 100 becomes uint(100).
62- */
63- function _removeDust (uint256 _amountLD ) internal view virtual returns (uint256 amountLD ) {
64- return (_amountLD / decimalConversionRate) * decimalConversionRate;
34+ constructor (uint8 _localDecimals , uint8 _sharedDecimals ) {
35+ if (_localDecimals < _sharedDecimals) revert InvalidLocalDecimals ();
36+ decimalConversionRate = 10 ** (_localDecimals - _sharedDecimals);
6537 }
6638
6739 /**
0 commit comments