auctionflow-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
@@ -24,9 +24,15 @@ __export(index_exports, {
24
24
  AuctionBuilder: () => AuctionBuilder,
25
25
  AuctionFlowSDK: () => AuctionFlowSDK,
26
26
  AuctionState: () => AuctionState,
27
+ DEFAULT_LIQUIDITY_BPS: () => DEFAULT_LIQUIDITY_BPS,
28
+ DEFAULT_SLIPPAGE_BPS: () => DEFAULT_SLIPPAGE_BPS,
29
+ MIN_LIQUIDITY_BPS: () => MIN_LIQUIDITY_BPS,
27
30
  USDC_ADDRESSES: () => USDC_ADDRESSES,
31
+ applySlippage: () => applySlippage,
28
32
  calculateBuyCost: () => calculateBuyCost,
29
33
  calculateBuyQuote: () => calculateBuyQuote,
34
+ fillPurchase: () => fillPurchase,
35
+ maxBuyable: () => maxBuyable,
30
36
  spotPrice: () => spotPrice
31
37
  });
32
38
  module.exports = __toCommonJS(index_exports);
@@ -34,6 +40,10 @@ module.exports = __toCommonJS(index_exports);
34
40
  // src/client.ts
35
41
  var import_viem = require("viem");
36
42
 
43
+ // src/constants/protocol.ts
44
+ var MIN_LIQUIDITY_BPS = 2e3;
45
+ var DEFAULT_LIQUIDITY_BPS = 5e3;
46
+
37
47
  // src/builders/auction-builder.ts
38
48
  var AuctionBuilder = class {
39
49
  config = {};
@@ -56,6 +66,16 @@ var AuctionBuilder = class {
56
66
  this.config.maxRaise = maxRaise;
57
67
  return this;
58
68
  }
69
+ /**
70
+ * Share of the raise, in basis points, seeded into a Uniswap pool when the
71
+ * auction migrates (5000 = 50%). The rest goes to the creator. Defaults to
72
+ * 50%; must be between 20% and 100%.
73
+ */
74
+ withLiquidity(liquidityBps) {
75
+ if (!Number.isInteger(liquidityBps)) throw new Error("liquidityBps must be an integer");
76
+ this.config.liquidityBps = BigInt(liquidityBps);
77
+ return this;
78
+ }
59
79
  withSchedule(startTime, endTime) {
60
80
  this.config.startTime = startTime;
61
81
  this.config.endTime = endTime;
@@ -78,11 +98,15 @@ var AuctionBuilder = class {
78
98
  throw new Error(`Missing required field: ${key}`);
79
99
  }
80
100
  }
81
- const config = this.config;
101
+ const config = { liquidityBps: BigInt(DEFAULT_LIQUIDITY_BPS), ...this.config };
82
102
  if (config.maxSupply <= 0n) throw new Error("maxSupply must be greater than 0");
83
103
  if (config.basePrice <= 0n) throw new Error("basePrice must be greater than 0");
84
104
  if (config.slope < 0n) throw new Error("slope must not be negative");
85
105
  if (config.maxRaise <= 0n) throw new Error("maxRaise must be greater than 0");
106
+ const liquidityBps = config.liquidityBps;
107
+ if (liquidityBps < BigInt(MIN_LIQUIDITY_BPS) || liquidityBps > 10000n) {
108
+ throw new Error(`liquidityBps must be between ${MIN_LIQUIDITY_BPS} and 10000`);
109
+ }
86
110
  if (config.startTime >= config.endTime) {
87
111
  throw new Error("startTime must be before endTime");
88
112
  }
@@ -92,7 +116,7 @@ var AuctionBuilder = class {
92
116
 
93
117
  // src/constants/addresses.ts
94
118
  var AUCTION_ADDRESSES = {
95
- 84532: "0xadc3e02e962eed3856d7bee0315f84d187be1fea",
119
+ 84532: "0x722f4521b96aca1df7c65a1dbe3b1713803ccea9",
96
120
  8453: "0x0000000000000000000000000000000000000000"
97
121
  // not yet deployed
98
122
  };
@@ -115,10 +139,67 @@ var tokenAuctionAbi = [
115
139
  "name": "defaultFeeBps_",
116
140
  "type": "uint256",
117
141
  "internalType": "uint256"
142
+ },
143
+ {
144
+ "name": "positionManager_",
145
+ "type": "address",
146
+ "internalType": "contract INonfungiblePositionManager"
118
147
  }
119
148
  ],
120
149
  "stateMutability": "nonpayable"
121
150
  },
151
+ {
152
+ "type": "function",
153
+ "name": "MAX_FEE_BPS",
154
+ "inputs": [],
155
+ "outputs": [
156
+ {
157
+ "name": "",
158
+ "type": "uint256",
159
+ "internalType": "uint256"
160
+ }
161
+ ],
162
+ "stateMutability": "view"
163
+ },
164
+ {
165
+ "type": "function",
166
+ "name": "MAX_LP_FEE_SHARE_BPS",
167
+ "inputs": [],
168
+ "outputs": [
169
+ {
170
+ "name": "",
171
+ "type": "uint256",
172
+ "internalType": "uint256"
173
+ }
174
+ ],
175
+ "stateMutability": "view"
176
+ },
177
+ {
178
+ "type": "function",
179
+ "name": "MIN_LIQUIDITY_BPS",
180
+ "inputs": [],
181
+ "outputs": [
182
+ {
183
+ "name": "",
184
+ "type": "uint256",
185
+ "internalType": "uint256"
186
+ }
187
+ ],
188
+ "stateMutability": "view"
189
+ },
190
+ {
191
+ "type": "function",
192
+ "name": "POOL_FEE",
193
+ "inputs": [],
194
+ "outputs": [
195
+ {
196
+ "name": "",
197
+ "type": "uint24",
198
+ "internalType": "uint24"
199
+ }
200
+ ],
201
+ "stateMutability": "view"
202
+ },
122
203
  {
123
204
  "type": "function",
124
205
  "name": "auctionCount",
@@ -192,6 +273,16 @@ var tokenAuctionAbi = [
192
273
  "name": "protocolFeeBps",
193
274
  "type": "uint256",
194
275
  "internalType": "uint256"
276
+ },
277
+ {
278
+ "name": "liquidityBps",
279
+ "type": "uint256",
280
+ "internalType": "uint256"
281
+ },
282
+ {
283
+ "name": "lpFeeShareBps",
284
+ "type": "uint256",
285
+ "internalType": "uint256"
195
286
  }
196
287
  ]
197
288
  },
@@ -226,11 +317,40 @@ var tokenAuctionAbi = [
226
317
  "name": "amount",
227
318
  "type": "uint256",
228
319
  "internalType": "uint256"
320
+ },
321
+ {
322
+ "name": "maxCost",
323
+ "type": "uint256",
324
+ "internalType": "uint256"
229
325
  }
230
326
  ],
231
327
  "outputs": [],
232
328
  "stateMutability": "nonpayable"
233
329
  },
330
+ {
331
+ "type": "function",
332
+ "name": "collectFees",
333
+ "inputs": [
334
+ {
335
+ "name": "auctionId",
336
+ "type": "uint256",
337
+ "internalType": "uint256"
338
+ }
339
+ ],
340
+ "outputs": [
341
+ {
342
+ "name": "tokenFees",
343
+ "type": "uint256",
344
+ "internalType": "uint256"
345
+ },
346
+ {
347
+ "name": "paymentFees",
348
+ "type": "uint256",
349
+ "internalType": "uint256"
350
+ }
351
+ ],
352
+ "stateMutability": "nonpayable"
353
+ },
234
354
  {
235
355
  "type": "function",
236
356
  "name": "completeAuction",
@@ -249,63 +369,107 @@ var tokenAuctionAbi = [
249
369
  "name": "createAuction",
250
370
  "inputs": [
251
371
  {
252
- "name": "name",
253
- "type": "string",
254
- "internalType": "string"
255
- },
256
- {
257
- "name": "symbol",
258
- "type": "string",
259
- "internalType": "string"
260
- },
372
+ "name": "p",
373
+ "type": "tuple",
374
+ "internalType": "struct TokenAuction.AuctionParams",
375
+ "components": [
376
+ {
377
+ "name": "name",
378
+ "type": "string",
379
+ "internalType": "string"
380
+ },
381
+ {
382
+ "name": "symbol",
383
+ "type": "string",
384
+ "internalType": "string"
385
+ },
386
+ {
387
+ "name": "maxSupply",
388
+ "type": "uint256",
389
+ "internalType": "uint256"
390
+ },
391
+ {
392
+ "name": "paymentToken",
393
+ "type": "address",
394
+ "internalType": "address"
395
+ },
396
+ {
397
+ "name": "basePrice",
398
+ "type": "uint256",
399
+ "internalType": "uint256"
400
+ },
401
+ {
402
+ "name": "slope",
403
+ "type": "uint256",
404
+ "internalType": "uint256"
405
+ },
406
+ {
407
+ "name": "maxRaise",
408
+ "type": "uint256",
409
+ "internalType": "uint256"
410
+ },
411
+ {
412
+ "name": "startTime",
413
+ "type": "uint256",
414
+ "internalType": "uint256"
415
+ },
416
+ {
417
+ "name": "endTime",
418
+ "type": "uint256",
419
+ "internalType": "uint256"
420
+ },
421
+ {
422
+ "name": "liquidityBps",
423
+ "type": "uint256",
424
+ "internalType": "uint256"
425
+ }
426
+ ]
427
+ }
428
+ ],
429
+ "outputs": [
261
430
  {
262
- "name": "maxSupply",
431
+ "name": "auctionId",
263
432
  "type": "uint256",
264
433
  "internalType": "uint256"
265
- },
434
+ }
435
+ ],
436
+ "stateMutability": "nonpayable"
437
+ },
438
+ {
439
+ "type": "function",
440
+ "name": "custodied",
441
+ "inputs": [
266
442
  {
267
- "name": "paymentToken",
443
+ "name": "",
268
444
  "type": "address",
269
445
  "internalType": "address"
270
- },
271
- {
272
- "name": "basePrice",
273
- "type": "uint256",
274
- "internalType": "uint256"
275
- },
276
- {
277
- "name": "slope",
278
- "type": "uint256",
279
- "internalType": "uint256"
280
- },
281
- {
282
- "name": "maxRaise",
283
- "type": "uint256",
284
- "internalType": "uint256"
285
- },
286
- {
287
- "name": "startTime",
288
- "type": "uint256",
289
- "internalType": "uint256"
290
- },
446
+ }
447
+ ],
448
+ "outputs": [
291
449
  {
292
- "name": "endTime",
450
+ "name": "",
293
451
  "type": "uint256",
294
452
  "internalType": "uint256"
295
453
  }
296
454
  ],
455
+ "stateMutability": "view"
456
+ },
457
+ {
458
+ "type": "function",
459
+ "name": "defaultFeeBps",
460
+ "inputs": [],
297
461
  "outputs": [
298
462
  {
299
- "name": "auctionId",
463
+ "name": "",
300
464
  "type": "uint256",
301
465
  "internalType": "uint256"
302
466
  }
303
467
  ],
304
- "stateMutability": "nonpayable"
468
+ "stateMutability": "view"
305
469
  },
306
470
  {
307
471
  "type": "function",
308
- "name": "defaultFeeBps",
472
+ "name": "defaultLpFeeShareBps",
309
473
  "inputs": [],
310
474
  "outputs": [
311
475
  {
@@ -364,6 +528,19 @@ var tokenAuctionAbi = [
364
528
  ],
365
529
  "stateMutability": "view"
366
530
  },
531
+ {
532
+ "type": "function",
533
+ "name": "migrate",
534
+ "inputs": [
535
+ {
536
+ "name": "auctionId",
537
+ "type": "uint256",
538
+ "internalType": "uint256"
539
+ }
540
+ ],
541
+ "outputs": [],
542
+ "stateMutability": "nonpayable"
543
+ },
367
544
  {
368
545
  "type": "function",
369
546
  "name": "owner",
@@ -377,6 +554,57 @@ var tokenAuctionAbi = [
377
554
  ],
378
555
  "stateMutability": "view"
379
556
  },
557
+ {
558
+ "type": "function",
559
+ "name": "poolOf",
560
+ "inputs": [
561
+ {
562
+ "name": "",
563
+ "type": "uint256",
564
+ "internalType": "uint256"
565
+ }
566
+ ],
567
+ "outputs": [
568
+ {
569
+ "name": "",
570
+ "type": "address",
571
+ "internalType": "address"
572
+ }
573
+ ],
574
+ "stateMutability": "view"
575
+ },
576
+ {
577
+ "type": "function",
578
+ "name": "positionId",
579
+ "inputs": [
580
+ {
581
+ "name": "",
582
+ "type": "uint256",
583
+ "internalType": "uint256"
584
+ }
585
+ ],
586
+ "outputs": [
587
+ {
588
+ "name": "",
589
+ "type": "uint256",
590
+ "internalType": "uint256"
591
+ }
592
+ ],
593
+ "stateMutability": "view"
594
+ },
595
+ {
596
+ "type": "function",
597
+ "name": "positionManager",
598
+ "inputs": [],
599
+ "outputs": [
600
+ {
601
+ "name": "",
602
+ "type": "address",
603
+ "internalType": "contract INonfungiblePositionManager"
604
+ }
605
+ ],
606
+ "stateMutability": "view"
607
+ },
380
608
  {
381
609
  "type": "function",
382
610
  "name": "proceedsWithdrawn",
@@ -416,6 +644,63 @@ var tokenAuctionAbi = [
416
644
  "outputs": [],
417
645
  "stateMutability": "nonpayable"
418
646
  },
647
+ {
648
+ "type": "function",
649
+ "name": "setDefaultFeeBps",
650
+ "inputs": [
651
+ {
652
+ "name": "feeBps",
653
+ "type": "uint256",
654
+ "internalType": "uint256"
655
+ }
656
+ ],
657
+ "outputs": [],
658
+ "stateMutability": "nonpayable"
659
+ },
660
+ {
661
+ "type": "function",
662
+ "name": "setDefaultLpFeeShareBps",
663
+ "inputs": [
664
+ {
665
+ "name": "shareBps",
666
+ "type": "uint256",
667
+ "internalType": "uint256"
668
+ }
669
+ ],
670
+ "outputs": [],
671
+ "stateMutability": "nonpayable"
672
+ },
673
+ {
674
+ "type": "function",
675
+ "name": "setProtocolFeeRecipient",
676
+ "inputs": [
677
+ {
678
+ "name": "recipient",
679
+ "type": "address",
680
+ "internalType": "address"
681
+ }
682
+ ],
683
+ "outputs": [],
684
+ "stateMutability": "nonpayable"
685
+ },
686
+ {
687
+ "type": "function",
688
+ "name": "sweep",
689
+ "inputs": [
690
+ {
691
+ "name": "token",
692
+ "type": "address",
693
+ "internalType": "contract IERC20"
694
+ },
695
+ {
696
+ "name": "to",
697
+ "type": "address",
698
+ "internalType": "address"
699
+ }
700
+ ],
701
+ "outputs": [],
702
+ "stateMutability": "nonpayable"
703
+ },
419
704
  {
420
705
  "type": "function",
421
706
  "name": "transferOwnership",
@@ -429,6 +714,29 @@ var tokenAuctionAbi = [
429
714
  "outputs": [],
430
715
  "stateMutability": "nonpayable"
431
716
  },
717
+ {
718
+ "type": "function",
719
+ "name": "uniswapV3SwapCallback",
720
+ "inputs": [
721
+ {
722
+ "name": "amount0Delta",
723
+ "type": "int256",
724
+ "internalType": "int256"
725
+ },
726
+ {
727
+ "name": "amount1Delta",
728
+ "type": "int256",
729
+ "internalType": "int256"
730
+ },
731
+ {
732
+ "name": "data",
733
+ "type": "bytes",
734
+ "internalType": "bytes"
735
+ }
736
+ ],
737
+ "outputs": [],
738
+ "stateMutability": "nonpayable"
739
+ },
432
740
  {
433
741
  "type": "function",
434
742
  "name": "userPurchases",
@@ -548,6 +856,12 @@ var tokenAuctionAbi = [
548
856
  "type": "uint256",
549
857
  "indexed": false,
550
858
  "internalType": "uint256"
859
+ },
860
+ {
861
+ "name": "liquidityBps",
862
+ "type": "uint256",
863
+ "indexed": false,
864
+ "internalType": "uint256"
551
865
  }
552
866
  ],
553
867
  "anonymous": false
@@ -563,10 +877,103 @@ var tokenAuctionAbi = [
563
877
  "internalType": "uint256"
564
878
  },
565
879
  {
566
- "name": "liquidityPool",
880
+ "name": "pool",
567
881
  "type": "address",
568
882
  "indexed": false,
569
883
  "internalType": "address"
884
+ },
885
+ {
886
+ "name": "positionId",
887
+ "type": "uint256",
888
+ "indexed": false,
889
+ "internalType": "uint256"
890
+ },
891
+ {
892
+ "name": "tokenLiquidity",
893
+ "type": "uint256",
894
+ "indexed": false,
895
+ "internalType": "uint256"
896
+ },
897
+ {
898
+ "name": "paymentLiquidity",
899
+ "type": "uint256",
900
+ "indexed": false,
901
+ "internalType": "uint256"
902
+ }
903
+ ],
904
+ "anonymous": false
905
+ },
906
+ {
907
+ "type": "event",
908
+ "name": "DefaultFeeBpsUpdated",
909
+ "inputs": [
910
+ {
911
+ "name": "previous",
912
+ "type": "uint256",
913
+ "indexed": false,
914
+ "internalType": "uint256"
915
+ },
916
+ {
917
+ "name": "current",
918
+ "type": "uint256",
919
+ "indexed": false,
920
+ "internalType": "uint256"
921
+ }
922
+ ],
923
+ "anonymous": false
924
+ },
925
+ {
926
+ "type": "event",
927
+ "name": "DefaultLpFeeShareBpsUpdated",
928
+ "inputs": [
929
+ {
930
+ "name": "previous",
931
+ "type": "uint256",
932
+ "indexed": false,
933
+ "internalType": "uint256"
934
+ },
935
+ {
936
+ "name": "current",
937
+ "type": "uint256",
938
+ "indexed": false,
939
+ "internalType": "uint256"
940
+ }
941
+ ],
942
+ "anonymous": false
943
+ },
944
+ {
945
+ "type": "event",
946
+ "name": "LpFeesCollected",
947
+ "inputs": [
948
+ {
949
+ "name": "auctionId",
950
+ "type": "uint256",
951
+ "indexed": true,
952
+ "internalType": "uint256"
953
+ },
954
+ {
955
+ "name": "creatorTokenFees",
956
+ "type": "uint256",
957
+ "indexed": false,
958
+ "internalType": "uint256"
959
+ },
960
+ {
961
+ "name": "creatorPaymentFees",
962
+ "type": "uint256",
963
+ "indexed": false,
964
+ "internalType": "uint256"
965
+ },
966
+ {
967
+ "name": "protocolTokenFees",
968
+ "type": "uint256",
969
+ "indexed": false,
970
+ "internalType": "uint256"
971
+ },
972
+ {
973
+ "name": "protocolPaymentFees",
974
+ "type": "uint256",
975
+ "indexed": false,
976
+ "internalType": "uint256"
570
977
  }
571
978
  ],
572
979
  "anonymous": false
@@ -615,6 +1022,50 @@ var tokenAuctionAbi = [
615
1022
  ],
616
1023
  "anonymous": false
617
1024
  },
1025
+ {
1026
+ "type": "event",
1027
+ "name": "ProtocolFeeRecipientUpdated",
1028
+ "inputs": [
1029
+ {
1030
+ "name": "previous",
1031
+ "type": "address",
1032
+ "indexed": true,
1033
+ "internalType": "address"
1034
+ },
1035
+ {
1036
+ "name": "current",
1037
+ "type": "address",
1038
+ "indexed": true,
1039
+ "internalType": "address"
1040
+ }
1041
+ ],
1042
+ "anonymous": false
1043
+ },
1044
+ {
1045
+ "type": "event",
1046
+ "name": "Swept",
1047
+ "inputs": [
1048
+ {
1049
+ "name": "token",
1050
+ "type": "address",
1051
+ "indexed": true,
1052
+ "internalType": "address"
1053
+ },
1054
+ {
1055
+ "name": "to",
1056
+ "type": "address",
1057
+ "indexed": true,
1058
+ "internalType": "address"
1059
+ },
1060
+ {
1061
+ "name": "amount",
1062
+ "type": "uint256",
1063
+ "indexed": false,
1064
+ "internalType": "uint256"
1065
+ }
1066
+ ],
1067
+ "anonymous": false
1068
+ },
618
1069
  {
619
1070
  "type": "event",
620
1071
  "name": "TokensPurchased",
@@ -705,13 +1156,18 @@ var tokenAuctionAbi = [
705
1156
  ];
706
1157
 
707
1158
  // src/utils/bonding-curve.ts
1159
+ var TOKEN_SCALE = 10n ** 18n;
1160
+ var ceilDiv = (a, b) => (a + b - 1n) / b;
708
1161
  function calculateBuyCost(currentSupply, amount, basePrice, slope) {
709
- const linearCost = basePrice * amount;
710
- const curveCost = slope * amount * (2n * currentSupply + amount) / 2n;
1162
+ const linearCost = ceilDiv(basePrice * amount, TOKEN_SCALE);
1163
+ const curveCost = ceilDiv(
1164
+ slope * amount * (2n * currentSupply + amount),
1165
+ 2n * TOKEN_SCALE * TOKEN_SCALE
1166
+ );
711
1167
  return linearCost + curveCost;
712
1168
  }
713
1169
  function spotPrice(currentSupply, basePrice, slope) {
714
- return basePrice + slope * currentSupply;
1170
+ return basePrice + slope * currentSupply / TOKEN_SCALE;
715
1171
  }
716
1172
  function calculateBuyQuote(currentSupply, amount, basePrice, slope, feeBps) {
717
1173
  const cost = calculateBuyCost(currentSupply, amount, basePrice, slope);
@@ -723,6 +1179,37 @@ function calculateBuyQuote(currentSupply, amount, basePrice, slope, feeBps) {
723
1179
  spotPriceAfter: spotPrice(currentSupply + amount, basePrice, slope)
724
1180
  };
725
1181
  }
1182
+ var DEFAULT_SLIPPAGE_BPS = 100;
1183
+ function applySlippage(total, slippageBps) {
1184
+ if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > 1e4) {
1185
+ throw new Error("slippageBps must be an integer between 0 and 10000");
1186
+ }
1187
+ return (total * BigInt(1e4 + slippageBps) + 9999n) / 10000n;
1188
+ }
1189
+ function maxBuyable(currentSupply, budget, basePrice, slope, upperBound) {
1190
+ let hi = budget * TOKEN_SCALE / basePrice + 1n;
1191
+ if (hi > upperBound) hi = upperBound;
1192
+ let lo = 0n;
1193
+ while (lo < hi) {
1194
+ const mid = (lo + hi + 1n) / 2n;
1195
+ if (calculateBuyCost(currentSupply, mid, basePrice, slope) <= budget) lo = mid;
1196
+ else hi = mid - 1n;
1197
+ }
1198
+ return lo;
1199
+ }
1200
+ function fillPurchase(currentSupply, requested, basePrice, slope, totalRaised, maxRaise) {
1201
+ const remaining = maxRaise - totalRaised;
1202
+ const cost = calculateBuyCost(currentSupply, requested, basePrice, slope);
1203
+ if (cost < remaining) return { amount: requested, cost, fillsAuction: false };
1204
+ if (cost === remaining) return { amount: requested, cost, fillsAuction: true };
1205
+ const amount = maxBuyable(currentSupply, remaining, basePrice, slope, requested);
1206
+ if (amount === 0n) throw new Error("Auction is sold out");
1207
+ return {
1208
+ amount,
1209
+ cost: calculateBuyCost(currentSupply, amount, basePrice, slope),
1210
+ fillsAuction: true
1211
+ };
1212
+ }
726
1213
 
727
1214
  // src/utils/chains.ts
728
1215
  var import_chains = require("viem/chains");
@@ -771,34 +1258,50 @@ var AuctionFlowSDK = class {
771
1258
  abi: tokenAuctionAbi,
772
1259
  functionName: "createAuction",
773
1260
  args: [
774
- config.name,
775
- config.symbol,
776
- config.maxSupply,
777
- config.paymentToken,
778
- config.basePrice,
779
- config.slope,
780
- config.maxRaise,
781
- config.startTime,
782
- config.endTime
1261
+ {
1262
+ name: config.name,
1263
+ symbol: config.symbol,
1264
+ maxSupply: config.maxSupply,
1265
+ paymentToken: config.paymentToken,
1266
+ basePrice: config.basePrice,
1267
+ slope: config.slope,
1268
+ maxRaise: config.maxRaise,
1269
+ startTime: config.startTime,
1270
+ endTime: config.endTime,
1271
+ liquidityBps: config.liquidityBps ?? BigInt(DEFAULT_LIQUIDITY_BPS)
1272
+ }
783
1273
  ]
784
1274
  });
785
1275
  return hash;
786
1276
  }
787
- async buyTokens(auctionId, amount) {
1277
+ /**
1278
+ * Buy `amount` tokens (in token wei). The price rises with every purchase, so
1279
+ * the contract takes a maximum total cost and reverts if the price moved past
1280
+ * it before the transaction landed.
1281
+ *
1282
+ * Pass `maxCost` to set that bound exactly, or `slippageBps` to derive it
1283
+ * from a fresh quote (default 100 = 1% above the quoted total).
1284
+ */
1285
+ async buyTokens(auctionId, amount, options = {}) {
788
1286
  if (!this.walletClient) throw new Error("Wallet client required");
1287
+ const maxCost = options.maxCost ?? applySlippage(
1288
+ (await this.getQuote(auctionId, amount)).totalCost,
1289
+ options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
1290
+ );
789
1291
  const hash = await this.walletClient.writeContract({
790
1292
  chain: this.chain,
791
1293
  account: this.walletClient.account,
792
1294
  address: this.auctionAddress,
793
1295
  abi: tokenAuctionAbi,
794
1296
  functionName: "buyTokens",
795
- args: [auctionId, amount]
1297
+ args: [auctionId, amount, maxCost]
796
1298
  });
797
1299
  return hash;
798
1300
  }
799
1301
  /**
800
- * Withdraw a completed auction's raised payment tokens to its creator.
801
- * Only the auction's creator can call this, and only once.
1302
+ * Pay a completed auction's creator their share of the raise: everything
1303
+ * not reserved for Uniswap liquidity. Creator only, once, before or after
1304
+ * migration.
802
1305
  */
803
1306
  async withdrawProceeds(auctionId) {
804
1307
  if (!this.walletClient) throw new Error("Wallet client required");
@@ -812,6 +1315,53 @@ var AuctionFlowSDK = class {
812
1315
  });
813
1316
  return hash;
814
1317
  }
1318
+ /**
1319
+ * Move a completed auction's liquidity into a Uniswap v3 pool at the
1320
+ * auction's final price, lock it, and unlock the token for trading. Anyone
1321
+ * may call it.
1322
+ */
1323
+ async migrate(auctionId) {
1324
+ return this.write("migrate", [auctionId]);
1325
+ }
1326
+ /**
1327
+ * Collect the migrated pool's trading fees. The protocol takes its share and
1328
+ * the creator receives the rest. Anyone may call it.
1329
+ */
1330
+ async collectFees(auctionId) {
1331
+ return this.write("collectFees", [auctionId]);
1332
+ }
1333
+ /** The Uniswap pool and position for a migrated auction. */
1334
+ async getMigration(auctionId) {
1335
+ const [pool, positionId] = await Promise.all([
1336
+ this.publicClient.readContract({
1337
+ address: this.auctionAddress,
1338
+ abi: tokenAuctionAbi,
1339
+ functionName: "poolOf",
1340
+ args: [auctionId]
1341
+ }),
1342
+ this.publicClient.readContract({
1343
+ address: this.auctionAddress,
1344
+ abi: tokenAuctionAbi,
1345
+ functionName: "positionId",
1346
+ args: [auctionId]
1347
+ })
1348
+ ]);
1349
+ return {
1350
+ pool: pool === import_viem.zeroAddress ? null : pool,
1351
+ positionId: positionId === 0n ? null : positionId
1352
+ };
1353
+ }
1354
+ async write(functionName, args) {
1355
+ if (!this.walletClient) throw new Error("Wallet client required");
1356
+ return this.walletClient.writeContract({
1357
+ chain: this.chain,
1358
+ account: this.walletClient.account,
1359
+ address: this.auctionAddress,
1360
+ abi: tokenAuctionAbi,
1361
+ functionName,
1362
+ args
1363
+ });
1364
+ }
815
1365
  // Read: Has an auction's creator already withdrawn its proceeds?
816
1366
  async hasWithdrawnProceeds(auctionId) {
817
1367
  return this.publicClient.readContract({
@@ -834,18 +1384,22 @@ var AuctionFlowSDK = class {
834
1384
  // Read: Get buy quote (off-chain calculation)
835
1385
  async getQuote(auctionId, amount) {
836
1386
  const auction = await this.getAuction(auctionId);
837
- const quote = calculateBuyQuote(
1387
+ const fill = fillPurchase(
838
1388
  auction.totalSold,
839
1389
  amount,
840
1390
  auction.basePrice,
841
1391
  auction.slope,
842
- auction.protocolFeeBps
1392
+ auction.totalRaised,
1393
+ auction.maxRaise
843
1394
  );
1395
+ const fee = fill.cost * auction.protocolFeeBps / 10000n;
844
1396
  return {
845
- cost: quote.cost,
846
- fee: quote.fee,
847
- totalCost: quote.total,
848
- spotPriceAfter: quote.spotPriceAfter
1397
+ amount: fill.amount,
1398
+ cost: fill.cost,
1399
+ fee,
1400
+ totalCost: fill.cost + fee,
1401
+ spotPriceAfter: spotPrice(auction.totalSold + fill.amount, auction.basePrice, auction.slope),
1402
+ fillsAuction: fill.fillsAuction
849
1403
  };
850
1404
  }
851
1405
  // Read: Get spot price
@@ -871,7 +1425,9 @@ var AuctionFlowSDK = class {
871
1425
  state: raw.state,
872
1426
  totalRaised: raw.totalRaised,
873
1427
  totalSold: raw.totalSold,
874
- protocolFeeBps: raw.config.protocolFeeBps
1428
+ protocolFeeBps: raw.config.protocolFeeBps,
1429
+ liquidityBps: raw.config.liquidityBps,
1430
+ lpFeeShareBps: raw.config.lpFeeShareBps
875
1431
  };
876
1432
  }
877
1433
  };
@@ -890,9 +1446,15 @@ var AuctionState = /* @__PURE__ */ ((AuctionState2) => {
890
1446
  AuctionBuilder,
891
1447
  AuctionFlowSDK,
892
1448
  AuctionState,
1449
+ DEFAULT_LIQUIDITY_BPS,
1450
+ DEFAULT_SLIPPAGE_BPS,
1451
+ MIN_LIQUIDITY_BPS,
893
1452
  USDC_ADDRESSES,
1453
+ applySlippage,
894
1454
  calculateBuyCost,
895
1455
  calculateBuyQuote,
1456
+ fillPurchase,
1457
+ maxBuyable,
896
1458
  spotPrice
897
1459
  });
898
1460
  //# sourceMappingURL=index.js.map