@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,446 @@
|
|
|
1
|
+
import { sepolia, unichainSepolia, baseSepolia } from 'viem/chains';
|
|
2
|
+
import { getAbiItem, formatUnits, encodeFunctionData, decodeFunctionResult } from 'viem';
|
|
3
|
+
|
|
4
|
+
// src/abis/auction.ts
|
|
5
|
+
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" }] }];
|
|
6
|
+
|
|
7
|
+
// src/abis/factory.ts
|
|
8
|
+
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" }] }];
|
|
9
|
+
|
|
10
|
+
// src/abis/auctionStateLens.ts
|
|
11
|
+
var auctionStateLensAbi = [{ "type": "function", "name": "revertWithState", "inputs": [{ "name": "auction", "type": "address", "internalType": "contract IContinuousClearingAuction" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "state", "inputs": [{ "name": "auction", "type": "address", "internalType": "contract IContinuousClearingAuction" }], "outputs": [{ "name": "", "type": "tuple", "internalType": "struct AuctionState", "components": [{ "name": "checkpoint", "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" }] }, { "name": "currencyRaised", "type": "uint256", "internalType": "uint256" }, { "name": "totalCleared", "type": "uint256", "internalType": "uint256" }, { "name": "isGraduated", "type": "bool", "internalType": "bool" }] }], "stateMutability": "nonpayable" }, { "type": "error", "name": "CheckpointFailed", "inputs": [] }, { "type": "error", "name": "InvalidRevertReasonLength", "inputs": [] }];
|
|
12
|
+
var auctionStateLensDeployedBytecode = "0x608060405234801561000f575f80fd5b5060043610610034575f3560e01c806321a13d371461003857806331e658a51461004d575b5f80fd5b61004b61004636600461048a565b610076565b005b61006061005b36600461048a565b6102c7565b60405161006d91906104bd565b60405180910390f35b8073ffffffffffffffffffffffffffffffffffffffff1663c2c4c5c16040518163ffffffff1660e01b815260040160c0604051808303815f875af19250505080156100fc575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526100f991810190610620565b60015b610132576040517fd027b09000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60405180608001604052808381526020018473ffffffffffffffffffffffffffffffffffffffff1663998ba4fc6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561018d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101b1919061063a565b81526020018473ffffffffffffffffffffffffffffffffffffffff16633e9d91746040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101ff573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610223919061063a565b81526020018473ffffffffffffffffffffffffffffffffffffffff16639e5f26026040518163ffffffff1660e01b8152600401602060405180830381865afa158015610271573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102959190610660565b151581525090505f816040516020016102ae91906104bd565b6040516020818303038152906040529050805160208201fd5b60408051610140810182525f6080820181815260a0830182905260c0830182905260e083018290526101008301829052610120830182905282526020820181905291810182905260608101919091526040517f21a13d3700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8316600482015230906321a13d37906024015f604051808303815f87803b15801561037a575f80fd5b505af192505050801561038b575060015b6103ce573d8080156103b8576040519150601f19603f3d011682016040523d82523d5f602084013e6103bd565b606091505b506103c7816103d3565b9392505050565b919050565b60408051610140810182525f6080820181815260a0830182905260c0830182905260e083018290526101008301829052610120830182905282526020820181905291810182905260608101919091528151610120146104705760208251111561043e57815160208301fd5b6040517fa75357f900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b818060200190518101906104849190610679565b92915050565b5f6020828403121561049a575f80fd5b813573ffffffffffffffffffffffffffffffffffffffff811681146103c7575f80fd5b5f61012082019050825180518352602081015160208401526040810151604084015262ffffff606082015116606084015267ffffffffffffffff608082015116608084015267ffffffffffffffff60a08201511660a084015250602083015160c0830152604083015160e0830152606083015161053f61010084018215159052565b5092915050565b60405160c0810167ffffffffffffffff8111828210171561058e577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405290565b805167ffffffffffffffff811681146103ce575f80fd5b5f60c082840312156105bb575f80fd5b6105c3610546565b825181526020808401519082015260408084015190820152606083015190915062ffffff811681146105f3575f80fd5b606082015261060460808301610594565b608082015261061560a08301610594565b60a082015292915050565b5f60c08284031215610630575f80fd5b6103c783836105ab565b5f6020828403121561064a575f80fd5b5051919050565b805180151581146103ce575f80fd5b5f60208284031215610670575f80fd5b6103c782610651565b5f61012082840312801561068b575f80fd5b506040516080810167ffffffffffffffff811182821017156106d4577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040526106e184846105ab565b815260c0830151602082015260e083015160408201526107046101008401610651565b6060820152939250505056fea164736f6c634300081a000a";
|
|
13
|
+
|
|
14
|
+
// src/abis/index.ts
|
|
15
|
+
var UPSTREAM_TAG = "v1.1.0";
|
|
16
|
+
var UPSTREAM_COMMIT = "a0aabaa45d8677a4944fc04d5dea2c4b499b3d3a";
|
|
17
|
+
|
|
18
|
+
// src/q96.ts
|
|
19
|
+
var Q96 = 2n ** 96n;
|
|
20
|
+
var MPS = 10000000n;
|
|
21
|
+
var X7 = MPS;
|
|
22
|
+
var DECIMAL_PATTERN = /^-?\d+(\.\d+)?$/;
|
|
23
|
+
function q96ToDecimalString(valueQ96, precision = 18, trimTrailingZeros = true) {
|
|
24
|
+
if (precision < 0 || !Number.isInteger(precision)) {
|
|
25
|
+
throw new TypeError(
|
|
26
|
+
`q96ToDecimalString: precision must be a non-negative integer, got ${precision}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const negative = valueQ96 < 0n;
|
|
30
|
+
const magnitude = negative ? -valueQ96 : valueQ96;
|
|
31
|
+
const whole = magnitude / Q96;
|
|
32
|
+
const remainder = magnitude % Q96;
|
|
33
|
+
if (precision === 0) {
|
|
34
|
+
return `${negative && whole !== 0n ? "-" : ""}${whole}`;
|
|
35
|
+
}
|
|
36
|
+
const scale = 10n ** BigInt(precision);
|
|
37
|
+
const fractional = remainder * scale / Q96;
|
|
38
|
+
let fractionalDigits = fractional.toString().padStart(precision, "0");
|
|
39
|
+
if (trimTrailingZeros) {
|
|
40
|
+
fractionalDigits = fractionalDigits.replace(/0+$/, "");
|
|
41
|
+
}
|
|
42
|
+
const sign = negative && (whole !== 0n || fractional !== 0n) ? "-" : "";
|
|
43
|
+
return fractionalDigits.length > 0 ? `${sign}${whole}.${fractionalDigits}` : `${sign}${whole}`;
|
|
44
|
+
}
|
|
45
|
+
function q96ToNumber(valueQ96) {
|
|
46
|
+
return Number(q96ToDecimalString(valueQ96, 20, false));
|
|
47
|
+
}
|
|
48
|
+
function decimalToQ96(decimal) {
|
|
49
|
+
const asString = typeof decimal === "number" ? numberToDecimalString(decimal) : decimal.trim();
|
|
50
|
+
if (!DECIMAL_PATTERN.test(asString)) {
|
|
51
|
+
throw new TypeError(`decimalToQ96: expected a decimal string, got "${decimal}"`);
|
|
52
|
+
}
|
|
53
|
+
const negative = asString.startsWith("-");
|
|
54
|
+
const unsigned = negative ? asString.slice(1) : asString;
|
|
55
|
+
const [wholePart = "0", fractionalPart = ""] = unsigned.split(".");
|
|
56
|
+
const scale = 10n ** BigInt(fractionalPart.length);
|
|
57
|
+
const scaledValue = BigInt(wholePart) * scale + (fractionalPart === "" ? 0n : BigInt(fractionalPart));
|
|
58
|
+
const result = scaledValue * Q96 / scale;
|
|
59
|
+
return negative ? -result : result;
|
|
60
|
+
}
|
|
61
|
+
function numberToDecimalString(value) {
|
|
62
|
+
if (!Number.isFinite(value)) {
|
|
63
|
+
throw new TypeError(`decimalToQ96: expected a finite number, got ${value}`);
|
|
64
|
+
}
|
|
65
|
+
return value.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 20 });
|
|
66
|
+
}
|
|
67
|
+
function formatQ96(valueQ96, significantDigits = 6) {
|
|
68
|
+
if (valueQ96 === 0n) return "0";
|
|
69
|
+
const negative = valueQ96 < 0n;
|
|
70
|
+
const magnitude = negative ? -valueQ96 : valueQ96;
|
|
71
|
+
const sign = negative ? "-" : "";
|
|
72
|
+
let precision;
|
|
73
|
+
if (magnitude / Q96 > 0n) {
|
|
74
|
+
precision = significantDigits;
|
|
75
|
+
} else {
|
|
76
|
+
const fractional = q96ToDecimalString(magnitude, 40, false).split(".")[1] ?? "";
|
|
77
|
+
const firstSignificant = fractional.search(/[1-9]/);
|
|
78
|
+
if (firstSignificant === -1) return "0";
|
|
79
|
+
precision = firstSignificant + significantDigits;
|
|
80
|
+
}
|
|
81
|
+
const scale = 10n ** BigInt(precision);
|
|
82
|
+
const rounded = (magnitude * scale * 2n + Q96) / (Q96 * 2n);
|
|
83
|
+
const wholePart = rounded / scale;
|
|
84
|
+
const fractionalPart = (rounded % scale).toString().padStart(precision, "0").replace(/0+$/, "");
|
|
85
|
+
return fractionalPart.length > 0 ? `${sign}${wholePart}.${fractionalPart}` : `${sign}${wholePart}`;
|
|
86
|
+
}
|
|
87
|
+
function mpsToFraction(cumulativeMps) {
|
|
88
|
+
return Number(BigInt(cumulativeMps)) / Number(MPS);
|
|
89
|
+
}
|
|
90
|
+
function formatMpsPercent(cumulativeMps, fractionDigits = 2) {
|
|
91
|
+
return (mpsToFraction(cumulativeMps) * 100).toFixed(fractionDigits);
|
|
92
|
+
}
|
|
93
|
+
function fromValueX7(valueX7) {
|
|
94
|
+
return valueX7 / X7;
|
|
95
|
+
}
|
|
96
|
+
function formatQ96Compact(valueQ96, significantDigits = 6) {
|
|
97
|
+
if (valueQ96 === 0n) return "0";
|
|
98
|
+
const negative = valueQ96 < 0n;
|
|
99
|
+
const magnitude = negative ? -valueQ96 : valueQ96;
|
|
100
|
+
const sign = negative ? "-" : "";
|
|
101
|
+
const plain = formatQ96(magnitude, significantDigits);
|
|
102
|
+
const [integerPart = "0", fractionalPart = ""] = plain.split(".");
|
|
103
|
+
if (integerPart !== "0") return `${sign}${plain}`;
|
|
104
|
+
const firstSignificant = fractionalPart.search(/[1-9]/);
|
|
105
|
+
if (firstSignificant === -1) return "0";
|
|
106
|
+
if (firstSignificant < 6) return `${sign}${plain}`;
|
|
107
|
+
const digits = fractionalPart.slice(firstSignificant).replace(/0+$/, "");
|
|
108
|
+
const exponent = -(firstSignificant + 1);
|
|
109
|
+
const mantissa = digits.length > 1 ? `${digits[0]}.${digits.slice(1)}` : digits;
|
|
110
|
+
return `${sign}${mantissa}e${exponent}`;
|
|
111
|
+
}
|
|
112
|
+
var FACTORY_ADDRESS = "0xCCccCcCAE7503Cac057829BF2811De42E16e0bD5";
|
|
113
|
+
var FACTORY_DEPLOY_BLOCK = {
|
|
114
|
+
[sepolia.id]: 10130119n
|
|
115
|
+
};
|
|
116
|
+
var SUPPORTED_CHAINS = {
|
|
117
|
+
[sepolia.id]: sepolia,
|
|
118
|
+
[baseSepolia.id]: baseSepolia,
|
|
119
|
+
[unichainSepolia.id]: unichainSepolia
|
|
120
|
+
};
|
|
121
|
+
var BLOCK_TIME_SECONDS = {
|
|
122
|
+
[sepolia.id]: 12,
|
|
123
|
+
[baseSepolia.id]: 2,
|
|
124
|
+
[unichainSepolia.id]: 1
|
|
125
|
+
};
|
|
126
|
+
var DEFAULT_LOG_CHUNK_SIZE = 50000n;
|
|
127
|
+
var NATIVE_CURRENCY = "0x0000000000000000000000000000000000000000";
|
|
128
|
+
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
129
|
+
var auctionCreatedEvent = getAbiItem({ abi: factoryAbi, name: "AuctionCreated" });
|
|
130
|
+
function toDiscoveredAuction(log) {
|
|
131
|
+
const { auction, token, amount, configData } = log.args;
|
|
132
|
+
if (!auction || !token) {
|
|
133
|
+
throw new Error(`Malformed AuctionCreated log in block ${log.blockNumber}: missing auction/token`);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
auction,
|
|
137
|
+
token,
|
|
138
|
+
amount: amount ?? 0n,
|
|
139
|
+
configData: configData ?? "0x",
|
|
140
|
+
blockNumber: log.blockNumber,
|
|
141
|
+
transactionHash: log.transactionHash,
|
|
142
|
+
logIndex: log.logIndex
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async function scanAuctions(client, options = {}) {
|
|
146
|
+
const headBlock = options.toBlock ?? await client.publicClient.getBlockNumber();
|
|
147
|
+
const startBlock = options.fromBlock ?? client.factoryDeployBlock;
|
|
148
|
+
const maxChunk = options.chunkSize ?? DEFAULT_LOG_CHUNK_SIZE;
|
|
149
|
+
if (startBlock > headBlock) return [];
|
|
150
|
+
const emptyChunkRetries = options.emptyChunkRetries ?? 2;
|
|
151
|
+
const found = [];
|
|
152
|
+
let cursor = startBlock;
|
|
153
|
+
let chunkSize = maxChunk;
|
|
154
|
+
while (cursor <= headBlock) {
|
|
155
|
+
const chunkEnd = min(cursor + chunkSize - 1n, headBlock);
|
|
156
|
+
const fetchChunk = async (from, to) => await client.logsClient.getLogs({
|
|
157
|
+
address: client.factoryAddress,
|
|
158
|
+
event: auctionCreatedEvent,
|
|
159
|
+
fromBlock: from,
|
|
160
|
+
toBlock: to
|
|
161
|
+
});
|
|
162
|
+
let logs;
|
|
163
|
+
try {
|
|
164
|
+
logs = await fetchChunk(cursor, chunkEnd);
|
|
165
|
+
for (let attempt = 0; logs.length === 0 && attempt < emptyChunkRetries; attempt++) {
|
|
166
|
+
const retry = await fetchChunk(cursor, chunkEnd);
|
|
167
|
+
if (retry.length > 0) {
|
|
168
|
+
options.onAnomaly?.({
|
|
169
|
+
fromBlock: cursor,
|
|
170
|
+
toBlock: chunkEnd,
|
|
171
|
+
recoveredLogs: retry.length
|
|
172
|
+
});
|
|
173
|
+
logs = retry;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (chunkSize > 1n) {
|
|
178
|
+
chunkSize = chunkSize / 2n;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
throw new Error(
|
|
182
|
+
`eth_getLogs failed for a single block (${cursor}) on ${client.chain.name}: ${error.message}`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
for (const log of logs) found.push(toDiscoveredAuction(log));
|
|
186
|
+
options.onProgress?.({
|
|
187
|
+
fromBlock: cursor,
|
|
188
|
+
toBlock: chunkEnd,
|
|
189
|
+
scannedTo: chunkEnd,
|
|
190
|
+
headBlock,
|
|
191
|
+
found: found.length
|
|
192
|
+
});
|
|
193
|
+
cursor = chunkEnd + 1n;
|
|
194
|
+
if (chunkSize < maxChunk) chunkSize = min(chunkSize * 2n, maxChunk);
|
|
195
|
+
}
|
|
196
|
+
found.sort(
|
|
197
|
+
(a, b) => a.blockNumber === b.blockNumber ? a.logIndex - b.logIndex : a.blockNumber < b.blockNumber ? -1 : 1
|
|
198
|
+
);
|
|
199
|
+
return found;
|
|
200
|
+
}
|
|
201
|
+
function watchAuctions(client, onAuction, options = {}) {
|
|
202
|
+
return client.logsClient.watchEvent({
|
|
203
|
+
address: client.factoryAddress,
|
|
204
|
+
event: auctionCreatedEvent,
|
|
205
|
+
poll: true,
|
|
206
|
+
pollingInterval: options.pollingIntervalMs ?? 12e3,
|
|
207
|
+
onError: options.onError,
|
|
208
|
+
onLogs: (logs) => {
|
|
209
|
+
for (const log of logs) {
|
|
210
|
+
try {
|
|
211
|
+
onAuction(toDiscoveredAuction(log));
|
|
212
|
+
} catch (error) {
|
|
213
|
+
options.onError?.(error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
async function scanAuctionsForToken(client, token, options = {}) {
|
|
220
|
+
const all = await scanAuctions(client, options);
|
|
221
|
+
return all.filter((entry) => entry.token.toLowerCase() === token.toLowerCase());
|
|
222
|
+
}
|
|
223
|
+
function min(a, b) {
|
|
224
|
+
return a < b ? a : b;
|
|
225
|
+
}
|
|
226
|
+
var erc20MetadataAbi = [
|
|
227
|
+
{ type: "function", name: "symbol", inputs: [], outputs: [{ type: "string" }], stateMutability: "view" },
|
|
228
|
+
{ type: "function", name: "name", inputs: [], outputs: [{ type: "string" }], stateMutability: "view" },
|
|
229
|
+
{ type: "function", name: "decimals", inputs: [], outputs: [{ type: "uint8" }], stateMutability: "view" }
|
|
230
|
+
];
|
|
231
|
+
async function getTokenMetadata(client, address) {
|
|
232
|
+
if (address === NATIVE_CURRENCY) {
|
|
233
|
+
const native = client.chain.nativeCurrency;
|
|
234
|
+
return {
|
|
235
|
+
address,
|
|
236
|
+
symbol: native.symbol,
|
|
237
|
+
name: native.name,
|
|
238
|
+
decimals: native.decimals,
|
|
239
|
+
isNative: true
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const contract = { address, abi: erc20MetadataAbi };
|
|
243
|
+
const [symbol, name, decimals] = await client.publicClient.multicall({
|
|
244
|
+
allowFailure: true,
|
|
245
|
+
contracts: [
|
|
246
|
+
{ ...contract, functionName: "symbol" },
|
|
247
|
+
{ ...contract, functionName: "name" },
|
|
248
|
+
{ ...contract, functionName: "decimals" }
|
|
249
|
+
]
|
|
250
|
+
});
|
|
251
|
+
return {
|
|
252
|
+
address,
|
|
253
|
+
symbol: symbol.status === "success" ? symbol.result : shortAddress(address),
|
|
254
|
+
name: name.status === "success" ? name.result : shortAddress(address),
|
|
255
|
+
// 18 is the overwhelmingly common default; better than refusing to render.
|
|
256
|
+
decimals: decimals.status === "success" ? Number(decimals.result) : 18,
|
|
257
|
+
isNative: false
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
async function getTokenMetadataBatch(client, addresses) {
|
|
261
|
+
const unique = [...new Set(addresses)];
|
|
262
|
+
const entries = await Promise.all(
|
|
263
|
+
unique.map(async (address) => [address, await getTokenMetadata(client, address)])
|
|
264
|
+
);
|
|
265
|
+
return new Map(entries);
|
|
266
|
+
}
|
|
267
|
+
function formatTokenAmount(amount, token, maxFractionDigits = 4) {
|
|
268
|
+
if (amount === 0n) return `0 ${token.symbol}`;
|
|
269
|
+
const negative = amount < 0n;
|
|
270
|
+
const whole = formatUnits(negative ? -amount : amount, token.decimals);
|
|
271
|
+
const [integerPart = "0", fractionalPart = ""] = whole.split(".");
|
|
272
|
+
const grouped = BigInt(integerPart).toLocaleString("en-US");
|
|
273
|
+
let trimmed = fractionalPart.slice(0, maxFractionDigits).replace(/0+$/, "");
|
|
274
|
+
if (integerPart === "0" && trimmed.length === 0) {
|
|
275
|
+
const firstSignificant = fractionalPart.search(/[1-9]/);
|
|
276
|
+
if (firstSignificant !== -1) {
|
|
277
|
+
trimmed = fractionalPart.slice(0, firstSignificant + 4).replace(/0+$/, "");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const sign = negative ? "-" : "";
|
|
281
|
+
return trimmed.length > 0 ? `${sign}${grouped}.${trimmed} ${token.symbol}` : `${sign}${grouped} ${token.symbol}`;
|
|
282
|
+
}
|
|
283
|
+
function shortAddress(address) {
|
|
284
|
+
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
285
|
+
}
|
|
286
|
+
var LENS_OVERRIDE_ADDRESS = "0x00000000000000000000000000000000BEAC0E75";
|
|
287
|
+
function toCheckpoint(raw) {
|
|
288
|
+
return {
|
|
289
|
+
clearingPriceQ96: raw.clearingPrice,
|
|
290
|
+
currencyRaisedAtClearingPriceQ96X7: raw.currencyRaisedAtClearingPriceQ96_X7,
|
|
291
|
+
cumulativeMpsPerPrice: raw.cumulativeMpsPerPrice,
|
|
292
|
+
cumulativeMps: Number(raw.cumulativeMps),
|
|
293
|
+
prevBlock: BigInt(raw.prev),
|
|
294
|
+
nextBlock: BigInt(raw.next)
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
async function getAuctionState(client, auction) {
|
|
298
|
+
const data = encodeFunctionData({
|
|
299
|
+
abi: auctionStateLensAbi,
|
|
300
|
+
functionName: "state",
|
|
301
|
+
args: [auction]
|
|
302
|
+
});
|
|
303
|
+
const useOverride = client.lensAddress === void 0;
|
|
304
|
+
const target = client.lensAddress ?? LENS_OVERRIDE_ADDRESS;
|
|
305
|
+
const { data: returnData } = await client.publicClient.call({
|
|
306
|
+
to: target,
|
|
307
|
+
data,
|
|
308
|
+
...useOverride ? {
|
|
309
|
+
stateOverride: [
|
|
310
|
+
{ address: LENS_OVERRIDE_ADDRESS, code: auctionStateLensDeployedBytecode }
|
|
311
|
+
]
|
|
312
|
+
} : {}
|
|
313
|
+
});
|
|
314
|
+
if (!returnData) {
|
|
315
|
+
throw new Error(
|
|
316
|
+
`AuctionStateLens.state(${auction}) returned no data. Is ${auction} really a ContinuousClearingAuction on ${client.chain.name}?`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
const raw = decodeFunctionResult({
|
|
320
|
+
abi: auctionStateLensAbi,
|
|
321
|
+
functionName: "state",
|
|
322
|
+
data: returnData
|
|
323
|
+
});
|
|
324
|
+
return {
|
|
325
|
+
checkpoint: toCheckpoint(raw.checkpoint),
|
|
326
|
+
currencyRaised: raw.currencyRaised,
|
|
327
|
+
totalCleared: raw.totalCleared,
|
|
328
|
+
isGraduated: raw.isGraduated
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
async function getAuctionInfo(client, auction) {
|
|
332
|
+
const contract = { address: auction, abi: auctionAbi };
|
|
333
|
+
const [token, currency, totalSupply, startBlock, endBlock, floorPrice, tickSpacing] = await client.publicClient.multicall({
|
|
334
|
+
allowFailure: false,
|
|
335
|
+
contracts: [
|
|
336
|
+
{ ...contract, functionName: "token" },
|
|
337
|
+
{ ...contract, functionName: "currency" },
|
|
338
|
+
{ ...contract, functionName: "totalSupply" },
|
|
339
|
+
{ ...contract, functionName: "startBlock" },
|
|
340
|
+
{ ...contract, functionName: "endBlock" },
|
|
341
|
+
{ ...contract, functionName: "floorPrice" },
|
|
342
|
+
{ ...contract, functionName: "tickSpacing" }
|
|
343
|
+
]
|
|
344
|
+
});
|
|
345
|
+
return {
|
|
346
|
+
auction,
|
|
347
|
+
token,
|
|
348
|
+
currency,
|
|
349
|
+
totalSupply,
|
|
350
|
+
startBlock: BigInt(startBlock),
|
|
351
|
+
endBlock: BigInt(endBlock),
|
|
352
|
+
floorPriceQ96: floorPrice,
|
|
353
|
+
tickSpacing
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
async function getClearingPrice(client, auction) {
|
|
357
|
+
return client.publicClient.readContract({
|
|
358
|
+
address: auction,
|
|
359
|
+
abi: auctionAbi,
|
|
360
|
+
functionName: "clearingPrice"
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
async function isGraduated(client, auction) {
|
|
364
|
+
return client.publicClient.readContract({
|
|
365
|
+
address: auction,
|
|
366
|
+
abi: auctionAbi,
|
|
367
|
+
functionName: "isGraduated"
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function deriveStatus(info, blockNumber) {
|
|
371
|
+
if (blockNumber < info.startBlock) return "pending";
|
|
372
|
+
if (blockNumber <= info.endBlock) return "live";
|
|
373
|
+
return "ended";
|
|
374
|
+
}
|
|
375
|
+
async function getAuctionSummary(client, auction, options = {}) {
|
|
376
|
+
const [info, state, blockNumber] = await Promise.all([
|
|
377
|
+
options.info ?? getAuctionInfo(client, auction),
|
|
378
|
+
getAuctionState(client, auction),
|
|
379
|
+
options.blockNumber ?? client.publicClient.getBlockNumber()
|
|
380
|
+
]);
|
|
381
|
+
const status = deriveStatus(info, blockNumber);
|
|
382
|
+
const blocksRemaining = status === "pending" ? info.startBlock - blockNumber : status === "live" ? info.endBlock - blockNumber : 0n;
|
|
383
|
+
return {
|
|
384
|
+
info,
|
|
385
|
+
state,
|
|
386
|
+
blockNumber,
|
|
387
|
+
status,
|
|
388
|
+
clearingPrice: formatQ96(state.checkpoint.clearingPriceQ96),
|
|
389
|
+
supplyScheduleProgress: mpsToFraction(state.checkpoint.cumulativeMps),
|
|
390
|
+
hasClearedSupply: state.totalCleared > 0n,
|
|
391
|
+
blocksRemaining,
|
|
392
|
+
secondsRemaining: Number(blocksRemaining) * client.blockTimeSeconds
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function isFailedSummary(result) {
|
|
396
|
+
return "error" in result;
|
|
397
|
+
}
|
|
398
|
+
async function getAuctionSummaries(client, auctions, options = {}) {
|
|
399
|
+
const concurrency = options.concurrency ?? 5;
|
|
400
|
+
const blockNumber = await client.publicClient.getBlockNumber();
|
|
401
|
+
const results = [];
|
|
402
|
+
for (let i = 0; i < auctions.length; i += concurrency) {
|
|
403
|
+
const batch = auctions.slice(i, i + concurrency);
|
|
404
|
+
const settled = await Promise.all(
|
|
405
|
+
batch.map(async (auction) => {
|
|
406
|
+
try {
|
|
407
|
+
return await getAuctionSummary(client, auction, { blockNumber });
|
|
408
|
+
} catch (error) {
|
|
409
|
+
return { auction, error };
|
|
410
|
+
}
|
|
411
|
+
})
|
|
412
|
+
);
|
|
413
|
+
results.push(...settled);
|
|
414
|
+
}
|
|
415
|
+
return results;
|
|
416
|
+
}
|
|
417
|
+
async function getAuctionListStates(client, auctions) {
|
|
418
|
+
const result = /* @__PURE__ */ new Map();
|
|
419
|
+
if (auctions.length === 0) return result;
|
|
420
|
+
const contracts = auctions.flatMap((auction) => {
|
|
421
|
+
const base = { address: auction, abi: auctionAbi };
|
|
422
|
+
return [
|
|
423
|
+
{ ...base, functionName: "clearingPrice" },
|
|
424
|
+
{ ...base, functionName: "isGraduated" },
|
|
425
|
+
{ ...base, functionName: "currencyRaised" },
|
|
426
|
+
{ ...base, functionName: "totalCleared" }
|
|
427
|
+
];
|
|
428
|
+
});
|
|
429
|
+
const responses = await client.publicClient.multicall({ allowFailure: true, contracts });
|
|
430
|
+
auctions.forEach((auction, index) => {
|
|
431
|
+
const [price, graduated, raised, cleared] = responses.slice(index * 4, index * 4 + 4);
|
|
432
|
+
if (price?.status !== "success") return;
|
|
433
|
+
result.set(auction, {
|
|
434
|
+
auction,
|
|
435
|
+
clearingPriceQ96: price.result,
|
|
436
|
+
isGraduated: graduated?.status === "success" ? graduated.result : false,
|
|
437
|
+
currencyRaised: raised?.status === "success" ? raised.result : 0n,
|
|
438
|
+
totalCleared: cleared?.status === "success" ? cleared.result : 0n
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
return result;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export { BLOCK_TIME_SECONDS, DEFAULT_LOG_CHUNK_SIZE, FACTORY_ADDRESS, FACTORY_DEPLOY_BLOCK, LENS_OVERRIDE_ADDRESS, MPS, NATIVE_CURRENCY, PERMIT2_ADDRESS, Q96, SUPPORTED_CHAINS, UPSTREAM_COMMIT, UPSTREAM_TAG, X7, auctionAbi, auctionCreatedEvent, auctionStateLensAbi, auctionStateLensDeployedBytecode, decimalToQ96, deriveStatus, erc20MetadataAbi, factoryAbi, formatMpsPercent, formatQ96, formatQ96Compact, formatTokenAmount, fromValueX7, getAuctionInfo, getAuctionListStates, getAuctionState, getAuctionSummaries, getAuctionSummary, getClearingPrice, getTokenMetadata, getTokenMetadataBatch, isFailedSummary, isGraduated, mpsToFraction, q96ToDecimalString, q96ToNumber, scanAuctions, scanAuctionsForToken, watchAuctions };
|
|
445
|
+
//# sourceMappingURL=chunk-ABCX23D6.js.map
|
|
446
|
+
//# sourceMappingURL=chunk-ABCX23D6.js.map
|