@sabaaa1/common 0.0.1
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/.env.example +5 -0
- package/.eslintrc.json +18 -0
- package/README.md +164 -0
- package/copyPackageJson.js +81 -0
- package/handleCDNWorkers.js +92 -0
- package/jest.config.ts +10 -0
- package/package.json +101 -0
- package/polyfillWorker.ts +15 -0
- package/project.json +32 -0
- package/src/API/API.ts +203 -0
- package/src/API/admin-calls.ts +8 -0
- package/src/API/ai-calls.ts +48 -0
- package/src/API/brotherhoodCalls.ts +184 -0
- package/src/API/callLifiAPI.ts +41 -0
- package/src/API/callMonitor.ts +9 -0
- package/src/API/callOdosAPI.ts +89 -0
- package/src/API/callOneInchAPI.ts +47 -0
- package/src/API/callRelayer.ts +23 -0
- package/src/API/checkRisk.ts +7 -0
- package/src/API/duneAPI.ts +26 -0
- package/src/API/enclaveCalls.ts +23 -0
- package/src/API/fetchCommitmentsCache.ts +63 -0
- package/src/API/generate-trading-points.ts +77 -0
- package/src/API/get-token-data.ts +12 -0
- package/src/API/getBridgeProtocols.ts +16 -0
- package/src/API/getCoingeckoPrice.ts +59 -0
- package/src/API/getGasEstimates.ts +30 -0
- package/src/API/getLifiStatus.ts +35 -0
- package/src/API/getRelayerURL.ts +27 -0
- package/src/API/getServerURL.ts +116 -0
- package/src/API/getTokenPrice.ts +39 -0
- package/src/API/getWebsiteURL.ts +58 -0
- package/src/API/index.ts +19 -0
- package/src/API/is-tx-stateless.ts +32 -0
- package/src/API/kycCalls.ts +81 -0
- package/src/API/leaderboardCalls.ts +32 -0
- package/src/API/mysteryBoxesCalls.ts +141 -0
- package/src/API/passwordCalls.ts +34 -0
- package/src/API/proxyAccountsCalls.ts +40 -0
- package/src/API/referralsCalls.ts +52 -0
- package/src/API/relayCalls.ts +14 -0
- package/src/API/restoreSnapshots.ts +7 -0
- package/src/API/rewardsUserCalls.ts +124 -0
- package/src/API/send-telegram-callback.ts +17 -0
- package/src/API/simulate-batch-tx.ts +19 -0
- package/src/API/tenderly.api.ts +96 -0
- package/src/API/token-calls.ts +19 -0
- package/src/API/weeklyAnalyticCalls.ts +43 -0
- package/src/constants/activity.constants.ts +10 -0
- package/src/constants/addresses.constants.ts +74 -0
- package/src/constants/assets.constants.ts +15 -0
- package/src/constants/backend.constants.ts +16 -0
- package/src/constants/balance.constants.ts +1 -0
- package/src/constants/bridging.constants.ts +5 -0
- package/src/constants/chains.constants.ts +194 -0
- package/src/constants/coingecko.constants.ts +67 -0
- package/src/constants/contracts.constants.ts +106 -0
- package/src/constants/conversion.constants.ts +1 -0
- package/src/constants/deploy-data/deploy-data-arbMainnet.json +5685 -0
- package/src/constants/deploy-data/deploy-data-arcTestnet.json +6157 -0
- package/src/constants/deploy-data/deploy-data-avalanche.json +5921 -0
- package/src/constants/deploy-data/deploy-data-base.json +5695 -0
- package/src/constants/deploy-data/deploy-data-bnbMainnet.json +5921 -0
- package/src/constants/deploy-data/deploy-data-ethMainnet.json +5922 -0
- package/src/constants/deploy-data/deploy-data-localhost.json +5921 -0
- package/src/constants/deploy-data/deploy-data-optimism.json +5687 -0
- package/src/constants/deploy-data/deploy-data-polygon.json +5695 -0
- package/src/constants/deploy-data/index.ts +21 -0
- package/src/constants/events.constants.ts +10 -0
- package/src/constants/fees.constants.ts +4 -0
- package/src/constants/function-signatures.constants.ts +6 -0
- package/src/constants/index.ts +30 -0
- package/src/constants/kyc.constants.ts +202 -0
- package/src/constants/lifi.constants.ts +1 -0
- package/src/constants/mediaUrls.constants.ts +25 -0
- package/src/constants/mystery-boxes.constants.ts +402 -0
- package/src/constants/oauthUrls.constants.ts +7 -0
- package/src/constants/permit2.constants.ts +28 -0
- package/src/constants/presale.constants.ts +503 -0
- package/src/constants/protocol.constants.ts +65 -0
- package/src/constants/reorg-depths.constants.ts +13 -0
- package/src/constants/rewards.constants.ts +27 -0
- package/src/constants/save-depths.ts +13 -0
- package/src/constants/server.constants.ts +233 -0
- package/src/constants/tasks.constants.ts +205 -0
- package/src/constants/token-data/ERC20Registry.ts +90 -0
- package/src/constants/token-data/arbMainnetRegistry.json +1841 -0
- package/src/constants/token-data/arbMainnetRegistryFixed.json +1841 -0
- package/src/constants/token-data/arcTestnetRegistry.json +436 -0
- package/src/constants/token-data/avalancheRegistry.json +729 -0
- package/src/constants/token-data/avalancheRegistryFixed.json +729 -0
- package/src/constants/token-data/baseRegistry.json +1134 -0
- package/src/constants/token-data/baseRegistryFixed.json +1134 -0
- package/src/constants/token-data/bnbMainnetRegistry.json +900 -0
- package/src/constants/token-data/bnbMainnetRegistryFixed.json +900 -0
- package/src/constants/token-data/ethMainnetRegistry.json +4298 -0
- package/src/constants/token-data/ethMainnetRegistryFixed.json +4298 -0
- package/src/constants/token-data/index.ts +60 -0
- package/src/constants/token-data/localhostRegistry.json +2784 -0
- package/src/constants/token-data/optimismRegistry.json +701 -0
- package/src/constants/token-data/optimismRegistryFixed.json +701 -0
- package/src/constants/token-data/polygonRegistry.json +2309 -0
- package/src/constants/token-data/polygonRegistryFixed.json +2309 -0
- package/src/constants/token-data/popularTokens.constants.ts +11 -0
- package/src/constants/token-data/tokenPricing.consts.ts +2 -0
- package/src/constants/token.limits.constants.ts +31 -0
- package/src/constants/vite.constants.ts +74 -0
- package/src/constants/wallet.constants.ts +9 -0
- package/src/crypto/babyJub.ts +31 -0
- package/src/crypto/index.ts +3 -0
- package/src/crypto/poseidon.ts +36 -0
- package/src/crypto/preProcessing.ts +20 -0
- package/src/data-structures/ApprovalDBs/EventsPublicApprovalsDB.ts +288 -0
- package/src/data-structures/ApprovalDBs/index.ts +1 -0
- package/src/data-structures/Hinkal/Hinkal.ts +746 -0
- package/src/data-structures/Hinkal/IHinkal.ts +315 -0
- package/src/data-structures/Hinkal/handleAutoDepositBack.ts +138 -0
- package/src/data-structures/Hinkal/hinkalActionFundApproveAndTransact.ts +64 -0
- package/src/data-structures/Hinkal/hinkalActionReceive.ts +65 -0
- package/src/data-structures/Hinkal/hinkalActionStake.ts +152 -0
- package/src/data-structures/Hinkal/hinkalApprove.ts +170 -0
- package/src/data-structures/Hinkal/hinkalCheckTokenRegistry.ts +26 -0
- package/src/data-structures/Hinkal/hinkalDeposit.ts +199 -0
- package/src/data-structures/Hinkal/hinkalGetRecipientInfo.ts +12 -0
- package/src/data-structures/Hinkal/hinkalGetZkMeProvider.ts +31 -0
- package/src/data-structures/Hinkal/hinkalInsideTransact.ts +190 -0
- package/src/data-structures/Hinkal/hinkalMultiSend.ts +26 -0
- package/src/data-structures/Hinkal/hinkalPrivateWallet.ts +198 -0
- package/src/data-structures/Hinkal/hinkalProoflessDeposit.ts +91 -0
- package/src/data-structures/Hinkal/hinkalProxySwap.ts +91 -0
- package/src/data-structures/Hinkal/hinkalSignSubAccount.ts +28 -0
- package/src/data-structures/Hinkal/hinkalSwap.ts +157 -0
- package/src/data-structures/Hinkal/hinkalTransfer.ts +171 -0
- package/src/data-structures/Hinkal/hinkalWithdraw.ts +161 -0
- package/src/data-structures/Hinkal/index.ts +9 -0
- package/src/data-structures/Hinkal/resetMerkleTrees.ts +64 -0
- package/src/data-structures/IndexedDB/activity-db.ts +204 -0
- package/src/data-structures/IndexedDB/balances-db.ts +97 -0
- package/src/data-structures/IndexedDB/contact-db.ts +81 -0
- package/src/data-structures/IndexedDB/index.ts +6 -0
- package/src/data-structures/IndexedDB/prices-db.ts +89 -0
- package/src/data-structures/IndexedDB/private-balances-db.ts +31 -0
- package/src/data-structures/IndexedDB/signatures-db.ts +62 -0
- package/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.ts +152 -0
- package/src/data-structures/TokenDBs/AlchemyPublicTokensDB.ts +224 -0
- package/src/data-structures/TokenDBs/ArcPublicTokensDB.ts +198 -0
- package/src/data-structures/TokenDBs/EventsPublicTokensDB.ts +216 -0
- package/src/data-structures/TokenDBs/IPublicTokensDB.ts +7 -0
- package/src/data-structures/TokenDBs/PrivateTokensDB.ts +96 -0
- package/src/data-structures/TokenDBs/PublicTokensDB.ts +49 -0
- package/src/data-structures/TokenDBs/index.ts +4 -0
- package/src/data-structures/TokenDBs/token-visibility-db.ts +154 -0
- package/src/data-structures/ValueCache/ValueCache.ts +29 -0
- package/src/data-structures/ValueCache/index.ts +1 -0
- package/src/data-structures/cacheDevices/AttachableMemoryCacheDevice.ts +33 -0
- package/src/data-structures/cacheDevices/BaseCacheDevice.ts +30 -0
- package/src/data-structures/cacheDevices/FileCacheDevice.ts +59 -0
- package/src/data-structures/cacheDevices/LocalStorageCacheDevice.ts +36 -0
- package/src/data-structures/cacheDevices/index.ts +2 -0
- package/src/data-structures/crypto-keys/decodeUTXO.ts +60 -0
- package/src/data-structures/crypto-keys/encryptDecryptUtxo.ts +74 -0
- package/src/data-structures/crypto-keys/index.ts +4 -0
- package/src/data-structures/crypto-keys/keyUtils.ts +8 -0
- package/src/data-structures/crypto-keys/keys.ts +203 -0
- package/src/data-structures/custom-token-registry/CustomTokenRegistry.ts +49 -0
- package/src/data-structures/event-service/AbstractAccessTokenSnapshotService.ts +142 -0
- package/src/data-structures/event-service/AbstractApprovalsSnapshotService.ts +152 -0
- package/src/data-structures/event-service/AbstractCommitmentsSnapshotService.ts +116 -0
- package/src/data-structures/event-service/AbstractEventService.ts +44 -0
- package/src/data-structures/event-service/AbstractNullifierSnapshotService.ts +76 -0
- package/src/data-structures/event-service/AbstractSnapshotService.ts +63 -0
- package/src/data-structures/event-service/BlockchainEventEmitter.ts +132 -0
- package/src/data-structures/event-service/index.ts +7 -0
- package/src/data-structures/index.ts +18 -0
- package/src/data-structures/merkle-tree/MerkleTree.test.ts +77 -0
- package/src/data-structures/merkle-tree/MerkleTree.ts +253 -0
- package/src/data-structures/merkle-tree/MerkleTreeIncompleteError.ts +6 -0
- package/src/data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.ts +24 -0
- package/src/data-structures/merkle-tree/index.ts +3 -0
- package/src/data-structures/presale/PresaleContractWrapper.ts +80 -0
- package/src/data-structures/presale/index.ts +1 -0
- package/src/data-structures/provider-adapter/IProviderAdapter.ts +43 -0
- package/src/data-structures/snapshot/ClientAccessTokenSnapshotService.ts +41 -0
- package/src/data-structures/snapshot/ClientApprovalsSnapshotService.ts +36 -0
- package/src/data-structures/snapshot/ClientCommitmentsSnapshotService.ts +30 -0
- package/src/data-structures/snapshot/ClientNullifierSnapshotService.ts +28 -0
- package/src/data-structures/snapshot/SnapshotFetcherService.ts +68 -0
- package/src/data-structures/snapshot/index.ts +1 -0
- package/src/data-structures/token-price-fetcher/TokenChecker.ts +45 -0
- package/src/data-structures/token-price-fetcher/index.ts +1 -0
- package/src/data-structures/tor/HttpClient.ts +118 -0
- package/src/data-structures/tor/TorAdapter.ts +94 -0
- package/src/data-structures/tor/TorClient.ts +283 -0
- package/src/data-structures/tor/WebSocketDuplex.ts +32 -0
- package/src/data-structures/tor/index.ts +3 -0
- package/src/data-structures/transactions-manager/history/history.types.ts +14 -0
- package/src/data-structures/transactions-manager/index.ts +1 -0
- package/src/data-structures/utxo/Utxo.ts +189 -0
- package/src/error-handling/customErrors/ErrorWithAmount.ts +8 -0
- package/src/error-handling/customErrors/ErrorWithTx.ts +10 -0
- package/src/error-handling/customErrors/FeeOverTransactionValueError.ts +16 -0
- package/src/error-handling/customErrors/SimulationFailureError.ts +9 -0
- package/src/error-handling/customErrors/customErrors.helpers.ts +39 -0
- package/src/error-handling/customErrors/index.ts +5 -0
- package/src/error-handling/error-codes.constants.ts +214 -0
- package/src/error-handling/get-error.message.ts +149 -0
- package/src/error-handling/handleErrorRestore.ts +25 -0
- package/src/error-handling/index.ts +7 -0
- package/src/error-handling/logError.ts +8 -0
- package/src/error-handling/logger.ts +21 -0
- package/src/error-handling/types.ts +10 -0
- package/src/externalABIs/BUSD.ts +516 -0
- package/src/externalABIs/BabPassport.json +24 -0
- package/src/externalABIs/DAI.ts +331 -0
- package/src/externalABIs/ERC1155.json +316 -0
- package/src/externalABIs/ERC20.json +297 -0
- package/src/externalABIs/ERC20.ts +1 -0
- package/src/externalABIs/ERC721.json +205 -0
- package/src/externalABIs/GalxePassport.json +23 -0
- package/src/externalABIs/IQuoterV2.json +211 -0
- package/src/externalABIs/ISwapRouter.json +568 -0
- package/src/externalABIs/IUniswapV3Factory.json +207 -0
- package/src/externalABIs/IUniswapV3Pool.json +999 -0
- package/src/externalABIs/NodeInterfaceABI.json +1 -0
- package/src/externalABIs/OptimismGasPriceOracle.json +1 -0
- package/src/externalABIs/PoLidoNftAbi.json +307 -0
- package/src/externalABIs/SanctionsList.ts +86 -0
- package/src/externalABIs/USDC.ts +718 -0
- package/src/externalABIs/USDR.ts +343 -0
- package/src/externalABIs/USDR3CRV.ts +539 -0
- package/src/externalABIs/USDT.ts +390 -0
- package/src/externalABIs/UniswapV2PoolAbi.json +66 -0
- package/src/externalABIs/WETH.ts +153 -0
- package/src/externalABIs/amToken.ts +347 -0
- package/src/externalABIs/index.ts +53 -0
- package/src/externalABIs/swapAbi.ts +442 -0
- package/src/externalABIs/transactionsProver.json +45 -0
- package/src/functions/index.ts +16 -0
- package/src/functions/kyc/aiPriseHelper.ts +0 -0
- package/src/functions/kyc/authentoHelper.ts +44 -0
- package/src/functions/kyc/index.ts +3 -0
- package/src/functions/kyc/openDefaultPassportWindow.ts +9 -0
- package/src/functions/kyc/passportHelper.ts +13 -0
- package/src/functions/kyc/zkMeHelper.ts +69 -0
- package/src/functions/pre-transaction/constructAdminData.ts +21 -0
- package/src/functions/pre-transaction/getExternalSwapAddress.ts +30 -0
- package/src/functions/pre-transaction/getFeeStructure.ts +44 -0
- package/src/functions/pre-transaction/getFlatFees.ts +88 -0
- package/src/functions/pre-transaction/getSignatureDataForTransact.ts +16 -0
- package/src/functions/pre-transaction/getVolatileTransferAmount.ts +56 -0
- package/src/functions/pre-transaction/index.ts +7 -0
- package/src/functions/pre-transaction/interaction-to-action.ts +17 -0
- package/src/functions/pre-transaction/merge-with-fee-structure-emporium.ts +50 -0
- package/src/functions/pre-transaction/merge-with-fee-structure.ts +35 -0
- package/src/functions/pre-transaction/outputApprovalDataProcessing.ts +95 -0
- package/src/functions/pre-transaction/outputUtxoProcessing.ts +52 -0
- package/src/functions/pre-transaction/process-gas-estimates.ts +36 -0
- package/src/functions/pre-transaction/shouldPatchAccessTokenMerkleTree.ts +15 -0
- package/src/functions/private-wallet/emporium.helpers.ts +296 -0
- package/src/functions/private-wallet/emporium.swap.helpers.ts +284 -0
- package/src/functions/private-wallet/index.ts +3 -0
- package/src/functions/private-wallet/opProducer.ts +33 -0
- package/src/functions/snarkjs/common.snarkjs.ts +377 -0
- package/src/functions/snarkjs/constant.ts +490 -0
- package/src/functions/snarkjs/constructEmporiumProof.ts +301 -0
- package/src/functions/snarkjs/constructGeneralZkProof.ts +281 -0
- package/src/functions/snarkjs/generateCircomData.ts +81 -0
- package/src/functions/snarkjs/generateZkProof.ts +21 -0
- package/src/functions/snarkjs/generateZkProofEnclave.ts +45 -0
- package/src/functions/snarkjs/generateZkProofSelf.ts +29 -0
- package/src/functions/snarkjs/getOriginalSender.ts +4 -0
- package/src/functions/snarkjs/getZKFiles.ts +29 -0
- package/src/functions/snarkjs/index.ts +4 -0
- package/src/functions/staking/index.ts +78 -0
- package/src/functions/utils/addresses.ts +37 -0
- package/src/functions/utils/amounts.utils.test.ts +91 -0
- package/src/functions/utils/amounts.utils.ts +119 -0
- package/src/functions/utils/arraysMatch.ts +4 -0
- package/src/functions/utils/cacheDevice.utils.ts +21 -0
- package/src/functions/utils/cacheFunctions.ts +154 -0
- package/src/functions/utils/caseInsensitive.utils.ts +10 -0
- package/src/functions/utils/convertEmporiumOpToCallInfo.ts +19 -0
- package/src/functions/utils/convertIntegrationProviderToExternalActionId.ts +14 -0
- package/src/functions/utils/create-provider.ts +11 -0
- package/src/functions/utils/encodeTokenWithId.ts +4 -0
- package/src/functions/utils/encryptInputForEnclave.ts +119 -0
- package/src/functions/utils/enum.utils.ts +30 -0
- package/src/functions/utils/erc20tokenFunctions.ts +110 -0
- package/src/functions/utils/ethers-formatter.utils.ts +32 -0
- package/src/functions/utils/evmNetworkFunctions.ts +9 -0
- package/src/functions/utils/external-action.utils.ts +15 -0
- package/src/functions/utils/fees.utils.ts +26 -0
- package/src/functions/utils/get-hinkal-approvals.ts +36 -0
- package/src/functions/utils/get-signature-header.ts +5 -0
- package/src/functions/utils/getBlockExplorerUrl.ts +14 -0
- package/src/functions/utils/getDataFromTransaction.ts +79 -0
- package/src/functions/utils/getRecipientInfoFromUserKeys.ts +28 -0
- package/src/functions/utils/inLogicMetadata.ts +9 -0
- package/src/functions/utils/index.ts +43 -0
- package/src/functions/utils/involves-permit2-op.ts +17 -0
- package/src/functions/utils/ipfs.ts +74 -0
- package/src/functions/utils/is-valid-url.ts +5 -0
- package/src/functions/utils/lifi.utils.ts +3 -0
- package/src/functions/utils/memoize.utils.ts +23 -0
- package/src/functions/utils/merkleTree.utils.ts +27 -0
- package/src/functions/utils/mutexes.utils.ts +3 -0
- package/src/functions/utils/mystery-box-auction.utils.ts +61 -0
- package/src/functions/utils/networks.utils.ts +6 -0
- package/src/functions/utils/nftTokenFunctions.ts +25 -0
- package/src/functions/utils/nickname.utils.ts +4 -0
- package/src/functions/utils/postToOffscreen.ts +6 -0
- package/src/functions/utils/prepareHinkal.ts +78 -0
- package/src/functions/utils/process.utils.ts +23 -0
- package/src/functions/utils/processUseApprovalUtxoData.ts +26 -0
- package/src/functions/utils/publicBalance.utils.ts +131 -0
- package/src/functions/utils/reloadPage.ts +1 -0
- package/src/functions/utils/replaceAddressInCalldata.ts +6 -0
- package/src/functions/utils/requireEnv.ts +10 -0
- package/src/functions/utils/resolve-sync.utils.ts +40 -0
- package/src/functions/utils/rpc-int-encode.ts +7 -0
- package/src/functions/utils/serialize.utils.ts +12 -0
- package/src/functions/utils/string.utils.ts +92 -0
- package/src/functions/utils/time.utils.ts +80 -0
- package/src/functions/utils/token-check.utils.ts +12 -0
- package/src/functions/utils/trimFieldValues.ts +24 -0
- package/src/functions/utils/upToDateState.ts +12 -0
- package/src/functions/utils/userAgent.ts +26 -0
- package/src/functions/utils/walletBalances.utils.ts +117 -0
- package/src/functions/web3/EIP-712.test.ts +302 -0
- package/src/functions/web3/EIP-712.ts +243 -0
- package/src/functions/web3/etherFunctions.test.ts +129 -0
- package/src/functions/web3/etherFunctions.ts +84 -0
- package/src/functions/web3/events/balanceChangedCustomHandler.ts +13 -0
- package/src/functions/web3/events/balanceChangedHandler.ts +10 -0
- package/src/functions/web3/events/getApprovedBalance.ts +154 -0
- package/src/functions/web3/events/getInputUtxoAndBalance.ts +305 -0
- package/src/functions/web3/events/getInputUtxosEnclave.ts +40 -0
- package/src/functions/web3/events/getShieldedBalance.ts +163 -0
- package/src/functions/web3/events/getTransactionLogEvents.ts +55 -0
- package/src/functions/web3/events/index.ts +7 -0
- package/src/functions/web3/events/web3RetrieveEvents.ts +33 -0
- package/src/functions/web3/functionCalls/accessTokenCalls.ts +27 -0
- package/src/functions/web3/functionCalls/approveToken.ts +180 -0
- package/src/functions/web3/functionCalls/approveTokensToHinkal.ts +21 -0
- package/src/functions/web3/functionCalls/estimateGasRelayer.ts +40 -0
- package/src/functions/web3/functionCalls/getRootHash.ts +7 -0
- package/src/functions/web3/functionCalls/inHinkalApprovalCalls.ts +60 -0
- package/src/functions/web3/functionCalls/relayFunctions.ts +12 -0
- package/src/functions/web3/functionCalls/transactCallDirect.ts +71 -0
- package/src/functions/web3/functionCalls/transactCallRelayer.ts +57 -0
- package/src/functions/web3/getContractMetadata.ts +43 -0
- package/src/functions/web3/getPublicAddressBalance.ts +17 -0
- package/src/functions/web3/getTokenHolder.ts +53 -0
- package/src/functions/web3/index.ts +9 -0
- package/src/functions/web3/lifiAPI.ts +41 -0
- package/src/functions/web3/odosAPI.ts +50 -0
- package/src/functions/web3/oneInchAPI.ts +47 -0
- package/src/functions/web3/runContractFunction.ts +116 -0
- package/src/functions/web3/uniswapAPI.ts +156 -0
- package/src/index.ts +9 -0
- package/src/mutexes/index.ts +1 -0
- package/src/mutexes/mutex.ts +3 -0
- package/src/providers/EthersProviderAdapter.ts +230 -0
- package/src/providers/TorExternalProvider.ts +36 -0
- package/src/providers/WagmiProviderAdapter.ts +311 -0
- package/src/providers/exportProviers.ts +11 -0
- package/src/providers/prepareEthersHinkal.ts +18 -0
- package/src/providers/prepareWagmiHinkal.ts +16 -0
- package/src/types/API.types.ts +23 -0
- package/src/types/ICacheDevice.ts +5 -0
- package/src/types/IMultiThreadedUtxoUtils.ts +16 -0
- package/src/types/RewardUserEnums.ts +12 -0
- package/src/types/TransactionSimulator.types.ts +30 -0
- package/src/types/WeeklyAnalytics.types.ts +44 -0
- package/src/types/activities.types.ts +90 -0
- package/src/types/admin.types.ts +30 -0
- package/src/types/all-points.types.ts +8 -0
- package/src/types/approvals.types.ts +45 -0
- package/src/types/balances.types.ts +20 -0
- package/src/types/big-intable.types.ts +3 -0
- package/src/types/bridging.types.ts +30 -0
- package/src/types/brotherhood-user.types.ts +13 -0
- package/src/types/cache.types.ts +42 -0
- package/src/types/circom-data.types.ts +120 -0
- package/src/types/coingecko.types.ts +216 -0
- package/src/types/commitments.types.ts +39 -0
- package/src/types/confirmation-request.types.ts +10 -0
- package/src/types/contacts.types.ts +6 -0
- package/src/types/crypto.types.ts +8 -0
- package/src/types/duneAPI.types.ts +9 -0
- package/src/types/eip5792.types.ts +31 -0
- package/src/types/ethereum-network.types.ts +70 -0
- package/src/types/external-action.types.ts +19 -0
- package/src/types/fee.types.ts +11 -0
- package/src/types/generatePoints.ts +14 -0
- package/src/types/hinkal.stake.types.ts +12 -0
- package/src/types/hinkal.types.ts +150 -0
- package/src/types/index.ts +50 -0
- package/src/types/kyc.types.ts +49 -0
- package/src/types/merch-order.types.ts +18 -0
- package/src/types/message.types.ts +6 -0
- package/src/types/mystery-boxes.types.ts +50 -0
- package/src/types/new-rewards.type.ts +181 -0
- package/src/types/offscreen.types.ts +8 -0
- package/src/types/presaleReferral.types.ts +4 -0
- package/src/types/proxy.types.ts +11 -0
- package/src/types/referral.types.ts +13 -0
- package/src/types/relayer.types.ts +16 -0
- package/src/types/remote-proof.types.ts +18 -0
- package/src/types/rewards.types.ts +53 -0
- package/src/types/routing.types.ts +7 -0
- package/src/types/sandbox.types.ts +246 -0
- package/src/types/session.types.ts +12 -0
- package/src/types/signature.types.ts +11 -0
- package/src/types/slippage.types.ts +3 -0
- package/src/types/snark.types.ts +43 -0
- package/src/types/tenderly.api.types.ts +200 -0
- package/src/types/token-prices.types.ts +8 -0
- package/src/types/token-with-id.types.ts +4 -0
- package/src/types/token.types.ts +86 -0
- package/src/types/transactions.types.ts +120 -0
- package/src/types/wc.types.ts +83 -0
- package/src/types/with-id.types.ts +1 -0
- package/src/webworker/performTaskWithWorker.ts +50 -0
- package/src/webworker/snarkjsWorker/snarkjs.d.ts +2 -0
- package/src/webworker/snarkjsWorker/snarkjsWorker.types.ts +18 -0
- package/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts +19 -0
- package/src/webworker/snarkjsWorker/snarkjsWorkerLogic.ts +90 -0
- package/src/webworker/utxoWorker/utxoWorker.types.ts +41 -0
- package/src/webworker/utxoWorker/utxoWorkerLauncher.ts +19 -0
- package/src/webworker/utxoWorker/utxoWorkerLogic.ts +107 -0
- package/src/webworker/viteWorkerURL.constant.ts +25 -0
- package/src/webworker/worker.registry.ts +11 -0
- package/src/webworker/worker.types.ts +35 -0
- package/src/webworker/workerErrorHandler.ts +10 -0
- package/src/webworker/workerFactory.ts +47 -0
- package/src/webworker/workerProxy.ts +88 -0
- package/src/webworker/zkProofWorker/zkProofWorker.types.ts +52 -0
- package/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts +19 -0
- package/src/webworker/zkProofWorker/zkProofWorkerLogic.ts +84 -0
- package/tsconfig.json +23 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +15 -0
- package/vite.config.ts +97 -0
- package/vite.config.workers.ts +51 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
import {
|
|
3
|
+
ApprovedUtxo,
|
|
4
|
+
ApprovedUtxoWithInteractionAddress,
|
|
5
|
+
FeeStructure,
|
|
6
|
+
type ParsedInLogicMetadata,
|
|
7
|
+
} from '../../types/hinkal.types';
|
|
8
|
+
import { ContractMetadata, ContractType, EthereumNetwork } from '../../types/ethereum-network.types';
|
|
9
|
+
import { EncryptedOutputWithSign } from '../../types/commitments.types';
|
|
10
|
+
import { ExternalActionId } from '../../types/external-action.types';
|
|
11
|
+
import { type IMultiThreadedUtxoUtils } from '../../types/IMultiThreadedUtxoUtils';
|
|
12
|
+
import { RelayerTransaction } from '../../types/relayer.types';
|
|
13
|
+
import { SignatureData } from '../../types/crypto.types';
|
|
14
|
+
import { ERC20Token, TokenBalance, TokenChanges } from '../../types/token.types';
|
|
15
|
+
|
|
16
|
+
import { Bytes, ethers } from 'ethers';
|
|
17
|
+
import { type UserKeys } from '../crypto-keys/keys';
|
|
18
|
+
import { IProviderAdapter } from '../provider-adapter/IProviderAdapter';
|
|
19
|
+
import { ClientAccessTokenSnapshotService } from '../snapshot/ClientAccessTokenSnapshotService';
|
|
20
|
+
import { ClientCommitmentsSnapshotService } from '../snapshot/ClientCommitmentsSnapshotService';
|
|
21
|
+
import { ClientNullifierSnapshotService } from '../snapshot/ClientNullifierSnapshotService';
|
|
22
|
+
import { ClientApprovalsSnapshotService } from '../snapshot/ClientApprovalsSnapshotService';
|
|
23
|
+
|
|
24
|
+
import { MerkleTree } from '../merkle-tree';
|
|
25
|
+
import { IAPI } from '../../API/API';
|
|
26
|
+
import { type ICacheDevice } from '../../types/ICacheDevice';
|
|
27
|
+
import type { StealthAddressStructure, TypedData } from '../../types/circom-data.types';
|
|
28
|
+
import { SubAccount } from '../../types/proxy.types';
|
|
29
|
+
import { AdminTransactionType } from '@hinkal/common/types';
|
|
30
|
+
|
|
31
|
+
export interface IHinkal<ConnectorType = unknown> {
|
|
32
|
+
userKeys: UserKeys;
|
|
33
|
+
|
|
34
|
+
readonly signingMessage: string;
|
|
35
|
+
|
|
36
|
+
merkleTreeHinkal: MerkleTree<bigint>;
|
|
37
|
+
|
|
38
|
+
merkleTreeAccessToken: MerkleTree<bigint>;
|
|
39
|
+
|
|
40
|
+
nullifiers: Set<string>;
|
|
41
|
+
|
|
42
|
+
encryptedOutputs: EncryptedOutputWithSign[];
|
|
43
|
+
|
|
44
|
+
approvals: Map<string, ApprovedUtxo[]>;
|
|
45
|
+
|
|
46
|
+
commitmentsSnapshotService?: ClientCommitmentsSnapshotService;
|
|
47
|
+
|
|
48
|
+
nullifierSnapshotService?: ClientNullifierSnapshotService;
|
|
49
|
+
|
|
50
|
+
accessTokenSnapshotService?: ClientAccessTokenSnapshotService;
|
|
51
|
+
|
|
52
|
+
approvalsSnapshotService?: ClientApprovalsSnapshotService;
|
|
53
|
+
|
|
54
|
+
generateProofRemotely: boolean;
|
|
55
|
+
|
|
56
|
+
utxoUtils: IMultiThreadedUtxoUtils;
|
|
57
|
+
|
|
58
|
+
cacheDevice: ICacheDevice;
|
|
59
|
+
|
|
60
|
+
getBalances(
|
|
61
|
+
chainId: number,
|
|
62
|
+
passedShieldedPrivateKey: string,
|
|
63
|
+
passedShieldedPublicKey: string,
|
|
64
|
+
ethAddress: string,
|
|
65
|
+
resetCacheBefore?: boolean,
|
|
66
|
+
updateTokensListBefore?: boolean,
|
|
67
|
+
): Promise<Map<string, TokenBalance>>;
|
|
68
|
+
|
|
69
|
+
getApprovedBalances(resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<Map<string, TokenBalance>>;
|
|
70
|
+
|
|
71
|
+
getTotalBalance(
|
|
72
|
+
chainId?: number,
|
|
73
|
+
userKeys?: UserKeys,
|
|
74
|
+
ethAddress?: string,
|
|
75
|
+
resetCacheBefore?: boolean,
|
|
76
|
+
updateTokensListBefore?: boolean,
|
|
77
|
+
): Promise<TokenBalance[]>;
|
|
78
|
+
|
|
79
|
+
getSupportedPassportLinks(): string[];
|
|
80
|
+
|
|
81
|
+
checkAccessToken(): Promise<boolean>;
|
|
82
|
+
|
|
83
|
+
getEthereumAddress(): Promise<string>;
|
|
84
|
+
|
|
85
|
+
resetMerkleTreesIfNecessary(): Promise<void>;
|
|
86
|
+
|
|
87
|
+
resetMerkle(): Promise<void>;
|
|
88
|
+
|
|
89
|
+
getEventsFromHinkal(): Promise<void>;
|
|
90
|
+
|
|
91
|
+
mintHinkalAccessToken(signatureData: SignatureData, fromWallet?: boolean): Promise<ethers.ContractTransaction>;
|
|
92
|
+
|
|
93
|
+
getRandomRelay(markAsPending?: boolean): Promise<string | undefined>;
|
|
94
|
+
|
|
95
|
+
getGasPrice(): Promise<bigint>;
|
|
96
|
+
|
|
97
|
+
getAPI(): IAPI;
|
|
98
|
+
|
|
99
|
+
resetCache(): void;
|
|
100
|
+
|
|
101
|
+
snapshotsClearInterval(): void;
|
|
102
|
+
|
|
103
|
+
checkTokenRegistry(erc20Addresses: string[], amountChanges: bigint[]): Promise<boolean>;
|
|
104
|
+
|
|
105
|
+
getRecipientInfo(extendedInfo?: boolean): string;
|
|
106
|
+
|
|
107
|
+
getInteractionApprovals(interactionAddress: string): Promise<ApprovedUtxo[]>;
|
|
108
|
+
|
|
109
|
+
getApprovedUtxos(resetCacheBefore?: boolean): ApprovedUtxoWithInteractionAddress[];
|
|
110
|
+
|
|
111
|
+
getApprovedUtxosForToken(erc20Address: string, resetCacheBefore?: boolean): ApprovedUtxoWithInteractionAddress[];
|
|
112
|
+
|
|
113
|
+
getMyApprovalAmountForInteraction(interactionAddress: string, tokenAddress: string): bigint;
|
|
114
|
+
|
|
115
|
+
checkExistingApprovalFromHinkal(erc20Address: string, interactionAddress: string): Promise<bigint>;
|
|
116
|
+
|
|
117
|
+
getBufferEntry(approveTo: string, tokenAddress: string, inHinkalAddress: bigint): Promise<bigint>;
|
|
118
|
+
|
|
119
|
+
deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[]): Promise<ethers.ContractTransaction>;
|
|
120
|
+
|
|
121
|
+
depositForOther(
|
|
122
|
+
erc20Tokens: ERC20Token[],
|
|
123
|
+
amountChanges: bigint[],
|
|
124
|
+
recepinetInfo: string,
|
|
125
|
+
): Promise<ethers.ContractTransaction>;
|
|
126
|
+
|
|
127
|
+
prooflessDeposit(
|
|
128
|
+
erc20Tokens: ERC20Token[],
|
|
129
|
+
amountChanges: bigint[],
|
|
130
|
+
stealthAddressStructures?: StealthAddressStructure[],
|
|
131
|
+
): Promise<ethers.ContractTransaction>;
|
|
132
|
+
|
|
133
|
+
transfer(
|
|
134
|
+
erc20Tokens: ERC20Token[],
|
|
135
|
+
amountChanges: bigint[],
|
|
136
|
+
recipientAddress: string,
|
|
137
|
+
feeToken?: string,
|
|
138
|
+
feeStructureOverride?: FeeStructure,
|
|
139
|
+
action?: AdminTransactionType,
|
|
140
|
+
onlyGasEstimate?: boolean,
|
|
141
|
+
): Promise<RelayerTransaction | bigint>;
|
|
142
|
+
|
|
143
|
+
withdraw(
|
|
144
|
+
erc20Tokens: ERC20Token[],
|
|
145
|
+
deltaAmounts: bigint[],
|
|
146
|
+
recipientAddress: string,
|
|
147
|
+
isRelayerOff: boolean,
|
|
148
|
+
feeToken?: string,
|
|
149
|
+
feeStructureOverride?: FeeStructure,
|
|
150
|
+
action?: AdminTransactionType,
|
|
151
|
+
onlyGasEstimate?: boolean,
|
|
152
|
+
): Promise<ethers.ContractTransaction | RelayerTransaction | bigint>;
|
|
153
|
+
|
|
154
|
+
swap(
|
|
155
|
+
erc20Tokens: ERC20Token[],
|
|
156
|
+
deltaAmounts: bigint[],
|
|
157
|
+
externalActionId: ExternalActionId,
|
|
158
|
+
swapData: string,
|
|
159
|
+
feeToken?: string,
|
|
160
|
+
feeStructureOverride?: FeeStructure,
|
|
161
|
+
action?: AdminTransactionType,
|
|
162
|
+
onlyGasEstimate?: boolean,
|
|
163
|
+
withPrivateMempool?: boolean,
|
|
164
|
+
): Promise<RelayerTransaction | bigint>;
|
|
165
|
+
|
|
166
|
+
getProviderAdapter(): IProviderAdapter;
|
|
167
|
+
|
|
168
|
+
initUserKeys(): Promise<void>;
|
|
169
|
+
|
|
170
|
+
initUserKeysWithPassword(password: string): Promise<void>;
|
|
171
|
+
|
|
172
|
+
initProviderAdapter(connector: ConnectorType, providerAdapter: IProviderAdapter<ConnectorType>): Promise<void>;
|
|
173
|
+
|
|
174
|
+
connectAndPatchProvider(connector: ConnectorType): Promise<number>;
|
|
175
|
+
|
|
176
|
+
disconnectFromConnector(): Promise<void>;
|
|
177
|
+
|
|
178
|
+
updateProviderAdapter(providerAdapter: IProviderAdapter): Promise<void>;
|
|
179
|
+
|
|
180
|
+
setListeners(providerAdapter: IProviderAdapter): Promise<void>;
|
|
181
|
+
|
|
182
|
+
waitForTransaction(transactionHash: string, confirmations?: number): Promise<boolean>;
|
|
183
|
+
|
|
184
|
+
getContractMetadata(contractType: ContractType, chainId?: number): ContractMetadata;
|
|
185
|
+
|
|
186
|
+
getContract(contract: ContractType, contractAddress?: string, chainId?: number): ethers.Contract;
|
|
187
|
+
|
|
188
|
+
getContractWithSigner(contract: ContractType, contractAddress?: string): ethers.Contract;
|
|
189
|
+
|
|
190
|
+
getContractWithFetcher(contract: ContractType, contractAddress?: string): ethers.Contract;
|
|
191
|
+
|
|
192
|
+
getContractWithFetcherByChainId(
|
|
193
|
+
chainId: number,
|
|
194
|
+
contractType: ContractType,
|
|
195
|
+
contractAddress?: string,
|
|
196
|
+
): ethers.Contract;
|
|
197
|
+
|
|
198
|
+
getContractWithFetcherForEthereum(contract: ContractType, contractAddress?: string): ethers.Contract;
|
|
199
|
+
|
|
200
|
+
isSelectedNetworkSupported(): boolean;
|
|
201
|
+
|
|
202
|
+
switchNetwork(network: EthereumNetwork): Promise<unknown>;
|
|
203
|
+
|
|
204
|
+
switchAccount(signer: ethers.Signer): Promise<unknown>;
|
|
205
|
+
|
|
206
|
+
getCurrentChainId(): number;
|
|
207
|
+
|
|
208
|
+
monitorConnectedAddress(): Promise<void>;
|
|
209
|
+
|
|
210
|
+
getSelectedNetwork(): EthereumNetwork | undefined;
|
|
211
|
+
|
|
212
|
+
isPermitterAvailable(): boolean;
|
|
213
|
+
|
|
214
|
+
signMessage(message: Bytes | string): Promise<string>;
|
|
215
|
+
|
|
216
|
+
signTypedData(
|
|
217
|
+
domain: ethers.TypedDataDomain,
|
|
218
|
+
types: Record<string, ethers.TypedDataField[]>,
|
|
219
|
+
value: Record<string, unknown>,
|
|
220
|
+
): Promise<string>;
|
|
221
|
+
|
|
222
|
+
signWithSubAccount(
|
|
223
|
+
messageToSign: string | undefined,
|
|
224
|
+
typedData: TypedData | undefined,
|
|
225
|
+
subAccount: SubAccount,
|
|
226
|
+
): Promise<string>;
|
|
227
|
+
|
|
228
|
+
actionFundApproveAndTransact(
|
|
229
|
+
tokenChanges: TokenChanges<bigint>[],
|
|
230
|
+
subAccount: SubAccount,
|
|
231
|
+
spenderAddress?: string,
|
|
232
|
+
to?: string,
|
|
233
|
+
callDataString?: string,
|
|
234
|
+
value?: bigint,
|
|
235
|
+
feeToken?: string,
|
|
236
|
+
feeStructureOverride?: FeeStructure,
|
|
237
|
+
autoDepositBack?: boolean,
|
|
238
|
+
maxGasInDollar?: string,
|
|
239
|
+
action?: AdminTransactionType,
|
|
240
|
+
onlyGasEstimate?: boolean,
|
|
241
|
+
): Promise<RelayerTransaction | bigint>;
|
|
242
|
+
|
|
243
|
+
actionPrivateWallet(
|
|
244
|
+
erc20Addresses: string[],
|
|
245
|
+
deltaAmounts: bigint[],
|
|
246
|
+
onChainCreation: boolean[],
|
|
247
|
+
ops: string[],
|
|
248
|
+
emporiumTokenChanges: TokenChanges<bigint>[],
|
|
249
|
+
subAccount: SubAccount,
|
|
250
|
+
feeToken?: string,
|
|
251
|
+
feeStructureOverride?: FeeStructure,
|
|
252
|
+
relayOverride?: string,
|
|
253
|
+
autoDepositBack?: boolean,
|
|
254
|
+
maxGasInDollar?: string,
|
|
255
|
+
action?: AdminTransactionType,
|
|
256
|
+
onlyGasEstimate?: boolean,
|
|
257
|
+
): Promise<RelayerTransaction | bigint>;
|
|
258
|
+
|
|
259
|
+
actionReceive(
|
|
260
|
+
erc20Tokens: ERC20Token[],
|
|
261
|
+
deltaAmounts: bigint[],
|
|
262
|
+
feeTokens?: string,
|
|
263
|
+
feeStructureOverride?: FeeStructure,
|
|
264
|
+
subAccount?: SubAccount,
|
|
265
|
+
action?: AdminTransactionType,
|
|
266
|
+
onlyGasEstimate?: boolean,
|
|
267
|
+
): Promise<RelayerTransaction | bigint>;
|
|
268
|
+
|
|
269
|
+
approve(
|
|
270
|
+
erc20Addresses: string[],
|
|
271
|
+
amount: bigint,
|
|
272
|
+
approvedTo: string,
|
|
273
|
+
feeToken?: string,
|
|
274
|
+
feeStructureOverride?: FeeStructure,
|
|
275
|
+
onlyGasEstimate?: boolean,
|
|
276
|
+
): Promise<RelayerTransaction | bigint>;
|
|
277
|
+
|
|
278
|
+
hinkalInsideTransact(
|
|
279
|
+
erc20Addresses: string[],
|
|
280
|
+
deltaChanges: bigint[],
|
|
281
|
+
approvalChanges: bigint[],
|
|
282
|
+
externalAddress: string,
|
|
283
|
+
externalActionMetadata: string,
|
|
284
|
+
parsedInLogicMetadata: ParsedInLogicMetadata,
|
|
285
|
+
feeToken?: string,
|
|
286
|
+
feeStructureOverride?: FeeStructure,
|
|
287
|
+
action?: AdminTransactionType,
|
|
288
|
+
onlyGasEstimate?: boolean,
|
|
289
|
+
): Promise<RelayerTransaction | bigint>;
|
|
290
|
+
|
|
291
|
+
proxySwap(
|
|
292
|
+
erc20Tokens: ERC20Token[],
|
|
293
|
+
deltaAmounts: bigint[],
|
|
294
|
+
externalActionId: ExternalActionId,
|
|
295
|
+
swapData: string,
|
|
296
|
+
isTheSameChainSwap: boolean,
|
|
297
|
+
subAccount: SubAccount,
|
|
298
|
+
feeToken?: string,
|
|
299
|
+
feeStructureOverride?: FeeStructure,
|
|
300
|
+
autoDepositBack?: boolean,
|
|
301
|
+
maxGasInDollar?: string,
|
|
302
|
+
action?: AdminTransactionType,
|
|
303
|
+
onlyGasEstimate?: boolean,
|
|
304
|
+
): Promise<RelayerTransaction | bigint>;
|
|
305
|
+
|
|
306
|
+
multiSendPrivateRecipients(
|
|
307
|
+
erc20Tokens: ERC20Token[],
|
|
308
|
+
amounts: bigint[],
|
|
309
|
+
extendedRecipientInfos?: string[],
|
|
310
|
+
): Promise<ethers.ContractTransaction>;
|
|
311
|
+
|
|
312
|
+
areMerkleTreeUpdatesDisabled(): boolean;
|
|
313
|
+
|
|
314
|
+
updateMerkleTreeUpdates(value: boolean): void;
|
|
315
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { API } from '../../API/API';
|
|
2
|
+
import { networkRegistry } from '../../constants/chains.constants';
|
|
3
|
+
import { getErrorMessageFromSandboxRequest } from '../../error-handling/get-error.message';
|
|
4
|
+
import { TokenChanges } from '../../types/token.types';
|
|
5
|
+
import { ExternalActionId } from '../../types/external-action.types';
|
|
6
|
+
import { TransactionStatus } from '../../types/transactions.types';
|
|
7
|
+
import { SandboxRequestType } from '../../types/sandbox.types';
|
|
8
|
+
import { createTransaferEmporiumOpsBatch } from '../../functions/private-wallet';
|
|
9
|
+
import {
|
|
10
|
+
caseInsensitiveEqual,
|
|
11
|
+
convertEmporiumOpToCallInfo,
|
|
12
|
+
createTorRpcProvider,
|
|
13
|
+
getERC20Token,
|
|
14
|
+
getPublicBalance,
|
|
15
|
+
postToOffscreen,
|
|
16
|
+
} from '../../functions/utils';
|
|
17
|
+
import { getAmountInToken } from '../../functions/web3';
|
|
18
|
+
import { getFeeStructure } from '../../functions/pre-transaction/getFeeStructure';
|
|
19
|
+
import { modifyVolatileTokenAmountChanges } from '../../functions/pre-transaction/getVolatileTransferAmount';
|
|
20
|
+
import { IHinkal } from './IHinkal';
|
|
21
|
+
import { Logger } from '../../error-handling/logger';
|
|
22
|
+
import { MessagesFromOffscreen } from '../../types/offscreen.types';
|
|
23
|
+
import { gasErrorCodes } from '../../error-handling';
|
|
24
|
+
import { SubAccount } from '../../types/proxy.types';
|
|
25
|
+
import { CircomDataV1x1 } from '../../types';
|
|
26
|
+
|
|
27
|
+
export const handleAutoDepositBack = async (
|
|
28
|
+
hinkal: IHinkal,
|
|
29
|
+
walletAddress: string | undefined,
|
|
30
|
+
subAccount: SubAccount,
|
|
31
|
+
feeToken: string | undefined,
|
|
32
|
+
maxGasInDollar: string | undefined,
|
|
33
|
+
emporiumTokenChanges: TokenChanges<bigint>[],
|
|
34
|
+
circomData: CircomDataV1x1,
|
|
35
|
+
) => {
|
|
36
|
+
if (!walletAddress) return;
|
|
37
|
+
try {
|
|
38
|
+
const chainId = hinkal.getCurrentChainId();
|
|
39
|
+
|
|
40
|
+
const tokensToDepositBack = emporiumTokenChanges
|
|
41
|
+
.filter((tc) => !caseInsensitiveEqual(tc.token.erc20TokenAddress, feeToken))
|
|
42
|
+
.map((tc) => tc.token);
|
|
43
|
+
|
|
44
|
+
if (!tokensToDepositBack.length) return;
|
|
45
|
+
|
|
46
|
+
const { fetchRpcUrl } = networkRegistry[chainId];
|
|
47
|
+
if (!fetchRpcUrl) throw new Error(`No RPC URL configured for chain ${chainId}`);
|
|
48
|
+
|
|
49
|
+
const providerAdapter = createTorRpcProvider(fetchRpcUrl);
|
|
50
|
+
|
|
51
|
+
const amounts: bigint[] = await Promise.all(
|
|
52
|
+
tokensToDepositBack.map(async (token) => {
|
|
53
|
+
const balance = await getPublicBalance(providerAdapter as any, walletAddress, token);
|
|
54
|
+
return BigInt(balance?.balance || 0);
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const erc20Addresses = tokensToDepositBack.map(({ erc20TokenAddress }) => erc20TokenAddress);
|
|
59
|
+
|
|
60
|
+
const deltaAmounts = await modifyVolatileTokenAmountChanges(chainId, tokensToDepositBack, amounts, walletAddress);
|
|
61
|
+
|
|
62
|
+
const transferOps = createTransaferEmporiumOpsBatch(hinkal, erc20Addresses, deltaAmounts);
|
|
63
|
+
|
|
64
|
+
const feeStructure = await getFeeStructure(
|
|
65
|
+
chainId,
|
|
66
|
+
feeToken,
|
|
67
|
+
erc20Addresses,
|
|
68
|
+
ExternalActionId.Emporium,
|
|
69
|
+
transferOps.map((transferOp) => convertEmporiumOpToCallInfo(transferOp, walletAddress, chainId)),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const erc20FeeToken = getERC20Token(feeStructure.feeToken, chainId);
|
|
73
|
+
if (!erc20FeeToken) return;
|
|
74
|
+
const gasAmount = getAmountInToken(erc20FeeToken, feeStructure.flatFee);
|
|
75
|
+
|
|
76
|
+
const tokenPrice = await API.getTokenPrice(chainId, erc20FeeToken.erc20TokenAddress);
|
|
77
|
+
const gasFeeInDollar = tokenPrice.price * Number(gasAmount);
|
|
78
|
+
|
|
79
|
+
if (maxGasInDollar && +maxGasInDollar < gasFeeInDollar) {
|
|
80
|
+
postToOffscreen(MessagesFromOffscreen.AutoShieldTxStatus, {
|
|
81
|
+
message: gasErrorCodes.GAS_PRICE_EXCEEDS_AUTOSHIELD_LIMIT,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
postToOffscreen(MessagesFromOffscreen.AutoShieldTxStatus, { status: TransactionStatus.Loading });
|
|
87
|
+
|
|
88
|
+
const outCommitments = circomData.outCommitments?.flat();
|
|
89
|
+
const encryptedOutputs = circomData.encryptedOutputs?.flat();
|
|
90
|
+
const inputNullifiers = circomData.inputNullifiers?.flat();
|
|
91
|
+
|
|
92
|
+
const merkleTreeStartIndex = hinkal.merkleTreeHinkal.getStartIndex();
|
|
93
|
+
const merkleTreeCount = BigInt(hinkal.merkleTreeHinkal.toJSON().count);
|
|
94
|
+
|
|
95
|
+
const updateHinkal = outCommitments.length !== 0 || encryptedOutputs.length !== 0 || inputNullifiers.length !== 0;
|
|
96
|
+
|
|
97
|
+
if (updateHinkal) {
|
|
98
|
+
if (outCommitments.length !== 0) {
|
|
99
|
+
outCommitments.forEach((commitment) => {
|
|
100
|
+
if (commitment === '0' || commitment === '0x') {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
hinkal.merkleTreeHinkal.insert(BigInt(commitment), merkleTreeStartIndex + merkleTreeCount);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (encryptedOutputs.length !== 0) {
|
|
107
|
+
encryptedOutputs.forEach((encryptedOutput) => {
|
|
108
|
+
if (encryptedOutput === '0' || encryptedOutput === '0x') {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
hinkal.encryptedOutputs.push({
|
|
112
|
+
value: encryptedOutput,
|
|
113
|
+
isPositive: true,
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (inputNullifiers.length !== 0) {
|
|
118
|
+
inputNullifiers.forEach((inputNullifier) => {
|
|
119
|
+
if (inputNullifier === '0' || inputNullifier === '0x') {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
hinkal.nullifiers.add(inputNullifier);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
hinkal.updateMerkleTreeUpdates(false);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
await hinkal.actionReceive(tokensToDepositBack, amounts, feeStructure?.feeToken, undefined, subAccount);
|
|
129
|
+
|
|
130
|
+
postToOffscreen(MessagesFromOffscreen.AutoShieldTxStatus, { status: TransactionStatus.Confirmed });
|
|
131
|
+
} catch (error) {
|
|
132
|
+
postToOffscreen(MessagesFromOffscreen.AutoShieldTxStatus, {
|
|
133
|
+
status: TransactionStatus.Failed,
|
|
134
|
+
error: getErrorMessageFromSandboxRequest(error, SandboxRequestType.ReceiveFromShieldedAccount),
|
|
135
|
+
});
|
|
136
|
+
Logger.error('Error in auto deposit back:', error);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { FeeStructure } from '../../types/hinkal.types';
|
|
2
|
+
import { getNecessaryAssetsForFunding } from '../../functions/utils/walletBalances.utils';
|
|
3
|
+
import { generateFundApproveAndTransactOps } from '../../functions/private-wallet/emporium.helpers';
|
|
4
|
+
import { RelayerTransaction } from '../../types/relayer.types';
|
|
5
|
+
import { IHinkal } from './IHinkal';
|
|
6
|
+
import { TokenChanges } from '../../types/token.types';
|
|
7
|
+
import { UserKeys } from '../crypto-keys/keys';
|
|
8
|
+
import { SubAccount } from '../../types/proxy.types';
|
|
9
|
+
import { AdminTransactionType } from '../../types/admin.types';
|
|
10
|
+
|
|
11
|
+
export const hinkalActionFundApproveAndTransact = async (
|
|
12
|
+
hinkal: IHinkal,
|
|
13
|
+
tokenChanges: TokenChanges<bigint>[],
|
|
14
|
+
subAccount: SubAccount,
|
|
15
|
+
spenderAddress?: string,
|
|
16
|
+
to?: string,
|
|
17
|
+
callDataString?: string,
|
|
18
|
+
value?: bigint,
|
|
19
|
+
feeToken?: string,
|
|
20
|
+
feeStructureOverride?: FeeStructure,
|
|
21
|
+
autoDepositBack?: boolean,
|
|
22
|
+
maxGasInDollar?: string,
|
|
23
|
+
action?: AdminTransactionType,
|
|
24
|
+
onlyGasEstimate?: boolean,
|
|
25
|
+
): Promise<RelayerTransaction | bigint> => {
|
|
26
|
+
const walletAddress = UserKeys.getSignerAddressFromPrivateKey(subAccount.privateKey);
|
|
27
|
+
|
|
28
|
+
const { fundAmounts, tokensToFund, approveTokenAddresses, approvedTokenAmounts } = await getNecessaryAssetsForFunding(
|
|
29
|
+
hinkal,
|
|
30
|
+
walletAddress,
|
|
31
|
+
tokenChanges,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const erc20AddressesToFund = tokensToFund.map((token) => token.erc20TokenAddress);
|
|
35
|
+
|
|
36
|
+
const emporiumOps = generateFundApproveAndTransactOps(
|
|
37
|
+
hinkal,
|
|
38
|
+
erc20AddressesToFund,
|
|
39
|
+
fundAmounts,
|
|
40
|
+
approveTokenAddresses,
|
|
41
|
+
approvedTokenAmounts,
|
|
42
|
+
walletAddress,
|
|
43
|
+
spenderAddress,
|
|
44
|
+
to,
|
|
45
|
+
callDataString,
|
|
46
|
+
value,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return hinkal.actionPrivateWallet(
|
|
50
|
+
erc20AddressesToFund,
|
|
51
|
+
fundAmounts.map((amount) => -1n * amount), // deltaAmounts
|
|
52
|
+
erc20AddressesToFund.map(() => false), // onChainCreation
|
|
53
|
+
emporiumOps,
|
|
54
|
+
tokenChanges,
|
|
55
|
+
subAccount,
|
|
56
|
+
feeToken,
|
|
57
|
+
feeStructureOverride,
|
|
58
|
+
undefined,
|
|
59
|
+
autoDepositBack,
|
|
60
|
+
maxGasInDollar,
|
|
61
|
+
action,
|
|
62
|
+
onlyGasEstimate,
|
|
63
|
+
);
|
|
64
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createTransaferEmporiumOpsBatch } from '../../functions/private-wallet/emporium.helpers';
|
|
2
|
+
import { RelayerTransaction } from '../../types/relayer.types';
|
|
3
|
+
import { IHinkal } from './IHinkal';
|
|
4
|
+
import { getFeeStructure } from '../../functions/pre-transaction/getFeeStructure';
|
|
5
|
+
import { convertEmporiumOpToCallInfo } from '../../functions/utils/convertEmporiumOpToCallInfo';
|
|
6
|
+
import { ExternalActionId } from '../../types/external-action.types';
|
|
7
|
+
import { FeeStructure } from '../../types/hinkal.types';
|
|
8
|
+
import { ERC20Token } from '../../types/token.types';
|
|
9
|
+
import { modifyVolatileTokenAmountChanges } from '../../functions/pre-transaction/getVolatileTransferAmount';
|
|
10
|
+
import { UserKeys } from '../crypto-keys/keys';
|
|
11
|
+
import { SubAccount } from '../../types/proxy.types';
|
|
12
|
+
import { AdminTransactionType } from '../../types/admin.types';
|
|
13
|
+
|
|
14
|
+
export const hinkalActionReceive = async (
|
|
15
|
+
hinkal: IHinkal,
|
|
16
|
+
erc20Tokens: ERC20Token[],
|
|
17
|
+
deltaAmountsBase: bigint[], // should be positive
|
|
18
|
+
feeToken?: string,
|
|
19
|
+
feeStructureOverride?: FeeStructure,
|
|
20
|
+
subAccount?: SubAccount,
|
|
21
|
+
action?: AdminTransactionType,
|
|
22
|
+
onlyGasEstimate = false,
|
|
23
|
+
): Promise<RelayerTransaction | bigint> => {
|
|
24
|
+
if (!subAccount) throw Error('hinkalActionReceive: subAccount should be provided');
|
|
25
|
+
if (!feeToken) throw new Error('Fee token is required in hinkalActionReceive');
|
|
26
|
+
|
|
27
|
+
const chainId = hinkal.getCurrentChainId();
|
|
28
|
+
|
|
29
|
+
const walletAddress = UserKeys.getSignerAddressFromPrivateKey(subAccount.privateKey);
|
|
30
|
+
const erc20Addresses = erc20Tokens.map((token) => token.erc20TokenAddress);
|
|
31
|
+
const deltaAmounts = await modifyVolatileTokenAmountChanges(chainId, erc20Tokens, deltaAmountsBase, walletAddress);
|
|
32
|
+
|
|
33
|
+
const transferOps = createTransaferEmporiumOpsBatch(hinkal, erc20Addresses, deltaAmounts);
|
|
34
|
+
|
|
35
|
+
const feeStructure =
|
|
36
|
+
feeStructureOverride ??
|
|
37
|
+
(await getFeeStructure(
|
|
38
|
+
chainId,
|
|
39
|
+
feeToken,
|
|
40
|
+
erc20Addresses,
|
|
41
|
+
ExternalActionId.Emporium,
|
|
42
|
+
transferOps.map((transferOp) => convertEmporiumOpToCallInfo(transferOp, walletAddress, chainId)),
|
|
43
|
+
));
|
|
44
|
+
|
|
45
|
+
const emporiumTokenChanges = erc20Tokens.map((token, index) => ({
|
|
46
|
+
token,
|
|
47
|
+
amount: -1n * deltaAmounts[index],
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
return hinkal.actionPrivateWallet(
|
|
51
|
+
erc20Addresses,
|
|
52
|
+
deltaAmounts,
|
|
53
|
+
deltaAmounts.map(() => false),
|
|
54
|
+
transferOps,
|
|
55
|
+
emporiumTokenChanges,
|
|
56
|
+
subAccount,
|
|
57
|
+
feeToken,
|
|
58
|
+
feeStructure,
|
|
59
|
+
undefined,
|
|
60
|
+
undefined,
|
|
61
|
+
undefined,
|
|
62
|
+
action,
|
|
63
|
+
onlyGasEstimate,
|
|
64
|
+
);
|
|
65
|
+
};
|