@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.
- package/README.md +48 -0
- package/dist/action-providers/compound/compoundActionProvider.d.ts +67 -0
- package/dist/action-providers/compound/compoundActionProvider.js +365 -0
- package/dist/action-providers/compound/compoundActionProvider.test.d.ts +1 -0
- package/dist/action-providers/compound/compoundActionProvider.test.js +353 -0
- package/dist/action-providers/compound/constants.d.ts +180 -0
- package/dist/action-providers/compound/constants.js +129 -0
- package/dist/action-providers/compound/index.d.ts +1 -0
- package/dist/action-providers/compound/index.js +17 -0
- package/dist/action-providers/compound/schemas.d.ts +57 -0
- package/dist/action-providers/compound/schemas.js +58 -0
- package/dist/action-providers/compound/utils.d.ts +95 -0
- package/dist/action-providers/compound/utils.js +353 -0
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/wallet-providers/index.d.ts +1 -0
- package/dist/wallet-providers/index.js +1 -0
- package/dist/wallet-providers/smartWalletProvider.d.ts +177 -0
- package/dist/wallet-providers/smartWalletProvider.js +303 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
|
|
|
30
30
|
- [PrivyWalletProvider](#privywalletprovider)
|
|
31
31
|
- [Authorization Keys](#authorization-keys)
|
|
32
32
|
- [Exporting Privy Wallet information](#exporting-privy-wallet-information)
|
|
33
|
+
- [SmartWalletProvider](#smartwalletprovider)
|
|
33
34
|
- [SVM Wallet Providers](#svm-wallet-providers)
|
|
34
35
|
- [SolanaKeypairWalletProvider](#solanakeypairwalletprovider)
|
|
35
36
|
- [Network Configuration](#solana-network-configuration)
|
|
@@ -166,6 +167,31 @@ const agent = createReactAgent({
|
|
|
166
167
|
</table>
|
|
167
168
|
</details>
|
|
168
169
|
<details>
|
|
170
|
+
<summary><strong>Compound</strong></summary>
|
|
171
|
+
<table width="100%">
|
|
172
|
+
<tr>
|
|
173
|
+
<td width="200"><code>supply</code></td>
|
|
174
|
+
<td width="768">Supplies collateral assets (WETH, CBETH, CBBTC, WSTETH, or USDC) to Compound.</td>
|
|
175
|
+
</tr>
|
|
176
|
+
<tr>
|
|
177
|
+
<td width="200"><code>withdraw</code></td>
|
|
178
|
+
<td width="768">Withdraws previously supplied collateral assets from Compound.</td>
|
|
179
|
+
</tr>
|
|
180
|
+
<tr>
|
|
181
|
+
<td width="200"><code>borrow</code></td>
|
|
182
|
+
<td width="768">Borrows base assets (WETH or USDC) from Compound using supplied collateral.</td>
|
|
183
|
+
</tr>
|
|
184
|
+
<tr>
|
|
185
|
+
<td width="200"><code>repay</code></td>
|
|
186
|
+
<td width="768">Repays borrowed assets back to Compound.</td>
|
|
187
|
+
</tr>
|
|
188
|
+
<tr>
|
|
189
|
+
<td width="200"><code>get_portfolio</code></td>
|
|
190
|
+
<td width="768">Retrieves portfolio details including collateral balances and borrowed amounts.</td>
|
|
191
|
+
</tr>
|
|
192
|
+
</table>
|
|
193
|
+
</details>
|
|
194
|
+
<details>
|
|
169
195
|
<summary><strong>ERC20</strong></summary>
|
|
170
196
|
<table width="100%">
|
|
171
197
|
<tr>
|
|
@@ -609,6 +635,28 @@ const walletData = await walletProvider.exportWallet();
|
|
|
609
635
|
}
|
|
610
636
|
```
|
|
611
637
|
|
|
638
|
+
### SmartWalletProvider
|
|
639
|
+
|
|
640
|
+
The `SmartWalletProvider` is a wallet provider that uses [CDP Smart Wallets](https://docs.cdp.coinbase.com/wallet-api/docs/smart-wallets).
|
|
641
|
+
|
|
642
|
+
```typescript
|
|
643
|
+
import { SmartWalletProvider, SmartWalletConfig } from "@coinbase/agentkit";
|
|
644
|
+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
645
|
+
|
|
646
|
+
const networkId = process.env.NETWORK_ID || "base-sepolia";
|
|
647
|
+
|
|
648
|
+
const privateKey = process.env.PRIVATE_KEY || generatePrivateKey();
|
|
649
|
+
const signer = privateKeyToAccount(privateKey);
|
|
650
|
+
|
|
651
|
+
// Configure Wallet Provider
|
|
652
|
+
const walletProvider = await SmartWalletProvider.configureWithWallet({
|
|
653
|
+
networkId,
|
|
654
|
+
signer,
|
|
655
|
+
smartWalletAddress: undefined, // If not provided a new smart wallet will be created
|
|
656
|
+
paymasterUrl: undefined, // Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome
|
|
657
|
+
});
|
|
658
|
+
```
|
|
659
|
+
|
|
612
660
|
## SVM Wallet Providers
|
|
613
661
|
|
|
614
662
|
SVM:
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
4
|
+
import { Network } from "../../network";
|
|
5
|
+
import { CompoundSupplySchema, CompoundWithdrawSchema, CompoundBorrowSchema, CompoundRepaySchema, CompoundPortfolioSchema } from "./schemas";
|
|
6
|
+
/**
|
|
7
|
+
* CompoundActionProvider is an action provider for Compound protocol interactions.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CompoundActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a new CompoundActionProvider instance.
|
|
12
|
+
*/
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Supplies collateral assets to Compound.
|
|
16
|
+
*
|
|
17
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
18
|
+
* @param args - The input arguments including assetId and amount.
|
|
19
|
+
* @returns A message indicating success or an error message.
|
|
20
|
+
*/
|
|
21
|
+
supply(wallet: EvmWalletProvider, args: z.infer<typeof CompoundSupplySchema>): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Withdraws collateral assets from Compound.
|
|
24
|
+
*
|
|
25
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
26
|
+
* @param args - The input arguments including assetId and amount.
|
|
27
|
+
* @returns A message indicating success or an error message.
|
|
28
|
+
*/
|
|
29
|
+
withdraw(wallet: EvmWalletProvider, args: z.infer<typeof CompoundWithdrawSchema>): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Borrows base assets from Compound.
|
|
32
|
+
*
|
|
33
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
34
|
+
* @param args - The input arguments including assetId and amount.
|
|
35
|
+
* @returns A message indicating success or an error message.
|
|
36
|
+
*/
|
|
37
|
+
borrow(wallet: EvmWalletProvider, args: z.infer<typeof CompoundBorrowSchema>): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Repays borrowed assets to Compound.
|
|
40
|
+
*
|
|
41
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
42
|
+
* @param args - The input arguments including assetId and amount.
|
|
43
|
+
* @returns A message indicating success or an error message.
|
|
44
|
+
*/
|
|
45
|
+
repay(wallet: EvmWalletProvider, args: z.infer<typeof CompoundRepaySchema>): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves portfolio details from Compound.
|
|
48
|
+
*
|
|
49
|
+
* @param wallet - The wallet instance to fetch portfolio details.
|
|
50
|
+
* @param _ - No input is required for this action.
|
|
51
|
+
* @returns A Markdown formatted string with portfolio details or an error message.
|
|
52
|
+
*/
|
|
53
|
+
getPortfolio(wallet: EvmWalletProvider, _: z.infer<typeof CompoundPortfolioSchema>): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if the Compound action provider supports the given network.
|
|
56
|
+
*
|
|
57
|
+
* @param network - The network to check.
|
|
58
|
+
* @returns True if the network is supported, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
supportsNetwork: (network: Network) => boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Factory function to create a new instance of CompoundActionProvider.
|
|
64
|
+
*
|
|
65
|
+
* @returns A new CompoundActionProvider instance.
|
|
66
|
+
*/
|
|
67
|
+
export declare const compoundActionProvider: () => CompoundActionProvider;
|
|
@@ -0,0 +1,365 @@
|
|
|
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.compoundActionProvider = exports.CompoundActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const viem_1 = require("viem");
|
|
15
|
+
const actionProvider_1 = require("../actionProvider");
|
|
16
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
17
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
18
|
+
const utils_1 = require("../../utils");
|
|
19
|
+
const constants_1 = require("./constants");
|
|
20
|
+
const schemas_1 = require("./schemas");
|
|
21
|
+
const utils_2 = require("./utils");
|
|
22
|
+
/**
|
|
23
|
+
* CompoundActionProvider is an action provider for Compound protocol interactions.
|
|
24
|
+
*/
|
|
25
|
+
class CompoundActionProvider extends actionProvider_1.ActionProvider {
|
|
26
|
+
/**
|
|
27
|
+
* Constructs a new CompoundActionProvider instance.
|
|
28
|
+
*/
|
|
29
|
+
constructor() {
|
|
30
|
+
super("compound", []);
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the Compound action provider supports the given network.
|
|
33
|
+
*
|
|
34
|
+
* @param network - The network to check.
|
|
35
|
+
* @returns True if the network is supported, false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
this.supportsNetwork = (network) => network.protocolFamily === "evm" &&
|
|
38
|
+
(network.networkId === "base-mainnet" || network.networkId === "base-sepolia");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Supplies collateral assets to Compound.
|
|
42
|
+
*
|
|
43
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
44
|
+
* @param args - The input arguments including assetId and amount.
|
|
45
|
+
* @returns A message indicating success or an error message.
|
|
46
|
+
*/
|
|
47
|
+
async supply(wallet, args) {
|
|
48
|
+
try {
|
|
49
|
+
const network = wallet.getNetwork();
|
|
50
|
+
const cometAddress = (0, utils_2.getCometAddress)(network);
|
|
51
|
+
const tokenAddress = (0, utils_2.getAssetAddress)(network, args.assetId);
|
|
52
|
+
if (!tokenAddress) {
|
|
53
|
+
throw new Error(`Token address undefined for assetId ${args.assetId}`);
|
|
54
|
+
}
|
|
55
|
+
const decimals = await (0, utils_2.getTokenDecimals)(wallet, tokenAddress);
|
|
56
|
+
const amountAtomic = (0, viem_1.parseUnits)(args.amount, decimals);
|
|
57
|
+
// Check wallet balance before proceeding
|
|
58
|
+
const walletBalance = await (0, utils_2.getTokenBalance)(wallet, tokenAddress);
|
|
59
|
+
if (walletBalance < amountAtomic) {
|
|
60
|
+
const humanBalance = (0, viem_1.formatUnits)(walletBalance, decimals);
|
|
61
|
+
return `Error: Insufficient balance. You have ${humanBalance}, but trying to supply ${args.amount}`;
|
|
62
|
+
}
|
|
63
|
+
// Get current health ratio for reference
|
|
64
|
+
const currentHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
65
|
+
// Approve Compound to spend tokens
|
|
66
|
+
const approvalResult = await (0, utils_1.approve)(wallet, tokenAddress, cometAddress, amountAtomic);
|
|
67
|
+
if (approvalResult.startsWith("Error")) {
|
|
68
|
+
return `Error approving token: ${approvalResult}`;
|
|
69
|
+
}
|
|
70
|
+
// Supply tokens to Compound
|
|
71
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
72
|
+
abi: constants_1.COMET_ABI,
|
|
73
|
+
functionName: "supply",
|
|
74
|
+
args: [tokenAddress, amountAtomic],
|
|
75
|
+
});
|
|
76
|
+
const txHash = await wallet.sendTransaction({
|
|
77
|
+
to: cometAddress,
|
|
78
|
+
data,
|
|
79
|
+
});
|
|
80
|
+
await wallet.waitForTransactionReceipt(txHash);
|
|
81
|
+
// Get new health ratio and token symbol
|
|
82
|
+
const newHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
83
|
+
const tokenSymbol = await (0, utils_2.getTokenSymbol)(wallet, tokenAddress);
|
|
84
|
+
// Only add the health ratio message if at least one of the values is not Infinity
|
|
85
|
+
const healthMessage = currentHealth.eq(Infinity) && newHealth.eq(Infinity)
|
|
86
|
+
? ""
|
|
87
|
+
: `\nHealth ratio changed from ${currentHealth.toFixed(2)} to ${newHealth.toFixed(2)}`;
|
|
88
|
+
return `Supplied ${args.amount} ${tokenSymbol} to Compound.\nTransaction hash: ${txHash}${healthMessage}`;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return `Error supplying to Compound: ${error instanceof Error
|
|
92
|
+
? error.message
|
|
93
|
+
: error && typeof error === "object" && "message" in error
|
|
94
|
+
? `Error: ${error.message}`
|
|
95
|
+
: error}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Withdraws collateral assets from Compound.
|
|
100
|
+
*
|
|
101
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
102
|
+
* @param args - The input arguments including assetId and amount.
|
|
103
|
+
* @returns A message indicating success or an error message.
|
|
104
|
+
*/
|
|
105
|
+
async withdraw(wallet, args) {
|
|
106
|
+
try {
|
|
107
|
+
const cometAddress = (0, utils_2.getCometAddress)(wallet.getNetwork());
|
|
108
|
+
const tokenAddress = (0, utils_2.getAssetAddress)(wallet.getNetwork(), args.assetId);
|
|
109
|
+
const decimals = await (0, utils_2.getTokenDecimals)(wallet, tokenAddress);
|
|
110
|
+
const amountAtomic = (0, viem_1.parseUnits)(args.amount, decimals);
|
|
111
|
+
// Check that there is enough collateral supplied to withdraw
|
|
112
|
+
const collateralBalance = await (0, utils_2.getCollateralBalance)(wallet, cometAddress, tokenAddress);
|
|
113
|
+
if (amountAtomic > collateralBalance) {
|
|
114
|
+
const humanBalance = (0, viem_1.formatUnits)(collateralBalance, decimals);
|
|
115
|
+
return `Error: Insufficient balance. Trying to withdraw ${args.amount}, but only have ${humanBalance} supplied`;
|
|
116
|
+
}
|
|
117
|
+
// Check if position would be healthy after withdrawal
|
|
118
|
+
const projectedHealthRatio = await (0, utils_2.getHealthRatioAfterWithdraw)(wallet, cometAddress, tokenAddress, amountAtomic);
|
|
119
|
+
if (projectedHealthRatio.lessThan(1)) {
|
|
120
|
+
return `Error: Withdrawing ${args.amount} would result in an unhealthy position. Health ratio would be ${projectedHealthRatio.toFixed(2)}`;
|
|
121
|
+
}
|
|
122
|
+
// Withdraw from Compound
|
|
123
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
124
|
+
abi: constants_1.COMET_ABI,
|
|
125
|
+
functionName: "withdraw",
|
|
126
|
+
args: [tokenAddress, amountAtomic],
|
|
127
|
+
});
|
|
128
|
+
const txHash = await wallet.sendTransaction({
|
|
129
|
+
to: cometAddress,
|
|
130
|
+
data,
|
|
131
|
+
});
|
|
132
|
+
await wallet.waitForTransactionReceipt(txHash);
|
|
133
|
+
// Get current and new health ratios and token symbol
|
|
134
|
+
const currentHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
135
|
+
const newHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
136
|
+
const tokenSymbol = await (0, utils_2.getTokenSymbol)(wallet, tokenAddress);
|
|
137
|
+
return (`Withdrawn ${args.amount} ${tokenSymbol} from Compound.\n` +
|
|
138
|
+
`Transaction hash: ${txHash}\n` +
|
|
139
|
+
`Health ratio changed from ${currentHealth.toFixed(2)} to ${newHealth.toFixed(2)}`);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return `Error withdrawing from Compound: ${error instanceof Error ? error : error && typeof error === "object" && "message" in error ? `Error: ${error.message}` : error}`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Borrows base assets from Compound.
|
|
147
|
+
*
|
|
148
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
149
|
+
* @param args - The input arguments including assetId and amount.
|
|
150
|
+
* @returns A message indicating success or an error message.
|
|
151
|
+
*/
|
|
152
|
+
async borrow(wallet, args) {
|
|
153
|
+
try {
|
|
154
|
+
const cometAddress = (0, utils_2.getCometAddress)(wallet.getNetwork());
|
|
155
|
+
const baseTokenAddress = await (0, utils_2.getBaseTokenAddress)(wallet, cometAddress);
|
|
156
|
+
const decimals = await (0, utils_2.getTokenDecimals)(wallet, baseTokenAddress);
|
|
157
|
+
// Convert human-readable amount to atomic units
|
|
158
|
+
const amountAtomic = (0, viem_1.parseUnits)(args.amount, decimals);
|
|
159
|
+
// Get current health ratio for reference
|
|
160
|
+
const currentHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
161
|
+
const currentHealthStr = currentHealth.eq(Infinity) ? "Inf.%" : currentHealth.toFixed(2);
|
|
162
|
+
// Check if position would be healthy after borrow
|
|
163
|
+
const projectedHealthRatio = await (0, utils_2.getHealthRatioAfterBorrow)(wallet, cometAddress, amountAtomic);
|
|
164
|
+
if (projectedHealthRatio.lessThan(1)) {
|
|
165
|
+
return `Error: Borrowing ${args.amount} USDC would result in an unhealthy position. Health ratio would be ${projectedHealthRatio.toFixed(2)}`;
|
|
166
|
+
}
|
|
167
|
+
// Use the withdraw method to borrow from Compound
|
|
168
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
169
|
+
abi: constants_1.COMET_ABI,
|
|
170
|
+
functionName: "withdraw",
|
|
171
|
+
args: [baseTokenAddress, amountAtomic],
|
|
172
|
+
});
|
|
173
|
+
const txHash = await wallet.sendTransaction({
|
|
174
|
+
to: cometAddress,
|
|
175
|
+
data,
|
|
176
|
+
});
|
|
177
|
+
await wallet.waitForTransactionReceipt(txHash);
|
|
178
|
+
// Get new health ratio
|
|
179
|
+
const newHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
180
|
+
const newHealthStr = newHealth.eq(Infinity) ? "Inf.%" : newHealth.toFixed(2);
|
|
181
|
+
return (`Borrowed ${args.amount} USDC from Compound.\n` +
|
|
182
|
+
`Transaction hash: ${txHash}\n` +
|
|
183
|
+
`Health ratio changed from ${currentHealthStr} to ${newHealthStr}`);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return `Error borrowing from Compound: ${error instanceof Error ? error : error && typeof error === "object" && "message" in error ? `Error: ${error.message}` : error}`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Repays borrowed assets to Compound.
|
|
191
|
+
*
|
|
192
|
+
* @param wallet - The wallet instance to perform the transaction.
|
|
193
|
+
* @param args - The input arguments including assetId and amount.
|
|
194
|
+
* @returns A message indicating success or an error message.
|
|
195
|
+
*/
|
|
196
|
+
async repay(wallet, args) {
|
|
197
|
+
try {
|
|
198
|
+
const cometAddress = (0, utils_2.getCometAddress)(wallet.getNetwork());
|
|
199
|
+
const tokenAddress = (0, utils_2.getAssetAddress)(wallet.getNetwork(), args.assetId);
|
|
200
|
+
const tokenDecimals = await (0, utils_2.getTokenDecimals)(wallet, tokenAddress);
|
|
201
|
+
const amountAtomic = (0, viem_1.parseUnits)(args.amount, tokenDecimals);
|
|
202
|
+
const tokenBalance = await (0, utils_2.getTokenBalance)(wallet, tokenAddress);
|
|
203
|
+
if (tokenBalance < amountAtomic) {
|
|
204
|
+
const humanBalance = (0, viem_1.formatUnits)(tokenBalance, tokenDecimals);
|
|
205
|
+
return `Error: Insufficient balance. You have ${humanBalance}, but trying to repay ${args.amount}`;
|
|
206
|
+
}
|
|
207
|
+
// Get current health ratio for reference
|
|
208
|
+
const currentHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
209
|
+
// Approve Compound to spend tokens
|
|
210
|
+
const approvalResult = await (0, utils_1.approve)(wallet, tokenAddress, cometAddress, amountAtomic);
|
|
211
|
+
if (approvalResult.startsWith("Error")) {
|
|
212
|
+
return `Error approving token: ${approvalResult}`;
|
|
213
|
+
}
|
|
214
|
+
// Repay debt by supplying tokens to Compound
|
|
215
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
216
|
+
abi: constants_1.COMET_ABI,
|
|
217
|
+
functionName: "supply",
|
|
218
|
+
args: [tokenAddress, amountAtomic],
|
|
219
|
+
});
|
|
220
|
+
const txHash = await wallet.sendTransaction({
|
|
221
|
+
to: cometAddress,
|
|
222
|
+
data,
|
|
223
|
+
});
|
|
224
|
+
await wallet.waitForTransactionReceipt(txHash);
|
|
225
|
+
// Get new health ratio and token symbol
|
|
226
|
+
const newHealth = await (0, utils_2.getHealthRatio)(wallet, cometAddress);
|
|
227
|
+
const tokenSymbol = await (0, utils_2.getTokenSymbol)(wallet, tokenAddress);
|
|
228
|
+
return (`Repaid ${args.amount} ${tokenSymbol} to Compound.\n` +
|
|
229
|
+
`Transaction hash: ${txHash}\n` +
|
|
230
|
+
`Health ratio improved from ${currentHealth.toFixed(2)} to ${newHealth.toFixed(2)}`);
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
return `Error repaying to Compound: ${error instanceof Error ? error : error && typeof error === "object" && "message" in error ? `Error: ${error.message}` : error}`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Retrieves portfolio details from Compound.
|
|
238
|
+
*
|
|
239
|
+
* @param wallet - The wallet instance to fetch portfolio details.
|
|
240
|
+
* @param _ - No input is required for this action.
|
|
241
|
+
* @returns A Markdown formatted string with portfolio details or an error message.
|
|
242
|
+
*/
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
244
|
+
async getPortfolio(wallet, _) {
|
|
245
|
+
try {
|
|
246
|
+
const cometAddress = (0, utils_2.getCometAddress)(wallet.getNetwork());
|
|
247
|
+
return await (0, utils_2.getPortfolioDetailsMarkdown)(wallet, cometAddress);
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
return `Error getting portfolio details: ${error && typeof error === "object" && "message" in error ? error.message : error}`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.CompoundActionProvider = CompoundActionProvider;
|
|
255
|
+
__decorate([
|
|
256
|
+
(0, actionDecorator_1.CreateAction)({
|
|
257
|
+
name: "supply",
|
|
258
|
+
description: `
|
|
259
|
+
This tool allows supplying collateral assets to Compound.
|
|
260
|
+
It takes:
|
|
261
|
+
- assetId: The asset to supply, one of 'weth', 'cbeth', 'cbbtc', 'wsteth', or 'usdc'
|
|
262
|
+
- amount: The amount of tokens to supply in human-readable format
|
|
263
|
+
Examples:
|
|
264
|
+
- 1 WETH
|
|
265
|
+
- 0.1 WETH
|
|
266
|
+
- 0.01 WETH
|
|
267
|
+
Important notes:
|
|
268
|
+
- Use the exact amount provided
|
|
269
|
+
- The token must be an approved collateral asset for the Compound market
|
|
270
|
+
`,
|
|
271
|
+
schema: schemas_1.CompoundSupplySchema,
|
|
272
|
+
}),
|
|
273
|
+
__metadata("design:type", Function),
|
|
274
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
275
|
+
__metadata("design:returntype", Promise)
|
|
276
|
+
], CompoundActionProvider.prototype, "supply", null);
|
|
277
|
+
__decorate([
|
|
278
|
+
(0, actionDecorator_1.CreateAction)({
|
|
279
|
+
name: "withdraw",
|
|
280
|
+
description: `
|
|
281
|
+
This tool allows withdrawing collateral assets from Compound.
|
|
282
|
+
It takes:
|
|
283
|
+
- assetId: The asset to withdraw, one of 'weth', 'cbeth', 'cbbtc', 'wsteth', or 'usdc'
|
|
284
|
+
- amount: The amount of tokens to withdraw in human-readable format
|
|
285
|
+
Examples:
|
|
286
|
+
- 1 WETH
|
|
287
|
+
- 0.1 WETH
|
|
288
|
+
- 0.01 WETH
|
|
289
|
+
Important notes:
|
|
290
|
+
- Use the exact amount provided
|
|
291
|
+
- The token must be a collateral asset you have supplied to the Compound market
|
|
292
|
+
`,
|
|
293
|
+
schema: schemas_1.CompoundWithdrawSchema,
|
|
294
|
+
}),
|
|
295
|
+
__metadata("design:type", Function),
|
|
296
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
297
|
+
__metadata("design:returntype", Promise)
|
|
298
|
+
], CompoundActionProvider.prototype, "withdraw", null);
|
|
299
|
+
__decorate([
|
|
300
|
+
(0, actionDecorator_1.CreateAction)({
|
|
301
|
+
name: "borrow",
|
|
302
|
+
description: `
|
|
303
|
+
This tool allows borrowing base assets from Compound.
|
|
304
|
+
It takes:
|
|
305
|
+
- assetId: The asset to borrow, either 'weth' or 'usdc'
|
|
306
|
+
- amount: The amount of base tokens to borrow in human-readable format
|
|
307
|
+
Examples:
|
|
308
|
+
- 1000 USDC
|
|
309
|
+
- 0.5 WETH
|
|
310
|
+
Important notes:
|
|
311
|
+
- Use the exact amount provided
|
|
312
|
+
- Ensure you have sufficient collateral to borrow
|
|
313
|
+
`,
|
|
314
|
+
schema: schemas_1.CompoundBorrowSchema,
|
|
315
|
+
}),
|
|
316
|
+
__metadata("design:type", Function),
|
|
317
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
318
|
+
__metadata("design:returntype", Promise)
|
|
319
|
+
], CompoundActionProvider.prototype, "borrow", null);
|
|
320
|
+
__decorate([
|
|
321
|
+
(0, actionDecorator_1.CreateAction)({
|
|
322
|
+
name: "repay",
|
|
323
|
+
description: `
|
|
324
|
+
This tool allows repaying borrowed assets to Compound.
|
|
325
|
+
It takes:
|
|
326
|
+
- assetId: The asset to repay, either 'weth' or 'usdc'
|
|
327
|
+
- amount: The amount of tokens to repay in human-readable format
|
|
328
|
+
Examples:
|
|
329
|
+
- 1000 USDC
|
|
330
|
+
- 0.5 WETH
|
|
331
|
+
Important notes:
|
|
332
|
+
- Use the exact amount provided
|
|
333
|
+
- Ensure you have sufficient balance of the asset to repay
|
|
334
|
+
`,
|
|
335
|
+
schema: schemas_1.CompoundRepaySchema,
|
|
336
|
+
}),
|
|
337
|
+
__metadata("design:type", Function),
|
|
338
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
339
|
+
__metadata("design:returntype", Promise)
|
|
340
|
+
], CompoundActionProvider.prototype, "repay", null);
|
|
341
|
+
__decorate([
|
|
342
|
+
(0, actionDecorator_1.CreateAction)({
|
|
343
|
+
name: "get_portfolio",
|
|
344
|
+
description: `
|
|
345
|
+
This tool allows getting portfolio details from Compound.
|
|
346
|
+
Returns portfolio details including:
|
|
347
|
+
- Collateral balances and USD values
|
|
348
|
+
- Borrowed amounts and USD values
|
|
349
|
+
Formatted in Markdown for readability.
|
|
350
|
+
`,
|
|
351
|
+
schema: schemas_1.CompoundPortfolioSchema,
|
|
352
|
+
})
|
|
353
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
354
|
+
,
|
|
355
|
+
__metadata("design:type", Function),
|
|
356
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
357
|
+
__metadata("design:returntype", Promise)
|
|
358
|
+
], CompoundActionProvider.prototype, "getPortfolio", null);
|
|
359
|
+
/**
|
|
360
|
+
* Factory function to create a new instance of CompoundActionProvider.
|
|
361
|
+
*
|
|
362
|
+
* @returns A new CompoundActionProvider instance.
|
|
363
|
+
*/
|
|
364
|
+
const compoundActionProvider = () => new CompoundActionProvider();
|
|
365
|
+
exports.compoundActionProvider = compoundActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|