@hyperbridge/sdk 2.8.11 → 2.8.13
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/browser/index.d.ts +76 -19
- package/dist/browser/index.js +202 -27
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +205 -27
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +2 -2
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +202 -27
- package/dist/node/index.js.map +1 -1
- package/dist/node/{intents-helpers-BRegx4yZ.d.cts → intents-helpers-fntBuoYM.d.cts} +76 -19
- package/dist/node/{intents-helpers-BRegx4yZ.d.ts → intents-helpers-fntBuoYM.d.ts} +76 -19
- package/dist/node/intents-helpers.cjs +162 -27
- package/dist/node/intents-helpers.cjs.map +1 -1
- package/dist/node/intents-helpers.d.cts +1 -1
- package/dist/node/intents-helpers.d.ts +1 -1
- package/dist/node/intents-helpers.js +159 -27
- package/dist/node/intents-helpers.js.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -3570,13 +3570,6 @@ interface FillerConfig {
|
|
|
3570
3570
|
* Example: { 1: true, 56: false } - watch-only on Ethereum, normal execution on BSC
|
|
3571
3571
|
*/
|
|
3572
3572
|
watchOnly?: Record<number, boolean>;
|
|
3573
|
-
/**
|
|
3574
|
-
* Source chains (state machine ids, e.g. "EVM-8453") this filler accepts payment from when
|
|
3575
|
-
* filling cross-chain orders, declared inside its phantom bids' paymasterAndData. Omit to
|
|
3576
|
-
* declare nothing, which downstream consumers read as "accepts all CCTP/USDT0-covered
|
|
3577
|
-
* chains"; an empty array declares that no source chain is accepted.
|
|
3578
|
-
*/
|
|
3579
|
-
acceptedSourceChains?: string[];
|
|
3580
3573
|
/**
|
|
3581
3574
|
* Uniswap V4 position tokenIds this filler holds, per chain (state machine id -> tokenIds as
|
|
3582
3575
|
* decimal strings), declared inside its phantom bids' paymasterAndData for the bid's own chain.
|
|
@@ -6499,6 +6492,24 @@ declare function decodeFillOrder(data: HexString$1): {
|
|
|
6499
6492
|
} | null;
|
|
6500
6493
|
|
|
6501
6494
|
type HexString = `0x${string}`;
|
|
6495
|
+
/** A complete Permit2-sponsored paymasterAndData, before any declaration is appended. */
|
|
6496
|
+
declare const PERMIT2_SPONSORSHIP_BYTES: number;
|
|
6497
|
+
/**
|
|
6498
|
+
* The Permit2 sponsorship a bid's paymasterAndData carries when it was built on the real-bid path:
|
|
6499
|
+
* which paymaster it names and the fee-token permit it signed for that paymaster. Read for the
|
|
6500
|
+
* record only — the bid's authenticity comes from the solver signature over the userOpHash, which
|
|
6501
|
+
* covers these bytes, so nothing here is verified further and the permit signature is not kept.
|
|
6502
|
+
*/
|
|
6503
|
+
interface PhantomBidSponsorship {
|
|
6504
|
+
paymaster: HexString;
|
|
6505
|
+
/** The fee token the permit draws on. */
|
|
6506
|
+
token: HexString;
|
|
6507
|
+
permitAmount: bigint;
|
|
6508
|
+
/** Permit2 unordered nonce — random per op, which is what lets a solver's bids run in parallel. */
|
|
6509
|
+
nonce: bigint;
|
|
6510
|
+
/** Unix seconds after which the permit is unusable. */
|
|
6511
|
+
deadline: bigint;
|
|
6512
|
+
}
|
|
6502
6513
|
/** What a phantom bid's paymasterAndData declares about the solver behind it. */
|
|
6503
6514
|
interface PhantomBidDeclaration {
|
|
6504
6515
|
/**
|
|
@@ -6522,12 +6533,53 @@ declare function encodePhantomBidDeclaration(declaration: {
|
|
|
6522
6533
|
acceptedSourceChains?: string[];
|
|
6523
6534
|
uniswapV4Positions?: bigint[];
|
|
6524
6535
|
}): HexString;
|
|
6536
|
+
/** Everything a phantom bid's paymasterAndData was found to carry. */
|
|
6537
|
+
interface PhantomBidPaymasterAndData {
|
|
6538
|
+
/**
|
|
6539
|
+
* Which shape the field was read as: a bare declaration, a Permit2-sponsored bid (with or
|
|
6540
|
+
* without a declaration appended), or neither — empty, or bytes matching no known layout.
|
|
6541
|
+
*/
|
|
6542
|
+
mode: "declaration" | "permit2" | "none";
|
|
6543
|
+
/** Never null: an unreadable or missing declaration is the absent one (null sources, no positions). */
|
|
6544
|
+
declaration: PhantomBidDeclaration;
|
|
6545
|
+
/** The paymaster fields of a sponsored bid; null for the other two modes. */
|
|
6546
|
+
sponsorship: PhantomBidSponsorship | null;
|
|
6547
|
+
}
|
|
6548
|
+
/**
|
|
6549
|
+
* Decodes a phantom bid's paymasterAndData in whichever shape it takes.
|
|
6550
|
+
*
|
|
6551
|
+
* A bare declaration is tried first, so every bid placed before sponsored phantom bids existed
|
|
6552
|
+
* decodes to the byte exactly as it did. Failing that, a blob opening with a complete
|
|
6553
|
+
* Permit2-sponsored payload is read as a sponsored bid, and whatever follows the permit is parsed
|
|
6554
|
+
* as its declaration. Both parsers demand exact consumption — a bare declaration must end where
|
|
6555
|
+
* the bytes end, and a sponsored bid's tail must be a whole declaration or nothing — so neither
|
|
6556
|
+
* shape can be half-read as the other.
|
|
6557
|
+
*
|
|
6558
|
+
* A malformed tail on a sponsored bid yields the absent declaration but still reports the
|
|
6559
|
+
* sponsorship: the bid is still a bid, it just declared nothing readable.
|
|
6560
|
+
*/
|
|
6561
|
+
declare function decodePhantomBidPaymasterAndData(paymasterAndData: string | undefined | null): PhantomBidPaymasterAndData;
|
|
6525
6562
|
/**
|
|
6526
|
-
* Decodes a phantom bid's paymasterAndData
|
|
6563
|
+
* Decodes the declaration out of a phantom bid's paymasterAndData, whichever shape it takes (see
|
|
6564
|
+
* {@link decodePhantomBidPaymasterAndData}). Understands both declaration versions, so bids placed
|
|
6527
6565
|
* before positions existed keep decoding unchanged. Anything absent, unversioned or malformed
|
|
6528
6566
|
* yields a null `acceptedSources` with no positions — never a partial read.
|
|
6529
6567
|
*/
|
|
6530
6568
|
declare function decodePhantomBidDeclaration(paymasterAndData: string | undefined | null): PhantomBidDeclaration;
|
|
6569
|
+
/**
|
|
6570
|
+
* Builds a phantom bid's paymasterAndData: the declaration alone, or appended to a Permit2
|
|
6571
|
+
* sponsorship when the bid was built on the real-bid path and carries one.
|
|
6572
|
+
*
|
|
6573
|
+
* `sponsorship` is the packed EntryPoint v0.8 paymasterAndData the paymaster builder produced. It
|
|
6574
|
+
* must be exactly the Permit2-mode layout — the only one the decoder recognises — so a caller
|
|
6575
|
+
* cannot sign bytes the aggregation would read as "no declaration"; anything else throws. Empty
|
|
6576
|
+
* or omitted, the result is the bare declaration, byte-identical to what unsponsored bids carry.
|
|
6577
|
+
*/
|
|
6578
|
+
declare function encodePhantomBidPaymasterAndData(bid: {
|
|
6579
|
+
sponsorship?: HexString | null;
|
|
6580
|
+
acceptedSourceChains?: string[];
|
|
6581
|
+
uniswapV4Positions?: bigint[];
|
|
6582
|
+
}): HexString;
|
|
6531
6583
|
/** Back-compat wrapper: the source-chain half of {@link encodePhantomBidDeclaration}. */
|
|
6532
6584
|
declare function encodeAcceptedSourceChains(chains: string[]): HexString;
|
|
6533
6585
|
/** Back-compat wrapper: the source-chain half of {@link decodePhantomBidDeclaration}. */
|
|
@@ -6542,19 +6594,24 @@ declare function decodeAcceptedSourceChains(paymasterAndData: string | undefined
|
|
|
6542
6594
|
* paid its cost of goods.
|
|
6543
6595
|
*/
|
|
6544
6596
|
declare const UNISWAP_QUOTE_HAIRCUT_BPS = 10n;
|
|
6597
|
+
/** Applies {@link UNISWAP_QUOTE_HAIRCUT_BPS} to a quoted output amount, rounding down. */
|
|
6598
|
+
declare function applyUniswapQuoteHaircut(amount: bigint): bigint;
|
|
6545
6599
|
/**
|
|
6546
|
-
*
|
|
6600
|
+
* The protocol fee haircut: the fee the IntentGateway at `gatewayAddress` charges on order inputs,
|
|
6601
|
+
* in basis points, read live from its `params()`.
|
|
6547
6602
|
*
|
|
6548
|
-
* A wallet-funded quote is
|
|
6549
|
-
*
|
|
6550
|
-
*
|
|
6551
|
-
*
|
|
6603
|
+
* A wallet-funded quote is shaded by exactly this, so the published rate is the one a taker
|
|
6604
|
+
* actually realizes after the gateway takes its cut, and it moves with governance rather than
|
|
6605
|
+
* with a constant someone has to remember to keep in step. Read on the phantom order's own chain,
|
|
6606
|
+
* which is the chain whose gateway will collect the fee on the fills this rate is published for.
|
|
6607
|
+
*
|
|
6608
|
+
* Fails loudly rather than defaulting: a gateway that returns no code, or a fee at or above 100%,
|
|
6609
|
+
* is a misconfiguration, and pricing a window unhaircut on the back of it would publish a rate
|
|
6610
|
+
* nobody can trade at. The `PhantomRpcError` lets the run's retry loop have another go first.
|
|
6552
6611
|
*/
|
|
6553
|
-
declare
|
|
6554
|
-
/** Applies {@link
|
|
6555
|
-
declare function
|
|
6556
|
-
/** Applies {@link PHANTOM_QUOTE_HAIRCUT_BPS} to a quoted output amount, rounding down. */
|
|
6557
|
-
declare function applyPhantomQuoteHaircut(amount: bigint): bigint;
|
|
6612
|
+
declare function readProtocolFeeHaircutBps(evmRpcUrl: string, gatewayAddress: string): Promise<bigint>;
|
|
6613
|
+
/** Applies the protocol fee haircut (see {@link readProtocolFeeHaircutBps}) to a quoted output amount, rounding down. */
|
|
6614
|
+
declare function applyProtocolFeeHaircut(amount: bigint, protocolFeeBps: bigint): bigint;
|
|
6558
6615
|
|
|
6559
6616
|
declare const ABI$1: readonly [{
|
|
6560
6617
|
readonly type: "constructor";
|
|
@@ -11582,4 +11639,4 @@ declare function teleport(teleport_param: {
|
|
|
11582
11639
|
extrinsics?: Array<SubmittableExtrinsic<"promise", ISubmittableResult>>;
|
|
11583
11640
|
}): Promise<ReadableStream<HyperbridgeTxEvents>>;
|
|
11584
11641
|
|
|
11585
|
-
export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type AvailableLiquidity, type Bid, type BidStorageEntry, type BidSubmissionResult, type BlockMetadata, type BridgeParams, type BridgeStep, type BundlerGasEstimate, BundlerMethod, type BuyAndSellRates, type BytesLikeHex, CHAINS_WITHOUT_VALID_UNTIL, type CancelEvent, type CancelOptions, type CancelOrderOptions, type CancelQuote, type ChainConfig, type ChainConfigData, ChainConfigService, Chains, type ClientConfig, type ConfiguredAssetSymbol, type ConfiguredAssetSymbolInput, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type Deployment, type DispatchGet, type DispatchInfo, type DispatchPost, ERC20Method, type ERC7821Call, ERC7821_BATCH_MODE, type Erc4626VaultConfigData, type EstimateFillOrderParams, type EstimateGasCallData, EvmChain, type EvmChainParams, ABI as EvmHostABI, EvmLanguage, type ExecuteIntentOrderOptions, type ExecutionResult, FILL_ORDER_V1_ABI, type FillOptions, type FillOptionsVersion, type FillOrderEstimate, type FillerBid, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString$1 as HexString, type HostParams, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, type HyperbridgeTxEvents, type IBatchConsensusAndGetResponseMessage, type IBatchConsensusAndPostRequestMessage, type IChain, type IConfig, type IConsensusMessage, type IEvmChain, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, INCLUSION_TIMEOUT_MS, type IPharosConfig, type IPolkadotHubConfig, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, type IndexedRateIntentQuoteMetadata, type IndexedRateQuoteIntentResult, type IndexedRateSide, IndexedRateUnavailableError, type IndexerQueryClient, IntentGateway, ABI$1 as IntentGatewayABI, type IntentGatewayContext, type IntentGatewayParams, IntentOrderStatus, type IntentOrderStatusKey, type IntentOrderStatusUpdate, type IntentQuoteStrategy, type IntentQuoteTradeType, IntentsCoprocessor, InvalidIndexedRateError, InvalidLiquidityIndexerResponseError, InvalidPhantomSnapshotError, IsmpClient, type IsmpRequest, LEGACY_FILL_OPTIONS_IMPLEMENTATIONS, type LiquiditySlice, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, type Order, type OrderFeesQuote, type OrderResponse, OrderStatus, OrderStatusChecker, type OrderStatusMetadata, type OrderWithStatus, PACKED_USEROP_TYPEHASH,
|
|
11642
|
+
export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type AvailableLiquidity, type Bid, type BidStorageEntry, type BidSubmissionResult, type BlockMetadata, type BridgeParams, type BridgeStep, type BundlerGasEstimate, BundlerMethod, type BuyAndSellRates, type BytesLikeHex, CHAINS_WITHOUT_VALID_UNTIL, type CancelEvent, type CancelOptions, type CancelOrderOptions, type CancelQuote, type ChainConfig, type ChainConfigData, ChainConfigService, Chains, type ClientConfig, type ConfiguredAssetSymbol, type ConfiguredAssetSymbolInput, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type Deployment, type DispatchGet, type DispatchInfo, type DispatchPost, ERC20Method, type ERC7821Call, ERC7821_BATCH_MODE, type Erc4626VaultConfigData, type EstimateFillOrderParams, type EstimateGasCallData, EvmChain, type EvmChainParams, ABI as EvmHostABI, EvmLanguage, type ExecuteIntentOrderOptions, type ExecutionResult, FILL_ORDER_V1_ABI, type FillOptions, type FillOptionsVersion, type FillOrderEstimate, type FillerBid, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString$1 as HexString, type HostParams, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, type HyperbridgeTxEvents, type IBatchConsensusAndGetResponseMessage, type IBatchConsensusAndPostRequestMessage, type IChain, type IConfig, type IConsensusMessage, type IEvmChain, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, INCLUSION_TIMEOUT_MS, type IPharosConfig, type IPolkadotHubConfig, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, type IndexedRateIntentQuoteMetadata, type IndexedRateQuoteIntentResult, type IndexedRateSide, IndexedRateUnavailableError, type IndexerQueryClient, IntentGateway, ABI$1 as IntentGatewayABI, type IntentGatewayContext, type IntentGatewayParams, IntentOrderStatus, type IntentOrderStatusKey, type IntentOrderStatusUpdate, type IntentQuoteStrategy, type IntentQuoteTradeType, IntentsCoprocessor, InvalidIndexedRateError, InvalidLiquidityIndexerResponseError, InvalidPhantomSnapshotError, IsmpClient, type IsmpRequest, LEGACY_FILL_OPTIONS_IMPLEMENTATIONS, type LiquiditySlice, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, type Order, type OrderFeesQuote, type OrderResponse, OrderStatus, OrderStatusChecker, type OrderStatusMetadata, type OrderWithStatus, PACKED_USEROP_TYPEHASH, PERMIT2_SPONSORSHIP_BYTES, PLACE_ORDER_SELECTOR, type PackedUserOperation, type Params, type PaymentInfo, type PhantomBid, type PhantomBidBatchResult, type PhantomBidDeclaration, type PhantomBidOutcome, type PhantomBidPaymasterAndData, type PhantomBidSponsorship, type PhantomOrderEvent, type PhantomOrderLeg, type PhantomOrderPriceSnapshot, type PhantomOrderPriceSnapshotsResponse, type PhantomSnapshotIntentQuoteMetadata, type PhantomSnapshotQuoteIntentResult, PhantomSnapshotUnavailableError, type PhantomTimings, PharosChain, type PharosChainParams, PolkadotHubChain, type PolkadotHubChainParams, type PollPhantomOrdersOptions, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, type QueryBuyAndSellRatesParams, type QuoteIntentParams, type QuoteIntentResult, type QuoteNativeResult, type QuoteResult, type QuoteUniswapParams, type QuoteUniswapResult, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type ResumeIntentOrderOptions, type RetryConfig, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, type SelectBidResult, type SelectOptions, type SigningAccount, type StateMachineHeight, type StateMachineId, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, type SubmitBidOptions, SubstrateChain, Swap, TESTNET_CHAINS, type TeleportParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, TokenGateway, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type Transaction, TronChain, type TronChainParams, UNISWAP_QUOTE_HAIRCUT_BPS, USE_ETHERSCAN_CHAINS, type UniswapProtocol, type UniswapQuote, type UniswapQuoteToken, type UniswapTradeType, type UniswapV4IntentQuoteMetadata, type UniswapV4IntentQuoteOptions, type UniswapV4PoolConfigData, type UniswapV4PoolKey, type UniswapV4QuoteIntentResult, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, UnsupportedLiquidityAssetError, UnsupportedLiquidityChainError, WrappedHyperFungibleTokenABI, type XcmGatewayParams, __test, adjustDecimals, applyProtocolFeeHaircut, applyUniswapQuoteHaircut, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeAcceptedSourceChains, decodeERC7821ExecuteBatch, decodeFillOrder, decodePhantomBidDeclaration, decodePhantomBidPaymasterAndData, decodeUserOpScale, deriveHttpUrl, encodeAcceptedSourceChains, encodeERC7821ExecuteBatch, encodeFillOrder, encodeISMPMessage, encodePhantomBidDeclaration, encodePhantomBidPaymasterAndData, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getFillOptionsVersion, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmAddress, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, poolSlug, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, readProtocolFeeHaircutBps, requestCommitmentKey, resetFillOptionsVersionCache, responseCommitmentKey, retryPromise, sortPoolSymbols, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
package/dist/browser/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { match } from 'ts-pattern';
|
|
|
7
7
|
import { WsProvider, ApiPromise, Keyring, HttpProvider } from '@polkadot/api';
|
|
8
8
|
import { Struct, Vector, u8, Bytes, Enum, Tuple, _void, u64, u32, Option, bool, u128 } from 'scale-ts';
|
|
9
9
|
import { xxhashAsU8a, keccakAsU8a, decodeAddress, keccakAsHex, blake2AsU8a } from '@polkadot/util-crypto';
|
|
10
|
-
import { u8aToHex, u8aConcat, hexToU8a,
|
|
10
|
+
import { u8aToHex, u8aConcat, hexToU8a, isHex as isHex$1 } from '@polkadot/util';
|
|
11
11
|
import PQueue from 'p-queue';
|
|
12
12
|
import { hasWindow, isNode, env } from 'std-env';
|
|
13
13
|
import mergeRace from '@async-generator/merge-race';
|
|
@@ -20606,13 +20606,116 @@ var IntentGateway = class _IntentGateway {
|
|
|
20606
20606
|
}
|
|
20607
20607
|
}
|
|
20608
20608
|
};
|
|
20609
|
-
|
|
20610
|
-
|
|
20609
|
+
function rpcFetch() {
|
|
20610
|
+
const f = globalThis.fetch;
|
|
20611
|
+
if (typeof f !== "function") {
|
|
20612
|
+
throw new Error("No fetch available; call setAggregationFetch() before using the aggregation helpers");
|
|
20613
|
+
}
|
|
20614
|
+
return f;
|
|
20615
|
+
}
|
|
20616
|
+
var PhantomRpcError = class extends Error {
|
|
20617
|
+
constructor(message, cause) {
|
|
20618
|
+
super(message);
|
|
20619
|
+
this.cause = cause;
|
|
20620
|
+
this.name = "PhantomRpcError";
|
|
20621
|
+
}
|
|
20622
|
+
cause;
|
|
20623
|
+
};
|
|
20624
|
+
async function rpcCall(url, payload) {
|
|
20625
|
+
let lastErr;
|
|
20626
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
20627
|
+
if (attempt > 0) await new Promise((resolve) => setTimeout(resolve, 150 * attempt));
|
|
20628
|
+
let timer;
|
|
20629
|
+
try {
|
|
20630
|
+
const timeout = new Promise((_, reject) => {
|
|
20631
|
+
timer = setTimeout(() => reject(new Error(`rpc timeout: ${url}`)), 12e3);
|
|
20632
|
+
});
|
|
20633
|
+
const response = await Promise.race([
|
|
20634
|
+
rpcFetch()(url, {
|
|
20635
|
+
method: "POST",
|
|
20636
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
20637
|
+
body: JSON.stringify(payload)
|
|
20638
|
+
}),
|
|
20639
|
+
timeout
|
|
20640
|
+
]);
|
|
20641
|
+
const body = await response.json();
|
|
20642
|
+
if (body?.error) {
|
|
20643
|
+
lastErr = new Error(`rpc error: ${JSON.stringify(body.error).slice(0, 200)}`);
|
|
20644
|
+
continue;
|
|
20645
|
+
}
|
|
20646
|
+
return body;
|
|
20647
|
+
} catch (err) {
|
|
20648
|
+
lastErr = err;
|
|
20649
|
+
} finally {
|
|
20650
|
+
if (timer) clearTimeout(timer);
|
|
20651
|
+
}
|
|
20652
|
+
}
|
|
20653
|
+
throw new PhantomRpcError(`RPC call failed after 4 attempts: ${url}`, lastErr);
|
|
20654
|
+
}
|
|
20611
20655
|
var FILL_ORDER_ABI = IntentGatewayV2_default.ABI;
|
|
20612
20656
|
var DECLARATION_V1 = 1;
|
|
20613
20657
|
var DECLARATION_V2 = 2;
|
|
20658
|
+
var PAYMASTER_ADDRESS_BYTES = 20;
|
|
20659
|
+
var PAYMASTER_GAS_LIMIT_BYTES = 16;
|
|
20660
|
+
var PAYMASTER_DATA_OFFSET = PAYMASTER_ADDRESS_BYTES + 2 * PAYMASTER_GAS_LIMIT_BYTES;
|
|
20661
|
+
var SIMPLEX_MODE_PERMIT2 = 2;
|
|
20662
|
+
var PERMIT2_DATA_BYTES = 1 + 20 + 32 + 32 + 32 + 1 + 32 + 32;
|
|
20663
|
+
var PERMIT2_SPONSORSHIP_BYTES = PAYMASTER_DATA_OFFSET + PERMIT2_DATA_BYTES;
|
|
20614
20664
|
var MAX_DECLARED_ENTRIES = 255;
|
|
20615
20665
|
var MAX_TOKEN_ID_BYTES = 32;
|
|
20666
|
+
function utf8Encode(text) {
|
|
20667
|
+
const bytes = [];
|
|
20668
|
+
for (const char of text) {
|
|
20669
|
+
const codePoint = char.codePointAt(0);
|
|
20670
|
+
if (codePoint < 128) bytes.push(codePoint);
|
|
20671
|
+
else if (codePoint < 2048) bytes.push(192 | codePoint >> 6, 128 | codePoint & 63);
|
|
20672
|
+
else if (codePoint < 65536) {
|
|
20673
|
+
bytes.push(224 | codePoint >> 12, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
|
|
20674
|
+
} else {
|
|
20675
|
+
bytes.push(
|
|
20676
|
+
240 | codePoint >> 18,
|
|
20677
|
+
128 | codePoint >> 12 & 63,
|
|
20678
|
+
128 | codePoint >> 6 & 63,
|
|
20679
|
+
128 | codePoint & 63
|
|
20680
|
+
);
|
|
20681
|
+
}
|
|
20682
|
+
}
|
|
20683
|
+
return bytes;
|
|
20684
|
+
}
|
|
20685
|
+
function utf8Decode(bytes) {
|
|
20686
|
+
let text = "";
|
|
20687
|
+
for (let offset = 0; offset < bytes.length; ) {
|
|
20688
|
+
const lead = bytes[offset];
|
|
20689
|
+
let codePoint;
|
|
20690
|
+
let continuations;
|
|
20691
|
+
if (lead < 128) {
|
|
20692
|
+
codePoint = lead;
|
|
20693
|
+
continuations = 0;
|
|
20694
|
+
} else if ((lead & 224) === 192) {
|
|
20695
|
+
codePoint = lead & 31;
|
|
20696
|
+
continuations = 1;
|
|
20697
|
+
} else if ((lead & 240) === 224) {
|
|
20698
|
+
codePoint = lead & 15;
|
|
20699
|
+
continuations = 2;
|
|
20700
|
+
} else if ((lead & 248) === 240) {
|
|
20701
|
+
codePoint = lead & 7;
|
|
20702
|
+
continuations = 3;
|
|
20703
|
+
} else {
|
|
20704
|
+
return null;
|
|
20705
|
+
}
|
|
20706
|
+
if (offset + continuations >= bytes.length) return null;
|
|
20707
|
+
for (let index = 1; index <= continuations; index++) {
|
|
20708
|
+
const byte = bytes[offset + index];
|
|
20709
|
+
if ((byte & 192) !== 128) return null;
|
|
20710
|
+
codePoint = codePoint << 6 | byte & 63;
|
|
20711
|
+
}
|
|
20712
|
+
const overlong = continuations === 1 && codePoint < 128 || continuations === 2 && codePoint < 2048 || continuations === 3 && codePoint < 65536;
|
|
20713
|
+
if (overlong || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return null;
|
|
20714
|
+
text += String.fromCodePoint(codePoint);
|
|
20715
|
+
offset += continuations + 1;
|
|
20716
|
+
}
|
|
20717
|
+
return text;
|
|
20718
|
+
}
|
|
20616
20719
|
function tokenIdToBytes(tokenId) {
|
|
20617
20720
|
if (tokenId < 0n) throw new Error(`Uniswap V4 tokenId cannot be negative: ${tokenId}`);
|
|
20618
20721
|
const bytes = [];
|
|
@@ -20635,7 +20738,7 @@ function encodePhantomBidDeclaration(declaration) {
|
|
|
20635
20738
|
const version = positions.length > 0 ? DECLARATION_V2 : DECLARATION_V1;
|
|
20636
20739
|
const bytes = [version, chains2.length];
|
|
20637
20740
|
for (const chain of chains2) {
|
|
20638
|
-
const encoded =
|
|
20741
|
+
const encoded = utf8Encode(chain);
|
|
20639
20742
|
if (encoded.length === 0 || encoded.length > 255) {
|
|
20640
20743
|
throw new Error(`Invalid state machine id in source chain declaration: ${chain}`);
|
|
20641
20744
|
}
|
|
@@ -20653,42 +20756,94 @@ function encodePhantomBidDeclaration(declaration) {
|
|
|
20653
20756
|
}
|
|
20654
20757
|
return u8aToHex(new Uint8Array(bytes));
|
|
20655
20758
|
}
|
|
20656
|
-
function
|
|
20657
|
-
|
|
20658
|
-
|
|
20659
|
-
|
|
20660
|
-
if (bytes.length < 2) return absent;
|
|
20661
|
-
const version = bytes[0];
|
|
20662
|
-
if (version !== DECLARATION_V1 && version !== DECLARATION_V2) return absent;
|
|
20759
|
+
function parseDeclaration(bytes, start) {
|
|
20760
|
+
if (bytes.length - start < 2) return null;
|
|
20761
|
+
const version = bytes[start];
|
|
20762
|
+
if (version !== DECLARATION_V1 && version !== DECLARATION_V2) return null;
|
|
20663
20763
|
const chains2 = [];
|
|
20664
|
-
let offset = 2;
|
|
20665
|
-
for (let entry = 0; entry < bytes[1]; entry++) {
|
|
20666
|
-
if (offset >= bytes.length) return
|
|
20764
|
+
let offset = start + 2;
|
|
20765
|
+
for (let entry = 0; entry < bytes[start + 1]; entry++) {
|
|
20766
|
+
if (offset >= bytes.length) return null;
|
|
20667
20767
|
const length = bytes[offset];
|
|
20668
20768
|
offset += 1;
|
|
20669
|
-
if (length === 0 || offset + length > bytes.length) return
|
|
20670
|
-
|
|
20769
|
+
if (length === 0 || offset + length > bytes.length) return null;
|
|
20770
|
+
const chain = utf8Decode(bytes.subarray(offset, offset + length));
|
|
20771
|
+
if (chain === null) return null;
|
|
20772
|
+
chains2.push(chain);
|
|
20671
20773
|
offset += length;
|
|
20672
20774
|
}
|
|
20673
20775
|
const positions = [];
|
|
20674
20776
|
if (version === DECLARATION_V2) {
|
|
20675
|
-
if (offset >= bytes.length) return
|
|
20777
|
+
if (offset >= bytes.length) return null;
|
|
20676
20778
|
const count = bytes[offset];
|
|
20677
20779
|
offset += 1;
|
|
20678
20780
|
for (let entry = 0; entry < count; entry++) {
|
|
20679
|
-
if (offset >= bytes.length) return
|
|
20781
|
+
if (offset >= bytes.length) return null;
|
|
20680
20782
|
const length = bytes[offset];
|
|
20681
20783
|
offset += 1;
|
|
20682
|
-
if (length === 0 || length > MAX_TOKEN_ID_BYTES || offset + length > bytes.length) return
|
|
20683
|
-
|
|
20684
|
-
for (const byte of bytes.subarray(offset, offset + length)) tokenId = tokenId << 8n | BigInt(byte);
|
|
20685
|
-
positions.push(tokenId);
|
|
20784
|
+
if (length === 0 || length > MAX_TOKEN_ID_BYTES || offset + length > bytes.length) return null;
|
|
20785
|
+
positions.push(bytesToBigInt3(bytes.subarray(offset, offset + length)));
|
|
20686
20786
|
offset += length;
|
|
20687
20787
|
}
|
|
20688
20788
|
}
|
|
20689
|
-
if (offset !== bytes.length) return
|
|
20789
|
+
if (offset !== bytes.length) return null;
|
|
20690
20790
|
return { acceptedSources: chains2, uniswapV4Positions: positions };
|
|
20691
20791
|
}
|
|
20792
|
+
function bytesToBigInt3(bytes) {
|
|
20793
|
+
let value = 0n;
|
|
20794
|
+
for (const byte of bytes) value = value << 8n | BigInt(byte);
|
|
20795
|
+
return value;
|
|
20796
|
+
}
|
|
20797
|
+
function bytesToAddress(bytes) {
|
|
20798
|
+
return u8aToHex(bytes);
|
|
20799
|
+
}
|
|
20800
|
+
function hasPermit2Sponsorship(bytes) {
|
|
20801
|
+
return bytes.length >= PERMIT2_SPONSORSHIP_BYTES && bytes[PAYMASTER_DATA_OFFSET] === SIMPLEX_MODE_PERMIT2;
|
|
20802
|
+
}
|
|
20803
|
+
function parseSponsorship(bytes) {
|
|
20804
|
+
let offset = 0;
|
|
20805
|
+
const take = (length) => {
|
|
20806
|
+
const slice = bytes.subarray(offset, offset + length);
|
|
20807
|
+
offset += length;
|
|
20808
|
+
return slice;
|
|
20809
|
+
};
|
|
20810
|
+
const paymaster = bytesToAddress(take(PAYMASTER_ADDRESS_BYTES));
|
|
20811
|
+
take(2 * PAYMASTER_GAS_LIMIT_BYTES);
|
|
20812
|
+
take(1);
|
|
20813
|
+
const token = bytesToAddress(take(20));
|
|
20814
|
+
const permitAmount = bytesToBigInt3(take(32));
|
|
20815
|
+
const nonce = bytesToBigInt3(take(32));
|
|
20816
|
+
const deadline = bytesToBigInt3(take(32));
|
|
20817
|
+
return { paymaster, token, permitAmount, nonce, deadline };
|
|
20818
|
+
}
|
|
20819
|
+
var absentDeclaration = () => ({ acceptedSources: null, uniswapV4Positions: [] });
|
|
20820
|
+
function decodePhantomBidPaymasterAndData(paymasterAndData) {
|
|
20821
|
+
const none = { mode: "none", declaration: absentDeclaration(), sponsorship: null };
|
|
20822
|
+
if (!paymasterAndData || !isHex$1(paymasterAndData)) return none;
|
|
20823
|
+
const bytes = hexToU8a(paymasterAndData);
|
|
20824
|
+
const bare = parseDeclaration(bytes, 0);
|
|
20825
|
+
if (bare) return { mode: "declaration", declaration: bare, sponsorship: null };
|
|
20826
|
+
if (!hasPermit2Sponsorship(bytes)) return none;
|
|
20827
|
+
const sponsorship = parseSponsorship(bytes);
|
|
20828
|
+
const tail = bytes.length > PERMIT2_SPONSORSHIP_BYTES ? parseDeclaration(bytes, PERMIT2_SPONSORSHIP_BYTES) : null;
|
|
20829
|
+
return { mode: "permit2", declaration: tail ?? absentDeclaration(), sponsorship };
|
|
20830
|
+
}
|
|
20831
|
+
function decodePhantomBidDeclaration(paymasterAndData) {
|
|
20832
|
+
return decodePhantomBidPaymasterAndData(paymasterAndData).declaration;
|
|
20833
|
+
}
|
|
20834
|
+
function encodePhantomBidPaymasterAndData(bid) {
|
|
20835
|
+
const declaration = encodePhantomBidDeclaration(bid);
|
|
20836
|
+
const sponsorship = bid.sponsorship;
|
|
20837
|
+
if (!sponsorship || sponsorship === "0x") return declaration;
|
|
20838
|
+
if (!isHex$1(sponsorship)) throw new Error("Phantom bid sponsorship is not hex");
|
|
20839
|
+
const bytes = hexToU8a(sponsorship);
|
|
20840
|
+
if (bytes.length !== PERMIT2_SPONSORSHIP_BYTES || !hasPermit2Sponsorship(bytes)) {
|
|
20841
|
+
throw new Error(
|
|
20842
|
+
`Phantom bid sponsorship must be a ${PERMIT2_SPONSORSHIP_BYTES}-byte Permit2-mode paymasterAndData, got ${bytes.length} bytes`
|
|
20843
|
+
);
|
|
20844
|
+
}
|
|
20845
|
+
return `${sponsorship}${declaration.slice(2)}`;
|
|
20846
|
+
}
|
|
20692
20847
|
function encodeAcceptedSourceChains(chains2) {
|
|
20693
20848
|
return encodePhantomBidDeclaration({ acceptedSourceChains: chains2 });
|
|
20694
20849
|
}
|
|
@@ -20696,15 +20851,35 @@ function decodeAcceptedSourceChains(paymasterAndData) {
|
|
|
20696
20851
|
return decodePhantomBidDeclaration(paymasterAndData).acceptedSources;
|
|
20697
20852
|
}
|
|
20698
20853
|
var UNISWAP_QUOTE_HAIRCUT_BPS = 10n;
|
|
20699
|
-
var PHANTOM_QUOTE_HAIRCUT_BPS = 5n;
|
|
20700
20854
|
function haircut(amount, bps) {
|
|
20701
20855
|
return amount * (10000n - bps) / 10000n;
|
|
20702
20856
|
}
|
|
20703
20857
|
function applyUniswapQuoteHaircut(amount) {
|
|
20704
20858
|
return haircut(amount, UNISWAP_QUOTE_HAIRCUT_BPS);
|
|
20705
20859
|
}
|
|
20706
|
-
|
|
20707
|
-
|
|
20860
|
+
var SELECTOR_GATEWAY_PARAMS = "0xcff0ab96";
|
|
20861
|
+
var GATEWAY_PARAMS_WORDS = 6;
|
|
20862
|
+
var GATEWAY_PARAMS_FEE_WORD = 4;
|
|
20863
|
+
async function readProtocolFeeHaircutBps(evmRpcUrl, gatewayAddress) {
|
|
20864
|
+
const result = await rpcCall(evmRpcUrl, {
|
|
20865
|
+
id: 1,
|
|
20866
|
+
jsonrpc: "2.0",
|
|
20867
|
+
method: "eth_call",
|
|
20868
|
+
params: [{ to: gatewayAddress, data: SELECTOR_GATEWAY_PARAMS }, "latest"]
|
|
20869
|
+
});
|
|
20870
|
+
const hex = result.result;
|
|
20871
|
+
if (typeof hex !== "string" || hex.length < 2 + 64 * GATEWAY_PARAMS_WORDS) {
|
|
20872
|
+
throw new PhantomRpcError(`IntentGateway.params() returned no usable result from ${gatewayAddress} on ${evmRpcUrl}`);
|
|
20873
|
+
}
|
|
20874
|
+
const start = 2 + 64 * GATEWAY_PARAMS_FEE_WORD;
|
|
20875
|
+
const protocolFeeBps = BigInt(`0x${hex.slice(start, start + 64)}`);
|
|
20876
|
+
if (protocolFeeBps >= 10000n) {
|
|
20877
|
+
throw new PhantomRpcError(`IntentGateway ${gatewayAddress} reports an implausible protocol fee: ${protocolFeeBps} bps`);
|
|
20878
|
+
}
|
|
20879
|
+
return protocolFeeBps;
|
|
20880
|
+
}
|
|
20881
|
+
function applyProtocolFeeHaircut(amount, protocolFeeBps) {
|
|
20882
|
+
return haircut(amount, protocolFeeBps);
|
|
20708
20883
|
}
|
|
20709
20884
|
FILL_ORDER_ABI.find(
|
|
20710
20885
|
(item) => item?.type === "function" && item?.name === "fillOrder"
|
|
@@ -25179,6 +25354,6 @@ async function teleportDot(param_) {
|
|
|
25179
25354
|
return stream;
|
|
25180
25355
|
}
|
|
25181
25356
|
|
|
25182
|
-
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, CHAINS_WITHOUT_VALID_UNTIL, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, FILL_ORDER_V1_ABI, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, INCLUSION_TIMEOUT_MS, IndexedRateUnavailableError, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, InvalidIndexedRateError, InvalidLiquidityIndexerResponseError, InvalidPhantomSnapshotError, IsmpClient, LEGACY_FILL_OPTIONS_IMPLEMENTATIONS, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH,
|
|
25357
|
+
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, CHAINS_WITHOUT_VALID_UNTIL, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, FILL_ORDER_V1_ABI, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, INCLUSION_TIMEOUT_MS, IndexedRateUnavailableError, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, InvalidIndexedRateError, InvalidLiquidityIndexerResponseError, InvalidPhantomSnapshotError, IsmpClient, LEGACY_FILL_OPTIONS_IMPLEMENTATIONS, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH, PERMIT2_SPONSORSHIP_BYTES, PLACE_ORDER_SELECTOR, PhantomSnapshotUnavailableError, PharosChain, PolkadotHubChain, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, SubstrateChain, Swap, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, TronChain, UNISWAP_QUOTE_HAIRCUT_BPS, USE_ETHERSCAN_CHAINS, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, UnsupportedLiquidityAssetError, UnsupportedLiquidityChainError, WrappedHyperFungibleTokenABI, __test, adjustDecimals, applyProtocolFeeHaircut, applyUniswapQuoteHaircut, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeAcceptedSourceChains, decodeERC7821ExecuteBatch, decodeFillOrder, decodePhantomBidDeclaration, decodePhantomBidPaymasterAndData, decodeUserOpScale, deriveHttpUrl, encodeAcceptedSourceChains, encodeERC7821ExecuteBatch, encodeFillOrder, encodeISMPMessage, encodePhantomBidDeclaration, encodePhantomBidPaymasterAndData, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getFillOptionsVersion, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmAddress, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, poolSlug, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, readProtocolFeeHaircutBps, requestCommitmentKey, resetFillOptionsVersionCache, responseCommitmentKey, retryPromise, sortPoolSymbols, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
25183
25358
|
//# sourceMappingURL=index.js.map
|
|
25184
25359
|
//# sourceMappingURL=index.js.map
|