@coinbase/agentkit 0.1.0

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 (148) hide show
  1. package/README.md +305 -0
  2. package/dist/action-providers/actionDecorator.d.ts +69 -0
  3. package/dist/action-providers/actionDecorator.js +96 -0
  4. package/dist/action-providers/actionProvider.d.ts +48 -0
  5. package/dist/action-providers/actionProvider.js +62 -0
  6. package/dist/action-providers/basename/basenameActionProvider.d.ts +30 -0
  7. package/dist/action-providers/basename/basenameActionProvider.js +109 -0
  8. package/dist/action-providers/basename/basenameActionProvider.test.d.ts +1 -0
  9. package/dist/action-providers/basename/basenameActionProvider.test.js +146 -0
  10. package/dist/action-providers/basename/constants.d.ts +52 -0
  11. package/dist/action-providers/basename/constants.js +81 -0
  12. package/dist/action-providers/basename/index.d.ts +2 -0
  13. package/dist/action-providers/basename/index.js +18 -0
  14. package/dist/action-providers/basename/schemas.d.ts +14 -0
  15. package/dist/action-providers/basename/schemas.js +14 -0
  16. package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +41 -0
  17. package/dist/action-providers/cdp/cdpApiActionProvider.js +111 -0
  18. package/dist/action-providers/cdp/cdpApiActionProvider.test.d.ts +1 -0
  19. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +134 -0
  20. package/dist/action-providers/cdp/cdpWalletActionProvider.d.ts +58 -0
  21. package/dist/action-providers/cdp/cdpWalletActionProvider.js +218 -0
  22. package/dist/action-providers/cdp/cdpWalletActionProvider.test.d.ts +1 -0
  23. package/dist/action-providers/cdp/cdpWalletActionProvider.test.js +259 -0
  24. package/dist/action-providers/cdp/constants.d.ts +31 -0
  25. package/dist/action-providers/cdp/constants.js +34 -0
  26. package/dist/action-providers/cdp/index.d.ts +3 -0
  27. package/dist/action-providers/cdp/index.js +19 -0
  28. package/dist/action-providers/cdp/schemas.d.ts +91 -0
  29. package/dist/action-providers/cdp/schemas.js +77 -0
  30. package/dist/action-providers/customActionProvider.d.ts +30 -0
  31. package/dist/action-providers/customActionProvider.js +66 -0
  32. package/dist/action-providers/erc20/constants.d.ts +135 -0
  33. package/dist/action-providers/erc20/constants.js +191 -0
  34. package/dist/action-providers/erc20/erc20ActionProvider.d.ts +38 -0
  35. package/dist/action-providers/erc20/erc20ActionProvider.js +118 -0
  36. package/dist/action-providers/erc20/erc20ActionProvider.test.d.ts +1 -0
  37. package/dist/action-providers/erc20/erc20ActionProvider.test.js +117 -0
  38. package/dist/action-providers/erc20/index.d.ts +1 -0
  39. package/dist/action-providers/erc20/index.js +17 -0
  40. package/dist/action-providers/erc20/schemas.d.ts +27 -0
  41. package/dist/action-providers/erc20/schemas.js +26 -0
  42. package/dist/action-providers/erc721/constants.d.ts +236 -0
  43. package/dist/action-providers/erc721/constants.js +301 -0
  44. package/dist/action-providers/erc721/erc721ActionProvider.d.ts +46 -0
  45. package/dist/action-providers/erc721/erc721ActionProvider.js +164 -0
  46. package/dist/action-providers/erc721/erc721ActionProvider.test.d.ts +1 -0
  47. package/dist/action-providers/erc721/erc721ActionProvider.test.js +137 -0
  48. package/dist/action-providers/erc721/index.d.ts +1 -0
  49. package/dist/action-providers/erc721/index.js +17 -0
  50. package/dist/action-providers/erc721/schemas.d.ts +46 -0
  51. package/dist/action-providers/erc721/schemas.js +44 -0
  52. package/dist/action-providers/farcaster/farcasterActionProvider.d.ts +57 -0
  53. package/dist/action-providers/farcaster/farcasterActionProvider.js +142 -0
  54. package/dist/action-providers/farcaster/farcasterActionProvider.test.d.ts +1 -0
  55. package/dist/action-providers/farcaster/farcasterActionProvider.test.js +143 -0
  56. package/dist/action-providers/farcaster/index.d.ts +2 -0
  57. package/dist/action-providers/farcaster/index.js +18 -0
  58. package/dist/action-providers/farcaster/schemas.d.ts +15 -0
  59. package/dist/action-providers/farcaster/schemas.js +20 -0
  60. package/dist/action-providers/index.d.ts +13 -0
  61. package/dist/action-providers/index.js +29 -0
  62. package/dist/action-providers/morpho/constants.d.ts +16 -0
  63. package/dist/action-providers/morpho/constants.js +27 -0
  64. package/dist/action-providers/morpho/index.d.ts +2 -0
  65. package/dist/action-providers/morpho/index.js +18 -0
  66. package/dist/action-providers/morpho/morphoActionProvider.d.ts +39 -0
  67. package/dist/action-providers/morpho/morphoActionProvider.js +147 -0
  68. package/dist/action-providers/morpho/morphoActionProvider.test.d.ts +1 -0
  69. package/dist/action-providers/morpho/morphoActionProvider.test.js +126 -0
  70. package/dist/action-providers/morpho/schemas.d.ts +36 -0
  71. package/dist/action-providers/morpho/schemas.js +47 -0
  72. package/dist/action-providers/pyth/index.d.ts +2 -0
  73. package/dist/action-providers/pyth/index.js +18 -0
  74. package/dist/action-providers/pyth/pythActionProvider.d.ts +33 -0
  75. package/dist/action-providers/pyth/pythActionProvider.js +121 -0
  76. package/dist/action-providers/pyth/schemas.d.ts +21 -0
  77. package/dist/action-providers/pyth/schemas.js +20 -0
  78. package/dist/action-providers/twitter/index.d.ts +2 -0
  79. package/dist/action-providers/twitter/index.js +18 -0
  80. package/dist/action-providers/twitter/schemas.d.ts +38 -0
  81. package/dist/action-providers/twitter/schemas.js +44 -0
  82. package/dist/action-providers/twitter/twitterActionProvider.d.ts +82 -0
  83. package/dist/action-providers/twitter/twitterActionProvider.js +204 -0
  84. package/dist/action-providers/twitter/twitterActionProvider.test.d.ts +1 -0
  85. package/dist/action-providers/twitter/twitterActionProvider.test.js +185 -0
  86. package/dist/action-providers/wallet/index.d.ts +1 -0
  87. package/dist/action-providers/wallet/index.js +17 -0
  88. package/dist/action-providers/wallet/schemas.d.ts +19 -0
  89. package/dist/action-providers/wallet/schemas.js +19 -0
  90. package/dist/action-providers/wallet/walletActionProvider.d.ts +44 -0
  91. package/dist/action-providers/wallet/walletActionProvider.js +127 -0
  92. package/dist/action-providers/wallet/walletActionProvider.test.d.ts +1 -0
  93. package/dist/action-providers/wallet/walletActionProvider.test.js +116 -0
  94. package/dist/action-providers/weth/constants.d.ts +19 -0
  95. package/dist/action-providers/weth/constants.js +29 -0
  96. package/dist/action-providers/weth/index.d.ts +1 -0
  97. package/dist/action-providers/weth/index.js +17 -0
  98. package/dist/action-providers/weth/schemas.d.ts +8 -0
  99. package/dist/action-providers/weth/schemas.js +10 -0
  100. package/dist/action-providers/weth/wethActionProvider.d.ts +30 -0
  101. package/dist/action-providers/weth/wethActionProvider.js +89 -0
  102. package/dist/action-providers/weth/wethActionProvider.test.d.ts +1 -0
  103. package/dist/action-providers/weth/wethActionProvider.test.js +92 -0
  104. package/dist/action-providers/wow/constants.d.ts +15 -0
  105. package/dist/action-providers/wow/constants.js +844 -0
  106. package/dist/action-providers/wow/index.d.ts +2 -0
  107. package/dist/action-providers/wow/index.js +18 -0
  108. package/dist/action-providers/wow/schemas.d.ts +43 -0
  109. package/dist/action-providers/wow/schemas.js +47 -0
  110. package/dist/action-providers/wow/uniswap/constants.d.ts +3 -0
  111. package/dist/action-providers/wow/uniswap/constants.js +100 -0
  112. package/dist/action-providers/wow/uniswap/utils.d.ts +82 -0
  113. package/dist/action-providers/wow/uniswap/utils.js +226 -0
  114. package/dist/action-providers/wow/utils.d.ts +27 -0
  115. package/dist/action-providers/wow/utils.js +63 -0
  116. package/dist/action-providers/wow/wowActionProvider.d.ts +46 -0
  117. package/dist/action-providers/wow/wowActionProvider.js +223 -0
  118. package/dist/action-providers/wow/wowActionProvider.test.d.ts +1 -0
  119. package/dist/action-providers/wow/wowActionProvider.test.js +287 -0
  120. package/dist/agentkit.d.ts +45 -0
  121. package/dist/agentkit.js +60 -0
  122. package/dist/analytics/index.d.ts +1 -0
  123. package/dist/analytics/index.js +17 -0
  124. package/dist/analytics/sendAnalyticsEvent.d.ts +31 -0
  125. package/dist/analytics/sendAnalyticsEvent.js +51 -0
  126. package/dist/index.d.ts +3 -0
  127. package/dist/index.js +22 -0
  128. package/dist/network/index.d.ts +1 -0
  129. package/dist/network/index.js +17 -0
  130. package/dist/network/network.d.ts +13 -0
  131. package/dist/network/network.js +41 -0
  132. package/dist/network/types.d.ts +17 -0
  133. package/dist/network/types.js +2 -0
  134. package/dist/utils.d.ts +11 -0
  135. package/dist/utils.js +43 -0
  136. package/dist/utils.test.d.ts +1 -0
  137. package/dist/utils.test.js +50 -0
  138. package/dist/wallet-providers/cdpWalletProvider.d.ts +218 -0
  139. package/dist/wallet-providers/cdpWalletProvider.js +362 -0
  140. package/dist/wallet-providers/evmWalletProvider.d.ts +51 -0
  141. package/dist/wallet-providers/evmWalletProvider.js +14 -0
  142. package/dist/wallet-providers/index.d.ts +4 -0
  143. package/dist/wallet-providers/index.js +20 -0
  144. package/dist/wallet-providers/viemWalletProvider.d.ts +89 -0
  145. package/dist/wallet-providers/viemWalletProvider.js +187 -0
  146. package/dist/wallet-providers/walletProvider.d.ts +48 -0
  147. package/dist/wallet-providers/walletProvider.js +41 -0
  148. package/package.json +65 -0
@@ -0,0 +1,2 @@
1
+ export * from "./schemas";
2
+ export * from "./wowActionProvider";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schemas"), exports);
18
+ __exportStar(require("./wowActionProvider"), exports);
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Input schema for buying WOW tokens.
4
+ */
5
+ export declare const WowBuyTokenInput: z.ZodObject<{
6
+ contractAddress: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
7
+ amountEthInWei: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ contractAddress: `0x${string}`;
10
+ amountEthInWei: string;
11
+ }, {
12
+ contractAddress: `0x${string}`;
13
+ amountEthInWei: string;
14
+ }>;
15
+ /**
16
+ * Input schema for creating WOW tokens.
17
+ */
18
+ export declare const WowCreateTokenInput: z.ZodObject<{
19
+ name: z.ZodString;
20
+ symbol: z.ZodString;
21
+ tokenUri: z.ZodOptional<z.ZodString>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ symbol: string;
24
+ name: string;
25
+ tokenUri?: string | undefined;
26
+ }, {
27
+ symbol: string;
28
+ name: string;
29
+ tokenUri?: string | undefined;
30
+ }>;
31
+ /**
32
+ * Input schema for selling WOW tokens.
33
+ */
34
+ export declare const WowSellTokenInput: z.ZodObject<{
35
+ contractAddress: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
36
+ amountTokensInWei: z.ZodString;
37
+ }, "strip", z.ZodTypeAny, {
38
+ contractAddress: `0x${string}`;
39
+ amountTokensInWei: string;
40
+ }, {
41
+ contractAddress: `0x${string}`;
42
+ amountTokensInWei: string;
43
+ }>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WowSellTokenInput = exports.WowCreateTokenInput = exports.WowBuyTokenInput = void 0;
4
+ const zod_1 = require("zod");
5
+ const viem_1 = require("viem");
6
+ const ethereumAddress = zod_1.z.custom(val => typeof val === "string" && (0, viem_1.isAddress)(val), "Invalid address");
7
+ /**
8
+ * Input schema for buying WOW tokens.
9
+ */
10
+ exports.WowBuyTokenInput = zod_1.z
11
+ .object({
12
+ contractAddress: ethereumAddress.describe("The WOW token contract address"),
13
+ amountEthInWei: zod_1.z
14
+ .string()
15
+ .regex(/^\d+$/, "Must be a valid wei amount")
16
+ .describe("Amount of ETH to spend (in wei)"),
17
+ })
18
+ .strip()
19
+ .describe("Instructions for buying WOW tokens");
20
+ /**
21
+ * Input schema for creating WOW tokens.
22
+ */
23
+ exports.WowCreateTokenInput = zod_1.z
24
+ .object({
25
+ name: zod_1.z.string().min(1).describe("The name of the token to create, e.g. WowCoin"),
26
+ symbol: zod_1.z.string().min(1).describe("The symbol of the token to create, e.g. WOW"),
27
+ tokenUri: zod_1.z
28
+ .string()
29
+ .url()
30
+ .optional()
31
+ .describe("The URI of the token metadata to store on IPFS, e.g. ipfs://QmY1GqprFYvojCcUEKgqHeDj9uhZD9jmYGrQTfA9vAE78J"),
32
+ })
33
+ .strip()
34
+ .describe("Instructions for creating a WOW token");
35
+ /**
36
+ * Input schema for selling WOW tokens.
37
+ */
38
+ exports.WowSellTokenInput = zod_1.z
39
+ .object({
40
+ contractAddress: ethereumAddress.describe("The WOW token contract address, such as `0x036CbD53842c5426634e7929541eC2318f3dCF7e`"),
41
+ amountTokensInWei: zod_1.z
42
+ .string()
43
+ .regex(/^\d+$/, "Must be a valid wei amount")
44
+ .describe("Amount of tokens to sell (in wei), meaning 1 is 1 wei or 0.000000000000000001 of the token"),
45
+ })
46
+ .strip()
47
+ .describe("Instructions for selling WOW tokens");
@@ -0,0 +1,3 @@
1
+ import type { Abi } from "abitype";
2
+ export declare const UNISWAP_QUOTER_ABI: Abi;
3
+ export declare const UNISWAP_V3_ABI: Abi;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNISWAP_V3_ABI = exports.UNISWAP_QUOTER_ABI = void 0;
4
+ exports.UNISWAP_QUOTER_ABI = [
5
+ {
6
+ inputs: [
7
+ {
8
+ components: [
9
+ { internalType: "address", name: "tokenIn", type: "address" },
10
+ { internalType: "address", name: "tokenOut", type: "address" },
11
+ { internalType: "uint256", name: "amountIn", type: "uint256" },
12
+ { internalType: "uint24", name: "fee", type: "uint24" },
13
+ { internalType: "uint160", name: "sqrtPriceLimitX96", type: "uint160" },
14
+ ],
15
+ internalType: "struct IQuoterV2.QuoteExactInputSingleParams",
16
+ name: "params",
17
+ type: "tuple",
18
+ },
19
+ ],
20
+ name: "quoteExactInputSingle",
21
+ outputs: [
22
+ { internalType: "uint256", name: "amountOut", type: "uint256" },
23
+ { internalType: "uint160", name: "sqrtPriceX96After", type: "uint160" },
24
+ { internalType: "uint32", name: "initializedTicksCrossed", type: "uint32" },
25
+ { internalType: "uint256", name: "gasEstimate", type: "uint256" },
26
+ ],
27
+ stateMutability: "nonpayable",
28
+ type: "function",
29
+ },
30
+ {
31
+ inputs: [
32
+ {
33
+ components: [
34
+ { internalType: "address", name: "tokenIn", type: "address" },
35
+ { internalType: "address", name: "tokenOut", type: "address" },
36
+ { internalType: "uint256", name: "amount", type: "uint256" },
37
+ { internalType: "uint24", name: "fee", type: "uint24" },
38
+ { internalType: "uint160", name: "sqrtPriceLimitX96", type: "uint160" },
39
+ ],
40
+ internalType: "struct IQuoterV2.QuoteExactOutputSingleParams",
41
+ name: "params",
42
+ type: "tuple",
43
+ },
44
+ ],
45
+ name: "quoteExactOutputSingle",
46
+ outputs: [
47
+ { internalType: "uint256", name: "amountIn", type: "uint256" },
48
+ { internalType: "uint160", name: "sqrtPriceX96After", type: "uint160" },
49
+ { internalType: "uint32", name: "initializedTicksCrossed", type: "uint32" },
50
+ { internalType: "uint256", name: "gasEstimate", type: "uint256" },
51
+ ],
52
+ stateMutability: "nonpayable",
53
+ type: "function",
54
+ },
55
+ ];
56
+ exports.UNISWAP_V3_ABI = [
57
+ {
58
+ inputs: [],
59
+ name: "fee",
60
+ outputs: [{ internalType: "uint24", name: "", type: "uint24" }],
61
+ stateMutability: "view",
62
+ type: "function",
63
+ },
64
+ {
65
+ inputs: [],
66
+ name: "liquidity",
67
+ outputs: [{ internalType: "uint128", name: "", type: "uint128" }],
68
+ stateMutability: "view",
69
+ type: "function",
70
+ },
71
+ {
72
+ inputs: [],
73
+ name: "slot0",
74
+ outputs: [
75
+ { internalType: "uint160", name: "sqrtPriceX96", type: "uint160" },
76
+ { internalType: "int24", name: "tick", type: "int24" },
77
+ { internalType: "uint16", name: "observationIndex", type: "uint16" },
78
+ { internalType: "uint16", name: "observationCardinality", type: "uint16" },
79
+ { internalType: "uint16", name: "observationCardinalityNext", type: "uint16" },
80
+ { internalType: "uint8", name: "feeProtocol", type: "uint8" },
81
+ { internalType: "bool", name: "unlocked", type: "bool" },
82
+ ],
83
+ stateMutability: "view",
84
+ type: "function",
85
+ },
86
+ {
87
+ inputs: [],
88
+ name: "token0",
89
+ outputs: [{ internalType: "address", name: "", type: "address" }],
90
+ stateMutability: "view",
91
+ type: "function",
92
+ },
93
+ {
94
+ inputs: [],
95
+ name: "token1",
96
+ outputs: [{ internalType: "address", name: "", type: "address" }],
97
+ stateMutability: "view",
98
+ type: "function",
99
+ },
100
+ ];
@@ -0,0 +1,82 @@
1
+ import { EvmWalletProvider } from "../../../wallet-providers";
2
+ export interface PriceInfo {
3
+ eth: string;
4
+ usd: number;
5
+ }
6
+ export interface Balance {
7
+ erc20z: string;
8
+ weth: string;
9
+ }
10
+ export interface Price {
11
+ perToken: PriceInfo;
12
+ total: PriceInfo;
13
+ }
14
+ export interface Quote {
15
+ amountIn: number;
16
+ amountOut: number;
17
+ balance: Balance | null;
18
+ fee: number | null;
19
+ error: string | null;
20
+ }
21
+ export interface PoolInfo {
22
+ token0: string;
23
+ balance0: number;
24
+ token1: string;
25
+ balance1: number;
26
+ fee: number;
27
+ liquidity: number;
28
+ sqrtPriceX96: number;
29
+ }
30
+ /**
31
+ * Creates a PriceInfo object from wei amount and ETH price.
32
+ *
33
+ * @param weiAmount - Amount in wei
34
+ * @param ethPriceInUsd - Current ETH price in USD
35
+ * @returns A PriceInfo object containing the amount in ETH and USD
36
+ */
37
+ export declare function createPriceInfo(weiAmount: string, ethPriceInUsd: number): PriceInfo;
38
+ /**
39
+ * Gets pool info for a given uniswap v3 pool address.
40
+ *
41
+ * @param wallet - The wallet provider to use for contract calls
42
+ * @param poolAddress - Uniswap v3 pool address
43
+ * @returns A PoolInfo object containing pool details
44
+ */
45
+ export declare function getPoolInfo(wallet: EvmWalletProvider, poolAddress: string): Promise<PoolInfo>;
46
+ /**
47
+ * Gets exact input quote from Uniswap.
48
+ *
49
+ * @param wallet - The wallet provider to use for contract calls
50
+ * @param tokenIn - Token address to swap from
51
+ * @param tokenOut - Token address to swap to
52
+ * @param amountIn - Amount of tokens to swap (in Wei)
53
+ * @param fee - Fee for the swap
54
+ * @returns Amount of tokens to receive (in Wei)
55
+ */
56
+ export declare function exactInputSingle(wallet: EvmWalletProvider, tokenIn: string, tokenOut: string, amountIn: string, fee: string): Promise<number>;
57
+ /**
58
+ * Gets Uniswap quote for buying or selling tokens.
59
+ *
60
+ * @param wallet - The wallet provider to use for contract calls
61
+ * @param tokenAddress - Token address
62
+ * @param amount - Amount of tokens (in Wei)
63
+ * @param quoteType - 'buy' or 'sell'
64
+ * @returns A Quote object containing quote details
65
+ */
66
+ export declare function getUniswapQuote(wallet: EvmWalletProvider, tokenAddress: string, amount: number, quoteType: "buy" | "sell"): Promise<Quote>;
67
+ /**
68
+ * Checks if a token has graduated from the Zora Wow protocol.
69
+ *
70
+ * @param wallet - The wallet provider to use for contract calls
71
+ * @param tokenAddress - Token address
72
+ * @returns True if the token has graduated, false otherwise
73
+ */
74
+ export declare function getHasGraduated(wallet: EvmWalletProvider, tokenAddress: string): Promise<boolean>;
75
+ /**
76
+ * Fetches the uniswap v3 pool address for a given token.
77
+ *
78
+ * @param wallet - The wallet provider to use for contract calls
79
+ * @param tokenAddress - The address of the token contract
80
+ * @returns The uniswap v3 pool address associated with the token
81
+ */
82
+ export declare function getPoolAddress(wallet: EvmWalletProvider, tokenAddress: string): Promise<string>;
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPriceInfo = createPriceInfo;
4
+ exports.getPoolInfo = getPoolInfo;
5
+ exports.exactInputSingle = exactInputSingle;
6
+ exports.getUniswapQuote = getUniswapQuote;
7
+ exports.getHasGraduated = getHasGraduated;
8
+ exports.getPoolAddress = getPoolAddress;
9
+ const viem_1 = require("viem");
10
+ const constants_1 = require("../constants");
11
+ const constants_2 = require("./constants");
12
+ /**
13
+ * Creates a PriceInfo object from wei amount and ETH price.
14
+ *
15
+ * @param weiAmount - Amount in wei
16
+ * @param ethPriceInUsd - Current ETH price in USD
17
+ * @returns A PriceInfo object containing the amount in ETH and USD
18
+ */
19
+ function createPriceInfo(weiAmount, ethPriceInUsd) {
20
+ const amountInEth = (0, viem_1.formatEther)(BigInt(weiAmount));
21
+ const usd = Number(amountInEth) * ethPriceInUsd;
22
+ return {
23
+ eth: weiAmount,
24
+ usd,
25
+ };
26
+ }
27
+ /**
28
+ * Gets pool info for a given uniswap v3 pool address.
29
+ *
30
+ * @param wallet - The wallet provider to use for contract calls
31
+ * @param poolAddress - Uniswap v3 pool address
32
+ * @returns A PoolInfo object containing pool details
33
+ */
34
+ async function getPoolInfo(wallet, poolAddress) {
35
+ try {
36
+ const results = await Promise.all([
37
+ wallet.readContract({
38
+ address: poolAddress,
39
+ functionName: "token0",
40
+ args: [],
41
+ abi: constants_2.UNISWAP_V3_ABI,
42
+ }),
43
+ wallet.readContract({
44
+ address: poolAddress,
45
+ functionName: "token1",
46
+ args: [],
47
+ abi: constants_2.UNISWAP_V3_ABI,
48
+ }),
49
+ wallet.readContract({
50
+ address: poolAddress,
51
+ functionName: "fee",
52
+ args: [],
53
+ abi: constants_2.UNISWAP_V3_ABI,
54
+ }),
55
+ wallet.readContract({
56
+ address: poolAddress,
57
+ functionName: "liquidity",
58
+ args: [],
59
+ abi: constants_2.UNISWAP_V3_ABI,
60
+ }),
61
+ wallet.readContract({
62
+ address: poolAddress,
63
+ functionName: "slot0",
64
+ args: [],
65
+ abi: constants_2.UNISWAP_V3_ABI,
66
+ }),
67
+ ]);
68
+ const [token0Result, token1Result, fee, liquidity, slot0] = results;
69
+ const [balance0, balance1] = await Promise.all([
70
+ wallet.readContract({
71
+ address: token0Result,
72
+ functionName: "balanceOf",
73
+ args: [poolAddress],
74
+ abi: constants_1.WOW_ABI,
75
+ }),
76
+ wallet.readContract({
77
+ address: token1Result,
78
+ functionName: "balanceOf",
79
+ args: [poolAddress],
80
+ abi: constants_1.WOW_ABI,
81
+ }),
82
+ ]);
83
+ return {
84
+ token0: token0Result,
85
+ balance0: Number(balance0),
86
+ token1: token1Result,
87
+ balance1: Number(balance1),
88
+ fee: Number(fee),
89
+ liquidity: Number(liquidity),
90
+ sqrtPriceX96: Number(slot0[0]),
91
+ };
92
+ }
93
+ catch (error) {
94
+ throw new Error(`Failed to fetch pool information: ${error}`);
95
+ }
96
+ }
97
+ /**
98
+ * Gets exact input quote from Uniswap.
99
+ *
100
+ * @param wallet - The wallet provider to use for contract calls
101
+ * @param tokenIn - Token address to swap from
102
+ * @param tokenOut - Token address to swap to
103
+ * @param amountIn - Amount of tokens to swap (in Wei)
104
+ * @param fee - Fee for the swap
105
+ * @returns Amount of tokens to receive (in Wei)
106
+ */
107
+ async function exactInputSingle(wallet, tokenIn, tokenOut, amountIn, fee) {
108
+ try {
109
+ const networkId = wallet.getNetwork().networkId;
110
+ const amount = await wallet.readContract({
111
+ address: constants_1.ADDRESSES[networkId].UniswapQuoter,
112
+ functionName: "quoteExactInputSingle",
113
+ args: [
114
+ {
115
+ tokenIn: (0, viem_1.getAddress)(tokenIn),
116
+ tokenOut: (0, viem_1.getAddress)(tokenOut),
117
+ fee,
118
+ amountIn,
119
+ sqrtPriceLimitX96: 0,
120
+ },
121
+ ],
122
+ abi: constants_2.UNISWAP_QUOTER_ABI,
123
+ });
124
+ return Number(amount);
125
+ }
126
+ catch (error) {
127
+ console.error("Quoter error:", error);
128
+ return 0;
129
+ }
130
+ }
131
+ /**
132
+ * Gets Uniswap quote for buying or selling tokens.
133
+ *
134
+ * @param wallet - The wallet provider to use for contract calls
135
+ * @param tokenAddress - Token address
136
+ * @param amount - Amount of tokens (in Wei)
137
+ * @param quoteType - 'buy' or 'sell'
138
+ * @returns A Quote object containing quote details
139
+ */
140
+ async function getUniswapQuote(wallet, tokenAddress, amount, quoteType) {
141
+ let pool = null;
142
+ let tokens = null;
143
+ let balances = null;
144
+ let quoteResult = null;
145
+ const utilization = 0;
146
+ const networkId = wallet.getNetwork().networkId;
147
+ const poolAddress = await getPoolAddress(wallet, tokenAddress);
148
+ const invalidPoolError = !poolAddress ? "Invalid pool address" : null;
149
+ try {
150
+ pool = await getPoolInfo(wallet, poolAddress);
151
+ const { token0, token1, balance0, balance1, fee } = pool;
152
+ tokens = [token0, token1];
153
+ balances = [balance0, balance1];
154
+ const isToken0Weth = token0.toLowerCase() === constants_1.ADDRESSES[networkId].WETH.toLowerCase();
155
+ const tokenIn = (quoteType === "buy" && isToken0Weth) || (quoteType === "sell" && !isToken0Weth)
156
+ ? token0
157
+ : token1;
158
+ const [tokenOut, balanceOut] = tokenIn === token0 ? [token1, balance1] : [token0, balance0];
159
+ const isInsufficientLiquidity = quoteType === "buy" && amount > balanceOut;
160
+ if (!isInsufficientLiquidity) {
161
+ quoteResult = await exactInputSingle(wallet, tokenIn, tokenOut, String(amount), String(fee));
162
+ }
163
+ }
164
+ catch (error) {
165
+ console.error("Error fetching quote:", error);
166
+ }
167
+ const insufficientLiquidity = (quoteType === "sell" && pool && !quoteResult) || false;
168
+ let errorMsg = null;
169
+ if (!pool) {
170
+ errorMsg = "Failed fetching pool";
171
+ }
172
+ else if (insufficientLiquidity) {
173
+ errorMsg = "Insufficient liquidity";
174
+ }
175
+ else if (!quoteResult && utilization >= 0.9) {
176
+ errorMsg = "Price impact too high";
177
+ }
178
+ else if (!quoteResult) {
179
+ errorMsg = "Failed fetching quote";
180
+ }
181
+ const balanceResult = tokens && balances
182
+ ? {
183
+ erc20z: String(balances[tokens[0].toLowerCase() === constants_1.ADDRESSES[networkId].WETH.toLowerCase() ? 1 : 0]),
184
+ weth: String(balances[tokens[0].toLowerCase() === constants_1.ADDRESSES[networkId].WETH.toLowerCase() ? 0 : 1]),
185
+ }
186
+ : null;
187
+ return {
188
+ amountIn: Number(amount),
189
+ amountOut: quoteResult || 0,
190
+ balance: balanceResult,
191
+ fee: pool?.fee ? pool.fee / 1000000 : null,
192
+ error: invalidPoolError || errorMsg,
193
+ };
194
+ }
195
+ /**
196
+ * Checks if a token has graduated from the Zora Wow protocol.
197
+ *
198
+ * @param wallet - The wallet provider to use for contract calls
199
+ * @param tokenAddress - Token address
200
+ * @returns True if the token has graduated, false otherwise
201
+ */
202
+ async function getHasGraduated(wallet, tokenAddress) {
203
+ const marketType = await wallet.readContract({
204
+ address: tokenAddress,
205
+ functionName: "marketType",
206
+ args: [],
207
+ abi: constants_1.WOW_ABI,
208
+ });
209
+ return marketType === 1;
210
+ }
211
+ /**
212
+ * Fetches the uniswap v3 pool address for a given token.
213
+ *
214
+ * @param wallet - The wallet provider to use for contract calls
215
+ * @param tokenAddress - The address of the token contract
216
+ * @returns The uniswap v3 pool address associated with the token
217
+ */
218
+ async function getPoolAddress(wallet, tokenAddress) {
219
+ const poolAddress = await wallet.readContract({
220
+ address: tokenAddress,
221
+ functionName: "poolAddress",
222
+ args: [],
223
+ abi: constants_1.WOW_ABI,
224
+ });
225
+ return poolAddress;
226
+ }
@@ -0,0 +1,27 @@
1
+ import { EvmWalletProvider } from "../../wallet-providers";
2
+ /**
3
+ * Gets the current supply of a token.
4
+ *
5
+ * @param wallet - The wallet provider to use for contract calls
6
+ * @param tokenAddress - Address of the token contract
7
+ * @returns The current token supply
8
+ */
9
+ export declare function getCurrentSupply(wallet: EvmWalletProvider, tokenAddress: string): Promise<string>;
10
+ /**
11
+ * Gets quote for buying tokens.
12
+ *
13
+ * @param wallet - The wallet provider to use for contract calls
14
+ * @param tokenAddress - Address of the token contract
15
+ * @param amountEthInWei - Amount of ETH to buy (in wei)
16
+ * @returns The buy quote amount
17
+ */
18
+ export declare function getBuyQuote(wallet: EvmWalletProvider, tokenAddress: string, amountEthInWei: string): Promise<string>;
19
+ /**
20
+ * Gets quote for selling tokens.
21
+ *
22
+ * @param wallet - The wallet provider to use for contract calls
23
+ * @param tokenAddress - Address of the token contract
24
+ * @param amountTokensInWei - Amount of tokens to sell (in wei)
25
+ * @returns The sell quote amount
26
+ */
27
+ export declare function getSellQuote(wallet: EvmWalletProvider, tokenAddress: string, amountTokensInWei: string): Promise<string>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrentSupply = getCurrentSupply;
4
+ exports.getBuyQuote = getBuyQuote;
5
+ exports.getSellQuote = getSellQuote;
6
+ const constants_1 = require("./constants");
7
+ const utils_1 = require("./uniswap/utils");
8
+ /**
9
+ * Gets the current supply of a token.
10
+ *
11
+ * @param wallet - The wallet provider to use for contract calls
12
+ * @param tokenAddress - Address of the token contract
13
+ * @returns The current token supply
14
+ */
15
+ async function getCurrentSupply(wallet, tokenAddress) {
16
+ const supply = await wallet.readContract({
17
+ address: tokenAddress,
18
+ abi: constants_1.WOW_ABI,
19
+ functionName: "totalSupply",
20
+ args: [],
21
+ });
22
+ return supply;
23
+ }
24
+ /**
25
+ * Gets quote for buying tokens.
26
+ *
27
+ * @param wallet - The wallet provider to use for contract calls
28
+ * @param tokenAddress - Address of the token contract
29
+ * @param amountEthInWei - Amount of ETH to buy (in wei)
30
+ * @returns The buy quote amount
31
+ */
32
+ async function getBuyQuote(wallet, tokenAddress, amountEthInWei) {
33
+ const hasGraduated = await (0, utils_1.getHasGraduated)(wallet, tokenAddress);
34
+ const tokenQuote = (hasGraduated
35
+ ? (await (0, utils_1.getUniswapQuote)(wallet, tokenAddress, Number(amountEthInWei), "buy")).amountOut
36
+ : await wallet.readContract({
37
+ address: tokenAddress,
38
+ abi: constants_1.WOW_ABI,
39
+ functionName: "getEthBuyQuote",
40
+ args: [amountEthInWei],
41
+ }));
42
+ return tokenQuote.toString();
43
+ }
44
+ /**
45
+ * Gets quote for selling tokens.
46
+ *
47
+ * @param wallet - The wallet provider to use for contract calls
48
+ * @param tokenAddress - Address of the token contract
49
+ * @param amountTokensInWei - Amount of tokens to sell (in wei)
50
+ * @returns The sell quote amount
51
+ */
52
+ async function getSellQuote(wallet, tokenAddress, amountTokensInWei) {
53
+ const hasGraduated = await (0, utils_1.getHasGraduated)(wallet, tokenAddress);
54
+ const tokenQuote = (hasGraduated
55
+ ? (await (0, utils_1.getUniswapQuote)(wallet, tokenAddress, Number(amountTokensInWei), "sell")).amountOut
56
+ : await wallet.readContract({
57
+ address: tokenAddress,
58
+ abi: constants_1.WOW_ABI,
59
+ functionName: "getTokenSellQuote",
60
+ args: [amountTokensInWei],
61
+ }));
62
+ return tokenQuote.toString();
63
+ }
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { ActionProvider } from "../actionProvider";
3
+ import { EvmWalletProvider } from "../../wallet-providers";
4
+ import { Network } from "../../network";
5
+ import { WowBuyTokenInput, WowCreateTokenInput, WowSellTokenInput } from "./schemas";
6
+ /**
7
+ * WowActionProvider is an action provider for Wow protocol interactions.
8
+ */
9
+ export declare class WowActionProvider extends ActionProvider {
10
+ /**
11
+ * Constructor for the WowActionProvider class.
12
+ */
13
+ constructor();
14
+ /**
15
+ * Buys a Zora Wow ERC20 memecoin with ETH.
16
+ *
17
+ * @param wallet - The wallet to create the token from.
18
+ * @param args - The input arguments for the action.
19
+ * @returns A message containing the token purchase details.
20
+ */
21
+ buyToken(wallet: EvmWalletProvider, args: z.infer<typeof WowBuyTokenInput>): Promise<string>;
22
+ /**
23
+ * Creates a Zora Wow ERC20 memecoin.
24
+ *
25
+ * @param wallet - The wallet to create the token from.
26
+ * @param args - The input arguments for the action.
27
+ * @returns A message containing the token creation details.
28
+ */
29
+ createToken(wallet: EvmWalletProvider, args: z.infer<typeof WowCreateTokenInput>): Promise<string>;
30
+ /**
31
+ * Sells WOW tokens for ETH.
32
+ *
33
+ * @param wallet - The wallet to sell the tokens from.
34
+ * @param args - The input arguments for the action.
35
+ * @returns A message confirming the sale with the transaction hash.
36
+ */
37
+ sellToken(wallet: EvmWalletProvider, args: z.infer<typeof WowSellTokenInput>): Promise<string>;
38
+ /**
39
+ * Checks if the Wow action provider supports the given network.
40
+ *
41
+ * @param network - The network to check.
42
+ * @returns True if the Wow action provider supports the network, false otherwise.
43
+ */
44
+ supportsNetwork: (network: Network) => boolean;
45
+ }
46
+ export declare const wowActionProvider: () => WowActionProvider;