@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,180 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/dot-notation */
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
|
|
4
|
+
import { chainIds, getNonLocalhostChainId } from '../../../constants/chains.constants';
|
|
5
|
+
import { permitSignatureValidFor } from '../../../constants/protocol.constants';
|
|
6
|
+
|
|
7
|
+
import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
|
|
8
|
+
|
|
9
|
+
import { ApprovalType, ERC20Token } from '../../../types/token.types';
|
|
10
|
+
import { ContractType } from '../../../types/ethereum-network.types';
|
|
11
|
+
|
|
12
|
+
const skipApprovalIfAlreadyHave = async (
|
|
13
|
+
amount: bigint,
|
|
14
|
+
contractToApprove: ethers.Contract,
|
|
15
|
+
tokenContract: ethers.Contract,
|
|
16
|
+
) => {
|
|
17
|
+
const allowance = BigInt(
|
|
18
|
+
await tokenContract['allowance'](await tokenContract.signer.getAddress(), contractToApprove.address),
|
|
19
|
+
);
|
|
20
|
+
return amount === allowance;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const clearAllowanceIfNecessary = async (
|
|
24
|
+
hinkal: IHinkal,
|
|
25
|
+
contractToApprove: ethers.Contract,
|
|
26
|
+
token: ERC20Token,
|
|
27
|
+
tokenContract: ethers.Contract,
|
|
28
|
+
) => {
|
|
29
|
+
if (getNonLocalhostChainId(hinkal.getCurrentChainId()) !== chainIds.ethMainnet) return;
|
|
30
|
+
if (token.symbol.toLowerCase() !== 'usdt') return;
|
|
31
|
+
const allowance = BigInt(
|
|
32
|
+
await tokenContract['allowance'](await tokenContract.signer.getAddress(), contractToApprove.address),
|
|
33
|
+
);
|
|
34
|
+
if (allowance === 0n) return;
|
|
35
|
+
const tx = await tokenContract['approve'](contractToApprove.address, 0n);
|
|
36
|
+
if (tx && 'hash' in tx) await hinkal.waitForTransaction(tx.hash);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const approveTokenToHinkal = async (
|
|
40
|
+
hinkal: IHinkal,
|
|
41
|
+
contractToApprove: ethers.Contract,
|
|
42
|
+
amount: bigint,
|
|
43
|
+
token: ERC20Token,
|
|
44
|
+
): Promise<Uint8Array | undefined> => {
|
|
45
|
+
const tokenContract = hinkal.getContractWithSigner(ContractType.ERC20Contract, token.erc20TokenAddress); // as IERC20;
|
|
46
|
+
|
|
47
|
+
const approvalType = token.approvalType ?? ApprovalType.Classic;
|
|
48
|
+
|
|
49
|
+
if (approvalType === ApprovalType.Classic || !hinkal.isPermitterAvailable()) {
|
|
50
|
+
const skipApproval = await skipApprovalIfAlreadyHave(amount, contractToApprove, tokenContract);
|
|
51
|
+
if (skipApproval) return undefined;
|
|
52
|
+
|
|
53
|
+
await clearAllowanceIfNecessary(hinkal, contractToApprove, token, tokenContract);
|
|
54
|
+
|
|
55
|
+
const tx = await tokenContract['approve'](
|
|
56
|
+
contractToApprove.address,
|
|
57
|
+
amount,
|
|
58
|
+
// { gasLimit: 10000000 }
|
|
59
|
+
);
|
|
60
|
+
if (tx && 'hash' in tx) await hinkal.waitForTransaction(tx.hash);
|
|
61
|
+
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const userAddress = await hinkal.getEthereumAddress();
|
|
66
|
+
|
|
67
|
+
const permitterContract = hinkal.getContract(ContractType.PermitterContract);
|
|
68
|
+
|
|
69
|
+
const nonceContract = hinkal.getContractWithFetcher(ContractType.ContractWithNonces, token.erc20TokenAddress);
|
|
70
|
+
const nonce: ethers.BigNumberish = await nonceContract['nonces'](userAddress);
|
|
71
|
+
|
|
72
|
+
const deadline = BigInt(Date.now() + permitSignatureValidFor) / 1000n; // we need to convert it into seconds
|
|
73
|
+
|
|
74
|
+
const dataToSign = {
|
|
75
|
+
owner: userAddress,
|
|
76
|
+
holder: userAddress,
|
|
77
|
+
spender: permitterContract.address,
|
|
78
|
+
value: amount,
|
|
79
|
+
nonce,
|
|
80
|
+
deadline,
|
|
81
|
+
expiry: deadline,
|
|
82
|
+
allowed: true,
|
|
83
|
+
};
|
|
84
|
+
const { v, r, s } = ethers.utils.splitSignature(
|
|
85
|
+
await hinkal.signTypedData(
|
|
86
|
+
{
|
|
87
|
+
name: await tokenContract['name'](),
|
|
88
|
+
chainId: hinkal.getCurrentChainId(),
|
|
89
|
+
version: '1',
|
|
90
|
+
verifyingContract: token.erc20TokenAddress,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
Permit:
|
|
94
|
+
approvalType === ApprovalType.ERC20Permit
|
|
95
|
+
? [
|
|
96
|
+
{
|
|
97
|
+
name: 'owner',
|
|
98
|
+
type: 'address',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'spender',
|
|
102
|
+
type: 'address',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'value',
|
|
106
|
+
type: 'uint256',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'nonce',
|
|
110
|
+
type: 'uint256',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'deadline',
|
|
114
|
+
type: 'uint256',
|
|
115
|
+
},
|
|
116
|
+
]
|
|
117
|
+
: [
|
|
118
|
+
{
|
|
119
|
+
name: 'holder',
|
|
120
|
+
type: 'address',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'spender',
|
|
124
|
+
type: 'address',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'nonce',
|
|
128
|
+
type: 'uint256',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'expiry',
|
|
132
|
+
type: 'uint256',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'allowed',
|
|
136
|
+
type: 'bool',
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
dataToSign,
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (approvalType === ApprovalType.ERC20Permit) {
|
|
145
|
+
const permitInterface = new ethers.utils.Interface([
|
|
146
|
+
'function permit(address owner,address spender,uint256 value,uint256 deadline,uint8 v,bytes32 r,bytes32 s) external',
|
|
147
|
+
]);
|
|
148
|
+
return ethers.utils
|
|
149
|
+
.arrayify(
|
|
150
|
+
permitInterface.encodeFunctionData('permit', [
|
|
151
|
+
dataToSign.owner,
|
|
152
|
+
dataToSign.spender,
|
|
153
|
+
dataToSign.value,
|
|
154
|
+
dataToSign.deadline,
|
|
155
|
+
v,
|
|
156
|
+
ethers.utils.arrayify(r),
|
|
157
|
+
ethers.utils.arrayify(s),
|
|
158
|
+
]),
|
|
159
|
+
)
|
|
160
|
+
.slice(4);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const permitInterface = new ethers.utils.Interface([
|
|
164
|
+
'function permit(address holder,address spender,uint256 nonce,uint256 expiry,bool allowed,uint8 v,bytes32 r,bytes32 s) external',
|
|
165
|
+
]);
|
|
166
|
+
return ethers.utils
|
|
167
|
+
.arrayify(
|
|
168
|
+
permitInterface.encodeFunctionData('permit', [
|
|
169
|
+
dataToSign.holder,
|
|
170
|
+
dataToSign.spender,
|
|
171
|
+
dataToSign.nonce,
|
|
172
|
+
dataToSign.expiry,
|
|
173
|
+
dataToSign.allowed,
|
|
174
|
+
v,
|
|
175
|
+
ethers.utils.arrayify(r),
|
|
176
|
+
ethers.utils.arrayify(s),
|
|
177
|
+
]),
|
|
178
|
+
)
|
|
179
|
+
.slice(4);
|
|
180
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { zeroAddress } from '../../../constants/protocol.constants';
|
|
3
|
+
import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
|
|
4
|
+
import { ERC20Token } from '../../../types/token.types';
|
|
5
|
+
import { approveTokenToHinkal } from './approveToken';
|
|
6
|
+
|
|
7
|
+
export const approveTokensToHinkal = async (
|
|
8
|
+
hinkal: IHinkal,
|
|
9
|
+
contractForApproval: ethers.Contract,
|
|
10
|
+
tokensToApprove: ERC20Token[],
|
|
11
|
+
amounts: bigint[],
|
|
12
|
+
) => {
|
|
13
|
+
for (let i = 0; i < amounts.length; i += 1) {
|
|
14
|
+
const currentAmount = amounts[i];
|
|
15
|
+
const currentToken = tokensToApprove[i];
|
|
16
|
+
if (currentAmount > 0n && currentToken.erc20TokenAddress !== zeroAddress) {
|
|
17
|
+
// eslint-disable-next-line no-await-in-loop
|
|
18
|
+
await approveTokenToHinkal(hinkal, contractForApproval, currentAmount, currentToken);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
|
|
2
|
+
import { CircomDataBaseType, DimDataType } from '../../../types/circom-data.types';
|
|
3
|
+
import { NewZkCallDataType } from '../../../types/snark.types';
|
|
4
|
+
import { type AuthorizationData } from '../../../types/hinkal.types';
|
|
5
|
+
import { ethers as ethersV6, InterfaceAbi } from 'ethers-v6h';
|
|
6
|
+
import { recoverAuthorizationData } from '../../private-wallet/emporium.helpers';
|
|
7
|
+
import { networkRegistry } from '../../../constants/chains.constants';
|
|
8
|
+
|
|
9
|
+
export const estimateGasRelayer = async (
|
|
10
|
+
hinkal: IHinkal,
|
|
11
|
+
newZkCallData: NewZkCallDataType,
|
|
12
|
+
dimData: DimDataType,
|
|
13
|
+
circomData: CircomDataBaseType,
|
|
14
|
+
authorizationData?: AuthorizationData,
|
|
15
|
+
): Promise<bigint> => {
|
|
16
|
+
const { hinkalAddress, hinkalABI } = networkRegistry[hinkal.getCurrentChainId()].contractData;
|
|
17
|
+
const provider = new ethersV6.JsonRpcProvider(networkRegistry[hinkal.getCurrentChainId()].fetchRpcUrl);
|
|
18
|
+
const hinkalContract = new ethersV6.Contract(hinkalAddress, hinkalABI as InterfaceAbi, provider);
|
|
19
|
+
|
|
20
|
+
const callFunctionForGas = 'transact';
|
|
21
|
+
|
|
22
|
+
let overrides: ethersV6.TransactionRequest = { from: circomData.relay };
|
|
23
|
+
if (authorizationData) {
|
|
24
|
+
const authData = recoverAuthorizationData(authorizationData);
|
|
25
|
+
if (authData) {
|
|
26
|
+
overrides = { ...overrides, authorizationList: [authData], type: 4 };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const gasEstimate = await hinkalContract[callFunctionForGas].estimateGas(
|
|
31
|
+
newZkCallData[0],
|
|
32
|
+
newZkCallData[1],
|
|
33
|
+
newZkCallData[2],
|
|
34
|
+
dimData,
|
|
35
|
+
circomData,
|
|
36
|
+
overrides,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return gasEstimate;
|
|
40
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
|
+
|
|
3
|
+
export const getRootHash = async (merkleTreeContract: Contract): Promise<bigint> => {
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
5
|
+
const rootHash = await merkleTreeContract['getRootHash']();
|
|
6
|
+
return rootHash.toBigInt();
|
|
7
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/dot-notation */
|
|
2
|
+
import { BigNumber } from 'ethers';
|
|
3
|
+
import { type IHinkal } from '../../../data-structures/Hinkal/IHinkal';
|
|
4
|
+
import { type ApprovedUtxo } from '../../../types';
|
|
5
|
+
import { ContractType } from '../../../types/ethereum-network.types';
|
|
6
|
+
|
|
7
|
+
export const getInteractionApprovals = async (hinkal: IHinkal, interactionAddress: string) => {
|
|
8
|
+
const hinkalContract = hinkal.getContractWithFetcher(ContractType.HinkalContract);
|
|
9
|
+
|
|
10
|
+
const plainApprovedUtxos: unknown[] = await hinkalContract.callStatic['getInteractionApprovals'](interactionAddress);
|
|
11
|
+
|
|
12
|
+
if (!plainApprovedUtxos) {
|
|
13
|
+
throw Error('getInteractionApprovals fail: no approved utxos fetched');
|
|
14
|
+
}
|
|
15
|
+
const approvedUtxos: ApprovedUtxo[] = plainApprovedUtxos.map((entry) => {
|
|
16
|
+
const element = entry as ApprovedUtxo<BigNumber>;
|
|
17
|
+
return {
|
|
18
|
+
amount: element['amount'].toBigInt(),
|
|
19
|
+
inHinkalAddress: element['inHinkalAddress'].toBigInt(),
|
|
20
|
+
tokenAddress: element['tokenAddress'],
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
return approvedUtxos;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const checkExistingApprovalFromHinkal = async (
|
|
27
|
+
hinkal: IHinkal,
|
|
28
|
+
erc20Address: string,
|
|
29
|
+
interactionAddress: string,
|
|
30
|
+
): Promise<bigint> => {
|
|
31
|
+
const hinkalContract = hinkal.getContractWithFetcher(ContractType.HinkalContract);
|
|
32
|
+
const erc20Token = hinkal.getContractWithFetcher(ContractType.ERC20Contract, erc20Address);
|
|
33
|
+
|
|
34
|
+
const approvalAmountBG: BigNumber = await erc20Token.callStatic['allowance'](
|
|
35
|
+
hinkalContract.address,
|
|
36
|
+
interactionAddress,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (approvalAmountBG === undefined) {
|
|
40
|
+
throw Error('checkExistingApprovalFromHinkal Error, no allowance fetched');
|
|
41
|
+
}
|
|
42
|
+
return approvalAmountBG.toBigInt();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const getBufferEntry = async (
|
|
46
|
+
hinkal: IHinkal,
|
|
47
|
+
approveTo: string,
|
|
48
|
+
tokenAddress: string,
|
|
49
|
+
inHinkalAddress: bigint,
|
|
50
|
+
) => {
|
|
51
|
+
const hinkalContract = hinkal.getContractWithFetcher(ContractType.HinkalContract);
|
|
52
|
+
|
|
53
|
+
const amount: BigNumber = await hinkalContract.callStatic['getBufferEntry'](approveTo, tokenAddress, inHinkalAddress);
|
|
54
|
+
|
|
55
|
+
if (amount === undefined) {
|
|
56
|
+
throw Error('getBufferEntry Fail: No amount fatched');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return amount.toBigInt();
|
|
60
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/dot-notation */
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
|
|
4
|
+
export const getRelayPercentage = async (contract: ethers.Contract): Promise<bigint> => {
|
|
5
|
+
const relayPercentage = await contract['relayPercentage']();
|
|
6
|
+
return BigInt(relayPercentage);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const getRelay = async (hinkalHelperContract: ethers.Contract): Promise<string> => {
|
|
10
|
+
const relayList: string[] = await hinkalHelperContract['getRelayStore']();
|
|
11
|
+
return relayList[0];
|
|
12
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* eslint-disable no-undef-init */
|
|
3
|
+
/* eslint-disable @typescript-eslint/dot-notation */
|
|
4
|
+
import { ethers } from 'ethers';
|
|
5
|
+
import { zeroAddress } from '../../../constants/protocol.constants';
|
|
6
|
+
import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
|
|
7
|
+
|
|
8
|
+
import { CircomDataBaseType, DimDataType } from '../../../types/circom-data.types';
|
|
9
|
+
import { ContractType } from '../../../types/ethereum-network.types';
|
|
10
|
+
import { ERC20Token } from '../../../types/token.types';
|
|
11
|
+
import { NewZkCallDataType } from '../../../types/snark.types';
|
|
12
|
+
import { waitLittle } from '../../utils/time.utils';
|
|
13
|
+
import { approveTokensToHinkal } from './approveTokensToHinkal';
|
|
14
|
+
|
|
15
|
+
export const transactCallDirect = async (
|
|
16
|
+
hinkal: IHinkal,
|
|
17
|
+
amount: bigint | bigint[],
|
|
18
|
+
tokenToApprove: ERC20Token | ERC20Token[],
|
|
19
|
+
newZkCallData: NewZkCallDataType,
|
|
20
|
+
circomData: CircomDataBaseType,
|
|
21
|
+
dimData: DimDataType,
|
|
22
|
+
contractApproval?: ethers.Contract,
|
|
23
|
+
contractTransaction?: ethers.Contract,
|
|
24
|
+
) => {
|
|
25
|
+
const amounts = Array.isArray(amount) ? amount : [amount];
|
|
26
|
+
const tokensToApprove = Array.isArray(tokenToApprove) ? tokenToApprove : [tokenToApprove];
|
|
27
|
+
if (amounts.length !== tokensToApprove.length) throw new Error('token and amount length mismatch');
|
|
28
|
+
const hinkalContract = hinkal.getContractWithSigner(ContractType.HinkalContract);
|
|
29
|
+
const ethereumAddress = await hinkal.getEthereumAddress();
|
|
30
|
+
|
|
31
|
+
const contractForApproval = contractApproval ?? hinkalContract;
|
|
32
|
+
const contractForTransaction = contractTransaction ?? hinkalContract;
|
|
33
|
+
|
|
34
|
+
const method = 'transact';
|
|
35
|
+
await approveTokensToHinkal(hinkal, contractForApproval, tokensToApprove, amounts);
|
|
36
|
+
|
|
37
|
+
const ethIndex = tokensToApprove.findIndex(({ erc20TokenAddress }) => erc20TokenAddress === zeroAddress);
|
|
38
|
+
const ethAmount = ethIndex === -1 ? 0n : amounts[ethIndex];
|
|
39
|
+
|
|
40
|
+
const overrides: { value?: string; gasLimit?: number } = {
|
|
41
|
+
value: ethAmount > 0n ? BigInt(ethAmount).toString() : undefined,
|
|
42
|
+
};
|
|
43
|
+
let gasCosts: number | undefined = undefined;
|
|
44
|
+
|
|
45
|
+
const callData = [
|
|
46
|
+
newZkCallData[0],
|
|
47
|
+
newZkCallData[1],
|
|
48
|
+
newZkCallData[2],
|
|
49
|
+
dimData,
|
|
50
|
+
circomData,
|
|
51
|
+
{ ...overrides, from: ethereumAddress },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
gasCosts = (await contractForTransaction.estimateGas[method](...callData)).toNumber();
|
|
56
|
+
console.log({ gasCosts });
|
|
57
|
+
console.log({
|
|
58
|
+
signerAddress: await contractForTransaction.signer.getAddress(),
|
|
59
|
+
chainIdHinkal: hinkal.getCurrentChainId(),
|
|
60
|
+
ethersNetwork: await contractForTransaction.provider.getNetwork(),
|
|
61
|
+
});
|
|
62
|
+
} catch (err: any) {
|
|
63
|
+
console.log('hinkalDeposit: gas estimation error', { err });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const extendedGasCosts = gasCosts && gasCosts >= 0 ? Math.ceil((gasCosts * 12) / 10) : undefined;
|
|
67
|
+
overrides.gasLimit = extendedGasCosts;
|
|
68
|
+
await waitLittle(); // because public rpc link gives 429
|
|
69
|
+
const tx = await contractForTransaction[method](...callData);
|
|
70
|
+
return tx;
|
|
71
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ErrorWithRelayerTransaction } from '../../../error-handling';
|
|
2
|
+
import { callRelayerTransactAPI } from '../../../API/callRelayer';
|
|
3
|
+
import {
|
|
4
|
+
AdminDataType,
|
|
5
|
+
AuthorizationData,
|
|
6
|
+
CircomDataBaseJsonType,
|
|
7
|
+
CircomDataBaseType,
|
|
8
|
+
CircomDataV1,
|
|
9
|
+
CircomDataV1x1,
|
|
10
|
+
DimDataType,
|
|
11
|
+
NewZkCallDataType,
|
|
12
|
+
RelayerTransaction,
|
|
13
|
+
} from '../../../types';
|
|
14
|
+
import { serializeCircomData } from '../../snarkjs';
|
|
15
|
+
|
|
16
|
+
export interface RelayerResponseInterface {
|
|
17
|
+
status: string;
|
|
18
|
+
message: RelayerTransaction;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const transactCallRelayer = async (
|
|
23
|
+
chainId: number,
|
|
24
|
+
newZkCallData: NewZkCallDataType,
|
|
25
|
+
dimData: DimDataType,
|
|
26
|
+
circomData: CircomDataBaseType,
|
|
27
|
+
withPrivateMempool?: boolean,
|
|
28
|
+
// use workaround for uniswap's dapp not properly recongnizing approval transaction
|
|
29
|
+
// this should not be used within our own dapp
|
|
30
|
+
withUniswapWorkAround?: boolean,
|
|
31
|
+
authorizationData?: AuthorizationData,
|
|
32
|
+
adminData?: AdminDataType,
|
|
33
|
+
): Promise<RelayerTransaction> => {
|
|
34
|
+
const circomDataJson: CircomDataBaseJsonType = serializeCircomData(circomData as CircomDataV1 | CircomDataV1x1);
|
|
35
|
+
const relayerResponse: RelayerResponseInterface = await callRelayerTransactAPI(chainId, {
|
|
36
|
+
a: newZkCallData[0],
|
|
37
|
+
b: newZkCallData[1],
|
|
38
|
+
c: newZkCallData[2],
|
|
39
|
+
dimData,
|
|
40
|
+
circomData: circomDataJson,
|
|
41
|
+
withPrivateMempool,
|
|
42
|
+
withUniswapWorkAround,
|
|
43
|
+
authorizationData,
|
|
44
|
+
adminData,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (relayerResponse.status === 'success') {
|
|
48
|
+
return relayerResponse.message;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (relayerResponse.message && relayerResponse.error) {
|
|
52
|
+
const error = new ErrorWithRelayerTransaction(relayerResponse.error, relayerResponse.message);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
const error = new Error(relayerResponse.error);
|
|
56
|
+
throw error;
|
|
57
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { contractMetadataMapping } from '../../constants/contracts.constants';
|
|
2
|
+
import { networkRegistry } from '../../constants/chains.constants';
|
|
3
|
+
import { ContractMetadata, ContractType } from '../../types/ethereum-network.types';
|
|
4
|
+
import { transactionErrorCodes } from '../../error-handling/error-codes.constants';
|
|
5
|
+
import { ethers } from 'ethers';
|
|
6
|
+
import { createTorRpcProvider } from '../utils';
|
|
7
|
+
|
|
8
|
+
export const getContractMetadata = (contractType: ContractType, chainId: number): ContractMetadata => {
|
|
9
|
+
const network = networkRegistry[chainId];
|
|
10
|
+
if (!network) {
|
|
11
|
+
throw new Error(transactionErrorCodes.UNSUPPORTED_NETWORK);
|
|
12
|
+
}
|
|
13
|
+
const getContractMetadataFn = contractMetadataMapping[contractType];
|
|
14
|
+
if (!getContractMetadataFn) {
|
|
15
|
+
throw new Error(`Unsupported contractType: ${contractType}`);
|
|
16
|
+
}
|
|
17
|
+
return getContractMetadataFn(network.contractData);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const getContract = (contractType: ContractType, chainId: number, contractAddress?: string) => {
|
|
21
|
+
const contractMetadata: ContractMetadata = getContractMetadata(contractType, chainId);
|
|
22
|
+
if (!contractMetadata.abi) {
|
|
23
|
+
throw new Error(`No ABI configured for contractType: ${contractType}`);
|
|
24
|
+
}
|
|
25
|
+
if (contractMetadata.address && contractAddress) {
|
|
26
|
+
throw new Error(`Overriding address is not supported for contractType: ${contractType}`);
|
|
27
|
+
}
|
|
28
|
+
const resultContractAddress = contractMetadata.address ?? contractAddress;
|
|
29
|
+
if (!resultContractAddress) {
|
|
30
|
+
throw new Error(`No contractAddress configured for contractType: ${contractType}`);
|
|
31
|
+
}
|
|
32
|
+
return new ethers.Contract(resultContractAddress, contractMetadata.abi);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getContractWithFetcherByChainId = (
|
|
36
|
+
chainId: number,
|
|
37
|
+
contractType: ContractType,
|
|
38
|
+
contractAddress = undefined,
|
|
39
|
+
): ethers.Contract => {
|
|
40
|
+
const { fetchRpcUrl } = networkRegistry[chainId];
|
|
41
|
+
if (!fetchRpcUrl) throw new Error('RPC URL not found for the specified chain ID');
|
|
42
|
+
return getContract(contractType, chainId, contractAddress).connect(createTorRpcProvider(fetchRpcUrl));
|
|
43
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type IHinkal } from '../../data-structures/Hinkal/IHinkal';
|
|
2
|
+
import { zeroAddress } from '../../constants/protocol.constants';
|
|
3
|
+
import { ContractType } from '../../types/ethereum-network.types';
|
|
4
|
+
|
|
5
|
+
export const getPublicAddressBalance = async (
|
|
6
|
+
hinkal: IHinkal,
|
|
7
|
+
tokenAddress: string,
|
|
8
|
+
ethereumAddress: string,
|
|
9
|
+
): Promise<bigint> => {
|
|
10
|
+
const tokenContract = hinkal.getContractWithFetcher(ContractType.ERC20Contract, tokenAddress);
|
|
11
|
+
|
|
12
|
+
if (tokenAddress === zeroAddress) {
|
|
13
|
+
return (await tokenContract.provider.getBalance(ethereumAddress)).toBigInt();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (await tokenContract['balanceOf'](ethereumAddress)).toBigInt();
|
|
17
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { chainIds, networkRegistry } from '../../constants/chains.constants';
|
|
3
|
+
import { ERC20ABI } from '../../externalABIs';
|
|
4
|
+
import { httpClient } from '../../data-structures/tor';
|
|
5
|
+
import { createTorRpcProvider } from '../utils';
|
|
6
|
+
|
|
7
|
+
// avalanche and arcTestnet are not supported by blockscout
|
|
8
|
+
const chainNameMapping = {
|
|
9
|
+
[chainIds.base]: 'base',
|
|
10
|
+
[chainIds.optimism]: 'optimism',
|
|
11
|
+
[chainIds.arbMainnet]: 'arbitrum',
|
|
12
|
+
[chainIds.polygon]: 'polygon',
|
|
13
|
+
[chainIds.ethMainnet]: 'eth',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getTokenHolderFromBlockscout = async (chainId: number, tokenAddress: string) => {
|
|
17
|
+
const chainName = chainNameMapping[chainId];
|
|
18
|
+
const url = `https://${chainName}.blockscout.com/api?module=token&action=getTokenHolders&contractaddress=${tokenAddress}&page=0&offset=10`;
|
|
19
|
+
const { result } = await httpClient.get<{ result: { address: string; value: string }[] }>(url);
|
|
20
|
+
const { fetchRpcUrl } = networkRegistry[chainId];
|
|
21
|
+
if (!fetchRpcUrl) throw new Error('RPC URL not found for the specified chain ID');
|
|
22
|
+
const provider = createTorRpcProvider(fetchRpcUrl);
|
|
23
|
+
const tokenContract = new ethers.Contract(tokenAddress, ERC20ABI, provider);
|
|
24
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
25
|
+
for (const { address } of result) {
|
|
26
|
+
// eslint-disable-next-line no-await-in-loop
|
|
27
|
+
const balance: ethers.BigNumber = await tokenContract['balanceOf'](address);
|
|
28
|
+
if (balance.toBigInt() !== 0n) return address;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getTokenHolderFromRoutescan = async (chainId: number, tokenAddress: string) => {
|
|
34
|
+
const url = `https://api.routescan.io/v2/network/mainnet/evm/${chainId}/etherscan/api?module=token&action=tokenholderlist&contractaddress=${tokenAddress}&page=1&offset=10&apikey=YourApiKeyToken`;
|
|
35
|
+
const { result } = await httpClient.get<{ result: { TokenHolderAddress: string; TokenHolderQuantity: string }[] }>(
|
|
36
|
+
url,
|
|
37
|
+
);
|
|
38
|
+
return result.at(0)?.TokenHolderAddress;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const getTokenHolder = async (chainId: number, tokenAddress: string) => {
|
|
42
|
+
try {
|
|
43
|
+
if (!(chainId in chainNameMapping)) throw new Error('Chain is not supported by blockscout');
|
|
44
|
+
|
|
45
|
+
const tokenHolderFromBlockScout = await getTokenHolderFromBlockscout(chainId, tokenAddress);
|
|
46
|
+
if (!tokenHolderFromBlockScout || !ethers.utils.isAddress(tokenHolderFromBlockScout)) {
|
|
47
|
+
throw new Error('Token holder not found in blockscout');
|
|
48
|
+
}
|
|
49
|
+
return tokenHolderFromBlockScout;
|
|
50
|
+
} catch {
|
|
51
|
+
return await getTokenHolderFromRoutescan(chainId, tokenAddress);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './etherFunctions';
|
|
2
|
+
export * from './events';
|
|
3
|
+
export * from './uniswapAPI';
|
|
4
|
+
export * from './odosAPI';
|
|
5
|
+
export * from './oneInchAPI';
|
|
6
|
+
export * from './lifiAPI';
|
|
7
|
+
export * from './runContractFunction';
|
|
8
|
+
export * from './getTokenHolder';
|
|
9
|
+
export * from './EIP-712';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { transactionErrorCodes } from '../../error-handling/error-codes.constants';
|
|
2
|
+
import { ERC20Token } from '../../types/token.types';
|
|
3
|
+
import { callLifiAPI, LifiRequestData } from '../../API/callLifiAPI';
|
|
4
|
+
import { getAmountInWei } from './etherFunctions';
|
|
5
|
+
import { zeroAddress } from '../../constants/protocol.constants';
|
|
6
|
+
|
|
7
|
+
export const getLifiPrice = async (
|
|
8
|
+
chainId: number,
|
|
9
|
+
inSwapToken: ERC20Token,
|
|
10
|
+
outSwapToken: ERC20Token,
|
|
11
|
+
inSwapAmount: string,
|
|
12
|
+
bridgingSlippage: number,
|
|
13
|
+
fromAddress: string,
|
|
14
|
+
toAddress?: string,
|
|
15
|
+
) => {
|
|
16
|
+
try {
|
|
17
|
+
const fromAmount = getAmountInWei(inSwapToken, inSwapAmount);
|
|
18
|
+
const request: LifiRequestData = {
|
|
19
|
+
fromChain: inSwapToken.chainId,
|
|
20
|
+
toChain: outSwapToken.chainId,
|
|
21
|
+
fromToken: inSwapToken.erc20TokenAddress,
|
|
22
|
+
toToken: outSwapToken.erc20TokenAddress,
|
|
23
|
+
fromAddress,
|
|
24
|
+
fromAmount: fromAmount.toString(),
|
|
25
|
+
order: 'FASTEST', // TO BE DECIDED
|
|
26
|
+
slippage: bridgingSlippage,
|
|
27
|
+
...(toAddress && { toAddress }),
|
|
28
|
+
};
|
|
29
|
+
const { lifiResponse } = await callLifiAPI(chainId, request);
|
|
30
|
+
return {
|
|
31
|
+
lifiDataValue: lifiResponse.transactionRequest.data,
|
|
32
|
+
outSwapAmountValue: BigInt(lifiResponse.estimate.toAmount),
|
|
33
|
+
extraNativeTokenFee:
|
|
34
|
+
inSwapToken.erc20TokenAddress === zeroAddress
|
|
35
|
+
? BigInt(lifiResponse.transactionRequest.value) - fromAmount
|
|
36
|
+
: BigInt(lifiResponse.transactionRequest.value),
|
|
37
|
+
};
|
|
38
|
+
} catch (error: unknown) {
|
|
39
|
+
throw Error(transactionErrorCodes.NO_LIFI_PRICE);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { callOdosAPI, OdosSwapData, OdosSwapRequest } from '../../API/callOdosAPI';
|
|
2
|
+
import { localhostNetwork, networkRegistry, zeroAddress } from '../../constants';
|
|
3
|
+
import { transactionErrorCodes } from '../../error-handling';
|
|
4
|
+
import { ERC20Token } from '../../types';
|
|
5
|
+
import { getAmountInWei } from './etherFunctions';
|
|
6
|
+
|
|
7
|
+
export const getOdosPrice = async (
|
|
8
|
+
chainId: number,
|
|
9
|
+
inSwapToken: ERC20Token,
|
|
10
|
+
outSwapToken: ERC20Token,
|
|
11
|
+
inSwapAmount: string,
|
|
12
|
+
slippagePercentage = 0.7,
|
|
13
|
+
) => {
|
|
14
|
+
try {
|
|
15
|
+
const raw: OdosSwapRequest = {
|
|
16
|
+
chainId: chainId !== 31337 ? chainId : localhostNetwork,
|
|
17
|
+
inputTokens: [
|
|
18
|
+
{
|
|
19
|
+
tokenAddress: inSwapToken?.wrappedErc20TokenAddress ?? inSwapToken.erc20TokenAddress,
|
|
20
|
+
amount: getAmountInWei(inSwapToken, inSwapAmount).toString(),
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
outputTokens: [
|
|
24
|
+
{
|
|
25
|
+
tokenAddress: outSwapToken?.wrappedErc20TokenAddress ?? outSwapToken.erc20TokenAddress,
|
|
26
|
+
proportion: 1,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
userAddr: networkRegistry[chainId].contractData.odosExternalActionInstanceAddress || zeroAddress,
|
|
30
|
+
slippageLimitPercent: slippagePercentage,
|
|
31
|
+
disableRFQs: true, // sometimes swap fails because of RFQs
|
|
32
|
+
};
|
|
33
|
+
const { odosResponse, status }: { odosResponse: OdosSwapData; status: string; message: string } = await callOdosAPI(
|
|
34
|
+
chainId,
|
|
35
|
+
raw,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (status !== 'success') {
|
|
39
|
+
throw Error('Odos API Fetch Error');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
outSwapAmountValue: BigInt(odosResponse.outputTokens[0].amount),
|
|
44
|
+
odosDataValue: odosResponse.transaction.data,
|
|
45
|
+
};
|
|
46
|
+
} catch (error: unknown) {
|
|
47
|
+
console.log({ error });
|
|
48
|
+
throw Error(transactionErrorCodes.NO_ODOS_PRICE);
|
|
49
|
+
}
|
|
50
|
+
};
|