@coinbase/agentkit 0.0.0-nightly-20250820210426 → 0.0.0-nightly-20250822210413
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 +37 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -11
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -65
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +17 -1
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +219 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +270 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -1
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +220 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +254 -0
- package/dist/action-providers/cdp/schemas.d.ts +12 -12
- package/dist/action-providers/cdp/schemas.js +17 -5
- package/dist/action-providers/cdp/swapUtils.d.ts +32 -0
- package/dist/action-providers/cdp/swapUtils.js +142 -0
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/jupiter/schemas.d.ts +1 -1
- package/dist/action-providers/superfluid/constants.d.ts +814 -0
- package/dist/action-providers/superfluid/constants.js +2826 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
- package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
- package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
- package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
- package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
- package/dist/action-providers/superfluid/index.d.ts +7 -0
- package/dist/action-providers/superfluid/index.js +23 -0
- package/dist/action-providers/superfluid/schemas.d.ts +86 -0
- package/dist/action-providers/superfluid/schemas.js +103 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +108 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +18 -0
- package/dist/action-providers/superfluid/utils/parseLogs.js +78 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +3 -2
- package/dist/wallet-providers/cdpSmartWalletProvider.js +4 -5
- package/dist/wallet-providers/viemWalletProvider.d.ts +4 -0
- package/dist/wallet-providers/viemWalletProvider.js +2 -1
- package/package.json +3 -2
|
@@ -0,0 +1,108 @@
|
|
|
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.superfluidSuperTokenCreatorActionProvider = exports.SuperfluidSuperTokenCreatorActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const schemas_1 = require("./schemas");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const viem_1 = require("viem");
|
|
17
|
+
const actionProvider_1 = require("../actionProvider");
|
|
18
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
19
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
20
|
+
const constants_2 = require("../erc20/constants");
|
|
21
|
+
const parseLogs_1 = require("./utils/parseLogs");
|
|
22
|
+
/**
|
|
23
|
+
* SuperfluidSuperTokenCreatorActionProvider is an action provider for Superfluid interactions.
|
|
24
|
+
*/
|
|
25
|
+
class SuperfluidSuperTokenCreatorActionProvider extends actionProvider_1.ActionProvider {
|
|
26
|
+
/**
|
|
27
|
+
* Constructor for the SuperfluidSuperTokenCreatorActionProvider class.
|
|
28
|
+
*/
|
|
29
|
+
constructor() {
|
|
30
|
+
super("superfluid-super-token-creator", []);
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the Superfluid action provider supports the given network.
|
|
33
|
+
*
|
|
34
|
+
* @param network - The network to check.
|
|
35
|
+
* @returns True if the Superfluid action provider supports the network, false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
this.supportsNetwork = (network) => network.networkId === "base-mainnet" || network.networkId === "base-sepolia";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new Super token
|
|
41
|
+
*
|
|
42
|
+
* @param walletProvider - The wallet provider to start the stream from.
|
|
43
|
+
* @param args - The input arguments for the action.
|
|
44
|
+
* @returns A JSON string containing the account details or error message
|
|
45
|
+
*/
|
|
46
|
+
async createSuperToken(walletProvider, args) {
|
|
47
|
+
try {
|
|
48
|
+
const decimals = await walletProvider.readContract({
|
|
49
|
+
address: args.erc20TokenAddress,
|
|
50
|
+
abi: constants_2.abi,
|
|
51
|
+
functionName: "decimals",
|
|
52
|
+
args: [],
|
|
53
|
+
});
|
|
54
|
+
const name = await walletProvider.readContract({
|
|
55
|
+
address: args.erc20TokenAddress,
|
|
56
|
+
abi: constants_2.abi,
|
|
57
|
+
functionName: "name",
|
|
58
|
+
args: [],
|
|
59
|
+
});
|
|
60
|
+
const symbol = await walletProvider.readContract({
|
|
61
|
+
address: args.erc20TokenAddress,
|
|
62
|
+
abi: constants_2.abi,
|
|
63
|
+
functionName: "symbol",
|
|
64
|
+
args: [],
|
|
65
|
+
});
|
|
66
|
+
const createSuperTokenData = (0, viem_1.encodeFunctionData)({
|
|
67
|
+
abi: constants_1.SuperTokenFactoryABI,
|
|
68
|
+
functionName: "createERC20Wrapper",
|
|
69
|
+
args: [
|
|
70
|
+
args.erc20TokenAddress,
|
|
71
|
+
decimals,
|
|
72
|
+
2, // upgradeable
|
|
73
|
+
`Super ${name}`,
|
|
74
|
+
`${symbol}x`,
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
const createSuperTokenHash = await walletProvider.sendTransaction({
|
|
78
|
+
to: walletProvider.getNetwork().networkId === "base-sepolia"
|
|
79
|
+
? constants_1.SuperTokenFactoryAddress_Base_Sepolia
|
|
80
|
+
: constants_1.SuperTokenFactoryAddress,
|
|
81
|
+
data: createSuperTokenData,
|
|
82
|
+
});
|
|
83
|
+
const receipt = await walletProvider.waitForTransactionReceipt(createSuperTokenHash);
|
|
84
|
+
const superTokenAddress = (0, parseLogs_1.extractCreatedSuperTokenAddressAbi)(receipt);
|
|
85
|
+
return `Created super token for ${args.erc20TokenAddress}. Super token address at ${superTokenAddress} Transaction hash: ${createSuperTokenHash}`;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return `Error creating Superfluid Super Token: ${error}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.SuperfluidSuperTokenCreatorActionProvider = SuperfluidSuperTokenCreatorActionProvider;
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, actionDecorator_1.CreateAction)({
|
|
95
|
+
name: "create_super_token",
|
|
96
|
+
description: `
|
|
97
|
+
This action will create a Super token, essentially a wrapper token around an ERC20 that can freely stream between wallets.
|
|
98
|
+
It will return the address of the newly created Supertoken.
|
|
99
|
+
You should only take this action when requested. A Supertoken implementation is needed to stream tokens or to wrap an ERC20 token.
|
|
100
|
+
`,
|
|
101
|
+
schema: schemas_1.SuperfluidCreateSuperTokenSchema,
|
|
102
|
+
}),
|
|
103
|
+
__metadata("design:type", Function),
|
|
104
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
105
|
+
__metadata("design:returntype", Promise)
|
|
106
|
+
], SuperfluidSuperTokenCreatorActionProvider.prototype, "createSuperToken", null);
|
|
107
|
+
const superfluidSuperTokenCreatorActionProvider = () => new SuperfluidSuperTokenCreatorActionProvider();
|
|
108
|
+
exports.superfluidSuperTokenCreatorActionProvider = superfluidSuperTokenCreatorActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const viem_1 = require("viem");
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const superfluidSuperTokenCreatorActionProvider_1 = require("./superfluidSuperTokenCreatorActionProvider");
|
|
6
|
+
describe("SuperfluidSuperTokenCreatorActionProvider", () => {
|
|
7
|
+
const MOCK_ADDRESS = "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83";
|
|
8
|
+
const MOCK_ERC20_CONTRACT = "0x1234567890123456789012345678901234567890";
|
|
9
|
+
const MOCK_DECIMALS = 18;
|
|
10
|
+
const MOCK_NAME = "TestToken";
|
|
11
|
+
const MOCK_SYMBOL = "TT";
|
|
12
|
+
let mockWallet;
|
|
13
|
+
const actionProvider = (0, superfluidSuperTokenCreatorActionProvider_1.superfluidSuperTokenCreatorActionProvider)();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
mockWallet = {
|
|
16
|
+
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
17
|
+
getNetwork: jest.fn().mockReturnValue({ protocolFamily: "evm" }),
|
|
18
|
+
sendTransaction: jest.fn(),
|
|
19
|
+
waitForTransactionReceipt: jest.fn(),
|
|
20
|
+
readContract: jest.fn(),
|
|
21
|
+
call: jest.fn(),
|
|
22
|
+
};
|
|
23
|
+
mockWallet.sendTransaction.mockResolvedValue("0xmockhash");
|
|
24
|
+
mockWallet.waitForTransactionReceipt.mockResolvedValue({});
|
|
25
|
+
mockWallet.readContract.mockImplementation(async ({ address, functionName, args }) => {
|
|
26
|
+
if (functionName === "decimals")
|
|
27
|
+
return MOCK_DECIMALS;
|
|
28
|
+
if (functionName === "name")
|
|
29
|
+
return MOCK_NAME;
|
|
30
|
+
if (functionName === "symbol")
|
|
31
|
+
return MOCK_SYMBOL;
|
|
32
|
+
throw new Error(`No mock for ${functionName}(${JSON.stringify(args)}) @ ${address}`);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("create super token", () => {
|
|
36
|
+
it("should successfully create a superfluid super token", async () => {
|
|
37
|
+
const args = {
|
|
38
|
+
erc20TokenAddress: MOCK_ERC20_CONTRACT,
|
|
39
|
+
};
|
|
40
|
+
await actionProvider.createSuperToken(mockWallet, args);
|
|
41
|
+
const createSuperTokenData = (0, viem_1.encodeFunctionData)({
|
|
42
|
+
abi: constants_1.SuperTokenFactoryABI,
|
|
43
|
+
functionName: "createERC20Wrapper",
|
|
44
|
+
args: [
|
|
45
|
+
args.erc20TokenAddress,
|
|
46
|
+
MOCK_DECIMALS,
|
|
47
|
+
2, // upgradeable
|
|
48
|
+
`Super ${MOCK_NAME}`,
|
|
49
|
+
`${MOCK_SYMBOL}x`,
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
|
|
53
|
+
to: constants_1.SuperTokenFactoryAddress,
|
|
54
|
+
data: createSuperTokenData,
|
|
55
|
+
});
|
|
56
|
+
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith("0xmockhash");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("supportsNetwork", () => {
|
|
60
|
+
it("should return true for Base", () => {
|
|
61
|
+
const result = actionProvider.supportsNetwork({
|
|
62
|
+
protocolFamily: "evm",
|
|
63
|
+
networkId: "base-mainnet",
|
|
64
|
+
});
|
|
65
|
+
expect(result).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
it("should return false for non-base networks", () => {
|
|
68
|
+
const result = actionProvider.supportsNetwork({
|
|
69
|
+
protocolFamily: "bitcoin",
|
|
70
|
+
networkId: "any",
|
|
71
|
+
});
|
|
72
|
+
expect(result).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SuperfluidWrapTokenSchema } from "./schemas";
|
|
3
|
+
import { ActionProvider } from "../actionProvider";
|
|
4
|
+
import { Network } from "../../network";
|
|
5
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
6
|
+
/**
|
|
7
|
+
* SuperfluidStreamActionProvider is an action provider for wrapping superfluid token.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SuperfluidWrapperActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor for the SuperfluidWrapperActionProvider class.
|
|
12
|
+
*/
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a token to a Super token
|
|
16
|
+
* The Super token must already exist
|
|
17
|
+
* If it does not, see SuperfluidCreateSuperTokenAction
|
|
18
|
+
*
|
|
19
|
+
* @param walletProvider - The wallet provider to start the stream from.
|
|
20
|
+
* @param args - The input arguments for the action.
|
|
21
|
+
* @returns A JSON string containing the account details or error message
|
|
22
|
+
*/
|
|
23
|
+
wrapToken(walletProvider: EvmWalletProvider, args: z.infer<typeof SuperfluidWrapTokenSchema>): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the Superfluid action provider supports the given network.
|
|
26
|
+
*
|
|
27
|
+
* @param network - The network to check.
|
|
28
|
+
* @returns True if the Superfluid action provider supports the network, false otherwise.
|
|
29
|
+
*/
|
|
30
|
+
supportsNetwork: (network: Network) => boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare const superfluidWrapperActionProvider: () => SuperfluidWrapperActionProvider;
|
|
@@ -0,0 +1,101 @@
|
|
|
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.superfluidWrapperActionProvider = exports.SuperfluidWrapperActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const schemas_1 = require("./schemas");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const viem_1 = require("viem");
|
|
17
|
+
const actionProvider_1 = require("../actionProvider");
|
|
18
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
19
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
20
|
+
const constants_2 = require("../erc20/constants");
|
|
21
|
+
/**
|
|
22
|
+
* SuperfluidStreamActionProvider is an action provider for wrapping superfluid token.
|
|
23
|
+
*/
|
|
24
|
+
class SuperfluidWrapperActionProvider extends actionProvider_1.ActionProvider {
|
|
25
|
+
/**
|
|
26
|
+
* Constructor for the SuperfluidWrapperActionProvider class.
|
|
27
|
+
*/
|
|
28
|
+
constructor() {
|
|
29
|
+
super("superfluid-wrap", []);
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the Superfluid action provider supports the given network.
|
|
32
|
+
*
|
|
33
|
+
* @param network - The network to check.
|
|
34
|
+
* @returns True if the Superfluid action provider supports the network, false otherwise.
|
|
35
|
+
*/
|
|
36
|
+
this.supportsNetwork = (network) => network.networkId === "base-mainnet" || network.networkId === "base-sepolia";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Wraps a token to a Super token
|
|
40
|
+
* The Super token must already exist
|
|
41
|
+
* If it does not, see SuperfluidCreateSuperTokenAction
|
|
42
|
+
*
|
|
43
|
+
* @param walletProvider - The wallet provider to start the stream from.
|
|
44
|
+
* @param args - The input arguments for the action.
|
|
45
|
+
* @returns A JSON string containing the account details or error message
|
|
46
|
+
*/
|
|
47
|
+
async wrapToken(walletProvider, args) {
|
|
48
|
+
try {
|
|
49
|
+
const decimals = await walletProvider.readContract({
|
|
50
|
+
address: args.erc20TokenAddress,
|
|
51
|
+
abi: constants_2.abi,
|
|
52
|
+
functionName: "decimals",
|
|
53
|
+
args: [],
|
|
54
|
+
});
|
|
55
|
+
const amount = (0, viem_1.parseUnits)(String(args.wrapAmount), Number(decimals));
|
|
56
|
+
const approveData = (0, viem_1.encodeFunctionData)({
|
|
57
|
+
abi: constants_2.abi,
|
|
58
|
+
functionName: "approve",
|
|
59
|
+
args: [args.superTokenAddress, amount],
|
|
60
|
+
});
|
|
61
|
+
const approveHash = await walletProvider.sendTransaction({
|
|
62
|
+
to: args.erc20TokenAddress,
|
|
63
|
+
data: approveData,
|
|
64
|
+
});
|
|
65
|
+
await walletProvider.waitForTransactionReceipt(approveHash);
|
|
66
|
+
const wrapData = (0, viem_1.encodeFunctionData)({
|
|
67
|
+
abi: constants_1.ISuperTokenAbi,
|
|
68
|
+
functionName: "upgrade",
|
|
69
|
+
args: [amount],
|
|
70
|
+
});
|
|
71
|
+
const wrapHash = await walletProvider.sendTransaction({
|
|
72
|
+
to: args.superTokenAddress,
|
|
73
|
+
data: wrapData,
|
|
74
|
+
});
|
|
75
|
+
await walletProvider.waitForTransactionReceipt(wrapHash);
|
|
76
|
+
return `Wrapped ${args.wrapAmount} of token ${args.erc20TokenAddress} as a SuperToken. Transaction hash: ${wrapHash}`;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return `Error wrapping Superfluid token: ${error}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.SuperfluidWrapperActionProvider = SuperfluidWrapperActionProvider;
|
|
84
|
+
__decorate([
|
|
85
|
+
(0, actionDecorator_1.CreateAction)({
|
|
86
|
+
name: "wrap_superfluid_token",
|
|
87
|
+
description: `
|
|
88
|
+
This tool will directly wrap an amount of ERC20 tokens into its corresponding Super token.
|
|
89
|
+
The user must provide the erc20 address, and the super token address.
|
|
90
|
+
If this fails, the most likely culprits are:
|
|
91
|
+
1. You don't own any of the ERC20 token, or
|
|
92
|
+
2. The Super token does not exist. If it does not exist, suggest the user create the Super token with your SuperTokenCreator action.
|
|
93
|
+
`,
|
|
94
|
+
schema: schemas_1.SuperfluidWrapTokenSchema,
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
98
|
+
__metadata("design:returntype", Promise)
|
|
99
|
+
], SuperfluidWrapperActionProvider.prototype, "wrapToken", null);
|
|
100
|
+
const superfluidWrapperActionProvider = () => new SuperfluidWrapperActionProvider();
|
|
101
|
+
exports.superfluidWrapperActionProvider = superfluidWrapperActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const viem_1 = require("viem");
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const superfluidWrapperActionProvider_1 = require("./superfluidWrapperActionProvider");
|
|
6
|
+
const constants_2 = require("../erc20/constants");
|
|
7
|
+
describe("SuperfluidWrapperActionProvider", () => {
|
|
8
|
+
const MOCK_ADDRESS = "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83";
|
|
9
|
+
const MOCK_ERC20_CONTRACT = "0x1234567890123456789012345678901234567890";
|
|
10
|
+
const MOCK_SUPERTOKEN_CONTRACT = "0x1234567890123456789012345678901234567890";
|
|
11
|
+
const MOCK_WRAP_AMOUNT = 100;
|
|
12
|
+
const MOCK_DECIMALS = 18;
|
|
13
|
+
const MOCK_NAME = "TestToken";
|
|
14
|
+
const MOCK_SYMBOL = "TT";
|
|
15
|
+
let mockWallet;
|
|
16
|
+
const actionProvider = (0, superfluidWrapperActionProvider_1.superfluidWrapperActionProvider)();
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockWallet = {
|
|
19
|
+
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
20
|
+
getNetwork: jest.fn().mockReturnValue({ protocolFamily: "evm" }),
|
|
21
|
+
sendTransaction: jest.fn(),
|
|
22
|
+
waitForTransactionReceipt: jest.fn(),
|
|
23
|
+
readContract: jest.fn(),
|
|
24
|
+
call: jest.fn(),
|
|
25
|
+
};
|
|
26
|
+
mockWallet.sendTransaction.mockResolvedValue("0xmockhash");
|
|
27
|
+
mockWallet.waitForTransactionReceipt.mockResolvedValue({});
|
|
28
|
+
mockWallet.readContract.mockImplementation(async ({ address, functionName, args }) => {
|
|
29
|
+
if (functionName === "decimals")
|
|
30
|
+
return MOCK_DECIMALS;
|
|
31
|
+
if (functionName === "name")
|
|
32
|
+
return MOCK_NAME;
|
|
33
|
+
if (functionName === "symbol")
|
|
34
|
+
return MOCK_SYMBOL;
|
|
35
|
+
throw new Error(`No mock for ${functionName}(${JSON.stringify(args)}) @ ${address}`);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("wraps an erc20 into a super token", () => {
|
|
39
|
+
it("should successfully wrap an erc20 to a super token", async () => {
|
|
40
|
+
const args = {
|
|
41
|
+
erc20TokenAddress: MOCK_ERC20_CONTRACT,
|
|
42
|
+
superTokenAddress: MOCK_SUPERTOKEN_CONTRACT,
|
|
43
|
+
wrapAmount: MOCK_WRAP_AMOUNT,
|
|
44
|
+
};
|
|
45
|
+
await actionProvider.wrapToken(mockWallet, args);
|
|
46
|
+
const amount = (0, viem_1.parseUnits)(String(args.wrapAmount), Number(MOCK_DECIMALS));
|
|
47
|
+
const approveData = (0, viem_1.encodeFunctionData)({
|
|
48
|
+
abi: constants_2.abi,
|
|
49
|
+
functionName: "approve",
|
|
50
|
+
args: [MOCK_SUPERTOKEN_CONTRACT, amount],
|
|
51
|
+
});
|
|
52
|
+
const wrapData = (0, viem_1.encodeFunctionData)({
|
|
53
|
+
abi: constants_1.ISuperTokenAbi,
|
|
54
|
+
functionName: "upgrade",
|
|
55
|
+
args: [amount],
|
|
56
|
+
});
|
|
57
|
+
expect(mockWallet.sendTransaction).toHaveBeenCalledTimes(2);
|
|
58
|
+
expect(mockWallet.sendTransaction).toHaveBeenNthCalledWith(1, {
|
|
59
|
+
to: MOCK_ERC20_CONTRACT,
|
|
60
|
+
data: approveData,
|
|
61
|
+
});
|
|
62
|
+
expect(mockWallet.sendTransaction).toHaveBeenNthCalledWith(2, {
|
|
63
|
+
to: MOCK_SUPERTOKEN_CONTRACT,
|
|
64
|
+
data: wrapData,
|
|
65
|
+
});
|
|
66
|
+
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledTimes(2);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("supportsNetwork", () => {
|
|
70
|
+
it("should return true for Base", () => {
|
|
71
|
+
const result = actionProvider.supportsNetwork({
|
|
72
|
+
protocolFamily: "evm",
|
|
73
|
+
networkId: "base-mainnet",
|
|
74
|
+
});
|
|
75
|
+
expect(result).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it("should return false for non-base networks", () => {
|
|
78
|
+
const result = actionProvider.supportsNetwork({
|
|
79
|
+
protocolFamily: "bitcoin",
|
|
80
|
+
networkId: "any",
|
|
81
|
+
});
|
|
82
|
+
expect(result).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
type RawLog = {
|
|
3
|
+
address: `0x${string}`;
|
|
4
|
+
data: Hex;
|
|
5
|
+
topics: readonly `0x${string}`[];
|
|
6
|
+
};
|
|
7
|
+
type TxReceipt = {
|
|
8
|
+
to?: `0x${string}` | null;
|
|
9
|
+
logs: RawLog[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Extracts the super token address using the contract abi
|
|
13
|
+
*
|
|
14
|
+
* @param receipt - the transaction receipt from creating the super token
|
|
15
|
+
* @returns - The contract address of the created Super Token
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractCreatedSuperTokenAddressAbi(receipt: TxReceipt): `0x${string}`;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractCreatedSuperTokenAddressAbi = extractCreatedSuperTokenAddressAbi;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
/**
|
|
7
|
+
* Casts the topics to a tuple
|
|
8
|
+
*
|
|
9
|
+
* @param topics - the topics to search for
|
|
10
|
+
* @returns - A tuple of topics
|
|
11
|
+
*/
|
|
12
|
+
function asTopicTuple(topics) {
|
|
13
|
+
if (!topics.length) {
|
|
14
|
+
throw new Error("Log has no topics (anonymous event?)");
|
|
15
|
+
}
|
|
16
|
+
return [topics[0], ...topics.slice(1)];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks for records to avoid any cast
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to check
|
|
22
|
+
* @returns - A boolean if the record is valid
|
|
23
|
+
*/
|
|
24
|
+
function isRecord(value) {
|
|
25
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
const TOKEN_KEYS = ["token", "superToken", "proxy"];
|
|
28
|
+
/**
|
|
29
|
+
* Pulls a 0x-address string from decoded args under one of: token | superToken | proxy
|
|
30
|
+
*
|
|
31
|
+
* @param args - The unknown value to check
|
|
32
|
+
* @returns - A contract address of the super token, or null
|
|
33
|
+
*/
|
|
34
|
+
function pickTokenLike(args) {
|
|
35
|
+
if (!isRecord(args))
|
|
36
|
+
return null;
|
|
37
|
+
for (const key of TOKEN_KEYS) {
|
|
38
|
+
const v = args[key];
|
|
39
|
+
if (typeof v === "string" && v.startsWith("0x")) {
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extracts the super token address using the contract abi
|
|
47
|
+
*
|
|
48
|
+
* @param receipt - the transaction receipt from creating the super token
|
|
49
|
+
* @returns - The contract address of the created Super Token
|
|
50
|
+
*/
|
|
51
|
+
function extractCreatedSuperTokenAddressAbi(receipt) {
|
|
52
|
+
const factory = receipt.to?.toLowerCase();
|
|
53
|
+
if (!factory)
|
|
54
|
+
throw new Error("Missing receipt.to (factory address)");
|
|
55
|
+
for (const log of receipt.logs) {
|
|
56
|
+
if (log.address.toLowerCase() !== factory)
|
|
57
|
+
continue;
|
|
58
|
+
if (!log.topics.length)
|
|
59
|
+
continue; // skip anonymous logs
|
|
60
|
+
try {
|
|
61
|
+
const { eventName, args } = (0, viem_1.decodeEventLog)({
|
|
62
|
+
abi: constants_1.SuperTokenFactoryABI,
|
|
63
|
+
data: log.data,
|
|
64
|
+
topics: asTopicTuple(log.topics),
|
|
65
|
+
});
|
|
66
|
+
if (eventName === "SuperTokenCreated") {
|
|
67
|
+
const token = pickTokenLike(args);
|
|
68
|
+
if (!token)
|
|
69
|
+
throw new Error("Token arg missing on SuperTokenCreated");
|
|
70
|
+
return (0, viem_1.getAddress)(token);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// not a matching event for this signature — ignore
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
throw new Error("SuperTokenCreated not found on factory logs");
|
|
78
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CdpClient, EvmSmartAccount } from "@coinbase/cdp-sdk";
|
|
2
|
-
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, PublicClient, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
1
|
+
import { CdpClient, EvmSmartAccount, EvmServerAccount } from "@coinbase/cdp-sdk";
|
|
2
|
+
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, PublicClient, ReadContractParameters, ReadContractReturnType, TransactionRequest, LocalAccount } from "viem";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
5
|
import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpShared";
|
|
@@ -9,6 +9,7 @@ import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpSha
|
|
|
9
9
|
export declare class CdpSmartWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
|
|
10
10
|
#private;
|
|
11
11
|
smartAccount: EvmSmartAccount;
|
|
12
|
+
ownerAccount: LocalAccount | EvmServerAccount;
|
|
12
13
|
/**
|
|
13
14
|
* Constructs a new CdpSmartWalletProvider.
|
|
14
15
|
*
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
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");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _CdpSmartWalletProvider_instances, _CdpSmartWalletProvider_publicClient,
|
|
13
|
+
var _CdpSmartWalletProvider_instances, _CdpSmartWalletProvider_publicClient, _CdpSmartWalletProvider_cdp, _CdpSmartWalletProvider_network, _CdpSmartWalletProvider_paymasterUrl, _CdpSmartWalletProvider_getCdpSdkNetwork;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CdpSmartWalletProvider = void 0;
|
|
16
16
|
const cdp_sdk_1 = require("@coinbase/cdp-sdk");
|
|
@@ -30,12 +30,11 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
30
30
|
super();
|
|
31
31
|
_CdpSmartWalletProvider_instances.add(this);
|
|
32
32
|
_CdpSmartWalletProvider_publicClient.set(this, void 0);
|
|
33
|
-
_CdpSmartWalletProvider_ownerAccount.set(this, void 0);
|
|
34
33
|
_CdpSmartWalletProvider_cdp.set(this, void 0);
|
|
35
34
|
_CdpSmartWalletProvider_network.set(this, void 0);
|
|
36
35
|
_CdpSmartWalletProvider_paymasterUrl.set(this, void 0);
|
|
37
36
|
this.smartAccount = config.smartAccount;
|
|
38
|
-
|
|
37
|
+
this.ownerAccount = config.ownerAccount;
|
|
39
38
|
__classPrivateFieldSet(this, _CdpSmartWalletProvider_cdp, config.cdp, "f");
|
|
40
39
|
__classPrivateFieldSet(this, _CdpSmartWalletProvider_publicClient, config.publicClient, "f");
|
|
41
40
|
__classPrivateFieldSet(this, _CdpSmartWalletProvider_network, config.network, "f");
|
|
@@ -115,7 +114,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
115
114
|
return {
|
|
116
115
|
name: this.smartAccount.name,
|
|
117
116
|
address: this.smartAccount.address,
|
|
118
|
-
ownerAddress:
|
|
117
|
+
ownerAddress: this.ownerAccount.address,
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
/**
|
|
@@ -272,7 +271,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
272
271
|
}
|
|
273
272
|
}
|
|
274
273
|
exports.CdpSmartWalletProvider = CdpSmartWalletProvider;
|
|
275
|
-
_CdpSmartWalletProvider_publicClient = new WeakMap(),
|
|
274
|
+
_CdpSmartWalletProvider_publicClient = new WeakMap(), _CdpSmartWalletProvider_cdp = new WeakMap(), _CdpSmartWalletProvider_network = new WeakMap(), _CdpSmartWalletProvider_paymasterUrl = new WeakMap(), _CdpSmartWalletProvider_instances = new WeakSet(), _CdpSmartWalletProvider_getCdpSdkNetwork = function _CdpSmartWalletProvider_getCdpSdkNetwork() {
|
|
276
275
|
switch (__classPrivateFieldGet(this, _CdpSmartWalletProvider_network, "f").networkId) {
|
|
277
276
|
case "base-sepolia":
|
|
278
277
|
return "base-sepolia";
|
|
@@ -13,6 +13,10 @@ export interface ViemWalletProviderGasConfig {
|
|
|
13
13
|
* An internal multiplier on fee per gas estimation.
|
|
14
14
|
*/
|
|
15
15
|
feePerGasMultiplier?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Optional RPC URL override for Viem public client.
|
|
18
|
+
*/
|
|
19
|
+
rpcUrl?: string;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* A wallet provider that uses the Viem library.
|
|
@@ -36,9 +36,10 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
36
36
|
_ViemWalletProvider_gasLimitMultiplier.set(this, void 0);
|
|
37
37
|
_ViemWalletProvider_feePerGasMultiplier.set(this, void 0);
|
|
38
38
|
__classPrivateFieldSet(this, _ViemWalletProvider_walletClient, walletClient, "f");
|
|
39
|
+
const rpcUrl = gasConfig?.rpcUrl || process.env.RPC_URL;
|
|
39
40
|
__classPrivateFieldSet(this, _ViemWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
40
41
|
chain: walletClient.chain,
|
|
41
|
-
transport: (0, viem_1.http)(),
|
|
42
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
42
43
|
}), "f");
|
|
43
44
|
__classPrivateFieldSet(this, _ViemWalletProvider_gasLimitMultiplier, Math.max(gasConfig?.gasLimitMultiplier ?? 1.2, 1), "f");
|
|
44
45
|
__classPrivateFieldSet(this, _ViemWalletProvider_feePerGasMultiplier, Math.max(gasConfig?.feePerGasMultiplier ?? 1, 1), "f");
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@coinbase/agentkit",
|
|
3
3
|
"description": "Coinbase AgentKit core primitives",
|
|
4
4
|
"repository": "https://github.com/coinbase/agentkit",
|
|
5
|
-
"version": "0.0.0-nightly-
|
|
5
|
+
"version": "0.0.0-nightly-20250822210413",
|
|
6
6
|
"author": "Coinbase Inc.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@across-protocol/app-sdk": "^0.2.0",
|
|
26
26
|
"@alloralabs/allora-sdk": "^0.1.0",
|
|
27
|
-
"@coinbase/cdp-sdk": "^1.
|
|
27
|
+
"@coinbase/cdp-sdk": "^1.36.0",
|
|
28
28
|
"@coinbase/coinbase-sdk": "^0.20.0",
|
|
29
29
|
"@jup-ag/api": "^6.0.39",
|
|
30
30
|
"@privy-io/public-api": "2.18.5",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"canonicalize": "^2.1.0",
|
|
41
41
|
"decimal.js": "^10.5.0",
|
|
42
42
|
"ethers": "^6.13.5",
|
|
43
|
+
"graphql-request": "^7.2.0",
|
|
43
44
|
"md5": "^2.3.0",
|
|
44
45
|
"opensea-js": "^7.1.18",
|
|
45
46
|
"reflect-metadata": "^0.2.2",
|