mantle-agent-kit-sdk 1.0.1 → 1.0.3
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 +32 -8
- package/dist/index.cjs +174 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -6
- package/dist/index.d.ts +36 -6
- package/dist/index.js +178 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { WalletClient, Transport, Chain, PublicActions, Address as Address$1, Hex } from 'viem';
|
|
3
3
|
import { PrivateKeyAccount, Address } from 'viem/accounts';
|
|
4
|
+
import { Erc7811Actions } from 'viem/experimental';
|
|
4
5
|
|
|
5
6
|
interface SquidRoute {
|
|
6
7
|
route: {
|
|
@@ -144,10 +145,11 @@ declare function getProjectConfig(): ProjectConfig;
|
|
|
144
145
|
|
|
145
146
|
declare class MNTAgentKit {
|
|
146
147
|
account: PrivateKeyAccount;
|
|
147
|
-
client: WalletClient<Transport, Chain, PrivateKeyAccount> & PublicActions;
|
|
148
|
+
client: WalletClient<Transport, Chain, PrivateKeyAccount> & PublicActions & Erc7811Actions;
|
|
148
149
|
chain: "testnet" | "mainnet";
|
|
150
|
+
demo: boolean;
|
|
149
151
|
projectConfig?: ProjectConfig;
|
|
150
|
-
constructor(privateKey: Address, chain: "mainnet" | "testnet");
|
|
152
|
+
constructor(privateKey: Address, chain: "mainnet" | "testnet" | "testnet-demo");
|
|
151
153
|
/**
|
|
152
154
|
* Initialize the agent with platform validation
|
|
153
155
|
*
|
|
@@ -168,7 +170,7 @@ declare class MNTAgentKit {
|
|
|
168
170
|
getSwapQuote(fromTokenAddress: string, toTokenAddress: string, amount: string, slippagePercentage?: string): Promise<any>;
|
|
169
171
|
executeSwap(fromTokenAddress: string, toTokenAddress: string, amount: string, slippagePercentage?: string): Promise<{
|
|
170
172
|
data: any;
|
|
171
|
-
}
|
|
173
|
+
}>;
|
|
172
174
|
getOpenOceanQuote(fromToken: Address, toToken: Address, amount: string): Promise<OpenOceanQuote>;
|
|
173
175
|
swapOnOpenOcean(fromToken: Address, toToken: Address, amount: string, slippage?: number): Promise<{
|
|
174
176
|
txHash: string;
|
|
@@ -191,11 +193,25 @@ declare class MNTAgentKit {
|
|
|
191
193
|
agniSwap(tokenIn: Address, tokenOut: Address, amountIn: string, slippagePercent?: number, feeTier?: number): Promise<`0x${string}`>;
|
|
192
194
|
merchantMoeSwap(tokenIn: Address, tokenOut: Address, amountIn: string, slippagePercent?: number): Promise<`0x${string}`>;
|
|
193
195
|
getMethTokenAddress(): "0x0000000000000000000000000000000000000000" | "0xcDA86A272531e8640cD7F1a92c01839911B90bb0";
|
|
194
|
-
getSquidRoute(fromToken: Address, toToken: Address, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<
|
|
196
|
+
getSquidRoute(fromToken: Address, toToken: Address, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<{
|
|
197
|
+
route: {
|
|
198
|
+
estimate: {
|
|
199
|
+
toAmount: string;
|
|
200
|
+
};
|
|
201
|
+
transactionRequest: {
|
|
202
|
+
targetAddress: string;
|
|
203
|
+
data: string;
|
|
204
|
+
value: string;
|
|
205
|
+
gasLimit: string;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
demo: boolean;
|
|
209
|
+
message: string;
|
|
210
|
+
} | SquidRoute>;
|
|
195
211
|
crossChainSwapViaSquid(fromToken: Address, toToken: Address, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<`0x${string}`>;
|
|
196
212
|
}
|
|
197
213
|
|
|
198
|
-
declare const sendTransaction: (agent: MNTAgentKit, to: Address$1, amount: string) => Promise<viem.TransactionReceipt<bigint, number, "success" | "reverted", viem.TransactionType>>;
|
|
214
|
+
declare const sendTransaction: (agent: MNTAgentKit, to: Address$1, amount: string, tokenAddress?: Address$1) => Promise<viem.TransactionReceipt<bigint, number, "success" | "reverted", viem.TransactionType>>;
|
|
199
215
|
|
|
200
216
|
/**
|
|
201
217
|
* Check allowance and get approve tx data if needed
|
|
@@ -318,7 +334,21 @@ declare function crossChainSwapViaSquid(agent: MNTAgentKit, fromToken: Address$1
|
|
|
318
334
|
* @param slippage - Slippage tolerance percentage (default: 1%)
|
|
319
335
|
* @returns Route data including estimated output and fees
|
|
320
336
|
*/
|
|
321
|
-
declare function getSquidRoute(agent: MNTAgentKit, fromToken: Address$1, toToken: Address$1, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<
|
|
337
|
+
declare function getSquidRoute(agent: MNTAgentKit, fromToken: Address$1, toToken: Address$1, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<{
|
|
338
|
+
route: {
|
|
339
|
+
estimate: {
|
|
340
|
+
toAmount: string;
|
|
341
|
+
};
|
|
342
|
+
transactionRequest: {
|
|
343
|
+
targetAddress: string;
|
|
344
|
+
data: string;
|
|
345
|
+
value: string;
|
|
346
|
+
gasLimit: string;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
demo: boolean;
|
|
350
|
+
message: string;
|
|
351
|
+
} | SquidRoute>;
|
|
322
352
|
|
|
323
353
|
/**
|
|
324
354
|
* Supply (deposit) tokens to Lendle Protocol
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { WalletClient, Transport, Chain, PublicActions, Address as Address$1, Hex } from 'viem';
|
|
3
3
|
import { PrivateKeyAccount, Address } from 'viem/accounts';
|
|
4
|
+
import { Erc7811Actions } from 'viem/experimental';
|
|
4
5
|
|
|
5
6
|
interface SquidRoute {
|
|
6
7
|
route: {
|
|
@@ -144,10 +145,11 @@ declare function getProjectConfig(): ProjectConfig;
|
|
|
144
145
|
|
|
145
146
|
declare class MNTAgentKit {
|
|
146
147
|
account: PrivateKeyAccount;
|
|
147
|
-
client: WalletClient<Transport, Chain, PrivateKeyAccount> & PublicActions;
|
|
148
|
+
client: WalletClient<Transport, Chain, PrivateKeyAccount> & PublicActions & Erc7811Actions;
|
|
148
149
|
chain: "testnet" | "mainnet";
|
|
150
|
+
demo: boolean;
|
|
149
151
|
projectConfig?: ProjectConfig;
|
|
150
|
-
constructor(privateKey: Address, chain: "mainnet" | "testnet");
|
|
152
|
+
constructor(privateKey: Address, chain: "mainnet" | "testnet" | "testnet-demo");
|
|
151
153
|
/**
|
|
152
154
|
* Initialize the agent with platform validation
|
|
153
155
|
*
|
|
@@ -168,7 +170,7 @@ declare class MNTAgentKit {
|
|
|
168
170
|
getSwapQuote(fromTokenAddress: string, toTokenAddress: string, amount: string, slippagePercentage?: string): Promise<any>;
|
|
169
171
|
executeSwap(fromTokenAddress: string, toTokenAddress: string, amount: string, slippagePercentage?: string): Promise<{
|
|
170
172
|
data: any;
|
|
171
|
-
}
|
|
173
|
+
}>;
|
|
172
174
|
getOpenOceanQuote(fromToken: Address, toToken: Address, amount: string): Promise<OpenOceanQuote>;
|
|
173
175
|
swapOnOpenOcean(fromToken: Address, toToken: Address, amount: string, slippage?: number): Promise<{
|
|
174
176
|
txHash: string;
|
|
@@ -191,11 +193,25 @@ declare class MNTAgentKit {
|
|
|
191
193
|
agniSwap(tokenIn: Address, tokenOut: Address, amountIn: string, slippagePercent?: number, feeTier?: number): Promise<`0x${string}`>;
|
|
192
194
|
merchantMoeSwap(tokenIn: Address, tokenOut: Address, amountIn: string, slippagePercent?: number): Promise<`0x${string}`>;
|
|
193
195
|
getMethTokenAddress(): "0x0000000000000000000000000000000000000000" | "0xcDA86A272531e8640cD7F1a92c01839911B90bb0";
|
|
194
|
-
getSquidRoute(fromToken: Address, toToken: Address, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<
|
|
196
|
+
getSquidRoute(fromToken: Address, toToken: Address, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<{
|
|
197
|
+
route: {
|
|
198
|
+
estimate: {
|
|
199
|
+
toAmount: string;
|
|
200
|
+
};
|
|
201
|
+
transactionRequest: {
|
|
202
|
+
targetAddress: string;
|
|
203
|
+
data: string;
|
|
204
|
+
value: string;
|
|
205
|
+
gasLimit: string;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
demo: boolean;
|
|
209
|
+
message: string;
|
|
210
|
+
} | SquidRoute>;
|
|
195
211
|
crossChainSwapViaSquid(fromToken: Address, toToken: Address, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<`0x${string}`>;
|
|
196
212
|
}
|
|
197
213
|
|
|
198
|
-
declare const sendTransaction: (agent: MNTAgentKit, to: Address$1, amount: string) => Promise<viem.TransactionReceipt<bigint, number, "success" | "reverted", viem.TransactionType>>;
|
|
214
|
+
declare const sendTransaction: (agent: MNTAgentKit, to: Address$1, amount: string, tokenAddress?: Address$1) => Promise<viem.TransactionReceipt<bigint, number, "success" | "reverted", viem.TransactionType>>;
|
|
199
215
|
|
|
200
216
|
/**
|
|
201
217
|
* Check allowance and get approve tx data if needed
|
|
@@ -318,7 +334,21 @@ declare function crossChainSwapViaSquid(agent: MNTAgentKit, fromToken: Address$1
|
|
|
318
334
|
* @param slippage - Slippage tolerance percentage (default: 1%)
|
|
319
335
|
* @returns Route data including estimated output and fees
|
|
320
336
|
*/
|
|
321
|
-
declare function getSquidRoute(agent: MNTAgentKit, fromToken: Address$1, toToken: Address$1, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<
|
|
337
|
+
declare function getSquidRoute(agent: MNTAgentKit, fromToken: Address$1, toToken: Address$1, fromChain: number, toChain: number, amount: string, slippage?: number): Promise<{
|
|
338
|
+
route: {
|
|
339
|
+
estimate: {
|
|
340
|
+
toAmount: string;
|
|
341
|
+
};
|
|
342
|
+
transactionRequest: {
|
|
343
|
+
targetAddress: string;
|
|
344
|
+
data: string;
|
|
345
|
+
value: string;
|
|
346
|
+
gasLimit: string;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
demo: boolean;
|
|
350
|
+
message: string;
|
|
351
|
+
} | SquidRoute>;
|
|
322
352
|
|
|
323
353
|
/**
|
|
324
354
|
* Supply (deposit) tokens to Lendle Protocol
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,53 @@
|
|
|
1
|
-
import { parseEther, encodeFunctionData, createWalletClient, http, publicActions, erc20Abi } from 'viem';
|
|
1
|
+
import { parseUnits, parseEther, encodeFunctionData, createWalletClient, http, publicActions, erc20Abi as erc20Abi$1 } from 'viem';
|
|
2
2
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
3
3
|
import { mantle, mantleSepoliaTestnet } from 'viem/chains';
|
|
4
4
|
import { getTransactionReceipt } from 'viem/actions';
|
|
5
5
|
import axios6 from 'axios';
|
|
6
6
|
import CryptoJS from 'crypto-js';
|
|
7
|
+
import { erc7811Actions } from 'viem/experimental';
|
|
7
8
|
|
|
8
9
|
var __defProp = Object.defineProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
11
|
for (var name in all)
|
|
11
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
13
|
};
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
var erc20Abi = [
|
|
15
|
+
{
|
|
16
|
+
name: "transfer",
|
|
17
|
+
type: "function",
|
|
18
|
+
inputs: [
|
|
19
|
+
{ name: "to", type: "address" },
|
|
20
|
+
{ name: "amount", type: "uint256" }
|
|
21
|
+
],
|
|
22
|
+
outputs: [{ type: "bool" }]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "decimals",
|
|
26
|
+
type: "function",
|
|
27
|
+
inputs: [],
|
|
28
|
+
outputs: [{ type: "uint8" }]
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
var sendTransaction = async (agent, to, amount, tokenAddress) => {
|
|
32
|
+
let hash;
|
|
33
|
+
if (tokenAddress) {
|
|
34
|
+
const decimals = await agent.client.readContract({
|
|
35
|
+
address: tokenAddress,
|
|
36
|
+
abi: erc20Abi,
|
|
37
|
+
functionName: "decimals"
|
|
38
|
+
});
|
|
39
|
+
hash = await agent.client.writeContract({
|
|
40
|
+
address: tokenAddress,
|
|
41
|
+
abi: erc20Abi,
|
|
42
|
+
functionName: "transfer",
|
|
43
|
+
args: [to, parseUnits(amount, decimals)]
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
hash = await agent.client.sendTransaction({
|
|
47
|
+
to,
|
|
48
|
+
value: parseEther(amount)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
18
51
|
const receipt = await getTransactionReceipt(agent.client, {
|
|
19
52
|
hash
|
|
20
53
|
});
|
|
@@ -24,7 +57,7 @@ async function checkAllowance(agent, tokenAddress, ownerAddress, spenderAddress)
|
|
|
24
57
|
try {
|
|
25
58
|
const allowance = await agent.client.readContract({
|
|
26
59
|
address: tokenAddress,
|
|
27
|
-
abi: erc20Abi,
|
|
60
|
+
abi: erc20Abi$1,
|
|
28
61
|
functionName: "allowance",
|
|
29
62
|
args: [ownerAddress, spenderAddress]
|
|
30
63
|
});
|
|
@@ -188,9 +221,85 @@ async function getSwapTransaction(fromTokenAddress, toTokenAddress, amount, user
|
|
|
188
221
|
throw error;
|
|
189
222
|
}
|
|
190
223
|
}
|
|
224
|
+
var DEMO_TX_HASH = "0xdemo000000000000000000000000000000000000000000000000000000000001";
|
|
225
|
+
function createMockSwapResponse(protocol, inputAmount) {
|
|
226
|
+
return {
|
|
227
|
+
txHash: DEMO_TX_HASH,
|
|
228
|
+
amountOut: inputAmount,
|
|
229
|
+
demo: true,
|
|
230
|
+
message: `[DEMO] ${protocol} swap simulated`
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function createMockQuoteResponse(protocol, inputAmount) {
|
|
234
|
+
return {
|
|
235
|
+
estimatedAmount: inputAmount,
|
|
236
|
+
demo: true,
|
|
237
|
+
message: `[DEMO] ${protocol} quote simulated`
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function createMockLendleResponse(action, amount) {
|
|
241
|
+
return {
|
|
242
|
+
txHash: DEMO_TX_HASH,
|
|
243
|
+
amount,
|
|
244
|
+
demo: true,
|
|
245
|
+
message: `[DEMO] Lendle ${action} simulated`
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function createMockTxHash() {
|
|
249
|
+
return DEMO_TX_HASH;
|
|
250
|
+
}
|
|
251
|
+
function createMock1inchSwapResponse(inputAmount) {
|
|
252
|
+
return {
|
|
253
|
+
txHash: DEMO_TX_HASH,
|
|
254
|
+
dstAmount: inputAmount,
|
|
255
|
+
demo: true,
|
|
256
|
+
message: "[DEMO] 1inch swap simulated"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function createMockOkxSwapResponse(inputAmount) {
|
|
260
|
+
return {
|
|
261
|
+
data: DEMO_TX_HASH,
|
|
262
|
+
demo: true,
|
|
263
|
+
message: "[DEMO] OKX swap simulated"
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function createMockOpenOceanSwapResponse(inputAmount) {
|
|
267
|
+
return {
|
|
268
|
+
txHash: DEMO_TX_HASH,
|
|
269
|
+
outAmount: inputAmount,
|
|
270
|
+
demo: true,
|
|
271
|
+
message: "[DEMO] OpenOcean swap simulated"
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function createMockUniswapSwapResponse(inputAmount) {
|
|
275
|
+
return {
|
|
276
|
+
txHash: DEMO_TX_HASH,
|
|
277
|
+
amountOut: inputAmount,
|
|
278
|
+
demo: true,
|
|
279
|
+
message: "[DEMO] Uniswap swap simulated"
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function createMockSquidRoute(amount) {
|
|
283
|
+
return {
|
|
284
|
+
route: {
|
|
285
|
+
estimate: { toAmount: amount },
|
|
286
|
+
transactionRequest: {
|
|
287
|
+
targetAddress: "0x0000000000000000000000000000000000000000",
|
|
288
|
+
data: "0x",
|
|
289
|
+
value: "0",
|
|
290
|
+
gasLimit: "0"
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
demo: true,
|
|
294
|
+
message: "[DEMO] Squid route simulated"
|
|
295
|
+
};
|
|
296
|
+
}
|
|
191
297
|
|
|
192
298
|
// src/tools/okx/swap.ts
|
|
193
299
|
async function executeSwap(agent, fromTokenAddress, toTokenAddress, amount, slippagePercent) {
|
|
300
|
+
if (agent.demo) {
|
|
301
|
+
return createMockOkxSwapResponse();
|
|
302
|
+
}
|
|
194
303
|
const chainIndex = agent.chain === "mainnet" ? "5000" : "5003";
|
|
195
304
|
const walletAddress = agent.account.address;
|
|
196
305
|
if (fromTokenAddress !== ETH_ADDRESS) {
|
|
@@ -324,13 +433,16 @@ async function getSwapData(fromToken, toToken, amount, userAddress, slippage, ch
|
|
|
324
433
|
|
|
325
434
|
// src/tools/openocean/getQuote.ts
|
|
326
435
|
async function getOpenOceanQuote(agent, fromToken, toToken, amount) {
|
|
436
|
+
if (agent.demo) {
|
|
437
|
+
return createMockQuoteResponse("OpenOcean", amount);
|
|
438
|
+
}
|
|
327
439
|
return await getQuoteData(fromToken, toToken, amount, agent.chain);
|
|
328
440
|
}
|
|
329
441
|
async function checkAllowance2(agent, tokenAddress, ownerAddress, spenderAddress) {
|
|
330
442
|
try {
|
|
331
443
|
const allowance = await agent.client.readContract({
|
|
332
444
|
address: tokenAddress,
|
|
333
|
-
abi: erc20Abi,
|
|
445
|
+
abi: erc20Abi$1,
|
|
334
446
|
functionName: "allowance",
|
|
335
447
|
args: [ownerAddress, spenderAddress]
|
|
336
448
|
});
|
|
@@ -355,7 +467,7 @@ async function approveToken2(agent, tokenAddress, spenderAddress, amount) {
|
|
|
355
467
|
console.log("Insufficient allowance, approving tokens...");
|
|
356
468
|
const { encodeFunctionData: encodeFunctionData8 } = await import('viem');
|
|
357
469
|
const approveData = encodeFunctionData8({
|
|
358
|
-
abi: erc20Abi,
|
|
470
|
+
abi: erc20Abi$1,
|
|
359
471
|
functionName: "approve",
|
|
360
472
|
args: [spenderAddress, BigInt(amount)]
|
|
361
473
|
});
|
|
@@ -380,6 +492,9 @@ async function approveToken2(agent, tokenAddress, spenderAddress, amount) {
|
|
|
380
492
|
|
|
381
493
|
// src/tools/openocean/swap.ts
|
|
382
494
|
async function swapOnOpenOcean(agent, fromToken, toToken, amount, slippage = "1") {
|
|
495
|
+
if (agent.demo) {
|
|
496
|
+
return createMockOpenOceanSwapResponse(amount);
|
|
497
|
+
}
|
|
383
498
|
const walletAddress = agent.account.address;
|
|
384
499
|
if (fromToken.toLowerCase() !== NATIVE_TOKEN_ADDRESS.toLowerCase()) {
|
|
385
500
|
await approveToken2(agent, fromToken, OPENOCEAN_EXCHANGE_PROXY, amount);
|
|
@@ -491,11 +606,17 @@ async function getSwapData2(fromToken, toToken, amount, userAddress, slippage, c
|
|
|
491
606
|
|
|
492
607
|
// src/tools/oneinch/getQuote.ts
|
|
493
608
|
async function get1inchQuote(agent, fromToken, toToken, amount) {
|
|
609
|
+
if (agent.demo) {
|
|
610
|
+
return createMockQuoteResponse("1inch", amount);
|
|
611
|
+
}
|
|
494
612
|
return await getQuoteData2(fromToken, toToken, amount, agent.chain);
|
|
495
613
|
}
|
|
496
614
|
|
|
497
615
|
// src/tools/oneinch/swap.ts
|
|
498
616
|
async function swapOn1inch(agent, fromToken, toToken, amount, slippage = "1") {
|
|
617
|
+
if (agent.demo) {
|
|
618
|
+
return createMock1inchSwapResponse(amount);
|
|
619
|
+
}
|
|
499
620
|
const walletAddress = agent.account.address;
|
|
500
621
|
if (fromToken.toLowerCase() !== NATIVE_TOKEN_ADDRESS2.toLowerCase()) {
|
|
501
622
|
await approveToken2(agent, fromToken, ONEINCH_ROUTER_ADDRESS, amount);
|
|
@@ -662,11 +783,17 @@ function buildSwapCalldata(params, fee = DEFAULT_POOL_FEE) {
|
|
|
662
783
|
|
|
663
784
|
// src/tools/uniswap/getQuote.ts
|
|
664
785
|
async function getUniswapQuote(agent, fromToken, toToken, amount, fee = DEFAULT_POOL_FEE) {
|
|
786
|
+
if (agent.demo) {
|
|
787
|
+
return createMockQuoteResponse("Uniswap", amount);
|
|
788
|
+
}
|
|
665
789
|
return await getUniswapQuoteData(agent, fromToken, toToken, amount, fee);
|
|
666
790
|
}
|
|
667
791
|
|
|
668
792
|
// src/tools/uniswap/swap.ts
|
|
669
793
|
async function swapOnUniswap(agent, fromToken, toToken, amount, slippage = "0.5", fee = DEFAULT_POOL_FEE) {
|
|
794
|
+
if (agent.demo) {
|
|
795
|
+
return createMockUniswapSwapResponse(amount);
|
|
796
|
+
}
|
|
670
797
|
const walletAddress = agent.account.address;
|
|
671
798
|
const isNativeIn = fromToken.toLowerCase() === NATIVE_TOKEN_ADDRESS3.toLowerCase();
|
|
672
799
|
const quote = await getUniswapQuoteData(agent, fromToken, toToken, amount, fee);
|
|
@@ -765,6 +892,9 @@ async function getRouteData(fromToken, toToken, fromChain, toChain, amount, from
|
|
|
765
892
|
|
|
766
893
|
// src/tools/squid/crossChainSwap.ts
|
|
767
894
|
async function crossChainSwapViaSquid(agent, fromToken, toToken, fromChain, toChain, amount, slippage = 1) {
|
|
895
|
+
if (agent.demo) {
|
|
896
|
+
return createMockTxHash();
|
|
897
|
+
}
|
|
768
898
|
const routeData = await getRouteData(
|
|
769
899
|
fromToken,
|
|
770
900
|
toToken,
|
|
@@ -793,6 +923,9 @@ async function crossChainSwapViaSquid(agent, fromToken, toToken, fromChain, toCh
|
|
|
793
923
|
return hash;
|
|
794
924
|
}
|
|
795
925
|
async function getSquidRoute(agent, fromToken, toToken, fromChain, toChain, amount, slippage = 1) {
|
|
926
|
+
if (agent.demo) {
|
|
927
|
+
return createMockSquidRoute(amount);
|
|
928
|
+
}
|
|
796
929
|
return await getRouteData(
|
|
797
930
|
fromToken,
|
|
798
931
|
toToken,
|
|
@@ -932,6 +1065,9 @@ var LENDING_POOL_ABI = [
|
|
|
932
1065
|
async function lendleSupply(agent, tokenAddress, amount) {
|
|
933
1066
|
const lendingPoolAddress = LENDING_POOL[agent.chain];
|
|
934
1067
|
if (lendingPoolAddress === "0x0000000000000000000000000000000000000000") {
|
|
1068
|
+
if (agent.demo) {
|
|
1069
|
+
return createMockLendleResponse("supply", amount).txHash;
|
|
1070
|
+
}
|
|
935
1071
|
throw new Error(
|
|
936
1072
|
`Lendle LendingPool not configured for ${agent.chain}. Only available on mainnet.`
|
|
937
1073
|
);
|
|
@@ -958,6 +1094,9 @@ async function lendleSupply(agent, tokenAddress, amount) {
|
|
|
958
1094
|
async function lendleWithdraw(agent, tokenAddress, amount, to) {
|
|
959
1095
|
const lendingPoolAddress = LENDING_POOL[agent.chain];
|
|
960
1096
|
if (lendingPoolAddress === "0x0000000000000000000000000000000000000000") {
|
|
1097
|
+
if (agent.demo) {
|
|
1098
|
+
return createMockLendleResponse("withdraw", amount).txHash;
|
|
1099
|
+
}
|
|
961
1100
|
throw new Error(
|
|
962
1101
|
`Lendle LendingPool not configured for ${agent.chain}. Only available on mainnet.`
|
|
963
1102
|
);
|
|
@@ -979,6 +1118,9 @@ async function lendleWithdraw(agent, tokenAddress, amount, to) {
|
|
|
979
1118
|
async function lendleBorrow(agent, tokenAddress, amount, interestRateMode = INTEREST_RATE_MODE.VARIABLE, onBehalfOf) {
|
|
980
1119
|
const lendingPoolAddress = LENDING_POOL[agent.chain];
|
|
981
1120
|
if (lendingPoolAddress === "0x0000000000000000000000000000000000000000") {
|
|
1121
|
+
if (agent.demo) {
|
|
1122
|
+
return createMockLendleResponse("borrow", amount).txHash;
|
|
1123
|
+
}
|
|
982
1124
|
throw new Error(
|
|
983
1125
|
`Lendle LendingPool not configured for ${agent.chain}. Only available on mainnet.`
|
|
984
1126
|
);
|
|
@@ -1001,6 +1143,9 @@ async function lendleBorrow(agent, tokenAddress, amount, interestRateMode = INTE
|
|
|
1001
1143
|
async function lendleRepay(agent, tokenAddress, amount, rateMode = INTEREST_RATE_MODE.VARIABLE, onBehalfOf) {
|
|
1002
1144
|
const lendingPoolAddress = LENDING_POOL[agent.chain];
|
|
1003
1145
|
if (lendingPoolAddress === "0x0000000000000000000000000000000000000000") {
|
|
1146
|
+
if (agent.demo) {
|
|
1147
|
+
return createMockLendleResponse("repay", amount).txHash;
|
|
1148
|
+
}
|
|
1004
1149
|
throw new Error(
|
|
1005
1150
|
`Lendle LendingPool not configured for ${agent.chain}. Only available on mainnet.`
|
|
1006
1151
|
);
|
|
@@ -1081,6 +1226,9 @@ var FEE_TIERS2 = {
|
|
|
1081
1226
|
async function agniSwap(agent, tokenIn, tokenOut, amountIn, slippagePercent = 0.5, feeTier = FEE_TIERS2.MEDIUM) {
|
|
1082
1227
|
const swapRouterAddress = SWAP_ROUTER[agent.chain];
|
|
1083
1228
|
if (swapRouterAddress === "0x0000000000000000000000000000000000000000") {
|
|
1229
|
+
if (agent.demo) {
|
|
1230
|
+
return createMockSwapResponse("Agni", amountIn).txHash;
|
|
1231
|
+
}
|
|
1084
1232
|
throw new Error(`Agni SwapRouter not available on ${agent.chain}`);
|
|
1085
1233
|
}
|
|
1086
1234
|
const amountInBigInt = BigInt(amountIn);
|
|
@@ -1153,6 +1301,9 @@ var LB_ROUTER_ABI = [
|
|
|
1153
1301
|
async function merchantMoeSwap(agent, tokenIn, tokenOut, amountIn, slippagePercent = 0.5) {
|
|
1154
1302
|
const routerAddress = LB_ROUTER[agent.chain];
|
|
1155
1303
|
if (routerAddress === "0x0000000000000000000000000000000000000000") {
|
|
1304
|
+
if (agent.demo) {
|
|
1305
|
+
return createMockSwapResponse("MerchantMoe", amountIn).txHash;
|
|
1306
|
+
}
|
|
1156
1307
|
throw new Error(`Merchant Moe LB Router not available on ${agent.chain}`);
|
|
1157
1308
|
}
|
|
1158
1309
|
const amountInBigInt = BigInt(amountIn);
|
|
@@ -1185,6 +1336,9 @@ var METH_TOKEN = {
|
|
|
1185
1336
|
|
|
1186
1337
|
// src/tools/okx/getSwapQuote.ts
|
|
1187
1338
|
var getSwapQuote = async (agent, from, to, amount, slippagePercentage) => {
|
|
1339
|
+
if (agent.demo) {
|
|
1340
|
+
return createMockQuoteResponse("OKX", amount);
|
|
1341
|
+
}
|
|
1188
1342
|
const chainIndex = agent.chain === "mainnet" ? "5000" : "5003";
|
|
1189
1343
|
return getSwapTransaction(from, to, amount, chainIndex, slippagePercentage);
|
|
1190
1344
|
};
|
|
@@ -1271,21 +1425,21 @@ function getProjectConfig() {
|
|
|
1271
1425
|
}
|
|
1272
1426
|
return cachedConfig;
|
|
1273
1427
|
}
|
|
1274
|
-
|
|
1275
|
-
// src/agent.ts
|
|
1276
1428
|
var MNTAgentKit = class {
|
|
1277
1429
|
account;
|
|
1278
1430
|
client;
|
|
1279
1431
|
chain;
|
|
1432
|
+
demo;
|
|
1280
1433
|
projectConfig;
|
|
1281
1434
|
constructor(privateKey, chain) {
|
|
1282
1435
|
this.account = privateKeyToAccount(privateKey);
|
|
1283
|
-
this.
|
|
1436
|
+
this.demo = chain === "testnet-demo";
|
|
1437
|
+
this.chain = chain === "testnet-demo" ? "testnet" : chain;
|
|
1284
1438
|
this.client = createWalletClient({
|
|
1285
|
-
chain: chain == "mainnet" ? mantle : mantleSepoliaTestnet,
|
|
1439
|
+
chain: this.chain == "mainnet" ? mantle : mantleSepoliaTestnet,
|
|
1286
1440
|
transport: http(),
|
|
1287
1441
|
account: this.account
|
|
1288
|
-
}).extend(publicActions);
|
|
1442
|
+
}).extend(publicActions).extend(erc7811Actions());
|
|
1289
1443
|
}
|
|
1290
1444
|
/**
|
|
1291
1445
|
* Initialize the agent with platform validation
|
|
@@ -1320,15 +1474,13 @@ var MNTAgentKit = class {
|
|
|
1320
1474
|
);
|
|
1321
1475
|
}
|
|
1322
1476
|
async executeSwap(fromTokenAddress, toTokenAddress, amount, slippagePercentage = "0.5") {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
);
|
|
1331
|
-
}
|
|
1477
|
+
return await executeSwap(
|
|
1478
|
+
this,
|
|
1479
|
+
fromTokenAddress,
|
|
1480
|
+
toTokenAddress,
|
|
1481
|
+
amount,
|
|
1482
|
+
slippagePercentage
|
|
1483
|
+
);
|
|
1332
1484
|
}
|
|
1333
1485
|
// OpenOcean DEX Aggregator
|
|
1334
1486
|
async getOpenOceanQuote(fromToken, toToken, amount) {
|
|
@@ -1411,6 +1563,9 @@ var MNTAgentKit = class {
|
|
|
1411
1563
|
}
|
|
1412
1564
|
// mETH Protocol - Liquid Staking Token
|
|
1413
1565
|
getMethTokenAddress() {
|
|
1566
|
+
if (this.demo) {
|
|
1567
|
+
return METH_TOKEN.mainnet;
|
|
1568
|
+
}
|
|
1414
1569
|
return METH_TOKEN[this.chain];
|
|
1415
1570
|
}
|
|
1416
1571
|
// Squid Router Cross-chain
|