@coinbase/agentkit 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -2
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +5 -3
- package/dist/action-providers/cdp/cdpApiActionProvider.js +15 -4
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +14 -2
- package/dist/action-providers/cdp/cdpWalletActionProvider.js +4 -1
- package/dist/action-providers/index.d.ts +2 -0
- package/dist/action-providers/index.js +2 -0
- package/dist/action-providers/jupiter/index.d.ts +1 -0
- package/dist/action-providers/jupiter/index.js +17 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.d.ts +36 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +115 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +146 -0
- package/dist/action-providers/jupiter/schemas.d.ts +20 -0
- package/dist/action-providers/jupiter/schemas.js +20 -0
- package/dist/action-providers/spl/schemas.d.ts +13 -0
- package/dist/action-providers/spl/schemas.js +13 -1
- package/dist/action-providers/spl/splActionProvider.d.ts +9 -1
- package/dist/action-providers/spl/splActionProvider.js +62 -1
- package/dist/action-providers/spl/splActionProvider.test.js +101 -7
- package/dist/action-providers/wow/constants.js +1 -1
- package/dist/action-providers/wow/wowActionProvider.d.ts +4 -4
- package/dist/action-providers/wow/wowActionProvider.js +19 -19
- package/dist/action-providers/wow/wowActionProvider.test.js +14 -10
- package/dist/analytics/sendAnalyticsEvent.js +1 -0
- package/dist/network/svm.d.ts +1 -0
- package/dist/network/svm.js +6 -1
- package/dist/wallet-providers/cdpWalletProvider.js +1 -1
- package/dist/wallet-providers/index.d.ts +2 -0
- package/dist/wallet-providers/index.js +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +140 -0
- package/dist/wallet-providers/privyShared.d.ts +40 -0
- package/dist/wallet-providers/privyShared.js +49 -0
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +128 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +212 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +21 -56
- package/dist/wallet-providers/privyWalletProvider.js +18 -118
- package/package.json +2 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapTokenSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Schema for swapping tokens using Jupiter.
|
|
7
|
+
*/
|
|
8
|
+
exports.SwapTokenSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
inputMint: zod_1.z.string().describe("The mint address of the token to swap from"),
|
|
11
|
+
outputMint: zod_1.z.string().describe("The mint address of the token to swap to"),
|
|
12
|
+
amount: zod_1.z.number().positive().describe("Amount of tokens to swap"),
|
|
13
|
+
slippageBps: zod_1.z
|
|
14
|
+
.number()
|
|
15
|
+
.int()
|
|
16
|
+
.positive()
|
|
17
|
+
.default(50)
|
|
18
|
+
.describe("Slippage tolerance in basis points (e.g., 50 = 0.5%)"),
|
|
19
|
+
})
|
|
20
|
+
.describe("Swap tokens using Jupiter DEX aggregator");
|
|
@@ -15,3 +15,16 @@ export declare const TransferTokenSchema: z.ZodObject<{
|
|
|
15
15
|
recipient: string;
|
|
16
16
|
mintAddress: string;
|
|
17
17
|
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Schema for getting SPL token balance.
|
|
20
|
+
*/
|
|
21
|
+
export declare const GetBalanceSchema: z.ZodObject<{
|
|
22
|
+
mintAddress: z.ZodString;
|
|
23
|
+
address: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
mintAddress: string;
|
|
26
|
+
address?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
mintAddress: string;
|
|
29
|
+
address?: string | undefined;
|
|
30
|
+
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransferTokenSchema = void 0;
|
|
3
|
+
exports.GetBalanceSchema = exports.TransferTokenSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
/**
|
|
6
6
|
* Schema for transferring SPL tokens to another address.
|
|
@@ -12,3 +12,15 @@ exports.TransferTokenSchema = zod_1.z
|
|
|
12
12
|
amount: zod_1.z.number().positive().describe("Amount of tokens to transfer"),
|
|
13
13
|
})
|
|
14
14
|
.describe("Transfer SPL tokens to another Solana address");
|
|
15
|
+
/**
|
|
16
|
+
* Schema for getting SPL token balance.
|
|
17
|
+
*/
|
|
18
|
+
exports.GetBalanceSchema = zod_1.z
|
|
19
|
+
.object({
|
|
20
|
+
mintAddress: zod_1.z.string().describe("The SPL token's mint address"),
|
|
21
|
+
address: zod_1.z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("Optional address to check balance for. If not provided, uses the wallet's address"),
|
|
25
|
+
})
|
|
26
|
+
.describe("Get SPL token balance for an address");
|
|
@@ -2,7 +2,7 @@ import { ActionProvider } from "../actionProvider";
|
|
|
2
2
|
import { Network } from "../../network";
|
|
3
3
|
import { SvmWalletProvider } from "../../wallet-providers/svmWalletProvider";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { TransferTokenSchema } from "./schemas";
|
|
5
|
+
import { TransferTokenSchema, GetBalanceSchema } from "./schemas";
|
|
6
6
|
/**
|
|
7
7
|
* SplActionProvider serves as a provider for SPL token actions.
|
|
8
8
|
* It provides SPL token transfer functionality.
|
|
@@ -12,6 +12,14 @@ export declare class SplActionProvider extends ActionProvider<SvmWalletProvider>
|
|
|
12
12
|
* Creates a new SplActionProvider instance.
|
|
13
13
|
*/
|
|
14
14
|
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Get the balance of SPL tokens for an address.
|
|
17
|
+
*
|
|
18
|
+
* @param walletProvider - The wallet provider to use
|
|
19
|
+
* @param args - Parameters including mint address and optional target address
|
|
20
|
+
* @returns A message indicating the token balance
|
|
21
|
+
*/
|
|
22
|
+
getBalance(walletProvider: SvmWalletProvider, args: z.infer<typeof GetBalanceSchema>): Promise<string>;
|
|
15
23
|
/**
|
|
16
24
|
* Transfer SPL tokens to another address.
|
|
17
25
|
*
|
|
@@ -27,6 +27,46 @@ class SplActionProvider extends actionProvider_1.ActionProvider {
|
|
|
27
27
|
constructor() {
|
|
28
28
|
super("spl", []);
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the balance of SPL tokens for an address.
|
|
32
|
+
*
|
|
33
|
+
* @param walletProvider - The wallet provider to use
|
|
34
|
+
* @param args - Parameters including mint address and optional target address
|
|
35
|
+
* @returns A message indicating the token balance
|
|
36
|
+
*/
|
|
37
|
+
async getBalance(walletProvider, args) {
|
|
38
|
+
try {
|
|
39
|
+
if (!args.address) {
|
|
40
|
+
args.address = walletProvider.getAddress();
|
|
41
|
+
}
|
|
42
|
+
const connection = walletProvider.getConnection();
|
|
43
|
+
const mintPubkey = new web3_js_1.PublicKey(args.mintAddress);
|
|
44
|
+
const ownerPubkey = new web3_js_1.PublicKey(args.address);
|
|
45
|
+
const { getMint, getAssociatedTokenAddress, getAccount, TokenAccountNotFoundError } = await import("@solana/spl-token");
|
|
46
|
+
let mintInfo;
|
|
47
|
+
try {
|
|
48
|
+
mintInfo = await getMint(connection, mintPubkey);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return `Failed to fetch mint info for mint address ${args.mintAddress}. Error: ${error}`;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const ata = await getAssociatedTokenAddress(mintPubkey, ownerPubkey);
|
|
55
|
+
const account = await getAccount(connection, ata);
|
|
56
|
+
const balance = Number(account.amount) / Math.pow(10, mintInfo.decimals);
|
|
57
|
+
return `Balance for ${args.address} is ${balance} tokens`;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof TokenAccountNotFoundError) {
|
|
61
|
+
return `Balance for ${args.address} is 0 tokens`;
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return `Error getting SPL token balance: ${error}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
30
70
|
/**
|
|
31
71
|
* Transfer SPL tokens to another address.
|
|
32
72
|
*
|
|
@@ -41,7 +81,13 @@ class SplActionProvider extends actionProvider_1.ActionProvider {
|
|
|
41
81
|
const toPubkey = new web3_js_1.PublicKey(args.recipient);
|
|
42
82
|
const mintPubkey = new web3_js_1.PublicKey(args.mintAddress);
|
|
43
83
|
const { getMint, getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, createTransferCheckedInstruction, } = await import("@solana/spl-token");
|
|
44
|
-
|
|
84
|
+
let mintInfo;
|
|
85
|
+
try {
|
|
86
|
+
mintInfo = await getMint(connection, mintPubkey);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return `Failed to fetch mint info for mint address ${args.mintAddress}. Error: ${error}`;
|
|
90
|
+
}
|
|
45
91
|
const adjustedAmount = args.amount * Math.pow(10, mintInfo.decimals);
|
|
46
92
|
const sourceAta = await getAssociatedTokenAddress(mintPubkey, fromPubkey);
|
|
47
93
|
const destinationAta = await getAssociatedTokenAddress(mintPubkey, toPubkey);
|
|
@@ -86,6 +132,21 @@ class SplActionProvider extends actionProvider_1.ActionProvider {
|
|
|
86
132
|
}
|
|
87
133
|
}
|
|
88
134
|
exports.SplActionProvider = SplActionProvider;
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, actionDecorator_1.CreateAction)({
|
|
137
|
+
name: "get_balance",
|
|
138
|
+
description: `
|
|
139
|
+
This tool will get the balance of SPL tokens for an address.
|
|
140
|
+
- Mint address must be a valid SPL token mint
|
|
141
|
+
- If no address is provided, uses the connected wallet's address
|
|
142
|
+
- Returns the token balance in token units (not raw)
|
|
143
|
+
`,
|
|
144
|
+
schema: schemas_1.GetBalanceSchema,
|
|
145
|
+
}),
|
|
146
|
+
__metadata("design:type", Function),
|
|
147
|
+
__metadata("design:paramtypes", [svmWalletProvider_1.SvmWalletProvider, void 0]),
|
|
148
|
+
__metadata("design:returntype", Promise)
|
|
149
|
+
], SplActionProvider.prototype, "getBalance", null);
|
|
89
150
|
__decorate([
|
|
90
151
|
(0, actionDecorator_1.CreateAction)({
|
|
91
152
|
name: "transfer",
|
|
@@ -16,13 +16,30 @@ jest.mock("@solana/web3.js", () => ({
|
|
|
16
16
|
compile: jest.fn().mockReturnValue({}),
|
|
17
17
|
},
|
|
18
18
|
}));
|
|
19
|
-
jest.mock("@solana/spl-token", () =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
jest.mock("@solana/spl-token", () => {
|
|
20
|
+
/**
|
|
21
|
+
* Custom error class for token account not found scenarios.
|
|
22
|
+
* Used to simulate cases where a token account doesn't exist.
|
|
23
|
+
*/
|
|
24
|
+
class TokenAccountNotFoundError extends Error {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new TokenAccountNotFoundError instance.
|
|
27
|
+
* Sets the error message and name to identify token account not found scenarios.
|
|
28
|
+
*/
|
|
29
|
+
constructor() {
|
|
30
|
+
super("Token account not found");
|
|
31
|
+
this.name = "TokenAccountNotFoundError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
getAssociatedTokenAddress: jest.fn(),
|
|
36
|
+
getMint: jest.fn(),
|
|
37
|
+
getAccount: jest.fn(),
|
|
38
|
+
createAssociatedTokenAccountInstruction: jest.fn(),
|
|
39
|
+
createTransferCheckedInstruction: jest.fn(),
|
|
40
|
+
TokenAccountNotFoundError,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
26
43
|
jest.mock("../../wallet-providers/svmWalletProvider");
|
|
27
44
|
describe("SplActionProvider", () => {
|
|
28
45
|
let actionProvider;
|
|
@@ -203,4 +220,81 @@ describe("SplActionProvider", () => {
|
|
|
203
220
|
expect(result).toContain(`Successfully transferred ${transferArgs.amount} tokens`);
|
|
204
221
|
});
|
|
205
222
|
});
|
|
223
|
+
/**
|
|
224
|
+
* Tests for the getBalance method
|
|
225
|
+
*/
|
|
226
|
+
describe("getBalance", () => {
|
|
227
|
+
const MINT_ADDRESS = "So11111111111111111111111111111111111111112";
|
|
228
|
+
const TARGET_ADDRESS = "DjXsn34uz8yCBQ8bevLrEPYYC1RvhHvjzuVF8opNc4K2";
|
|
229
|
+
const SENDER_ADDRESS = "11111111111111111111111111111111";
|
|
230
|
+
const balanceArgs = {
|
|
231
|
+
mintAddress: MINT_ADDRESS,
|
|
232
|
+
};
|
|
233
|
+
const balanceWithAddressArgs = {
|
|
234
|
+
mintAddress: MINT_ADDRESS,
|
|
235
|
+
address: TARGET_ADDRESS,
|
|
236
|
+
};
|
|
237
|
+
const mockTokenAccount = {
|
|
238
|
+
amount: BigInt(1000000000),
|
|
239
|
+
address: new web3_js_1.PublicKey(MINT_ADDRESS),
|
|
240
|
+
mint: new web3_js_1.PublicKey(MINT_ADDRESS),
|
|
241
|
+
owner: new web3_js_1.PublicKey(TARGET_ADDRESS),
|
|
242
|
+
delegate: null,
|
|
243
|
+
delegatedAmount: BigInt(0),
|
|
244
|
+
closeAuthority: null,
|
|
245
|
+
isFrozen: false,
|
|
246
|
+
isNative: false,
|
|
247
|
+
rentExemptReserve: null,
|
|
248
|
+
isInitialized: true,
|
|
249
|
+
tlvData: new Map(),
|
|
250
|
+
};
|
|
251
|
+
beforeEach(() => {
|
|
252
|
+
mockWallet.getPublicKey.mockReturnValue(new web3_js_1.PublicKey(SENDER_ADDRESS));
|
|
253
|
+
mockWallet.getAddress.mockReturnValue(SENDER_ADDRESS);
|
|
254
|
+
});
|
|
255
|
+
/**
|
|
256
|
+
* Tests that getBalance returns the correct balance for the connected wallet
|
|
257
|
+
* when no specific address is provided.
|
|
258
|
+
*/
|
|
259
|
+
it("should get balance for connected wallet", async () => {
|
|
260
|
+
mockGetAccount.mockResolvedValue(mockTokenAccount);
|
|
261
|
+
const result = await actionProvider.getBalance(mockWallet, balanceArgs);
|
|
262
|
+
expect(mockGetAssociatedTokenAddress).toHaveBeenCalledWith(new web3_js_1.PublicKey(balanceArgs.mintAddress), new web3_js_1.PublicKey(SENDER_ADDRESS));
|
|
263
|
+
expect(mockGetMint).toHaveBeenCalledWith(mockConnection, new web3_js_1.PublicKey(balanceArgs.mintAddress));
|
|
264
|
+
expect(mockGetAccount).toHaveBeenCalled();
|
|
265
|
+
expect(result).toBe(`Balance for ${SENDER_ADDRESS} is 1000 tokens`);
|
|
266
|
+
});
|
|
267
|
+
/**
|
|
268
|
+
* Tests that getBalance returns the correct balance when a specific
|
|
269
|
+
* address is provided in the arguments.
|
|
270
|
+
*/
|
|
271
|
+
it("should get balance for specified address", async () => {
|
|
272
|
+
mockGetAccount.mockResolvedValue(mockTokenAccount);
|
|
273
|
+
const result = await actionProvider.getBalance(mockWallet, balanceWithAddressArgs);
|
|
274
|
+
expect(mockGetAssociatedTokenAddress).toHaveBeenCalledWith(new web3_js_1.PublicKey(balanceWithAddressArgs.mintAddress), new web3_js_1.PublicKey(balanceWithAddressArgs.address));
|
|
275
|
+
expect(mockGetMint).toHaveBeenCalledWith(mockConnection, new web3_js_1.PublicKey(balanceWithAddressArgs.mintAddress));
|
|
276
|
+
expect(mockGetAccount).toHaveBeenCalled();
|
|
277
|
+
expect(result).toBe(`Balance for ${TARGET_ADDRESS} is 1000 tokens`);
|
|
278
|
+
});
|
|
279
|
+
/**
|
|
280
|
+
* Tests that getBalance correctly handles the case where a token account
|
|
281
|
+
* does not exist, returning a zero balance instead of an error.
|
|
282
|
+
*/
|
|
283
|
+
it("should handle non-existent token account", async () => {
|
|
284
|
+
const { TokenAccountNotFoundError } = jest.requireMock("@solana/spl-token");
|
|
285
|
+
mockGetAccount.mockRejectedValue(new TokenAccountNotFoundError());
|
|
286
|
+
const result = await actionProvider.getBalance(mockWallet, balanceArgs);
|
|
287
|
+
expect(result).toBe(`Balance for ${SENDER_ADDRESS} is 0 tokens`);
|
|
288
|
+
});
|
|
289
|
+
/**
|
|
290
|
+
* Tests that getBalance properly handles and reports unexpected errors
|
|
291
|
+
* that occur during the balance check.
|
|
292
|
+
*/
|
|
293
|
+
it("should handle errors", async () => {
|
|
294
|
+
const error = new Error("Test error");
|
|
295
|
+
mockGetAccount.mockRejectedValue(error);
|
|
296
|
+
const result = await actionProvider.getBalance(mockWallet, balanceArgs);
|
|
297
|
+
expect(result).toBe("Error getting SPL token balance: Error: Test error");
|
|
298
|
+
});
|
|
299
|
+
});
|
|
206
300
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GENERIC_TOKEN_METADATA_URI = exports.ADDRESSES = exports.WOW_FACTORY_CONTRACT_ADDRESSES = exports.WOW_ABI = exports.WOW_FACTORY_ABI = exports.SUPPORTED_NETWORKS = void 0;
|
|
4
4
|
exports.getFactoryAddress = getFactoryAddress;
|
|
5
|
-
exports.SUPPORTED_NETWORKS = ["base-mainnet"];
|
|
5
|
+
exports.SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
|
|
6
6
|
exports.WOW_FACTORY_ABI = [
|
|
7
7
|
{
|
|
8
8
|
type: "constructor",
|
|
@@ -14,11 +14,11 @@ export declare class WowActionProvider extends ActionProvider<EvmWalletProvider>
|
|
|
14
14
|
/**
|
|
15
15
|
* Buys a Zora Wow ERC20 memecoin with ETH.
|
|
16
16
|
*
|
|
17
|
-
* @param
|
|
17
|
+
* @param walletProvider - The wallet to create the token from.
|
|
18
18
|
* @param args - The input arguments for the action.
|
|
19
19
|
* @returns A message containing the token purchase details.
|
|
20
20
|
*/
|
|
21
|
-
buyToken(
|
|
21
|
+
buyToken(walletProvider: EvmWalletProvider, args: z.infer<typeof WowBuyTokenInput>): Promise<string>;
|
|
22
22
|
/**
|
|
23
23
|
* Creates a Zora Wow ERC20 memecoin.
|
|
24
24
|
*
|
|
@@ -30,11 +30,11 @@ export declare class WowActionProvider extends ActionProvider<EvmWalletProvider>
|
|
|
30
30
|
/**
|
|
31
31
|
* Sells WOW tokens for ETH.
|
|
32
32
|
*
|
|
33
|
-
* @param
|
|
33
|
+
* @param walletProvider - The wallet to sell the tokens from.
|
|
34
34
|
* @param args - The input arguments for the action.
|
|
35
35
|
* @returns A message confirming the sale with the transaction hash.
|
|
36
36
|
*/
|
|
37
|
-
sellToken(
|
|
37
|
+
sellToken(walletProvider: EvmWalletProvider, args: z.infer<typeof WowSellTokenInput>): Promise<string>;
|
|
38
38
|
/**
|
|
39
39
|
* Checks if the Wow action provider supports the given network.
|
|
40
40
|
*
|
|
@@ -39,22 +39,22 @@ class WowActionProvider extends actionProvider_1.ActionProvider {
|
|
|
39
39
|
/**
|
|
40
40
|
* Buys a Zora Wow ERC20 memecoin with ETH.
|
|
41
41
|
*
|
|
42
|
-
* @param
|
|
42
|
+
* @param walletProvider - The wallet to create the token from.
|
|
43
43
|
* @param args - The input arguments for the action.
|
|
44
44
|
* @returns A message containing the token purchase details.
|
|
45
45
|
*/
|
|
46
|
-
async buyToken(
|
|
46
|
+
async buyToken(walletProvider, args) {
|
|
47
47
|
try {
|
|
48
|
-
const tokenQuote = await (0, utils_1.getBuyQuote)(
|
|
48
|
+
const tokenQuote = await (0, utils_1.getBuyQuote)(walletProvider, args.contractAddress, args.amountEthInWei);
|
|
49
49
|
// Multiply by 99/100 and floor to get 99% of quote as minimum
|
|
50
50
|
const minTokens = BigInt(Math.floor(Number(tokenQuote) * 99)) / BigInt(100);
|
|
51
|
-
const hasGraduated = await (0, utils_2.getHasGraduated)(
|
|
51
|
+
const hasGraduated = await (0, utils_2.getHasGraduated)(walletProvider, args.contractAddress);
|
|
52
52
|
const data = (0, viem_1.encodeFunctionData)({
|
|
53
53
|
abi: constants_1.WOW_ABI,
|
|
54
54
|
functionName: "buy",
|
|
55
55
|
args: [
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
walletProvider.getAddress(),
|
|
57
|
+
walletProvider.getAddress(),
|
|
58
58
|
"0x0000000000000000000000000000000000000000",
|
|
59
59
|
"",
|
|
60
60
|
hasGraduated ? 1n : 0n,
|
|
@@ -62,13 +62,13 @@ class WowActionProvider extends actionProvider_1.ActionProvider {
|
|
|
62
62
|
0n,
|
|
63
63
|
],
|
|
64
64
|
});
|
|
65
|
-
const txHash = await
|
|
65
|
+
const txHash = await walletProvider.sendTransaction({
|
|
66
66
|
to: args.contractAddress,
|
|
67
67
|
data,
|
|
68
68
|
value: BigInt(args.amountEthInWei),
|
|
69
69
|
});
|
|
70
|
-
|
|
71
|
-
return `Purchased WoW ERC20 memecoin with transaction hash: ${txHash}
|
|
70
|
+
await walletProvider.waitForTransactionReceipt(txHash);
|
|
71
|
+
return `Purchased WoW ERC20 memecoin with transaction hash: ${txHash}`;
|
|
72
72
|
}
|
|
73
73
|
catch (error) {
|
|
74
74
|
return `Error buying Zora Wow ERC20 memecoin: ${error}`;
|
|
@@ -99,8 +99,8 @@ class WowActionProvider extends actionProvider_1.ActionProvider {
|
|
|
99
99
|
to: factoryAddress,
|
|
100
100
|
data,
|
|
101
101
|
});
|
|
102
|
-
|
|
103
|
-
return `Created WoW ERC20 memecoin ${args.name} with symbol ${args.symbol} on network ${wallet.getNetwork().networkId}.\nTransaction hash
|
|
102
|
+
await wallet.waitForTransactionReceipt(txHash);
|
|
103
|
+
return `Created WoW ERC20 memecoin ${args.name} with symbol ${args.symbol} on network ${wallet.getNetwork().networkId}.\nTransaction hash: ${txHash}`;
|
|
104
104
|
}
|
|
105
105
|
catch (error) {
|
|
106
106
|
return `Error creating Zora Wow ERC20 memecoin: ${error}`;
|
|
@@ -109,14 +109,14 @@ class WowActionProvider extends actionProvider_1.ActionProvider {
|
|
|
109
109
|
/**
|
|
110
110
|
* Sells WOW tokens for ETH.
|
|
111
111
|
*
|
|
112
|
-
* @param
|
|
112
|
+
* @param walletProvider - The wallet to sell the tokens from.
|
|
113
113
|
* @param args - The input arguments for the action.
|
|
114
114
|
* @returns A message confirming the sale with the transaction hash.
|
|
115
115
|
*/
|
|
116
|
-
async sellToken(
|
|
116
|
+
async sellToken(walletProvider, args) {
|
|
117
117
|
try {
|
|
118
|
-
const ethQuote = await (0, utils_1.getSellQuote)(
|
|
119
|
-
const hasGraduated = await (0, utils_2.getHasGraduated)(
|
|
118
|
+
const ethQuote = await (0, utils_1.getSellQuote)(walletProvider, args.contractAddress, args.amountTokensInWei);
|
|
119
|
+
const hasGraduated = await (0, utils_2.getHasGraduated)(walletProvider, args.contractAddress);
|
|
120
120
|
// Multiply by 98/100 and floor to get 98% of quote as minimum
|
|
121
121
|
const minEth = BigInt(Math.floor(Number(ethQuote) * 98)) / BigInt(100);
|
|
122
122
|
const data = (0, viem_1.encodeFunctionData)({
|
|
@@ -124,7 +124,7 @@ class WowActionProvider extends actionProvider_1.ActionProvider {
|
|
|
124
124
|
functionName: "sell",
|
|
125
125
|
args: [
|
|
126
126
|
BigInt(args.amountTokensInWei),
|
|
127
|
-
|
|
127
|
+
walletProvider.getAddress(),
|
|
128
128
|
"0x0000000000000000000000000000000000000000",
|
|
129
129
|
"",
|
|
130
130
|
hasGraduated ? 1n : 0n,
|
|
@@ -132,12 +132,12 @@ class WowActionProvider extends actionProvider_1.ActionProvider {
|
|
|
132
132
|
0n,
|
|
133
133
|
],
|
|
134
134
|
});
|
|
135
|
-
const txHash = await
|
|
135
|
+
const txHash = await walletProvider.sendTransaction({
|
|
136
136
|
to: args.contractAddress,
|
|
137
137
|
data,
|
|
138
138
|
});
|
|
139
|
-
|
|
140
|
-
return `Sold WoW ERC20 memecoin with transaction hash: ${txHash}
|
|
139
|
+
await walletProvider.waitForTransactionReceipt(txHash);
|
|
140
|
+
return `Sold WoW ERC20 memecoin with transaction hash: ${txHash}`;
|
|
141
141
|
}
|
|
142
142
|
catch (error) {
|
|
143
143
|
return `Error selling Zora Wow ERC20 memecoin: ${error}`;
|
|
@@ -142,13 +142,17 @@ describe("WowActionProvider", () => {
|
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
describe("supportsNetwork", () => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
const testCases = [
|
|
146
|
+
{ network: { protocolFamily: "evm", networkId: "base-mainnet" }, expected: true },
|
|
147
|
+
{ network: { protocolFamily: "evm", networkId: "base-sepolia" }, expected: true },
|
|
148
|
+
{ network: { protocolFamily: "evm", networkId: "ethereum" }, expected: false },
|
|
149
|
+
{ network: { protocolFamily: "evm", networkId: "optimism" }, expected: false },
|
|
150
|
+
{ network: { protocolFamily: "bitcoin", networkId: "base-mainnet" }, expected: false },
|
|
151
|
+
];
|
|
152
|
+
testCases.forEach(({ network, expected }) => {
|
|
153
|
+
it(`should ${expected ? "support" : "not support"} ${network.protocolFamily}/${network.networkId}`, () => {
|
|
154
|
+
expect(provider.supportsNetwork(network)).toBe(expected);
|
|
155
|
+
});
|
|
152
156
|
});
|
|
153
157
|
});
|
|
154
158
|
describe("buyToken", () => {
|
|
@@ -186,7 +190,7 @@ describe("WowActionProvider", () => {
|
|
|
186
190
|
const error = new Error("Buy failed");
|
|
187
191
|
mockWallet.sendTransaction.mockRejectedValue(error);
|
|
188
192
|
const response = await provider.buyToken(mockWallet, args);
|
|
189
|
-
expect(response).
|
|
193
|
+
expect(response).toBe(`Error buying Zora Wow ERC20 memecoin: ${error}`);
|
|
190
194
|
});
|
|
191
195
|
});
|
|
192
196
|
describe("createToken", () => {
|
|
@@ -244,7 +248,7 @@ describe("WowActionProvider", () => {
|
|
|
244
248
|
const error = new Error("Create failed");
|
|
245
249
|
mockWallet.sendTransaction.mockRejectedValue(error);
|
|
246
250
|
const response = await provider.createToken(mockWallet, args);
|
|
247
|
-
expect(response).
|
|
251
|
+
expect(response).toBe(`Error creating Zora Wow ERC20 memecoin: ${error}`);
|
|
248
252
|
});
|
|
249
253
|
});
|
|
250
254
|
describe("sellToken", () => {
|
|
@@ -281,7 +285,7 @@ describe("WowActionProvider", () => {
|
|
|
281
285
|
const error = new Error("Sell failed");
|
|
282
286
|
mockWallet.sendTransaction.mockRejectedValue(error);
|
|
283
287
|
const response = await provider.sellToken(mockWallet, args);
|
|
284
|
-
expect(response).
|
|
288
|
+
expect(response).toBe(`Error selling Zora Wow ERC20 memecoin: ${error}`);
|
|
285
289
|
});
|
|
286
290
|
});
|
|
287
291
|
});
|
package/dist/network/svm.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export declare const SOLANA_MAINNET_NETWORK: Network;
|
|
|
12
12
|
export declare const SOLANA_TESTNET_NETWORK: Network;
|
|
13
13
|
export declare const SOLANA_DEVNET_NETWORK: Network;
|
|
14
14
|
export declare const SOLANA_NETWORKS: Record<SOLANA_CLUSTER, Network>;
|
|
15
|
+
export declare const SOLANA_CLUSTER_ID_BY_NETWORK_ID: Record<SOLANA_NETWORK_ID, string>;
|
package/dist/network/svm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SOLANA_NETWORKS = exports.SOLANA_DEVNET_NETWORK = exports.SOLANA_TESTNET_NETWORK = exports.SOLANA_MAINNET_NETWORK = exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH = exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH = exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH = exports.SOLANA_PROTOCOL_FAMILY = exports.SOLANA_DEVNET_NETWORK_ID = exports.SOLANA_TESTNET_NETWORK_ID = exports.SOLANA_MAINNET_NETWORK_ID = void 0;
|
|
3
|
+
exports.SOLANA_CLUSTER_ID_BY_NETWORK_ID = exports.SOLANA_NETWORKS = exports.SOLANA_DEVNET_NETWORK = exports.SOLANA_TESTNET_NETWORK = exports.SOLANA_MAINNET_NETWORK = exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH = exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH = exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH = exports.SOLANA_PROTOCOL_FAMILY = exports.SOLANA_DEVNET_NETWORK_ID = exports.SOLANA_TESTNET_NETWORK_ID = exports.SOLANA_MAINNET_NETWORK_ID = void 0;
|
|
4
4
|
// CDP Network IDs
|
|
5
5
|
exports.SOLANA_MAINNET_NETWORK_ID = "solana-mainnet";
|
|
6
6
|
exports.SOLANA_TESTNET_NETWORK_ID = "solana-testnet";
|
|
@@ -31,3 +31,8 @@ exports.SOLANA_NETWORKS = {
|
|
|
31
31
|
[exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH]: exports.SOLANA_TESTNET_NETWORK,
|
|
32
32
|
[exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH]: exports.SOLANA_DEVNET_NETWORK,
|
|
33
33
|
};
|
|
34
|
+
exports.SOLANA_CLUSTER_ID_BY_NETWORK_ID = {
|
|
35
|
+
[exports.SOLANA_MAINNET_NETWORK_ID]: "mainnet-beta",
|
|
36
|
+
[exports.SOLANA_TESTNET_NETWORK_ID]: "testnet",
|
|
37
|
+
[exports.SOLANA_DEVNET_NETWORK_ID]: "devnet",
|
|
38
|
+
};
|
|
@@ -58,7 +58,7 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
58
58
|
if (config.apiKeyName && config.apiKeyPrivateKey) {
|
|
59
59
|
coinbase_sdk_1.Coinbase.configure({
|
|
60
60
|
apiKeyName: config.apiKeyName,
|
|
61
|
-
privateKey: config.apiKeyPrivateKey,
|
|
61
|
+
privateKey: config.apiKeyPrivateKey?.replace(/\\n/g, "\n"),
|
|
62
62
|
source: "agentkit",
|
|
63
63
|
sourceVersion: package_json_1.version,
|
|
64
64
|
});
|
|
@@ -21,3 +21,5 @@ __exportStar(require("./cdpWalletProvider"), exports);
|
|
|
21
21
|
__exportStar(require("./svmWalletProvider"), exports);
|
|
22
22
|
__exportStar(require("./solanaKeypairWalletProvider"), exports);
|
|
23
23
|
__exportStar(require("./privyWalletProvider"), exports);
|
|
24
|
+
__exportStar(require("./privyEvmWalletProvider"), exports);
|
|
25
|
+
__exportStar(require("./privySvmWalletProvider"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ViemWalletProvider } from "./viemWalletProvider";
|
|
2
|
+
import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the Privy wallet provider.
|
|
5
|
+
*
|
|
6
|
+
* @interface
|
|
7
|
+
*/
|
|
8
|
+
export interface PrivyEvmWalletConfig extends PrivyWalletConfig {
|
|
9
|
+
/** Optional chain ID to connect to */
|
|
10
|
+
chainId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
14
|
+
* This provider extends the ViemWalletProvider to provide Privy-specific wallet functionality
|
|
15
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
16
|
+
*/
|
|
17
|
+
export declare class PrivyEvmWalletProvider extends ViemWalletProvider {
|
|
18
|
+
#private;
|
|
19
|
+
/**
|
|
20
|
+
* Private constructor to enforce use of factory method.
|
|
21
|
+
*
|
|
22
|
+
* @param walletClient - The Viem wallet client instance
|
|
23
|
+
* @param config - The configuration options for the Privy wallet
|
|
24
|
+
*/
|
|
25
|
+
private constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Creates and configures a new PrivyWalletProvider instance.
|
|
28
|
+
*
|
|
29
|
+
* @param config - The configuration options for the Privy wallet
|
|
30
|
+
* @returns A configured PrivyWalletProvider instance
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const provider = await PrivyWalletProvider.configureWithWallet({
|
|
35
|
+
* appId: "your-app-id",
|
|
36
|
+
* appSecret: "your-app-secret",
|
|
37
|
+
* walletId: "wallet-id",
|
|
38
|
+
* chainId: "84532"
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static configureWithWallet(config: PrivyEvmWalletConfig): Promise<PrivyEvmWalletProvider>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the name of the wallet provider.
|
|
45
|
+
*
|
|
46
|
+
* @returns The string identifier for this wallet provider
|
|
47
|
+
*/
|
|
48
|
+
getName(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Exports the wallet data.
|
|
51
|
+
*
|
|
52
|
+
* @returns The wallet data
|
|
53
|
+
*/
|
|
54
|
+
exportWallet(): PrivyWalletExport;
|
|
55
|
+
}
|