@coinbase/agentkit 0.10.0 → 0.10.1
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 +75 -0
- package/dist/action-providers/across/acrossActionProvider.js +3 -3
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -81
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +18 -3
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +223 -23
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +278 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -2
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +223 -18
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +265 -1
- package/dist/action-providers/cdp/schemas.d.ts +12 -12
- package/dist/action-providers/cdp/schemas.js +17 -5
- package/dist/action-providers/cdp/swapUtils.d.ts +32 -0
- package/dist/action-providers/cdp/swapUtils.js +142 -0
- package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
- package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
- package/dist/action-providers/clanker/index.d.ts +2 -0
- package/dist/action-providers/clanker/index.js +18 -0
- package/dist/action-providers/clanker/schemas.d.ts +56 -0
- package/dist/action-providers/clanker/schemas.js +47 -0
- package/dist/action-providers/clanker/utils.d.ts +9 -0
- package/dist/action-providers/clanker/utils.js +23 -0
- package/dist/action-providers/compound/constants.d.ts +1 -1
- package/dist/action-providers/compound/constants.js +2 -2
- package/dist/action-providers/erc20/constants.d.ts +35 -135
- package/dist/action-providers/erc20/constants.js +37 -189
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
- package/dist/action-providers/erc20/schemas.d.ts +25 -12
- package/dist/action-providers/erc20/schemas.js +34 -6
- package/dist/action-providers/erc20/utils.d.ts +19 -0
- package/dist/action-providers/erc20/utils.js +54 -0
- package/dist/action-providers/flaunch/constants.d.ts +1 -1
- package/dist/action-providers/flaunch/constants.js +2 -2
- package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
- package/dist/action-providers/index.d.ts +3 -0
- package/dist/action-providers/index.js +3 -0
- package/dist/action-providers/jupiter/schemas.d.ts +1 -1
- package/dist/action-providers/moonwell/schemas.d.ts +2 -2
- package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
- package/dist/action-providers/morpho/schemas.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +5 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +5 -1
- package/dist/action-providers/superfluid/constants.d.ts +814 -0
- package/dist/action-providers/superfluid/constants.js +2826 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
- package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
- package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
- package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
- package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
- package/dist/action-providers/superfluid/index.d.ts +7 -0
- package/dist/action-providers/superfluid/index.js +23 -0
- package/dist/action-providers/superfluid/schemas.d.ts +86 -0
- package/dist/action-providers/superfluid/schemas.js +103 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +108 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +18 -0
- package/dist/action-providers/superfluid/utils/parseLogs.js +78 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
- package/dist/action-providers/wallet/walletActionProvider.js +21 -10
- package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
- package/dist/action-providers/zeroX/index.d.ts +1 -0
- package/dist/action-providers/zeroX/index.js +17 -0
- package/dist/action-providers/zeroX/schemas.d.ts +51 -0
- package/dist/action-providers/zeroX/schemas.js +82 -0
- package/dist/action-providers/zeroX/utils.d.ts +23 -0
- package/dist/action-providers/zeroX/utils.js +106 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +20 -2
- package/dist/wallet-providers/cdpEvmWalletProvider.js +40 -15
- package/dist/wallet-providers/cdpShared.d.ts +5 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +22 -3
- package/dist/wallet-providers/cdpSmartWalletProvider.js +43 -19
- package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
- package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -2
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +12 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +12 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.js +11 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +10 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +12 -3
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
- package/dist/wallet-providers/viemWalletProvider.d.ts +12 -2
- package/dist/wallet-providers/viemWalletProvider.js +12 -3
- package/dist/wallet-providers/viemWalletProvider.test.js +6 -5
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +10 -2
- package/dist/wallet-providers/zeroDevWalletProvider.js +14 -5
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +2 -2
- package/package.json +4 -2
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const erc20ActionProvider_1 = require("./erc20ActionProvider");
|
|
4
4
|
const schemas_1 = require("./schemas");
|
|
5
|
-
const viem_1 = require("viem");
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
5
|
const MOCK_AMOUNT = 15;
|
|
8
6
|
const MOCK_DECIMALS = 6;
|
|
9
7
|
const MOCK_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890";
|
|
@@ -12,9 +10,9 @@ const MOCK_ADDRESS = "0x1234567890123456789012345678901234567890";
|
|
|
12
10
|
describe("Transfer Schema", () => {
|
|
13
11
|
it("should successfully parse valid input", () => {
|
|
14
12
|
const validInput = {
|
|
15
|
-
amount: MOCK_AMOUNT,
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
amount: MOCK_AMOUNT.toString(),
|
|
14
|
+
tokenAddress: MOCK_CONTRACT_ADDRESS,
|
|
15
|
+
destinationAddress: MOCK_DESTINATION,
|
|
18
16
|
};
|
|
19
17
|
const result = schemas_1.TransferSchema.safeParse(validInput);
|
|
20
18
|
expect(result.success).toBe(true);
|
|
@@ -28,49 +26,53 @@ describe("Transfer Schema", () => {
|
|
|
28
26
|
});
|
|
29
27
|
describe("Get Balance Action", () => {
|
|
30
28
|
let mockWallet;
|
|
29
|
+
let mockMulticall;
|
|
31
30
|
const actionProvider = (0, erc20ActionProvider_1.erc20ActionProvider)();
|
|
32
31
|
beforeEach(async () => {
|
|
32
|
+
mockMulticall = jest.fn();
|
|
33
|
+
const mockPublicClient = {
|
|
34
|
+
multicall: mockMulticall,
|
|
35
|
+
getCode: jest.fn().mockResolvedValue("0x"),
|
|
36
|
+
};
|
|
33
37
|
mockWallet = {
|
|
34
38
|
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
35
|
-
|
|
39
|
+
getPublicClient: jest.fn().mockReturnValue(mockPublicClient),
|
|
36
40
|
};
|
|
37
41
|
});
|
|
38
42
|
it("should successfully respond", async () => {
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
mockMulticall.mockResolvedValueOnce([
|
|
44
|
+
{ result: "MockToken" }, // name
|
|
45
|
+
{ result: MOCK_DECIMALS }, // decimals
|
|
46
|
+
{ result: BigInt(MOCK_AMOUNT * 10 ** MOCK_DECIMALS) }, // balance
|
|
47
|
+
]);
|
|
41
48
|
const args = {
|
|
42
|
-
|
|
49
|
+
tokenAddress: MOCK_CONTRACT_ADDRESS,
|
|
43
50
|
};
|
|
44
51
|
const response = await actionProvider.getBalance(mockWallet, args);
|
|
45
|
-
expect(
|
|
46
|
-
|
|
47
|
-
abi: constants_1.abi,
|
|
48
|
-
functionName: "balanceOf",
|
|
49
|
-
args: [mockWallet.getAddress()],
|
|
50
|
-
});
|
|
51
|
-
expect(response).toContain(`Balance of ${MOCK_CONTRACT_ADDRESS} is ${MOCK_AMOUNT / 10 ** MOCK_DECIMALS}`);
|
|
52
|
+
expect(mockMulticall).toHaveBeenCalled();
|
|
53
|
+
expect(response).toContain(`Balance of MockToken (${MOCK_CONTRACT_ADDRESS}) at address ${MOCK_ADDRESS} is ${MOCK_AMOUNT}`);
|
|
52
54
|
});
|
|
53
55
|
it("should fail with an error", async () => {
|
|
54
56
|
const args = {
|
|
55
|
-
|
|
57
|
+
tokenAddress: MOCK_CONTRACT_ADDRESS,
|
|
56
58
|
};
|
|
57
|
-
|
|
58
|
-
mockWallet.readContract.mockRejectedValue(error);
|
|
59
|
+
mockMulticall.mockRejectedValue(new Error("Failed to get balance"));
|
|
59
60
|
const response = await actionProvider.getBalance(mockWallet, args);
|
|
60
|
-
expect(
|
|
61
|
-
|
|
62
|
-
abi: constants_1.abi,
|
|
63
|
-
functionName: "balanceOf",
|
|
64
|
-
args: [mockWallet.getAddress()],
|
|
65
|
-
});
|
|
66
|
-
expect(response).toContain(`Error getting balance: ${error}`);
|
|
61
|
+
expect(mockMulticall).toHaveBeenCalled();
|
|
62
|
+
expect(response).toContain("Error: Could not fetch token details");
|
|
67
63
|
});
|
|
68
64
|
});
|
|
69
65
|
describe("Transfer Action", () => {
|
|
70
66
|
const TRANSACTION_HASH = "0xghijkl987654321";
|
|
71
67
|
let mockWallet;
|
|
68
|
+
let mockMulticall;
|
|
72
69
|
const actionProvider = (0, erc20ActionProvider_1.erc20ActionProvider)();
|
|
73
70
|
beforeEach(async () => {
|
|
71
|
+
mockMulticall = jest.fn();
|
|
72
|
+
const mockPublicClient = {
|
|
73
|
+
multicall: mockMulticall,
|
|
74
|
+
getCode: jest.fn().mockResolvedValue("0x"),
|
|
75
|
+
};
|
|
74
76
|
mockWallet = {
|
|
75
77
|
sendTransaction: jest.fn(),
|
|
76
78
|
waitForTransactionReceipt: jest.fn(),
|
|
@@ -78,47 +80,40 @@ describe("Transfer Action", () => {
|
|
|
78
80
|
getNetwork: jest.fn().mockReturnValue({
|
|
79
81
|
networkId: "base-mainnet",
|
|
80
82
|
}),
|
|
83
|
+
getPublicClient: jest.fn().mockReturnValue(mockPublicClient),
|
|
84
|
+
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
81
85
|
};
|
|
82
86
|
mockWallet.sendTransaction.mockResolvedValue(TRANSACTION_HASH);
|
|
83
87
|
mockWallet.waitForTransactionReceipt.mockResolvedValue({});
|
|
84
88
|
});
|
|
85
89
|
it("should successfully respond", async () => {
|
|
90
|
+
mockMulticall.mockResolvedValueOnce([
|
|
91
|
+
{ result: "MockToken" }, // name
|
|
92
|
+
{ result: MOCK_DECIMALS }, // decimals
|
|
93
|
+
{ result: BigInt(100000 * 10 ** MOCK_DECIMALS) }, // balance
|
|
94
|
+
]);
|
|
86
95
|
const args = {
|
|
87
|
-
amount:
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
amount: MOCK_AMOUNT.toString(),
|
|
97
|
+
tokenAddress: MOCK_CONTRACT_ADDRESS,
|
|
98
|
+
destinationAddress: MOCK_DESTINATION,
|
|
90
99
|
};
|
|
91
100
|
const response = await actionProvider.transfer(mockWallet, args);
|
|
92
|
-
expect(
|
|
93
|
-
|
|
94
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
95
|
-
abi: constants_1.abi,
|
|
96
|
-
functionName: "transfer",
|
|
97
|
-
args: [args.destination, BigInt(args.amount)],
|
|
98
|
-
}),
|
|
99
|
-
});
|
|
101
|
+
expect(mockMulticall).toHaveBeenCalled();
|
|
102
|
+
expect(mockWallet.sendTransaction).toHaveBeenCalled();
|
|
100
103
|
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith(TRANSACTION_HASH);
|
|
101
|
-
expect(response).toContain(`Transferred ${MOCK_AMOUNT} of ${MOCK_CONTRACT_ADDRESS} to ${MOCK_DESTINATION}`);
|
|
104
|
+
expect(response).toContain(`Transferred ${MOCK_AMOUNT} of MockToken (${MOCK_CONTRACT_ADDRESS}) to ${MOCK_DESTINATION}`);
|
|
102
105
|
expect(response).toContain(`Transaction hash for the transfer: ${TRANSACTION_HASH}`);
|
|
103
106
|
});
|
|
104
107
|
it("should fail with an error", async () => {
|
|
108
|
+
mockMulticall.mockRejectedValue(new Error("Failed to get token details"));
|
|
105
109
|
const args = {
|
|
106
|
-
amount:
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
amount: MOCK_AMOUNT.toString(),
|
|
111
|
+
tokenAddress: MOCK_CONTRACT_ADDRESS,
|
|
112
|
+
destinationAddress: MOCK_DESTINATION,
|
|
109
113
|
};
|
|
110
|
-
const error = new Error("Failed to execute transfer");
|
|
111
|
-
mockWallet.sendTransaction.mockRejectedValue(error);
|
|
112
114
|
const response = await actionProvider.transfer(mockWallet, args);
|
|
113
|
-
expect(
|
|
114
|
-
|
|
115
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
116
|
-
abi: constants_1.abi,
|
|
117
|
-
functionName: "transfer",
|
|
118
|
-
args: [args.destination, BigInt(args.amount)],
|
|
119
|
-
}),
|
|
120
|
-
});
|
|
121
|
-
expect(response).toContain(`Error transferring the asset: ${error}`);
|
|
115
|
+
expect(mockMulticall).toHaveBeenCalled();
|
|
116
|
+
expect(response).toContain("Error: Could not fetch token details");
|
|
122
117
|
});
|
|
123
118
|
describe("supportsNetwork", () => {
|
|
124
119
|
it("should return true when protocolFamily is evm", () => {
|
|
@@ -129,3 +124,71 @@ describe("Transfer Action", () => {
|
|
|
129
124
|
});
|
|
130
125
|
});
|
|
131
126
|
});
|
|
127
|
+
describe("GetTokenAddress Schema", () => {
|
|
128
|
+
it("should successfully parse valid token symbol", () => {
|
|
129
|
+
const validInput = { symbol: "usdc" };
|
|
130
|
+
const result = schemas_1.GetTokenAddressSchema.safeParse(validInput);
|
|
131
|
+
expect(result.success).toBe(true);
|
|
132
|
+
expect(result.data?.symbol).toBe("USDC"); // Should be uppercase
|
|
133
|
+
});
|
|
134
|
+
it("should fail parsing empty symbol", () => {
|
|
135
|
+
const emptyInput = { symbol: "" };
|
|
136
|
+
const result = schemas_1.GetTokenAddressSchema.safeParse(emptyInput);
|
|
137
|
+
expect(result.success).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
it("should fail parsing symbol too long", () => {
|
|
140
|
+
const longInput = { symbol: "VERYLONGTOKENSYMBOL" };
|
|
141
|
+
const result = schemas_1.GetTokenAddressSchema.safeParse(longInput);
|
|
142
|
+
expect(result.success).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe("Get Token Address Action", () => {
|
|
146
|
+
let mockWallet;
|
|
147
|
+
const actionProvider = (0, erc20ActionProvider_1.erc20ActionProvider)();
|
|
148
|
+
beforeEach(() => {
|
|
149
|
+
mockWallet = {
|
|
150
|
+
getNetwork: jest.fn(),
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
it("should return token address for valid symbol on base-mainnet", async () => {
|
|
154
|
+
mockWallet.getNetwork.mockReturnValue({
|
|
155
|
+
protocolFamily: "evm",
|
|
156
|
+
networkId: "base-mainnet",
|
|
157
|
+
});
|
|
158
|
+
const response = await actionProvider.getTokenAddress(mockWallet, { symbol: "USDC" });
|
|
159
|
+
expect(response).toContain("Token address for USDC on base-mainnet: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913");
|
|
160
|
+
});
|
|
161
|
+
it("should return token address for valid symbol on base-sepolia", async () => {
|
|
162
|
+
mockWallet.getNetwork.mockReturnValue({
|
|
163
|
+
protocolFamily: "evm",
|
|
164
|
+
networkId: "base-sepolia",
|
|
165
|
+
});
|
|
166
|
+
const response = await actionProvider.getTokenAddress(mockWallet, { symbol: "EURC" });
|
|
167
|
+
expect(response).toContain("Token address for EURC on base-sepolia: 0x808456652fdb597867f38412077A9182bf77359F");
|
|
168
|
+
});
|
|
169
|
+
it("should return error for unsupported network", async () => {
|
|
170
|
+
mockWallet.getNetwork.mockReturnValue({
|
|
171
|
+
protocolFamily: "evm",
|
|
172
|
+
networkId: "unsupported-network",
|
|
173
|
+
});
|
|
174
|
+
const response = await actionProvider.getTokenAddress(mockWallet, { symbol: "USDC" });
|
|
175
|
+
expect(response).toContain('Error: Token symbol "USDC" not found on unsupported-network');
|
|
176
|
+
});
|
|
177
|
+
it("should return error for unknown token symbol", async () => {
|
|
178
|
+
mockWallet.getNetwork.mockReturnValue({
|
|
179
|
+
protocolFamily: "evm",
|
|
180
|
+
networkId: "base-mainnet",
|
|
181
|
+
});
|
|
182
|
+
const response = await actionProvider.getTokenAddress(mockWallet, { symbol: "UNKNOWN" });
|
|
183
|
+
expect(response).toContain('Error: Token symbol "UNKNOWN" not found on base-mainnet');
|
|
184
|
+
expect(response).toContain('Error: Token symbol "UNKNOWN" not found on base-mainnet');
|
|
185
|
+
});
|
|
186
|
+
it("should return error when network ID is not available", async () => {
|
|
187
|
+
mockWallet.getNetwork.mockReturnValue({
|
|
188
|
+
protocolFamily: "evm",
|
|
189
|
+
// networkId is undefined
|
|
190
|
+
});
|
|
191
|
+
const response = await actionProvider.getTokenAddress(mockWallet, { symbol: "USDC" });
|
|
192
|
+
expect(response).toContain('Error: Token symbol "USDC" not found on undefined');
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -3,25 +3,38 @@ import { z } from "zod";
|
|
|
3
3
|
* Input schema for transfer action.
|
|
4
4
|
*/
|
|
5
5
|
export declare const TransferSchema: z.ZodObject<{
|
|
6
|
-
amount: z.
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
amount: z.ZodString;
|
|
7
|
+
tokenAddress: z.ZodString;
|
|
8
|
+
destinationAddress: z.ZodString;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
amount: string;
|
|
11
|
+
tokenAddress: string;
|
|
12
|
+
destinationAddress: string;
|
|
13
13
|
}, {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
amount: string;
|
|
15
|
+
tokenAddress: string;
|
|
16
|
+
destinationAddress: string;
|
|
17
17
|
}>;
|
|
18
18
|
/**
|
|
19
19
|
* Input schema for get balance action.
|
|
20
20
|
*/
|
|
21
21
|
export declare const GetBalanceSchema: z.ZodObject<{
|
|
22
|
-
|
|
22
|
+
tokenAddress: z.ZodString;
|
|
23
|
+
address: z.ZodOptional<z.ZodString>;
|
|
23
24
|
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
|
|
25
|
+
tokenAddress: string;
|
|
26
|
+
address?: string | undefined;
|
|
25
27
|
}, {
|
|
26
|
-
|
|
28
|
+
tokenAddress: string;
|
|
29
|
+
address?: string | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Input schema for get token address action.
|
|
33
|
+
*/
|
|
34
|
+
export declare const GetTokenAddressSchema: z.ZodObject<{
|
|
35
|
+
symbol: z.ZodString;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
symbol: string;
|
|
38
|
+
}, {
|
|
39
|
+
symbol: string;
|
|
27
40
|
}>;
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetBalanceSchema = exports.TransferSchema = void 0;
|
|
3
|
+
exports.GetTokenAddressSchema = exports.GetBalanceSchema = exports.TransferSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
/**
|
|
6
6
|
* Input schema for transfer action.
|
|
7
7
|
*/
|
|
8
8
|
exports.TransferSchema = zod_1.z
|
|
9
9
|
.object({
|
|
10
|
-
amount: zod_1.z
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
amount: zod_1.z
|
|
11
|
+
.string()
|
|
12
|
+
.describe("The amount of the asset to transfer in whole units (e.g. 1.5 USDC)"),
|
|
13
|
+
tokenAddress: zod_1.z
|
|
14
|
+
.string()
|
|
15
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
16
|
+
.describe("The contract address of the token to transfer"),
|
|
17
|
+
destinationAddress: zod_1.z
|
|
18
|
+
.string()
|
|
19
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
20
|
+
.describe("The destination to transfer the funds"),
|
|
13
21
|
})
|
|
14
22
|
.strip()
|
|
15
23
|
.describe("Instructions for transferring assets");
|
|
@@ -18,9 +26,29 @@ exports.TransferSchema = zod_1.z
|
|
|
18
26
|
*/
|
|
19
27
|
exports.GetBalanceSchema = zod_1.z
|
|
20
28
|
.object({
|
|
21
|
-
|
|
29
|
+
tokenAddress: zod_1.z
|
|
22
30
|
.string()
|
|
23
|
-
.
|
|
31
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
32
|
+
.describe("The contract address of the ERC20 token to get the balance for"),
|
|
33
|
+
address: zod_1.z
|
|
34
|
+
.string()
|
|
35
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
36
|
+
.optional()
|
|
37
|
+
.describe("The address to check the balance for. If not provided, uses the wallet's address"),
|
|
24
38
|
})
|
|
25
39
|
.strip()
|
|
26
40
|
.describe("Instructions for getting wallet balance");
|
|
41
|
+
/**
|
|
42
|
+
* Input schema for get token address action.
|
|
43
|
+
*/
|
|
44
|
+
exports.GetTokenAddressSchema = zod_1.z
|
|
45
|
+
.object({
|
|
46
|
+
symbol: zod_1.z
|
|
47
|
+
.string()
|
|
48
|
+
.min(1)
|
|
49
|
+
.max(10)
|
|
50
|
+
.toUpperCase()
|
|
51
|
+
.describe("The token symbol (e.g., USDC, WETH, DEGEN)"),
|
|
52
|
+
})
|
|
53
|
+
.strip()
|
|
54
|
+
.describe("Instructions for getting a token's contract address by symbol");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
2
|
+
/**
|
|
3
|
+
* Interface for token details
|
|
4
|
+
*/
|
|
5
|
+
export interface TokenDetails {
|
|
6
|
+
name: string;
|
|
7
|
+
decimals: number;
|
|
8
|
+
balance: bigint;
|
|
9
|
+
formattedBalance: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Gets the details of an ERC20 token including name, decimals, and balance.
|
|
13
|
+
*
|
|
14
|
+
* @param walletProvider - The wallet provider to use for the multicall.
|
|
15
|
+
* @param contractAddress - The contract address of the ERC20 token.
|
|
16
|
+
* @param address - The address to check the balance for. If not provided, uses the wallet's address.
|
|
17
|
+
* @returns A promise that resolves to TokenDetails or null if there's an error.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getTokenDetails(walletProvider: EvmWalletProvider, contractAddress: string, address?: string): Promise<TokenDetails | null>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenDetails = getTokenDetails;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* Gets the details of an ERC20 token including name, decimals, and balance.
|
|
7
|
+
*
|
|
8
|
+
* @param walletProvider - The wallet provider to use for the multicall.
|
|
9
|
+
* @param contractAddress - The contract address of the ERC20 token.
|
|
10
|
+
* @param address - The address to check the balance for. If not provided, uses the wallet's address.
|
|
11
|
+
* @returns A promise that resolves to TokenDetails or null if there's an error.
|
|
12
|
+
*/
|
|
13
|
+
async function getTokenDetails(walletProvider, contractAddress, address) {
|
|
14
|
+
try {
|
|
15
|
+
const results = await walletProvider.getPublicClient().multicall({
|
|
16
|
+
contracts: [
|
|
17
|
+
{
|
|
18
|
+
address: contractAddress,
|
|
19
|
+
abi: viem_1.erc20Abi,
|
|
20
|
+
functionName: "name",
|
|
21
|
+
args: [],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
address: contractAddress,
|
|
25
|
+
abi: viem_1.erc20Abi,
|
|
26
|
+
functionName: "decimals",
|
|
27
|
+
args: [],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
address: contractAddress,
|
|
31
|
+
abi: viem_1.erc20Abi,
|
|
32
|
+
functionName: "balanceOf",
|
|
33
|
+
args: [(address || walletProvider.getAddress())],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
const name = results[0].result;
|
|
38
|
+
const decimals = results[1]?.result;
|
|
39
|
+
const balance = results[2]?.result;
|
|
40
|
+
if (balance === undefined || decimals === undefined || name === undefined) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const formattedBalance = (0, viem_1.formatUnits)(BigInt(balance), decimals);
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
decimals,
|
|
47
|
+
balance: BigInt(balance),
|
|
48
|
+
formattedBalance,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Addresses } from "./types";
|
|
2
|
-
import {
|
|
2
|
+
import { erc20Abi as ERC20_ABI } from "viem";
|
|
3
3
|
export { ERC20_ABI };
|
|
4
4
|
export declare const FastFlaunchZapAddress: Addresses;
|
|
5
5
|
export declare const FlaunchPositionManagerAddress: Addresses;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PERMIT_TYPES = exports.PERMIT_DETAILS = exports.PERMIT2_ABI = exports.UNIVERSAL_ROUTER_ABI = exports.URCommands = exports.V4Actions = exports.IV4RouterAbiExactOutput = exports.IV4RouterAbiExactInput = exports.QUOTER_ABI = exports.POSITION_MANAGER_ABI = exports.FAST_FLAUNCH_ZAP_ABI = exports.Permit2Address = exports.UniversalRouterAddress = exports.QuoterAddress = exports.FLETHHooksAddress = exports.FLETHAddress = exports.FlaunchPositionManagerAddress = exports.FastFlaunchZapAddress = exports.ERC20_ABI = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const chains_1 = require("viem/chains");
|
|
6
|
-
const
|
|
7
|
-
Object.defineProperty(exports, "ERC20_ABI", { enumerable: true, get: function () { return
|
|
6
|
+
const viem_2 = require("viem");
|
|
7
|
+
Object.defineProperty(exports, "ERC20_ABI", { enumerable: true, get: function () { return viem_2.erc20Abi; } });
|
|
8
8
|
exports.FastFlaunchZapAddress = {
|
|
9
9
|
[chains_1.base.id]: "0xd79e27f51ddf9df5ee76106ee192530f474b02f6",
|
|
10
10
|
[chains_1.baseSepolia.id]: "0x251e97446a7019E5DA4860d4CF47291321C693D0",
|
|
@@ -209,11 +209,7 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
209
209
|
signature = await walletProvider.signTypedData(typedData);
|
|
210
210
|
permitSingle = message;
|
|
211
211
|
}
|
|
212
|
-
const
|
|
213
|
-
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
|
|
214
|
-
transport: (0, viem_1.http)(),
|
|
215
|
-
});
|
|
216
|
-
const quoteResult = await viemPublicClient.simulateContract({
|
|
212
|
+
const quoteResult = await walletProvider.getPublicClient().simulateContract({
|
|
217
213
|
address: constants_1.QuoterAddress[chainId],
|
|
218
214
|
abi: constants_1.QUOTER_ABI,
|
|
219
215
|
functionName: "quoteExactInput",
|
|
@@ -308,17 +304,13 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
308
304
|
throw new Error("Chain ID is not set.");
|
|
309
305
|
}
|
|
310
306
|
try {
|
|
311
|
-
const viemPublicClient = (0, viem_1.createPublicClient)({
|
|
312
|
-
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
|
|
313
|
-
transport: (0, viem_1.http)(),
|
|
314
|
-
});
|
|
315
307
|
let amountIn;
|
|
316
308
|
let amountOutMin;
|
|
317
309
|
let amountOut;
|
|
318
310
|
let amountInMax;
|
|
319
311
|
if (swapType === "EXACT_IN") {
|
|
320
312
|
amountIn = (0, viem_1.parseEther)(swapParams.amountIn);
|
|
321
|
-
const quoteResult = await
|
|
313
|
+
const quoteResult = await walletProvider.getPublicClient().simulateContract({
|
|
322
314
|
address: constants_1.QuoterAddress[chainId],
|
|
323
315
|
abi: constants_1.QUOTER_ABI,
|
|
324
316
|
functionName: "quoteExactInput",
|
|
@@ -351,7 +343,7 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
351
343
|
else {
|
|
352
344
|
// EXACT_OUT
|
|
353
345
|
amountOut = (0, viem_1.parseEther)(swapParams.amountOut);
|
|
354
|
-
const quoteResult = await
|
|
346
|
+
const quoteResult = await walletProvider.getPublicClient().simulateContract({
|
|
355
347
|
address: constants_1.QuoterAddress[chainId],
|
|
356
348
|
abi: constants_1.QUOTER_ABI,
|
|
357
349
|
functionName: "quoteExactOutput",
|
|
@@ -116,6 +116,11 @@ describe("FlaunchActionProvider", () => {
|
|
|
116
116
|
return undefined;
|
|
117
117
|
}),
|
|
118
118
|
signTypedData: jest.fn().mockResolvedValue("0xsignature"),
|
|
119
|
+
getPublicClient: jest.fn().mockReturnValue({
|
|
120
|
+
simulateContract: jest.fn().mockResolvedValue({
|
|
121
|
+
result: [BigInt(1000000000000000000)],
|
|
122
|
+
}),
|
|
123
|
+
}),
|
|
119
124
|
};
|
|
120
125
|
});
|
|
121
126
|
describe("network support", () => {
|
|
@@ -18,6 +18,7 @@ export * from "./moonwell";
|
|
|
18
18
|
export * from "./morpho";
|
|
19
19
|
export * from "./opensea";
|
|
20
20
|
export * from "./spl";
|
|
21
|
+
export * from "./superfluid";
|
|
21
22
|
export * from "./truemarkets";
|
|
22
23
|
export * from "./twitter";
|
|
23
24
|
export * from "./wallet";
|
|
@@ -30,4 +31,6 @@ export * from "./vaultsfyi";
|
|
|
30
31
|
export * from "./x402";
|
|
31
32
|
export * from "./zerion";
|
|
32
33
|
export * from "./zerodev";
|
|
34
|
+
export * from "./zeroX";
|
|
33
35
|
export * from "./zora";
|
|
36
|
+
export * from "./clanker";
|
|
@@ -34,6 +34,7 @@ __exportStar(require("./moonwell"), exports);
|
|
|
34
34
|
__exportStar(require("./morpho"), exports);
|
|
35
35
|
__exportStar(require("./opensea"), exports);
|
|
36
36
|
__exportStar(require("./spl"), exports);
|
|
37
|
+
__exportStar(require("./superfluid"), exports);
|
|
37
38
|
__exportStar(require("./truemarkets"), exports);
|
|
38
39
|
__exportStar(require("./twitter"), exports);
|
|
39
40
|
__exportStar(require("./wallet"), exports);
|
|
@@ -46,4 +47,6 @@ __exportStar(require("./vaultsfyi"), exports);
|
|
|
46
47
|
__exportStar(require("./x402"), exports);
|
|
47
48
|
__exportStar(require("./zerion"), exports);
|
|
48
49
|
__exportStar(require("./zerodev"), exports);
|
|
50
|
+
__exportStar(require("./zeroX"), exports);
|
|
49
51
|
__exportStar(require("./zora"), exports);
|
|
52
|
+
__exportStar(require("./clanker"), exports);
|
|
@@ -9,9 +9,9 @@ export declare const SwapTokenSchema: z.ZodObject<{
|
|
|
9
9
|
slippageBps: z.ZodDefault<z.ZodNumber>;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
11
|
amount: number;
|
|
12
|
+
slippageBps: number;
|
|
12
13
|
inputMint: string;
|
|
13
14
|
outputMint: string;
|
|
14
|
-
slippageBps: number;
|
|
15
15
|
}, {
|
|
16
16
|
amount: number;
|
|
17
17
|
inputMint: string;
|
|
@@ -7,12 +7,12 @@ export declare const MintSchema: z.ZodObject<{
|
|
|
7
7
|
tokenAddress: z.ZodString;
|
|
8
8
|
mTokenAddress: z.ZodString;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
assets: string;
|
|
11
10
|
tokenAddress: string;
|
|
11
|
+
assets: string;
|
|
12
12
|
mTokenAddress: string;
|
|
13
13
|
}, {
|
|
14
|
-
assets: string;
|
|
15
14
|
tokenAddress: string;
|
|
15
|
+
assets: string;
|
|
16
16
|
mTokenAddress: string;
|
|
17
17
|
}>;
|
|
18
18
|
/**
|
|
@@ -13,12 +13,12 @@ exports.morphoActionProvider = exports.MorphoActionProvider = exports.SUPPORTED_
|
|
|
13
13
|
const zod_1 = require("zod");
|
|
14
14
|
const decimal_js_1 = require("decimal.js");
|
|
15
15
|
const viem_1 = require("viem");
|
|
16
|
-
const
|
|
16
|
+
const viem_2 = require("viem");
|
|
17
17
|
const actionProvider_1 = require("../actionProvider");
|
|
18
18
|
const wallet_providers_1 = require("../../wallet-providers");
|
|
19
19
|
const actionDecorator_1 = require("../actionDecorator");
|
|
20
20
|
const utils_1 = require("../../utils");
|
|
21
|
-
const
|
|
21
|
+
const constants_1 = require("./constants");
|
|
22
22
|
const schemas_1 = require("./schemas");
|
|
23
23
|
exports.SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
|
|
24
24
|
/**
|
|
@@ -53,7 +53,7 @@ class MorphoActionProvider extends actionProvider_1.ActionProvider {
|
|
|
53
53
|
try {
|
|
54
54
|
const decimals = await wallet.readContract({
|
|
55
55
|
address: args.tokenAddress,
|
|
56
|
-
abi:
|
|
56
|
+
abi: viem_2.erc20Abi,
|
|
57
57
|
functionName: "decimals",
|
|
58
58
|
args: [],
|
|
59
59
|
});
|
|
@@ -63,7 +63,7 @@ class MorphoActionProvider extends actionProvider_1.ActionProvider {
|
|
|
63
63
|
return `Error approving Morpho Vault as spender: ${approvalResult}`;
|
|
64
64
|
}
|
|
65
65
|
const data = (0, viem_1.encodeFunctionData)({
|
|
66
|
-
abi:
|
|
66
|
+
abi: constants_1.METAMORPHO_ABI,
|
|
67
67
|
functionName: "deposit",
|
|
68
68
|
args: [atomicAssets, args.receiver],
|
|
69
69
|
});
|
|
@@ -91,7 +91,7 @@ class MorphoActionProvider extends actionProvider_1.ActionProvider {
|
|
|
91
91
|
}
|
|
92
92
|
try {
|
|
93
93
|
const data = (0, viem_1.encodeFunctionData)({
|
|
94
|
-
abi:
|
|
94
|
+
abi: constants_1.METAMORPHO_ABI,
|
|
95
95
|
functionName: "withdraw",
|
|
96
96
|
args: [BigInt(args.assets), args.receiver, args.receiver],
|
|
97
97
|
});
|
|
@@ -8,14 +8,14 @@ export declare const DepositSchema: z.ZodObject<{
|
|
|
8
8
|
tokenAddress: z.ZodString;
|
|
9
9
|
vaultAddress: z.ZodString;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
tokenAddress: string;
|
|
11
12
|
receiver: string;
|
|
12
13
|
assets: string;
|
|
13
|
-
tokenAddress: string;
|
|
14
14
|
vaultAddress: string;
|
|
15
15
|
}, {
|
|
16
|
+
tokenAddress: string;
|
|
16
17
|
receiver: string;
|
|
17
18
|
assets: string;
|
|
18
|
-
tokenAddress: string;
|
|
19
19
|
vaultAddress: string;
|
|
20
20
|
}>;
|
|
21
21
|
/**
|
|
@@ -37,6 +37,11 @@ class PythActionProvider extends actionProvider_1.ActionProvider {
|
|
|
37
37
|
* @returns The price feed ID as a string.
|
|
38
38
|
*/
|
|
39
39
|
async fetchPriceFeed(args) {
|
|
40
|
+
// Stop-gap solution: Return hardcoded price feed ID for ETH
|
|
41
|
+
// This is temporary until proper new API link is provided after talking to the Pyth team
|
|
42
|
+
if (args.tokenSymbol.toUpperCase() === "ETH") {
|
|
43
|
+
return "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace";
|
|
44
|
+
}
|
|
40
45
|
const url = `https://hermes.pyth.network/v2/price_feeds?query=${args.tokenSymbol}&asset_type=crypto`;
|
|
41
46
|
const response = await fetch(url);
|
|
42
47
|
if (!response.ok) {
|
|
@@ -22,7 +22,11 @@ describe("PythActionProvider", () => {
|
|
|
22
22
|
ok: true,
|
|
23
23
|
json: async () => [{ id: "some-price-feed-id", attributes: { base: "BTC" } }],
|
|
24
24
|
});
|
|
25
|
-
await expect(provider.fetchPriceFeed({ tokenSymbol: "
|
|
25
|
+
await expect(provider.fetchPriceFeed({ tokenSymbol: "SOL" })).rejects.toThrow("No price feed found for SOL");
|
|
26
|
+
});
|
|
27
|
+
it("should return hardcoded price feed ID for ETH", async () => {
|
|
28
|
+
const priceFeedId = await provider.fetchPriceFeed({ tokenSymbol: "ETH" });
|
|
29
|
+
expect(priceFeedId).toEqual("0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace");
|
|
26
30
|
});
|
|
27
31
|
it("should throw an error if the response is not ok", async () => {
|
|
28
32
|
fetchMock.mockResolvedValueOnce({
|