auctionflow-sdk 2.1.0 → 3.0.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.
package/dist/index.mjs CHANGED
@@ -77,7 +77,7 @@ var AuctionBuilder = class {
77
77
 
78
78
  // src/constants/addresses.ts
79
79
  var AUCTION_ADDRESSES = {
80
- 84532: "0xe57fe62e31666a9b749e89086a8a5487a530153b",
80
+ 84532: "0x424fdc89af63f3585716370901f7e7de3b11c3e8",
81
81
  8453: "0x0000000000000000000000000000000000000000"
82
82
  // not yet deployed
83
83
  };
@@ -85,6 +85,10 @@ var USDC_ADDRESSES = {
85
85
  84532: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
86
86
  8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
87
87
  };
88
+ var WETH_ADDRESSES = {
89
+ 84532: "0x4200000000000000000000000000000000000006",
90
+ 8453: "0x4200000000000000000000000000000000000006"
91
+ };
88
92
 
89
93
  // src/abis/token-auction.ts
90
94
  var tokenAuctionAbi = [
@@ -105,10 +109,19 @@ var tokenAuctionAbi = [
105
109
  "name": "positionManager_",
106
110
  "type": "address",
107
111
  "internalType": "contract INonfungiblePositionManager"
112
+ },
113
+ {
114
+ "name": "weth_",
115
+ "type": "address",
116
+ "internalType": "contract IWETH9"
108
117
  }
109
118
  ],
110
119
  "stateMutability": "nonpayable"
111
120
  },
121
+ {
122
+ "type": "receive",
123
+ "stateMutability": "payable"
124
+ },
112
125
  {
113
126
  "type": "function",
114
127
  "name": "MAX_FEE_BPS",
@@ -285,6 +298,24 @@ var tokenAuctionAbi = [
285
298
  "outputs": [],
286
299
  "stateMutability": "nonpayable"
287
300
  },
301
+ {
302
+ "type": "function",
303
+ "name": "buyTokensWithETH",
304
+ "inputs": [
305
+ {
306
+ "name": "auctionId",
307
+ "type": "uint256",
308
+ "internalType": "uint256"
309
+ },
310
+ {
311
+ "name": "amount",
312
+ "type": "uint256",
313
+ "internalType": "uint256"
314
+ }
315
+ ],
316
+ "outputs": [],
317
+ "stateMutability": "payable"
318
+ },
288
319
  {
289
320
  "type": "function",
290
321
  "name": "claim",
@@ -548,6 +579,11 @@ var tokenAuctionAbi = [
548
579
  "name": "metadataURI",
549
580
  "type": "string",
550
581
  "internalType": "string"
582
+ },
583
+ {
584
+ "name": "paymentToken",
585
+ "type": "address",
586
+ "internalType": "address"
551
587
  }
552
588
  ],
553
589
  "outputs": [
@@ -561,8 +597,14 @@ var tokenAuctionAbi = [
561
597
  },
562
598
  {
563
599
  "type": "function",
564
- "name": "launchPreset",
565
- "inputs": [],
600
+ "name": "launchPresets",
601
+ "inputs": [
602
+ {
603
+ "name": "",
604
+ "type": "address",
605
+ "internalType": "address"
606
+ }
607
+ ],
566
608
  "outputs": [
567
609
  {
568
610
  "name": "paymentToken",
@@ -807,6 +849,29 @@ var tokenAuctionAbi = [
807
849
  "outputs": [],
808
850
  "stateMutability": "nonpayable"
809
851
  },
852
+ {
853
+ "type": "function",
854
+ "name": "sellTokensForETH",
855
+ "inputs": [
856
+ {
857
+ "name": "auctionId",
858
+ "type": "uint256",
859
+ "internalType": "uint256"
860
+ },
861
+ {
862
+ "name": "amount",
863
+ "type": "uint256",
864
+ "internalType": "uint256"
865
+ },
866
+ {
867
+ "name": "minProceeds",
868
+ "type": "uint256",
869
+ "internalType": "uint256"
870
+ }
871
+ ],
872
+ "outputs": [],
873
+ "stateMutability": "nonpayable"
874
+ },
810
875
  {
811
876
  "type": "function",
812
877
  "name": "setDefaultFeeBps",
@@ -994,6 +1059,19 @@ var tokenAuctionAbi = [
994
1059
  ],
995
1060
  "stateMutability": "view"
996
1061
  },
1062
+ {
1063
+ "type": "function",
1064
+ "name": "weth",
1065
+ "inputs": [],
1066
+ "outputs": [
1067
+ {
1068
+ "name": "",
1069
+ "type": "address",
1070
+ "internalType": "contract IWETH9"
1071
+ }
1072
+ ],
1073
+ "stateMutability": "view"
1074
+ },
997
1075
  {
998
1076
  "type": "function",
999
1077
  "name": "withdrawProceeds",
@@ -1662,7 +1740,7 @@ function fillPurchase(currentSupply, requested, basePrice, slope, totalRaised, m
1662
1740
  if (cost < remaining) return { amount: requested, cost, fillsAuction: false };
1663
1741
  if (cost === remaining) return { amount: requested, cost, fillsAuction: true };
1664
1742
  const amount = maxBuyable(currentSupply, remaining, basePrice, slope, requested);
1665
- if (amount === 0n) throw new Error("Auction is sold out");
1743
+ if (amount === 0n) return { amount: 0n, cost: 0n, fillsAuction: true };
1666
1744
  return {
1667
1745
  amount,
1668
1746
  cost: calculateBuyCost(currentSupply, amount, basePrice, slope),
@@ -1740,9 +1818,10 @@ var AuctionFlowSDK = class {
1740
1818
  }
1741
1819
  /**
1742
1820
  * One-click launch: a token with the protocol's standard curve, threshold
1743
- * and liquidity share. Trading starts immediately.
1821
+ * and liquidity share for `paymentToken`. Trading starts immediately.
1822
+ * Defaults to WETH, so the token trades in plain ETH (see `buyTokensWithETH`).
1744
1823
  */
1745
- async launch(name, symbol, metadataURI = "") {
1824
+ async launch(name, symbol, metadataURI = "", paymentToken = WETH_ADDRESSES[this.chainId]) {
1746
1825
  if (!this.walletClient) throw new Error("Wallet client required");
1747
1826
  return this.walletClient.writeContract({
1748
1827
  chain: this.chain,
@@ -1750,9 +1829,20 @@ var AuctionFlowSDK = class {
1750
1829
  address: this.auctionAddress,
1751
1830
  abi: tokenAuctionAbi,
1752
1831
  functionName: "launch",
1753
- args: [name, symbol, metadataURI]
1832
+ args: [name, symbol, metadataURI, paymentToken]
1754
1833
  });
1755
1834
  }
1835
+ /** The standard launch for `paymentToken`, or null if none is configured. */
1836
+ async getLaunchPreset(paymentToken) {
1837
+ const [token, maxSupply, basePrice, slope, maxRaise, liquidityBps] = await this.publicClient.readContract({
1838
+ address: this.auctionAddress,
1839
+ abi: tokenAuctionAbi,
1840
+ functionName: "launchPresets",
1841
+ args: [paymentToken]
1842
+ });
1843
+ if (token === zeroAddress) return null;
1844
+ return { paymentToken: token, maxSupply, basePrice, slope, maxRaise, liquidityBps };
1845
+ }
1756
1846
  /**
1757
1847
  * Sell `amount` tokens (in token wei) back to the curve before graduation.
1758
1848
  * The contract reverts if the price fell below the bound before the
@@ -1774,6 +1864,25 @@ var AuctionFlowSDK = class {
1774
1864
  args: [auctionId, amount, minProceeds]
1775
1865
  });
1776
1866
  }
1867
+ /**
1868
+ * `sellTokens` for an auction priced in WETH, paid out in plain ETH. Takes
1869
+ * the same `minProceeds` / `slippageBps` options.
1870
+ */
1871
+ async sellTokensForETH(auctionId, amount, options = {}) {
1872
+ if (!this.walletClient) throw new Error("Wallet client required");
1873
+ const minProceeds = options.minProceeds ?? applySellSlippage(
1874
+ (await this.getSellQuote(auctionId, amount)).netProceeds,
1875
+ options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
1876
+ );
1877
+ return this.walletClient.writeContract({
1878
+ chain: this.chain,
1879
+ account: this.walletClient.account,
1880
+ address: this.auctionAddress,
1881
+ abi: tokenAuctionAbi,
1882
+ functionName: "sellTokensForETH",
1883
+ args: [auctionId, amount, minProceeds]
1884
+ });
1885
+ }
1777
1886
  /** What selling `amount` tokens back to the curve would pay right now. */
1778
1887
  async getSellQuote(auctionId, amount) {
1779
1888
  const auction = await this.getAuction(auctionId);
@@ -1810,6 +1919,33 @@ var AuctionFlowSDK = class {
1810
1919
  });
1811
1920
  return hash;
1812
1921
  }
1922
+ /**
1923
+ * `buyTokens` for an auction priced in WETH, paid in plain ETH, with no
1924
+ * token approval. The ETH sent is the most the purchase may cost (`maxCost`,
1925
+ * or a fresh quote plus `slippageBps`); whatever it doesn't use is refunded
1926
+ * in the same transaction.
1927
+ */
1928
+ async buyTokensWithETH(auctionId, amount, options = {}) {
1929
+ if (!this.walletClient) throw new Error("Wallet client required");
1930
+ const maxCost = options.maxCost ?? applySlippage(
1931
+ (await this.getQuote(auctionId, amount)).totalCost,
1932
+ options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
1933
+ );
1934
+ return this.walletClient.writeContract({
1935
+ chain: this.chain,
1936
+ account: this.walletClient.account,
1937
+ address: this.auctionAddress,
1938
+ abi: tokenAuctionAbi,
1939
+ functionName: "buyTokensWithETH",
1940
+ args: [auctionId, amount],
1941
+ value: maxCost
1942
+ });
1943
+ }
1944
+ /** Is this auction priced in WETH, so it can be bought and sold with plain ETH? */
1945
+ async isPricedInETH(auctionId) {
1946
+ const auction = await this.getAuction(auctionId);
1947
+ return auction.paymentToken.toLowerCase() === WETH_ADDRESSES[this.chainId].toLowerCase();
1948
+ }
1813
1949
  /**
1814
1950
  * Pay a completed auction's creator their share of the raise: everything
1815
1951
  * not reserved for Uniswap liquidity. Creator only, once, before or after
@@ -1934,13 +2070,27 @@ var AuctionFlowSDK = class {
1934
2070
  }
1935
2071
  // Read: Get auction data
1936
2072
  async getAuction(auctionId) {
1937
- const result = await this.publicClient.readContract({
2073
+ const [config, state, totalRaised, totalSold] = await this.publicClient.readContract({
1938
2074
  address: this.auctionAddress,
1939
2075
  abi: tokenAuctionAbi,
1940
2076
  functionName: "auctions",
1941
2077
  args: [auctionId]
1942
2078
  });
1943
- return this.parseAuctionResult(auctionId, result);
2079
+ return {
2080
+ id: auctionId,
2081
+ token: config.token,
2082
+ paymentToken: config.paymentToken,
2083
+ creator: config.creator,
2084
+ basePrice: config.basePrice,
2085
+ slope: config.slope,
2086
+ maxRaise: config.maxRaise,
2087
+ state,
2088
+ totalRaised,
2089
+ totalSold,
2090
+ protocolFeeBps: config.protocolFeeBps,
2091
+ liquidityBps: config.liquidityBps,
2092
+ lpFeeShareBps: config.lpFeeShareBps
2093
+ };
1944
2094
  }
1945
2095
  // Read: Get buy quote (off-chain calculation)
1946
2096
  async getQuote(auctionId, amount) {
@@ -1972,23 +2122,6 @@ var AuctionFlowSDK = class {
1972
2122
  args: [auctionId]
1973
2123
  });
1974
2124
  }
1975
- parseAuctionResult(id, raw) {
1976
- return {
1977
- id,
1978
- token: raw.config.token,
1979
- paymentToken: raw.config.paymentToken,
1980
- creator: raw.config.creator,
1981
- basePrice: raw.config.basePrice,
1982
- slope: raw.config.slope,
1983
- maxRaise: raw.config.maxRaise,
1984
- state: raw.state,
1985
- totalRaised: raw.totalRaised,
1986
- totalSold: raw.totalSold,
1987
- protocolFeeBps: raw.config.protocolFeeBps,
1988
- liquidityBps: raw.config.liquidityBps,
1989
- lpFeeShareBps: raw.config.lpFeeShareBps
1990
- };
1991
- }
1992
2125
  };
1993
2126
 
1994
2127
  // src/types/index.ts
@@ -2009,6 +2142,7 @@ export {
2009
2142
  MIN_LIQUIDITY_BPS,
2010
2143
  PRICE_SCALE,
2011
2144
  USDC_ADDRESSES,
2145
+ WETH_ADDRESSES,
2012
2146
  applySellSlippage,
2013
2147
  applySlippage,
2014
2148
  calculateBuyCost,
@@ -2018,6 +2152,7 @@ export {
2018
2152
  formatCurvePrice,
2019
2153
  maxBuyable,
2020
2154
  parseCurvePrice,
2021
- spotPrice
2155
+ spotPrice,
2156
+ tokenAuctionAbi
2022
2157
  };
2023
2158
  //# sourceMappingURL=index.mjs.map