@hinkal/common 0.2.26 → 0.2.27

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
@@ -12,10 +12,12 @@ With Hinkal SDK, developers can:
12
12
 
13
13
  ## Compatibility
14
14
 
15
+
15
16
  | Environment | Supported | Notes |
16
17
  | ----------- | --------- | -------------------------- |
17
- | Node.js | ✅ | v18+ |
18
- | Browser | ✅ | React, Next.js, vanilla JS |
18
+ | Node.js | ✅ | v18+ |
19
+ | Browser | ✅ | React, Next.js, vanilla JS |
20
+
19
21
 
20
22
  ## Installation
21
23
 
@@ -100,7 +102,7 @@ Shielding is the process of moving your tokens from a public blockchain address
100
102
  A user can deposit funds to their shielded address using:
101
103
 
102
104
  ```typescript
103
- function deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean): Promise<ethers.providers.TransactionResponse>;
105
+ function deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean, returnTxData?: boolean ): Promise<ethers.ContractTransaction | ethers.TransactionRequest >;
104
106
  ```
105
107
 
106
108
  where:
@@ -108,6 +110,7 @@ where:
108
110
  - `erc20Tokens` is an array of tokens to deposit
109
111
  - `amountChanges` represents the corresponding token amounts for the deposit
110
112
  - `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.
113
+ - `returnTxData` If true, returns unsigned transaction data without executing. Defaults to false.
111
114
 
112
115
  The `ERC20Token` type is defined as follows:
113
116
 
@@ -272,12 +275,12 @@ function emporiumOp(
272
275
 
273
276
  The function accepts the following arguments:
274
277
 
275
- 1. `contract` _(required)_ - target address or contract instance (with address). The contract instance will be used to properly encode the call function, if any, in the custom operation.
276
- 2. `func` _(optional)_ - the name of the function to be called on the target address.
277
- 3. `args` _(optional)_ - arguments of the function to be called on the target address.
278
- 4. `callDataString` _(optional)_ - pre-encoded calldata string. If provided, `func` and `args` should not be used.
279
- 5. `invokeWallet` _(optional)_ - boolean flag that determines the type of interaction (see the stateless/stateful interactions below).
280
- 6. `value` _(optional)_ - the value field to the user operation call.
278
+ 1. `contract` *(required)* - target address or contract instance (with address). The contract instance will be used to properly encode the call function, if any, in the custom operation.
279
+ 2. `func` *(optional)* - the name of the function to be called on the target address.
280
+ 3. `args` *(optional)* - arguments of the function to be called on the target address.
281
+ 4. `callDataString` *(optional)* - pre-encoded calldata string. If provided, `func` and `args` should not be used.
282
+ 5. `invokeWallet` *(optional)* - boolean flag that determines the type of interaction (see the stateless/stateful interactions below).
283
+ 6. `value` *(optional)* - the value field to the user operation call.
281
284
 
282
285
  When the Emporium contract executes a user operation, it receives the data in this format:
283
286
 
@@ -358,15 +361,17 @@ After passing the compliance check with one of the supported providers, the acce
358
361
 
359
362
  Hinkal SDK is available on the following blockchain networks:
360
363
 
364
+
361
365
  | Chain | Chain ID | Status |
362
366
  | -------- | -------- | -------------- |
363
- | Ethereum | 1 | ✅ Live |
364
- | Polygon | 137 | ✅ Live |
365
- | Base | 8453 | ✅ Live |
366
- | Arbitrum | 42161 | ✅ Live |
367
- | Optimism | 10 | ✅ Live |
367
+ | Ethereum | 1 | ✅ Live |
368
+ | Polygon | 137 | ✅ Live |
369
+ | Base | 8453 | ✅ Live |
370
+ | Arbitrum | 42161 | ✅ Live |
371
+ | Optimism | 10 | ✅ Live |
368
372
  | Solana | - | 🚧 In Progress |
369
373
 
374
+
370
375
  Each chain supports the full suite of Hinkal privacy features including shielding, transfers, and confidential interactions with DeFi protocols.
371
376
 
372
377
  ## References
@@ -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,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;
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 ae=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 ne=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,a=!1,n,s=!1){return W.getShieldedBalance(this,e,t,r,i,a,this.generateProofRemotely,n,s)}async getApprovedBalances(e=!1,t=!1){return v.getApprovedBalance(this,e,t)}async getTotalBalance(e,t,r,i=!1,a,n=!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,a,n),p=!h.isSolanaLike(s)&&!n?await this.getApprovedBalances(i,a):new Map,d=_.isExtension?await ie.privateTokensDB.getPrivateTokens(s,o):ae.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(a=>a.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:a}=h.networkRegistry[e].contractData;if(!r||!i||!a)throw new Error(`Missing Solana configuration for chain ${e}`);const n=new g.PublicKey(a),s=new g.PublicKey(i),o=E.getMerkleAccountPublicKey(s,n),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:a}=h.networkRegistry[e].contractData;if(!r||!i||!a)throw new Error(`Missing Solana configuration for chain ${e}`);const n=new g.PublicKey(a),s=new g.PublicKey(i),o=E.getAccessTokenMerkleAccountPublicKey(s,n),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:a,hinkalAddress:n,originalDeployer:s}=h.networkRegistry[r].contractData;if(!a||!n||!s)throw new Error("missing solana data");const o=this.getSolanaProgram(a),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,i=!1){return I.hinkalDeposit(this,e,t,r,i)}async depositForOther(e,t,r,i=!0,a=!1){return I.hinkalDepositForOther(this,e,t,r,i,a)}async depositAndWithdraw(e,t,r,i,a,n,s=!0){return h.isSolanaLike(this.getCurrentChainId())?de.hinkalSolanaDepositAndWithdraw(this,e.erc20TokenAddress,t,r,i,a,n):B.hinkalDepositAndWithdraw(this,e,t,r,i,a,n,s)}async depositAndBridge(e,t,r,i,a,n=!0){return ye.hinkalDepositAndBridge(this,e,t,r,i,a,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,a,n,s=!1){return h.isSolanaLike(this.getCurrentChainId())?ue.hinkalSolanaTransfer(this,e,t,r,i,a,s):he.hinkalTransfer(this,e,t,r,i,a,n,s)}async withdraw(e,t,r,i,a,n,s,o=!1){return h.isSolanaLike(this.getCurrentChainId())?pe.hinkalSolanaWithdraw(this,e.map(c=>c.erc20TokenAddress),t,r,a,n,o):U.hinkalWithdraw(this,e,t,r,i,a,n,s,o)}async withdrawStuckUtxos(e,t){return L.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,r,i,a,n,s,o=!1,c=!1){return h.isSolanaLike(this.getCurrentChainId())?this.swapSolana(e,t,i,a,n,o):K.hinkalSwap(this,e,t,r,i,a,n,s,o,c)}async swapSolana(e,t,r,i,a,n=!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,a,n)}async actionReceive(e,t,r,i,a,n,s=!1){if(!a)throw new Error("subAccount is required");return h.isSolanaLike(this.getCurrentChainId())?D.hinkalSolanaProxyShield(this,e[0],t[0],a,void 0,s):te.hinkalActionReceive(this,e,t,r,i,a,n,s)}async actionFundApproveAndTransact(e,t,r,i,a,n,s,o,c=!1,l,p,d){return re.hinkalActionFundApproveAndTransact(this,e,t,r,i,a,n,s,o,c,l,p,d)}async actionPrivateWallet(e,t,r,i,a,n,s,o,c,l=!1,p,d,u,k=!1){return $.hinkalPrivateWallet(this,e,t,r,i,a,n,s,o,c,l,p,d,u,k)}async approve(e,t,r,i,a,n=!1){return Y.hinkalApprove(this,e,t,r,i,a,n)}async hinkalInsideTransact(e,t,r,i,a,n,s,o,c,l=!1){return Z.hinkalInsideTransact(this,e,t,r,i,a,n,s,o,c,l)}async proxySwap(e,t,r,i,a,n,s,o,c=!1,l,p,d=!1){return h.isSolanaLike(this.getCurrentChainId())?ve.hinkalSolanaProxySwap(this,e,t,i,n,s,o,d):oe.hinkalProxySwap(this,e,t,r,i,a,n,s,o,c,l,p,d)}async proxyToPrivate(e,t,r,i,a,n,s,o=!1){return h.isSolanaLike(this.getCurrentChainId())?D.hinkalSolanaProxyShield(this,e[0],t[0],r,i,o):le.hinkalProxyToPrivate(this,e,t,i,a,n,r,s,o)}async proxySend(e,t,r,i,a,n,s,o=!1){if(h.isSolanaLike(this.getCurrentChainId()))return ke.hinkalSolanaProxySend(this,e[0],t[0],r,i,o);const c=ne.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,a,n,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,8 +92,8 @@ 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[], preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
96
- depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recipientInfo: string, preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
95
+ deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean, returnTxData?: boolean): Promise<ethers.ContractTransaction | ethers.TransactionRequest>;
96
+ depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recipientInfo: string, preEstimateGas?: boolean, returnTxData?: boolean): Promise<ethers.ContractTransaction | ethers.TransactionRequest>;
97
97
  depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean): Promise<string>;
98
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>;
@@ -365,11 +365,11 @@ class cr {
365
365
  async getBufferEntry(e, t, r) {
366
366
  return se(this, e, t, r);
367
367
  }
368
- async deposit(e, t, r = !0) {
369
- return b(this, e, t, r);
368
+ async deposit(e, t, r = !0, i = !1) {
369
+ return b(this, e, t, r, i);
370
370
  }
371
- async depositForOther(e, t, r, i = !0) {
372
- return W(this, e, t, r, i);
371
+ async depositForOther(e, t, r, i = !0, a = !1) {
372
+ return W(this, e, t, r, i, a);
373
373
  }
374
374
  async depositAndWithdraw(e, t, r, i, a, n, o = !0) {
375
375
  return p(this.getCurrentChainId()) ? Se(
@@ -61,8 +61,8 @@ 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[], preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
65
- depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recepinetInfo: string, preEstimateGas?: boolean): Promise<ethers.ContractTransaction>;
64
+ deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean, returnTxData?: boolean): Promise<ethers.ContractTransaction | ethers.TransactionRequest>;
65
+ depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recepinetInfo: string, preEstimateGas?: boolean, returnTxData?: boolean): Promise<ethers.ContractTransaction | ethers.TransactionRequest>;
66
66
  depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean): Promise<string>;
67
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>;
@@ -1 +1 @@
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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("../../constants/protocol.constants.cjs"),F=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),I=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),R=require("../../functions/web3/events/getShieldedBalance.cjs"),M=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),w=require("../utxo/Utxo.cjs"),_=require("../../error-handling/error-codes.constants.cjs");require("../../types/circom-data.types.cjs");const S=require("../../types/ethereum-network.types.cjs"),U=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),H=require("../../functions/utils/addresses.cjs"),O=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),b=require("../../functions/utils/time.utils.cjs"),K=require("../../API/admin-calls.cjs"),f=require("../../functions/pre-transaction/constructAdminData.cjs"),E=async(t,s,e)=>{const{patchAccessTokenMerkleTree:n,kycRequired:d,hasAccessToken:o}=await O.shouldPatchAccessTokenMerkleTree(t,s,e),r=void 0,u=await t.getEthereumAddress(),A=await z.getSignatureDataForTransact(t.getCurrentChainId(),u,t.userKeys,d,o),l={externalActionId:0n,externalAddress:await t.getEthereumAddress(),externalActionMetadata:"0x00"};return{signatureData:A,externalActionData:l,contractTransaction:r,contractToApprove:r,patchAccessTokenMerkleTree:n}},N=async(t,s,e,n=!0,d=!1)=>{const o=s.map(a=>a.erc20TokenAddress),{externalActionData:r,contractTransaction:u,contractToApprove:A,patchAccessTokenMerkleTree:l,signatureData:T}=await E(t,o,e),p=[...await R.addPaddingToUtxos(t,o,e)],m=`swapperM${e.length.toString()}x${p[0].length}x1`,c=[],x=b.getCurrentTimeInSeconds().toString();for(let a=0;a<o.length;a+=1){const{outputUtxos:P}=F.outputUtxoProcessing(t.userKeys,p[a],e[a],x);c.push(P)}const{zkCallData:g,circomData:y,dimData:D}=await I.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,p,c,t.userKeys,m,r.externalActionId,r.externalAddress,r.externalActionMetadata,t.generateProofRemotely,q.zeroAddress,t.getCurrentChainId(),void 0,void 0,void 0,l,void 0,void 0,void 0,t.getContractWithFetcher(S.ContractType.HinkalHelperContract),T),v=await M.transactCallDirect(t,e,s,g,y,D,A,u,n,d),C=f.constructAdminData(U.AdminTransactionType.Onboarding,t.getCurrentChainId(),o,e,await t.getEthereumAddress());return K.emitTxPublicData(t.getCurrentChainId(),C),v},k=async(t,s,e,n,d=!0,o=!1)=>{const r=s.map(i=>i.erc20TokenAddress),[u,A,l]=n.split(",");if(!H.isValidPrivateAddress(n))throw Error(_.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);const T=r.map(i=>[new w.Utxo({amount:0n,erc20TokenAddress:i,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()}),new w.Utxo({amount:0n,erc20TokenAddress:i,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()})]),p=`swapperM${e.length.toString()}x${T[0].length}x1`,m=r.map((i,h)=>[new w.Utxo({amount:e[h],erc20TokenAddress:i,randomization:BigInt(u),stealthAddress:A,encryptionKey:l})]),{externalActionData:c,contractTransaction:x,contractToApprove:g,patchAccessTokenMerkleTree:y}=await E(t,r,e),{zkCallData:D,circomData:v,dimData:C}=await I.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,T,m,t.userKeys,p,c.externalActionId,c.externalAddress,c.externalActionMetadata,t.generateProofRemotely,q.zeroAddress,t.getCurrentChainId(),void 0,void 0,void 0,y,void 0,void 0,void 0,t.getContractWithFetcher(S.ContractType.HinkalHelperContract)),a=await M.transactCallDirect(t,e,s,D,v,C,g,x,d,o),P=f.constructAdminData(U.AdminTransactionType.PaymentLink,t.getCurrentChainId(),r,e,await t.getEthereumAddress());return K.emitTxPublicData(t.getCurrentChainId(),P),a};exports.hinkalDeposit=N;exports.hinkalDepositForOther=k;
@@ -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[], preEstimateGas?: boolean) => Promise<any>;
4
- export declare const hinkalDepositForOther: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], recipinetInfo: string, preEstimateGas?: boolean) => Promise<any>;
3
+ export declare const hinkalDeposit: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean, returnTxData?: boolean) => Promise<any>;
4
+ export declare const hinkalDepositForOther: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], recipinetInfo: string, preEstimateGas?: boolean, returnTxData?: boolean) => Promise<any>;
@@ -1,62 +1,62 @@
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";
1
+ import { zeroAddress as P } from "../../constants/protocol.constants.mjs";
2
+ import { outputUtxoProcessing as z } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
3
+ import { constructZkProof as I } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
4
+ import { addPaddingToUtxos as F } from "../../functions/web3/events/getShieldedBalance.mjs";
5
+ import { transactCallDirect as K } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
6
+ import { Utxo as C } from "../utxo/Utxo.mjs";
7
+ import { transactionErrorCodes as N } from "../../error-handling/error-codes.constants.mjs";
8
8
  import "../../types/circom-data.types.mjs";
9
- import { ContractType as K } from "../../types/ethereum-network.types.mjs";
10
- import { AdminTransactionType as M } from "../../types/admin.types.mjs";
9
+ import { ContractType as M } from "../../types/ethereum-network.types.mjs";
10
+ import { AdminTransactionType as E } from "../../types/admin.types.mjs";
11
11
  import "../../types/activities.types.mjs";
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 $(
12
+ import { getSignatureDataForTransact as O } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
13
+ import { isValidPrivateAddress as $ } from "../../functions/utils/addresses.mjs";
14
+ import { shouldPatchAccessTokenMerkleTree as b } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
+ import { getCurrentTimeInSeconds as W } from "../../functions/utils/time.utils.mjs";
16
+ import { emitTxPublicData as S } from "../../API/admin-calls.mjs";
17
+ import { constructAdminData as U } from "../../functions/pre-transaction/constructAdminData.mjs";
18
+ const R = async (t, s, e) => {
19
+ const { patchAccessTokenMerkleTree: n, kycRequired: d, hasAccessToken: o } = await b(
20
20
  t,
21
21
  s,
22
22
  e
23
- ), c = void 0, p = await t.getEthereumAddress(), A = await N(
23
+ ), r = void 0, m = await t.getEthereumAddress(), p = await O(
24
24
  t.getCurrentChainId(),
25
- p,
25
+ m,
26
26
  t.userKeys,
27
- o,
28
- r
29
- ), i = {
27
+ d,
28
+ o
29
+ ), A = {
30
30
  externalActionId: 0n,
31
31
  externalAddress: await t.getEthereumAddress(),
32
32
  externalActionMetadata: "0x00"
33
33
  };
34
34
  return {
35
- signatureData: A,
36
- externalActionData: i,
37
- contractTransaction: c,
38
- contractToApprove: c,
35
+ signatureData: p,
36
+ externalActionData: A,
37
+ contractTransaction: r,
38
+ contractToApprove: r,
39
39
  patchAccessTokenMerkleTree: n
40
40
  };
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();
41
+ }, ot = async (t, s, e, n = !0, d = !1) => {
42
+ const o = s.map((a) => a.erc20TokenAddress), { externalActionData: r, contractTransaction: m, contractToApprove: p, patchAccessTokenMerkleTree: A, signatureData: x } = await R(t, o, e), u = [...await F(t, o, e)], T = `swapperM${e.length.toString()}x${u[0].length}x1`, c = [], g = W().toString();
43
43
  for (let a = 0; a < o.length; a += 1) {
44
- const { outputUtxos: w } = H(t.userKeys, u[a], e[a], T);
45
- d.push(w);
44
+ const { outputUtxos: D } = z(t.userKeys, u[a], e[a], g);
45
+ c.push(D);
46
46
  }
47
- const { zkCallData: g, circomData: y, dimData: l } = await P(
47
+ const { zkCallData: l, circomData: y, dimData: v } = await I(
48
48
  "v1x1",
49
49
  t.merkleTreeHinkal,
50
50
  t.merkleTreeAccessToken,
51
51
  u,
52
- d,
52
+ c,
53
53
  t.userKeys,
54
- x,
54
+ T,
55
55
  r.externalActionId,
56
56
  r.externalAddress,
57
57
  r.externalActionMetadata,
58
58
  t.generateProofRemotely,
59
- C,
59
+ P,
60
60
  t.getCurrentChainId(),
61
61
  void 0,
62
62
  void 0,
@@ -65,55 +65,56 @@ const U = async (t, s, e) => {
65
65
  void 0,
66
66
  void 0,
67
67
  void 0,
68
- t.getContractWithFetcher(K.HinkalHelperContract),
69
- i
70
- ), v = await I(
68
+ t.getContractWithFetcher(M.HinkalHelperContract),
69
+ x
70
+ ), f = await K(
71
71
  t,
72
72
  e,
73
73
  // for volotile tokens: amountChanges != amountOfTokenToApprove
74
74
  s,
75
- g,
76
- y,
77
75
  l,
76
+ y,
77
+ v,
78
78
  p,
79
- c,
80
- n
81
- ), f = S(
82
- M.Onboarding,
79
+ m,
80
+ n,
81
+ d
82
+ ), w = U(
83
+ E.Onboarding,
83
84
  t.getCurrentChainId(),
84
85
  o,
85
86
  e,
86
87
  await t.getEthereumAddress()
87
88
  );
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);
93
- const i = r.map((m) => [
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],
99
- erc20TokenAddress: m,
100
- randomization: BigInt(c),
89
+ return S(t.getCurrentChainId(), w), f;
90
+ }, at = async (t, s, e, n, d = !0, o = !1) => {
91
+ const r = s.map((i) => i.erc20TokenAddress), [m, p, A] = n.split(",");
92
+ if (!$(n))
93
+ throw Error(N.RECIPIENT_FORMAT_INCORRECT);
94
+ const x = r.map((i) => [
95
+ new C({ amount: 0n, erc20TokenAddress: i, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() }),
96
+ new C({ amount: 0n, erc20TokenAddress: i, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() })
97
+ ]), u = `swapperM${e.length.toString()}x${x[0].length}x1`, T = r.map((i, H) => [
98
+ new C({
99
+ amount: e[H],
100
+ erc20TokenAddress: i,
101
+ randomization: BigInt(m),
101
102
  stealthAddress: p,
102
103
  encryptionKey: A
103
104
  })
104
- ]), { externalActionData: d, contractTransaction: T, contractToApprove: g, patchAccessTokenMerkleTree: y } = await U(t, r, e), { zkCallData: l, circomData: v, dimData: f } = await P(
105
+ ]), { externalActionData: c, contractTransaction: g, contractToApprove: l, patchAccessTokenMerkleTree: y } = await R(t, r, e), { zkCallData: v, circomData: f, dimData: w } = await I(
105
106
  "v1x1",
106
107
  t.merkleTreeHinkal,
107
108
  t.merkleTreeAccessToken,
108
- i,
109
109
  x,
110
+ T,
110
111
  t.userKeys,
111
112
  u,
112
- d.externalActionId,
113
- d.externalAddress,
114
- d.externalActionMetadata,
113
+ c.externalActionId,
114
+ c.externalAddress,
115
+ c.externalActionMetadata,
115
116
  t.generateProofRemotely,
116
- C,
117
+ P,
117
118
  t.getCurrentChainId(),
118
119
  void 0,
119
120
  void 0,
@@ -122,27 +123,28 @@ const U = async (t, s, e) => {
122
123
  void 0,
123
124
  void 0,
124
125
  void 0,
125
- t.getContractWithFetcher(K.HinkalHelperContract)
126
- ), a = await I(
126
+ t.getContractWithFetcher(M.HinkalHelperContract)
127
+ ), a = await K(
127
128
  t,
128
129
  e,
129
130
  s,
130
- l,
131
131
  v,
132
132
  f,
133
+ w,
134
+ l,
133
135
  g,
134
- T,
136
+ d,
135
137
  o
136
- ), w = S(
137
- M.PaymentLink,
138
+ ), D = U(
139
+ E.PaymentLink,
138
140
  t.getCurrentChainId(),
139
141
  r,
140
142
  e,
141
143
  await t.getEthereumAddress()
142
144
  );
143
- return E(t.getCurrentChainId(), w), a;
145
+ return S(t.getCurrentChainId(), D), a;
144
146
  };
145
147
  export {
146
- rt as hinkalDeposit,
147
- ot as hinkalDepositForOther
148
+ ot as hinkalDeposit,
149
+ at as hinkalDepositForOther
148
150
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../constants/chains.constants.cjs"),o=require("./constant.cjs"),l=(e,i,t)=>{const r=e==="v1x0"?"":e;if(t===s.chainIds.localhost||t===s.chainIds.solanaLocalnet)return o.localVerifiers[`${i}${r}Wasm`];const c=o.prodVerifiers(t,e)[`${i}${r}Wasm`];return console.log({verifier:c}),c},a=(e,i,t)=>{const r=e==="v1x0"?"":e;return t===s.chainIds.localhost||t===s.chainIds.solanaLocalnet?o.localVerifiers[`${i}${r}Zkey`]:o.prodVerifiers(t,e)[`${i}${r}Zkey`]};exports.getWASMFile=l;exports.getZKeyFile=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../constants/chains.constants.cjs"),c=require("./constant.cjs"),a=(e,i,t)=>{const r=e==="v1x0"?"":e;return t===s.chainIds.localhost||t===s.chainIds.solanaLocalnet?c.localVerifiers[`${i}${r}Wasm`]:c.prodVerifiers(t,e)[`${i}${r}Wasm`]},l=(e,i,t)=>{const r=e==="v1x0"?"":e;return t===s.chainIds.localhost||t===s.chainIds.solanaLocalnet?c.localVerifiers[`${i}${r}Zkey`]:c.prodVerifiers(t,e)[`${i}${r}Zkey`]};exports.getWASMFile=a;exports.getZKeyFile=l;
@@ -1,14 +1,11 @@
1
- import { chainIds as i } from "../../constants/chains.constants.mjs";
2
- import { prodVerifiers as c, localVerifiers as l } from "./constant.mjs";
3
- const $ = (e, r, t) => {
4
- const o = e === "v1x0" ? "" : e;
5
- if (t === i.localhost || t === i.solanaLocalnet)
6
- return l[`${r}${o}Wasm`];
7
- const s = c(t, e)[`${r}${o}Wasm`];
8
- return console.log({ verifier: s }), s;
9
- }, v = (e, r, t) => {
10
- const o = e === "v1x0" ? "" : e;
11
- return t === i.localhost || t === i.solanaLocalnet ? l[`${r}${o}Zkey`] : c(t, e)[`${r}${o}Zkey`];
1
+ import { chainIds as o } from "../../constants/chains.constants.mjs";
2
+ import { prodVerifiers as s, localVerifiers as c } from "./constant.mjs";
3
+ const $ = (e, t, r) => {
4
+ const i = e === "v1x0" ? "" : e;
5
+ return r === o.localhost || r === o.solanaLocalnet ? c[`${t}${i}Wasm`] : s(r, e)[`${t}${i}Wasm`];
6
+ }, v = (e, t, r) => {
7
+ const i = e === "v1x0" ? "" : e;
8
+ return r === o.localhost || r === o.solanaLocalnet ? c[`${t}${i}Zkey`] : s(r, e)[`${t}${i}Zkey`];
12
9
  };
13
10
  export {
14
11
  $ as getWASMFile,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("ethers"),f=require("../../../constants/protocol.constants.cjs"),S=require("../../../types/ethereum-network.types.cjs"),F=require("../../utils/time.utils.cjs"),N=require("./approveTokensToHinkal.cjs"),_=require("./constructBatchCall.cjs"),z=require("./recoverTransactionFromError.cjs"),G=require("../../utils/getContractAddress.cjs"),L=async(r,d,l,s,p,A,q,x,b=!0)=>{const n=Array.isArray(d)?d:[d],e=Array.isArray(l)?l:[l];if(n.length!==e.length)throw new Error("token and amount length mismatch");const w=r.getContractWithSigner(S.ContractType.HinkalContract),k=await r.getEthereumAddress(),v=q??w,a=x??w,m="transact",C=e.findIndex(({erc20TokenAddress:t})=>t===f.zeroAddress),H=e.some(({erc20TokenAddress:t})=>t!==f.zeroAddress),h=C===-1?0n:n[C],u=r.getProviderAdapter();if(H&&await u.supportsBatchCall?.()&&u.sendBatchCallsTransaction){const t=e.map(E=>E.erc20TokenAddress),i=await _.buildApproveAndTransactCalls(t,n,G.getContractAddress(v),a,s,A,p,h);return await u.sendBatchCallsTransaction(i)}await N.approveTokensToHinkal(r,v,e,n);const T={value:h>0n?BigInt(h).toString():void 0};let o;const y=[s[0],s[1],s[2],A,p,{...T,from:k}],{runner:c}=a;if(!(c instanceof I.ethers.AbstractSigner))throw new Error("expected signer");if(b)try{o=Number(await a[m].estimateGas(...y)),console.log({gasCosts:o}),console.log({signerAddress:await c.getAddress(),chainIdHinkal:r.getCurrentChainId(),ethersNetwork:await c.provider.getNetwork()})}catch(t){console.log("hinkalDeposit: gas estimation error",{err:t})}const B=o&&o>=0?Math.ceil(o*12/10):void 0;T.gasLimit=B,await F.waitLittle();let g;try{g=await a[m](...y)}catch(t){if(!t?.transactionHash)throw t;const i=await z.recoverTransactionFromError(c.provider,t.transactionHash);if(!i)throw t;g=i}return g};exports.transactCallDirect=L;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("ethers"),b=require("../../../constants/protocol.constants.cjs"),F=require("../../../types/ethereum-network.types.cjs"),L=require("../../utils/time.utils.cjs"),N=require("./approveTokensToHinkal.cjs"),_=require("./constructBatchCall.cjs"),z=require("./recoverTransactionFromError.cjs"),G=require("../../utils/getContractAddress.cjs"),M=async(r,h,g,n,v,C,k,x,H=!0,u=!1)=>{const a=Array.isArray(h)?h:[h],e=Array.isArray(g)?g:[g];if(a.length!==e.length)throw new Error("token and amount length mismatch");const f=r.getContractWithSigner(F.ContractType.HinkalContract),B=await r.getEthereumAddress(),T=k??f,s=x??f,p="transact",y=e.findIndex(({erc20TokenAddress:t})=>t===b.zeroAddress),E=e.some(({erc20TokenAddress:t})=>t!==b.zeroAddress),A=y===-1?0n:a[y],w=r.getProviderAdapter();if(!u&&E&&await w.supportsBatchCall?.()&&w.sendBatchCallsTransaction){const t=e.map(I=>I.erc20TokenAddress),l=await _.buildApproveAndTransactCalls(t,a,G.getContractAddress(T),s,n,C,v,A);return await w.sendBatchCallsTransaction(l)}u||await N.approveTokensToHinkal(r,T,e,a);const q={value:A>0n?BigInt(A).toString():void 0,gasLimit:void 0};let o;const i=[n[0],n[1],n[2],C,v,{...q,from:B}],{runner:c}=s;if(!(c instanceof S.ethers.AbstractSigner))throw new Error("expected signer");if(H)try{o=Number(await s[p].estimateGas(...i)),console.log({gasCosts:o}),console.log({signerAddress:await c.getAddress(),chainIdHinkal:r.getCurrentChainId(),ethersNetwork:await c.provider.getNetwork()})}catch(t){console.log("hinkalDeposit: gas estimation error",{err:t})}const m=o&&o>=0?Math.ceil(o*12/10):void 0;q.gasLimit=m,m&&(i[5].gasLimit=m),await L.waitLittle();let d;try{u?d=await s[p].populateTransaction(...i):d=await s[p](...i)}catch(t){if(!t?.transactionHash)throw t;const l=await z.recoverTransactionFromError(c.provider,t.transactionHash);if(!l)throw t;d=l}return d};exports.transactCallDirect=M;
@@ -3,4 +3,4 @@ import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
3
3
  import { CircomDataBaseType, DimDataType } from '../../../types/circom-data.types';
4
4
  import { ERC20Token } from '../../../types/token.types';
5
5
  import { NewZkCallDataType } from '../../../types/snark.types';
6
- export declare const transactCallDirect: (hinkal: IHinkal, amount: bigint | bigint[], tokenToApprove: ERC20Token | ERC20Token[], newZkCallData: NewZkCallDataType, circomData: CircomDataBaseType, dimData: DimDataType, contractApproval?: ethers.Contract, contractTransaction?: ethers.Contract, preEstimateGas?: boolean) => Promise<any>;
6
+ export declare const transactCallDirect: (hinkal: IHinkal, amount: bigint | bigint[], tokenToApprove: ERC20Token | ERC20Token[], newZkCallData: NewZkCallDataType, circomData: CircomDataBaseType, dimData: DimDataType, contractApproval?: ethers.Contract, contractTransaction?: ethers.Contract, preEstimateGas?: boolean, returnTxData?: boolean) => Promise<any>;
@@ -1,69 +1,70 @@
1
1
  import { ethers as F } from "ethers";
2
- import { zeroAddress as T } from "../../../constants/protocol.constants.mjs";
2
+ import { zeroAddress as H } from "../../../constants/protocol.constants.mjs";
3
3
  import { ContractType as N } from "../../../types/ethereum-network.types.mjs";
4
4
  import { waitLittle as S } from "../../utils/time.utils.mjs";
5
5
  import { approveTokensToHinkal as G } from "./approveTokensToHinkal.mjs";
6
- import { buildApproveAndTransactCalls as L } from "./constructBatchCall.mjs";
7
- import { recoverTransactionFromError as z } from "./recoverTransactionFromError.mjs";
8
- import { getContractAddress as M } from "../../utils/getContractAddress.mjs";
9
- const U = async (r, d, m, s, g, A, y, H, I = !0) => {
10
- const n = Array.isArray(d) ? d : [d], o = Array.isArray(m) ? m : [m];
6
+ import { buildApproveAndTransactCalls as z } from "./constructBatchCall.mjs";
7
+ import { recoverTransactionFromError as M } from "./recoverTransactionFromError.mjs";
8
+ import { getContractAddress as P } from "../../utils/getContractAddress.mjs";
9
+ const V = async (r, l, p, a, v, C, I, b, B = !0, h = !1) => {
10
+ const n = Array.isArray(l) ? l : [l], o = Array.isArray(p) ? p : [p];
11
11
  if (n.length !== o.length)
12
12
  throw new Error("token and amount length mismatch");
13
- const f = r.getContractWithSigner(N.HinkalContract), b = await r.getEthereumAddress(), w = y ?? f, a = H ?? f, v = "transact", u = o.findIndex(({ erc20TokenAddress: t }) => t === T), B = o.some(({ erc20TokenAddress: t }) => t !== T), l = u === -1 ? 0n : n[u], p = r.getProviderAdapter();
14
- if (B && await p.supportsBatchCall?.() && p.sendBatchCallsTransaction) {
15
- const t = o.map((k) => k.erc20TokenAddress), c = await L(
13
+ const u = r.getContractWithSigner(N.HinkalContract), E = await r.getEthereumAddress(), y = I ?? u, e = b ?? u, g = "transact", T = o.findIndex(({ erc20TokenAddress: t }) => t === H), L = o.some(({ erc20TokenAddress: t }) => t !== H), f = T === -1 ? 0n : n[T], A = r.getProviderAdapter();
14
+ if (!h && L && await A.supportsBatchCall?.() && A.sendBatchCallsTransaction) {
15
+ const t = o.map((k) => k.erc20TokenAddress), m = await z(
16
16
  t,
17
17
  n,
18
- M(w),
18
+ P(y),
19
+ e,
19
20
  a,
20
- s,
21
- A,
22
- g,
23
- l
21
+ C,
22
+ v,
23
+ f
24
24
  );
25
- return await p.sendBatchCallsTransaction(c);
25
+ return await A.sendBatchCallsTransaction(m);
26
26
  }
27
- await G(r, w, o, n);
28
- const C = {
29
- value: l > 0n ? BigInt(l).toString() : void 0
27
+ h || await G(r, y, o, n);
28
+ const x = {
29
+ value: f > 0n ? BigInt(f).toString() : void 0,
30
+ gasLimit: void 0
30
31
  };
31
- let e;
32
- const x = [
33
- s[0],
34
- s[1],
35
- s[2],
36
- A,
37
- g,
38
- { ...C, from: b }
39
- ], { runner: i } = a;
40
- if (!(i instanceof F.AbstractSigner))
32
+ let s;
33
+ const i = [
34
+ a[0],
35
+ a[1],
36
+ a[2],
37
+ C,
38
+ v,
39
+ { ...x, from: E }
40
+ ], { runner: c } = e;
41
+ if (!(c instanceof F.AbstractSigner))
41
42
  throw new Error("expected signer");
42
- if (I)
43
+ if (B)
43
44
  try {
44
- e = Number(await a[v].estimateGas(...x)), console.log({ gasCosts: e }), console.log({
45
- signerAddress: await i.getAddress(),
45
+ s = Number(await e[g].estimateGas(...i)), console.log({ gasCosts: s }), console.log({
46
+ signerAddress: await c.getAddress(),
46
47
  chainIdHinkal: r.getCurrentChainId(),
47
- ethersNetwork: await i.provider.getNetwork()
48
+ ethersNetwork: await c.provider.getNetwork()
48
49
  });
49
50
  } catch (t) {
50
51
  console.log("hinkalDeposit: gas estimation error", { err: t });
51
52
  }
52
- const E = e && e >= 0 ? Math.ceil(e * 12 / 10) : void 0;
53
- C.gasLimit = E, await S();
54
- let h;
53
+ const w = s && s >= 0 ? Math.ceil(s * 12 / 10) : void 0;
54
+ x.gasLimit = w, w && (i[5].gasLimit = w), await S();
55
+ let d;
55
56
  try {
56
- h = await a[v](...x);
57
+ h ? d = await e[g].populateTransaction(...i) : d = await e[g](...i);
57
58
  } catch (t) {
58
59
  if (!t?.transactionHash)
59
60
  throw t;
60
- const c = await z(i.provider, t.transactionHash);
61
- if (!c)
61
+ const m = await M(c.provider, t.transactionHash);
62
+ if (!m)
62
63
  throw t;
63
- h = c;
64
+ d = m;
64
65
  }
65
- return h;
66
+ return d;
66
67
  };
67
68
  export {
68
- U as transactCallDirect
69
+ V as transactCallDirect
69
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hinkal/common",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"