auctionflow-sdk 1.2.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/README.md +118 -23
- package/dist/index.d.mts +134 -9
- package/dist/index.d.ts +134 -9
- package/dist/index.js +949 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +932 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,10 @@ import {
|
|
|
5
5
|
zeroAddress
|
|
6
6
|
} from "viem";
|
|
7
7
|
|
|
8
|
+
// src/constants/protocol.ts
|
|
9
|
+
var MIN_LIQUIDITY_BPS = 2e3;
|
|
10
|
+
var DEFAULT_LIQUIDITY_BPS = 5e3;
|
|
11
|
+
|
|
8
12
|
// src/builders/auction-builder.ts
|
|
9
13
|
var AuctionBuilder = class {
|
|
10
14
|
config = {};
|
|
@@ -23,13 +27,24 @@ var AuctionBuilder = class {
|
|
|
23
27
|
this.config.slope = slope;
|
|
24
28
|
return this;
|
|
25
29
|
}
|
|
30
|
+
/** Graduation threshold: once this much is raised, trading moves to Uniswap. */
|
|
26
31
|
withMaxRaise(maxRaise) {
|
|
27
32
|
this.config.maxRaise = maxRaise;
|
|
28
33
|
return this;
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Share of the raise, in basis points, seeded into a Uniswap pool when the
|
|
37
|
+
* auction migrates (5000 = 50%). The rest goes to the creator. Defaults to
|
|
38
|
+
* 50%; must be between 20% and 100%.
|
|
39
|
+
*/
|
|
40
|
+
withLiquidity(liquidityBps) {
|
|
41
|
+
if (!Number.isInteger(liquidityBps)) throw new Error("liquidityBps must be an integer");
|
|
42
|
+
this.config.liquidityBps = BigInt(liquidityBps);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/** Off-chain metadata for the token, such as its image (e.g. an IPFS URI). */
|
|
46
|
+
withMetadata(metadataURI) {
|
|
47
|
+
this.config.metadataURI = metadataURI;
|
|
33
48
|
return this;
|
|
34
49
|
}
|
|
35
50
|
build() {
|
|
@@ -40,22 +55,21 @@ var AuctionBuilder = class {
|
|
|
40
55
|
"paymentToken",
|
|
41
56
|
"basePrice",
|
|
42
57
|
"slope",
|
|
43
|
-
"maxRaise"
|
|
44
|
-
"startTime",
|
|
45
|
-
"endTime"
|
|
58
|
+
"maxRaise"
|
|
46
59
|
];
|
|
47
60
|
for (const key of required) {
|
|
48
61
|
if (this.config[key] === void 0) {
|
|
49
62
|
throw new Error(`Missing required field: ${key}`);
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
|
-
const config = this.config;
|
|
65
|
+
const config = { liquidityBps: BigInt(DEFAULT_LIQUIDITY_BPS), ...this.config };
|
|
53
66
|
if (config.maxSupply <= 0n) throw new Error("maxSupply must be greater than 0");
|
|
54
67
|
if (config.basePrice <= 0n) throw new Error("basePrice must be greater than 0");
|
|
55
68
|
if (config.slope < 0n) throw new Error("slope must not be negative");
|
|
56
69
|
if (config.maxRaise <= 0n) throw new Error("maxRaise must be greater than 0");
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
const liquidityBps = config.liquidityBps;
|
|
71
|
+
if (liquidityBps < BigInt(MIN_LIQUIDITY_BPS) || liquidityBps > 10000n) {
|
|
72
|
+
throw new Error(`liquidityBps must be between ${MIN_LIQUIDITY_BPS} and 10000`);
|
|
59
73
|
}
|
|
60
74
|
return config;
|
|
61
75
|
}
|
|
@@ -63,7 +77,7 @@ var AuctionBuilder = class {
|
|
|
63
77
|
|
|
64
78
|
// src/constants/addresses.ts
|
|
65
79
|
var AUCTION_ADDRESSES = {
|
|
66
|
-
84532: "
|
|
80
|
+
84532: "0xc6db1c900faeb4079281ecd6ec538c027cd18c28",
|
|
67
81
|
8453: "0x0000000000000000000000000000000000000000"
|
|
68
82
|
// not yet deployed
|
|
69
83
|
};
|
|
@@ -86,10 +100,67 @@ var tokenAuctionAbi = [
|
|
|
86
100
|
"name": "defaultFeeBps_",
|
|
87
101
|
"type": "uint256",
|
|
88
102
|
"internalType": "uint256"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "positionManager_",
|
|
106
|
+
"type": "address",
|
|
107
|
+
"internalType": "contract INonfungiblePositionManager"
|
|
89
108
|
}
|
|
90
109
|
],
|
|
91
110
|
"stateMutability": "nonpayable"
|
|
92
111
|
},
|
|
112
|
+
{
|
|
113
|
+
"type": "function",
|
|
114
|
+
"name": "MAX_FEE_BPS",
|
|
115
|
+
"inputs": [],
|
|
116
|
+
"outputs": [
|
|
117
|
+
{
|
|
118
|
+
"name": "",
|
|
119
|
+
"type": "uint256",
|
|
120
|
+
"internalType": "uint256"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"stateMutability": "view"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"type": "function",
|
|
127
|
+
"name": "MAX_LP_FEE_SHARE_BPS",
|
|
128
|
+
"inputs": [],
|
|
129
|
+
"outputs": [
|
|
130
|
+
{
|
|
131
|
+
"name": "",
|
|
132
|
+
"type": "uint256",
|
|
133
|
+
"internalType": "uint256"
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"stateMutability": "view"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"type": "function",
|
|
140
|
+
"name": "MIN_LIQUIDITY_BPS",
|
|
141
|
+
"inputs": [],
|
|
142
|
+
"outputs": [
|
|
143
|
+
{
|
|
144
|
+
"name": "",
|
|
145
|
+
"type": "uint256",
|
|
146
|
+
"internalType": "uint256"
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
"stateMutability": "view"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"type": "function",
|
|
153
|
+
"name": "POOL_FEE",
|
|
154
|
+
"inputs": [],
|
|
155
|
+
"outputs": [
|
|
156
|
+
{
|
|
157
|
+
"name": "",
|
|
158
|
+
"type": "uint24",
|
|
159
|
+
"internalType": "uint24"
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"stateMutability": "view"
|
|
163
|
+
},
|
|
93
164
|
{
|
|
94
165
|
"type": "function",
|
|
95
166
|
"name": "auctionCount",
|
|
@@ -145,22 +216,22 @@ var tokenAuctionAbi = [
|
|
|
145
216
|
"internalType": "uint256"
|
|
146
217
|
},
|
|
147
218
|
{
|
|
148
|
-
"name": "
|
|
149
|
-
"type": "
|
|
150
|
-
"internalType": "
|
|
219
|
+
"name": "creator",
|
|
220
|
+
"type": "address",
|
|
221
|
+
"internalType": "address"
|
|
151
222
|
},
|
|
152
223
|
{
|
|
153
|
-
"name": "
|
|
224
|
+
"name": "protocolFeeBps",
|
|
154
225
|
"type": "uint256",
|
|
155
226
|
"internalType": "uint256"
|
|
156
227
|
},
|
|
157
228
|
{
|
|
158
|
-
"name": "
|
|
159
|
-
"type": "
|
|
160
|
-
"internalType": "
|
|
229
|
+
"name": "liquidityBps",
|
|
230
|
+
"type": "uint256",
|
|
231
|
+
"internalType": "uint256"
|
|
161
232
|
},
|
|
162
233
|
{
|
|
163
|
-
"name": "
|
|
234
|
+
"name": "lpFeeShareBps",
|
|
164
235
|
"type": "uint256",
|
|
165
236
|
"internalType": "uint256"
|
|
166
237
|
}
|
|
@@ -197,6 +268,11 @@ var tokenAuctionAbi = [
|
|
|
197
268
|
"name": "amount",
|
|
198
269
|
"type": "uint256",
|
|
199
270
|
"internalType": "uint256"
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"name": "maxCost",
|
|
274
|
+
"type": "uint256",
|
|
275
|
+
"internalType": "uint256"
|
|
200
276
|
}
|
|
201
277
|
],
|
|
202
278
|
"outputs": [],
|
|
@@ -204,7 +280,7 @@ var tokenAuctionAbi = [
|
|
|
204
280
|
},
|
|
205
281
|
{
|
|
206
282
|
"type": "function",
|
|
207
|
-
"name": "
|
|
283
|
+
"name": "collectFees",
|
|
208
284
|
"inputs": [
|
|
209
285
|
{
|
|
210
286
|
"name": "auctionId",
|
|
@@ -212,12 +288,182 @@ var tokenAuctionAbi = [
|
|
|
212
288
|
"internalType": "uint256"
|
|
213
289
|
}
|
|
214
290
|
],
|
|
215
|
-
"outputs": [
|
|
291
|
+
"outputs": [
|
|
292
|
+
{
|
|
293
|
+
"name": "tokenFees",
|
|
294
|
+
"type": "uint256",
|
|
295
|
+
"internalType": "uint256"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
"name": "paymentFees",
|
|
299
|
+
"type": "uint256",
|
|
300
|
+
"internalType": "uint256"
|
|
301
|
+
}
|
|
302
|
+
],
|
|
216
303
|
"stateMutability": "nonpayable"
|
|
217
304
|
},
|
|
218
305
|
{
|
|
219
306
|
"type": "function",
|
|
220
307
|
"name": "createAuction",
|
|
308
|
+
"inputs": [
|
|
309
|
+
{
|
|
310
|
+
"name": "p",
|
|
311
|
+
"type": "tuple",
|
|
312
|
+
"internalType": "struct TokenAuction.AuctionParams",
|
|
313
|
+
"components": [
|
|
314
|
+
{
|
|
315
|
+
"name": "name",
|
|
316
|
+
"type": "string",
|
|
317
|
+
"internalType": "string"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
"name": "symbol",
|
|
321
|
+
"type": "string",
|
|
322
|
+
"internalType": "string"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
"name": "metadataURI",
|
|
326
|
+
"type": "string",
|
|
327
|
+
"internalType": "string"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"name": "maxSupply",
|
|
331
|
+
"type": "uint256",
|
|
332
|
+
"internalType": "uint256"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"name": "paymentToken",
|
|
336
|
+
"type": "address",
|
|
337
|
+
"internalType": "address"
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
"name": "basePrice",
|
|
341
|
+
"type": "uint256",
|
|
342
|
+
"internalType": "uint256"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"name": "slope",
|
|
346
|
+
"type": "uint256",
|
|
347
|
+
"internalType": "uint256"
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
"name": "maxRaise",
|
|
351
|
+
"type": "uint256",
|
|
352
|
+
"internalType": "uint256"
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
"name": "liquidityBps",
|
|
356
|
+
"type": "uint256",
|
|
357
|
+
"internalType": "uint256"
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
}
|
|
361
|
+
],
|
|
362
|
+
"outputs": [
|
|
363
|
+
{
|
|
364
|
+
"name": "auctionId",
|
|
365
|
+
"type": "uint256",
|
|
366
|
+
"internalType": "uint256"
|
|
367
|
+
}
|
|
368
|
+
],
|
|
369
|
+
"stateMutability": "nonpayable"
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
"type": "function",
|
|
373
|
+
"name": "custodied",
|
|
374
|
+
"inputs": [
|
|
375
|
+
{
|
|
376
|
+
"name": "",
|
|
377
|
+
"type": "address",
|
|
378
|
+
"internalType": "address"
|
|
379
|
+
}
|
|
380
|
+
],
|
|
381
|
+
"outputs": [
|
|
382
|
+
{
|
|
383
|
+
"name": "",
|
|
384
|
+
"type": "uint256",
|
|
385
|
+
"internalType": "uint256"
|
|
386
|
+
}
|
|
387
|
+
],
|
|
388
|
+
"stateMutability": "view"
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
"type": "function",
|
|
392
|
+
"name": "defaultFeeBps",
|
|
393
|
+
"inputs": [],
|
|
394
|
+
"outputs": [
|
|
395
|
+
{
|
|
396
|
+
"name": "",
|
|
397
|
+
"type": "uint256",
|
|
398
|
+
"internalType": "uint256"
|
|
399
|
+
}
|
|
400
|
+
],
|
|
401
|
+
"stateMutability": "view"
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
"type": "function",
|
|
405
|
+
"name": "defaultLpFeeShareBps",
|
|
406
|
+
"inputs": [],
|
|
407
|
+
"outputs": [
|
|
408
|
+
{
|
|
409
|
+
"name": "",
|
|
410
|
+
"type": "uint256",
|
|
411
|
+
"internalType": "uint256"
|
|
412
|
+
}
|
|
413
|
+
],
|
|
414
|
+
"stateMutability": "view"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
"type": "function",
|
|
418
|
+
"name": "getBuyCost",
|
|
419
|
+
"inputs": [
|
|
420
|
+
{
|
|
421
|
+
"name": "auctionId",
|
|
422
|
+
"type": "uint256",
|
|
423
|
+
"internalType": "uint256"
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
"name": "amount",
|
|
427
|
+
"type": "uint256",
|
|
428
|
+
"internalType": "uint256"
|
|
429
|
+
}
|
|
430
|
+
],
|
|
431
|
+
"outputs": [
|
|
432
|
+
{
|
|
433
|
+
"name": "cost",
|
|
434
|
+
"type": "uint256",
|
|
435
|
+
"internalType": "uint256"
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
"name": "fee",
|
|
439
|
+
"type": "uint256",
|
|
440
|
+
"internalType": "uint256"
|
|
441
|
+
}
|
|
442
|
+
],
|
|
443
|
+
"stateMutability": "view"
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
"type": "function",
|
|
447
|
+
"name": "getSpotPrice",
|
|
448
|
+
"inputs": [
|
|
449
|
+
{
|
|
450
|
+
"name": "auctionId",
|
|
451
|
+
"type": "uint256",
|
|
452
|
+
"internalType": "uint256"
|
|
453
|
+
}
|
|
454
|
+
],
|
|
455
|
+
"outputs": [
|
|
456
|
+
{
|
|
457
|
+
"name": "",
|
|
458
|
+
"type": "uint256",
|
|
459
|
+
"internalType": "uint256"
|
|
460
|
+
}
|
|
461
|
+
],
|
|
462
|
+
"stateMutability": "view"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
"type": "function",
|
|
466
|
+
"name": "launch",
|
|
221
467
|
"inputs": [
|
|
222
468
|
{
|
|
223
469
|
"name": "name",
|
|
@@ -230,98 +476,109 @@ var tokenAuctionAbi = [
|
|
|
230
476
|
"internalType": "string"
|
|
231
477
|
},
|
|
232
478
|
{
|
|
233
|
-
"name": "
|
|
479
|
+
"name": "metadataURI",
|
|
480
|
+
"type": "string",
|
|
481
|
+
"internalType": "string"
|
|
482
|
+
}
|
|
483
|
+
],
|
|
484
|
+
"outputs": [
|
|
485
|
+
{
|
|
486
|
+
"name": "auctionId",
|
|
234
487
|
"type": "uint256",
|
|
235
488
|
"internalType": "uint256"
|
|
236
|
-
}
|
|
489
|
+
}
|
|
490
|
+
],
|
|
491
|
+
"stateMutability": "nonpayable"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"type": "function",
|
|
495
|
+
"name": "launchPreset",
|
|
496
|
+
"inputs": [],
|
|
497
|
+
"outputs": [
|
|
237
498
|
{
|
|
238
499
|
"name": "paymentToken",
|
|
239
500
|
"type": "address",
|
|
240
501
|
"internalType": "address"
|
|
241
502
|
},
|
|
242
503
|
{
|
|
243
|
-
"name": "
|
|
504
|
+
"name": "maxSupply",
|
|
244
505
|
"type": "uint256",
|
|
245
506
|
"internalType": "uint256"
|
|
246
507
|
},
|
|
247
508
|
{
|
|
248
|
-
"name": "
|
|
509
|
+
"name": "basePrice",
|
|
249
510
|
"type": "uint256",
|
|
250
511
|
"internalType": "uint256"
|
|
251
512
|
},
|
|
252
513
|
{
|
|
253
|
-
"name": "
|
|
514
|
+
"name": "slope",
|
|
254
515
|
"type": "uint256",
|
|
255
516
|
"internalType": "uint256"
|
|
256
517
|
},
|
|
257
518
|
{
|
|
258
|
-
"name": "
|
|
519
|
+
"name": "maxRaise",
|
|
259
520
|
"type": "uint256",
|
|
260
521
|
"internalType": "uint256"
|
|
261
522
|
},
|
|
262
523
|
{
|
|
263
|
-
"name": "
|
|
524
|
+
"name": "liquidityBps",
|
|
264
525
|
"type": "uint256",
|
|
265
526
|
"internalType": "uint256"
|
|
266
527
|
}
|
|
267
528
|
],
|
|
268
|
-
"
|
|
529
|
+
"stateMutability": "view"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
"type": "function",
|
|
533
|
+
"name": "migrate",
|
|
534
|
+
"inputs": [
|
|
269
535
|
{
|
|
270
536
|
"name": "auctionId",
|
|
271
537
|
"type": "uint256",
|
|
272
538
|
"internalType": "uint256"
|
|
273
539
|
}
|
|
274
540
|
],
|
|
541
|
+
"outputs": [],
|
|
275
542
|
"stateMutability": "nonpayable"
|
|
276
543
|
},
|
|
277
544
|
{
|
|
278
545
|
"type": "function",
|
|
279
|
-
"name": "
|
|
546
|
+
"name": "owner",
|
|
280
547
|
"inputs": [],
|
|
281
548
|
"outputs": [
|
|
282
549
|
{
|
|
283
550
|
"name": "",
|
|
284
|
-
"type": "
|
|
285
|
-
"internalType": "
|
|
551
|
+
"type": "address",
|
|
552
|
+
"internalType": "address"
|
|
286
553
|
}
|
|
287
554
|
],
|
|
288
555
|
"stateMutability": "view"
|
|
289
556
|
},
|
|
290
557
|
{
|
|
291
558
|
"type": "function",
|
|
292
|
-
"name": "
|
|
559
|
+
"name": "poolOf",
|
|
293
560
|
"inputs": [
|
|
294
561
|
{
|
|
295
|
-
"name": "
|
|
296
|
-
"type": "uint256",
|
|
297
|
-
"internalType": "uint256"
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
"name": "amount",
|
|
562
|
+
"name": "",
|
|
301
563
|
"type": "uint256",
|
|
302
564
|
"internalType": "uint256"
|
|
303
565
|
}
|
|
304
566
|
],
|
|
305
567
|
"outputs": [
|
|
306
568
|
{
|
|
307
|
-
"name": "
|
|
308
|
-
"type": "
|
|
309
|
-
"internalType": "
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
"name": "fee",
|
|
313
|
-
"type": "uint256",
|
|
314
|
-
"internalType": "uint256"
|
|
569
|
+
"name": "",
|
|
570
|
+
"type": "address",
|
|
571
|
+
"internalType": "address"
|
|
315
572
|
}
|
|
316
573
|
],
|
|
317
574
|
"stateMutability": "view"
|
|
318
575
|
},
|
|
319
576
|
{
|
|
320
577
|
"type": "function",
|
|
321
|
-
"name": "
|
|
578
|
+
"name": "positionId",
|
|
322
579
|
"inputs": [
|
|
323
580
|
{
|
|
324
|
-
"name": "
|
|
581
|
+
"name": "",
|
|
325
582
|
"type": "uint256",
|
|
326
583
|
"internalType": "uint256"
|
|
327
584
|
}
|
|
@@ -337,13 +594,13 @@ var tokenAuctionAbi = [
|
|
|
337
594
|
},
|
|
338
595
|
{
|
|
339
596
|
"type": "function",
|
|
340
|
-
"name": "
|
|
597
|
+
"name": "positionManager",
|
|
341
598
|
"inputs": [],
|
|
342
599
|
"outputs": [
|
|
343
600
|
{
|
|
344
601
|
"name": "",
|
|
345
602
|
"type": "address",
|
|
346
|
-
"internalType": "
|
|
603
|
+
"internalType": "contract INonfungiblePositionManager"
|
|
347
604
|
}
|
|
348
605
|
],
|
|
349
606
|
"stateMutability": "view"
|
|
@@ -387,6 +644,131 @@ var tokenAuctionAbi = [
|
|
|
387
644
|
"outputs": [],
|
|
388
645
|
"stateMutability": "nonpayable"
|
|
389
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
|
+
},
|
|
670
|
+
{
|
|
671
|
+
"type": "function",
|
|
672
|
+
"name": "setDefaultFeeBps",
|
|
673
|
+
"inputs": [
|
|
674
|
+
{
|
|
675
|
+
"name": "feeBps",
|
|
676
|
+
"type": "uint256",
|
|
677
|
+
"internalType": "uint256"
|
|
678
|
+
}
|
|
679
|
+
],
|
|
680
|
+
"outputs": [],
|
|
681
|
+
"stateMutability": "nonpayable"
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
"type": "function",
|
|
685
|
+
"name": "setDefaultLpFeeShareBps",
|
|
686
|
+
"inputs": [
|
|
687
|
+
{
|
|
688
|
+
"name": "shareBps",
|
|
689
|
+
"type": "uint256",
|
|
690
|
+
"internalType": "uint256"
|
|
691
|
+
}
|
|
692
|
+
],
|
|
693
|
+
"outputs": [],
|
|
694
|
+
"stateMutability": "nonpayable"
|
|
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
|
+
},
|
|
741
|
+
{
|
|
742
|
+
"type": "function",
|
|
743
|
+
"name": "setProtocolFeeRecipient",
|
|
744
|
+
"inputs": [
|
|
745
|
+
{
|
|
746
|
+
"name": "recipient",
|
|
747
|
+
"type": "address",
|
|
748
|
+
"internalType": "address"
|
|
749
|
+
}
|
|
750
|
+
],
|
|
751
|
+
"outputs": [],
|
|
752
|
+
"stateMutability": "nonpayable"
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
"type": "function",
|
|
756
|
+
"name": "sweep",
|
|
757
|
+
"inputs": [
|
|
758
|
+
{
|
|
759
|
+
"name": "token",
|
|
760
|
+
"type": "address",
|
|
761
|
+
"internalType": "contract IERC20"
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
"name": "to",
|
|
765
|
+
"type": "address",
|
|
766
|
+
"internalType": "address"
|
|
767
|
+
}
|
|
768
|
+
],
|
|
769
|
+
"outputs": [],
|
|
770
|
+
"stateMutability": "nonpayable"
|
|
771
|
+
},
|
|
390
772
|
{
|
|
391
773
|
"type": "function",
|
|
392
774
|
"name": "transferOwnership",
|
|
@@ -400,46 +782,155 @@ var tokenAuctionAbi = [
|
|
|
400
782
|
"outputs": [],
|
|
401
783
|
"stateMutability": "nonpayable"
|
|
402
784
|
},
|
|
785
|
+
{
|
|
786
|
+
"type": "function",
|
|
787
|
+
"name": "uniswapV3SwapCallback",
|
|
788
|
+
"inputs": [
|
|
789
|
+
{
|
|
790
|
+
"name": "amount0Delta",
|
|
791
|
+
"type": "int256",
|
|
792
|
+
"internalType": "int256"
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
"name": "amount1Delta",
|
|
796
|
+
"type": "int256",
|
|
797
|
+
"internalType": "int256"
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
"name": "data",
|
|
801
|
+
"type": "bytes",
|
|
802
|
+
"internalType": "bytes"
|
|
803
|
+
}
|
|
804
|
+
],
|
|
805
|
+
"outputs": [],
|
|
806
|
+
"stateMutability": "nonpayable"
|
|
807
|
+
},
|
|
403
808
|
{
|
|
404
809
|
"type": "function",
|
|
405
810
|
"name": "userPurchases",
|
|
406
811
|
"inputs": [
|
|
407
812
|
{
|
|
408
|
-
"name": "",
|
|
813
|
+
"name": "",
|
|
814
|
+
"type": "uint256",
|
|
815
|
+
"internalType": "uint256"
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
"name": "",
|
|
819
|
+
"type": "address",
|
|
820
|
+
"internalType": "address"
|
|
821
|
+
}
|
|
822
|
+
],
|
|
823
|
+
"outputs": [
|
|
824
|
+
{
|
|
825
|
+
"name": "",
|
|
826
|
+
"type": "uint256",
|
|
827
|
+
"internalType": "uint256"
|
|
828
|
+
}
|
|
829
|
+
],
|
|
830
|
+
"stateMutability": "view"
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
"type": "function",
|
|
834
|
+
"name": "withdrawProceeds",
|
|
835
|
+
"inputs": [
|
|
836
|
+
{
|
|
837
|
+
"name": "auctionId",
|
|
838
|
+
"type": "uint256",
|
|
839
|
+
"internalType": "uint256"
|
|
840
|
+
}
|
|
841
|
+
],
|
|
842
|
+
"outputs": [],
|
|
843
|
+
"stateMutability": "nonpayable"
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
"type": "event",
|
|
847
|
+
"name": "AuctionCompleted",
|
|
848
|
+
"inputs": [
|
|
849
|
+
{
|
|
850
|
+
"name": "auctionId",
|
|
851
|
+
"type": "uint256",
|
|
852
|
+
"indexed": true,
|
|
853
|
+
"internalType": "uint256"
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
"name": "totalRaised",
|
|
857
|
+
"type": "uint256",
|
|
858
|
+
"indexed": false,
|
|
859
|
+
"internalType": "uint256"
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
"name": "totalSold",
|
|
863
|
+
"type": "uint256",
|
|
864
|
+
"indexed": false,
|
|
865
|
+
"internalType": "uint256"
|
|
866
|
+
}
|
|
867
|
+
],
|
|
868
|
+
"anonymous": false
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
"type": "event",
|
|
872
|
+
"name": "AuctionCreated",
|
|
873
|
+
"inputs": [
|
|
874
|
+
{
|
|
875
|
+
"name": "auctionId",
|
|
876
|
+
"type": "uint256",
|
|
877
|
+
"indexed": true,
|
|
878
|
+
"internalType": "uint256"
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
"name": "creator",
|
|
882
|
+
"type": "address",
|
|
883
|
+
"indexed": true,
|
|
884
|
+
"internalType": "address"
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
"name": "token",
|
|
888
|
+
"type": "address",
|
|
889
|
+
"indexed": false,
|
|
890
|
+
"internalType": "address"
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
"name": "paymentToken",
|
|
894
|
+
"type": "address",
|
|
895
|
+
"indexed": false,
|
|
896
|
+
"internalType": "address"
|
|
897
|
+
},
|
|
898
|
+
{
|
|
899
|
+
"name": "basePrice",
|
|
409
900
|
"type": "uint256",
|
|
901
|
+
"indexed": false,
|
|
410
902
|
"internalType": "uint256"
|
|
411
903
|
},
|
|
412
904
|
{
|
|
413
|
-
"name": "",
|
|
414
|
-
"type": "
|
|
415
|
-
"
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
"outputs": [
|
|
905
|
+
"name": "slope",
|
|
906
|
+
"type": "uint256",
|
|
907
|
+
"indexed": false,
|
|
908
|
+
"internalType": "uint256"
|
|
909
|
+
},
|
|
419
910
|
{
|
|
420
|
-
"name": "",
|
|
911
|
+
"name": "maxRaise",
|
|
421
912
|
"type": "uint256",
|
|
913
|
+
"indexed": false,
|
|
422
914
|
"internalType": "uint256"
|
|
423
|
-
}
|
|
424
|
-
],
|
|
425
|
-
"stateMutability": "view"
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
"type": "function",
|
|
429
|
-
"name": "withdrawProceeds",
|
|
430
|
-
"inputs": [
|
|
915
|
+
},
|
|
431
916
|
{
|
|
432
|
-
"name": "
|
|
917
|
+
"name": "liquidityBps",
|
|
433
918
|
"type": "uint256",
|
|
919
|
+
"indexed": false,
|
|
434
920
|
"internalType": "uint256"
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
"name": "metadataURI",
|
|
924
|
+
"type": "string",
|
|
925
|
+
"indexed": false,
|
|
926
|
+
"internalType": "string"
|
|
435
927
|
}
|
|
436
928
|
],
|
|
437
|
-
"
|
|
438
|
-
"stateMutability": "nonpayable"
|
|
929
|
+
"anonymous": false
|
|
439
930
|
},
|
|
440
931
|
{
|
|
441
932
|
"type": "event",
|
|
442
|
-
"name": "
|
|
933
|
+
"name": "AuctionMigrated",
|
|
443
934
|
"inputs": [
|
|
444
935
|
{
|
|
445
936
|
"name": "auctionId",
|
|
@@ -448,13 +939,25 @@ var tokenAuctionAbi = [
|
|
|
448
939
|
"internalType": "uint256"
|
|
449
940
|
},
|
|
450
941
|
{
|
|
451
|
-
"name": "
|
|
942
|
+
"name": "pool",
|
|
943
|
+
"type": "address",
|
|
944
|
+
"indexed": false,
|
|
945
|
+
"internalType": "address"
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
"name": "positionId",
|
|
452
949
|
"type": "uint256",
|
|
453
950
|
"indexed": false,
|
|
454
951
|
"internalType": "uint256"
|
|
455
952
|
},
|
|
456
953
|
{
|
|
457
|
-
"name": "
|
|
954
|
+
"name": "tokenLiquidity",
|
|
955
|
+
"type": "uint256",
|
|
956
|
+
"indexed": false,
|
|
957
|
+
"internalType": "uint256"
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
"name": "paymentLiquidity",
|
|
458
961
|
"type": "uint256",
|
|
459
962
|
"indexed": false,
|
|
460
963
|
"internalType": "uint256"
|
|
@@ -464,26 +967,46 @@ var tokenAuctionAbi = [
|
|
|
464
967
|
},
|
|
465
968
|
{
|
|
466
969
|
"type": "event",
|
|
467
|
-
"name": "
|
|
970
|
+
"name": "DefaultFeeBpsUpdated",
|
|
468
971
|
"inputs": [
|
|
469
972
|
{
|
|
470
|
-
"name": "
|
|
973
|
+
"name": "previous",
|
|
471
974
|
"type": "uint256",
|
|
472
|
-
"indexed":
|
|
975
|
+
"indexed": false,
|
|
473
976
|
"internalType": "uint256"
|
|
474
977
|
},
|
|
475
978
|
{
|
|
476
|
-
"name": "
|
|
477
|
-
"type": "
|
|
478
|
-
"indexed":
|
|
479
|
-
"internalType": "
|
|
480
|
-
}
|
|
979
|
+
"name": "current",
|
|
980
|
+
"type": "uint256",
|
|
981
|
+
"indexed": false,
|
|
982
|
+
"internalType": "uint256"
|
|
983
|
+
}
|
|
984
|
+
],
|
|
985
|
+
"anonymous": false
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
"type": "event",
|
|
989
|
+
"name": "DefaultLpFeeShareBpsUpdated",
|
|
990
|
+
"inputs": [
|
|
481
991
|
{
|
|
482
|
-
"name": "
|
|
483
|
-
"type": "
|
|
992
|
+
"name": "previous",
|
|
993
|
+
"type": "uint256",
|
|
484
994
|
"indexed": false,
|
|
485
|
-
"internalType": "
|
|
995
|
+
"internalType": "uint256"
|
|
486
996
|
},
|
|
997
|
+
{
|
|
998
|
+
"name": "current",
|
|
999
|
+
"type": "uint256",
|
|
1000
|
+
"indexed": false,
|
|
1001
|
+
"internalType": "uint256"
|
|
1002
|
+
}
|
|
1003
|
+
],
|
|
1004
|
+
"anonymous": false
|
|
1005
|
+
},
|
|
1006
|
+
{
|
|
1007
|
+
"type": "event",
|
|
1008
|
+
"name": "LaunchPresetUpdated",
|
|
1009
|
+
"inputs": [
|
|
487
1010
|
{
|
|
488
1011
|
"name": "paymentToken",
|
|
489
1012
|
"type": "address",
|
|
@@ -491,31 +1014,31 @@ var tokenAuctionAbi = [
|
|
|
491
1014
|
"internalType": "address"
|
|
492
1015
|
},
|
|
493
1016
|
{
|
|
494
|
-
"name": "
|
|
1017
|
+
"name": "maxSupply",
|
|
495
1018
|
"type": "uint256",
|
|
496
1019
|
"indexed": false,
|
|
497
1020
|
"internalType": "uint256"
|
|
498
1021
|
},
|
|
499
1022
|
{
|
|
500
|
-
"name": "
|
|
1023
|
+
"name": "basePrice",
|
|
501
1024
|
"type": "uint256",
|
|
502
1025
|
"indexed": false,
|
|
503
1026
|
"internalType": "uint256"
|
|
504
1027
|
},
|
|
505
1028
|
{
|
|
506
|
-
"name": "
|
|
1029
|
+
"name": "slope",
|
|
507
1030
|
"type": "uint256",
|
|
508
1031
|
"indexed": false,
|
|
509
1032
|
"internalType": "uint256"
|
|
510
1033
|
},
|
|
511
1034
|
{
|
|
512
|
-
"name": "
|
|
1035
|
+
"name": "maxRaise",
|
|
513
1036
|
"type": "uint256",
|
|
514
1037
|
"indexed": false,
|
|
515
1038
|
"internalType": "uint256"
|
|
516
1039
|
},
|
|
517
1040
|
{
|
|
518
|
-
"name": "
|
|
1041
|
+
"name": "liquidityBps",
|
|
519
1042
|
"type": "uint256",
|
|
520
1043
|
"indexed": false,
|
|
521
1044
|
"internalType": "uint256"
|
|
@@ -525,7 +1048,7 @@ var tokenAuctionAbi = [
|
|
|
525
1048
|
},
|
|
526
1049
|
{
|
|
527
1050
|
"type": "event",
|
|
528
|
-
"name": "
|
|
1051
|
+
"name": "LpFeesCollected",
|
|
529
1052
|
"inputs": [
|
|
530
1053
|
{
|
|
531
1054
|
"name": "auctionId",
|
|
@@ -534,10 +1057,28 @@ var tokenAuctionAbi = [
|
|
|
534
1057
|
"internalType": "uint256"
|
|
535
1058
|
},
|
|
536
1059
|
{
|
|
537
|
-
"name": "
|
|
538
|
-
"type": "
|
|
1060
|
+
"name": "creatorTokenFees",
|
|
1061
|
+
"type": "uint256",
|
|
539
1062
|
"indexed": false,
|
|
540
|
-
"internalType": "
|
|
1063
|
+
"internalType": "uint256"
|
|
1064
|
+
},
|
|
1065
|
+
{
|
|
1066
|
+
"name": "creatorPaymentFees",
|
|
1067
|
+
"type": "uint256",
|
|
1068
|
+
"indexed": false,
|
|
1069
|
+
"internalType": "uint256"
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
"name": "protocolTokenFees",
|
|
1073
|
+
"type": "uint256",
|
|
1074
|
+
"indexed": false,
|
|
1075
|
+
"internalType": "uint256"
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
"name": "protocolPaymentFees",
|
|
1079
|
+
"type": "uint256",
|
|
1080
|
+
"indexed": false,
|
|
1081
|
+
"internalType": "uint256"
|
|
541
1082
|
}
|
|
542
1083
|
],
|
|
543
1084
|
"anonymous": false
|
|
@@ -586,6 +1127,50 @@ var tokenAuctionAbi = [
|
|
|
586
1127
|
],
|
|
587
1128
|
"anonymous": false
|
|
588
1129
|
},
|
|
1130
|
+
{
|
|
1131
|
+
"type": "event",
|
|
1132
|
+
"name": "ProtocolFeeRecipientUpdated",
|
|
1133
|
+
"inputs": [
|
|
1134
|
+
{
|
|
1135
|
+
"name": "previous",
|
|
1136
|
+
"type": "address",
|
|
1137
|
+
"indexed": true,
|
|
1138
|
+
"internalType": "address"
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
"name": "current",
|
|
1142
|
+
"type": "address",
|
|
1143
|
+
"indexed": true,
|
|
1144
|
+
"internalType": "address"
|
|
1145
|
+
}
|
|
1146
|
+
],
|
|
1147
|
+
"anonymous": false
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
"type": "event",
|
|
1151
|
+
"name": "Swept",
|
|
1152
|
+
"inputs": [
|
|
1153
|
+
{
|
|
1154
|
+
"name": "token",
|
|
1155
|
+
"type": "address",
|
|
1156
|
+
"indexed": true,
|
|
1157
|
+
"internalType": "address"
|
|
1158
|
+
},
|
|
1159
|
+
{
|
|
1160
|
+
"name": "to",
|
|
1161
|
+
"type": "address",
|
|
1162
|
+
"indexed": true,
|
|
1163
|
+
"internalType": "address"
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
"name": "amount",
|
|
1167
|
+
"type": "uint256",
|
|
1168
|
+
"indexed": false,
|
|
1169
|
+
"internalType": "uint256"
|
|
1170
|
+
}
|
|
1171
|
+
],
|
|
1172
|
+
"anonymous": false
|
|
1173
|
+
},
|
|
589
1174
|
{
|
|
590
1175
|
"type": "event",
|
|
591
1176
|
"name": "TokensPurchased",
|
|
@@ -635,6 +1220,55 @@ var tokenAuctionAbi = [
|
|
|
635
1220
|
],
|
|
636
1221
|
"anonymous": false
|
|
637
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
|
+
},
|
|
638
1272
|
{
|
|
639
1273
|
"type": "error",
|
|
640
1274
|
"name": "OwnableInvalidOwner",
|
|
@@ -676,12 +1310,32 @@ var tokenAuctionAbi = [
|
|
|
676
1310
|
];
|
|
677
1311
|
|
|
678
1312
|
// src/utils/bonding-curve.ts
|
|
1313
|
+
import { formatUnits, parseUnits } from "viem";
|
|
679
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
|
+
}
|
|
1323
|
+
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
680
1324
|
function calculateBuyCost(currentSupply, amount, basePrice, slope) {
|
|
681
|
-
const linearCost = basePrice * amount
|
|
682
|
-
const curveCost =
|
|
1325
|
+
const linearCost = ceilDiv(basePrice * amount, SCALE);
|
|
1326
|
+
const curveCost = ceilDiv(
|
|
1327
|
+
slope * amount * (2n * currentSupply + amount),
|
|
1328
|
+
2n * SCALE * TOKEN_SCALE
|
|
1329
|
+
);
|
|
683
1330
|
return linearCost + curveCost;
|
|
684
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
|
+
}
|
|
685
1339
|
function spotPrice(currentSupply, basePrice, slope) {
|
|
686
1340
|
return basePrice + slope * currentSupply / TOKEN_SCALE;
|
|
687
1341
|
}
|
|
@@ -695,6 +1349,43 @@ function calculateBuyQuote(currentSupply, amount, basePrice, slope, feeBps) {
|
|
|
695
1349
|
spotPriceAfter: spotPrice(currentSupply + amount, basePrice, slope)
|
|
696
1350
|
};
|
|
697
1351
|
}
|
|
1352
|
+
var DEFAULT_SLIPPAGE_BPS = 100;
|
|
1353
|
+
function applySlippage(total, slippageBps) {
|
|
1354
|
+
if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > 1e4) {
|
|
1355
|
+
throw new Error("slippageBps must be an integer between 0 and 10000");
|
|
1356
|
+
}
|
|
1357
|
+
return (total * BigInt(1e4 + slippageBps) + 9999n) / 10000n;
|
|
1358
|
+
}
|
|
1359
|
+
function maxBuyable(currentSupply, budget, basePrice, slope, upperBound) {
|
|
1360
|
+
let hi = budget * SCALE / basePrice + 1n;
|
|
1361
|
+
if (hi > upperBound) hi = upperBound;
|
|
1362
|
+
let lo = 0n;
|
|
1363
|
+
while (lo < hi) {
|
|
1364
|
+
const mid = (lo + hi + 1n) / 2n;
|
|
1365
|
+
if (calculateBuyCost(currentSupply, mid, basePrice, slope) <= budget) lo = mid;
|
|
1366
|
+
else hi = mid - 1n;
|
|
1367
|
+
}
|
|
1368
|
+
return lo;
|
|
1369
|
+
}
|
|
1370
|
+
function fillPurchase(currentSupply, requested, basePrice, slope, totalRaised, maxRaise) {
|
|
1371
|
+
const remaining = maxRaise - totalRaised;
|
|
1372
|
+
const cost = calculateBuyCost(currentSupply, requested, basePrice, slope);
|
|
1373
|
+
if (cost < remaining) return { amount: requested, cost, fillsAuction: false };
|
|
1374
|
+
if (cost === remaining) return { amount: requested, cost, fillsAuction: true };
|
|
1375
|
+
const amount = maxBuyable(currentSupply, remaining, basePrice, slope, requested);
|
|
1376
|
+
if (amount === 0n) throw new Error("Auction is sold out");
|
|
1377
|
+
return {
|
|
1378
|
+
amount,
|
|
1379
|
+
cost: calculateBuyCost(currentSupply, amount, basePrice, slope),
|
|
1380
|
+
fillsAuction: true
|
|
1381
|
+
};
|
|
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
|
+
}
|
|
698
1389
|
|
|
699
1390
|
// src/utils/chains.ts
|
|
700
1391
|
import { base, baseSepolia } from "viem/chains";
|
|
@@ -743,34 +1434,97 @@ var AuctionFlowSDK = class {
|
|
|
743
1434
|
abi: tokenAuctionAbi,
|
|
744
1435
|
functionName: "createAuction",
|
|
745
1436
|
args: [
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
1437
|
+
{
|
|
1438
|
+
name: config.name,
|
|
1439
|
+
symbol: config.symbol,
|
|
1440
|
+
metadataURI: config.metadataURI ?? "",
|
|
1441
|
+
maxSupply: config.maxSupply,
|
|
1442
|
+
paymentToken: config.paymentToken,
|
|
1443
|
+
basePrice: config.basePrice,
|
|
1444
|
+
slope: config.slope,
|
|
1445
|
+
maxRaise: config.maxRaise,
|
|
1446
|
+
liquidityBps: config.liquidityBps ?? BigInt(DEFAULT_LIQUIDITY_BPS)
|
|
1447
|
+
}
|
|
755
1448
|
]
|
|
756
1449
|
});
|
|
757
1450
|
return hash;
|
|
758
1451
|
}
|
|
759
|
-
|
|
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
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Buy `amount` tokens (in token wei). The price rises with every purchase, so
|
|
1502
|
+
* the contract takes a maximum total cost and reverts if the price moved past
|
|
1503
|
+
* it before the transaction landed.
|
|
1504
|
+
*
|
|
1505
|
+
* Pass `maxCost` to set that bound exactly, or `slippageBps` to derive it
|
|
1506
|
+
* from a fresh quote (default 100 = 1% above the quoted total).
|
|
1507
|
+
*/
|
|
1508
|
+
async buyTokens(auctionId, amount, options = {}) {
|
|
760
1509
|
if (!this.walletClient) throw new Error("Wallet client required");
|
|
1510
|
+
const maxCost = options.maxCost ?? applySlippage(
|
|
1511
|
+
(await this.getQuote(auctionId, amount)).totalCost,
|
|
1512
|
+
options.slippageBps ?? DEFAULT_SLIPPAGE_BPS
|
|
1513
|
+
);
|
|
761
1514
|
const hash = await this.walletClient.writeContract({
|
|
762
1515
|
chain: this.chain,
|
|
763
1516
|
account: this.walletClient.account,
|
|
764
1517
|
address: this.auctionAddress,
|
|
765
1518
|
abi: tokenAuctionAbi,
|
|
766
1519
|
functionName: "buyTokens",
|
|
767
|
-
args: [auctionId, amount]
|
|
1520
|
+
args: [auctionId, amount, maxCost]
|
|
768
1521
|
});
|
|
769
1522
|
return hash;
|
|
770
1523
|
}
|
|
771
1524
|
/**
|
|
772
|
-
*
|
|
773
|
-
*
|
|
1525
|
+
* Pay a completed auction's creator their share of the raise: everything
|
|
1526
|
+
* not reserved for Uniswap liquidity. Creator only, once, before or after
|
|
1527
|
+
* migration.
|
|
774
1528
|
*/
|
|
775
1529
|
async withdrawProceeds(auctionId) {
|
|
776
1530
|
if (!this.walletClient) throw new Error("Wallet client required");
|
|
@@ -784,6 +1538,53 @@ var AuctionFlowSDK = class {
|
|
|
784
1538
|
});
|
|
785
1539
|
return hash;
|
|
786
1540
|
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Move a completed auction's liquidity into a Uniswap v3 pool at the
|
|
1543
|
+
* auction's final price, lock it, and unlock the token for trading. Anyone
|
|
1544
|
+
* may call it.
|
|
1545
|
+
*/
|
|
1546
|
+
async migrate(auctionId) {
|
|
1547
|
+
return this.write("migrate", [auctionId]);
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Collect the migrated pool's trading fees. The protocol takes its share and
|
|
1551
|
+
* the creator receives the rest. Anyone may call it.
|
|
1552
|
+
*/
|
|
1553
|
+
async collectFees(auctionId) {
|
|
1554
|
+
return this.write("collectFees", [auctionId]);
|
|
1555
|
+
}
|
|
1556
|
+
/** The Uniswap pool and position for a migrated auction. */
|
|
1557
|
+
async getMigration(auctionId) {
|
|
1558
|
+
const [pool, positionId] = await Promise.all([
|
|
1559
|
+
this.publicClient.readContract({
|
|
1560
|
+
address: this.auctionAddress,
|
|
1561
|
+
abi: tokenAuctionAbi,
|
|
1562
|
+
functionName: "poolOf",
|
|
1563
|
+
args: [auctionId]
|
|
1564
|
+
}),
|
|
1565
|
+
this.publicClient.readContract({
|
|
1566
|
+
address: this.auctionAddress,
|
|
1567
|
+
abi: tokenAuctionAbi,
|
|
1568
|
+
functionName: "positionId",
|
|
1569
|
+
args: [auctionId]
|
|
1570
|
+
})
|
|
1571
|
+
]);
|
|
1572
|
+
return {
|
|
1573
|
+
pool: pool === zeroAddress ? null : pool,
|
|
1574
|
+
positionId: positionId === 0n ? null : positionId
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
async write(functionName, args) {
|
|
1578
|
+
if (!this.walletClient) throw new Error("Wallet client required");
|
|
1579
|
+
return this.walletClient.writeContract({
|
|
1580
|
+
chain: this.chain,
|
|
1581
|
+
account: this.walletClient.account,
|
|
1582
|
+
address: this.auctionAddress,
|
|
1583
|
+
abi: tokenAuctionAbi,
|
|
1584
|
+
functionName,
|
|
1585
|
+
args
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
787
1588
|
// Read: Has an auction's creator already withdrawn its proceeds?
|
|
788
1589
|
async hasWithdrawnProceeds(auctionId) {
|
|
789
1590
|
return this.publicClient.readContract({
|
|
@@ -806,18 +1607,22 @@ var AuctionFlowSDK = class {
|
|
|
806
1607
|
// Read: Get buy quote (off-chain calculation)
|
|
807
1608
|
async getQuote(auctionId, amount) {
|
|
808
1609
|
const auction = await this.getAuction(auctionId);
|
|
809
|
-
const
|
|
1610
|
+
const fill = fillPurchase(
|
|
810
1611
|
auction.totalSold,
|
|
811
1612
|
amount,
|
|
812
1613
|
auction.basePrice,
|
|
813
1614
|
auction.slope,
|
|
814
|
-
auction.
|
|
1615
|
+
auction.totalRaised,
|
|
1616
|
+
auction.maxRaise
|
|
815
1617
|
);
|
|
1618
|
+
const fee = fill.cost * auction.protocolFeeBps / 10000n;
|
|
816
1619
|
return {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
1620
|
+
amount: fill.amount,
|
|
1621
|
+
cost: fill.cost,
|
|
1622
|
+
fee,
|
|
1623
|
+
totalCost: fill.cost + fee,
|
|
1624
|
+
spotPriceAfter: spotPrice(auction.totalSold + fill.amount, auction.basePrice, auction.slope),
|
|
1625
|
+
fillsAuction: fill.fillsAuction
|
|
821
1626
|
};
|
|
822
1627
|
}
|
|
823
1628
|
// Read: Get spot price
|
|
@@ -838,12 +1643,12 @@ var AuctionFlowSDK = class {
|
|
|
838
1643
|
basePrice: raw.config.basePrice,
|
|
839
1644
|
slope: raw.config.slope,
|
|
840
1645
|
maxRaise: raw.config.maxRaise,
|
|
841
|
-
startTime: raw.config.startTime,
|
|
842
|
-
endTime: raw.config.endTime,
|
|
843
1646
|
state: raw.state,
|
|
844
1647
|
totalRaised: raw.totalRaised,
|
|
845
1648
|
totalSold: raw.totalSold,
|
|
846
|
-
protocolFeeBps: raw.config.protocolFeeBps
|
|
1649
|
+
protocolFeeBps: raw.config.protocolFeeBps,
|
|
1650
|
+
liquidityBps: raw.config.liquidityBps,
|
|
1651
|
+
lpFeeShareBps: raw.config.lpFeeShareBps
|
|
847
1652
|
};
|
|
848
1653
|
}
|
|
849
1654
|
};
|
|
@@ -861,9 +1666,20 @@ export {
|
|
|
861
1666
|
AuctionBuilder,
|
|
862
1667
|
AuctionFlowSDK,
|
|
863
1668
|
AuctionState,
|
|
1669
|
+
DEFAULT_LIQUIDITY_BPS,
|
|
1670
|
+
DEFAULT_SLIPPAGE_BPS,
|
|
1671
|
+
MIN_LIQUIDITY_BPS,
|
|
1672
|
+
PRICE_SCALE,
|
|
864
1673
|
USDC_ADDRESSES,
|
|
1674
|
+
applySellSlippage,
|
|
1675
|
+
applySlippage,
|
|
865
1676
|
calculateBuyCost,
|
|
866
1677
|
calculateBuyQuote,
|
|
1678
|
+
calculateSellProceeds,
|
|
1679
|
+
fillPurchase,
|
|
1680
|
+
formatCurvePrice,
|
|
1681
|
+
maxBuyable,
|
|
1682
|
+
parseCurvePrice,
|
|
867
1683
|
spotPrice
|
|
868
1684
|
};
|
|
869
1685
|
//# sourceMappingURL=index.mjs.map
|