@polymarbot/shared 0.1.0
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/basic.cjs +88 -0
- package/basic.d.cts +34 -0
- package/basic.d.ts +34 -0
- package/basic.js +60 -0
- package/package.json +47 -0
- package/relayer-client.cjs +64 -0
- package/relayer-client.d.cts +27 -0
- package/relayer-client.d.ts +27 -0
- package/relayer-client.js +38 -0
- package/trade-strategy/normalize.cjs +168 -0
- package/trade-strategy/normalize.d.cts +29 -0
- package/trade-strategy/normalize.d.ts +29 -0
- package/trade-strategy/normalize.js +142 -0
- package/trade-strategy/types.cjs +18 -0
- package/trade-strategy/types.d.cts +231 -0
- package/trade-strategy/types.d.ts +231 -0
- package/trade-strategy/types.js +0 -0
- package/wallet.cjs +76 -0
- package/wallet.d.cts +39 -0
- package/wallet.d.ts +39 -0
- package/wallet.js +45 -0
package/wallet.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PublicClient, Address } from 'viem';
|
|
2
|
+
|
|
3
|
+
declare const USDC_ADDRESS = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
4
|
+
declare const USDC_DECIMALS = 6;
|
|
5
|
+
declare const USDC_ABI: readonly [{
|
|
6
|
+
readonly name: "balanceOf";
|
|
7
|
+
readonly type: "function";
|
|
8
|
+
readonly stateMutability: "view";
|
|
9
|
+
readonly inputs: readonly [{
|
|
10
|
+
readonly type: "address";
|
|
11
|
+
}];
|
|
12
|
+
readonly outputs: readonly [{
|
|
13
|
+
readonly type: "uint256";
|
|
14
|
+
}];
|
|
15
|
+
}];
|
|
16
|
+
/**
|
|
17
|
+
* 创建单例 publicClient,避免重复实例化
|
|
18
|
+
* @returns viem PublicClient 实例
|
|
19
|
+
*/
|
|
20
|
+
declare const getPublicClient: () => PublicClient;
|
|
21
|
+
/**
|
|
22
|
+
* 格式化原始余额为可读格式
|
|
23
|
+
* @param rawBalance - 原始余额
|
|
24
|
+
* @param decimals - 小数位数
|
|
25
|
+
* @returns 格式化后的余额
|
|
26
|
+
*/
|
|
27
|
+
declare function formatBalance(rawBalance: string | bigint, decimals?: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* 查询指定地址的 USDC 余额
|
|
30
|
+
* @param address - 要查询的地址
|
|
31
|
+
* @returns USDC 余额 (原始值,需要用 formatBalance 格式化)
|
|
32
|
+
*/
|
|
33
|
+
declare function getUSDCBalance(address: string): Promise<bigint>;
|
|
34
|
+
/**
|
|
35
|
+
* 比较两个以太坊地址是否相等
|
|
36
|
+
*/
|
|
37
|
+
declare function isAddressEqual(a?: Address | string | null, b?: Address | string | null): boolean;
|
|
38
|
+
|
|
39
|
+
export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, isAddressEqual };
|
package/wallet.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PublicClient, Address } from 'viem';
|
|
2
|
+
|
|
3
|
+
declare const USDC_ADDRESS = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
4
|
+
declare const USDC_DECIMALS = 6;
|
|
5
|
+
declare const USDC_ABI: readonly [{
|
|
6
|
+
readonly name: "balanceOf";
|
|
7
|
+
readonly type: "function";
|
|
8
|
+
readonly stateMutability: "view";
|
|
9
|
+
readonly inputs: readonly [{
|
|
10
|
+
readonly type: "address";
|
|
11
|
+
}];
|
|
12
|
+
readonly outputs: readonly [{
|
|
13
|
+
readonly type: "uint256";
|
|
14
|
+
}];
|
|
15
|
+
}];
|
|
16
|
+
/**
|
|
17
|
+
* 创建单例 publicClient,避免重复实例化
|
|
18
|
+
* @returns viem PublicClient 实例
|
|
19
|
+
*/
|
|
20
|
+
declare const getPublicClient: () => PublicClient;
|
|
21
|
+
/**
|
|
22
|
+
* 格式化原始余额为可读格式
|
|
23
|
+
* @param rawBalance - 原始余额
|
|
24
|
+
* @param decimals - 小数位数
|
|
25
|
+
* @returns 格式化后的余额
|
|
26
|
+
*/
|
|
27
|
+
declare function formatBalance(rawBalance: string | bigint, decimals?: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* 查询指定地址的 USDC 余额
|
|
30
|
+
* @param address - 要查询的地址
|
|
31
|
+
* @returns USDC 余额 (原始值,需要用 formatBalance 格式化)
|
|
32
|
+
*/
|
|
33
|
+
declare function getUSDCBalance(address: string): Promise<bigint>;
|
|
34
|
+
/**
|
|
35
|
+
* 比较两个以太坊地址是否相等
|
|
36
|
+
*/
|
|
37
|
+
declare function isAddressEqual(a?: Address | string | null, b?: Address | string | null): boolean;
|
|
38
|
+
|
|
39
|
+
export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, isAddressEqual };
|
package/wallet.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/utils/wallet.ts
|
|
2
|
+
import { createPublicClient, http, formatUnits, parseAbi } from "viem";
|
|
3
|
+
import { polygon } from "viem/chains";
|
|
4
|
+
var USDC_ADDRESS = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
5
|
+
var USDC_DECIMALS = 6;
|
|
6
|
+
var USDC_ABI = parseAbi(["function balanceOf(address) view returns (uint256)"]);
|
|
7
|
+
var getPublicClient = (() => {
|
|
8
|
+
const POLYGON_RPC = process.env.POLYGON_RPC || polygon.rpcUrls.default.http[0];
|
|
9
|
+
let client = null;
|
|
10
|
+
return () => {
|
|
11
|
+
if (!client) {
|
|
12
|
+
client = createPublicClient({
|
|
13
|
+
chain: polygon,
|
|
14
|
+
transport: http(POLYGON_RPC)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return client;
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
function formatBalance(rawBalance, decimals = USDC_DECIMALS) {
|
|
21
|
+
return parseFloat(formatUnits(BigInt(rawBalance), decimals)).toFixed(2);
|
|
22
|
+
}
|
|
23
|
+
async function getUSDCBalance(address) {
|
|
24
|
+
const publicClient = getPublicClient();
|
|
25
|
+
return await publicClient.readContract({
|
|
26
|
+
address: USDC_ADDRESS,
|
|
27
|
+
abi: USDC_ABI,
|
|
28
|
+
functionName: "balanceOf",
|
|
29
|
+
args: [address]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function isAddressEqual(a, b) {
|
|
33
|
+
if (!a) return false;
|
|
34
|
+
if (!b) return false;
|
|
35
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
USDC_ABI,
|
|
39
|
+
USDC_ADDRESS,
|
|
40
|
+
USDC_DECIMALS,
|
|
41
|
+
formatBalance,
|
|
42
|
+
getPublicClient,
|
|
43
|
+
getUSDCBalance,
|
|
44
|
+
isAddressEqual
|
|
45
|
+
};
|