@gurge/sdk-react-native 0.3.71 → 0.3.76
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/_virtual/_rolldown/runtime.mjs +11 -2
- package/common/src/API/getCoingeckoPrice.cjs +1 -1
- package/common/src/API/proxyAccountsCalls.cjs +1 -1
- package/common/src/crypto/EddsaRN.cjs +1 -1
- package/common/src/crypto/babyJub.cjs +1 -1
- package/common/src/crypto/babyJub.mjs +7 -6
- package/common/src/crypto/ecdh-sealed-keys.cjs +1 -1
- package/common/src/crypto/ecdh.cjs +1 -1
- package/common/src/crypto/eddsa.cjs +1 -1
- package/common/src/crypto/eddsa.mjs +7 -6
- package/common/src/crypto/poseidon.cjs +1 -1
- package/common/src/crypto/poseidon.mjs +13 -13
- package/common/src/crypto/preProcessing.cjs +1 -1
- package/common/src/data-structures/AccountActions/AccountActions.cjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaProxySend.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaProxyShield.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaProxySwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.cjs +1 -1
- package/common/src/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/common/src/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/activity-db.mjs +38 -38
- package/common/src/data-structures/IndexedDB/balances-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/balances-db.mjs +18 -16
- package/common/src/data-structures/IndexedDB/contact-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/contact-db.mjs +16 -14
- package/common/src/data-structures/IndexedDB/key-val-store.cjs +1 -1
- package/common/src/data-structures/IndexedDB/key-val-store.mjs +12 -12
- package/common/src/data-structures/IndexedDB/pay-activity-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/pay-activity-db.mjs +10 -8
- package/common/src/data-structures/IndexedDB/signatures-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/signatures-db.mjs +23 -21
- package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.mjs +32 -31
- package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.mjs +25 -25
- package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.mjs +47 -46
- package/common/src/data-structures/TokenDBs/PrivateTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/PrivateTokensDB.mjs +20 -20
- package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.mjs +19 -19
- package/common/src/data-structures/TokenDBs/TronPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/TronPublicTokensDB.mjs +19 -19
- package/common/src/data-structures/TokenDBs/token-visibility-db.cjs +1 -1
- package/common/src/data-structures/TokenDBs/token-visibility-db.mjs +45 -44
- package/common/src/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
- package/common/src/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/common/src/data-structures/crypto-keys/keys.cjs +1 -1
- package/common/src/data-structures/event-service/evm/AbstractNullifierSnapshotService.cjs +1 -1
- package/common/src/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
- package/common/src/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.cjs +1 -1
- package/common/src/data-structures/event-service/solana/SolanaBlockchainEventEmitter.cjs +1 -1
- package/common/src/data-structures/http/BasicHttpClient.cjs +1 -1
- package/common/src/functions/pre-transaction/convert-okx-instructions.cjs +1 -1
- package/common/src/functions/pre-transaction/ensureAmountChanges.cjs +1 -1
- package/common/src/functions/pre-transaction/getSolanaCalldataHash.cjs +1 -1
- package/common/src/functions/pre-transaction/sendV0Transaction.cjs +1 -1
- package/common/src/functions/pre-transaction/solana.cjs +1 -1
- package/common/src/functions/pre-transaction/solanaTransfer.utils.cjs +1 -1
- package/common/src/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/common/src/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
- package/common/src/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/common/src/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/fetchOnChainRootHashes.cjs +1 -1
- package/common/src/functions/snarkjs/signedMessageHash.cjs +1 -1
- package/common/src/functions/snarkjs/verifyCommitmentValidationData.cjs +1 -1
- package/common/src/functions/snarkjs/verifyCommitmentValidationData.mjs +4 -1
- package/common/src/functions/utils/abi.utils.cjs +1 -1
- package/common/src/functions/utils/addresses.cjs +1 -1
- package/common/src/functions/utils/cacheFunctions.cjs +1 -1
- package/common/src/functions/utils/cacheFunctions.mjs +13 -13
- package/common/src/functions/utils/convertEmporiumOpToCallInfo.cjs +1 -1
- package/common/src/functions/utils/create-provider.cjs +1 -1
- package/common/src/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/common/src/functions/utils/external-action.utils.cjs +1 -1
- package/common/src/functions/utils/getSignerFromContract.cjs +1 -1
- package/common/src/functions/utils/getUtxosFromReceiptSolana.cjs +1 -1
- package/common/src/functions/utils/ipfs.cjs +1 -1
- package/common/src/functions/utils/ipfs.mjs +3 -1
- package/common/src/functions/utils/mnemonics.cjs +1 -1
- package/common/src/functions/utils/publicBalance.utils.cjs +1 -1
- package/common/src/functions/utils/solana-memo.cjs +1 -1
- package/common/src/functions/utils/solanaMint.utils.cjs +1 -1
- package/common/src/functions/utils/tron.utils.cjs +1 -1
- package/common/src/functions/utils/userAgent.cjs +1 -1
- package/common/src/functions/web3/etherFunctions.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
- package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
- package/common/src/functions/web3/functionCalls/approveToken.cjs +1 -1
- package/common/src/functions/web3/functionCalls/constructBatchCall.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/common/src/functions/web3/getContractMetadata.cjs +1 -1
- package/common/src/functions/web3/okxAPI.cjs +1 -1
- package/common/src/functions/web3/uniswapAPI.cjs +1 -1
- package/common/src/mutexes/chainBalanceRwLock.cjs +1 -1
- package/common/src/mutexes/mutex.cjs +1 -1
- package/common/src/providers/EthersProviderAdapter.cjs +1 -1
- package/common/src/providers/SolanaProviderAdapter.cjs +1 -1
- package/common/src/providers/WagmiProviderAdapter.cjs +1 -1
- package/common/src/types/hinkal.types.cjs +1 -1
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/package.json +1 -1
- package/react-native/bridge/HinkalRNWorker.cjs +1 -1
- package/shims/circomlibjs-hinkal-fork.cjs +14 -0
- package/shims/circomlibjs-hinkal-fork.mjs +3 -0
- package/shims/circomlibjs.cjs +15 -0
- package/shims/circomlibjs.mjs +3 -0
- package/shims/constants.cjs +7 -0
- package/shims/constants.mjs +3 -0
- package/shims/crypto.cjs +102 -0
- package/shims/crypto.mjs +3 -0
- package/shims/ffjavascript.cjs +5 -0
- package/shims/ffjavascript.mjs +3 -0
- package/shims/globals.cjs +15 -0
- package/shims/globals.mjs +3 -0
- package/shims/idb-keyval.cjs +75 -0
- package/shims/idb-keyval.mjs +3 -0
- package/shims/multiformats.cjs +1 -0
- package/shims/multiformats.mjs +3 -0
- package/shims/os.cjs +7 -0
- package/shims/os.mjs +3 -0
- package/shims/readline.cjs +6 -0
- package/shims/readline.mjs +3 -0
- package/shims/snarkjs.cjs +21 -0
- package/shims/snarkjs.mjs +3 -0
- package/shims/url.cjs +5 -0
- package/shims/url.mjs +3 -0
- package/shims/web-worker.cjs +7 -0
- package/shims/web-worker.mjs +3 -0
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { ALCHEMY_API_KEY as e, chainIds as t, isSolanaLike as n, networkRegistry as r } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { SOLANA_NFT_INTERFACES as i, TokenType as a, solanaNativeAddress as o, zeroAddress as s } from "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { caseInsensitiveEqual as c, lowerCaseIncludes as l } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { require_idb_keyval as u } from "../../../../shims/idb-keyval.mjs";
|
|
5
|
+
import { StorageKeys as d } from "../../types/cache.types.mjs";
|
|
6
|
+
import { httpClient as f } from "../http/HttpClient.mjs";
|
|
6
7
|
import "../http/index.mjs";
|
|
7
|
-
import { Logger as
|
|
8
|
-
import { API as
|
|
9
|
-
import { getStateKey as
|
|
10
|
-
import { tokenVisibilityStorage as
|
|
11
|
-
import { overlayTokensWithRegistryData as
|
|
12
|
-
import { createCustomSolanaConnection as
|
|
13
|
-
import { getPublicBalanceByTokenAddress as
|
|
14
|
-
import { PublicKey as
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
var w = new class {
|
|
8
|
+
import { Logger as p } from "../../error-handling/logger.mjs";
|
|
9
|
+
import { API as m } from "../../API/API.mjs";
|
|
10
|
+
import { getStateKey as h } from "../../functions/utils/string.utils.mjs";
|
|
11
|
+
import { tokenVisibilityStorage as g } from "./token-visibility-db.mjs";
|
|
12
|
+
import { overlayTokensWithRegistryData as _ } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
13
|
+
import { createCustomSolanaConnection as v } from "../../functions/utils/create-provider.mjs";
|
|
14
|
+
import { getPublicBalanceByTokenAddress as y } from "../../functions/utils/publicBalance.utils.mjs";
|
|
15
|
+
import { PublicKey as b } from "@solana/web3.js";
|
|
16
|
+
import { TOKEN_2022_PROGRAM_ID as x, TOKEN_PROGRAM_ID as S } from "@solana/spl-token";
|
|
17
|
+
//#region common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.ts
|
|
18
|
+
var C = u(), w = new class {
|
|
18
19
|
fetchedTokens = {};
|
|
19
20
|
ALCHEMY_URLS = {
|
|
20
21
|
[t.ethMainnet]: "eth-mainnet",
|
|
@@ -34,21 +35,21 @@ var w = new class {
|
|
|
34
35
|
return this.KNOWN_GOOD_NFTS[t] ? this.KNOWN_GOOD_NFTS[t].some((t) => c(e, t)) : !1;
|
|
35
36
|
}
|
|
36
37
|
async getPublicTokens(e, t) {
|
|
37
|
-
let n =
|
|
38
|
-
return
|
|
38
|
+
let n = h(t, e);
|
|
39
|
+
return _((await (0, C.get)(d.ALCHEMY_PUBLIC_TOKENS))?.[n] || [], e);
|
|
39
40
|
}
|
|
40
41
|
async getFetchedTokens(e, t) {
|
|
41
|
-
let n =
|
|
42
|
-
return
|
|
42
|
+
let n = h(t, e);
|
|
43
|
+
return _(this.fetchedTokens[n] || [], e);
|
|
43
44
|
}
|
|
44
45
|
fetchAndUpdatePublicTokens(e, t) {
|
|
45
46
|
return n(t) ? this.fetchAndUpdateSolanaTokens(e, t) : this.fetchAndUpdateEVMTokens(e, t);
|
|
46
47
|
}
|
|
47
48
|
async fetchAndUpdateSolanaTokens(e, t) {
|
|
48
|
-
let n =
|
|
49
|
+
let n = h(e, t), [r, i] = await Promise.all([this.getSolanaTokenAddresses(t, e), this.getNFTAddresses(t, e)]), a = Array.from(new Set([...r, ...i]));
|
|
49
50
|
if (!a.length) return;
|
|
50
|
-
let o = (await
|
|
51
|
-
await
|
|
51
|
+
let o = (await m.tokensInfoCall(t, a)).filter((e) => !!e), s = await g.hideSpamsAndFetchHiddenTokensAddresses(t, o), c = o.filter((e) => !l(s, e.erc20TokenAddress));
|
|
52
|
+
await (0, C.update)(d.ALCHEMY_PUBLIC_TOKENS, (e = {}) => {
|
|
52
53
|
let t = {
|
|
53
54
|
...e,
|
|
54
55
|
[n]: c
|
|
@@ -60,9 +61,9 @@ var w = new class {
|
|
|
60
61
|
return n(e) ? this.getSolanaTokenAddresses(e, t) : this.getEVMTokenAddresses(e, t);
|
|
61
62
|
}
|
|
62
63
|
async fetchAndUpdateEVMTokens(e, t) {
|
|
63
|
-
let n =
|
|
64
|
+
let n = h(e, t), r = await this.getEVMTokenAddresses(t, e), i = await this.getNFTTokens(t, e), o = i.map((e) => e.contractAddress), s = [...r, ...o];
|
|
64
65
|
if (!s.length) return;
|
|
65
|
-
let
|
|
66
|
+
let u = (await m.tokensInfoCall(t, s)).map((e, n) => {
|
|
66
67
|
if (e) return e;
|
|
67
68
|
let r = s[n], o = i.find((e) => c(e.contractAddress, r));
|
|
68
69
|
return o && o.tokenIds && o.tokenIds.length > 0 && this.isWhitelistedNFT(r, t) ? {
|
|
@@ -74,14 +75,14 @@ var w = new class {
|
|
|
74
75
|
nftTokenType: a.ERC721,
|
|
75
76
|
tokenIds: o.tokenIds
|
|
76
77
|
} : null;
|
|
77
|
-
}).filter((e) => !!e), f = await
|
|
78
|
+
}).filter((e) => !!e), f = await g.hideSpamsAndFetchHiddenTokensAddresses(t, u), p = u.filter((e) => !l(f, e.erc20TokenAddress)).map((e) => ({
|
|
78
79
|
...e,
|
|
79
80
|
tokenIds: i.find((t) => c(t.contractAddress, e.erc20TokenAddress))?.tokenIds
|
|
80
81
|
}));
|
|
81
|
-
await
|
|
82
|
+
await (0, C.update)(d.ALCHEMY_PUBLIC_TOKENS, (e = {}) => {
|
|
82
83
|
let t = {
|
|
83
84
|
...e,
|
|
84
|
-
[n]:
|
|
85
|
+
[n]: p
|
|
85
86
|
};
|
|
86
87
|
return this.fetchedTokens = t, t;
|
|
87
88
|
});
|
|
@@ -89,7 +90,7 @@ var w = new class {
|
|
|
89
90
|
async getSolanaTokenAddresses(e, t) {
|
|
90
91
|
let { fetchRpcUrl: n } = r[e];
|
|
91
92
|
if (!n) throw Error("RPC URL not found for the specified chain ID");
|
|
92
|
-
let i =
|
|
93
|
+
let i = v(n), a = await i.getBalance(new b(t)), [s, c] = await Promise.all([i.getParsedTokenAccountsByOwner(new b(t), { programId: S }), i.getParsedTokenAccountsByOwner(new b(t), { programId: x })]), l = [...s.value, ...c.value].filter((e) => {
|
|
93
94
|
let { amount: t } = e.account.data.parsed.info.tokenAmount;
|
|
94
95
|
return BigInt(t) > 0n;
|
|
95
96
|
}).map((e) => e.account.data.parsed.info.mint);
|
|
@@ -101,7 +102,7 @@ var w = new class {
|
|
|
101
102
|
try {
|
|
102
103
|
let e = [], r = 1;
|
|
103
104
|
do {
|
|
104
|
-
let { items: a = [], page: o } = (await
|
|
105
|
+
let { items: a = [], page: o } = (await f.post(n, {
|
|
105
106
|
jsonrpc: "2.0",
|
|
106
107
|
id: 1,
|
|
107
108
|
method: "getAssetsByOwner",
|
|
@@ -119,17 +120,17 @@ var w = new class {
|
|
|
119
120
|
} while (r > 0);
|
|
120
121
|
return e;
|
|
121
122
|
} catch (e) {
|
|
122
|
-
return
|
|
123
|
+
return p.error("Failed to fetch NFTs from DAS API", e), [];
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
async getEVMTokenAddresses(t, n) {
|
|
126
|
-
let r = await
|
|
127
|
+
let r = await y(t, n, s), i = this.ALCHEMY_URLS[t];
|
|
127
128
|
if (!i) throw Error(`Alchemy URL not found for the specified chain ID: ${t}`);
|
|
128
129
|
let a = `https://${i}.g.alchemy.com/v2/${e}`, o = [], c;
|
|
129
130
|
do {
|
|
130
131
|
let e = [n, "erc20"];
|
|
131
132
|
c && e.push({ pageKey: c });
|
|
132
|
-
let { result: t } = await
|
|
133
|
+
let { result: t } = await f.post(a, {
|
|
133
134
|
jsonrpc: "2.0",
|
|
134
135
|
id: 1,
|
|
135
136
|
method: "alchemy_getTokenBalances",
|
|
@@ -155,7 +156,7 @@ var w = new class {
|
|
|
155
156
|
pageSize: "100"
|
|
156
157
|
});
|
|
157
158
|
a && e.append("pageKey", a);
|
|
158
|
-
let { ownedNfts: t = [], pageKey: o } = await
|
|
159
|
+
let { ownedNfts: t = [], pageKey: o } = await f.get(`${r}?${e.toString()}`);
|
|
159
160
|
i.push(...t), a = o;
|
|
160
161
|
} while (a);
|
|
161
162
|
let o = i.filter(({ contractAddress: e, tokenId: t }) => e && t).reduce((e, { contractAddress: t, tokenId: n }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(
|
|
1
|
+
const e=require(`../../../../_virtual/_rolldown/runtime.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../functions/utils/caseInsensitive.utils.cjs`),i=require(`../../../../shims/idb-keyval.cjs`),a=require(`../../types/ethereum-network.types.cjs`),o=require(`../../types/cache.types.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../../API/API.cjs`),l=require(`../../functions/utils/string.utils.cjs`),u=require(`./token-visibility-db.cjs`),d=require(`../../functions/web3/getContractMetadata.cjs`);let f=require(`axios`);f=e.__toESM(f);var p=i.default,m=class{API_BASE=`https://testnet.arcscan.app/api`;fetchedTokens={};async getPublicTokens(e){let n=l.getStateKey(e,t.chainIds.arcTestnet);return(await(0,p.get)(o.StorageKeys.ARC_PUBLIC_TOKENS))?.[n]||[]}getFetchedTokens(e){let n=l.getStateKey(e,t.chainIds.arcTestnet);return this.fetchedTokens[n]||[]}async fetchAndUpdatePublicTokens(e){let i=l.getStateKey(e,t.chainIds.arcTestnet),a=await this.getERC20TokenAddresses(e),s=await this.getNFTTokens(e),d=s.map(e=>e.contractAddress),f=[...a,...d];if(!f.length)return;let m=(await c.API.tokensInfoCall(t.chainIds.arcTestnet,f)).map((e,i)=>{if(e)return e;let a=f[i],o=s.find(e=>r.caseInsensitiveEqual(e.contractAddress,a));return o&&o.tokenIds&&o.tokenIds.length>0?{chainId:t.chainIds.arcTestnet,name:`Unknown NFT`,symbol:`NFT`,erc20TokenAddress:a,decimals:0,nftTokenType:n.TokenType.ERC721,tokenIds:o.tokenIds}:null}).filter(e=>!!e),h=await u.tokenVisibilityStorage.hideSpamsAndFetchHiddenTokensAddresses(t.chainIds.arcTestnet,m),g=m.filter(e=>!r.lowerCaseIncludes(h,e.erc20TokenAddress)).map(e=>({...e,tokenIds:s.find(t=>r.caseInsensitiveEqual(t.contractAddress,e.erc20TokenAddress))?.tokenIds}));await(0,p.update)(o.StorageKeys.ARC_PUBLIC_TOKENS,(e={})=>{let t={...e,[i]:g};return this.fetchedTokens=t,t})}async getERC20TokenAddresses(e){let n=[];try{let r=(await f.default.post(`${this.API_BASE}?module=account&action=tokentx&address=${e}`)).data;if(r.status===`1`&&r.result){let i=[...new Set(r.result.map(({contractAddress:e})=>e))];for(let r of i)try{let i=d.getContractWithFetcherByChainId(t.chainIds.arcTestnet,a.ContractType.ERC20Contract,r),o=BigInt(await i.balanceOf(e));o>0n&&n.push({contractAddress:r,tokenBalance:o.toString()})}catch(e){s.Logger.error(`Error fetching ARC testnet token balance:`,e)}}}catch(e){s.Logger.error(`Error fetching ARC testnet token transactions:`,e)}return n.filter(({tokenBalance:e})=>Number(e)!==0).map(({contractAddress:e})=>e)}async getNFTTokens(e){let t=`${this.API_BASE}/v2/addresses/${e}/nft?type=ERC-721,ERC-1155`,n=[],r;do{let e=r?`&${new URLSearchParams(r)}`:``,{data:i}=await f.default.get(`${t}${e}`),{items:a=[],next_page_params:o}=i;n.push(...a),r=o?{token_contract_address_hash:o.token_contract_address_hash,token_id:o.token_id,token_type:o.token_type}:void 0}while(r);let i=n.reduce((e,t)=>{let n=t.token.address_hash.toLowerCase(),r=t.id;return e.has(n)||e.set(n,[]),e.get(n)?.push(r),e},new Map);return Array.from(i.entries()).map(([e,t])=>({contractAddress:e,tokenIds:t}))}},h=new m;exports.ArcPublicTokensDB=m,exports.arcPublicTokensDB=h;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { chainIds as e } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { TokenType as t } from "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { caseInsensitiveEqual as n, lowerCaseIncludes as r } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
4
|
+
import { require_idb_keyval as i } from "../../../../shims/idb-keyval.mjs";
|
|
5
|
+
import { ContractType as a } from "../../types/ethereum-network.types.mjs";
|
|
6
|
+
import { StorageKeys as o } from "../../types/cache.types.mjs";
|
|
7
|
+
import { Logger as s } from "../../error-handling/logger.mjs";
|
|
8
|
+
import { API as c } from "../../API/API.mjs";
|
|
9
|
+
import { getStateKey as l } from "../../functions/utils/string.utils.mjs";
|
|
10
|
+
import { tokenVisibilityStorage as u } from "./token-visibility-db.mjs";
|
|
11
|
+
import { getContractWithFetcherByChainId as d } from "../../functions/web3/getContractMetadata.mjs";
|
|
12
|
+
import f from "axios";
|
|
13
13
|
//#region common/src/data-structures/TokenDBs/ArcPublicTokensDB.ts
|
|
14
|
-
var m = class {
|
|
14
|
+
var p = i(), m = class {
|
|
15
15
|
API_BASE = "https://testnet.arcscan.app/api";
|
|
16
16
|
fetchedTokens = {};
|
|
17
17
|
async getPublicTokens(t) {
|
|
18
|
-
let n =
|
|
19
|
-
return (await
|
|
18
|
+
let n = l(t, e.arcTestnet);
|
|
19
|
+
return (await (0, p.get)(o.ARC_PUBLIC_TOKENS))?.[n] || [];
|
|
20
20
|
}
|
|
21
21
|
getFetchedTokens(t) {
|
|
22
|
-
let n =
|
|
22
|
+
let n = l(t, e.arcTestnet);
|
|
23
23
|
return this.fetchedTokens[n] || [];
|
|
24
24
|
}
|
|
25
25
|
async fetchAndUpdatePublicTokens(i) {
|
|
26
|
-
let
|
|
26
|
+
let a = l(i, e.arcTestnet), s = await this.getERC20TokenAddresses(i), d = await this.getNFTTokens(i), f = d.map((e) => e.contractAddress), m = [...s, ...f];
|
|
27
27
|
if (!m.length) return;
|
|
28
|
-
let h = (await
|
|
28
|
+
let h = (await c.tokensInfoCall(e.arcTestnet, m)).map((r, i) => {
|
|
29
29
|
if (r) return r;
|
|
30
30
|
let a = m[i], o = d.find((e) => n(e.contractAddress, a));
|
|
31
31
|
return o && o.tokenIds && o.tokenIds.length > 0 ? {
|
|
@@ -37,14 +37,14 @@ var m = class {
|
|
|
37
37
|
nftTokenType: t.ERC721,
|
|
38
38
|
tokenIds: o.tokenIds
|
|
39
39
|
} : null;
|
|
40
|
-
}).filter((e) => !!e), g = await
|
|
40
|
+
}).filter((e) => !!e), g = await u.hideSpamsAndFetchHiddenTokensAddresses(e.arcTestnet, h), _ = h.filter((e) => !r(g, e.erc20TokenAddress)).map((e) => ({
|
|
41
41
|
...e,
|
|
42
42
|
tokenIds: d.find((t) => n(t.contractAddress, e.erc20TokenAddress))?.tokenIds
|
|
43
43
|
}));
|
|
44
|
-
await
|
|
44
|
+
await (0, p.update)(o.ARC_PUBLIC_TOKENS, (e = {}) => {
|
|
45
45
|
let t = {
|
|
46
46
|
...e,
|
|
47
|
-
[
|
|
47
|
+
[a]: _
|
|
48
48
|
};
|
|
49
49
|
return this.fetchedTokens = t, t;
|
|
50
50
|
});
|
|
@@ -52,28 +52,28 @@ var m = class {
|
|
|
52
52
|
async getERC20TokenAddresses(t) {
|
|
53
53
|
let n = [];
|
|
54
54
|
try {
|
|
55
|
-
let r = (await
|
|
55
|
+
let r = (await f.post(`${this.API_BASE}?module=account&action=tokentx&address=${t}`)).data;
|
|
56
56
|
if (r.status === "1" && r.result) {
|
|
57
|
-
let
|
|
58
|
-
for (let r of
|
|
59
|
-
let
|
|
57
|
+
let i = [...new Set(r.result.map(({ contractAddress: e }) => e))];
|
|
58
|
+
for (let r of i) try {
|
|
59
|
+
let i = d(e.arcTestnet, a.ERC20Contract, r), o = BigInt(await i.balanceOf(t));
|
|
60
60
|
o > 0n && n.push({
|
|
61
61
|
contractAddress: r,
|
|
62
62
|
tokenBalance: o.toString()
|
|
63
63
|
});
|
|
64
64
|
} catch (e) {
|
|
65
|
-
|
|
65
|
+
s.error("Error fetching ARC testnet token balance:", e);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
} catch (e) {
|
|
69
|
-
|
|
69
|
+
s.error("Error fetching ARC testnet token transactions:", e);
|
|
70
70
|
}
|
|
71
71
|
return n.filter(({ tokenBalance: e }) => Number(e) !== 0).map(({ contractAddress: e }) => e);
|
|
72
72
|
}
|
|
73
73
|
async getNFTTokens(e) {
|
|
74
74
|
let t = `${this.API_BASE}/v2/addresses/${e}/nft?type=ERC-721,ERC-1155`, n = [], r;
|
|
75
75
|
do {
|
|
76
|
-
let e = r ? `&${new URLSearchParams(r)}` : "", { data: i } = await
|
|
76
|
+
let e = r ? `&${new URLSearchParams(r)}` : "", { data: i } = await f.get(`${t}${e}`), { items: a = [], next_page_params: o } = i;
|
|
77
77
|
n.push(...a), r = o ? {
|
|
78
78
|
token_contract_address_hash: o.token_contract_address_hash,
|
|
79
79
|
token_id: o.token_id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/protocol.constants.cjs`),t=require(`../../functions/utils/caseInsensitive.utils.cjs`),n=require(`../../../../shims/idb-keyval.cjs`),r=require(`../../types/cache.types.cjs`),i=require(`../../error-handling/logger.cjs`),a=require(`../../functions/utils/tron.utils.cjs`),o=require(`../../API/API.cjs`),s=require(`../../functions/utils/string.utils.cjs`),c=require(`./token-visibility-db.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`),u=require(`../../functions/utils/create-provider.cjs`),d=require(`../../constants/events.constants.cjs`);require(`../../functions/index.cjs`);let f=require(`ethers`),p=require(`async-mutex`);var m=n.default,h=new class{fetchedTokens={};updateMutexes={};transferEventTopic=f.ethers.id(`Transfer(address,address,uint256)`);chunkSize=2e3;getMutex(e){return this.updateMutexes[e]||(this.updateMutexes[e]=new p.Mutex),this.updateMutexes[e]}async getPublicTokens(e,t){let n=s.getStateKey(t,e);return l.overlayTokensWithRegistryData((await(0,m.get)(r.StorageKeys.EVENTS_PUBLIC_TOKENS))?.[n]||[],e)}async getFetchedTokens(e,t){let n=s.getStateKey(t,e);return l.overlayTokensWithRegistryData(this.fetchedTokens[n]||[],e)}async fetchAndUpdatePublicTokens(e,n){let a=s.getStateKey(e,n);await this.getMutex(a).runExclusive(async()=>{try{let i=(await this.getPublicTokens(n,e)).map(e=>e.erc20TokenAddress),{toEvents:o,fromEvents:s,latestBlock:l}=await this.getEvents(e,n),u=[...o,...s],{erc20Tokens:d}=await this.fetchPublicTokens(u,n,i),f=await c.tokenVisibilityStorage.hideSpamsAndFetchHiddenTokensAddresses(n,d),p=d.filter(e=>!t.lowerCaseIncludes(f,e.erc20TokenAddress));await(0,m.update)(r.StorageKeys.EVENTS_PUBLIC_TOKENS,(e={})=>{let n=e[a]||[],r=n.map(e=>e.erc20TokenAddress),i=p.filter(e=>!t.lowerCaseIncludes(r,e.erc20TokenAddress));n.push(...i);let c=this.updateTokenIds(s,o,n),l={...e,[a]:c};return this.fetchedTokens=l,l}),l&&await this.updateLastProcessedBlock(n,e,l)}catch(e){i.Logger.error(`public tokens db error`,e)}})}async getLastProcessedBlock(e,t){return(await(0,m.get)(r.StorageKeys.PUBLIC_TOKENS_LAST_PROCESSED_BLOCKS)||{})[s.getStateKey(t,e)]||d.EVENTS_INITIAL_BLOCKS[e]}async updateLastProcessedBlock(e,t,n){await(0,m.update)(r.StorageKeys.PUBLIC_TOKENS_LAST_PROCESSED_BLOCKS,(r={})=>{let i=s.getStateKey(t,e);return{...r,[i]:n}})}async getEvents(e,t){try{let n=u.createJsonRpcProvider(t),r=await this.getLastProcessedBlock(t,e)+1,i=await n.getBlockNumber(),o=a.addressToHexFormat(e),s=f.ethers.zeroPadValue(o,32),c=[],l=[];for(let e=r;e<=i;e+=this.chunkSize){let t=Math.min(e+this.chunkSize-1,i),r={topics:[this.transferEventTopic,null,s],fromBlock:e,toBlock:t},a={topics:[this.transferEventTopic,s,null],fromBlock:e,toBlock:t},[o,u]=await Promise.all([n.getLogs(r),n.getLogs(a)]);c.push(...o),l.push(...u)}return{toEvents:c,fromEvents:l,latestBlock:i}}catch(n){return i.Logger.error(`Error fetching events:`,n,`chainId`,t,`walletAddress`,e),{toEvents:[],fromEvents:[],latestBlock:void 0}}}updateTokenIds(e,t,n){let r=new Map;return n.forEach(e=>{if(l.isNFTToken(e)&&e.tokenIds){let t=e.erc20TokenAddress.toLowerCase();r.set(t,[...e.tokenIds])}}),t.forEach(e=>{if(e.topics.length<=3)return;let t=e.address.toLowerCase(),n=BigInt(e.topics[3]).toString();r.has(t)||r.set(t,[]),r.get(t)?.push(n)}),e.forEach(e=>{if(e.topics.length<=3)return;let t=e.address.toLowerCase(),n=r.get(t);if(n?.length){let t=BigInt(e.topics[3]).toString(),r=n.indexOf(t);r!==-1&&n.splice(r,1)}}),n.forEach(e=>{if(l.isNFTToken(e)){let t=e.erc20TokenAddress.toLowerCase(),n=r.get(t);e.tokenIds=n?.length&&n.length>0?n:void 0}}),n}async fetchPublicTokens(n,r,a){try{let i=[e.zeroAddress,...new Set(n.map(e=>e.address))].filter(e=>e&&!t.lowerCaseIncludes(a,e));return i.length?{erc20Tokens:(await o.API.tokensInfoCall(r,i)).filter(e=>!!e)}:{erc20Tokens:[]}}catch(e){return i.Logger.error(`Error fetching public tokens:`,e),{erc20Tokens:[]}}}};exports.eventsPublicTokensDB=h;
|
|
@@ -1,70 +1,71 @@
|
|
|
1
1
|
import { zeroAddress as e } from "../../constants/protocol.constants.mjs";
|
|
2
2
|
import { lowerCaseIncludes as t } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
3
|
+
import { require_idb_keyval as n } from "../../../../shims/idb-keyval.mjs";
|
|
4
|
+
import { StorageKeys as r } from "../../types/cache.types.mjs";
|
|
5
|
+
import { Logger as i } from "../../error-handling/logger.mjs";
|
|
6
|
+
import { addressToHexFormat as a } from "../../functions/utils/tron.utils.mjs";
|
|
7
|
+
import { API as o } from "../../API/API.mjs";
|
|
8
|
+
import { getStateKey as s } from "../../functions/utils/string.utils.mjs";
|
|
9
|
+
import { tokenVisibilityStorage as c } from "./token-visibility-db.mjs";
|
|
10
|
+
import { isNFTToken as l, overlayTokensWithRegistryData as u } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
11
|
+
import { createJsonRpcProvider as d } from "../../functions/utils/create-provider.mjs";
|
|
12
|
+
import { EVENTS_INITIAL_BLOCKS as f } from "../../constants/events.constants.mjs";
|
|
12
13
|
import "../../functions/index.mjs";
|
|
13
|
-
import { ethers as
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
var g = new class {
|
|
14
|
+
import { ethers as p } from "ethers";
|
|
15
|
+
import { Mutex as m } from "async-mutex";
|
|
16
|
+
//#region common/src/data-structures/TokenDBs/EventsPublicTokensDB.ts
|
|
17
|
+
var h = n(), g = new class {
|
|
17
18
|
fetchedTokens = {};
|
|
18
19
|
updateMutexes = {};
|
|
19
|
-
transferEventTopic =
|
|
20
|
+
transferEventTopic = p.id("Transfer(address,address,uint256)");
|
|
20
21
|
chunkSize = 2e3;
|
|
21
22
|
getMutex(e) {
|
|
22
|
-
return this.updateMutexes[e] || (this.updateMutexes[e] = new
|
|
23
|
+
return this.updateMutexes[e] || (this.updateMutexes[e] = new m()), this.updateMutexes[e];
|
|
23
24
|
}
|
|
24
25
|
async getPublicTokens(e, t) {
|
|
25
|
-
let
|
|
26
|
-
return
|
|
26
|
+
let n = s(t, e);
|
|
27
|
+
return u((await (0, h.get)(r.EVENTS_PUBLIC_TOKENS))?.[n] || [], e);
|
|
27
28
|
}
|
|
28
29
|
async getFetchedTokens(e, t) {
|
|
29
|
-
let n =
|
|
30
|
-
return
|
|
30
|
+
let n = s(t, e);
|
|
31
|
+
return u(this.fetchedTokens[n] || [], e);
|
|
31
32
|
}
|
|
32
|
-
async fetchAndUpdatePublicTokens(e,
|
|
33
|
-
let a =
|
|
33
|
+
async fetchAndUpdatePublicTokens(e, n) {
|
|
34
|
+
let a = s(e, n);
|
|
34
35
|
await this.getMutex(a).runExclusive(async () => {
|
|
35
36
|
try {
|
|
36
|
-
let
|
|
37
|
-
await
|
|
37
|
+
let i = (await this.getPublicTokens(n, e)).map((e) => e.erc20TokenAddress), { toEvents: o, fromEvents: s, latestBlock: l } = await this.getEvents(e, n), u = [...o, ...s], { erc20Tokens: d } = await this.fetchPublicTokens(u, n, i), f = await c.hideSpamsAndFetchHiddenTokensAddresses(n, d), p = d.filter((e) => !t(f, e.erc20TokenAddress));
|
|
38
|
+
await (0, h.update)(r.EVENTS_PUBLIC_TOKENS, (e = {}) => {
|
|
38
39
|
let n = e[a] || [], r = n.map((e) => e.erc20TokenAddress), i = p.filter((e) => !t(r, e.erc20TokenAddress));
|
|
39
40
|
n.push(...i);
|
|
40
|
-
let
|
|
41
|
+
let c = this.updateTokenIds(s, o, n), l = {
|
|
41
42
|
...e,
|
|
42
|
-
[a]:
|
|
43
|
+
[a]: c
|
|
43
44
|
};
|
|
44
45
|
return this.fetchedTokens = l, l;
|
|
45
|
-
}), l && await this.updateLastProcessedBlock(
|
|
46
|
+
}), l && await this.updateLastProcessedBlock(n, e, l);
|
|
46
47
|
} catch (e) {
|
|
47
|
-
|
|
48
|
+
i.error("public tokens db error", e);
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
52
|
async getLastProcessedBlock(e, t) {
|
|
52
|
-
return (await
|
|
53
|
+
return (await (0, h.get)(r.PUBLIC_TOKENS_LAST_PROCESSED_BLOCKS) || {})[s(t, e)] || f[e];
|
|
53
54
|
}
|
|
54
|
-
async updateLastProcessedBlock(e, t,
|
|
55
|
-
await
|
|
56
|
-
let i =
|
|
55
|
+
async updateLastProcessedBlock(e, t, n) {
|
|
56
|
+
await (0, h.update)(r.PUBLIC_TOKENS_LAST_PROCESSED_BLOCKS, (r = {}) => {
|
|
57
|
+
let i = s(t, e);
|
|
57
58
|
return {
|
|
58
|
-
...
|
|
59
|
-
[i]:
|
|
59
|
+
...r,
|
|
60
|
+
[i]: n
|
|
60
61
|
};
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
async getEvents(e, t) {
|
|
64
65
|
try {
|
|
65
|
-
let n =
|
|
66
|
-
for (let e = r; e <=
|
|
67
|
-
let t = Math.min(e + this.chunkSize - 1,
|
|
66
|
+
let n = d(t), r = await this.getLastProcessedBlock(t, e) + 1, i = await n.getBlockNumber(), o = a(e), s = p.zeroPadValue(o, 32), c = [], l = [];
|
|
67
|
+
for (let e = r; e <= i; e += this.chunkSize) {
|
|
68
|
+
let t = Math.min(e + this.chunkSize - 1, i), r = {
|
|
68
69
|
topics: [
|
|
69
70
|
this.transferEventTopic,
|
|
70
71
|
null,
|
|
@@ -72,7 +73,7 @@ var g = new class {
|
|
|
72
73
|
],
|
|
73
74
|
fromBlock: e,
|
|
74
75
|
toBlock: t
|
|
75
|
-
},
|
|
76
|
+
}, a = {
|
|
76
77
|
topics: [
|
|
77
78
|
this.transferEventTopic,
|
|
78
79
|
s,
|
|
@@ -80,16 +81,16 @@ var g = new class {
|
|
|
80
81
|
],
|
|
81
82
|
fromBlock: e,
|
|
82
83
|
toBlock: t
|
|
83
|
-
}, [o, u] = await Promise.all([n.getLogs(r), n.getLogs(
|
|
84
|
+
}, [o, u] = await Promise.all([n.getLogs(r), n.getLogs(a)]);
|
|
84
85
|
c.push(...o), l.push(...u);
|
|
85
86
|
}
|
|
86
87
|
return {
|
|
87
88
|
toEvents: c,
|
|
88
89
|
fromEvents: l,
|
|
89
|
-
latestBlock:
|
|
90
|
+
latestBlock: i
|
|
90
91
|
};
|
|
91
92
|
} catch (n) {
|
|
92
|
-
return
|
|
93
|
+
return i.error("Error fetching events:", n, "chainId", t, "walletAddress", e), {
|
|
93
94
|
toEvents: [],
|
|
94
95
|
fromEvents: [],
|
|
95
96
|
latestBlock: void 0
|
|
@@ -99,7 +100,7 @@ var g = new class {
|
|
|
99
100
|
updateTokenIds(e, t, n) {
|
|
100
101
|
let r = /* @__PURE__ */ new Map();
|
|
101
102
|
return n.forEach((e) => {
|
|
102
|
-
if (
|
|
103
|
+
if (l(e) && e.tokenIds) {
|
|
103
104
|
let t = e.erc20TokenAddress.toLowerCase();
|
|
104
105
|
r.set(t, [...e.tokenIds]);
|
|
105
106
|
}
|
|
@@ -115,18 +116,18 @@ var g = new class {
|
|
|
115
116
|
r !== -1 && n.splice(r, 1);
|
|
116
117
|
}
|
|
117
118
|
}), n.forEach((e) => {
|
|
118
|
-
if (
|
|
119
|
+
if (l(e)) {
|
|
119
120
|
let t = e.erc20TokenAddress.toLowerCase(), n = r.get(t);
|
|
120
121
|
e.tokenIds = n?.length && n.length > 0 ? n : void 0;
|
|
121
122
|
}
|
|
122
123
|
}), n;
|
|
123
124
|
}
|
|
124
|
-
async fetchPublicTokens(n,
|
|
125
|
+
async fetchPublicTokens(n, r, a) {
|
|
125
126
|
try {
|
|
126
|
-
let
|
|
127
|
-
return
|
|
127
|
+
let i = [e, ...new Set(n.map((e) => e.address))].filter((e) => e && !t(a, e));
|
|
128
|
+
return i.length ? { erc20Tokens: (await o.tokensInfoCall(r, i)).filter((e) => !!e) } : { erc20Tokens: [] };
|
|
128
129
|
} catch (e) {
|
|
129
|
-
return
|
|
130
|
+
return i.error("Error fetching public tokens:", e), { erc20Tokens: [] };
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
}();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`../../functions/utils/caseInsensitive.utils.cjs`),t=require(`../../../../shims/idb-keyval.cjs`),n=require(`../../types/cache.types.cjs`),r=require(`../../error-handling/logger.cjs`),i=require(`../../API/API.cjs`),a=require(`../../functions/utils/string.utils.cjs`),o=require(`./token-visibility-db.cjs`);var s=t.default,c=class{fetchedTokens={};initalFetched=!1;async updateFetchedTokens(){let e=await(0,s.get)(n.StorageKeys.PRIVATE_TOKENS);this.fetchedTokens=e??{},this.initalFetched=!0}async getPrivateTokens(e,t){let r=a.getStateKey(t,e);return(await(0,s.get)(n.StorageKeys.PRIVATE_TOKENS))?.[r]||[]}async fetchPrivateTokens(t,n,a){try{let r=[...new Set(n)].filter(t=>t&&!e.lowerCaseIncludes(a,t));if(!r.length)return[];let o=(await i.API.tokensInfoCall(t,r)).filter(e=>!!e),s=new Map;return o.forEach(e=>{s.set(e.erc20TokenAddress.toLowerCase(),e)}),Array.from(s.values())}catch(e){return r.Logger.error(`Error fetching private tokens:`,e),[]}}async fetchAndUpdatePrivateTokens(t,r,i,c){let l=(await this.getPrivateTokens(r,i)).map(e=>e.erc20TokenAddress),u=c??await this.fetchPrivateTokens(r,t,l),d=await o.tokenVisibilityStorage.hideSpamsAndFetchHiddenTokensAddresses(r,u),f=a.getStateKey(i,r);await(0,s.update)(n.StorageKeys.PRIVATE_TOKENS,(t={})=>{let n=t?.[f]||[],r=n.map(e=>e.erc20TokenAddress),i=u.filter(t=>!e.lowerCaseIncludes(r,t.erc20TokenAddress));n.push(...i);let a=n.filter(t=>!e.lowerCaseIncludes(d,t.erc20TokenAddress)),o={...t,[f]:a};return this.fetchedTokens=o,o})}getFetchedTokens(e,t){let n=a.getStateKey(t,e);return this.fetchedTokens[n]||[]}},l=new c;exports.PrivateTokensDB=c,exports.privateTokensDB=l;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { lowerCaseIncludes as e } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { require_idb_keyval as t } from "../../../../shims/idb-keyval.mjs";
|
|
3
|
+
import { StorageKeys as n } from "../../types/cache.types.mjs";
|
|
4
|
+
import { Logger as r } from "../../error-handling/logger.mjs";
|
|
5
|
+
import { API as i } from "../../API/API.mjs";
|
|
6
|
+
import { getStateKey as a } from "../../functions/utils/string.utils.mjs";
|
|
7
|
+
import { tokenVisibilityStorage as o } from "./token-visibility-db.mjs";
|
|
8
8
|
//#region common/src/data-structures/TokenDBs/PrivateTokensDB.ts
|
|
9
|
-
var c = class {
|
|
9
|
+
var s = t(), c = class {
|
|
10
10
|
fetchedTokens = {};
|
|
11
11
|
initalFetched = !1;
|
|
12
12
|
async updateFetchedTokens() {
|
|
13
|
-
let e = await
|
|
13
|
+
let e = await (0, s.get)(n.PRIVATE_TOKENS);
|
|
14
14
|
this.fetchedTokens = e ?? {}, this.initalFetched = !0;
|
|
15
15
|
}
|
|
16
|
-
async getPrivateTokens(e,
|
|
17
|
-
let r =
|
|
18
|
-
return (await
|
|
16
|
+
async getPrivateTokens(e, t) {
|
|
17
|
+
let r = a(t, e);
|
|
18
|
+
return (await (0, s.get)(n.PRIVATE_TOKENS))?.[r] || [];
|
|
19
19
|
}
|
|
20
|
-
async fetchPrivateTokens(t,
|
|
20
|
+
async fetchPrivateTokens(t, n, a) {
|
|
21
21
|
try {
|
|
22
|
-
let
|
|
23
|
-
if (!
|
|
24
|
-
let o = (await
|
|
22
|
+
let r = [...new Set(n)].filter((t) => t && !e(a, t));
|
|
23
|
+
if (!r.length) return [];
|
|
24
|
+
let o = (await i.tokensInfoCall(t, r)).filter((e) => !!e), s = /* @__PURE__ */ new Map();
|
|
25
25
|
return o.forEach((e) => {
|
|
26
26
|
s.set(e.erc20TokenAddress.toLowerCase(), e);
|
|
27
27
|
}), Array.from(s.values());
|
|
28
28
|
} catch (e) {
|
|
29
|
-
return
|
|
29
|
+
return r.error("Error fetching private tokens:", e), [];
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
async fetchAndUpdatePrivateTokens(
|
|
33
|
-
let l = (await this.getPrivateTokens(r,
|
|
34
|
-
await s(
|
|
32
|
+
async fetchAndUpdatePrivateTokens(t, r, i, c) {
|
|
33
|
+
let l = (await this.getPrivateTokens(r, i)).map((e) => e.erc20TokenAddress), u = c ?? await this.fetchPrivateTokens(r, t, l), d = await o.hideSpamsAndFetchHiddenTokensAddresses(r, u), f = a(i, r);
|
|
34
|
+
await (0, s.update)(n.PRIVATE_TOKENS, (t = {}) => {
|
|
35
35
|
let n = t?.[f] || [], r = n.map((e) => e.erc20TokenAddress), i = u.filter((t) => !e(r, t.erc20TokenAddress));
|
|
36
36
|
n.push(...i);
|
|
37
37
|
let a = n.filter((t) => !e(d, t.erc20TokenAddress)), o = {
|
|
@@ -42,7 +42,7 @@ var c = class {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
getFetchedTokens(e, t) {
|
|
45
|
-
let n =
|
|
45
|
+
let n = a(t, e);
|
|
46
46
|
return this.fetchedTokens[n] || [];
|
|
47
47
|
}
|
|
48
48
|
}, l = new c();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`../../functions/utils/caseInsensitive.utils.cjs`),t=require(`../../../../shims/idb-keyval.cjs`),n=require(`../../types/cache.types.cjs`),r=require(`../../API/API.cjs`),i=require(`../../functions/utils/string.utils.cjs`),a=require(`./token-visibility-db.cjs`),o=require(`../../functions/utils/erc20tokenFunctions.cjs`),s=require(`../../functions/utils/publicBalance.utils.cjs`);var c=t.default,l=class{fetchedTokens={};async getPublicTokens(e,t){let r=i.getStateKey(e,t);return o.overlayTokensWithRegistryData((await(0,c.get)(n.StorageKeys.TEMPO_PUBLIC_TOKENS))?.[r]||[],t)}async getFetchedTokens(e,t){let n=i.getStateKey(e,t);return o.overlayTokensWithRegistryData(this.fetchedTokens[n]||[],t)}async fetchAndUpdatePublicTokens(t,o){let s=i.getStateKey(t,o),l=await this.getHeldTokenAddresses(t,o);if(!l.length)return;let u=(await r.API.tokensInfoCall(o,l)).filter(e=>!!e),d=await a.tokenVisibilityStorage.hideSpamsAndFetchHiddenTokensAddresses(o,u),f=u.filter(t=>!e.lowerCaseIncludes(d,t.erc20TokenAddress));await(0,c.update)(n.StorageKeys.TEMPO_PUBLIC_TOKENS,(e={})=>{let t={...e,[s]:f};return this.fetchedTokens=t,t})}async getHeldTokenAddresses(e,t){let n=await o.getErc20TokensForChainAPI(t),r=await Promise.all(n.map(async n=>{let r=await s.getPublicBalanceByTokenAddress(t,e,n.erc20TokenAddress);return r&&r>0n?n.erc20TokenAddress:null}));return Array.from(new Set(r.filter(e=>!!e)))}},u=new l;exports.TempoPublicTokensDB=l,exports.tempoPublicTokensDB=u;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { lowerCaseIncludes as e } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { require_idb_keyval as t } from "../../../../shims/idb-keyval.mjs";
|
|
3
|
+
import { StorageKeys as n } from "../../types/cache.types.mjs";
|
|
4
|
+
import { API as r } from "../../API/API.mjs";
|
|
5
|
+
import { getStateKey as i } from "../../functions/utils/string.utils.mjs";
|
|
6
|
+
import { tokenVisibilityStorage as a } from "./token-visibility-db.mjs";
|
|
7
|
+
import { getErc20TokensForChainAPI as o, overlayTokensWithRegistryData as s } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
8
|
+
import { getPublicBalanceByTokenAddress as c } from "../../functions/utils/publicBalance.utils.mjs";
|
|
9
9
|
//#region common/src/data-structures/TokenDBs/TempoPublicTokensDB.ts
|
|
10
|
-
var u = class {
|
|
10
|
+
var l = t(), u = class {
|
|
11
11
|
fetchedTokens = {};
|
|
12
|
-
async getPublicTokens(e,
|
|
13
|
-
let
|
|
14
|
-
return
|
|
12
|
+
async getPublicTokens(e, t) {
|
|
13
|
+
let r = i(e, t);
|
|
14
|
+
return s((await (0, l.get)(n.TEMPO_PUBLIC_TOKENS))?.[r] || [], t);
|
|
15
15
|
}
|
|
16
16
|
async getFetchedTokens(e, t) {
|
|
17
|
-
let n =
|
|
18
|
-
return
|
|
17
|
+
let n = i(e, t);
|
|
18
|
+
return s(this.fetchedTokens[n] || [], t);
|
|
19
19
|
}
|
|
20
|
-
async fetchAndUpdatePublicTokens(
|
|
21
|
-
let s =
|
|
20
|
+
async fetchAndUpdatePublicTokens(t, o) {
|
|
21
|
+
let s = i(t, o), c = await this.getHeldTokenAddresses(t, o);
|
|
22
22
|
if (!c.length) return;
|
|
23
|
-
let u = (await
|
|
24
|
-
await l(
|
|
23
|
+
let u = (await r.tokensInfoCall(o, c)).filter((e) => !!e), d = await a.hideSpamsAndFetchHiddenTokensAddresses(o, u), f = u.filter((t) => !e(d, t.erc20TokenAddress));
|
|
24
|
+
await (0, l.update)(n.TEMPO_PUBLIC_TOKENS, (e = {}) => {
|
|
25
25
|
let t = {
|
|
26
26
|
...e,
|
|
27
27
|
[s]: f
|
|
@@ -30,8 +30,8 @@ var u = class {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
async getHeldTokenAddresses(e, t) {
|
|
33
|
-
let n = await
|
|
34
|
-
let r = await
|
|
33
|
+
let n = await o(t), r = await Promise.all(n.map(async (n) => {
|
|
34
|
+
let r = await c(t, e, n.erc20TokenAddress);
|
|
35
35
|
return r && r > 0n ? n.erc20TokenAddress : null;
|
|
36
36
|
}));
|
|
37
37
|
return Array.from(new Set(r.filter((e) => !!e)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`../../constants/protocol.constants.cjs`),t=require(`../../functions/utils/caseInsensitive.utils.cjs`),n=require(`../../../../shims/idb-keyval.cjs`),r=require(`../../types/cache.types.cjs`),i=require(`../http/HttpClient.cjs`);require(`../http/index.cjs`);const a=require(`../../functions/utils/tron.utils.cjs`),o=require(`../../API/API.cjs`),s=require(`../../functions/utils/string.utils.cjs`),c=require(`./token-visibility-db.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`);var u=n.default,d=class{fetchedTokens={};async getPublicTokens(e,t){let n=s.getStateKey(e,t);return l.overlayTokensWithRegistryData((await(0,u.get)(r.StorageKeys.TRON_PUBLIC_TOKENS))?.[n]||[],t)}async getFetchedTokens(e,t){let n=s.getStateKey(e,t);return l.overlayTokensWithRegistryData(this.fetchedTokens[n]||[],t)}async fetchAndUpdatePublicTokens(e,n){let i=s.getStateKey(e,n),a=await this.getHeldTokenAddresses(e,n);if(!a.length)return;let l=(await o.API.tokensInfoCall(n,a)).filter(e=>!!e),d=await c.tokenVisibilityStorage.hideSpamsAndFetchHiddenTokensAddresses(n,l),f=l.filter(e=>!t.lowerCaseIncludes(d,e.erc20TokenAddress));await(0,u.update)(r.StorageKeys.TRON_PUBLIC_TOKENS,(e={})=>{let t={...e,[i]:f};return this.fetchedTokens=t,t})}async getHeldTokenAddresses(t,n){let r=a.toTronBase58IfHex(t),o=`${a.getTronWalletRpcUrl(n)}/v1/accounts/${r}`,s=(await i.httpClient.get(o))?.data?.[0];if(!s)return[];let c=[];return s.balance&&s.balance>0&&c.push(e.zeroAddress),(s.trc20??[]).forEach(e=>{Object.entries(e).forEach(([e,t])=>{BigInt(t)>0n&&c.push(a.addressToHexFormat(e))})}),Array.from(new Set(c))}},f=new d;exports.TronPublicTokensDB=d,exports.tronPublicTokensDB=f;
|