@hammerock/cca-sdk 0.1.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 +21 -0
- package/README.md +145 -0
- package/dist/chunk-ABCX23D6.js +446 -0
- package/dist/chunk-ABCX23D6.js.map +1 -0
- package/dist/erc20-C3yff839.d.cts +231 -0
- package/dist/erc20-C3yff839.d.ts +231 -0
- package/dist/index.cjs +998 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2717 -0
- package/dist/index.d.ts +2717 -0
- package/dist/index.js +485 -0
- package/dist/index.js.map +1 -0
- package/dist/node.cjs +448 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +97 -0
- package/dist/node.d.ts +97 -0
- package/dist/node.js +277 -0
- package/dist/node.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { PublicClient, Chain, Address, Hex } from 'viem';
|
|
2
|
+
|
|
3
|
+
interface BeaconClientConfig {
|
|
4
|
+
/** JSON-RPC endpoint used for state reads (eth_call, multicall). */
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
/**
|
|
7
|
+
* Optional separate endpoint for `eth_getLogs`.
|
|
8
|
+
*
|
|
9
|
+
* State reads and log scanning have different provider requirements, and one
|
|
10
|
+
* endpoint is often bad at one of them. Alchemy's free tier serves eth_call
|
|
11
|
+
* beautifully but caps eth_getLogs at a 10-block range, which makes a
|
|
12
|
+
* historical backfill impossible; public wide-range endpoints allow the range
|
|
13
|
+
* but can silently return empty results. Defaults to `rpcUrl`.
|
|
14
|
+
*/
|
|
15
|
+
logsRpcUrl?: string;
|
|
16
|
+
/** Chain id. Must be a supported testnet - mainnet is rejected. */
|
|
17
|
+
chainId: number;
|
|
18
|
+
/** Override the factory address. Defaults to the cross-chain singleton. */
|
|
19
|
+
factoryAddress?: Address;
|
|
20
|
+
/**
|
|
21
|
+
* Address of a deployed `AuctionStateLens`.
|
|
22
|
+
*
|
|
23
|
+
* Optional. When omitted, reads run the lens via an `eth_call` state
|
|
24
|
+
* override instead, so no deployment is required. See `read.ts`.
|
|
25
|
+
*/
|
|
26
|
+
lensAddress?: Address;
|
|
27
|
+
/** Override the block the factory was deployed at. */
|
|
28
|
+
factoryDeployBlock?: bigint;
|
|
29
|
+
}
|
|
30
|
+
interface BeaconClient {
|
|
31
|
+
publicClient: PublicClient;
|
|
32
|
+
/** Client used for `eth_getLogs`. Same as `publicClient` unless overridden. */
|
|
33
|
+
logsClient: PublicClient;
|
|
34
|
+
chain: Chain;
|
|
35
|
+
chainId: number;
|
|
36
|
+
factoryAddress: Address;
|
|
37
|
+
lensAddress?: Address;
|
|
38
|
+
factoryDeployBlock: bigint;
|
|
39
|
+
/** Approximate seconds per block, for time-remaining estimates. */
|
|
40
|
+
blockTimeSeconds: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Throw unless `chainId` is a testnet Beacon supports.
|
|
44
|
+
*
|
|
45
|
+
* This is the choke point that keeps every Beacon surface off mainnet. The
|
|
46
|
+
* bidding agent layers its own guard on top before it broadcasts anything.
|
|
47
|
+
*/
|
|
48
|
+
declare function assertSupportedChain(chainId: number): Chain;
|
|
49
|
+
/** Build a Beacon client. Throws immediately on a non-testnet chain id. */
|
|
50
|
+
declare function createBeaconClient(config: BeaconClientConfig): BeaconClient;
|
|
51
|
+
/**
|
|
52
|
+
* Confirm the RPC is actually serving the chain we were configured for.
|
|
53
|
+
*
|
|
54
|
+
* Cheap insurance against a copy-pasted RPC URL silently pointing at the wrong
|
|
55
|
+
* network - which otherwise shows up as "no auctions found".
|
|
56
|
+
*/
|
|
57
|
+
declare function assertChainMatches(client: BeaconClient): Promise<void>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Types mirrored from Uniswap/continuous-clearing-auction @ v1.1.0.
|
|
61
|
+
*
|
|
62
|
+
* Field names follow the contracts, with an explicit `Q96` / `X7` suffix added
|
|
63
|
+
* where the contract encodes a fixed-point value, so callers cannot mistake a
|
|
64
|
+
* Q96 price for a plain integer. Use the helpers in `q96.ts` to convert.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A checkpoint of auction state at a given block.
|
|
69
|
+
* Mirrors `struct Checkpoint` in `libraries/CheckpointLib.sol`.
|
|
70
|
+
*/
|
|
71
|
+
interface Checkpoint {
|
|
72
|
+
/** Price the auction is currently clearing at, Q96-encoded. */
|
|
73
|
+
clearingPriceQ96: bigint;
|
|
74
|
+
/** Currency raised so far at the clearing price. Q96, then X7-scaled. */
|
|
75
|
+
currencyRaisedAtClearingPriceQ96X7: bigint;
|
|
76
|
+
/** Running sum of the ratio between mps and price. */
|
|
77
|
+
cumulativeMpsPerPrice: bigint;
|
|
78
|
+
/**
|
|
79
|
+
* How much of the auction's supply SCHEDULE has been released so far, in
|
|
80
|
+
* milli-bips out of `MPS` (1e7).
|
|
81
|
+
*
|
|
82
|
+
* This is emphatically NOT "tokens sold": an auction that ended with zero
|
|
83
|
+
* bids still reports `cumulativeMps == MPS`, because the schedule fully
|
|
84
|
+
* elapsed. Use `totalCleared` / `currencyRaised` for what actually sold.
|
|
85
|
+
*/
|
|
86
|
+
cumulativeMps: number;
|
|
87
|
+
/** Block number of the previous checkpoint. */
|
|
88
|
+
prevBlock: bigint;
|
|
89
|
+
/** Block number of the next checkpoint. */
|
|
90
|
+
nextBlock: bigint;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The auction's live state.
|
|
94
|
+
* Mirrors `struct AuctionState` returned by `AuctionStateLens.state()`.
|
|
95
|
+
*/
|
|
96
|
+
interface AuctionState {
|
|
97
|
+
checkpoint: Checkpoint;
|
|
98
|
+
/** Total currency raised, in the currency's smallest unit. */
|
|
99
|
+
currencyRaised: bigint;
|
|
100
|
+
/** Total token supply cleared so far, in the token's smallest unit. */
|
|
101
|
+
totalCleared: bigint;
|
|
102
|
+
/** Whether the auction raised enough to seed the pool. */
|
|
103
|
+
isGraduated: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Immutable-ish configuration of an auction, read once and safe to cache.
|
|
107
|
+
*/
|
|
108
|
+
interface AuctionInfo {
|
|
109
|
+
auction: Address;
|
|
110
|
+
/** The token being sold. */
|
|
111
|
+
token: Address;
|
|
112
|
+
/** The currency bids are denominated in. `address(0)` means native ETH. */
|
|
113
|
+
currency: Address;
|
|
114
|
+
/** Total token supply offered by the auction. */
|
|
115
|
+
totalSupply: bigint;
|
|
116
|
+
/** Block the auction opens for bids. */
|
|
117
|
+
startBlock: bigint;
|
|
118
|
+
/** Block the auction closes. */
|
|
119
|
+
endBlock: bigint;
|
|
120
|
+
/** Lowest price the auction will clear at, Q96-encoded. */
|
|
121
|
+
floorPriceQ96: bigint;
|
|
122
|
+
/** Spacing between initialised price ticks. */
|
|
123
|
+
tickSpacing: bigint;
|
|
124
|
+
}
|
|
125
|
+
/** Lifecycle position of an auction relative to the current block. */
|
|
126
|
+
type AuctionStatus = "pending" | "live" | "ended";
|
|
127
|
+
/**
|
|
128
|
+
* Everything a UI needs about one auction: static config, live state, and the
|
|
129
|
+
* derived values that would otherwise be recomputed in four places.
|
|
130
|
+
*/
|
|
131
|
+
interface AuctionSummary {
|
|
132
|
+
info: AuctionInfo;
|
|
133
|
+
state: AuctionState;
|
|
134
|
+
/** Block this summary was read at. */
|
|
135
|
+
blockNumber: bigint;
|
|
136
|
+
status: AuctionStatus;
|
|
137
|
+
/** Clearing price as a display string. */
|
|
138
|
+
clearingPrice: string;
|
|
139
|
+
/**
|
|
140
|
+
* Fraction of the supply schedule released so far, in [0, 1].
|
|
141
|
+
* Not the fraction sold - see `Checkpoint.cumulativeMps`.
|
|
142
|
+
*/
|
|
143
|
+
supplyScheduleProgress: number;
|
|
144
|
+
/** Whether anything has actually cleared. `totalCleared > 0`. */
|
|
145
|
+
hasClearedSupply: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Blocks until the auction ends. `0n` once ended, and counts down to the
|
|
148
|
+
* START block while the auction is still pending.
|
|
149
|
+
*/
|
|
150
|
+
blocksRemaining: bigint;
|
|
151
|
+
/** Estimated seconds remaining, from `blocksRemaining` and the chain's block time. */
|
|
152
|
+
secondsRemaining: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* One `AuctionCreated` event from the factory.
|
|
156
|
+
* Mirrors `event AuctionCreated(address indexed auction, address indexed token, uint256 amount, bytes configData)`.
|
|
157
|
+
*/
|
|
158
|
+
interface DiscoveredAuction {
|
|
159
|
+
/** The newly created ContinuousClearingAuction. */
|
|
160
|
+
auction: Address;
|
|
161
|
+
/** The token being auctioned. */
|
|
162
|
+
token: Address;
|
|
163
|
+
/** Token amount supplied to the auction. */
|
|
164
|
+
amount: bigint;
|
|
165
|
+
/** ABI-encoded `AuctionParameters` the auction was configured with. */
|
|
166
|
+
configData: Hex;
|
|
167
|
+
blockNumber: bigint;
|
|
168
|
+
transactionHash: Hex;
|
|
169
|
+
logIndex: number;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** ERC-20 reads Beacon needs. Hand-written because it is the standard, not a CCA ABI. */
|
|
173
|
+
declare const erc20MetadataAbi: readonly [{
|
|
174
|
+
readonly type: "function";
|
|
175
|
+
readonly name: "symbol";
|
|
176
|
+
readonly inputs: readonly [];
|
|
177
|
+
readonly outputs: readonly [{
|
|
178
|
+
readonly type: "string";
|
|
179
|
+
}];
|
|
180
|
+
readonly stateMutability: "view";
|
|
181
|
+
}, {
|
|
182
|
+
readonly type: "function";
|
|
183
|
+
readonly name: "name";
|
|
184
|
+
readonly inputs: readonly [];
|
|
185
|
+
readonly outputs: readonly [{
|
|
186
|
+
readonly type: "string";
|
|
187
|
+
}];
|
|
188
|
+
readonly stateMutability: "view";
|
|
189
|
+
}, {
|
|
190
|
+
readonly type: "function";
|
|
191
|
+
readonly name: "decimals";
|
|
192
|
+
readonly inputs: readonly [];
|
|
193
|
+
readonly outputs: readonly [{
|
|
194
|
+
readonly type: "uint8";
|
|
195
|
+
}];
|
|
196
|
+
readonly stateMutability: "view";
|
|
197
|
+
}];
|
|
198
|
+
interface TokenMetadata {
|
|
199
|
+
address: Address;
|
|
200
|
+
symbol: string;
|
|
201
|
+
name: string;
|
|
202
|
+
decimals: number;
|
|
203
|
+
/** True when this is the chain's native currency rather than an ERC-20. */
|
|
204
|
+
isNative: boolean;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Read a currency's symbol, name and decimals.
|
|
208
|
+
*
|
|
209
|
+
* `address(0)` is the CCA sentinel for native currency, and resolves to the
|
|
210
|
+
* chain's own native currency rather than an on-chain call.
|
|
211
|
+
*
|
|
212
|
+
* Tolerant by design: a token that omits `symbol`/`name` (or returns bytes32
|
|
213
|
+
* instead of string) still yields usable metadata rather than throwing, because
|
|
214
|
+
* failing to render an alert is worse than rendering a shortened address.
|
|
215
|
+
*/
|
|
216
|
+
declare function getTokenMetadata(client: BeaconClient, address: Address): Promise<TokenMetadata>;
|
|
217
|
+
/** Read metadata for several currencies at once, de-duplicated by address. */
|
|
218
|
+
declare function getTokenMetadataBatch(client: BeaconClient, addresses: readonly Address[]): Promise<Map<Address, TokenMetadata>>;
|
|
219
|
+
/**
|
|
220
|
+
* Render a raw token amount with its symbol, e.g. `"1,000 BEACON"`.
|
|
221
|
+
*
|
|
222
|
+
* A nonzero amount is NEVER rendered as "0". Real CCA test auctions raise
|
|
223
|
+
* amounts like 52 wei, and truncating those to "0 ETH" makes a live auction
|
|
224
|
+
* look dead. When an amount is too small for `maxFractionDigits`, the output
|
|
225
|
+
* widens to show four significant digits instead.
|
|
226
|
+
*
|
|
227
|
+
* @param maxFractionDigits Fractional digits to keep for ordinary amounts.
|
|
228
|
+
*/
|
|
229
|
+
declare function formatTokenAmount(amount: bigint, token: Pick<TokenMetadata, "symbol" | "decimals">, maxFractionDigits?: number): string;
|
|
230
|
+
|
|
231
|
+
export { type AuctionInfo as A, type BeaconClient as B, type Checkpoint as C, type DiscoveredAuction as D, type TokenMetadata as T, type AuctionStatus as a, type AuctionState as b, type AuctionSummary as c, type BeaconClientConfig as d, assertChainMatches as e, assertSupportedChain as f, createBeaconClient as g, erc20MetadataAbi as h, formatTokenAmount as i, getTokenMetadata as j, getTokenMetadataBatch as k };
|