@coti-io/coti-contracts 1.2.0 → 1.3.0

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 (267) hide show
  1. package/.github/workflows/npm-publish.yml +1 -1
  2. package/contracts/messaging/PrivateMessaging.sol +456 -0
  3. package/contracts/mocks/messaging/PrivateMessagingHarness.sol +54 -0
  4. package/contracts/mocks/oracle/CotiPriceConsumerMock.sol +31 -0
  5. package/contracts/mocks/token/ERC20DecimalsMock.sol +21 -0
  6. package/contracts/mocks/token/PrivateERC20/PrivacyBridgeERC20Mock.sol +8 -3
  7. package/contracts/node/SoulboundNodeNFT.sol +22 -22
  8. package/contracts/oracle/CotiPriceConsumer.sol +103 -0
  9. package/contracts/oracle/ICotiPriceConsumer.sol +15 -0
  10. package/contracts/oracle/IStdReference.sol +26 -0
  11. package/contracts/privacyBridge/PrivacyBridge.sol +373 -91
  12. package/contracts/privacyBridge/PrivacyBridgeCotiNative.sol +209 -161
  13. package/contracts/privacyBridge/PrivacyBridgeERC20.sol +241 -159
  14. package/contracts/privacyBridge/PrivacyBridgeUSDCe.sol +7 -1
  15. package/contracts/privacyBridge/PrivacyBridgeUSDT.sol +7 -1
  16. package/contracts/privacyBridge/PrivacyBridgeWADA.sol +7 -1
  17. package/contracts/privacyBridge/PrivacyBridgeWBTC.sol +7 -1
  18. package/contracts/privacyBridge/PrivacyBridgeWETH.sol +7 -1
  19. package/contracts/privacyBridge/PrivacyBridgegCoti.sol +7 -1
  20. package/hardhat.config.ts +5 -2
  21. package/package.json +2 -2
  22. package/scripts/add-bridge-operators.cjs +87 -0
  23. package/scripts/deploy-coti-price-consumer-mainnet.cjs +49 -0
  24. package/scripts/deployCotiNodeRewards.ts +51 -0
  25. package/scripts/redeploy-private-and-bridges.cjs +201 -0
  26. package/scripts/set-bridge-limits-mainnet.cjs +177 -0
  27. package/scripts/verify-mainnet-private-bridges.cjs +289 -0
  28. package/sonar-project.properties +11 -0
  29. package/test/messaging/PrivateMessaging.test.ts +158 -0
  30. package/test/privacyBridge/UnifiedPrivacyBridges.test.cjs +1663 -0
  31. package/test/token/PrivateERC20/PrivacyBridge.fees.test.ts +162 -239
  32. package/typechain-types/@openzeppelin/contracts/access/AccessControl.ts +324 -0
  33. package/typechain-types/@openzeppelin/contracts/access/AccessControlEnumerable.ts +361 -0
  34. package/typechain-types/@openzeppelin/contracts/access/IAccessControl.ts +292 -0
  35. package/typechain-types/@openzeppelin/contracts/access/IAccessControlEnumerable.ts +329 -0
  36. package/typechain-types/@openzeppelin/contracts/access/index.ts +4 -0
  37. package/typechain-types/@openzeppelin/contracts/index.ts +2 -0
  38. package/typechain-types/@openzeppelin/contracts/security/Pausable.ts +150 -0
  39. package/typechain-types/@openzeppelin/contracts/security/index.ts +4 -0
  40. package/typechain-types/@openzeppelin/contracts/token/ERC20/ERC20.ts +330 -0
  41. package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.ts +286 -0
  42. package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/index.ts +1 -0
  43. package/typechain-types/@openzeppelin/contracts/token/ERC20/index.ts +1 -0
  44. package/typechain-types/@openzeppelin/contracts/token/ERC721/ERC721.ts +420 -0
  45. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.ts +420 -0
  46. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/index.ts +4 -0
  47. package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +3 -0
  48. package/typechain-types/contracts/disperse/coinByRatio/FixedRatioCoinDisperserLeftoverS1.ts +735 -0
  49. package/typechain-types/contracts/disperse/coinByRatio/FixedRatioCoinDisperserUnlimitedWindow.ts +734 -0
  50. package/typechain-types/contracts/disperse/coinByRatio/index.ts +2 -0
  51. package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/IOwnable.ts +95 -0
  52. package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser.ts +22 -0
  53. package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +1 -0
  54. package/typechain-types/contracts/index.ts +8 -0
  55. package/typechain-types/contracts/messaging/PrivateMessaging.ts +871 -0
  56. package/typechain-types/contracts/messaging/index.ts +4 -0
  57. package/typechain-types/contracts/mocks/index.ts +4 -0
  58. package/typechain-types/contracts/mocks/messaging/PrivateMessagingHarness.ts +951 -0
  59. package/typechain-types/contracts/mocks/messaging/index.ts +4 -0
  60. package/typechain-types/contracts/mocks/oracle/CotiPriceConsumerMock.ts +163 -0
  61. package/typechain-types/contracts/mocks/oracle/index.ts +4 -0
  62. package/typechain-types/contracts/mocks/token/ERC20DecimalsMock.ts +349 -0
  63. package/typechain-types/contracts/mocks/token/ERC20Mock.ts +368 -0
  64. package/typechain-types/contracts/mocks/token/PrivateERC20/EncryptedTokenReceiverMock.ts +108 -0
  65. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivacyBridgeERC20Mock.ts +1892 -0
  66. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20AuditorSupplyMock.ts +1296 -0
  67. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20CappedMock.ts +1270 -0
  68. package/typechain-types/contracts/mocks/{utils/mpc/Bitwise128BitTestsContract.ts → token/PrivateERC20/PrivateERC20GtCallerMock.ts} +47 -67
  69. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +757 -25
  70. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol/IPrivateERC20TransferAndCallEncrypted.ts +102 -0
  71. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol/PrivateERC20ReentrantReceiverMock.ts +154 -0
  72. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol/index.ts +5 -0
  73. package/typechain-types/contracts/mocks/token/PrivateERC20/PublicReentrantTokenReceiverMock.ts +155 -0
  74. package/typechain-types/contracts/mocks/token/PrivateERC20/PublicTokenReceiverBoolMock.ts +107 -0
  75. package/typechain-types/contracts/mocks/token/PrivateERC20/PublicTokenReceiverMock.ts +100 -0
  76. package/typechain-types/contracts/mocks/token/PrivateERC20/index.ts +10 -0
  77. package/typechain-types/contracts/mocks/token/index.ts +2 -0
  78. package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.ts +6 -6
  79. package/typechain-types/contracts/node/CotiNodeRewards.ts +566 -0
  80. package/typechain-types/contracts/node/SoulboundNodeNFT.sol/IERC5192.ts +123 -0
  81. package/typechain-types/contracts/node/SoulboundNodeNFT.sol/SoulboundNodeNFT.ts +975 -0
  82. package/typechain-types/contracts/node/SoulboundNodeNFT.sol/index.ts +5 -0
  83. package/typechain-types/contracts/node/index.ts +6 -0
  84. package/typechain-types/contracts/oracle/CotiPriceConsumer.ts +256 -0
  85. package/typechain-types/contracts/oracle/ICotiPriceConsumer.ts +119 -0
  86. package/typechain-types/contracts/oracle/IStdReference.ts +136 -0
  87. package/typechain-types/contracts/oracle/index.ts +6 -0
  88. package/typechain-types/contracts/privacyBridge/PrivacyBridge.ts +1628 -0
  89. package/typechain-types/contracts/privacyBridge/PrivacyBridgeCotiNative.ts +1870 -0
  90. package/typechain-types/contracts/privacyBridge/PrivacyBridgeERC20.sol/IHasDecimals.ts +84 -0
  91. package/typechain-types/contracts/privacyBridge/PrivacyBridgeERC20.sol/PrivacyBridgeERC20.ts +1892 -0
  92. package/typechain-types/contracts/privacyBridge/PrivacyBridgeERC20.sol/index.ts +5 -0
  93. package/typechain-types/contracts/privacyBridge/PrivacyBridgeUSDCe.ts +1892 -0
  94. package/typechain-types/contracts/privacyBridge/PrivacyBridgeUSDT.ts +1892 -0
  95. package/typechain-types/contracts/privacyBridge/PrivacyBridgeWADA.ts +1892 -0
  96. package/typechain-types/contracts/privacyBridge/PrivacyBridgeWBTC.ts +1892 -0
  97. package/typechain-types/contracts/privacyBridge/PrivacyBridgeWETH.ts +1892 -0
  98. package/typechain-types/contracts/privacyBridge/PrivacyBridgegCoti.ts +1892 -0
  99. package/typechain-types/contracts/privacyBridge/index.ts +13 -0
  100. package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +439 -19
  101. package/typechain-types/contracts/token/PrivateERC20/ITokenReceiver.ts +100 -0
  102. package/typechain-types/contracts/token/PrivateERC20/ITokenReceiverEncrypted.ts +99 -0
  103. package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +763 -15
  104. package/typechain-types/contracts/token/PrivateERC20/index.ts +4 -0
  105. package/typechain-types/contracts/token/PrivateERC20/tokens/PrivateBridgedUSDC.ts +1270 -0
  106. package/typechain-types/contracts/token/PrivateERC20/tokens/PrivateCOTI.ts +1270 -0
  107. package/typechain-types/contracts/token/PrivateERC20/tokens/PrivateCOTITreasuryGovernanceToken.ts +1270 -0
  108. package/typechain-types/contracts/token/PrivateERC20/tokens/PrivateTetherUSD.ts +1270 -0
  109. package/typechain-types/contracts/token/PrivateERC20/tokens/PrivateWrappedADA.ts +1270 -0
  110. package/typechain-types/contracts/token/PrivateERC20/tokens/PrivateWrappedBTC.ts +1270 -0
  111. package/typechain-types/contracts/token/PrivateERC20/tokens/PrivateWrappedEther.ts +1270 -0
  112. package/typechain-types/contracts/token/PrivateERC20/tokens/index.ts +10 -0
  113. package/typechain-types/factories/@openzeppelin/contracts/access/AccessControlEnumerable__factory.ts +276 -0
  114. package/typechain-types/factories/@openzeppelin/contracts/access/AccessControl__factory.ts +229 -0
  115. package/typechain-types/factories/@openzeppelin/contracts/access/IAccessControlEnumerable__factory.ts +244 -0
  116. package/typechain-types/factories/@openzeppelin/contracts/access/IAccessControl__factory.ts +197 -0
  117. package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +4 -0
  118. package/typechain-types/factories/@openzeppelin/contracts/index.ts +1 -0
  119. package/typechain-types/factories/@openzeppelin/contracts/security/Pausable__factory.ts +61 -0
  120. package/typechain-types/factories/@openzeppelin/contracts/security/index.ts +4 -0
  121. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/ERC20__factory.ts +356 -0
  122. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata__factory.ts +247 -0
  123. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.ts +1 -0
  124. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.ts +1 -0
  125. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/ERC721__factory.ts +416 -0
  126. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata__factory.ts +355 -0
  127. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/index.ts +4 -0
  128. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +2 -0
  129. package/typechain-types/factories/contracts/disperse/coinByRatio/FixedRatioCoinDisperserLeftoverS1__factory.ts +791 -0
  130. package/typechain-types/factories/contracts/disperse/coinByRatio/FixedRatioCoinDisperserUnlimitedWindow__factory.ts +711 -0
  131. package/typechain-types/factories/contracts/disperse/coinByRatio/FixedRatioCoinDisperser__factory.ts +1 -1
  132. package/typechain-types/factories/contracts/disperse/coinByRatio/index.ts +2 -0
  133. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/IOwnable__factory.ts +35 -0
  134. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser__factory.ts +19 -1
  135. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +1 -0
  136. package/typechain-types/factories/contracts/disperse/disperseToken/TokenDisperser__factory.ts +1 -1
  137. package/typechain-types/factories/contracts/index.ts +4 -0
  138. package/typechain-types/factories/contracts/messaging/PrivateMessaging__factory.ts +1035 -0
  139. package/typechain-types/factories/contracts/messaging/index.ts +4 -0
  140. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
  141. package/typechain-types/factories/contracts/mocks/index.ts +2 -0
  142. package/typechain-types/factories/contracts/mocks/messaging/PrivateMessagingHarness__factory.ts +1161 -0
  143. package/typechain-types/factories/contracts/mocks/messaging/index.ts +4 -0
  144. package/typechain-types/factories/contracts/mocks/oracle/CotiPriceConsumerMock__factory.ts +159 -0
  145. package/typechain-types/factories/contracts/mocks/oracle/index.ts +4 -0
  146. package/typechain-types/factories/contracts/mocks/token/ERC20DecimalsMock__factory.ts +394 -0
  147. package/typechain-types/factories/contracts/mocks/token/ERC20Mock__factory.ts +392 -0
  148. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/EncryptedTokenReceiverMock__factory.ts +125 -0
  149. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivacyBridgeERC20Mock__factory.ts +1797 -0
  150. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20AuditorSupplyMock__factory.ts +1514 -0
  151. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20CappedMock__factory.ts +1466 -0
  152. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20GtCallerMock__factory.ts +165 -0
  153. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +771 -55
  154. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol/IPrivateERC20TransferAndCallEncrypted__factory.ts +54 -0
  155. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol/PrivateERC20ReentrantReceiverMock__factory.ts +159 -0
  156. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol/index.ts +5 -0
  157. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PublicReentrantTokenReceiverMock__factory.ts +164 -0
  158. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PublicTokenReceiverBoolMock__factory.ts +130 -0
  159. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PublicTokenReceiverMock__factory.ts +102 -0
  160. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/index.ts +9 -0
  161. package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
  162. package/typechain-types/factories/contracts/mocks/token/index.ts +2 -0
  163. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128TestsContract__factory.ts +1 -1
  164. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256TestsContract__factory.ts +1 -1
  165. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +1 -1
  166. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128TestsContract__factory.ts +1 -1
  167. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256TestsContract__factory.ts +1 -1
  168. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +1 -1
  169. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract__factory.ts +1 -1
  170. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract__factory.ts +1 -1
  171. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/CheckedArithmeticWithOverflowBitTestsContract__factory.ts +1 -1
  172. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128TestsContract__factory.ts +1 -1
  173. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
  174. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256TestsContract__factory.ts +1 -1
  175. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +1 -1
  176. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax128TestsContract__factory.ts +1 -1
  177. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax256TestsContract__factory.ts +1 -1
  178. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
  179. package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalImplementation__factory.ts +1 -1
  180. package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalProxy__factory.ts +1 -1
  181. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
  182. package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
  183. package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperations128TestContract__factory.ts +1 -1
  184. package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperationsTestContract__factory.ts +1 -1
  185. package/typechain-types/factories/contracts/mocks/utils/mpc/Mux128TestsContract__factory.ts +1 -1
  186. package/typechain-types/factories/contracts/mocks/utils/mpc/Mux256TestsContract__factory.ts +1 -1
  187. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +1 -1
  188. package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard128TestsContract__factory.ts +1 -1
  189. package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard256TestsContract__factory.ts +1 -1
  190. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV1__factory.ts +1 -1
  191. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV2__factory.ts +1 -1
  192. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyProxy__factory.ts +1 -1
  193. package/typechain-types/factories/contracts/mocks/utils/mpc/Random128TestsContract__factory.ts +1 -1
  194. package/typechain-types/factories/contracts/mocks/utils/mpc/Random256TestsContract__factory.ts +1 -1
  195. package/typechain-types/factories/contracts/mocks/utils/mpc/Shift128TestsContract__factory.ts +1 -1
  196. package/typechain-types/factories/contracts/mocks/utils/mpc/Shift256TestsContract__factory.ts +1 -1
  197. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
  198. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
  199. package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer128TestsContract__factory.ts +1 -1
  200. package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer256TestsContract__factory.ts +1 -1
  201. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
  202. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
  203. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract__factory.ts +1 -1
  204. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract__factory.ts +1 -1
  205. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +1 -1
  206. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +1 -1
  207. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +1 -1
  208. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +1 -1
  209. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +1 -1
  210. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +1 -1
  211. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract__factory.ts +1 -1
  212. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract__factory.ts +1 -1
  213. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract__factory.ts +1 -1
  214. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +4 -22
  215. package/typechain-types/factories/contracts/node/CotiNodeRewards__factory.ts +549 -0
  216. package/typechain-types/factories/contracts/node/SoulboundNodeNFT.sol/IERC5192__factory.ts +54 -0
  217. package/typechain-types/factories/contracts/node/SoulboundNodeNFT.sol/SoulboundNodeNFT__factory.ts +947 -0
  218. package/typechain-types/factories/contracts/node/SoulboundNodeNFT.sol/index.ts +5 -0
  219. package/typechain-types/factories/contracts/node/index.ts +5 -0
  220. package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +1 -1
  221. package/typechain-types/factories/contracts/oracle/CotiPriceConsumer__factory.ts +295 -0
  222. package/typechain-types/factories/contracts/oracle/ICotiPriceConsumer__factory.ts +73 -0
  223. package/typechain-types/factories/contracts/oracle/IStdReference__factory.ts +107 -0
  224. package/typechain-types/factories/contracts/oracle/index.ts +6 -0
  225. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeCotiNative__factory.ts +1676 -0
  226. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeERC20.sol/IHasDecimals__factory.ts +38 -0
  227. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeERC20.sol/PrivacyBridgeERC20__factory.ts +1678 -0
  228. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeERC20.sol/index.ts +5 -0
  229. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeUSDCe__factory.ts +1782 -0
  230. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeUSDT__factory.ts +1782 -0
  231. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeWADA__factory.ts +1782 -0
  232. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeWBTC__factory.ts +1782 -0
  233. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgeWETH__factory.ts +1782 -0
  234. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridge__factory.ts +1367 -0
  235. package/typechain-types/factories/contracts/privacyBridge/PrivacyBridgegCoti__factory.ts +1782 -0
  236. package/typechain-types/factories/contracts/privacyBridge/index.ts +12 -0
  237. package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +481 -35
  238. package/typechain-types/factories/contracts/token/PrivateERC20/ITokenReceiverEncrypted__factory.ts +53 -0
  239. package/typechain-types/factories/contracts/token/PrivateERC20/ITokenReceiver__factory.ts +54 -0
  240. package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +793 -59
  241. package/typechain-types/factories/contracts/token/PrivateERC20/index.ts +3 -0
  242. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/PrivateBridgedUSDC__factory.ts +1445 -0
  243. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/PrivateCOTITreasuryGovernanceToken__factory.ts +1451 -0
  244. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/PrivateCOTI__factory.ts +1442 -0
  245. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/PrivateTetherUSD__factory.ts +1445 -0
  246. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/PrivateWrappedADA__factory.ts +1445 -0
  247. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/PrivateWrappedBTC__factory.ts +1445 -0
  248. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/PrivateWrappedEther__factory.ts +1451 -0
  249. package/typechain-types/factories/contracts/token/PrivateERC20/tokens/index.ts +10 -0
  250. package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +1 -1
  251. package/typechain-types/hardhat.d.ts +953 -17
  252. package/typechain-types/index.ts +104 -0
  253. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.ts +0 -341
  254. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.ts +0 -347
  255. package/typechain-types/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.ts +0 -186
  256. package/typechain-types/contracts/mocks/utils/mpc/Comparison128BitTestsContract.ts +0 -260
  257. package/typechain-types/contracts/mocks/utils/mpc/Comparison256BitTestsContract.ts +0 -260
  258. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.ts +0 -302
  259. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.ts +0 -322
  260. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract__factory.ts +0 -349
  261. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract__factory.ts +0 -364
  262. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128BitTestsContract__factory.ts +0 -182
  263. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256BitTestsContract__factory.ts +0 -182
  264. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128BitTestsContract__factory.ts +0 -255
  265. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256BitTestsContract__factory.ts +0 -255
  266. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract__factory.ts +0 -332
  267. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract__factory.ts +0 -380
@@ -2,200 +2,216 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import "./PrivacyBridge.sol";
5
+ import "@openzeppelin/contracts/utils/math/Math.sol";
5
6
  import "../token/PrivateERC20/tokens/PrivateCOTI.sol";
6
- import "../token/PrivateERC20/ITokenReceiver.sol";
7
- import "../utils/mpc/MpcCore.sol";
8
7
 
9
8
  /**
10
9
  * @title PrivacyBridgeCotiNative
11
10
  * @notice Bridge contract for converting between native COTI and privacy-preserving COTI.p tokens
11
+ * @dev Withdraw pulls private balance via `IPrivateERC20(address(privateCoti)).transferFrom` so the call matches
12
+ * the canonical {IPrivateERC20} surface (`contracts/token/PrivateERC20/IPrivateERC20.sol`) while `privateCoti`
13
+ * remains the concrete {PrivateCOTI} type for mint/burn. Deploy `_privateCoti` as that implementation (or a
14
+ * fully ABI-compatible successor); do not point at arbitrary ERC-20s.
15
+ *
16
+ * **Two native deposit paths (document for wallets / indexers):**
17
+ * - {deposit(uint256,uint256)}: user passes `cotiOracleTimestamp` and `tokenOracleTimestamp` (same value
18
+ * twice for `"COTI"`); {_validateOracleTimestamps} enforces they match the on-chain Band row—same quote row
19
+ * as {estimateDepositFee}. Use this when you need binding between off-chain estimate and execution.
20
+ * - {receive} / plain ETH send: uses {_directDeposit}; fee still uses {_computeCotiFee} with staleness
21
+ * ({_requireOracleFreshness}) but **does not** require equality to estimate timestamps—no prior estimate row
22
+ * is pinned. Prefer explicit {deposit} for predictable “what I quoted is what executes.”
23
+ *
24
+ * **Unsolicited native:** balance can increase via `selfdestruct` or other forced transfers without invoking
25
+ * {receive}; that ETH does not mint private tokens and does not update {PrivacyBridge.totalUserLiability}.
12
26
  */
13
- contract PrivacyBridgeCotiNative is PrivacyBridge, ITokenReceiver {
27
+ contract PrivacyBridgeCotiNative is PrivacyBridge {
14
28
  PrivateCOTI public privateCoti;
15
29
 
16
- error ExceedsRescueableAmount();
30
+ event NativeRescued(address indexed to, uint256 amount);
17
31
 
18
32
  // Scaling factor removed (using native 18 decimals due to uint256 upgrade)
19
33
 
20
34
  /**
21
35
  * @notice Initialize the Native Bridge
22
36
  * @param _privateCoti Address of the PrivateCoti token contract
37
+ * @param _priceOracle Non-zero price oracle (see {PrivacyBridge}'s constructor)
23
38
  */
24
- constructor(address _privateCoti) PrivacyBridge() {
39
+ constructor(address _privateCoti, address _feeRecipient, address _rescueRecipient, address _priceOracle) PrivacyBridge(_feeRecipient, _rescueRecipient, _priceOracle) {
25
40
  if (_privateCoti == address(0)) revert InvalidAddress();
26
41
  privateCoti = PrivateCOTI(_privateCoti);
27
42
  }
28
43
 
29
44
  /**
30
- * @notice Internal function to handle deposits
31
- * @param sender Address of the depositor
45
+ * @dev Native COTI fee math + one {getPriceWithMeta("COTI")} read. Used by {_computeCotiFee} and
46
+ * {estimateDepositFee}/{estimateWithdrawFee}. Each {Math.mulDiv} truncates toward zero (see
47
+ * {PrivacyBridge.FEE_DIVISOR} NatSpec). Extreme `cotiAmount`×`cotiUsdRate` values can make {Math.mulDiv}
48
+ * revert—keep amounts within configured max deposit/withdraw limits.
49
+ * @param cotiAmount Amount in COTI wei the fee is computed for
50
+ * @param fixedFee Minimum fee floor in COTI wei
51
+ * @param percentageBps Percentage parameter scaled by {PrivacyBridge.FEE_DIVISOR}
52
+ * @param maxFee Maximum fee cap in COTI wei
53
+ * @return fee Computed fee in COTI wei
54
+ * @return cotiLastUpdated COTI oracle row `lastUpdated`
55
+ * @return blockTimestamp Third field from the COTI oracle row
32
56
  */
33
- function _deposit(
34
- address sender,
35
- bool isEncrypted,
36
- itUint256 memory encryptedAmount
37
- ) internal {
38
- if (!isDepositEnabled) revert DepositDisabled();
39
- if (msg.value == 0) revert AmountZero();
40
-
41
- _checkDepositLimits(msg.value);
42
-
43
- // Calculate and deduct deposit fee
44
- uint256 feeAmount = _calculateFeeAmount(
45
- msg.value,
46
- depositFeeBasisPoints
47
- );
48
- uint256 amountAfterFee = msg.value - feeAmount;
49
- accumulatedFees += feeAmount;
50
-
51
- if (isEncrypted) {
52
- // Verify parity between msg.value and encrypted amount
53
- gtUint256 gtAmount = MpcCore.validateCiphertext(encryptedAmount);
54
- gtBool amountMatch = MpcCore.eq(
55
- gtAmount,
56
- MpcCore.setPublic256(amountAfterFee)
57
- );
58
- require(MpcCore.decrypt(amountMatch), "Encrypted amount mismatch");
59
-
60
- privateCoti.mintGt(sender, gtAmount);
61
- } else {
62
- privateCoti.mint(sender, amountAfterFee);
63
- }
57
+ function _computeCotiFeeAndMeta(
58
+ uint256 cotiAmount,
59
+ uint256 fixedFee,
60
+ uint256 percentageBps,
61
+ uint256 maxFee
62
+ ) internal view returns (uint256 fee, uint256 cotiLastUpdated, uint256 blockTimestamp) {
63
+ _requirePriceOracle();
64
+ (uint256 cotiUsdRate, uint256 cotiLU, uint256 cotiBts) = ICotiPriceConsumer(priceOracle).getPriceWithMeta("COTI");
65
+ _requirePositiveOracleRate(cotiUsdRate);
66
+ _requireOracleFreshness(cotiLU);
67
+ uint256 txValueUsd = Math.mulDiv(cotiAmount, cotiUsdRate, 1e18);
68
+ uint256 percentageFeeUsd = Math.mulDiv(txValueUsd, percentageBps, FEE_DIVISOR);
69
+ uint256 percentageFeeCoti = Math.mulDiv(percentageFeeUsd, 1e18, cotiUsdRate);
70
+ fee = _calculateDynamicFee(percentageFeeCoti, fixedFee, maxFee);
71
+ cotiLastUpdated = cotiLU;
72
+ blockTimestamp = cotiBts;
73
+ }
64
74
 
65
- // Emit gross deposit amount and net private tokens minted
66
- emit Deposit(sender, msg.value, amountAfterFee);
75
+ function _computeCotiFee(
76
+ uint256 cotiAmount,
77
+ uint256 fixedFee,
78
+ uint256 percentageBps,
79
+ uint256 maxFee
80
+ ) internal view returns (uint256) {
81
+ (uint256 f,,) = _computeCotiFeeAndMeta(cotiAmount, fixedFee, percentageBps, maxFee);
82
+ return f;
67
83
  }
68
84
 
69
85
  /**
70
- * @notice Deposit native COTI to receive private COTI (COTI.p)
71
- * @dev User sends native COTI with the transaction
86
+ * @notice Simulate fee calculation for native COTI with arbitrary parameters.
87
+ * @dev Public view allows frontends/operators to preview fees with custom fee params.
88
+ * Reads live COTI oracle price but accepts custom fee configuration.
89
+ * @param cotiAmount The COTI amount to compute fee for (wei; very large values can revert in fee math)
90
+ * @param fixedFee The minimum fee floor in COTI wei
91
+ * @param percentageBps The percentage in basis points (relative to {FEE_DIVISOR})
92
+ * @param maxFee The maximum fee cap in COTI wei
93
+ * @return The computed fee in COTI wei
72
94
  */
73
- function deposit() external payable nonReentrant whenNotPaused {
74
- _deposit(
75
- msg.sender,
76
- false,
77
- itUint256(ctUint256(ctUint128.wrap(0), ctUint128.wrap(0)), "")
78
- );
95
+ function computeCotiFee(
96
+ uint256 cotiAmount,
97
+ uint256 fixedFee,
98
+ uint256 percentageBps,
99
+ uint256 maxFee
100
+ ) external view returns (uint256) {
101
+ return _computeCotiFee(cotiAmount, fixedFee, percentageBps, maxFee);
79
102
  }
80
103
 
81
104
  /**
82
- * @notice Deposit native COTI with an encrypted amount for the private minting event
83
- * @param encryptedAmount Encrypted amount to mint
105
+ * @notice Estimate the deposit fee in COTI for a given COTI amount
106
+ * @param cotiAmount The amount of native COTI to deposit (wei; very large values can revert in fee math)
107
+ * @return fee The estimated fee in COTI wei
108
+ * @return cotiLastUpdated COTI oracle data last update timestamp
109
+ * @return blockTimestamp Third field from the COTI oracle row (same as pre-refactor behavior)
110
+ * @dev Use `cotiLastUpdated` for **both** `cotiOracleTimestamp` and `tokenOracleTimestamp` on {deposit}/{withdraw}
111
+ * (native bridge validates `"COTI"` twice). See {PrivacyBridge._validateOracleTimestamps}.
84
112
  */
85
- function deposit(itUint256 calldata encryptedAmount) external payable nonReentrant whenNotPaused {
86
- _deposit(msg.sender, true, encryptedAmount);
113
+ function estimateDepositFee(uint256 cotiAmount) external view returns (uint256 fee, uint256 cotiLastUpdated, uint256 blockTimestamp) {
114
+ (fee, cotiLastUpdated, blockTimestamp) = _computeCotiFeeAndMeta(
115
+ cotiAmount,
116
+ depositFixedFee,
117
+ depositPercentageBps,
118
+ depositMaxFee
119
+ );
87
120
  }
88
121
 
89
122
  /**
90
- * @notice Withdraw native COTI by burning private COTI
91
- * @param amount Amount of private COTI to burn
92
- * @dev User must have approved the bridge to spend their private tokens.
123
+ * @notice Estimate the withdrawal fee in COTI for a given COTI amount
124
+ * @param cotiAmount The amount of native COTI to withdraw (wei; very large values can revert in fee math)
125
+ * @return fee The estimated fee in COTI wei
126
+ * @return cotiLastUpdated COTI oracle data last update timestamp
127
+ * @return blockTimestamp Third field from the COTI oracle row (same as pre-refactor behavior)
128
+ * @dev Same timestamp usage as {estimateDepositFee} for the subsequent {withdraw}.
93
129
  */
130
+ function estimateWithdrawFee(uint256 cotiAmount) external view returns (uint256 fee, uint256 cotiLastUpdated, uint256 blockTimestamp) {
131
+ (fee, cotiLastUpdated, blockTimestamp) = _computeCotiFeeAndMeta(
132
+ cotiAmount,
133
+ withdrawFixedFee,
134
+ withdrawPercentageBps,
135
+ withdrawMaxFee
136
+ );
137
+ }
138
+
94
139
  /**
95
- * @notice Handle callback from PrivateCoti.transferAndCall
96
- * @dev Called when user transfers tokens to the bridge to withdraw. Third parameter (data) is required by ITokenReceiver but unused.
97
- * @param from Address of the sender
98
- * @param amount Amount of tokens received
140
+ * @notice Internal function to handle deposits
141
+ * @param sender Address of the depositor
99
142
  */
100
- function onTokenReceived(
101
- address from,
102
- uint256 amount,
103
- bytes calldata
104
- ) external nonReentrant whenNotPaused returns (bool) {
105
- if (msg.sender != address(privateCoti)) revert InvalidAddress();
106
- if (amount == 0) revert AmountZero();
107
-
108
- _checkWithdrawLimits(amount);
143
+ function _deposit(address sender, uint256 cotiOracleTimestamp, uint256 tokenOracleTimestamp) internal {
144
+ if (!isDepositEnabled) revert DepositDisabled();
145
+ if (msg.value == 0) revert AmountZero();
109
146
 
110
- // Calculate fee
111
- uint256 feeAmount = _calculateFeeAmount(amount, withdrawFeeBasisPoints);
112
- uint256 publicAmount = amount - feeAmount;
113
- accumulatedFees += feeAmount;
147
+ _checkDepositLimits(msg.value);
148
+ _validateOracleTimestamps(cotiOracleTimestamp, tokenOracleTimestamp, "COTI");
114
149
 
115
- if (address(this).balance < publicAmount)
116
- revert InsufficientEthBalance();
150
+ // Compute dynamic fee in COTI
151
+ uint256 fee = _computeCotiFee(msg.value, depositFixedFee, depositPercentageBps, depositMaxFee);
152
+ uint256 netAmount = msg.value - fee;
153
+ if (netAmount == 0) revert AmountZero();
117
154
 
118
- // Private tokens are already transferred to this contract by transferAndCall
119
- // We just need to burn them.
120
- privateCoti.burn(amount);
155
+ accumulatedCotiFees += fee;
121
156
 
122
- (bool success, ) = from.call{value: publicAmount}("");
123
- if (!success) revert EthTransferFailed();
157
+ totalUserLiability += netAmount;
158
+ privateCoti.mint(sender, netAmount);
124
159
 
125
- // Emit gross private amount burned and net native COTI sent
126
- emit Withdraw(from, amount, publicAmount);
127
- return true;
160
+ // Emit gross deposit amount and net private tokens minted
161
+ emit Deposit(sender, msg.value, netAmount);
128
162
  }
129
163
 
130
164
  /**
131
- * @notice Withdraw native COTI by burning private COTI
132
- * @param amount Amount of private COTI to burn
133
- * @dev User must have approved the bridge to spend their private tokens.
165
+ * @notice Deposit native COTI to receive private COTI (COTI.p)
166
+ * @param cotiOracleTimestamp COTI `lastUpdated` from the latest `estimateDepositFee` (must still equal on-chain at execution).
167
+ * @param tokenOracleTimestamp Same value as `cotiOracleTimestamp` for this bridge (both checks use `"COTI"`).
168
+ * @dev User sends native COTI with the transaction. Oracle races: {OracleTimestampMismatch} — re-estimate; see {_validateOracleTimestamps}.
134
169
  */
135
- function withdraw(uint256 amount) external nonReentrant whenNotPaused {
136
- _withdraw(
137
- msg.sender,
138
- amount,
139
- false,
140
- itUint256(ctUint256(ctUint128.wrap(0), ctUint128.wrap(0)), "")
141
- );
170
+ function deposit(uint256 cotiOracleTimestamp, uint256 tokenOracleTimestamp) external payable nonReentrant whenNotPaused notBlacklisted {
171
+ _deposit(msg.sender, cotiOracleTimestamp, tokenOracleTimestamp);
142
172
  }
143
173
 
144
174
  /**
145
- * @notice Withdraw native COTI by burning private COTI with an encrypted amount
146
- * @param amount Public amount to release
147
- * @param encryptedAmount Encrypted amount to burn
175
+ * @notice Withdraw native COTI by burning private COTI
176
+ * @param amount Amount of private COTI to burn
177
+ * @param cotiOracleTimestamp COTI `lastUpdated` from the latest `estimateWithdrawFee` (must still equal on-chain at execution).
178
+ * @param tokenOracleTimestamp Same value as `cotiOracleTimestamp` for this bridge.
179
+ * @dev User must have approved the bridge to spend their private tokens. Oracle rules: {_validateOracleTimestamps}.
148
180
  */
149
- function withdraw(
150
- uint256 amount,
151
- itUint256 calldata encryptedAmount
152
- ) external nonReentrant whenNotPaused {
153
- _withdraw(msg.sender, amount, true, encryptedAmount);
181
+ function withdraw(uint256 amount, uint256 cotiOracleTimestamp, uint256 tokenOracleTimestamp) external nonReentrant whenNotPaused notBlacklisted {
182
+ _withdraw(msg.sender, amount, cotiOracleTimestamp, tokenOracleTimestamp);
154
183
  }
155
184
 
156
185
  function _withdraw(
157
186
  address to,
158
187
  uint256 amount,
159
- bool isEncrypted,
160
- itUint256 memory encryptedAmount
188
+ uint256 cotiOracleTimestamp,
189
+ uint256 tokenOracleTimestamp
161
190
  ) internal {
162
191
  if (amount == 0) revert AmountZero();
163
192
  _checkWithdrawLimits(amount);
193
+ _validateOracleTimestamps(cotiOracleTimestamp, tokenOracleTimestamp, "COTI");
164
194
 
165
- // Calculate fee on the public side
166
- uint256 feeAmount = _calculateFeeAmount(amount, withdrawFeeBasisPoints);
167
- uint256 publicAmount = amount - feeAmount;
168
- accumulatedFees += feeAmount;
195
+ // Compute dynamic withdrawal fee in COTI
196
+ uint256 fee = _computeCotiFee(amount, withdrawFixedFee, withdrawPercentageBps, withdrawMaxFee);
197
+ uint256 publicAmount = amount - fee;
198
+ if (publicAmount == 0) revert AmountZero();
199
+
200
+ accumulatedCotiFees += fee;
169
201
 
170
202
  if (address(this).balance < publicAmount)
171
203
  revert InsufficientEthBalance();
172
204
 
173
- if (isEncrypted) {
174
- // Verify parity
175
- gtUint256 gtAmount = MpcCore.validateCiphertext(encryptedAmount);
176
- gtBool amountMatch = MpcCore.eq(
177
- gtAmount,
178
- MpcCore.setPublic256(amount)
179
- );
180
- require(MpcCore.decrypt(amountMatch), "Encrypted amount mismatch");
181
-
182
- // Use already-validated gt handle so PrivateCOTI does not re-call
183
- // validateCiphertext with a different contract context (signature mismatch)
184
- IPrivateERC20(address(privateCoti)).transferFromGT(
185
- msg.sender,
186
- address(this),
187
- gtAmount
188
- );
189
- privateCoti.burnGt(gtAmount);
190
- } else {
191
- // Standard withdrawal (public amount)
192
- IPrivateERC20(address(privateCoti)).transferFrom(
193
- msg.sender,
194
- address(this),
195
- amount
196
- );
197
- privateCoti.burn(amount);
198
- }
205
+ // Extinguish liability for the full private amount burned (fee stays with bridge as native revenue).
206
+ totalUserLiability -= amount;
207
+
208
+ // Pull and burn private tokens
209
+ IPrivateERC20(address(privateCoti)).transferFrom(
210
+ msg.sender,
211
+ address(this),
212
+ amount
213
+ );
214
+ privateCoti.burn(amount);
199
215
 
200
216
  (bool success, ) = to.call{value: publicAmount}("");
201
217
  if (!success) revert EthTransferFailed();
@@ -204,14 +220,38 @@ contract PrivacyBridgeCotiNative is PrivacyBridge, ITokenReceiver {
204
220
  }
205
221
 
206
222
  /**
207
- * @notice Fallback function to handle direct COTI transfers as deposits
223
+ * @notice Internal deposit without binding to a prior estimate’s oracle `lastUpdated` snapshot.
224
+ * @dev Used by {receive}. Fee uses {_computeCotiFee}, which still enforces: oracle configured
225
+ * ({PriceOracleNotSet}), non-zero COTI/USD rate ({InvalidOraclePrice}), and max age of
226
+ * `lastUpdated` when {PrivacyBridge.maxOracleAge} is set ({OraclePriceStale} /
227
+ * {OracleLastUpdatedInFuture}). What plain sends do **not** do is equality to timestamps
228
+ * passed into {deposit} from an off-chain estimate—users who need that binding should call {deposit}.
208
229
  */
209
- receive() external payable nonReentrant whenNotPaused {
210
- _deposit(
211
- msg.sender,
212
- false,
213
- itUint256(ctUint256(ctUint128.wrap(0), ctUint128.wrap(0)), "")
214
- );
230
+ function _directDeposit(address sender) internal {
231
+ if (!isDepositEnabled) revert DepositDisabled();
232
+ if (msg.value == 0) revert AmountZero();
233
+
234
+ _checkDepositLimits(msg.value);
235
+
236
+ uint256 fee = _computeCotiFee(msg.value, depositFixedFee, depositPercentageBps, depositMaxFee);
237
+ uint256 netAmount = msg.value - fee;
238
+ if (netAmount == 0) revert AmountZero();
239
+
240
+ accumulatedCotiFees += fee;
241
+
242
+ totalUserLiability += netAmount;
243
+ privateCoti.mint(sender, netAmount);
244
+
245
+ emit Deposit(sender, msg.value, netAmount);
246
+ }
247
+
248
+ /**
249
+ * @notice Fallback for plain native transfers: same fee path as {_directDeposit}.
250
+ * @dev See {_directDeposit}: zero/stale oracle rates are rejected via {_computeCotiFee}; use {deposit}
251
+ * when you must match `lastUpdated` from {estimateDepositFee} to the on-chain row (see {_validateOracleTimestamps}).
252
+ */
253
+ receive() external payable nonReentrant whenNotPaused notBlacklisted {
254
+ _directDeposit(msg.sender);
215
255
  }
216
256
 
217
257
  /**
@@ -223,46 +263,54 @@ contract PrivacyBridgeCotiNative is PrivacyBridge, ITokenReceiver {
223
263
  }
224
264
 
225
265
  /**
226
- * @notice Withdraw accumulated fees (Native implementation)
227
- * @param to Address to send fees to
266
+ * @notice Withdraw accumulated fees to feeRecipient (Native implementation)
228
267
  * @param amount Amount of fees to withdraw
229
268
  * @dev Only the owner can call this function
230
269
  */
231
270
  function withdrawFees(
232
- address to,
233
271
  uint256 amount
234
- ) external override onlyOperator {
235
- if (to == address(0)) revert InvalidAddress();
272
+ ) external onlyOwner nonReentrant {
273
+ if (feeRecipient == address(0)) revert FeeRecipientNotSet();
236
274
  if (amount == 0) revert AmountZero();
237
- if (amount > accumulatedFees) revert InsufficientAccumulatedFees();
275
+ if (amount > accumulatedCotiFees) revert InsufficientAccumulatedFees();
238
276
  if (amount > address(this).balance) revert InsufficientEthBalance();
239
277
 
240
- accumulatedFees -= amount;
278
+ accumulatedCotiFees -= amount;
241
279
 
242
- // Transfer native COTI tokens
243
- (bool success, ) = to.call{value: amount}("");
280
+ // Transfer native COTI tokens to feeRecipient
281
+ (bool success, ) = feeRecipient.call{value: amount}("");
244
282
  if (!success) revert EthTransferFailed();
245
283
 
246
- emit FeesWithdrawn(to, amount);
284
+ emit FeesWithdrawn(feeRecipient, amount);
247
285
  }
248
286
 
249
287
  /**
250
- * @dev Rescue native COTI coins mistakenly sent to the contract.
251
- * Only excess over the accumulated fee reserve can be rescued.
252
- * Owner must NOT rescue amounts that would remove liquidity needed for user withdrawals;
253
- * doing so would break withdraw() and onTokenReceived() until new deposits restore balance.
254
- * @param to Address to send the coins to
255
- * @param amount Amount of coins to rescue
256
- * @notice Only the owner can call this function
288
+ * @notice Move native COTI from this bridge to {rescueRecipient} while the bridge is paused.
289
+ * @dev Emergency / migration path: sends up to `amount` (typically the full {address(this).balance}) to
290
+ * {rescueRecipient}. That balance can include all user-deposited native liquidity and unswept fee
291
+ * float—there is no on-chain carve-out that keeps “user principal” behind. Intended for bug recovery
292
+ * or handover to a new bridge; a malicious or compromised owner who has paused can drain TVL to
293
+ * {rescueRecipient} in one or more calls. See {PrivacyBridge} contract-level @dev (3) for governance
294
+ * mitigations (multisig, timelock, monitoring). After a partial rescue, {accumulatedCotiFees} is capped
295
+ * to the remaining balance so fee accounting cannot exceed what is still on the contract. {totalUserLiability}
296
+ * is **not** adjusted: rescue only moves native to {rescueRecipient}; it does not burn private tokens or
297
+ * reduce user obligations on this contract, so the counter may exceed {address(this).balance} until a
298
+ * separate migration makes users whole.
299
+ * @param amount Amount of native currency to send (often the full balance for migration).
257
300
  */
258
- function rescueNative(address to, uint256 amount) external onlyOwner {
259
- if (to == address(0)) revert InvalidAddress();
301
+ function rescueNative(uint256 amount) external onlyOwner nonReentrant whenPaused {
260
302
  if (amount == 0) revert AmountZero();
261
303
  if (amount > address(this).balance) revert InsufficientEthBalance();
262
- if (address(this).balance < accumulatedFees) revert InsufficientEthBalance();
263
- if (amount > address(this).balance - accumulatedFees) revert ExceedsRescueableAmount();
264
304
 
265
- (bool success, ) = to.call{value: amount}("");
305
+ (bool success, ) = rescueRecipient.call{value: amount}("");
266
306
  if (!success) revert EthTransferFailed();
307
+
308
+ uint256 remaining = address(this).balance;
309
+ if (accumulatedCotiFees > remaining) {
310
+ accumulatedCotiFees = remaining;
311
+ }
312
+
313
+ emit NativeRescued(rescueRecipient, amount);
267
314
  }
315
+
268
316
  }