h_test_1 0.0.10 → 0.0.12
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/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +2 -2
- package/data-structures/Hinkal/Hinkal.mjs +4 -4
- package/data-structures/Hinkal/IHinkal.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDeposit.mjs +73 -71
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +41 -41
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
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: n, kycRequired:
|
|
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:
|
|
35
|
+
signatureData: p,
|
|
36
|
+
externalActionData: A,
|
|
37
|
+
contractTransaction: r,
|
|
38
|
+
contractToApprove: r,
|
|
39
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
51
|
u,
|
|
52
|
-
|
|
52
|
+
c,
|
|
53
53
|
t.userKeys,
|
|
54
|
-
|
|
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,55 +65,56 @@ const U = 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
|
-
g,
|
|
76
|
-
y,
|
|
77
75
|
l,
|
|
76
|
+
y,
|
|
77
|
+
v,
|
|
78
78
|
p,
|
|
79
|
-
|
|
80
|
-
n
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
89
|
-
},
|
|
90
|
-
const r = s.map((
|
|
91
|
-
if (
|
|
92
|
-
throw Error(
|
|
93
|
-
const
|
|
94
|
-
new
|
|
95
|
-
new
|
|
96
|
-
]), u = `swapperM${e.length.toString()}x${
|
|
97
|
-
new
|
|
98
|
-
amount: e[
|
|
99
|
-
erc20TokenAddress:
|
|
100
|
-
randomization: BigInt(
|
|
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:
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
c.externalActionId,
|
|
114
|
+
c.externalAddress,
|
|
115
|
+
c.externalActionMetadata,
|
|
115
116
|
t.generateProofRemotely,
|
|
116
|
-
|
|
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(
|
|
126
|
-
), a = await
|
|
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
|
-
|
|
136
|
+
d,
|
|
135
137
|
o
|
|
136
|
-
),
|
|
137
|
-
|
|
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
|
|
145
|
+
return S(t.getCurrentChainId(), D), a;
|
|
144
146
|
};
|
|
145
147
|
export {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
ot as hinkalDeposit,
|
|
149
|
+
at as hinkalDepositForOther
|
|
148
150
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("ethers"),q=require("../../../constants/protocol.constants.cjs"),F=require("../../../types/ethereum-network.types.cjs"),N=require("../../utils/time.utils.cjs"),_=require("./approveTokensToHinkal.cjs"),z=require("./constructBatchCall.cjs"),G=require("./recoverTransactionFromError.cjs"),L=require("../../utils/getContractAddress.cjs"),M=async(r,l,h,n,w,v,x,b,k=!0,m=!1)=>{const a=Array.isArray(l)?l:[l],e=Array.isArray(h)?h:[h];if(a.length!==e.length)throw new Error("token and amount length mismatch");const C=r.getContractWithSigner(F.ContractType.HinkalContract),H=await r.getEthereumAddress(),f=x??C,s=b??C,u="transact",T=e.findIndex(({erc20TokenAddress:t})=>t===q.zeroAddress),B=e.some(({erc20TokenAddress:t})=>t!==q.zeroAddress),g=T===-1?0n:a[T],p=r.getProviderAdapter();if(B&&await p.supportsBatchCall?.()&&p.sendBatchCallsTransaction){const t=e.map(I=>I.erc20TokenAddress),d=await z.buildApproveAndTransactCalls(t,a,L.getContractAddress(f),s,n,v,w,g);return await p.sendBatchCallsTransaction(d)}m||await _.approveTokensToHinkal(r,f,e,a);const y={value:g>0n?BigInt(g).toString():void 0};let o;const A=[n[0],n[1],n[2],v,w,{...y,from:H}],{runner:c}=s;if(!(c instanceof S.ethers.AbstractSigner))throw new Error("expected signer");if(k)try{o=Number(await s[u].estimateGas(...A)),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 E=o&&o>=0?Math.ceil(o*12/10):void 0;y.gasLimit=E,await N.waitLittle();let i;try{m?i=await s[u].populateTransaction(...A):i=await s[u](...A)}catch(t){if(!t?.transactionHash)throw t;const d=await G.recoverTransactionFromError(c.provider,t.transactionHash);if(!d)throw t;i=d}return i};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,47 +1,47 @@
|
|
|
1
|
-
import { ethers as
|
|
2
|
-
import { zeroAddress as
|
|
3
|
-
import { ContractType as
|
|
4
|
-
import { waitLittle as
|
|
5
|
-
import { approveTokensToHinkal as
|
|
6
|
-
import { buildApproveAndTransactCalls as
|
|
7
|
-
import { recoverTransactionFromError as
|
|
8
|
-
import { getContractAddress as
|
|
9
|
-
const
|
|
10
|
-
const n = Array.isArray(
|
|
1
|
+
import { ethers as N } from "ethers";
|
|
2
|
+
import { zeroAddress as y } from "../../../constants/protocol.constants.mjs";
|
|
3
|
+
import { ContractType as S } from "../../../types/ethereum-network.types.mjs";
|
|
4
|
+
import { waitLittle as G } from "../../utils/time.utils.mjs";
|
|
5
|
+
import { approveTokensToHinkal as L } from "./approveTokensToHinkal.mjs";
|
|
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, m, a, A, w, H, I, b = !0, v = !1) => {
|
|
10
|
+
const n = Array.isArray(l) ? l : [l], o = Array.isArray(m) ? m : [m];
|
|
11
11
|
if (n.length !== o.length)
|
|
12
12
|
throw new Error("token and amount length mismatch");
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
const t = o.map((
|
|
13
|
+
const u = r.getContractWithSigner(S.HinkalContract), B = await r.getEthereumAddress(), C = H ?? u, e = I ?? u, p = "transact", T = o.findIndex(({ erc20TokenAddress: t }) => t === y), E = o.some(({ erc20TokenAddress: t }) => t !== y), h = T === -1 ? 0n : n[T], g = r.getProviderAdapter();
|
|
14
|
+
if (E && await g.supportsBatchCall?.() && g.sendBatchCallsTransaction) {
|
|
15
|
+
const t = o.map((F) => F.erc20TokenAddress), d = await z(
|
|
16
16
|
t,
|
|
17
17
|
n,
|
|
18
|
-
|
|
18
|
+
P(C),
|
|
19
|
+
e,
|
|
19
20
|
a,
|
|
20
|
-
|
|
21
|
+
w,
|
|
21
22
|
A,
|
|
22
|
-
|
|
23
|
-
l
|
|
23
|
+
h
|
|
24
24
|
);
|
|
25
|
-
return await
|
|
25
|
+
return await g.sendBatchCallsTransaction(d);
|
|
26
26
|
}
|
|
27
|
-
await
|
|
28
|
-
const
|
|
29
|
-
value:
|
|
27
|
+
v || await L(r, C, o, n);
|
|
28
|
+
const x = {
|
|
29
|
+
value: h > 0n ? BigInt(h).toString() : void 0
|
|
30
30
|
};
|
|
31
|
-
let
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
let s;
|
|
32
|
+
const f = [
|
|
33
|
+
a[0],
|
|
34
|
+
a[1],
|
|
35
|
+
a[2],
|
|
36
|
+
w,
|
|
36
37
|
A,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!(i instanceof F.AbstractSigner))
|
|
38
|
+
{ ...x, from: B }
|
|
39
|
+
], { runner: i } = e;
|
|
40
|
+
if (!(i instanceof N.AbstractSigner))
|
|
41
41
|
throw new Error("expected signer");
|
|
42
|
-
if (
|
|
42
|
+
if (b)
|
|
43
43
|
try {
|
|
44
|
-
|
|
44
|
+
s = Number(await e[p].estimateGas(...f)), console.log({ gasCosts: s }), console.log({
|
|
45
45
|
signerAddress: await i.getAddress(),
|
|
46
46
|
chainIdHinkal: r.getCurrentChainId(),
|
|
47
47
|
ethersNetwork: await i.provider.getNetwork()
|
|
@@ -49,21 +49,21 @@ const U = async (r, d, m, s, g, A, y, H, I = !0) => {
|
|
|
49
49
|
} catch (t) {
|
|
50
50
|
console.log("hinkalDeposit: gas estimation error", { err: t });
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
let
|
|
52
|
+
const k = s && s >= 0 ? Math.ceil(s * 12 / 10) : void 0;
|
|
53
|
+
x.gasLimit = k, await G();
|
|
54
|
+
let c;
|
|
55
55
|
try {
|
|
56
|
-
|
|
56
|
+
v ? c = await e[p].populateTransaction(...f) : c = await e[p](...f);
|
|
57
57
|
} catch (t) {
|
|
58
58
|
if (!t?.transactionHash)
|
|
59
59
|
throw t;
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
60
|
+
const d = await M(i.provider, t.transactionHash);
|
|
61
|
+
if (!d)
|
|
62
62
|
throw t;
|
|
63
|
-
|
|
63
|
+
c = d;
|
|
64
64
|
}
|
|
65
|
-
return
|
|
65
|
+
return c;
|
|
66
66
|
};
|
|
67
67
|
export {
|
|
68
|
-
|
|
68
|
+
V as transactCallDirect
|
|
69
69
|
};
|