@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,36 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Shift128TestsContract {
|
|
7
|
+
uint128 shlResult;
|
|
8
|
+
uint128 shrResult;
|
|
9
|
+
|
|
10
|
+
function getShlResult() public view returns (uint128) {
|
|
11
|
+
return shlResult;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getShrResult() public view returns (uint128) {
|
|
15
|
+
return shrResult;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function shlTest(uint128 a, uint8 shift) public returns (uint128) {
|
|
19
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
20
|
+
|
|
21
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.shl(a128, shift)));
|
|
22
|
+
shlResult = result;
|
|
23
|
+
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function shrTest(uint128 a, uint8 shift) public returns (uint128) {
|
|
28
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
29
|
+
|
|
30
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.shr(a128, shift)));
|
|
31
|
+
shrResult = result;
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Shift256TestsContract {
|
|
7
|
+
uint256 shlResult;
|
|
8
|
+
uint256 shrResult;
|
|
9
|
+
|
|
10
|
+
function getShlResult() public view returns (uint256) {
|
|
11
|
+
return shlResult;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getShrResult() public view returns (uint256) {
|
|
15
|
+
return shrResult;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function shlTest(uint256 a, uint8 shift) public returns (uint256) {
|
|
19
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
20
|
+
|
|
21
|
+
uint256 result = MpcCore.decrypt(MpcCore.shl(a256, shift));
|
|
22
|
+
shlResult = result;
|
|
23
|
+
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function shrTest(uint256 a, uint8 shift) public returns (uint256) {
|
|
28
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
29
|
+
|
|
30
|
+
uint256 result = MpcCore.decrypt(MpcCore.shr(a256, shift));
|
|
31
|
+
shrResult = result;
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Transfer128TestsContract {
|
|
7
|
+
uint128 newA;
|
|
8
|
+
uint128 newB;
|
|
9
|
+
bool result;
|
|
10
|
+
|
|
11
|
+
function getResults() public view returns (uint128, uint128, bool) {
|
|
12
|
+
return (newA, newB, result);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function transferTest(uint128 a, uint128 b, uint128 amount) public returns (uint128, uint128, bool) {
|
|
16
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
17
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
18
|
+
gtUint128 amount128 = MpcCore.setPublic128(amount);
|
|
19
|
+
|
|
20
|
+
(gtUint128 newA128, gtUint128 newB128, gtBool res) = MpcCore.transfer(a128, b128, amount128);
|
|
21
|
+
|
|
22
|
+
newA = uint128(MpcCore.decrypt(newA128));
|
|
23
|
+
newB = uint128(MpcCore.decrypt(newB128));
|
|
24
|
+
result = MpcCore.decrypt(res);
|
|
25
|
+
|
|
26
|
+
return (newA, newB, result);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Transfer256TestsContract {
|
|
7
|
+
uint256 newA;
|
|
8
|
+
uint256 newB;
|
|
9
|
+
bool result;
|
|
10
|
+
|
|
11
|
+
function getResults() public view returns (uint256, uint256, bool) {
|
|
12
|
+
return (newA, newB, result);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function transferTest(uint256 a, uint256 b, uint256 amount) public returns (uint256, uint256, bool) {
|
|
16
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
17
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
18
|
+
gtUint256 amount256 = MpcCore.setPublic256(amount);
|
|
19
|
+
|
|
20
|
+
(gtUint256 newA256, gtUint256 newB256, gtBool res) = MpcCore.transfer(a256, b256, amount256);
|
|
21
|
+
|
|
22
|
+
newA = MpcCore.decrypt(newA256);
|
|
23
|
+
newB = MpcCore.decrypt(newB256);
|
|
24
|
+
result = MpcCore.decrypt(res);
|
|
25
|
+
|
|
26
|
+
return (newA, newB, result);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract TransferWithAllowance128TestsContract {
|
|
7
|
+
uint128 newA;
|
|
8
|
+
uint128 newB;
|
|
9
|
+
bool result;
|
|
10
|
+
uint128 newAllowance;
|
|
11
|
+
|
|
12
|
+
function getResults() public view returns (uint128, uint128, bool, uint128) {
|
|
13
|
+
return (newA, newB, result, newAllowance);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function transferWithAllowanceTest(uint128 a, uint128 b, uint128 amount, uint128 allowance) public returns (uint128, uint128, bool, uint128) {
|
|
17
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
18
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
19
|
+
gtUint128 amount128 = MpcCore.setPublic128(amount);
|
|
20
|
+
gtUint128 allowance128 = MpcCore.setPublic128(allowance);
|
|
21
|
+
|
|
22
|
+
(gtUint128 newA128, gtUint128 newB128, gtBool res, gtUint128 newAllowance128) = MpcCore.transferWithAllowance(a128, b128, amount128, allowance128);
|
|
23
|
+
|
|
24
|
+
newA = uint128(MpcCore.decrypt(newA128));
|
|
25
|
+
newB = uint128(MpcCore.decrypt(newB128));
|
|
26
|
+
result = MpcCore.decrypt(res);
|
|
27
|
+
newAllowance = uint128(MpcCore.decrypt(newAllowance128));
|
|
28
|
+
|
|
29
|
+
return (newA, newB, result, newAllowance);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract TransferWithAllowance256TestsContract {
|
|
7
|
+
uint256 newA;
|
|
8
|
+
uint256 newB;
|
|
9
|
+
bool result;
|
|
10
|
+
uint256 newAllowance;
|
|
11
|
+
|
|
12
|
+
function getResults() public view returns (uint256, uint256, bool, uint256) {
|
|
13
|
+
return (newA, newB, result, newAllowance);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function transferWithAllowanceTest(uint256 a, uint256 b, uint256 amount, uint256 allowance) public returns (uint256, uint256, bool, uint256) {
|
|
17
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
18
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
19
|
+
gtUint256 amount256 = MpcCore.setPublic256(amount);
|
|
20
|
+
gtUint256 allowance256 = MpcCore.setPublic256(allowance);
|
|
21
|
+
|
|
22
|
+
(gtUint256 newA256, gtUint256 newB256, gtBool res, gtUint256 newAllowance256) = MpcCore.transferWithAllowance(a256, b256, amount256, allowance256);
|
|
23
|
+
|
|
24
|
+
newA = MpcCore.decrypt(newA256);
|
|
25
|
+
newB = MpcCore.decrypt(newB256);
|
|
26
|
+
result = MpcCore.decrypt(res);
|
|
27
|
+
newAllowance = MpcCore.decrypt(newAllowance256);
|
|
28
|
+
|
|
29
|
+
return (newA, newB, result, newAllowance);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title ValidateCiphertext128TestsContract
|
|
8
|
+
* @notice Simple contract to test buildInputText with 128-bit values via Wallet.encryptValue
|
|
9
|
+
* @dev Validates itUint128 and returns ctUint128 via offBoardToUser
|
|
10
|
+
*/
|
|
11
|
+
contract ValidateCiphertext128TestsContract {
|
|
12
|
+
|
|
13
|
+
// Events
|
|
14
|
+
event ValueValidated(address indexed user, string operation);
|
|
15
|
+
event ValueOffBoarded128(address indexed user, ctUint128 result);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @dev Validates an encrypted uint128 input and returns it encrypted for user
|
|
19
|
+
* @param input The encrypted uint128 input (itUint128)
|
|
20
|
+
* @return The encrypted value for the user (ctUint128)
|
|
21
|
+
*/
|
|
22
|
+
function validateAndReturn(itUint128 calldata input) external returns (ctUint128) {
|
|
23
|
+
// Validate the ciphertext and convert to gtUint128
|
|
24
|
+
gtUint128 validatedValue = MpcCore.validateCiphertext(input);
|
|
25
|
+
|
|
26
|
+
emit ValueValidated(msg.sender, "validateAndReturn");
|
|
27
|
+
|
|
28
|
+
// OffBoard to user (GT → CT for user to decrypt)
|
|
29
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(validatedValue, msg.sender);
|
|
30
|
+
|
|
31
|
+
emit ValueOffBoarded128(msg.sender, ctResult);
|
|
32
|
+
|
|
33
|
+
return ctResult;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @dev Validates and adds two encrypted uint128 values
|
|
38
|
+
* @param a First encrypted value (itUint128)
|
|
39
|
+
* @param b Second encrypted value (itUint128)
|
|
40
|
+
* @return The result encrypted for the user (ctUint128)
|
|
41
|
+
*/
|
|
42
|
+
function validateAndAdd(itUint128 calldata a, itUint128 calldata b) external returns (ctUint128) {
|
|
43
|
+
// Validate both inputs
|
|
44
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
45
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
46
|
+
|
|
47
|
+
emit ValueValidated(msg.sender, "validateAndAdd");
|
|
48
|
+
|
|
49
|
+
// Perform addition
|
|
50
|
+
gtUint128 result = MpcCore.add(gtA, gtB);
|
|
51
|
+
|
|
52
|
+
// OffBoard to user
|
|
53
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, msg.sender);
|
|
54
|
+
|
|
55
|
+
emit ValueOffBoarded128(msg.sender, ctResult);
|
|
56
|
+
|
|
57
|
+
return ctResult;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract ValidateCiphertext256TestsContract {
|
|
7
|
+
uint256 storedValue;
|
|
8
|
+
bool validationResult;
|
|
9
|
+
ctUint256 storedEncryptedValue;
|
|
10
|
+
|
|
11
|
+
function getStoredValue() public view returns (uint256) {
|
|
12
|
+
return storedValue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getValidationResult() public view returns (bool) {
|
|
16
|
+
return validationResult;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getStoredEncryptedValue() public view returns (ctUint256 memory) {
|
|
20
|
+
return storedEncryptedValue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @dev Validates an encrypted uint256 input and stores the decrypted value
|
|
25
|
+
* @param input The encrypted uint256 input (itUint256)
|
|
26
|
+
* @return The decrypted uint256 value
|
|
27
|
+
*/
|
|
28
|
+
function validateAndStore(itUint256 memory input) public returns (uint256) {
|
|
29
|
+
// Validate the ciphertext and convert to gtUint256
|
|
30
|
+
gtUint256 validatedValue = MpcCore.validateCiphertext(input);
|
|
31
|
+
|
|
32
|
+
// Store the encrypted value as ctUint256 (offBoard from gtUint256)
|
|
33
|
+
storedEncryptedValue = MpcCore.offBoard(validatedValue);
|
|
34
|
+
|
|
35
|
+
// Decrypt the value to store it
|
|
36
|
+
uint256 decryptedValue = MpcCore.decrypt(validatedValue);
|
|
37
|
+
|
|
38
|
+
storedValue = decryptedValue;
|
|
39
|
+
validationResult = true;
|
|
40
|
+
|
|
41
|
+
return decryptedValue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @dev Validates an encrypted uint256 input and performs a simple operation (add 1)
|
|
46
|
+
* @param input The encrypted uint256 input (itUint256)
|
|
47
|
+
* @return The result after adding 1
|
|
48
|
+
*/
|
|
49
|
+
function validateAndIncrement(itUint256 memory input) public returns (uint256) {
|
|
50
|
+
// Validate the ciphertext and convert to gtUint256
|
|
51
|
+
gtUint256 validatedValue = MpcCore.validateCiphertext(input);
|
|
52
|
+
|
|
53
|
+
// Add 1 to the value
|
|
54
|
+
gtUint256 one = MpcCore.setPublic256(1);
|
|
55
|
+
gtUint256 result = MpcCore.add(validatedValue, one);
|
|
56
|
+
|
|
57
|
+
// Decrypt and return
|
|
58
|
+
uint256 decryptedResult = MpcCore.decrypt(result);
|
|
59
|
+
|
|
60
|
+
return decryptedResult;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title ValidateCiphertextTestsContract
|
|
8
|
+
* @notice Contract to test validateCiphertext for 8/16/32/64-bit values
|
|
9
|
+
* @dev Validates itUint (8/16/32/64-bit) and returns ctUint via offBoardToUser
|
|
10
|
+
*/
|
|
11
|
+
contract ValidateCiphertextTestsContract {
|
|
12
|
+
|
|
13
|
+
// Events
|
|
14
|
+
event ValueValidated(address indexed user, string operation);
|
|
15
|
+
event ValueOffBoarded(address indexed user, ctUint8 result);
|
|
16
|
+
|
|
17
|
+
uint8 storedValue;
|
|
18
|
+
bool validationResult;
|
|
19
|
+
ctUint8 storedEncryptedValue;
|
|
20
|
+
|
|
21
|
+
function getStoredValue() public view returns (uint8) {
|
|
22
|
+
return storedValue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getValidationResult() public view returns (bool) {
|
|
26
|
+
return validationResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getStoredEncryptedValue() public view returns (ctUint8) {
|
|
30
|
+
return storedEncryptedValue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @dev Validates an encrypted uint8 input and returns it encrypted for user
|
|
35
|
+
* @param input The encrypted input (itUint8)
|
|
36
|
+
* @return The encrypted value for the user (ctUint8)
|
|
37
|
+
*/
|
|
38
|
+
function validateAndReturn(itUint8 calldata input) external returns (ctUint8) {
|
|
39
|
+
// Validate the ciphertext and convert to gtUint8
|
|
40
|
+
gtUint8 validatedValue = MpcCore.validateCiphertext(input);
|
|
41
|
+
|
|
42
|
+
emit ValueValidated(msg.sender, "validateAndReturn");
|
|
43
|
+
|
|
44
|
+
// OffBoard to user (GT → CT for user to decrypt)
|
|
45
|
+
ctUint8 ctResult = MpcCore.offBoardToUser(validatedValue, msg.sender);
|
|
46
|
+
|
|
47
|
+
emit ValueOffBoarded(msg.sender, ctResult);
|
|
48
|
+
|
|
49
|
+
return ctResult;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @dev Validates an encrypted input and stores the decrypted value
|
|
54
|
+
* @param input The encrypted input (itUint8)
|
|
55
|
+
* @return The decrypted uint8 value
|
|
56
|
+
*/
|
|
57
|
+
function validateAndStore(itUint8 calldata input) external returns (uint8) {
|
|
58
|
+
// Validate the ciphertext and convert to gtUint8
|
|
59
|
+
gtUint8 validatedValue = MpcCore.validateCiphertext(input);
|
|
60
|
+
|
|
61
|
+
// Store the encrypted value as ctUint8 (offBoard from gtUint8)
|
|
62
|
+
storedEncryptedValue = MpcCore.offBoard(validatedValue);
|
|
63
|
+
|
|
64
|
+
// Decrypt the value to store it
|
|
65
|
+
uint8 decryptedValue = MpcCore.decrypt(validatedValue);
|
|
66
|
+
|
|
67
|
+
storedValue = decryptedValue;
|
|
68
|
+
validationResult = true;
|
|
69
|
+
|
|
70
|
+
emit ValueValidated(msg.sender, "validateAndStore");
|
|
71
|
+
|
|
72
|
+
return decryptedValue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @dev Validates and adds two encrypted values
|
|
77
|
+
* @param a First encrypted value (itUint8)
|
|
78
|
+
* @param b Second encrypted value (itUint8)
|
|
79
|
+
* @return The result encrypted for the user (ctUint8)
|
|
80
|
+
*/
|
|
81
|
+
function validateAndAdd(itUint8 calldata a, itUint8 calldata b) external returns (ctUint8) {
|
|
82
|
+
// Validate both inputs
|
|
83
|
+
gtUint8 gtA = MpcCore.validateCiphertext(a);
|
|
84
|
+
gtUint8 gtB = MpcCore.validateCiphertext(b);
|
|
85
|
+
|
|
86
|
+
emit ValueValidated(msg.sender, "validateAndAdd");
|
|
87
|
+
|
|
88
|
+
// Perform addition
|
|
89
|
+
gtUint8 result = MpcCore.add(gtA, gtB);
|
|
90
|
+
|
|
91
|
+
// OffBoard to user
|
|
92
|
+
ctUint8 ctResult = MpcCore.offBoardToUser(result, msg.sender);
|
|
93
|
+
|
|
94
|
+
emit ValueOffBoarded(msg.sender, ctResult);
|
|
95
|
+
|
|
96
|
+
return ctResult;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
pragma solidity ^0.8.19;
|
|
4
4
|
|
|
5
5
|
import "../../../token/PrivateERC20/IPrivateERC20.sol";
|
|
6
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
7
|
|
|
7
8
|
contract PrivateERC20WalletMock {
|
|
8
9
|
constructor() {}
|
|
@@ -11,15 +12,15 @@ contract PrivateERC20WalletMock {
|
|
|
11
12
|
return IPrivateERC20(token).setAccountEncryptionAddress(accountEncryptionAddress);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
function transfer(address token, address to,
|
|
15
|
-
|
|
15
|
+
function transfer(address token, address to, uint256 value) public {
|
|
16
|
+
IPrivateERC20(token).transfer(to, value);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
function approve(address token, address spender,
|
|
19
|
-
|
|
19
|
+
function approve(address token, address spender, uint256 value) public {
|
|
20
|
+
IPrivateERC20(token).approve(spender, value);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
function transferFrom(address token, address from, address to,
|
|
23
|
-
|
|
23
|
+
function transferFrom(address token, address from, address to, uint256 value) public {
|
|
24
|
+
IPrivateERC20(token).transferFrom(from, to, value);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
|
5
|
+
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title CotiNodeRewards
|
|
9
|
+
* @notice Manages eligibility rules and native COTI rewards for the COTI node ecosystem.
|
|
10
|
+
* @dev COTI is the chain's native token (like ETH). Owner funds the contract by sending native COTI,
|
|
11
|
+
* sets eligibility rules, allocates claimable rewards; users claim and receive native COTI.
|
|
12
|
+
* @dev Decimals: USDC = 6 ({DECIMALS_USDC}), native COTI = 18 ({DECIMALS_COTI}). Reward amounts are in COTI wei.
|
|
13
|
+
*/
|
|
14
|
+
contract CotiNodeRewards is Ownable, ReentrancyGuard {
|
|
15
|
+
|
|
16
|
+
// ============ Decimals ============
|
|
17
|
+
/// @notice USDC uses 6 decimals (amounts in eligibility rules for USDC are in 10^6 units)
|
|
18
|
+
uint8 public constant DECIMALS_USDC = 6;
|
|
19
|
+
/// @notice Native COTI uses 18 decimals (reward amounts and contract balance are in wei, 10^18 units)
|
|
20
|
+
uint8 public constant DECIMALS_COTI = 18;
|
|
21
|
+
|
|
22
|
+
// ============ Eligibility rules: rule name (bytes32) => value ============
|
|
23
|
+
/// @dev Use getEligibilityRule(string) or predefined keys (e.g. PLATFORM_USDC_AMOUNT)
|
|
24
|
+
mapping(bytes32 => uint256) public eligibilityRules;
|
|
25
|
+
|
|
26
|
+
/// @notice Predefined rule key: Platform USDC amount (value in USDC smallest unit, 6 decimals; e.g. 10 * 10^6 = 10 USDC)
|
|
27
|
+
bytes32 public constant RULE_PLATFORM_USDC_AMOUNT = keccak256("RULE_PLATFORM_USDC_AMOUNT");
|
|
28
|
+
/// @notice Predefined rule key: Platform COTI amount (value in COTI smallest unit, 18 decimals; e.g. 5e18 = 5 COTI)
|
|
29
|
+
bytes32 public constant RULE_PLATFORM_COTI_AMOUNT = keccak256("RULE_PLATFORM_COTI_AMOUNT");
|
|
30
|
+
/// @notice Predefined rule key: Full node uptime percentage threshold (e.g. 98 for 98%)
|
|
31
|
+
bytes32 public constant RULE_FULL_NODE_UPTIME_PERCENTAGE_THRESHOLD = keccak256("RULE_FULL_NODE_UPTIME_PERCENTAGE_THRESHOLD");
|
|
32
|
+
|
|
33
|
+
// ============ Reward state ============
|
|
34
|
+
/// @notice Per address: total COTI ever claimed by this address
|
|
35
|
+
mapping(address => uint256) public totalPerAddressClaimedCotiToken;
|
|
36
|
+
/// @notice Per address: COTI currently claimable (not yet claimed)
|
|
37
|
+
mapping(address => uint256) public totalPerAddressClaimableCotiToken;
|
|
38
|
+
/// @notice Per address: last epoch in which this wallet was rewarded (used to prevent double rewards per epoch)
|
|
39
|
+
mapping(address => uint256) public lastRewardEpoch;
|
|
40
|
+
|
|
41
|
+
/// @notice Total COTI ever allocated as claimable (sum of all rewards ever added)
|
|
42
|
+
uint256 public totalRewardedCoti;
|
|
43
|
+
/// @notice Total COTI ever claimed by all users
|
|
44
|
+
uint256 public totalClaimedCoti;
|
|
45
|
+
/// @notice Sum of all current claimable amounts (invariant: contract native balance must be >= this)
|
|
46
|
+
uint256 public totalClaimableCoti;
|
|
47
|
+
|
|
48
|
+
// ============ Events ============
|
|
49
|
+
event EligibilityRuleSet(bytes32 indexed ruleKey, uint256 value);
|
|
50
|
+
event RewardAdded(address indexed wallet, uint256 amount);
|
|
51
|
+
event Claimed(address indexed wallet, uint256 amount);
|
|
52
|
+
|
|
53
|
+
error ZeroAddress();
|
|
54
|
+
error ZeroAmount();
|
|
55
|
+
error InsufficientContractBalance();
|
|
56
|
+
error NothingToClaim();
|
|
57
|
+
error ArrayLengthMismatch();
|
|
58
|
+
error TransferFailed();
|
|
59
|
+
error AlreadyRewardedInEpoch(address wallet, uint256 epoch);
|
|
60
|
+
error InvalidEpoch(uint256 epoch);
|
|
61
|
+
|
|
62
|
+
constructor() Ownable() {
|
|
63
|
+
eligibilityRules[RULE_PLATFORM_COTI_AMOUNT] = 100_000 * 10**DECIMALS_COTI; // 100k COTI
|
|
64
|
+
eligibilityRules[RULE_PLATFORM_USDC_AMOUNT] = 50_000 * 10**DECIMALS_USDC; // 50k USDC
|
|
65
|
+
eligibilityRules[RULE_FULL_NODE_UPTIME_PERCENTAGE_THRESHOLD] = 98; // 98%
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// @notice Accept native COTI so the contract can be funded for rewards.
|
|
69
|
+
receive() external payable {}
|
|
70
|
+
|
|
71
|
+
// ============ Eligibility rules (owner) ============
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @notice Set an eligibility rule by key and value.
|
|
75
|
+
* @param ruleKey Rule identifier (use constants or keccak256("name"))
|
|
76
|
+
* @param value Rule value (e.g. threshold, amount in smallest units)
|
|
77
|
+
*/
|
|
78
|
+
function setEligibilityRule(bytes32 ruleKey, uint256 value) external onlyOwner {
|
|
79
|
+
eligibilityRules[ruleKey] = value;
|
|
80
|
+
emit EligibilityRuleSet(ruleKey, value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @notice Get eligibility rule value by string name (e.g. "Platform_USDC_amount").
|
|
85
|
+
*/
|
|
86
|
+
function getEligibilityRule(string calldata ruleName) external view returns (uint256) {
|
|
87
|
+
return eligibilityRules[keccak256(bytes(ruleName))];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ============ Reward allocation (owner) ============
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @dev Increases the claimable native COTI amount for a wallet for a specific epoch. Owner only.
|
|
94
|
+
* Each wallet can only be rewarded once per epoch, and epochs must be strictly increasing per wallet.
|
|
95
|
+
* Contract must have sufficient native balance to cover existing claimable + new amount.
|
|
96
|
+
* @param wallet Address to reward
|
|
97
|
+
* @param amount Native COTI amount in wei (18 decimals, {DECIMALS_COTI}) to add to claimable
|
|
98
|
+
* @param epoch Logical epoch identifier for this reward (must be greater than the wallet's lastRewardEpoch)
|
|
99
|
+
*/
|
|
100
|
+
function rewardWallet(address wallet, uint256 amount, uint256 epoch) external onlyOwner {
|
|
101
|
+
if (wallet == address(0)) revert ZeroAddress();
|
|
102
|
+
if (amount == 0) revert ZeroAmount();
|
|
103
|
+
if (epoch == 0) revert InvalidEpoch(epoch);
|
|
104
|
+
if (epoch <= lastRewardEpoch[wallet]) revert AlreadyRewardedInEpoch(wallet, epoch);
|
|
105
|
+
|
|
106
|
+
uint256 newTotalClaimable = totalClaimableCoti + amount;
|
|
107
|
+
if (address(this).balance < newTotalClaimable) revert InsufficientContractBalance();
|
|
108
|
+
|
|
109
|
+
totalPerAddressClaimableCotiToken[wallet] += amount;
|
|
110
|
+
totalClaimableCoti = newTotalClaimable;
|
|
111
|
+
totalRewardedCoti += amount;
|
|
112
|
+
lastRewardEpoch[wallet] = epoch;
|
|
113
|
+
|
|
114
|
+
emit RewardAdded(wallet, amount);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @notice Add claimable rewards for multiple wallets in one call, for a specific epoch. Owner only.
|
|
119
|
+
* Each wallet can only be rewarded once per epoch, and epochs must be strictly increasing per wallet.
|
|
120
|
+
* @param wallets Addresses to reward
|
|
121
|
+
* @param amounts Native COTI amounts in wei to add to claimable for each wallet
|
|
122
|
+
* @param epoch Logical epoch identifier for this reward batch
|
|
123
|
+
*/
|
|
124
|
+
function rewardWallets(address[] calldata wallets, uint256[] calldata amounts, uint256 epoch) external onlyOwner {
|
|
125
|
+
uint256 len = wallets.length;
|
|
126
|
+
if (len != amounts.length) revert ArrayLengthMismatch();
|
|
127
|
+
if (epoch == 0) revert InvalidEpoch(epoch);
|
|
128
|
+
|
|
129
|
+
uint256 added;
|
|
130
|
+
for (uint256 i; i < len; ) {
|
|
131
|
+
address wallet = wallets[i];
|
|
132
|
+
uint256 amount = amounts[i];
|
|
133
|
+
if (wallet == address(0)) revert ZeroAddress();
|
|
134
|
+
if (amount != 0) {
|
|
135
|
+
if (epoch <= lastRewardEpoch[wallet]) revert AlreadyRewardedInEpoch(wallet, epoch);
|
|
136
|
+
totalPerAddressClaimableCotiToken[wallet] += amount;
|
|
137
|
+
added += amount;
|
|
138
|
+
lastRewardEpoch[wallet] = epoch;
|
|
139
|
+
emit RewardAdded(wallet, amount);
|
|
140
|
+
}
|
|
141
|
+
unchecked { ++i; }
|
|
142
|
+
}
|
|
143
|
+
if (added != 0) {
|
|
144
|
+
uint256 newTotalClaimable = totalClaimableCoti + added;
|
|
145
|
+
if (address(this).balance < newTotalClaimable) revert InsufficientContractBalance();
|
|
146
|
+
totalClaimableCoti = newTotalClaimable;
|
|
147
|
+
totalRewardedCoti += added;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ============ Claim (user) ============
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @dev Lets msg.sender claim their claimable native COTI. Reduces total_per_address_claimable_Coti_token
|
|
155
|
+
* and adds the claimed amount to total_per_address_claimed_coti_token; sends native COTI (18 decimals) to the user.
|
|
156
|
+
*/
|
|
157
|
+
function claimReward() external nonReentrant {
|
|
158
|
+
uint256 amount = totalPerAddressClaimableCotiToken[msg.sender];
|
|
159
|
+
if (amount == 0) revert NothingToClaim();
|
|
160
|
+
|
|
161
|
+
totalPerAddressClaimableCotiToken[msg.sender] = 0;
|
|
162
|
+
totalPerAddressClaimedCotiToken[msg.sender] += amount;
|
|
163
|
+
totalClaimableCoti -= amount;
|
|
164
|
+
totalClaimedCoti += amount;
|
|
165
|
+
|
|
166
|
+
(bool success, ) = payable(msg.sender).call{value: amount}("");
|
|
167
|
+
if (!success) revert TransferFailed();
|
|
168
|
+
emit Claimed(msg.sender, amount);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @notice Returns the claimable COTI amount for the caller.
|
|
173
|
+
*/
|
|
174
|
+
function claimableOf(address account) external view returns (uint256) {
|
|
175
|
+
return totalPerAddressClaimableCotiToken[account];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ============ Admin withdrawal ============
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @notice Withdraw excess native COTI that is not reserved for current rewards.
|
|
182
|
+
* @dev Ensures that after withdrawal, the contract still holds at least `totalClaimableCoti`.
|
|
183
|
+
* @param to Recipient address for the withdrawn native COTI.
|
|
184
|
+
* @param amount Native COTI amount in wei to withdraw.
|
|
185
|
+
*/
|
|
186
|
+
function withdrawExcess(address payable to, uint256 amount) external onlyOwner {
|
|
187
|
+
if (to == address(0)) revert ZeroAddress();
|
|
188
|
+
if (amount == 0) revert ZeroAmount();
|
|
189
|
+
|
|
190
|
+
uint256 balance = address(this).balance;
|
|
191
|
+
if (balance < totalClaimableCoti) revert InsufficientContractBalance();
|
|
192
|
+
|
|
193
|
+
uint256 available = balance - totalClaimableCoti;
|
|
194
|
+
if (amount > available) revert InsufficientContractBalance();
|
|
195
|
+
|
|
196
|
+
(bool success, ) = to.call{value: amount}("");
|
|
197
|
+
if (!success) revert TransferFailed();
|
|
198
|
+
}
|
|
199
|
+
}
|