auctionflow-sdk 1.3.0 → 2.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.mjs CHANGED
@@ -27,6 +27,7 @@ var AuctionBuilder = class {
27
27
  this.config.slope = slope;
28
28
  return this;
29
29
  }
30
+ /** Graduation threshold: once this much is raised, trading moves to Uniswap. */
30
31
  withMaxRaise(maxRaise) {
31
32
  this.config.maxRaise = maxRaise;
32
33
  return this;
@@ -41,9 +42,9 @@ var AuctionBuilder = class {
41
42
  this.config.liquidityBps = BigInt(liquidityBps);
42
43
  return this;
43
44
  }
44
- withSchedule(startTime, endTime) {
45
- this.config.startTime = startTime;
46
- this.config.endTime = endTime;
45
+ /** Off-chain metadata for the token, such as its image (e.g. an IPFS URI). */
46
+ withMetadata(metadataURI) {
47
+ this.config.metadataURI = metadataURI;
47
48
  return this;
48
49
  }
49
50
  build() {
@@ -54,9 +55,7 @@ var AuctionBuilder = class {
54
55
  "paymentToken",
55
56
  "basePrice",
56
57
  "slope",
57
- "maxRaise",
58
- "startTime",
59
- "endTime"
58
+ "maxRaise"
60
59
  ];
61
60
  for (const key of required) {
62
61
  if (this.config[key] === void 0) {
@@ -72,16 +71,13 @@ var AuctionBuilder = class {
72
71
  if (liquidityBps < BigInt(MIN_LIQUIDITY_BPS) || liquidityBps > 10000n) {
73
72
  throw new Error(`liquidityBps must be between ${MIN_LIQUIDITY_BPS} and 10000`);
74
73
  }
75
- if (config.startTime >= config.endTime) {
76
- throw new Error("startTime must be before endTime");
77
- }
78
74
  return config;
79
75
  }
80
76
  };
81
77
 
82
78
  // src/constants/addresses.ts
83
79
  var AUCTION_ADDRESSES = {
84
- 84532: "0x722f4521b96aca1df7c65a1dbe3b1713803ccea9",
80
+ 84532: "0xc6db1c900faeb4079281ecd6ec538c027cd18c28",
85
81
  8453: "0x0000000000000000000000000000000000000000"
86
82
  // not yet deployed
87
83
  };
@@ -219,16 +215,6 @@ var tokenAuctionAbi = [
219
215
  "type": "uint256",
220
216
  "internalType": "uint256"
221
217
  },
222
- {
223
- "name": "startTime",
224
- "type": "uint256",
225
- "internalType": "uint256"
226
- },
227
- {
228
- "name": "endTime",
229
- "type": "uint256",
230
- "internalType": "uint256"
231
- },
232
218
  {
233
219
  "name": "creator",
234
220
  "type": "address",
@@ -316,19 +302,6 @@ var tokenAuctionAbi = [
316
302
  ],
317
303
  "stateMutability": "nonpayable"
318
304
  },
319
- {
320
- "type": "function",
321
- "name": "completeAuction",
322
- "inputs": [
323
- {
324
- "name": "auctionId",
325
- "type": "uint256",
326
- "internalType": "uint256"
327
- }
328
- ],
329
- "outputs": [],
330
- "stateMutability": "nonpayable"
331
- },
332
305
  {
333
306
  "type": "function",
334
307
  "name": "createAuction",
@@ -348,6 +321,11 @@ var tokenAuctionAbi = [
348
321
  "type": "string",
349
322
  "internalType": "string"
350
323
  },
324
+ {
325
+ "name": "metadataURI",
326
+ "type": "string",
327
+ "internalType": "string"
328
+ },
351
329
  {
352
330
  "name": "maxSupply",
353
331
  "type": "uint256",
@@ -373,16 +351,6 @@ var tokenAuctionAbi = [
373
351
  "type": "uint256",
374
352
  "internalType": "uint256"
375
353
  },
376
- {
377
- "name": "startTime",
378
- "type": "uint256",
379
- "internalType": "uint256"
380
- },
381
- {
382
- "name": "endTime",
383
- "type": "uint256",
384
- "internalType": "uint256"
385
- },
386
354
  {
387
355
  "name": "liquidityBps",
388
356
  "type": "uint256",
@@ -493,6 +461,73 @@ var tokenAuctionAbi = [
493
461
  ],
494
462
  "stateMutability": "view"
495
463
  },
464
+ {
465
+ "type": "function",
466
+ "name": "launch",
467
+ "inputs": [
468
+ {
469
+ "name": "name",
470
+ "type": "string",
471
+ "internalType": "string"
472
+ },
473
+ {
474
+ "name": "symbol",
475
+ "type": "string",
476
+ "internalType": "string"
477
+ },
478
+ {
479
+ "name": "metadataURI",
480
+ "type": "string",
481
+ "internalType": "string"
482
+ }
483
+ ],
484
+ "outputs": [
485
+ {
486
+ "name": "auctionId",
487
+ "type": "uint256",
488
+ "internalType": "uint256"
489
+ }
490
+ ],
491
+ "stateMutability": "nonpayable"
492
+ },
493
+ {
494
+ "type": "function",
495
+ "name": "launchPreset",
496
+ "inputs": [],
497
+ "outputs": [
498
+ {
499
+ "name": "paymentToken",
500
+ "type": "address",
501
+ "internalType": "address"
502
+ },
503
+ {
504
+ "name": "maxSupply",
505
+ "type": "uint256",
506
+ "internalType": "uint256"
507
+ },
508
+ {
509
+ "name": "basePrice",
510
+ "type": "uint256",
511
+ "internalType": "uint256"
512
+ },
513
+ {
514
+ "name": "slope",
515
+ "type": "uint256",
516
+ "internalType": "uint256"
517
+ },
518
+ {
519
+ "name": "maxRaise",
520
+ "type": "uint256",
521
+ "internalType": "uint256"
522
+ },
523
+ {
524
+ "name": "liquidityBps",
525
+ "type": "uint256",
526
+ "internalType": "uint256"
527
+ }
528
+ ],
529
+ "stateMutability": "view"
530
+ },
496
531
  {
497
532
  "type": "function",
498
533
  "name": "migrate",
@@ -609,6 +644,29 @@ var tokenAuctionAbi = [
609
644
  "outputs": [],
610
645
  "stateMutability": "nonpayable"
611
646
  },
647
+ {
648
+ "type": "function",
649
+ "name": "sellTokens",
650
+ "inputs": [
651
+ {
652
+ "name": "auctionId",
653
+ "type": "uint256",
654
+ "internalType": "uint256"
655
+ },
656
+ {
657
+ "name": "amount",
658
+ "type": "uint256",
659
+ "internalType": "uint256"
660
+ },
661
+ {
662
+ "name": "minProceeds",
663
+ "type": "uint256",
664
+ "internalType": "uint256"
665
+ }
666
+ ],
667
+ "outputs": [],
668
+ "stateMutability": "nonpayable"
669
+ },
612
670
  {
613
671
  "type": "function",
614
672
  "name": "setDefaultFeeBps",
@@ -635,6 +693,51 @@ var tokenAuctionAbi = [
635
693
  "outputs": [],
636
694
  "stateMutability": "nonpayable"
637
695
  },
696
+ {
697
+ "type": "function",
698
+ "name": "setLaunchPreset",
699
+ "inputs": [
700
+ {
701
+ "name": "preset",
702
+ "type": "tuple",
703
+ "internalType": "struct TokenAuction.LaunchPreset",
704
+ "components": [
705
+ {
706
+ "name": "paymentToken",
707
+ "type": "address",
708
+ "internalType": "address"
709
+ },
710
+ {
711
+ "name": "maxSupply",
712
+ "type": "uint256",
713
+ "internalType": "uint256"
714
+ },
715
+ {
716
+ "name": "basePrice",
717
+ "type": "uint256",
718
+ "internalType": "uint256"
719
+ },
720
+ {
721
+ "name": "slope",
722
+ "type": "uint256",
723
+ "internalType": "uint256"
724
+ },
725
+ {
726
+ "name": "maxRaise",
727
+ "type": "uint256",
728
+ "internalType": "uint256"
729
+ },
730
+ {
731
+ "name": "liquidityBps",
732
+ "type": "uint256",
733
+ "internalType": "uint256"
734
+ }
735
+ ]
736
+ }
737
+ ],
738
+ "outputs": [],
739
+ "stateMutability": "nonpayable"
740
+ },
638
741
  {
639
742
  "type": "function",
640
743
  "name": "setProtocolFeeRecipient",
@@ -811,22 +914,16 @@ var tokenAuctionAbi = [
811
914
  "internalType": "uint256"
812
915
  },
813
916
  {
814
- "name": "startTime",
815
- "type": "uint256",
816
- "indexed": false,
817
- "internalType": "uint256"
818
- },
819
- {
820
- "name": "endTime",
917
+ "name": "liquidityBps",
821
918
  "type": "uint256",
822
919
  "indexed": false,
823
920
  "internalType": "uint256"
824
921
  },
825
922
  {
826
- "name": "liquidityBps",
827
- "type": "uint256",
923
+ "name": "metadataURI",
924
+ "type": "string",
828
925
  "indexed": false,
829
- "internalType": "uint256"
926
+ "internalType": "string"
830
927
  }
831
928
  ],
832
929
  "anonymous": false
@@ -906,6 +1003,49 @@ var tokenAuctionAbi = [
906
1003
  ],
907
1004
  "anonymous": false
908
1005
  },
1006
+ {
1007
+ "type": "event",
1008
+ "name": "LaunchPresetUpdated",
1009
+ "inputs": [
1010
+ {
1011
+ "name": "paymentToken",
1012
+ "type": "address",
1013
+ "indexed": false,
1014
+ "internalType": "address"
1015
+ },
1016
+ {
1017
+ "name": "maxSupply",
1018
+ "type": "uint256",
1019
+ "indexed": false,
1020
+ "internalType": "uint256"
1021
+ },
1022
+ {
1023
+ "name": "basePrice",
1024
+ "type": "uint256",
1025
+ "indexed": false,
1026
+ "internalType": "uint256"
1027
+ },
1028
+ {
1029
+ "name": "slope",
1030
+ "type": "uint256",
1031
+ "indexed": false,
1032
+ "internalType": "uint256"
1033
+ },
1034
+ {
1035
+ "name": "maxRaise",
1036
+ "type": "uint256",
1037
+ "indexed": false,
1038
+ "internalType": "uint256"
1039
+ },
1040
+ {
1041
+ "name": "liquidityBps",
1042
+ "type": "uint256",
1043
+ "indexed": false,
1044
+ "internalType": "uint256"
1045
+ }
1046
+ ],
1047
+ "anonymous": false
1048
+ },
909
1049
  {
910
1050
  "type": "event",
911
1051
  "name": "LpFeesCollected",
@@ -1080,6 +1220,55 @@ var tokenAuctionAbi = [
1080
1220
  ],
1081
1221
  "anonymous": false
1082
1222
  },
1223
+ {
1224
+ "type": "event",
1225
+ "name": "TokensSold",
1226
+ "inputs": [
1227
+ {
1228
+ "name": "auctionId",
1229
+ "type": "uint256",
1230
+ "indexed": true,
1231
+ "internalType": "uint256"
1232
+ },
1233
+ {
1234
+ "name": "seller",
1235
+ "type": "address",
1236
+ "indexed": true,
1237
+ "internalType": "address"
1238
+ },
1239
+ {
1240
+ "name": "amount",
1241
+ "type": "uint256",
1242
+ "indexed": false,
1243
+ "internalType": "uint256"
1244
+ },
1245
+ {
1246
+ "name": "proceeds",
1247
+ "type": "uint256",
1248
+ "indexed": false,
1249
+ "internalType": "uint256"
1250
+ },
1251
+ {
1252
+ "name": "protocolFee",
1253
+ "type": "uint256",
1254
+ "indexed": false,
1255
+ "internalType": "uint256"
1256
+ },
1257
+ {
1258
+ "name": "newTotalRaised",
1259
+ "type": "uint256",
1260
+ "indexed": false,
1261
+ "internalType": "uint256"
1262
+ },
1263
+ {
1264
+ "name": "newTotalSold",
1265
+ "type": "uint256",
1266
+ "indexed": false,
1267
+ "internalType": "uint256"
1268
+ }
1269
+ ],
1270
+ "anonymous": false
1271
+ },
1083
1272
  {
1084
1273
  "type": "error",
1085
1274
  "name": "OwnableInvalidOwner",
@@ -1121,16 +1310,32 @@ var tokenAuctionAbi = [
1121
1310
  ];
1122
1311
 
1123
1312
  // src/utils/bonding-curve.ts
1313
+ import { formatUnits, parseUnits } from "viem";
1124
1314
  var TOKEN_SCALE = 10n ** 18n;
1315
+ var PRICE_SCALE = 10n ** 18n;
1316
+ var SCALE = TOKEN_SCALE * PRICE_SCALE;
1317
+ function parseCurvePrice(price, paymentDecimals) {
1318
+ return parseUnits(price, paymentDecimals + 18);
1319
+ }
1320
+ function formatCurvePrice(price, paymentDecimals) {
1321
+ return formatUnits(price, paymentDecimals + 18);
1322
+ }
1125
1323
  var ceilDiv = (a, b) => (a + b - 1n) / b;
1126
1324
  function calculateBuyCost(currentSupply, amount, basePrice, slope) {
1127
- const linearCost = ceilDiv(basePrice * amount, TOKEN_SCALE);
1325
+ const linearCost = ceilDiv(basePrice * amount, SCALE);
1128
1326
  const curveCost = ceilDiv(
1129
1327
  slope * amount * (2n * currentSupply + amount),
1130
- 2n * TOKEN_SCALE * TOKEN_SCALE
1328
+ 2n * SCALE * TOKEN_SCALE
1131
1329
  );
1132
1330
  return linearCost + curveCost;
1133
1331
  }
1332
+ function calculateSellProceeds(currentSupply, amount, basePrice, slope) {
1333
+ if (amount > currentSupply) throw new Error("Cannot sell more than is outstanding");
1334
+ const from = currentSupply - amount;
1335
+ const linear = basePrice * amount / SCALE;
1336
+ const curve = slope * amount * (2n * from + amount) / (2n * SCALE * TOKEN_SCALE);
1337
+ return linear + curve;
1338
+ }
1134
1339
  function spotPrice(currentSupply, basePrice, slope) {
1135
1340
  return basePrice + slope * currentSupply / TOKEN_SCALE;
1136
1341
  }
@@ -1152,7 +1357,7 @@ function applySlippage(total, slippageBps) {
1152
1357
  return (total * BigInt(1e4 + slippageBps) + 9999n) / 10000n;
1153
1358
  }
1154
1359
  function maxBuyable(currentSupply, budget, basePrice, slope, upperBound) {
1155
- let hi = budget * TOKEN_SCALE / basePrice + 1n;
1360
+ let hi = budget * SCALE / basePrice + 1n;
1156
1361
  if (hi > upperBound) hi = upperBound;
1157
1362
  let lo = 0n;
1158
1363
  while (lo < hi) {
@@ -1175,6 +1380,12 @@ function fillPurchase(currentSupply, requested, basePrice, slope, totalRaised, m
1175
1380
  fillsAuction: true
1176
1381
  };
1177
1382
  }
1383
+ function applySellSlippage(netProceeds, slippageBps) {
1384
+ if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > 1e4) {
1385
+ throw new Error("slippageBps must be an integer between 0 and 10000");
1386
+ }
1387
+ return netProceeds * BigInt(1e4 - slippageBps) / 10000n;
1388
+ }
1178
1389
 
1179
1390
  // src/utils/chains.ts
1180
1391
  import { base, baseSepolia } from "viem/chains";
@@ -1226,19 +1437,66 @@ var AuctionFlowSDK = class {
1226
1437
  {
1227
1438
  name: config.name,
1228
1439
  symbol: config.symbol,
1440
+ metadataURI: config.metadataURI ?? "",
1229
1441
  maxSupply: config.maxSupply,
1230
1442
  paymentToken: config.paymentToken,
1231
1443
  basePrice: config.basePrice,
1232
1444
  slope: config.slope,
1233
1445
  maxRaise: config.maxRaise,
1234
- startTime: config.startTime,
1235
- endTime: config.endTime,
1236
1446
  liquidityBps: config.liquidityBps ?? BigInt(DEFAULT_LIQUIDITY_BPS)
1237
1447
  }
1238
1448
  ]
1239
1449
  });
1240
1450
  return hash;
1241
1451
  }
1452
+ /**
1453
+ * One-click launch: a token with the protocol's standard curve, threshold
1454
+ * and liquidity share. Trading starts immediately.
1455
+ */
1456
+ async launch(name, symbol, metadataURI = "") {
1457
+ if (!this.walletClient) throw new Error("Wallet client required");
1458
+ return this.walletClient.writeContract({
1459
+ chain: this.chain,
1460
+ account: this.walletClient.account,
1461
+ address: this.auctionAddress,
1462
+ abi: tokenAuctionAbi,
1463
+ functionName: "launch",
1464
+ args: [name, symbol, metadataURI]
1465
+ });
1466
+ }
1467
+ /**
1468
+ * Sell `amount` tokens (in token wei) back to the curve before graduation.
1469
+ * The contract reverts if the price fell below the bound before the
1470
+ * transaction landed: pass `minProceeds` to set it exactly, or `slippageBps`
1471
+ * to derive it from a fresh quote (default 100 = 1% below it).
1472
+ */
1473
+ async sellTokens(auctionId, amount, options = {}) {
1474
+ if (!this.walletClient) throw new Error("Wallet client required");
1475
+ const minProceeds = options.minProceeds ?? applySellSlippage(
1476
+ (await this.getSellQuote(auctionId, amount)).netProceeds,
1477
+ options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
1478
+ );
1479
+ return this.walletClient.writeContract({
1480
+ chain: this.chain,
1481
+ account: this.walletClient.account,
1482
+ address: this.auctionAddress,
1483
+ abi: tokenAuctionAbi,
1484
+ functionName: "sellTokens",
1485
+ args: [auctionId, amount, minProceeds]
1486
+ });
1487
+ }
1488
+ /** What selling `amount` tokens back to the curve would pay right now. */
1489
+ async getSellQuote(auctionId, amount) {
1490
+ const auction = await this.getAuction(auctionId);
1491
+ const proceeds = calculateSellProceeds(auction.totalSold, amount, auction.basePrice, auction.slope);
1492
+ const fee = proceeds * auction.protocolFeeBps / 10000n;
1493
+ return {
1494
+ proceeds,
1495
+ fee,
1496
+ netProceeds: proceeds - fee,
1497
+ spotPriceAfter: spotPrice(auction.totalSold - amount, auction.basePrice, auction.slope)
1498
+ };
1499
+ }
1242
1500
  /**
1243
1501
  * Buy `amount` tokens (in token wei). The price rises with every purchase, so
1244
1502
  * the contract takes a maximum total cost and reverts if the price moved past
@@ -1385,8 +1643,6 @@ var AuctionFlowSDK = class {
1385
1643
  basePrice: raw.config.basePrice,
1386
1644
  slope: raw.config.slope,
1387
1645
  maxRaise: raw.config.maxRaise,
1388
- startTime: raw.config.startTime,
1389
- endTime: raw.config.endTime,
1390
1646
  state: raw.state,
1391
1647
  totalRaised: raw.totalRaised,
1392
1648
  totalSold: raw.totalSold,
@@ -1413,12 +1669,17 @@ export {
1413
1669
  DEFAULT_LIQUIDITY_BPS,
1414
1670
  DEFAULT_SLIPPAGE_BPS,
1415
1671
  MIN_LIQUIDITY_BPS,
1672
+ PRICE_SCALE,
1416
1673
  USDC_ADDRESSES,
1674
+ applySellSlippage,
1417
1675
  applySlippage,
1418
1676
  calculateBuyCost,
1419
1677
  calculateBuyQuote,
1678
+ calculateSellProceeds,
1420
1679
  fillPurchase,
1680
+ formatCurvePrice,
1421
1681
  maxBuyable,
1682
+ parseCurvePrice,
1422
1683
  spotPrice
1423
1684
  };
1424
1685
  //# sourceMappingURL=index.mjs.map