auctionflow-sdk 1.3.0 → 2.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.js CHANGED
@@ -27,18 +27,23 @@ __export(index_exports, {
27
27
  DEFAULT_LIQUIDITY_BPS: () => DEFAULT_LIQUIDITY_BPS,
28
28
  DEFAULT_SLIPPAGE_BPS: () => DEFAULT_SLIPPAGE_BPS,
29
29
  MIN_LIQUIDITY_BPS: () => MIN_LIQUIDITY_BPS,
30
+ PRICE_SCALE: () => PRICE_SCALE,
30
31
  USDC_ADDRESSES: () => USDC_ADDRESSES,
32
+ applySellSlippage: () => applySellSlippage,
31
33
  applySlippage: () => applySlippage,
32
34
  calculateBuyCost: () => calculateBuyCost,
33
35
  calculateBuyQuote: () => calculateBuyQuote,
36
+ calculateSellProceeds: () => calculateSellProceeds,
34
37
  fillPurchase: () => fillPurchase,
38
+ formatCurvePrice: () => formatCurvePrice,
35
39
  maxBuyable: () => maxBuyable,
40
+ parseCurvePrice: () => parseCurvePrice,
36
41
  spotPrice: () => spotPrice
37
42
  });
38
43
  module.exports = __toCommonJS(index_exports);
39
44
 
40
45
  // src/client.ts
41
- var import_viem = require("viem");
46
+ var import_viem2 = require("viem");
42
47
 
43
48
  // src/constants/protocol.ts
44
49
  var MIN_LIQUIDITY_BPS = 2e3;
@@ -62,6 +67,7 @@ var AuctionBuilder = class {
62
67
  this.config.slope = slope;
63
68
  return this;
64
69
  }
70
+ /** Graduation threshold: once this much is raised, trading moves to Uniswap. */
65
71
  withMaxRaise(maxRaise) {
66
72
  this.config.maxRaise = maxRaise;
67
73
  return this;
@@ -76,9 +82,9 @@ var AuctionBuilder = class {
76
82
  this.config.liquidityBps = BigInt(liquidityBps);
77
83
  return this;
78
84
  }
79
- withSchedule(startTime, endTime) {
80
- this.config.startTime = startTime;
81
- this.config.endTime = endTime;
85
+ /** Off-chain metadata for the token, such as its image (e.g. an IPFS URI). */
86
+ withMetadata(metadataURI) {
87
+ this.config.metadataURI = metadataURI;
82
88
  return this;
83
89
  }
84
90
  build() {
@@ -89,9 +95,7 @@ var AuctionBuilder = class {
89
95
  "paymentToken",
90
96
  "basePrice",
91
97
  "slope",
92
- "maxRaise",
93
- "startTime",
94
- "endTime"
98
+ "maxRaise"
95
99
  ];
96
100
  for (const key of required) {
97
101
  if (this.config[key] === void 0) {
@@ -107,16 +111,13 @@ var AuctionBuilder = class {
107
111
  if (liquidityBps < BigInt(MIN_LIQUIDITY_BPS) || liquidityBps > 10000n) {
108
112
  throw new Error(`liquidityBps must be between ${MIN_LIQUIDITY_BPS} and 10000`);
109
113
  }
110
- if (config.startTime >= config.endTime) {
111
- throw new Error("startTime must be before endTime");
112
- }
113
114
  return config;
114
115
  }
115
116
  };
116
117
 
117
118
  // src/constants/addresses.ts
118
119
  var AUCTION_ADDRESSES = {
119
- 84532: "0x722f4521b96aca1df7c65a1dbe3b1713803ccea9",
120
+ 84532: "0x24a702f10f17a522b9b5511ec2970ee029195ee4",
120
121
  8453: "0x0000000000000000000000000000000000000000"
121
122
  // not yet deployed
122
123
  };
@@ -254,16 +255,6 @@ var tokenAuctionAbi = [
254
255
  "type": "uint256",
255
256
  "internalType": "uint256"
256
257
  },
257
- {
258
- "name": "startTime",
259
- "type": "uint256",
260
- "internalType": "uint256"
261
- },
262
- {
263
- "name": "endTime",
264
- "type": "uint256",
265
- "internalType": "uint256"
266
- },
267
258
  {
268
259
  "name": "creator",
269
260
  "type": "address",
@@ -351,19 +342,6 @@ var tokenAuctionAbi = [
351
342
  ],
352
343
  "stateMutability": "nonpayable"
353
344
  },
354
- {
355
- "type": "function",
356
- "name": "completeAuction",
357
- "inputs": [
358
- {
359
- "name": "auctionId",
360
- "type": "uint256",
361
- "internalType": "uint256"
362
- }
363
- ],
364
- "outputs": [],
365
- "stateMutability": "nonpayable"
366
- },
367
345
  {
368
346
  "type": "function",
369
347
  "name": "createAuction",
@@ -383,6 +361,11 @@ var tokenAuctionAbi = [
383
361
  "type": "string",
384
362
  "internalType": "string"
385
363
  },
364
+ {
365
+ "name": "metadataURI",
366
+ "type": "string",
367
+ "internalType": "string"
368
+ },
386
369
  {
387
370
  "name": "maxSupply",
388
371
  "type": "uint256",
@@ -408,16 +391,6 @@ var tokenAuctionAbi = [
408
391
  "type": "uint256",
409
392
  "internalType": "uint256"
410
393
  },
411
- {
412
- "name": "startTime",
413
- "type": "uint256",
414
- "internalType": "uint256"
415
- },
416
- {
417
- "name": "endTime",
418
- "type": "uint256",
419
- "internalType": "uint256"
420
- },
421
394
  {
422
395
  "name": "liquidityBps",
423
396
  "type": "uint256",
@@ -528,6 +501,73 @@ var tokenAuctionAbi = [
528
501
  ],
529
502
  "stateMutability": "view"
530
503
  },
504
+ {
505
+ "type": "function",
506
+ "name": "launch",
507
+ "inputs": [
508
+ {
509
+ "name": "name",
510
+ "type": "string",
511
+ "internalType": "string"
512
+ },
513
+ {
514
+ "name": "symbol",
515
+ "type": "string",
516
+ "internalType": "string"
517
+ },
518
+ {
519
+ "name": "metadataURI",
520
+ "type": "string",
521
+ "internalType": "string"
522
+ }
523
+ ],
524
+ "outputs": [
525
+ {
526
+ "name": "auctionId",
527
+ "type": "uint256",
528
+ "internalType": "uint256"
529
+ }
530
+ ],
531
+ "stateMutability": "nonpayable"
532
+ },
533
+ {
534
+ "type": "function",
535
+ "name": "launchPreset",
536
+ "inputs": [],
537
+ "outputs": [
538
+ {
539
+ "name": "paymentToken",
540
+ "type": "address",
541
+ "internalType": "address"
542
+ },
543
+ {
544
+ "name": "maxSupply",
545
+ "type": "uint256",
546
+ "internalType": "uint256"
547
+ },
548
+ {
549
+ "name": "basePrice",
550
+ "type": "uint256",
551
+ "internalType": "uint256"
552
+ },
553
+ {
554
+ "name": "slope",
555
+ "type": "uint256",
556
+ "internalType": "uint256"
557
+ },
558
+ {
559
+ "name": "maxRaise",
560
+ "type": "uint256",
561
+ "internalType": "uint256"
562
+ },
563
+ {
564
+ "name": "liquidityBps",
565
+ "type": "uint256",
566
+ "internalType": "uint256"
567
+ }
568
+ ],
569
+ "stateMutability": "view"
570
+ },
531
571
  {
532
572
  "type": "function",
533
573
  "name": "migrate",
@@ -644,6 +684,29 @@ var tokenAuctionAbi = [
644
684
  "outputs": [],
645
685
  "stateMutability": "nonpayable"
646
686
  },
687
+ {
688
+ "type": "function",
689
+ "name": "sellTokens",
690
+ "inputs": [
691
+ {
692
+ "name": "auctionId",
693
+ "type": "uint256",
694
+ "internalType": "uint256"
695
+ },
696
+ {
697
+ "name": "amount",
698
+ "type": "uint256",
699
+ "internalType": "uint256"
700
+ },
701
+ {
702
+ "name": "minProceeds",
703
+ "type": "uint256",
704
+ "internalType": "uint256"
705
+ }
706
+ ],
707
+ "outputs": [],
708
+ "stateMutability": "nonpayable"
709
+ },
647
710
  {
648
711
  "type": "function",
649
712
  "name": "setDefaultFeeBps",
@@ -670,6 +733,51 @@ var tokenAuctionAbi = [
670
733
  "outputs": [],
671
734
  "stateMutability": "nonpayable"
672
735
  },
736
+ {
737
+ "type": "function",
738
+ "name": "setLaunchPreset",
739
+ "inputs": [
740
+ {
741
+ "name": "preset",
742
+ "type": "tuple",
743
+ "internalType": "struct TokenAuction.LaunchPreset",
744
+ "components": [
745
+ {
746
+ "name": "paymentToken",
747
+ "type": "address",
748
+ "internalType": "address"
749
+ },
750
+ {
751
+ "name": "maxSupply",
752
+ "type": "uint256",
753
+ "internalType": "uint256"
754
+ },
755
+ {
756
+ "name": "basePrice",
757
+ "type": "uint256",
758
+ "internalType": "uint256"
759
+ },
760
+ {
761
+ "name": "slope",
762
+ "type": "uint256",
763
+ "internalType": "uint256"
764
+ },
765
+ {
766
+ "name": "maxRaise",
767
+ "type": "uint256",
768
+ "internalType": "uint256"
769
+ },
770
+ {
771
+ "name": "liquidityBps",
772
+ "type": "uint256",
773
+ "internalType": "uint256"
774
+ }
775
+ ]
776
+ }
777
+ ],
778
+ "outputs": [],
779
+ "stateMutability": "nonpayable"
780
+ },
673
781
  {
674
782
  "type": "function",
675
783
  "name": "setProtocolFeeRecipient",
@@ -846,22 +954,16 @@ var tokenAuctionAbi = [
846
954
  "internalType": "uint256"
847
955
  },
848
956
  {
849
- "name": "startTime",
850
- "type": "uint256",
851
- "indexed": false,
852
- "internalType": "uint256"
853
- },
854
- {
855
- "name": "endTime",
957
+ "name": "liquidityBps",
856
958
  "type": "uint256",
857
959
  "indexed": false,
858
960
  "internalType": "uint256"
859
961
  },
860
962
  {
861
- "name": "liquidityBps",
862
- "type": "uint256",
963
+ "name": "metadataURI",
964
+ "type": "string",
863
965
  "indexed": false,
864
- "internalType": "uint256"
966
+ "internalType": "string"
865
967
  }
866
968
  ],
867
969
  "anonymous": false
@@ -941,6 +1043,49 @@ var tokenAuctionAbi = [
941
1043
  ],
942
1044
  "anonymous": false
943
1045
  },
1046
+ {
1047
+ "type": "event",
1048
+ "name": "LaunchPresetUpdated",
1049
+ "inputs": [
1050
+ {
1051
+ "name": "paymentToken",
1052
+ "type": "address",
1053
+ "indexed": false,
1054
+ "internalType": "address"
1055
+ },
1056
+ {
1057
+ "name": "maxSupply",
1058
+ "type": "uint256",
1059
+ "indexed": false,
1060
+ "internalType": "uint256"
1061
+ },
1062
+ {
1063
+ "name": "basePrice",
1064
+ "type": "uint256",
1065
+ "indexed": false,
1066
+ "internalType": "uint256"
1067
+ },
1068
+ {
1069
+ "name": "slope",
1070
+ "type": "uint256",
1071
+ "indexed": false,
1072
+ "internalType": "uint256"
1073
+ },
1074
+ {
1075
+ "name": "maxRaise",
1076
+ "type": "uint256",
1077
+ "indexed": false,
1078
+ "internalType": "uint256"
1079
+ },
1080
+ {
1081
+ "name": "liquidityBps",
1082
+ "type": "uint256",
1083
+ "indexed": false,
1084
+ "internalType": "uint256"
1085
+ }
1086
+ ],
1087
+ "anonymous": false
1088
+ },
944
1089
  {
945
1090
  "type": "event",
946
1091
  "name": "LpFeesCollected",
@@ -1115,6 +1260,55 @@ var tokenAuctionAbi = [
1115
1260
  ],
1116
1261
  "anonymous": false
1117
1262
  },
1263
+ {
1264
+ "type": "event",
1265
+ "name": "TokensSold",
1266
+ "inputs": [
1267
+ {
1268
+ "name": "auctionId",
1269
+ "type": "uint256",
1270
+ "indexed": true,
1271
+ "internalType": "uint256"
1272
+ },
1273
+ {
1274
+ "name": "seller",
1275
+ "type": "address",
1276
+ "indexed": true,
1277
+ "internalType": "address"
1278
+ },
1279
+ {
1280
+ "name": "amount",
1281
+ "type": "uint256",
1282
+ "indexed": false,
1283
+ "internalType": "uint256"
1284
+ },
1285
+ {
1286
+ "name": "proceeds",
1287
+ "type": "uint256",
1288
+ "indexed": false,
1289
+ "internalType": "uint256"
1290
+ },
1291
+ {
1292
+ "name": "protocolFee",
1293
+ "type": "uint256",
1294
+ "indexed": false,
1295
+ "internalType": "uint256"
1296
+ },
1297
+ {
1298
+ "name": "newTotalRaised",
1299
+ "type": "uint256",
1300
+ "indexed": false,
1301
+ "internalType": "uint256"
1302
+ },
1303
+ {
1304
+ "name": "newTotalSold",
1305
+ "type": "uint256",
1306
+ "indexed": false,
1307
+ "internalType": "uint256"
1308
+ }
1309
+ ],
1310
+ "anonymous": false
1311
+ },
1118
1312
  {
1119
1313
  "type": "error",
1120
1314
  "name": "OwnableInvalidOwner",
@@ -1156,16 +1350,32 @@ var tokenAuctionAbi = [
1156
1350
  ];
1157
1351
 
1158
1352
  // src/utils/bonding-curve.ts
1353
+ var import_viem = require("viem");
1159
1354
  var TOKEN_SCALE = 10n ** 18n;
1355
+ var PRICE_SCALE = 10n ** 18n;
1356
+ var SCALE = TOKEN_SCALE * PRICE_SCALE;
1357
+ function parseCurvePrice(price, paymentDecimals) {
1358
+ return (0, import_viem.parseUnits)(price, paymentDecimals + 18);
1359
+ }
1360
+ function formatCurvePrice(price, paymentDecimals) {
1361
+ return (0, import_viem.formatUnits)(price, paymentDecimals + 18);
1362
+ }
1160
1363
  var ceilDiv = (a, b) => (a + b - 1n) / b;
1161
1364
  function calculateBuyCost(currentSupply, amount, basePrice, slope) {
1162
- const linearCost = ceilDiv(basePrice * amount, TOKEN_SCALE);
1365
+ const linearCost = ceilDiv(basePrice * amount, SCALE);
1163
1366
  const curveCost = ceilDiv(
1164
1367
  slope * amount * (2n * currentSupply + amount),
1165
- 2n * TOKEN_SCALE * TOKEN_SCALE
1368
+ 2n * SCALE * TOKEN_SCALE
1166
1369
  );
1167
1370
  return linearCost + curveCost;
1168
1371
  }
1372
+ function calculateSellProceeds(currentSupply, amount, basePrice, slope) {
1373
+ if (amount > currentSupply) throw new Error("Cannot sell more than is outstanding");
1374
+ const from = currentSupply - amount;
1375
+ const linear = basePrice * amount / SCALE;
1376
+ const curve = slope * amount * (2n * from + amount) / (2n * SCALE * TOKEN_SCALE);
1377
+ return linear + curve;
1378
+ }
1169
1379
  function spotPrice(currentSupply, basePrice, slope) {
1170
1380
  return basePrice + slope * currentSupply / TOKEN_SCALE;
1171
1381
  }
@@ -1187,7 +1397,7 @@ function applySlippage(total, slippageBps) {
1187
1397
  return (total * BigInt(1e4 + slippageBps) + 9999n) / 10000n;
1188
1398
  }
1189
1399
  function maxBuyable(currentSupply, budget, basePrice, slope, upperBound) {
1190
- let hi = budget * TOKEN_SCALE / basePrice + 1n;
1400
+ let hi = budget * SCALE / basePrice + 1n;
1191
1401
  if (hi > upperBound) hi = upperBound;
1192
1402
  let lo = 0n;
1193
1403
  while (lo < hi) {
@@ -1210,6 +1420,12 @@ function fillPurchase(currentSupply, requested, basePrice, slope, totalRaised, m
1210
1420
  fillsAuction: true
1211
1421
  };
1212
1422
  }
1423
+ function applySellSlippage(netProceeds, slippageBps) {
1424
+ if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > 1e4) {
1425
+ throw new Error("slippageBps must be an integer between 0 and 10000");
1426
+ }
1427
+ return netProceeds * BigInt(1e4 - slippageBps) / 10000n;
1428
+ }
1213
1429
 
1214
1430
  // src/utils/chains.ts
1215
1431
  var import_chains = require("viem/chains");
@@ -1229,19 +1445,19 @@ var AuctionFlowSDK = class {
1229
1445
  this.chainId = params.chainId;
1230
1446
  this.chain = CHAINS[params.chainId];
1231
1447
  this.auctionAddress = params.auctionAddress ?? AUCTION_ADDRESSES[params.chainId];
1232
- if (params.auctionAddress === import_viem.zeroAddress) {
1448
+ if (params.auctionAddress === import_viem2.zeroAddress) {
1233
1449
  throw new Error(
1234
1450
  "auctionAddress must not be the zero address."
1235
1451
  );
1236
1452
  }
1237
- if (this.auctionAddress === import_viem.zeroAddress) {
1453
+ if (this.auctionAddress === import_viem2.zeroAddress) {
1238
1454
  throw new Error(
1239
- `AuctionFlow has no canonical deployment on chain ${params.chainId}. Chains with a built-in deployment: ${Object.entries(AUCTION_ADDRESSES).filter(([, addr]) => addr !== import_viem.zeroAddress).map(([id]) => id).join(", ")}. Pass \`auctionAddress\` to use your own deployment.`
1455
+ `AuctionFlow has no canonical deployment on chain ${params.chainId}. Chains with a built-in deployment: ${Object.entries(AUCTION_ADDRESSES).filter(([, addr]) => addr !== import_viem2.zeroAddress).map(([id]) => id).join(", ")}. Pass \`auctionAddress\` to use your own deployment.`
1240
1456
  );
1241
1457
  }
1242
- this.publicClient = (0, import_viem.createPublicClient)({
1458
+ this.publicClient = (0, import_viem2.createPublicClient)({
1243
1459
  chain: this.chain,
1244
- transport: (0, import_viem.http)(params.rpcUrl)
1460
+ transport: (0, import_viem2.http)(params.rpcUrl)
1245
1461
  });
1246
1462
  this.walletClient = params.walletClient;
1247
1463
  }
@@ -1261,19 +1477,66 @@ var AuctionFlowSDK = class {
1261
1477
  {
1262
1478
  name: config.name,
1263
1479
  symbol: config.symbol,
1480
+ metadataURI: config.metadataURI ?? "",
1264
1481
  maxSupply: config.maxSupply,
1265
1482
  paymentToken: config.paymentToken,
1266
1483
  basePrice: config.basePrice,
1267
1484
  slope: config.slope,
1268
1485
  maxRaise: config.maxRaise,
1269
- startTime: config.startTime,
1270
- endTime: config.endTime,
1271
1486
  liquidityBps: config.liquidityBps ?? BigInt(DEFAULT_LIQUIDITY_BPS)
1272
1487
  }
1273
1488
  ]
1274
1489
  });
1275
1490
  return hash;
1276
1491
  }
1492
+ /**
1493
+ * One-click launch: a token with the protocol's standard curve, threshold
1494
+ * and liquidity share. Trading starts immediately.
1495
+ */
1496
+ async launch(name, symbol, metadataURI = "") {
1497
+ if (!this.walletClient) throw new Error("Wallet client required");
1498
+ return this.walletClient.writeContract({
1499
+ chain: this.chain,
1500
+ account: this.walletClient.account,
1501
+ address: this.auctionAddress,
1502
+ abi: tokenAuctionAbi,
1503
+ functionName: "launch",
1504
+ args: [name, symbol, metadataURI]
1505
+ });
1506
+ }
1507
+ /**
1508
+ * Sell `amount` tokens (in token wei) back to the curve before graduation.
1509
+ * The contract reverts if the price fell below the bound before the
1510
+ * transaction landed: pass `minProceeds` to set it exactly, or `slippageBps`
1511
+ * to derive it from a fresh quote (default 100 = 1% below it).
1512
+ */
1513
+ async sellTokens(auctionId, amount, options = {}) {
1514
+ if (!this.walletClient) throw new Error("Wallet client required");
1515
+ const minProceeds = options.minProceeds ?? applySellSlippage(
1516
+ (await this.getSellQuote(auctionId, amount)).netProceeds,
1517
+ options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
1518
+ );
1519
+ return this.walletClient.writeContract({
1520
+ chain: this.chain,
1521
+ account: this.walletClient.account,
1522
+ address: this.auctionAddress,
1523
+ abi: tokenAuctionAbi,
1524
+ functionName: "sellTokens",
1525
+ args: [auctionId, amount, minProceeds]
1526
+ });
1527
+ }
1528
+ /** What selling `amount` tokens back to the curve would pay right now. */
1529
+ async getSellQuote(auctionId, amount) {
1530
+ const auction = await this.getAuction(auctionId);
1531
+ const proceeds = calculateSellProceeds(auction.totalSold, amount, auction.basePrice, auction.slope);
1532
+ const fee = proceeds * auction.protocolFeeBps / 10000n;
1533
+ return {
1534
+ proceeds,
1535
+ fee,
1536
+ netProceeds: proceeds - fee,
1537
+ spotPriceAfter: spotPrice(auction.totalSold - amount, auction.basePrice, auction.slope)
1538
+ };
1539
+ }
1277
1540
  /**
1278
1541
  * Buy `amount` tokens (in token wei). The price rises with every purchase, so
1279
1542
  * the contract takes a maximum total cost and reverts if the price moved past
@@ -1347,7 +1610,7 @@ var AuctionFlowSDK = class {
1347
1610
  })
1348
1611
  ]);
1349
1612
  return {
1350
- pool: pool === import_viem.zeroAddress ? null : pool,
1613
+ pool: pool === import_viem2.zeroAddress ? null : pool,
1351
1614
  positionId: positionId === 0n ? null : positionId
1352
1615
  };
1353
1616
  }
@@ -1420,8 +1683,6 @@ var AuctionFlowSDK = class {
1420
1683
  basePrice: raw.config.basePrice,
1421
1684
  slope: raw.config.slope,
1422
1685
  maxRaise: raw.config.maxRaise,
1423
- startTime: raw.config.startTime,
1424
- endTime: raw.config.endTime,
1425
1686
  state: raw.state,
1426
1687
  totalRaised: raw.totalRaised,
1427
1688
  totalSold: raw.totalSold,
@@ -1449,12 +1710,17 @@ var AuctionState = /* @__PURE__ */ ((AuctionState2) => {
1449
1710
  DEFAULT_LIQUIDITY_BPS,
1450
1711
  DEFAULT_SLIPPAGE_BPS,
1451
1712
  MIN_LIQUIDITY_BPS,
1713
+ PRICE_SCALE,
1452
1714
  USDC_ADDRESSES,
1715
+ applySellSlippage,
1453
1716
  applySlippage,
1454
1717
  calculateBuyCost,
1455
1718
  calculateBuyQuote,
1719
+ calculateSellProceeds,
1456
1720
  fillPurchase,
1721
+ formatCurvePrice,
1457
1722
  maxBuyable,
1723
+ parseCurvePrice,
1458
1724
  spotPrice
1459
1725
  });
1460
1726
  //# sourceMappingURL=index.js.map