@kapa123456789/sdk 0.0.23 → 0.0.24
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/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.d.ts +0 -4
- package/common/src/data-structures/Hinkal/Hinkal.mjs +2 -10
- package/common/src/data-structures/Hinkal/IHinkal.d.ts +0 -3
- package/common/src/data-structures/Hinkal/index.d.ts +0 -1
- package/common/src/data-structures/IndexedDB/index.cjs +1 -1
- package/common/src/data-structures/IndexedDB/index.d.ts +0 -1
- package/common/src/data-structures/IndexedDB/index.mjs +0 -1
- package/common/src/data-structures/IndexedDB/prices-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/prices-db.mjs +17 -18
- package/common/src/data-structures/IndexedDB/private-balances-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/private-balances-db.mjs +11 -10
- package/common/src/functions/web3/events/balanceChangedHandler.d.ts +1 -1
- package/common/src/types/balances.types.d.ts +0 -22
- package/common/src/webworker/package.json +1 -1
- package/common/src/webworker/snarkjsWorkerNode.cjs +10 -2
- package/common/src/webworker/utxoWorkerNode.cjs +1 -1
- package/common/src/webworker/{workerProxy-CEspdgQn.js → workerProxy-DPSmXOIl.js} +4 -2
- package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
- package/package.json +1 -1
- package/services/Hinkal.cjs +1 -1
- package/services/Hinkal.d.ts +3 -3
- package/services/Hinkal.mjs +7 -9
- package/types/IHinkal.d.ts +3 -4
- package/types/balances.types.d.ts +1 -1
- package/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.cjs +0 -1
- package/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.d.ts +0 -19
- package/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.mjs +0 -239
- package/common/src/data-structures/IndexedDB/key-val-store.cjs +0 -1
- package/common/src/data-structures/IndexedDB/key-val-store.d.ts +0 -6
- package/common/src/data-structures/IndexedDB/key-val-store.mjs +0 -41
- package/common/src/webworker/logError-DdWQYd9m.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../functions/utils/serialize.utils.cjs`),t=require(`../../constants/vite.constants.cjs`),n=require(`../../constants/chains.constants.cjs`),r=require(`../../types/hinkal.types.cjs`),i=require(`../../types/ethereum-network.types.cjs`),a=require(`../../crypto/poseidon.cjs`),o=require(`../../functions/pre-transaction/solana.cjs`),s=require(`./hinkalCheckSolanaTokenRegistry.cjs`),c=require(`../../functions/web3/functionCalls/accessTokenCalls.cjs`),l=require(`../../error-handling/error-codes.constants.cjs`),u=require(`../../functions/utils/erc20tokenFunctions.cjs`),d=require(`../crypto-keys/keys.cjs`),f=require(`../../API/API.cjs`),p=require(`../../functions/utils/token-check.utils.cjs`),m=require(`../TokenDBs/PrivateTokensDB.cjs`),ee=require(`../../functions/web3/events/getShieldedBalance.cjs`),h=require(`../../constants/kyc.constants.cjs`),g=require(`../../functions/utils/reloadPage.cjs`),te=require(`../../functions/utils/cacheDevice.utils.cjs`),_=require(`../../functions/web3/getContractMetadata.cjs`),v=require(`../../providers/SolanaProviderAdapter.cjs`),y=require(`./hinkalCheckTokenRegistry.cjs`),b=require(`../merkle-tree/MerkleTree.cjs`);require(`../merkle-tree/index.cjs`);const x=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),S=require(`./hinkalDeposit.cjs`),C=require(`../../functions/private-wallet/emporium.helpers.cjs`);require(`../../API/index.cjs`);const w=require(`../../functions/kyc/checkTokenLimitsUSD.cjs`),T=require(`./hinkalDepositAndWithdraw.cjs`),E=require(`./hinkalSolanaDeposit.cjs`),D=require(`./hinkalSwap.cjs`),O=require(`./hinkalWithdraw.cjs`),k=require(`./resetMerkleTrees.cjs`),A=require(`../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs`),j=require(`./hinkalPrivateWallet.cjs`),M=require(`./hinkalGetRecipientInfo.cjs`),N=require(`./hinkalSignSubAccount.cjs`),P=require(`./hinkalActionReceive.cjs`);require(`../TokenDBs/index.cjs`);const F=require(`./hinkalProoflessDeposit.cjs`),I=require(`./hinkalProxySwap.cjs`),L=require(`./hinkalMultiSend.cjs`),ne=require(`./hinkalTransfer.cjs`),R=require(`./hinkalProxyToPrivate.cjs`),z=require(`../../providers/TronProviderAdapter.cjs`),B=require(`./hinkalSolanaDepositAndWithdraw.cjs`),V=require(`./hinkalSolanaWithdraw.cjs`),H=require(`./hinkalSolanaTransfer.cjs`),U=require(`./hinkalSolanaSwap.cjs`),W=require(`./hinkalSolanaProxySend.cjs`),G=require(`./hinkalSolanaProxySwap.cjs`),K=require(`./hinkalSolanaProxyShield.cjs`),q=require(`./hinkalDepositAndBridge.cjs`),J=require(`./hinkalClaimUtxo.cjs`),Y=require(`./hinkalSolanaProoflessDeposit.cjs`),X=require(`./hinkalSolanaClaimUtxo.cjs`),Z=require(`./hinkalWithdrawStuckUtxos.cjs`),re=require(`./HinkalPrivateBalanceController.cjs`);let Q=require(`ethers`),$=require(`@solana/web3.js`);var ie=class{ethereumProviderAdapter;solanaProviderAdapter;tronProviderAdapter;userKeys;signingMessage=`Login to Hinkal Protocol`;privateTransferSigningMessage=`Login to Hinkal's Private Transfer App`;merkleTreeHinkalByChain={};merkleTreeAccessTokenByChain={};nullifiersByChain={};encryptedOutputsByChain={};commitmentsSnapshotServiceByChain={};nullifierSnapshotServiceByChain={};accessTokenSnapshotServiceByChain={};utxoUtils;lastCallState=new Map;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;privateBalances=new re.HinkalPrivateBalanceController(this);constructor(e){this.userKeys=new d.UserKeys(void 0),n.HINKAL_SUPPORTED_CHAINS.forEach(e=>{this.merkleTreeHinkalByChain[e]=b.MerkleTree.create(a.poseidonFunction,0n),this.merkleTreeAccessTokenByChain[e]=b.MerkleTree.create(a.poseidonFunction,0n),this.nullifiersByChain[e]=new Set,this.encryptedOutputsByChain[e]=[]}),this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new A.MultiThreadedUtxoUtils,this.cacheDevice=te.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}enforceRateLimit(t,n,r=1e3){let i=Date.now(),a=e.CustomJSONStringify(n),o=this.lastCallState.get(t);if(o&&o.argsKey===a&&i-o.timestamp<r)throw Error(`${t} was already called with the same arguments`);this.lastCallState.set(t,{timestamp:i,argsKey:a})}getProviderAdapter(e){let t=e;t||=this.ethereumProviderAdapter?n.chainIds.ethMainnet:this.solanaProviderAdapter?n.chainIds.solanaMainnet:n.chainIds.tronMainnet;let r;if(r=n.isSolanaLike(t)?this.solanaProviderAdapter:n.isTronLike(t)?this.tronProviderAdapter:this.ethereumProviderAdapter,!r)throw Error(`ProviderAdapter is not initialized`);return r}async initProviderAdapter(e,t){let r=n.chainIds.ethMainnet;t instanceof v.SolanaProviderAdapter?r=n.chainIds.solanaMainnet:t instanceof z.TronProviderAdapter&&(r=n.currentTronChainId),await this.updateProviderAdapter(r,t),t.initConnector(e);let i=await t.connectAndPatchProvider(e);await t.init(i),await this.setListeners()}getSigningMessage(e=r.LoginMessageMode.PROTOCOL){switch(e){case r.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case r.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async initUserKeys(e=r.LoginMessageMode.PROTOCOL){let t=this.getSigningMessage(e);this.userKeys=new d.UserKeys(await this.getProviderAdapter().signMessage(t))}initUserKeysWithSignature(e){this.userKeys=new d.UserKeys(e)}async initUserKeysFromSeedPhrases(e){let t=e.join(` `),n=Q.ethers.toUtf8Bytes(t),r=Q.ethers.keccak256(n);this.userKeys=new d.UserKeys(r)}async resetMerkle(e){this.disableMerkleTreeUpdates||(e?.every(e=>this.isSelectedNetworkSupported(e))??!0)&&await k.resetMerkleTrees(this,e)}getTronWeb(){let e=this.tronProviderAdapter;if(!e)throw Error(`Tron provider adapter not initialized`);if(!(e instanceof z.TronProviderAdapter))throw Error(`Tron provider adapter is not a TronProviderAdapter`);let t=e.getTronWeb();if(!t)throw Error(`TronWeb not available`);return t}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?n.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>!n.isSolanaLike(e)&&!n.isTronLike(e)):this.solanaProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>n.isSolanaLike(e)):this.tronProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>n.isTronLike(e)):[]}async waitForTransaction(e,t,n=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,t,n)}getContract(e,t,n=void 0){return this.getProviderAdapter(e).getContract(e,t,n)}getContractWithFetcherByChainId(e,t,n=void 0){return _.getContractWithFetcherByChainId(e,t,n)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,n){return await this.getProviderAdapter().signTypedData(e,t,n)}async signWithSubAccount(e,t,n,r){return N.hinkalSignSubAccount(e,t,n,r)}getContractWithSigner(e,t,n=``){return this.getProviderAdapter(e).getContractWithSigner(e,t,n)}getContractWithFetcher(e,t,n=``){return this.getProviderAdapter(e).getContractWithFetcher(e,t,n)}isSelectedNetworkSupported(e){return!!n.networkRegistry[e]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw Error(l.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async disconnectFromConnector(){await this.ethereumProviderAdapter?.disconnectFromConnector(),await this.solanaProviderAdapter?.disconnectFromConnector(),await this.tronProviderAdapter?.disconnectFromConnector()}async resetProviderAdapters(){this.ethereumProviderAdapter=void 0,this.solanaProviderAdapter=void 0,this.tronProviderAdapter=void 0}async updateProviderAdapter(e,t){try{n.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=t):n.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=t):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=t)}catch(e){throw console.error(e),Error(`updateProviderAdapter failed, please try again.`)}}async setListeners(){this.ethereumProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.solanaProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.tronProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.ethereumProviderAdapter?.onAccountChanged(),await this.solanaProviderAdapter?.onAccountChanged(),await this.tronProviderAdapter?.onAccountChanged();let e=r.EventType.AccountChanged;typeof document<`u`?document?.dispatchEvent(new Event(e)):process?.emit(`message`,e,void 0)}async onChainChanged(e){e?await this.getProviderAdapter(e).onChainChanged(e):(await this.disconnectFromConnector(),g.reloadPage())}async monitorConnectedAddress(e){await f.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,t,n,r,i=!1,a,o=!1){return ee.getShieldedBalance(this,e,t,n,r,i,this.generateProofRemotely,a,o)}async getTotalBalance(e,n,r,i=!1,a,o=!1){let s=r??await this.getEthereumAddressByChain(e),c=n??this.userKeys,l=await this.getBalances(e,c.getShieldedPrivateKey(),c.getShieldedPublicKey(),s,i,a,o),d=t.isExtension?await m.privateTokensDB.getPrivateTokens(e,s):u.getErc20TokensForChain(e),f=[];return d.forEach(e=>{let t=e.erc20TokenAddress.toLowerCase(),n=l.get(t),r={token:e,balance:n?.balance??0n,timestamp:n?.timestamp||`0`,nfts:n?.nfts||[]};f.push(r)}),f}async getStuckShieldedBalances(e,t,n,r=!1,i=!1){return(await this.getTotalBalance(e,t,n,r,i,!0)).filter(e=>e.balance>0n)}get privateBalancesWithUSD(){return this.privateBalances.getSnapshot()}onPrivateBalancesWithUSDChange(e){return this.privateBalances.onPrivateBalancesWithUSDChange(e)}getSupportedPassportLinks(){return h.supportedPassportLinks}checkAccessToken(e,t){return c.checkHinkalAccessToken(this,e,t)}checkExternalTokenLimitsUSD(e,t,n){return w.checkTokenLimitsUSD(e,t,n)}async getHinkalTreeRootHash(e){if(n.isSolanaLike(e)){let{hinkalIdl:t,hinkalAddress:r,originalDeployer:i}=n.networkRegistry[e].contractData;if(!t||!r||!i)throw Error(`Missing Solana configuration for chain ${e}`);let a=new $.PublicKey(i),s=o.getMerkleAccountPublicKey(new $.PublicKey(r),a);return x.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(t),s)}return this.getContractWithFetcherByChainId(e,i.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(e){if(n.isSolanaLike(e)){let{hinkalIdl:t,hinkalAddress:r,originalDeployer:i}=n.networkRegistry[e].contractData;if(!t||!r||!i)throw Error(`Missing Solana configuration for chain ${e}`);let a=new $.PublicKey(i),s=o.getAccessTokenMerkleAccountPublicKey(new $.PublicKey(r),a);return x.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(t),s)}return this.getContractWithFetcherByChainId(e,i.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(e){let t=(await Promise.all((e??this.getSupportedChains()).map(async e=>{let[t,n]=await Promise.all([this.getHinkalTreeRootHash(e),this.getAccessTokenTreeRootHash(e)]);return{chainId:e,needsReset:BigInt(t)!==this.merkleTreeHinkalByChain[e].getRootHash()||BigInt(n)!==this.merkleTreeAccessTokenByChain[e].getRootHash()}}))).filter(e=>e.needsReset).map(e=>e.chainId);t.length>0&&(console.log(`resetting merkle tree in resetMerkleTreesIfNecessary for chains:`,t),await this.resetMerkle(t))}async getEthereumAddress(){let e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw Error(`No provider adapter initialized`);return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,t=!1){return(await f.API.getIdleRelay(e,t)).relay}getGasPrice(e){let t=this.getProviderAdapter(e);if(!t)throw Error(`Illegal State of providerAdapter in Hinkal: no providerAdapter initialized`);return t.getGasPrice(e)}getAPI(){return f.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.accessTokenSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear()})}checkTokenRegistry(e,t,r){if(n.isSolanaLike(e)){let{hinkalIdl:i,hinkalAddress:a,originalDeployer:o}=n.networkRegistry[e].contractData;if(!i||!a||!o)throw Error(`missing solana data`);return s.hinkalCheckSolanaTokenRegistry(this.getSolanaProgram(i),new $.PublicKey(o),t,r)}return n.isTronLike(e)?y.hinkalCheckTronTokenRegistry(t,r,e):y.hinkalCheckTokenRegistry(this.getContractWithFetcher(e,i.ContractType.HinkalHelperContract),t,r)}getRecipientInfo(){return M.getRecipientInfo(this)}async deposit(e,t,n=!0,r=!1){return S.hinkalDeposit(this,e,t,n,r)}async depositSolana(e,t){return E.hinkalSolanaDeposit(this,e,t)}async depositForOther(e,t,n,r=!0,i=!1){return this.enforceRateLimit(this.depositForOther.name,[e,t,n]),S.hinkalDepositForOther(this,e,t,n,r,i)}async depositSolanaForOther(e,t,n){return this.enforceRateLimit(this.depositSolanaForOther.name,[e,t,n]),E.hinkalSolanaDepositForOther(this,e,t,n)}async depositAndWithdraw(e,t,r,i,a,o,s,c,l=!0){return n.isSolanaLike(p.validateAndGetChainId([e]))?B.hinkalSolanaDepositAndWithdraw(this,e,t,r,i,a,o,s,c):T.hinkalDepositAndWithdraw(this,e,t,r,i,a,o,s,c,l)}async claimUtxo(e,t,r,i){return n.isSolanaLike(p.validateAndGetChainId([e]))?X.hinkalSolanaClaimUtxo(this,e,t,r,i):J.hinkalClaimUtxo(this,e,t,r,i)}async depositAndBridge(e,t,n,r,i,a,o,s=!0){return q.hinkalDepositAndBridge(this,e,t,n,r,i,a,o,s)}async prooflessDeposit(e,t,r,i){return n.isSolanaLike(p.validateAndGetChainId(e))?Y.hinkalSolanaProoflessDeposit(this,e,t,r,i):F.hinkalProoflessDeposit(this,e,t,r,i)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaProgram`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaPublicKey`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,t,r,i,a,o){return n.isSolanaLike(p.validateAndGetChainId(e))?H.hinkalSolanaTransfer(this,e,t,r,i,a,o):ne.hinkalTransfer(this,e,t,r,i,a,o)}async withdraw(e,t,r,i,a,o,s){return n.isSolanaLike(p.validateAndGetChainId(e))?V.hinkalSolanaWithdraw(this,e,t,r,a,o,s):O.hinkalWithdraw(this,e,t,r,i,a,o,s)}async withdrawStuckUtxos(e,t){return Z.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,r,i,a,o,s){return n.isSolanaLike(p.validateAndGetChainId(e))?this.swapSolana(e,t,i,a,o):D.hinkalSwap(this,e,t,r,i,a,o,s)}async swapSolana(e,t,n,r,i){let a=JSON.parse(n),o=BigInt(a.swapperAccountSalt),{instructionLists:s,addressLookupTableAccount:c}=a.data;return U.hinkalSolanaSwap(this,e,t,o,s,c,r,i)}async actionReceive(e,t,r,i,a,o){if(!a)throw Error(`subAccount is required`);return n.isSolanaLike(p.validateAndGetChainId(e))?K.hinkalSolanaProxyShield(this,e[0],t[0],a,void 0,o):P.hinkalActionReceive(this,e,t,r,i,a,o)}async actionPrivateWallet(e,t,n,r,i,a,o,s,c,l,u=!1,d,f,p){return this.enforceRateLimit(this.actionPrivateWallet.name,[e,t,n,r,i,a,o,s,c,p]),j.hinkalPrivateWallet(this,e,t,n,r,i,a,o,s,c,l,u,d,f,p)}async proxySwap(e,t,r,i,a,o,s,c,l=!1,u,d){return n.isSolanaLike(p.validateAndGetChainId(e))?G.hinkalSolanaProxySwap(this,e,t,i,o,r,s,c,d):I.hinkalProxySwap(this,e,t,r,i,a,o,s,c,l,u,d)}async proxyToPrivate(e,t,r,i,a,o,s){return n.isSolanaLike(p.validateAndGetChainId(e))?(this.enforceRateLimit(this.proxyToPrivate.name,[e[0],t[0],r,i]),K.hinkalSolanaProxyShield(this,e[0],t[0],r,i,s)):R.hinkalProxyToPrivate(this,e,t,i,a,o,r,s)}async proxySend(e,t,r,i,a,o,s){let c=p.validateAndGetChainId(e);if(n.isSolanaLike(c))return W.hinkalSolanaProxySend(this,e[0],t[0],r,i,s);let l=C.createTransaferEmporiumOpsBatch(this,c,e.map(e=>e.erc20TokenAddress),t,i),u=e.map((e,n)=>({token:e,amount:-1n*t[n]}));return await this.actionPrivateWallet(c,[],[],[],l,u,r,a,o,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,t,n){return this.enforceRateLimit(this.multiSendPrivateRecipients.name,[e,t,n]),L.hinkalMultiSendPrivateRecipients(this,e,t,n)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}};exports.Hinkal=ie;
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../functions/utils/serialize.utils.cjs`),t=require(`../../constants/vite.constants.cjs`),n=require(`../../constants/chains.constants.cjs`),r=require(`../../types/hinkal.types.cjs`),i=require(`../../types/ethereum-network.types.cjs`),a=require(`../../crypto/poseidon.cjs`),o=require(`../../functions/pre-transaction/solana.cjs`),s=require(`./hinkalCheckSolanaTokenRegistry.cjs`),c=require(`../../functions/web3/functionCalls/accessTokenCalls.cjs`),l=require(`../../error-handling/error-codes.constants.cjs`),u=require(`../../functions/utils/erc20tokenFunctions.cjs`),d=require(`../crypto-keys/keys.cjs`),f=require(`../../API/API.cjs`),p=require(`../../functions/utils/token-check.utils.cjs`),m=require(`../TokenDBs/PrivateTokensDB.cjs`),ee=require(`../../functions/web3/events/getShieldedBalance.cjs`),h=require(`../../constants/kyc.constants.cjs`),g=require(`../../functions/utils/reloadPage.cjs`),te=require(`../../functions/utils/cacheDevice.utils.cjs`),_=require(`../../functions/web3/getContractMetadata.cjs`),v=require(`../../providers/SolanaProviderAdapter.cjs`),y=require(`./hinkalCheckTokenRegistry.cjs`),b=require(`../merkle-tree/MerkleTree.cjs`);require(`../merkle-tree/index.cjs`);const x=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),S=require(`./hinkalDeposit.cjs`),C=require(`../../functions/private-wallet/emporium.helpers.cjs`);require(`../../API/index.cjs`);const w=require(`../../functions/kyc/checkTokenLimitsUSD.cjs`),T=require(`./hinkalDepositAndWithdraw.cjs`),E=require(`./hinkalSolanaDeposit.cjs`),D=require(`./hinkalSwap.cjs`),O=require(`./hinkalWithdraw.cjs`),k=require(`./resetMerkleTrees.cjs`),A=require(`../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs`),j=require(`./hinkalPrivateWallet.cjs`),M=require(`./hinkalGetRecipientInfo.cjs`),N=require(`./hinkalSignSubAccount.cjs`),P=require(`./hinkalActionReceive.cjs`);require(`../TokenDBs/index.cjs`);const F=require(`./hinkalProoflessDeposit.cjs`),I=require(`./hinkalProxySwap.cjs`),L=require(`./hinkalMultiSend.cjs`),ne=require(`./hinkalTransfer.cjs`),R=require(`./hinkalProxyToPrivate.cjs`),z=require(`../../providers/TronProviderAdapter.cjs`),B=require(`./hinkalSolanaDepositAndWithdraw.cjs`),V=require(`./hinkalSolanaWithdraw.cjs`),H=require(`./hinkalSolanaTransfer.cjs`),U=require(`./hinkalSolanaSwap.cjs`),W=require(`./hinkalSolanaProxySend.cjs`),G=require(`./hinkalSolanaProxySwap.cjs`),K=require(`./hinkalSolanaProxyShield.cjs`),q=require(`./hinkalDepositAndBridge.cjs`),J=require(`./hinkalClaimUtxo.cjs`),Y=require(`./hinkalSolanaProoflessDeposit.cjs`),X=require(`./hinkalSolanaClaimUtxo.cjs`),Z=require(`./hinkalWithdrawStuckUtxos.cjs`);let Q=require(`ethers`),$=require(`@solana/web3.js`);var re=class{ethereumProviderAdapter;solanaProviderAdapter;tronProviderAdapter;userKeys;signingMessage=`Login to Hinkal Protocol`;privateTransferSigningMessage=`Login to Hinkal's Private Transfer App`;merkleTreeHinkalByChain={};merkleTreeAccessTokenByChain={};nullifiersByChain={};encryptedOutputsByChain={};commitmentsSnapshotServiceByChain={};nullifierSnapshotServiceByChain={};accessTokenSnapshotServiceByChain={};utxoUtils;lastCallState=new Map;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;constructor(e){this.userKeys=new d.UserKeys(void 0),n.HINKAL_SUPPORTED_CHAINS.forEach(e=>{this.merkleTreeHinkalByChain[e]=b.MerkleTree.create(a.poseidonFunction,0n),this.merkleTreeAccessTokenByChain[e]=b.MerkleTree.create(a.poseidonFunction,0n),this.nullifiersByChain[e]=new Set,this.encryptedOutputsByChain[e]=[]}),this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new A.MultiThreadedUtxoUtils,this.cacheDevice=te.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}enforceRateLimit(t,n,r=1e3){let i=Date.now(),a=e.CustomJSONStringify(n),o=this.lastCallState.get(t);if(o&&o.argsKey===a&&i-o.timestamp<r)throw Error(`${t} was already called with the same arguments`);this.lastCallState.set(t,{timestamp:i,argsKey:a})}getProviderAdapter(e){let t=e;t||=this.ethereumProviderAdapter?n.chainIds.ethMainnet:this.solanaProviderAdapter?n.chainIds.solanaMainnet:n.chainIds.tronMainnet;let r;if(r=n.isSolanaLike(t)?this.solanaProviderAdapter:n.isTronLike(t)?this.tronProviderAdapter:this.ethereumProviderAdapter,!r)throw Error(`ProviderAdapter is not initialized`);return r}async initProviderAdapter(e,t){let r=n.chainIds.ethMainnet;t instanceof v.SolanaProviderAdapter?r=n.chainIds.solanaMainnet:t instanceof z.TronProviderAdapter&&(r=n.currentTronChainId),await this.updateProviderAdapter(r,t),t.initConnector(e);let i=await t.connectAndPatchProvider(e);await t.init(i),await this.setListeners()}getSigningMessage(e=r.LoginMessageMode.PROTOCOL){switch(e){case r.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case r.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async initUserKeys(e=r.LoginMessageMode.PROTOCOL){let t=this.getSigningMessage(e);this.userKeys=new d.UserKeys(await this.getProviderAdapter().signMessage(t))}initUserKeysWithSignature(e){this.userKeys=new d.UserKeys(e)}async initUserKeysFromSeedPhrases(e){let t=e.join(` `),n=Q.ethers.toUtf8Bytes(t),r=Q.ethers.keccak256(n);this.userKeys=new d.UserKeys(r)}async resetMerkle(e){this.disableMerkleTreeUpdates||(e?.every(e=>this.isSelectedNetworkSupported(e))??!0)&&await k.resetMerkleTrees(this,e)}getTronWeb(){let e=this.tronProviderAdapter;if(!e)throw Error(`Tron provider adapter not initialized`);if(!(e instanceof z.TronProviderAdapter))throw Error(`Tron provider adapter is not a TronProviderAdapter`);let t=e.getTronWeb();if(!t)throw Error(`TronWeb not available`);return t}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?n.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>!n.isSolanaLike(e)&&!n.isTronLike(e)):this.solanaProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>n.isSolanaLike(e)):this.tronProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>n.isTronLike(e)):[]}async waitForTransaction(e,t,n=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,t,n)}getContract(e,t,n=void 0){return this.getProviderAdapter(e).getContract(e,t,n)}getContractWithFetcherByChainId(e,t,n=void 0){return _.getContractWithFetcherByChainId(e,t,n)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,n){return await this.getProviderAdapter().signTypedData(e,t,n)}async signWithSubAccount(e,t,n,r){return N.hinkalSignSubAccount(e,t,n,r)}getContractWithSigner(e,t,n=``){return this.getProviderAdapter(e).getContractWithSigner(e,t,n)}getContractWithFetcher(e,t,n=``){return this.getProviderAdapter(e).getContractWithFetcher(e,t,n)}isSelectedNetworkSupported(e){return!!n.networkRegistry[e]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw Error(l.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async disconnectFromConnector(){await this.ethereumProviderAdapter?.disconnectFromConnector(),await this.solanaProviderAdapter?.disconnectFromConnector(),await this.tronProviderAdapter?.disconnectFromConnector()}async resetProviderAdapters(){this.ethereumProviderAdapter=void 0,this.solanaProviderAdapter=void 0,this.tronProviderAdapter=void 0}async updateProviderAdapter(e,t){try{n.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=t):n.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=t):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=t)}catch(e){throw console.error(e),Error(`updateProviderAdapter failed, please try again.`)}}async setListeners(){this.ethereumProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.solanaProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.tronProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.ethereumProviderAdapter?.onAccountChanged(),await this.solanaProviderAdapter?.onAccountChanged(),await this.tronProviderAdapter?.onAccountChanged();let e=r.EventType.AccountChanged;typeof document<`u`?document?.dispatchEvent(new Event(e)):process?.emit(`message`,e,void 0)}async onChainChanged(e){e?await this.getProviderAdapter(e).onChainChanged(e):(await this.disconnectFromConnector(),g.reloadPage())}async monitorConnectedAddress(e){await f.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,t,n,r,i=!1,a,o=!1){return ee.getShieldedBalance(this,e,t,n,r,i,this.generateProofRemotely,a,o)}async getTotalBalance(e,n,r,i=!1,a,o=!1){let s=r??await this.getEthereumAddressByChain(e),c=n??this.userKeys,l=await this.getBalances(e,c.getShieldedPrivateKey(),c.getShieldedPublicKey(),s,i,a,o),d=t.isExtension?await m.privateTokensDB.getPrivateTokens(e,s):u.getErc20TokensForChain(e),f=[];return d.forEach(e=>{let t=e.erc20TokenAddress.toLowerCase(),n=l.get(t),r={token:e,balance:n?.balance??0n,timestamp:n?.timestamp||`0`,nfts:n?.nfts||[]};f.push(r)}),f}async getStuckShieldedBalances(e,t,n,r=!1,i=!1){return(await this.getTotalBalance(e,t,n,r,i,!0)).filter(e=>e.balance>0n)}getSupportedPassportLinks(){return h.supportedPassportLinks}checkAccessToken(e,t){return c.checkHinkalAccessToken(this,e,t)}checkExternalTokenLimitsUSD(e,t,n){return w.checkTokenLimitsUSD(e,t,n)}async getHinkalTreeRootHash(e){if(n.isSolanaLike(e)){let{hinkalIdl:t,hinkalAddress:r,originalDeployer:i}=n.networkRegistry[e].contractData;if(!t||!r||!i)throw Error(`Missing Solana configuration for chain ${e}`);let a=new $.PublicKey(i),s=o.getMerkleAccountPublicKey(new $.PublicKey(r),a);return x.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(t),s)}return this.getContractWithFetcherByChainId(e,i.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(e){if(n.isSolanaLike(e)){let{hinkalIdl:t,hinkalAddress:r,originalDeployer:i}=n.networkRegistry[e].contractData;if(!t||!r||!i)throw Error(`Missing Solana configuration for chain ${e}`);let a=new $.PublicKey(i),s=o.getAccessTokenMerkleAccountPublicKey(new $.PublicKey(r),a);return x.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(t),s)}return this.getContractWithFetcherByChainId(e,i.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(e){let t=(await Promise.all((e??this.getSupportedChains()).map(async e=>{let[t,n]=await Promise.all([this.getHinkalTreeRootHash(e),this.getAccessTokenTreeRootHash(e)]);return{chainId:e,needsReset:BigInt(t)!==this.merkleTreeHinkalByChain[e].getRootHash()||BigInt(n)!==this.merkleTreeAccessTokenByChain[e].getRootHash()}}))).filter(e=>e.needsReset).map(e=>e.chainId);t.length>0&&(console.log(`resetting merkle tree in resetMerkleTreesIfNecessary for chains:`,t),await this.resetMerkle(t))}async getEthereumAddress(){let e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw Error(`No provider adapter initialized`);return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,t=!1){return(await f.API.getIdleRelay(e,t)).relay}getGasPrice(e){let t=this.getProviderAdapter(e);if(!t)throw Error(`Illegal State of providerAdapter in Hinkal: no providerAdapter initialized`);return t.getGasPrice(e)}getAPI(){return f.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.accessTokenSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear()})}checkTokenRegistry(e,t,r){if(n.isSolanaLike(e)){let{hinkalIdl:i,hinkalAddress:a,originalDeployer:o}=n.networkRegistry[e].contractData;if(!i||!a||!o)throw Error(`missing solana data`);return s.hinkalCheckSolanaTokenRegistry(this.getSolanaProgram(i),new $.PublicKey(o),t,r)}return n.isTronLike(e)?y.hinkalCheckTronTokenRegistry(t,r,e):y.hinkalCheckTokenRegistry(this.getContractWithFetcher(e,i.ContractType.HinkalHelperContract),t,r)}getRecipientInfo(){return M.getRecipientInfo(this)}async deposit(e,t,n=!0,r=!1){return S.hinkalDeposit(this,e,t,n,r)}async depositSolana(e,t){return E.hinkalSolanaDeposit(this,e,t)}async depositForOther(e,t,n,r=!0,i=!1){return this.enforceRateLimit(this.depositForOther.name,[e,t,n]),S.hinkalDepositForOther(this,e,t,n,r,i)}async depositSolanaForOther(e,t,n){return this.enforceRateLimit(this.depositSolanaForOther.name,[e,t,n]),E.hinkalSolanaDepositForOther(this,e,t,n)}async depositAndWithdraw(e,t,r,i,a,o,s,c,l=!0){return n.isSolanaLike(p.validateAndGetChainId([e]))?B.hinkalSolanaDepositAndWithdraw(this,e,t,r,i,a,o,s,c):T.hinkalDepositAndWithdraw(this,e,t,r,i,a,o,s,c,l)}async claimUtxo(e,t,r,i){return n.isSolanaLike(p.validateAndGetChainId([e]))?X.hinkalSolanaClaimUtxo(this,e,t,r,i):J.hinkalClaimUtxo(this,e,t,r,i)}async depositAndBridge(e,t,n,r,i,a,o,s=!0){return q.hinkalDepositAndBridge(this,e,t,n,r,i,a,o,s)}async prooflessDeposit(e,t,r,i){return n.isSolanaLike(p.validateAndGetChainId(e))?Y.hinkalSolanaProoflessDeposit(this,e,t,r,i):F.hinkalProoflessDeposit(this,e,t,r,i)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaProgram`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaPublicKey`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,t,r,i,a,o){return n.isSolanaLike(p.validateAndGetChainId(e))?H.hinkalSolanaTransfer(this,e,t,r,i,a,o):ne.hinkalTransfer(this,e,t,r,i,a,o)}async withdraw(e,t,r,i,a,o,s){return n.isSolanaLike(p.validateAndGetChainId(e))?V.hinkalSolanaWithdraw(this,e,t,r,a,o,s):O.hinkalWithdraw(this,e,t,r,i,a,o,s)}async withdrawStuckUtxos(e,t){return Z.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,r,i,a,o,s){return n.isSolanaLike(p.validateAndGetChainId(e))?this.swapSolana(e,t,i,a,o):D.hinkalSwap(this,e,t,r,i,a,o,s)}async swapSolana(e,t,n,r,i){let a=JSON.parse(n),o=BigInt(a.swapperAccountSalt),{instructionLists:s,addressLookupTableAccount:c}=a.data;return U.hinkalSolanaSwap(this,e,t,o,s,c,r,i)}async actionReceive(e,t,r,i,a,o){if(!a)throw Error(`subAccount is required`);return n.isSolanaLike(p.validateAndGetChainId(e))?K.hinkalSolanaProxyShield(this,e[0],t[0],a,void 0,o):P.hinkalActionReceive(this,e,t,r,i,a,o)}async actionPrivateWallet(e,t,n,r,i,a,o,s,c,l,u=!1,d,f,p){return this.enforceRateLimit(this.actionPrivateWallet.name,[e,t,n,r,i,a,o,s,c,p]),j.hinkalPrivateWallet(this,e,t,n,r,i,a,o,s,c,l,u,d,f,p)}async proxySwap(e,t,r,i,a,o,s,c,l=!1,u,d){return n.isSolanaLike(p.validateAndGetChainId(e))?G.hinkalSolanaProxySwap(this,e,t,i,o,r,s,c,d):I.hinkalProxySwap(this,e,t,r,i,a,o,s,c,l,u,d)}async proxyToPrivate(e,t,r,i,a,o,s){return n.isSolanaLike(p.validateAndGetChainId(e))?(this.enforceRateLimit(this.proxyToPrivate.name,[e[0],t[0],r,i]),K.hinkalSolanaProxyShield(this,e[0],t[0],r,i,s)):R.hinkalProxyToPrivate(this,e,t,i,a,o,r,s)}async proxySend(e,t,r,i,a,o,s){let c=p.validateAndGetChainId(e);if(n.isSolanaLike(c))return W.hinkalSolanaProxySend(this,e[0],t[0],r,i,s);let l=C.createTransaferEmporiumOpsBatch(this,c,e.map(e=>e.erc20TokenAddress),t,i),u=e.map((e,n)=>({token:e,amount:-1n*t[n]}));return await this.actionPrivateWallet(c,[],[],[],l,u,r,a,o,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,t,n){return this.enforceRateLimit(this.multiSendPrivateRecipients.name,[e,t,n]),L.hinkalMultiSendPrivateRecipients(this,e,t,n)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}};exports.Hinkal=re;
|
|
@@ -19,7 +19,6 @@ import { Idl, Program } from '@coral-xyz/anchor';
|
|
|
19
19
|
import { PublicKey } from '@solana/web3.js';
|
|
20
20
|
import { BridgeRecipient } from '../../types/bridging-tx.types';
|
|
21
21
|
import { Utxo } from '../utxo/Utxo';
|
|
22
|
-
import { PrivateBalancesState } from '../../types/balances.types';
|
|
23
22
|
export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
24
23
|
private ethereumProviderAdapter?;
|
|
25
24
|
private solanaProviderAdapter?;
|
|
@@ -39,7 +38,6 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
|
39
38
|
cacheDevice: ICacheDevice;
|
|
40
39
|
generateProofRemotely: boolean;
|
|
41
40
|
private disableMerkleTreeUpdates;
|
|
42
|
-
private readonly privateBalances;
|
|
43
41
|
constructor(hinkalConfig?: HinkalConfig);
|
|
44
42
|
private enforceRateLimit;
|
|
45
43
|
getProviderAdapter(chainId?: number): IProviderAdapter<ConnectorType>;
|
|
@@ -72,8 +70,6 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
|
72
70
|
getBalances(chainId: number, passedShieldedPrivateKey: string, passedShieldedPublicKey: string, ethAddress: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean): Promise<Map<string, TokenBalance>>;
|
|
73
71
|
getTotalBalance(chainId: number, _userKeys?: UserKeys, _ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean): Promise<TokenBalance[]>;
|
|
74
72
|
getStuckShieldedBalances(chainId: number, _userKeys?: UserKeys, _ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
|
|
75
|
-
get privateBalancesWithUSD(): PrivateBalancesState;
|
|
76
|
-
onPrivateBalancesWithUSDChange(callback: (state: PrivateBalancesState) => void): () => void;
|
|
77
73
|
getSupportedPassportLinks(): string[];
|
|
78
74
|
checkAccessToken(chainId: number, accessKeyOverride?: string): Promise<boolean>;
|
|
79
75
|
checkExternalTokenLimitsUSD(chainId: number, tokenAddresses: string[], amounts: bigint[]): Promise<boolean>;
|
|
@@ -56,11 +56,10 @@ import { hinkalClaimUtxo as de } from "./hinkalClaimUtxo.mjs";
|
|
|
56
56
|
import { hinkalSolanaProoflessDeposit as Z } from "./hinkalSolanaProoflessDeposit.mjs";
|
|
57
57
|
import { hinkalSolanaClaimUtxo as fe } from "./hinkalSolanaClaimUtxo.mjs";
|
|
58
58
|
import { hinkalWithdrawStuckUtxos as pe } from "./hinkalWithdrawStuckUtxos.mjs";
|
|
59
|
-
import { HinkalPrivateBalanceController as me } from "./HinkalPrivateBalanceController.mjs";
|
|
60
59
|
import { ethers as Q } from "ethers";
|
|
61
60
|
import { PublicKey as $ } from "@solana/web3.js";
|
|
62
61
|
//#region libs/shared/common/src/data-structures/Hinkal/Hinkal.ts
|
|
63
|
-
var
|
|
62
|
+
var me = class {
|
|
64
63
|
ethereumProviderAdapter;
|
|
65
64
|
solanaProviderAdapter;
|
|
66
65
|
tronProviderAdapter;
|
|
@@ -79,7 +78,6 @@ var he = class {
|
|
|
79
78
|
cacheDevice;
|
|
80
79
|
generateProofRemotely;
|
|
81
80
|
disableMerkleTreeUpdates;
|
|
82
|
-
privateBalances = new me(this);
|
|
83
81
|
constructor(e) {
|
|
84
82
|
this.userKeys = new _(void 0), n.forEach((e) => {
|
|
85
83
|
this.merkleTreeHinkalByChain[e] = D.create(f, 0n), this.merkleTreeAccessTokenByChain[e] = D.create(f, 0n), this.nullifiersByChain[e] = /* @__PURE__ */ new Set(), this.encryptedOutputsByChain[e] = [];
|
|
@@ -241,12 +239,6 @@ var he = class {
|
|
|
241
239
|
async getStuckShieldedBalances(e, t, n, r = !1, i = !1) {
|
|
242
240
|
return (await this.getTotalBalance(e, t, n, r, i, !0)).filter((e) => e.balance > 0n);
|
|
243
241
|
}
|
|
244
|
-
get privateBalancesWithUSD() {
|
|
245
|
-
return this.privateBalances.getSnapshot();
|
|
246
|
-
}
|
|
247
|
-
onPrivateBalancesWithUSDChange(e) {
|
|
248
|
-
return this.privateBalances.onPrivateBalancesWithUSDChange(e);
|
|
249
|
-
}
|
|
250
242
|
getSupportedPassportLinks() {
|
|
251
243
|
return b;
|
|
252
244
|
}
|
|
@@ -430,4 +422,4 @@ var he = class {
|
|
|
430
422
|
}
|
|
431
423
|
};
|
|
432
424
|
//#endregion
|
|
433
|
-
export {
|
|
425
|
+
export { me as Hinkal };
|
|
@@ -17,7 +17,6 @@ import { AdminTransactionType } from '../../types/admin.types';
|
|
|
17
17
|
import { Idl, Program } from '@coral-xyz/anchor';
|
|
18
18
|
import { PublicKey } from '@solana/web3.js';
|
|
19
19
|
import { BridgeRecipient } from '../../types/bridging-tx.types';
|
|
20
|
-
import { PrivateBalancesState } from '../../types/balances.types';
|
|
21
20
|
import { Utxo } from '../utxo/Utxo';
|
|
22
21
|
import { TronWeb } from 'tronweb';
|
|
23
22
|
export interface IHinkal<ConnectorType = unknown> {
|
|
@@ -37,8 +36,6 @@ export interface IHinkal<ConnectorType = unknown> {
|
|
|
37
36
|
getBalances(chainId: number, passedShieldedPrivateKey: string, passedShieldedPublicKey: string, ethAddress: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<Map<string, TokenBalance>>;
|
|
38
37
|
getTotalBalance(chainId: number, userKeys?: UserKeys, ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean): Promise<TokenBalance[]>;
|
|
39
38
|
getStuckShieldedBalances(chainId: number, userKeys?: UserKeys, ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
|
|
40
|
-
privateBalancesWithUSD: PrivateBalancesState;
|
|
41
|
-
onPrivateBalancesWithUSDChange(callback: (state: PrivateBalancesState) => void): () => void;
|
|
42
39
|
getSupportedPassportLinks(): string[];
|
|
43
40
|
checkAccessToken(chainId: number, accessKeyOverride?: string): Promise<boolean>;
|
|
44
41
|
checkExternalTokenLimitsUSD(chainId: number, tokenAddresses: string[], amounts: bigint[]): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./
|
|
1
|
+
require(`./activity-db.cjs`),require(`./balances-db.cjs`),require(`./private-balances-db.cjs`),require(`./prices-db.cjs`),require(`./contact-db.cjs`),require(`./signatures-db.cjs`),require(`./pay-activity-db.cjs`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../API/API.cjs`),t=require(`../../functions/utils/string.utils.cjs`)
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../API/API.cjs`),t=require(`../../functions/utils/string.utils.cjs`);let n=require(`idb-keyval`);new class{tokenPricesRecordLabel=`tokenPrices`;async getPrices(){return await(0,n.get)(this.tokenPricesRecordLabel)}async updatePrices(r,i){if(!i.length)return[];let{prices:a}=await e.API.getTokenPrices(r,i);return await(0,n.update)(this.tokenPricesRecordLabel,(e={})=>{let n={...e};return a.forEach((e,a)=>{n[t.getTokenStateKey(i[a],r)]=e}),n}),a}async getAndUpdatePrices(e,n){let r=await this.getPrices(),i=Array(n.length).fill(0);if(!r)i=await this.updatePrices(e,n);else{let a=[],o=[];n.forEach((n,s)=>{let c=t.getTokenStateKey(n,e);r[c]?i[s]=r[c]:(a.push(n),o.push(s))});let s=await this.updatePrices(e,a);o.forEach((e,t)=>{i[e]=s[t]})}return i}async updateCachedPricesByChain(r){let i=await this.getPrices();if(!i||Object.keys(i).length===0)return;let a=Object.entries(i).filter(([e])=>{let[,t]=e.split(`-`);return parseInt(t,10)===r}).map(([e])=>e.split(`-`)[0]);if(a.length===0)return;let{prices:o}=await e.API.getTokenPrices(r,a);await(0,n.update)(this.tokenPricesRecordLabel,(e={})=>{let n={...e};return o.forEach((e,i)=>{let o=t.getTokenStateKey(a[i],r);n[o]=e}),n})}};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { API as e } from "../../API/API.mjs";
|
|
2
2
|
import { getTokenStateKey as t } from "../../functions/utils/string.utils.mjs";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { get as n, update as r } from "idb-keyval";
|
|
4
|
+
new class {
|
|
5
5
|
tokenPricesRecordLabel = "tokenPrices";
|
|
6
6
|
async getPrices() {
|
|
7
|
-
return n
|
|
7
|
+
return await n(this.tokenPricesRecordLabel);
|
|
8
8
|
}
|
|
9
|
-
async updatePrices(
|
|
9
|
+
async updatePrices(n, i) {
|
|
10
10
|
if (!i.length) return [];
|
|
11
|
-
let { prices: a } = await e.getTokenPrices(
|
|
12
|
-
return await
|
|
13
|
-
let
|
|
11
|
+
let { prices: a } = await e.getTokenPrices(n, i);
|
|
12
|
+
return await r(this.tokenPricesRecordLabel, (e = {}) => {
|
|
13
|
+
let r = { ...e };
|
|
14
14
|
return a.forEach((e, a) => {
|
|
15
|
-
|
|
16
|
-
}),
|
|
15
|
+
r[t(i[a], n)] = e;
|
|
16
|
+
}), r;
|
|
17
17
|
}), a;
|
|
18
18
|
}
|
|
19
19
|
async getAndUpdatePrices(e, n) {
|
|
@@ -32,23 +32,22 @@ var r = new class {
|
|
|
32
32
|
}
|
|
33
33
|
return i;
|
|
34
34
|
}
|
|
35
|
-
async updateCachedPricesByChain(
|
|
35
|
+
async updateCachedPricesByChain(n) {
|
|
36
36
|
let i = await this.getPrices();
|
|
37
37
|
if (!i || Object.keys(i).length === 0) return;
|
|
38
38
|
let a = Object.entries(i).filter(([e]) => {
|
|
39
39
|
let [, t] = e.split("-");
|
|
40
|
-
return parseInt(t, 10) ===
|
|
40
|
+
return parseInt(t, 10) === n;
|
|
41
41
|
}).map(([e]) => e.split("-")[0]);
|
|
42
42
|
if (a.length === 0) return;
|
|
43
|
-
let { prices: o } = await e.getTokenPrices(
|
|
44
|
-
await
|
|
45
|
-
let
|
|
43
|
+
let { prices: o } = await e.getTokenPrices(n, a);
|
|
44
|
+
await r(this.tokenPricesRecordLabel, (e = {}) => {
|
|
45
|
+
let r = { ...e };
|
|
46
46
|
return o.forEach((e, i) => {
|
|
47
|
-
let o = t(a[i],
|
|
48
|
-
|
|
49
|
-
}),
|
|
47
|
+
let o = t(a[i], n);
|
|
48
|
+
r[o] = e;
|
|
49
|
+
}), r;
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
}();
|
|
53
53
|
//#endregion
|
|
54
|
-
export { r as pricesStorage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../functions/utils/string.utils.cjs`)
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../functions/utils/string.utils.cjs`);let t=require(`idb-keyval`);new class{balancesRecordLabel=`privateWalletsBalances`;async getBalances(){return await(0,t.get)(this.balancesRecordLabel)}async getBalancesByWallet(t,n){let r=await this.getBalances();if(r)return r[e.getStateKey(t,n,!0)]}async setBalances(n,r,i){await(0,t.update)(this.balancesRecordLabel,(t={})=>{let a=e.getStateKey(n,r,!0);return{...t,[a]:i}})}};
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { getStateKey as e } from "../../functions/utils/string.utils.mjs";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { get as t, update as n } from "idb-keyval";
|
|
3
|
+
new class {
|
|
4
4
|
balancesRecordLabel = "privateWalletsBalances";
|
|
5
5
|
async getBalances() {
|
|
6
|
-
return t
|
|
6
|
+
return await t(this.balancesRecordLabel);
|
|
7
7
|
}
|
|
8
8
|
async getBalancesByWallet(t, n) {
|
|
9
9
|
let r = await this.getBalances();
|
|
10
10
|
if (r) return r[e(t, n, !0)];
|
|
11
11
|
}
|
|
12
|
-
async setBalances(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
async setBalances(t, r, i) {
|
|
13
|
+
await n(this.balancesRecordLabel, (n = {}) => {
|
|
14
|
+
let a = e(t, r, !0);
|
|
15
|
+
return {
|
|
16
|
+
...n,
|
|
17
|
+
[a]: i
|
|
18
|
+
};
|
|
19
|
+
});
|
|
18
20
|
}
|
|
19
21
|
}();
|
|
20
22
|
//#endregion
|
|
21
|
-
export { n as privateBalancesStorage };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PrivateBalanceUpdateEventType } from '../../../types';
|
|
2
|
-
type BalanceChangeListener = (detail
|
|
2
|
+
type BalanceChangeListener = (detail: PrivateBalanceUpdateEventType) => void;
|
|
3
3
|
export declare const subscribeToBalanceChange: (listener: BalanceChangeListener) => (() => void);
|
|
4
4
|
export declare const balanceChangedHandler: (detail: PrivateBalanceUpdateEventType) => void;
|
|
5
5
|
export {};
|
|
@@ -1,26 +1,4 @@
|
|
|
1
1
|
import { UserKeys } from '../data-structures/crypto-keys/keys';
|
|
2
|
-
import { TokenBalanceWithUsdValue } from './token.types';
|
|
3
|
-
export type PrivateBalancesState = Record<number, TokenBalanceWithUsdValue[] | undefined>;
|
|
4
|
-
export type PrivateBalancesAction = {
|
|
5
|
-
type: 'SET_BALANCES';
|
|
6
|
-
chainId: number;
|
|
7
|
-
balances: TokenBalanceWithUsdValue[] | undefined;
|
|
8
|
-
} | {
|
|
9
|
-
type: 'SET_USD_BALANCES';
|
|
10
|
-
chainId: number;
|
|
11
|
-
balances: TokenBalanceWithUsdValue[] | undefined;
|
|
12
|
-
} | {
|
|
13
|
-
type: 'CLEAR_BALANCES';
|
|
14
|
-
chainId?: number;
|
|
15
|
-
} | {
|
|
16
|
-
type: 'SET_LOADING';
|
|
17
|
-
chainId: number;
|
|
18
|
-
newValue: boolean;
|
|
19
|
-
} | {
|
|
20
|
-
type: 'SET_USD_LOADING';
|
|
21
|
-
chainId: number;
|
|
22
|
-
newValue: boolean;
|
|
23
|
-
};
|
|
24
2
|
export declare enum PrivateBalanceUpdateType {
|
|
25
3
|
OnlyCache = "ONLY_CACHE",
|
|
26
4
|
Fresh = "FRESH",
|