@coinbase/agentkit 0.2.3-nightly.20250227.18 → 0.2.3-nightly.20250227.20

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.
@@ -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("./compoundActionProvider"), exports);
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Input schema for Compound supply action.
4
+ */
5
+ export declare const CompoundSupplySchema: z.ZodObject<{
6
+ assetId: z.ZodEnum<["weth", "cbeth", "cbbtc", "wsteth", "usdc"]>;
7
+ amount: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ amount: string;
10
+ assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
11
+ }, {
12
+ amount: string;
13
+ assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
14
+ }>;
15
+ /**
16
+ * Input schema for Compound withdraw action.
17
+ */
18
+ export declare const CompoundWithdrawSchema: z.ZodObject<{
19
+ assetId: z.ZodEnum<["weth", "cbeth", "cbbtc", "wsteth", "usdc"]>;
20
+ amount: z.ZodString;
21
+ }, "strip", z.ZodTypeAny, {
22
+ amount: string;
23
+ assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
24
+ }, {
25
+ amount: string;
26
+ assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
27
+ }>;
28
+ /**
29
+ * Input schema for Compound borrow action.
30
+ */
31
+ export declare const CompoundBorrowSchema: z.ZodObject<{
32
+ assetId: z.ZodEnum<["weth", "usdc"]>;
33
+ amount: z.ZodString;
34
+ }, "strip", z.ZodTypeAny, {
35
+ amount: string;
36
+ assetId: "weth" | "usdc";
37
+ }, {
38
+ amount: string;
39
+ assetId: "weth" | "usdc";
40
+ }>;
41
+ /**
42
+ * Input schema for Compound repay action.
43
+ */
44
+ export declare const CompoundRepaySchema: z.ZodObject<{
45
+ assetId: z.ZodEnum<["weth", "usdc"]>;
46
+ amount: z.ZodString;
47
+ }, "strip", z.ZodTypeAny, {
48
+ amount: string;
49
+ assetId: "weth" | "usdc";
50
+ }, {
51
+ amount: string;
52
+ assetId: "weth" | "usdc";
53
+ }>;
54
+ /**
55
+ * Input schema for Compound get portfolio action.
56
+ */
57
+ export declare const CompoundPortfolioSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompoundPortfolioSchema = exports.CompoundRepaySchema = exports.CompoundBorrowSchema = exports.CompoundWithdrawSchema = exports.CompoundSupplySchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Input schema for Compound supply action.
7
+ */
8
+ exports.CompoundSupplySchema = zod_1.z
9
+ .object({
10
+ assetId: zod_1.z.enum(["weth", "cbeth", "cbbtc", "wsteth", "usdc"]).describe("The asset to supply"),
11
+ amount: zod_1.z
12
+ .string()
13
+ .regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
14
+ .describe("The amount of tokens to supply in human-readable format"),
15
+ })
16
+ .describe("Input schema for Compound supply action");
17
+ /**
18
+ * Input schema for Compound withdraw action.
19
+ */
20
+ exports.CompoundWithdrawSchema = zod_1.z
21
+ .object({
22
+ assetId: zod_1.z.enum(["weth", "cbeth", "cbbtc", "wsteth", "usdc"]).describe("The asset to withdraw"),
23
+ amount: zod_1.z
24
+ .string()
25
+ .regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
26
+ .describe("The amount of tokens to withdraw in human-readable format"),
27
+ })
28
+ .describe("Input schema for Compound withdraw action");
29
+ /**
30
+ * Input schema for Compound borrow action.
31
+ */
32
+ exports.CompoundBorrowSchema = zod_1.z
33
+ .object({
34
+ assetId: zod_1.z.enum(["weth", "usdc"]).describe("The asset to borrow"),
35
+ amount: zod_1.z
36
+ .string()
37
+ .regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
38
+ .describe("The amount of base tokens to borrow in human-readable format"),
39
+ })
40
+ .describe("Input schema for Compound borrow action");
41
+ /**
42
+ * Input schema for Compound repay action.
43
+ */
44
+ exports.CompoundRepaySchema = zod_1.z
45
+ .object({
46
+ assetId: zod_1.z.enum(["weth", "usdc"]).describe("The asset to repay"),
47
+ amount: zod_1.z
48
+ .string()
49
+ .regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
50
+ .describe("The amount of tokens to repay in human-readable format"),
51
+ })
52
+ .describe("Input schema for Compound repay action");
53
+ /**
54
+ * Input schema for Compound get portfolio action.
55
+ */
56
+ exports.CompoundPortfolioSchema = zod_1.z
57
+ .object({})
58
+ .describe("Input schema for Compound get portfolio action");
@@ -0,0 +1,95 @@
1
+ import { Decimal } from "decimal.js";
2
+ import { Address } from "viem";
3
+ import { EvmWalletProvider } from "../../wallet-providers";
4
+ import { Network } from "../../network";
5
+ /**
6
+ * Get token decimals from contract
7
+ *
8
+ * @param wallet - The wallet provider instance
9
+ * @param tokenAddress - The address of the token contract
10
+ * @returns The number of decimals for the token
11
+ */
12
+ export declare const getTokenDecimals: (wallet: EvmWalletProvider, tokenAddress: Address) => Promise<number>;
13
+ /**
14
+ * Get token symbol from contract
15
+ *
16
+ * @param wallet - The wallet provider instance
17
+ * @param tokenAddress - The address of the token contract
18
+ * @returns The symbol of the token
19
+ */
20
+ export declare const getTokenSymbol: (wallet: EvmWalletProvider, tokenAddress: Address) => Promise<string>;
21
+ /**
22
+ * Get token balance for an address
23
+ *
24
+ * @param wallet - The wallet provider instance
25
+ * @param tokenAddress - The address of the token contract
26
+ * @returns The token balance as a bigint
27
+ */
28
+ export declare const getTokenBalance: (wallet: EvmWalletProvider, tokenAddress: Address) => Promise<bigint>;
29
+ /**
30
+ * Get collateral balance for an address
31
+ *
32
+ * @param wallet - The wallet provider instance
33
+ * @param cometAddress - The address of the Comet contract
34
+ * @param tokenAddress - The address of the token contract
35
+ * @returns The collateral balance as a bigint
36
+ */
37
+ export declare const getCollateralBalance: (wallet: EvmWalletProvider, cometAddress: Address, tokenAddress: Address) => Promise<bigint>;
38
+ /**
39
+ * Get health ratio for an account
40
+ *
41
+ * @param wallet - The wallet provider instance
42
+ * @param cometAddress - The address of the Comet contract
43
+ * @returns The health ratio as a Decimal
44
+ */
45
+ export declare const getHealthRatio: (wallet: EvmWalletProvider, cometAddress: Address) => Promise<Decimal>;
46
+ /**
47
+ * Get health ratio after a hypothetical withdraw
48
+ *
49
+ * @param wallet - The wallet provider instance
50
+ * @param cometAddress - The address of the Comet contract
51
+ * @param tokenAddress - The address of the token contract
52
+ * @param amount - The amount to withdraw
53
+ * @returns The health ratio after withdraw as a Decimal
54
+ */
55
+ export declare const getHealthRatioAfterWithdraw: (wallet: EvmWalletProvider, cometAddress: Address, tokenAddress: Address, amount: bigint) => Promise<Decimal>;
56
+ /**
57
+ * Get health ratio after a hypothetical borrow
58
+ *
59
+ * @param wallet - The wallet provider instance
60
+ * @param cometAddress - The address of the Comet contract
61
+ * @param amount - The amount to borrow
62
+ * @returns The health ratio after borrow as a Decimal
63
+ */
64
+ export declare const getHealthRatioAfterBorrow: (wallet: EvmWalletProvider, cometAddress: Address, amount: bigint) => Promise<Decimal>;
65
+ /**
66
+ * Get portfolio details in markdown format
67
+ *
68
+ * @param wallet - The wallet provider instance
69
+ * @param cometAddress - The address of the Comet contract
70
+ * @returns A markdown formatted string with portfolio details
71
+ */
72
+ export declare const getPortfolioDetailsMarkdown: (wallet: EvmWalletProvider, cometAddress: Address) => Promise<string>;
73
+ /**
74
+ * Gets the Comet address for the current network.
75
+ *
76
+ * @param network - The network instance
77
+ * @returns The Comet contract address
78
+ */
79
+ export declare const getCometAddress: (network: Network) => Address;
80
+ /**
81
+ * Gets the asset address for a given assetId on the current network.
82
+ *
83
+ * @param network - The network instance
84
+ * @param assetId - The identifier of the asset
85
+ * @returns The asset contract address
86
+ */
87
+ export declare const getAssetAddress: (network: Network, assetId: string) => Address;
88
+ /**
89
+ * Get the base token address for a Compound market
90
+ *
91
+ * @param wallet - The wallet provider instance
92
+ * @param cometAddress - The address of the Comet contract
93
+ * @returns The base token address
94
+ */
95
+ export declare const getBaseTokenAddress: (wallet: EvmWalletProvider, cometAddress: Address) => Promise<Address>;
@@ -0,0 +1,353 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBaseTokenAddress = exports.getAssetAddress = exports.getCometAddress = exports.getPortfolioDetailsMarkdown = exports.getHealthRatioAfterBorrow = exports.getHealthRatioAfterWithdraw = exports.getHealthRatio = exports.getCollateralBalance = exports.getTokenBalance = exports.getTokenSymbol = exports.getTokenDecimals = void 0;
4
+ const decimal_js_1 = require("decimal.js");
5
+ const viem_1 = require("viem");
6
+ const constants_1 = require("./constants");
7
+ const constants_2 = require("./constants");
8
+ /**
9
+ * Get token decimals from contract
10
+ *
11
+ * @param wallet - The wallet provider instance
12
+ * @param tokenAddress - The address of the token contract
13
+ * @returns The number of decimals for the token
14
+ */
15
+ const getTokenDecimals = async (wallet, tokenAddress) => {
16
+ const decimals = await wallet.readContract({
17
+ address: tokenAddress,
18
+ abi: constants_1.ERC20_ABI,
19
+ functionName: "decimals",
20
+ });
21
+ return Number(decimals);
22
+ };
23
+ exports.getTokenDecimals = getTokenDecimals;
24
+ /**
25
+ * Get token symbol from contract
26
+ *
27
+ * @param wallet - The wallet provider instance
28
+ * @param tokenAddress - The address of the token contract
29
+ * @returns The symbol of the token
30
+ */
31
+ const getTokenSymbol = async (wallet, tokenAddress) => {
32
+ const symbol = await wallet.readContract({
33
+ address: tokenAddress,
34
+ abi: constants_1.ERC20_ABI,
35
+ functionName: "symbol",
36
+ });
37
+ return symbol;
38
+ };
39
+ exports.getTokenSymbol = getTokenSymbol;
40
+ /**
41
+ * Get token balance for an address
42
+ *
43
+ * @param wallet - The wallet provider instance
44
+ * @param tokenAddress - The address of the token contract
45
+ * @returns The token balance as a bigint
46
+ */
47
+ const getTokenBalance = async (wallet, tokenAddress) => {
48
+ const balance = await wallet.readContract({
49
+ address: tokenAddress,
50
+ abi: constants_1.ERC20_ABI,
51
+ functionName: "balanceOf",
52
+ args: [wallet.getAddress()],
53
+ });
54
+ return balance;
55
+ };
56
+ exports.getTokenBalance = getTokenBalance;
57
+ /**
58
+ * Get collateral balance for an address
59
+ *
60
+ * @param wallet - The wallet provider instance
61
+ * @param cometAddress - The address of the Comet contract
62
+ * @param tokenAddress - The address of the token contract
63
+ * @returns The collateral balance as a bigint
64
+ */
65
+ const getCollateralBalance = async (wallet, cometAddress, tokenAddress) => {
66
+ const balance = await wallet.readContract({
67
+ address: cometAddress,
68
+ abi: constants_1.COMET_ABI,
69
+ functionName: "collateralBalanceOf",
70
+ args: [(await wallet.getAddress()), tokenAddress],
71
+ });
72
+ return balance;
73
+ };
74
+ exports.getCollateralBalance = getCollateralBalance;
75
+ /**
76
+ * Get health ratio for an account
77
+ *
78
+ * @param wallet - The wallet provider instance
79
+ * @param cometAddress - The address of the Comet contract
80
+ * @returns The health ratio as a Decimal
81
+ */
82
+ const getHealthRatio = async (wallet, cometAddress) => {
83
+ const borrowDetails = await getBorrowDetails(wallet, cometAddress);
84
+ const supplyDetails = await getSupplyDetails(wallet, cometAddress);
85
+ const borrowValue = borrowDetails.borrowAmount.mul(borrowDetails.price);
86
+ let totalAdjustedCollateral = new decimal_js_1.Decimal(0);
87
+ for (const supply of supplyDetails) {
88
+ const collateralValue = supply.supplyAmount.mul(supply.price);
89
+ const adjustedValue = collateralValue.mul(supply.collateralFactor);
90
+ totalAdjustedCollateral = totalAdjustedCollateral.add(adjustedValue);
91
+ }
92
+ return borrowValue.eq(0) ? new decimal_js_1.Decimal(Infinity) : totalAdjustedCollateral.div(borrowValue);
93
+ };
94
+ exports.getHealthRatio = getHealthRatio;
95
+ /**
96
+ * Get health ratio after a hypothetical withdraw
97
+ *
98
+ * @param wallet - The wallet provider instance
99
+ * @param cometAddress - The address of the Comet contract
100
+ * @param tokenAddress - The address of the token contract
101
+ * @param amount - The amount to withdraw
102
+ * @returns The health ratio after withdraw as a Decimal
103
+ */
104
+ const getHealthRatioAfterWithdraw = async (wallet, cometAddress, tokenAddress, amount) => {
105
+ const borrowDetails = await getBorrowDetails(wallet, cometAddress);
106
+ const supplyDetails = await getSupplyDetails(wallet, cometAddress);
107
+ const borrowValue = borrowDetails.borrowAmount.mul(borrowDetails.price);
108
+ let totalAdjustedCollateral = new decimal_js_1.Decimal(0);
109
+ for (const supply of supplyDetails) {
110
+ const supplyTokenSymbol = supply.tokenSymbol;
111
+ const withdrawTokenSymbol = await (0, exports.getTokenSymbol)(wallet, tokenAddress);
112
+ if (supplyTokenSymbol === withdrawTokenSymbol) {
113
+ const decimals = await (0, exports.getTokenDecimals)(wallet, tokenAddress);
114
+ const withdrawAmountHuman = new decimal_js_1.Decimal((0, viem_1.formatUnits)(amount, decimals));
115
+ const newSupplyAmount = supply.supplyAmount.sub(withdrawAmountHuman);
116
+ const assetValue = newSupplyAmount.mul(supply.price);
117
+ totalAdjustedCollateral = totalAdjustedCollateral.add(assetValue.mul(supply.collateralFactor));
118
+ }
119
+ else {
120
+ totalAdjustedCollateral = totalAdjustedCollateral.add(supply.supplyAmount.mul(supply.price).mul(supply.collateralFactor));
121
+ }
122
+ }
123
+ return borrowValue.eq(0) ? new decimal_js_1.Decimal(Infinity) : totalAdjustedCollateral.div(borrowValue);
124
+ };
125
+ exports.getHealthRatioAfterWithdraw = getHealthRatioAfterWithdraw;
126
+ /**
127
+ * Get health ratio after a hypothetical borrow
128
+ *
129
+ * @param wallet - The wallet provider instance
130
+ * @param cometAddress - The address of the Comet contract
131
+ * @param amount - The amount to borrow
132
+ * @returns The health ratio after borrow as a Decimal
133
+ */
134
+ const getHealthRatioAfterBorrow = async (wallet, cometAddress, amount) => {
135
+ const borrowDetails = await getBorrowDetails(wallet, cometAddress);
136
+ const supplyDetails = await getSupplyDetails(wallet, cometAddress);
137
+ const baseToken = await (0, exports.getBaseTokenAddress)(wallet, cometAddress);
138
+ const baseDecimals = await (0, exports.getTokenDecimals)(wallet, baseToken);
139
+ const additionalBorrow = new decimal_js_1.Decimal((0, viem_1.formatUnits)(amount, baseDecimals));
140
+ const newBorrow = borrowDetails.borrowAmount.add(additionalBorrow);
141
+ const newBorrowValue = newBorrow.mul(borrowDetails.price);
142
+ let totalAdjustedCollateral = new decimal_js_1.Decimal(0);
143
+ for (const supply of supplyDetails) {
144
+ totalAdjustedCollateral = totalAdjustedCollateral.add(supply.supplyAmount.mul(supply.price).mul(supply.collateralFactor));
145
+ }
146
+ return newBorrowValue.eq(0) ? new decimal_js_1.Decimal(Infinity) : totalAdjustedCollateral.div(newBorrowValue);
147
+ };
148
+ exports.getHealthRatioAfterBorrow = getHealthRatioAfterBorrow;
149
+ /**
150
+ * Get portfolio details in markdown format
151
+ *
152
+ * @param wallet - The wallet provider instance
153
+ * @param cometAddress - The address of the Comet contract
154
+ * @returns A markdown formatted string with portfolio details
155
+ */
156
+ const getPortfolioDetailsMarkdown = async (wallet, cometAddress) => {
157
+ let markdownOutput = "# Portfolio Details\n\n";
158
+ markdownOutput += "## Supply Details\n\n";
159
+ let totalSupplyValue = new decimal_js_1.Decimal(0);
160
+ const supplyDetails = await getSupplyDetails(wallet, cometAddress);
161
+ if (supplyDetails.length > 0) {
162
+ for (const supply of supplyDetails) {
163
+ const token = supply.tokenSymbol;
164
+ const supplyAmount = supply.supplyAmount;
165
+ const price = supply.price;
166
+ const decimals = supply.decimals;
167
+ const collateralFactor = supply.collateralFactor;
168
+ const assetValue = supplyAmount.mul(price);
169
+ markdownOutput += `### ${token}\n`;
170
+ markdownOutput += `- **Supply Amount:** ${supplyAmount.toFixed(decimals)}\n`;
171
+ markdownOutput += `- **Price:** $${price.toFixed(2)}\n`;
172
+ markdownOutput += `- **Collateral Factor:** ${collateralFactor.toFixed(2)}\n`;
173
+ markdownOutput += `- **Asset Value:** $${assetValue.toFixed(2)}\n\n`;
174
+ totalSupplyValue = totalSupplyValue.add(assetValue);
175
+ }
176
+ }
177
+ else {
178
+ markdownOutput += "No supplied assets found in your Compound position.\n\n";
179
+ }
180
+ markdownOutput += `### Total Supply Value: $${totalSupplyValue.toFixed(2)}\n\n`;
181
+ markdownOutput += "## Borrow Details\n\n";
182
+ const borrowDetails = await getBorrowDetails(wallet, cometAddress);
183
+ if (borrowDetails.borrowAmount.gt(0)) {
184
+ const token = borrowDetails.tokenSymbol;
185
+ const price = borrowDetails.price;
186
+ const borrowValue = borrowDetails.borrowAmount.mul(price);
187
+ markdownOutput += `### ${token}\n`;
188
+ markdownOutput += `- **Borrow Amount:** ${borrowDetails.borrowAmount.toFixed(6)}\n`;
189
+ markdownOutput += `- **Price:** $${price.toFixed(2)}\n`;
190
+ markdownOutput += `- **Borrow Value:** $${borrowValue.toFixed(2)}\n\n`;
191
+ }
192
+ else {
193
+ markdownOutput += "No borrowed assets found in your Compound position.\n\n";
194
+ }
195
+ markdownOutput += "## Overall Health\n\n";
196
+ const healthRatio = await (0, exports.getHealthRatio)(wallet, cometAddress);
197
+ markdownOutput += `- **Health Ratio:** ${healthRatio.toFixed(2)}\n`;
198
+ return markdownOutput;
199
+ };
200
+ exports.getPortfolioDetailsMarkdown = getPortfolioDetailsMarkdown;
201
+ /**
202
+ * Fetch the latest price feed data.
203
+ *
204
+ * @param wallet - The wallet provider instance
205
+ * @param priceFeedAddress - The address of the price feed contract
206
+ * @returns A tuple containing the price and timestamp
207
+ */
208
+ const getPriceFeedData = async (wallet, priceFeedAddress) => {
209
+ const latestData = await wallet.readContract({
210
+ address: priceFeedAddress,
211
+ abi: constants_1.PRICE_FEED_ABI,
212
+ functionName: "latestRoundData",
213
+ args: [],
214
+ });
215
+ const answer = latestData[1].toString();
216
+ const updatedAt = Number(latestData[3]);
217
+ return [answer, updatedAt];
218
+ };
219
+ /**
220
+ * Retrieve borrow details: amount, base token symbol, and price.
221
+ *
222
+ * @param wallet - The wallet provider instance
223
+ * @param cometAddress - The address of the Comet contract
224
+ * @returns An object containing borrow details
225
+ */
226
+ const getBorrowDetails = async (wallet, cometAddress) => {
227
+ const borrowAmountRaw = await wallet.readContract({
228
+ address: cometAddress,
229
+ abi: constants_1.COMET_ABI,
230
+ functionName: "borrowBalanceOf",
231
+ args: [(await wallet.getAddress())],
232
+ });
233
+ const baseToken = await (0, exports.getBaseTokenAddress)(wallet, cometAddress);
234
+ const baseDecimals = await (0, exports.getTokenDecimals)(wallet, baseToken);
235
+ const baseTokenSymbol = await (0, exports.getTokenSymbol)(wallet, baseToken);
236
+ const basePriceFeed = await wallet.readContract({
237
+ address: cometAddress,
238
+ abi: constants_1.COMET_ABI,
239
+ functionName: "baseTokenPriceFeed",
240
+ args: [],
241
+ });
242
+ const [basePriceRaw] = await getPriceFeedData(wallet, basePriceFeed);
243
+ const humanBorrowAmount = new decimal_js_1.Decimal((0, viem_1.formatUnits)(borrowAmountRaw, baseDecimals));
244
+ const price = new decimal_js_1.Decimal(basePriceRaw).div(new decimal_js_1.Decimal(10).pow(8));
245
+ return { tokenSymbol: baseTokenSymbol, borrowAmount: humanBorrowAmount, price };
246
+ };
247
+ /**
248
+ * Retrieve supply details across all collateral assets.
249
+ *
250
+ * @param wallet - The wallet provider instance
251
+ * @param cometAddress - The address of the Comet contract
252
+ * @returns An array of supply details for each asset
253
+ */
254
+ const getSupplyDetails = async (wallet, cometAddress) => {
255
+ const numAssets = await wallet.readContract({
256
+ address: cometAddress,
257
+ abi: constants_1.COMET_ABI,
258
+ functionName: "numAssets",
259
+ args: [],
260
+ });
261
+ const supplyDetails = [];
262
+ for (let i = 0; i < numAssets; i++) {
263
+ const assetInfo = await wallet.readContract({
264
+ address: cometAddress,
265
+ abi: constants_1.COMET_ABI,
266
+ functionName: "getAssetInfo",
267
+ args: [i],
268
+ });
269
+ const assetAddress = assetInfo.asset;
270
+ const collateralBalance = await (0, exports.getCollateralBalance)(wallet, cometAddress, assetAddress);
271
+ if (collateralBalance > 0n) {
272
+ const tokenSymbol = await (0, exports.getTokenSymbol)(wallet, assetAddress);
273
+ const decimals = await (0, exports.getTokenDecimals)(wallet, assetAddress);
274
+ const [priceRaw] = await getPriceFeedData(wallet, assetInfo.priceFeed);
275
+ const humanSupplyAmount = new decimal_js_1.Decimal((0, viem_1.formatUnits)(collateralBalance, decimals));
276
+ const price = new decimal_js_1.Decimal(priceRaw).div(new decimal_js_1.Decimal(10).pow(8));
277
+ const collateralFactor = new decimal_js_1.Decimal(assetInfo.borrowCollateralFactor.toString()).div(new decimal_js_1.Decimal(10).pow(18));
278
+ supplyDetails.push({
279
+ tokenSymbol,
280
+ supplyAmount: humanSupplyAmount,
281
+ price,
282
+ collateralFactor,
283
+ decimals,
284
+ });
285
+ }
286
+ }
287
+ return supplyDetails;
288
+ };
289
+ /**
290
+ * Gets the Comet address for the current network.
291
+ *
292
+ * @param network - The network instance
293
+ * @returns The Comet contract address
294
+ */
295
+ const getCometAddress = (network) => {
296
+ if (!network.networkId) {
297
+ throw new Error("Network ID is required");
298
+ }
299
+ if (network.networkId === "base-mainnet") {
300
+ return constants_2.COMET_ADDRESSES["base-mainnet"];
301
+ }
302
+ else if (network.networkId === "base-sepolia") {
303
+ return constants_2.COMET_ADDRESSES["base-sepolia"];
304
+ }
305
+ throw new Error(`Network ${network.networkId} not supported`);
306
+ };
307
+ exports.getCometAddress = getCometAddress;
308
+ /**
309
+ * Gets the asset address for a given assetId on the current network.
310
+ *
311
+ * @param network - The network instance
312
+ * @param assetId - The identifier of the asset
313
+ * @returns The asset contract address
314
+ */
315
+ const getAssetAddress = (network, assetId) => {
316
+ if (!network.networkId) {
317
+ throw new Error("Network ID is required");
318
+ }
319
+ const normalizedAssetId = assetId.toLowerCase();
320
+ if (network.networkId === "base-mainnet") {
321
+ const address = constants_2.ASSET_ADDRESSES["base-mainnet"][normalizedAssetId];
322
+ if (!address) {
323
+ throw new Error(`Asset ${assetId} not supported on Base Mainnet`);
324
+ }
325
+ return address;
326
+ }
327
+ else if (network.networkId === "base-sepolia") {
328
+ const address = constants_2.ASSET_ADDRESSES["base-sepolia"][normalizedAssetId];
329
+ if (!address) {
330
+ throw new Error(`Asset ${assetId} not supported on Base Sepolia`);
331
+ }
332
+ return address;
333
+ }
334
+ throw new Error(`Network ${network.networkId} not supported`);
335
+ };
336
+ exports.getAssetAddress = getAssetAddress;
337
+ /**
338
+ * Get the base token address for a Compound market
339
+ *
340
+ * @param wallet - The wallet provider instance
341
+ * @param cometAddress - The address of the Comet contract
342
+ * @returns The base token address
343
+ */
344
+ const getBaseTokenAddress = async (wallet, cometAddress) => {
345
+ const baseToken = await wallet.readContract({
346
+ address: cometAddress,
347
+ abi: constants_1.COMET_ABI,
348
+ functionName: "baseToken",
349
+ args: [],
350
+ });
351
+ return baseToken;
352
+ };
353
+ exports.getBaseTokenAddress = getBaseTokenAddress;
@@ -4,6 +4,7 @@ export * from "./customActionProvider";
4
4
  export * from "./alchemy";
5
5
  export * from "./basename";
6
6
  export * from "./cdp";
7
+ export * from "./compound";
7
8
  export * from "./erc20";
8
9
  export * from "./erc721";
9
10
  export * from "./farcaster";
@@ -20,6 +20,7 @@ __exportStar(require("./customActionProvider"), exports);
20
20
  __exportStar(require("./alchemy"), exports);
21
21
  __exportStar(require("./basename"), exports);
22
22
  __exportStar(require("./cdp"), exports);
23
+ __exportStar(require("./compound"), exports);
23
24
  __exportStar(require("./erc20"), exports);
24
25
  __exportStar(require("./erc721"), exports);
25
26
  __exportStar(require("./farcaster"), exports);
@@ -3,6 +3,7 @@ export * from "./evmWalletProvider";
3
3
  export * from "./viemWalletProvider";
4
4
  export * from "./cdpWalletProvider";
5
5
  export * from "./svmWalletProvider";
6
+ export * from "./smartWalletProvider";
6
7
  export * from "./solanaKeypairWalletProvider";
7
8
  export * from "./privyWalletProvider";
8
9
  export * from "./privyEvmWalletProvider";
@@ -19,6 +19,7 @@ __exportStar(require("./evmWalletProvider"), exports);
19
19
  __exportStar(require("./viemWalletProvider"), exports);
20
20
  __exportStar(require("./cdpWalletProvider"), exports);
21
21
  __exportStar(require("./svmWalletProvider"), exports);
22
+ __exportStar(require("./smartWalletProvider"), exports);
22
23
  __exportStar(require("./solanaKeypairWalletProvider"), exports);
23
24
  __exportStar(require("./privyWalletProvider"), exports);
24
25
  __exportStar(require("./privyEvmWalletProvider"), exports);