auctionflow-sdk 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sodiq Agunbiade
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # auctionflow-sdk
2
+
3
+ Type-safe TypeScript SDK for the [AuctionFlow](https://github.com/Sodiq-123/AuctionFlow) bonding-curve token auction protocol, built on [viem](https://viem.sh).
4
+
5
+ Create auctions, buy tokens, and read on-chain state with a fluent builder API and off-chain price quotes that mirror the Solidity bonding-curve math exactly.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install auctionflow-sdk viem
11
+ # or
12
+ pnpm add auctionflow-sdk viem
13
+ ```
14
+
15
+ `viem` is a peer of everyday usage — you supply the wallet client.
16
+
17
+ ## Quick start
18
+
19
+ ```typescript
20
+ import { AuctionFlowSDK } from "auctionflow-sdk";
21
+ import { createWalletClient, http, parseUnits } from "viem";
22
+ import { privateKeyToAccount } from "viem/accounts";
23
+ import { baseSepolia } from "viem/chains";
24
+
25
+ const account = privateKeyToAccount("0x...");
26
+ const walletClient = createWalletClient({
27
+ account,
28
+ chain: baseSepolia,
29
+ transport: http("https://sepolia.base.org"),
30
+ });
31
+
32
+ const sdk = new AuctionFlowSDK({
33
+ chainId: 84532, // Base Sepolia
34
+ rpcUrl: "https://sepolia.base.org",
35
+ walletClient,
36
+ });
37
+ ```
38
+
39
+ ## Create an auction
40
+
41
+ The builder validates required fields and basic invariants (`startTime < endTime`,
42
+ positive `basePrice` / `maxSupply` / `maxRaise`) before producing a config.
43
+
44
+ ```typescript
45
+ const config = sdk
46
+ .buildAuction()
47
+ .withToken("MyToken", "MTK", parseUnits("1000000", 18))
48
+ .withPaymentToken("0x036CbD53842c5426634e7929541eC2318f3dCF7e") // USDC Sepolia
49
+ .withBondingCurve(
50
+ parseUnits("0.01", 6), // base price: 0.01 USDC
51
+ parseUnits("0.000001", 6) // slope
52
+ )
53
+ .withMaxRaise(parseUnits("50000", 6))
54
+ .withSchedule(
55
+ BigInt(Math.floor(Date.now() / 1000) + 3600),
56
+ BigInt(Math.floor(Date.now() / 1000) + 3600 * 72)
57
+ )
58
+ .build();
59
+
60
+ const hash = await sdk.createAuction(config);
61
+ ```
62
+
63
+ ## Buy tokens
64
+
65
+ ```typescript
66
+ const hash = await sdk.buyTokens(0n, parseUnits("1000", 18));
67
+ ```
68
+
69
+ ## Read state & quotes
70
+
71
+ ```typescript
72
+ // On-chain reads
73
+ const auction = await sdk.getAuction(0n);
74
+ const spot = await sdk.getSpotPrice(0n);
75
+
76
+ // Off-chain quote — no gas, mirrors BondingCurve.sol
77
+ const quote = await sdk.getQuote(0n, parseUnits("1000", 18));
78
+ console.log(quote.cost, quote.fee, quote.totalCost, quote.spotPriceAfter);
79
+ ```
80
+
81
+ The bonding-curve helpers are also exported directly for UI/preview use:
82
+
83
+ ```typescript
84
+ import { calculateBuyQuote, spotPrice } from "auctionflow-sdk";
85
+ ```
86
+
87
+ ## Withdraw proceeds
88
+
89
+ Once an auction reaches `COMPLETED` — either by hitting `maxRaise` or via
90
+ `completeAuction` after `endTime` — its creator claims the raised payment
91
+ tokens. Callable once, by the creator only.
92
+
93
+ ```typescript
94
+ if (!(await sdk.hasWithdrawnProceeds(0n))) {
95
+ const hash = await sdk.withdrawProceeds(0n);
96
+ }
97
+ ```
98
+
99
+ Protocol fees are routed to the fee recipient at buy time, so the amount paid
100
+ out is exactly the auction's `totalRaised`.
101
+
102
+ ## How the bonding curve works
103
+
104
+ Each auction uses a **linear bonding curve** — price rises as tokens are sold:
105
+
106
+ ```text
107
+ price = basePrice + slope × totalSold
108
+ ```
109
+
110
+ The cost to buy `n` tokens from current supply `s` is the integral:
111
+
112
+ ```text
113
+ cost = basePrice × n + slope × n × (2s + n) / 2
114
+ ```
115
+
116
+ Early buyers pay less; later buyers pay more.
117
+
118
+ ## Supported chains
119
+
120
+ | Chain | Chain ID | Status |
121
+ | --- | --- | --- |
122
+ | Base Sepolia | `84532` | Deployed |
123
+ | Base Mainnet | `8453` | Not yet deployed — the SDK throws on construction |
124
+
125
+ ## API
126
+
127
+ | Member | Description |
128
+ | --- | --- |
129
+ | `new AuctionFlowSDK({ chainId, rpcUrl, walletClient? })` | Construct against a supported chain. Throws if the chain has no deployment. |
130
+ | `buildAuction()` | Returns an `AuctionBuilder` (fluent config builder). |
131
+ | `createAuction(config)` | Send the `createAuction` transaction. Requires a wallet client. |
132
+ | `buyTokens(auctionId, amount)` | Send the `buyTokens` transaction. Requires a wallet client. |
133
+ | `getAuction(auctionId)` | Read the full auction struct. |
134
+ | `getSpotPrice(auctionId)` | Read the current on-chain spot price. |
135
+ | `getQuote(auctionId, amount)` | Off-chain cost + fee + post-trade spot price. |
136
+ | `withdrawProceeds(auctionId)` | Pay a completed auction's `totalRaised` to its creator. Creator-only, once. Requires a wallet client. |
137
+ | `hasWithdrawnProceeds(auctionId)` | Whether the creator has already claimed the proceeds. |
138
+
139
+ ## License
140
+
141
+ [MIT](https://github.com/Sodiq-123/AuctionFlow/blob/main/LICENSE) — Sodiq Agunbiade
@@ -0,0 +1,97 @@
1
+ import { Address, Hash, PublicClient, WalletClient } from 'viem';
2
+
3
+ declare enum AuctionState {
4
+ PENDING = 0,
5
+ ACTIVE = 1,
6
+ COMPLETED = 2,
7
+ MIGRATED = 3
8
+ }
9
+ interface AuctionConfig {
10
+ name: string;
11
+ symbol: string;
12
+ maxSupply: bigint;
13
+ paymentToken: Address;
14
+ basePrice: bigint;
15
+ slope: bigint;
16
+ maxRaise: bigint;
17
+ startTime: bigint;
18
+ endTime: bigint;
19
+ }
20
+ interface AuctionData {
21
+ id: bigint;
22
+ token: Address;
23
+ paymentToken: Address;
24
+ creator: Address;
25
+ basePrice: bigint;
26
+ slope: bigint;
27
+ maxRaise: bigint;
28
+ startTime: bigint;
29
+ endTime: bigint;
30
+ state: AuctionState;
31
+ totalRaised: bigint;
32
+ totalSold: bigint;
33
+ protocolFeeBps: bigint;
34
+ }
35
+ interface BuyQuote {
36
+ cost: bigint;
37
+ fee: bigint;
38
+ totalCost: bigint;
39
+ spotPriceAfter: bigint;
40
+ }
41
+ interface TransactionResult {
42
+ hash: Hash;
43
+ }
44
+ type SupportedChainId = 8453 | 84532;
45
+
46
+ declare class AuctionBuilder {
47
+ private config;
48
+ withToken(name: string, symbol: string, maxSupply: bigint): this;
49
+ withPaymentToken(address: Address): this;
50
+ withBondingCurve(basePrice: bigint, slope: bigint): this;
51
+ withMaxRaise(maxRaise: bigint): this;
52
+ withSchedule(startTime: bigint, endTime: bigint): this;
53
+ build(): AuctionConfig;
54
+ }
55
+
56
+ declare class AuctionFlowSDK {
57
+ readonly publicClient: PublicClient;
58
+ readonly walletClient?: WalletClient;
59
+ readonly auctionAddress: Address;
60
+ readonly chainId: SupportedChainId;
61
+ private readonly chain;
62
+ constructor(params: {
63
+ chainId: SupportedChainId;
64
+ rpcUrl: string;
65
+ walletClient?: WalletClient;
66
+ });
67
+ buildAuction(): AuctionBuilder;
68
+ createAuction(config: AuctionConfig): Promise<Hash>;
69
+ buyTokens(auctionId: bigint, amount: bigint): Promise<Hash>;
70
+ /**
71
+ * Withdraw a completed auction's raised payment tokens to its creator.
72
+ * Only the auction's creator can call this, and only once.
73
+ */
74
+ withdrawProceeds(auctionId: bigint): Promise<Hash>;
75
+ hasWithdrawnProceeds(auctionId: bigint): Promise<boolean>;
76
+ getAuction(auctionId: bigint): Promise<AuctionData>;
77
+ getQuote(auctionId: bigint, amount: bigint): Promise<BuyQuote>;
78
+ getSpotPrice(auctionId: bigint): Promise<bigint>;
79
+ private parseAuctionResult;
80
+ }
81
+
82
+ declare const AUCTION_ADDRESSES: Record<SupportedChainId, Address>;
83
+ declare const USDC_ADDRESSES: Record<SupportedChainId, Address>;
84
+
85
+ /**
86
+ * Off-chain bonding curve calculations (mirrors BondingCurve.sol)
87
+ */
88
+ declare function calculateBuyCost(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint): bigint;
89
+ declare function spotPrice(currentSupply: bigint, basePrice: bigint, slope: bigint): bigint;
90
+ declare function calculateBuyQuote(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint, feeBps: bigint): {
91
+ cost: bigint;
92
+ fee: bigint;
93
+ total: bigint;
94
+ spotPriceAfter: bigint;
95
+ };
96
+
97
+ export { AUCTION_ADDRESSES, AuctionBuilder, type AuctionConfig, type AuctionData, AuctionFlowSDK, AuctionState, type BuyQuote, type SupportedChainId, type TransactionResult, USDC_ADDRESSES, calculateBuyCost, calculateBuyQuote, spotPrice };
@@ -0,0 +1,97 @@
1
+ import { Address, Hash, PublicClient, WalletClient } from 'viem';
2
+
3
+ declare enum AuctionState {
4
+ PENDING = 0,
5
+ ACTIVE = 1,
6
+ COMPLETED = 2,
7
+ MIGRATED = 3
8
+ }
9
+ interface AuctionConfig {
10
+ name: string;
11
+ symbol: string;
12
+ maxSupply: bigint;
13
+ paymentToken: Address;
14
+ basePrice: bigint;
15
+ slope: bigint;
16
+ maxRaise: bigint;
17
+ startTime: bigint;
18
+ endTime: bigint;
19
+ }
20
+ interface AuctionData {
21
+ id: bigint;
22
+ token: Address;
23
+ paymentToken: Address;
24
+ creator: Address;
25
+ basePrice: bigint;
26
+ slope: bigint;
27
+ maxRaise: bigint;
28
+ startTime: bigint;
29
+ endTime: bigint;
30
+ state: AuctionState;
31
+ totalRaised: bigint;
32
+ totalSold: bigint;
33
+ protocolFeeBps: bigint;
34
+ }
35
+ interface BuyQuote {
36
+ cost: bigint;
37
+ fee: bigint;
38
+ totalCost: bigint;
39
+ spotPriceAfter: bigint;
40
+ }
41
+ interface TransactionResult {
42
+ hash: Hash;
43
+ }
44
+ type SupportedChainId = 8453 | 84532;
45
+
46
+ declare class AuctionBuilder {
47
+ private config;
48
+ withToken(name: string, symbol: string, maxSupply: bigint): this;
49
+ withPaymentToken(address: Address): this;
50
+ withBondingCurve(basePrice: bigint, slope: bigint): this;
51
+ withMaxRaise(maxRaise: bigint): this;
52
+ withSchedule(startTime: bigint, endTime: bigint): this;
53
+ build(): AuctionConfig;
54
+ }
55
+
56
+ declare class AuctionFlowSDK {
57
+ readonly publicClient: PublicClient;
58
+ readonly walletClient?: WalletClient;
59
+ readonly auctionAddress: Address;
60
+ readonly chainId: SupportedChainId;
61
+ private readonly chain;
62
+ constructor(params: {
63
+ chainId: SupportedChainId;
64
+ rpcUrl: string;
65
+ walletClient?: WalletClient;
66
+ });
67
+ buildAuction(): AuctionBuilder;
68
+ createAuction(config: AuctionConfig): Promise<Hash>;
69
+ buyTokens(auctionId: bigint, amount: bigint): Promise<Hash>;
70
+ /**
71
+ * Withdraw a completed auction's raised payment tokens to its creator.
72
+ * Only the auction's creator can call this, and only once.
73
+ */
74
+ withdrawProceeds(auctionId: bigint): Promise<Hash>;
75
+ hasWithdrawnProceeds(auctionId: bigint): Promise<boolean>;
76
+ getAuction(auctionId: bigint): Promise<AuctionData>;
77
+ getQuote(auctionId: bigint, amount: bigint): Promise<BuyQuote>;
78
+ getSpotPrice(auctionId: bigint): Promise<bigint>;
79
+ private parseAuctionResult;
80
+ }
81
+
82
+ declare const AUCTION_ADDRESSES: Record<SupportedChainId, Address>;
83
+ declare const USDC_ADDRESSES: Record<SupportedChainId, Address>;
84
+
85
+ /**
86
+ * Off-chain bonding curve calculations (mirrors BondingCurve.sol)
87
+ */
88
+ declare function calculateBuyCost(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint): bigint;
89
+ declare function spotPrice(currentSupply: bigint, basePrice: bigint, slope: bigint): bigint;
90
+ declare function calculateBuyQuote(currentSupply: bigint, amount: bigint, basePrice: bigint, slope: bigint, feeBps: bigint): {
91
+ cost: bigint;
92
+ fee: bigint;
93
+ total: bigint;
94
+ spotPriceAfter: bigint;
95
+ };
96
+
97
+ export { AUCTION_ADDRESSES, AuctionBuilder, type AuctionConfig, type AuctionData, AuctionFlowSDK, AuctionState, type BuyQuote, type SupportedChainId, type TransactionResult, USDC_ADDRESSES, calculateBuyCost, calculateBuyQuote, spotPrice };