@hinkal/common 0.2.19 → 0.2.21
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/API/API.cjs +1 -1
- package/API/API.d.ts +6 -1
- package/API/API.mjs +48 -41
- package/API/enclaveCalls.cjs +1 -1
- package/API/enclaveCalls.mjs +5 -4
- package/API/index.d.ts +1 -0
- package/API/proxyAccountsCalls.cjs +1 -1
- package/API/proxyAccountsCalls.d.ts +7 -2
- package/API/proxyAccountsCalls.mjs +26 -20
- package/API/temporaryWalletCalls.cjs +1 -0
- package/API/temporaryWalletCalls.d.ts +13 -0
- package/API/temporaryWalletCalls.mjs +20 -0
- package/API/unspent-utxos-calls.cjs +1 -1
- package/API/unspent-utxos-calls.d.ts +1 -1
- package/API/unspent-utxos-calls.mjs +16 -14
- package/README.md +36 -13
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.d.ts +1 -1
- package/constants/chains.constants.mjs +69 -51
- package/constants/deploy-data/deploy-data-solana.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-solana.json.mjs +28 -2
- package/constants/kyc.constants.cjs +1 -1
- package/constants/kyc.constants.mjs +39 -40
- package/constants/mediaUrls.constants.cjs +1 -1
- package/constants/mediaUrls.constants.d.ts +1 -0
- package/constants/mediaUrls.constants.mjs +2 -1
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.d.ts +6 -1
- package/constants/server.constants.mjs +37 -32
- package/constants/token-data/polygonRegistry.json.cjs +1 -1
- package/constants/token-data/polygonRegistry.json.mjs +4 -4
- package/constants/token-data/polygonRegistryFixed.json.cjs +1 -1
- package/constants/token-data/polygonRegistryFixed.json.mjs +4 -4
- package/data-structures/AccountActions/AccountActions.cjs +1 -0
- package/data-structures/AccountActions/AccountActions.d.ts +18 -0
- package/data-structures/AccountActions/AccountActions.mjs +78 -0
- package/data-structures/AccountActions/index.d.ts +1 -0
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +68 -71
- package/data-structures/BlockchainEvent/BlockchainEvent.cjs +1 -0
- package/data-structures/BlockchainEvent/BlockchainEvent.d.ts +14 -0
- package/data-structures/BlockchainEvent/BlockchainEvent.mjs +41 -0
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +14 -8
- package/data-structures/Hinkal/Hinkal.mjs +215 -179
- package/data-structures/Hinkal/IHinkal.d.ts +9 -6
- package/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
- package/data-structures/Hinkal/handleAutoDepositBack.mjs +47 -48
- package/data-structures/Hinkal/hinkalActionReceive.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionReceive.mjs +25 -22
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.cjs +1 -1
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.mjs +12 -12
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +63 -63
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +60 -147
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -0
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +4 -0
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +103 -0
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -0
- package/data-structures/Hinkal/hinkalDepostAndBridge.d.ts +4 -0
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +214 -0
- package/data-structures/Hinkal/hinkalGetZkMeProvider.cjs +1 -1
- package/data-structures/Hinkal/hinkalGetZkMeProvider.mjs +4 -4
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.d.ts +2 -2
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +103 -99
- package/data-structures/Hinkal/hinkalProxySwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalProxySwap.mjs +44 -41
- package/data-structures/Hinkal/hinkalProxyToPrivate.cjs +1 -1
- package/data-structures/Hinkal/hinkalProxyToPrivate.mjs +31 -28
- package/data-structures/Hinkal/hinkalSignSubAccount.cjs +1 -1
- package/data-structures/Hinkal/hinkalSignSubAccount.mjs +16 -13
- package/data-structures/Hinkal/hinkalSolanaDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDeposit.mjs +34 -34
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +67 -65
- package/data-structures/Hinkal/hinkalSolanaProxySend.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxySend.mjs +35 -32
- package/data-structures/Hinkal/hinkalSolanaProxyShield.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxyShield.mjs +59 -56
- package/data-structures/Hinkal/hinkalSolanaProxySwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxySwap.mjs +35 -32
- package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaSwap.mjs +10 -10
- package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +25 -25
- package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +34 -30
- package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalTransfer.mjs +43 -39
- package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.mjs +47 -43
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +50 -46
- package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/data-structures/Hinkal/resetMerkleTrees.mjs +36 -34
- package/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/data-structures/IndexedDB/activity-db.d.ts +1 -0
- package/data-structures/IndexedDB/activity-db.mjs +86 -70
- package/data-structures/IndexedDB/balances-db.cjs +1 -1
- package/data-structures/IndexedDB/balances-db.mjs +33 -30
- package/data-structures/IndexedDB/contact-db.cjs +1 -1
- package/data-structures/IndexedDB/contact-db.mjs +9 -6
- package/data-structures/PublicBalance/PublicBalanceWatcher.cjs +1 -0
- package/data-structures/PublicBalance/PublicBalanceWatcher.d.ts +20 -0
- package/data-structures/PublicBalance/PublicBalanceWatcher.mjs +124 -0
- package/data-structures/PublicBalance/SolanaPublicBalancerWatcher.cjs +1 -0
- package/data-structures/PublicBalance/SolanaPublicBalancerWatcher.d.ts +15 -0
- package/data-structures/PublicBalance/SolanaPublicBalancerWatcher.mjs +64 -0
- package/data-structures/PublicBalance/index.d.ts +2 -0
- package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +77 -78
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.d.ts +0 -11
- package/data-structures/crypto-keys/keys.mjs +47 -107
- package/data-structures/event-service/evm/AbstractAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractAccessTokenSnapshotService.d.ts +3 -2
- package/data-structures/event-service/evm/AbstractAccessTokenSnapshotService.mjs +9 -9
- package/data-structures/event-service/evm/AbstractApprovalsSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractApprovalsSnapshotService.d.ts +3 -2
- package/data-structures/event-service/evm/AbstractApprovalsSnapshotService.mjs +5 -5
- package/data-structures/event-service/evm/AbstractCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractCommitmentsSnapshotService.d.ts +3 -2
- package/data-structures/event-service/evm/AbstractCommitmentsSnapshotService.mjs +6 -6
- package/data-structures/event-service/evm/AbstractEventService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractEventService.d.ts +3 -2
- package/data-structures/event-service/evm/AbstractEventService.mjs +16 -19
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.d.ts +3 -3
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.mjs +6 -5
- package/data-structures/event-service/evm/AbstractSnapshotService.d.ts +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.d.ts +7 -4
- package/data-structures/event-service/evm/BlockchainEventEmitter.mjs +35 -34
- package/data-structures/event-service/evm/ClientBlockchainEventEmitter.cjs +1 -0
- package/data-structures/event-service/evm/ClientBlockchainEventEmitter.d.ts +11 -0
- package/data-structures/event-service/evm/ClientBlockchainEventEmitter.mjs +21 -0
- package/data-structures/event-service/evm/PollingBlockchainEventEmitter.cjs +1 -0
- package/data-structures/event-service/evm/PollingBlockchainEventEmitter.d.ts +6 -0
- package/data-structures/event-service/evm/PollingBlockchainEventEmitter.mjs +16 -0
- package/data-structures/event-service/helpers/ClientEventHelper.cjs +1 -0
- package/data-structures/event-service/helpers/ClientEventHelper.d.ts +11 -0
- package/data-structures/event-service/helpers/ClientEventHelper.mjs +26 -0
- package/data-structures/event-service/helpers/PollingEventHelper.cjs +1 -0
- package/data-structures/event-service/helpers/PollingEventHelper.d.ts +5 -0
- package/data-structures/event-service/helpers/PollingEventHelper.mjs +14 -0
- package/data-structures/event-service/index.d.ts +4 -0
- package/data-structures/event-service/solana/AbstractSolanaAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaAccessTokenSnapshotService.d.ts +3 -2
- package/data-structures/event-service/solana/AbstractSolanaAccessTokenSnapshotService.mjs +6 -6
- package/data-structures/event-service/solana/AbstractSolanaCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaCommitmentsSnapshotService.d.ts +4 -3
- package/data-structures/event-service/solana/AbstractSolanaCommitmentsSnapshotService.mjs +8 -8
- package/data-structures/event-service/solana/AbstractSolanaEventService.cjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaEventService.d.ts +3 -10
- package/data-structures/event-service/solana/AbstractSolanaEventService.mjs +5 -5
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.d.ts +3 -2
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.mjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaSnapshotService.d.ts +1 -1
- package/data-structures/event-service/solana/ClientSolanaBlockchainEventEmitter.cjs +1 -0
- package/data-structures/event-service/solana/ClientSolanaBlockchainEventEmitter.d.ts +11 -0
- package/data-structures/event-service/solana/ClientSolanaBlockchainEventEmitter.mjs +22 -0
- package/data-structures/event-service/solana/PollingSolanaBlockchainEventEmitter.cjs +1 -0
- package/data-structures/event-service/solana/PollingSolanaBlockchainEventEmitter.d.ts +6 -0
- package/data-structures/event-service/solana/PollingSolanaBlockchainEventEmitter.mjs +16 -0
- package/data-structures/event-service/solana/SolanaBlockchainEventEmitter.cjs +1 -1
- package/data-structures/event-service/solana/SolanaBlockchainEventEmitter.d.ts +8 -14
- package/data-structures/event-service/solana/SolanaBlockchainEventEmitter.mjs +68 -67
- package/data-structures/index.d.ts +3 -0
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.mjs +5 -2
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.mjs +5 -2
- package/data-structures/snapshot/evm-snapshots/ClientCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientCommitmentsSnapshotService.mjs +5 -2
- package/data-structures/snapshot/evm-snapshots/ClientNullifierSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientNullifierSnapshotService.mjs +5 -2
- package/data-structures/snapshot/solana-snapshots/ClientSolanaAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/solana-snapshots/ClientSolanaAccessTokenSnapshotService.mjs +5 -2
- package/data-structures/snapshot/solana-snapshots/ClientSolanaCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/solana-snapshots/ClientSolanaCommitmentsSnapshotService.mjs +5 -2
- package/data-structures/snapshot/solana-snapshots/ClientSolanaNullifierSnapshotService.cjs +1 -1
- package/data-structures/snapshot/solana-snapshots/ClientSolanaNullifierSnapshotService.mjs +5 -2
- package/data-structures/utxo/Utxo.cjs +1 -1
- package/data-structures/utxo/Utxo.d.ts +1 -0
- package/data-structures/utxo/Utxo.mjs +18 -4
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.mjs +2 -2
- package/functions/pre-transaction/getSolanaCalldataHash.cjs +1 -1
- package/functions/pre-transaction/getSolanaCalldataHash.mjs +22 -22
- package/functions/pre-transaction/sendV0Transaction.cjs +1 -1
- package/functions/pre-transaction/sendV0Transaction.mjs +53 -50
- package/functions/pre-transaction/solana.cjs +1 -1
- package/functions/pre-transaction/solana.mjs +93 -93
- package/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.helpers.d.ts +3 -2
- package/functions/private-wallet/emporium.helpers.mjs +118 -93
- package/functions/snarkjs/constructEmporiumProof.cjs +1 -1
- package/functions/snarkjs/constructEmporiumProof.d.ts +1 -2
- package/functions/snarkjs/constructEmporiumProof.mjs +89 -89
- package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/functions/snarkjs/constructSolanaZkProof.mjs +6 -2
- package/functions/utils/bytes32.utils.cjs +1 -1
- package/functions/utils/bytes32.utils.mjs +8 -7
- package/functions/utils/create-provider.cjs +1 -1
- package/functions/utils/create-provider.d.ts +1 -1
- package/functions/utils/create-provider.mjs +13 -9
- package/functions/utils/index.d.ts +0 -1
- package/functions/utils/prepareHinkal.cjs +1 -1
- package/functions/utils/prepareHinkal.d.ts +6 -7
- package/functions/utils/prepareHinkal.mjs +45 -53
- package/functions/utils/publicBalance.utils.cjs +1 -1
- package/functions/utils/publicBalance.utils.mjs +49 -54
- package/functions/utils/socket.utils.cjs +1 -0
- package/functions/utils/socket.utils.d.ts +1 -0
- package/functions/utils/socket.utils.mjs +12 -0
- package/functions/utils/string.utils.cjs +1 -1
- package/functions/utils/string.utils.d.ts +1 -0
- package/functions/utils/string.utils.mjs +18 -14
- package/functions/utils/walletBalances.utils.cjs +1 -1
- package/functions/utils/walletBalances.utils.d.ts +1 -1
- package/functions/utils/walletBalances.utils.mjs +4 -4
- package/functions/web3/crypto.cjs +1 -0
- package/functions/web3/crypto.d.ts +1 -0
- package/functions/web3/crypto.mjs +7 -0
- package/functions/web3/events/getApprovedBalance.cjs +1 -1
- package/functions/web3/events/getApprovedBalance.mjs +14 -14
- package/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/functions/web3/events/getInputUtxoAndBalance.mjs +61 -59
- package/functions/web3/events/getTransactionLogEvents.cjs +1 -1
- package/functions/web3/events/getTransactionLogEvents.mjs +32 -32
- package/functions/web3/fetchSolanaMerkleTreeRootHash.cjs +1 -1
- package/functions/web3/fetchSolanaMerkleTreeRootHash.mjs +6 -3
- package/functions/web3/functionCalls/approveToken.cjs +1 -1
- package/functions/web3/functionCalls/approveToken.mjs +17 -17
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +16 -16
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +13 -11
- package/functions/web3/getContractMetadata.cjs +1 -1
- package/functions/web3/getContractMetadata.mjs +17 -22
- package/functions/web3/getTokenHolder.cjs +1 -1
- package/functions/web3/getTokenHolder.mjs +20 -20
- package/functions/web3/index.d.ts +1 -0
- package/index.cjs +1 -1
- package/index.mjs +913 -890
- package/package.json +3 -2
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.mjs +2 -5
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +11 -4
- package/providers/prepareWagmiHinkal.cjs +1 -1
- package/providers/prepareWagmiHinkal.mjs +11 -4
- package/types/activities.types.d.ts +2 -0
- package/types/bridging-tx.types.d.ts +17 -0
- package/types/cache.types.cjs +1 -1
- package/types/cache.types.d.ts +5 -1
- package/types/cache.types.mjs +1 -1
- package/types/ethereum-network.types.d.ts +1 -0
- package/types/events.types.cjs +1 -0
- package/types/events.types.d.ts +9 -0
- package/types/events.types.mjs +5 -0
- package/types/index.d.ts +2 -0
- package/types/proxy.types.d.ts +11 -4
- package/types/sandbox.types.d.ts +2 -0
- package/types/solana.types.d.ts +8 -0
- package/types/token.types.d.ts +5 -0
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
- package/functions/kyc/authentoHelper.cjs +0 -1
- package/functions/kyc/authentoHelper.d.ts +0 -12
- package/functions/kyc/authentoHelper.mjs +0 -30
- package/functions/utils/get-hinkal-approvals.cjs +0 -1
- package/functions/utils/get-hinkal-approvals.d.ts +0 -3
- package/functions/utils/get-hinkal-approvals.mjs +0 -38
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { get as
|
|
1
|
+
import { get as N, update as l } from "idb-keyval";
|
|
2
2
|
import { BigNumber as T } from "ethers";
|
|
3
3
|
import "../../types/circom-data.types.mjs";
|
|
4
|
-
import { solanaNativeAddress as
|
|
4
|
+
import { solanaNativeAddress as C, zeroAddress as q } from "../../constants/protocol.constants.mjs";
|
|
5
5
|
import "../../types/transactions.types.mjs";
|
|
6
6
|
import { ActivityStatus as f } from "../../types/activities.types.mjs";
|
|
7
|
-
import { StorageKeys as
|
|
7
|
+
import { StorageKeys as c } from "../../types/cache.types.mjs";
|
|
8
8
|
import "../../constants/token-data/index.mjs";
|
|
9
|
-
import { isSolanaLike as
|
|
9
|
+
import { isSolanaLike as H } from "../../constants/chains.constants.mjs";
|
|
10
10
|
import "../../constants/contracts.constants.mjs";
|
|
11
11
|
import "../../constants/kyc.constants.mjs";
|
|
12
12
|
import "../../constants/server.constants.mjs";
|
|
@@ -21,118 +21,134 @@ import "../../constants/tasks.constants.mjs";
|
|
|
21
21
|
import "../../constants/events.constants.mjs";
|
|
22
22
|
import "@coral-xyz/anchor";
|
|
23
23
|
import "@solana/web3.js";
|
|
24
|
-
import { fixDecimalsAmount as
|
|
24
|
+
import { fixDecimalsAmount as _ } from "../../functions/utils/amounts.utils.mjs";
|
|
25
25
|
import "circomlibjs-hinkal-fork";
|
|
26
26
|
import "../http/HttpClient.mjs";
|
|
27
|
-
import { Logger as
|
|
28
|
-
import { getERC20Token as
|
|
27
|
+
import { Logger as b } from "../../error-handling/logger.mjs";
|
|
28
|
+
import { getERC20Token as E } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
29
29
|
import "../../functions/utils/convertIntegrationProviderToExternalActionId.mjs";
|
|
30
|
-
import { getAmountInToken as
|
|
30
|
+
import { getAmountInToken as R } from "../../functions/web3/etherFunctions.mjs";
|
|
31
31
|
import "../crypto-keys/keys.mjs";
|
|
32
32
|
import "../../error-handling/error-codes.constants.mjs";
|
|
33
33
|
import "../../API/getServerURL.mjs";
|
|
34
34
|
import "axios";
|
|
35
35
|
import "@solana/spl-token";
|
|
36
|
+
import "ethers-v6h";
|
|
37
|
+
import "tweetnacl";
|
|
38
|
+
import "bs58";
|
|
39
|
+
import "buffer";
|
|
36
40
|
import "../../functions/utils/userAgent.mjs";
|
|
37
41
|
import "libsodium-wrappers";
|
|
38
42
|
import "multiformats";
|
|
39
|
-
import { API as
|
|
43
|
+
import { API as F } from "../../API/API.mjs";
|
|
40
44
|
import "async-mutex";
|
|
41
|
-
import "../../API/tenderly.api.mjs";
|
|
42
45
|
import "process";
|
|
43
|
-
import "buffer";
|
|
44
46
|
import "../../providers/EthersProviderAdapter.mjs";
|
|
45
|
-
import "
|
|
47
|
+
import "../../functions/web3/events/getInputUtxoAndBalance.mjs";
|
|
46
48
|
import "../../functions/web3/events/getApprovedBalance.mjs";
|
|
47
49
|
import "../../functions/web3/getTokenHolder.mjs";
|
|
48
|
-
import "
|
|
49
|
-
class
|
|
50
|
+
import "node-forge";
|
|
51
|
+
class V {
|
|
50
52
|
generateTxId() {
|
|
51
53
|
const t = (/* @__PURE__ */ new Date()).getTime(), o = Math.random().toString(36).substring(2, 15);
|
|
52
54
|
return `tx_${t}_${o}`;
|
|
53
55
|
}
|
|
54
56
|
async getTransactionRecord() {
|
|
55
|
-
return await
|
|
57
|
+
return await N(c.TX_ACTIVITY) || {};
|
|
56
58
|
}
|
|
57
59
|
async saveTxRequest(t) {
|
|
58
60
|
const {
|
|
59
61
|
from: o,
|
|
60
62
|
to: r,
|
|
61
|
-
gas:
|
|
63
|
+
gas: e,
|
|
62
64
|
gasPrice: a,
|
|
63
65
|
gasInDollar: s,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
extraNativeTokenFee: n,
|
|
67
|
+
value: m,
|
|
68
|
+
chainId: i,
|
|
69
|
+
status: d,
|
|
70
|
+
txHash: p,
|
|
71
|
+
activityType: u,
|
|
72
|
+
tokensReceive: I,
|
|
73
|
+
tokensSpend: w,
|
|
74
|
+
tokensApprove: x,
|
|
75
|
+
ownerPublicAddress: h,
|
|
76
|
+
activityIcon: y,
|
|
77
|
+
dappUrl: A,
|
|
78
|
+
dappName: D,
|
|
79
|
+
integrationProvider: S,
|
|
80
|
+
knownPartialSignature: k
|
|
81
|
+
} = t, g = this.generateTxId(), P = {
|
|
82
|
+
id: g,
|
|
79
83
|
from: o,
|
|
80
84
|
to: r,
|
|
81
|
-
gas:
|
|
85
|
+
gas: e,
|
|
82
86
|
gasPrice: a,
|
|
83
87
|
gasInDollar: s?.toString(),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
extraNativeTokenFee: n?.toString(),
|
|
89
|
+
value: m,
|
|
90
|
+
chainId: i,
|
|
91
|
+
txHash: p,
|
|
92
|
+
activityType: u,
|
|
93
|
+
status: d ?? f.PENDING,
|
|
89
94
|
timestamp: /* @__PURE__ */ new Date(),
|
|
90
|
-
tokensReceive:
|
|
91
|
-
tokensSpend:
|
|
92
|
-
tokensApprove:
|
|
93
|
-
ownerPublicAddress:
|
|
94
|
-
activityIcon:
|
|
95
|
-
dappUrl:
|
|
96
|
-
dappName:
|
|
97
|
-
integrationProvider:
|
|
95
|
+
tokensReceive: I,
|
|
96
|
+
tokensSpend: w,
|
|
97
|
+
tokensApprove: x,
|
|
98
|
+
ownerPublicAddress: h,
|
|
99
|
+
activityIcon: y,
|
|
100
|
+
dappUrl: A,
|
|
101
|
+
dappName: D,
|
|
102
|
+
integrationProvider: S,
|
|
103
|
+
knownPartialSignature: k
|
|
98
104
|
};
|
|
99
|
-
return await
|
|
105
|
+
return await l(c.TX_ACTIVITY, (v = {}) => (v[g] = P, v)), g;
|
|
100
106
|
}
|
|
101
107
|
async getTxRequest(t) {
|
|
102
108
|
return (await this.getTransactionRecord())[t] || null;
|
|
103
109
|
}
|
|
104
110
|
async getAllTxRequests(t) {
|
|
105
111
|
const o = await this.getTransactionRecord();
|
|
106
|
-
return Object.values(o).filter((r) => r.chainId === t).sort((r,
|
|
112
|
+
return Object.values(o).filter((r) => r.chainId === t).sort((r, e) => new Date(e.timestamp).getTime() - new Date(r.timestamp).getTime());
|
|
113
|
+
}
|
|
114
|
+
async updateTxHash(t, o) {
|
|
115
|
+
const r = await this.getTxRequest(t);
|
|
116
|
+
if (!r)
|
|
117
|
+
throw new Error("Activity not found");
|
|
118
|
+
const e = {
|
|
119
|
+
...r,
|
|
120
|
+
txHash: o
|
|
121
|
+
};
|
|
122
|
+
await l(c.TX_ACTIVITY, (a = {}) => (a[t] = e, a));
|
|
107
123
|
}
|
|
108
|
-
async updateTxStatusAndHash(t, o, r,
|
|
109
|
-
const
|
|
110
|
-
if (!
|
|
124
|
+
async updateTxStatusAndHash(t, o, r, e, a, s, n, m) {
|
|
125
|
+
const i = await this.getTxRequest(t);
|
|
126
|
+
if (!i)
|
|
111
127
|
throw new Error("Transaction not found");
|
|
112
|
-
const
|
|
113
|
-
...
|
|
128
|
+
const d = await this.getGasInDollar(n, m, i.chainId), p = {
|
|
129
|
+
...i,
|
|
114
130
|
status: o,
|
|
115
131
|
txHash: r,
|
|
116
|
-
value:
|
|
117
|
-
from:
|
|
118
|
-
to:
|
|
132
|
+
value: i.value ?? e,
|
|
133
|
+
from: i.from ?? a,
|
|
134
|
+
to: i.to ?? s,
|
|
119
135
|
gas: n,
|
|
120
136
|
gasPrice: m,
|
|
121
|
-
gasInDollar:
|
|
137
|
+
gasInDollar: i.gasInDollar ?? d?.toString(),
|
|
122
138
|
timestamp: /* @__PURE__ */ new Date()
|
|
123
139
|
};
|
|
124
|
-
return await
|
|
140
|
+
return await l(c.TX_ACTIVITY, (u = {}) => (u[t] = p, u)), p;
|
|
125
141
|
}
|
|
126
|
-
async updateActivity(t, o, r,
|
|
142
|
+
async updateActivity(t, o, r, e, a, s, n, m) {
|
|
127
143
|
try {
|
|
128
|
-
await this.updateTxStatusAndHash(t, o, r,
|
|
129
|
-
} catch (
|
|
130
|
-
console.log("error in updating tx request",
|
|
144
|
+
await this.updateTxStatusAndHash(t, o, r, e, a, s, n, m);
|
|
145
|
+
} catch (i) {
|
|
146
|
+
console.log("error in updating tx request", i);
|
|
131
147
|
}
|
|
132
148
|
}
|
|
133
149
|
async removePendingTransactions(t) {
|
|
134
150
|
try {
|
|
135
|
-
await
|
|
151
|
+
await l(c.TX_ACTIVITY, (o = {}) => (delete o[t], o));
|
|
136
152
|
} catch (o) {
|
|
137
153
|
console.log("error in deleting tx requests", o);
|
|
138
154
|
}
|
|
@@ -167,21 +183,21 @@ class R {
|
|
|
167
183
|
getGasInDollar = async (t, o, r) => {
|
|
168
184
|
if (!(!t || !o))
|
|
169
185
|
try {
|
|
170
|
-
const
|
|
186
|
+
const e = H(r) ? C : q, a = E(e, r);
|
|
171
187
|
if (!a)
|
|
172
188
|
return;
|
|
173
|
-
const { prices: s } = await
|
|
189
|
+
const { prices: s } = await F.getTokenPrices(r, [a.erc20TokenAddress]), n = s[0];
|
|
174
190
|
if (!n)
|
|
175
191
|
return;
|
|
176
|
-
const
|
|
177
|
-
return
|
|
178
|
-
} catch (
|
|
179
|
-
|
|
192
|
+
const i = n * Number(R(a, o.toBigInt())) * Number(t.toBigInt());
|
|
193
|
+
return _(i);
|
|
194
|
+
} catch (e) {
|
|
195
|
+
b.error("Failed to calculate gas cost in dollars:", { chainId: r, error: e });
|
|
180
196
|
return;
|
|
181
197
|
}
|
|
182
198
|
};
|
|
183
199
|
}
|
|
184
|
-
const
|
|
200
|
+
const Rt = new V();
|
|
185
201
|
export {
|
|
186
|
-
|
|
202
|
+
Rt as activityStorage
|
|
187
203
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("idb-keyval");require("ethers");require("../../constants/chains.constants.cjs");require("@solana/web3.js");require("../http/HttpClient.cjs");const B=require("../../error-handling/logger.cjs");require("../../constants/token-data/index.cjs");require("../../error-handling/error-codes.constants.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/activities.types.cjs");require("circomlibjs-hinkal-fork");require("../crypto-keys/keys.cjs");require("../../constants/server.constants.cjs");require("../../API/getServerURL.cjs");require("axios");require("../../constants/vite.constants.cjs");require("@coral-xyz/anchor");require("@solana/spl-token");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/userAgent.cjs");const q=require("../../functions/utils/string.utils.cjs");require("libsodium-wrappers");require("multiformats");require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("idb-keyval");require("ethers");require("../../constants/chains.constants.cjs");require("@solana/web3.js");require("../http/HttpClient.cjs");const B=require("../../error-handling/logger.cjs");require("../../constants/token-data/index.cjs");require("../../error-handling/error-codes.constants.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/activities.types.cjs");require("circomlibjs-hinkal-fork");require("../crypto-keys/keys.cjs");require("../../constants/server.constants.cjs");require("../../API/getServerURL.cjs");require("axios");require("../../constants/vite.constants.cjs");require("@coral-xyz/anchor");require("@solana/spl-token");require("ethers-v6h");require("tweetnacl");require("bs58");require("buffer");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/userAgent.cjs");const q=require("../../functions/utils/string.utils.cjs");require("libsodium-wrappers");require("multiformats");require("../../API/enclaveCalls.cjs");require("async-mutex");require("process");require("../../providers/EthersProviderAdapter.cjs");class y{balancesRecordLabel="walletsBalances";async getBalances(){return await c.get(this.balancesRecordLabel)}async getBalancesByWallet(r,a){const e=await this.getBalances();if(!e)return;const i=q.getStateKey(r,a);return e[i]}async setBalances(r,a,e,i){let n=[];if(!i)return await c.update(this.balancesRecordLabel,(t={})=>{const u=q.getStateKey(a,r);return{...t,[u]:e}}),e;if(i.length===0)return await this.getBalancesByWallet(a,r)??[];try{await c.update(this.balancesRecordLabel,(t={})=>{const u=q.getStateKey(a,r),s=this.createBalanceLookup(t[u]),o=this.createBalanceLookup(e);return i.forEach(({erc20TokenAddress:g})=>{const l=g.toLowerCase();l in o?s[l]=o[l]:delete s[l]}),n=Object.values(s),{...t,[u]:n}})}catch(t){B.Logger.error("Failed to update wallet balances:",t)}return n}createBalanceLookup(r=[]){return r.reduce((a,e)=>({...a,[e.token.erc20TokenAddress.toLowerCase()]:e}),{})}}const w=new y;exports.publicBalancesStorage=w;
|
|
@@ -18,6 +18,10 @@ import "axios";
|
|
|
18
18
|
import "../../constants/vite.constants.mjs";
|
|
19
19
|
import "@coral-xyz/anchor";
|
|
20
20
|
import "@solana/spl-token";
|
|
21
|
+
import "ethers-v6h";
|
|
22
|
+
import "tweetnacl";
|
|
23
|
+
import "bs58";
|
|
24
|
+
import "buffer";
|
|
21
25
|
import "../../constants/contracts.constants.mjs";
|
|
22
26
|
import "../../constants/kyc.constants.mjs";
|
|
23
27
|
import "../../constants/coingecko.constants.mjs";
|
|
@@ -29,65 +33,64 @@ import "../../constants/activity.constants.mjs";
|
|
|
29
33
|
import "../../constants/tasks.constants.mjs";
|
|
30
34
|
import "../../constants/events.constants.mjs";
|
|
31
35
|
import "../../functions/utils/userAgent.mjs";
|
|
32
|
-
import { getStateKey as
|
|
36
|
+
import { getStateKey as n } from "../../functions/utils/string.utils.mjs";
|
|
33
37
|
import "libsodium-wrappers";
|
|
34
38
|
import "multiformats";
|
|
39
|
+
import "../../API/enclaveCalls.mjs";
|
|
35
40
|
import "async-mutex";
|
|
36
|
-
import "../../API/tenderly.api.mjs";
|
|
37
41
|
import "process";
|
|
38
|
-
import "buffer";
|
|
39
42
|
import "../../providers/EthersProviderAdapter.mjs";
|
|
40
43
|
class g {
|
|
41
44
|
balancesRecordLabel = "walletsBalances";
|
|
42
45
|
async getBalances() {
|
|
43
46
|
return await u(this.balancesRecordLabel);
|
|
44
47
|
}
|
|
45
|
-
async getBalancesByWallet(
|
|
48
|
+
async getBalancesByWallet(r, e) {
|
|
46
49
|
const t = await this.getBalances();
|
|
47
50
|
if (!t)
|
|
48
51
|
return;
|
|
49
|
-
const
|
|
50
|
-
return t[
|
|
52
|
+
const a = n(r, e);
|
|
53
|
+
return t[a];
|
|
51
54
|
}
|
|
52
|
-
async setBalances(
|
|
53
|
-
let
|
|
54
|
-
if (!
|
|
55
|
-
return await s(this.balancesRecordLabel, (
|
|
56
|
-
const i =
|
|
55
|
+
async setBalances(r, e, t, a) {
|
|
56
|
+
let m = [];
|
|
57
|
+
if (!a)
|
|
58
|
+
return await s(this.balancesRecordLabel, (o = {}) => {
|
|
59
|
+
const i = n(e, r);
|
|
57
60
|
return {
|
|
58
|
-
...
|
|
61
|
+
...o,
|
|
59
62
|
[i]: t
|
|
60
63
|
};
|
|
61
64
|
}), t;
|
|
62
|
-
if (
|
|
63
|
-
return await this.getBalancesByWallet(
|
|
65
|
+
if (a.length === 0)
|
|
66
|
+
return await this.getBalancesByWallet(e, r) ?? [];
|
|
64
67
|
try {
|
|
65
|
-
await s(this.balancesRecordLabel, (
|
|
66
|
-
const i =
|
|
67
|
-
return
|
|
68
|
+
await s(this.balancesRecordLabel, (o = {}) => {
|
|
69
|
+
const i = n(e, r), l = this.createBalanceLookup(o[i]), c = this.createBalanceLookup(t);
|
|
70
|
+
return a.forEach(({ erc20TokenAddress: B }) => {
|
|
68
71
|
const p = B.toLowerCase();
|
|
69
|
-
p in
|
|
70
|
-
}),
|
|
71
|
-
...
|
|
72
|
-
[i]:
|
|
72
|
+
p in c ? l[p] = c[p] : delete l[p];
|
|
73
|
+
}), m = Object.values(l), {
|
|
74
|
+
...o,
|
|
75
|
+
[i]: m
|
|
73
76
|
};
|
|
74
77
|
});
|
|
75
|
-
} catch (
|
|
76
|
-
w.error("Failed to update wallet balances:",
|
|
78
|
+
} catch (o) {
|
|
79
|
+
w.error("Failed to update wallet balances:", o);
|
|
77
80
|
}
|
|
78
|
-
return
|
|
81
|
+
return m;
|
|
79
82
|
}
|
|
80
|
-
createBalanceLookup(
|
|
81
|
-
return
|
|
82
|
-
(
|
|
83
|
-
...
|
|
83
|
+
createBalanceLookup(r = []) {
|
|
84
|
+
return r.reduce(
|
|
85
|
+
(e, t) => ({
|
|
86
|
+
...e,
|
|
84
87
|
[t.token.erc20TokenAddress.toLowerCase()]: t
|
|
85
88
|
}),
|
|
86
89
|
{}
|
|
87
90
|
);
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
|
-
const
|
|
93
|
+
const it = new g();
|
|
91
94
|
export {
|
|
92
|
-
|
|
95
|
+
it as publicBalancesStorage
|
|
93
96
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("idb-keyval"),q=require("../../error-handling/logger.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/activities.types.cjs");require("../../constants/chains.constants.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");require("ethers");require("circomlibjs-hinkal-fork");require("../../constants/kyc.constants.cjs");require("../http/HttpClient.cjs");require("../../constants/token-data/index.cjs");require("../../error-handling/error-codes.constants.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../crypto-keys/keys.cjs");require("../../constants/server.constants.cjs");require("../../API/getServerURL.cjs");require("axios");require("../../constants/vite.constants.cjs");const d=require("../../functions/utils/caseInsensitive.utils.cjs");require("@solana/spl-token");require("ethers-v6h");require("tweetnacl");require("bs58");require("buffer");require("../../constants/contracts.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/userAgent.cjs");require("libsodium-wrappers");require("multiformats");require("../../API/enclaveCalls.cjs");require("async-mutex");require("process");require("../../providers/EthersProviderAdapter.cjs");require("../../functions/web3/events/getInputUtxoAndBalance.cjs");require("../../functions/web3/events/getApprovedBalance.cjs");require("../../functions/web3/getTokenHolder.cjs");require("node-forge");class l{STORAGE_KEY="contacts";checkForDuplicate(o,e,r){if(o.find(({ethereumAddress:t,nickname:i})=>(t===e.ethereumAddress||i===e.nickname)&&t!==r)!==void 0)throw new Error("Duplicate Contact attribute")}async createContact(o,e){const r=o.toLowerCase();await u.update(this.STORAGE_KEY,c=>{const t=c??{},i=t[r]??[];return this.checkForDuplicate(i,e),i.push(e),t[r]=i,t})}async getContacts(o){try{const e=o.toLowerCase(),r=await u.get(this.STORAGE_KEY);return!r||!r[e]?[]:r[e]}catch(e){return q.Logger.error("Error while getting contacts:",e),[]}}async editContact(o,e,r){const c=o.toLowerCase();await u.update(this.STORAGE_KEY,t=>{const i=t??{},a=i[c];if(!i||!a)throw new Error("Contacts could not be fetched");this.checkForDuplicate(a,r,e);const n=a.findIndex(({ethereumAddress:s})=>d.caseInsensitiveEqual(s,e));if(n===-1)throw new Error("Contact to be edited was not found");return a[n]=r,i[c]=a,i})}async deleteContact(o,e){const r=o.toLowerCase();await u.update(this.STORAGE_KEY,c=>{const t=c??{},i=t[r];if(!t||!i)throw new Error("Contacts could not be fetched");const a=i.filter(({ethereumAddress:n})=>n!==e);return t[r]=a,t})}}const w=new l;exports.contactStorage=w;
|
|
@@ -20,6 +20,10 @@ import "axios";
|
|
|
20
20
|
import "../../constants/vite.constants.mjs";
|
|
21
21
|
import { caseInsensitiveEqual as l } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
22
22
|
import "@solana/spl-token";
|
|
23
|
+
import "ethers-v6h";
|
|
24
|
+
import "tweetnacl";
|
|
25
|
+
import "bs58";
|
|
26
|
+
import "buffer";
|
|
23
27
|
import "../../constants/contracts.constants.mjs";
|
|
24
28
|
import "../../constants/coingecko.constants.mjs";
|
|
25
29
|
import "../../constants/reorg-depths.constants.mjs";
|
|
@@ -32,15 +36,14 @@ import "../../constants/events.constants.mjs";
|
|
|
32
36
|
import "../../functions/utils/userAgent.mjs";
|
|
33
37
|
import "libsodium-wrappers";
|
|
34
38
|
import "multiformats";
|
|
39
|
+
import "../../API/enclaveCalls.mjs";
|
|
35
40
|
import "async-mutex";
|
|
36
|
-
import "../../API/tenderly.api.mjs";
|
|
37
41
|
import "process";
|
|
38
|
-
import "buffer";
|
|
39
42
|
import "../../providers/EthersProviderAdapter.mjs";
|
|
40
|
-
import "
|
|
43
|
+
import "../../functions/web3/events/getInputUtxoAndBalance.mjs";
|
|
41
44
|
import "../../functions/web3/events/getApprovedBalance.mjs";
|
|
42
45
|
import "../../functions/web3/getTokenHolder.mjs";
|
|
43
|
-
import "
|
|
46
|
+
import "node-forge";
|
|
44
47
|
class w {
|
|
45
48
|
STORAGE_KEY = "contacts";
|
|
46
49
|
checkForDuplicate(e, t, o) {
|
|
@@ -92,7 +95,7 @@ class w {
|
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
const
|
|
98
|
+
const nt = new w();
|
|
96
99
|
export {
|
|
97
|
-
|
|
100
|
+
nt as contactStorage
|
|
98
101
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("ethers-v6h"),u=require("../../constants/chains.constants.cjs"),b=require("../../externalABIs/index.cjs"),l=require("../../functions/utils/caseInsensitive.utils.cjs"),d=require("../../functions/utils/string.utils.cjs"),C=1e4;class g{subscribedAddresses=new Set;providers=new Map;nativeBalances=new Map;balanceChangeCallback;eventListeners=new Map;constructor(){u.WALLET_SUPPORTED_CHAINS.forEach(e=>{u.isSolanaLike(e)||this.initializeChain(e)})}initializeChain(e){const{wsRpcUrl:t}=u.networkRegistry[e];if(!t)return;const n=new i.WebSocketProvider(t,e);this.providers.set(e,n),this.eventListeners.set(e,[]),this.setupNativeBalanceListener(n,e),this.setupFilteredEventListeners(n,e)}setupFilteredEventListeners(e,t){if(this.eventListeners.get(t)?.forEach(h=>h()),this.eventListeners.set(t,[]),this.subscribedAddresses.size===0)return;const s=Array.from(this.subscribedAddresses).map(h=>i.zeroPadValue(h,32)),r=i.keccak256(i.toUtf8Bytes("Transfer(address,address,uint256)")),c=i.keccak256(i.toUtf8Bytes("TransferSingle(address,address,address,uint256,uint256)")),o=i.keccak256(i.toUtf8Bytes("TransferBatch(address,address,address,uint256[],uint256[])")),a=this.setupERC20Listener(e,[r,s]),f=this.setupERC20Listener(e,[r,null,s]),v=this.setupERC1155Listener(e,[c,null,s]),p=this.setupERC1155Listener(e,[c,null,null,s]),E=this.setupERC1155Listener(e,[o,null,s]),L=this.setupERC1155Listener(e,[o,null,null,s]);this.eventListeners.set(t,[a,f,v,p,E,L])}setupERC20Listener(e,t){const n=s=>{try{const r=new i.Interface(b.ERC20ABI).parseLog({topics:s.topics,data:s.data});if(!r)return;const{from:c,to:o}=r.args;Array.from(this.subscribedAddresses).filter(a=>l.caseInsensitiveEqual(a,c)||l.caseInsensitiveEqual(a,o)).forEach(a=>this.balanceChangeCallback?.(a))}catch{}};return e.on({topics:t},n),()=>e.off({topics:t},n)}setupERC1155Listener(e,t){const n=s=>{try{const r=new i.Interface(b.ERC1155ABI).parseLog({topics:s.topics,data:s.data});if(!r)return;const{from:c,to:o}=r.args;Array.from(this.subscribedAddresses).filter(a=>l.caseInsensitiveEqual(a,c)||l.caseInsensitiveEqual(a,o)).forEach(a=>this.balanceChangeCallback?.(a))}catch{}};return e.on({topics:t},n),()=>e.off({topics:t},n)}setupNativeBalanceListener(e,t){setInterval(async()=>{if(this.subscribedAddresses.size!==0)try{await Promise.all(Array.from(this.subscribedAddresses).map(async n=>{const s=await e.getBalance(n),r=d.getStateKey(n,t),c=this.nativeBalances.get(r)??0n;s!==c&&(this.nativeBalances.set(r,s),this.balanceChangeCallback?.(n))}))}catch{}},C)}async subscribe(e){const t=e.toLowerCase();this.subscribedAddresses.has(t)||(this.subscribedAddresses.add(t),this.providers.forEach((n,s)=>this.setupFilteredEventListeners(n,s)),await Promise.all(u.WALLET_SUPPORTED_CHAINS.map(async n=>{const s=this.providers.get(n);if(s)try{const r=await s.getBalance(t);this.nativeBalances.set(d.getStateKey(t,n),r)}catch{}})))}unsubscribe(e){const t=e.toLowerCase();this.subscribedAddresses.delete(t),this.nativeBalances.forEach((n,s)=>{l.caseInsensitiveEqual(d.getAddressFromStateKey(s),t)&&this.nativeBalances.delete(s)}),this.providers.forEach((n,s)=>this.setupFilteredEventListeners(n,s))}onBalanceChange(e){return this.balanceChangeCallback=e,()=>{this.balanceChangeCallback=void 0}}cleanup(){this.eventListeners.forEach(e=>e.forEach(t=>t())),this.eventListeners.clear()}}const A=new g;exports.publicBalanceWatcher=A;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type BalanceChangeCallback = (walletAddress: string) => void | Promise<void>;
|
|
2
|
+
declare class PublicBalanceWatcher {
|
|
3
|
+
private subscribedAddresses;
|
|
4
|
+
private providers;
|
|
5
|
+
private nativeBalances;
|
|
6
|
+
private balanceChangeCallback?;
|
|
7
|
+
private eventListeners;
|
|
8
|
+
constructor();
|
|
9
|
+
private initializeChain;
|
|
10
|
+
private setupFilteredEventListeners;
|
|
11
|
+
private setupERC20Listener;
|
|
12
|
+
private setupERC1155Listener;
|
|
13
|
+
private setupNativeBalanceListener;
|
|
14
|
+
subscribe(address: string): Promise<void>;
|
|
15
|
+
unsubscribe(address: string): void;
|
|
16
|
+
onBalanceChange(callback: BalanceChangeCallback): () => void;
|
|
17
|
+
cleanup(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare const publicBalanceWatcher: PublicBalanceWatcher;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { WebSocketProvider as E, zeroPadValue as A, keccak256 as h, toUtf8Bytes as d, Interface as u } from "ethers-v6h";
|
|
2
|
+
import { WALLET_SUPPORTED_CHAINS as f, isSolanaLike as B, networkRegistry as g } from "../../constants/chains.constants.mjs";
|
|
3
|
+
import { ERC20ABI as w, ERC1155ABI as y } from "../../externalABIs/index.mjs";
|
|
4
|
+
import { caseInsensitiveEqual as o } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
5
|
+
import { getStateKey as b, getAddressFromStateKey as T } from "../../functions/utils/string.utils.mjs";
|
|
6
|
+
const R = 1e4;
|
|
7
|
+
class k {
|
|
8
|
+
subscribedAddresses = /* @__PURE__ */ new Set();
|
|
9
|
+
providers = /* @__PURE__ */ new Map();
|
|
10
|
+
nativeBalances = /* @__PURE__ */ new Map();
|
|
11
|
+
balanceChangeCallback;
|
|
12
|
+
eventListeners = /* @__PURE__ */ new Map();
|
|
13
|
+
constructor() {
|
|
14
|
+
f.forEach((e) => {
|
|
15
|
+
B(e) || this.initializeChain(e);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
initializeChain(e) {
|
|
19
|
+
const { wsRpcUrl: t } = g[e];
|
|
20
|
+
if (!t)
|
|
21
|
+
return;
|
|
22
|
+
const r = new E(t, e);
|
|
23
|
+
this.providers.set(e, r), this.eventListeners.set(e, []), this.setupNativeBalanceListener(r, e), this.setupFilteredEventListeners(r, e);
|
|
24
|
+
}
|
|
25
|
+
setupFilteredEventListeners(e, t) {
|
|
26
|
+
if (this.eventListeners.get(t)?.forEach((l) => l()), this.eventListeners.set(t, []), this.subscribedAddresses.size === 0)
|
|
27
|
+
return;
|
|
28
|
+
const s = Array.from(this.subscribedAddresses).map((l) => A(l, 32)), a = h(d("Transfer(address,address,uint256)")), i = h(
|
|
29
|
+
d("TransferSingle(address,address,address,uint256,uint256)")
|
|
30
|
+
), c = h(
|
|
31
|
+
d("TransferBatch(address,address,address,uint256[],uint256[])")
|
|
32
|
+
), n = this.setupERC20Listener(e, [a, s]), p = this.setupERC20Listener(e, [a, null, s]), L = this.setupERC1155Listener(e, [i, null, s]), m = this.setupERC1155Listener(e, [
|
|
33
|
+
i,
|
|
34
|
+
null,
|
|
35
|
+
null,
|
|
36
|
+
s
|
|
37
|
+
]), v = this.setupERC1155Listener(e, [c, null, s]), C = this.setupERC1155Listener(e, [
|
|
38
|
+
c,
|
|
39
|
+
null,
|
|
40
|
+
null,
|
|
41
|
+
s
|
|
42
|
+
]);
|
|
43
|
+
this.eventListeners.set(t, [
|
|
44
|
+
n,
|
|
45
|
+
p,
|
|
46
|
+
L,
|
|
47
|
+
m,
|
|
48
|
+
v,
|
|
49
|
+
C
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
setupERC20Listener(e, t) {
|
|
53
|
+
const r = (s) => {
|
|
54
|
+
try {
|
|
55
|
+
const a = new u(w).parseLog({ topics: s.topics, data: s.data });
|
|
56
|
+
if (!a)
|
|
57
|
+
return;
|
|
58
|
+
const { from: i, to: c } = a.args;
|
|
59
|
+
Array.from(this.subscribedAddresses).filter((n) => o(n, i) || o(n, c)).forEach((n) => this.balanceChangeCallback?.(n));
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return e.on({ topics: t }, r), () => e.off({ topics: t }, r);
|
|
64
|
+
}
|
|
65
|
+
setupERC1155Listener(e, t) {
|
|
66
|
+
const r = (s) => {
|
|
67
|
+
try {
|
|
68
|
+
const a = new u(y).parseLog({ topics: s.topics, data: s.data });
|
|
69
|
+
if (!a)
|
|
70
|
+
return;
|
|
71
|
+
const { from: i, to: c } = a.args;
|
|
72
|
+
Array.from(this.subscribedAddresses).filter((n) => o(n, i) || o(n, c)).forEach((n) => this.balanceChangeCallback?.(n));
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return e.on({ topics: t }, r), () => e.off({ topics: t }, r);
|
|
77
|
+
}
|
|
78
|
+
setupNativeBalanceListener(e, t) {
|
|
79
|
+
setInterval(async () => {
|
|
80
|
+
if (this.subscribedAddresses.size !== 0)
|
|
81
|
+
try {
|
|
82
|
+
await Promise.all(
|
|
83
|
+
Array.from(this.subscribedAddresses).map(async (r) => {
|
|
84
|
+
const s = await e.getBalance(r), a = b(r, t), i = this.nativeBalances.get(a) ?? 0n;
|
|
85
|
+
s !== i && (this.nativeBalances.set(a, s), this.balanceChangeCallback?.(r));
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
} catch {
|
|
89
|
+
}
|
|
90
|
+
}, R);
|
|
91
|
+
}
|
|
92
|
+
async subscribe(e) {
|
|
93
|
+
const t = e.toLowerCase();
|
|
94
|
+
this.subscribedAddresses.has(t) || (this.subscribedAddresses.add(t), this.providers.forEach((r, s) => this.setupFilteredEventListeners(r, s)), await Promise.all(
|
|
95
|
+
f.map(async (r) => {
|
|
96
|
+
const s = this.providers.get(r);
|
|
97
|
+
if (s)
|
|
98
|
+
try {
|
|
99
|
+
const a = await s.getBalance(t);
|
|
100
|
+
this.nativeBalances.set(b(t, r), a);
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
));
|
|
105
|
+
}
|
|
106
|
+
unsubscribe(e) {
|
|
107
|
+
const t = e.toLowerCase();
|
|
108
|
+
this.subscribedAddresses.delete(t), this.nativeBalances.forEach((r, s) => {
|
|
109
|
+
o(T(s), t) && this.nativeBalances.delete(s);
|
|
110
|
+
}), this.providers.forEach((r, s) => this.setupFilteredEventListeners(r, s));
|
|
111
|
+
}
|
|
112
|
+
onBalanceChange(e) {
|
|
113
|
+
return this.balanceChangeCallback = e, () => {
|
|
114
|
+
this.balanceChangeCallback = void 0;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
cleanup() {
|
|
118
|
+
this.eventListeners.forEach((e) => e.forEach((t) => t())), this.eventListeners.clear();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const W = new k();
|
|
122
|
+
export {
|
|
123
|
+
W as publicBalanceWatcher
|
|
124
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@solana/spl-token"),t=require("../../constants/chains.constants.cjs"),a=require("@solana/web3.js"),b=15e3;class r{connection;subscribedAddresses=new Set;solBalances=new Map;balanceChangeCallback;constructor(){this.connection=new a.Connection(t.networkRegistry[t.chainIds.solanaMainnet].fetchRpcUrl??"","confirmed")}async subscribe(e){if(this.subscribedAddresses.has(e))return;const c=new a.PublicKey(e);this.subscribedAddresses.add(e);const o=await this.connection.getBalance(c);this.solBalances.set(e,o),this.connection.onAccountChange(c,i=>{const n=i.lamports,l=this.solBalances.get(e)??0;n!==l&&(this.solBalances.set(e,n),this.executeCallback(e))}),this.subscribeTokenAccounts(c,s.TOKEN_PROGRAM_ID),this.subscribeTokenAccounts(c,s.TOKEN_2022_PROGRAM_ID)}unsubscribe(e){this.subscribedAddresses.delete(e),this.solBalances.delete(e)}onBalanceChange(e){return this.balanceChangeCallback=e,()=>{this.balanceChangeCallback=void 0}}subscribeTokenAccounts(e,c){this.connection.onProgramAccountChange(c,()=>{this.executeCallback(e.toBase58())},{commitment:"confirmed",filters:[{memcmp:{offset:32,bytes:e.toBase58()}}]})}executeCallback(e){setTimeout(()=>{try{this.balanceChangeCallback?.(e)}catch{}},b)}}const h=new r;exports.solanaPublicBalanceWatcher=h;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type BalanceChangeCallback = (walletAddress: string) => void | Promise<void>;
|
|
2
|
+
declare class SolanaPublicBalanceWatcher {
|
|
3
|
+
private connection;
|
|
4
|
+
private subscribedAddresses;
|
|
5
|
+
private solBalances;
|
|
6
|
+
private balanceChangeCallback?;
|
|
7
|
+
constructor();
|
|
8
|
+
subscribe(address: string): Promise<void>;
|
|
9
|
+
unsubscribe(address: string): void;
|
|
10
|
+
onBalanceChange(callback: BalanceChangeCallback): () => void;
|
|
11
|
+
private subscribeTokenAccounts;
|
|
12
|
+
private executeCallback;
|
|
13
|
+
}
|
|
14
|
+
export declare const solanaPublicBalanceWatcher: SolanaPublicBalanceWatcher;
|
|
15
|
+
export {};
|