@gibs/bridge-sdk 1.13.1 → 1.18.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/README.md +295 -18
- package/abis/package.json +6 -0
- package/bridge-limits/package.json +6 -0
- package/chain-info/package.json +6 -0
- package/chain-names/package.json +6 -0
- package/chains/package.json +6 -0
- package/claims/package.json +6 -0
- package/config/package.json +6 -0
- package/consolidated-quote/package.json +6 -0
- package/destination-calldata/package.json +6 -0
- package/dist/chain-info.d.ts +1 -1
- package/dist/chain-info.js +11 -12
- package/dist/chains.d.ts +25 -0
- package/dist/chains.js +55 -20
- package/dist/cjs/abis.d.ts +1 -0
- package/dist/cjs/abis.js +19 -0
- package/dist/cjs/bridge-limits.d.ts +103 -0
- package/dist/cjs/bridge-limits.js +89 -0
- package/dist/cjs/chain-info.d.ts +169 -0
- package/dist/cjs/chain-info.js +452 -0
- package/dist/cjs/chain-names.d.ts +160 -0
- package/dist/cjs/chain-names.js +207 -0
- package/dist/cjs/chains.d.ts +90 -0
- package/dist/cjs/chains.js +357 -0
- package/dist/cjs/claims.d.ts +198 -0
- package/dist/cjs/claims.js +182 -0
- package/dist/cjs/config.d.ts +255 -0
- package/dist/cjs/config.js +569 -0
- package/dist/cjs/consolidated-quote.d.ts +648 -0
- package/dist/cjs/consolidated-quote.js +1048 -0
- package/dist/cjs/destination-calldata.d.ts +118 -0
- package/dist/cjs/destination-calldata.js +156 -0
- package/dist/cjs/ecosystems.d.ts +217 -0
- package/dist/cjs/ecosystems.js +298 -0
- package/dist/cjs/execution.d.ts +359 -0
- package/dist/cjs/execution.js +495 -0
- package/dist/cjs/fee-type.d.ts +10 -0
- package/dist/cjs/fee-type.js +10 -0
- package/dist/cjs/hyperliquid-execution.d.ts +152 -0
- package/dist/cjs/hyperliquid-execution.js +175 -0
- package/dist/cjs/image-links.d.ts +117 -0
- package/dist/cjs/image-links.js +153 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +40 -0
- package/dist/cjs/lifi-execution-guard.d.ts +210 -0
- package/dist/cjs/lifi-execution-guard.js +409 -0
- package/dist/cjs/near-intents-conformance.d.ts +85 -0
- package/dist/cjs/near-intents-conformance.js +337 -0
- package/dist/cjs/near-intents-route.d.ts +47 -0
- package/dist/cjs/near-intents-route.js +303 -0
- package/dist/cjs/near-intents.d.ts +524 -0
- package/dist/cjs/near-intents.js +1071 -0
- package/dist/cjs/origin-deposit.d.ts +326 -0
- package/dist/cjs/origin-deposit.js +82 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pre-quote.d.ts +198 -0
- package/dist/cjs/pre-quote.js +180 -0
- package/dist/cjs/prices.d.ts +117 -0
- package/dist/cjs/prices.js +224 -0
- package/dist/cjs/providers.d.ts +238 -0
- package/dist/cjs/providers.js +171 -0
- package/dist/cjs/quote-fees.d.ts +102 -0
- package/dist/cjs/quote-fees.js +201 -0
- package/dist/cjs/referral.d.ts +85 -0
- package/dist/cjs/referral.js +85 -0
- package/dist/cjs/relay-currencies.d.ts +47 -0
- package/dist/cjs/relay-currencies.js +95 -0
- package/dist/cjs/relay-depository.d.ts +2 -0
- package/dist/cjs/relay-depository.js +85 -0
- package/dist/cjs/relay-quote.d.ts +301 -0
- package/dist/cjs/relay-quote.js +996 -0
- package/dist/cjs/route-steps.d.ts +138 -0
- package/dist/cjs/route-steps.js +310 -0
- package/dist/cjs/routing/amounts.d.ts +80 -0
- package/dist/cjs/routing/amounts.js +126 -0
- package/dist/cjs/routing/candidate-route.d.ts +43 -0
- package/dist/cjs/routing/candidate-route.js +50 -0
- package/dist/cjs/routing/candidate.d.ts +237 -0
- package/dist/cjs/routing/candidate.js +100 -0
- package/dist/cjs/routing/carrier-provider-key.d.ts +31 -0
- package/dist/cjs/routing/carrier-provider-key.js +42 -0
- package/dist/cjs/routing/carriers/ask-answer.d.ts +77 -0
- package/dist/cjs/routing/carriers/ask-answer.js +2 -0
- package/dist/cjs/routing/carriers/omnibridge.d.ts +137 -0
- package/dist/cjs/routing/carriers/omnibridge.js +459 -0
- package/dist/cjs/routing/carriers/pulsex-paths.d.ts +80 -0
- package/dist/cjs/routing/carriers/pulsex-paths.js +97 -0
- package/dist/cjs/routing/carriers/pulsex-split.d.ts +175 -0
- package/dist/cjs/routing/carriers/pulsex-split.js +193 -0
- package/dist/cjs/routing/carriers/pulsex.d.ts +184 -0
- package/dist/cjs/routing/carriers/pulsex.js +615 -0
- package/dist/cjs/routing/carriers/wrap.d.ts +25 -0
- package/dist/cjs/routing/carriers/wrap.js +119 -0
- package/dist/cjs/routing/composed-route-quality.d.ts +125 -0
- package/dist/cjs/routing/composed-route-quality.js +144 -0
- package/dist/cjs/routing/entry-chain-anchor.d.ts +88 -0
- package/dist/cjs/routing/entry-chain-anchor.js +59 -0
- package/dist/cjs/routing/format.d.ts +31 -0
- package/dist/cjs/routing/format.js +64 -0
- package/dist/cjs/routing/index.d.ts +42 -0
- package/dist/cjs/routing/index.js +142 -0
- package/dist/cjs/routing/producers.d.ts +770 -0
- package/dist/cjs/routing/producers.js +1617 -0
- package/dist/cjs/routing/providers.d.ts +31 -0
- package/dist/cjs/routing/providers.js +48 -0
- package/dist/cjs/routing/route-data.d.ts +397 -0
- package/dist/cjs/routing/route-data.js +2 -0
- package/dist/cjs/routing/search/compose.d.ts +168 -0
- package/dist/cjs/routing/search/compose.js +104 -0
- package/dist/cjs/routing/search/graph.d.ts +668 -0
- package/dist/cjs/routing/search/graph.js +461 -0
- package/dist/cjs/routing/search/plan-route-data.d.ts +285 -0
- package/dist/cjs/routing/search/plan-route-data.js +871 -0
- package/dist/cjs/routing/search/score.d.ts +356 -0
- package/dist/cjs/routing/search/score.js +445 -0
- package/dist/cjs/routing/swap-transactions.d.ts +95 -0
- package/dist/cjs/routing/swap-transactions.js +133 -0
- package/dist/cjs/routing/usd-value.d.ts +17 -0
- package/dist/cjs/routing/usd-value.js +29 -0
- package/dist/cjs/settings.d.ts +785 -0
- package/dist/cjs/settings.js +1074 -0
- package/dist/cjs/swap-venues.d.ts +43 -0
- package/dist/cjs/swap-venues.js +29 -0
- package/dist/cjs/ton-connect.d.ts +98 -0
- package/dist/cjs/ton-connect.js +206 -0
- package/dist/cjs/ton-execution.d.ts +7 -0
- package/dist/cjs/ton-execution.js +23 -0
- package/dist/cjs/ton.d.ts +37 -0
- package/dist/cjs/ton.js +83 -0
- package/dist/cjs/tron-execution.d.ts +146 -0
- package/dist/cjs/tron-execution.js +248 -0
- package/dist/cjs/types.d.ts +51 -0
- package/dist/cjs/types.js +2 -0
- package/dist/claims.d.ts +198 -0
- package/dist/claims.js +140 -0
- package/dist/config.d.ts +42 -3
- package/dist/config.js +87 -21
- package/dist/consolidated-quote.d.ts +109 -15
- package/dist/consolidated-quote.js +310 -52
- package/dist/execution.d.ts +359 -0
- package/dist/execution.js +455 -0
- package/dist/hyperliquid-execution.js +2 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/lifi-execution-guard.d.ts +13 -2
- package/dist/lifi-execution-guard.js +4 -0
- package/dist/near-intents.js +2 -3
- package/dist/pre-quote.d.ts +6 -6
- package/dist/pre-quote.js +10 -14
- package/dist/prices.d.ts +10 -0
- package/dist/prices.js +52 -1
- package/dist/providers.d.ts +17 -0
- package/dist/providers.js +6 -0
- package/dist/referral.d.ts +12 -4
- package/dist/referral.js +12 -4
- package/dist/relay-depository.d.ts +2 -0
- package/dist/relay-depository.js +82 -0
- package/dist/relay-quote.js +2 -3
- package/dist/routing/candidate.d.ts +3 -3
- package/dist/routing/candidate.js +3 -3
- package/dist/routing/carrier-provider-key.d.ts +31 -0
- package/dist/routing/carrier-provider-key.js +37 -0
- package/dist/routing/carriers/ask-answer.d.ts +17 -0
- package/dist/routing/carriers/omnibridge.js +23 -21
- package/dist/routing/carriers/pulsex-paths.d.ts +80 -0
- package/dist/routing/carriers/pulsex-paths.js +92 -0
- package/dist/routing/carriers/pulsex-split.d.ts +175 -0
- package/dist/routing/carriers/pulsex-split.js +185 -0
- package/dist/routing/carriers/pulsex.d.ts +81 -46
- package/dist/routing/carriers/pulsex.js +267 -148
- package/dist/routing/composed-route-quality.d.ts +28 -6
- package/dist/routing/composed-route-quality.js +36 -5
- package/dist/routing/entry-chain-anchor.d.ts +1 -1
- package/dist/routing/entry-chain-anchor.js +1 -1
- package/dist/routing/index.d.ts +11 -3
- package/dist/routing/index.js +8 -2
- package/dist/routing/producers.js +1 -1
- package/dist/routing/providers.d.ts +5 -0
- package/dist/routing/providers.js +5 -0
- package/dist/routing/route-data.d.ts +47 -5
- package/dist/routing/search/graph.d.ts +15 -0
- package/dist/routing/search/plan-route-data.d.ts +42 -1
- package/dist/routing/search/plan-route-data.js +68 -9
- package/dist/routing/search/score.d.ts +3 -0
- package/dist/routing/search/score.js +11 -3
- package/dist/routing/swap-transactions.d.ts +95 -0
- package/dist/routing/swap-transactions.js +127 -0
- package/dist/settings.d.ts +94 -1
- package/dist/settings.js +95 -3
- package/dist/swap-venues.d.ts +43 -0
- package/dist/swap-venues.js +24 -0
- package/dist/ton-connect.d.ts +98 -0
- package/dist/ton-connect.js +200 -0
- package/dist/ton-execution.d.ts +4 -114
- package/dist/ton-execution.js +4 -244
- package/dist/ton.d.ts +37 -0
- package/dist/ton.js +65 -0
- package/docs/examples/example-a-ether-to-pulse.ts +300 -0
- package/docs/examples/example-b-token-pulsechain-to-ethereum.ts +270 -0
- package/docs/examples/shared.ts +261 -0
- package/docs/examples/tsconfig.json +18 -0
- package/docs/integration-guide.md +617 -0
- package/ecosystems/package.json +6 -0
- package/execution/package.json +6 -0
- package/fee-type/package.json +6 -0
- package/hyperliquid-execution/package.json +6 -0
- package/image-links/package.json +6 -0
- package/lifi-execution-guard/package.json +6 -0
- package/llms.txt +75 -10
- package/near-intents/package.json +6 -0
- package/near-intents-route/package.json +6 -0
- package/origin-deposit/package.json +6 -0
- package/package.json +817 -10
- package/pre-quote/package.json +6 -0
- package/prices/package.json +6 -0
- package/providers/package.json +6 -0
- package/quote-fees/package.json +6 -0
- package/referral/package.json +6 -0
- package/relay-currencies/package.json +6 -0
- package/relay-quote/package.json +6 -0
- package/route-steps/package.json +6 -0
- package/routing/package.json +6 -0
- package/settings/package.json +6 -0
- package/ton/package.json +6 -0
- package/ton-connect/package.json +6 -0
- package/ton-execution/package.json +6 -0
- package/tron-execution/package.json +6 -0
- package/types/package.json +6 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import type { TokenBridgeInfo } from './chain-info.js';
|
|
3
|
+
import { type SwapVenues } from './swap-venues.js';
|
|
4
|
+
import { type AggregatorOriginRefusal, type ConsolidatedQuote, type ConsolidatedQuoteRequest } from './consolidated-quote.js';
|
|
5
|
+
import type { FeeType } from './fee-type.js';
|
|
6
|
+
import type { RouteCandidate } from './routing/candidate.js';
|
|
7
|
+
import type { HopEdge, PlannedHop } from './routing/search/graph.js';
|
|
8
|
+
import type { ResolveNodeToken } from './routing/search/plan-route-data.js';
|
|
9
|
+
import type { BridgeKey, Token } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* EXECUTION PLANS. Turns a chosen route into the ordered list of transactions
|
|
12
|
+
* a wallet sends, one {@link PlannedTx} at a time.
|
|
13
|
+
*
|
|
14
|
+
* Every builder here is the one the interface already signs with: the
|
|
15
|
+
* omnibridge call is `settings.ts`'s `transactionInputs`, the PulseX swap and
|
|
16
|
+
* the wrap are `routing/swap-transactions.ts`, the aggregator deposit is
|
|
17
|
+
* `consolidated-quote.ts`'s `aggregatorOriginCalls`, and the approval is
|
|
18
|
+
* `settings.ts`'s `approveCall` sized by `approvalAmounts`. This module only
|
|
19
|
+
* orders them and decides which approvals to skip.
|
|
20
|
+
*
|
|
21
|
+
* EVERY SPENDER IS ONE THIS CODE ALREADY KNOWS. Approvals are for the exact
|
|
22
|
+
* amount spent, never unlimited, and go only to:
|
|
23
|
+
* - the omnibridge pathway's `from` mediator, read from `config.ts`;
|
|
24
|
+
* - the swap router the edge was quoted on, found in the swap venues (the defaults in `config.ts` unless the caller passes its own);
|
|
25
|
+
* - an aggregator spender that `aggregatorOriginCalls` checked against a
|
|
26
|
+
* fixed table for its provider and chain (LI.FI's Diamond, Relay's
|
|
27
|
+
* depository). A quote cannot name its own spender.
|
|
28
|
+
*
|
|
29
|
+
* A PLAN IS ORDERED, AND EACH STEP WAITS FOR THE ONE BEFORE IT. An approval
|
|
30
|
+
* must land before the call that spends it, and a later section spends what
|
|
31
|
+
* the earlier one delivered. So every transaction except the last carries
|
|
32
|
+
* `waitForReceipt: true`.
|
|
33
|
+
*
|
|
34
|
+
* A RECEIPT IS NOT ARRIVAL. When a later section starts on a different chain
|
|
35
|
+
* than the one before it ends on, the earlier receipt only says the crossing
|
|
36
|
+
* started. The wallet must also wait for the funds to arrive on the next
|
|
37
|
+
* chain (the bridge indexer's delivery status) before it sends that section.
|
|
38
|
+
*/
|
|
39
|
+
/** What one planned transaction does. */
|
|
40
|
+
export type PlannedTxKind = 'approve' | 'bridge' | 'swap' | 'wrap' | 'unwrap' | 'claim';
|
|
41
|
+
/** One transaction for the wallet to sign and send, in plan order. */
|
|
42
|
+
export type PlannedTx = {
|
|
43
|
+
readonly chainId: number;
|
|
44
|
+
readonly kind: PlannedTxKind;
|
|
45
|
+
readonly to: Hex;
|
|
46
|
+
readonly data: Hex;
|
|
47
|
+
readonly value: bigint;
|
|
48
|
+
/** The gas limit the quote names, or null to let the wallet estimate it. */
|
|
49
|
+
readonly gasLimit: bigint | null;
|
|
50
|
+
/** True when the next transaction depends on this one, so the wallet must wait for its receipt first. */
|
|
51
|
+
readonly waitForReceipt: boolean;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Reads an ERC-20 allowance on chain.
|
|
55
|
+
*
|
|
56
|
+
* @param chainId - the chain the token lives on
|
|
57
|
+
* @param token - the token
|
|
58
|
+
* @param owner - the account that sends the plan
|
|
59
|
+
* @param spender - the contract that pulls the token
|
|
60
|
+
* @returns the current allowance, in the token's base units
|
|
61
|
+
*/
|
|
62
|
+
export type AllowanceReader = (chainId: number, token: Hex, owner: Hex, spender: Hex) => Promise<bigint>;
|
|
63
|
+
/**
|
|
64
|
+
* An {@link AllowanceReader} that reports no allowance anywhere, so the plan
|
|
65
|
+
* includes every approval. For a caller that reads allowances itself at send
|
|
66
|
+
* time.
|
|
67
|
+
*/
|
|
68
|
+
export declare const assumeNoAllowance: AllowanceReader;
|
|
69
|
+
/**
|
|
70
|
+
* The delivery fee terms, quoted before the plan is built. They become the
|
|
71
|
+
* on-chain fee director, so the reader sees exactly what the router may take.
|
|
72
|
+
*/
|
|
73
|
+
export type QuotedDeliveryFee = {
|
|
74
|
+
readonly feeType: FeeType;
|
|
75
|
+
/**
|
|
76
|
+
* The most the delivery router may take, in base units of {@link assetOut}.
|
|
77
|
+
* It is the fee director's `limit` in every mode: the fixed fee, the gas
|
|
78
|
+
* cap, or the percent fee's own cap.
|
|
79
|
+
*/
|
|
80
|
+
readonly maximumFee: bigint;
|
|
81
|
+
/** The percent rate as a fraction of one ether (5e14 is 0.05%). Read in percent mode only. */
|
|
82
|
+
readonly percentFee: bigint;
|
|
83
|
+
/** The tip over the gas cost as a fraction of one ether. Read in gas mode only. */
|
|
84
|
+
readonly gasTipFee: bigint;
|
|
85
|
+
/** The native-coin price in the delivered token, as `priceCorrective` reads it in `settings.ts`. */
|
|
86
|
+
readonly priceCorrective: bigint;
|
|
87
|
+
/** The token the destination router delivers and takes its fee in. */
|
|
88
|
+
readonly assetOut: Token;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Whether the reader buys delivery, and at what fee. There is no default: the
|
|
92
|
+
* caller states it.
|
|
93
|
+
*
|
|
94
|
+
* Only a pathway whose `requiresDelivery` is true sells delivery (PulseChain
|
|
95
|
+
* to Ethereum or BNB Smart Chain). On the way home to PulseChain the bridge
|
|
96
|
+
* itself delivers, so the only accepted choice there is `shouldDeliver: false`.
|
|
97
|
+
*/
|
|
98
|
+
export type DeliveryChoice = {
|
|
99
|
+
readonly shouldDeliver: false;
|
|
100
|
+
} | {
|
|
101
|
+
readonly shouldDeliver: true;
|
|
102
|
+
readonly fee: QuotedDeliveryFee;
|
|
103
|
+
};
|
|
104
|
+
/** A direct omnibridge crossing: `relayTokens`, `relayTokensAndCall`, `wrapAndRelayTokens` or `transferAndCall`. */
|
|
105
|
+
export type OmnibridgeLeg = {
|
|
106
|
+
readonly kind: 'omnibridge';
|
|
107
|
+
readonly bridgeKey: BridgeKey;
|
|
108
|
+
/** True reads only the mainnet pathways; false also reads the testnet ones. */
|
|
109
|
+
readonly isProd: boolean;
|
|
110
|
+
readonly assetIn: Token;
|
|
111
|
+
readonly assetLink: TokenBridgeInfo;
|
|
112
|
+
readonly amountIn: bigint;
|
|
113
|
+
readonly recipient: Hex;
|
|
114
|
+
readonly delivery: DeliveryChoice;
|
|
115
|
+
/** Whether the crossing unwraps to the native coin on arrival. Pass the value the pair allows, not only the reader's wish. */
|
|
116
|
+
readonly unwrap: boolean;
|
|
117
|
+
};
|
|
118
|
+
/** A PulseX swap, signed along the path its hop was priced on. */
|
|
119
|
+
export type PulseXSwapLeg = {
|
|
120
|
+
readonly kind: 'pulsex-swap';
|
|
121
|
+
readonly hop: Pick<PlannedHop, 'edge' | 'outcome'>;
|
|
122
|
+
readonly amountIn: bigint;
|
|
123
|
+
readonly minAmountOut: bigint;
|
|
124
|
+
readonly recipient: Hex;
|
|
125
|
+
/** The unix-seconds deadline the router enforces. */
|
|
126
|
+
readonly deadline: bigint;
|
|
127
|
+
};
|
|
128
|
+
/** A native-coin wrap or unwrap on the wrapped token's own contract. */
|
|
129
|
+
export type WrapLeg = {
|
|
130
|
+
readonly kind: 'wrap';
|
|
131
|
+
readonly edge: HopEdge;
|
|
132
|
+
readonly amountIn: bigint;
|
|
133
|
+
};
|
|
134
|
+
/** An aggregator's origin deposit, from a LIVE quote asked for the reader's own wallet. */
|
|
135
|
+
export type AggregatorLeg = {
|
|
136
|
+
readonly kind: 'aggregator';
|
|
137
|
+
readonly quote: ConsolidatedQuote;
|
|
138
|
+
readonly request: ConsolidatedQuoteRequest;
|
|
139
|
+
};
|
|
140
|
+
/** One signature's worth of work, in concrete terms. */
|
|
141
|
+
export type ExecutionLeg = OmnibridgeLeg | PulseXSwapLeg | WrapLeg | AggregatorLeg;
|
|
142
|
+
/** Why a leg or a section cannot be planned. */
|
|
143
|
+
export type ExecutionRefusal = {
|
|
144
|
+
readonly reason: 'amount-not-positive';
|
|
145
|
+
} | {
|
|
146
|
+
readonly reason: 'no-pathway';
|
|
147
|
+
} | {
|
|
148
|
+
readonly reason: 'delivery-not-offered';
|
|
149
|
+
} | {
|
|
150
|
+
readonly reason: 'delivery-fee-missing';
|
|
151
|
+
} | {
|
|
152
|
+
readonly reason: 'delivery-fee-unencodable';
|
|
153
|
+
} | {
|
|
154
|
+
readonly reason: 'bridge-call-refused';
|
|
155
|
+
} | {
|
|
156
|
+
readonly reason: 'swap-refused';
|
|
157
|
+
} | {
|
|
158
|
+
readonly reason: 'swap-estimate-only';
|
|
159
|
+
} | {
|
|
160
|
+
readonly reason: 'swap-quote-not-positive';
|
|
161
|
+
} | {
|
|
162
|
+
readonly reason: 'wrap-refused';
|
|
163
|
+
} | {
|
|
164
|
+
readonly reason: 'aggregator-origin-refused';
|
|
165
|
+
readonly origin: AggregatorOriginRefusal;
|
|
166
|
+
} | {
|
|
167
|
+
readonly reason: 'live-quote-required';
|
|
168
|
+
} | {
|
|
169
|
+
readonly reason: 'quote-provider-mismatch';
|
|
170
|
+
readonly quoteProvider: string;
|
|
171
|
+
readonly sectionCarrier: string;
|
|
172
|
+
} | {
|
|
173
|
+
readonly reason: 'paid-by-hand';
|
|
174
|
+
} | {
|
|
175
|
+
readonly reason: 'section-inputs-missing';
|
|
176
|
+
readonly needs: 'omnibridge' | 'swap';
|
|
177
|
+
} | {
|
|
178
|
+
readonly reason: 'section-shape';
|
|
179
|
+
readonly detail: string;
|
|
180
|
+
};
|
|
181
|
+
/** The delivery one omnibridge leg buys. */
|
|
182
|
+
export type DeliveryTerms = {
|
|
183
|
+
readonly status: 'not-requested';
|
|
184
|
+
} | {
|
|
185
|
+
readonly status: 'requested';
|
|
186
|
+
readonly feeType: FeeType;
|
|
187
|
+
/** The most the router may take, in base units of {@link feeToken}. */
|
|
188
|
+
readonly maximumFee: bigint;
|
|
189
|
+
readonly feeToken: Token;
|
|
190
|
+
};
|
|
191
|
+
/** The delivery a planned leg buys, so the wallet can show the fee before signing. */
|
|
192
|
+
export type PlannedDelivery = DeliveryTerms & {
|
|
193
|
+
readonly legIndex: number;
|
|
194
|
+
};
|
|
195
|
+
/** The transactions for a list of legs, or the first leg that cannot be planned. */
|
|
196
|
+
export type ExecutionPlan = {
|
|
197
|
+
readonly kind: 'planned';
|
|
198
|
+
readonly transactions: readonly PlannedTx[];
|
|
199
|
+
/** One entry per omnibridge leg, in leg order. */
|
|
200
|
+
readonly deliveries: readonly PlannedDelivery[];
|
|
201
|
+
} | {
|
|
202
|
+
readonly kind: 'refused';
|
|
203
|
+
readonly legIndex: number;
|
|
204
|
+
readonly refusal: ExecutionRefusal;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Plans the transactions for a list of legs, in order.
|
|
208
|
+
*
|
|
209
|
+
* Each leg contributes the exact approval it needs when the allowance on
|
|
210
|
+
* chain does not cover it (a reset to zero first when a smaller allowance
|
|
211
|
+
* remains), then its own call. Nothing is sent.
|
|
212
|
+
*
|
|
213
|
+
* @param options.account - the account that signs every transaction
|
|
214
|
+
* @param options.legs - the legs, in the order the wallet signs them
|
|
215
|
+
* @param options.readAllowance - reads an allowance on chain; see {@link AllowanceReader}
|
|
216
|
+
* @param options.swapVenues - the routers swaps may sign on, merged over the defaults; a swap whose router is in none of them throws
|
|
217
|
+
* @returns the ordered transactions, or the first leg that cannot be planned
|
|
218
|
+
* @throws when a swap leg's router is not in the swap venues
|
|
219
|
+
*/
|
|
220
|
+
export declare const planExecution: ({ account, legs, readAllowance, swapVenues, }: {
|
|
221
|
+
readonly account: Hex;
|
|
222
|
+
readonly legs: readonly ExecutionLeg[];
|
|
223
|
+
readonly readAllowance: AllowanceReader;
|
|
224
|
+
readonly swapVenues?: SwapVenues;
|
|
225
|
+
}) => Promise<ExecutionPlan>;
|
|
226
|
+
/**
|
|
227
|
+
* What the caller supplies for one signature section of a candidate. Each
|
|
228
|
+
* kind-specific group is read only when the section needs it.
|
|
229
|
+
*/
|
|
230
|
+
export type SectionExecutionInputs = {
|
|
231
|
+
/** The amount this section spends, in its first token's base units. */
|
|
232
|
+
readonly amountIn: bigint;
|
|
233
|
+
/** Where this section delivers: the reader's own wallet, or their chosen address on the last section. */
|
|
234
|
+
readonly recipient: Hex;
|
|
235
|
+
/** Needed by an omnibridge section. */
|
|
236
|
+
readonly omnibridge?: {
|
|
237
|
+
readonly isProd: boolean;
|
|
238
|
+
readonly assetLink: TokenBridgeInfo;
|
|
239
|
+
readonly delivery: DeliveryChoice;
|
|
240
|
+
readonly unwrap: boolean;
|
|
241
|
+
};
|
|
242
|
+
/** Needed by a PulseX swap section. */
|
|
243
|
+
readonly swap?: {
|
|
244
|
+
readonly slippageBasisPoints: bigint;
|
|
245
|
+
/**
|
|
246
|
+
* The unix-seconds deadline the router enforces. A section planned late
|
|
247
|
+
* should pass a fresh deadline, not one chosen before the crossing before it.
|
|
248
|
+
*/
|
|
249
|
+
readonly deadline: bigint;
|
|
250
|
+
/**
|
|
251
|
+
* A fresh quote of what the swap delivers for this section's `amountIn`,
|
|
252
|
+
* read just before signing (see {@link readPulseXSectionQuote}). When
|
|
253
|
+
* given, the slippage floor comes from it and not from the hop's
|
|
254
|
+
* search-time figure, so the hop may be an estimate. When absent, the
|
|
255
|
+
* floor comes from the hop, which must hold a real quote.
|
|
256
|
+
*/
|
|
257
|
+
readonly quotedAmountOut?: bigint;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Needed by an aggregator section: the LIVE quote asked for this reader's
|
|
261
|
+
* wallet, recipient and amount, with the request it answered. A route's
|
|
262
|
+
* display price is a dry probe and cannot be signed, so the candidate's own
|
|
263
|
+
* quote is never used in its place.
|
|
264
|
+
*/
|
|
265
|
+
readonly aggregator?: {
|
|
266
|
+
readonly quote: ConsolidatedQuote;
|
|
267
|
+
readonly request: ConsolidatedQuoteRequest;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
/** What {@link planCandidateExecution} reads. */
|
|
271
|
+
export type CandidateExecutionInputs = {
|
|
272
|
+
readonly candidate: RouteCandidate;
|
|
273
|
+
readonly account: Hex;
|
|
274
|
+
readonly readAllowance: AllowanceReader;
|
|
275
|
+
/** The resolver the candidate was built with; turns a plan's graph node into its token. */
|
|
276
|
+
readonly resolveToken: ResolveNodeToken;
|
|
277
|
+
/**
|
|
278
|
+
* The routers swaps may sign on, merged over the defaults: a chain named
|
|
279
|
+
* here replaces that chain's default list. Pass the SAME venues the route
|
|
280
|
+
* search used. A swap whose router is in none of them throws.
|
|
281
|
+
*/
|
|
282
|
+
readonly swapVenues?: SwapVenues;
|
|
283
|
+
/**
|
|
284
|
+
* The index of the section that `sections[0]` plans. It defaults to 0.
|
|
285
|
+
* Pass it to plan a later section after the earlier ones landed, with the
|
|
286
|
+
* amount that actually arrived and fresh swap figures. Then `sections[i]`
|
|
287
|
+
* plans section `firstSectionIndex + i`.
|
|
288
|
+
*/
|
|
289
|
+
readonly firstSectionIndex?: number;
|
|
290
|
+
/**
|
|
291
|
+
* One entry per section to plan now, first section first. Pass one entry
|
|
292
|
+
* to plan only the signature the reader can make now; pass more to plan
|
|
293
|
+
* later sections whose amounts are already known.
|
|
294
|
+
*/
|
|
295
|
+
readonly sections: readonly SectionExecutionInputs[];
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* The transactions for the planned sections of a candidate, or the first
|
|
299
|
+
* section that cannot be planned. Every section index is absolute: it counts
|
|
300
|
+
* from the first section of the candidate, not from `firstSectionIndex`.
|
|
301
|
+
*/
|
|
302
|
+
export type CandidateExecutionPlan = {
|
|
303
|
+
readonly kind: 'planned';
|
|
304
|
+
readonly transactions: readonly PlannedTx[];
|
|
305
|
+
/** One entry per omnibridge section planned; `legIndex` is the absolute section index. */
|
|
306
|
+
readonly deliveries: readonly PlannedDelivery[];
|
|
307
|
+
/** How many sections still follow the planned ones (after `firstSectionIndex + sections.length`). Each needs its own plan later. */
|
|
308
|
+
readonly remainingSectionCount: number;
|
|
309
|
+
} | {
|
|
310
|
+
readonly kind: 'refused';
|
|
311
|
+
readonly sectionIndex: number;
|
|
312
|
+
readonly refusal: ExecutionRefusal;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Plans the transactions for a chosen route candidate: the candidate
|
|
316
|
+
* `buildRouteCandidateFromPlan` returns for an engine plan (the interface's
|
|
317
|
+
* `buildCandidateFromEnginePlan`), or a candidate built without a plan.
|
|
318
|
+
*
|
|
319
|
+
* ONE SECTION IS ONE SIGNATURE. A plan's `signatures` groups its hops into
|
|
320
|
+
* sections; the section's first hop names its carrier. An omnibridge section
|
|
321
|
+
* becomes a crossing, a PulseX section a swap signed on its recorded path, a
|
|
322
|
+
* wrap section a wrap or unwrap, and any other wallet-signed carrier an
|
|
323
|
+
* aggregator deposit from the live quote the caller supplies. A section paid
|
|
324
|
+
* by hand has nothing to sign and is refused.
|
|
325
|
+
*
|
|
326
|
+
* A LATER SECTION CAN BE PLANNED ALONE. Pass `firstSectionIndex` to skip the
|
|
327
|
+
* sections that already landed. The wallet then plans the swap after the
|
|
328
|
+
* crossing arrived, from the amount that arrived, with a fresh
|
|
329
|
+
* `swap.quotedAmountOut` and a fresh `swap.deadline`. The slippage floor and the
|
|
330
|
+
* deadline are not fixed minutes before the swap is signed. Every safety check
|
|
331
|
+
* still applies to the later section: verified spenders, live quotes for
|
|
332
|
+
* aggregator sections, exact approvals.
|
|
333
|
+
*
|
|
334
|
+
* Every `sectionIndex` in a refusal and every `legIndex` in `deliveries` is
|
|
335
|
+
* the absolute section index.
|
|
336
|
+
*
|
|
337
|
+
* @param inputs - see {@link CandidateExecutionInputs}
|
|
338
|
+
* @returns the ordered transactions with the deliveries they buy, or the first section that cannot be planned
|
|
339
|
+
*/
|
|
340
|
+
export declare const planCandidateExecution: (inputs: CandidateExecutionInputs) => Promise<CandidateExecutionPlan>;
|
|
341
|
+
/**
|
|
342
|
+
* Reads a fresh quote for a PulseX section: what the router's `getAmountsOut`
|
|
343
|
+
* says the swap delivers for `amountIn`, along the exact path the swap signs
|
|
344
|
+
* ({@link pulseXSwapPathForHop}) on the edge's own router. A wallet passes the
|
|
345
|
+
* result as `swap.quotedAmountOut` just before it signs.
|
|
346
|
+
*
|
|
347
|
+
* @param options.hop - the swap hop; its recorded path and edge name what to read
|
|
348
|
+
* @param options.amountIn - the amount the swap spends, in base units
|
|
349
|
+
* @param options.client - a client that can call `readContract`
|
|
350
|
+
* @param options.swapVenues - the routers swaps may sign on, merged over the defaults
|
|
351
|
+
* @returns the amount the last token of the path delivers, or null when the hop records no path, the amount is not positive, or the read fails or returns nothing
|
|
352
|
+
* @throws when the hop records a path but its router is not in the swap venues
|
|
353
|
+
*/
|
|
354
|
+
export declare const readPulseXSectionQuote: ({ hop, amountIn, client, swapVenues, }: {
|
|
355
|
+
readonly hop: Pick<PlannedHop, "edge" | "outcome">;
|
|
356
|
+
readonly amountIn: bigint;
|
|
357
|
+
readonly client: Pick<PublicClient, "readContract">;
|
|
358
|
+
readonly swapVenues?: SwapVenues;
|
|
359
|
+
}) => Promise<bigint | null>;
|