@coinbase/agentkit 0.1.0 → 0.1.2
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 +27 -7
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.d.ts +55 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.js +173 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.d.ts +1 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.js +131 -0
- package/dist/action-providers/alchemy/index.d.ts +2 -0
- package/dist/action-providers/alchemy/index.js +18 -0
- package/dist/action-providers/alchemy/schemas.d.ts +41 -0
- package/dist/action-providers/alchemy/schemas.js +34 -0
- package/dist/action-providers/basename/basenameActionProvider.d.ts +1 -1
- package/dist/action-providers/cdp/cdpApiActionProvider.js +7 -1
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +1 -1
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +1 -1
- package/dist/action-providers/index.d.ts +2 -0
- package/dist/action-providers/index.js +2 -0
- package/dist/action-providers/moonwell/constants.d.ts +78 -0
- package/dist/action-providers/moonwell/constants.js +111 -0
- package/dist/action-providers/moonwell/index.d.ts +1 -0
- package/dist/action-providers/moonwell/index.js +5 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.d.ts +39 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.js +249 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.d.ts +1 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.js +455 -0
- package/dist/action-providers/moonwell/schemas.d.ts +30 -0
- package/dist/action-providers/moonwell/schemas.js +39 -0
- package/dist/action-providers/morpho/morphoActionProvider.d.ts +1 -1
- package/dist/action-providers/pyth/pythActionProvider.test.d.ts +1 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +113 -0
- package/dist/action-providers/weth/wethActionProvider.d.ts +1 -1
- package/dist/action-providers/wow/wowActionProvider.d.ts +1 -1
- package/dist/agentkit.d.ts +1 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -4
- package/dist/network/index.d.ts +1 -0
- package/dist/network/index.js +1 -0
- package/dist/wallet-providers/cdpWalletProvider.js +17 -1
- package/dist/wallet-providers/viemWalletProvider.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare const MOONWELL_BASE_ADDRESSES: {
|
|
2
|
+
"0xEdc817A28E8B93B03976FBd4a3dDBc9f7D176c22": string;
|
|
3
|
+
"0x73b06D8d18De422E269645eaCe15400DE7462417": string;
|
|
4
|
+
"0x628ff693426583D9a7FB391E54366292F509D457": string;
|
|
5
|
+
"0x3bf93770f2d4a794c3d9EBEfBAeBAE2a8f09A5E5": string;
|
|
6
|
+
"0x627Fe393Bc6EdDA28e99AE648fD6fF362514304b": string;
|
|
7
|
+
"0x73902f619CEB9B31FD8EFecf435CbDf89E369Ba6": string;
|
|
8
|
+
"0xb8051464C8c92209C92F3a4CD9C73746C4c3CFb3": string;
|
|
9
|
+
"0xF877ACaFA28c19b96727966690b2f44d35aD5976": string;
|
|
10
|
+
"0xb682c840B5F4FC58B20769E691A6fa1305A501a2": string;
|
|
11
|
+
"0xfC41B49d064Ac646015b459C522820DB9472F4B5": string;
|
|
12
|
+
"0xdC7810B47eAAb250De623F0eE07764afa5F71ED1": string;
|
|
13
|
+
"0xb6419c6C2e60c4025D6D06eE4F913ce89425a357": string;
|
|
14
|
+
"0x9A858ebfF1bEb0D3495BB0e2897c1528eD84A218": string;
|
|
15
|
+
"0x70778cfcFC475c7eA0f24cC625Baf6EaE475D0c9": string;
|
|
16
|
+
};
|
|
17
|
+
export declare const MOONWELL_BASE_SEPOLIA_ADDRESSES: {
|
|
18
|
+
"0x876852425331a113d8E432eFFB3aC5BEf38f033a": string;
|
|
19
|
+
"0x5302EbD8BC32435C823c2e22B04Cd6c45f593e89": string;
|
|
20
|
+
"0x2F39a349A79492a70E152760ce7123A1933eCf28": string;
|
|
21
|
+
};
|
|
22
|
+
export declare const WETH_ROUTER_ADDRESS = "0x70778cfcFC475c7eA0f24cC625Baf6EaE475D0c9";
|
|
23
|
+
export declare const TOKEN_DECIMALS: {
|
|
24
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913": number;
|
|
25
|
+
"0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42": number;
|
|
26
|
+
"0x04C0599Ae5A44757c0af6F9eC3b93da8976c150A": number;
|
|
27
|
+
"0xEDfa23602D0EC14714057867A78d01e94176BEA0": number;
|
|
28
|
+
"0x236aa50979D5f3De3Bd1Eeb40E81137F22ab794b": number;
|
|
29
|
+
"0xA88594D404727625A9437C3f886C7643872296AE": number;
|
|
30
|
+
"0x820C137fa70C8691f0e44Dc420a5e53c168921Dc": number;
|
|
31
|
+
"0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb": number;
|
|
32
|
+
"0x4200000000000000000000000000000000000006": number;
|
|
33
|
+
"0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22": number;
|
|
34
|
+
"0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452": number;
|
|
35
|
+
"0x940181a94a35a4569e4529a3cdfb74e38fd98631": number;
|
|
36
|
+
"0x0000000000000000000000000000000000000000": number;
|
|
37
|
+
};
|
|
38
|
+
export declare const MTOKENS_UNDERLYING_DECIMALS: {
|
|
39
|
+
MOONWELL_USDC: number;
|
|
40
|
+
MOONWELL_DAI: number;
|
|
41
|
+
MOONWELL_WETH: number;
|
|
42
|
+
MOONWELL_cbETH: number;
|
|
43
|
+
MOONWELL_wstETH: number;
|
|
44
|
+
MOONWELL_AERO: number;
|
|
45
|
+
MOONWELL_weETH: number;
|
|
46
|
+
MOONWELL_cbBTC: number;
|
|
47
|
+
MOONWELL_EURC: number;
|
|
48
|
+
MOONWELL_wrsETH: number;
|
|
49
|
+
MOONWELL_WELL: number;
|
|
50
|
+
MOONWELL_USDS: number;
|
|
51
|
+
MOONWELL_TBTC: number;
|
|
52
|
+
};
|
|
53
|
+
export declare const ETH_ROUTER_ABI: {
|
|
54
|
+
name: string;
|
|
55
|
+
inputs: {
|
|
56
|
+
internalType: string;
|
|
57
|
+
name: string;
|
|
58
|
+
type: string;
|
|
59
|
+
}[];
|
|
60
|
+
outputs: never[];
|
|
61
|
+
stateMutability: string;
|
|
62
|
+
type: string;
|
|
63
|
+
}[];
|
|
64
|
+
export declare const MTOKEN_ABI: {
|
|
65
|
+
type: string;
|
|
66
|
+
name: string;
|
|
67
|
+
inputs: {
|
|
68
|
+
name: string;
|
|
69
|
+
type: string;
|
|
70
|
+
internalType: string;
|
|
71
|
+
}[];
|
|
72
|
+
outputs: {
|
|
73
|
+
name: string;
|
|
74
|
+
type: string;
|
|
75
|
+
internalType: string;
|
|
76
|
+
}[];
|
|
77
|
+
stateMutability: string;
|
|
78
|
+
}[];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MTOKEN_ABI = exports.ETH_ROUTER_ABI = exports.MTOKENS_UNDERLYING_DECIMALS = exports.TOKEN_DECIMALS = exports.WETH_ROUTER_ADDRESS = exports.MOONWELL_BASE_SEPOLIA_ADDRESSES = exports.MOONWELL_BASE_ADDRESSES = void 0;
|
|
4
|
+
exports.MOONWELL_BASE_ADDRESSES = {
|
|
5
|
+
"0xEdc817A28E8B93B03976FBd4a3dDBc9f7D176c22": "MOONWELL_USDC",
|
|
6
|
+
"0x73b06D8d18De422E269645eaCe15400DE7462417": "MOONWELL_DAI",
|
|
7
|
+
"0x628ff693426583D9a7FB391E54366292F509D457": "MOONWELL_WETH",
|
|
8
|
+
"0x3bf93770f2d4a794c3d9EBEfBAeBAE2a8f09A5E5": "MOONWELL_cbETH",
|
|
9
|
+
"0x627Fe393Bc6EdDA28e99AE648fD6fF362514304b": "MOONWELL_wstETH",
|
|
10
|
+
"0x73902f619CEB9B31FD8EFecf435CbDf89E369Ba6": "MOONWELL_AERO",
|
|
11
|
+
"0xb8051464C8c92209C92F3a4CD9C73746C4c3CFb3": "MOONWELL_weETH",
|
|
12
|
+
"0xF877ACaFA28c19b96727966690b2f44d35aD5976": "MOONWELL_cbBTC",
|
|
13
|
+
"0xb682c840B5F4FC58B20769E691A6fa1305A501a2": "MOONWELL_EURC",
|
|
14
|
+
"0xfC41B49d064Ac646015b459C522820DB9472F4B5": "MOONWELL_wrsETH",
|
|
15
|
+
"0xdC7810B47eAAb250De623F0eE07764afa5F71ED1": "MOONWELL_WELL",
|
|
16
|
+
"0xb6419c6C2e60c4025D6D06eE4F913ce89425a357": "MOONWELL_USDS",
|
|
17
|
+
"0x9A858ebfF1bEb0D3495BB0e2897c1528eD84A218": "MOONWELL_TBTC",
|
|
18
|
+
"0x70778cfcFC475c7eA0f24cC625Baf6EaE475D0c9": "WETH_ROUTER",
|
|
19
|
+
};
|
|
20
|
+
exports.MOONWELL_BASE_SEPOLIA_ADDRESSES = {
|
|
21
|
+
"0x876852425331a113d8E432eFFB3aC5BEf38f033a": "MOONWELL_USDBC",
|
|
22
|
+
"0x5302EbD8BC32435C823c2e22B04Cd6c45f593e89": "MOONWELL_cbETH",
|
|
23
|
+
"0x2F39a349A79492a70E152760ce7123A1933eCf28": "MOONWELL_WETH",
|
|
24
|
+
};
|
|
25
|
+
exports.WETH_ROUTER_ADDRESS = "0x70778cfcFC475c7eA0f24cC625Baf6EaE475D0c9";
|
|
26
|
+
// Token decimals mapping
|
|
27
|
+
exports.TOKEN_DECIMALS = {
|
|
28
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913": 6, // USDC
|
|
29
|
+
"0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42": 6, // EURC
|
|
30
|
+
"0x04C0599Ae5A44757c0af6F9eC3b93da8976c150A": 18, // weETH
|
|
31
|
+
"0xEDfa23602D0EC14714057867A78d01e94176BEA0": 18, // wrsETH
|
|
32
|
+
"0x236aa50979D5f3De3Bd1Eeb40E81137F22ab794b": 18, // tBTC
|
|
33
|
+
"0xA88594D404727625A9437C3f886C7643872296AE": 18, // WELL
|
|
34
|
+
"0x820C137fa70C8691f0e44Dc420a5e53c168921Dc": 18, // USDS
|
|
35
|
+
"0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb": 18, // DAI
|
|
36
|
+
"0x4200000000000000000000000000000000000006": 18, // WETH
|
|
37
|
+
"0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22": 18, // cbETH
|
|
38
|
+
"0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452": 18, // wstETH
|
|
39
|
+
"0x940181a94a35a4569e4529a3cdfb74e38fd98631": 18, // AERO
|
|
40
|
+
"0x0000000000000000000000000000000000000000": 18, // ETH (native)
|
|
41
|
+
};
|
|
42
|
+
exports.MTOKENS_UNDERLYING_DECIMALS = {
|
|
43
|
+
MOONWELL_USDC: 6,
|
|
44
|
+
MOONWELL_DAI: 18,
|
|
45
|
+
MOONWELL_WETH: 18,
|
|
46
|
+
MOONWELL_cbETH: 18,
|
|
47
|
+
MOONWELL_wstETH: 18,
|
|
48
|
+
MOONWELL_AERO: 18,
|
|
49
|
+
MOONWELL_weETH: 18,
|
|
50
|
+
MOONWELL_cbBTC: 18,
|
|
51
|
+
MOONWELL_EURC: 6,
|
|
52
|
+
MOONWELL_wrsETH: 18,
|
|
53
|
+
MOONWELL_WELL: 18,
|
|
54
|
+
MOONWELL_USDS: 18,
|
|
55
|
+
MOONWELL_TBTC: 18,
|
|
56
|
+
};
|
|
57
|
+
exports.ETH_ROUTER_ABI = [
|
|
58
|
+
{
|
|
59
|
+
name: "mint",
|
|
60
|
+
inputs: [
|
|
61
|
+
{
|
|
62
|
+
internalType: "address",
|
|
63
|
+
name: "receiver",
|
|
64
|
+
type: "address",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
outputs: [],
|
|
68
|
+
stateMutability: "payable",
|
|
69
|
+
type: "function",
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
exports.MTOKEN_ABI = [
|
|
73
|
+
{
|
|
74
|
+
type: "function",
|
|
75
|
+
name: "mint",
|
|
76
|
+
inputs: [
|
|
77
|
+
{
|
|
78
|
+
name: "mintAmount",
|
|
79
|
+
type: "uint256",
|
|
80
|
+
internalType: "uint256",
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
outputs: [
|
|
84
|
+
{
|
|
85
|
+
name: "",
|
|
86
|
+
type: "uint256",
|
|
87
|
+
internalType: "uint256",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
stateMutability: "nonpayable",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: "function",
|
|
94
|
+
name: "redeemUnderlying",
|
|
95
|
+
inputs: [
|
|
96
|
+
{
|
|
97
|
+
name: "redeemAmount",
|
|
98
|
+
type: "uint256",
|
|
99
|
+
internalType: "uint256",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
outputs: [
|
|
103
|
+
{
|
|
104
|
+
name: "",
|
|
105
|
+
type: "uint256",
|
|
106
|
+
internalType: "uint256",
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
stateMutability: "nonpayable",
|
|
110
|
+
},
|
|
111
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { moonwellActionProvider } from "./moonwellActionProvider";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moonwellActionProvider = void 0;
|
|
4
|
+
var moonwellActionProvider_1 = require("./moonwellActionProvider");
|
|
5
|
+
Object.defineProperty(exports, "moonwellActionProvider", { enumerable: true, get: function () { return moonwellActionProvider_1.moonwellActionProvider; } });
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
4
|
+
import { MintSchema, RedeemSchema } from "./schemas";
|
|
5
|
+
import { Network } from "../../network";
|
|
6
|
+
export declare const SUPPORTED_NETWORKS: string[];
|
|
7
|
+
/**
|
|
8
|
+
* MoonwellActionProvider is an action provider for Moonwell MToken interactions.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MoonwellActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
11
|
+
/**
|
|
12
|
+
* Constructor for the MoonwellActionProvider class.
|
|
13
|
+
*/
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Deposits assets into a Moonwell MToken
|
|
17
|
+
*
|
|
18
|
+
* @param wallet - The wallet instance to execute the transaction
|
|
19
|
+
* @param args - The input arguments for the action
|
|
20
|
+
* @returns A success message with transaction details or an error message
|
|
21
|
+
*/
|
|
22
|
+
mint(wallet: EvmWalletProvider, args: z.infer<typeof MintSchema>): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Redeems assets from a Moonwell MToken
|
|
25
|
+
*
|
|
26
|
+
* @param wallet - The wallet instance to execute the transaction
|
|
27
|
+
* @param args - The input arguments for the action
|
|
28
|
+
* @returns A success message with transaction details or an error message
|
|
29
|
+
*/
|
|
30
|
+
redeem(wallet: EvmWalletProvider, args: z.infer<typeof RedeemSchema>): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the Moonwell action provider supports the given network.
|
|
33
|
+
*
|
|
34
|
+
* @param network - The network to check.
|
|
35
|
+
* @returns True if the Moonwell action provider supports the network, false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
supportsNetwork: (network: Network) => boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare const moonwellActionProvider: () => MoonwellActionProvider;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.moonwellActionProvider = exports.MoonwellActionProvider = exports.SUPPORTED_NETWORKS = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const decimal_js_1 = require("decimal.js");
|
|
15
|
+
const viem_1 = require("viem");
|
|
16
|
+
const actionProvider_1 = require("../actionProvider");
|
|
17
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
18
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
19
|
+
const utils_1 = require("../../utils");
|
|
20
|
+
const constants_1 = require("./constants");
|
|
21
|
+
const schemas_1 = require("./schemas");
|
|
22
|
+
exports.SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
|
|
23
|
+
/**
|
|
24
|
+
* MoonwellActionProvider is an action provider for Moonwell MToken interactions.
|
|
25
|
+
*/
|
|
26
|
+
class MoonwellActionProvider extends actionProvider_1.ActionProvider {
|
|
27
|
+
/**
|
|
28
|
+
* Constructor for the MoonwellActionProvider class.
|
|
29
|
+
*/
|
|
30
|
+
constructor() {
|
|
31
|
+
super("moonwell", []);
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the Moonwell action provider supports the given network.
|
|
34
|
+
*
|
|
35
|
+
* @param network - The network to check.
|
|
36
|
+
* @returns True if the Moonwell action provider supports the network, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
this.supportsNetwork = (network) => network.protocolFamily === "evm" && exports.SUPPORTED_NETWORKS.includes(network.networkId);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Deposits assets into a Moonwell MToken
|
|
42
|
+
*
|
|
43
|
+
* @param wallet - The wallet instance to execute the transaction
|
|
44
|
+
* @param args - The input arguments for the action
|
|
45
|
+
* @returns A success message with transaction details or an error message
|
|
46
|
+
*/
|
|
47
|
+
async mint(wallet, args) {
|
|
48
|
+
const assets = new decimal_js_1.Decimal(args.assets);
|
|
49
|
+
if (assets.comparedTo(new decimal_js_1.Decimal(0.0)) != 1) {
|
|
50
|
+
return "Error: Assets amount must be greater than 0";
|
|
51
|
+
}
|
|
52
|
+
const network = wallet.getNetwork();
|
|
53
|
+
const networkObject = network.networkId === "base-mainnet"
|
|
54
|
+
? constants_1.MOONWELL_BASE_ADDRESSES
|
|
55
|
+
: constants_1.MOONWELL_BASE_SEPOLIA_ADDRESSES;
|
|
56
|
+
if (!networkObject[args.mTokenAddress]) {
|
|
57
|
+
return "Error: Invalid MToken address";
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
// Handle different token decimals
|
|
61
|
+
let atomicAssets;
|
|
62
|
+
const userAddress = wallet.getAddress();
|
|
63
|
+
if (network.networkId === "base-mainnet" &&
|
|
64
|
+
"MOONWELL_WETH" === networkObject[args.mTokenAddress]) {
|
|
65
|
+
// For ETH minting, use parseEther (18 decimals)
|
|
66
|
+
atomicAssets = (0, viem_1.parseEther)(args.assets);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// For other tokens, use the correct decimals
|
|
70
|
+
const decimals = constants_1.TOKEN_DECIMALS[args.tokenAddress];
|
|
71
|
+
if (!decimals) {
|
|
72
|
+
return `Error: Unsupported token address ${args.tokenAddress}. Please verify the token address is correct.`;
|
|
73
|
+
}
|
|
74
|
+
atomicAssets = (0, viem_1.parseUnits)(args.assets, decimals);
|
|
75
|
+
}
|
|
76
|
+
// Check if this is a WETH mint on mainnet
|
|
77
|
+
if (network.networkId === "base-mainnet" &&
|
|
78
|
+
"MOONWELL_WETH" === networkObject[args.mTokenAddress]) {
|
|
79
|
+
// Use the router for ETH mints - no approval needed since we're sending native ETH
|
|
80
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
81
|
+
abi: constants_1.ETH_ROUTER_ABI,
|
|
82
|
+
functionName: "mint",
|
|
83
|
+
args: [userAddress],
|
|
84
|
+
});
|
|
85
|
+
const txHash = await wallet.sendTransaction({
|
|
86
|
+
to: constants_1.WETH_ROUTER_ADDRESS,
|
|
87
|
+
data,
|
|
88
|
+
value: atomicAssets,
|
|
89
|
+
});
|
|
90
|
+
const receipt = await wallet.waitForTransactionReceipt(txHash);
|
|
91
|
+
return `Deposited ${args.assets} ETH to Moonwell WETH via router with transaction hash: ${txHash}\nTransaction receipt: ${JSON.stringify(receipt, (_, value) => (typeof value === "bigint" ? value.toString() : value))}`;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// For all other tokens, we need approval first
|
|
95
|
+
const approvalResult = await (0, utils_1.approve)(wallet, args.tokenAddress, args.mTokenAddress, atomicAssets);
|
|
96
|
+
if (approvalResult.startsWith("Error")) {
|
|
97
|
+
return `Error approving Moonwell MToken as spender: ${approvalResult}`;
|
|
98
|
+
}
|
|
99
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
100
|
+
abi: constants_1.MTOKEN_ABI,
|
|
101
|
+
functionName: "mint",
|
|
102
|
+
args: [atomicAssets],
|
|
103
|
+
});
|
|
104
|
+
const txHash = await wallet.sendTransaction({
|
|
105
|
+
to: args.mTokenAddress,
|
|
106
|
+
data,
|
|
107
|
+
value: 0n,
|
|
108
|
+
});
|
|
109
|
+
const receipt = await wallet.waitForTransactionReceipt(txHash);
|
|
110
|
+
if (!receipt) {
|
|
111
|
+
throw new Error("No receipt received for mint transaction");
|
|
112
|
+
}
|
|
113
|
+
if (receipt.status !== "success") {
|
|
114
|
+
throw new Error(`Mint transaction failed with status ${receipt.status}`);
|
|
115
|
+
}
|
|
116
|
+
return `Deposited ${args.assets} to Moonwell MToken ${args.mTokenAddress} with transaction hash: ${txHash}\nTransaction receipt: ${JSON.stringify(receipt, (_, value) => (typeof value === "bigint" ? value.toString() : value))}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error("DEBUG - Mint error:", error);
|
|
121
|
+
if (error instanceof Error) {
|
|
122
|
+
return `Error minting Moonwell MToken: ${error.message}`;
|
|
123
|
+
}
|
|
124
|
+
return `Error minting Moonwell MToken: ${error}`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Redeems assets from a Moonwell MToken
|
|
129
|
+
*
|
|
130
|
+
* @param wallet - The wallet instance to execute the transaction
|
|
131
|
+
* @param args - The input arguments for the action
|
|
132
|
+
* @returns A success message with transaction details or an error message
|
|
133
|
+
*/
|
|
134
|
+
async redeem(wallet, args) {
|
|
135
|
+
const assets = new decimal_js_1.Decimal(args.assets);
|
|
136
|
+
if (assets.comparedTo(new decimal_js_1.Decimal(0.0)) != 1) {
|
|
137
|
+
return "Error: Assets amount must be greater than 0";
|
|
138
|
+
}
|
|
139
|
+
const network = wallet.getNetwork();
|
|
140
|
+
const networkObject = network.networkId === "base-mainnet"
|
|
141
|
+
? constants_1.MOONWELL_BASE_ADDRESSES
|
|
142
|
+
: constants_1.MOONWELL_BASE_SEPOLIA_ADDRESSES;
|
|
143
|
+
if (!networkObject[args.mTokenAddress]) {
|
|
144
|
+
return "Error: Invalid MToken address";
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
// Handle different token decimals
|
|
148
|
+
const decimals = constants_1.MTOKENS_UNDERLYING_DECIMALS[constants_1.MOONWELL_BASE_ADDRESSES[args.mTokenAddress]];
|
|
149
|
+
if (!decimals) {
|
|
150
|
+
return `Error: Unsupported token address ${args.mTokenAddress}. Please verify the token address is correct.`;
|
|
151
|
+
}
|
|
152
|
+
const atomicAssets = (0, viem_1.parseUnits)(args.assets, decimals);
|
|
153
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
154
|
+
abi: constants_1.MTOKEN_ABI,
|
|
155
|
+
functionName: "redeemUnderlying",
|
|
156
|
+
args: [atomicAssets],
|
|
157
|
+
});
|
|
158
|
+
const txHash = await wallet.sendTransaction({
|
|
159
|
+
to: args.mTokenAddress,
|
|
160
|
+
data,
|
|
161
|
+
value: 0n,
|
|
162
|
+
});
|
|
163
|
+
const receipt = await wallet.waitForTransactionReceipt(txHash);
|
|
164
|
+
if (!receipt) {
|
|
165
|
+
throw new Error("No receipt received for redeem transaction");
|
|
166
|
+
}
|
|
167
|
+
if (receipt.status !== "success") {
|
|
168
|
+
throw new Error(`Redeem transaction failed with status ${receipt.status}`);
|
|
169
|
+
}
|
|
170
|
+
return `Redeemed ${args.assets} from Moonwell MToken ${args.mTokenAddress} with transaction hash: ${txHash}\nTransaction receipt: ${JSON.stringify(receipt, (_, value) => (typeof value === "bigint" ? value.toString() : value))}`;
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error("DEBUG - Redeem error:", error);
|
|
174
|
+
if (error instanceof Error) {
|
|
175
|
+
return `Error redeeming from Moonwell MToken: ${error.message}`;
|
|
176
|
+
}
|
|
177
|
+
return `Error redeeming from Moonwell MToken: ${error}`;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.MoonwellActionProvider = MoonwellActionProvider;
|
|
182
|
+
__decorate([
|
|
183
|
+
(0, actionDecorator_1.CreateAction)({
|
|
184
|
+
name: "mint",
|
|
185
|
+
description: `
|
|
186
|
+
This tool allows minting assets into a Moonwell MToken.
|
|
187
|
+
|
|
188
|
+
It takes:
|
|
189
|
+
- mTokenAddress: The address of the Moonwell MToken to mint to
|
|
190
|
+
- assets: The amount of assets that will be approved to spend by the mToken in whole units
|
|
191
|
+
Examples for WETH:
|
|
192
|
+
- 1 WETH
|
|
193
|
+
- 0.1 WETH
|
|
194
|
+
- 0.01 WETH
|
|
195
|
+
Examples for cbETH:
|
|
196
|
+
- 1 cbETH
|
|
197
|
+
- 0.1 cbETH
|
|
198
|
+
- 0.01 cbETH
|
|
199
|
+
Examples for USDC:
|
|
200
|
+
- 1 USDC
|
|
201
|
+
- 0.1 USDC
|
|
202
|
+
- 0.01 USDC
|
|
203
|
+
- tokenAddress: The address of the token to approve
|
|
204
|
+
|
|
205
|
+
Important notes:
|
|
206
|
+
- Make sure to use the exact amount provided. Do not convert units for assets for this action.
|
|
207
|
+
- Please use a token address (example 0x4200000000000000000000000000000000000006) for the tokenAddress field.
|
|
208
|
+
- This tool handles token approval. If requested to mint on Moonwell, do not use any other actions to approve tokens.
|
|
209
|
+
`,
|
|
210
|
+
schema: schemas_1.MintSchema,
|
|
211
|
+
}),
|
|
212
|
+
__metadata("design:type", Function),
|
|
213
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
214
|
+
__metadata("design:returntype", Promise)
|
|
215
|
+
], MoonwellActionProvider.prototype, "mint", null);
|
|
216
|
+
__decorate([
|
|
217
|
+
(0, actionDecorator_1.CreateAction)({
|
|
218
|
+
name: "redeem",
|
|
219
|
+
description: `
|
|
220
|
+
This tool allows redeeming assets from a Moonwell MToken.
|
|
221
|
+
|
|
222
|
+
It takes:
|
|
223
|
+
- mTokenAddress: The address of the Moonwell MToken to redeem from
|
|
224
|
+
- assets: The amount of assets to redeem in whole units
|
|
225
|
+
Examples for WETH:
|
|
226
|
+
- 1 WETH
|
|
227
|
+
- 0.1 WETH
|
|
228
|
+
- 0.01 WETH
|
|
229
|
+
Examples for cbETH:
|
|
230
|
+
- 1 cbETH
|
|
231
|
+
- 0.1 cbETH
|
|
232
|
+
- 0.01 cbETH
|
|
233
|
+
Examples for USDC:
|
|
234
|
+
- 1 USDC
|
|
235
|
+
- 0.1 USDC
|
|
236
|
+
- 0.01 USDC
|
|
237
|
+
|
|
238
|
+
Important notes:
|
|
239
|
+
- Make sure to use the exact amount provided. Do not convert units for assets for this action.
|
|
240
|
+
- Please use a token address (example 0x4200000000000000000000000000000000000006) for the tokenAddress field.
|
|
241
|
+
`,
|
|
242
|
+
schema: schemas_1.RedeemSchema,
|
|
243
|
+
}),
|
|
244
|
+
__metadata("design:type", Function),
|
|
245
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
246
|
+
__metadata("design:returntype", Promise)
|
|
247
|
+
], MoonwellActionProvider.prototype, "redeem", null);
|
|
248
|
+
const moonwellActionProvider = () => new MoonwellActionProvider();
|
|
249
|
+
exports.moonwellActionProvider = moonwellActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|