@coti-io/coti-contracts 1.1.0 → 1.2.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.
- package/.github/workflows/npm-publish.yml +18 -14
- package/README.md +3 -1
- package/contracts/disperse/coinByRatio/FixedRatioCoinDisperser.sol +452 -0
- package/contracts/disperse/coinByRatio/FixedRatioCoinDisperserLeftoverS1.sol +490 -0
- package/contracts/disperse/coinByRatio/FixedRatioCoinDisperserUnlimitedWindow.sol +432 -0
- package/contracts/disperse/disperseToken/MintDisperser.sol +120 -0
- package/contracts/disperse/disperseToken/TokenDisperser.sol +139 -0
- package/contracts/mocks/token/ERC20Mock.sol +19 -0
- package/contracts/mocks/token/PrivateERC20/EncryptedTokenReceiverMock.sol +18 -0
- package/contracts/mocks/token/PrivateERC20/PrivacyBridgeERC20Mock.sol +13 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20AuditorSupplyMock.sol +44 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20CappedMock.sol +23 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20GtCallerMock.sol +29 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.sol +9 -4
- package/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol +39 -0
- package/contracts/mocks/token/PrivateERC20/PublicReentrantTokenReceiverMock.sol +29 -0
- package/contracts/mocks/token/PrivateERC20/PublicTokenReceiverBoolMock.sol +18 -0
- package/contracts/mocks/token/PrivateERC20/PublicTokenReceiverMock.sol +12 -0
- package/contracts/mocks/utils/mpc/Arithmetic128TestsContract.sol +123 -0
- package/contracts/mocks/utils/mpc/Arithmetic256TestsContract.sol +122 -0
- package/contracts/mocks/utils/mpc/Bitwise128TestsContract.sol +65 -0
- package/contracts/mocks/utils/mpc/Bitwise256TestsContract.sol +65 -0
- package/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract.sol +64 -0
- package/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract.sol +64 -0
- package/contracts/mocks/utils/mpc/Comparison128TestsContract.sol +98 -0
- package/contracts/mocks/utils/mpc/Comparison256TestsContract.sol +98 -0
- package/contracts/mocks/utils/mpc/MinMax128TestsContract.sol +44 -0
- package/contracts/mocks/utils/mpc/MinMax256TestsContract.sol +44 -0
- package/contracts/mocks/utils/mpc/MinimalImplementation.sol +55 -0
- package/contracts/mocks/utils/mpc/MinimalProxy.sol +27 -0
- package/contracts/mocks/utils/mpc/MpcOperations128TestContract.sol +267 -0
- package/contracts/mocks/utils/mpc/MpcOperationsTestContract.sol +334 -0
- package/contracts/mocks/utils/mpc/Mux128TestsContract.sol +24 -0
- package/contracts/mocks/utils/mpc/Mux256TestsContract.sol +24 -0
- package/contracts/mocks/utils/mpc/OnBoard128TestsContract.sol +93 -0
- package/contracts/mocks/utils/mpc/OnBoard256TestsContract.sol +116 -0
- package/contracts/mocks/utils/mpc/PrivacyImplementationV1.sol +157 -0
- package/contracts/mocks/utils/mpc/PrivacyImplementationV2.sol +133 -0
- package/contracts/mocks/utils/mpc/PrivacyProxy.sol +137 -0
- package/contracts/mocks/utils/mpc/Random128TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/Random256TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/Shift128TestsContract.sol +36 -0
- package/contracts/mocks/utils/mpc/Shift256TestsContract.sol +36 -0
- package/contracts/mocks/utils/mpc/Transfer128TestsContract.sol +29 -0
- package/contracts/mocks/utils/mpc/Transfer256TestsContract.sol +29 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract.sol +59 -0
- package/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract.sol +63 -0
- package/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract.sol +99 -0
- package/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.sol +7 -6
- package/contracts/node/CotiNodeRewards.sol +199 -0
- package/contracts/node/SoulboundNodeNFT.sol +519 -0
- package/contracts/privacyBridge/PrivacyBridge.sol +318 -0
- package/contracts/privacyBridge/PrivacyBridgeCotiNative.sol +268 -0
- package/contracts/privacyBridge/PrivacyBridgeERC20.sol +251 -0
- package/contracts/privacyBridge/PrivacyBridgeUSDCe.sol +16 -0
- package/contracts/privacyBridge/PrivacyBridgeUSDT.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgeWADA.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgeWBTC.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgeWETH.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgegCoti.sol +17 -0
- package/contracts/token/PrivateERC20/IPrivateERC20.sol +273 -40
- package/contracts/token/PrivateERC20/ITokenReceiver.sol +17 -0
- package/contracts/token/PrivateERC20/ITokenReceiverEncrypted.sol +20 -0
- package/contracts/token/PrivateERC20/PrivateERC20.sol +861 -152
- package/contracts/token/PrivateERC20/tokens/PrivateBridgedUSDC.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateCOTI.sol +13 -0
- package/contracts/token/PrivateERC20/tokens/PrivateCOTITreasuryGovernanceToken.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateTetherUSD.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateWrappedADA.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateWrappedBTC.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateWrappedEther.sol +13 -0
- package/contracts/utils/mpc/MpcCore.sol +10780 -4962
- package/contracts/utils/mpc/MpcInterface.sol +7 -2
- package/hardhat/gasPriceBump.ts +60 -0
- package/hardhat.config.ts +60 -12
- package/package.json +21 -3
- package/scripts/deploySoulboundNodeNFT.ts +57 -0
- package/test/token/PrivateERC20/PrivacyBridge.fees.test.ts +327 -0
- package/test/token/PrivateERC20/PrivateERC20.test.ts +1109 -268
- package/test/utils/mpc/Bitwise128.test.ts +92 -0
- package/test/utils/mpc/Bitwise256.test.ts +101 -0
- package/test/utils/mpc/BuildInputText128.test.ts +398 -0
- package/test/utils/mpc/CheckedArithmetic128.test.ts +45 -0
- package/test/utils/mpc/CheckedArithmetic256.test.ts +45 -0
- package/test/utils/mpc/Comparison128.test.ts +48 -0
- package/test/utils/mpc/Comparison256.test.ts +48 -0
- package/test/utils/mpc/InvalidCiphertext.test.ts +179 -0
- package/test/utils/mpc/InvalidCiphertext128.test.ts +179 -0
- package/test/utils/mpc/InvalidCiphertext256.test.ts +201 -0
- package/test/utils/mpc/InvalidTransfer128.test.ts +166 -0
- package/test/utils/mpc/InvalidTransfer256.test.ts +158 -0
- package/test/utils/mpc/MinMax128.test.ts +44 -0
- package/test/utils/mpc/MinMax256.test.ts +44 -0
- package/test/utils/mpc/MinimalProxyDemo.test.ts +280 -0
- package/test/utils/mpc/MpcOperations.test.ts +589 -0
- package/test/utils/mpc/MpcOperations128.test.ts +632 -0
- package/test/utils/mpc/Mux128.test.ts +41 -0
- package/test/utils/mpc/Mux256.test.ts +41 -0
- package/test/utils/mpc/NegativeCases.test.ts +478 -0
- package/test/utils/mpc/NegativeCases128.test.ts +237 -0
- package/test/utils/mpc/NegativeCases256.test.ts +236 -0
- package/test/utils/mpc/OnBoard128.test.ts +90 -0
- package/test/utils/mpc/OnBoard256.test.ts +114 -0
- package/test/utils/mpc/Precompile128.test.ts +51 -0
- package/test/utils/mpc/Precompile256.test.ts +115 -0
- package/test/utils/mpc/ProxyValidation.test.ts +199 -0
- package/test/utils/mpc/Random128.test.ts +47 -0
- package/test/utils/mpc/Random256.test.ts +47 -0
- package/test/utils/mpc/Shift128.test.ts +41 -0
- package/test/utils/mpc/Shift256.test.ts +41 -0
- package/test/utils/mpc/Transfer128.test.ts +46 -0
- package/test/utils/mpc/Transfer256.test.ts +46 -0
- package/test/utils/mpc/TransferWithAllowance128.test.ts +48 -0
- package/test/utils/mpc/TransferWithAllowance256.test.ts +48 -0
- package/test/utils/mpc/UpgradeablePrivacyProxy.test.ts +307 -0
- package/test/utils/mpc/ValidateCiphertext.test.ts +221 -0
- package/test/utils/mpc/ValidateCiphertext256.test.ts +161 -0
- package/test/utils/mpc/ValidateCiphertext256Decryption.test.ts +383 -0
- package/test/utils/mpc/WalletEncryptionFailures.test.ts +494 -0
- package/test/utils/privateErc20Helpers.ts +97 -0
- package/typechain-types/@openzeppelin/contracts/access/Ownable.ts +153 -0
- package/typechain-types/@openzeppelin/contracts/access/index.ts +4 -0
- package/typechain-types/@openzeppelin/contracts/index.ts +2 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/IERC20.ts +262 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.ts +143 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/index.ts +4 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/token/index.ts +2 -0
- package/typechain-types/contracts/disperse/coinByRatio/FixedRatioCoinDisperser.ts +679 -0
- package/typechain-types/contracts/disperse/coinByRatio/index.ts +4 -0
- package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/IMintableERC20.ts +97 -0
- package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser.ts +206 -0
- package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +5 -0
- package/typechain-types/contracts/disperse/disperseToken/TokenDisperser.ts +191 -0
- package/typechain-types/contracts/disperse/disperseToken/index.ts +6 -0
- package/typechain-types/contracts/disperse/index.ts +7 -0
- package/typechain-types/contracts/index.ts +2 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +77 -60
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128TestsContract.ts +311 -0
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256TestsContract.ts +311 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise128TestsContract.ts +179 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise256TestsContract.ts +179 -0
- package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract.ts +206 -0
- package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract.ts +206 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison128TestsContract.ts +278 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison256TestsContract.ts +278 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinMax128TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinMax256TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinimalImplementation.ts +259 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinimalProxy.ts +90 -0
- package/typechain-types/contracts/mocks/utils/mpc/MpcOperations128TestContract.ts +388 -0
- package/typechain-types/contracts/mocks/utils/mpc/MpcOperationsTestContract.ts +455 -0
- package/typechain-types/contracts/mocks/utils/mpc/Mux128TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/Mux256TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/OnBoard128TestsContract.ts +166 -0
- package/typechain-types/contracts/mocks/utils/mpc/OnBoard256TestsContract.ts +194 -0
- package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV1.ts +385 -0
- package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV2.ts +441 -0
- package/typechain-types/contracts/mocks/utils/mpc/PrivacyProxy.ts +201 -0
- package/typechain-types/contracts/mocks/utils/mpc/Random128TestsContract.ts +131 -0
- package/typechain-types/contracts/mocks/utils/mpc/Random256TestsContract.ts +131 -0
- package/typechain-types/contracts/mocks/utils/mpc/Shift128TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/Shift256TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/Transfer128TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/Transfer256TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract.ts +128 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract.ts +128 -0
- package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract.ts +198 -0
- package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract.ts +182 -0
- package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract.ts +257 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +32 -8
- package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +77 -60
- package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +77 -60
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +111 -10
- package/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.ts +74 -0
- package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/index.ts +1 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/IERC20__factory.ts +205 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit__factory.ts +100 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +1 -0
- package/typechain-types/factories/contracts/disperse/coinByRatio/FixedRatioCoinDisperser__factory.ts +759 -0
- package/typechain-types/factories/contracts/disperse/coinByRatio/index.ts +4 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/IMintableERC20__factory.ts +43 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser__factory.ts +185 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/TokenDisperser__factory.ts +198 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/index.ts +5 -0
- package/typechain-types/factories/contracts/disperse/index.ts +5 -0
- package/typechain-types/factories/contracts/index.ts +1 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +179 -47
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128TestsContract__factory.ts +330 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256TestsContract__factory.ts +330 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128TestsContract__factory.ts +184 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256TestsContract__factory.ts +184 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract__factory.ts +203 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract__factory.ts +203 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/CheckedArithmeticWithOverflowBitTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128TestsContract__factory.ts +295 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256TestsContract__factory.ts +295 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax128TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax256TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalImplementation__factory.ts +263 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalProxy__factory.ts +104 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperations128TestContract__factory.ts +723 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperationsTestContract__factory.ts +1410 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Mux128TestsContract__factory.ts +115 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Mux256TestsContract__factory.ts +115 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard128TestsContract__factory.ts +175 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard256TestsContract__factory.ts +205 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV1__factory.ts +521 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV2__factory.ts +648 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyProxy__factory.ts +179 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Random128TestsContract__factory.ts +131 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Random256TestsContract__factory.ts +131 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Shift128TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Shift256TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer128TestsContract__factory.ts +135 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer256TestsContract__factory.ts +135 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract__factory.ts +154 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract__factory.ts +154 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract__factory.ts +190 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract__factory.ts +210 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract__factory.ts +260 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +32 -8
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +7 -7
- package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +174 -42
- package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +174 -42
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +126 -0
- package/typechain-types/hardhat.d.ts +638 -80
- package/typechain-types/index.ts +78 -16
- package/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.sol +0 -260
- package/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.sol +0 -264
- package/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.sol +0 -91
- package/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.sol +0 -91
- package/contracts/mocks/utils/mpc/Comparison128BitTestsContract.sol +0 -158
- package/contracts/mocks/utils/mpc/Comparison256BitTestsContract.sol +0 -158
- package/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.sol +0 -185
- package/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.sol +0 -190
- package/contracts/mocks/utils/mpc/README.md +0 -486
- package/test/utils/mpc/Unsigned128BitIntegers.test.ts +0 -945
- package/test/utils/mpc/Unsigned256BitIntegers.test.ts +0 -1124
- package/test/utils/mpc/helpers.ts +0 -77
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
|
|
5
|
+
import "@openzeppelin/contracts/security/Pausable.sol";
|
|
6
|
+
import "@openzeppelin/contracts/access/Ownable.sol";
|
|
7
|
+
import "@openzeppelin/contracts/access/AccessControl.sol";
|
|
8
|
+
import "@openzeppelin/contracts/utils/math/Math.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @title PrivacyBridge
|
|
12
|
+
* @notice Base contract for Privacy Bridge contracts containing common logic
|
|
13
|
+
* @dev Trust assumptions: (1) MPC precompile at expected address is correct and non-malicious.
|
|
14
|
+
* (2) Private token implementation is trusted and only authorized minters can mint.
|
|
15
|
+
* (3) Owner operations (limits, fees, pause, withdraw fees, rescue) are centralized; consider timelock/multisig for sensitive actions.
|
|
16
|
+
* (4) Any new derived bridge must override withdrawFees to perform the actual transfer; base implementation reverts.
|
|
17
|
+
*/
|
|
18
|
+
abstract contract PrivacyBridge is ReentrancyGuard, Pausable, Ownable, AccessControl {
|
|
19
|
+
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
|
|
20
|
+
|
|
21
|
+
event OperatorAdded(address indexed account, address indexed by);
|
|
22
|
+
event OperatorRemoved(address indexed account, address indexed by);
|
|
23
|
+
event DepositEnabledUpdated(bool enabled, address indexed by);
|
|
24
|
+
event NativeCotiFeeUpdated(uint256 fee, address indexed by);
|
|
25
|
+
|
|
26
|
+
/// @notice Maximum amount that can be deposited in a single transaction
|
|
27
|
+
uint256 public maxDepositAmount;
|
|
28
|
+
|
|
29
|
+
/// @notice Maximum amount that can be withdrawn in a single transaction
|
|
30
|
+
uint256 public maxWithdrawAmount;
|
|
31
|
+
|
|
32
|
+
/// @notice Minimum amount required for a deposit
|
|
33
|
+
uint256 public minDepositAmount;
|
|
34
|
+
|
|
35
|
+
/// @notice Minimum amount required for a withdrawal
|
|
36
|
+
uint256 public minWithdrawAmount;
|
|
37
|
+
|
|
38
|
+
/// @notice Deposit fee in basis points (1 bp = 0.0001%, 1,000,000 = 100%)
|
|
39
|
+
uint256 public depositFeeBasisPoints;
|
|
40
|
+
|
|
41
|
+
/// @notice Withdrawal fee in basis points (1 bp = 0.0001%, 1,000,000 = 100%)
|
|
42
|
+
uint256 public withdrawFeeBasisPoints;
|
|
43
|
+
|
|
44
|
+
/// @notice Accumulated fees collected by the bridge (in bridged asset units)
|
|
45
|
+
uint256 public accumulatedFees;
|
|
46
|
+
|
|
47
|
+
/// @notice Accumulated native COTI fees (used only by ERC20 bridges for per-operation native fee; not used by native bridge)
|
|
48
|
+
uint256 public accumulatedCotiFees;
|
|
49
|
+
|
|
50
|
+
/// @notice Fee divisor (1,000,000)
|
|
51
|
+
uint256 public constant FEE_DIVISOR = 1000000;
|
|
52
|
+
|
|
53
|
+
/// @notice Maximum fee allowed (10% = 100,000 units)
|
|
54
|
+
uint256 public constant MAX_FEE_UNITS = 100000;
|
|
55
|
+
|
|
56
|
+
/// @notice Flag to enable/disable deposits
|
|
57
|
+
bool public isDepositEnabled = true;
|
|
58
|
+
|
|
59
|
+
/// @notice Fee in native COTI for bridge operations
|
|
60
|
+
uint256 public nativeCotiFee;
|
|
61
|
+
|
|
62
|
+
error AmountZero();
|
|
63
|
+
error InsufficientEthBalance();
|
|
64
|
+
error EthTransferFailed();
|
|
65
|
+
error InvalidAddress();
|
|
66
|
+
error DepositDisabled();
|
|
67
|
+
error InsufficientCotiFee();
|
|
68
|
+
error BridgePaused();
|
|
69
|
+
|
|
70
|
+
// Limits errors
|
|
71
|
+
error InvalidLimitConfiguration();
|
|
72
|
+
error DepositBelowMinimum();
|
|
73
|
+
error DepositExceedsMaximum();
|
|
74
|
+
error WithdrawBelowMinimum();
|
|
75
|
+
error WithdrawExceedsMaximum();
|
|
76
|
+
error InvalidFee();
|
|
77
|
+
error InsufficientAccumulatedFees();
|
|
78
|
+
error WithdrawFeesMustBeOverridden();
|
|
79
|
+
|
|
80
|
+
/// @notice Emitted when a user deposits tokens
|
|
81
|
+
/// @param user Address of the user
|
|
82
|
+
/// @param grossAmount Total amount provided by the user before fees
|
|
83
|
+
/// @param netAmount Net amount credited to the user after fees
|
|
84
|
+
event Deposit(address indexed user, uint256 grossAmount, uint256 netAmount);
|
|
85
|
+
|
|
86
|
+
/// @notice Emitted when a user withdraws tokens
|
|
87
|
+
/// @param user Address of the user
|
|
88
|
+
/// @param grossAmount Total amount of private tokens burned / requested
|
|
89
|
+
/// @param netAmount Net public/native amount sent to the user after fees
|
|
90
|
+
event Withdraw(address indexed user, uint256 grossAmount, uint256 netAmount);
|
|
91
|
+
|
|
92
|
+
/// @notice Emitted when deposit/withdrawal limits are updated
|
|
93
|
+
event LimitsUpdated(
|
|
94
|
+
uint256 minDeposit,
|
|
95
|
+
uint256 maxDeposit,
|
|
96
|
+
uint256 minWithdraw,
|
|
97
|
+
uint256 maxWithdraw
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
/// @notice Emitted when fees are updated
|
|
101
|
+
event FeeUpdated(string feeType, uint256 newFeeBasisPoints);
|
|
102
|
+
|
|
103
|
+
/// @notice Emitted when accumulated fees are withdrawn
|
|
104
|
+
event FeesWithdrawn(address indexed to, uint256 amount);
|
|
105
|
+
|
|
106
|
+
constructor() Ownable() {
|
|
107
|
+
maxDepositAmount = type(uint256).max;
|
|
108
|
+
maxWithdrawAmount = type(uint256).max;
|
|
109
|
+
minDepositAmount = 1;
|
|
110
|
+
minWithdrawAmount = 1;
|
|
111
|
+
|
|
112
|
+
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
|
113
|
+
_grantRole(OPERATOR_ROLE, msg.sender);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
modifier onlyOperator() {
|
|
117
|
+
_checkRole(OPERATOR_ROLE, msg.sender);
|
|
118
|
+
_;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function addOperator(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
122
|
+
if (account == address(0)) revert InvalidAddress();
|
|
123
|
+
_grantRole(OPERATOR_ROLE, account);
|
|
124
|
+
emit OperatorAdded(account, msg.sender);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function removeOperator(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
128
|
+
if (account == address(0)) revert InvalidAddress();
|
|
129
|
+
_revokeRole(OPERATOR_ROLE, account);
|
|
130
|
+
emit OperatorRemoved(account, msg.sender);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isOperator(address account) external view returns (bool) {
|
|
134
|
+
return hasRole(OPERATOR_ROLE, account);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @dev Overrides Ownable's transferOwnership to automatically grant roles to new owner
|
|
139
|
+
*/
|
|
140
|
+
function transferOwnership(address newOwner) public override onlyOwner {
|
|
141
|
+
if (newOwner == address(0)) revert InvalidAddress();
|
|
142
|
+
address oldOwner = owner();
|
|
143
|
+
super.transferOwnership(newOwner);
|
|
144
|
+
_grantRole(DEFAULT_ADMIN_ROLE, newOwner);
|
|
145
|
+
_grantRole(OPERATOR_ROLE, newOwner);
|
|
146
|
+
_revokeRole(DEFAULT_ADMIN_ROLE, oldOwner);
|
|
147
|
+
_revokeRole(OPERATOR_ROLE, oldOwner);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @notice Update deposit and withdrawal limits
|
|
152
|
+
* @dev Ensures min values are less than or equal to max values.
|
|
153
|
+
* Setting _maxDeposit or _maxWithdraw to 0 effectively disables deposits or withdrawals.
|
|
154
|
+
* @param _minDeposit New minimum deposit amount
|
|
155
|
+
* @param _maxDeposit New maximum deposit amount
|
|
156
|
+
* @param _minWithdraw New minimum withdrawal amount
|
|
157
|
+
* @param _maxWithdraw New maximum withdrawal amount
|
|
158
|
+
*/
|
|
159
|
+
function setLimits(
|
|
160
|
+
uint256 _minDeposit,
|
|
161
|
+
uint256 _maxDeposit,
|
|
162
|
+
uint256 _minWithdraw,
|
|
163
|
+
uint256 _maxWithdraw
|
|
164
|
+
) external onlyOwner {
|
|
165
|
+
if (_minDeposit > _maxDeposit) revert InvalidLimitConfiguration();
|
|
166
|
+
if (_minWithdraw > _maxWithdraw) revert InvalidLimitConfiguration();
|
|
167
|
+
minDepositAmount = _minDeposit;
|
|
168
|
+
maxDepositAmount = _maxDeposit;
|
|
169
|
+
minWithdrawAmount = _minWithdraw;
|
|
170
|
+
maxWithdrawAmount = _maxWithdraw;
|
|
171
|
+
|
|
172
|
+
emit LimitsUpdated(
|
|
173
|
+
_minDeposit,
|
|
174
|
+
_maxDeposit,
|
|
175
|
+
_minWithdraw,
|
|
176
|
+
_maxWithdraw
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @notice Pause the bridge, preventing deposits and withdrawals
|
|
182
|
+
* @dev Only the owner can call this function
|
|
183
|
+
*/
|
|
184
|
+
function pause() external onlyOwner {
|
|
185
|
+
_pause();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @notice Unpause the bridge, allowing deposits and withdrawals again
|
|
190
|
+
* @dev Only the owner can call this function
|
|
191
|
+
*/
|
|
192
|
+
function unpause() external onlyOwner {
|
|
193
|
+
_unpause();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @notice Check if a deposit amount is within configured limits
|
|
198
|
+
* @param amount The amount to check
|
|
199
|
+
* @dev Reverts if amount is below minimum or above maximum
|
|
200
|
+
*/
|
|
201
|
+
function _checkDepositLimits(uint256 amount) internal view {
|
|
202
|
+
if (amount < minDepositAmount) revert DepositBelowMinimum();
|
|
203
|
+
if (amount > maxDepositAmount) revert DepositExceedsMaximum();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @notice Check if a withdrawal amount is within configured limits
|
|
208
|
+
* @param amount The amount to check
|
|
209
|
+
* @dev Reverts if amount is below minimum or exceeds maximum withdrawal limit
|
|
210
|
+
*/
|
|
211
|
+
function _checkWithdrawLimits(uint256 amount) internal view {
|
|
212
|
+
if (amount < minWithdrawAmount) revert WithdrawBelowMinimum();
|
|
213
|
+
if (amount > maxWithdrawAmount) revert WithdrawExceedsMaximum();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @notice Set the deposit fee
|
|
218
|
+
* @param _feeBasisPoints New deposit fee in fee units (max 100,000 = 10%)
|
|
219
|
+
* @dev Only the operator can call this function
|
|
220
|
+
*/
|
|
221
|
+
function setDepositFee(uint256 _feeBasisPoints) external onlyOperator {
|
|
222
|
+
if (_feeBasisPoints > MAX_FEE_UNITS) revert InvalidFee();
|
|
223
|
+
depositFeeBasisPoints = _feeBasisPoints;
|
|
224
|
+
emit FeeUpdated("deposit", _feeBasisPoints);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @notice Set the withdrawal fee
|
|
229
|
+
* @param _feeBasisPoints New withdrawal fee in fee units (max 100,000 = 10%)
|
|
230
|
+
* @dev Only the operator can call this function
|
|
231
|
+
*/
|
|
232
|
+
function setWithdrawFee(uint256 _feeBasisPoints) external onlyOperator {
|
|
233
|
+
if (_feeBasisPoints > MAX_FEE_UNITS) revert InvalidFee();
|
|
234
|
+
withdrawFeeBasisPoints = _feeBasisPoints;
|
|
235
|
+
emit FeeUpdated("withdraw", _feeBasisPoints);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @notice Toggle deposit functionality
|
|
240
|
+
* @param _enabled True to enable, false to disable
|
|
241
|
+
* @dev Only the operator can call this function
|
|
242
|
+
*/
|
|
243
|
+
function setIsDepositEnabled(bool _enabled) external onlyOperator {
|
|
244
|
+
isDepositEnabled = _enabled;
|
|
245
|
+
emit DepositEnabledUpdated(_enabled, msg.sender);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @notice Set the native COTI fee
|
|
250
|
+
* @param _fee Amount in native tokens (wei-equivalent)
|
|
251
|
+
* @dev Used by ERC20 bridges: they require msg.value >= this value and refund excess to the caller (best-effort). Only the operator can call this function.
|
|
252
|
+
*/
|
|
253
|
+
function setNativeCotiFee(uint256 _fee) external onlyOperator {
|
|
254
|
+
nativeCotiFee = _fee;
|
|
255
|
+
emit NativeCotiFeeUpdated(_fee, msg.sender);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @notice Deposit preflight checks (for derived contracts)
|
|
260
|
+
* @dev Enforces pause state, deposit toggle, and amount limits.
|
|
261
|
+
*/
|
|
262
|
+
function _preflightDeposit(uint256 amount) internal view {
|
|
263
|
+
if (paused()) revert BridgePaused();
|
|
264
|
+
if (!isDepositEnabled) revert DepositDisabled();
|
|
265
|
+
_checkDepositLimits(amount);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @notice Calculate fee amount based on the input amount and fee basis points
|
|
271
|
+
* @param amount The amount to calculate fee for
|
|
272
|
+
* @param feeBasisPoints Fee in basis points (100 bp = 1%)
|
|
273
|
+
* @return The fee amount
|
|
274
|
+
*/
|
|
275
|
+
function _calculateFeeAmount(
|
|
276
|
+
uint256 amount,
|
|
277
|
+
uint256 feeBasisPoints
|
|
278
|
+
) internal pure returns (uint256) {
|
|
279
|
+
if (feeBasisPoints == 0) return 0;
|
|
280
|
+
return Math.mulDiv(amount, feeBasisPoints, FEE_DIVISOR);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @notice Withdraw accumulated fees
|
|
285
|
+
* @param to Address to send the fees to
|
|
286
|
+
* @param amount Amount of fees to withdraw
|
|
287
|
+
* @dev Only the operator can call this function. Must be overridden in derived contracts
|
|
288
|
+
* to perform the actual token/native transfer; base implementation reverts.
|
|
289
|
+
*/
|
|
290
|
+
function withdrawFees(
|
|
291
|
+
address to,
|
|
292
|
+
uint256 amount
|
|
293
|
+
) external virtual onlyOperator {
|
|
294
|
+
if (to == address(0)) revert InvalidAddress();
|
|
295
|
+
if (amount == 0) revert AmountZero();
|
|
296
|
+
if (amount > accumulatedFees) revert InsufficientAccumulatedFees();
|
|
297
|
+
revert WithdrawFeesMustBeOverridden();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* @notice Withdraw accumulated native COTI fees
|
|
302
|
+
* @param to Address to send the native COTI fees to
|
|
303
|
+
* @param amount Amount of native COTI fees to withdraw
|
|
304
|
+
* @dev Only the operator can call this function. Derived ERC20 bridges use this inherited implementation to withdraw
|
|
305
|
+
* accumulated native COTI fees; native bridge does not use this (accumulatedCotiFees remains 0).
|
|
306
|
+
*/
|
|
307
|
+
function withdrawCotiFees(address to, uint256 amount) external onlyOperator nonReentrant {
|
|
308
|
+
if (to == address(0)) revert InvalidAddress();
|
|
309
|
+
if (amount == 0) revert AmountZero();
|
|
310
|
+
if (amount > accumulatedCotiFees) revert InsufficientAccumulatedFees();
|
|
311
|
+
if (amount > address(this).balance) revert InsufficientEthBalance();
|
|
312
|
+
|
|
313
|
+
accumulatedCotiFees -= amount;
|
|
314
|
+
|
|
315
|
+
(bool success, ) = to.call{value: amount}("");
|
|
316
|
+
if (!success) revert EthTransferFailed();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "./PrivacyBridge.sol";
|
|
5
|
+
import "../token/PrivateERC20/tokens/PrivateCOTI.sol";
|
|
6
|
+
import "../token/PrivateERC20/ITokenReceiver.sol";
|
|
7
|
+
import "../utils/mpc/MpcCore.sol";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title PrivacyBridgeCotiNative
|
|
11
|
+
* @notice Bridge contract for converting between native COTI and privacy-preserving COTI.p tokens
|
|
12
|
+
*/
|
|
13
|
+
contract PrivacyBridgeCotiNative is PrivacyBridge, ITokenReceiver {
|
|
14
|
+
PrivateCOTI public privateCoti;
|
|
15
|
+
|
|
16
|
+
error ExceedsRescueableAmount();
|
|
17
|
+
|
|
18
|
+
// Scaling factor removed (using native 18 decimals due to uint256 upgrade)
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @notice Initialize the Native Bridge
|
|
22
|
+
* @param _privateCoti Address of the PrivateCoti token contract
|
|
23
|
+
*/
|
|
24
|
+
constructor(address _privateCoti) PrivacyBridge() {
|
|
25
|
+
if (_privateCoti == address(0)) revert InvalidAddress();
|
|
26
|
+
privateCoti = PrivateCOTI(_privateCoti);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @notice Internal function to handle deposits
|
|
31
|
+
* @param sender Address of the depositor
|
|
32
|
+
*/
|
|
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
|
+
}
|
|
64
|
+
|
|
65
|
+
// Emit gross deposit amount and net private tokens minted
|
|
66
|
+
emit Deposit(sender, msg.value, amountAfterFee);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @notice Deposit native COTI to receive private COTI (COTI.p)
|
|
71
|
+
* @dev User sends native COTI with the transaction
|
|
72
|
+
*/
|
|
73
|
+
function deposit() external payable nonReentrant whenNotPaused {
|
|
74
|
+
_deposit(
|
|
75
|
+
msg.sender,
|
|
76
|
+
false,
|
|
77
|
+
itUint256(ctUint256(ctUint128.wrap(0), ctUint128.wrap(0)), "")
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @notice Deposit native COTI with an encrypted amount for the private minting event
|
|
83
|
+
* @param encryptedAmount Encrypted amount to mint
|
|
84
|
+
*/
|
|
85
|
+
function deposit(itUint256 calldata encryptedAmount) external payable nonReentrant whenNotPaused {
|
|
86
|
+
_deposit(msg.sender, true, encryptedAmount);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
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.
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
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
|
|
99
|
+
*/
|
|
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);
|
|
109
|
+
|
|
110
|
+
// Calculate fee
|
|
111
|
+
uint256 feeAmount = _calculateFeeAmount(amount, withdrawFeeBasisPoints);
|
|
112
|
+
uint256 publicAmount = amount - feeAmount;
|
|
113
|
+
accumulatedFees += feeAmount;
|
|
114
|
+
|
|
115
|
+
if (address(this).balance < publicAmount)
|
|
116
|
+
revert InsufficientEthBalance();
|
|
117
|
+
|
|
118
|
+
// Private tokens are already transferred to this contract by transferAndCall
|
|
119
|
+
// We just need to burn them.
|
|
120
|
+
privateCoti.burn(amount);
|
|
121
|
+
|
|
122
|
+
(bool success, ) = from.call{value: publicAmount}("");
|
|
123
|
+
if (!success) revert EthTransferFailed();
|
|
124
|
+
|
|
125
|
+
// Emit gross private amount burned and net native COTI sent
|
|
126
|
+
emit Withdraw(from, amount, publicAmount);
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
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.
|
|
134
|
+
*/
|
|
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
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
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
|
|
148
|
+
*/
|
|
149
|
+
function withdraw(
|
|
150
|
+
uint256 amount,
|
|
151
|
+
itUint256 calldata encryptedAmount
|
|
152
|
+
) external nonReentrant whenNotPaused {
|
|
153
|
+
_withdraw(msg.sender, amount, true, encryptedAmount);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function _withdraw(
|
|
157
|
+
address to,
|
|
158
|
+
uint256 amount,
|
|
159
|
+
bool isEncrypted,
|
|
160
|
+
itUint256 memory encryptedAmount
|
|
161
|
+
) internal {
|
|
162
|
+
if (amount == 0) revert AmountZero();
|
|
163
|
+
_checkWithdrawLimits(amount);
|
|
164
|
+
|
|
165
|
+
// Calculate fee on the public side
|
|
166
|
+
uint256 feeAmount = _calculateFeeAmount(amount, withdrawFeeBasisPoints);
|
|
167
|
+
uint256 publicAmount = amount - feeAmount;
|
|
168
|
+
accumulatedFees += feeAmount;
|
|
169
|
+
|
|
170
|
+
if (address(this).balance < publicAmount)
|
|
171
|
+
revert InsufficientEthBalance();
|
|
172
|
+
|
|
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
|
+
}
|
|
199
|
+
|
|
200
|
+
(bool success, ) = to.call{value: publicAmount}("");
|
|
201
|
+
if (!success) revert EthTransferFailed();
|
|
202
|
+
|
|
203
|
+
emit Withdraw(to, amount, publicAmount);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @notice Fallback function to handle direct COTI transfers as deposits
|
|
208
|
+
*/
|
|
209
|
+
receive() external payable nonReentrant whenNotPaused {
|
|
210
|
+
_deposit(
|
|
211
|
+
msg.sender,
|
|
212
|
+
false,
|
|
213
|
+
itUint256(ctUint256(ctUint128.wrap(0), ctUint128.wrap(0)), "")
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @notice Get the native COTI balance held by the bridge
|
|
219
|
+
* @return The contract's balance in native units (wei-equivalent)
|
|
220
|
+
*/
|
|
221
|
+
function getBridgeBalance() external view returns (uint256) {
|
|
222
|
+
return address(this).balance;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @notice Withdraw accumulated fees (Native implementation)
|
|
227
|
+
* @param to Address to send fees to
|
|
228
|
+
* @param amount Amount of fees to withdraw
|
|
229
|
+
* @dev Only the owner can call this function
|
|
230
|
+
*/
|
|
231
|
+
function withdrawFees(
|
|
232
|
+
address to,
|
|
233
|
+
uint256 amount
|
|
234
|
+
) external override onlyOperator {
|
|
235
|
+
if (to == address(0)) revert InvalidAddress();
|
|
236
|
+
if (amount == 0) revert AmountZero();
|
|
237
|
+
if (amount > accumulatedFees) revert InsufficientAccumulatedFees();
|
|
238
|
+
if (amount > address(this).balance) revert InsufficientEthBalance();
|
|
239
|
+
|
|
240
|
+
accumulatedFees -= amount;
|
|
241
|
+
|
|
242
|
+
// Transfer native COTI tokens
|
|
243
|
+
(bool success, ) = to.call{value: amount}("");
|
|
244
|
+
if (!success) revert EthTransferFailed();
|
|
245
|
+
|
|
246
|
+
emit FeesWithdrawn(to, amount);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
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
|
|
257
|
+
*/
|
|
258
|
+
function rescueNative(address to, uint256 amount) external onlyOwner {
|
|
259
|
+
if (to == address(0)) revert InvalidAddress();
|
|
260
|
+
if (amount == 0) revert AmountZero();
|
|
261
|
+
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
|
+
|
|
265
|
+
(bool success, ) = to.call{value: amount}("");
|
|
266
|
+
if (!success) revert EthTransferFailed();
|
|
267
|
+
}
|
|
268
|
+
}
|