@polymarbot/shared 0.3.1 → 0.3.2
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/package.json +1 -1
- package/wallet.cjs +20 -0
- package/wallet.d.cts +3 -1
- package/wallet.d.ts +3 -1
- package/wallet.js +19 -0
package/package.json
CHANGED
package/wallet.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(wallet_exports, {
|
|
|
26
26
|
formatBalance: () => formatBalance,
|
|
27
27
|
getPublicClient: () => getPublicClient,
|
|
28
28
|
getUSDCBalance: () => getUSDCBalance,
|
|
29
|
+
getUSDCBalancesBatch: () => getUSDCBalancesBatch,
|
|
29
30
|
isAddressEqual: () => isAddressEqual
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(wallet_exports);
|
|
@@ -59,6 +60,24 @@ async function getUSDCBalance(address) {
|
|
|
59
60
|
args: [address]
|
|
60
61
|
});
|
|
61
62
|
}
|
|
63
|
+
async function getUSDCBalancesBatch(addresses) {
|
|
64
|
+
if (addresses.length === 0) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const publicClient = getPublicClient();
|
|
68
|
+
const multicallResults = await publicClient.multicall({
|
|
69
|
+
contracts: addresses.map((address) => ({
|
|
70
|
+
address: USDC_ADDRESS,
|
|
71
|
+
abi: USDC_ABI,
|
|
72
|
+
functionName: "balanceOf",
|
|
73
|
+
args: [address]
|
|
74
|
+
})),
|
|
75
|
+
allowFailure: true
|
|
76
|
+
});
|
|
77
|
+
return multicallResults.map(
|
|
78
|
+
(result) => result.status === "success" ? result.result : 0n
|
|
79
|
+
);
|
|
80
|
+
}
|
|
62
81
|
function isAddressEqual(a, b) {
|
|
63
82
|
if (!a) return false;
|
|
64
83
|
if (!b) return false;
|
|
@@ -72,5 +91,6 @@ function isAddressEqual(a, b) {
|
|
|
72
91
|
formatBalance,
|
|
73
92
|
getPublicClient,
|
|
74
93
|
getUSDCBalance,
|
|
94
|
+
getUSDCBalancesBatch,
|
|
75
95
|
isAddressEqual
|
|
76
96
|
});
|
package/wallet.d.cts
CHANGED
|
@@ -20,6 +20,8 @@ declare function formatBalance(rawBalance: string | bigint, decimals?: number):
|
|
|
20
20
|
|
|
21
21
|
declare function getUSDCBalance(address: string): Promise<bigint>;
|
|
22
22
|
|
|
23
|
+
declare function getUSDCBalancesBatch(addresses: string[]): Promise<bigint[]>;
|
|
24
|
+
|
|
23
25
|
declare function isAddressEqual(a?: Address | string | null, b?: Address | string | null): boolean;
|
|
24
26
|
|
|
25
|
-
export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, isAddressEqual };
|
|
27
|
+
export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, getUSDCBalancesBatch, isAddressEqual };
|
package/wallet.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ declare function formatBalance(rawBalance: string | bigint, decimals?: number):
|
|
|
20
20
|
|
|
21
21
|
declare function getUSDCBalance(address: string): Promise<bigint>;
|
|
22
22
|
|
|
23
|
+
declare function getUSDCBalancesBatch(addresses: string[]): Promise<bigint[]>;
|
|
24
|
+
|
|
23
25
|
declare function isAddressEqual(a?: Address | string | null, b?: Address | string | null): boolean;
|
|
24
26
|
|
|
25
|
-
export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, isAddressEqual };
|
|
27
|
+
export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, getUSDCBalancesBatch, isAddressEqual };
|
package/wallet.js
CHANGED
|
@@ -29,6 +29,24 @@ async function getUSDCBalance(address) {
|
|
|
29
29
|
args: [address]
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
+
async function getUSDCBalancesBatch(addresses) {
|
|
33
|
+
if (addresses.length === 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const publicClient = getPublicClient();
|
|
37
|
+
const multicallResults = await publicClient.multicall({
|
|
38
|
+
contracts: addresses.map((address) => ({
|
|
39
|
+
address: USDC_ADDRESS,
|
|
40
|
+
abi: USDC_ABI,
|
|
41
|
+
functionName: "balanceOf",
|
|
42
|
+
args: [address]
|
|
43
|
+
})),
|
|
44
|
+
allowFailure: true
|
|
45
|
+
});
|
|
46
|
+
return multicallResults.map(
|
|
47
|
+
(result) => result.status === "success" ? result.result : 0n
|
|
48
|
+
);
|
|
49
|
+
}
|
|
32
50
|
function isAddressEqual(a, b) {
|
|
33
51
|
if (!a) return false;
|
|
34
52
|
if (!b) return false;
|
|
@@ -41,5 +59,6 @@ export {
|
|
|
41
59
|
formatBalance,
|
|
42
60
|
getPublicClient,
|
|
43
61
|
getUSDCBalance,
|
|
62
|
+
getUSDCBalancesBatch,
|
|
44
63
|
isAddressEqual
|
|
45
64
|
};
|