@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/dist/node.cjs ADDED
@@ -0,0 +1,448 @@
1
+ 'use strict';
2
+
3
+ var viem = require('viem');
4
+ var chains = require('viem/chains');
5
+ var promises = require('fs/promises');
6
+ var path = require('path');
7
+
8
+ // src/erc20.ts
9
+ ({
10
+ [chains.sepolia.id]: 10130119n
11
+ });
12
+ ({
13
+ [chains.sepolia.id]: chains.sepolia,
14
+ [chains.baseSepolia.id]: chains.baseSepolia,
15
+ [chains.unichainSepolia.id]: chains.unichainSepolia
16
+ });
17
+ ({
18
+ [chains.sepolia.id]: 12,
19
+ [chains.baseSepolia.id]: 2,
20
+ [chains.unichainSepolia.id]: 1
21
+ });
22
+ var DEFAULT_LOG_CHUNK_SIZE = 50000n;
23
+ var NATIVE_CURRENCY = "0x0000000000000000000000000000000000000000";
24
+
25
+ // src/erc20.ts
26
+ var erc20MetadataAbi = [
27
+ { type: "function", name: "symbol", inputs: [], outputs: [{ type: "string" }], stateMutability: "view" },
28
+ { type: "function", name: "name", inputs: [], outputs: [{ type: "string" }], stateMutability: "view" },
29
+ { type: "function", name: "decimals", inputs: [], outputs: [{ type: "uint8" }], stateMutability: "view" }
30
+ ];
31
+ async function getTokenMetadata(client, address) {
32
+ if (address === NATIVE_CURRENCY) {
33
+ const native = client.chain.nativeCurrency;
34
+ return {
35
+ address,
36
+ symbol: native.symbol,
37
+ name: native.name,
38
+ decimals: native.decimals,
39
+ isNative: true
40
+ };
41
+ }
42
+ const contract = { address, abi: erc20MetadataAbi };
43
+ const [symbol, name, decimals] = await client.publicClient.multicall({
44
+ allowFailure: true,
45
+ contracts: [
46
+ { ...contract, functionName: "symbol" },
47
+ { ...contract, functionName: "name" },
48
+ { ...contract, functionName: "decimals" }
49
+ ]
50
+ });
51
+ return {
52
+ address,
53
+ symbol: symbol.status === "success" ? symbol.result : shortAddress(address),
54
+ name: name.status === "success" ? name.result : shortAddress(address),
55
+ // 18 is the overwhelmingly common default; better than refusing to render.
56
+ decimals: decimals.status === "success" ? Number(decimals.result) : 18,
57
+ isNative: false
58
+ };
59
+ }
60
+ function shortAddress(address) {
61
+ return `${address.slice(0, 6)}...${address.slice(-4)}`;
62
+ }
63
+
64
+ // src/abis/auction.ts
65
+ var auctionAbi = [{ "type": "constructor", "inputs": [{ "name": "_token", "type": "address", "internalType": "address" }, { "name": "_totalSupply", "type": "uint128", "internalType": "uint128" }, { "name": "_parameters", "type": "tuple", "internalType": "struct AuctionParameters", "components": [{ "name": "currency", "type": "address", "internalType": "address" }, { "name": "tokensRecipient", "type": "address", "internalType": "address" }, { "name": "fundsRecipient", "type": "address", "internalType": "address" }, { "name": "startBlock", "type": "uint64", "internalType": "uint64" }, { "name": "endBlock", "type": "uint64", "internalType": "uint64" }, { "name": "claimBlock", "type": "uint64", "internalType": "uint64" }, { "name": "tickSpacing", "type": "uint256", "internalType": "uint256" }, { "name": "validationHook", "type": "address", "internalType": "address" }, { "name": "floorPrice", "type": "uint256", "internalType": "uint256" }, { "name": "requiredCurrencyRaised", "type": "uint128", "internalType": "uint128" }, { "name": "auctionStepsData", "type": "bytes", "internalType": "bytes" }] }], "stateMutability": "nonpayable" }, { "type": "function", "name": "MAX_BID_PRICE", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "MAX_BLOCK_NUMBER", "inputs": [], "outputs": [{ "name": "", "type": "uint64", "internalType": "uint64" }], "stateMutability": "view" }, { "type": "function", "name": "MAX_TICK_PTR", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "bids", "inputs": [{ "name": "bidId", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "tuple", "internalType": "struct Bid", "components": [{ "name": "startBlock", "type": "uint64", "internalType": "uint64" }, { "name": "startCumulativeMps", "type": "uint24", "internalType": "uint24" }, { "name": "exitedBlock", "type": "uint64", "internalType": "uint64" }, { "name": "maxPrice", "type": "uint256", "internalType": "uint256" }, { "name": "owner", "type": "address", "internalType": "address" }, { "name": "amountQ96", "type": "uint256", "internalType": "uint256" }, { "name": "tokensFilled", "type": "uint256", "internalType": "uint256" }] }], "stateMutability": "view" }, { "type": "function", "name": "checkpoint", "inputs": [], "outputs": [{ "name": "", "type": "tuple", "internalType": "struct Checkpoint", "components": [{ "name": "clearingPrice", "type": "uint256", "internalType": "uint256" }, { "name": "currencyRaisedAtClearingPriceQ96_X7", "type": "uint256", "internalType": "ValueX7" }, { "name": "cumulativeMpsPerPrice", "type": "uint256", "internalType": "uint256" }, { "name": "cumulativeMps", "type": "uint24", "internalType": "uint24" }, { "name": "prev", "type": "uint64", "internalType": "uint64" }, { "name": "next", "type": "uint64", "internalType": "uint64" }] }], "stateMutability": "nonpayable" }, { "type": "function", "name": "checkpoints", "inputs": [{ "name": "blockNumber", "type": "uint64", "internalType": "uint64" }], "outputs": [{ "name": "", "type": "tuple", "internalType": "struct Checkpoint", "components": [{ "name": "clearingPrice", "type": "uint256", "internalType": "uint256" }, { "name": "currencyRaisedAtClearingPriceQ96_X7", "type": "uint256", "internalType": "ValueX7" }, { "name": "cumulativeMpsPerPrice", "type": "uint256", "internalType": "uint256" }, { "name": "cumulativeMps", "type": "uint24", "internalType": "uint24" }, { "name": "prev", "type": "uint64", "internalType": "uint64" }, { "name": "next", "type": "uint64", "internalType": "uint64" }] }], "stateMutability": "view" }, { "type": "function", "name": "claimBlock", "inputs": [], "outputs": [{ "name": "", "type": "uint64", "internalType": "uint64" }], "stateMutability": "view" }, { "type": "function", "name": "claimTokens", "inputs": [{ "name": "_bidId", "type": "uint256", "internalType": "uint256" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "claimTokensBatch", "inputs": [{ "name": "_owner", "type": "address", "internalType": "address" }, { "name": "_bidIds", "type": "uint256[]", "internalType": "uint256[]" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "clearingPrice", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "currency", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "currencyRaised", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "currencyRaisedQ96_X7", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "ValueX7" }], "stateMutability": "view" }, { "type": "function", "name": "endBlock", "inputs": [], "outputs": [{ "name": "", "type": "uint64", "internalType": "uint64" }], "stateMutability": "view" }, { "type": "function", "name": "exitBid", "inputs": [{ "name": "_bidId", "type": "uint256", "internalType": "uint256" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "exitPartiallyFilledBid", "inputs": [{ "name": "_bidId", "type": "uint256", "internalType": "uint256" }, { "name": "_lastFullyFilledCheckpointBlock", "type": "uint64", "internalType": "uint64" }, { "name": "_outbidBlock", "type": "uint64", "internalType": "uint64" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "floorPrice", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "forceIterateOverTicks", "inputs": [{ "name": "_untilTickPrice", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "nonpayable" }, { "type": "function", "name": "fundsRecipient", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "isGraduated", "inputs": [], "outputs": [{ "name": "", "type": "bool", "internalType": "bool" }], "stateMutability": "view" }, { "type": "function", "name": "lastCheckpointedBlock", "inputs": [], "outputs": [{ "name": "", "type": "uint64", "internalType": "uint64" }], "stateMutability": "view" }, { "type": "function", "name": "latestCheckpoint", "inputs": [], "outputs": [{ "name": "", "type": "tuple", "internalType": "struct Checkpoint", "components": [{ "name": "clearingPrice", "type": "uint256", "internalType": "uint256" }, { "name": "currencyRaisedAtClearingPriceQ96_X7", "type": "uint256", "internalType": "ValueX7" }, { "name": "cumulativeMpsPerPrice", "type": "uint256", "internalType": "uint256" }, { "name": "cumulativeMps", "type": "uint24", "internalType": "uint24" }, { "name": "prev", "type": "uint64", "internalType": "uint64" }, { "name": "next", "type": "uint64", "internalType": "uint64" }] }], "stateMutability": "view" }, { "type": "function", "name": "lbpInitializationParams", "inputs": [], "outputs": [{ "name": "params", "type": "tuple", "internalType": "struct LBPInitializationParams", "components": [{ "name": "initialPriceX96", "type": "uint256", "internalType": "uint256" }, { "name": "tokensSold", "type": "uint256", "internalType": "uint256" }, { "name": "currencyRaised", "type": "uint256", "internalType": "uint256" }] }], "stateMutability": "view" }, { "type": "function", "name": "nextActiveTickPrice", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "nextBidId", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "onTokensReceived", "inputs": [], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "pointer", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "startBlock", "inputs": [], "outputs": [{ "name": "", "type": "uint64", "internalType": "uint64" }], "stateMutability": "view" }, { "type": "function", "name": "step", "inputs": [], "outputs": [{ "name": "", "type": "tuple", "internalType": "struct AuctionStep", "components": [{ "name": "mps", "type": "uint24", "internalType": "uint24" }, { "name": "startBlock", "type": "uint64", "internalType": "uint64" }, { "name": "endBlock", "type": "uint64", "internalType": "uint64" }] }], "stateMutability": "view" }, { "type": "function", "name": "submitBid", "inputs": [{ "name": "_maxPrice", "type": "uint256", "internalType": "uint256" }, { "name": "_amount", "type": "uint128", "internalType": "uint128" }, { "name": "_owner", "type": "address", "internalType": "address" }, { "name": "_hookData", "type": "bytes", "internalType": "bytes" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "payable" }, { "type": "function", "name": "submitBid", "inputs": [{ "name": "_maxPrice", "type": "uint256", "internalType": "uint256" }, { "name": "_amount", "type": "uint128", "internalType": "uint128" }, { "name": "_owner", "type": "address", "internalType": "address" }, { "name": "_prevTickPrice", "type": "uint256", "internalType": "uint256" }, { "name": "_hookData", "type": "bytes", "internalType": "bytes" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "payable" }, { "type": "function", "name": "sumCurrencyDemandAboveClearingQ96", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "supportsInterface", "inputs": [{ "name": "interfaceId", "type": "bytes4", "internalType": "bytes4" }], "outputs": [{ "name": "", "type": "bool", "internalType": "bool" }], "stateMutability": "pure" }, { "type": "function", "name": "sweepCurrency", "inputs": [], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "sweepCurrencyBlock", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "sweepUnsoldTokens", "inputs": [], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "sweepUnsoldTokensBlock", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "tickSpacing", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "ticks", "inputs": [{ "name": "price", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "tuple", "internalType": "struct Tick", "components": [{ "name": "next", "type": "uint256", "internalType": "uint256" }, { "name": "currencyDemandQ96", "type": "uint256", "internalType": "uint256" }] }], "stateMutability": "view" }, { "type": "function", "name": "token", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "tokensRecipient", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "totalCleared", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "totalClearedQ96_X7", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "ValueX7" }], "stateMutability": "view" }, { "type": "function", "name": "totalSupply", "inputs": [], "outputs": [{ "name": "", "type": "uint128", "internalType": "uint128" }], "stateMutability": "view" }, { "type": "function", "name": "validationHook", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "contract IValidationHook" }], "stateMutability": "view" }, { "type": "event", "name": "AuctionStepRecorded", "inputs": [{ "name": "startBlock", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "endBlock", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "mps", "type": "uint24", "indexed": false, "internalType": "uint24" }], "anonymous": false }, { "type": "event", "name": "BidExited", "inputs": [{ "name": "bidId", "type": "uint256", "indexed": true, "internalType": "uint256" }, { "name": "owner", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokensFilled", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "currencyRefunded", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "BidSubmitted", "inputs": [{ "name": "id", "type": "uint256", "indexed": true, "internalType": "uint256" }, { "name": "owner", "type": "address", "indexed": true, "internalType": "address" }, { "name": "price", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "amount", "type": "uint128", "indexed": false, "internalType": "uint128" }], "anonymous": false }, { "type": "event", "name": "CheckpointUpdated", "inputs": [{ "name": "blockNumber", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "clearingPrice", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "cumulativeMps", "type": "uint24", "indexed": false, "internalType": "uint24" }], "anonymous": false }, { "type": "event", "name": "ClearingPriceUpdated", "inputs": [{ "name": "blockNumber", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "clearingPrice", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "CurrencySwept", "inputs": [{ "name": "fundsRecipient", "type": "address", "indexed": true, "internalType": "address" }, { "name": "currencyAmount", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "NextActiveTickUpdated", "inputs": [{ "name": "price", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "TickInitialized", "inputs": [{ "name": "price", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "TokensClaimed", "inputs": [{ "name": "bidId", "type": "uint256", "indexed": true, "internalType": "uint256" }, { "name": "owner", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokensFilled", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "TokensReceived", "inputs": [{ "name": "totalSupply", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "TokensSwept", "inputs": [{ "name": "tokensRecipient", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokensAmount", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "error", "name": "AuctionIsNotFinalized", "inputs": [] }, { "type": "error", "name": "AuctionIsNotOver", "inputs": [] }, { "type": "error", "name": "AuctionIsOver", "inputs": [] }, { "type": "error", "name": "AuctionNotStarted", "inputs": [] }, { "type": "error", "name": "AuctionSoldOut", "inputs": [] }, { "type": "error", "name": "BatchClaimDifferentOwner", "inputs": [{ "name": "expectedOwner", "type": "address", "internalType": "address" }, { "name": "receivedOwner", "type": "address", "internalType": "address" }] }, { "type": "error", "name": "BidAlreadyExited", "inputs": [] }, { "type": "error", "name": "BidAmountTooSmall", "inputs": [] }, { "type": "error", "name": "BidIdDoesNotExist", "inputs": [{ "name": "bidId", "type": "uint256", "internalType": "uint256" }] }, { "type": "error", "name": "BidMustBeAboveClearingPrice", "inputs": [] }, { "type": "error", "name": "BidNotExited", "inputs": [] }, { "type": "error", "name": "BidOwnerCannotBeZeroAddress", "inputs": [] }, { "type": "error", "name": "CannotExitBid", "inputs": [] }, { "type": "error", "name": "CannotPartiallyExitBidBeforeEndBlock", "inputs": [] }, { "type": "error", "name": "CannotPartiallyExitBidBeforeGraduation", "inputs": [] }, { "type": "error", "name": "CannotSweepCurrency", "inputs": [] }, { "type": "error", "name": "CannotSweepTokens", "inputs": [] }, { "type": "error", "name": "CannotUpdateUninitializedTick", "inputs": [] }, { "type": "error", "name": "CheckpointBlockNotIncreasing", "inputs": [] }, { "type": "error", "name": "ClaimBlockIsBeforeEndBlock", "inputs": [] }, { "type": "error", "name": "CurrencyIsNotNative", "inputs": [] }, { "type": "error", "name": "ERC20TransferFailed", "inputs": [] }, { "type": "error", "name": "FloorPriceAndTickSpacingGreaterThanMaxBidPrice", "inputs": [{ "name": "nextTick", "type": "uint256", "internalType": "uint256" }, { "name": "maxBidPrice", "type": "uint256", "internalType": "uint256" }] }, { "type": "error", "name": "FloorPriceAndTickSpacingTooLarge", "inputs": [] }, { "type": "error", "name": "FloorPriceIsZero", "inputs": [] }, { "type": "error", "name": "FloorPriceTooLow", "inputs": [] }, { "type": "error", "name": "FundsRecipientIsZero", "inputs": [] }, { "type": "error", "name": "InvalidAmount", "inputs": [] }, { "type": "error", "name": "InvalidAuctionDataLength", "inputs": [] }, { "type": "error", "name": "InvalidBidPriceTooHigh", "inputs": [{ "name": "maxPrice", "type": "uint256", "internalType": "uint256" }, { "name": "maxBidPrice", "type": "uint256", "internalType": "uint256" }] }, { "type": "error", "name": "InvalidBidUnableToClear", "inputs": [] }, { "type": "error", "name": "InvalidEndBlock", "inputs": [] }, { "type": "error", "name": "InvalidEndBlockGivenStepData", "inputs": [{ "name": "actualEndBlock", "type": "uint64", "internalType": "uint64" }, { "name": "expectedEndBlock", "type": "uint64", "internalType": "uint64" }] }, { "type": "error", "name": "InvalidLastFullyFilledCheckpointHint", "inputs": [] }, { "type": "error", "name": "InvalidOutbidBlockCheckpointHint", "inputs": [] }, { "type": "error", "name": "InvalidStepDataMps", "inputs": [{ "name": "actualMps", "type": "uint256", "internalType": "uint256" }, { "name": "expectedMps", "type": "uint256", "internalType": "uint256" }] }, { "type": "error", "name": "InvalidTickPrice", "inputs": [] }, { "type": "error", "name": "InvalidTokenAmountReceived", "inputs": [] }, { "type": "error", "name": "MpsRemainingIsZero", "inputs": [] }, { "type": "error", "name": "NativeTransferFailed", "inputs": [] }, { "type": "error", "name": "NotClaimable", "inputs": [] }, { "type": "error", "name": "NotGraduated", "inputs": [] }, { "type": "error", "name": "Reentrancy", "inputs": [] }, { "type": "error", "name": "StepBlockDeltaCannotBeZero", "inputs": [] }, { "type": "error", "name": "StepLib__InvalidOffsetNotAtStepBoundary", "inputs": [] }, { "type": "error", "name": "StepLib__InvalidOffsetTooLarge", "inputs": [] }, { "type": "error", "name": "TickHintMustBeGreaterThanNextActiveTickPrice", "inputs": [{ "name": "tickPrice", "type": "uint256", "internalType": "uint256" }, { "name": "nextActiveTickPrice", "type": "uint256", "internalType": "uint256" }] }, { "type": "error", "name": "TickNotInitialized", "inputs": [] }, { "type": "error", "name": "TickPreviousPriceInvalid", "inputs": [] }, { "type": "error", "name": "TickPriceNotAtBoundary", "inputs": [] }, { "type": "error", "name": "TickPriceNotIncreasing", "inputs": [] }, { "type": "error", "name": "TickSpacingTooSmall", "inputs": [] }, { "type": "error", "name": "TokenAndCurrencyCannotBeTheSame", "inputs": [] }, { "type": "error", "name": "TokenIsAddressZero", "inputs": [] }, { "type": "error", "name": "TokenTransferFailed", "inputs": [] }, { "type": "error", "name": "TokensNotReceived", "inputs": [] }, { "type": "error", "name": "TokensRecipientIsZero", "inputs": [] }, { "type": "error", "name": "TotalSupplyIsTooLarge", "inputs": [] }, { "type": "error", "name": "TotalSupplyIsZero", "inputs": [] }, { "type": "error", "name": "ValidationHookCallFailed", "inputs": [{ "name": "reason", "type": "bytes", "internalType": "bytes" }] }];
66
+
67
+ // src/abis/factory.ts
68
+ var factoryAbi = [{ "type": "function", "name": "getAuctionAddress", "inputs": [{ "name": "token", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }, { "name": "configData", "type": "bytes", "internalType": "bytes" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }, { "name": "sender", "type": "address", "internalType": "address" }], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "initializeDistribution", "inputs": [{ "name": "token", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }, { "name": "configData", "type": "bytes", "internalType": "bytes" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }], "outputs": [{ "name": "distributionContract", "type": "address", "internalType": "contract IDistributionContract" }], "stateMutability": "nonpayable" }, { "type": "event", "name": "AuctionCreated", "inputs": [{ "name": "auction", "type": "address", "indexed": true, "internalType": "address" }, { "name": "token", "type": "address", "indexed": true, "internalType": "address" }, { "name": "amount", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "configData", "type": "bytes", "indexed": false, "internalType": "bytes" }], "anonymous": false }, { "type": "error", "name": "InvalidTokenAmount", "inputs": [{ "name": "amount", "type": "uint256", "internalType": "uint256" }] }];
69
+
70
+ // src/read.ts
71
+ async function getAuctionInfo(client, auction) {
72
+ const contract = { address: auction, abi: auctionAbi };
73
+ const [token, currency, totalSupply, startBlock, endBlock, floorPrice, tickSpacing] = await client.publicClient.multicall({
74
+ allowFailure: false,
75
+ contracts: [
76
+ { ...contract, functionName: "token" },
77
+ { ...contract, functionName: "currency" },
78
+ { ...contract, functionName: "totalSupply" },
79
+ { ...contract, functionName: "startBlock" },
80
+ { ...contract, functionName: "endBlock" },
81
+ { ...contract, functionName: "floorPrice" },
82
+ { ...contract, functionName: "tickSpacing" }
83
+ ]
84
+ });
85
+ return {
86
+ auction,
87
+ token,
88
+ currency,
89
+ totalSupply,
90
+ startBlock: BigInt(startBlock),
91
+ endBlock: BigInt(endBlock),
92
+ floorPriceQ96: floorPrice,
93
+ tickSpacing
94
+ };
95
+ }
96
+
97
+ // src/enrich.ts
98
+ async function enrichStore(client, store, options = {}) {
99
+ const snapshot = await store.read();
100
+ if (!snapshot) {
101
+ return { enriched: 0, alreadyComplete: 0, failed: 0, total: 0 };
102
+ }
103
+ const needsWork = snapshot.auctions.filter(
104
+ (record) => !record.info || !record.tokenMeta || !record.currencyMeta
105
+ );
106
+ const alreadyComplete = snapshot.auctions.length - needsWork.length;
107
+ if (needsWork.length === 0) {
108
+ return { enriched: 0, alreadyComplete, failed: 0, total: snapshot.auctions.length };
109
+ }
110
+ options.onProgress?.(
111
+ `${needsWork.length} auction(s) need enrichment, ${alreadyComplete} already complete`
112
+ );
113
+ const metadataCache = /* @__PURE__ */ new Map();
114
+ const metadata = async (address) => {
115
+ const key = address.toLowerCase();
116
+ const cached = metadataCache.get(key);
117
+ if (cached) return cached;
118
+ const fetched = await getTokenMetadata(client, address);
119
+ metadataCache.set(key, fetched);
120
+ return fetched;
121
+ };
122
+ const concurrency = options.concurrency ?? 5;
123
+ const updated = [];
124
+ let failed = 0;
125
+ for (let i = 0; i < needsWork.length; i += concurrency) {
126
+ const batch = needsWork.slice(i, i + concurrency);
127
+ const settled = await Promise.all(
128
+ batch.map(async (record) => {
129
+ try {
130
+ const info = record.info ?? await getAuctionInfo(client, record.auction);
131
+ const [tokenMeta, currencyMeta] = await Promise.all([
132
+ record.tokenMeta ?? metadata(info.token),
133
+ record.currencyMeta ?? metadata(info.currency)
134
+ ]);
135
+ return { ...record, info, tokenMeta, currencyMeta };
136
+ } catch {
137
+ return null;
138
+ }
139
+ })
140
+ );
141
+ for (const record of settled) {
142
+ if (record) updated.push(record);
143
+ else failed++;
144
+ }
145
+ options.onProgress?.(
146
+ `enriched ${updated.length}/${needsWork.length}${failed > 0 ? ` (${failed} failed)` : ""}`
147
+ );
148
+ }
149
+ if (updated.length > 0) {
150
+ await store.merge({
151
+ chainId: snapshot.chainId,
152
+ factoryAddress: snapshot.factoryAddress,
153
+ lastSyncedBlock: snapshot.lastSyncedBlock,
154
+ auctions: updated
155
+ });
156
+ }
157
+ return {
158
+ enriched: updated.length,
159
+ alreadyComplete,
160
+ failed,
161
+ total: snapshot.auctions.length
162
+ };
163
+ }
164
+ function serializeInfo(info) {
165
+ return {
166
+ auction: info.auction,
167
+ token: info.token,
168
+ currency: info.currency,
169
+ totalSupply: info.totalSupply.toString(),
170
+ startBlock: info.startBlock.toString(),
171
+ endBlock: info.endBlock.toString(),
172
+ floorPriceQ96: info.floorPriceQ96.toString(),
173
+ tickSpacing: info.tickSpacing.toString()
174
+ };
175
+ }
176
+ function deserializeInfo(raw) {
177
+ return {
178
+ auction: raw.auction,
179
+ token: raw.token,
180
+ currency: raw.currency,
181
+ totalSupply: BigInt(raw.totalSupply),
182
+ startBlock: BigInt(raw.startBlock),
183
+ endBlock: BigInt(raw.endBlock),
184
+ floorPriceQ96: BigInt(raw.floorPriceQ96),
185
+ tickSpacing: BigInt(raw.tickSpacing)
186
+ };
187
+ }
188
+ function serializeRecord(record) {
189
+ return {
190
+ auction: record.auction,
191
+ token: record.token,
192
+ amount: record.amount.toString(),
193
+ configData: record.configData,
194
+ blockNumber: record.blockNumber.toString(),
195
+ transactionHash: record.transactionHash,
196
+ logIndex: record.logIndex,
197
+ ...record.info ? { info: serializeInfo(record.info) } : {},
198
+ ...record.tokenMeta ? { tokenMeta: record.tokenMeta } : {},
199
+ ...record.currencyMeta ? { currencyMeta: record.currencyMeta } : {}
200
+ };
201
+ }
202
+ function deserializeRecord(raw) {
203
+ return {
204
+ auction: raw.auction,
205
+ token: raw.token,
206
+ amount: BigInt(raw.amount),
207
+ configData: raw.configData,
208
+ blockNumber: BigInt(raw.blockNumber),
209
+ transactionHash: raw.transactionHash,
210
+ logIndex: raw.logIndex,
211
+ info: raw.info ? deserializeInfo(raw.info) : void 0,
212
+ tokenMeta: raw.tokenMeta,
213
+ currencyMeta: raw.currencyMeta
214
+ };
215
+ }
216
+ function sortRecords(records) {
217
+ return records.sort(
218
+ (a, b) => a.blockNumber === b.blockNumber ? a.logIndex - b.logIndex : a.blockNumber < b.blockNumber ? -1 : 1
219
+ );
220
+ }
221
+ function mergeRecords(existing, incoming) {
222
+ const byAddress = /* @__PURE__ */ new Map();
223
+ for (const record of existing) byAddress.set(record.auction.toLowerCase(), record);
224
+ let added = 0;
225
+ for (const record of incoming) {
226
+ const key = record.auction.toLowerCase();
227
+ const previous = byAddress.get(key);
228
+ if (!previous) added++;
229
+ byAddress.set(key, {
230
+ ...previous,
231
+ ...record,
232
+ info: record.info ?? previous?.info,
233
+ tokenMeta: record.tokenMeta ?? previous?.tokenMeta,
234
+ currencyMeta: record.currencyMeta ?? previous?.currencyMeta
235
+ });
236
+ }
237
+ return { merged: sortRecords([...byAddress.values()]), added };
238
+ }
239
+ var JsonAuctionStore = class {
240
+ constructor(filePath) {
241
+ this.filePath = filePath;
242
+ }
243
+ filePath;
244
+ async read() {
245
+ let raw;
246
+ try {
247
+ raw = await promises.readFile(this.filePath, "utf8");
248
+ } catch {
249
+ return void 0;
250
+ }
251
+ const parsed = JSON.parse(raw);
252
+ return {
253
+ chainId: parsed.chainId,
254
+ factoryAddress: parsed.factoryAddress,
255
+ lastSyncedBlock: BigInt(parsed.lastSyncedBlock),
256
+ auctions: sortRecords(parsed.auctions.map(deserializeRecord))
257
+ };
258
+ }
259
+ async merge(update) {
260
+ const existing = await this.read();
261
+ if (existing && (existing.chainId !== update.chainId || existing.factoryAddress.toLowerCase() !== update.factoryAddress.toLowerCase())) {
262
+ throw new Error(
263
+ `Auction store at ${this.filePath} holds chain ${existing.chainId}/${existing.factoryAddress}, refusing to merge chain ${update.chainId}/${update.factoryAddress}.`
264
+ );
265
+ }
266
+ const { merged, added } = mergeRecords(existing?.auctions ?? [], update.auctions);
267
+ const watermark = existing && existing.lastSyncedBlock > update.lastSyncedBlock ? existing.lastSyncedBlock : update.lastSyncedBlock;
268
+ await promises.mkdir(path.dirname(this.filePath), { recursive: true });
269
+ await promises.writeFile(
270
+ this.filePath,
271
+ JSON.stringify(
272
+ {
273
+ chainId: update.chainId,
274
+ factoryAddress: update.factoryAddress,
275
+ lastSyncedBlock: watermark.toString(),
276
+ auctions: merged.map(serializeRecord)
277
+ },
278
+ null,
279
+ 2
280
+ ) + "\n",
281
+ "utf8"
282
+ );
283
+ return { added, total: merged.length };
284
+ }
285
+ };
286
+ var MemoryAuctionStore = class {
287
+ snapshot;
288
+ async read() {
289
+ return this.snapshot;
290
+ }
291
+ async merge(update) {
292
+ const { merged, added } = mergeRecords(this.snapshot?.auctions ?? [], update.auctions);
293
+ const watermark = this.snapshot && this.snapshot.lastSyncedBlock > update.lastSyncedBlock ? this.snapshot.lastSyncedBlock : update.lastSyncedBlock;
294
+ this.snapshot = {
295
+ chainId: update.chainId,
296
+ factoryAddress: update.factoryAddress,
297
+ lastSyncedBlock: watermark,
298
+ auctions: merged
299
+ };
300
+ return { added, total: merged.length };
301
+ }
302
+ };
303
+ var auctionCreatedEvent = viem.getAbiItem({ abi: factoryAbi, name: "AuctionCreated" });
304
+ function toDiscoveredAuction(log) {
305
+ const { auction, token, amount, configData } = log.args;
306
+ if (!auction || !token) {
307
+ throw new Error(`Malformed AuctionCreated log in block ${log.blockNumber}: missing auction/token`);
308
+ }
309
+ return {
310
+ auction,
311
+ token,
312
+ amount: amount ?? 0n,
313
+ configData: configData ?? "0x",
314
+ blockNumber: log.blockNumber,
315
+ transactionHash: log.transactionHash,
316
+ logIndex: log.logIndex
317
+ };
318
+ }
319
+ async function scanAuctions(client, options = {}) {
320
+ const headBlock = options.toBlock ?? await client.publicClient.getBlockNumber();
321
+ const startBlock = options.fromBlock ?? client.factoryDeployBlock;
322
+ const maxChunk = options.chunkSize ?? DEFAULT_LOG_CHUNK_SIZE;
323
+ if (startBlock > headBlock) return [];
324
+ const emptyChunkRetries = options.emptyChunkRetries ?? 2;
325
+ const found = [];
326
+ let cursor = startBlock;
327
+ let chunkSize = maxChunk;
328
+ while (cursor <= headBlock) {
329
+ const chunkEnd = min(cursor + chunkSize - 1n, headBlock);
330
+ const fetchChunk = async (from, to) => await client.logsClient.getLogs({
331
+ address: client.factoryAddress,
332
+ event: auctionCreatedEvent,
333
+ fromBlock: from,
334
+ toBlock: to
335
+ });
336
+ let logs;
337
+ try {
338
+ logs = await fetchChunk(cursor, chunkEnd);
339
+ for (let attempt = 0; logs.length === 0 && attempt < emptyChunkRetries; attempt++) {
340
+ const retry = await fetchChunk(cursor, chunkEnd);
341
+ if (retry.length > 0) {
342
+ options.onAnomaly?.({
343
+ fromBlock: cursor,
344
+ toBlock: chunkEnd,
345
+ recoveredLogs: retry.length
346
+ });
347
+ logs = retry;
348
+ }
349
+ }
350
+ } catch (error) {
351
+ if (chunkSize > 1n) {
352
+ chunkSize = chunkSize / 2n;
353
+ continue;
354
+ }
355
+ throw new Error(
356
+ `eth_getLogs failed for a single block (${cursor}) on ${client.chain.name}: ${error.message}`
357
+ );
358
+ }
359
+ for (const log of logs) found.push(toDiscoveredAuction(log));
360
+ options.onProgress?.({
361
+ fromBlock: cursor,
362
+ toBlock: chunkEnd,
363
+ scannedTo: chunkEnd,
364
+ headBlock,
365
+ found: found.length
366
+ });
367
+ cursor = chunkEnd + 1n;
368
+ if (chunkSize < maxChunk) chunkSize = min(chunkSize * 2n, maxChunk);
369
+ }
370
+ found.sort(
371
+ (a, b) => a.blockNumber === b.blockNumber ? a.logIndex - b.logIndex : a.blockNumber < b.blockNumber ? -1 : 1
372
+ );
373
+ return found;
374
+ }
375
+ function min(a, b) {
376
+ return a < b ? a : b;
377
+ }
378
+
379
+ // src/sync.ts
380
+ async function syncAuctions(client, store, options = {}) {
381
+ const head = await client.publicClient.getBlockNumber();
382
+ const existing = await store.read();
383
+ const passes = Math.max(1, options.passes ?? 1);
384
+ const from = options.full || !existing ? client.factoryDeployBlock : (
385
+ // Re-scan the last block already covered, in case it was mid-block.
386
+ existing.lastSyncedBlock
387
+ );
388
+ if (from > head) {
389
+ return {
390
+ added: 0,
391
+ total: existing?.auctions.length ?? 0,
392
+ scannedFrom: from,
393
+ scannedTo: head,
394
+ anomalies: 0,
395
+ passes: 0
396
+ };
397
+ }
398
+ let anomalies = 0;
399
+ const union = /* @__PURE__ */ new Map();
400
+ for (let pass = 1; pass <= passes; pass++) {
401
+ options.onProgress?.(`pass ${pass}/${passes}: scanning ${from} -> ${head}`);
402
+ const found = await scanAuctions(client, {
403
+ fromBlock: from,
404
+ toBlock: head,
405
+ chunkSize: options.chunkSize,
406
+ onAnomaly: () => {
407
+ anomalies++;
408
+ }
409
+ });
410
+ let newThisPass = 0;
411
+ for (const auction of found) {
412
+ const key = auction.auction.toLowerCase();
413
+ if (!union.has(key)) newThisPass++;
414
+ union.set(key, auction);
415
+ }
416
+ options.onProgress?.(
417
+ `pass ${pass}/${passes}: ${found.length} found, ${newThisPass} new (union ${union.size})`
418
+ );
419
+ }
420
+ const { added, total } = await store.merge({
421
+ chainId: client.chainId,
422
+ factoryAddress: client.factoryAddress,
423
+ lastSyncedBlock: head,
424
+ auctions: [...union.values()]
425
+ });
426
+ return { added, total, scannedFrom: from, scannedTo: head, anomalies, passes };
427
+ }
428
+ async function loadAuctions(client, store, options = {}) {
429
+ if (store) {
430
+ const snapshot = await store.read();
431
+ if (snapshot && snapshot.auctions.length > 0) {
432
+ return { auctions: snapshot.auctions, source: "store" };
433
+ }
434
+ }
435
+ if (options.fallbackToScan) {
436
+ const auctions = await scanAuctions(client);
437
+ return { auctions, source: "scan" };
438
+ }
439
+ return { auctions: [], source: "empty" };
440
+ }
441
+
442
+ exports.JsonAuctionStore = JsonAuctionStore;
443
+ exports.MemoryAuctionStore = MemoryAuctionStore;
444
+ exports.enrichStore = enrichStore;
445
+ exports.loadAuctions = loadAuctions;
446
+ exports.syncAuctions = syncAuctions;
447
+ //# sourceMappingURL=node.cjs.map
448
+ //# sourceMappingURL=node.cjs.map