@hinkal/common 0.2.25 → 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 +22 -14
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +4 -4
- package/data-structures/Hinkal/Hinkal.mjs +17 -8
- package/data-structures/Hinkal/IHinkal.d.ts +4 -4
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDeposit.mjs +83 -79
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +46 -45
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +48 -47
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +86 -85
- package/functions/snarkjs/getZKFiles.cjs +1 -1
- package/functions/snarkjs/getZKFiles.mjs +8 -11
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +52 -50
- package/package.json +1 -1
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 | ✅
|
|
18
|
-
| Browser | ✅
|
|
18
|
+
| Node.js | ✅ | v18+ |
|
|
19
|
+
| Browser | ✅ | React, Next.js, vanilla JS |
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
## Installation
|
|
21
23
|
|
|
@@ -100,13 +102,15 @@ 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[]): Promise<ethers.
|
|
105
|
+
function deposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], preEstimateGas?: boolean, returnTxData?: boolean ): Promise<ethers.ContractTransaction | ethers.TransactionRequest >;
|
|
104
106
|
```
|
|
105
107
|
|
|
106
108
|
where:
|
|
107
109
|
|
|
108
110
|
- `erc20Tokens` is an array of tokens to deposit
|
|
109
111
|
- `amountChanges` represents the corresponding token amounts for the deposit
|
|
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.
|
|
110
114
|
|
|
111
115
|
The `ERC20Token` type is defined as follows:
|
|
112
116
|
|
|
@@ -172,6 +176,7 @@ function depositAndWithdraw(
|
|
|
172
176
|
recipientAmounts: bigint[],
|
|
173
177
|
recipientAddresses: string[],
|
|
174
178
|
txCompletionTime?: number,
|
|
179
|
+
preEstimateGas?: boolean
|
|
175
180
|
): Promise<string>;
|
|
176
181
|
```
|
|
177
182
|
|
|
@@ -181,6 +186,7 @@ where:
|
|
|
181
186
|
- `recipientAmounts` is an array of amounts to send to each recipient (in the token's smallest unit)
|
|
182
187
|
- `recipientAddresses` is an array of public addresses that will receive the funds
|
|
183
188
|
- `txCompletionTime` (optional) specifies a delay in milliseconds before the withdrawal completes
|
|
189
|
+
- `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
190
|
|
|
185
191
|
### Swapping tokens from the shielded balance
|
|
186
192
|
|
|
@@ -269,12 +275,12 @@ function emporiumOp(
|
|
|
269
275
|
|
|
270
276
|
The function accepts the following arguments:
|
|
271
277
|
|
|
272
|
-
1. `contract`
|
|
273
|
-
2. `func`
|
|
274
|
-
3. `args`
|
|
275
|
-
4. `callDataString`
|
|
276
|
-
5. `invokeWallet`
|
|
277
|
-
6. `value`
|
|
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.
|
|
278
284
|
|
|
279
285
|
When the Emporium contract executes a user operation, it receives the data in this format:
|
|
280
286
|
|
|
@@ -355,15 +361,17 @@ After passing the compliance check with one of the supported providers, the acce
|
|
|
355
361
|
|
|
356
362
|
Hinkal SDK is available on the following blockchain networks:
|
|
357
363
|
|
|
364
|
+
|
|
358
365
|
| Chain | Chain ID | Status |
|
|
359
366
|
| -------- | -------- | -------------- |
|
|
360
|
-
| Ethereum | 1 | ✅ Live
|
|
361
|
-
| Polygon | 137 | ✅ Live
|
|
362
|
-
| Base | 8453 | ✅ Live
|
|
363
|
-
| Arbitrum | 42161 | ✅ Live
|
|
364
|
-
| Optimism | 10 | ✅ Live
|
|
367
|
+
| Ethereum | 1 | ✅ Live |
|
|
368
|
+
| Polygon | 137 | ✅ Live |
|
|
369
|
+
| Base | 8453 | ✅ Live |
|
|
370
|
+
| Arbitrum | 42161 | ✅ Live |
|
|
371
|
+
| Optimism | 10 | ✅ Live |
|
|
365
372
|
| Solana | - | 🚧 In Progress |
|
|
366
373
|
|
|
374
|
+
|
|
367
375
|
Each chain supports the full suite of Hinkal privacy features including shielding, transfers, and confidential interactions with DeFi protocols.
|
|
368
376
|
|
|
369
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){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 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,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, 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
|
+
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, i = !1) {
|
|
369
|
+
return b(this, e, t, r, i);
|
|
370
370
|
}
|
|
371
|
-
async depositForOther(e, t, r) {
|
|
372
|
-
return W(this, e, t, r);
|
|
371
|
+
async depositForOther(e, t, r, i = !0, a = !1) {
|
|
372
|
+
return W(this, e, t, r, i, a);
|
|
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(
|
|
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, 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
|
+
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
|
|
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[]) => 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, 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
|
|
2
|
-
import { outputUtxoProcessing as
|
|
3
|
-
import { constructZkProof as
|
|
4
|
-
import { addPaddingToUtxos as
|
|
5
|
-
import { transactCallDirect as
|
|
6
|
-
import { Utxo as
|
|
7
|
-
import { transactionErrorCodes as
|
|
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
|
|
10
|
-
import { AdminTransactionType as
|
|
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
|
|
13
|
-
import { isValidPrivateAddress as
|
|
14
|
-
import { shouldPatchAccessTokenMerkleTree as
|
|
15
|
-
import { getCurrentTimeInSeconds as
|
|
16
|
-
import { emitTxPublicData as
|
|
17
|
-
import { constructAdminData as
|
|
18
|
-
const
|
|
19
|
-
const { patchAccessTokenMerkleTree:
|
|
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
|
-
),
|
|
23
|
+
), r = void 0, m = await t.getEthereumAddress(), p = await O(
|
|
24
24
|
t.getCurrentChainId(),
|
|
25
|
-
|
|
25
|
+
m,
|
|
26
26
|
t.userKeys,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
),
|
|
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:
|
|
36
|
-
externalActionData:
|
|
37
|
-
contractTransaction:
|
|
38
|
-
contractToApprove:
|
|
39
|
-
patchAccessTokenMerkleTree:
|
|
35
|
+
signatureData: p,
|
|
36
|
+
externalActionData: A,
|
|
37
|
+
contractTransaction: r,
|
|
38
|
+
contractToApprove: r,
|
|
39
|
+
patchAccessTokenMerkleTree: n
|
|
40
40
|
};
|
|
41
|
-
},
|
|
42
|
-
const o = s.map((a) => a.erc20TokenAddress), { externalActionData: r, contractTransaction:
|
|
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:
|
|
45
|
-
|
|
44
|
+
const { outputUtxos: D } = z(t.userKeys, u[a], e[a], g);
|
|
45
|
+
c.push(D);
|
|
46
46
|
}
|
|
47
|
-
const { zkCallData:
|
|
47
|
+
const { zkCallData: l, circomData: y, dimData: v } = await I(
|
|
48
48
|
"v1x1",
|
|
49
49
|
t.merkleTreeHinkal,
|
|
50
50
|
t.merkleTreeAccessToken,
|
|
51
|
-
n,
|
|
52
|
-
d,
|
|
53
|
-
t.userKeys,
|
|
54
51
|
u,
|
|
52
|
+
c,
|
|
53
|
+
t.userKeys,
|
|
54
|
+
T,
|
|
55
55
|
r.externalActionId,
|
|
56
56
|
r.externalAddress,
|
|
57
57
|
r.externalActionMetadata,
|
|
58
58
|
t.generateProofRemotely,
|
|
59
|
-
|
|
59
|
+
P,
|
|
60
60
|
t.getCurrentChainId(),
|
|
61
61
|
void 0,
|
|
62
62
|
void 0,
|
|
@@ -65,82 +65,86 @@ const S = async (t, s, e) => {
|
|
|
65
65
|
void 0,
|
|
66
66
|
void 0,
|
|
67
67
|
void 0,
|
|
68
|
-
t.getContractWithFetcher(
|
|
69
|
-
|
|
70
|
-
),
|
|
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
|
-
|
|
76
|
-
g,
|
|
75
|
+
l,
|
|
77
76
|
y,
|
|
78
|
-
|
|
79
|
-
p
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
v,
|
|
78
|
+
p,
|
|
79
|
+
m,
|
|
80
|
+
n,
|
|
81
|
+
d
|
|
82
|
+
), w = U(
|
|
83
|
+
E.Onboarding,
|
|
82
84
|
t.getCurrentChainId(),
|
|
83
85
|
o,
|
|
84
86
|
e,
|
|
85
87
|
await t.getEthereumAddress()
|
|
86
88
|
);
|
|
87
|
-
return
|
|
88
|
-
},
|
|
89
|
-
const r = s.map((
|
|
90
|
-
if (
|
|
91
|
-
throw Error(
|
|
92
|
-
const
|
|
93
|
-
new
|
|
94
|
-
new
|
|
95
|
-
]),
|
|
96
|
-
new
|
|
97
|
-
amount: e[
|
|
98
|
-
erc20TokenAddress:
|
|
99
|
-
randomization: BigInt(
|
|
100
|
-
stealthAddress:
|
|
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),
|
|
102
|
+
stealthAddress: p,
|
|
101
103
|
encryptionKey: A
|
|
102
104
|
})
|
|
103
|
-
]), { externalActionData:
|
|
105
|
+
]), { externalActionData: c, contractTransaction: g, contractToApprove: l, patchAccessTokenMerkleTree: y } = await R(t, r, e), { zkCallData: v, circomData: f, dimData: w } = await I(
|
|
104
106
|
"v1x1",
|
|
105
107
|
t.merkleTreeHinkal,
|
|
106
108
|
t.merkleTreeAccessToken,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
x,
|
|
110
|
+
T,
|
|
109
111
|
t.userKeys,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
u,
|
|
113
|
+
c.externalActionId,
|
|
114
|
+
c.externalAddress,
|
|
115
|
+
c.externalActionMetadata,
|
|
114
116
|
t.generateProofRemotely,
|
|
115
|
-
|
|
117
|
+
P,
|
|
116
118
|
t.getCurrentChainId(),
|
|
117
119
|
void 0,
|
|
118
120
|
void 0,
|
|
119
121
|
void 0,
|
|
120
|
-
|
|
122
|
+
y,
|
|
121
123
|
void 0,
|
|
122
124
|
void 0,
|
|
123
125
|
void 0,
|
|
124
|
-
t.getContractWithFetcher(
|
|
125
|
-
), a = await
|
|
126
|
+
t.getContractWithFetcher(M.HinkalHelperContract)
|
|
127
|
+
), a = await K(
|
|
126
128
|
t,
|
|
127
129
|
e,
|
|
128
130
|
s,
|
|
129
|
-
y,
|
|
130
|
-
l,
|
|
131
131
|
v,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
f,
|
|
133
|
+
w,
|
|
134
|
+
l,
|
|
135
|
+
g,
|
|
136
|
+
d,
|
|
137
|
+
o
|
|
138
|
+
), D = U(
|
|
139
|
+
E.PaymentLink,
|
|
136
140
|
t.getCurrentChainId(),
|
|
137
141
|
r,
|
|
138
142
|
e,
|
|
139
143
|
await t.getEthereumAddress()
|
|
140
144
|
);
|
|
141
|
-
return
|
|
145
|
+
return S(t.getCurrentChainId(), D), a;
|
|
142
146
|
};
|
|
143
147
|
export {
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
ot as hinkalDeposit,
|
|
149
|
+
at as hinkalDepositForOther
|
|
146
150
|
};
|
|
@@ -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,
|
|
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>;
|