@coinbase/agentkit 0.0.0-nightly-20250808210408 → 0.0.0-nightly-20250815210416
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 +26 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +43 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +151 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +242 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +42 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +132 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +199 -0
- package/dist/action-providers/cdp/index.d.ts +3 -0
- package/dist/action-providers/cdp/index.js +3 -0
- package/dist/action-providers/cdp/schemas.d.ts +29 -0
- package/dist/action-providers/cdp/schemas.js +32 -1
- package/dist/action-providers/cdp/spendPermissionUtils.d.ts +24 -0
- package/dist/action-providers/cdp/spendPermissionUtils.js +66 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +10 -31
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +7 -1
- package/dist/wallet-providers/cdpEvmWalletProvider.js +10 -1
- package/dist/wallet-providers/cdpShared.d.ts +5 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +9 -2
- package/dist/wallet-providers/cdpSmartWalletProvider.js +20 -12
- package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +8 -1
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +11 -1
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +11 -1
- package/dist/wallet-providers/legacyCdpWalletProvider.js +10 -1
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +9 -1
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +10 -1
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
- package/dist/wallet-providers/viemWalletProvider.d.ts +7 -1
- package/dist/wallet-providers/viemWalletProvider.js +8 -0
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +9 -1
- package/dist/wallet-providers/zeroDevWalletProvider.js +10 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -171,6 +171,32 @@ const agent = createReactAgent({
|
|
|
171
171
|
|
|
172
172
|
## Action Providers
|
|
173
173
|
|
|
174
|
+
<details>
|
|
175
|
+
<summary><strong>CDP EVM Wallet</strong></summary>
|
|
176
|
+
<table width="100%">
|
|
177
|
+
<tr>
|
|
178
|
+
<td width="200"><code>list_spend_permissions</code></td>
|
|
179
|
+
<td width="768">Lists spend permissions that have been granted to the current EVM wallet by a smart account.</td>
|
|
180
|
+
</tr>
|
|
181
|
+
<tr>
|
|
182
|
+
<td width="200"><code>use_spend_permission</code></td>
|
|
183
|
+
<td width="768">Uses a spend permission to spend tokens on behalf of a smart account that the current EVM wallet has permission to spend.</td>
|
|
184
|
+
</tr>
|
|
185
|
+
</table>
|
|
186
|
+
</details>
|
|
187
|
+
<details>
|
|
188
|
+
<summary><strong>CDP Smart Wallet</strong></summary>
|
|
189
|
+
<table width="100%">
|
|
190
|
+
<tr>
|
|
191
|
+
<td width="200"><code>list_spend_permissions</code></td>
|
|
192
|
+
<td width="768">Lists spend permissions that have been granted to the current smart wallet by a smart account.</td>
|
|
193
|
+
</tr>
|
|
194
|
+
<tr>
|
|
195
|
+
<td width="200"><code>use_spend_permission</code></td>
|
|
196
|
+
<td width="768">Uses a spend permission to spend tokens on behalf of a smart account that the current smart wallet has permission to spend.</td>
|
|
197
|
+
</tr>
|
|
198
|
+
</table>
|
|
199
|
+
</details>
|
|
174
200
|
<details>
|
|
175
201
|
<summary><strong>Across</strong></summary>
|
|
176
202
|
<table width="100%">
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { WalletProvider } from "../../wallet-providers";
|
|
3
|
+
import { CdpEvmWalletProvider } from "../../wallet-providers/cdpEvmWalletProvider";
|
|
4
|
+
import { ActionProvider } from "../actionProvider";
|
|
5
|
+
import { UseSpendPermissionSchema, ListSpendPermissionsSchema } from "./schemas";
|
|
6
|
+
import type { Network } from "../../network";
|
|
7
|
+
/**
|
|
8
|
+
* CdpEvmWalletActionProvider is an action provider for CDP EVM Wallet specific actions.
|
|
9
|
+
*
|
|
10
|
+
* This provider is scoped specifically to EVM wallets and provides actions
|
|
11
|
+
* that are optimized for EVM functionality, including spend permission usage.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CdpEvmWalletActionProvider extends ActionProvider<CdpEvmWalletProvider> {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor for the CdpEvmWalletActionProvider class.
|
|
17
|
+
*/
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Lists spend permissions for a smart account.
|
|
21
|
+
*
|
|
22
|
+
* @param walletProvider - The server wallet provider to use for listing permissions.
|
|
23
|
+
* @param args - The input arguments for listing spend permissions.
|
|
24
|
+
* @returns A list of spend permissions available to the current wallet.
|
|
25
|
+
*/
|
|
26
|
+
listSpendPermissions(walletProvider: WalletProvider, args: z.infer<typeof ListSpendPermissionsSchema>): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Uses a spend permission to transfer tokens from a smart account to the current EVM wallet.
|
|
29
|
+
*
|
|
30
|
+
* @param walletProvider - The EVM wallet provider to use for the spend operation.
|
|
31
|
+
* @param args - The input arguments for using the spend permission.
|
|
32
|
+
* @returns A confirmation message with transaction details.
|
|
33
|
+
*/
|
|
34
|
+
useSpendPermission(walletProvider: WalletProvider, args: z.infer<typeof UseSpendPermissionSchema>): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the EVM wallet action provider supports the given network.
|
|
37
|
+
*
|
|
38
|
+
* @param network - The network to check.
|
|
39
|
+
* @returns True if the EVM wallet action provider supports the network, false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
supportsNetwork: (network: Network) => boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare const cdpEvmWalletActionProvider: () => CdpEvmWalletActionProvider;
|
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var _CdpEvmWalletActionProvider_instances, _CdpEvmWalletActionProvider_getCdpSdkNetwork;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.cdpEvmWalletActionProvider = exports.CdpEvmWalletActionProvider = void 0;
|
|
19
|
+
const zod_1 = require("zod");
|
|
20
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
21
|
+
const cdpShared_1 = require("../../wallet-providers/cdpShared");
|
|
22
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
23
|
+
const actionProvider_1 = require("../actionProvider");
|
|
24
|
+
const schemas_1 = require("./schemas");
|
|
25
|
+
const spendPermissionUtils_1 = require("./spendPermissionUtils");
|
|
26
|
+
/**
|
|
27
|
+
* CdpEvmWalletActionProvider is an action provider for CDP EVM Wallet specific actions.
|
|
28
|
+
*
|
|
29
|
+
* This provider is scoped specifically to EVM wallets and provides actions
|
|
30
|
+
* that are optimized for EVM functionality, including spend permission usage.
|
|
31
|
+
*/
|
|
32
|
+
class CdpEvmWalletActionProvider extends actionProvider_1.ActionProvider {
|
|
33
|
+
/**
|
|
34
|
+
* Constructor for the CdpEvmWalletActionProvider class.
|
|
35
|
+
*/
|
|
36
|
+
constructor() {
|
|
37
|
+
super("cdp_evm_wallet", []);
|
|
38
|
+
_CdpEvmWalletActionProvider_instances.add(this);
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the EVM wallet action provider supports the given network.
|
|
41
|
+
*
|
|
42
|
+
* @param network - The network to check.
|
|
43
|
+
* @returns True if the EVM wallet action provider supports the network, false otherwise.
|
|
44
|
+
*/
|
|
45
|
+
this.supportsNetwork = (network) => {
|
|
46
|
+
// EVM wallets support EVM networks in general
|
|
47
|
+
return network.protocolFamily === "evm";
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Lists spend permissions for a smart account.
|
|
52
|
+
*
|
|
53
|
+
* @param walletProvider - The server wallet provider to use for listing permissions.
|
|
54
|
+
* @param args - The input arguments for listing spend permissions.
|
|
55
|
+
* @returns A list of spend permissions available to the current wallet.
|
|
56
|
+
*/
|
|
57
|
+
async listSpendPermissions(walletProvider, args) {
|
|
58
|
+
const network = walletProvider.getNetwork();
|
|
59
|
+
if ((0, cdpShared_1.isWalletProviderWithClient)(walletProvider)) {
|
|
60
|
+
if (network.protocolFamily === "evm") {
|
|
61
|
+
return await (0, spendPermissionUtils_1.listSpendPermissionsForSpender)(walletProvider.getClient(), args.smartAccountAddress, walletProvider.getAddress());
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return "Spend permissions are currently only supported on EVM networks.";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return "Wallet provider is not a CDP Wallet Provider.";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Uses a spend permission to transfer tokens from a smart account to the current EVM wallet.
|
|
73
|
+
*
|
|
74
|
+
* @param walletProvider - The EVM wallet provider to use for the spend operation.
|
|
75
|
+
* @param args - The input arguments for using the spend permission.
|
|
76
|
+
* @returns A confirmation message with transaction details.
|
|
77
|
+
*/
|
|
78
|
+
async useSpendPermission(walletProvider, args) {
|
|
79
|
+
const network = walletProvider.getNetwork();
|
|
80
|
+
const cdpNetwork = __classPrivateFieldGet(this, _CdpEvmWalletActionProvider_instances, "m", _CdpEvmWalletActionProvider_getCdpSdkNetwork).call(this, network.networkId);
|
|
81
|
+
if ((0, cdpShared_1.isWalletProviderWithClient)(walletProvider)) {
|
|
82
|
+
if (network.protocolFamily === "evm") {
|
|
83
|
+
try {
|
|
84
|
+
const spenderAddress = walletProvider.getAddress();
|
|
85
|
+
const permission = await (0, spendPermissionUtils_1.findLatestSpendPermission)(walletProvider.getClient(), args.smartAccountAddress, spenderAddress);
|
|
86
|
+
const account = await walletProvider.getClient().evm.getAccount({
|
|
87
|
+
address: spenderAddress,
|
|
88
|
+
});
|
|
89
|
+
const spendResult = await account.useSpendPermission({
|
|
90
|
+
spendPermission: permission,
|
|
91
|
+
value: BigInt(args.value),
|
|
92
|
+
network: cdpNetwork,
|
|
93
|
+
});
|
|
94
|
+
return `Successfully spent ${args.value} tokens using spend permission. Transaction hash: ${spendResult.transactionHash}`;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return `Failed to use spend permission: ${error}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return "Spend permissions are currently only supported on EVM networks.";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return "Wallet provider is not a CDP Wallet Provider.";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.CdpEvmWalletActionProvider = CdpEvmWalletActionProvider;
|
|
110
|
+
_CdpEvmWalletActionProvider_instances = new WeakSet(), _CdpEvmWalletActionProvider_getCdpSdkNetwork = function _CdpEvmWalletActionProvider_getCdpSdkNetwork(networkId) {
|
|
111
|
+
switch (networkId) {
|
|
112
|
+
case "base-sepolia":
|
|
113
|
+
return "base-sepolia";
|
|
114
|
+
case "base-mainnet":
|
|
115
|
+
return "base";
|
|
116
|
+
case "ethereum-sepolia":
|
|
117
|
+
return "ethereum-sepolia";
|
|
118
|
+
case "ethereum-mainnet":
|
|
119
|
+
return "ethereum";
|
|
120
|
+
default:
|
|
121
|
+
return networkId; // For other networks, use as-is
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
__decorate([
|
|
125
|
+
(0, actionDecorator_1.CreateAction)({
|
|
126
|
+
name: "list_spend_permissions",
|
|
127
|
+
description: `This tool lists spend permissions that have been granted to the current EVM wallet by a smart account.
|
|
128
|
+
It takes a smart account address and returns spend permissions where the current EVM wallet is the spender.
|
|
129
|
+
This is useful to see what spending allowances have been granted before using them.
|
|
130
|
+
This action is specifically designed for EVM wallets.`,
|
|
131
|
+
schema: schemas_1.ListSpendPermissionsSchema,
|
|
132
|
+
}),
|
|
133
|
+
__metadata("design:type", Function),
|
|
134
|
+
__metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
|
|
135
|
+
__metadata("design:returntype", Promise)
|
|
136
|
+
], CdpEvmWalletActionProvider.prototype, "listSpendPermissions", null);
|
|
137
|
+
__decorate([
|
|
138
|
+
(0, actionDecorator_1.CreateAction)({
|
|
139
|
+
name: "use_spend_permission",
|
|
140
|
+
description: `This tool uses a spend permission to spend tokens on behalf of a smart account that the current EVM wallet has permission to spend.
|
|
141
|
+
It automatically finds the latest valid spend permission granted by the smart account to the current EVM wallet and uses it to spend the specified amount.
|
|
142
|
+
The smart account must have previously granted a spend permission to the current EVM wallet using createSpendPermission.
|
|
143
|
+
This action is specifically designed for EVM wallets and uses the EVM wallet for spend permission execution.`,
|
|
144
|
+
schema: schemas_1.UseSpendPermissionSchema,
|
|
145
|
+
}),
|
|
146
|
+
__metadata("design:type", Function),
|
|
147
|
+
__metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
|
|
148
|
+
__metadata("design:returntype", Promise)
|
|
149
|
+
], CdpEvmWalletActionProvider.prototype, "useSpendPermission", null);
|
|
150
|
+
const cdpEvmWalletActionProvider = () => new CdpEvmWalletActionProvider();
|
|
151
|
+
exports.cdpEvmWalletActionProvider = cdpEvmWalletActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,242 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const cdpEvmWalletActionProvider_1 = require("./cdpEvmWalletActionProvider");
|
|
37
|
+
const schemas_1 = require("./schemas");
|
|
38
|
+
const spendPermissionUtils = __importStar(require("./spendPermissionUtils"));
|
|
39
|
+
// Mock the CDP SDK and utility functions
|
|
40
|
+
jest.mock("@coinbase/cdp-sdk");
|
|
41
|
+
jest.mock("./spendPermissionUtils");
|
|
42
|
+
describe("CDP EVM Wallet Action Provider", () => {
|
|
43
|
+
let actionProvider;
|
|
44
|
+
let mockWalletProvider;
|
|
45
|
+
let mockCdpClient;
|
|
46
|
+
let mockAccount;
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
mockAccount = {
|
|
50
|
+
useSpendPermission: jest.fn(),
|
|
51
|
+
address: "0x1234567890123456789012345678901234567890",
|
|
52
|
+
};
|
|
53
|
+
mockCdpClient = {
|
|
54
|
+
evm: {
|
|
55
|
+
listSpendPermissions: jest.fn(),
|
|
56
|
+
getAccount: jest.fn(),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
mockWalletProvider = {
|
|
60
|
+
getNetwork: jest.fn(),
|
|
61
|
+
getAddress: jest.fn(),
|
|
62
|
+
getClient: jest.fn(),
|
|
63
|
+
};
|
|
64
|
+
actionProvider = new cdpEvmWalletActionProvider_1.CdpEvmWalletActionProvider();
|
|
65
|
+
});
|
|
66
|
+
describe("listSpendPermissions", () => {
|
|
67
|
+
const mockArgs = {
|
|
68
|
+
smartAccountAddress: "0xabcd1234567890123456789012345678901234567890",
|
|
69
|
+
};
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
mockWalletProvider.getNetwork.mockReturnValue({
|
|
72
|
+
protocolFamily: "evm",
|
|
73
|
+
networkId: "base-sepolia",
|
|
74
|
+
});
|
|
75
|
+
mockWalletProvider.getAddress.mockReturnValue("0x1234567890123456789012345678901234567890");
|
|
76
|
+
mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
|
|
77
|
+
});
|
|
78
|
+
it("should successfully list spend permissions for EVM wallets", async () => {
|
|
79
|
+
const expectedResult = "Found 2 spend permission(s):\n1. Token: USDC, Allowance: 500, Period: 1800 seconds, Start: 111111, End: 222222\n2. Token: ETH, Allowance: 1000, Period: 3600 seconds, Start: 123456, End: 234567";
|
|
80
|
+
spendPermissionUtils.listSpendPermissionsForSpender.mockResolvedValue(expectedResult);
|
|
81
|
+
const result = await actionProvider.listSpendPermissions(mockWalletProvider, mockArgs);
|
|
82
|
+
expect(spendPermissionUtils.listSpendPermissionsForSpender).toHaveBeenCalledWith(mockCdpClient, mockArgs.smartAccountAddress, "0x1234567890123456789012345678901234567890");
|
|
83
|
+
expect(result).toBe(expectedResult);
|
|
84
|
+
});
|
|
85
|
+
it("should return error message for non-EVM networks", async () => {
|
|
86
|
+
mockWalletProvider.getNetwork.mockReturnValue({
|
|
87
|
+
protocolFamily: "svm",
|
|
88
|
+
networkId: "solana-devnet",
|
|
89
|
+
});
|
|
90
|
+
const result = await actionProvider.listSpendPermissions(mockWalletProvider, mockArgs);
|
|
91
|
+
expect(result).toBe("Spend permissions are currently only supported on EVM networks.");
|
|
92
|
+
expect(spendPermissionUtils.listSpendPermissionsForSpender).not.toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
it("should handle utility function errors gracefully", async () => {
|
|
95
|
+
spendPermissionUtils.listSpendPermissionsForSpender.mockResolvedValue("Failed to list spend permissions: Network error");
|
|
96
|
+
const result = await actionProvider.listSpendPermissions(mockWalletProvider, mockArgs);
|
|
97
|
+
expect(result).toBe("Failed to list spend permissions: Network error");
|
|
98
|
+
});
|
|
99
|
+
it("should validate input schema", () => {
|
|
100
|
+
const validInput = { smartAccountAddress: "0xabcd1234567890123456789012345678901234567890" };
|
|
101
|
+
const invalidInput = { wrongField: "0xabcd1234567890123456789012345678901234567890" };
|
|
102
|
+
expect(() => schemas_1.ListSpendPermissionsSchema.parse(validInput)).not.toThrow();
|
|
103
|
+
expect(() => schemas_1.ListSpendPermissionsSchema.parse(invalidInput)).toThrow();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe("useSpendPermission", () => {
|
|
107
|
+
const mockArgs = {
|
|
108
|
+
smartAccountAddress: "0xabcd1234567890123456789012345678901234567890",
|
|
109
|
+
value: "2500",
|
|
110
|
+
};
|
|
111
|
+
beforeEach(() => {
|
|
112
|
+
mockWalletProvider.getNetwork.mockReturnValue({
|
|
113
|
+
protocolFamily: "evm",
|
|
114
|
+
networkId: "base-sepolia",
|
|
115
|
+
});
|
|
116
|
+
mockWalletProvider.getAddress.mockReturnValue("0x1234567890123456789012345678901234567890");
|
|
117
|
+
mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
|
|
118
|
+
mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
|
|
119
|
+
});
|
|
120
|
+
it("should successfully use spend permission for EVM wallets", async () => {
|
|
121
|
+
const mockPermission = {
|
|
122
|
+
spender: "0x1234567890123456789012345678901234567890",
|
|
123
|
+
token: "USDC",
|
|
124
|
+
allowance: "5000",
|
|
125
|
+
period: 7200,
|
|
126
|
+
start: 111111,
|
|
127
|
+
end: 333333,
|
|
128
|
+
};
|
|
129
|
+
const mockSpendResult = {
|
|
130
|
+
status: "completed",
|
|
131
|
+
transactionHash: "0xdef456789",
|
|
132
|
+
};
|
|
133
|
+
spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
|
|
134
|
+
mockAccount.useSpendPermission.mockResolvedValue(mockSpendResult);
|
|
135
|
+
const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
|
|
136
|
+
expect(spendPermissionUtils.findLatestSpendPermission).toHaveBeenCalledWith(mockCdpClient, mockArgs.smartAccountAddress, "0x1234567890123456789012345678901234567890");
|
|
137
|
+
expect(mockCdpClient.evm.getAccount).toHaveBeenCalledWith({
|
|
138
|
+
address: "0x1234567890123456789012345678901234567890",
|
|
139
|
+
});
|
|
140
|
+
expect(mockAccount.useSpendPermission).toHaveBeenCalledWith({
|
|
141
|
+
spendPermission: mockPermission,
|
|
142
|
+
value: BigInt(2500),
|
|
143
|
+
network: "base-sepolia",
|
|
144
|
+
});
|
|
145
|
+
expect(result).toBe("Successfully spent 2500 tokens using spend permission. Transaction hash: 0xdef456789");
|
|
146
|
+
});
|
|
147
|
+
it("should handle different network conversions", async () => {
|
|
148
|
+
const testCases = [
|
|
149
|
+
{ networkId: "base-sepolia", expected: "base-sepolia" },
|
|
150
|
+
{ networkId: "base-mainnet", expected: "base" },
|
|
151
|
+
{ networkId: "ethereum-sepolia", expected: "ethereum-sepolia" },
|
|
152
|
+
{ networkId: "ethereum-mainnet", expected: "ethereum" },
|
|
153
|
+
];
|
|
154
|
+
const mockPermission = { spender: "0x1234", token: "ETH" };
|
|
155
|
+
const mockSpendResult = { status: "completed" };
|
|
156
|
+
spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
|
|
157
|
+
mockAccount.useSpendPermission.mockResolvedValue(mockSpendResult);
|
|
158
|
+
for (const testCase of testCases) {
|
|
159
|
+
jest.clearAllMocks();
|
|
160
|
+
mockWalletProvider.getNetwork.mockReturnValue({
|
|
161
|
+
protocolFamily: "evm",
|
|
162
|
+
networkId: testCase.networkId,
|
|
163
|
+
});
|
|
164
|
+
mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
|
|
165
|
+
mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
|
|
166
|
+
await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
|
|
167
|
+
expect(mockAccount.useSpendPermission).toHaveBeenCalledWith({
|
|
168
|
+
spendPermission: mockPermission,
|
|
169
|
+
value: BigInt(2500),
|
|
170
|
+
network: testCase.expected,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
it("should handle unknown networks by passing them as-is", async () => {
|
|
175
|
+
mockWalletProvider.getNetwork.mockReturnValue({
|
|
176
|
+
protocolFamily: "evm",
|
|
177
|
+
networkId: "polygon-mainnet",
|
|
178
|
+
});
|
|
179
|
+
const mockPermission = { spender: "0x1234", token: "MATIC" };
|
|
180
|
+
const mockSpendResult = { status: "completed" };
|
|
181
|
+
spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
|
|
182
|
+
mockAccount.useSpendPermission.mockResolvedValue(mockSpendResult);
|
|
183
|
+
await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
|
|
184
|
+
expect(mockAccount.useSpendPermission).toHaveBeenCalledWith({
|
|
185
|
+
spendPermission: mockPermission,
|
|
186
|
+
value: BigInt(2500),
|
|
187
|
+
network: "polygon-mainnet",
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
it("should return error message for non-EVM networks", async () => {
|
|
191
|
+
mockWalletProvider.getNetwork.mockReturnValue({
|
|
192
|
+
protocolFamily: "svm",
|
|
193
|
+
networkId: "solana-devnet",
|
|
194
|
+
});
|
|
195
|
+
const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
|
|
196
|
+
expect(result).toBe("Spend permissions are currently only supported on EVM networks.");
|
|
197
|
+
});
|
|
198
|
+
it("should handle spend permission not found error", async () => {
|
|
199
|
+
spendPermissionUtils.findLatestSpendPermission.mockRejectedValue(new Error("No spend permissions found for spender"));
|
|
200
|
+
const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
|
|
201
|
+
expect(result).toBe("Failed to use spend permission: Error: No spend permissions found for spender");
|
|
202
|
+
});
|
|
203
|
+
it("should handle account creation failure", async () => {
|
|
204
|
+
spendPermissionUtils.findLatestSpendPermission.mockResolvedValue({
|
|
205
|
+
spender: "0x1234",
|
|
206
|
+
token: "ETH",
|
|
207
|
+
});
|
|
208
|
+
mockCdpClient.evm.getAccount.mockRejectedValue(new Error("Account not found"));
|
|
209
|
+
const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
|
|
210
|
+
expect(result).toBe("Failed to use spend permission: Error: Account not found");
|
|
211
|
+
});
|
|
212
|
+
it("should handle account use permission failure", async () => {
|
|
213
|
+
const mockPermission = { spender: "0x1234", token: "ETH" };
|
|
214
|
+
spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
|
|
215
|
+
mockAccount.useSpendPermission.mockRejectedValue(new Error("Insufficient allowance"));
|
|
216
|
+
const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
|
|
217
|
+
expect(result).toBe("Failed to use spend permission: Error: Insufficient allowance");
|
|
218
|
+
});
|
|
219
|
+
it("should validate input schema", () => {
|
|
220
|
+
const validInput = {
|
|
221
|
+
smartAccountAddress: "0xabcd1234567890123456789012345678901234567890",
|
|
222
|
+
value: "1000",
|
|
223
|
+
};
|
|
224
|
+
const invalidInput = {
|
|
225
|
+
smartAccountAddress: "not-an-address",
|
|
226
|
+
value: -100,
|
|
227
|
+
};
|
|
228
|
+
expect(() => schemas_1.UseSpendPermissionSchema.parse(validInput)).not.toThrow();
|
|
229
|
+
expect(() => schemas_1.UseSpendPermissionSchema.parse(invalidInput)).toThrow();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
describe("supportsNetwork", () => {
|
|
233
|
+
it("should return true for EVM networks", () => {
|
|
234
|
+
const evmNetwork = { protocolFamily: "evm", networkId: "base-sepolia" };
|
|
235
|
+
expect(actionProvider.supportsNetwork(evmNetwork)).toBe(true);
|
|
236
|
+
});
|
|
237
|
+
it("should return false for non-EVM networks", () => {
|
|
238
|
+
const svmNetwork = { protocolFamily: "svm", networkId: "solana-devnet" };
|
|
239
|
+
expect(actionProvider.supportsNetwork(svmNetwork)).toBe(false);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CdpSmartWalletProvider } from "../../wallet-providers/cdpSmartWalletProvider";
|
|
3
|
+
import { ActionProvider } from "../actionProvider";
|
|
4
|
+
import { UseSpendPermissionSchema, ListSpendPermissionsSchema } from "./schemas";
|
|
5
|
+
import type { Network } from "../../network";
|
|
6
|
+
/**
|
|
7
|
+
* CdpSmartWalletActionProvider is an action provider for CDP Smart Wallet specific actions.
|
|
8
|
+
*
|
|
9
|
+
* This provider is scoped specifically to CdpSmartWalletProvider and provides actions
|
|
10
|
+
* that are optimized for smart wallet functionality.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CdpSmartWalletActionProvider extends ActionProvider<CdpSmartWalletProvider> {
|
|
13
|
+
#private;
|
|
14
|
+
/**
|
|
15
|
+
* Constructor for the CdpSmartWalletActionProvider class.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Lists spend permissions for a smart account.
|
|
20
|
+
*
|
|
21
|
+
* @param walletProvider - The smart wallet provider to use for listing permissions.
|
|
22
|
+
* @param args - The input arguments for listing spend permissions.
|
|
23
|
+
* @returns A list of spend permissions available to the current wallet.
|
|
24
|
+
*/
|
|
25
|
+
listSpendPermissions(walletProvider: CdpSmartWalletProvider, args: z.infer<typeof ListSpendPermissionsSchema>): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Uses a spend permission to transfer tokens from a smart account to the current smart wallet.
|
|
28
|
+
*
|
|
29
|
+
* @param walletProvider - The smart wallet provider to use for the spend operation.
|
|
30
|
+
* @param args - The input arguments for using the spend permission.
|
|
31
|
+
* @returns A confirmation message with transaction details.
|
|
32
|
+
*/
|
|
33
|
+
useSpendPermission(walletProvider: CdpSmartWalletProvider, args: z.infer<typeof UseSpendPermissionSchema>): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the smart wallet action provider supports the given network.
|
|
36
|
+
*
|
|
37
|
+
* @param _ - The network to check.
|
|
38
|
+
* @returns True if the smart wallet action provider supports the network, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
supportsNetwork: (_: Network) => boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare const cdpSmartWalletActionProvider: () => CdpSmartWalletActionProvider;
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var _CdpSmartWalletActionProvider_instances, _CdpSmartWalletActionProvider_getCdpSdkNetwork;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.cdpSmartWalletActionProvider = exports.CdpSmartWalletActionProvider = void 0;
|
|
19
|
+
const zod_1 = require("zod");
|
|
20
|
+
const cdpSmartWalletProvider_1 = require("../../wallet-providers/cdpSmartWalletProvider");
|
|
21
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
22
|
+
const actionProvider_1 = require("../actionProvider");
|
|
23
|
+
const schemas_1 = require("./schemas");
|
|
24
|
+
const spendPermissionUtils_1 = require("./spendPermissionUtils");
|
|
25
|
+
/**
|
|
26
|
+
* CdpSmartWalletActionProvider is an action provider for CDP Smart Wallet specific actions.
|
|
27
|
+
*
|
|
28
|
+
* This provider is scoped specifically to CdpSmartWalletProvider and provides actions
|
|
29
|
+
* that are optimized for smart wallet functionality.
|
|
30
|
+
*/
|
|
31
|
+
class CdpSmartWalletActionProvider extends actionProvider_1.ActionProvider {
|
|
32
|
+
/**
|
|
33
|
+
* Constructor for the CdpSmartWalletActionProvider class.
|
|
34
|
+
*/
|
|
35
|
+
constructor() {
|
|
36
|
+
super("cdp_smart_wallet", []);
|
|
37
|
+
_CdpSmartWalletActionProvider_instances.add(this);
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the smart wallet action provider supports the given network.
|
|
40
|
+
*
|
|
41
|
+
* @param _ - The network to check.
|
|
42
|
+
* @returns True if the smart wallet action provider supports the network, false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
this.supportsNetwork = (_) => {
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Lists spend permissions for a smart account.
|
|
50
|
+
*
|
|
51
|
+
* @param walletProvider - The smart wallet provider to use for listing permissions.
|
|
52
|
+
* @param args - The input arguments for listing spend permissions.
|
|
53
|
+
* @returns A list of spend permissions available to the current wallet.
|
|
54
|
+
*/
|
|
55
|
+
async listSpendPermissions(walletProvider, args) {
|
|
56
|
+
const network = walletProvider.getNetwork();
|
|
57
|
+
if (network.protocolFamily === "evm") {
|
|
58
|
+
const spenderAddress = walletProvider.getAddress();
|
|
59
|
+
return await (0, spendPermissionUtils_1.listSpendPermissionsForSpender)(walletProvider.getClient(), args.smartAccountAddress, spenderAddress);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return "Spend permissions are currently only supported on EVM networks.";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Uses a spend permission to transfer tokens from a smart account to the current smart wallet.
|
|
67
|
+
*
|
|
68
|
+
* @param walletProvider - The smart wallet provider to use for the spend operation.
|
|
69
|
+
* @param args - The input arguments for using the spend permission.
|
|
70
|
+
* @returns A confirmation message with transaction details.
|
|
71
|
+
*/
|
|
72
|
+
async useSpendPermission(walletProvider, args) {
|
|
73
|
+
const network = walletProvider.getNetwork();
|
|
74
|
+
const cdpNetwork = __classPrivateFieldGet(this, _CdpSmartWalletActionProvider_instances, "m", _CdpSmartWalletActionProvider_getCdpSdkNetwork).call(this, network.networkId);
|
|
75
|
+
if (network.protocolFamily === "evm") {
|
|
76
|
+
try {
|
|
77
|
+
const permission = await (0, spendPermissionUtils_1.findLatestSpendPermission)(walletProvider.getClient(), args.smartAccountAddress, walletProvider.getAddress());
|
|
78
|
+
const spendResult = await walletProvider.smartAccount.useSpendPermission({
|
|
79
|
+
spendPermission: permission,
|
|
80
|
+
value: BigInt(args.value),
|
|
81
|
+
network: cdpNetwork,
|
|
82
|
+
});
|
|
83
|
+
return `Successfully spent ${args.value} tokens using spend permission. Status: ${spendResult.status}`;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new Error(`Failed to use spend permission: ${error}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error("Spend permissions are currently only supported on EVM networks.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.CdpSmartWalletActionProvider = CdpSmartWalletActionProvider;
|
|
95
|
+
_CdpSmartWalletActionProvider_instances = new WeakSet(), _CdpSmartWalletActionProvider_getCdpSdkNetwork = function _CdpSmartWalletActionProvider_getCdpSdkNetwork(networkId) {
|
|
96
|
+
switch (networkId) {
|
|
97
|
+
case "base-sepolia":
|
|
98
|
+
return "base-sepolia";
|
|
99
|
+
case "base-mainnet":
|
|
100
|
+
return "base";
|
|
101
|
+
default:
|
|
102
|
+
throw new Error(`Unsupported network for smart wallets: ${networkId}`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, actionDecorator_1.CreateAction)({
|
|
107
|
+
name: "list_spend_permissions",
|
|
108
|
+
description: `This tool lists spend permissions that have been granted to the current smart wallet by another smart account.
|
|
109
|
+
It takes a smart account address and returns spend permissions where the current smart wallet is the spender.
|
|
110
|
+
This is useful to see what spending allowances have been granted before using them.
|
|
111
|
+
This action is specifically designed for smart wallets.`,
|
|
112
|
+
schema: schemas_1.ListSpendPermissionsSchema,
|
|
113
|
+
}),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", [cdpSmartWalletProvider_1.CdpSmartWalletProvider, void 0]),
|
|
116
|
+
__metadata("design:returntype", Promise)
|
|
117
|
+
], CdpSmartWalletActionProvider.prototype, "listSpendPermissions", null);
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, actionDecorator_1.CreateAction)({
|
|
120
|
+
name: "use_spend_permission",
|
|
121
|
+
description: `This tool uses a spend permission to spend tokens on behalf of a smart account that the current smart wallet has permission to spend.
|
|
122
|
+
It automatically finds the latest valid spend permission granted by the smart account to the current smart wallet and uses it to spend the specified amount.
|
|
123
|
+
The smart account must have previously granted a spend permission to the current smart wallet using createSpendPermission.
|
|
124
|
+
This action is specifically designed for smart wallets and uses the smart account directly for optimal performance.`,
|
|
125
|
+
schema: schemas_1.UseSpendPermissionSchema,
|
|
126
|
+
}),
|
|
127
|
+
__metadata("design:type", Function),
|
|
128
|
+
__metadata("design:paramtypes", [cdpSmartWalletProvider_1.CdpSmartWalletProvider, void 0]),
|
|
129
|
+
__metadata("design:returntype", Promise)
|
|
130
|
+
], CdpSmartWalletActionProvider.prototype, "useSpendPermission", null);
|
|
131
|
+
const cdpSmartWalletActionProvider = () => new CdpSmartWalletActionProvider();
|
|
132
|
+
exports.cdpSmartWalletActionProvider = cdpSmartWalletActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|