auctionflow-sdk 2.1.0 → 3.0.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
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  MIN_LIQUIDITY_BPS: () => MIN_LIQUIDITY_BPS,
30
30
  PRICE_SCALE: () => PRICE_SCALE,
31
31
  USDC_ADDRESSES: () => USDC_ADDRESSES,
32
+ WETH_ADDRESSES: () => WETH_ADDRESSES,
32
33
  applySellSlippage: () => applySellSlippage,
33
34
  applySlippage: () => applySlippage,
34
35
  calculateBuyCost: () => calculateBuyCost,
@@ -38,7 +39,8 @@ __export(index_exports, {
38
39
  formatCurvePrice: () => formatCurvePrice,
39
40
  maxBuyable: () => maxBuyable,
40
41
  parseCurvePrice: () => parseCurvePrice,
41
- spotPrice: () => spotPrice
42
+ spotPrice: () => spotPrice,
43
+ tokenAuctionAbi: () => tokenAuctionAbi
42
44
  });
43
45
  module.exports = __toCommonJS(index_exports);
44
46
 
@@ -117,7 +119,7 @@ var AuctionBuilder = class {
117
119
 
118
120
  // src/constants/addresses.ts
119
121
  var AUCTION_ADDRESSES = {
120
- 84532: "0xe57fe62e31666a9b749e89086a8a5487a530153b",
122
+ 84532: "0x990a04ffe0d49356321271629889fa0413ad1bdc",
121
123
  8453: "0x0000000000000000000000000000000000000000"
122
124
  // not yet deployed
123
125
  };
@@ -125,6 +127,10 @@ var USDC_ADDRESSES = {
125
127
  84532: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
126
128
  8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
127
129
  };
130
+ var WETH_ADDRESSES = {
131
+ 84532: "0x4200000000000000000000000000000000000006",
132
+ 8453: "0x4200000000000000000000000000000000000006"
133
+ };
128
134
 
129
135
  // src/abis/token-auction.ts
130
136
  var tokenAuctionAbi = [
@@ -145,10 +151,19 @@ var tokenAuctionAbi = [
145
151
  "name": "positionManager_",
146
152
  "type": "address",
147
153
  "internalType": "contract INonfungiblePositionManager"
154
+ },
155
+ {
156
+ "name": "weth_",
157
+ "type": "address",
158
+ "internalType": "contract IWETH9"
148
159
  }
149
160
  ],
150
161
  "stateMutability": "nonpayable"
151
162
  },
163
+ {
164
+ "type": "receive",
165
+ "stateMutability": "payable"
166
+ },
152
167
  {
153
168
  "type": "function",
154
169
  "name": "MAX_FEE_BPS",
@@ -325,6 +340,24 @@ var tokenAuctionAbi = [
325
340
  "outputs": [],
326
341
  "stateMutability": "nonpayable"
327
342
  },
343
+ {
344
+ "type": "function",
345
+ "name": "buyTokensWithETH",
346
+ "inputs": [
347
+ {
348
+ "name": "auctionId",
349
+ "type": "uint256",
350
+ "internalType": "uint256"
351
+ },
352
+ {
353
+ "name": "amount",
354
+ "type": "uint256",
355
+ "internalType": "uint256"
356
+ }
357
+ ],
358
+ "outputs": [],
359
+ "stateMutability": "payable"
360
+ },
328
361
  {
329
362
  "type": "function",
330
363
  "name": "claim",
@@ -588,6 +621,11 @@ var tokenAuctionAbi = [
588
621
  "name": "metadataURI",
589
622
  "type": "string",
590
623
  "internalType": "string"
624
+ },
625
+ {
626
+ "name": "paymentToken",
627
+ "type": "address",
628
+ "internalType": "address"
591
629
  }
592
630
  ],
593
631
  "outputs": [
@@ -601,8 +639,14 @@ var tokenAuctionAbi = [
601
639
  },
602
640
  {
603
641
  "type": "function",
604
- "name": "launchPreset",
605
- "inputs": [],
642
+ "name": "launchPresets",
643
+ "inputs": [
644
+ {
645
+ "name": "",
646
+ "type": "address",
647
+ "internalType": "address"
648
+ }
649
+ ],
606
650
  "outputs": [
607
651
  {
608
652
  "name": "paymentToken",
@@ -847,6 +891,29 @@ var tokenAuctionAbi = [
847
891
  "outputs": [],
848
892
  "stateMutability": "nonpayable"
849
893
  },
894
+ {
895
+ "type": "function",
896
+ "name": "sellTokensForETH",
897
+ "inputs": [
898
+ {
899
+ "name": "auctionId",
900
+ "type": "uint256",
901
+ "internalType": "uint256"
902
+ },
903
+ {
904
+ "name": "amount",
905
+ "type": "uint256",
906
+ "internalType": "uint256"
907
+ },
908
+ {
909
+ "name": "minProceeds",
910
+ "type": "uint256",
911
+ "internalType": "uint256"
912
+ }
913
+ ],
914
+ "outputs": [],
915
+ "stateMutability": "nonpayable"
916
+ },
850
917
  {
851
918
  "type": "function",
852
919
  "name": "setDefaultFeeBps",
@@ -1034,6 +1101,19 @@ var tokenAuctionAbi = [
1034
1101
  ],
1035
1102
  "stateMutability": "view"
1036
1103
  },
1104
+ {
1105
+ "type": "function",
1106
+ "name": "weth",
1107
+ "inputs": [],
1108
+ "outputs": [
1109
+ {
1110
+ "name": "",
1111
+ "type": "address",
1112
+ "internalType": "contract IWETH9"
1113
+ }
1114
+ ],
1115
+ "stateMutability": "view"
1116
+ },
1037
1117
  {
1038
1118
  "type": "function",
1039
1119
  "name": "withdrawProceeds",
@@ -1702,7 +1782,7 @@ function fillPurchase(currentSupply, requested, basePrice, slope, totalRaised, m
1702
1782
  if (cost < remaining) return { amount: requested, cost, fillsAuction: false };
1703
1783
  if (cost === remaining) return { amount: requested, cost, fillsAuction: true };
1704
1784
  const amount = maxBuyable(currentSupply, remaining, basePrice, slope, requested);
1705
- if (amount === 0n) throw new Error("Auction is sold out");
1785
+ if (amount === 0n) return { amount: 0n, cost: 0n, fillsAuction: true };
1706
1786
  return {
1707
1787
  amount,
1708
1788
  cost: calculateBuyCost(currentSupply, amount, basePrice, slope),
@@ -1780,9 +1860,10 @@ var AuctionFlowSDK = class {
1780
1860
  }
1781
1861
  /**
1782
1862
  * One-click launch: a token with the protocol's standard curve, threshold
1783
- * and liquidity share. Trading starts immediately.
1863
+ * and liquidity share for `paymentToken`. Trading starts immediately.
1864
+ * Defaults to WETH, so the token trades in plain ETH (see `buyTokensWithETH`).
1784
1865
  */
1785
- async launch(name, symbol, metadataURI = "") {
1866
+ async launch(name, symbol, metadataURI = "", paymentToken = WETH_ADDRESSES[this.chainId]) {
1786
1867
  if (!this.walletClient) throw new Error("Wallet client required");
1787
1868
  return this.walletClient.writeContract({
1788
1869
  chain: this.chain,
@@ -1790,9 +1871,20 @@ var AuctionFlowSDK = class {
1790
1871
  address: this.auctionAddress,
1791
1872
  abi: tokenAuctionAbi,
1792
1873
  functionName: "launch",
1793
- args: [name, symbol, metadataURI]
1874
+ args: [name, symbol, metadataURI, paymentToken]
1794
1875
  });
1795
1876
  }
1877
+ /** The standard launch for `paymentToken`, or null if none is configured. */
1878
+ async getLaunchPreset(paymentToken) {
1879
+ const [token, maxSupply, basePrice, slope, maxRaise, liquidityBps] = await this.publicClient.readContract({
1880
+ address: this.auctionAddress,
1881
+ abi: tokenAuctionAbi,
1882
+ functionName: "launchPresets",
1883
+ args: [paymentToken]
1884
+ });
1885
+ if (token === import_viem2.zeroAddress) return null;
1886
+ return { paymentToken: token, maxSupply, basePrice, slope, maxRaise, liquidityBps };
1887
+ }
1796
1888
  /**
1797
1889
  * Sell `amount` tokens (in token wei) back to the curve before graduation.
1798
1890
  * The contract reverts if the price fell below the bound before the
@@ -1814,6 +1906,25 @@ var AuctionFlowSDK = class {
1814
1906
  args: [auctionId, amount, minProceeds]
1815
1907
  });
1816
1908
  }
1909
+ /**
1910
+ * `sellTokens` for an auction priced in WETH, paid out in plain ETH. Takes
1911
+ * the same `minProceeds` / `slippageBps` options.
1912
+ */
1913
+ async sellTokensForETH(auctionId, amount, options = {}) {
1914
+ if (!this.walletClient) throw new Error("Wallet client required");
1915
+ const minProceeds = options.minProceeds ?? applySellSlippage(
1916
+ (await this.getSellQuote(auctionId, amount)).netProceeds,
1917
+ options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
1918
+ );
1919
+ return this.walletClient.writeContract({
1920
+ chain: this.chain,
1921
+ account: this.walletClient.account,
1922
+ address: this.auctionAddress,
1923
+ abi: tokenAuctionAbi,
1924
+ functionName: "sellTokensForETH",
1925
+ args: [auctionId, amount, minProceeds]
1926
+ });
1927
+ }
1817
1928
  /** What selling `amount` tokens back to the curve would pay right now. */
1818
1929
  async getSellQuote(auctionId, amount) {
1819
1930
  const auction = await this.getAuction(auctionId);
@@ -1850,6 +1961,33 @@ var AuctionFlowSDK = class {
1850
1961
  });
1851
1962
  return hash;
1852
1963
  }
1964
+ /**
1965
+ * `buyTokens` for an auction priced in WETH, paid in plain ETH, with no
1966
+ * token approval. The ETH sent is the most the purchase may cost (`maxCost`,
1967
+ * or a fresh quote plus `slippageBps`); whatever it doesn't use is refunded
1968
+ * in the same transaction.
1969
+ */
1970
+ async buyTokensWithETH(auctionId, amount, options = {}) {
1971
+ if (!this.walletClient) throw new Error("Wallet client required");
1972
+ const maxCost = options.maxCost ?? applySlippage(
1973
+ (await this.getQuote(auctionId, amount)).totalCost,
1974
+ options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
1975
+ );
1976
+ return this.walletClient.writeContract({
1977
+ chain: this.chain,
1978
+ account: this.walletClient.account,
1979
+ address: this.auctionAddress,
1980
+ abi: tokenAuctionAbi,
1981
+ functionName: "buyTokensWithETH",
1982
+ args: [auctionId, amount],
1983
+ value: maxCost
1984
+ });
1985
+ }
1986
+ /** Is this auction priced in WETH, so it can be bought and sold with plain ETH? */
1987
+ async isPricedInETH(auctionId) {
1988
+ const auction = await this.getAuction(auctionId);
1989
+ return auction.paymentToken.toLowerCase() === WETH_ADDRESSES[this.chainId].toLowerCase();
1990
+ }
1853
1991
  /**
1854
1992
  * Pay a completed auction's creator their share of the raise: everything
1855
1993
  * not reserved for Uniswap liquidity. Creator only, once, before or after
@@ -1974,13 +2112,27 @@ var AuctionFlowSDK = class {
1974
2112
  }
1975
2113
  // Read: Get auction data
1976
2114
  async getAuction(auctionId) {
1977
- const result = await this.publicClient.readContract({
2115
+ const [config, state, totalRaised, totalSold] = await this.publicClient.readContract({
1978
2116
  address: this.auctionAddress,
1979
2117
  abi: tokenAuctionAbi,
1980
2118
  functionName: "auctions",
1981
2119
  args: [auctionId]
1982
2120
  });
1983
- return this.parseAuctionResult(auctionId, result);
2121
+ return {
2122
+ id: auctionId,
2123
+ token: config.token,
2124
+ paymentToken: config.paymentToken,
2125
+ creator: config.creator,
2126
+ basePrice: config.basePrice,
2127
+ slope: config.slope,
2128
+ maxRaise: config.maxRaise,
2129
+ state,
2130
+ totalRaised,
2131
+ totalSold,
2132
+ protocolFeeBps: config.protocolFeeBps,
2133
+ liquidityBps: config.liquidityBps,
2134
+ lpFeeShareBps: config.lpFeeShareBps
2135
+ };
1984
2136
  }
1985
2137
  // Read: Get buy quote (off-chain calculation)
1986
2138
  async getQuote(auctionId, amount) {
@@ -2012,23 +2164,6 @@ var AuctionFlowSDK = class {
2012
2164
  args: [auctionId]
2013
2165
  });
2014
2166
  }
2015
- parseAuctionResult(id, raw) {
2016
- return {
2017
- id,
2018
- token: raw.config.token,
2019
- paymentToken: raw.config.paymentToken,
2020
- creator: raw.config.creator,
2021
- basePrice: raw.config.basePrice,
2022
- slope: raw.config.slope,
2023
- maxRaise: raw.config.maxRaise,
2024
- state: raw.state,
2025
- totalRaised: raw.totalRaised,
2026
- totalSold: raw.totalSold,
2027
- protocolFeeBps: raw.config.protocolFeeBps,
2028
- liquidityBps: raw.config.liquidityBps,
2029
- lpFeeShareBps: raw.config.lpFeeShareBps
2030
- };
2031
- }
2032
2167
  };
2033
2168
 
2034
2169
  // src/types/index.ts
@@ -2050,6 +2185,7 @@ var AuctionState = /* @__PURE__ */ ((AuctionState2) => {
2050
2185
  MIN_LIQUIDITY_BPS,
2051
2186
  PRICE_SCALE,
2052
2187
  USDC_ADDRESSES,
2188
+ WETH_ADDRESSES,
2053
2189
  applySellSlippage,
2054
2190
  applySlippage,
2055
2191
  calculateBuyCost,
@@ -2059,6 +2195,7 @@ var AuctionState = /* @__PURE__ */ ((AuctionState2) => {
2059
2195
  formatCurvePrice,
2060
2196
  maxBuyable,
2061
2197
  parseCurvePrice,
2062
- spotPrice
2198
+ spotPrice,
2199
+ tokenAuctionAbi
2063
2200
  });
2064
2201
  //# sourceMappingURL=index.js.map