liquid-sdk 1.1.0 → 1.3.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.
package/dist/index.js CHANGED
@@ -39,9 +39,13 @@ __export(index_exports, {
39
39
  LiquidSDK: () => LiquidSDK,
40
40
  LiquidSniperAuctionV2Abi: () => LiquidSniperAuctionV2Abi,
41
41
  LiquidSniperUtilV2Abi: () => LiquidSniperUtilV2Abi,
42
+ LiquidTokenAbi: () => LiquidTokenAbi,
43
+ LiquidUniv4EthDevBuyAbi: () => LiquidUniv4EthDevBuyAbi,
42
44
  LiquidVaultAbi: () => LiquidVaultAbi,
43
45
  POOL_POSITIONS: () => POOL_POSITIONS,
44
46
  TOKEN: () => TOKEN,
47
+ buildContext: () => buildContext,
48
+ buildMetadata: () => buildMetadata,
45
49
  createDefaultPositions: () => createDefaultPositions,
46
50
  createPositions: () => createPositions,
47
51
  createPositionsUSD: () => createPositionsUSD,
@@ -53,7 +57,9 @@ __export(index_exports, {
53
57
  getTickFromMarketCapStable: () => getTickFromMarketCapStable,
54
58
  getTickFromMarketCapUSD: () => getTickFromMarketCapUSD,
55
59
  marketCapFromTickETH: () => marketCapFromTickETH,
56
- marketCapFromTickUSD: () => marketCapFromTickUSD
60
+ marketCapFromTickUSD: () => marketCapFromTickUSD,
61
+ parseContext: () => parseContext,
62
+ parseMetadata: () => parseMetadata
57
63
  });
58
64
  module.exports = __toCommonJS(index_exports);
59
65
 
@@ -145,6 +151,8 @@ var POOL_POSITIONS = {
145
151
  };
146
152
  var DEFAULTS = {
147
153
  HOOK: ADDRESSES.HOOK_STATIC_FEE_V2,
154
+ /** LP Locker with fee conversion (converts fees to ETH before distributing) */
155
+ LOCKER: ADDRESSES.LP_LOCKER_FEE_CONVERSION,
148
156
  TICK_SPACING: 200,
149
157
  TICK_IF_TOKEN0_IS_LIQUID: -230400,
150
158
  /** Static fee on buys (ETH → token): 1% (100 bps). Fees collected in ETH. */
@@ -253,6 +261,68 @@ function encodeSniperAuctionData(config) {
253
261
  ]);
254
262
  }
255
263
 
264
+ // src/utils/context.ts
265
+ function buildContext(input) {
266
+ const ctx = {
267
+ interface: input?.interface ?? "SDK"
268
+ };
269
+ if (input?.platform !== void 0) ctx.platform = input.platform;
270
+ if (input?.messageId !== void 0) ctx.messageId = input.messageId;
271
+ if (input?.id !== void 0) ctx.id = input.id;
272
+ return JSON.stringify(ctx);
273
+ }
274
+ function buildMetadata(input) {
275
+ if (!input) return "{}";
276
+ const meta = {};
277
+ if (input.description !== void 0) meta.description = input.description;
278
+ if (input.socialMediaUrls !== void 0 && input.socialMediaUrls.length > 0) {
279
+ meta.socialMediaUrls = input.socialMediaUrls;
280
+ }
281
+ if (input.auditUrls !== void 0 && input.auditUrls.length > 0) {
282
+ meta.auditUrls = input.auditUrls;
283
+ }
284
+ return JSON.stringify(meta);
285
+ }
286
+ function parseContext(contextString) {
287
+ if (!contextString || contextString === "") return null;
288
+ try {
289
+ const parsed = JSON.parse(contextString);
290
+ if (typeof parsed !== "object" || parsed === null) return null;
291
+ return {
292
+ interface: typeof parsed.interface === "string" ? parsed.interface : "unknown",
293
+ ...typeof parsed.platform === "string" && { platform: parsed.platform },
294
+ ...typeof parsed.messageId === "string" && { messageId: parsed.messageId },
295
+ ...typeof parsed.id === "string" && { id: parsed.id }
296
+ };
297
+ } catch {
298
+ return null;
299
+ }
300
+ }
301
+ function parseMetadata(metadataString) {
302
+ if (!metadataString || metadataString === "") return null;
303
+ try {
304
+ const parsed = JSON.parse(metadataString);
305
+ if (typeof parsed !== "object" || parsed === null) return null;
306
+ const result = {};
307
+ if (typeof parsed.description === "string") {
308
+ result.description = parsed.description;
309
+ }
310
+ if (Array.isArray(parsed.socialMediaUrls)) {
311
+ result.socialMediaUrls = parsed.socialMediaUrls.filter(
312
+ (item) => typeof item === "object" && item !== null && typeof item.platform === "string" && typeof item.url === "string"
313
+ );
314
+ }
315
+ if (Array.isArray(parsed.auditUrls)) {
316
+ result.auditUrls = parsed.auditUrls.filter(
317
+ (item) => typeof item === "string"
318
+ );
319
+ }
320
+ return result;
321
+ } catch {
322
+ return null;
323
+ }
324
+ }
325
+
256
326
  // src/abis/LiquidFactory.ts
257
327
  var LiquidFactoryAbi = [
258
328
  {
@@ -871,6 +941,52 @@ var LiquidLpLockerAbi = [
871
941
  }
872
942
  ];
873
943
 
944
+ // src/abis/LiquidToken.ts
945
+ var LiquidTokenAbi = [
946
+ {
947
+ type: "function",
948
+ name: "updateImage",
949
+ inputs: [{ name: "image_", type: "string" }],
950
+ outputs: [],
951
+ stateMutability: "nonpayable"
952
+ },
953
+ {
954
+ type: "function",
955
+ name: "updateMetadata",
956
+ inputs: [{ name: "metadata_", type: "string" }],
957
+ outputs: [],
958
+ stateMutability: "nonpayable"
959
+ },
960
+ {
961
+ type: "function",
962
+ name: "updateAdmin",
963
+ inputs: [{ name: "admin_", type: "address" }],
964
+ outputs: [],
965
+ stateMutability: "nonpayable"
966
+ },
967
+ {
968
+ type: "event",
969
+ name: "UpdateImage",
970
+ inputs: [{ name: "image", type: "string", indexed: false }],
971
+ anonymous: false
972
+ },
973
+ {
974
+ type: "event",
975
+ name: "UpdateMetadata",
976
+ inputs: [{ name: "metadata", type: "string", indexed: false }],
977
+ anonymous: false
978
+ },
979
+ {
980
+ type: "event",
981
+ name: "UpdateAdmin",
982
+ inputs: [
983
+ { name: "oldAdmin", type: "address", indexed: false },
984
+ { name: "newAdmin", type: "address", indexed: false }
985
+ ],
986
+ anonymous: false
987
+ }
988
+ ];
989
+
874
990
  // src/abis/ERC20.ts
875
991
  var ERC20Abi = [
876
992
  {
@@ -1106,7 +1222,7 @@ var LiquidSDK = class {
1106
1222
  ),
1107
1223
  image: params.image ?? "",
1108
1224
  metadata: params.metadata ?? "",
1109
- context: params.context ?? "",
1225
+ context: params.context ?? buildContext(),
1110
1226
  originatingChainId: BigInt(DEFAULT_CHAIN_ID)
1111
1227
  },
1112
1228
  poolConfig: {
@@ -1120,7 +1236,7 @@ var LiquidSDK = class {
1120
1236
  )
1121
1237
  },
1122
1238
  lockerConfig: {
1123
- locker: params.locker ?? ADDRESSES.LP_LOCKER,
1239
+ locker: params.locker ?? DEFAULTS.LOCKER,
1124
1240
  rewardAdmins: params.rewardAdmins ?? [account],
1125
1241
  rewardRecipients: params.rewardRecipients ?? [account],
1126
1242
  rewardBps: params.rewardBps ?? [1e4],
@@ -1510,7 +1626,7 @@ var LiquidSDK = class {
1510
1626
  }
1511
1627
  // ── LP Locker ───────────────────────────────────────────────────────
1512
1628
  async getTokenRewards(tokenAddress, lockerAddress) {
1513
- const locker = lockerAddress ?? ADDRESSES.LP_LOCKER;
1629
+ const locker = lockerAddress ?? DEFAULTS.LOCKER;
1514
1630
  const result = await this.publicClient.readContract({
1515
1631
  address: locker,
1516
1632
  abi: LiquidLpLockerAbi,
@@ -1532,7 +1648,7 @@ var LiquidSDK = class {
1532
1648
  if (!this.walletClient?.account) {
1533
1649
  throw new Error("walletClient with account required for collectRewards");
1534
1650
  }
1535
- const locker = lockerAddress ?? ADDRESSES.LP_LOCKER;
1651
+ const locker = lockerAddress ?? DEFAULTS.LOCKER;
1536
1652
  return await this.walletClient.writeContract({
1537
1653
  address: locker,
1538
1654
  abi: LiquidLpLockerAbi,
@@ -1548,7 +1664,7 @@ var LiquidSDK = class {
1548
1664
  "walletClient with account required for collectRewardsWithoutUnlock"
1549
1665
  );
1550
1666
  }
1551
- const locker = lockerAddress ?? ADDRESSES.LP_LOCKER;
1667
+ const locker = lockerAddress ?? DEFAULTS.LOCKER;
1552
1668
  return await this.walletClient.writeContract({
1553
1669
  address: locker,
1554
1670
  abi: LiquidLpLockerAbi,
@@ -1564,7 +1680,7 @@ var LiquidSDK = class {
1564
1680
  "walletClient with account required for updateRewardRecipient"
1565
1681
  );
1566
1682
  }
1567
- const locker = lockerAddress ?? ADDRESSES.LP_LOCKER;
1683
+ const locker = lockerAddress ?? DEFAULTS.LOCKER;
1568
1684
  return await this.walletClient.writeContract({
1569
1685
  address: locker,
1570
1686
  abi: LiquidLpLockerAbi,
@@ -1599,8 +1715,298 @@ var LiquidSDK = class {
1599
1715
  args: [poolId]
1600
1716
  });
1601
1717
  }
1718
+ // ── Token Metadata Updates ──────────────────────────────────────────
1719
+ /**
1720
+ * Update a token's image. Must be called by the token admin.
1721
+ */
1722
+ async updateImage(tokenAddress, newImage) {
1723
+ if (!this.walletClient?.account) {
1724
+ throw new Error("walletClient with account required for updateImage");
1725
+ }
1726
+ return await this.walletClient.writeContract({
1727
+ address: tokenAddress,
1728
+ abi: LiquidTokenAbi,
1729
+ functionName: "updateImage",
1730
+ args: [newImage],
1731
+ chain: import_chains2.base,
1732
+ account: this.walletClient.account
1733
+ });
1734
+ }
1735
+ /**
1736
+ * Update a token's metadata. Must be called by the token admin.
1737
+ */
1738
+ async updateMetadata(tokenAddress, newMetadata) {
1739
+ if (!this.walletClient?.account) {
1740
+ throw new Error("walletClient with account required for updateMetadata");
1741
+ }
1742
+ return await this.walletClient.writeContract({
1743
+ address: tokenAddress,
1744
+ abi: LiquidTokenAbi,
1745
+ functionName: "updateMetadata",
1746
+ args: [newMetadata],
1747
+ chain: import_chains2.base,
1748
+ account: this.walletClient.account
1749
+ });
1750
+ }
1751
+ // ── Token Discovery ─────────────────────────────────────────────────
1752
+ /**
1753
+ * Get all tokens deployed by a specific address by querying TokenCreated events.
1754
+ * @param deployer - The address that deployed the tokens (msgSender)
1755
+ * @param fromBlock - Starting block to search from (defaults to 0n)
1756
+ * @param toBlock - Ending block to search to (defaults to 'latest')
1757
+ */
1758
+ async getDeployedTokens(deployer, fromBlock, toBlock) {
1759
+ return this.getTokens({ deployer, fromBlock, toBlock });
1760
+ }
1761
+ /**
1762
+ * Query TokenCreated events with optional filtering.
1763
+ *
1764
+ * Use this for token discovery, indexing, or building token lists.
1765
+ * Returns events in chronological order with block numbers for pagination.
1766
+ *
1767
+ * @example
1768
+ * // Get all tokens
1769
+ * const allTokens = await sdk.getTokens();
1770
+ *
1771
+ * // Get tokens by deployer
1772
+ * const myTokens = await sdk.getTokens({ deployer: myAddress });
1773
+ *
1774
+ * // Paginate with block ranges
1775
+ * const page1 = await sdk.getTokens({ fromBlock: 20000000n, toBlock: 20100000n });
1776
+ * const page2 = await sdk.getTokens({ fromBlock: 20100001n, toBlock: 20200000n });
1777
+ */
1778
+ async getTokens(options) {
1779
+ const logs = await this.publicClient.getLogs({
1780
+ address: ADDRESSES.FACTORY,
1781
+ event: (0, import_viem2.parseAbiItem)(
1782
+ "event TokenCreated(address msgSender, address indexed tokenAddress, address indexed tokenAdmin, string tokenImage, string tokenName, string tokenSymbol, string tokenMetadata, string tokenContext, int24 startingTick, address poolHook, bytes32 poolId, address pairedToken, address locker, address mevModule, uint256 extensionsSupply, address[] extensions)"
1783
+ ),
1784
+ fromBlock: options?.fromBlock ?? 0n,
1785
+ toBlock: options?.toBlock ?? "latest"
1786
+ });
1787
+ const deployer = options?.deployer;
1788
+ return logs.filter((log) => {
1789
+ if (!deployer) return true;
1790
+ const sender = log.args.msgSender;
1791
+ return sender && (0, import_viem2.getAddress)(sender) === (0, import_viem2.getAddress)(deployer);
1792
+ }).map((log) => {
1793
+ const args = log.args;
1794
+ return {
1795
+ msgSender: args.msgSender,
1796
+ tokenAddress: args.tokenAddress,
1797
+ tokenAdmin: args.tokenAdmin,
1798
+ tokenImage: args.tokenImage,
1799
+ tokenName: args.tokenName,
1800
+ tokenSymbol: args.tokenSymbol,
1801
+ tokenMetadata: args.tokenMetadata,
1802
+ tokenContext: args.tokenContext,
1803
+ startingTick: args.startingTick,
1804
+ poolHook: args.poolHook,
1805
+ poolId: args.poolId,
1806
+ pairedToken: args.pairedToken,
1807
+ locker: args.locker,
1808
+ mevModule: args.mevModule,
1809
+ extensionsSupply: args.extensionsSupply,
1810
+ extensions: args.extensions,
1811
+ blockNumber: log.blockNumber
1812
+ };
1813
+ });
1814
+ }
1815
+ /**
1816
+ * Look up a single token's on-chain event data by contract address.
1817
+ *
1818
+ * Returns the full TokenCreated event including metadata, context, poolId,
1819
+ * hook, locker, extensions — everything a wallet or aggregator needs to
1820
+ * display the token. Returns `null` if not found.
1821
+ *
1822
+ * This is indexed on-chain (tokenAddress is indexed in the event), so it's
1823
+ * a single RPC call regardless of how many tokens exist.
1824
+ */
1825
+ async getTokenEvent(tokenAddress) {
1826
+ const logs = await this.publicClient.getLogs({
1827
+ address: ADDRESSES.FACTORY,
1828
+ event: (0, import_viem2.parseAbiItem)(
1829
+ "event TokenCreated(address msgSender, address indexed tokenAddress, address indexed tokenAdmin, string tokenImage, string tokenName, string tokenSymbol, string tokenMetadata, string tokenContext, int24 startingTick, address poolHook, bytes32 poolId, address pairedToken, address locker, address mevModule, uint256 extensionsSupply, address[] extensions)"
1830
+ ),
1831
+ args: { tokenAddress },
1832
+ fromBlock: 0n,
1833
+ toBlock: "latest"
1834
+ });
1835
+ if (logs.length === 0) return null;
1836
+ const log = logs[0];
1837
+ const args = log.args;
1838
+ return {
1839
+ msgSender: args.msgSender,
1840
+ tokenAddress: args.tokenAddress,
1841
+ tokenAdmin: args.tokenAdmin,
1842
+ tokenImage: args.tokenImage,
1843
+ tokenName: args.tokenName,
1844
+ tokenSymbol: args.tokenSymbol,
1845
+ tokenMetadata: args.tokenMetadata,
1846
+ tokenContext: args.tokenContext,
1847
+ startingTick: args.startingTick,
1848
+ poolHook: args.poolHook,
1849
+ poolId: args.poolId,
1850
+ pairedToken: args.pairedToken,
1851
+ locker: args.locker,
1852
+ mevModule: args.mevModule,
1853
+ extensionsSupply: args.extensionsSupply,
1854
+ extensions: args.extensions,
1855
+ blockNumber: log.blockNumber
1856
+ };
1857
+ }
1602
1858
  };
1603
1859
 
1860
+ // src/abis/LiquidUniv4EthDevBuy.ts
1861
+ var LiquidUniv4EthDevBuyAbi = [
1862
+ {
1863
+ type: "constructor",
1864
+ inputs: [
1865
+ { name: "factory_", type: "address" },
1866
+ { name: "weth_", type: "address" },
1867
+ { name: "universalRouter_", type: "address" },
1868
+ { name: "permit2_", type: "address" }
1869
+ ],
1870
+ stateMutability: "nonpayable"
1871
+ },
1872
+ {
1873
+ type: "function",
1874
+ name: "factory",
1875
+ inputs: [],
1876
+ outputs: [{ name: "", type: "address" }],
1877
+ stateMutability: "view"
1878
+ },
1879
+ {
1880
+ type: "function",
1881
+ name: "weth",
1882
+ inputs: [],
1883
+ outputs: [{ name: "", type: "address" }],
1884
+ stateMutability: "view"
1885
+ },
1886
+ {
1887
+ type: "function",
1888
+ name: "universalRouter",
1889
+ inputs: [],
1890
+ outputs: [{ name: "", type: "address" }],
1891
+ stateMutability: "view"
1892
+ },
1893
+ {
1894
+ type: "function",
1895
+ name: "permit2",
1896
+ inputs: [],
1897
+ outputs: [{ name: "", type: "address" }],
1898
+ stateMutability: "view"
1899
+ },
1900
+ {
1901
+ type: "function",
1902
+ name: "receiveTokens",
1903
+ inputs: [
1904
+ {
1905
+ name: "deploymentConfig",
1906
+ type: "tuple",
1907
+ components: [
1908
+ {
1909
+ name: "tokenConfig",
1910
+ type: "tuple",
1911
+ components: [
1912
+ { name: "tokenAdmin", type: "address" },
1913
+ { name: "name", type: "string" },
1914
+ { name: "symbol", type: "string" },
1915
+ { name: "salt", type: "bytes32" },
1916
+ { name: "image", type: "string" },
1917
+ { name: "metadata", type: "string" },
1918
+ { name: "context", type: "string" },
1919
+ { name: "originatingChainId", type: "uint256" }
1920
+ ]
1921
+ },
1922
+ {
1923
+ name: "poolConfig",
1924
+ type: "tuple",
1925
+ components: [
1926
+ { name: "hook", type: "address" },
1927
+ { name: "pairedToken", type: "address" },
1928
+ { name: "tickIfToken0IsLiquid", type: "int24" },
1929
+ { name: "tickSpacing", type: "int24" },
1930
+ { name: "poolData", type: "bytes" }
1931
+ ]
1932
+ },
1933
+ {
1934
+ name: "lockerConfig",
1935
+ type: "tuple",
1936
+ components: [
1937
+ { name: "locker", type: "address" },
1938
+ { name: "rewardAdmins", type: "address[]" },
1939
+ { name: "rewardRecipients", type: "address[]" },
1940
+ { name: "rewardBps", type: "uint16[]" },
1941
+ { name: "tickLower", type: "int24[]" },
1942
+ { name: "tickUpper", type: "int24[]" },
1943
+ { name: "positionBps", type: "uint16[]" },
1944
+ { name: "lockerData", type: "bytes" }
1945
+ ]
1946
+ },
1947
+ {
1948
+ name: "mevModuleConfig",
1949
+ type: "tuple",
1950
+ components: [
1951
+ { name: "mevModule", type: "address" },
1952
+ { name: "mevModuleData", type: "bytes" }
1953
+ ]
1954
+ },
1955
+ {
1956
+ name: "extensionConfigs",
1957
+ type: "tuple[]",
1958
+ components: [
1959
+ { name: "extension", type: "address" },
1960
+ { name: "msgValue", type: "uint256" },
1961
+ { name: "extensionBps", type: "uint16" },
1962
+ { name: "extensionData", type: "bytes" }
1963
+ ]
1964
+ }
1965
+ ]
1966
+ },
1967
+ {
1968
+ name: "tokenPoolKey",
1969
+ type: "tuple",
1970
+ components: [
1971
+ { name: "currency0", type: "address" },
1972
+ { name: "currency1", type: "address" },
1973
+ { name: "fee", type: "uint24" },
1974
+ { name: "tickSpacing", type: "int24" },
1975
+ { name: "hooks", type: "address" }
1976
+ ]
1977
+ },
1978
+ { name: "token", type: "address" },
1979
+ { name: "extensionSupply", type: "uint256" },
1980
+ { name: "extensionIndex", type: "uint256" }
1981
+ ],
1982
+ outputs: [],
1983
+ stateMutability: "payable"
1984
+ },
1985
+ {
1986
+ type: "function",
1987
+ name: "supportsInterface",
1988
+ inputs: [{ name: "interfaceId", type: "bytes4" }],
1989
+ outputs: [{ name: "", type: "bool" }],
1990
+ stateMutability: "pure"
1991
+ },
1992
+ {
1993
+ type: "event",
1994
+ name: "EthDevBuy",
1995
+ inputs: [
1996
+ { name: "token", type: "address", indexed: true },
1997
+ { name: "user", type: "address", indexed: true },
1998
+ { name: "ethAmount", type: "uint256", indexed: false },
1999
+ { name: "tokenAmount", type: "uint256", indexed: false }
2000
+ ],
2001
+ anonymous: false
2002
+ },
2003
+ { type: "error", name: "InvalidEthDevBuyPercentage", inputs: [] },
2004
+ { type: "error", name: "InvalidMsgValue", inputs: [] },
2005
+ { type: "error", name: "InvalidPairedTokenPoolKey", inputs: [] },
2006
+ { type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] },
2007
+ { type: "error", name: "Unauthorized", inputs: [] }
2008
+ ];
2009
+
1604
2010
  // src/utils/tick-math.ts
1605
2011
  var LOG_BASE = Math.log(1.0001);
1606
2012
  var DEFAULT_TICK_SPACING = 200;
@@ -1729,9 +2135,13 @@ function describePositions(positions, ethPriceUSD) {
1729
2135
  LiquidSDK,
1730
2136
  LiquidSniperAuctionV2Abi,
1731
2137
  LiquidSniperUtilV2Abi,
2138
+ LiquidTokenAbi,
2139
+ LiquidUniv4EthDevBuyAbi,
1732
2140
  LiquidVaultAbi,
1733
2141
  POOL_POSITIONS,
1734
2142
  TOKEN,
2143
+ buildContext,
2144
+ buildMetadata,
1735
2145
  createDefaultPositions,
1736
2146
  createPositions,
1737
2147
  createPositionsUSD,
@@ -1743,6 +2153,8 @@ function describePositions(positions, ethPriceUSD) {
1743
2153
  getTickFromMarketCapStable,
1744
2154
  getTickFromMarketCapUSD,
1745
2155
  marketCapFromTickETH,
1746
- marketCapFromTickUSD
2156
+ marketCapFromTickUSD,
2157
+ parseContext,
2158
+ parseMetadata
1747
2159
  });
1748
2160
  //# sourceMappingURL=index.js.map