@kapa123456789/sdk 0.0.36 → 0.0.37

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.
Files changed (32) hide show
  1. package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
  2. package/common/src/data-structures/Hinkal/Hinkal.d.ts +4 -0
  3. package/common/src/data-structures/Hinkal/Hinkal.mjs +10 -2
  4. package/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.cjs +1 -0
  5. package/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.d.ts +19 -0
  6. package/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.mjs +239 -0
  7. package/common/src/data-structures/Hinkal/IHinkal.d.ts +3 -0
  8. package/common/src/data-structures/Hinkal/index.d.ts +1 -0
  9. package/common/src/data-structures/IndexedDB/index.d.ts +1 -0
  10. package/common/src/data-structures/IndexedDB/key-val-store.cjs +1 -0
  11. package/common/src/data-structures/IndexedDB/key-val-store.d.ts +6 -0
  12. package/common/src/data-structures/IndexedDB/key-val-store.mjs +41 -0
  13. package/common/src/data-structures/IndexedDB/prices-db.cjs +1 -0
  14. package/common/src/data-structures/IndexedDB/prices-db.mjs +54 -0
  15. package/common/src/data-structures/IndexedDB/private-balances-db.cjs +1 -0
  16. package/common/src/data-structures/IndexedDB/private-balances-db.mjs +21 -0
  17. package/common/src/functions/utils/publicBalance.utils.mjs +1 -0
  18. package/common/src/functions/utils/string.utils.cjs +1 -1
  19. package/common/src/functions/utils/string.utils.mjs +10 -7
  20. package/common/src/functions/web3/events/balanceChangedHandler.d.ts +1 -1
  21. package/common/src/types/balances.types.d.ts +22 -0
  22. package/common/src/webworker/package.json +1 -1
  23. package/functions/index.mjs +1 -0
  24. package/functions/integrations/index.mjs +5 -0
  25. package/functions/utils/getFeeStructure.mjs +1 -0
  26. package/functions/utils/index.mjs +1 -0
  27. package/package.json +1 -1
  28. package/services/Hinkal.cjs +1 -1
  29. package/services/Hinkal.d.ts +3 -3
  30. package/services/Hinkal.mjs +9 -7
  31. package/types/IHinkal.d.ts +4 -3
  32. package/types/balances.types.d.ts +1 -1
@@ -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`),x=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),S=require(`./hinkalDeposit.cjs`),C=require(`../../functions/private-wallet/emporium.helpers.cjs`),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`),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;
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`),x=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),S=require(`./hinkalDeposit.cjs`),C=require(`../../functions/private-wallet/emporium.helpers.cjs`),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`),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;
@@ -19,6 +19,7 @@ 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';
22
23
  export declare class Hinkal<ConnectorType> implements IHinkal {
23
24
  private ethereumProviderAdapter?;
24
25
  private solanaProviderAdapter?;
@@ -38,6 +39,7 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
38
39
  cacheDevice: ICacheDevice;
39
40
  generateProofRemotely: boolean;
40
41
  private disableMerkleTreeUpdates;
42
+ private readonly privateBalances;
41
43
  constructor(hinkalConfig?: HinkalConfig);
42
44
  private enforceRateLimit;
43
45
  getProviderAdapter(chainId?: number): IProviderAdapter<ConnectorType>;
@@ -70,6 +72,8 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
70
72
  getBalances(chainId: number, passedShieldedPrivateKey: string, passedShieldedPublicKey: string, ethAddress: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean): Promise<Map<string, TokenBalance>>;
71
73
  getTotalBalance(chainId: number, _userKeys?: UserKeys, _ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean): Promise<TokenBalance[]>;
72
74
  getStuckShieldedBalances(chainId: number, _userKeys?: UserKeys, _ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
75
+ get privateBalancesWithUSD(): PrivateBalancesState;
76
+ onPrivateBalancesWithUSDChange(callback: (state: PrivateBalancesState) => void): () => void;
73
77
  getSupportedPassportLinks(): string[];
74
78
  checkAccessToken(chainId: number, accessKeyOverride?: string): Promise<boolean>;
75
79
  checkExternalTokenLimitsUSD(chainId: number, tokenAddresses: string[], amounts: bigint[]): Promise<boolean>;
@@ -53,10 +53,11 @@ import { hinkalClaimUtxo as de } from "./hinkalClaimUtxo.mjs";
53
53
  import { hinkalSolanaProoflessDeposit as Z } from "./hinkalSolanaProoflessDeposit.mjs";
54
54
  import { hinkalSolanaClaimUtxo as fe } from "./hinkalSolanaClaimUtxo.mjs";
55
55
  import { hinkalWithdrawStuckUtxos as pe } from "./hinkalWithdrawStuckUtxos.mjs";
56
+ import { HinkalPrivateBalanceController as me } from "./HinkalPrivateBalanceController.mjs";
56
57
  import { ethers as Q } from "ethers";
57
58
  import { PublicKey as $ } from "@solana/web3.js";
58
59
  //#region libs/shared/common/src/data-structures/Hinkal/Hinkal.ts
59
- var me = class {
60
+ var he = class {
60
61
  ethereumProviderAdapter;
61
62
  solanaProviderAdapter;
62
63
  tronProviderAdapter;
@@ -75,6 +76,7 @@ var me = class {
75
76
  cacheDevice;
76
77
  generateProofRemotely;
77
78
  disableMerkleTreeUpdates;
79
+ privateBalances = new me(this);
78
80
  constructor(e) {
79
81
  this.userKeys = new _(void 0), n.forEach((e) => {
80
82
  this.merkleTreeHinkalByChain[e] = D.create(f, 0n), this.merkleTreeAccessTokenByChain[e] = D.create(f, 0n), this.nullifiersByChain[e] = /* @__PURE__ */ new Set(), this.encryptedOutputsByChain[e] = [];
@@ -236,6 +238,12 @@ var me = class {
236
238
  async getStuckShieldedBalances(e, t, n, r = !1, i = !1) {
237
239
  return (await this.getTotalBalance(e, t, n, r, i, !0)).filter((e) => e.balance > 0n);
238
240
  }
241
+ get privateBalancesWithUSD() {
242
+ return this.privateBalances.getSnapshot();
243
+ }
244
+ onPrivateBalancesWithUSDChange(e) {
245
+ return this.privateBalances.onPrivateBalancesWithUSDChange(e);
246
+ }
239
247
  getSupportedPassportLinks() {
240
248
  return b;
241
249
  }
@@ -419,4 +427,4 @@ var me = class {
419
427
  }
420
428
  };
421
429
  //#endregion
422
- export { me as Hinkal };
430
+ export { he as Hinkal };
@@ -0,0 +1 @@
1
+ const e=require(`../../types/balances.types.cjs`),t=require(`../../functions/web3/etherFunctions.cjs`),n=require(`../../functions/utils/upToDateState.cjs`),r=require(`../../error-handling/logger.cjs`),i=require(`../../functions/utils/string.utils.cjs`),a=require(`../../functions/utils/token-check.utils.cjs`),o=require(`../../functions/web3/events/balanceChangedHandler.cjs`),s=require(`../IndexedDB/private-balances-db.cjs`),c=require(`../IndexedDB/prices-db.cjs`);var l=(e,t)=>{switch(t.type){case`SET_BALANCES`:{let n=e[t.chainId];if(t.balances===void 0){let n={...e};return delete n[t.chainId],Object.keys(n).length>0?n:{}}if(n===void 0)return{...e,[t.chainId]:t.balances};let r=t.balances,i=r.filter(e=>!n.some(t=>a.isSameERC20Token(e.token,t.token))),o=n.map(e=>({...e,balance:r.find(t=>a.isSameERC20Token(t.token,e.token))?.balance??0n})).filter(e=>e.balance>0n);return o=[...o,...i],{...e,[t.chainId]:o}}case`SET_USD_BALANCES`:{let n=e[t.chainId];if(n===void 0||t.balances===void 0)return e;let r=t.balances,i=n.map(e=>({...e,usdValue:r.find(t=>a.isSameERC20Token(t.token,e.token))?.usdValue??0}));return{...e,[t.chainId]:i}}case`CLEAR_BALANCES`:{if(t.chainId===void 0)return{};let n={...e};return delete n[t.chainId],Object.keys(n).length>0?n:{}}case`SET_LOADING`:{let n=e[t.chainId];if(n===void 0)return e;if(n.length===0&&t.newValue)return{...e,[t.chainId]:void 0};let r=n.map(e=>({...e,isBalanceLoading:t.newValue}));return{...e,[t.chainId]:r}}case`SET_USD_LOADING`:{let n=e[t.chainId];if(n===void 0)return e;let r=n.map(e=>({...e,isUsdValueLoading:t.newValue}));return{...e,[t.chainId]:r}}default:return e}},u=class{privateBalancesState={};privateBalancesListeners=new Set;constructor(e){this.hinkal=e,o.subscribeToBalanceChange(e=>{this.applyRefreshFromBalanceChangeEvent(e).catch(e=>{r.Logger.error(`Private balance refresh from balance change failed:`,e)})})}getSnapshot(){return this.privateBalancesState}onPrivateBalancesWithUSDChange(e){return this.privateBalancesListeners.add(e),()=>this.privateBalancesListeners.delete(e)}async applyRefreshFromBalanceChangeEvent(t){if(!t){await this.refreshInternal(e.PrivateBalanceUpdateType.FreshWithoutLoader);return}let{updateType:n,balanceChangeState:r,chainIdToUpdate:i,resetCacheBefore:a,updateTokensListBefore:o}=t;await this.refreshInternal(n,r,a,o,i)}dispatch(e){this.privateBalancesState=l(this.privateBalancesState,e);let t=this.privateBalancesState;this.privateBalancesListeners.forEach(e=>e(t))}async getAddressAndChain(e){return{ethAdd:e?.ethereumAddress??await this.hinkal.getEthereumAddress(),userKeys:e?.userKeys??this.hinkal.userKeys}}async hasCache(e,t){return await s.privateBalancesStorage.getBalancesByWallet(e,t)!==void 0}async getBalancesWithUsdValues(e,n){try{if(!n)return[];let r=e.map(e=>e.token.erc20TokenAddress);if(!r.length)return[];let i=await c.pricesStorage.getAndUpdatePrices(n,r),a=new Map(r.map((e,t)=>[e,i[t]]));return[...e.map(e=>{try{let n=e.token.erc20TokenAddress,r=a.get(n)??0,i=e.balance,o=Number(t.getAmountInToken(e.token,i))*r;return{...e,usdValue:o}}catch{return{...e,usdValue:0}}})]}catch{return r.Logger.log(`Error fetching private token balances`),[]}}handleCached=async(e,a)=>{try{await n.checkAddressNotUpdated(this.hinkal,e),this.dispatch({type:`SET_BALANCES`,chainId:a,balances:void 0});let r=await s.privateBalancesStorage.getBalancesByWallet(e,a),o=await c.pricesStorage.getPrices();if(await n.checkAddressNotUpdated(this.hinkal,e),!r||(this.dispatch({type:`SET_BALANCES`,chainId:a,balances:r}),!o))return;let l=r.map(e=>{let n=i.getTokenStateKey(e.token.erc20TokenAddress,a);return{...e,usdValue:o[n]?Number(t.getAmountInToken(e.token,e.balance))*o[n]:0}});this.dispatch({type:`SET_USD_BALANCES`,chainId:a,balances:l})}catch(e){r.Logger.error(`Error refreshing cached private balance:`,e)}};handleFresh=async(e,t,i,a,o,c)=>{let l=o;try{await n.checkAddressNotUpdated(this.hinkal,e);let r=await this.hasCache(e,t);await n.checkAddressNotUpdated(this.hinkal,e),l=o||!r,l&&this.dispatch({type:`SET_LOADING`,chainId:t,newValue:!0}),await n.checkAddressNotUpdated(this.hinkal,e),a&&await this.hinkal.resetMerkle([t]);let u=await this.hinkal.getTotalBalance(t,i,e,a,c);await n.checkAddressNotUpdated(this.hinkal,e);let d=u.filter(e=>e.balance>0n);this.dispatch({type:`SET_BALANCES`,chainId:t,balances:d}),await s.privateBalancesStorage.setBalances(e,t,d),await n.checkAddressNotUpdated(this.hinkal,e),l&&(this.dispatch({type:`SET_USD_LOADING`,chainId:t,newValue:!0}),this.dispatch({type:`SET_LOADING`,chainId:t,newValue:!1})),await n.checkAddressNotUpdated(this.hinkal,e);let f=await this.getBalancesWithUsdValues(d,t);await n.checkAddressNotUpdated(this.hinkal,e),f.length>0&&this.dispatch({type:`SET_USD_BALANCES`,chainId:t,balances:f})}catch(e){r.Logger.error(`Error refreshing private balance:`,e)}finally{l&&(this.dispatch({type:`SET_LOADING`,chainId:t,newValue:!1}),this.dispatch({type:`SET_USD_LOADING`,chainId:t,newValue:!1}))}};getSupportedChainsToUpdate(e){let t=this.hinkal.getSupportedChains();return e?t.includes(e)?[e]:[]:t}async refreshInternal(t=e.PrivateBalanceUpdateType.FreshWithoutLoader,n,r=!1,i=!1,a){let{ethAdd:o,userKeys:s}=await this.getAddressAndChain(n);!o||!s?.getShieldedPublicKey()||await Promise.all(this.getSupportedChainsToUpdate(a).map(async n=>{switch(t){case e.PrivateBalanceUpdateType.OnlyCache:await this.handleCached(o,n);break;case e.PrivateBalanceUpdateType.Fresh:await this.handleFresh(o,n,s,r,!0,i);break;case e.PrivateBalanceUpdateType.FreshWithoutLoader:await this.handleFresh(o,n,s,r,!1,i);break;default:break}}))}};exports.HinkalPrivateBalanceController=u;
@@ -0,0 +1,19 @@
1
+ import { PrivateBalancesState } from '../../types/balances.types';
2
+ import { IHinkal } from './IHinkal';
3
+ export declare class HinkalPrivateBalanceController {
4
+ private readonly hinkal;
5
+ private privateBalancesState;
6
+ private readonly privateBalancesListeners;
7
+ constructor(hinkal: IHinkal);
8
+ getSnapshot(): PrivateBalancesState;
9
+ onPrivateBalancesWithUSDChange(callback: (state: PrivateBalancesState) => void): () => void;
10
+ private applyRefreshFromBalanceChangeEvent;
11
+ private dispatch;
12
+ private getAddressAndChain;
13
+ private hasCache;
14
+ private getBalancesWithUsdValues;
15
+ private handleCached;
16
+ private handleFresh;
17
+ private getSupportedChainsToUpdate;
18
+ private refreshInternal;
19
+ }
@@ -0,0 +1,239 @@
1
+ import { PrivateBalanceUpdateType as e } from "../../types/balances.types.mjs";
2
+ import { getAmountInToken as t } from "../../functions/web3/etherFunctions.mjs";
3
+ import { checkAddressNotUpdated as n } from "../../functions/utils/upToDateState.mjs";
4
+ import { Logger as r } from "../../error-handling/logger.mjs";
5
+ import { getTokenStateKey as i } from "../../functions/utils/string.utils.mjs";
6
+ import { isSameERC20Token as a } from "../../functions/utils/token-check.utils.mjs";
7
+ import { subscribeToBalanceChange as o } from "../../functions/web3/events/balanceChangedHandler.mjs";
8
+ import { privateBalancesStorage as s } from "../IndexedDB/private-balances-db.mjs";
9
+ import { pricesStorage as c } from "../IndexedDB/prices-db.mjs";
10
+ //#region libs/shared/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.ts
11
+ var l = (e, t) => {
12
+ switch (t.type) {
13
+ case "SET_BALANCES": {
14
+ let n = e[t.chainId];
15
+ if (t.balances === void 0) {
16
+ let n = { ...e };
17
+ return delete n[t.chainId], Object.keys(n).length > 0 ? n : {};
18
+ }
19
+ if (n === void 0) return {
20
+ ...e,
21
+ [t.chainId]: t.balances
22
+ };
23
+ let r = t.balances, i = r.filter((e) => !n.some((t) => a(e.token, t.token))), o = n.map((e) => ({
24
+ ...e,
25
+ balance: r.find((t) => a(t.token, e.token))?.balance ?? 0n
26
+ })).filter((e) => e.balance > 0n);
27
+ return o = [...o, ...i], {
28
+ ...e,
29
+ [t.chainId]: o
30
+ };
31
+ }
32
+ case "SET_USD_BALANCES": {
33
+ let n = e[t.chainId];
34
+ if (n === void 0 || t.balances === void 0) return e;
35
+ let r = t.balances, i = n.map((e) => ({
36
+ ...e,
37
+ usdValue: r.find((t) => a(t.token, e.token))?.usdValue ?? 0
38
+ }));
39
+ return {
40
+ ...e,
41
+ [t.chainId]: i
42
+ };
43
+ }
44
+ case "CLEAR_BALANCES": {
45
+ if (t.chainId === void 0) return {};
46
+ let n = { ...e };
47
+ return delete n[t.chainId], Object.keys(n).length > 0 ? n : {};
48
+ }
49
+ case "SET_LOADING": {
50
+ let n = e[t.chainId];
51
+ if (n === void 0) return e;
52
+ if (n.length === 0 && t.newValue) return {
53
+ ...e,
54
+ [t.chainId]: void 0
55
+ };
56
+ let r = n.map((e) => ({
57
+ ...e,
58
+ isBalanceLoading: t.newValue
59
+ }));
60
+ return {
61
+ ...e,
62
+ [t.chainId]: r
63
+ };
64
+ }
65
+ case "SET_USD_LOADING": {
66
+ let n = e[t.chainId];
67
+ if (n === void 0) return e;
68
+ let r = n.map((e) => ({
69
+ ...e,
70
+ isUsdValueLoading: t.newValue
71
+ }));
72
+ return {
73
+ ...e,
74
+ [t.chainId]: r
75
+ };
76
+ }
77
+ default: return e;
78
+ }
79
+ }, u = class {
80
+ privateBalancesState = {};
81
+ privateBalancesListeners = /* @__PURE__ */ new Set();
82
+ constructor(e) {
83
+ this.hinkal = e, o((e) => {
84
+ this.applyRefreshFromBalanceChangeEvent(e).catch((e) => {
85
+ r.error("Private balance refresh from balance change failed:", e);
86
+ });
87
+ });
88
+ }
89
+ getSnapshot() {
90
+ return this.privateBalancesState;
91
+ }
92
+ onPrivateBalancesWithUSDChange(e) {
93
+ return this.privateBalancesListeners.add(e), () => this.privateBalancesListeners.delete(e);
94
+ }
95
+ async applyRefreshFromBalanceChangeEvent(t) {
96
+ if (!t) {
97
+ await this.refreshInternal(e.FreshWithoutLoader);
98
+ return;
99
+ }
100
+ let { updateType: n, balanceChangeState: r, chainIdToUpdate: i, resetCacheBefore: a, updateTokensListBefore: o } = t;
101
+ await this.refreshInternal(n, r, a, o, i);
102
+ }
103
+ dispatch(e) {
104
+ this.privateBalancesState = l(this.privateBalancesState, e);
105
+ let t = this.privateBalancesState;
106
+ this.privateBalancesListeners.forEach((e) => e(t));
107
+ }
108
+ async getAddressAndChain(e) {
109
+ return {
110
+ ethAdd: e?.ethereumAddress ?? await this.hinkal.getEthereumAddress(),
111
+ userKeys: e?.userKeys ?? this.hinkal.userKeys
112
+ };
113
+ }
114
+ async hasCache(e, t) {
115
+ return await s.getBalancesByWallet(e, t) !== void 0;
116
+ }
117
+ async getBalancesWithUsdValues(e, n) {
118
+ try {
119
+ if (!n) return [];
120
+ let r = e.map((e) => e.token.erc20TokenAddress);
121
+ if (!r.length) return [];
122
+ let i = await c.getAndUpdatePrices(n, r), a = new Map(r.map((e, t) => [e, i[t]]));
123
+ return [...e.map((e) => {
124
+ try {
125
+ let n = e.token.erc20TokenAddress, r = a.get(n) ?? 0, i = e.balance, o = Number(t(e.token, i)) * r;
126
+ return {
127
+ ...e,
128
+ usdValue: o
129
+ };
130
+ } catch {
131
+ return {
132
+ ...e,
133
+ usdValue: 0
134
+ };
135
+ }
136
+ })];
137
+ } catch {
138
+ return r.log("Error fetching private token balances"), [];
139
+ }
140
+ }
141
+ handleCached = async (e, a) => {
142
+ try {
143
+ await n(this.hinkal, e), this.dispatch({
144
+ type: "SET_BALANCES",
145
+ chainId: a,
146
+ balances: void 0
147
+ });
148
+ let r = await s.getBalancesByWallet(e, a), o = await c.getPrices();
149
+ if (await n(this.hinkal, e), !r || (this.dispatch({
150
+ type: "SET_BALANCES",
151
+ chainId: a,
152
+ balances: r
153
+ }), !o)) return;
154
+ let l = r.map((e) => {
155
+ let n = i(e.token.erc20TokenAddress, a);
156
+ return {
157
+ ...e,
158
+ usdValue: o[n] ? Number(t(e.token, e.balance)) * o[n] : 0
159
+ };
160
+ });
161
+ this.dispatch({
162
+ type: "SET_USD_BALANCES",
163
+ chainId: a,
164
+ balances: l
165
+ });
166
+ } catch (e) {
167
+ r.error("Error refreshing cached private balance:", e);
168
+ }
169
+ };
170
+ handleFresh = async (e, t, i, a, o, c) => {
171
+ let l = o;
172
+ try {
173
+ await n(this.hinkal, e);
174
+ let r = await this.hasCache(e, t);
175
+ await n(this.hinkal, e), l = o || !r, l && this.dispatch({
176
+ type: "SET_LOADING",
177
+ chainId: t,
178
+ newValue: !0
179
+ }), await n(this.hinkal, e), a && await this.hinkal.resetMerkle([t]);
180
+ let u = await this.hinkal.getTotalBalance(t, i, e, a, c);
181
+ await n(this.hinkal, e);
182
+ let d = u.filter((e) => e.balance > 0n);
183
+ this.dispatch({
184
+ type: "SET_BALANCES",
185
+ chainId: t,
186
+ balances: d
187
+ }), await s.setBalances(e, t, d), await n(this.hinkal, e), l && (this.dispatch({
188
+ type: "SET_USD_LOADING",
189
+ chainId: t,
190
+ newValue: !0
191
+ }), this.dispatch({
192
+ type: "SET_LOADING",
193
+ chainId: t,
194
+ newValue: !1
195
+ })), await n(this.hinkal, e);
196
+ let f = await this.getBalancesWithUsdValues(d, t);
197
+ await n(this.hinkal, e), f.length > 0 && this.dispatch({
198
+ type: "SET_USD_BALANCES",
199
+ chainId: t,
200
+ balances: f
201
+ });
202
+ } catch (e) {
203
+ r.error("Error refreshing private balance:", e);
204
+ } finally {
205
+ l && (this.dispatch({
206
+ type: "SET_LOADING",
207
+ chainId: t,
208
+ newValue: !1
209
+ }), this.dispatch({
210
+ type: "SET_USD_LOADING",
211
+ chainId: t,
212
+ newValue: !1
213
+ }));
214
+ }
215
+ };
216
+ getSupportedChainsToUpdate(e) {
217
+ let t = this.hinkal.getSupportedChains();
218
+ return e ? t.includes(e) ? [e] : [] : t;
219
+ }
220
+ async refreshInternal(t = e.FreshWithoutLoader, n, r = !1, i = !1, a) {
221
+ let { ethAdd: o, userKeys: s } = await this.getAddressAndChain(n);
222
+ !o || !s?.getShieldedPublicKey() || await Promise.all(this.getSupportedChainsToUpdate(a).map(async (n) => {
223
+ switch (t) {
224
+ case e.OnlyCache:
225
+ await this.handleCached(o, n);
226
+ break;
227
+ case e.Fresh:
228
+ await this.handleFresh(o, n, s, r, !0, i);
229
+ break;
230
+ case e.FreshWithoutLoader:
231
+ await this.handleFresh(o, n, s, r, !1, i);
232
+ break;
233
+ default: break;
234
+ }
235
+ }));
236
+ }
237
+ };
238
+ //#endregion
239
+ export { u as HinkalPrivateBalanceController };
@@ -17,6 +17,7 @@ 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';
20
21
  import { Utxo } from '../utxo/Utxo';
21
22
  import { TronWeb } from 'tronweb';
22
23
  export interface IHinkal<ConnectorType = unknown> {
@@ -36,6 +37,8 @@ export interface IHinkal<ConnectorType = unknown> {
36
37
  getBalances(chainId: number, passedShieldedPrivateKey: string, passedShieldedPublicKey: string, ethAddress: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<Map<string, TokenBalance>>;
37
38
  getTotalBalance(chainId: number, userKeys?: UserKeys, ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean): Promise<TokenBalance[]>;
38
39
  getStuckShieldedBalances(chainId: number, userKeys?: UserKeys, ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
40
+ privateBalancesWithUSD: PrivateBalancesState;
41
+ onPrivateBalancesWithUSDChange(callback: (state: PrivateBalancesState) => void): () => void;
39
42
  getSupportedPassportLinks(): string[];
40
43
  checkAccessToken(chainId: number, accessKeyOverride?: string): Promise<boolean>;
41
44
  checkExternalTokenLimitsUSD(chainId: number, tokenAddresses: string[], amounts: bigint[]): Promise<boolean>;
@@ -1,4 +1,5 @@
1
1
  export * from './Hinkal';
2
+ export * from './HinkalPrivateBalanceController';
2
3
  export * from './IHinkal';
3
4
  export * from './hinkalDeposit';
4
5
  export * from './hinkalSwap';
@@ -1,3 +1,4 @@
1
+ export * from './key-val-store';
1
2
  export * from './activity-db';
2
3
  export * from './balances-db';
3
4
  export * from './private-balances-db';
@@ -0,0 +1 @@
1
+ const e=require(`../../functions/utils/serialize.utils.cjs`),t=require(`../cacheDevices/FileCacheDevice.cjs`);var n=()=>typeof globalThis<`u`&&`indexedDB`in globalThis&&globalThis.indexedDB!=null,r=class{idbPromise=null;idb(){return this.idbPromise||=import(`idb-keyval`),this.idbPromise}async get(e){let{get:t}=await this.idb();return t(e)}async set(e,t){let{set:n}=await this.idb();await n(e,t)}async update(e,t){let{update:n}=await this.idb(),r;return await n(e,e=>(r=t(e),r)),r}},i=class{device;constructor(){let e=require(`path`);this.device=new t.FileCacheDevice(!0,e.resolve(process.cwd(),`hinkalKeyValCache.json`))}async get(t){let n=this.device.get(t);if(n)return e.CustomJSONParse(n)}async set(t,n){this.device.set(t,e.CustomJSONStringify(n))}async update(e,t){let n=t(await this.get(e));return await this.set(e,n),n}},a=n()?new r:new i;exports.keyValStore=a;
@@ -0,0 +1,6 @@
1
+ export interface IKeyValStore {
2
+ get<T>(key: string): Promise<T | undefined>;
3
+ set<T>(key: string, value: T): Promise<void>;
4
+ update<T>(key: string, updater: (current: T | undefined) => T): Promise<T>;
5
+ }
6
+ export declare const keyValStore: IKeyValStore;
@@ -0,0 +1,41 @@
1
+ import { __require as e } from "../../../../_virtual/_rolldown/runtime.mjs";
2
+ import { CustomJSONParse as t, CustomJSONStringify as n } from "../../functions/utils/serialize.utils.mjs";
3
+ import { FileCacheDevice as r } from "../cacheDevices/FileCacheDevice.mjs";
4
+ //#region libs/shared/common/src/data-structures/IndexedDB/key-val-store.ts
5
+ var i = () => typeof globalThis < "u" && "indexedDB" in globalThis && globalThis.indexedDB != null, a = class {
6
+ idbPromise = null;
7
+ idb() {
8
+ return this.idbPromise ||= import("idb-keyval"), this.idbPromise;
9
+ }
10
+ async get(e) {
11
+ let { get: t } = await this.idb();
12
+ return t(e);
13
+ }
14
+ async set(e, t) {
15
+ let { set: n } = await this.idb();
16
+ await n(e, t);
17
+ }
18
+ async update(e, t) {
19
+ let { update: n } = await this.idb(), r;
20
+ return await n(e, (e) => (r = t(e), r)), r;
21
+ }
22
+ }, o = class {
23
+ device;
24
+ constructor() {
25
+ let t = e("path");
26
+ this.device = new r(!0, t.resolve(process.cwd(), "hinkalKeyValCache.json"));
27
+ }
28
+ async get(e) {
29
+ let n = this.device.get(e);
30
+ if (n) return t(n);
31
+ }
32
+ async set(e, t) {
33
+ this.device.set(e, n(t));
34
+ }
35
+ async update(e, t) {
36
+ let n = t(await this.get(e));
37
+ return await this.set(e, n), n;
38
+ }
39
+ }, s = i() ? new a() : new o();
40
+ //#endregion
41
+ export { s as keyValStore };
@@ -0,0 +1 @@
1
+ const e=require(`../../API/API.cjs`),t=require(`../../functions/utils/string.utils.cjs`),n=require(`./key-val-store.cjs`);var r=new class{tokenPricesRecordLabel=`tokenPrices`;async getPrices(){return n.keyValStore.get(this.tokenPricesRecordLabel)}async updatePrices(r,i){if(!i.length)return[];let{prices:a}=await e.API.getTokenPrices(r,i);return await n.keyValStore.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 n.keyValStore.update(this.tokenPricesRecordLabel,(e={})=>{let n={...e};return o.forEach((e,i)=>{let o=t.getTokenStateKey(a[i],r);n[o]=e}),n})}};exports.pricesStorage=r;
@@ -0,0 +1,54 @@
1
+ import { API as e } from "../../API/API.mjs";
2
+ import { getTokenStateKey as t } from "../../functions/utils/string.utils.mjs";
3
+ import { keyValStore as n } from "./key-val-store.mjs";
4
+ var r = new class {
5
+ tokenPricesRecordLabel = "tokenPrices";
6
+ async getPrices() {
7
+ return n.get(this.tokenPricesRecordLabel);
8
+ }
9
+ async updatePrices(r, i) {
10
+ if (!i.length) return [];
11
+ let { prices: a } = await e.getTokenPrices(r, i);
12
+ return await n.update(this.tokenPricesRecordLabel, (e = {}) => {
13
+ let n = { ...e };
14
+ return a.forEach((e, a) => {
15
+ n[t(i[a], r)] = e;
16
+ }), n;
17
+ }), a;
18
+ }
19
+ async getAndUpdatePrices(e, n) {
20
+ let r = await this.getPrices(), i = Array(n.length).fill(0);
21
+ if (!r) i = await this.updatePrices(e, n);
22
+ else {
23
+ let a = [], o = [];
24
+ n.forEach((n, s) => {
25
+ let c = t(n, e);
26
+ r[c] ? i[s] = r[c] : (a.push(n), o.push(s));
27
+ });
28
+ let s = await this.updatePrices(e, a);
29
+ o.forEach((e, t) => {
30
+ i[e] = s[t];
31
+ });
32
+ }
33
+ return i;
34
+ }
35
+ async updateCachedPricesByChain(r) {
36
+ let i = await this.getPrices();
37
+ if (!i || Object.keys(i).length === 0) return;
38
+ let a = Object.entries(i).filter(([e]) => {
39
+ let [, t] = e.split("-");
40
+ return parseInt(t, 10) === r;
41
+ }).map(([e]) => e.split("-")[0]);
42
+ if (a.length === 0) return;
43
+ let { prices: o } = await e.getTokenPrices(r, a);
44
+ await n.update(this.tokenPricesRecordLabel, (e = {}) => {
45
+ let n = { ...e };
46
+ return o.forEach((e, i) => {
47
+ let o = t(a[i], r);
48
+ n[o] = e;
49
+ }), n;
50
+ });
51
+ }
52
+ }();
53
+ //#endregion
54
+ export { r as pricesStorage };
@@ -0,0 +1 @@
1
+ const e=require(`../../functions/utils/string.utils.cjs`),t=require(`./key-val-store.cjs`);var n=new class{balancesRecordLabel=`privateWalletsBalances`;async getBalances(){return t.keyValStore.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){let a=e.getStateKey(n,r,!0);await t.keyValStore.update(this.balancesRecordLabel,(e={})=>({...e,[a]:i}))}};exports.privateBalancesStorage=n;
@@ -0,0 +1,21 @@
1
+ import { getStateKey as e } from "../../functions/utils/string.utils.mjs";
2
+ import { keyValStore as t } from "./key-val-store.mjs";
3
+ var n = new class {
4
+ balancesRecordLabel = "privateWalletsBalances";
5
+ async getBalances() {
6
+ return t.get(this.balancesRecordLabel);
7
+ }
8
+ async getBalancesByWallet(t, n) {
9
+ let r = await this.getBalances();
10
+ if (r) return r[e(t, n, !0)];
11
+ }
12
+ async setBalances(n, r, i) {
13
+ let a = e(n, r, !0);
14
+ await t.update(this.balancesRecordLabel, (e = {}) => ({
15
+ ...e,
16
+ [a]: i
17
+ }));
18
+ }
19
+ }();
20
+ //#endregion
21
+ export { n as privateBalancesStorage };
@@ -1,5 +1,6 @@
1
1
  import "../../constants/chains.constants.mjs";
2
2
  import { zeroAddress as e } from "../../constants/protocol.constants.mjs";
3
+ import "./erc20tokenFunctions.mjs";
3
4
  import { ERC20ABI as t } from "../../externalABIs/swapAbi.mjs";
4
5
  import { ethers as n } from "ethers";
5
6
  import "@solana/web3.js";
@@ -1 +1 @@
1
- const e=require(`../../constants/chains.constants.cjs`);var t=(t,n,r=!1)=>{let i=`${t}-${n}`;if(r){let{hinkalAddress:t}=e.networkRegistry[n].contractData;return`${i}-${t}`.toLowerCase()}return i.toLowerCase()},n=(e,t,n)=>{if(!t||!n)throw Error(`oldPart and newPart must be provided`);return e.toLowerCase().split(t.toLowerCase()).join(n.toLowerCase())};exports.getStateKey=t,exports.replaceAllInstances=n;
1
+ const e=require(`../../constants/chains.constants.cjs`);var t=(t,n)=>{let r=`${t}-${n}`;return e.isSolanaLike(n)||e.isTronLike(n)?r:r.toLowerCase()},n=(t,n,r=!1)=>{let i=`${t}-${n}`;if(r){let{hinkalAddress:t}=e.networkRegistry[n].contractData;return`${i}-${t}`.toLowerCase()}return i.toLowerCase()},r=(e,t,n)=>{if(!t||!n)throw Error(`oldPart and newPart must be provided`);return e.toLowerCase().split(t.toLowerCase()).join(n.toLowerCase())};exports.getStateKey=n,exports.getTokenStateKey=t,exports.replaceAllInstances=r;
@@ -1,15 +1,18 @@
1
- import { networkRegistry as e } from "../../constants/chains.constants.mjs";
1
+ import { isSolanaLike as e, isTronLike as t, networkRegistry as n } from "../../constants/chains.constants.mjs";
2
2
  //#region libs/shared/common/src/functions/utils/string.utils.ts
3
- var t = (t, n, r = !1) => {
4
- let i = `${t}-${n}`;
3
+ var r = (n, r) => {
4
+ let i = `${n}-${r}`;
5
+ return e(r) || t(r) ? i : i.toLowerCase();
6
+ }, i = (e, t, r = !1) => {
7
+ let i = `${e}-${t}`;
5
8
  if (r) {
6
- let { hinkalAddress: t } = e[n].contractData;
7
- return `${i}-${t}`.toLowerCase();
9
+ let { hinkalAddress: e } = n[t].contractData;
10
+ return `${i}-${e}`.toLowerCase();
8
11
  }
9
12
  return i.toLowerCase();
10
- }, n = (e, t, n) => {
13
+ }, a = (e, t, n) => {
11
14
  if (!t || !n) throw Error("oldPart and newPart must be provided");
12
15
  return e.toLowerCase().split(t.toLowerCase()).join(n.toLowerCase());
13
16
  };
14
17
  //#endregion
15
- export { t as getStateKey, n as replaceAllInstances };
18
+ export { i as getStateKey, r as getTokenStateKey, a as replaceAllInstances };
@@ -1,5 +1,5 @@
1
1
  import { PrivateBalanceUpdateEventType } from '../../../types';
2
- type BalanceChangeListener = (detail: PrivateBalanceUpdateEventType) => void;
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,4 +1,26 @@
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
+ };
2
24
  export declare enum PrivateBalanceUpdateType {
3
25
  OnlyCache = "ONLY_CACHE",
4
26
  Fresh = "FRESH",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapa123456789/sdk",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"
@@ -8,3 +8,4 @@ import "./utils/getErc20Token.mjs";
8
8
  import "./utils/refreshBalance.mjs";
9
9
  import "./utils/index.mjs";
10
10
  import "./integrations/swapApi.mjs";
11
+ import "./integrations/index.mjs";
@@ -0,0 +1,5 @@
1
+ import "../../common/src/functions/web3/odosAPI.mjs";
2
+ import "../../common/src/functions/web3/oneInchAPI.mjs";
3
+ import "../../common/src/functions/web3/lifiAPI.mjs";
4
+ import "../../common/src/functions/web3/okxAPI.mjs";
5
+ import "./swapApi.mjs";
@@ -0,0 +1 @@
1
+ import "../../common/src/functions/pre-transaction/getFeeStructure.mjs";
@@ -1,5 +1,6 @@
1
1
  import "../../common/src/functions/pre-transaction/getFeeStructure.mjs";
2
2
  import "../../common/src/crypto/preProcessing.mjs";
3
+ import "./getFeeStructure.mjs";
3
4
  import "./getErc20Token.mjs";
4
5
  import "./refreshBalance.mjs";
5
6
  import "./preProcessing.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapa123456789/sdk",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"
@@ -1 +1 @@
1
- const e=require(`../common/src/constants/chains.constants.cjs`),t=require(`../common/src/types/hinkal.types.cjs`),n=require(`../common/src/functions/web3/events/balanceChangedHandler.cjs`),r=require(`../common/src/data-structures/Hinkal/Hinkal.cjs`);var i=class{hinkalCommon;constructor(e){this.hinkalCommon=new r.Hinkal(e)}getProviderAdapter(e){return this.hinkalCommon.getProviderAdapter(e)}initProviderAdapter(e,t){return this.hinkalCommon.initProviderAdapter(e,t)}initUserKeys(e=t.LoginMessageMode.PROTOCOL){return this.hinkalCommon.initUserKeys(e)}initUserKeysWithSignature(e){return this.hinkalCommon.initUserKeysWithSignature(e)}initUserKeysFromSeedPhrases(e){return this.hinkalCommon.initUserKeysFromSeedPhrases(e)}resetProviderAdapters(){return this.hinkalCommon.resetProviderAdapters()}disconnectFromConnector(){return this.hinkalCommon.disconnectFromConnector()}signMessage(e){return this.hinkalCommon.signMessage(e)}signTypedData(e,t,n){return this.hinkalCommon.signTypedData(e,t,n)}getSupportedChains(){return this.hinkalCommon.getSupportedChains()}isSelectedNetworkSupported(e){return this.hinkalCommon.isSelectedNetworkSupported(e)}switchNetwork(t){let n=e.networkRegistry[t];if(!n)throw Error(`Network with chainId ${t} not supported`);return this.hinkalCommon.switchNetwork(n)}resetMerkle(e){return this.hinkalCommon.resetMerkle(e)}resetMerkleTreesIfNecessary(e){return this.hinkalCommon.resetMerkleTreesIfNecessary(e)}onBalanceRefresh(e){return n.subscribeToBalanceChange(e)}getTotalBalance(e,t=!1,n=!1){return this.hinkalCommon.getTotalBalance(e,void 0,void 0,t,n)}getStuckShieldedBalances(e,t=!1,n=!1){return this.hinkalCommon.getStuckShieldedBalances(e,void 0,void 0,t,n)}monitorConnectedAddress(e){return this.hinkalCommon.monitorConnectedAddress(e)}getSupportedPassportLinks(){return this.hinkalCommon.getSupportedPassportLinks()}checkAccessToken(e,t){return this.hinkalCommon.checkAccessToken(e,t)}waitForTransaction(e,t,n){return this.hinkalCommon.waitForTransaction(e,t,n)}getSolanaPublicKey(){return this.hinkalCommon.getSolanaPublicKey()}getEthereumAddress(){return this.hinkalCommon.getEthereumAddress()}getEthereumAddressByChain(e){return this.hinkalCommon.getEthereumAddressByChain(e)}getRecipientInfo(){return this.hinkalCommon.getRecipientInfo()}getShieldedPublicKey(){return this.hinkalCommon.userKeys.getShieldedPublicKey()}prooflessDeposit(e,t,n){return this.hinkalCommon.prooflessDeposit(e,t,n)}deposit(e,t,n,r){return this.hinkalCommon.deposit(e,t,n,r)}depositSolana(e,t){return this.hinkalCommon.depositSolana(e,t)}depositForOther(e,t,n,r,i){return this.hinkalCommon.depositForOther(e,t,n,r,i)}depositSolanaForOther(e,t,n){return this.hinkalCommon.depositSolanaForOther(e,t,n)}depositAndWithdraw(e,t,n,r,i,a){return this.hinkalCommon.depositAndWithdraw(e,t,n,r,i,void 0,void 0,void 0,a)}depositAndBridge(e,t,n,r,i){return this.hinkalCommon.depositAndBridge(e,t,n,r,void 0,void 0,void 0,i)}claimUtxo(e,t,n){return this.hinkalCommon.claimUtxo(e,t,n)}transfer(e,t,n,r,i){return this.hinkalCommon.transfer(e,t,n,r,i)}withdraw(e,t,n,r,i,a){return this.hinkalCommon.withdraw(e,t,n,r,i,a)}withdrawStuckUtxos(e,t){return this.hinkalCommon.withdrawStuckUtxos(e,t)}swap(e,t,n,r,i,a){return this.hinkalCommon.swap(e,t,n,r,i,a)}actionPrivateWallet(e,t,n,r,i,a,o,s,c){return this.hinkalCommon.actionPrivateWallet(e,t,n,r,i,a,o,s,c)}proxySwap(e,t,n,r,i,a,o,s){return this.hinkalCommon.proxySwap(e,t,n,r,i,a,o,s)}proxyToPrivate(e,t,n,r,i,a){return this.hinkalCommon.proxyToPrivate(e,t,n,r,i,a)}proxySend(e,t,n,r,i,a){return this.hinkalCommon.proxySend(e,t,n,r,i,a)}};exports.Hinkal=i;
1
+ const e=require(`../common/src/constants/chains.constants.cjs`),t=require(`../common/src/types/hinkal.types.cjs`),n=require(`../common/src/data-structures/Hinkal/Hinkal.cjs`);var r=class{hinkalCommon;constructor(e){this.hinkalCommon=new n.Hinkal(e)}getProviderAdapter(e){return this.hinkalCommon.getProviderAdapter(e)}initProviderAdapter(e,t){return this.hinkalCommon.initProviderAdapter(e,t)}initUserKeys(e=t.LoginMessageMode.PROTOCOL){return this.hinkalCommon.initUserKeys(e)}initUserKeysWithSignature(e){return this.hinkalCommon.initUserKeysWithSignature(e)}initUserKeysFromSeedPhrases(e){return this.hinkalCommon.initUserKeysFromSeedPhrases(e)}resetProviderAdapters(){return this.hinkalCommon.resetProviderAdapters()}disconnectFromConnector(){return this.hinkalCommon.disconnectFromConnector()}signMessage(e){return this.hinkalCommon.signMessage(e)}signTypedData(e,t,n){return this.hinkalCommon.signTypedData(e,t,n)}getSupportedChains(){return this.hinkalCommon.getSupportedChains()}isSelectedNetworkSupported(e){return this.hinkalCommon.isSelectedNetworkSupported(e)}switchNetwork(t){let n=e.networkRegistry[t];if(!n)throw Error(`Network with chainId ${t} not supported`);return this.hinkalCommon.switchNetwork(n)}resetMerkle(e){return this.hinkalCommon.resetMerkle(e)}resetMerkleTreesIfNecessary(e){return this.hinkalCommon.resetMerkleTreesIfNecessary(e)}get privateBalancesWithUSD(){return this.hinkalCommon.privateBalancesWithUSD}onPrivateBalancesWithUSDChange(e){return this.hinkalCommon.onPrivateBalancesWithUSDChange(e)}getTotalBalance(e,t=!1,n=!1){return this.hinkalCommon.getTotalBalance(e,void 0,void 0,t,n)}getStuckShieldedBalances(e,t=!1,n=!1){return this.hinkalCommon.getStuckShieldedBalances(e,void 0,void 0,t,n)}monitorConnectedAddress(e){return this.hinkalCommon.monitorConnectedAddress(e)}getSupportedPassportLinks(){return this.hinkalCommon.getSupportedPassportLinks()}checkAccessToken(e,t){return this.hinkalCommon.checkAccessToken(e,t)}waitForTransaction(e,t,n){return this.hinkalCommon.waitForTransaction(e,t,n)}getSolanaPublicKey(){return this.hinkalCommon.getSolanaPublicKey()}getEthereumAddress(){return this.hinkalCommon.getEthereumAddress()}getEthereumAddressByChain(e){return this.hinkalCommon.getEthereumAddressByChain(e)}getRecipientInfo(){return this.hinkalCommon.getRecipientInfo()}getShieldedPublicKey(){return this.hinkalCommon.userKeys.getShieldedPublicKey()}prooflessDeposit(e,t,n){return this.hinkalCommon.prooflessDeposit(e,t,n)}deposit(e,t,n,r){return this.hinkalCommon.deposit(e,t,n,r)}depositSolana(e,t){return this.hinkalCommon.depositSolana(e,t)}depositForOther(e,t,n,r,i){return this.hinkalCommon.depositForOther(e,t,n,r,i)}depositSolanaForOther(e,t,n){return this.hinkalCommon.depositSolanaForOther(e,t,n)}depositAndWithdraw(e,t,n,r,i,a){return this.hinkalCommon.depositAndWithdraw(e,t,n,r,i,void 0,void 0,void 0,a)}depositAndBridge(e,t,n,r,i){return this.hinkalCommon.depositAndBridge(e,t,n,r,void 0,void 0,void 0,i)}claimUtxo(e,t,n){return this.hinkalCommon.claimUtxo(e,t,n)}transfer(e,t,n,r,i){return this.hinkalCommon.transfer(e,t,n,r,i)}withdraw(e,t,n,r,i,a){return this.hinkalCommon.withdraw(e,t,n,r,i,a)}withdrawStuckUtxos(e,t){return this.hinkalCommon.withdrawStuckUtxos(e,t)}swap(e,t,n,r,i,a){return this.hinkalCommon.swap(e,t,n,r,i,a)}actionPrivateWallet(e,t,n,r,i,a,o,s,c){return this.hinkalCommon.actionPrivateWallet(e,t,n,r,i,a,o,s,c)}proxySwap(e,t,n,r,i,a,o,s){return this.hinkalCommon.proxySwap(e,t,n,r,i,a,o,s)}proxyToPrivate(e,t,n,r,i,a){return this.hinkalCommon.proxyToPrivate(e,t,n,r,i,a)}proxySend(e,t,n,r,i,a){return this.hinkalCommon.proxySend(e,t,n,r,i,a)}};exports.Hinkal=r;
@@ -1,9 +1,8 @@
1
- import { BridgeRecipient, ERC20Token, ExternalActionId, FeeStructure, HinkalConfig, LoginMessageMode, StealthAddressStructure, SubAccount, TokenBalance, TokenChanges } from '../common/src/types';
1
+ import { BridgeRecipient, ERC20Token, ExternalActionId, FeeStructure, HinkalConfig, LoginMessageMode, StealthAddressStructure, SubAccount, TokenBalance, TokenChanges, PrivateBalancesState } from '../common/src/types';
2
2
  import { ethers, TypedDataDomain, TypedDataField } from 'ethers';
3
3
  import { Utxo } from '../common/src/data-structures/utxo/Utxo';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { IHinkal, IProviderAdapter } from '../types';
6
- import { PrivateBalanceUpdateEventType } from '../types/balances.types';
7
6
  export declare class Hinkal<ConnectorType> implements IHinkal<ConnectorType> {
8
7
  private readonly hinkalCommon;
9
8
  constructor(hinkalConfig?: HinkalConfig);
@@ -21,7 +20,8 @@ export declare class Hinkal<ConnectorType> implements IHinkal<ConnectorType> {
21
20
  switchNetwork(chainId: number): Promise<unknown>;
22
21
  resetMerkle(chainIdsToReset?: number[]): Promise<void>;
23
22
  resetMerkleTreesIfNecessary(chainIdsToCheck?: number[]): Promise<void>;
24
- onBalanceRefresh(callback: (detail: PrivateBalanceUpdateEventType) => void | Promise<void>): () => void;
23
+ get privateBalancesWithUSD(): PrivateBalancesState;
24
+ onPrivateBalancesWithUSDChange(callback: (state: PrivateBalancesState) => void): () => void;
25
25
  getTotalBalance(chainId: number, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
26
26
  getStuckShieldedBalances(chainId: number, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
27
27
  monitorConnectedAddress(chainId: number): Promise<void>;
@@ -1,12 +1,11 @@
1
1
  import { networkRegistry as e } from "../common/src/constants/chains.constants.mjs";
2
2
  import { LoginMessageMode as t } from "../common/src/types/hinkal.types.mjs";
3
- import { subscribeToBalanceChange as n } from "../common/src/functions/web3/events/balanceChangedHandler.mjs";
4
- import { Hinkal as r } from "../common/src/data-structures/Hinkal/Hinkal.mjs";
3
+ import { Hinkal as n } from "../common/src/data-structures/Hinkal/Hinkal.mjs";
5
4
  //#region libs/shared/sdk/src/services/Hinkal.ts
6
- var i = class {
5
+ var r = class {
7
6
  hinkalCommon;
8
7
  constructor(e) {
9
- this.hinkalCommon = new r(e);
8
+ this.hinkalCommon = new n(e);
10
9
  }
11
10
  getProviderAdapter(e) {
12
11
  return this.hinkalCommon.getProviderAdapter(e);
@@ -52,8 +51,11 @@ var i = class {
52
51
  resetMerkleTreesIfNecessary(e) {
53
52
  return this.hinkalCommon.resetMerkleTreesIfNecessary(e);
54
53
  }
55
- onBalanceRefresh(e) {
56
- return n(e);
54
+ get privateBalancesWithUSD() {
55
+ return this.hinkalCommon.privateBalancesWithUSD;
56
+ }
57
+ onPrivateBalancesWithUSDChange(e) {
58
+ return this.hinkalCommon.onPrivateBalancesWithUSDChange(e);
57
59
  }
58
60
  getTotalBalance(e, t = !1, n = !1) {
59
61
  return this.hinkalCommon.getTotalBalance(e, void 0, void 0, t, n);
@@ -138,4 +140,4 @@ var i = class {
138
140
  }
139
141
  };
140
142
  //#endregion
141
- export { i as Hinkal };
143
+ export { r as Hinkal };
@@ -1,9 +1,8 @@
1
- import { BridgeRecipient, ERC20Token, ExternalActionId, FeeStructure, LoginMessageMode, StealthAddressStructure, SubAccount, TokenBalance, TokenChanges } from '../common/src/types';
1
+ import { PrivateBalancesState, BridgeRecipient, ERC20Token, ExternalActionId, FeeStructure, LoginMessageMode, StealthAddressStructure, SubAccount, TokenBalance, TokenChanges } from '../common/src/types';
2
2
  import { ethers, TypedDataDomain, TypedDataField } from 'ethers';
3
3
  import { Utxo } from '../common/src/data-structures/utxo/Utxo';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { IProviderAdapter } from './IProviderAdapter';
6
- import { PrivateBalanceUpdateEventType } from './balances.types';
7
6
  export interface IHinkal<ConnectorType = unknown> {
8
7
  getProviderAdapter(chainId?: number): IProviderAdapter;
9
8
  initProviderAdapter(connector: ConnectorType, providerAdapter: IProviderAdapter<ConnectorType>): Promise<void>;
@@ -19,7 +18,9 @@ export interface IHinkal<ConnectorType = unknown> {
19
18
  switchNetwork(chainId: number): Promise<unknown>;
20
19
  resetMerkle(chainIdsToReset?: number[]): Promise<void>;
21
20
  resetMerkleTreesIfNecessary(chainIdsToCheck?: number[]): Promise<void>;
22
- onBalanceRefresh(callback: (detail: PrivateBalanceUpdateEventType) => void | Promise<void>): () => void;
21
+ privateBalancesWithUSD: PrivateBalancesState;
22
+ /** Returns unsubscribe. Multiple listeners supported. */
23
+ onPrivateBalancesWithUSDChange(callback: (state: PrivateBalancesState) => void): () => void;
23
24
  getTotalBalance(chainId: number, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
24
25
  getStuckShieldedBalances(chainId: number, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<TokenBalance[]>;
25
26
  monitorConnectedAddress(chainId: number): Promise<void>;
@@ -1,4 +1,4 @@
1
1
  import { PrivateBalanceUpdateEventType as CommonPrivateBalanceUpdateEventType } from '../common/src/types';
2
2
  export { PrivateBalanceUpdateType } from '../common/src/types';
3
- export type { TokenBalance } from '../common/src/types';
3
+ export type { PrivateBalancesState, TokenBalance } from '../common/src/types';
4
4
  export type PrivateBalanceUpdateEventType = Omit<CommonPrivateBalanceUpdateEventType, 'balanceChangeState'>;