@coinbase/agentkit 0.0.0-nightly-20250328174338
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/README.md +827 -0
- package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
- package/dist/action-providers/across/acrossActionProvider.js +333 -0
- package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
- package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
- package/dist/action-providers/across/constants.d.ts +1 -0
- package/dist/action-providers/across/constants.js +2 -0
- package/dist/action-providers/across/index.d.ts +1 -0
- package/dist/action-providers/across/index.js +17 -0
- package/dist/action-providers/across/schemas.d.ts +36 -0
- package/dist/action-providers/across/schemas.js +46 -0
- package/dist/action-providers/across/utils.d.ts +7 -0
- package/dist/action-providers/across/utils.js +25 -0
- package/dist/action-providers/actionDecorator.d.ts +69 -0
- package/dist/action-providers/actionDecorator.js +96 -0
- package/dist/action-providers/actionProvider.d.ts +48 -0
- package/dist/action-providers/actionProvider.js +62 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.d.ts +55 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.js +173 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.d.ts +1 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.js +131 -0
- package/dist/action-providers/alchemy/index.d.ts +2 -0
- package/dist/action-providers/alchemy/index.js +18 -0
- package/dist/action-providers/alchemy/schemas.d.ts +41 -0
- package/dist/action-providers/alchemy/schemas.js +34 -0
- package/dist/action-providers/allora/alloraActionProvider.d.ts +44 -0
- package/dist/action-providers/allora/alloraActionProvider.js +195 -0
- package/dist/action-providers/allora/alloraActionProvider.test.d.ts +1 -0
- package/dist/action-providers/allora/alloraActionProvider.test.js +109 -0
- package/dist/action-providers/allora/index.d.ts +2 -0
- package/dist/action-providers/allora/index.js +18 -0
- package/dist/action-providers/allora/schemas.d.ts +28 -0
- package/dist/action-providers/allora/schemas.js +30 -0
- package/dist/action-providers/basename/basenameActionProvider.d.ts +30 -0
- package/dist/action-providers/basename/basenameActionProvider.js +109 -0
- package/dist/action-providers/basename/basenameActionProvider.test.d.ts +1 -0
- package/dist/action-providers/basename/basenameActionProvider.test.js +146 -0
- package/dist/action-providers/basename/constants.d.ts +52 -0
- package/dist/action-providers/basename/constants.js +81 -0
- package/dist/action-providers/basename/index.d.ts +2 -0
- package/dist/action-providers/basename/index.js +18 -0
- package/dist/action-providers/basename/schemas.d.ts +14 -0
- package/dist/action-providers/basename/schemas.js +14 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +43 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.js +128 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.d.ts +58 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.js +224 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.js +267 -0
- package/dist/action-providers/cdp/constants.d.ts +31 -0
- package/dist/action-providers/cdp/constants.js +34 -0
- package/dist/action-providers/cdp/index.d.ts +3 -0
- package/dist/action-providers/cdp/index.js +19 -0
- package/dist/action-providers/cdp/schemas.d.ts +91 -0
- package/dist/action-providers/cdp/schemas.js +77 -0
- package/dist/action-providers/compound/compoundActionProvider.d.ts +67 -0
- package/dist/action-providers/compound/compoundActionProvider.js +365 -0
- package/dist/action-providers/compound/compoundActionProvider.test.d.ts +1 -0
- package/dist/action-providers/compound/compoundActionProvider.test.js +353 -0
- package/dist/action-providers/compound/constants.d.ts +180 -0
- package/dist/action-providers/compound/constants.js +129 -0
- package/dist/action-providers/compound/index.d.ts +1 -0
- package/dist/action-providers/compound/index.js +17 -0
- package/dist/action-providers/compound/schemas.d.ts +57 -0
- package/dist/action-providers/compound/schemas.js +58 -0
- package/dist/action-providers/compound/utils.d.ts +95 -0
- package/dist/action-providers/compound/utils.js +353 -0
- package/dist/action-providers/customActionProvider.d.ts +30 -0
- package/dist/action-providers/customActionProvider.js +66 -0
- package/dist/action-providers/defillama/constants.d.ts +8 -0
- package/dist/action-providers/defillama/constants.js +11 -0
- package/dist/action-providers/defillama/defillamaActionProvider.d.ts +54 -0
- package/dist/action-providers/defillama/defillamaActionProvider.js +180 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.js +114 -0
- package/dist/action-providers/defillama/index.d.ts +1 -0
- package/dist/action-providers/defillama/index.js +17 -0
- package/dist/action-providers/defillama/schemas.d.ts +34 -0
- package/dist/action-providers/defillama/schemas.js +34 -0
- package/dist/action-providers/defillama/types.d.ts +73 -0
- package/dist/action-providers/defillama/types.js +2 -0
- package/dist/action-providers/defillama/utils.d.ts +10 -0
- package/dist/action-providers/defillama/utils.js +87 -0
- package/dist/action-providers/defillama/utils.test.d.ts +1 -0
- package/dist/action-providers/defillama/utils.test.js +124 -0
- package/dist/action-providers/erc20/constants.d.ts +137 -0
- package/dist/action-providers/erc20/constants.js +202 -0
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +38 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +142 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +131 -0
- package/dist/action-providers/erc20/index.d.ts +1 -0
- package/dist/action-providers/erc20/index.js +17 -0
- package/dist/action-providers/erc20/schemas.d.ts +27 -0
- package/dist/action-providers/erc20/schemas.js +26 -0
- package/dist/action-providers/erc721/constants.d.ts +232 -0
- package/dist/action-providers/erc721/constants.js +298 -0
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +46 -0
- package/dist/action-providers/erc721/erc721ActionProvider.js +164 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.js +137 -0
- package/dist/action-providers/erc721/index.d.ts +1 -0
- package/dist/action-providers/erc721/index.js +17 -0
- package/dist/action-providers/erc721/schemas.d.ts +46 -0
- package/dist/action-providers/erc721/schemas.js +44 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.d.ts +57 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.js +142 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +151 -0
- package/dist/action-providers/farcaster/index.d.ts +2 -0
- package/dist/action-providers/farcaster/index.js +18 -0
- package/dist/action-providers/farcaster/schemas.d.ts +15 -0
- package/dist/action-providers/farcaster/schemas.js +20 -0
- package/dist/action-providers/index.d.ts +24 -0
- package/dist/action-providers/index.js +40 -0
- package/dist/action-providers/jupiter/index.d.ts +1 -0
- package/dist/action-providers/jupiter/index.js +17 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.d.ts +36 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +115 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +146 -0
- package/dist/action-providers/jupiter/schemas.d.ts +20 -0
- package/dist/action-providers/jupiter/schemas.js +20 -0
- package/dist/action-providers/messari/constants.d.ts +17 -0
- package/dist/action-providers/messari/constants.js +20 -0
- package/dist/action-providers/messari/index.d.ts +5 -0
- package/dist/action-providers/messari/index.js +21 -0
- package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
- package/dist/action-providers/messari/messariActionProvider.js +128 -0
- package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
- package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
- package/dist/action-providers/messari/schemas.d.ts +11 -0
- package/dist/action-providers/messari/schemas.js +16 -0
- package/dist/action-providers/messari/types.d.ts +40 -0
- package/dist/action-providers/messari/types.js +2 -0
- package/dist/action-providers/messari/utils.d.ts +22 -0
- package/dist/action-providers/messari/utils.js +65 -0
- package/dist/action-providers/moonwell/constants.d.ts +78 -0
- package/dist/action-providers/moonwell/constants.js +111 -0
- package/dist/action-providers/moonwell/index.d.ts +1 -0
- package/dist/action-providers/moonwell/index.js +5 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.d.ts +39 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.js +249 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.d.ts +1 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.js +455 -0
- package/dist/action-providers/moonwell/schemas.d.ts +30 -0
- package/dist/action-providers/moonwell/schemas.js +39 -0
- package/dist/action-providers/morpho/constants.d.ts +16 -0
- package/dist/action-providers/morpho/constants.js +27 -0
- package/dist/action-providers/morpho/index.d.ts +2 -0
- package/dist/action-providers/morpho/index.js +18 -0
- package/dist/action-providers/morpho/morphoActionProvider.d.ts +39 -0
- package/dist/action-providers/morpho/morphoActionProvider.js +154 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.d.ts +1 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.js +128 -0
- package/dist/action-providers/morpho/schemas.d.ts +36 -0
- package/dist/action-providers/morpho/schemas.js +47 -0
- package/dist/action-providers/opensea/index.d.ts +1 -0
- package/dist/action-providers/opensea/index.js +17 -0
- package/dist/action-providers/opensea/openseaActionProvider.d.ts +59 -0
- package/dist/action-providers/opensea/openseaActionProvider.js +146 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.js +201 -0
- package/dist/action-providers/opensea/schemas.d.ts +30 -0
- package/dist/action-providers/opensea/schemas.js +33 -0
- package/dist/action-providers/opensea/utils.d.ts +12 -0
- package/dist/action-providers/opensea/utils.js +47 -0
- package/dist/action-providers/pyth/index.d.ts +2 -0
- package/dist/action-providers/pyth/index.js +18 -0
- package/dist/action-providers/pyth/pythActionProvider.d.ts +33 -0
- package/dist/action-providers/pyth/pythActionProvider.js +121 -0
- package/dist/action-providers/pyth/pythActionProvider.test.d.ts +1 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +113 -0
- package/dist/action-providers/pyth/schemas.d.ts +21 -0
- package/dist/action-providers/pyth/schemas.js +20 -0
- package/dist/action-providers/spl/index.d.ts +1 -0
- package/dist/action-providers/spl/index.js +17 -0
- package/dist/action-providers/spl/schemas.d.ts +30 -0
- package/dist/action-providers/spl/schemas.js +26 -0
- package/dist/action-providers/spl/splActionProvider.d.ts +45 -0
- package/dist/action-providers/spl/splActionProvider.js +173 -0
- package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
- package/dist/action-providers/spl/splActionProvider.test.js +300 -0
- package/dist/action-providers/twitter/index.d.ts +2 -0
- package/dist/action-providers/twitter/index.js +18 -0
- package/dist/action-providers/twitter/schemas.d.ts +38 -0
- package/dist/action-providers/twitter/schemas.js +44 -0
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +82 -0
- package/dist/action-providers/twitter/twitterActionProvider.js +204 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.js +185 -0
- package/dist/action-providers/wallet/index.d.ts +1 -0
- package/dist/action-providers/wallet/index.js +17 -0
- package/dist/action-providers/wallet/schemas.d.ts +19 -0
- package/dist/action-providers/wallet/schemas.js +19 -0
- package/dist/action-providers/wallet/walletActionProvider.d.ts +44 -0
- package/dist/action-providers/wallet/walletActionProvider.js +140 -0
- package/dist/action-providers/wallet/walletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wallet/walletActionProvider.test.js +194 -0
- package/dist/action-providers/weth/constants.d.ts +19 -0
- package/dist/action-providers/weth/constants.js +29 -0
- package/dist/action-providers/weth/index.d.ts +1 -0
- package/dist/action-providers/weth/index.js +17 -0
- package/dist/action-providers/weth/schemas.d.ts +8 -0
- package/dist/action-providers/weth/schemas.js +10 -0
- package/dist/action-providers/weth/wethActionProvider.d.ts +30 -0
- package/dist/action-providers/weth/wethActionProvider.js +89 -0
- package/dist/action-providers/weth/wethActionProvider.test.d.ts +1 -0
- package/dist/action-providers/weth/wethActionProvider.test.js +92 -0
- package/dist/action-providers/wow/constants.d.ts +15 -0
- package/dist/action-providers/wow/constants.js +844 -0
- package/dist/action-providers/wow/index.d.ts +2 -0
- package/dist/action-providers/wow/index.js +18 -0
- package/dist/action-providers/wow/schemas.d.ts +43 -0
- package/dist/action-providers/wow/schemas.js +47 -0
- package/dist/action-providers/wow/uniswap/constants.d.ts +3 -0
- package/dist/action-providers/wow/uniswap/constants.js +100 -0
- package/dist/action-providers/wow/uniswap/utils.d.ts +82 -0
- package/dist/action-providers/wow/uniswap/utils.js +226 -0
- package/dist/action-providers/wow/utils.d.ts +27 -0
- package/dist/action-providers/wow/utils.js +63 -0
- package/dist/action-providers/wow/wowActionProvider.d.ts +46 -0
- package/dist/action-providers/wow/wowActionProvider.js +223 -0
- package/dist/action-providers/wow/wowActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wow/wowActionProvider.test.js +291 -0
- package/dist/agentkit.d.ts +44 -0
- package/dist/agentkit.js +68 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +17 -0
- package/dist/analytics/sendAnalyticsEvent.d.ts +31 -0
- package/dist/analytics/sendAnalyticsEvent.js +52 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/network/index.d.ts +3 -0
- package/dist/network/index.js +19 -0
- package/dist/network/network.d.ts +20 -0
- package/dist/network/network.js +86 -0
- package/dist/network/svm.d.ts +15 -0
- package/dist/network/svm.js +38 -0
- package/dist/network/types.d.ts +17 -0
- package/dist/network/types.js +2 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +57 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +50 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +246 -0
- package/dist/wallet-providers/cdpWalletProvider.js +421 -0
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +701 -0
- package/dist/wallet-providers/evmWalletProvider.d.ts +51 -0
- package/dist/wallet-providers/evmWalletProvider.js +14 -0
- package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
- package/dist/wallet-providers/index.d.ts +10 -0
- package/dist/wallet-providers/index.js +26 -0
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +140 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
- package/dist/wallet-providers/privyShared.d.ts +40 -0
- package/dist/wallet-providers/privyShared.js +49 -0
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +128 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +212 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +35 -0
- package/dist/wallet-providers/privyWalletProvider.js +39 -0
- package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
- package/dist/wallet-providers/smartWalletProvider.d.ts +177 -0
- package/dist/wallet-providers/smartWalletProvider.js +303 -0
- package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +143 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +280 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +218 -0
- package/dist/wallet-providers/svmWalletProvider.d.ts +56 -0
- package/dist/wallet-providers/svmWalletProvider.js +13 -0
- package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +103 -0
- package/dist/wallet-providers/viemWalletProvider.js +206 -0
- package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
- package/dist/wallet-providers/walletProvider.d.ts +48 -0
- package/dist/wallet-providers/walletProvider.js +41 -0
- package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/walletProvider.test.js +103 -0
- package/package.json +83 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
describe("DefiLlama Utilities", () => {
|
|
5
|
+
describe("pruneGetProtocolResponse", () => {
|
|
6
|
+
it("should handle null input", () => {
|
|
7
|
+
expect((0, utils_1.pruneGetProtocolResponse)(null)).toBeNull();
|
|
8
|
+
});
|
|
9
|
+
it("should not modify objects without time-series data", () => {
|
|
10
|
+
const input = {
|
|
11
|
+
id: "test-protocol",
|
|
12
|
+
name: "Protocol",
|
|
13
|
+
symbol: "ABC",
|
|
14
|
+
};
|
|
15
|
+
const result = (0, utils_1.pruneGetProtocolResponse)(input);
|
|
16
|
+
expect(result).not.toBeNull();
|
|
17
|
+
expect(result).toEqual(input);
|
|
18
|
+
});
|
|
19
|
+
it("should prune time-series arrays", () => {
|
|
20
|
+
const timeSeriesData = Array.from({ length: 20 }, (_, i) => ({
|
|
21
|
+
date: Date.now() - i * 86400000,
|
|
22
|
+
totalLiquidityUSD: 1000 + i,
|
|
23
|
+
}));
|
|
24
|
+
const input = {
|
|
25
|
+
id: "test-protocol",
|
|
26
|
+
name: "Protocol",
|
|
27
|
+
tvl: [...timeSeriesData],
|
|
28
|
+
};
|
|
29
|
+
const result = (0, utils_1.pruneGetProtocolResponse)(input, 5);
|
|
30
|
+
expect(result).not.toBeNull();
|
|
31
|
+
if (result) {
|
|
32
|
+
expect(result.name).toBe("Protocol");
|
|
33
|
+
expect(result.tvl).toHaveLength(5);
|
|
34
|
+
const resultDates = result.tvl.map(entry => entry.date);
|
|
35
|
+
const sortedDates = [...resultDates].sort((a, b) => b - a);
|
|
36
|
+
expect(resultDates).toEqual(sortedDates);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
it("should prune nested time-series arrays in chainTvls", () => {
|
|
40
|
+
const timeSeriesData = Array.from({ length: 20 }, (_, i) => ({
|
|
41
|
+
date: Date.now() - i * 86400000,
|
|
42
|
+
totalLiquidityUSD: 1000 + i,
|
|
43
|
+
}));
|
|
44
|
+
const tokenTimeSeriesData = Array.from({ length: 20 }, (_, i) => ({
|
|
45
|
+
date: Date.now() - i * 86400000,
|
|
46
|
+
tokens: { ETH: 1000 + i },
|
|
47
|
+
}));
|
|
48
|
+
const input = {
|
|
49
|
+
id: "test-protocol",
|
|
50
|
+
name: "Protocol",
|
|
51
|
+
chainTvls: {
|
|
52
|
+
Ethereum: {
|
|
53
|
+
tvl: [...timeSeriesData],
|
|
54
|
+
tokens: [...tokenTimeSeriesData],
|
|
55
|
+
},
|
|
56
|
+
Polygon: {
|
|
57
|
+
tvl: [...timeSeriesData],
|
|
58
|
+
tokensInUsd: [...tokenTimeSeriesData],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const result = (0, utils_1.pruneGetProtocolResponse)(input, 3);
|
|
63
|
+
expect(result).not.toBeNull();
|
|
64
|
+
if (result) {
|
|
65
|
+
expect(result.name).toBe("Protocol");
|
|
66
|
+
expect(result.chainTvls).toBeDefined();
|
|
67
|
+
if (result.chainTvls) {
|
|
68
|
+
expect(result.chainTvls.Ethereum.tvl).toHaveLength(3);
|
|
69
|
+
expect(result.chainTvls.Ethereum.tokens).toHaveLength(3);
|
|
70
|
+
expect(result.chainTvls.Polygon.tvl).toHaveLength(3);
|
|
71
|
+
expect(result.chainTvls.Polygon.tokensInUsd).toHaveLength(3);
|
|
72
|
+
const ethereumTvlDates = result.chainTvls.Ethereum.tvl.map(entry => entry.date);
|
|
73
|
+
const sortedDates = [...ethereumTvlDates].sort((a, b) => b - a);
|
|
74
|
+
expect(ethereumTvlDates).toEqual(sortedDates);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
it("should respect the maxEntries parameter", () => {
|
|
79
|
+
const timeSeriesData = Array.from({ length: 50 }, (_, i) => ({
|
|
80
|
+
date: Date.now() - i * 86400000,
|
|
81
|
+
totalLiquidityUSD: 1000 + i,
|
|
82
|
+
}));
|
|
83
|
+
const tokenTimeSeriesData = Array.from({ length: 50 }, (_, i) => ({
|
|
84
|
+
date: Date.now() - i * 86400000,
|
|
85
|
+
tokens: { ETH: 1000 + i },
|
|
86
|
+
}));
|
|
87
|
+
const input = {
|
|
88
|
+
id: "test-protocol",
|
|
89
|
+
name: "Protocol",
|
|
90
|
+
tvl: [...timeSeriesData],
|
|
91
|
+
tokens: [...tokenTimeSeriesData],
|
|
92
|
+
};
|
|
93
|
+
const result1 = (0, utils_1.pruneGetProtocolResponse)(input, 1);
|
|
94
|
+
expect(result1).not.toBeNull();
|
|
95
|
+
if (result1) {
|
|
96
|
+
expect(result1.tvl).toHaveLength(1);
|
|
97
|
+
expect(result1.tokens).toHaveLength(1);
|
|
98
|
+
}
|
|
99
|
+
const result10 = (0, utils_1.pruneGetProtocolResponse)(input, 10);
|
|
100
|
+
expect(result10).not.toBeNull();
|
|
101
|
+
if (result10) {
|
|
102
|
+
expect(result10.tvl).toHaveLength(10);
|
|
103
|
+
expect(result10.tokens).toHaveLength(10);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
it("should handle arrays without date property", () => {
|
|
107
|
+
const nonDateArray = Array.from({ length: 20 }, (_, i) => ({
|
|
108
|
+
value: 1000 + i,
|
|
109
|
+
name: `Item ${i}`,
|
|
110
|
+
}));
|
|
111
|
+
// Using a type assertion for this test case as it's testing a specific behavior
|
|
112
|
+
const input = {
|
|
113
|
+
id: "test-protocol",
|
|
114
|
+
name: "Protocol",
|
|
115
|
+
tvl: [...nonDateArray],
|
|
116
|
+
};
|
|
117
|
+
const result = (0, utils_1.pruneGetProtocolResponse)(input, 5);
|
|
118
|
+
expect(result).not.toBeNull();
|
|
119
|
+
if (result) {
|
|
120
|
+
expect(result.tvl).toHaveLength(5);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export declare const abi: readonly [{
|
|
2
|
+
readonly type: "event";
|
|
3
|
+
readonly name: "Approval";
|
|
4
|
+
readonly inputs: readonly [{
|
|
5
|
+
readonly indexed: true;
|
|
6
|
+
readonly name: "owner";
|
|
7
|
+
readonly type: "address";
|
|
8
|
+
}, {
|
|
9
|
+
readonly indexed: true;
|
|
10
|
+
readonly name: "spender";
|
|
11
|
+
readonly type: "address";
|
|
12
|
+
}, {
|
|
13
|
+
readonly indexed: false;
|
|
14
|
+
readonly name: "value";
|
|
15
|
+
readonly type: "uint256";
|
|
16
|
+
}];
|
|
17
|
+
}, {
|
|
18
|
+
readonly type: "event";
|
|
19
|
+
readonly name: "Transfer";
|
|
20
|
+
readonly inputs: readonly [{
|
|
21
|
+
readonly indexed: true;
|
|
22
|
+
readonly name: "from";
|
|
23
|
+
readonly type: "address";
|
|
24
|
+
}, {
|
|
25
|
+
readonly indexed: true;
|
|
26
|
+
readonly name: "to";
|
|
27
|
+
readonly type: "address";
|
|
28
|
+
}, {
|
|
29
|
+
readonly indexed: false;
|
|
30
|
+
readonly name: "value";
|
|
31
|
+
readonly type: "uint256";
|
|
32
|
+
}];
|
|
33
|
+
}, {
|
|
34
|
+
readonly type: "function";
|
|
35
|
+
readonly name: "allowance";
|
|
36
|
+
readonly stateMutability: "view";
|
|
37
|
+
readonly inputs: readonly [{
|
|
38
|
+
readonly name: "owner";
|
|
39
|
+
readonly type: "address";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "spender";
|
|
42
|
+
readonly type: "address";
|
|
43
|
+
}];
|
|
44
|
+
readonly outputs: readonly [{
|
|
45
|
+
readonly type: "uint256";
|
|
46
|
+
}];
|
|
47
|
+
}, {
|
|
48
|
+
readonly type: "function";
|
|
49
|
+
readonly name: "approve";
|
|
50
|
+
readonly stateMutability: "nonpayable";
|
|
51
|
+
readonly inputs: readonly [{
|
|
52
|
+
readonly name: "spender";
|
|
53
|
+
readonly type: "address";
|
|
54
|
+
}, {
|
|
55
|
+
readonly name: "amount";
|
|
56
|
+
readonly type: "uint256";
|
|
57
|
+
}];
|
|
58
|
+
readonly outputs: readonly [{
|
|
59
|
+
readonly type: "bool";
|
|
60
|
+
}];
|
|
61
|
+
}, {
|
|
62
|
+
readonly type: "function";
|
|
63
|
+
readonly name: "balanceOf";
|
|
64
|
+
readonly stateMutability: "view";
|
|
65
|
+
readonly inputs: readonly [{
|
|
66
|
+
readonly name: "account";
|
|
67
|
+
readonly type: "address";
|
|
68
|
+
}];
|
|
69
|
+
readonly outputs: readonly [{
|
|
70
|
+
readonly type: "uint256";
|
|
71
|
+
}];
|
|
72
|
+
}, {
|
|
73
|
+
readonly type: "function";
|
|
74
|
+
readonly name: "decimals";
|
|
75
|
+
readonly stateMutability: "view";
|
|
76
|
+
readonly inputs: readonly [];
|
|
77
|
+
readonly outputs: readonly [{
|
|
78
|
+
readonly type: "uint8";
|
|
79
|
+
}];
|
|
80
|
+
}, {
|
|
81
|
+
readonly type: "function";
|
|
82
|
+
readonly name: "name";
|
|
83
|
+
readonly stateMutability: "view";
|
|
84
|
+
readonly inputs: readonly [];
|
|
85
|
+
readonly outputs: readonly [{
|
|
86
|
+
readonly type: "string";
|
|
87
|
+
}];
|
|
88
|
+
}, {
|
|
89
|
+
readonly type: "function";
|
|
90
|
+
readonly name: "symbol";
|
|
91
|
+
readonly stateMutability: "view";
|
|
92
|
+
readonly inputs: readonly [];
|
|
93
|
+
readonly outputs: readonly [{
|
|
94
|
+
readonly type: "string";
|
|
95
|
+
}];
|
|
96
|
+
}, {
|
|
97
|
+
readonly type: "function";
|
|
98
|
+
readonly name: "totalSupply";
|
|
99
|
+
readonly stateMutability: "view";
|
|
100
|
+
readonly inputs: readonly [];
|
|
101
|
+
readonly outputs: readonly [{
|
|
102
|
+
readonly type: "uint256";
|
|
103
|
+
}];
|
|
104
|
+
}, {
|
|
105
|
+
readonly type: "function";
|
|
106
|
+
readonly name: "transfer";
|
|
107
|
+
readonly stateMutability: "nonpayable";
|
|
108
|
+
readonly inputs: readonly [{
|
|
109
|
+
readonly name: "recipient";
|
|
110
|
+
readonly type: "address";
|
|
111
|
+
}, {
|
|
112
|
+
readonly name: "amount";
|
|
113
|
+
readonly type: "uint256";
|
|
114
|
+
}];
|
|
115
|
+
readonly outputs: readonly [{
|
|
116
|
+
readonly type: "bool";
|
|
117
|
+
}];
|
|
118
|
+
}, {
|
|
119
|
+
readonly type: "function";
|
|
120
|
+
readonly name: "transferFrom";
|
|
121
|
+
readonly stateMutability: "nonpayable";
|
|
122
|
+
readonly inputs: readonly [{
|
|
123
|
+
readonly name: "sender";
|
|
124
|
+
readonly type: "address";
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "recipient";
|
|
127
|
+
readonly type: "address";
|
|
128
|
+
}, {
|
|
129
|
+
readonly name: "amount";
|
|
130
|
+
readonly type: "uint256";
|
|
131
|
+
}];
|
|
132
|
+
readonly outputs: readonly [{
|
|
133
|
+
readonly type: "bool";
|
|
134
|
+
}];
|
|
135
|
+
}];
|
|
136
|
+
export declare const BaseTokenToAssetId: Map<string, string>;
|
|
137
|
+
export declare const BaseSepoliaTokenToAssetId: Map<string, string>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseSepoliaTokenToAssetId = exports.BaseTokenToAssetId = exports.abi = void 0;
|
|
4
|
+
const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
|
|
5
|
+
exports.abi = [
|
|
6
|
+
{
|
|
7
|
+
type: "event",
|
|
8
|
+
name: "Approval",
|
|
9
|
+
inputs: [
|
|
10
|
+
{
|
|
11
|
+
indexed: true,
|
|
12
|
+
name: "owner",
|
|
13
|
+
type: "address",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
indexed: true,
|
|
17
|
+
name: "spender",
|
|
18
|
+
type: "address",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
indexed: false,
|
|
22
|
+
name: "value",
|
|
23
|
+
type: "uint256",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: "event",
|
|
29
|
+
name: "Transfer",
|
|
30
|
+
inputs: [
|
|
31
|
+
{
|
|
32
|
+
indexed: true,
|
|
33
|
+
name: "from",
|
|
34
|
+
type: "address",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
indexed: true,
|
|
38
|
+
name: "to",
|
|
39
|
+
type: "address",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
indexed: false,
|
|
43
|
+
name: "value",
|
|
44
|
+
type: "uint256",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: "function",
|
|
50
|
+
name: "allowance",
|
|
51
|
+
stateMutability: "view",
|
|
52
|
+
inputs: [
|
|
53
|
+
{
|
|
54
|
+
name: "owner",
|
|
55
|
+
type: "address",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "spender",
|
|
59
|
+
type: "address",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
outputs: [
|
|
63
|
+
{
|
|
64
|
+
type: "uint256",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: "function",
|
|
70
|
+
name: "approve",
|
|
71
|
+
stateMutability: "nonpayable",
|
|
72
|
+
inputs: [
|
|
73
|
+
{
|
|
74
|
+
name: "spender",
|
|
75
|
+
type: "address",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "amount",
|
|
79
|
+
type: "uint256",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
outputs: [
|
|
83
|
+
{
|
|
84
|
+
type: "bool",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: "function",
|
|
90
|
+
name: "balanceOf",
|
|
91
|
+
stateMutability: "view",
|
|
92
|
+
inputs: [
|
|
93
|
+
{
|
|
94
|
+
name: "account",
|
|
95
|
+
type: "address",
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
outputs: [
|
|
99
|
+
{
|
|
100
|
+
type: "uint256",
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: "function",
|
|
106
|
+
name: "decimals",
|
|
107
|
+
stateMutability: "view",
|
|
108
|
+
inputs: [],
|
|
109
|
+
outputs: [
|
|
110
|
+
{
|
|
111
|
+
type: "uint8",
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: "function",
|
|
117
|
+
name: "name",
|
|
118
|
+
stateMutability: "view",
|
|
119
|
+
inputs: [],
|
|
120
|
+
outputs: [
|
|
121
|
+
{
|
|
122
|
+
type: "string",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: "function",
|
|
128
|
+
name: "symbol",
|
|
129
|
+
stateMutability: "view",
|
|
130
|
+
inputs: [],
|
|
131
|
+
outputs: [
|
|
132
|
+
{
|
|
133
|
+
type: "string",
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: "function",
|
|
139
|
+
name: "totalSupply",
|
|
140
|
+
stateMutability: "view",
|
|
141
|
+
inputs: [],
|
|
142
|
+
outputs: [
|
|
143
|
+
{
|
|
144
|
+
type: "uint256",
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: "function",
|
|
150
|
+
name: "transfer",
|
|
151
|
+
stateMutability: "nonpayable",
|
|
152
|
+
inputs: [
|
|
153
|
+
{
|
|
154
|
+
name: "recipient",
|
|
155
|
+
type: "address",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "amount",
|
|
159
|
+
type: "uint256",
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
outputs: [
|
|
163
|
+
{
|
|
164
|
+
type: "bool",
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
type: "function",
|
|
170
|
+
name: "transferFrom",
|
|
171
|
+
stateMutability: "nonpayable",
|
|
172
|
+
inputs: [
|
|
173
|
+
{
|
|
174
|
+
name: "sender",
|
|
175
|
+
type: "address",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "recipient",
|
|
179
|
+
type: "address",
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: "amount",
|
|
183
|
+
type: "uint256",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
outputs: [
|
|
187
|
+
{
|
|
188
|
+
type: "bool",
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
exports.BaseTokenToAssetId = new Map([
|
|
194
|
+
["0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf", coinbase_sdk_1.Coinbase.assets.Cbbtc],
|
|
195
|
+
["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", coinbase_sdk_1.Coinbase.assets.Usdc],
|
|
196
|
+
["0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42", coinbase_sdk_1.Coinbase.assets.Eurc],
|
|
197
|
+
]);
|
|
198
|
+
exports.BaseSepoliaTokenToAssetId = new Map([
|
|
199
|
+
["0xcbB7C0006F23900c38EB856149F799620fcb8A4a", coinbase_sdk_1.Coinbase.assets.Cbbtc],
|
|
200
|
+
["0x036CbD53842c5426634e7929541eC2318f3dCF7e", coinbase_sdk_1.Coinbase.assets.Usdc],
|
|
201
|
+
["0x808456652fdb597867f38412077A9182bf77359F", coinbase_sdk_1.Coinbase.assets.Eurc],
|
|
202
|
+
]);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { Network } from "../../network";
|
|
4
|
+
import { GetBalanceSchema, TransferSchema } from "./schemas";
|
|
5
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
6
|
+
/**
|
|
7
|
+
* ERC20ActionProvider is an action provider for ERC20 tokens.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ERC20ActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor for the ERC20ActionProvider.
|
|
12
|
+
*/
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Gets the balance of an ERC20 token.
|
|
16
|
+
*
|
|
17
|
+
* @param walletProvider - The wallet provider to get the balance from.
|
|
18
|
+
* @param args - The input arguments for the action.
|
|
19
|
+
* @returns A message containing the balance.
|
|
20
|
+
*/
|
|
21
|
+
getBalance(walletProvider: EvmWalletProvider, args: z.infer<typeof GetBalanceSchema>): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Transfers a specified amount of an ERC20 token to a destination onchain.
|
|
24
|
+
*
|
|
25
|
+
* @param walletProvider - The wallet provider to transfer the asset from.
|
|
26
|
+
* @param args - The input arguments for the action.
|
|
27
|
+
* @returns A message containing the transfer details.
|
|
28
|
+
*/
|
|
29
|
+
transfer(walletProvider: EvmWalletProvider, args: z.infer<typeof TransferSchema>): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the ERC20 action provider supports the given network.
|
|
32
|
+
*
|
|
33
|
+
* @param network - The network to check.
|
|
34
|
+
* @returns True if the ERC20 action provider supports the network, false otherwise.
|
|
35
|
+
*/
|
|
36
|
+
supportsNetwork: (network: Network) => boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare const erc20ActionProvider: () => ERC20ActionProvider;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.erc20ActionProvider = exports.ERC20ActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const actionProvider_1 = require("../actionProvider");
|
|
15
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
16
|
+
const schemas_1 = require("./schemas");
|
|
17
|
+
const constants_1 = require("./constants");
|
|
18
|
+
const viem_1 = require("viem");
|
|
19
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
20
|
+
/**
|
|
21
|
+
* ERC20ActionProvider is an action provider for ERC20 tokens.
|
|
22
|
+
*/
|
|
23
|
+
class ERC20ActionProvider extends actionProvider_1.ActionProvider {
|
|
24
|
+
/**
|
|
25
|
+
* Constructor for the ERC20ActionProvider.
|
|
26
|
+
*/
|
|
27
|
+
constructor() {
|
|
28
|
+
super("erc20", []);
|
|
29
|
+
/**
|
|
30
|
+
* Checks if the ERC20 action provider supports the given network.
|
|
31
|
+
*
|
|
32
|
+
* @param network - The network to check.
|
|
33
|
+
* @returns True if the ERC20 action provider supports the network, false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
this.supportsNetwork = (network) => network.protocolFamily === "evm";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets the balance of an ERC20 token.
|
|
39
|
+
*
|
|
40
|
+
* @param walletProvider - The wallet provider to get the balance from.
|
|
41
|
+
* @param args - The input arguments for the action.
|
|
42
|
+
* @returns A message containing the balance.
|
|
43
|
+
*/
|
|
44
|
+
async getBalance(walletProvider, args) {
|
|
45
|
+
try {
|
|
46
|
+
const balance = await walletProvider.readContract({
|
|
47
|
+
address: args.contractAddress,
|
|
48
|
+
abi: constants_1.abi,
|
|
49
|
+
functionName: "balanceOf",
|
|
50
|
+
args: [walletProvider.getAddress()],
|
|
51
|
+
});
|
|
52
|
+
const decimals = await walletProvider.readContract({
|
|
53
|
+
address: args.contractAddress,
|
|
54
|
+
abi: constants_1.abi,
|
|
55
|
+
functionName: "decimals",
|
|
56
|
+
args: [],
|
|
57
|
+
});
|
|
58
|
+
return `Balance of ${args.contractAddress} is ${(0, viem_1.formatUnits)(balance, decimals)}`;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return `Error getting balance: ${error}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Transfers a specified amount of an ERC20 token to a destination onchain.
|
|
66
|
+
*
|
|
67
|
+
* @param walletProvider - The wallet provider to transfer the asset from.
|
|
68
|
+
* @param args - The input arguments for the action.
|
|
69
|
+
* @returns A message containing the transfer details.
|
|
70
|
+
*/
|
|
71
|
+
async transfer(walletProvider, args) {
|
|
72
|
+
try {
|
|
73
|
+
// Check if we can do gasless transfer
|
|
74
|
+
const isCdpWallet = walletProvider.getName() === "cdp_wallet_provider";
|
|
75
|
+
const network = walletProvider.getNetwork();
|
|
76
|
+
const tokenAddress = (0, viem_1.getAddress)(args.contractAddress);
|
|
77
|
+
const canDoGasless = isCdpWallet &&
|
|
78
|
+
((network.networkId === "base-mainnet" && constants_1.BaseTokenToAssetId.has(tokenAddress)) ||
|
|
79
|
+
(network.networkId === "base-sepolia" && constants_1.BaseSepoliaTokenToAssetId.has(tokenAddress)));
|
|
80
|
+
if (canDoGasless) {
|
|
81
|
+
// Cast to CdpWalletProvider to access erc20Transfer
|
|
82
|
+
const cdpWallet = walletProvider;
|
|
83
|
+
const assetId = network.networkId === "base-mainnet"
|
|
84
|
+
? constants_1.BaseTokenToAssetId.get(tokenAddress)
|
|
85
|
+
: constants_1.BaseSepoliaTokenToAssetId.get(tokenAddress);
|
|
86
|
+
const hash = await cdpWallet.gaslessERC20Transfer(assetId, args.destination, args.amount);
|
|
87
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
88
|
+
return `Transferred ${args.amount} of ${args.contractAddress} to ${args.destination} using gasless transfer.\nTransaction hash: ${hash}`;
|
|
89
|
+
}
|
|
90
|
+
// Fallback to regular transfer
|
|
91
|
+
const hash = await walletProvider.sendTransaction({
|
|
92
|
+
to: args.contractAddress,
|
|
93
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
94
|
+
abi: constants_1.abi,
|
|
95
|
+
functionName: "transfer",
|
|
96
|
+
args: [args.destination, BigInt(args.amount)],
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
100
|
+
return `Transferred ${args.amount} of ${args.contractAddress} to ${args.destination}.\nTransaction hash for the transfer: ${hash}`;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return `Error transferring the asset: ${error}`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.ERC20ActionProvider = ERC20ActionProvider;
|
|
108
|
+
__decorate([
|
|
109
|
+
(0, actionDecorator_1.CreateAction)({
|
|
110
|
+
name: "get_balance",
|
|
111
|
+
description: `
|
|
112
|
+
This tool will get the balance of an ERC20 asset in the wallet. It takes the contract address as input.
|
|
113
|
+
`,
|
|
114
|
+
schema: schemas_1.GetBalanceSchema,
|
|
115
|
+
}),
|
|
116
|
+
__metadata("design:type", Function),
|
|
117
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
118
|
+
__metadata("design:returntype", Promise)
|
|
119
|
+
], ERC20ActionProvider.prototype, "getBalance", null);
|
|
120
|
+
__decorate([
|
|
121
|
+
(0, actionDecorator_1.CreateAction)({
|
|
122
|
+
name: "transfer",
|
|
123
|
+
description: `
|
|
124
|
+
This tool will transfer an ERC20 token from the wallet to another onchain address.
|
|
125
|
+
|
|
126
|
+
It takes the following inputs:
|
|
127
|
+
- amount: The amount to transfer
|
|
128
|
+
- contractAddress: The contract address of the token to transfer
|
|
129
|
+
- destination: Where to send the funds (can be an onchain address, ENS 'example.eth', or Basename 'example.base.eth')
|
|
130
|
+
|
|
131
|
+
Important notes:
|
|
132
|
+
- Ensure sufficient balance of the input asset before transferring
|
|
133
|
+
- When sending native assets (e.g. 'eth' on base-mainnet), ensure there is sufficient balance for the transfer itself AND the gas cost of this transfer
|
|
134
|
+
`,
|
|
135
|
+
schema: schemas_1.TransferSchema,
|
|
136
|
+
}),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], ERC20ActionProvider.prototype, "transfer", null);
|
|
141
|
+
const erc20ActionProvider = () => new ERC20ActionProvider();
|
|
142
|
+
exports.erc20ActionProvider = erc20ActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|