@layerzerolabs/oft-evm-contracts 0.2.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/.turbo/turbo-build.log +68 -0
  2. package/.turbo/turbo-lint.log +185 -0
  3. package/.turbo/turbo-test.log +144 -0
  4. package/LICENSE +23 -0
  5. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.dbg.json +4 -0
  6. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.json +1899 -0
  7. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol/ILayerZeroReceiver.dbg.json +4 -0
  8. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol/ILayerZeroReceiver.json +121 -0
  9. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.dbg.json +4 -0
  10. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.json +646 -0
  11. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.dbg.json +4 -0
  12. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.json +373 -0
  13. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingComposer.sol/IMessagingComposer.dbg.json +4 -0
  14. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingComposer.sol/IMessagingComposer.json +246 -0
  15. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingContext.sol/IMessagingContext.dbg.json +4 -0
  16. package/artifacts/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingContext.sol/IMessagingContext.json +42 -0
  17. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppCore.sol/IOAppCore.dbg.json +4 -0
  18. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppCore.sol/IOAppCore.json +148 -0
  19. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppExtended.sol/IOAppExtended.dbg.json +4 -0
  20. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppExtended.sol/IOAppExtended.json +467 -0
  21. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppMsgInspection.sol/IOAppMsgInspection.dbg.json +4 -0
  22. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppMsgInspection.sol/IOAppMsgInspection.json +50 -0
  23. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppOptionsType3.sol/IOAppOptionsType3.dbg.json +4 -0
  24. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppOptionsType3.sol/IOAppOptionsType3.json +135 -0
  25. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppReceiver.sol/IOAppReceiver.dbg.json +4 -0
  26. package/artifacts/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppReceiver.sol/IOAppReceiver.json +167 -0
  27. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeConfig.sol/IFeeConfig.dbg.json +4 -0
  28. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeConfig.sol/IFeeConfig.json +188 -0
  29. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeHandler.sol/IFeeHandler.dbg.json +4 -0
  30. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeHandler.sol/IFeeHandler.json +55 -0
  31. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IPauseByID.sol/IPauseByID.dbg.json +4 -0
  32. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IPauseByID.sol/IPauseByID.json +177 -0
  33. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IRateLimiter.sol/IRateLimiter.dbg.json +4 -0
  34. package/artifacts/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IRateLimiter.sol/IRateLimiter.json +532 -0
  35. package/artifacts/build-info/eba77569fb49f02e67cb445bb3ee5d37.json +1 -0
  36. package/artifacts/contracts/interfaces/IOFT.sol/IOFT.dbg.json +4 -0
  37. package/artifacts/contracts/interfaces/IOFT.sol/IOFT.json +467 -0
  38. package/artifacts/contracts/interfaces/IOFTDecimalUtils.sol/IOFTDecimalUtils.dbg.json +4 -0
  39. package/artifacts/contracts/interfaces/IOFTDecimalUtils.sol/IOFTDecimalUtils.json +66 -0
  40. package/artifacts/contracts/interfaces/IOFTExtended.sol/IOFTExtended.dbg.json +4 -0
  41. package/artifacts/contracts/interfaces/IOFTExtended.sol/IOFTExtended.json +1831 -0
  42. package/artifacts/contracts/libs/OFTComposeMsgCodec.sol/OFTComposeMsgCodec.dbg.json +4 -0
  43. package/artifacts/contracts/libs/OFTComposeMsgCodec.sol/OFTComposeMsgCodec.json +10 -0
  44. package/artifacts/contracts/libs/OFTMsgCodec.sol/OFTMsgCodec.dbg.json +4 -0
  45. package/artifacts/contracts/libs/OFTMsgCodec.sol/OFTMsgCodec.json +10 -0
  46. package/artifacts/contracts/utils/OFTDecimalUtils.sol/OFTDecimalUtils.dbg.json +4 -0
  47. package/artifacts/contracts/utils/OFTDecimalUtils.sol/OFTDecimalUtils.json +66 -0
  48. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.dbg.json +4 -0
  49. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.json +1899 -0
  50. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol/ILayerZeroReceiver.dbg.json +4 -0
  51. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol/ILayerZeroReceiver.json +121 -0
  52. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.dbg.json +4 -0
  53. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.json +646 -0
  54. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.dbg.json +4 -0
  55. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.json +373 -0
  56. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingComposer.sol/IMessagingComposer.dbg.json +4 -0
  57. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingComposer.sol/IMessagingComposer.json +246 -0
  58. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingContext.sol/IMessagingContext.dbg.json +4 -0
  59. package/artifacts-tron/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingContext.sol/IMessagingContext.json +42 -0
  60. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppCore.sol/IOAppCore.dbg.json +4 -0
  61. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppCore.sol/IOAppCore.json +148 -0
  62. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppExtended.sol/IOAppExtended.dbg.json +4 -0
  63. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppExtended.sol/IOAppExtended.json +467 -0
  64. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppMsgInspection.sol/IOAppMsgInspection.dbg.json +4 -0
  65. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppMsgInspection.sol/IOAppMsgInspection.json +50 -0
  66. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppOptionsType3.sol/IOAppOptionsType3.dbg.json +4 -0
  67. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppOptionsType3.sol/IOAppOptionsType3.json +135 -0
  68. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppReceiver.sol/IOAppReceiver.dbg.json +4 -0
  69. package/artifacts-tron/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppReceiver.sol/IOAppReceiver.json +167 -0
  70. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeConfig.sol/IFeeConfig.dbg.json +4 -0
  71. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeConfig.sol/IFeeConfig.json +188 -0
  72. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeHandler.sol/IFeeHandler.dbg.json +4 -0
  73. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeHandler.sol/IFeeHandler.json +55 -0
  74. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IPauseByID.sol/IPauseByID.dbg.json +4 -0
  75. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IPauseByID.sol/IPauseByID.json +177 -0
  76. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IRateLimiter.sol/IRateLimiter.dbg.json +4 -0
  77. package/artifacts-tron/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IRateLimiter.sol/IRateLimiter.json +532 -0
  78. package/artifacts-tron/build-info/8846688aca1ca86abc2af4e130f3effa.json +1 -0
  79. package/artifacts-tron/contracts/interfaces/IOFT.sol/IOFT.dbg.json +4 -0
  80. package/artifacts-tron/contracts/interfaces/IOFT.sol/IOFT.json +467 -0
  81. package/artifacts-tron/contracts/interfaces/IOFTDecimalUtils.sol/IOFTDecimalUtils.dbg.json +4 -0
  82. package/artifacts-tron/contracts/interfaces/IOFTDecimalUtils.sol/IOFTDecimalUtils.json +66 -0
  83. package/artifacts-tron/contracts/interfaces/IOFTExtended.sol/IOFTExtended.dbg.json +4 -0
  84. package/artifacts-tron/contracts/interfaces/IOFTExtended.sol/IOFTExtended.json +1831 -0
  85. package/artifacts-tron/contracts/libs/OFTComposeMsgCodec.sol/OFTComposeMsgCodec.dbg.json +4 -0
  86. package/artifacts-tron/contracts/libs/OFTComposeMsgCodec.sol/OFTComposeMsgCodec.json +10 -0
  87. package/artifacts-tron/contracts/libs/OFTMsgCodec.sol/OFTMsgCodec.dbg.json +4 -0
  88. package/artifacts-tron/contracts/libs/OFTMsgCodec.sol/OFTMsgCodec.json +10 -0
  89. package/artifacts-tron/contracts/utils/OFTDecimalUtils.sol/OFTDecimalUtils.dbg.json +4 -0
  90. package/artifacts-tron/contracts/utils/OFTDecimalUtils.sol/OFTDecimalUtils.json +66 -0
  91. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.dbg.json +4 -0
  92. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.json +1900 -0
  93. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol/ILayerZeroReceiver.dbg.json +4 -0
  94. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol/ILayerZeroReceiver.json +122 -0
  95. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.dbg.json +4 -0
  96. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.json +647 -0
  97. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.dbg.json +4 -0
  98. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.json +374 -0
  99. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingComposer.sol/IMessagingComposer.dbg.json +4 -0
  100. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingComposer.sol/IMessagingComposer.json +247 -0
  101. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingContext.sol/IMessagingContext.dbg.json +4 -0
  102. package/artifacts-zk/@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingContext.sol/IMessagingContext.json +43 -0
  103. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppCore.sol/IOAppCore.dbg.json +4 -0
  104. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppCore.sol/IOAppCore.json +149 -0
  105. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppExtended.sol/IOAppExtended.dbg.json +4 -0
  106. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppExtended.sol/IOAppExtended.json +468 -0
  107. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppMsgInspection.sol/IOAppMsgInspection.dbg.json +4 -0
  108. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppMsgInspection.sol/IOAppMsgInspection.json +51 -0
  109. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppOptionsType3.sol/IOAppOptionsType3.dbg.json +4 -0
  110. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppOptionsType3.sol/IOAppOptionsType3.json +136 -0
  111. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppReceiver.sol/IOAppReceiver.dbg.json +4 -0
  112. package/artifacts-zk/@layerzerolabs/oapp-evm-contracts/contracts/interfaces/IOAppReceiver.sol/IOAppReceiver.json +168 -0
  113. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeConfig.sol/IFeeConfig.dbg.json +4 -0
  114. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeConfig.sol/IFeeConfig.json +189 -0
  115. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeHandler.sol/IFeeHandler.dbg.json +4 -0
  116. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeHandler.sol/IFeeHandler.json +56 -0
  117. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IPauseByID.sol/IPauseByID.dbg.json +4 -0
  118. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IPauseByID.sol/IPauseByID.json +178 -0
  119. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IRateLimiter.sol/IRateLimiter.dbg.json +4 -0
  120. package/artifacts-zk/@layerzerolabs/utils-evm-contracts/contracts/interfaces/IRateLimiter.sol/IRateLimiter.json +533 -0
  121. package/artifacts-zk/build-info/be85166c48418856c8b56dff21efc105.json +1 -0
  122. package/artifacts-zk/contracts/interfaces/IOFT.sol/IOFT.dbg.json +4 -0
  123. package/artifacts-zk/contracts/interfaces/IOFT.sol/IOFT.json +468 -0
  124. package/artifacts-zk/contracts/interfaces/IOFTDecimalUtils.sol/IOFTDecimalUtils.dbg.json +4 -0
  125. package/artifacts-zk/contracts/interfaces/IOFTDecimalUtils.sol/IOFTDecimalUtils.json +67 -0
  126. package/artifacts-zk/contracts/interfaces/IOFTExtended.sol/IOFTExtended.dbg.json +4 -0
  127. package/artifacts-zk/contracts/interfaces/IOFTExtended.sol/IOFTExtended.json +1832 -0
  128. package/artifacts-zk/contracts/libs/OFTComposeMsgCodec.sol/OFTComposeMsgCodec.dbg.json +4 -0
  129. package/artifacts-zk/contracts/libs/OFTComposeMsgCodec.sol/OFTComposeMsgCodec.json +11 -0
  130. package/artifacts-zk/contracts/libs/OFTMsgCodec.sol/OFTMsgCodec.dbg.json +4 -0
  131. package/artifacts-zk/contracts/libs/OFTMsgCodec.sol/OFTMsgCodec.json +11 -0
  132. package/artifacts-zk/contracts/utils/OFTDecimalUtils.sol/OFTDecimalUtils.dbg.json +4 -0
  133. package/artifacts-zk/contracts/utils/OFTDecimalUtils.sol/OFTDecimalUtils.json +67 -0
  134. package/contracts/interfaces/IOFT.sol +158 -0
  135. package/contracts/interfaces/IOFTDecimalUtils.sol +39 -0
  136. package/contracts/interfaces/IOFTExtended.sol +17 -0
  137. package/contracts/libs/OFTComposeMsgCodec.sol +90 -0
  138. package/contracts/libs/OFTMsgCodec.sol +82 -0
  139. package/contracts/utils/OFTDecimalUtils.sol +88 -0
  140. package/foundry.toml +21 -0
  141. package/package.json +44 -0
  142. package/solhint.config.js +3 -0
  143. package/test/OFTDecimalUtils.t.sol +354 -0
@@ -0,0 +1,354 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.22;
3
+
4
+ import { Test } from "forge-std/Test.sol";
5
+ import { IOFTDecimalUtils } from "./../contracts/interfaces/IOFTDecimalUtils.sol";
6
+ import { OFTDecimalUtils } from "./../contracts/utils/OFTDecimalUtils.sol";
7
+
8
+ contract OFTDecimalUtilsHarness is OFTDecimalUtils {
9
+ constructor(uint8 _localDecimals, uint8 _sharedDecimals) OFTDecimalUtils(_localDecimals, _sharedDecimals) {}
10
+
11
+ function removeDust(uint256 _amountLD) external view returns (uint256) {
12
+ return _removeDust(_amountLD);
13
+ }
14
+
15
+ function toLD(uint64 _amountSD) external view returns (uint256) {
16
+ return _toLD(_amountSD);
17
+ }
18
+
19
+ function toSD(uint256 _amountLD) external view returns (uint64) {
20
+ return _toSD(_amountLD);
21
+ }
22
+ }
23
+
24
+ contract OFTDecimalUtilsTest is Test {
25
+ OFTDecimalUtilsHarness harness18_6;
26
+ OFTDecimalUtilsHarness harness18_8;
27
+ OFTDecimalUtilsHarness harness6_6;
28
+ OFTDecimalUtilsHarness harness8_6;
29
+ OFTDecimalUtilsHarness harness0_0;
30
+
31
+ function setUp() public {
32
+ harness18_6 = new OFTDecimalUtilsHarness(18, 6);
33
+ harness18_8 = new OFTDecimalUtilsHarness(18, 8);
34
+ harness6_6 = new OFTDecimalUtilsHarness(6, 6);
35
+ harness8_6 = new OFTDecimalUtilsHarness(8, 6);
36
+ harness0_0 = new OFTDecimalUtilsHarness(0, 0);
37
+ }
38
+
39
+ // ============ Constructor / Getter Tests ============
40
+
41
+ function test_constructor_18_6() public view {
42
+ assertEq(harness18_6.localDecimals(), 18);
43
+ assertEq(harness18_6.sharedDecimals(), 6);
44
+ assertEq(harness18_6.decimalConversionRate(), 10 ** 12);
45
+ }
46
+
47
+ function test_constructor_18_8() public view {
48
+ assertEq(harness18_8.localDecimals(), 18);
49
+ assertEq(harness18_8.sharedDecimals(), 8);
50
+ assertEq(harness18_8.decimalConversionRate(), 10 ** 10);
51
+ }
52
+
53
+ function test_constructor_6_6() public view {
54
+ assertEq(harness6_6.localDecimals(), 6);
55
+ assertEq(harness6_6.sharedDecimals(), 6);
56
+ assertEq(harness6_6.decimalConversionRate(), 1);
57
+ }
58
+
59
+ function test_constructor_8_6() public view {
60
+ assertEq(harness8_6.localDecimals(), 8);
61
+ assertEq(harness8_6.sharedDecimals(), 6);
62
+ assertEq(harness8_6.decimalConversionRate(), 100);
63
+ }
64
+
65
+ function test_constructor_0_0() public view {
66
+ assertEq(harness0_0.localDecimals(), 0);
67
+ assertEq(harness0_0.sharedDecimals(), 0);
68
+ assertEq(harness0_0.decimalConversionRate(), 1);
69
+ }
70
+
71
+ function test_constructor_Fuzz(uint8 _localDecimals, uint8 _sharedDecimals) public {
72
+ vm.assume(_localDecimals >= _sharedDecimals);
73
+ // Max safe value is around 77 (10^77 < 2^256).
74
+ vm.assume(_localDecimals - _sharedDecimals <= 77);
75
+
76
+ OFTDecimalUtilsHarness harness = new OFTDecimalUtilsHarness(_localDecimals, _sharedDecimals);
77
+
78
+ assertEq(harness.localDecimals(), _localDecimals);
79
+ assertEq(harness.sharedDecimals(), _sharedDecimals);
80
+ assertEq(harness.decimalConversionRate(), 10 ** (_localDecimals - _sharedDecimals));
81
+ }
82
+
83
+ function test_constructor_Revert_SharedGreaterThanLocal() public {
84
+ vm.expectRevert(IOFTDecimalUtils.InvalidLocalDecimals.selector);
85
+ new OFTDecimalUtilsHarness(6, 8);
86
+ }
87
+
88
+ // ============ Remove Dust Tests ============
89
+
90
+ function test_removeDust_18_6_NoDust() public view {
91
+ uint256 amountLD = 1e18;
92
+ uint256 result = harness18_6.removeDust(amountLD);
93
+ assertEq(result, amountLD);
94
+ }
95
+
96
+ function test_removeDust_18_6_WithDust() public view {
97
+ uint256 amountLD = 1e18 + 123456789012;
98
+ uint256 result = harness18_6.removeDust(amountLD);
99
+ assertEq(result, 1e18);
100
+ }
101
+
102
+ function test_removeDust_18_6_OnlyDust() public view {
103
+ uint256 amountLD = 999999999999;
104
+ uint256 result = harness18_6.removeDust(amountLD);
105
+ assertEq(result, 0);
106
+ }
107
+
108
+ function test_removeDust_18_6_Zero() public view {
109
+ uint256 result = harness18_6.removeDust(0);
110
+ assertEq(result, 0);
111
+ }
112
+
113
+ function test_removeDust_6_6() public view {
114
+ uint256 amountLD = 123456;
115
+ uint256 result = harness6_6.removeDust(amountLD);
116
+ assertEq(result, amountLD);
117
+ }
118
+
119
+ function test_removeDust_8_6_WithDust() public view {
120
+ uint256 amountLD = 12345678;
121
+ uint256 result = harness8_6.removeDust(amountLD);
122
+ assertEq(result, 12345600);
123
+ }
124
+
125
+ function test_removeDust_0_0() public view {
126
+ uint256 amountLD = 12345;
127
+ uint256 result = harness0_0.removeDust(amountLD);
128
+ assertEq(result, amountLD);
129
+ }
130
+
131
+ function test_removeDust_Fuzz_18_6(uint256 amountLD) public view {
132
+ uint256 result1 = harness18_6.removeDust(amountLD);
133
+ uint256 result2 = harness18_6.removeDust(result1);
134
+ assertEq(result1, (amountLD / harness18_6.decimalConversionRate()) * harness18_6.decimalConversionRate());
135
+ assertEq(result2, result1);
136
+ }
137
+
138
+ function test_removeDust_Fuzz_6_6(uint256 amountLD) public view {
139
+ uint256 result1 = harness6_6.removeDust(amountLD);
140
+ uint256 result2 = harness6_6.removeDust(result1);
141
+ assertEq(result1, amountLD);
142
+ assertEq(result2, result1);
143
+ }
144
+
145
+ function test_removeDust_Fuzz_8_6(uint256 amountLD) public view {
146
+ uint256 result1 = harness8_6.removeDust(amountLD);
147
+ uint256 result2 = harness8_6.removeDust(result1);
148
+ assertEq(result1, (amountLD / 100) * 100);
149
+ assertEq(result2, result1);
150
+ }
151
+
152
+ function test_removeDust_Fuzz_0_0(uint256 amountLD) public view {
153
+ uint256 result1 = harness0_0.removeDust(amountLD);
154
+ uint256 result2 = harness0_0.removeDust(result1);
155
+ assertEq(result1, amountLD);
156
+ assertEq(result2, result1);
157
+ }
158
+
159
+ // ============ To Local Decimals Tests ============
160
+
161
+ function test_toLD_18_6() public view {
162
+ uint64 amountSD = 1e6;
163
+ uint256 result = harness18_6.toLD(amountSD);
164
+ assertEq(result, 1e18);
165
+ }
166
+
167
+ function test_toLD_18_6_Zero() public view {
168
+ uint256 result = harness18_6.toLD(0);
169
+ assertEq(result, 0);
170
+ }
171
+
172
+ function test_toLD_18_6_MaxUint64() public view {
173
+ uint64 amountSD = type(uint64).max;
174
+ uint256 result = harness18_6.toLD(amountSD);
175
+ assertEq(result, uint256(type(uint64).max) * 1e12);
176
+ }
177
+
178
+ function test_toLD_6_6() public view {
179
+ uint64 amountSD = 123456;
180
+ uint256 result = harness6_6.toLD(amountSD);
181
+ assertEq(result, amountSD);
182
+ }
183
+
184
+ function test_toLD_8_6() public view {
185
+ uint64 amountSD = 1e6;
186
+ uint256 result = harness8_6.toLD(amountSD);
187
+ assertEq(result, 1e8);
188
+ }
189
+
190
+ function test_toLD_0_0() public view {
191
+ uint64 amountSD = 12345;
192
+ uint256 result = harness0_0.toLD(amountSD);
193
+ assertEq(result, amountSD);
194
+ }
195
+
196
+ function test_toLD_Fuzz_18_6(uint64 _amountSD) public view {
197
+ uint256 result = harness18_6.toLD(_amountSD);
198
+ assertEq(result, uint256(_amountSD) * 10 ** 12);
199
+ }
200
+
201
+ function test_toLD_Fuzz_6_6(uint64 _amountSD) public view {
202
+ uint256 result = harness6_6.toLD(_amountSD);
203
+ assertEq(result, uint256(_amountSD));
204
+ }
205
+
206
+ function test_toLD_Fuzz_8_6(uint64 _amountSD) public view {
207
+ uint256 result = harness8_6.toLD(_amountSD);
208
+ assertEq(result, uint256(_amountSD) * 100);
209
+ }
210
+
211
+ function test_toLD_Fuzz_0_0(uint64 _amountSD) public view {
212
+ uint256 result = harness0_0.toLD(_amountSD);
213
+ assertEq(result, uint256(_amountSD));
214
+ }
215
+
216
+ // ============ To Shared Decimals Tests ============
217
+
218
+ function test_toSD_18_6() public view {
219
+ uint256 amountLD = 1e18;
220
+ uint64 result = harness18_6.toSD(amountLD);
221
+ assertEq(result, 1e6);
222
+ }
223
+
224
+ function test_toSD_18_6_Zero() public view {
225
+ uint64 result = harness18_6.toSD(0);
226
+ assertEq(result, 0);
227
+ }
228
+
229
+ function test_toSD_18_6_Truncates() public view {
230
+ uint256 amountLD = 1e18 + 999999999999;
231
+ uint64 result = harness18_6.toSD(amountLD);
232
+ assertEq(result, 1e6);
233
+ }
234
+
235
+ function test_toSD_18_6_LessThanConversionRate() public view {
236
+ uint256 amountLD = 1e11;
237
+ uint64 result = harness18_6.toSD(amountLD);
238
+ assertEq(result, 0);
239
+ }
240
+
241
+ function test_toSD_6_6() public view {
242
+ uint256 amountLD = 123456;
243
+ uint64 result = harness6_6.toSD(amountLD);
244
+ assertEq(result, 123456);
245
+ }
246
+
247
+ function test_toSD_8_6() public view {
248
+ uint256 amountLD = 1e8;
249
+ uint64 result = harness8_6.toSD(amountLD);
250
+ assertEq(result, 1e6);
251
+ }
252
+
253
+ function test_toSD_0_0() public view {
254
+ uint256 amountLD = 1234;
255
+ uint64 result = harness0_0.toSD(amountLD);
256
+ assertEq(result, amountLD);
257
+ }
258
+
259
+ function test_toSD_Fuzz_18_6(uint104 _amountLD) public view {
260
+ uint256 amountLD = uint256(_amountLD);
261
+ vm.assume(amountLD <= uint256(type(uint64).max) * 1e12);
262
+ uint64 result = harness18_6.toSD(amountLD);
263
+ assertEq(result, amountLD / harness18_6.decimalConversionRate());
264
+ }
265
+
266
+ function test_toSD_Fuzz_6_6(uint64 _amountLD) public view {
267
+ uint256 amountLD = uint256(_amountLD);
268
+ uint64 result = harness6_6.toSD(amountLD);
269
+ assertEq(result, amountLD);
270
+ }
271
+
272
+ function test_toSD_Fuzz_8_6(uint72 _amountLD) public view {
273
+ uint256 amountLD = uint256(_amountLD);
274
+ vm.assume(amountLD <= uint256(type(uint64).max) * 100);
275
+ uint64 result = harness8_6.toSD(amountLD);
276
+ assertEq(result, amountLD / 100);
277
+ }
278
+
279
+ function test_toSD_Fuzz_0_0(uint64 _amountLD) public view {
280
+ uint256 amountLD = uint256(_amountLD);
281
+ uint64 result = harness0_0.toSD(amountLD);
282
+ assertEq(result, amountLD);
283
+ }
284
+
285
+ function test_toSD_Revert_AmountSDOverflowed_18_6() public {
286
+ uint256 amountLD = uint256(type(uint64).max) * 1e12 + 1e12;
287
+ uint256 expectedAmountSD = amountLD / 1e12;
288
+
289
+ vm.expectRevert(abi.encodeWithSelector(IOFTDecimalUtils.AmountSDOverflowed.selector, expectedAmountSD));
290
+ harness18_6.toSD(amountLD);
291
+ }
292
+
293
+ function test_toSD_Revert_AmountSDOverflowed_6_6() public {
294
+ uint256 amountLD = uint256(type(uint64).max) + 1;
295
+
296
+ vm.expectRevert(abi.encodeWithSelector(IOFTDecimalUtils.AmountSDOverflowed.selector, amountLD));
297
+ harness6_6.toSD(amountLD);
298
+ }
299
+
300
+ function test_toSD_Revert_AmountSDOverflowed_0_0() public {
301
+ uint256 amountLD = uint256(type(uint64).max) + 1;
302
+
303
+ vm.expectRevert(abi.encodeWithSelector(IOFTDecimalUtils.AmountSDOverflowed.selector, amountLD));
304
+ harness0_0.toSD(amountLD);
305
+ }
306
+
307
+ function test_toSD_Fuzz_Revert_AmountSDOverflowed_18_6(uint256 _amountLD) public {
308
+ uint256 maxAmountLD = uint256(type(uint64).max) * 1e12 + (1e12 - 1);
309
+ vm.assume(_amountLD > maxAmountLD);
310
+
311
+ uint256 expectedAmountSD = _amountLD / 1e12;
312
+ vm.expectRevert(abi.encodeWithSelector(IOFTDecimalUtils.AmountSDOverflowed.selector, expectedAmountSD));
313
+ harness18_6.toSD(_amountLD);
314
+ }
315
+
316
+ function test_toSD_Fuzz_Revert_AmountSDOverflowed_6_6(uint256 _amountLD) public {
317
+ vm.assume(_amountLD > type(uint64).max);
318
+
319
+ vm.expectRevert(abi.encodeWithSelector(IOFTDecimalUtils.AmountSDOverflowed.selector, _amountLD));
320
+ harness6_6.toSD(_amountLD);
321
+ }
322
+
323
+ // ============ Roundtrip Tests ============
324
+
325
+ function test_Roundtrip_toSD_toLD_18_6() public view {
326
+ uint256 amountLD = 12345678901234567890;
327
+ uint256 dustRemoved = harness18_6.removeDust(amountLD);
328
+ uint64 amountSD = harness18_6.toSD(amountLD);
329
+ uint256 amountLDBack = harness18_6.toLD(amountSD);
330
+ assertEq(amountLDBack, dustRemoved);
331
+ }
332
+
333
+ function test_Roundtrip_toLD_toSD_18_6() public view {
334
+ uint64 amountSD = 123456;
335
+ uint256 amountLD = harness18_6.toLD(amountSD);
336
+ uint64 amountSDBack = harness18_6.toSD(amountLD);
337
+ assertEq(amountSDBack, amountSD);
338
+ }
339
+
340
+ function test_Roundtrip_Fuzz_toSD_toLD_18_6(uint104 _amountLD) public view {
341
+ uint256 amountLD = uint256(_amountLD);
342
+ vm.assume(amountLD <= uint256(type(uint64).max) * 1e12);
343
+ uint256 dustRemoved = harness18_6.removeDust(amountLD);
344
+ uint64 amountSD = harness18_6.toSD(amountLD);
345
+ uint256 amountLDBack = harness18_6.toLD(amountSD);
346
+ assertEq(amountLDBack, dustRemoved);
347
+ }
348
+
349
+ function test_Roundtrip_Fuzz_toLD_toSD_18_6(uint64 _amountSD) public view {
350
+ uint256 amountLD = harness18_6.toLD(_amountSD);
351
+ uint64 amountSDBack = harness18_6.toSD(amountLD);
352
+ assertEq(amountSDBack, _amountSD);
353
+ }
354
+ }