@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
|
@@ -8,18 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var _TrueMarketsActionProvider_publicClient;
|
|
23
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
12
|
exports.truemarketsActionProvider = exports.TrueMarketsActionProvider = void 0;
|
|
25
13
|
const zod_1 = require("zod");
|
|
@@ -27,22 +15,18 @@ const actionProvider_1 = require("../actionProvider");
|
|
|
27
15
|
const actionDecorator_1 = require("../actionDecorator");
|
|
28
16
|
const schemas_1 = require("./schemas");
|
|
29
17
|
const constants_1 = require("./constants");
|
|
30
|
-
const constants_2 = require("../erc20/constants");
|
|
31
|
-
const wallet_providers_1 = require("../../wallet-providers");
|
|
32
18
|
const viem_1 = require("viem");
|
|
33
|
-
const
|
|
19
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
20
|
+
const viem_2 = require("viem");
|
|
34
21
|
/**
|
|
35
|
-
*
|
|
22
|
+
* Action provider for TrueMarkets interactions.
|
|
36
23
|
*/
|
|
37
24
|
class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
38
25
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param config - The configuration options for the TrueMarketsActionProvider.
|
|
26
|
+
* Creates a new TrueMarkets action provider.
|
|
42
27
|
*/
|
|
43
|
-
constructor(
|
|
28
|
+
constructor() {
|
|
44
29
|
super("truemarkets", []);
|
|
45
|
-
_TrueMarketsActionProvider_publicClient.set(this, void 0);
|
|
46
30
|
/**
|
|
47
31
|
* Checks if the TrueMarkets action provider supports the given network.
|
|
48
32
|
* Currently only supports Base mainnet.
|
|
@@ -51,10 +35,6 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
51
35
|
* @returns True if the TrueMarkets action provider supports the network, false otherwise.
|
|
52
36
|
*/
|
|
53
37
|
this.supportsNetwork = (network) => network.networkId === "base-mainnet";
|
|
54
|
-
__classPrivateFieldSet(this, _TrueMarketsActionProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
55
|
-
chain: chains_1.base,
|
|
56
|
-
transport: config?.RPC_URL ? (0, viem_1.http)(config.RPC_URL) : (0, viem_1.http)(),
|
|
57
|
-
}), "f");
|
|
58
38
|
}
|
|
59
39
|
/**
|
|
60
40
|
* Gets active markets from the TruthMarketManager contract.
|
|
@@ -105,7 +85,7 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
105
85
|
functionName: "getActiveMarketAddress",
|
|
106
86
|
args: [BigInt(index)],
|
|
107
87
|
}));
|
|
108
|
-
const marketAddresses = await
|
|
88
|
+
const marketAddresses = await walletProvider.getPublicClient().multicall({
|
|
109
89
|
contracts: addressCalls,
|
|
110
90
|
});
|
|
111
91
|
// Filter out errors and extract results
|
|
@@ -124,7 +104,7 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
124
104
|
abi: constants_1.TruthMarketABI,
|
|
125
105
|
functionName: "marketQuestion",
|
|
126
106
|
}));
|
|
127
|
-
const marketQuestionsResult = await
|
|
107
|
+
const marketQuestionsResult = await walletProvider.getPublicClient().multicall({
|
|
128
108
|
contracts: questionCalls,
|
|
129
109
|
});
|
|
130
110
|
// Create market objects mapping indices to addresses and questions
|
|
@@ -175,7 +155,7 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
175
155
|
});
|
|
176
156
|
}
|
|
177
157
|
try {
|
|
178
|
-
marketAddress = (await
|
|
158
|
+
marketAddress = (await walletProvider.getPublicClient().readContract({
|
|
179
159
|
address: constants_1.TruthMarketManager_ADDRESS,
|
|
180
160
|
abi: constants_1.TruthMarketManagerABI,
|
|
181
161
|
functionName: "getActiveMarketAddress",
|
|
@@ -227,7 +207,7 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
227
207
|
functionName: "winningPosition",
|
|
228
208
|
},
|
|
229
209
|
];
|
|
230
|
-
const basicInfoResults = await
|
|
210
|
+
const basicInfoResults = await walletProvider.getPublicClient().multicall({
|
|
231
211
|
contracts: basicInfoCalls,
|
|
232
212
|
});
|
|
233
213
|
// Extract results, handling potential errors
|
|
@@ -279,7 +259,7 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
279
259
|
functionName: "slot0",
|
|
280
260
|
},
|
|
281
261
|
];
|
|
282
|
-
const poolInfoResults = await
|
|
262
|
+
const poolInfoResults = await walletProvider.getPublicClient().multicall({
|
|
283
263
|
contracts: poolInfoCalls,
|
|
284
264
|
});
|
|
285
265
|
if (poolInfoResults.some(result => result.status === "failure")) {
|
|
@@ -308,30 +288,30 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
308
288
|
const balanceCalls = [
|
|
309
289
|
{
|
|
310
290
|
address: payToken,
|
|
311
|
-
abi:
|
|
291
|
+
abi: viem_1.erc20Abi,
|
|
312
292
|
functionName: "balanceOf",
|
|
313
293
|
args: [yesPool],
|
|
314
294
|
},
|
|
315
295
|
{
|
|
316
296
|
address: yesToken,
|
|
317
|
-
abi:
|
|
297
|
+
abi: viem_1.erc20Abi,
|
|
318
298
|
functionName: "balanceOf",
|
|
319
299
|
args: [yesPool],
|
|
320
300
|
},
|
|
321
301
|
{
|
|
322
302
|
address: payToken,
|
|
323
|
-
abi:
|
|
303
|
+
abi: viem_1.erc20Abi,
|
|
324
304
|
functionName: "balanceOf",
|
|
325
305
|
args: [noPool],
|
|
326
306
|
},
|
|
327
307
|
{
|
|
328
308
|
address: noToken,
|
|
329
|
-
abi:
|
|
309
|
+
abi: viem_1.erc20Abi,
|
|
330
310
|
functionName: "balanceOf",
|
|
331
311
|
args: [noPool],
|
|
332
312
|
},
|
|
333
313
|
];
|
|
334
|
-
const balanceResults = await
|
|
314
|
+
const balanceResults = await walletProvider.getPublicClient().multicall({
|
|
335
315
|
contracts: balanceCalls,
|
|
336
316
|
});
|
|
337
317
|
if (balanceResults.some(result => result.status === "failure")) {
|
|
@@ -366,10 +346,10 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
366
346
|
const yesPrice = calculatePrice(yesSqrtPriceX96, isYesToken0, payDecimals, yesNoTokenDecimals_);
|
|
367
347
|
const noPrice = calculatePrice(noSqrtPriceX96, isNoToken0, payDecimals, yesNoTokenDecimals_);
|
|
368
348
|
// Calculate TVL using token balances
|
|
369
|
-
const yesPoolStableValue = Number((0,
|
|
370
|
-
const yesPoolTokenValue = Number((0,
|
|
371
|
-
const noPoolStableValue = Number((0,
|
|
372
|
-
const noPoolTokenValue = Number((0,
|
|
349
|
+
const yesPoolStableValue = Number((0, viem_2.formatUnits)(yesPoolStableBalance || 0n, payDecimals));
|
|
350
|
+
const yesPoolTokenValue = Number((0, viem_2.formatUnits)(yesPoolTokenBalance || 0n, yesNoTokenDecimals_)) * yesPrice;
|
|
351
|
+
const noPoolStableValue = Number((0, viem_2.formatUnits)(noPoolStableBalance || 0n, payDecimals));
|
|
352
|
+
const noPoolTokenValue = Number((0, viem_2.formatUnits)(noPoolTokenBalance || 0n, yesNoTokenDecimals_)) * noPrice;
|
|
373
353
|
const yesTVL = yesPoolStableValue + yesPoolTokenValue;
|
|
374
354
|
const noTVL = noPoolStableValue + noPoolTokenValue;
|
|
375
355
|
const totalTVL = yesTVL + noTVL;
|
|
@@ -430,7 +410,6 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
|
|
|
430
410
|
}
|
|
431
411
|
}
|
|
432
412
|
exports.TrueMarketsActionProvider = TrueMarketsActionProvider;
|
|
433
|
-
_TrueMarketsActionProvider_publicClient = new WeakMap();
|
|
434
413
|
__decorate([
|
|
435
414
|
(0, actionDecorator_1.CreateAction)({
|
|
436
415
|
name: "get_prediction_markets",
|
|
@@ -465,5 +444,5 @@ __decorate([
|
|
|
465
444
|
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
466
445
|
__metadata("design:returntype", Promise)
|
|
467
446
|
], TrueMarketsActionProvider.prototype, "getPredictionMarketDetails", null);
|
|
468
|
-
const truemarketsActionProvider = (
|
|
447
|
+
const truemarketsActionProvider = () => new TrueMarketsActionProvider();
|
|
469
448
|
exports.truemarketsActionProvider = truemarketsActionProvider;
|
|
@@ -2,29 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const truemarketsActionProvider_1 = require("./truemarketsActionProvider");
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
-
const viem_1 = require("viem");
|
|
6
|
-
// Mock viem's createPublicClient
|
|
7
|
-
jest.mock("viem", () => {
|
|
8
|
-
const originalModule = jest.requireActual("viem");
|
|
9
|
-
return {
|
|
10
|
-
...originalModule,
|
|
11
|
-
createPublicClient: jest.fn().mockImplementation(() => ({
|
|
12
|
-
// Mock public client methods as needed
|
|
13
|
-
multicall: jest.fn().mockImplementation(({ contracts }) => {
|
|
14
|
-
// Create mock responses with success status
|
|
15
|
-
return contracts.map(() => ({
|
|
16
|
-
status: "success",
|
|
17
|
-
result: "mock result",
|
|
18
|
-
}));
|
|
19
|
-
}),
|
|
20
|
-
readContract: jest.fn(),
|
|
21
|
-
})),
|
|
22
|
-
http: jest.fn().mockImplementation(url => ({ url })),
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
5
|
describe("TrueMarketsActionProvider", () => {
|
|
26
6
|
let provider;
|
|
27
7
|
let mockWallet;
|
|
8
|
+
let publicClientMock;
|
|
28
9
|
// Mock addresses and data for tests
|
|
29
10
|
const MOCK_MARKET_ADDRESS = "0x1234567890123456789012345678901234567890";
|
|
30
11
|
const MOCK_YES_POOL_ADDRESS = "0x2345678901234567890123456789012345678901";
|
|
@@ -36,26 +17,22 @@ describe("TrueMarketsActionProvider", () => {
|
|
|
36
17
|
const MOCK_MARKET_SOURCE = "Test source";
|
|
37
18
|
const MOCK_STATUS_NUM = 0n; // Created status
|
|
38
19
|
const MOCK_END_OF_TRADING = 1717171717n; // Unix timestamp
|
|
39
|
-
describe("constructor", () => {
|
|
40
|
-
it("should use the provided RPC_URL for the public client", () => {
|
|
41
|
-
const customRpcUrl = "https://custom-rpc.example.com";
|
|
42
|
-
(0, truemarketsActionProvider_1.truemarketsActionProvider)({ RPC_URL: customRpcUrl });
|
|
43
|
-
// Verify createPublicClient was called with the correct URL
|
|
44
|
-
expect(viem_1.createPublicClient).toHaveBeenCalledWith(expect.objectContaining({
|
|
45
|
-
chain: expect.anything(),
|
|
46
|
-
transport: expect.objectContaining({ url: customRpcUrl }),
|
|
47
|
-
}));
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
20
|
beforeEach(() => {
|
|
51
21
|
jest.clearAllMocks();
|
|
52
22
|
provider = (0, truemarketsActionProvider_1.truemarketsActionProvider)();
|
|
23
|
+
publicClientMock = {
|
|
24
|
+
multicall: jest
|
|
25
|
+
.fn()
|
|
26
|
+
.mockImplementation(({ contracts }) => contracts.map(() => ({ status: "success", result: "mock result" }))),
|
|
27
|
+
readContract: jest.fn(),
|
|
28
|
+
};
|
|
53
29
|
mockWallet = {
|
|
54
30
|
readContract: jest.fn(),
|
|
55
31
|
getName: jest.fn().mockReturnValue("evm_wallet_provider"),
|
|
56
32
|
getNetwork: jest.fn().mockReturnValue({
|
|
57
33
|
networkId: "base-mainnet",
|
|
58
34
|
}),
|
|
35
|
+
getPublicClient: jest.fn().mockReturnValue(publicClientMock),
|
|
59
36
|
};
|
|
60
37
|
});
|
|
61
38
|
afterEach(() => {
|
|
@@ -134,8 +111,9 @@ describe("TrueMarketsActionProvider", () => {
|
|
|
134
111
|
describe("getPredictionMarketDetails", () => {
|
|
135
112
|
let mockPublicClient;
|
|
136
113
|
beforeEach(() => {
|
|
137
|
-
//
|
|
138
|
-
mockPublicClient =
|
|
114
|
+
// Use the shared mocked public client
|
|
115
|
+
mockPublicClient = publicClientMock;
|
|
116
|
+
mockPublicClient.multicall.mockReset();
|
|
139
117
|
// Setup multicall mock responses
|
|
140
118
|
mockPublicClient.multicall
|
|
141
119
|
// Basic info calls
|
|
@@ -14,12 +14,25 @@ const zod_1 = require("zod");
|
|
|
14
14
|
const actionDecorator_1 = require("../actionDecorator");
|
|
15
15
|
const actionProvider_1 = require("../actionProvider");
|
|
16
16
|
const wallet_providers_1 = require("../../wallet-providers");
|
|
17
|
+
const viem_1 = require("viem");
|
|
17
18
|
const schemas_1 = require("./schemas");
|
|
18
19
|
const PROTOCOL_FAMILY_TO_TERMINOLOGY = {
|
|
19
|
-
evm: {
|
|
20
|
-
|
|
20
|
+
evm: {
|
|
21
|
+
unit: "WEI",
|
|
22
|
+
displayUnit: "ETH",
|
|
23
|
+
decimals: 18,
|
|
24
|
+
type: "Transaction hash",
|
|
25
|
+
verb: "transaction",
|
|
26
|
+
},
|
|
27
|
+
svm: { unit: "LAMPORTS", displayUnit: "SOL", decimals: 9, type: "Signature", verb: "transfer" },
|
|
28
|
+
};
|
|
29
|
+
const DEFAULT_TERMINOLOGY = {
|
|
30
|
+
unit: "",
|
|
31
|
+
displayUnit: "",
|
|
32
|
+
decimals: 0,
|
|
33
|
+
type: "Hash",
|
|
34
|
+
verb: "transfer",
|
|
21
35
|
};
|
|
22
|
-
const DEFAULT_TERMINOLOGY = { unit: "", displayUnit: "", type: "Hash", verb: "transfer" };
|
|
23
36
|
/**
|
|
24
37
|
* WalletActionProvider provides actions for getting basic wallet information.
|
|
25
38
|
*/
|
|
@@ -61,6 +74,7 @@ class WalletActionProvider extends actionProvider_1.ActionProvider {
|
|
|
61
74
|
` * Network ID: ${network.networkId || "N/A"}`,
|
|
62
75
|
` * Chain ID: ${network.chainId || "N/A"}`,
|
|
63
76
|
`- Native Balance: ${balance.toString()} ${terminology.unit}`,
|
|
77
|
+
`- Native Balance: ${(0, viem_1.formatUnits)(balance, terminology.decimals)} ${terminology.displayUnit}`,
|
|
64
78
|
].join("\n");
|
|
65
79
|
}
|
|
66
80
|
catch (error) {
|
|
@@ -81,7 +95,8 @@ class WalletActionProvider extends actionProvider_1.ActionProvider {
|
|
|
81
95
|
if (protocolFamily === "evm" && !args.to.startsWith("0x")) {
|
|
82
96
|
args.to = `0x${args.to}`;
|
|
83
97
|
}
|
|
84
|
-
const
|
|
98
|
+
const amountInAtomicUnits = (0, viem_1.parseUnits)(args.value, terminology.decimals);
|
|
99
|
+
const result = await walletProvider.nativeTransfer(args.to, amountInAtomicUnits.toString());
|
|
85
100
|
return [
|
|
86
101
|
`Transferred ${args.value} ${terminology.displayUnit} to ${args.to}`,
|
|
87
102
|
`${terminology.type}: ${result}`,
|
|
@@ -115,15 +130,11 @@ __decorate([
|
|
|
115
130
|
(0, actionDecorator_1.CreateAction)({
|
|
116
131
|
name: "native_transfer",
|
|
117
132
|
description: `
|
|
118
|
-
This tool will transfer native tokens from the wallet to another onchain address.
|
|
133
|
+
This tool will transfer (send) native tokens from the wallet to another onchain address.
|
|
119
134
|
|
|
120
135
|
It takes the following inputs:
|
|
121
|
-
- amount: The amount to transfer in whole units (e.g.
|
|
136
|
+
- amount: The amount to transfer in whole units (e.g. 4.2 ETH, 0.1 SOL)
|
|
122
137
|
- destination: The address to receive the funds
|
|
123
|
-
|
|
124
|
-
Important notes:
|
|
125
|
-
- Ensure sufficient balance of the input asset before transferring
|
|
126
|
-
- Ensure there is sufficient native token balance for gas fees
|
|
127
138
|
`,
|
|
128
139
|
schema: schemas_1.NativeTransferSchema,
|
|
129
140
|
}),
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const walletActionProvider_1 = require("./walletActionProvider");
|
|
4
4
|
const schemas_1 = require("./schemas");
|
|
5
|
+
const viem_1 = require("viem");
|
|
5
6
|
describe("Wallet Action Provider", () => {
|
|
6
7
|
const MOCK_ADDRESS = "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83";
|
|
7
8
|
const MOCK_ETH_BALANCE = 1000000000000000000n;
|
|
@@ -47,6 +48,7 @@ describe("Wallet Action Provider", () => {
|
|
|
47
48
|
` * Network ID: ${MOCK_EVM_NETWORK.networkId}`,
|
|
48
49
|
` * Chain ID: ${MOCK_EVM_NETWORK.chainId}`,
|
|
49
50
|
`- Native Balance: ${MOCK_ETH_BALANCE.toString()} WEI`,
|
|
51
|
+
`- Native Balance: ${(0, viem_1.formatUnits)(MOCK_ETH_BALANCE, 18)} ETH`,
|
|
50
52
|
].join("\n");
|
|
51
53
|
expect(response).toBe(expectedResponse);
|
|
52
54
|
});
|
|
@@ -63,6 +65,7 @@ describe("Wallet Action Provider", () => {
|
|
|
63
65
|
` * Network ID: ${MOCK_SOLANA_NETWORK.networkId}`,
|
|
64
66
|
` * Chain ID: N/A`,
|
|
65
67
|
`- Native Balance: ${MOCK_SOL_BALANCE.toString()} LAMPORTS`,
|
|
68
|
+
`- Native Balance: ${(0, viem_1.formatUnits)(MOCK_SOL_BALANCE, 9)} SOL`,
|
|
66
69
|
].join("\n");
|
|
67
70
|
expect(response).toBe(expectedResponse);
|
|
68
71
|
});
|
|
@@ -79,6 +82,7 @@ describe("Wallet Action Provider", () => {
|
|
|
79
82
|
` * Network ID: ${MOCK_UNKNOWN_NETWORK.networkId}`,
|
|
80
83
|
` * Chain ID: N/A`,
|
|
81
84
|
`- Native Balance: ${MOCK_ETH_BALANCE.toString()} `,
|
|
85
|
+
`- Native Balance: ${MOCK_ETH_BALANCE.toString()} `,
|
|
82
86
|
].join("\n");
|
|
83
87
|
expect(response).toBe(expectedResponse);
|
|
84
88
|
});
|
|
@@ -125,7 +129,7 @@ describe("Wallet Action Provider", () => {
|
|
|
125
129
|
value: MOCK_AMOUNT,
|
|
126
130
|
};
|
|
127
131
|
const response = await actionProvider.nativeTransfer(mockWallet, args);
|
|
128
|
-
expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, MOCK_AMOUNT);
|
|
132
|
+
expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, (0, viem_1.parseUnits)(MOCK_AMOUNT, 18).toString());
|
|
129
133
|
expect(response).toBe(`Transferred ${MOCK_AMOUNT} ETH to ${MOCK_DESTINATION}\nTransaction hash: ${MOCK_TRANSACTION_HASH}`);
|
|
130
134
|
});
|
|
131
135
|
it("should successfully transfer SOL", async () => {
|
|
@@ -136,7 +140,7 @@ describe("Wallet Action Provider", () => {
|
|
|
136
140
|
value: MOCK_AMOUNT,
|
|
137
141
|
};
|
|
138
142
|
const response = await actionProvider.nativeTransfer(mockWallet, args);
|
|
139
|
-
expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, MOCK_AMOUNT);
|
|
143
|
+
expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, (0, viem_1.parseUnits)(MOCK_AMOUNT, 9).toString());
|
|
140
144
|
expect(response).toBe(`Transferred ${MOCK_AMOUNT} SOL to ${MOCK_DESTINATION}\nSignature: ${MOCK_SIGNATURE}`);
|
|
141
145
|
});
|
|
142
146
|
it("should handle ETH transfer errors", async () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./zeroXActionProvider";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./zeroXActionProvider"), exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for getting a swap price.
|
|
4
|
+
*/
|
|
5
|
+
export declare const GetSwapPriceSchema: z.ZodObject<{
|
|
6
|
+
sellToken: z.ZodString;
|
|
7
|
+
buyToken: z.ZodString;
|
|
8
|
+
sellAmount: z.ZodString;
|
|
9
|
+
slippageBps: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
10
|
+
swapFeeRecipient: z.ZodOptional<z.ZodString>;
|
|
11
|
+
swapFeeBps: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
slippageBps: number;
|
|
14
|
+
buyToken: string;
|
|
15
|
+
sellToken: string;
|
|
16
|
+
sellAmount: string;
|
|
17
|
+
swapFeeBps: number;
|
|
18
|
+
swapFeeRecipient?: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
buyToken: string;
|
|
21
|
+
sellToken: string;
|
|
22
|
+
sellAmount: string;
|
|
23
|
+
slippageBps?: number | undefined;
|
|
24
|
+
swapFeeRecipient?: string | undefined;
|
|
25
|
+
swapFeeBps?: number | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Input schema for executing a swap.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ExecuteSwapSchema: z.ZodObject<{
|
|
31
|
+
sellToken: z.ZodString;
|
|
32
|
+
buyToken: z.ZodString;
|
|
33
|
+
sellAmount: z.ZodString;
|
|
34
|
+
slippageBps: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
35
|
+
swapFeeRecipient: z.ZodOptional<z.ZodString>;
|
|
36
|
+
swapFeeBps: z.ZodDefault<z.ZodNumber>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
slippageBps: number;
|
|
39
|
+
buyToken: string;
|
|
40
|
+
sellToken: string;
|
|
41
|
+
sellAmount: string;
|
|
42
|
+
swapFeeBps: number;
|
|
43
|
+
swapFeeRecipient?: string | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
buyToken: string;
|
|
46
|
+
sellToken: string;
|
|
47
|
+
sellAmount: string;
|
|
48
|
+
slippageBps?: number | undefined;
|
|
49
|
+
swapFeeRecipient?: string | undefined;
|
|
50
|
+
swapFeeBps?: number | undefined;
|
|
51
|
+
}>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecuteSwapSchema = exports.GetSwapPriceSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for getting a swap price.
|
|
7
|
+
*/
|
|
8
|
+
exports.GetSwapPriceSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
sellToken: zod_1.z
|
|
11
|
+
.string()
|
|
12
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
13
|
+
.describe("The token contract address to sell"),
|
|
14
|
+
buyToken: zod_1.z
|
|
15
|
+
.string()
|
|
16
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
17
|
+
.describe("The token contract address to buy"),
|
|
18
|
+
sellAmount: zod_1.z
|
|
19
|
+
.string()
|
|
20
|
+
.describe("The amount of sellToken to sell in whole units (e.g., 1.5 WETH, 10 USDC)"),
|
|
21
|
+
slippageBps: zod_1.z
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
24
|
+
.min(0)
|
|
25
|
+
.max(10000)
|
|
26
|
+
.optional()
|
|
27
|
+
.default(100)
|
|
28
|
+
.describe("The maximum acceptable slippage in basis points (0-10000, default: 100)"),
|
|
29
|
+
swapFeeRecipient: zod_1.z
|
|
30
|
+
.string()
|
|
31
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
32
|
+
.optional()
|
|
33
|
+
.describe("The wallet address to receive an affiliate fee on the trade"),
|
|
34
|
+
swapFeeBps: zod_1.z
|
|
35
|
+
.number()
|
|
36
|
+
.int()
|
|
37
|
+
.min(0)
|
|
38
|
+
.max(1000)
|
|
39
|
+
.default(100)
|
|
40
|
+
.describe("The amount in basis points (0-1000) of the sellToken to charge as trading fee (defaults to 100 = 1%), only used if swapFeeRecipient is provided"),
|
|
41
|
+
})
|
|
42
|
+
.strip()
|
|
43
|
+
.describe("Get a price quote for swapping one token for another");
|
|
44
|
+
/**
|
|
45
|
+
* Input schema for executing a swap.
|
|
46
|
+
*/
|
|
47
|
+
exports.ExecuteSwapSchema = zod_1.z
|
|
48
|
+
.object({
|
|
49
|
+
sellToken: zod_1.z
|
|
50
|
+
.string()
|
|
51
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
52
|
+
.describe("The token contract address to sell"),
|
|
53
|
+
buyToken: zod_1.z
|
|
54
|
+
.string()
|
|
55
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
56
|
+
.describe("The token contract address to buy"),
|
|
57
|
+
sellAmount: zod_1.z
|
|
58
|
+
.string()
|
|
59
|
+
.describe("The amount of sellToken to sell in whole units (e.g., 1.5 WETH, 10 USDC)"),
|
|
60
|
+
slippageBps: zod_1.z
|
|
61
|
+
.number()
|
|
62
|
+
.int()
|
|
63
|
+
.min(0)
|
|
64
|
+
.max(10000)
|
|
65
|
+
.optional()
|
|
66
|
+
.default(100)
|
|
67
|
+
.describe("The maximum acceptable slippage in basis points (0-10000, default: 100)"),
|
|
68
|
+
swapFeeRecipient: zod_1.z
|
|
69
|
+
.string()
|
|
70
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
71
|
+
.optional()
|
|
72
|
+
.describe("The wallet address to receive an affiliate fee on the trade"),
|
|
73
|
+
swapFeeBps: zod_1.z
|
|
74
|
+
.number()
|
|
75
|
+
.int()
|
|
76
|
+
.min(0)
|
|
77
|
+
.max(1000)
|
|
78
|
+
.default(100)
|
|
79
|
+
.describe("The amount in basis points (0-1000) of the sellToken to charge as trading fee (defaults to 100 = 1%), only used if swapFeeRecipient is provided"),
|
|
80
|
+
})
|
|
81
|
+
.strip()
|
|
82
|
+
.describe("Execute a swap between two tokens");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
2
|
+
export declare const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a token is native ETH.
|
|
5
|
+
*
|
|
6
|
+
* @param token - The token address to check.
|
|
7
|
+
* @returns True if the token is native ETH, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isNativeEth(token: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the details (decimals and name) for both fromToken and toToken
|
|
12
|
+
*
|
|
13
|
+
* @param walletProvider - The EVM wallet provider to read contracts
|
|
14
|
+
* @param fromToken - The contract address of the from token
|
|
15
|
+
* @param toToken - The contract address of the to token
|
|
16
|
+
* @returns Promise<{fromTokenDecimals: number, toTokenDecimals: number, fromTokenName: string, toTokenName: string}>
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTokenDetails(walletProvider: EvmWalletProvider, fromToken: string, toToken: string): Promise<{
|
|
19
|
+
fromTokenDecimals: number;
|
|
20
|
+
toTokenDecimals: number;
|
|
21
|
+
fromTokenName: string;
|
|
22
|
+
toTokenName: string;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERMIT2_ADDRESS = void 0;
|
|
4
|
+
exports.isNativeEth = isNativeEth;
|
|
5
|
+
exports.getTokenDetails = getTokenDetails;
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
// Permit2 contract address is the same across all networks
|
|
8
|
+
exports.PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a token is native ETH.
|
|
11
|
+
*
|
|
12
|
+
* @param token - The token address to check.
|
|
13
|
+
* @returns True if the token is native ETH, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
function isNativeEth(token) {
|
|
16
|
+
return token.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Gets the details (decimals and name) for both fromToken and toToken
|
|
20
|
+
*
|
|
21
|
+
* @param walletProvider - The EVM wallet provider to read contracts
|
|
22
|
+
* @param fromToken - The contract address of the from token
|
|
23
|
+
* @param toToken - The contract address of the to token
|
|
24
|
+
* @returns Promise<{fromTokenDecimals: number, toTokenDecimals: number, fromTokenName: string, toTokenName: string}>
|
|
25
|
+
*/
|
|
26
|
+
async function getTokenDetails(walletProvider, fromToken, toToken) {
|
|
27
|
+
// Initialize default values for native ETH
|
|
28
|
+
let fromTokenDecimals = 18;
|
|
29
|
+
let fromTokenName = "ETH";
|
|
30
|
+
let toTokenDecimals = 18;
|
|
31
|
+
let toTokenName = "ETH";
|
|
32
|
+
// Prepare multicall contracts array
|
|
33
|
+
const contracts = [];
|
|
34
|
+
const contractIndexMap = {
|
|
35
|
+
fromDecimals: -1,
|
|
36
|
+
fromName: -1,
|
|
37
|
+
toDecimals: -1,
|
|
38
|
+
toName: -1,
|
|
39
|
+
};
|
|
40
|
+
// Add from token contracts if not native ETH
|
|
41
|
+
if (!isNativeEth(fromToken)) {
|
|
42
|
+
contractIndexMap.fromDecimals = contracts.length;
|
|
43
|
+
contracts.push({
|
|
44
|
+
address: fromToken,
|
|
45
|
+
abi: viem_1.erc20Abi,
|
|
46
|
+
functionName: "decimals",
|
|
47
|
+
});
|
|
48
|
+
contractIndexMap.fromName = contracts.length;
|
|
49
|
+
contracts.push({
|
|
50
|
+
address: fromToken,
|
|
51
|
+
abi: viem_1.erc20Abi,
|
|
52
|
+
functionName: "name",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Add to token contracts if not native ETH
|
|
56
|
+
if (!isNativeEth(toToken)) {
|
|
57
|
+
contractIndexMap.toDecimals = contracts.length;
|
|
58
|
+
contracts.push({
|
|
59
|
+
address: toToken,
|
|
60
|
+
abi: viem_1.erc20Abi,
|
|
61
|
+
functionName: "decimals",
|
|
62
|
+
});
|
|
63
|
+
contractIndexMap.toName = contracts.length;
|
|
64
|
+
contracts.push({
|
|
65
|
+
address: toToken,
|
|
66
|
+
abi: viem_1.erc20Abi,
|
|
67
|
+
functionName: "name",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Execute multicall if there are contracts to call
|
|
71
|
+
if (contracts.length > 0) {
|
|
72
|
+
try {
|
|
73
|
+
const results = await walletProvider.getPublicClient().multicall({
|
|
74
|
+
contracts,
|
|
75
|
+
});
|
|
76
|
+
// Extract from token details
|
|
77
|
+
if (contractIndexMap.fromDecimals !== -1) {
|
|
78
|
+
const decimalsResult = results[contractIndexMap.fromDecimals];
|
|
79
|
+
const nameResult = results[contractIndexMap.fromName];
|
|
80
|
+
if (decimalsResult.status === "success" && nameResult.status === "success") {
|
|
81
|
+
fromTokenDecimals = decimalsResult.result;
|
|
82
|
+
fromTokenName = nameResult.result;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new Error(`Failed to read details for fromToken ${fromToken}. This address may not be a valid ERC20 contract.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Extract to token details
|
|
89
|
+
if (contractIndexMap.toDecimals !== -1) {
|
|
90
|
+
const decimalsResult = results[contractIndexMap.toDecimals];
|
|
91
|
+
const nameResult = results[contractIndexMap.toName];
|
|
92
|
+
if (decimalsResult.status === "success" && nameResult.status === "success") {
|
|
93
|
+
toTokenDecimals = decimalsResult.result;
|
|
94
|
+
toTokenName = nameResult.result;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw new Error(`Failed to read details for toToken ${toToken}. This address may not be a valid ERC20 contract.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw new Error(`Failed to read token details via multicall. Error: ${error}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { fromTokenDecimals, toTokenDecimals, fromTokenName, toTokenName };
|
|
106
|
+
}
|