@coinbase/agentkit 0.10.0 → 0.10.1

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.
Files changed (131) hide show
  1. package/README.md +75 -0
  2. package/dist/action-providers/across/acrossActionProvider.js +3 -3
  3. package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
  4. package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -81
  5. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
  6. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +18 -3
  7. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +223 -23
  8. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +278 -0
  9. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -2
  10. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +223 -18
  11. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +265 -1
  12. package/dist/action-providers/cdp/schemas.d.ts +12 -12
  13. package/dist/action-providers/cdp/schemas.js +17 -5
  14. package/dist/action-providers/cdp/swapUtils.d.ts +32 -0
  15. package/dist/action-providers/cdp/swapUtils.js +142 -0
  16. package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
  17. package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
  18. package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
  19. package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
  20. package/dist/action-providers/clanker/index.d.ts +2 -0
  21. package/dist/action-providers/clanker/index.js +18 -0
  22. package/dist/action-providers/clanker/schemas.d.ts +56 -0
  23. package/dist/action-providers/clanker/schemas.js +47 -0
  24. package/dist/action-providers/clanker/utils.d.ts +9 -0
  25. package/dist/action-providers/clanker/utils.js +23 -0
  26. package/dist/action-providers/compound/constants.d.ts +1 -1
  27. package/dist/action-providers/compound/constants.js +2 -2
  28. package/dist/action-providers/erc20/constants.d.ts +35 -135
  29. package/dist/action-providers/erc20/constants.js +37 -189
  30. package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
  31. package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
  32. package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
  33. package/dist/action-providers/erc20/schemas.d.ts +25 -12
  34. package/dist/action-providers/erc20/schemas.js +34 -6
  35. package/dist/action-providers/erc20/utils.d.ts +19 -0
  36. package/dist/action-providers/erc20/utils.js +54 -0
  37. package/dist/action-providers/flaunch/constants.d.ts +1 -1
  38. package/dist/action-providers/flaunch/constants.js +2 -2
  39. package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
  40. package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
  41. package/dist/action-providers/index.d.ts +3 -0
  42. package/dist/action-providers/index.js +3 -0
  43. package/dist/action-providers/jupiter/schemas.d.ts +1 -1
  44. package/dist/action-providers/moonwell/schemas.d.ts +2 -2
  45. package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
  46. package/dist/action-providers/morpho/schemas.d.ts +2 -2
  47. package/dist/action-providers/pyth/pythActionProvider.js +5 -0
  48. package/dist/action-providers/pyth/pythActionProvider.test.js +5 -1
  49. package/dist/action-providers/superfluid/constants.d.ts +814 -0
  50. package/dist/action-providers/superfluid/constants.js +2826 -0
  51. package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
  52. package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
  53. package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
  54. package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
  55. package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
  56. package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
  57. package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
  58. package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
  59. package/dist/action-providers/superfluid/index.d.ts +7 -0
  60. package/dist/action-providers/superfluid/index.js +23 -0
  61. package/dist/action-providers/superfluid/schemas.d.ts +86 -0
  62. package/dist/action-providers/superfluid/schemas.js +103 -0
  63. package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
  64. package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
  65. package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
  66. package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
  67. package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
  68. package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
  69. package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
  70. package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
  71. package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
  72. package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
  73. package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
  74. package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
  75. package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
  76. package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
  77. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
  78. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +108 -0
  79. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
  80. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
  81. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
  82. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
  83. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
  84. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
  85. package/dist/action-providers/superfluid/utils/parseLogs.d.ts +18 -0
  86. package/dist/action-providers/superfluid/utils/parseLogs.js +78 -0
  87. package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
  88. package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
  89. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
  90. package/dist/action-providers/wallet/walletActionProvider.js +21 -10
  91. package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
  92. package/dist/action-providers/zeroX/index.d.ts +1 -0
  93. package/dist/action-providers/zeroX/index.js +17 -0
  94. package/dist/action-providers/zeroX/schemas.d.ts +51 -0
  95. package/dist/action-providers/zeroX/schemas.js +82 -0
  96. package/dist/action-providers/zeroX/utils.d.ts +23 -0
  97. package/dist/action-providers/zeroX/utils.js +106 -0
  98. package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
  99. package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
  100. package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
  101. package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
  102. package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +20 -2
  103. package/dist/wallet-providers/cdpEvmWalletProvider.js +40 -15
  104. package/dist/wallet-providers/cdpShared.d.ts +5 -0
  105. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +22 -3
  106. package/dist/wallet-providers/cdpSmartWalletProvider.js +43 -19
  107. package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
  108. package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
  109. package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
  110. package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
  111. package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -2
  112. package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +12 -2
  113. package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +12 -2
  114. package/dist/wallet-providers/legacyCdpWalletProvider.js +11 -2
  115. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +10 -2
  116. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +12 -3
  117. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
  118. package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
  119. package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
  120. package/dist/wallet-providers/privyEvmWalletProvider.test.js +1 -1
  121. package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
  122. package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
  123. package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
  124. package/dist/wallet-providers/viemWalletProvider.d.ts +12 -2
  125. package/dist/wallet-providers/viemWalletProvider.js +12 -3
  126. package/dist/wallet-providers/viemWalletProvider.test.js +6 -5
  127. package/dist/wallet-providers/walletProvider.d.ts +1 -1
  128. package/dist/wallet-providers/zeroDevWalletProvider.d.ts +10 -2
  129. package/dist/wallet-providers/zeroDevWalletProvider.js +14 -5
  130. package/dist/wallet-providers/zeroDevWalletProvider.test.js +2 -2
  131. package/package.json +4 -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 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 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,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,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,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
+ }
@@ -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
- * Configuration options for the TrueMarketsActionProvider.
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
- * Constructor for the TrueMarketsActionProvider.
22
- *
23
- * @param config - The configuration options for the TrueMarketsActionProvider.
11
+ * Creates a new TrueMarkets action provider.
24
12
  */
25
- constructor(config?: TrueMarketsActionProviderConfig);
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: (config?: TrueMarketsActionProviderConfig) => TrueMarketsActionProvider;
39
+ export declare const truemarketsActionProvider: () => TrueMarketsActionProvider;