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/README.md +66 -19
- package/dist/index.d.mts +54 -7
- package/dist/index.d.ts +54 -7
- package/dist/index.js +333 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +321 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ pnpm add auctionflow-sdk viem
|
|
|
17
17
|
## Quick start
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import { AuctionFlowSDK } from "auctionflow-sdk";
|
|
20
|
+
import { AuctionFlowSDK, parseCurvePrice } from "auctionflow-sdk";
|
|
21
21
|
import { createWalletClient, http, parseUnits } from "viem";
|
|
22
22
|
import { privateKeyToAccount } from "viem/accounts";
|
|
23
23
|
import { baseSepolia } from "viem/chains";
|
|
@@ -53,11 +53,31 @@ const sdk = new AuctionFlowSDK({
|
|
|
53
53
|
|
|
54
54
|
Without it, constructing on a chain that has no built-in deployment throws.
|
|
55
55
|
|
|
56
|
-
##
|
|
56
|
+
## How a launch works
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
1. **Launch.** A token is created and trading starts immediately on a bonding
|
|
59
|
+
curve: every buy raises the price, every sell lowers it.
|
|
60
|
+
2. **Trade.** Anyone can buy, and sell back to the curve, until the auction has
|
|
61
|
+
raised its **graduation threshold** (`maxRaise`). Tokens can't be transferred
|
|
62
|
+
in the meantime; selling back is how you exit.
|
|
63
|
+
3. **Graduate.** The purchase that reaches the threshold closes the curve, and
|
|
64
|
+
the token migrates to a Uniswap v3 pool where it trades freely.
|
|
65
|
+
|
|
66
|
+
## Launch a token (one click)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const hash = await sdk.launch("My Token", "MTK", "ipfs://<metadata-json>");
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Everything except the name, symbol and metadata (such as the token image) comes
|
|
73
|
+
from the protocol's standard launch preset: the payment token, supply, curve,
|
|
74
|
+
graduation threshold and liquidity share.
|
|
75
|
+
|
|
76
|
+
## Create an auction with custom parameters
|
|
77
|
+
|
|
78
|
+
The builder validates required fields and basic invariants (positive
|
|
79
|
+
`basePrice` / `maxSupply` / `maxRaise`, a liquidity share between 20% and 100%)
|
|
80
|
+
before producing a config.
|
|
61
81
|
|
|
62
82
|
```typescript
|
|
63
83
|
const config = sdk
|
|
@@ -65,27 +85,31 @@ const config = sdk
|
|
|
65
85
|
.withToken("MyToken", "MTK", parseUnits("1000000", 18))
|
|
66
86
|
.withPaymentToken("0x036CbD53842c5426634e7929541eC2318f3dCF7e") // USDC Sepolia
|
|
67
87
|
.withBondingCurve(
|
|
68
|
-
|
|
69
|
-
|
|
88
|
+
parseCurvePrice("0.01", 6), // base price: 0.01 USDC per token
|
|
89
|
+
parseCurvePrice("0.000001", 6) // slope: +0.000001 USDC per token sold
|
|
70
90
|
)
|
|
71
|
-
.withMaxRaise(parseUnits("50000", 6))
|
|
91
|
+
.withMaxRaise(parseUnits("50000", 6)) // graduation threshold
|
|
72
92
|
.withLiquidity(5_000) // 50% of the raise seeds the Uniswap pool (the default)
|
|
73
|
-
.
|
|
74
|
-
BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
75
|
-
BigInt(Math.floor(Date.now() / 1000) + 3600 * 72)
|
|
76
|
-
)
|
|
93
|
+
.withMetadata("ipfs://<metadata-json>")
|
|
77
94
|
.build();
|
|
78
95
|
|
|
79
96
|
const hash = await sdk.createAuction(config);
|
|
80
97
|
```
|
|
81
98
|
|
|
99
|
+
Prices are per whole token, stored with 18 extra decimals so a curve can rise
|
|
100
|
+
by far less than one USDC unit per token, as a billion-token memecoin needs.
|
|
101
|
+
`parseCurvePrice(price, paymentDecimals)` converts a human price into those
|
|
102
|
+
units, and `formatCurvePrice` converts back (for example, a `getSpotPrice`
|
|
103
|
+
result for display).
|
|
104
|
+
|
|
82
105
|
`withLiquidity` sets the share of the raise, in basis points, that is paired
|
|
83
106
|
with newly minted tokens to open a Uniswap pool when the auction ends; the
|
|
84
107
|
creator receives the rest. The token supply must leave room for those tokens on
|
|
85
108
|
top of a sold-out sale, so the contract rejects a `maxSupply` that is too small.
|
|
86
109
|
|
|
87
110
|
Auction tokens can't be transferred until the auction migrates. That stops any
|
|
88
|
-
holder from creating or pricing the Uniswap pool ahead of the auction.
|
|
111
|
+
holder from creating or pricing the Uniswap pool ahead of the auction. Holders
|
|
112
|
+
can always exit before then by selling back to the curve.
|
|
89
113
|
|
|
90
114
|
## Buy tokens
|
|
91
115
|
|
|
@@ -109,6 +133,26 @@ the remaining budget buys, and closes the auction. `getQuote` reports this up
|
|
|
109
133
|
front: `quote.amount` is what you'll actually receive and `quote.fillsAuction`
|
|
110
134
|
says whether your purchase completes the sale.
|
|
111
135
|
|
|
136
|
+
## Sell tokens
|
|
137
|
+
|
|
138
|
+
Until graduation, anyone can sell tokens back to the curve at the curve price,
|
|
139
|
+
minus the protocol fee. The tokens are burned and the seller is paid from the
|
|
140
|
+
raise, so the price falls by exactly what the purchase raised it.
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const quote = await sdk.getSellQuote(0n, parseUnits("400", 18));
|
|
144
|
+
console.log(quote.proceeds, quote.fee, quote.netProceeds);
|
|
145
|
+
|
|
146
|
+
await sdk.sellTokens(0n, parseUnits("400", 18)); // 1% below the quote
|
|
147
|
+
await sdk.sellTokens(0n, parseUnits("400", 18), { slippageBps: 50 }); // 0.5% tolerance
|
|
148
|
+
await sdk.sellTokens(0n, parseUnits("400", 18), { minProceeds: 4_000_000n });
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Like `buyTokens`, the contract reverts if the price moved past your bound before
|
|
152
|
+
the transaction landed. Purchases round up and sales round down, so a round
|
|
153
|
+
trip can never profit, and the contract always holds enough to buy back every
|
|
154
|
+
outstanding token.
|
|
155
|
+
|
|
112
156
|
## Read state & quotes
|
|
113
157
|
|
|
114
158
|
```typescript
|
|
@@ -124,14 +168,13 @@ console.log(quote.cost, quote.fee, quote.totalCost, quote.spotPriceAfter);
|
|
|
124
168
|
The bonding-curve helpers are also exported directly for UI/preview use:
|
|
125
169
|
|
|
126
170
|
```typescript
|
|
127
|
-
import { calculateBuyQuote, spotPrice } from "auctionflow-sdk";
|
|
171
|
+
import { calculateBuyQuote, calculateSellProceeds, spotPrice, formatCurvePrice } from "auctionflow-sdk";
|
|
128
172
|
```
|
|
129
173
|
|
|
130
|
-
## After
|
|
174
|
+
## After graduation: migrate, withdraw, collect fees
|
|
131
175
|
|
|
132
|
-
Once an auction
|
|
133
|
-
|
|
134
|
-
withdrawal, which only the creator can make.
|
|
176
|
+
Once an auction graduates, three things happen. Each can be called by anyone
|
|
177
|
+
except the withdrawal, which only the creator can make.
|
|
135
178
|
|
|
136
179
|
```typescript
|
|
137
180
|
// 1. Open the Uniswap v3 pool and unlock the token for trading.
|
|
@@ -188,13 +231,17 @@ Early buyers pay less; later buyers pay more.
|
|
|
188
231
|
| Member | Description |
|
|
189
232
|
| --- | --- |
|
|
190
233
|
| `new AuctionFlowSDK({ chainId, rpcUrl, walletClient?, auctionAddress? })` | Construct against a supported chain. `auctionAddress` overrides the built-in deployment; without it, a chain with no canonical deployment throws. |
|
|
234
|
+
| `launch(name, symbol, metadataURI?)` | One-click launch with the protocol's standard preset. Requires a wallet client. |
|
|
191
235
|
| `buildAuction()` | Returns an `AuctionBuilder` (fluent config builder). |
|
|
192
|
-
| `createAuction(config)` |
|
|
236
|
+
| `createAuction(config)` | Launch with custom parameters. Requires a wallet client. |
|
|
193
237
|
| `buyTokens(auctionId, amount, { maxCost?, slippageBps? })` | Send the `buyTokens` transaction with a maximum total cost; reverts if the price moved past it. Defaults to the quote plus 1%. Requires a wallet client. |
|
|
194
238
|
| `getAuction(auctionId)` | Read the full auction struct. |
|
|
195
239
|
| `getSpotPrice(auctionId)` | Read the current on-chain spot price. |
|
|
196
240
|
| `getQuote(auctionId, amount)` | Tokens actually filled, cost, fee, post-trade spot price, and whether the purchase completes the auction. |
|
|
197
241
|
| `applySlippage(total, slippageBps)` | The maximum cost `buyTokens` would send for a quoted total. |
|
|
242
|
+
| `sellTokens(auctionId, amount, { minProceeds?, slippageBps? })` | Sell back to the curve before graduation, with a minimum payout; defaults to the quote minus 1%. Requires a wallet client. |
|
|
243
|
+
| `getSellQuote(auctionId, amount)` | Proceeds, fee, net payout, and post-trade spot price for a sale. |
|
|
244
|
+
| `applySellSlippage(netProceeds, slippageBps)` | The minimum payout `sellTokens` would send for a quoted sale. |
|
|
198
245
|
| `migrate(auctionId)` | Open the Uniswap v3 pool at the final price, lock the liquidity, unlock the token. Anyone may call. |
|
|
199
246
|
| `getMigration(auctionId)` | The pool address and position NFT id, or `null` before migration. |
|
|
200
247
|
| `withdrawProceeds(auctionId)` | Pay the creator their share of the raise (what isn't reserved for liquidity). Creator-only, once. |
|
package/dist/index.d.mts
CHANGED
|
@@ -13,9 +13,10 @@ interface AuctionConfig {
|
|
|
13
13
|
paymentToken: Address;
|
|
14
14
|
basePrice: bigint;
|
|
15
15
|
slope: bigint;
|
|
16
|
+
/** Graduation threshold: once this much is raised, trading moves to Uniswap. */
|
|
16
17
|
maxRaise: bigint;
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/** Off-chain metadata for the token, such as its image (e.g. an IPFS URI). */
|
|
19
|
+
metadataURI?: string;
|
|
19
20
|
/**
|
|
20
21
|
* Share of the raise seeded into Uniswap at migration, in basis points
|
|
21
22
|
* (2000..10000). Defaults to 5000 (50%).
|
|
@@ -30,8 +31,6 @@ interface AuctionData {
|
|
|
30
31
|
basePrice: bigint;
|
|
31
32
|
slope: bigint;
|
|
32
33
|
maxRaise: bigint;
|
|
33
|
-
startTime: bigint;
|
|
34
|
-
endTime: bigint;
|
|
35
34
|
state: AuctionState;
|
|
36
35
|
totalRaised: bigint;
|
|
37
36
|
totalSold: bigint;
|
|
@@ -40,6 +39,14 @@ interface AuctionData {
|
|
|
40
39
|
/** Protocol's share of the Uniswap pool's trading fees, in basis points. */
|
|
41
40
|
lpFeeShareBps: bigint;
|
|
42
41
|
}
|
|
42
|
+
interface SellQuote {
|
|
43
|
+
/** Curve value of the tokens being sold, before the protocol fee. */
|
|
44
|
+
proceeds: bigint;
|
|
45
|
+
fee: bigint;
|
|
46
|
+
/** What the seller receives: proceeds minus fee. */
|
|
47
|
+
netProceeds: bigint;
|
|
48
|
+
spotPriceAfter: bigint;
|
|
49
|
+
}
|
|
43
50
|
interface MigrationInfo {
|
|
44
51
|
/** The Uniswap v3 pool, or null if the auction unlocked without one. */
|
|
45
52
|
pool: Address | null;
|
|
@@ -66,6 +73,7 @@ declare class AuctionBuilder {
|
|
|
66
73
|
withToken(name: string, symbol: string, maxSupply: bigint): this;
|
|
67
74
|
withPaymentToken(address: Address): this;
|
|
68
75
|
withBondingCurve(basePrice: bigint, slope: bigint): this;
|
|
76
|
+
/** Graduation threshold: once this much is raised, trading moves to Uniswap. */
|
|
69
77
|
withMaxRaise(maxRaise: bigint): this;
|
|
70
78
|
/**
|
|
71
79
|
* Share of the raise, in basis points, seeded into a Uniswap pool when the
|
|
@@ -73,7 +81,8 @@ declare class AuctionBuilder {
|
|
|
73
81
|
* 50%; must be between 20% and 100%.
|
|
74
82
|
*/
|
|
75
83
|
withLiquidity(liquidityBps: number): this;
|
|
76
|
-
|
|
84
|
+
/** Off-chain metadata for the token, such as its image (e.g. an IPFS URI). */
|
|
85
|
+
withMetadata(metadataURI: string): this;
|
|
77
86
|
build(): AuctionConfig;
|
|
78
87
|
}
|
|
79
88
|
|
|
@@ -91,6 +100,23 @@ declare class AuctionFlowSDK {
|
|
|
91
100
|
});
|
|
92
101
|
buildAuction(): AuctionBuilder;
|
|
93
102
|
createAuction(config: AuctionConfig): Promise<Hash>;
|
|
103
|
+
/**
|
|
104
|
+
* One-click launch: a token with the protocol's standard curve, threshold
|
|
105
|
+
* and liquidity share. Trading starts immediately.
|
|
106
|
+
*/
|
|
107
|
+
launch(name: string, symbol: string, metadataURI?: string): Promise<Hash>;
|
|
108
|
+
/**
|
|
109
|
+
* Sell `amount` tokens (in token wei) back to the curve before graduation.
|
|
110
|
+
* The contract reverts if the price fell below the bound before the
|
|
111
|
+
* transaction landed: pass `minProceeds` to set it exactly, or `slippageBps`
|
|
112
|
+
* to derive it from a fresh quote (default 100 = 1% below it).
|
|
113
|
+
*/
|
|
114
|
+
sellTokens(auctionId: bigint, amount: bigint, options?: {
|
|
115
|
+
minProceeds?: bigint;
|
|
116
|
+
slippageBps?: number;
|
|
117
|
+
}): Promise<Hash>;
|
|
118
|
+
/** What selling `amount` tokens back to the curve would pay right now. */
|
|
119
|
+
getSellQuote(auctionId: bigint, amount: bigint): Promise<SellQuote>;
|
|
94
120
|
/**
|
|
95
121
|
* Buy `amount` tokens (in token wei). The price rises with every purchase, so
|
|
96
122
|
* the contract takes a maximum total cost and reverts if the price moved past
|
|
@@ -138,7 +164,23 @@ declare const MIN_LIQUIDITY_BPS = 2000;
|
|
|
138
164
|
/** Liquidity share the builder uses when none is given (50%). */
|
|
139
165
|
declare const DEFAULT_LIQUIDITY_BPS = 5000;
|
|
140
166
|
|
|
167
|
+
/** Fixed-point scale of `basePrice`, `slope` and spot prices. */
|
|
168
|
+
declare const PRICE_SCALE: bigint;
|
|
169
|
+
/**
|
|
170
|
+
* A human-readable price per whole token, in curve units.
|
|
171
|
+
* `parseCurvePrice("0.01", 6)` is 0.01 USDC per token.
|
|
172
|
+
*/
|
|
173
|
+
declare function parseCurvePrice(price: string, paymentDecimals: number): bigint;
|
|
174
|
+
/** A curve price (e.g. from `getSpotPrice`) as a human-readable price per whole token. */
|
|
175
|
+
declare function formatCurvePrice(price: bigint, paymentDecimals: number): string;
|
|
141
176
|
declare function calculateBuyCost(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint): bigint;
|
|
177
|
+
/**
|
|
178
|
+
* Proceeds from selling `amount` tokens back to the curve when `currentSupply`
|
|
179
|
+
* are outstanding. Mirrors BondingCurve.calculateSellProceeds: the same
|
|
180
|
+
* integral as a purchase, but rounded down, so a round trip never profits.
|
|
181
|
+
*/
|
|
182
|
+
declare function calculateSellProceeds(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint): bigint;
|
|
183
|
+
/** Price of the next whole token, in curve units (payment units × 1e18). */
|
|
142
184
|
declare function spotPrice(currentSupply: bigint, basePrice: bigint, slope: bigint): bigint;
|
|
143
185
|
declare function calculateBuyQuote(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint, feeBps: bigint): {
|
|
144
186
|
cost: bigint;
|
|
@@ -146,7 +188,7 @@ declare function calculateBuyQuote(currentSupply: bigint, amount: bigint, basePr
|
|
|
146
188
|
total: bigint;
|
|
147
189
|
spotPriceAfter: bigint;
|
|
148
190
|
};
|
|
149
|
-
/** Default slippage tolerance for `buyTokens`, in basis points (100 = 1%). */
|
|
191
|
+
/** Default slippage tolerance for `buyTokens` and `sellTokens`, in basis points (100 = 1%). */
|
|
150
192
|
declare const DEFAULT_SLIPPAGE_BPS = 100;
|
|
151
193
|
/**
|
|
152
194
|
* Upper bound a buyer will accept for a quoted total, given a tolerance in
|
|
@@ -169,5 +211,10 @@ declare function fillPurchase(currentSupply: bigint, requested: bigint, basePric
|
|
|
169
211
|
cost: bigint;
|
|
170
212
|
fillsAuction: boolean;
|
|
171
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* Least a seller will accept for a quoted amount, given a tolerance in basis
|
|
216
|
+
* points. Rounds down so a tolerance never comes out tighter than asked.
|
|
217
|
+
*/
|
|
218
|
+
declare function applySellSlippage(netProceeds: bigint, slippageBps: number): bigint;
|
|
172
219
|
|
|
173
|
-
export { AUCTION_ADDRESSES, AuctionBuilder, type AuctionConfig, type AuctionData, AuctionFlowSDK, AuctionState, type BuyQuote, DEFAULT_LIQUIDITY_BPS, DEFAULT_SLIPPAGE_BPS, MIN_LIQUIDITY_BPS, type MigrationInfo, type SupportedChainId, type TransactionResult, USDC_ADDRESSES, applySlippage, calculateBuyCost, calculateBuyQuote, fillPurchase, maxBuyable, spotPrice };
|
|
220
|
+
export { AUCTION_ADDRESSES, AuctionBuilder, type AuctionConfig, type AuctionData, AuctionFlowSDK, AuctionState, type BuyQuote, DEFAULT_LIQUIDITY_BPS, DEFAULT_SLIPPAGE_BPS, MIN_LIQUIDITY_BPS, type MigrationInfo, PRICE_SCALE, type SellQuote, type SupportedChainId, type TransactionResult, USDC_ADDRESSES, applySellSlippage, applySlippage, calculateBuyCost, calculateBuyQuote, calculateSellProceeds, fillPurchase, formatCurvePrice, maxBuyable, parseCurvePrice, spotPrice };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ interface AuctionConfig {
|
|
|
13
13
|
paymentToken: Address;
|
|
14
14
|
basePrice: bigint;
|
|
15
15
|
slope: bigint;
|
|
16
|
+
/** Graduation threshold: once this much is raised, trading moves to Uniswap. */
|
|
16
17
|
maxRaise: bigint;
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/** Off-chain metadata for the token, such as its image (e.g. an IPFS URI). */
|
|
19
|
+
metadataURI?: string;
|
|
19
20
|
/**
|
|
20
21
|
* Share of the raise seeded into Uniswap at migration, in basis points
|
|
21
22
|
* (2000..10000). Defaults to 5000 (50%).
|
|
@@ -30,8 +31,6 @@ interface AuctionData {
|
|
|
30
31
|
basePrice: bigint;
|
|
31
32
|
slope: bigint;
|
|
32
33
|
maxRaise: bigint;
|
|
33
|
-
startTime: bigint;
|
|
34
|
-
endTime: bigint;
|
|
35
34
|
state: AuctionState;
|
|
36
35
|
totalRaised: bigint;
|
|
37
36
|
totalSold: bigint;
|
|
@@ -40,6 +39,14 @@ interface AuctionData {
|
|
|
40
39
|
/** Protocol's share of the Uniswap pool's trading fees, in basis points. */
|
|
41
40
|
lpFeeShareBps: bigint;
|
|
42
41
|
}
|
|
42
|
+
interface SellQuote {
|
|
43
|
+
/** Curve value of the tokens being sold, before the protocol fee. */
|
|
44
|
+
proceeds: bigint;
|
|
45
|
+
fee: bigint;
|
|
46
|
+
/** What the seller receives: proceeds minus fee. */
|
|
47
|
+
netProceeds: bigint;
|
|
48
|
+
spotPriceAfter: bigint;
|
|
49
|
+
}
|
|
43
50
|
interface MigrationInfo {
|
|
44
51
|
/** The Uniswap v3 pool, or null if the auction unlocked without one. */
|
|
45
52
|
pool: Address | null;
|
|
@@ -66,6 +73,7 @@ declare class AuctionBuilder {
|
|
|
66
73
|
withToken(name: string, symbol: string, maxSupply: bigint): this;
|
|
67
74
|
withPaymentToken(address: Address): this;
|
|
68
75
|
withBondingCurve(basePrice: bigint, slope: bigint): this;
|
|
76
|
+
/** Graduation threshold: once this much is raised, trading moves to Uniswap. */
|
|
69
77
|
withMaxRaise(maxRaise: bigint): this;
|
|
70
78
|
/**
|
|
71
79
|
* Share of the raise, in basis points, seeded into a Uniswap pool when the
|
|
@@ -73,7 +81,8 @@ declare class AuctionBuilder {
|
|
|
73
81
|
* 50%; must be between 20% and 100%.
|
|
74
82
|
*/
|
|
75
83
|
withLiquidity(liquidityBps: number): this;
|
|
76
|
-
|
|
84
|
+
/** Off-chain metadata for the token, such as its image (e.g. an IPFS URI). */
|
|
85
|
+
withMetadata(metadataURI: string): this;
|
|
77
86
|
build(): AuctionConfig;
|
|
78
87
|
}
|
|
79
88
|
|
|
@@ -91,6 +100,23 @@ declare class AuctionFlowSDK {
|
|
|
91
100
|
});
|
|
92
101
|
buildAuction(): AuctionBuilder;
|
|
93
102
|
createAuction(config: AuctionConfig): Promise<Hash>;
|
|
103
|
+
/**
|
|
104
|
+
* One-click launch: a token with the protocol's standard curve, threshold
|
|
105
|
+
* and liquidity share. Trading starts immediately.
|
|
106
|
+
*/
|
|
107
|
+
launch(name: string, symbol: string, metadataURI?: string): Promise<Hash>;
|
|
108
|
+
/**
|
|
109
|
+
* Sell `amount` tokens (in token wei) back to the curve before graduation.
|
|
110
|
+
* The contract reverts if the price fell below the bound before the
|
|
111
|
+
* transaction landed: pass `minProceeds` to set it exactly, or `slippageBps`
|
|
112
|
+
* to derive it from a fresh quote (default 100 = 1% below it).
|
|
113
|
+
*/
|
|
114
|
+
sellTokens(auctionId: bigint, amount: bigint, options?: {
|
|
115
|
+
minProceeds?: bigint;
|
|
116
|
+
slippageBps?: number;
|
|
117
|
+
}): Promise<Hash>;
|
|
118
|
+
/** What selling `amount` tokens back to the curve would pay right now. */
|
|
119
|
+
getSellQuote(auctionId: bigint, amount: bigint): Promise<SellQuote>;
|
|
94
120
|
/**
|
|
95
121
|
* Buy `amount` tokens (in token wei). The price rises with every purchase, so
|
|
96
122
|
* the contract takes a maximum total cost and reverts if the price moved past
|
|
@@ -138,7 +164,23 @@ declare const MIN_LIQUIDITY_BPS = 2000;
|
|
|
138
164
|
/** Liquidity share the builder uses when none is given (50%). */
|
|
139
165
|
declare const DEFAULT_LIQUIDITY_BPS = 5000;
|
|
140
166
|
|
|
167
|
+
/** Fixed-point scale of `basePrice`, `slope` and spot prices. */
|
|
168
|
+
declare const PRICE_SCALE: bigint;
|
|
169
|
+
/**
|
|
170
|
+
* A human-readable price per whole token, in curve units.
|
|
171
|
+
* `parseCurvePrice("0.01", 6)` is 0.01 USDC per token.
|
|
172
|
+
*/
|
|
173
|
+
declare function parseCurvePrice(price: string, paymentDecimals: number): bigint;
|
|
174
|
+
/** A curve price (e.g. from `getSpotPrice`) as a human-readable price per whole token. */
|
|
175
|
+
declare function formatCurvePrice(price: bigint, paymentDecimals: number): string;
|
|
141
176
|
declare function calculateBuyCost(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint): bigint;
|
|
177
|
+
/**
|
|
178
|
+
* Proceeds from selling `amount` tokens back to the curve when `currentSupply`
|
|
179
|
+
* are outstanding. Mirrors BondingCurve.calculateSellProceeds: the same
|
|
180
|
+
* integral as a purchase, but rounded down, so a round trip never profits.
|
|
181
|
+
*/
|
|
182
|
+
declare function calculateSellProceeds(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint): bigint;
|
|
183
|
+
/** Price of the next whole token, in curve units (payment units × 1e18). */
|
|
142
184
|
declare function spotPrice(currentSupply: bigint, basePrice: bigint, slope: bigint): bigint;
|
|
143
185
|
declare function calculateBuyQuote(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint, feeBps: bigint): {
|
|
144
186
|
cost: bigint;
|
|
@@ -146,7 +188,7 @@ declare function calculateBuyQuote(currentSupply: bigint, amount: bigint, basePr
|
|
|
146
188
|
total: bigint;
|
|
147
189
|
spotPriceAfter: bigint;
|
|
148
190
|
};
|
|
149
|
-
/** Default slippage tolerance for `buyTokens`, in basis points (100 = 1%). */
|
|
191
|
+
/** Default slippage tolerance for `buyTokens` and `sellTokens`, in basis points (100 = 1%). */
|
|
150
192
|
declare const DEFAULT_SLIPPAGE_BPS = 100;
|
|
151
193
|
/**
|
|
152
194
|
* Upper bound a buyer will accept for a quoted total, given a tolerance in
|
|
@@ -169,5 +211,10 @@ declare function fillPurchase(currentSupply: bigint, requested: bigint, basePric
|
|
|
169
211
|
cost: bigint;
|
|
170
212
|
fillsAuction: boolean;
|
|
171
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* Least a seller will accept for a quoted amount, given a tolerance in basis
|
|
216
|
+
* points. Rounds down so a tolerance never comes out tighter than asked.
|
|
217
|
+
*/
|
|
218
|
+
declare function applySellSlippage(netProceeds: bigint, slippageBps: number): bigint;
|
|
172
219
|
|
|
173
|
-
export { AUCTION_ADDRESSES, AuctionBuilder, type AuctionConfig, type AuctionData, AuctionFlowSDK, AuctionState, type BuyQuote, DEFAULT_LIQUIDITY_BPS, DEFAULT_SLIPPAGE_BPS, MIN_LIQUIDITY_BPS, type MigrationInfo, type SupportedChainId, type TransactionResult, USDC_ADDRESSES, applySlippage, calculateBuyCost, calculateBuyQuote, fillPurchase, maxBuyable, spotPrice };
|
|
220
|
+
export { AUCTION_ADDRESSES, AuctionBuilder, type AuctionConfig, type AuctionData, AuctionFlowSDK, AuctionState, type BuyQuote, DEFAULT_LIQUIDITY_BPS, DEFAULT_SLIPPAGE_BPS, MIN_LIQUIDITY_BPS, type MigrationInfo, PRICE_SCALE, type SellQuote, type SupportedChainId, type TransactionResult, USDC_ADDRESSES, applySellSlippage, applySlippage, calculateBuyCost, calculateBuyQuote, calculateSellProceeds, fillPurchase, formatCurvePrice, maxBuyable, parseCurvePrice, spotPrice };
|