@hinkal/common 0.2.22 → 0.2.23
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/API/proxyAccountsCalls.cjs +1 -1
- package/API/proxyAccountsCalls.mjs +13 -13
- package/README.md +63 -267
- package/constants/activity.constants.cjs +1 -1
- package/constants/activity.constants.mjs +0 -1
- package/constants/addresses.constants.cjs +1 -1
- package/constants/addresses.constants.mjs +9 -10
- package/constants/contracts.constants.cjs +1 -1
- package/constants/contracts.constants.d.ts +3 -3
- package/constants/contracts.constants.mjs +29 -29
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.mjs +28 -29
- package/constants/tasks.constants.cjs +1 -1
- package/constants/tasks.constants.mjs +4 -5
- package/crypto/poseidon.cjs +1 -1
- package/crypto/poseidon.mjs +10 -10
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +24 -24
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +4 -5
- package/data-structures/Hinkal/IHinkal.d.ts +2 -2
- package/data-structures/Hinkal/hinkalApprove.cjs +1 -1
- package/data-structures/Hinkal/hinkalApprove.mjs +40 -40
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.cjs +1 -1
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.mjs +7 -8
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +4 -5
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +2 -3
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +18 -19
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +3 -4
- package/data-structures/Hinkal/hinkalInsideTransact.cjs +1 -1
- package/data-structures/Hinkal/hinkalInsideTransact.mjs +14 -13
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +2 -3
- package/data-structures/Hinkal/hinkalProoflessDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalProoflessDeposit.mjs +27 -26
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +38 -39
- package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaSwap.mjs +16 -17
- package/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaTransfer.mjs +24 -25
- package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +15 -16
- package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +2 -3
- package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalTransfer.mjs +2 -3
- package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.mjs +9 -10
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +8 -9
- package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/data-structures/Hinkal/resetMerkleTrees.mjs +10 -10
- package/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/data-structures/IndexedDB/activity-db.mjs +39 -41
- package/data-structures/IndexedDB/balances-db.cjs +1 -1
- package/data-structures/IndexedDB/balances-db.mjs +8 -9
- package/data-structures/IndexedDB/contact-db.cjs +1 -1
- package/data-structures/IndexedDB/contact-db.mjs +21 -23
- package/data-structures/IndexedDB/signatures-db.cjs +1 -1
- package/data-structures/IndexedDB/signatures-db.mjs +2 -3
- package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +34 -36
- package/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
- package/data-structures/crypto-keys/decodeUTXO.mjs +45 -45
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +28 -27
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.d.ts +2 -3
- package/data-structures/crypto-keys/keys.mjs +56 -57
- package/data-structures/event-service/evm/AbstractEventService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractEventService.mjs +14 -14
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.d.ts +2 -3
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.mjs +5 -4
- package/data-structures/event-service/evm/AbstractSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractSnapshotService.mjs +6 -3
- package/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.d.ts +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.mjs +22 -18
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.mjs +2 -2
- package/data-structures/presale/PresaleContractWrapper.cjs +1 -1
- package/data-structures/presale/PresaleContractWrapper.d.ts +3 -3
- package/data-structures/presale/PresaleContractWrapper.mjs +10 -10
- package/data-structures/provider-adapter/IProviderAdapter.d.ts +7 -7
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.mjs +16 -14
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.mjs +7 -5
- package/error-handling/get-error.message.cjs +1 -1
- package/error-handling/get-error.message.mjs +2 -3
- package/functions/kyc/zkMeHelper.cjs +1 -1
- package/functions/kyc/zkMeHelper.mjs +3 -3
- package/functions/pre-transaction/getFlatFees.cjs +1 -1
- package/functions/pre-transaction/getFlatFees.mjs +2 -3
- package/functions/pre-transaction/getSolanaCalldataHash.cjs +1 -1
- package/functions/pre-transaction/getSolanaCalldataHash.mjs +21 -21
- package/functions/pre-transaction/getVolatileTransferAmount.cjs +1 -1
- package/functions/pre-transaction/getVolatileTransferAmount.mjs +2 -3
- package/functions/pre-transaction/interaction-to-action.cjs +1 -1
- package/functions/pre-transaction/interaction-to-action.mjs +2 -3
- package/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.helpers.d.ts +6 -7
- package/functions/private-wallet/emporium.helpers.mjs +104 -105
- package/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.swap.helpers.mjs +44 -43
- package/functions/private-wallet/opProducer.cjs +1 -1
- package/functions/private-wallet/opProducer.mjs +1 -1
- package/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/functions/snarkjs/common.snarkjs.mjs +21 -18
- package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/functions/snarkjs/constructSolanaZkProof.mjs +11 -12
- package/functions/utils/addresses.cjs +1 -1
- package/functions/utils/addresses.mjs +6 -6
- package/functions/utils/cacheFunctions.cjs +1 -1
- package/functions/utils/cacheFunctions.d.ts +1 -1
- package/functions/utils/cacheFunctions.mjs +55 -54
- package/functions/utils/convertEmporiumOpToCallInfo.cjs +1 -1
- package/functions/utils/convertEmporiumOpToCallInfo.mjs +5 -5
- package/functions/utils/create-provider.cjs +1 -1
- package/functions/utils/create-provider.d.ts +2 -2
- package/functions/utils/create-provider.mjs +5 -5
- package/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/functions/utils/encryptInputForEnclave.mjs +9 -9
- package/functions/utils/ethers-formatter.utils.d.ts +1 -1
- package/functions/utils/external-action.utils.cjs +1 -1
- package/functions/utils/external-action.utils.mjs +2 -2
- package/functions/utils/getContractAddress.cjs +1 -0
- package/functions/utils/getContractAddress.d.ts +2 -0
- package/functions/utils/getContractAddress.mjs +9 -0
- package/functions/utils/getDataFromTransaction.cjs +1 -1
- package/functions/utils/getDataFromTransaction.d.ts +0 -11
- package/functions/utils/getDataFromTransaction.mjs +26 -50
- package/functions/utils/getRecipientInfoFromUserKeys.cjs +1 -1
- package/functions/utils/getRecipientInfoFromUserKeys.mjs +1 -1
- package/functions/utils/getSignerFromContract.cjs +1 -0
- package/functions/utils/getSignerFromContract.d.ts +3 -0
- package/functions/utils/getSignerFromContract.mjs +16 -0
- package/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
- package/functions/utils/getUtxosFromReceipt.utils.d.ts +1 -1
- package/functions/utils/getUtxosFromReceipt.utils.mjs +15 -16
- package/functions/utils/inLogicMetadata.cjs +1 -1
- package/functions/utils/inLogicMetadata.mjs +2 -2
- package/functions/utils/nftTokenFunctions.cjs +1 -1
- package/functions/utils/nftTokenFunctions.mjs +2 -3
- package/functions/utils/publicBalance.utils.cjs +1 -1
- package/functions/utils/publicBalance.utils.d.ts +1 -1
- package/functions/utils/publicBalance.utils.mjs +42 -42
- package/functions/utils/rpc-int-encode.cjs +1 -1
- package/functions/utils/rpc-int-encode.d.ts +1 -2
- package/functions/utils/rpc-int-encode.mjs +3 -6
- package/functions/utils/solanaMint.utils.cjs +1 -1
- package/functions/utils/solanaMint.utils.mjs +6 -6
- package/functions/web3/EIP-712.cjs +1 -1
- package/functions/web3/EIP-712.d.ts +4 -4
- package/functions/web3/EIP-712.mjs +1 -1
- package/functions/web3/etherFunctions.cjs +1 -1
- package/functions/web3/etherFunctions.mjs +32 -29
- package/functions/web3/events/balanceChangedCustomHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedCustomHandler.mjs +4 -5
- package/functions/web3/events/balanceChangedHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedHandler.mjs +2 -3
- package/functions/web3/events/getApprovedBalance.cjs +1 -1
- package/functions/web3/events/getApprovedBalance.mjs +1 -1
- package/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
- package/functions/web3/events/getInputUtxosEnclave.mjs +20 -20
- package/functions/web3/events/getTransactionLogEvents.cjs +1 -1
- package/functions/web3/events/getTransactionLogEvents.d.ts +3 -3
- package/functions/web3/events/getTransactionLogEvents.mjs +6 -5
- package/functions/web3/events/index.d.ts +0 -1
- package/functions/web3/fetchSolanaMerkleTreeRootHash.cjs +1 -1
- package/functions/web3/fetchSolanaMerkleTreeRootHash.d.ts +1 -2
- package/functions/web3/fetchSolanaMerkleTreeRootHash.mjs +4 -5
- package/functions/web3/functionCalls/accessTokenCalls.cjs +1 -1
- package/functions/web3/functionCalls/accessTokenCalls.mjs +10 -11
- package/functions/web3/functionCalls/approveToken.cjs +1 -1
- package/functions/web3/functionCalls/approveToken.mjs +61 -58
- package/functions/web3/functionCalls/constructBatchCall.cjs +1 -1
- package/functions/web3/functionCalls/constructBatchCall.d.ts +2 -2
- package/functions/web3/functionCalls/constructBatchCall.mjs +10 -9
- package/functions/web3/functionCalls/estimateGasRelayer.cjs +1 -1
- package/functions/web3/functionCalls/estimateGasRelayer.mjs +1 -1
- package/functions/web3/functionCalls/inHinkalApprovalCalls.cjs +1 -1
- package/functions/web3/functionCalls/inHinkalApprovalCalls.mjs +18 -21
- package/functions/web3/functionCalls/recoverTransactionFromError.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +38 -34
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +8 -10
- package/functions/web3/getContractMetadata.cjs +1 -1
- package/functions/web3/getContractMetadata.d.ts +1 -1
- package/functions/web3/getContractMetadata.mjs +25 -25
- package/functions/web3/getPublicAddressBalance.cjs +1 -1
- package/functions/web3/getPublicAddressBalance.mjs +7 -6
- package/functions/web3/getTokenHolder.cjs +1 -1
- package/functions/web3/getTokenHolder.mjs +16 -15
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.mjs +6 -7
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +2 -3
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.d.ts +6 -5
- package/functions/web3/runContractFunction.mjs +41 -45
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.d.ts +2 -2
- package/functions/web3/uniswapAPI.mjs +23 -24
- package/index.cjs +1 -1
- package/index.mjs +336 -340
- package/package.json +3 -4
- package/providers/CustomEthersProvider.d.ts +1 -1
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.d.ts +7 -7
- package/providers/EthersProviderAdapter.mjs +46 -44
- package/providers/SolanaProviderAdapter.d.ts +1 -1
- package/providers/WagmiProviderAdapter.cjs +1 -1
- package/providers/WagmiProviderAdapter.d.ts +5 -5
- package/providers/WagmiProviderAdapter.mjs +37 -33
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.d.ts +2 -2
- package/providers/prepareEthersHinkal.mjs +3 -5
- package/providers/prepareWagmiHinkal.cjs +1 -1
- package/providers/prepareWagmiHinkal.mjs +3 -5
- package/types/activities.types.d.ts +2 -3
- package/types/big-intable.types.d.ts +3 -2
- package/types/ethereum-network.types.d.ts +10 -10
- package/types/transactions.types.cjs +1 -1
- package/types/transactions.types.d.ts +2 -3
- package/types/transactions.types.mjs +6 -7
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
- package/functions/web3/events/web3RetrieveEvents.cjs +0 -1
- package/functions/web3/events/web3RetrieveEvents.d.ts +0 -14
- package/functions/web3/events/web3RetrieveEvents.mjs +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("../../constants/protocol.constants.cjs"),X=require("../../error-handling/error-codes.constants.cjs"),ee=require("../../functions/snarkjs/constructEmporiumProof.cjs"),te=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),I=require("../../types/external-action.types.cjs"),O=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const re=require("../../types/ethereum-network.types.cjs");require("../../types/activities.types.cjs");const W=require("../../types/scheduled-transactions.types.cjs"),se=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),oe=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),ne=require("../../functions/utils/time.utils.cjs"),ie=require("../../functions/pre-transaction/getFeeStructure.cjs"),ae=require("../../functions/utils/addresses.cjs"),ce=require("../../constants/chains.constants.cjs"),L=require("../../constants/addresses.constants.cjs");require("idb-keyval");require("@solana/web3.js");require("../http/HttpClient.cjs");require("../../constants/vite.constants.cjs");require("ethers");const ue=require("../../functions/utils/erc20tokenFunctions.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../constants/server.constants.cjs");require("axios");const N=require("../../functions/utils/caseInsensitive.utils.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/save-depths.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("../crypto-keys/keys.cjs");require("@solana/spl-token");require("../../constants/token-data/index.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/userAgent.cjs");const de=require("../../functions/utils/convertEmporiumOpToCallInfo.cjs");require("multiformats");const le=require("../../API/API.cjs");require("../../API/tenderly.api.cjs");const b=require("./hinkalDepositOnChainUtxos.cjs"),K=require("../../functions/private-wallet/emporium.helpers.cjs"),z=require("../../API/deposit-and-withdraw-status-calls.cjs"),pe=async(e,A,s,v,i,f,d,l)=>{if(s.length===0)throw new Error("No recipients to bridge");const n=A.erc20TokenAddress,r=e.getCurrentChainId(),{contractData:a}=ce.networkRegistry[r],{emporiumAddress:T}=a;if(!T)throw Error("No Emporium Address");const D=L.SWAP_ROUTER_ADDRESSES[I.ExternalActionId.Lifi][r];if(!D)throw new Error(`LIFI not configured for chain ${r}`);const m=await e.getRandomRelay();if(!m)throw Error(X.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const C=await e.getEthereumAddress(),h=ne.getCurrentTimeInSeconds().toString(),w=e.generateProofRemotely?5:1,y=[];for(let p=0;p<s.length;p+=w){const t=s.slice(p,p+w),o=await Promise.all(t.map(async({utxo:c,nativeUtxo:u,bridgeAmount:B,quote:x,temporarySubAccount:R})=>{await le.API.addTemporaryWalletNonce(r,i,R.index);const H=x.nativeFee>0n&&!N.caseInsensitiveEqual(n,q.zeroAddress),E=[n],U=[-c.amount],_=[!1],k=new O.Utxo({amount:0n,erc20TokenAddress:n,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:h,tokenId:0}),S=[[c,k]],F=[[k]];if(H&&u){const P=new O.Utxo({amount:0n,erc20TokenAddress:q.zeroAddress,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:h,tokenId:0});E.push(q.zeroAddress),U.push(-u.amount),_.push(!1),S.push([u,P]),F.push([P])}const M=K.createLifiBridgeOps(e,R.ethAddress,D,n,c.amount,B,x),{patchAccessTokenMerkleTree:j,kycRequired:V,hasAccessToken:Y}=await oe.shouldPatchAccessTokenMerkleTree(e,E,U),Z=await se.getSignatureDataForTransact(r,C,e.userKeys,V,Y),{zkCallData:$,circomData:G,dimData:J,authorizationData:Q}=await ee.constructEmporiumProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,E,E.map(()=>0),S,F,e.userKeys,E.length,S[0].length,T,M,e.generateProofRemotely,m??q.zeroAddress,r,_,void 0,R.privateKey,void 0,j,void 0,v,e.getContractWithFetcher(re.ContractType.HinkalHelperContract),Z,void 0,!1);return{zkCallData:$,dimData:J,circomData:G,authorizationData:Q}}));y.push(...o)}await z.safeUpdateDepositAndWithdrawStatus(r,{id:f,hashedEthereumAddress:i,phase:W.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await te.transactCallRelayerBatch(r,y,i,d,l);return await z.safeUpdateDepositAndWithdrawStatus(r,{id:f,hashedEthereumAddress:i,phase:W.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},qe=async(e,A,s,v,i,f)=>{const d=A.erc20TokenAddress,l=e.getCurrentChainId(),n=ae.hashEthereumAddress(await e.getEthereumAddress()),r=L.SWAP_ROUTER_ADDRESSES[I.ExternalActionId.Lifi][l];if(!r)throw Error("LIFI router not configured");let a;if(i)a=i;else{const t=s[0],c=K.createLifiBridgeOps(e,t.temporarySubAccount.ethAddress,r,d,t.bridgeAmount,t.bridgeAmount,t.quote).map(u=>de.convertEmporiumOpToCallInfo(u,t.temporarySubAccount.ethAddress,l));a=await ie.getFeeStructure(l,d,[d],I.ExternalActionId.Emporium,c)}const T={feeToken:a.feeToken,flatFee:0n,variableRate:0n},m=s.reduce((t,o)=>t+o.quote.nativeFee,0n)>0n&&!N.caseInsensitiveEqual(d,q.zeroAddress),C=s.map(t=>t.bridgeAmount),h=s.map(t=>t.recipientAddress),{userDepositedUtxos:w,statusId:y}=await b.hinkalDepositOnChainUtxos(e,A,C,h,a,n);let g=[];if(m){const t=ue.getERC20Token(q.zeroAddress,l);if(!t)throw Error("No native token");const o=s.map(u=>u.quote.nativeFee),{userDepositedUtxos:c}=await b.hinkalDepositOnChainUtxos(e,t,o,h,T,n);g=c}const p=s.map((t,o)=>({...t,utxo:w[o].utxo,nativeUtxo:m?g[o]?.utxo:void 0}));return pe(e,A,p,a,n,y,v,f)};exports.hinkalDepositAndBridge=qe;
|
|
@@ -6,7 +6,6 @@ import { ExternalActionId as S } from "../../types/external-action.types.mjs";
|
|
|
6
6
|
import { Utxo as K } from "../utxo/Utxo.mjs";
|
|
7
7
|
import "../../types/circom-data.types.mjs";
|
|
8
8
|
import { ContractType as ot } from "../../types/ethereum-network.types.mjs";
|
|
9
|
-
import "../../types/transactions.types.mjs";
|
|
10
9
|
import "../../types/activities.types.mjs";
|
|
11
10
|
import { DepositAndWithdrawPhase as N } from "../../types/scheduled-transactions.types.mjs";
|
|
12
11
|
import { getSignatureDataForTransact as rt } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
|
|
@@ -16,11 +15,11 @@ import { getFeeStructure as nt } from "../../functions/pre-transaction/getFeeStr
|
|
|
16
15
|
import { hashEthereumAddress as at } from "../../functions/utils/addresses.mjs";
|
|
17
16
|
import { networkRegistry as mt } from "../../constants/chains.constants.mjs";
|
|
18
17
|
import { SWAP_ROUTER_ADDRESSES as H } from "../../constants/addresses.constants.mjs";
|
|
19
|
-
import "ethers";
|
|
20
18
|
import "idb-keyval";
|
|
21
19
|
import "@solana/web3.js";
|
|
22
20
|
import "../http/HttpClient.mjs";
|
|
23
21
|
import "../../constants/vite.constants.mjs";
|
|
22
|
+
import "ethers";
|
|
24
23
|
import { getERC20Token as pt } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
25
24
|
import "../../functions/utils/convertIntegrationProviderToExternalActionId.mjs";
|
|
26
25
|
import "../../constants/server.constants.mjs";
|
|
@@ -157,7 +156,7 @@ const ut = async (t, A, r, R, n, T, c, d) => {
|
|
|
157
156
|
phase: N.AFTER_SCHEDULE_WITHDRAW,
|
|
158
157
|
scheduleId: g
|
|
159
158
|
}), g;
|
|
160
|
-
},
|
|
159
|
+
}, Ae = async (t, A, r, R, n, T) => {
|
|
161
160
|
const c = A.erc20TokenAddress, d = t.getCurrentChainId(), i = at(await t.getEthereumAddress()), o = H[S.Lifi][d];
|
|
162
161
|
if (!o)
|
|
163
162
|
throw Error("LIFI router not configured");
|
|
@@ -222,5 +221,5 @@ const ut = async (t, A, r, R, n, T, c, d) => {
|
|
|
222
221
|
);
|
|
223
222
|
};
|
|
224
223
|
export {
|
|
225
|
-
|
|
224
|
+
Ae as hinkalDepositAndBridge
|
|
226
225
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("../../error-handling/error-codes.constants.cjs"),K=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),V=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),X=require("../../functions/web3/events/getShieldedBalance.cjs"),z=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),G=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("../../error-handling/error-codes.constants.cjs"),K=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),V=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),X=require("../../functions/web3/events/getShieldedBalance.cjs"),z=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),G=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),C=require("../../types/external-action.types.cjs"),P=require("../../types/hinkal.types.cjs"),f=require("../../functions/utils/amounts.utils.cjs"),Z=require("../../functions/pre-transaction/outputApprovalDataProcessing.cjs"),$=require("../../constants/conversion.constants.cjs"),j=require("../../constants/protocol.constants.cjs"),Y=require("../../functions/pre-transaction/merge-with-fee-structure.cjs"),J=require("../../functions/pre-transaction/getFeeStructure.cjs"),w=require("../../types/ethereum-network.types.cjs"),v=require("../../error-handling/logger.cjs"),Q=require("../../functions/utils/involves-permit2-op.cjs"),tt=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),et=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),rt=require("../../functions/utils/inLogicMetadata.cjs"),ot=require("../../functions/utils/time.utils.cjs"),nt=require("../../functions/pre-transaction/constructAdminData.cjs"),at=require("../../functions/utils/getContractAddress.cjs"),ct=async(t,o,r,n,a,g,E,S,U,_,l=!1)=>{const R=rt.encodeParsedInLogicMetadata(E),i={externalActionId:C.ExternalActionId.Wallet,externalAddress:a,externalActionMetadata:R},k=t.getContractWithFetcher(w.ContractType.HinkalContract),u=o.findIndex(e=>e===j.zeroAddress),L=u!==-1&&r[u]<0n?-r[u]:0n,A=U??await J.getFeeStructure(t.getCurrentChainId(),S,o,C.ExternalActionId.Wallet,[{from:at.getContractAddress(k),to:a,value:L,calldata:g}]);Y.mergeWithFeeStructure(t.getCurrentChainId(),o,r,A),n=[...n],n.length<r.length&&n.push(0n);const c=[...await X.addPaddingToUtxos(t,o,r)],M=`swapperMHA${r.length.toString()}x${c[0].length}x1`,p=r.map(e=>!(e<0n)),m=[],s={inHinkalAddress:t.userKeys.getInHinkalAddress(a),executeApprovalChanges:n,hinkalLogicAction:P.HinkalLogicAction.EXECUTE,doPreTxApproval:!1,useApprovalUtxoData:[]},O=ot.getCurrentTimeInSeconds().toString();for(let e=0;e<o.length;e+=1){const y=p[e]?0n:-(f.absBigInt(r[e])-f.absBigInt(n[e])),{outputUtxos:b}=K.outputUtxoProcessing(t.userKeys,c[e],y,O,void 0,!1);m.push(b);const{useApprovalUtxoData:D}=Z.outputApprovalDataProcessing(t,c[e],y,a);s.useApprovalUtxoData.push(D??P.defaultUseApprovalUTXOData($.APPROVED_UTXO_CONVERSION_COUNT,0n)),D&&(s.doPreTxApproval=!0)}const T=await t.getRandomRelay(!l);if(!T)throw Error(B.transactionErrorCodes.RELAYER_NOT_AVAILABLE);v.Logger.log("hinkaInAction",{hinkalLogicArgs:s,deltaChanges:r,approvalChanges:n});const{patchAccessTokenMerkleTree:F,kycRequired:H,hasAccessToken:W}=await et.shouldPatchAccessTokenMerkleTree(t,o,r),h=await tt.getSignatureDataForTransact(t.getCurrentChainId(),await t.getEthereumAddress(),t.userKeys,H,W),{zkCallData:q,circomData:d,dimData:x}=await V.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,c,m,t.userKeys,M,i.externalActionId,i.externalAddress,i.externalActionMetadata,t.generateProofRemotely,T,t.getCurrentChainId(),p,void 0,void 0,F,s,void 0,A,t.getContractWithFetcher(w.ContractType.HinkalHelperContract),h),I=Q.uniswapWorkaround([g]);if(v.Logger.log("hinkalInAction circomData",{circomData:d,withUniswapWorkAround:I}),l)return await z.estimateGasRelayer(t,q,x,d);const N=nt.constructAdminData(_,t.getCurrentChainId(),o,r,await t.getEthereumAddress());return await G.transactCallRelayer(t.getCurrentChainId(),q,x,d,I,void 0,void 0,N)};exports.hinkalInsideTransact=ct;
|
|
@@ -4,29 +4,30 @@ import { constructZkProof as B } from "../../functions/snarkjs/constructGeneralZ
|
|
|
4
4
|
import { addPaddingToUtxos as $ } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
5
5
|
import { estimateGasRelayer as b } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
6
6
|
import { transactCallRelayer as q } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
7
|
-
import { ExternalActionId as
|
|
7
|
+
import { ExternalActionId as C } from "../../types/external-action.types.mjs";
|
|
8
8
|
import { HinkalLogicAction as Y, defaultUseApprovalUTXOData as Z } from "../../types/hinkal.types.mjs";
|
|
9
|
-
import { absBigInt as
|
|
9
|
+
import { absBigInt as E } from "../../functions/utils/amounts.utils.mjs";
|
|
10
10
|
import { outputApprovalDataProcessing as h } from "../../functions/pre-transaction/outputApprovalDataProcessing.mjs";
|
|
11
11
|
import { APPROVED_UTXO_CONVERSION_COUNT as j } from "../../constants/conversion.constants.mjs";
|
|
12
12
|
import { zeroAddress as G } from "../../constants/protocol.constants.mjs";
|
|
13
13
|
import { mergeWithFeeStructure as J } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
|
|
14
14
|
import { getFeeStructure as Q } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
15
|
-
import { ContractType as
|
|
16
|
-
import { Logger as
|
|
15
|
+
import { ContractType as U } from "../../types/ethereum-network.types.mjs";
|
|
16
|
+
import { Logger as y } from "../../error-handling/logger.mjs";
|
|
17
17
|
import { uniswapWorkaround as tt } from "../../functions/utils/involves-permit2-op.mjs";
|
|
18
18
|
import { getSignatureDataForTransact as ot } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
|
|
19
19
|
import { shouldPatchAccessTokenMerkleTree as rt } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
|
|
20
20
|
import { encodeParsedInLogicMetadata as et } from "../../functions/utils/inLogicMetadata.mjs";
|
|
21
21
|
import { getCurrentTimeInSeconds as at } from "../../functions/utils/time.utils.mjs";
|
|
22
22
|
import { constructAdminData as nt } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
23
|
-
|
|
23
|
+
import { getContractAddress as it } from "../../functions/utils/getContractAddress.mjs";
|
|
24
|
+
const Lt = async (t, e, r, a, n, p, P, v, R, S, f = !1) => {
|
|
24
25
|
const H = et(P), m = {
|
|
25
|
-
externalActionId:
|
|
26
|
+
externalActionId: C.Wallet,
|
|
26
27
|
externalAddress: n,
|
|
27
28
|
externalActionMetadata: H
|
|
28
|
-
}, L = t.getContractWithFetcher(
|
|
29
|
-
{ from: L
|
|
29
|
+
}, L = t.getContractWithFetcher(U.HinkalContract), s = e.findIndex((o) => o === G), O = s !== -1 && r[s] < 0n ? -r[s] : 0n, d = R ?? await Q(t.getCurrentChainId(), v, e, C.Wallet, [
|
|
30
|
+
{ from: it(L), to: n, value: O, calldata: p }
|
|
30
31
|
]);
|
|
31
32
|
J(t.getCurrentChainId(), e, r, d), a = [...a], a.length < r.length && a.push(0n);
|
|
32
33
|
const i = [...await $(t, e, r)], W = `swapperMHA${r.length.toString()}x${i[0].length}x1`, A = r.map((o) => !(o < 0n)), g = [], c = {
|
|
@@ -37,7 +38,7 @@ const St = async (t, e, r, a, n, p, P, v, R, S, f = !1) => {
|
|
|
37
38
|
useApprovalUtxoData: []
|
|
38
39
|
}, M = at().toString();
|
|
39
40
|
for (let o = 0; o < e.length; o += 1) {
|
|
40
|
-
const D = A[o] ? 0n : -(
|
|
41
|
+
const D = A[o] ? 0n : -(E(r[o]) - E(a[o])), { outputUtxos: V } = z(
|
|
41
42
|
t.userKeys,
|
|
42
43
|
i[o],
|
|
43
44
|
D,
|
|
@@ -59,7 +60,7 @@ const St = async (t, e, r, a, n, p, P, v, R, S, f = !1) => {
|
|
|
59
60
|
const x = await t.getRandomRelay(!f);
|
|
60
61
|
if (!x)
|
|
61
62
|
throw Error(X.RELAYER_NOT_AVAILABLE);
|
|
62
|
-
|
|
63
|
+
y.log("hinkaInAction", { hinkalLogicArgs: c, deltaChanges: r, approvalChanges: a });
|
|
63
64
|
const { patchAccessTokenMerkleTree: F, kycRequired: N, hasAccessToken: _ } = await rt(
|
|
64
65
|
t,
|
|
65
66
|
e,
|
|
@@ -91,10 +92,10 @@ const St = async (t, e, r, a, n, p, P, v, R, S, f = !1) => {
|
|
|
91
92
|
c,
|
|
92
93
|
void 0,
|
|
93
94
|
d,
|
|
94
|
-
t.getContractWithFetcher(
|
|
95
|
+
t.getContractWithFetcher(U.HinkalHelperContract),
|
|
95
96
|
k
|
|
96
97
|
), T = tt([p]);
|
|
97
|
-
if (
|
|
98
|
+
if (y.log("hinkalInAction circomData", { circomData: u, withUniswapWorkAround: T }), f)
|
|
98
99
|
return await b(t, l, I, u);
|
|
99
100
|
const K = nt(
|
|
100
101
|
S,
|
|
@@ -115,5 +116,5 @@ const St = async (t, e, r, a, n, p, P, v, R, S, f = !1) => {
|
|
|
115
116
|
);
|
|
116
117
|
};
|
|
117
118
|
export {
|
|
118
|
-
|
|
119
|
+
Lt as hinkalInsideTransact
|
|
119
120
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("../../constants/chains.constants.cjs"),I=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("../../types/circom-data.types.cjs");const V=require("../../types/ethereum-network.types.cjs"),b=require("../../types/external-action.types.cjs"),j=require("../../types/hinkal.types.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("../../constants/chains.constants.cjs"),I=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("../../types/circom-data.types.cjs");const V=require("../../types/ethereum-network.types.cjs"),b=require("../../types/external-action.types.cjs"),j=require("../../types/hinkal.types.cjs"),S=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");require("../../constants/server.constants.cjs");require("../../API/getServerURL.cjs");require("../http/HttpClient.cjs");require("axios");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/save-depths.cjs");const G=require("../../functions/utils/caseInsensitive.utils.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");const Y=require("../crypto-keys/keys.cjs"),J=require("../../functions/utils/time.utils.cjs"),Q=require("../../functions/snarkjs/constructEmporiumProof.cjs"),X=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),Z=require("../../functions/web3/events/getShieldedBalance.cjs"),$=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),ee=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),re=require("../../functions/utils/involves-permit2-op.cjs"),te=require("../../functions/pre-transaction/outputApprovalDataProcessing.cjs"),oe=require("../../functions/utils/convertEmporiumOpToCallInfo.cjs"),se=require("../../functions/pre-transaction/getFeeStructure.cjs"),ie=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),ae=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),ne=require("../../functions/pre-transaction/merge-with-fee-structure-emporium.cjs"),ue=require("./handleAutoDepositBack.cjs");require("../../constants/token-data/index.cjs");const ce=require("../../functions/pre-transaction/constructAdminData.cjs");require("@solana/spl-token");const de=require("../../functions/pre-transaction/recipientUtxoProcessing.cjs"),pe=require("../../functions/utils/addresses.cjs"),qe=async(e,t,o,l,n,s,m,R,U,_,F=!1,C,g,u,v=!1)=>{if(u&&!pe.isValidPrivateAddress(u.recipientInfo))throw Error(I.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);const c=e.getCurrentChainId(),d=Y.UserKeys.getSignerAddressFromPrivateKey(c,m.privateKey),{contractData:K}=z.networkRegistry[c],{emporiumAddress:p}=K;if(!p)throw Error("No Emporium Address Provided");const q=U??await se.getFeeStructure(c,R,t,b.ExternalActionId.Emporium,n.map(r=>oe.convertEmporiumOpToCallInfo(r,d??"",c))),k=s.find(r=>G.caseInsensitiveEqual(r.token.erc20TokenAddress,q.feeToken))?.amount??0n;for(d&&await ne.mergeWithFeeStructureEmporium(e,d,n,t,o,q,k);l.length<t.length;)l.push(!1);const i=[...await Z.addPaddingToUtxos(e,t,o)],A=[],a=j.defaultHinkalLogicArgs(o.length,e.userKeys),f=J.getCurrentTimeInSeconds().toString();for(let r=0;r<t.length;r+=1){const{outputUtxos:B}=X.outputUtxoProcessing(e.userKeys,i[r],o[r],f,void 0,!1);A.push(B);const{useApprovalUtxoData:x}=te.outputApprovalDataProcessing(e,i[r],o[r]);x&&(a.doPreTxApproval=!0,a.useApprovalUtxoData[r]=x,a.interactionAddress=p,a.inHinkalAddress=e.userKeys.getInHinkalAddress(p))}u&&de.recipientUtxoProcessing(u,A,o,f);const E=_??await e.getRandomRelay(!v);if(!E)throw Error(I.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{patchAccessTokenMerkleTree:O,kycRequired:W,hasAccessToken:h}=await ie.shouldPatchAccessTokenMerkleTree(e,t,o),H=await ae.getSignatureDataForTransact(e.getCurrentChainId(),await e.getEthereumAddress(),e.userKeys,W,h),{zkCallData:w,circomData:y,dimData:P,authorizationData:D}=await Q.constructEmporiumProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,t,t.map(()=>0),i,A,e.userKeys,o.length,i.length>0?i[0].length:0,p,n,e.generateProofRemotely,E,e.getCurrentChainId(),l,void 0,m.privateKey,a,O,void 0,q,e.getContractWithFetcher(V.ContractType.HinkalHelperContract),H),L=re.uniswapWorkaround(n);if(v)return await $.estimateGasRelayer(e,w,P,y,D);const T=g===S.AdminTransactionType.FundApproveAndTransact,M=ce.constructAdminData(g,e.getCurrentChainId(),s.map(r=>r.token.erc20TokenAddress),s.map(r=>r.amount),await e.getEthereumAddress(),g===S.AdminTransactionType.PublicSwap?s.map(({token:r})=>r):void 0,T?o:void 0,T?t:void 0,T?s:void 0),N=await ee.transactCallRelayer(e.getCurrentChainId(),w,P,y,!1,L,D,M);return F&&ue.handleAutoDepositBack(e,d,m,q.feeToken,C,s,y),N};exports.hinkalPrivateWallet=qe;
|
|
@@ -5,7 +5,6 @@ import "../../types/circom-data.types.mjs";
|
|
|
5
5
|
import { ContractType as Y } from "../../types/ethereum-network.types.mjs";
|
|
6
6
|
import { ExternalActionId as j } from "../../types/external-action.types.mjs";
|
|
7
7
|
import { defaultHinkalLogicArgs as G } from "../../types/hinkal.types.mjs";
|
|
8
|
-
import "../../types/transactions.types.mjs";
|
|
9
8
|
import { AdminTransactionType as U } from "../../types/admin.types.mjs";
|
|
10
9
|
import "../../types/activities.types.mjs";
|
|
11
10
|
import "../../constants/server.constants.mjs";
|
|
@@ -43,7 +42,7 @@ import { constructAdminData as nt } from "../../functions/pre-transaction/constr
|
|
|
43
42
|
import "@solana/spl-token";
|
|
44
43
|
import { recipientUtxoProcessing as ct } from "../../functions/pre-transaction/recipientUtxoProcessing.mjs";
|
|
45
44
|
import { isValidPrivateAddress as ut } from "../../functions/utils/addresses.mjs";
|
|
46
|
-
const
|
|
45
|
+
const or = async (t, o, e, d, p, i, A, K, S, F, H = !1, C, g, s, y = !1) => {
|
|
47
46
|
if (s && !ut(s.recipientInfo))
|
|
48
47
|
throw Error(R.RECIPIENT_FORMAT_INCORRECT);
|
|
49
48
|
const n = t.getCurrentChainId(), c = Q.getSignerAddressFromPrivateKey(n, A.privateKey), { contractData: L } = k[n], { emporiumAddress: u } = L;
|
|
@@ -157,5 +156,5 @@ const er = async (t, o, e, d, p, i, A, K, S, F, H = !1, C, g, s, y = !1) => {
|
|
|
157
156
|
), B;
|
|
158
157
|
};
|
|
159
158
|
export {
|
|
160
|
-
|
|
159
|
+
or as hinkalPrivateWallet
|
|
161
160
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../functions/snarkjs/common.snarkjs.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../functions/snarkjs/common.snarkjs.cjs"),A=require("../../functions/web3/etherFunctions.cjs"),l=require("../../types/ethereum-network.types.cjs"),C=require("../utxo/Utxo.cjs"),h=require("../../constants/protocol.constants.cjs"),g=require("../../functions/utils/caseInsensitive.utils.cjs"),k=require("../../functions/utils/getContractAddress.cjs"),q=(n,e)=>{const r=[];let o=0;for(let s=0;s<n.length;s+=1){let a=!1;for(let t=0;t<o;t+=1)if(g.caseInsensitiveEqual(r[t].token.erc20TokenAddress,n[s].erc20TokenAddress)){r[t].balance+=e[s],a=!0;break}a||(r[o]={token:n[s],balance:e[s]},o+=1)}return r},y=async(n,e,r)=>{const o=q(e,r),s=n.getContractWithSigner(l.ContractType.HinkalContract),a=k.getContractAddress(s);for(let t=0;t<o.length;t+=1)g.caseInsensitiveEqual(o[t].token.erc20TokenAddress,h.zeroAddress)||await(await n.getContractWithSigner(l.ContractType.ERC20Contract,o[t].token.erc20TokenAddress).approve(a,o[t].balance)).wait()},v=async(n,e,r,o)=>{const s=n.getContractWithSigner(l.ContractType.HinkalContract),a=n.userKeys.getShieldedPrivateKey(),t=C.Utxo.findCorrectRandomization(A.randomBigInt(31),a),c=o??Array(e.length).fill(f.calcStealthAddressStructure(t,a));if(c.length!==e.length)throw new Error("Stealth address structures length must be equal to erc20 tokens length");await y(n,e,r);const d=e.findIndex(i=>i.erc20TokenAddress===h.zeroAddress),p=r[d]??0n,u=await s.prooflessDeposit(e.map(({erc20TokenAddress:i})=>i),r,e.map(()=>0n),c,{value:p});return await u.wait(),u};exports.hinkalProoflessDeposit=v;
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import { calcStealthAddressStructure as
|
|
1
|
+
import { calcStealthAddressStructure as h } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
2
2
|
import { randomBigInt as g } from "../../functions/web3/etherFunctions.mjs";
|
|
3
|
-
import { ContractType as
|
|
3
|
+
import { ContractType as d } from "../../types/ethereum-network.types.mjs";
|
|
4
4
|
import { Utxo as A } from "../utxo/Utxo.mjs";
|
|
5
|
-
import { zeroAddress as
|
|
6
|
-
import { caseInsensitiveEqual as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { zeroAddress as p } from "../../constants/protocol.constants.mjs";
|
|
6
|
+
import { caseInsensitiveEqual as m } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
7
|
+
import { getContractAddress as C } from "../../functions/utils/getContractAddress.mjs";
|
|
8
|
+
const k = (r, e) => {
|
|
9
|
+
const o = [];
|
|
10
|
+
let n = 0;
|
|
10
11
|
for (let a = 0; a < r.length; a += 1) {
|
|
11
12
|
let s = !1;
|
|
12
|
-
for (let t = 0; t <
|
|
13
|
-
if (
|
|
14
|
-
|
|
13
|
+
for (let t = 0; t < n; t += 1)
|
|
14
|
+
if (m(o[t].token.erc20TokenAddress, r[a].erc20TokenAddress)) {
|
|
15
|
+
o[t].balance += e[a], s = !0;
|
|
15
16
|
break;
|
|
16
17
|
}
|
|
17
|
-
s || (n
|
|
18
|
+
s || (o[n] = {
|
|
18
19
|
token: r[a],
|
|
19
20
|
balance: e[a]
|
|
20
|
-
},
|
|
21
|
+
}, n += 1);
|
|
21
22
|
}
|
|
22
|
-
return
|
|
23
|
-
},
|
|
24
|
-
const
|
|
25
|
-
for (let t = 0; t <
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
).approve(s,
|
|
30
|
-
},
|
|
31
|
-
const a = r.getContractWithSigner(
|
|
23
|
+
return o;
|
|
24
|
+
}, w = async (r, e, o) => {
|
|
25
|
+
const n = k(e, o), a = r.getContractWithSigner(d.HinkalContract), s = C(a);
|
|
26
|
+
for (let t = 0; t < n.length; t += 1)
|
|
27
|
+
m(n[t].token.erc20TokenAddress, p) || await (await r.getContractWithSigner(
|
|
28
|
+
d.ERC20Contract,
|
|
29
|
+
n[t].token.erc20TokenAddress
|
|
30
|
+
).approve(s, n[t].balance)).wait();
|
|
31
|
+
}, W = async (r, e, o, n) => {
|
|
32
|
+
const a = r.getContractWithSigner(d.HinkalContract), s = r.userKeys.getShieldedPrivateKey(), t = A.findCorrectRandomization(g(31), s), i = n ?? Array(e.length).fill(h(t, s));
|
|
32
33
|
if (i.length !== e.length)
|
|
33
34
|
throw new Error("Stealth address structures length must be equal to erc20 tokens length");
|
|
34
|
-
await
|
|
35
|
-
const
|
|
35
|
+
await w(r, e, o);
|
|
36
|
+
const l = e.findIndex((c) => c.erc20TokenAddress === p), u = o[l] ?? 0n, f = await a.prooflessDeposit(
|
|
36
37
|
e.map(({ erc20TokenAddress: c }) => c),
|
|
37
|
-
|
|
38
|
+
o,
|
|
38
39
|
e.map(() => 0n),
|
|
39
40
|
i,
|
|
40
41
|
{ value: u }
|
|
@@ -42,5 +43,5 @@ const C = (r, e) => {
|
|
|
42
43
|
return await f.wait(), f;
|
|
43
44
|
};
|
|
44
45
|
export {
|
|
45
|
-
|
|
46
|
+
W as hinkalProoflessDeposit
|
|
46
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs");require("idb-keyval");const j=require("../../constants/chains.constants.cjs"),G=require("ethers");require("../crypto-keys/keys.cjs");require("node-forge");require("../../constants/vite.constants.cjs");require("libsodium-wrappers");require("../http/HttpClient.cjs");require("axios");const $=require("../../functions/utils/solanaMint.utils.cjs"),N=require("@solana/web3.js"),J=require("../../functions/utils/addresses.cjs");require("../../constants/server.constants.cjs");require("../../constants/token-data/index.cjs");const _=require("../../constants/protocol.constants.cjs"),Q=require("../../API/API.cjs");require("../../functions/utils/mutexes.utils.cjs");require("../../types/circom-data.types.cjs");const ee=require("../../types/external-action.types.cjs");require("../../types/activities.types.cjs");const B=require("../../types/scheduled-transactions.types.cjs");require("../../functions/web3/events/getApprovedBalance.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("process");require("buffer");require("../../constants/save-depths.cjs");const te=require("@coral-xyz/anchor"),E=require("../../functions/pre-transaction/solana.cjs");require("@solana/spl-token");require("../../functions/utils/userAgent.cjs");const re=require("../../functions/utils/time.utils.cjs");require("multiformats");require("../../API/tenderly.api.cjs");const oe=require("../../functions/utils/fees.utils.cjs");require("../../functions/web3/getTokenHolder.cjs");const ne=require("../../functions/web3/signAndSendSerializedTransaction.cjs"),Z=require("../../functions/snarkjs/common.snarkjs.cjs"),ae=require("./hinkalCheckSolanaTokenRegistry.cjs"),se=require("../../functions/utils/getUtxosFromReceiptSolana.cjs"),ie=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ce=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),W=require("../../API/deposit-and-withdraw-status-calls.cjs"),de=async(e,r,d,l,g,h)=>{const p=d.map(t=>t+oe.calculateTotalFee(t,g)),{hinkalIdl:m,hinkalAddress:q,originalDeployer:i}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!m)throw new Error("No IDL configured for Solana program on this network");if(!i)throw new Error("missing original deployer");const w=e.userKeys.getShieldedPrivateKey(),P=z.Utxo.findCorrectRandomization(M.randomBigInt(31),w),S=Z.calcStealthAddressStructure(P,w),o=e.getSolanaProgram(m),b=e.getSolanaPublicKey(),n=new N.PublicKey(i),A=new N.PublicKey(q),{mintPublicKey:c}=$.formatMintAddress(r),D=c.toString(),O=E.getStorageAccountPublicKey(A,n),R=E.getStorageVaultPublicKey(A,n),F=E.getMerkleAccountPublicKey(A,n),v=E.buildAnchorStealthAddressStructure(S),f=e.getCurrentChainId(),x=p.reduce((t,s)=>t+s,0n),I=await ae.hinkalCheckSolanaTokenRegistry(o,new N.PublicKey(n),[r],[x]),K=p.map(t=>`${t}`);let a="";const T=(await W.updateDepositAndWithdrawStatus(f,{hashedEthereumAddress:h,phase:B.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0;if(I){const{serializedTransaction:t,blockhash:s,lastValidBlockHeight:y}=await Q.API.generateMultiPaymentDepositLimitless(f,{amounts:K,payer:e.getSolanaPublicKey().toBase58(),ethereumAddress:await e.getEthereumAddress(),mint:r,stealthAddressStructure:v}),{wallet:u}=o.provider;if(!u)throw new Error("missing wallet");a=await ne.signAndSendSerializedTransaction(o.provider,t,s,y)}else{const t=E.getTokenLimitStorageAccountPublicKey(o.programId,n,c),s=D===_.solanaNativeAddress?null:c,y=D===_.solanaNativeAddress?null:void 0;a=await o.methods.multiPaymentDeposit(K.map(L=>new te.BN(L)),v).accounts({mint:s,signer:b,signerAta:y,originalDeployer:n,storageAccount:O,storageVault:R,merkleAccount:F,tokenLimitStorage:t,storageVaultAta:y,accessTokenOwner:null}).rpc();const u=await o.provider.connection.getLatestBlockhash();await o.provider.connection.confirmTransaction({blockhash:u.blockhash,lastValidBlockHeight:u.lastValidBlockHeight,signature:a},"confirmed")}const k=await o.provider.connection.getTransaction(a,{commitment:"confirmed",maxSupportedTransactionVersion:0});if(!k)throw new Error("Transaction missing");await W.safeUpdateDepositAndWithdrawStatus(f,{id:T,hashedEthereumAddress:h,phase:B.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:a});const H=se.getUtxosFromReceiptSolana(k,o,e.userKeys),U=[],C=[...H];return l.forEach((t,s)=>{const y=p[s],u=C.find(X=>X.amount===y);if(!u)throw new Error(`Could not find newly created UTXO with amount ${y} for recipient ${t}.`);U.push({recipientAddress:t,utxo:u});const L=C.indexOf(u);C.splice(L,1)}),{userDepositedUtxos:U,signature:a,statusId:T}},le=async(e,r,d,l,g,h,p,m)=>{const q=e.getCurrentChainId();if(d.length===0)throw new Error("userDepositedUtxos must not be empty");const{hinkalIdl:i,originalDeployer:w}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!w||!i)throw new Error("missing data");const P=e.getSolanaProgram(i),S=await e.getRandomRelay(!0);if(!S)throw new Error(Y.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=re.getCurrentTimeInSeconds().toString(),b=e.generateProofRemotely?5:1,n=[];for(let c=0;c<d.length;c+=b){const D=d.slice(c,c+b),O=await Promise.all(D.map(async({recipientAddress:R,utxo:F})=>{const{compressedAddress:v}=$.formatMintAddress(_.solanaNativeAddress),f=new z.Utxo({amount:0n,mintAddress:r,erc20TokenAddress:v,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:o,tokenId:0}),x=[F,f],I=[f],K=z.Utxo.findCorrectRandomization(M.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),a={tokenNumber:1,nullifierAmount:x.length,outputAmount:I.length},V=Z.calcEncryptedOutputs([I])[0][0],T=Array.from(G.ethers.getBytes(V)),{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C}=await ie.constructSolanaZkProof(e.generateProofRemotely,w,e.merkleTreeHinkal,e.merkleTreeAccessToken,e.userKeys,P,[r],[x],[I],K,l.flatFee,l.variableRate,R,S,a,[T],e.getCurrentChainId(),void 0,void 0,void 0,void 0,void 0,!1),t=r===_.solanaNativeAddress,s={recipient:R,mint:t?void 0:r};return{relayAddress:S,functionName:"transact",args:{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C,encryptedOutputs:[T],relayerFee:l.flatFee.toString(),dimensions:a},accounts:s}}));n.push(...O)}await W.safeUpdateDepositAndWithdrawStatus(q,{id:h,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const A=await ce.solanaTransactCallRelayerBatch(e.getCurrentChainId(),n,g,p,m);return await W.safeUpdateDepositAndWithdrawStatus(q,{id:h,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:A}),A},ge=async(e,r,d,l,g,h,p)=>{const m=J.hashEthereumAddress(await e.getEthereumAddress()),q=e.getCurrentChainId(),i=h??await ue.getFeeStructure(q,r,[r],ee.ExternalActionId.Transact,[],0n),{userDepositedUtxos:w,statusId:P}=await de(e,r,d,l,i,m);return await le(e,r,w,i,m,P,g,p)};exports.hinkalSolanaDepositAndWithdraw=ge;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { randomBigInt as M } from "../../functions/web3/etherFunctions.mjs";
|
|
2
2
|
import { Utxo as z } from "../utxo/Utxo.mjs";
|
|
3
3
|
import { transactionErrorCodes as Y } from "../../error-handling/error-codes.constants.mjs";
|
|
4
|
-
import { ethers as Z } from "ethers";
|
|
5
4
|
import "idb-keyval";
|
|
6
5
|
import { networkRegistry as $ } from "../../constants/chains.constants.mjs";
|
|
6
|
+
import { ethers as Z } from "ethers";
|
|
7
7
|
import "../crypto-keys/keys.mjs";
|
|
8
8
|
import "node-forge";
|
|
9
9
|
import "../../constants/vite.constants.mjs";
|
|
@@ -20,7 +20,6 @@ import { API as G } from "../../API/API.mjs";
|
|
|
20
20
|
import "../../functions/utils/mutexes.utils.mjs";
|
|
21
21
|
import "../../types/circom-data.types.mjs";
|
|
22
22
|
import { ExternalActionId as J } from "../../types/external-action.types.mjs";
|
|
23
|
-
import "../../types/transactions.types.mjs";
|
|
24
23
|
import "../../types/activities.types.mjs";
|
|
25
24
|
import { DepositAndWithdrawPhase as k } from "../../types/scheduled-transactions.types.mjs";
|
|
26
25
|
import "../../functions/web3/events/getApprovedBalance.mjs";
|
|
@@ -41,10 +40,10 @@ import "process";
|
|
|
41
40
|
import "buffer";
|
|
42
41
|
import "../../constants/save-depths.mjs";
|
|
43
42
|
import { BN as Q } from "@coral-xyz/anchor";
|
|
44
|
-
import { getStorageAccountPublicKey as tt, getStorageVaultPublicKey as ot, getMerkleAccountPublicKey as rt, buildAnchorStealthAddressStructure as et, getTokenLimitStorageAccountPublicKey as
|
|
43
|
+
import { getStorageAccountPublicKey as tt, getStorageVaultPublicKey as ot, getMerkleAccountPublicKey as rt, buildAnchorStealthAddressStructure as et, getTokenLimitStorageAccountPublicKey as at } from "../../functions/pre-transaction/solana.mjs";
|
|
45
44
|
import "@solana/spl-token";
|
|
46
45
|
import "../../functions/utils/userAgent.mjs";
|
|
47
|
-
import { getCurrentTimeInSeconds as
|
|
46
|
+
import { getCurrentTimeInSeconds as it } from "../../functions/utils/time.utils.mjs";
|
|
48
47
|
import "multiformats";
|
|
49
48
|
import "../../API/tenderly.api.mjs";
|
|
50
49
|
import { calculateTotalFee as nt } from "../../functions/utils/fees.utils.mjs";
|
|
@@ -52,13 +51,13 @@ import "../../functions/web3/getTokenHolder.mjs";
|
|
|
52
51
|
import { signAndSendSerializedTransaction as st } from "../../functions/web3/signAndSendSerializedTransaction.mjs";
|
|
53
52
|
import { calcStealthAddressStructure as ct, calcEncryptedOutputs as mt } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
54
53
|
import { hinkalCheckSolanaTokenRegistry as pt } from "./hinkalCheckSolanaTokenRegistry.mjs";
|
|
55
|
-
import { getUtxosFromReceiptSolana as
|
|
56
|
-
import { constructSolanaZkProof as
|
|
54
|
+
import { getUtxosFromReceiptSolana as dt } from "../../functions/utils/getUtxosFromReceiptSolana.mjs";
|
|
55
|
+
import { constructSolanaZkProof as lt } from "../../functions/snarkjs/constructSolanaZkProof.mjs";
|
|
57
56
|
import { solanaTransactCallRelayerBatch as ut } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
58
57
|
import { getFeeStructure as gt } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
59
58
|
import { updateDepositAndWithdrawStatus as ht, safeUpdateDepositAndWithdrawStatus as N } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
60
|
-
const ft = async (t, r, p,
|
|
61
|
-
const g = p.map((o) => o + nt(o,
|
|
59
|
+
const ft = async (t, r, p, d, l, u) => {
|
|
60
|
+
const g = p.map((o) => o + nt(o, l)), {
|
|
62
61
|
hinkalIdl: h,
|
|
63
62
|
hinkalAddress: y,
|
|
64
63
|
originalDeployer: s
|
|
@@ -67,13 +66,13 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
67
66
|
throw new Error("No IDL configured for Solana program on this network");
|
|
68
67
|
if (!s)
|
|
69
68
|
throw new Error("missing original deployer");
|
|
70
|
-
const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f), S = ct(E, f), e = t.getSolanaProgram(h), v = t.getSolanaPublicKey(),
|
|
69
|
+
const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f), S = ct(E, f), e = t.getSolanaProgram(h), v = t.getSolanaPublicKey(), a = new W(s), A = new W(y), { mintPublicKey: c } = q(r), R = c.toString(), F = tt(A, a), b = ot(A, a), H = rt(A, a), x = et(S), I = t.getCurrentChainId(), D = g.reduce((o, n) => o + n, 0n), T = await pt(
|
|
71
70
|
e,
|
|
72
|
-
new W(
|
|
71
|
+
new W(a),
|
|
73
72
|
[r],
|
|
74
73
|
[D]
|
|
75
74
|
), K = g.map((o) => `${o}`);
|
|
76
|
-
let
|
|
75
|
+
let i = "";
|
|
77
76
|
const P = (await ht(I, {
|
|
78
77
|
hashedEthereumAddress: u,
|
|
79
78
|
phase: k.BEFORE_DEPOSIT
|
|
@@ -91,22 +90,22 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
91
90
|
), { wallet: m } = e.provider;
|
|
92
91
|
if (!m)
|
|
93
92
|
throw new Error("missing wallet");
|
|
94
|
-
|
|
93
|
+
i = await st(
|
|
95
94
|
e.provider,
|
|
96
95
|
o,
|
|
97
96
|
n,
|
|
98
97
|
w
|
|
99
98
|
);
|
|
100
99
|
} else {
|
|
101
|
-
const o =
|
|
102
|
-
|
|
100
|
+
const o = at(e.programId, a, c), n = R === U ? null : c, w = R === U ? null : void 0;
|
|
101
|
+
i = await e.methods.multiPaymentDeposit(
|
|
103
102
|
K.map((V) => new Q(V)),
|
|
104
103
|
x
|
|
105
104
|
).accounts({
|
|
106
105
|
mint: n,
|
|
107
106
|
signer: v,
|
|
108
107
|
signerAta: w,
|
|
109
|
-
originalDeployer:
|
|
108
|
+
originalDeployer: a,
|
|
110
109
|
storageAccount: F,
|
|
111
110
|
storageVault: b,
|
|
112
111
|
merkleAccount: H,
|
|
@@ -119,12 +118,12 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
119
118
|
{
|
|
120
119
|
blockhash: m.blockhash,
|
|
121
120
|
lastValidBlockHeight: m.lastValidBlockHeight,
|
|
122
|
-
signature:
|
|
121
|
+
signature: i
|
|
123
122
|
},
|
|
124
123
|
"confirmed"
|
|
125
124
|
);
|
|
126
125
|
}
|
|
127
|
-
const B = await e.provider.connection.getTransaction(
|
|
126
|
+
const B = await e.provider.connection.getTransaction(i, {
|
|
128
127
|
commitment: "confirmed",
|
|
129
128
|
maxSupportedTransactionVersion: 0
|
|
130
129
|
});
|
|
@@ -134,10 +133,10 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
134
133
|
id: P,
|
|
135
134
|
hashedEthereumAddress: u,
|
|
136
135
|
phase: k.AFTER_DEPOSIT,
|
|
137
|
-
depositTxHash:
|
|
136
|
+
depositTxHash: i
|
|
138
137
|
});
|
|
139
|
-
const L =
|
|
140
|
-
return
|
|
138
|
+
const L = dt(B, e, t.userKeys), O = [], C = [...L];
|
|
139
|
+
return d.forEach((o, n) => {
|
|
141
140
|
const w = g[n], m = C.find((X) => X.amount === w);
|
|
142
141
|
if (!m)
|
|
143
142
|
throw new Error(`Could not find newly created UTXO with amount ${w} for recipient ${o}.`);
|
|
@@ -147,8 +146,8 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
147
146
|
});
|
|
148
147
|
const V = C.indexOf(m);
|
|
149
148
|
C.splice(V, 1);
|
|
150
|
-
}), { userDepositedUtxos: O, signature:
|
|
151
|
-
}, wt = async (t, r, p,
|
|
149
|
+
}), { userDepositedUtxos: O, signature: i, statusId: P };
|
|
150
|
+
}, wt = async (t, r, p, d, l, u, g, h) => {
|
|
152
151
|
const y = t.getCurrentChainId();
|
|
153
152
|
if (p.length === 0)
|
|
154
153
|
throw new Error("userDepositedUtxos must not be empty");
|
|
@@ -158,7 +157,7 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
158
157
|
const E = t.getSolanaProgram(s), S = await t.getRandomRelay(!0);
|
|
159
158
|
if (!S)
|
|
160
159
|
throw new Error(Y.RELAYER_NOT_AVAILABLE);
|
|
161
|
-
const e =
|
|
160
|
+
const e = it().toString(), v = t.generateProofRemotely ? 5 : 1, a = [];
|
|
162
161
|
for (let c = 0; c < p.length; c += v) {
|
|
163
162
|
const R = p.slice(c, c + v), F = await Promise.all(
|
|
164
163
|
R.map(async ({ recipientAddress: b, utxo: H }) => {
|
|
@@ -172,11 +171,11 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
172
171
|
}), D = [H, I], T = [I], K = z.findCorrectRandomization(
|
|
173
172
|
M(31),
|
|
174
173
|
t.userKeys.getShieldedPrivateKey()
|
|
175
|
-
),
|
|
174
|
+
), i = {
|
|
176
175
|
tokenNumber: 1,
|
|
177
176
|
nullifierAmount: D.length,
|
|
178
177
|
outputAmount: T.length
|
|
179
|
-
}, _ = mt([T])[0][0], P = Array.from(Z.
|
|
178
|
+
}, _ = mt([T])[0][0], P = Array.from(Z.getBytes(_)), { proofAArr: B, proofBArr: L, proofCArr: O, publicInputsArr: C } = await lt(
|
|
180
179
|
t.generateProofRemotely,
|
|
181
180
|
f,
|
|
182
181
|
t.merkleTreeHinkal,
|
|
@@ -187,11 +186,11 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
187
186
|
[D],
|
|
188
187
|
[T],
|
|
189
188
|
K,
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
d.flatFee,
|
|
190
|
+
d.variableRate,
|
|
192
191
|
b,
|
|
193
192
|
S,
|
|
194
|
-
|
|
193
|
+
i,
|
|
195
194
|
[P],
|
|
196
195
|
t.getCurrentChainId(),
|
|
197
196
|
void 0,
|
|
@@ -213,39 +212,39 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
213
212
|
proofCArr: O,
|
|
214
213
|
publicInputsArr: C,
|
|
215
214
|
encryptedOutputs: [P],
|
|
216
|
-
relayerFee:
|
|
217
|
-
dimensions:
|
|
215
|
+
relayerFee: d.flatFee.toString(),
|
|
216
|
+
dimensions: i
|
|
218
217
|
},
|
|
219
218
|
accounts: n
|
|
220
219
|
};
|
|
221
220
|
})
|
|
222
221
|
);
|
|
223
|
-
|
|
222
|
+
a.push(...F);
|
|
224
223
|
}
|
|
225
224
|
await N(y, {
|
|
226
225
|
id: u,
|
|
227
|
-
hashedEthereumAddress:
|
|
226
|
+
hashedEthereumAddress: l,
|
|
228
227
|
phase: k.BEFORE_SCHEDULE_WITHDRAW
|
|
229
228
|
});
|
|
230
229
|
const A = await ut(
|
|
231
230
|
t.getCurrentChainId(),
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
a,
|
|
232
|
+
l,
|
|
234
233
|
g,
|
|
235
234
|
h
|
|
236
235
|
);
|
|
237
236
|
return await N(y, {
|
|
238
237
|
id: u,
|
|
239
|
-
hashedEthereumAddress:
|
|
238
|
+
hashedEthereumAddress: l,
|
|
240
239
|
phase: k.AFTER_SCHEDULE_WITHDRAW,
|
|
241
240
|
scheduleId: A
|
|
242
241
|
}), A;
|
|
243
|
-
},
|
|
242
|
+
}, To = async (t, r, p, d, l, u, g) => {
|
|
244
243
|
const h = j(await t.getEthereumAddress()), y = t.getCurrentChainId(), s = u ?? await gt(y, r, [r], J.Transact, [], 0n), { userDepositedUtxos: f, statusId: E } = await ft(
|
|
245
244
|
t,
|
|
246
245
|
r,
|
|
247
246
|
p,
|
|
248
|
-
|
|
247
|
+
d,
|
|
249
248
|
s,
|
|
250
249
|
h
|
|
251
250
|
);
|
|
@@ -256,10 +255,10 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
256
255
|
s,
|
|
257
256
|
h,
|
|
258
257
|
E,
|
|
259
|
-
|
|
258
|
+
l,
|
|
260
259
|
g
|
|
261
260
|
);
|
|
262
261
|
};
|
|
263
262
|
export {
|
|
264
|
-
|
|
263
|
+
To as hinkalSolanaDepositAndWithdraw
|
|
265
264
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../types/circom-data.types.cjs");const ne=require("../../types/external-action.types.cjs"),y=require("../../constants/protocol.constants.cjs");require("../../types/
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../types/circom-data.types.cjs");const ne=require("../../types/external-action.types.cjs"),y=require("../../constants/protocol.constants.cjs");require("../../types/activities.types.cjs");const se=require("../../types/cache.types.cjs"),ce=require("../../functions/web3/events/getShieldedBalance.cjs"),ae=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),ie=require("../../functions/utils/time.utils.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),le=require("../../functions/snarkjs/common.snarkjs.cjs"),de=require("../../constants/chains.constants.cjs"),c=require("@solana/web3.js"),m=require("../../functions/pre-transaction/solana.cjs"),pe=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ge=require("../utxo/Utxo.cjs"),S=require("../../functions/web3/etherFunctions.cjs"),Ae=require("../../functions/pre-transaction/convert-okx-instructions.cjs"),ye=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),me=require("../../error-handling/error-codes.constants.cjs"),Se=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),we=require("ethers"),Pe=async(t,o,r,w,K,x,E,R,v=!1)=>{if(v)throw new Error("onlyGasEstimate is not supported for Solana swap");const a=t.getCurrentChainId(),P=new c.PublicKey(y.solanaNativeAddress),{hinkalAddress:F,originalDeployer:i,hinkalIdl:f}=de.networkRegistry[a].contractData;if(!i||!f)throw new Error("No IDL configured for Solana program on this network");const u=new c.PublicKey(i),l=new c.PublicKey(F),n=o.map(e=>e.erc20TokenAddress),{userKeys:b,merkleTreeAccessToken:_,merkleTreeHinkal:N}=t,O=t.getSolanaProgram(f),s=R??await ue.getFeeStructure(a,E,n,ne.ExternalActionId.Transact),{patchAccessTokenMerkleTree:U,kycRequired:D,hasAccessToken:B}=await Se.shouldPatchAccessTokenMerkleTree(t,n,r);r[1]-=s.flatFee;const C=s.variableRate.toString(),L=Number(t.cacheDevice.get(se.StorageKeys.SLIPPAGE_PERCENTAGE)??0),d=o[1],M=S.getAmountInToken(d,r[1]),V=Number(M)*L/100;r[1]-=S.getAmountInWei(d,V.toFixed(d.decimals));const p=[...await ce.addPaddingToUtxos(t,n,r,6)],j=ie.getCurrentTimeInSeconds().toString(),G=t.userKeys.getShieldedPrivateKey(),g=[];for(let e=0;e<n.length;e+=1){const{outputUtxos:oe}=ae.outputUtxoProcessing(t.userKeys,p[e],r[e],j,void 0,!1);g.push([oe[0]])}const W=ge.Utxo.findCorrectRandomization(S.randomBigInt(31),G),T={tokenNumber:2,nullifierAmount:p[0].length,outputAmount:1},z=[!1,!0].slice(0,r.length),A=await t.getRandomRelay(!0);if(!A)throw Error(me.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const k=le.calcEncryptedOutputs(g).map(e=>[...we.ethers.getBytes(e[0])]),q=m.getSwapperAccountPublicKeyFromSalt(l,u,w),{remainingAccounts:I,hinkalInstructions:h}=Ae.convertOKXToHinkalInstructions(K,q),{proofAArr:H,proofBArr:Z,proofCArr:X,publicInputsArr:Y}=await pe.constructSolanaZkProof(t.generateProofRemotely,i,N,_,b,O,n,p,g,W,s.flatFee,s.variableRate,P.toString(),A,T,k,a,U,z,w,h,I),J=m.getStorageAccountPublicKey(l,u),Q=m.getStorageVaultPublicKey(l,u),$=o[0].erc20TokenAddress!==y.solanaNativeAddress?new c.PublicKey(o[0].erc20TokenAddress):null,ee=o[1].erc20TokenAddress!==y.solanaNativeAddress?new c.PublicKey(o[1].erc20TokenAddress):null,te={recipient:P.toString(),storageAccount:J.toString(),storageVault:Q.toString(),swapperAccount:q.toString(),mintFrom:$?.toString()??null,mintTo:ee?.toString()??null,remainingAccounts:I.map(e=>({pubkey:e.pubkey.toString(),isSigner:e.isSigner,isWritable:e.isWritable})),addressLookupTableAccount:x},re={encryptedOutputs:k,proofAArr:H,proofBArr:Z,proofCArr:X,publicInputsArr:Y,relayerFee:s.flatFee.toString(),variableRate:C,dimensions:T,hinkalInstructions:h.map(e=>({accountIndexes:[...e.accountIndexes],data:[...e.data],programIndex:e.programIndex}))};return ye.solanaTransactCallRelayer(a,{relayAddress:A,functionName:"swap",args:re,accounts:te,solanaAccessTokenData:!B&&D?{ethereumAddress:await t.getEthereumAddress(),accessKey:b.getAccessKey()}:void 0})};exports.hinkalSolanaSwap=Pe;
|