@hinkal/common 0.2.25 → 0.2.26

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/README.md CHANGED
@@ -100,13 +100,14 @@ Shielding is the process of moving your tokens from a public blockchain address
100
100
  A user can deposit funds to their shielded address using:
101
101
 
102
102
  ```typescript
103
- function deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[]): Promise<ethers.providers.TransactionResponse>;
103
+ function deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean): Promise<ethers.providers.TransactionResponse>;
104
104
  ```
105
105
 
106
106
  where:
107
107
 
108
108
  - `erc20Tokens` is an array of tokens to deposit
109
109
  - `amountChanges` represents the corresponding token amounts for the deposit
110
+ - `preEstimateGas` If true (default), the gas needed for the operation will be estimated before executing the deposit. This can help avoid failed transactions due to "out of gas" error.
110
111
 
111
112
  The `ERC20Token` type is defined as follows:
112
113
 
@@ -172,6 +173,7 @@ function depositAndWithdraw(
172
173
  recipientAmounts: bigint[],
173
174
  recipientAddresses: string[],
174
175
  txCompletionTime?: number,
176
+ preEstimateGas?: boolean
175
177
  ): Promise<string>;
176
178
  ```
177
179
 
@@ -181,6 +183,7 @@ where:
181
183
  - `recipientAmounts` is an array of amounts to send to each recipient (in the token's smallest unit)
182
184
  - `recipientAddresses` is an array of public addresses that will receive the funds
183
185
  - `txCompletionTime` (optional) specifies a delay in milliseconds before the withdrawal completes
186
+ - `preEstimateGas` If true (default), the gas needed for the operation will be estimated before executing the deposit. This can help avoid failed transactions due to "out of gas" error.
184
187
 
185
188
  ### Swapping tokens from the shielded balance
186
189
 
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../types/hinkal.types.cjs"),S=require("../../types/ethereum-network.types.cjs"),x=require("./hinkalCheckSolanaTokenRegistry.cjs"),m=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),W=require("../../functions/web3/events/getShieldedBalance.cjs"),A=require("../crypto-keys/keys.cjs"),I=require("./hinkalDeposit.cjs"),B=require("./hinkalDepositAndWithdraw.cjs"),w=require("./hinkalSolanaDeposit.cjs"),K=require("./hinkalSwap.cjs"),U=require("./hinkalWithdraw.cjs"),L=require("./hinkalWithdrawStuckUtxos.cjs"),N=require("./resetMerkleTrees.cjs"),M=require("../merkle-tree/MerkleTree.cjs");require("ethers");const R=require("../../error-handling/error-codes.constants.cjs"),F=require("../../crypto/poseidon.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const h=require("../../constants/chains.constants.cjs");require("../../API/getServerURL.cjs");require("axios");require("../../constants/coingecko.constants.cjs");require("../../constants/server.constants.cjs");require("../http/HttpClient.cjs");const _=require("../../constants/vite.constants.cjs"),P=require("../../API/API.cjs");require("../../constants/token-data/index.cjs");require("../../constants/contracts.constants.cjs");const O=require("../../constants/kyc.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("../../API/tenderly.api.cjs");const j=require("../../functions/utils/reloadPage.cjs"),z=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),$=require("./hinkalPrivateWallet.cjs"),J=require("../../functions/utils/cacheFunctions.cjs"),Q=require("../../functions/utils/cacheDevice.utils.cjs"),V=require("../../functions/web3/getContractMetadata.cjs"),X=require("./hinkalGetRecipientInfo.cjs"),Y=require("./hinkalApprove.cjs"),Z=require("./hinkalInsideTransact.cjs"),v=require("../../functions/web3/events/getApprovedBalance.cjs"),C=require("../../functions/web3/functionCalls/inHinkalApprovalCalls.cjs"),G=require("./hinkalSignSubAccount.cjs"),ee=require("./hinkalCheckTokenRegistry.cjs"),te=require("./hinkalActionReceive.cjs"),re=require("./hinkalActionFundApproveAndTransact.cjs"),ie=require("../TokenDBs/PrivateTokensDB.cjs");require("idb-keyval");const ne=require("../../functions/utils/erc20tokenFunctions.cjs");require("multiformats");const g=require("@solana/web3.js");require("@solana/spl-token");require("async-mutex");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../types/circom-data.types.cjs");require("../../types/activities.types.cjs");const E=require("../../functions/pre-transaction/solana.cjs");require("@coral-xyz/anchor");require("../../functions/utils/userAgent.cjs");require("../../functions/utils/mutexes.utils.cjs");require("node-forge");require("../../functions/web3/getTokenHolder.cjs");const ae=require("../../functions/private-wallet/emporium.helpers.cjs"),se=require("./hinkalProoflessDeposit.cjs"),oe=require("./hinkalProxySwap.cjs"),ce=require("./hinkalMultiSend.cjs"),he=require("./hinkalTransfer.cjs"),le=require("./hinkalProxyToPrivate.cjs"),de=require("./hinkalSolanaDepositAndWithdraw.cjs"),pe=require("./hinkalSolanaWithdraw.cjs"),ue=require("./hinkalSolanaTransfer.cjs"),ge=require("./hinkalSolanaSwap.cjs"),ke=require("./hinkalSolanaProxySend.cjs"),ve=require("./hinkalSolanaProxySwap.cjs"),D=require("./hinkalSolanaProxyShield.cjs"),H=require("../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs"),ye=require("./hinkalDepostAndBridge.cjs");class Se{providerAdapter;userKeys;signingMessage="Login to Hinkal Protocol";privateTransferSigningMessage="Login to Hinkal's Private Transfer App";merkleTreeHinkal;merkleTreeAccessToken;nullifiers;encryptedOutputs;approvals;commitmentsSnapshotService;nullifierSnapshotService;accessTokenSnapshotService;approvalsSnapshotService;utxoUtils;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;constructor(e){this.userKeys=new A.UserKeys(void 0),this.merkleTreeHinkal=M.MerkleTree.create(F.poseidonFunction,0n),this.merkleTreeAccessToken=M.MerkleTree.create(F.poseidonFunction,0n),this.nullifiers=new Set,this.encryptedOutputs=[],this.approvals=new Map,this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new z.MultiThreadedUtxoUtils,this.cacheDevice=Q.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}async initProviderAdapter(e,t){await this.updateProviderAdapter(t),this.providerAdapter?.initConnector(e);const r=await this.connectAndPatchProvider(e);await t.init(r),await this.setListeners()}async initUserKeys(e=!1){const t=e?this.privateTransferSigningMessage:this.signingMessage;this.userKeys=new A.UserKeys(await this.getProviderAdapter().signMessage(t))}async initUserKeysWithPassword(e){this.userKeys=new A.UserKeys(e)}async resetMerkle(){this.disableMerkleTreeUpdates||this.isSelectedNetworkSupported()&&await N.resetMerkleTrees(this)}getProviderAdapter(){if(!this.providerAdapter)throw new Error("ProviderAdapter is not initialized");return this.providerAdapter}async waitForTransaction(e,t=1){return!!await this.providerAdapter?.waitForTransaction(e,t)}getContractMetadata(e,t){return this.getProviderAdapter().getContractMetadata(e,t)}getContract(e,t=void 0,r){return this.getProviderAdapter().getContract(e,t,r)}getContractWithFetcherByChainId(e,t,r=void 0){return V.getContractWithFetcherByChainId(e,t,r)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,r){return await this.getProviderAdapter().signTypedData(e,t,r)}async signWithSubAccount(e,t,r){return G.hinkalSignSubAccount(this,e,t,r)}getContractWithSigner(e,t=""){return this.getProviderAdapter().getContractWithSigner(e,t)}getContractWithFetcher(e,t=""){return this.getProviderAdapter().getContractWithFetcher(e,t)}getContractWithFetcherForEthereum(e,t){return this.getProviderAdapter().getContractWithFetcherForEthereum(e,t)}isSelectedNetworkSupported(){return!!h.networkRegistry[this.getCurrentChainId()]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(R.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}async switchAccount(e){await this.getProviderAdapter().switchAccount(e)}getCurrentChainId(){const{chainId:e}=this.getProviderAdapter();if(!e)throw new Error("Illegal State: no chainId");return e}getSelectedNetwork(){return this.providerAdapter?.getSelectedNetwork()}isPermitterAvailable(){return this.getProviderAdapter().isPermitterAvailable()}async connectAndPatchProvider(e){return await this.getProviderAdapter().connectAndPatchProvider(e)}async disconnectFromConnector(){await this.getProviderAdapter().disconnectFromConnector()}async updateProviderAdapter(e){try{this.providerAdapter&&this.providerAdapter.release(),this.providerAdapter=e}catch(t){throw console.error(t),Error("updateProviderAdapter failed, please try again.")}}async setListeners(){this.providerAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.getProviderAdapter().onAccountChanged();const e=T.EventType.AccountChanged;typeof document<"u"?document?.dispatchEvent(new Event(e)):process?.emit("message",e,void 0)}async onChainChanged(e){if(e){await this.getProviderAdapter().onChainChanged(e);const t=T.EventType.NetworkChange;typeof document<"u"?document.dispatchEvent(new Event(t)):process?.emit("message",t,void 0)}else await this.disconnectFromConnector(),j.reloadPage()}async monitorConnectedAddress(){const e=this.getCurrentChainId();h.isSolanaLike(e)||await P.API.monitor(await this.getEthereumAddress(),e)}async getBalances(e,t,r,i,n=!1,a,s=!1){return W.getShieldedBalance(this,e,t,r,i,n,this.generateProofRemotely,a,s)}async getApprovedBalances(e=!1,t=!1){return v.getApprovedBalance(this,e,t)}async getTotalBalance(e,t,r,i=!1,n,a=!1){const s=e??this.getCurrentChainId(),o=r??await this.getEthereumAddress(),c=t??this.userKeys,l=await this.getBalances(s,c.getShieldedPrivateKey(),c.getShieldedPublicKey(),o,i,n,a),p=!h.isSolanaLike(s)&&!a?await this.getApprovedBalances(i,n):new Map,d=_.isExtension?await ie.privateTokensDB.getPrivateTokens(s,o):ne.getErc20TokensForChain(s),u=[];return d.forEach(k=>{const f=k.erc20TokenAddress.toLowerCase(),y=l.get(f),q=p.get(f),b={token:k,balance:(y?.balance??0n)+(q?.balance??0n),timestamp:y?.timestamp||q?.timestamp||"0",nfts:y?.nfts||[]};u.push(b)}),u}async getStuckShieldedBalances(e,t,r){return(await this.getTotalBalance(e,t,r,!1,!1,!0)).filter(n=>n.balance>0n)}getSupportedPassportLinks(){return O.supportedPassportLinks}checkAccessToken(){return m.checkHinkalAccessToken(this)}async mintHinkalAccessToken(e,t){return m.mintAccessToken(this,e,t)}async getHinkalTreeRootHash(){const e=this.getCurrentChainId();if(h.isSolanaLike(e)){const{hinkalIdl:r,hinkalAddress:i,originalDeployer:n}=h.networkRegistry[e].contractData;if(!r||!i||!n)throw new Error(`Missing Solana configuration for chain ${e}`);const a=new g.PublicKey(n),s=new g.PublicKey(i),o=E.getMerkleAccountPublicKey(s,a),c=this.getSolanaProgram(r);return H.fetchSolanaMerkleTreeRootHash(c,o)}return this.getContractWithFetcher(S.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(){const e=this.getCurrentChainId();if(h.isSolanaLike(e)){const{hinkalIdl:r,hinkalAddress:i,originalDeployer:n}=h.networkRegistry[e].contractData;if(!r||!i||!n)throw new Error(`Missing Solana configuration for chain ${e}`);const a=new g.PublicKey(n),s=new g.PublicKey(i),o=E.getAccessTokenMerkleAccountPublicKey(s,a),c=this.getSolanaProgram(r);return H.fetchSolanaMerkleTreeRootHash(c,o)}return this.getContractWithFetcher(S.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(){if(!this.isSelectedNetworkSupported())throw new Error(R.transactionErrorCodes.UNSUPPORTED_NETWORK);const[e,t]=await Promise.all([this.getHinkalTreeRootHash(),this.getAccessTokenTreeRootHash()]);(BigInt(e)!==this.merkleTreeHinkal.getRootHash()||BigInt(t)!==this.merkleTreeAccessToken.getRootHash())&&(console.log("resetting merkle tree in resetMerkleTreesIfNecessary"),await this.resetMerkle())}async getEventsFromHinkal(){await Promise.all([this.accessTokenSnapshotService?.retrieveEventsFromLatestBlock(),this.commitmentsSnapshotService?.retrieveEventsFromLatestBlock(),this.nullifierSnapshotService?.retrieveEventsFromLatestBlock(),this.approvalsSnapshotService?.retrieveEventsFromLatestBlock()])}getEthereumAddress(){return this.getProviderAdapter().getAddress()}async getRandomRelay(e=!1){const t=this.getCurrentChainId();return(await P.API.getIdleRelay(t,e)).relay}getGasPrice(){if(!this.providerAdapter?.chainId)throw new Error("Illegal State of providerAdapter in Hinkal: no chainId");return this.providerAdapter.getGasPrice()}getAPI(){return P.API}resetCache(){J.resetCache(this,this.getCurrentChainId(),this.userKeys.getShieldedPublicKey())}snapshotsClearInterval(){this.commitmentsSnapshotService?.intervalClear(),this.accessTokenSnapshotService?.intervalClear(),this.nullifierSnapshotService?.intervalClear(),this.approvalsSnapshotService?.intervalClear()}checkTokenRegistry(e,t){const r=this.getCurrentChainId();if(h.isSolanaLike(r)){const{hinkalIdl:n,hinkalAddress:a,originalDeployer:s}=h.networkRegistry[r].contractData;if(!n||!a||!s)throw new Error("missing solana data");const o=this.getSolanaProgram(n),c=new g.PublicKey(s);return x.hinkalCheckSolanaTokenRegistry(o,c,e,t)}const i=this.getContractWithFetcher(S.ContractType.HinkalHelperContract);return ee.hinkalCheckTokenRegistry(i,e,t)}getRecipientInfo(){return X.getRecipientInfo(this)}async getInteractionApprovals(e){return await C.getInteractionApprovals(this,e)}getApprovedUtxos(e=!1){return v.getApprovedUtxos(this,e)}getApprovedUtxosForToken(e,t=!1){return v.getApprovedUtxosForToken(this,e,t)}getMyApprovalAmountForInteraction(e,t){return v.getMyApprovalAmountForInteraction(this,e,t)}async checkExistingApprovalFromHinkal(e,t){return await C.checkExistingApprovalFromHinkal(this,e,t)}async getBufferEntry(e,t,r){return C.getBufferEntry(this,e,t,r)}async deposit(e,t){return I.hinkalDeposit(this,e,t)}async depositForOther(e,t,r){return I.hinkalDepositForOther(this,e,t,r)}async depositAndWithdraw(e,t,r,i,n,a){return h.isSolanaLike(this.getCurrentChainId())?de.hinkalSolanaDepositAndWithdraw(this,e.erc20TokenAddress,t,r,i,n,a):B.hinkalDepositAndWithdraw(this,e,t,r,i,n,a)}async depositAndBridge(e,t,r,i,n){return ye.hinkalDepositAndBridge(this,e,t,r,i,n)}async prooflessDeposit(e,t,r){return se.hinkalProoflessDeposit(this,e,t,r)}getSolanaProgram(e){if(!this.providerAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaProgram"in this.providerAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.providerAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.providerAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaPublicKey"in this.providerAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.providerAdapter.getSolanaPublicKey()}async depositSolana(e,t){return w.hinkalSolanaDeposit(this,e,t)}async depositSolanaForOther(e,t,r){return w.hinkalSolanaDepositForOther(this,e,t,r)}async solanaMultiPaymentDeposit(e,t){return w.hinkalSolanaMultiPaymentDeposit(this,e,t)}async transfer(e,t,r,i,n,a,s=!1){return h.isSolanaLike(this.getCurrentChainId())?ue.hinkalSolanaTransfer(this,e,t,r,i,n,s):he.hinkalTransfer(this,e,t,r,i,n,a,s)}async withdraw(e,t,r,i,n,a,s,o=!1){return h.isSolanaLike(this.getCurrentChainId())?pe.hinkalSolanaWithdraw(this,e.map(c=>c.erc20TokenAddress),t,r,n,a,o):U.hinkalWithdraw(this,e,t,r,i,n,a,s,o)}async withdrawStuckUtxos(e,t){return L.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,r,i,n,a,s,o=!1,c=!1){return h.isSolanaLike(this.getCurrentChainId())?this.swapSolana(e,t,i,n,a,o):K.hinkalSwap(this,e,t,r,i,n,a,s,o,c)}async swapSolana(e,t,r,i,n,a=!1){const s=JSON.parse(r),o=BigInt(s.swapperAccountSalt),{instructionLists:c,addressLookupTableAccount:l}=s.data;return ge.hinkalSolanaSwap(this,e,t,o,c,l,i,n,a)}async actionReceive(e,t,r,i,n,a,s=!1){if(!n)throw new Error("subAccount is required");return h.isSolanaLike(this.getCurrentChainId())?D.hinkalSolanaProxyShield(this,e[0],t[0],n,void 0,s):te.hinkalActionReceive(this,e,t,r,i,n,a,s)}async actionFundApproveAndTransact(e,t,r,i,n,a,s,o,c=!1,l,p,d){return re.hinkalActionFundApproveAndTransact(this,e,t,r,i,n,a,s,o,c,l,p,d)}async actionPrivateWallet(e,t,r,i,n,a,s,o,c,l=!1,p,d,u,k=!1){return $.hinkalPrivateWallet(this,e,t,r,i,n,a,s,o,c,l,p,d,u,k)}async approve(e,t,r,i,n,a=!1){return Y.hinkalApprove(this,e,t,r,i,n,a)}async hinkalInsideTransact(e,t,r,i,n,a,s,o,c,l=!1){return Z.hinkalInsideTransact(this,e,t,r,i,n,a,s,o,c,l)}async proxySwap(e,t,r,i,n,a,s,o,c=!1,l,p,d=!1){return h.isSolanaLike(this.getCurrentChainId())?ve.hinkalSolanaProxySwap(this,e,t,i,a,s,o,d):oe.hinkalProxySwap(this,e,t,r,i,n,a,s,o,c,l,p,d)}async proxyToPrivate(e,t,r,i,n,a,s,o=!1){return h.isSolanaLike(this.getCurrentChainId())?D.hinkalSolanaProxyShield(this,e[0],t[0],r,i,o):le.hinkalProxyToPrivate(this,e,t,i,n,a,r,s,o)}async proxySend(e,t,r,i,n,a,s,o=!1){if(h.isSolanaLike(this.getCurrentChainId()))return ke.hinkalSolanaProxySend(this,e[0],t[0],r,i,o);const c=ae.createTransaferEmporiumOpsBatch(this,e.map(d=>d.erc20TokenAddress),t,i),l=e.map((d,u)=>({token:d,amount:-1n*t[u]}));return await this.actionPrivateWallet([],[],[],c,l,r,n,a,void 0,void 0,void 0,s,void 0,o)}async multiSendPrivateRecipients(e,t,r){return ce.hinkalMultiSendPrivateRecipients(this,e,t,r)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}}exports.Hinkal=Se;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../types/hinkal.types.cjs"),S=require("../../types/ethereum-network.types.cjs"),x=require("./hinkalCheckSolanaTokenRegistry.cjs"),m=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),W=require("../../functions/web3/events/getShieldedBalance.cjs"),A=require("../crypto-keys/keys.cjs"),I=require("./hinkalDeposit.cjs"),B=require("./hinkalDepositAndWithdraw.cjs"),w=require("./hinkalSolanaDeposit.cjs"),K=require("./hinkalSwap.cjs"),U=require("./hinkalWithdraw.cjs"),L=require("./hinkalWithdrawStuckUtxos.cjs"),N=require("./resetMerkleTrees.cjs"),M=require("../merkle-tree/MerkleTree.cjs");require("ethers");const R=require("../../error-handling/error-codes.constants.cjs"),F=require("../../crypto/poseidon.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const h=require("../../constants/chains.constants.cjs");require("../../API/getServerURL.cjs");require("axios");require("../../constants/coingecko.constants.cjs");require("../../constants/server.constants.cjs");require("../http/HttpClient.cjs");const _=require("../../constants/vite.constants.cjs"),P=require("../../API/API.cjs");require("../../constants/token-data/index.cjs");require("../../constants/contracts.constants.cjs");const O=require("../../constants/kyc.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("../../API/tenderly.api.cjs");const j=require("../../functions/utils/reloadPage.cjs"),z=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),$=require("./hinkalPrivateWallet.cjs"),J=require("../../functions/utils/cacheFunctions.cjs"),Q=require("../../functions/utils/cacheDevice.utils.cjs"),V=require("../../functions/web3/getContractMetadata.cjs"),X=require("./hinkalGetRecipientInfo.cjs"),Y=require("./hinkalApprove.cjs"),Z=require("./hinkalInsideTransact.cjs"),v=require("../../functions/web3/events/getApprovedBalance.cjs"),C=require("../../functions/web3/functionCalls/inHinkalApprovalCalls.cjs"),G=require("./hinkalSignSubAccount.cjs"),ee=require("./hinkalCheckTokenRegistry.cjs"),te=require("./hinkalActionReceive.cjs"),re=require("./hinkalActionFundApproveAndTransact.cjs"),ie=require("../TokenDBs/PrivateTokensDB.cjs");require("idb-keyval");const ne=require("../../functions/utils/erc20tokenFunctions.cjs");require("multiformats");const g=require("@solana/web3.js");require("@solana/spl-token");require("async-mutex");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../types/circom-data.types.cjs");require("../../types/activities.types.cjs");const E=require("../../functions/pre-transaction/solana.cjs");require("@coral-xyz/anchor");require("../../functions/utils/userAgent.cjs");require("../../functions/utils/mutexes.utils.cjs");require("node-forge");require("../../functions/web3/getTokenHolder.cjs");const ae=require("../../functions/private-wallet/emporium.helpers.cjs"),se=require("./hinkalProoflessDeposit.cjs"),oe=require("./hinkalProxySwap.cjs"),ce=require("./hinkalMultiSend.cjs"),he=require("./hinkalTransfer.cjs"),le=require("./hinkalProxyToPrivate.cjs"),de=require("./hinkalSolanaDepositAndWithdraw.cjs"),pe=require("./hinkalSolanaWithdraw.cjs"),ue=require("./hinkalSolanaTransfer.cjs"),ge=require("./hinkalSolanaSwap.cjs"),ke=require("./hinkalSolanaProxySend.cjs"),ve=require("./hinkalSolanaProxySwap.cjs"),D=require("./hinkalSolanaProxyShield.cjs"),H=require("../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs"),ye=require("./hinkalDepostAndBridge.cjs");class Se{providerAdapter;userKeys;signingMessage="Login to Hinkal Protocol";privateTransferSigningMessage="Login to Hinkal's Private Transfer App";merkleTreeHinkal;merkleTreeAccessToken;nullifiers;encryptedOutputs;approvals;commitmentsSnapshotService;nullifierSnapshotService;accessTokenSnapshotService;approvalsSnapshotService;utxoUtils;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;constructor(e){this.userKeys=new A.UserKeys(void 0),this.merkleTreeHinkal=M.MerkleTree.create(F.poseidonFunction,0n),this.merkleTreeAccessToken=M.MerkleTree.create(F.poseidonFunction,0n),this.nullifiers=new Set,this.encryptedOutputs=[],this.approvals=new Map,this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new z.MultiThreadedUtxoUtils,this.cacheDevice=Q.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}async initProviderAdapter(e,t){await this.updateProviderAdapter(t),this.providerAdapter?.initConnector(e);const r=await this.connectAndPatchProvider(e);await t.init(r),await this.setListeners()}async initUserKeys(e=!1){const t=e?this.privateTransferSigningMessage:this.signingMessage;this.userKeys=new A.UserKeys(await this.getProviderAdapter().signMessage(t))}async initUserKeysWithPassword(e){this.userKeys=new A.UserKeys(e)}async resetMerkle(){this.disableMerkleTreeUpdates||this.isSelectedNetworkSupported()&&await N.resetMerkleTrees(this)}getProviderAdapter(){if(!this.providerAdapter)throw new Error("ProviderAdapter is not initialized");return this.providerAdapter}async waitForTransaction(e,t=1){return!!await this.providerAdapter?.waitForTransaction(e,t)}getContractMetadata(e,t){return this.getProviderAdapter().getContractMetadata(e,t)}getContract(e,t=void 0,r){return this.getProviderAdapter().getContract(e,t,r)}getContractWithFetcherByChainId(e,t,r=void 0){return V.getContractWithFetcherByChainId(e,t,r)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,r){return await this.getProviderAdapter().signTypedData(e,t,r)}async signWithSubAccount(e,t,r){return G.hinkalSignSubAccount(this,e,t,r)}getContractWithSigner(e,t=""){return this.getProviderAdapter().getContractWithSigner(e,t)}getContractWithFetcher(e,t=""){return this.getProviderAdapter().getContractWithFetcher(e,t)}getContractWithFetcherForEthereum(e,t){return this.getProviderAdapter().getContractWithFetcherForEthereum(e,t)}isSelectedNetworkSupported(){return!!h.networkRegistry[this.getCurrentChainId()]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(R.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}async switchAccount(e){await this.getProviderAdapter().switchAccount(e)}getCurrentChainId(){const{chainId:e}=this.getProviderAdapter();if(!e)throw new Error("Illegal State: no chainId");return e}getSelectedNetwork(){return this.providerAdapter?.getSelectedNetwork()}isPermitterAvailable(){return this.getProviderAdapter().isPermitterAvailable()}async connectAndPatchProvider(e){return await this.getProviderAdapter().connectAndPatchProvider(e)}async disconnectFromConnector(){await this.getProviderAdapter().disconnectFromConnector()}async updateProviderAdapter(e){try{this.providerAdapter&&this.providerAdapter.release(),this.providerAdapter=e}catch(t){throw console.error(t),Error("updateProviderAdapter failed, please try again.")}}async setListeners(){this.providerAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.getProviderAdapter().onAccountChanged();const e=T.EventType.AccountChanged;typeof document<"u"?document?.dispatchEvent(new Event(e)):process?.emit("message",e,void 0)}async onChainChanged(e){if(e){await this.getProviderAdapter().onChainChanged(e);const t=T.EventType.NetworkChange;typeof document<"u"?document.dispatchEvent(new Event(t)):process?.emit("message",t,void 0)}else await this.disconnectFromConnector(),j.reloadPage()}async monitorConnectedAddress(){const e=this.getCurrentChainId();h.isSolanaLike(e)||await P.API.monitor(await this.getEthereumAddress(),e)}async getBalances(e,t,r,i,n=!1,a,s=!1){return W.getShieldedBalance(this,e,t,r,i,n,this.generateProofRemotely,a,s)}async getApprovedBalances(e=!1,t=!1){return v.getApprovedBalance(this,e,t)}async getTotalBalance(e,t,r,i=!1,n,a=!1){const s=e??this.getCurrentChainId(),o=r??await this.getEthereumAddress(),c=t??this.userKeys,l=await this.getBalances(s,c.getShieldedPrivateKey(),c.getShieldedPublicKey(),o,i,n,a),p=!h.isSolanaLike(s)&&!a?await this.getApprovedBalances(i,n):new Map,d=_.isExtension?await ie.privateTokensDB.getPrivateTokens(s,o):ne.getErc20TokensForChain(s),u=[];return d.forEach(k=>{const f=k.erc20TokenAddress.toLowerCase(),y=l.get(f),q=p.get(f),b={token:k,balance:(y?.balance??0n)+(q?.balance??0n),timestamp:y?.timestamp||q?.timestamp||"0",nfts:y?.nfts||[]};u.push(b)}),u}async getStuckShieldedBalances(e,t,r){return(await this.getTotalBalance(e,t,r,!1,!1,!0)).filter(n=>n.balance>0n)}getSupportedPassportLinks(){return O.supportedPassportLinks}checkAccessToken(){return m.checkHinkalAccessToken(this)}async mintHinkalAccessToken(e,t){return m.mintAccessToken(this,e,t)}async getHinkalTreeRootHash(){const e=this.getCurrentChainId();if(h.isSolanaLike(e)){const{hinkalIdl:r,hinkalAddress:i,originalDeployer:n}=h.networkRegistry[e].contractData;if(!r||!i||!n)throw new Error(`Missing Solana configuration for chain ${e}`);const a=new g.PublicKey(n),s=new g.PublicKey(i),o=E.getMerkleAccountPublicKey(s,a),c=this.getSolanaProgram(r);return H.fetchSolanaMerkleTreeRootHash(c,o)}return this.getContractWithFetcher(S.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(){const e=this.getCurrentChainId();if(h.isSolanaLike(e)){const{hinkalIdl:r,hinkalAddress:i,originalDeployer:n}=h.networkRegistry[e].contractData;if(!r||!i||!n)throw new Error(`Missing Solana configuration for chain ${e}`);const a=new g.PublicKey(n),s=new g.PublicKey(i),o=E.getAccessTokenMerkleAccountPublicKey(s,a),c=this.getSolanaProgram(r);return H.fetchSolanaMerkleTreeRootHash(c,o)}return this.getContractWithFetcher(S.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(){if(!this.isSelectedNetworkSupported())throw new Error(R.transactionErrorCodes.UNSUPPORTED_NETWORK);const[e,t]=await Promise.all([this.getHinkalTreeRootHash(),this.getAccessTokenTreeRootHash()]);(BigInt(e)!==this.merkleTreeHinkal.getRootHash()||BigInt(t)!==this.merkleTreeAccessToken.getRootHash())&&(console.log("resetting merkle tree in resetMerkleTreesIfNecessary"),await this.resetMerkle())}async getEventsFromHinkal(){await Promise.all([this.accessTokenSnapshotService?.retrieveEventsFromLatestBlock(),this.commitmentsSnapshotService?.retrieveEventsFromLatestBlock(),this.nullifierSnapshotService?.retrieveEventsFromLatestBlock(),this.approvalsSnapshotService?.retrieveEventsFromLatestBlock()])}getEthereumAddress(){return this.getProviderAdapter().getAddress()}async getRandomRelay(e=!1){const t=this.getCurrentChainId();return(await P.API.getIdleRelay(t,e)).relay}getGasPrice(){if(!this.providerAdapter?.chainId)throw new Error("Illegal State of providerAdapter in Hinkal: no chainId");return this.providerAdapter.getGasPrice()}getAPI(){return P.API}resetCache(){J.resetCache(this,this.getCurrentChainId(),this.userKeys.getShieldedPublicKey())}snapshotsClearInterval(){this.commitmentsSnapshotService?.intervalClear(),this.accessTokenSnapshotService?.intervalClear(),this.nullifierSnapshotService?.intervalClear(),this.approvalsSnapshotService?.intervalClear()}checkTokenRegistry(e,t){const r=this.getCurrentChainId();if(h.isSolanaLike(r)){const{hinkalIdl:n,hinkalAddress:a,originalDeployer:s}=h.networkRegistry[r].contractData;if(!n||!a||!s)throw new Error("missing solana data");const o=this.getSolanaProgram(n),c=new g.PublicKey(s);return x.hinkalCheckSolanaTokenRegistry(o,c,e,t)}const i=this.getContractWithFetcher(S.ContractType.HinkalHelperContract);return ee.hinkalCheckTokenRegistry(i,e,t)}getRecipientInfo(){return X.getRecipientInfo(this)}async getInteractionApprovals(e){return await C.getInteractionApprovals(this,e)}getApprovedUtxos(e=!1){return v.getApprovedUtxos(this,e)}getApprovedUtxosForToken(e,t=!1){return v.getApprovedUtxosForToken(this,e,t)}getMyApprovalAmountForInteraction(e,t){return v.getMyApprovalAmountForInteraction(this,e,t)}async checkExistingApprovalFromHinkal(e,t){return await C.checkExistingApprovalFromHinkal(this,e,t)}async getBufferEntry(e,t,r){return C.getBufferEntry(this,e,t,r)}async deposit(e,t,r=!0){return I.hinkalDeposit(this,e,t,r)}async depositForOther(e,t,r,i=!0){return I.hinkalDepositForOther(this,e,t,r,i)}async depositAndWithdraw(e,t,r,i,n,a,s=!0){return h.isSolanaLike(this.getCurrentChainId())?de.hinkalSolanaDepositAndWithdraw(this,e.erc20TokenAddress,t,r,i,n,a):B.hinkalDepositAndWithdraw(this,e,t,r,i,n,a,s)}async depositAndBridge(e,t,r,i,n,a=!0){return ye.hinkalDepositAndBridge(this,e,t,r,i,n,a)}async prooflessDeposit(e,t,r){return se.hinkalProoflessDeposit(this,e,t,r)}getSolanaProgram(e){if(!this.providerAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaProgram"in this.providerAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.providerAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.providerAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaPublicKey"in this.providerAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.providerAdapter.getSolanaPublicKey()}async depositSolana(e,t){return w.hinkalSolanaDeposit(this,e,t)}async depositSolanaForOther(e,t,r){return w.hinkalSolanaDepositForOther(this,e,t,r)}async solanaMultiPaymentDeposit(e,t){return w.hinkalSolanaMultiPaymentDeposit(this,e,t)}async transfer(e,t,r,i,n,a,s=!1){return h.isSolanaLike(this.getCurrentChainId())?ue.hinkalSolanaTransfer(this,e,t,r,i,n,s):he.hinkalTransfer(this,e,t,r,i,n,a,s)}async withdraw(e,t,r,i,n,a,s,o=!1){return h.isSolanaLike(this.getCurrentChainId())?pe.hinkalSolanaWithdraw(this,e.map(c=>c.erc20TokenAddress),t,r,n,a,o):U.hinkalWithdraw(this,e,t,r,i,n,a,s,o)}async withdrawStuckUtxos(e,t){return L.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,r,i,n,a,s,o=!1,c=!1){return h.isSolanaLike(this.getCurrentChainId())?this.swapSolana(e,t,i,n,a,o):K.hinkalSwap(this,e,t,r,i,n,a,s,o,c)}async swapSolana(e,t,r,i,n,a=!1){const s=JSON.parse(r),o=BigInt(s.swapperAccountSalt),{instructionLists:c,addressLookupTableAccount:l}=s.data;return ge.hinkalSolanaSwap(this,e,t,o,c,l,i,n,a)}async actionReceive(e,t,r,i,n,a,s=!1){if(!n)throw new Error("subAccount is required");return h.isSolanaLike(this.getCurrentChainId())?D.hinkalSolanaProxyShield(this,e[0],t[0],n,void 0,s):te.hinkalActionReceive(this,e,t,r,i,n,a,s)}async actionFundApproveAndTransact(e,t,r,i,n,a,s,o,c=!1,l,p,d){return re.hinkalActionFundApproveAndTransact(this,e,t,r,i,n,a,s,o,c,l,p,d)}async actionPrivateWallet(e,t,r,i,n,a,s,o,c,l=!1,p,d,u,k=!1){return $.hinkalPrivateWallet(this,e,t,r,i,n,a,s,o,c,l,p,d,u,k)}async approve(e,t,r,i,n,a=!1){return Y.hinkalApprove(this,e,t,r,i,n,a)}async hinkalInsideTransact(e,t,r,i,n,a,s,o,c,l=!1){return Z.hinkalInsideTransact(this,e,t,r,i,n,a,s,o,c,l)}async proxySwap(e,t,r,i,n,a,s,o,c=!1,l,p,d=!1){return h.isSolanaLike(this.getCurrentChainId())?ve.hinkalSolanaProxySwap(this,e,t,i,a,s,o,d):oe.hinkalProxySwap(this,e,t,r,i,n,a,s,o,c,l,p,d)}async proxyToPrivate(e,t,r,i,n,a,s,o=!1){return h.isSolanaLike(this.getCurrentChainId())?D.hinkalSolanaProxyShield(this,e[0],t[0],r,i,o):le.hinkalProxyToPrivate(this,e,t,i,n,a,r,s,o)}async proxySend(e,t,r,i,n,a,s,o=!1){if(h.isSolanaLike(this.getCurrentChainId()))return ke.hinkalSolanaProxySend(this,e[0],t[0],r,i,o);const c=ae.createTransaferEmporiumOpsBatch(this,e.map(d=>d.erc20TokenAddress),t,i),l=e.map((d,u)=>({token:d,amount:-1n*t[u]}));return await this.actionPrivateWallet([],[],[],c,l,r,n,a,void 0,void 0,void 0,s,void 0,o)}async multiSendPrivateRecipients(e,t,r){return ce.hinkalMultiSendPrivateRecipients(this,e,t,r)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}}exports.Hinkal=Se;
@@ -92,10 +92,10 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
92
92
  getMyApprovalAmountForInteraction(interactionAddress: string, tokenAddress: string): bigint;
93
93
  checkExistingApprovalFromHinkal(erc20Address: string, interactionAddress: string): Promise<bigint>;
94
94
  getBufferEntry(approveTo: string, tokenAddress: string, inHinkalAddress: bigint): Promise<bigint>;
95
- deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[]): Promise<ethers.ContractTransaction>;
96
- depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recipientInfo: string): Promise<ethers.ContractTransaction>;
97
- depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string): Promise<string>;
98
- depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string): Promise<string>;
95
+ deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
96
+ depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recipientInfo: string, preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
97
+ depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean): Promise<string>;
98
+ depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean): Promise<string>;
99
99
  prooflessDeposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], stealthAddressStructures?: StealthAddressStructure[]): Promise<ethers.ContractTransaction>;
100
100
  getSolanaProgram(idl: Idl): Program;
101
101
  getSolanaPublicKey(): PublicKey;
@@ -365,13 +365,13 @@ class cr {
365
365
  async getBufferEntry(e, t, r) {
366
366
  return se(this, e, t, r);
367
367
  }
368
- async deposit(e, t) {
369
- return b(this, e, t);
368
+ async deposit(e, t, r = !0) {
369
+ return b(this, e, t, r);
370
370
  }
371
- async depositForOther(e, t, r) {
372
- return W(this, e, t, r);
371
+ async depositForOther(e, t, r, i = !0) {
372
+ return W(this, e, t, r, i);
373
373
  }
374
- async depositAndWithdraw(e, t, r, i, a, n) {
374
+ async depositAndWithdraw(e, t, r, i, a, n, o = !0) {
375
375
  return p(this.getCurrentChainId()) ? Se(
376
376
  this,
377
377
  e.erc20TokenAddress,
@@ -387,11 +387,20 @@ class cr {
387
387
  r,
388
388
  i,
389
389
  a,
390
- n
390
+ n,
391
+ o
391
392
  );
392
393
  }
393
- async depositAndBridge(e, t, r, i, a) {
394
- return Fe(this, e, t, r, i, a);
394
+ async depositAndBridge(e, t, r, i, a, n = !0) {
395
+ return Fe(
396
+ this,
397
+ e,
398
+ t,
399
+ r,
400
+ i,
401
+ a,
402
+ n
403
+ );
395
404
  }
396
405
  async prooflessDeposit(e, t, r) {
397
406
  return ve(this, e, t, r);
@@ -61,10 +61,10 @@ export interface IHinkal<ConnectorType = unknown> {
61
61
  getMyApprovalAmountForInteraction(interactionAddress: string, tokenAddress: string): bigint;
62
62
  checkExistingApprovalFromHinkal(erc20Address: string, interactionAddress: string): Promise<bigint>;
63
63
  getBufferEntry(approveTo: string, tokenAddress: string, inHinkalAddress: bigint): Promise<bigint>;
64
- deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[]): Promise<ethers.ContractTransaction>;
65
- depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recepinetInfo: string): Promise<ethers.ContractTransaction>;
66
- depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string): Promise<string>;
67
- depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string): Promise<string>;
64
+ deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
65
+ depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recepinetInfo: string, preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
66
+ depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean): Promise<string>;
67
+ depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean): Promise<string>;
68
68
  prooflessDeposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], stealthAddressStructures?: StealthAddressStructure[]): Promise<ethers.ContractTransaction>;
69
69
  getSolanaProgram(idl: Idl): Program;
70
70
  getSolanaPublicKey(): PublicKey;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../../constants/protocol.constants.cjs"),f=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),w=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),h=require("../../functions/web3/events/getShieldedBalance.cjs"),q=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),C=require("../utxo/Utxo.cjs"),F=require("../../error-handling/error-codes.constants.cjs");require("../../types/circom-data.types.cjs");const I=require("../../types/ethereum-network.types.cjs"),M=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const R=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),_=require("../../functions/utils/addresses.cjs"),z=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),H=require("../../functions/utils/time.utils.cjs"),S=require("../../API/admin-calls.cjs"),U=require("../../functions/pre-transaction/constructAdminData.cjs"),K=async(t,s,e)=>{const{patchAccessTokenMerkleTree:o,kycRequired:r,hasAccessToken:A}=await z.shouldPatchAccessTokenMerkleTree(t,s,e),c=void 0,l=await t.getEthereumAddress(),i=await R.getSignatureDataForTransact(t.getCurrentChainId(),l,t.userKeys,r,A),n={externalActionId:0n,externalAddress:await t.getEthereumAddress(),externalActionMetadata:"0x00"};return{signatureData:i,externalActionData:n,contractTransaction:c,contractToApprove:c,patchAccessTokenMerkleTree:o}},O=async(t,s,e)=>{const o=s.map(a=>a.erc20TokenAddress),{externalActionData:r,contractTransaction:A,contractToApprove:c,patchAccessTokenMerkleTree:l,signatureData:i}=await K(t,o,e),n=[...await h.addPaddingToUtxos(t,o,e)],p=`swapperM${e.length.toString()}x${n[0].length}x1`,d=[],T=H.getCurrentTimeInSeconds().toString();for(let a=0;a<o.length;a+=1){const{outputUtxos:v}=f.outputUtxoProcessing(t.userKeys,n[a],e[a],T);d.push(v)}const{zkCallData:m,circomData:x,dimData:g}=await w.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,n,d,t.userKeys,p,r.externalActionId,r.externalAddress,r.externalActionMetadata,t.generateProofRemotely,P.zeroAddress,t.getCurrentChainId(),void 0,void 0,void 0,l,void 0,void 0,void 0,t.getContractWithFetcher(I.ContractType.HinkalHelperContract),i),y=await q.transactCallDirect(t,e,s,m,x,g,c,A),D=U.constructAdminData(M.AdminTransactionType.Onboarding,t.getCurrentChainId(),o,e,await t.getEthereumAddress());return S.emitTxPublicData(t.getCurrentChainId(),D),y},b=async(t,s,e,o)=>{const r=s.map(u=>u.erc20TokenAddress),[A,c,l]=o.split(",");if(!_.isValidPrivateAddress(o))throw Error(F.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);const i=r.map(u=>[new C.Utxo({amount:0n,erc20TokenAddress:u,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()}),new C.Utxo({amount:0n,erc20TokenAddress:u,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()})]),n=`swapperM${e.length.toString()}x${i[0].length}x1`,p=r.map((u,E)=>[new C.Utxo({amount:e[E],erc20TokenAddress:u,randomization:BigInt(A),stealthAddress:c,encryptionKey:l})]),{externalActionData:d,contractTransaction:T,contractToApprove:m,patchAccessTokenMerkleTree:x}=await K(t,r,e),{zkCallData:g,circomData:y,dimData:D}=await w.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,i,p,t.userKeys,n,d.externalActionId,d.externalAddress,d.externalActionMetadata,t.generateProofRemotely,P.zeroAddress,t.getCurrentChainId(),void 0,void 0,void 0,x,void 0,void 0,void 0,t.getContractWithFetcher(I.ContractType.HinkalHelperContract)),a=await q.transactCallDirect(t,e,s,g,y,D,m,T),v=U.constructAdminData(M.AdminTransactionType.PaymentLink,t.getCurrentChainId(),r,e,await t.getEthereumAddress());return S.emitTxPublicData(t.getCurrentChainId(),v),a};exports.hinkalDeposit=O;exports.hinkalDepositForOther=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../constants/protocol.constants.cjs"),h=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),q=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),F=require("../../functions/web3/events/getShieldedBalance.cjs"),I=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),P=require("../utxo/Utxo.cjs"),R=require("../../error-handling/error-codes.constants.cjs");require("../../types/circom-data.types.cjs");const M=require("../../types/ethereum-network.types.cjs"),S=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const _=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),z=require("../../functions/utils/addresses.cjs"),H=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),O=require("../../functions/utils/time.utils.cjs"),U=require("../../API/admin-calls.cjs"),K=require("../../functions/pre-transaction/constructAdminData.cjs"),E=async(t,s,e)=>{const{patchAccessTokenMerkleTree:n,kycRequired:o,hasAccessToken:r}=await H.shouldPatchAccessTokenMerkleTree(t,s,e),c=void 0,A=await t.getEthereumAddress(),l=await _.getSignatureDataForTransact(t.getCurrentChainId(),A,t.userKeys,o,r),i={externalActionId:0n,externalAddress:await t.getEthereumAddress(),externalActionMetadata:"0x00"};return{signatureData:l,externalActionData:i,contractTransaction:c,contractToApprove:c,patchAccessTokenMerkleTree:n}},b=async(t,s,e,n=!0)=>{const o=s.map(a=>a.erc20TokenAddress),{externalActionData:r,contractTransaction:c,contractToApprove:A,patchAccessTokenMerkleTree:l,signatureData:i}=await E(t,o,e),p=[...await F.addPaddingToUtxos(t,o,e)],T=`swapperM${e.length.toString()}x${p[0].length}x1`,d=[],m=O.getCurrentTimeInSeconds().toString();for(let a=0;a<o.length;a+=1){const{outputUtxos:C}=h.outputUtxoProcessing(t.userKeys,p[a],e[a],m);d.push(C)}const{zkCallData:x,circomData:g,dimData:y}=await q.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,p,d,t.userKeys,T,r.externalActionId,r.externalAddress,r.externalActionMetadata,t.generateProofRemotely,w.zeroAddress,t.getCurrentChainId(),void 0,void 0,void 0,l,void 0,void 0,void 0,t.getContractWithFetcher(M.ContractType.HinkalHelperContract),i),D=await I.transactCallDirect(t,e,s,x,g,y,A,c,n),v=K.constructAdminData(S.AdminTransactionType.Onboarding,t.getCurrentChainId(),o,e,await t.getEthereumAddress());return U.emitTxPublicData(t.getCurrentChainId(),v),D},N=async(t,s,e,n,o=!0)=>{const r=s.map(u=>u.erc20TokenAddress),[c,A,l]=n.split(",");if(!z.isValidPrivateAddress(n))throw Error(R.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);const i=r.map(u=>[new P.Utxo({amount:0n,erc20TokenAddress:u,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()}),new P.Utxo({amount:0n,erc20TokenAddress:u,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()})]),p=`swapperM${e.length.toString()}x${i[0].length}x1`,T=r.map((u,f)=>[new P.Utxo({amount:e[f],erc20TokenAddress:u,randomization:BigInt(c),stealthAddress:A,encryptionKey:l})]),{externalActionData:d,contractTransaction:m,contractToApprove:x,patchAccessTokenMerkleTree:g}=await E(t,r,e),{zkCallData:y,circomData:D,dimData:v}=await q.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,i,T,t.userKeys,p,d.externalActionId,d.externalAddress,d.externalActionMetadata,t.generateProofRemotely,w.zeroAddress,t.getCurrentChainId(),void 0,void 0,void 0,g,void 0,void 0,void 0,t.getContractWithFetcher(M.ContractType.HinkalHelperContract)),a=await I.transactCallDirect(t,e,s,y,D,v,x,m,o),C=K.constructAdminData(S.AdminTransactionType.PaymentLink,t.getCurrentChainId(),r,e,await t.getEthereumAddress());return U.emitTxPublicData(t.getCurrentChainId(),C),a};exports.hinkalDeposit=b;exports.hinkalDepositForOther=N;
@@ -1,4 +1,4 @@
1
1
  import { IHinkal } from './IHinkal';
2
2
  import { ERC20Token } from '../../types';
3
- export declare const hinkalDeposit: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[]) => Promise<any>;
4
- export declare const hinkalDepositForOther: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], recipinetInfo: string) => Promise<any>;
3
+ export declare const hinkalDeposit: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean) => Promise<any>;
4
+ export declare const hinkalDepositForOther: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], recipinetInfo: string, preEstimateGas?: boolean) => Promise<any>;
@@ -1,62 +1,62 @@
1
- import { zeroAddress as D } from "../../constants/protocol.constants.mjs";
2
- import { outputUtxoProcessing as R } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
3
- import { constructZkProof as C } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
4
- import { addPaddingToUtxos as H } from "../../functions/web3/events/getShieldedBalance.mjs";
5
- import { transactCallDirect as P } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
6
- import { Utxo as w } from "../utxo/Utxo.mjs";
7
- import { transactionErrorCodes as z } from "../../error-handling/error-codes.constants.mjs";
1
+ import { zeroAddress as C } from "../../constants/protocol.constants.mjs";
2
+ import { outputUtxoProcessing as H } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
3
+ import { constructZkProof as P } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
4
+ import { addPaddingToUtxos as z } from "../../functions/web3/events/getShieldedBalance.mjs";
5
+ import { transactCallDirect as I } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
6
+ import { Utxo as D } from "../utxo/Utxo.mjs";
7
+ import { transactionErrorCodes as F } from "../../error-handling/error-codes.constants.mjs";
8
8
  import "../../types/circom-data.types.mjs";
9
- import { ContractType as I } from "../../types/ethereum-network.types.mjs";
10
- import { AdminTransactionType as K } from "../../types/admin.types.mjs";
9
+ import { ContractType as K } from "../../types/ethereum-network.types.mjs";
10
+ import { AdminTransactionType as M } from "../../types/admin.types.mjs";
11
11
  import "../../types/activities.types.mjs";
12
- import { getSignatureDataForTransact as F } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
13
- import { isValidPrivateAddress as N } from "../../functions/utils/addresses.mjs";
14
- import { shouldPatchAccessTokenMerkleTree as O } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
- import { getCurrentTimeInSeconds as $ } from "../../functions/utils/time.utils.mjs";
16
- import { emitTxPublicData as M } from "../../API/admin-calls.mjs";
17
- import { constructAdminData as E } from "../../functions/pre-transaction/constructAdminData.mjs";
18
- const S = async (t, s, e) => {
19
- const { patchAccessTokenMerkleTree: o, kycRequired: r, hasAccessToken: p } = await O(
12
+ import { getSignatureDataForTransact as N } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
13
+ import { isValidPrivateAddress as O } from "../../functions/utils/addresses.mjs";
14
+ import { shouldPatchAccessTokenMerkleTree as $ } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
+ import { getCurrentTimeInSeconds as b } from "../../functions/utils/time.utils.mjs";
16
+ import { emitTxPublicData as E } from "../../API/admin-calls.mjs";
17
+ import { constructAdminData as S } from "../../functions/pre-transaction/constructAdminData.mjs";
18
+ const U = async (t, s, e) => {
19
+ const { patchAccessTokenMerkleTree: n, kycRequired: o, hasAccessToken: r } = await $(
20
20
  t,
21
21
  s,
22
22
  e
23
- ), c = void 0, A = await t.getEthereumAddress(), i = await F(
23
+ ), c = void 0, p = await t.getEthereumAddress(), A = await N(
24
24
  t.getCurrentChainId(),
25
- A,
25
+ p,
26
26
  t.userKeys,
27
- r,
28
- p
29
- ), n = {
27
+ o,
28
+ r
29
+ ), i = {
30
30
  externalActionId: 0n,
31
31
  externalAddress: await t.getEthereumAddress(),
32
32
  externalActionMetadata: "0x00"
33
33
  };
34
34
  return {
35
- signatureData: i,
36
- externalActionData: n,
35
+ signatureData: A,
36
+ externalActionData: i,
37
37
  contractTransaction: c,
38
38
  contractToApprove: c,
39
- patchAccessTokenMerkleTree: o
39
+ patchAccessTokenMerkleTree: n
40
40
  };
41
- }, et = async (t, s, e) => {
42
- const o = s.map((a) => a.erc20TokenAddress), { externalActionData: r, contractTransaction: p, contractToApprove: c, patchAccessTokenMerkleTree: A, signatureData: i } = await S(t, o, e), n = [...await H(t, o, e)], u = `swapperM${e.length.toString()}x${n[0].length}x1`, d = [], x = $().toString();
41
+ }, rt = async (t, s, e, n = !0) => {
42
+ const o = s.map((a) => a.erc20TokenAddress), { externalActionData: r, contractTransaction: c, contractToApprove: p, patchAccessTokenMerkleTree: A, signatureData: i } = await U(t, o, e), u = [...await z(t, o, e)], x = `swapperM${e.length.toString()}x${u[0].length}x1`, d = [], T = b().toString();
43
43
  for (let a = 0; a < o.length; a += 1) {
44
- const { outputUtxos: f } = R(t.userKeys, n[a], e[a], x);
45
- d.push(f);
44
+ const { outputUtxos: w } = H(t.userKeys, u[a], e[a], T);
45
+ d.push(w);
46
46
  }
47
- const { zkCallData: T, circomData: g, dimData: y } = await C(
47
+ const { zkCallData: g, circomData: y, dimData: l } = await P(
48
48
  "v1x1",
49
49
  t.merkleTreeHinkal,
50
50
  t.merkleTreeAccessToken,
51
- n,
51
+ u,
52
52
  d,
53
53
  t.userKeys,
54
- u,
54
+ x,
55
55
  r.externalActionId,
56
56
  r.externalAddress,
57
57
  r.externalActionMetadata,
58
58
  t.generateProofRemotely,
59
- D,
59
+ C,
60
60
  t.getCurrentChainId(),
61
61
  void 0,
62
62
  void 0,
@@ -65,82 +65,84 @@ const S = async (t, s, e) => {
65
65
  void 0,
66
66
  void 0,
67
67
  void 0,
68
- t.getContractWithFetcher(I.HinkalHelperContract),
68
+ t.getContractWithFetcher(K.HinkalHelperContract),
69
69
  i
70
- ), l = await P(
70
+ ), v = await I(
71
71
  t,
72
72
  e,
73
73
  // for volotile tokens: amountChanges != amountOfTokenToApprove
74
74
  s,
75
- T,
76
75
  g,
77
76
  y,
77
+ l,
78
+ p,
78
79
  c,
79
- p
80
- ), v = E(
81
- K.Onboarding,
80
+ n
81
+ ), f = S(
82
+ M.Onboarding,
82
83
  t.getCurrentChainId(),
83
84
  o,
84
85
  e,
85
86
  await t.getEthereumAddress()
86
87
  );
87
- return M(t.getCurrentChainId(), v), l;
88
- }, rt = async (t, s, e, o) => {
89
- const r = s.map((m) => m.erc20TokenAddress), [p, c, A] = o.split(",");
90
- if (!N(o))
91
- throw Error(z.RECIPIENT_FORMAT_INCORRECT);
88
+ return E(t.getCurrentChainId(), f), v;
89
+ }, ot = async (t, s, e, n, o = !0) => {
90
+ const r = s.map((m) => m.erc20TokenAddress), [c, p, A] = n.split(",");
91
+ if (!O(n))
92
+ throw Error(F.RECIPIENT_FORMAT_INCORRECT);
92
93
  const i = r.map((m) => [
93
- new w({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() }),
94
- new w({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() })
95
- ]), n = `swapperM${e.length.toString()}x${i[0].length}x1`, u = r.map((m, U) => [
96
- new w({
97
- amount: e[U],
94
+ new D({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() }),
95
+ new D({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() })
96
+ ]), u = `swapperM${e.length.toString()}x${i[0].length}x1`, x = r.map((m, R) => [
97
+ new D({
98
+ amount: e[R],
98
99
  erc20TokenAddress: m,
99
- randomization: BigInt(p),
100
- stealthAddress: c,
100
+ randomization: BigInt(c),
101
+ stealthAddress: p,
101
102
  encryptionKey: A
102
103
  })
103
- ]), { externalActionData: d, contractTransaction: x, contractToApprove: T, patchAccessTokenMerkleTree: g } = await S(t, r, e), { zkCallData: y, circomData: l, dimData: v } = await C(
104
+ ]), { externalActionData: d, contractTransaction: T, contractToApprove: g, patchAccessTokenMerkleTree: y } = await U(t, r, e), { zkCallData: l, circomData: v, dimData: f } = await P(
104
105
  "v1x1",
105
106
  t.merkleTreeHinkal,
106
107
  t.merkleTreeAccessToken,
107
108
  i,
108
- u,
109
+ x,
109
110
  t.userKeys,
110
- n,
111
+ u,
111
112
  d.externalActionId,
112
113
  d.externalAddress,
113
114
  d.externalActionMetadata,
114
115
  t.generateProofRemotely,
115
- D,
116
+ C,
116
117
  t.getCurrentChainId(),
117
118
  void 0,
118
119
  void 0,
119
120
  void 0,
120
- g,
121
+ y,
121
122
  void 0,
122
123
  void 0,
123
124
  void 0,
124
- t.getContractWithFetcher(I.HinkalHelperContract)
125
- ), a = await P(
125
+ t.getContractWithFetcher(K.HinkalHelperContract)
126
+ ), a = await I(
126
127
  t,
127
128
  e,
128
129
  s,
129
- y,
130
130
  l,
131
131
  v,
132
+ f,
133
+ g,
132
134
  T,
133
- x
134
- ), f = E(
135
- K.PaymentLink,
135
+ o
136
+ ), w = S(
137
+ M.PaymentLink,
136
138
  t.getCurrentChainId(),
137
139
  r,
138
140
  e,
139
141
  await t.getEthereumAddress()
140
142
  );
141
- return M(t.getCurrentChainId(), f), a;
143
+ return E(t.getCurrentChainId(), w), a;
142
144
  };
143
145
  export {
144
- et as hinkalDeposit,
145
- rt as hinkalDepositForOther
146
+ rt as hinkalDeposit,
147
+ ot as hinkalDepositForOther
146
148
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../constants/protocol.constants.cjs"),F=require("../../error-handling/error-codes.constants.cjs"),O=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),K=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),L=require("../../types/external-action.types.cjs"),z=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const B=require("../../types/ethereum-network.types.cjs"),N=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const D=require("../../types/scheduled-transactions.types.cjs"),Z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),G=require("../../functions/utils/time.utils.cjs"),V=require("../../functions/pre-transaction/getFeeStructure.cjs"),Y=require("../../functions/utils/addresses.cjs"),$=require("./hinkalDepositOnChainUtxos.cjs"),J=require("../../functions/pre-transaction/constructAdminData.cjs"),q=require("../../API/deposit-and-withdraw-status-calls.cjs"),Q=async(e,t,r,w,a,c,A,i)=>{if(r.length===0)throw new Error("userDepositedUtxos must not be empty");const s=t.erc20TokenAddress,n=await e.getRandomRelay();if(!n)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=await e.getEthereumAddress(),l=G.getCurrentTimeInSeconds().toString(),d=e.generateProofRemotely?5:1,u=[];for(let h=0;h<r.length;h+=d){const x=r.slice(h,h+d),S=await Promise.all(x.map(async({recipientAddress:I,utxo:p})=>{const E=[-p.amount],T=new z.Utxo({amount:0n,erc20TokenAddress:s,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:l,tokenId:0}),y=[[p,T]],R=[[T]],P=`swapperM1x${y[0].length}x1`,m={externalActionId:0n,externalAddress:I,externalActionMetadata:"0x00"},{patchAccessTokenMerkleTree:_,kycRequired:f,hasAccessToken:U}=await j.shouldPatchAccessTokenMerkleTree(e,[s],E),W=await Z.getSignatureDataForTransact(e.getCurrentChainId(),o,e.userKeys,f,U),k=J.constructAdminData(N.AdminTransactionType.WithdrawOnChainUtxos,e.getCurrentChainId(),[s],[-p.amount],o),{zkCallData:v,circomData:H,dimData:M}=await O.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,y,R,e.userKeys,P,m.externalActionId,m.externalAddress,m.externalActionMetadata,e.generateProofRemotely,n??b.zeroAddress,e.getCurrentChainId(),void 0,void 0,void 0,_,void 0,void 0,w,e.getContractWithFetcher(B.ContractType.HinkalHelperContract),W,void 0,!1);return{zkCallData:v,dimData:M,circomData:H,adminData:k}}));u.push(...S)}const C=e.getCurrentChainId();await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:a,phase:D.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await K.transactCallRelayerBatch(e.getCurrentChainId(),u,a,A,i);return await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:a,phase:D.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},X=async(e,t,r,w,a,c,A)=>{const i=t.erc20TokenAddress,s=e.getCurrentChainId(),n=Y.hashEthereumAddress(await e.getEthereumAddress()),o=c??await V.getFeeStructure(s,i,[i],L.ExternalActionId.Transact),{userDepositedUtxos:l,statusId:d,depositTxHash:u}=await $.hinkalDepositOnChainUtxos(e,t,r,w,o,n);return await Q(e,t,l,o,n,d,a,A),u};exports.hinkalDepositAndWithdraw=X;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../constants/protocol.constants.cjs"),F=require("../../error-handling/error-codes.constants.cjs"),O=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),K=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),L=require("../../types/external-action.types.cjs"),z=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const B=require("../../types/ethereum-network.types.cjs"),N=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const D=require("../../types/scheduled-transactions.types.cjs"),Z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),G=require("../../functions/utils/time.utils.cjs"),V=require("../../functions/pre-transaction/getFeeStructure.cjs"),Y=require("../../functions/utils/addresses.cjs"),$=require("./hinkalDepositOnChainUtxos.cjs"),J=require("../../functions/pre-transaction/constructAdminData.cjs"),q=require("../../API/deposit-and-withdraw-status-calls.cjs"),Q=async(e,r,a,A,s,o,l,p)=>{if(a.length===0)throw new Error("userDepositedUtxos must not be empty");const t=r.erc20TokenAddress,c=await e.getRandomRelay();if(!c)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const n=await e.getEthereumAddress(),i=G.getCurrentTimeInSeconds().toString(),d=e.generateProofRemotely?5:1,u=[];for(let w=0;w<a.length;w+=d){const x=a.slice(w,w+d),S=await Promise.all(x.map(async({recipientAddress:I,utxo:m})=>{const E=[-m.amount],T=new z.Utxo({amount:0n,erc20TokenAddress:t,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:i,tokenId:0}),y=[[m,T]],R=[[T]],P=`swapperM1x${y[0].length}x1`,C={externalActionId:0n,externalAddress:I,externalActionMetadata:"0x00"},{patchAccessTokenMerkleTree:_,kycRequired:f,hasAccessToken:U}=await j.shouldPatchAccessTokenMerkleTree(e,[t],E),W=await Z.getSignatureDataForTransact(e.getCurrentChainId(),n,e.userKeys,f,U),k=J.constructAdminData(N.AdminTransactionType.WithdrawOnChainUtxos,e.getCurrentChainId(),[t],[-m.amount],n),{zkCallData:v,circomData:H,dimData:M}=await O.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,y,R,e.userKeys,P,C.externalActionId,C.externalAddress,C.externalActionMetadata,e.generateProofRemotely,c??b.zeroAddress,e.getCurrentChainId(),void 0,void 0,void 0,_,void 0,void 0,A,e.getContractWithFetcher(B.ContractType.HinkalHelperContract),W,void 0,!1);return{zkCallData:v,dimData:M,circomData:H,adminData:k}}));u.push(...S)}const h=e.getCurrentChainId();await q.safeUpdateDepositAndWithdrawStatus(h,{id:o,hashedEthereumAddress:s,phase:D.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await K.transactCallRelayerBatch(e.getCurrentChainId(),u,s,l,p);return await q.safeUpdateDepositAndWithdrawStatus(h,{id:o,hashedEthereumAddress:s,phase:D.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},X=async(e,r,a,A,s,o,l,p=!0)=>{const t=r.erc20TokenAddress,c=e.getCurrentChainId(),n=Y.hashEthereumAddress(await e.getEthereumAddress()),i=o??await V.getFeeStructure(c,t,[t],L.ExternalActionId.Transact),{userDepositedUtxos:d,statusId:u,depositTxHash:h}=await $.hinkalDepositOnChainUtxos(e,r,a,A,i,n,p);return await Q(e,r,d,i,n,u,s,l),h};exports.hinkalDepositAndWithdraw=X;
@@ -1,4 +1,4 @@
1
1
  import { IHinkal } from './IHinkal';
2
2
  import { ERC20Token } from '../../types';
3
3
  import { FeeStructure } from '../../types/hinkal.types';
4
- export declare const hinkalDepositAndWithdraw: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string) => Promise<string>;
4
+ export declare const hinkalDepositAndWithdraw: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean) => Promise<string>;
@@ -17,23 +17,23 @@ import { hashEthereumAddress as j } from "../../functions/utils/addresses.mjs";
17
17
  import { hinkalDepositOnChainUtxos as G } from "./hinkalDepositOnChainUtxos.mjs";
18
18
  import { constructAdminData as J } from "../../functions/pre-transaction/constructAdminData.mjs";
19
19
  import { safeUpdateDepositAndWithdrawStatus as x } from "../../API/deposit-and-withdraw-status-calls.mjs";
20
- const Q = async (t, e, r, u, o, i, w, c) => {
21
- if (r.length === 0)
20
+ const Q = async (t, r, o, w, a, n, h, A) => {
21
+ if (o.length === 0)
22
22
  throw new Error("userDepositedUtxos must not be empty");
23
- const a = e.erc20TokenAddress, s = await t.getRandomRelay();
24
- if (!s)
23
+ const e = r.erc20TokenAddress, i = await t.getRandomRelay();
24
+ if (!i)
25
25
  throw Error(F.RELAYER_NOT_AVAILABLE);
26
- const n = await t.getEthereumAddress(), h = Z().toString(), d = t.generateProofRemotely ? 5 : 1, m = [];
27
- for (let p = 0; p < r.length; p += d) {
28
- const I = r.slice(p, p + d), E = await Promise.all(
29
- I.map(async ({ recipientAddress: D, utxo: A }) => {
30
- const R = [-A.amount], l = new B({
26
+ const s = await t.getEthereumAddress(), c = Z().toString(), d = t.generateProofRemotely ? 5 : 1, m = [];
27
+ for (let u = 0; u < o.length; u += d) {
28
+ const I = o.slice(u, u + d), E = await Promise.all(
29
+ I.map(async ({ recipientAddress: D, utxo: f }) => {
30
+ const R = [-f.amount], l = new B({
31
31
  amount: 0n,
32
- erc20TokenAddress: a,
32
+ erc20TokenAddress: e,
33
33
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
34
- timeStamp: h,
34
+ timeStamp: c,
35
35
  tokenId: 0
36
- }), T = [[A, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`, f = {
36
+ }), T = [[f, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`, C = {
37
37
  externalActionId: 0n,
38
38
  externalAddress: D,
39
39
  externalActionMetadata: "0x00"
@@ -41,18 +41,18 @@ const Q = async (t, e, r, u, o, i, w, c) => {
41
41
  patchAccessTokenMerkleTree: H,
42
42
  kycRequired: P,
43
43
  hasAccessToken: U
44
- } = await Y(t, [a], R), W = await V(
44
+ } = await Y(t, [e], R), W = await V(
45
45
  t.getCurrentChainId(),
46
- n,
46
+ s,
47
47
  t.userKeys,
48
48
  P,
49
49
  U
50
50
  ), K = J(
51
51
  N.WithdrawOnChainUtxos,
52
52
  t.getCurrentChainId(),
53
- [a],
54
- [-A.amount],
55
- n
53
+ [e],
54
+ [-f.amount],
55
+ s
56
56
  ), { zkCallData: M, circomData: _, dimData: b } = await L(
57
57
  "v1x1",
58
58
  t.merkleTreeHinkal,
@@ -61,11 +61,11 @@ const Q = async (t, e, r, u, o, i, w, c) => {
61
61
  S,
62
62
  t.userKeys,
63
63
  v,
64
- f.externalActionId,
65
- f.externalAddress,
66
- f.externalActionMetadata,
64
+ C.externalActionId,
65
+ C.externalAddress,
66
+ C.externalActionMetadata,
67
67
  t.generateProofRemotely,
68
- s ?? k,
68
+ i ?? k,
69
69
  t.getCurrentChainId(),
70
70
  void 0,
71
71
  void 0,
@@ -73,7 +73,7 @@ const Q = async (t, e, r, u, o, i, w, c) => {
73
73
  H,
74
74
  void 0,
75
75
  void 0,
76
- u,
76
+ w,
77
77
  t.getContractWithFetcher(q.HinkalHelperContract),
78
78
  W,
79
79
  void 0,
@@ -89,44 +89,45 @@ const Q = async (t, e, r, u, o, i, w, c) => {
89
89
  );
90
90
  m.push(...E);
91
91
  }
92
- const C = t.getCurrentChainId();
93
- await x(C, {
94
- id: i,
95
- hashedEthereumAddress: o,
92
+ const p = t.getCurrentChainId();
93
+ await x(p, {
94
+ id: n,
95
+ hashedEthereumAddress: a,
96
96
  phase: y.BEFORE_SCHEDULE_WITHDRAW
97
97
  });
98
98
  const g = await O(
99
99
  t.getCurrentChainId(),
100
100
  m,
101
- o,
102
- w,
103
- c
101
+ a,
102
+ h,
103
+ A
104
104
  );
105
- return await x(C, {
106
- id: i,
107
- hashedEthereumAddress: o,
105
+ return await x(p, {
106
+ id: n,
107
+ hashedEthereumAddress: a,
108
108
  phase: y.AFTER_SCHEDULE_WITHDRAW,
109
109
  scheduleId: g
110
110
  }), g;
111
- }, gt = async (t, e, r, u, o, i, w) => {
112
- const c = e.erc20TokenAddress, a = t.getCurrentChainId(), s = j(await t.getEthereumAddress()), n = i ?? await $(a, c, [c], z.Transact), { userDepositedUtxos: h, statusId: d, depositTxHash: m } = await G(
111
+ }, gt = async (t, r, o, w, a, n, h, A = !0) => {
112
+ const e = r.erc20TokenAddress, i = t.getCurrentChainId(), s = j(await t.getEthereumAddress()), c = n ?? await $(i, e, [e], z.Transact), { userDepositedUtxos: d, statusId: m, depositTxHash: p } = await G(
113
113
  t,
114
- e,
115
114
  r,
116
- u,
117
- n,
118
- s
115
+ o,
116
+ w,
117
+ c,
118
+ s,
119
+ A
119
120
  );
120
121
  return await Q(
121
122
  t,
122
- e,
123
- h,
124
- n,
125
- s,
123
+ r,
126
124
  d,
127
- o,
128
- w
129
- ), m;
125
+ c,
126
+ s,
127
+ m,
128
+ a,
129
+ h
130
+ ), p;
130
131
  };
131
132
  export {
132
133
  gt as hinkalDepositAndWithdraw