@coinbase/agentkit 0.10.0 → 0.10.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 +195 -23
- package/dist/action-providers/across/acrossActionProvider.js +3 -3
- package/dist/action-providers/across/schemas.d.ts +1 -1
- package/dist/action-providers/baseAccount/baseAccountActionProvider.d.ts +46 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.js +404 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.d.ts +1 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.js +325 -0
- package/dist/action-providers/baseAccount/index.d.ts +2 -0
- package/dist/action-providers/baseAccount/index.js +18 -0
- package/dist/action-providers/baseAccount/schemas.d.ts +43 -0
- package/dist/action-providers/baseAccount/schemas.js +62 -0
- package/dist/action-providers/baseAccount/types.d.ts +17 -0
- package/dist/action-providers/baseAccount/types.js +2 -0
- package/dist/action-providers/baseAccount/utils.d.ts +14 -0
- package/dist/action-providers/baseAccount/utils.js +57 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -81
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +18 -3
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +224 -23
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +280 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -2
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +224 -18
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +267 -1
- 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 +23 -0
- package/dist/action-providers/cdp/swapUtils.js +106 -0
- package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
- package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
- package/dist/action-providers/clanker/index.d.ts +2 -0
- package/dist/action-providers/clanker/index.js +18 -0
- package/dist/action-providers/clanker/schemas.d.ts +56 -0
- package/dist/action-providers/clanker/schemas.js +47 -0
- package/dist/action-providers/clanker/utils.d.ts +9 -0
- package/dist/action-providers/clanker/utils.js +23 -0
- package/dist/action-providers/compound/constants.d.ts +1 -1
- package/dist/action-providers/compound/constants.js +2 -2
- package/dist/action-providers/erc20/constants.d.ts +35 -135
- package/dist/action-providers/erc20/constants.js +37 -189
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
- package/dist/action-providers/erc20/schemas.d.ts +25 -12
- package/dist/action-providers/erc20/schemas.js +34 -6
- package/dist/action-providers/erc20/utils.d.ts +19 -0
- package/dist/action-providers/erc20/utils.js +54 -0
- package/dist/action-providers/flaunch/client_utils.d.ts +25 -0
- package/dist/action-providers/flaunch/client_utils.js +62 -0
- package/dist/action-providers/flaunch/constants.d.ts +42 -21
- package/dist/action-providers/flaunch/constants.js +113 -38
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +4 -43
- package/dist/action-providers/flaunch/flaunchActionProvider.js +133 -209
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +113 -13
- package/dist/action-providers/flaunch/metadata_utils.d.ts +12 -0
- package/dist/action-providers/flaunch/metadata_utils.js +216 -0
- package/dist/action-providers/flaunch/schemas.d.ts +39 -3
- package/dist/action-providers/flaunch/schemas.js +62 -10
- package/dist/action-providers/flaunch/{utils.d.ts → swap_utils.d.ts} +17 -19
- package/dist/action-providers/flaunch/{utils.js → swap_utils.js} +137 -172
- package/dist/action-providers/index.d.ts +4 -0
- package/dist/action-providers/index.js +4 -0
- package/dist/action-providers/jupiter/schemas.d.ts +1 -1
- package/dist/action-providers/moonwell/schemas.d.ts +2 -2
- package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
- package/dist/action-providers/morpho/schemas.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +83 -26
- package/dist/action-providers/pyth/pythActionProvider.test.js +179 -23
- package/dist/action-providers/pyth/schemas.d.ts +6 -0
- package/dist/action-providers/pyth/schemas.js +9 -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 +109 -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 +19 -0
- package/dist/action-providers/superfluid/utils/parseLogs.js +81 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
- package/dist/action-providers/wallet/walletActionProvider.js +24 -10
- package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
- package/dist/action-providers/x402/schemas.d.ts +7 -0
- package/dist/action-providers/x402/schemas.js +11 -1
- package/dist/action-providers/x402/utils.d.ts +55 -0
- package/dist/action-providers/x402/utils.js +160 -0
- package/dist/action-providers/x402/x402ActionProvider.d.ts +9 -9
- package/dist/action-providers/x402/x402ActionProvider.js +158 -39
- package/dist/action-providers/x402/x402ActionProvider.test.js +116 -10
- package/dist/action-providers/zeroX/index.d.ts +1 -0
- package/dist/action-providers/zeroX/index.js +17 -0
- package/dist/action-providers/zeroX/schemas.d.ts +51 -0
- package/dist/action-providers/zeroX/schemas.js +82 -0
- package/dist/action-providers/zeroX/utils.d.ts +23 -0
- package/dist/action-providers/zeroX/utils.js +106 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +43 -13
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +27 -2
- package/dist/wallet-providers/cdpEvmWalletProvider.js +54 -36
- package/dist/wallet-providers/cdpEvmWalletProvider.test.js +7 -0
- package/dist/wallet-providers/cdpShared.d.ts +5 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +29 -3
- package/dist/wallet-providers/cdpSmartWalletProvider.js +66 -25
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +6 -10
- package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
- package/dist/wallet-providers/evmWalletProvider.d.ts +13 -2
- package/dist/wallet-providers/evmWalletProvider.js +4 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +18 -2
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +23 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +19 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.js +27 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.test.js +6 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +17 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +39 -3
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +12 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
- package/dist/wallet-providers/viemWalletProvider.d.ts +20 -3
- package/dist/wallet-providers/viemWalletProvider.js +33 -4
- package/dist/wallet-providers/viemWalletProvider.test.js +27 -6
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +17 -2
- package/dist/wallet-providers/zeroDevWalletProvider.js +26 -5
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +12 -2
- package/package.json +8 -4
|
@@ -0,0 +1,109 @@
|
|
|
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 viem_2 = require("viem");
|
|
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: viem_2.erc20Abi,
|
|
51
|
+
functionName: "decimals",
|
|
52
|
+
args: [],
|
|
53
|
+
});
|
|
54
|
+
const name = await walletProvider.readContract({
|
|
55
|
+
address: args.erc20TokenAddress,
|
|
56
|
+
abi: viem_2.erc20Abi,
|
|
57
|
+
functionName: "name",
|
|
58
|
+
args: [],
|
|
59
|
+
});
|
|
60
|
+
const symbol = await walletProvider.readContract({
|
|
61
|
+
address: args.erc20TokenAddress,
|
|
62
|
+
abi: viem_2.erc20Abi,
|
|
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 superTokenFactoryAddress = walletProvider.getNetwork().networkId === "base-sepolia"
|
|
78
|
+
? constants_1.SuperTokenFactoryAddress_Base_Sepolia
|
|
79
|
+
: constants_1.SuperTokenFactoryAddress;
|
|
80
|
+
const createSuperTokenHash = await walletProvider.sendTransaction({
|
|
81
|
+
to: superTokenFactoryAddress,
|
|
82
|
+
data: createSuperTokenData,
|
|
83
|
+
});
|
|
84
|
+
const receipt = await walletProvider.waitForTransactionReceipt(createSuperTokenHash);
|
|
85
|
+
const superTokenAddress = (0, parseLogs_1.extractCreatedSuperTokenAddressAbi)(receipt, superTokenFactoryAddress);
|
|
86
|
+
return `Created super token for ${args.erc20TokenAddress}. Super token address at ${superTokenAddress} Transaction hash: ${createSuperTokenHash}`;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return `Error creating Superfluid Super Token: ${error}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.SuperfluidSuperTokenCreatorActionProvider = SuperfluidSuperTokenCreatorActionProvider;
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, actionDecorator_1.CreateAction)({
|
|
96
|
+
name: "create_super_token",
|
|
97
|
+
description: `
|
|
98
|
+
This action will create a Super token, essentially a wrapper token around an ERC20 that can freely stream between wallets.
|
|
99
|
+
It will return the address of the newly created Supertoken.
|
|
100
|
+
You should only take this action when requested. A Supertoken implementation is needed to stream tokens or to wrap an ERC20 token.
|
|
101
|
+
`,
|
|
102
|
+
schema: schemas_1.SuperfluidCreateSuperTokenSchema,
|
|
103
|
+
}),
|
|
104
|
+
__metadata("design:type", Function),
|
|
105
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
106
|
+
__metadata("design:returntype", Promise)
|
|
107
|
+
], SuperfluidSuperTokenCreatorActionProvider.prototype, "createSuperToken", null);
|
|
108
|
+
const superfluidSuperTokenCreatorActionProvider = () => new SuperfluidSuperTokenCreatorActionProvider();
|
|
109
|
+
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 viem_2 = require("viem");
|
|
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: viem_2.erc20Abi,
|
|
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: viem_2.erc20Abi,
|
|
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 viem_2 = require("viem");
|
|
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: viem_2.erc20Abi,
|
|
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,19 @@
|
|
|
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
|
+
* @param factoryAddress - the address of the factory that created the super token
|
|
16
|
+
* @returns - The contract address of the created Super Token
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractCreatedSuperTokenAddressAbi(receipt: TxReceipt, factoryAddress: `0x${string}`): `0x${string}`;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
* @param factoryAddress - the address of the factory that created the super token
|
|
50
|
+
* @returns - The contract address of the created Super Token
|
|
51
|
+
*/
|
|
52
|
+
function extractCreatedSuperTokenAddressAbi(receipt, factoryAddress) {
|
|
53
|
+
const factory = factoryAddress.toLowerCase();
|
|
54
|
+
if (!factory)
|
|
55
|
+
throw new Error("Missing factory address");
|
|
56
|
+
console.log("factory", factory);
|
|
57
|
+
console.log("receipt.logs", receipt.logs);
|
|
58
|
+
for (const log of receipt.logs) {
|
|
59
|
+
if (log.address.toLowerCase() !== factory)
|
|
60
|
+
continue;
|
|
61
|
+
if (!log.topics.length)
|
|
62
|
+
continue; // skip anonymous logs
|
|
63
|
+
try {
|
|
64
|
+
const { eventName, args } = (0, viem_1.decodeEventLog)({
|
|
65
|
+
abi: constants_1.SuperTokenFactoryABI,
|
|
66
|
+
data: log.data,
|
|
67
|
+
topics: asTopicTuple(log.topics),
|
|
68
|
+
});
|
|
69
|
+
if (eventName === "SuperTokenCreated") {
|
|
70
|
+
const token = pickTokenLike(args);
|
|
71
|
+
if (!token)
|
|
72
|
+
throw new Error("Token arg missing on SuperTokenCreated");
|
|
73
|
+
return (0, viem_1.getAddress)(token);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// not a matching event for this signature — ignore
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
throw new Error("SuperTokenCreated not found on factory logs");
|
|
81
|
+
}
|
|
@@ -4,25 +4,13 @@ import { Network } from "../../network";
|
|
|
4
4
|
import { GetTruthMarketsSchema, GetTruthMarketDetailsSchema } from "./schemas";
|
|
5
5
|
import { EvmWalletProvider } from "../../wallet-providers";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export interface TrueMarketsActionProviderConfig {
|
|
10
|
-
/**
|
|
11
|
-
* RPC URL for creating the Viem public client
|
|
12
|
-
*/
|
|
13
|
-
RPC_URL?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* TrueMarketsActionProvider provides actions to interact with TrueMarkets contracts.
|
|
7
|
+
* Action provider for TrueMarkets interactions.
|
|
17
8
|
*/
|
|
18
9
|
export declare class TrueMarketsActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
19
|
-
#private;
|
|
20
10
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* @param config - The configuration options for the TrueMarketsActionProvider.
|
|
11
|
+
* Creates a new TrueMarkets action provider.
|
|
24
12
|
*/
|
|
25
|
-
constructor(
|
|
13
|
+
constructor();
|
|
26
14
|
/**
|
|
27
15
|
* Gets active markets from the TruthMarketManager contract.
|
|
28
16
|
*
|
|
@@ -48,4 +36,4 @@ export declare class TrueMarketsActionProvider extends ActionProvider<EvmWalletP
|
|
|
48
36
|
*/
|
|
49
37
|
supportsNetwork: (network: Network) => boolean;
|
|
50
38
|
}
|
|
51
|
-
export declare const truemarketsActionProvider: (
|
|
39
|
+
export declare const truemarketsActionProvider: () => TrueMarketsActionProvider;
|