@sun-protocol/sun-sdk-core 0.1.0-beta.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/NOTICE.md +5 -0
- package/README.md +34 -0
- package/dist/index.cjs +1594 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +628 -0
- package/dist/index.d.ts +628 -0
- package/dist/index.js +1494 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
3
|
+
import { BytesLike } from '@ethersproject/bytes';
|
|
4
|
+
|
|
5
|
+
declare enum ChainId {
|
|
6
|
+
MAINNET = 1,
|
|
7
|
+
GOERLI = 5,
|
|
8
|
+
SEPOLIA = 11155111,
|
|
9
|
+
OPTIMISM = 10,
|
|
10
|
+
OPTIMISM_GOERLI = 420,
|
|
11
|
+
OPTIMISM_SEPOLIA = 11155420,
|
|
12
|
+
ARBITRUM_ONE = 42161,
|
|
13
|
+
ARBITRUM_GOERLI = 421613,
|
|
14
|
+
ARBITRUM_SEPOLIA = 421614,
|
|
15
|
+
POLYGON = 137,
|
|
16
|
+
POLYGON_MUMBAI = 80001,
|
|
17
|
+
CELO = 42220,
|
|
18
|
+
CELO_ALFAJORES = 44787,
|
|
19
|
+
GNOSIS = 100,
|
|
20
|
+
MOONBEAM = 1284,
|
|
21
|
+
BNB = 56,
|
|
22
|
+
AVALANCHE = 43114,
|
|
23
|
+
BASE_GOERLI = 84531,
|
|
24
|
+
BASE_SEPOLIA = 84532,
|
|
25
|
+
BASE = 8453,
|
|
26
|
+
ZORA = 7777777,
|
|
27
|
+
ZORA_SEPOLIA = 999999999,
|
|
28
|
+
ROOTSTOCK = 30,
|
|
29
|
+
BLAST = 81457,
|
|
30
|
+
ZKSYNC = 324,
|
|
31
|
+
WORLDCHAIN = 480,
|
|
32
|
+
UNICHAIN_SEPOLIA = 1301,
|
|
33
|
+
UNICHAIN = 130,
|
|
34
|
+
MONAD_TESTNET = 10143,
|
|
35
|
+
SONEIUM = 1868,
|
|
36
|
+
MONAD = 143,
|
|
37
|
+
XLAYER = 196,
|
|
38
|
+
LINEA = 59144,
|
|
39
|
+
TEMPO = 4217,
|
|
40
|
+
MEGAETH = 4326,
|
|
41
|
+
ARC = 5042,
|
|
42
|
+
ROBINHOOD = 4663,
|
|
43
|
+
INK = 57073
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Average block time in seconds, per chain. Fractional values are intentional
|
|
47
|
+
* for sub-second chains so block-from-timestamp math stays accurate. Used as a
|
|
48
|
+
* single source of truth across UniswapX services and GPA to avoid drift.
|
|
49
|
+
*
|
|
50
|
+
* Values reflect each chain's most recent published target as of the last
|
|
51
|
+
* update; update here when chains alter their block cadence.
|
|
52
|
+
*/
|
|
53
|
+
declare const AVERAGE_BLOCK_TIMES_SECONDS: {
|
|
54
|
+
[chainId: number]: number;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Returns the average block time in seconds for a chain. Throws if the chain
|
|
58
|
+
* is not registered — callers must extend AVERAGE_BLOCK_TIMES_SECONDS rather
|
|
59
|
+
* than silently fall back to a mainnet-shaped default that would undercount
|
|
60
|
+
* blocks on faster chains.
|
|
61
|
+
*/
|
|
62
|
+
declare function getAverageBlockTimeSecs(chainId: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* Converts a wallclock duration in seconds to a block count for the given
|
|
65
|
+
* chain, rounding up so the resulting window fully covers the requested time.
|
|
66
|
+
* Throws if the chain is not registered in AVERAGE_BLOCK_TIMES_SECONDS.
|
|
67
|
+
*/
|
|
68
|
+
declare function secondsToBlocks(seconds: number, chainId: number): number;
|
|
69
|
+
declare const SUPPORTED_CHAINS: readonly [ChainId.MAINNET, ChainId.OPTIMISM, ChainId.OPTIMISM_GOERLI, ChainId.OPTIMISM_SEPOLIA, ChainId.ARBITRUM_ONE, ChainId.ARBITRUM_GOERLI, ChainId.ARBITRUM_SEPOLIA, ChainId.POLYGON, ChainId.POLYGON_MUMBAI, ChainId.GOERLI, ChainId.SEPOLIA, ChainId.CELO_ALFAJORES, ChainId.CELO, ChainId.BNB, ChainId.AVALANCHE, ChainId.BASE, ChainId.BASE_GOERLI, ChainId.BASE_SEPOLIA, ChainId.ZORA, ChainId.ZORA_SEPOLIA, ChainId.ROOTSTOCK, ChainId.BLAST, ChainId.ZKSYNC, ChainId.WORLDCHAIN, ChainId.UNICHAIN_SEPOLIA, ChainId.UNICHAIN, ChainId.MONAD_TESTNET, ChainId.SONEIUM, ChainId.MONAD, ChainId.XLAYER, ChainId.LINEA, ChainId.TEMPO, ChainId.MEGAETH, ChainId.ARC, ChainId.ROBINHOOD, ChainId.INK];
|
|
70
|
+
type SupportedChainsType = (typeof SUPPORTED_CHAINS)[number];
|
|
71
|
+
declare enum NativeCurrencyName {
|
|
72
|
+
ETHER = "ETH",
|
|
73
|
+
MATIC = "MATIC",
|
|
74
|
+
CELO = "CELO",
|
|
75
|
+
GNOSIS = "XDAI",
|
|
76
|
+
MOONBEAM = "GLMR",
|
|
77
|
+
BNB = "BNB",
|
|
78
|
+
AVAX = "AVAX",
|
|
79
|
+
ROOTSTOCK = "RBTC"
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
type AddressMap = {
|
|
83
|
+
[chainId: number]: string;
|
|
84
|
+
};
|
|
85
|
+
type ChainAddresses = {
|
|
86
|
+
v3CoreFactoryAddress: string;
|
|
87
|
+
multicallAddress: string;
|
|
88
|
+
quoterAddress: string;
|
|
89
|
+
v3MigratorAddress?: string;
|
|
90
|
+
nonfungiblePositionManagerAddress?: string;
|
|
91
|
+
tickLensAddress?: string;
|
|
92
|
+
swapRouter02Address?: string;
|
|
93
|
+
mixedRouteQuoterV1Address?: string;
|
|
94
|
+
mixedRouteQuoterV2Address?: string;
|
|
95
|
+
v4PoolManagerAddress?: string;
|
|
96
|
+
v4PositionManagerAddress?: string;
|
|
97
|
+
v4StateView?: string;
|
|
98
|
+
v4QuoterAddress?: string;
|
|
99
|
+
permissionedV4PositionManagerAddress?: string;
|
|
100
|
+
};
|
|
101
|
+
declare const UNI_ADDRESSES: AddressMap;
|
|
102
|
+
declare const UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS = "0x8B799381ac40b838BBA4131ffB26197C432AFe78";
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated use V2_FACTORY_ADDRESSES instead
|
|
105
|
+
*/
|
|
106
|
+
declare const V2_FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
|
|
107
|
+
declare const V2_FACTORY_ADDRESSES: AddressMap;
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated use V2_ROUTER_ADDRESSES instead
|
|
110
|
+
*/
|
|
111
|
+
declare const V2_ROUTER_ADDRESS = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
|
|
112
|
+
declare const V2_ROUTER_ADDRESSES: AddressMap;
|
|
113
|
+
declare const CHAIN_TO_ADDRESSES_MAP: Record<SupportedChainsType, ChainAddresses>;
|
|
114
|
+
declare const V3_CORE_FACTORY_ADDRESSES: AddressMap;
|
|
115
|
+
declare const V3_MIGRATOR_ADDRESSES: AddressMap;
|
|
116
|
+
declare const MULTICALL_ADDRESSES: AddressMap;
|
|
117
|
+
/**
|
|
118
|
+
* The oldest V0 governance address
|
|
119
|
+
*/
|
|
120
|
+
declare const GOVERNANCE_ALPHA_V0_ADDRESSES: AddressMap;
|
|
121
|
+
/**
|
|
122
|
+
* The older V1 governance address
|
|
123
|
+
*/
|
|
124
|
+
declare const GOVERNANCE_ALPHA_V1_ADDRESSES: AddressMap;
|
|
125
|
+
/**
|
|
126
|
+
* The latest governor bravo that is currently admin of timelock
|
|
127
|
+
*/
|
|
128
|
+
declare const GOVERNANCE_BRAVO_ADDRESSES: AddressMap;
|
|
129
|
+
declare const TIMELOCK_ADDRESSES: AddressMap;
|
|
130
|
+
declare const MERKLE_DISTRIBUTOR_ADDRESS: AddressMap;
|
|
131
|
+
declare const ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap;
|
|
132
|
+
declare const QUOTER_ADDRESSES: AddressMap;
|
|
133
|
+
declare const NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: AddressMap;
|
|
134
|
+
declare const ENS_REGISTRAR_ADDRESSES: AddressMap;
|
|
135
|
+
declare const SOCKS_CONTROLLER_ADDRESSES: AddressMap;
|
|
136
|
+
declare const TICK_LENS_ADDRESSES: AddressMap;
|
|
137
|
+
declare const MIXED_ROUTE_QUOTER_V1_ADDRESSES: AddressMap;
|
|
138
|
+
declare const SWAP_ROUTER_02_ADDRESSES: (chainId: number) => string;
|
|
139
|
+
|
|
140
|
+
type BigintIsh = JSBI | string | number;
|
|
141
|
+
declare enum TradeType {
|
|
142
|
+
EXACT_INPUT = 0,
|
|
143
|
+
EXACT_OUTPUT = 1
|
|
144
|
+
}
|
|
145
|
+
declare enum Rounding {
|
|
146
|
+
ROUND_DOWN = 0,
|
|
147
|
+
ROUND_HALF_UP = 1,
|
|
148
|
+
ROUND_UP = 2
|
|
149
|
+
}
|
|
150
|
+
declare const MaxUint256: JSBI;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Represents an ERC20 token with a unique address and some metadata.
|
|
154
|
+
*/
|
|
155
|
+
declare class Token extends BaseCurrency {
|
|
156
|
+
readonly isNative: false;
|
|
157
|
+
readonly isToken: true;
|
|
158
|
+
/**
|
|
159
|
+
* The contract address on the chain on which this token lives
|
|
160
|
+
*/
|
|
161
|
+
readonly address: string;
|
|
162
|
+
/**
|
|
163
|
+
* Relevant for fee-on-transfer (FOT) token taxes,
|
|
164
|
+
* Not every ERC20 token is FOT token, so this field is optional
|
|
165
|
+
*/
|
|
166
|
+
readonly buyFeeBps?: BigNumber | undefined;
|
|
167
|
+
readonly sellFeeBps?: BigNumber | undefined;
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param chainId {@link BaseCurrency#chainId}
|
|
171
|
+
* @param address The contract address on the chain on which this token lives
|
|
172
|
+
* @param decimals {@link BaseCurrency#decimals}
|
|
173
|
+
* @param symbol {@link BaseCurrency#symbol}
|
|
174
|
+
* @param name {@link BaseCurrency#name}
|
|
175
|
+
* @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
|
|
176
|
+
* @param buyFeeBps Buy fee tax for FOT tokens, in basis points
|
|
177
|
+
* @param sellFeeBps Sell fee tax for FOT tokens, in basis points
|
|
178
|
+
*/
|
|
179
|
+
constructor(chainId: number, address: string, decimals: number, symbol?: string, name?: string, bypassChecksum?: boolean, buyFeeBps?: BigNumber, sellFeeBps?: BigNumber);
|
|
180
|
+
/**
|
|
181
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
|
182
|
+
* @param other other token to compare
|
|
183
|
+
*/
|
|
184
|
+
equals(other: Currency): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Returns true if the address of this token sorts before the address of the other token
|
|
187
|
+
* @param other other token to compare
|
|
188
|
+
* @throws if the tokens have the same address
|
|
189
|
+
* @throws if the tokens are on different chains
|
|
190
|
+
*/
|
|
191
|
+
sortsBefore(other: Token): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Return this token, which does not need to be wrapped
|
|
194
|
+
*/
|
|
195
|
+
get wrapped(): Token;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
|
|
200
|
+
*/
|
|
201
|
+
declare abstract class BaseCurrency {
|
|
202
|
+
/**
|
|
203
|
+
* Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
|
|
204
|
+
*/
|
|
205
|
+
abstract readonly isNative: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Returns whether the currency is a token that is usable in Uniswap without wrapping
|
|
208
|
+
*/
|
|
209
|
+
abstract readonly isToken: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* The chain ID on which this currency resides
|
|
212
|
+
*/
|
|
213
|
+
readonly chainId: number;
|
|
214
|
+
/**
|
|
215
|
+
* The decimals used in representing currency amounts
|
|
216
|
+
*/
|
|
217
|
+
readonly decimals: number;
|
|
218
|
+
/**
|
|
219
|
+
* The symbol of the currency, i.e. a short textual non-unique identifier
|
|
220
|
+
*/
|
|
221
|
+
readonly symbol?: string | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* The name of the currency, i.e. a descriptive textual non-unique identifier
|
|
224
|
+
*/
|
|
225
|
+
readonly name?: string | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* Constructs an instance of the base class `BaseCurrency`.
|
|
228
|
+
* @param chainId the chain ID on which this currency resides
|
|
229
|
+
* @param decimals decimals of the currency
|
|
230
|
+
* @param symbol symbol of the currency
|
|
231
|
+
* @param name of the currency
|
|
232
|
+
*/
|
|
233
|
+
protected constructor(chainId: number, decimals: number, symbol?: string, name?: string);
|
|
234
|
+
/**
|
|
235
|
+
* Returns whether this currency is functionally equivalent to the other currency
|
|
236
|
+
* @param other the other currency
|
|
237
|
+
*/
|
|
238
|
+
abstract equals(other: Currency): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Return the wrapped version of this currency that can be used with the Uniswap contracts. Currencies must
|
|
241
|
+
* implement this to be used in Uniswap
|
|
242
|
+
*/
|
|
243
|
+
abstract get wrapped(): Token;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Represents the native currency of the chain on which it resides, e.g.
|
|
248
|
+
*/
|
|
249
|
+
declare abstract class NativeCurrency extends BaseCurrency {
|
|
250
|
+
readonly isNative: true;
|
|
251
|
+
readonly isToken: false;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
type Currency = NativeCurrency | Token;
|
|
255
|
+
|
|
256
|
+
declare class Fraction {
|
|
257
|
+
readonly numerator: JSBI;
|
|
258
|
+
readonly denominator: JSBI;
|
|
259
|
+
constructor(numerator: BigintIsh, denominator?: BigintIsh);
|
|
260
|
+
private static tryParseFraction;
|
|
261
|
+
get quotient(): JSBI;
|
|
262
|
+
get remainder(): Fraction;
|
|
263
|
+
invert(): Fraction;
|
|
264
|
+
add(other: Fraction | BigintIsh): Fraction;
|
|
265
|
+
subtract(other: Fraction | BigintIsh): Fraction;
|
|
266
|
+
lessThan(other: Fraction | BigintIsh): boolean;
|
|
267
|
+
equalTo(other: Fraction | BigintIsh): boolean;
|
|
268
|
+
greaterThan(other: Fraction | BigintIsh): boolean;
|
|
269
|
+
multiply(other: Fraction | BigintIsh): Fraction;
|
|
270
|
+
divide(other: Fraction | BigintIsh): Fraction;
|
|
271
|
+
toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
|
|
272
|
+
toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
|
|
273
|
+
/**
|
|
274
|
+
* Helper method for converting any super class back to a fraction
|
|
275
|
+
*/
|
|
276
|
+
get asFraction(): Fraction;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
declare class CurrencyAmount<T extends Currency> extends Fraction {
|
|
280
|
+
readonly currency: T;
|
|
281
|
+
readonly decimalScale: JSBI;
|
|
282
|
+
/**
|
|
283
|
+
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
|
284
|
+
* @param currency the currency in the amount
|
|
285
|
+
* @param rawAmount the raw token or ether amount
|
|
286
|
+
*/
|
|
287
|
+
static fromRawAmount<T extends Currency>(currency: T, rawAmount: BigintIsh): CurrencyAmount<T>;
|
|
288
|
+
/**
|
|
289
|
+
* Construct a currency amount with a denominator that is not equal to 1
|
|
290
|
+
* @param currency the currency
|
|
291
|
+
* @param numerator the numerator of the fractional token amount
|
|
292
|
+
* @param denominator the denominator of the fractional token amount
|
|
293
|
+
*/
|
|
294
|
+
static fromFractionalAmount<T extends Currency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount<T>;
|
|
295
|
+
protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
|
|
296
|
+
add(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
297
|
+
subtract(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
298
|
+
multiply(other: Fraction | BigintIsh): CurrencyAmount<T>;
|
|
299
|
+
divide(other: Fraction | BigintIsh): CurrencyAmount<T>;
|
|
300
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
301
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
302
|
+
toExact(format?: object): string;
|
|
303
|
+
get wrapped(): CurrencyAmount<Token>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
declare class Percent extends Fraction {
|
|
307
|
+
/**
|
|
308
|
+
* This boolean prevents a fraction from being interpreted as a Percent
|
|
309
|
+
*/
|
|
310
|
+
readonly isPercent: true;
|
|
311
|
+
add(other: Fraction | BigintIsh): Percent;
|
|
312
|
+
subtract(other: Fraction | BigintIsh): Percent;
|
|
313
|
+
multiply(other: Fraction | BigintIsh): Percent;
|
|
314
|
+
divide(other: Fraction | BigintIsh): Percent;
|
|
315
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
316
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
|
|
320
|
+
readonly baseCurrency: TBase;
|
|
321
|
+
readonly quoteCurrency: TQuote;
|
|
322
|
+
readonly scalar: Fraction;
|
|
323
|
+
/**
|
|
324
|
+
* Construct a price, either with the base and quote currency amount, or the
|
|
325
|
+
* @param args
|
|
326
|
+
*/
|
|
327
|
+
constructor(...args: [TBase, TQuote, BigintIsh, BigintIsh] | [{
|
|
328
|
+
baseAmount: CurrencyAmount<TBase>;
|
|
329
|
+
quoteAmount: CurrencyAmount<TQuote>;
|
|
330
|
+
}]);
|
|
331
|
+
/**
|
|
332
|
+
* Flip the price, switching the base and quote currency
|
|
333
|
+
*/
|
|
334
|
+
invert(): Price<TQuote, TBase>;
|
|
335
|
+
/**
|
|
336
|
+
* Multiply the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency
|
|
337
|
+
* @param other the other price
|
|
338
|
+
*/
|
|
339
|
+
multiply<TOtherQuote extends Currency>(other: Price<TQuote, TOtherQuote>): Price<TBase, TOtherQuote>;
|
|
340
|
+
/**
|
|
341
|
+
* Return the amount of quote currency corresponding to a given amount of the base currency
|
|
342
|
+
* @param currencyAmount the amount of base currency to quote against the price
|
|
343
|
+
*/
|
|
344
|
+
quote(currencyAmount: CurrencyAmount<TBase>): CurrencyAmount<TQuote>;
|
|
345
|
+
/**
|
|
346
|
+
* Get the value scaled by decimals for formatting
|
|
347
|
+
* @private
|
|
348
|
+
*/
|
|
349
|
+
private get adjustedForDecimals();
|
|
350
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
351
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Ether keeps the upstream sdk-core class/export shape while representing native TRX for Sun SDK chains.
|
|
356
|
+
*/
|
|
357
|
+
declare class Ether extends NativeCurrency {
|
|
358
|
+
protected constructor(chainId: number);
|
|
359
|
+
get wrapped(): Token;
|
|
360
|
+
private static _etherCache;
|
|
361
|
+
static onChain(chainId: number): Ether;
|
|
362
|
+
equals(other: Currency): boolean;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Known WTRX implementation addresses, used in our implementation of Ether#wrapped.
|
|
367
|
+
* TRON base58 addresses are represented here as EVM-style 20-byte addresses so Token remains sdk-core compatible.
|
|
368
|
+
*/
|
|
369
|
+
declare const WETH9: {
|
|
370
|
+
[chainId: number]: Token;
|
|
371
|
+
};
|
|
372
|
+
declare const WTRX: {
|
|
373
|
+
[chainId: number]: Token;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Returns the percent difference between the mid price and the execution price, i.e. price impact.
|
|
378
|
+
* @param midPrice mid price before the trade
|
|
379
|
+
* @param inputAmount the input amount of the trade
|
|
380
|
+
* @param outputAmount the output amount of the trade
|
|
381
|
+
*/
|
|
382
|
+
declare function computePriceImpact<TBase extends Currency, TQuote extends Currency>(midPrice: Price<TBase, TQuote>, inputAmount: CurrencyAmount<TBase>, outputAmount: CurrencyAmount<TQuote>): Percent;
|
|
383
|
+
|
|
384
|
+
declare function computeZksyncCreate2Address(sender: string, bytecodeHash: BytesLike, salt: BytesLike, input?: BytesLike): string;
|
|
385
|
+
|
|
386
|
+
declare function sortedInsert<T>(items: T[], add: T, maxSize: number, comparator: (a: T, b: T) => number): T | null;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Computes floor(sqrt(value))
|
|
390
|
+
* @param value the value for which to compute the square root, rounded down
|
|
391
|
+
*/
|
|
392
|
+
declare function sqrt(value: JSBI): JSBI;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Validates an address and returns the parsed (checksummed) version of that address
|
|
396
|
+
* @param address the unchecksummed hex address
|
|
397
|
+
*/
|
|
398
|
+
declare function validateAndParseAddress(address: string): string;
|
|
399
|
+
|
|
400
|
+
type TronAddress = string & {
|
|
401
|
+
readonly __tronAddress: unique symbol;
|
|
402
|
+
};
|
|
403
|
+
type TronHexAddress = string & {
|
|
404
|
+
readonly __tronHexAddress: unique symbol;
|
|
405
|
+
};
|
|
406
|
+
interface TronAddressCodec {
|
|
407
|
+
toHex(address: TronAddress): TronHexAddress | string;
|
|
408
|
+
fromHex(hex: TronHexAddress): TronAddress | string;
|
|
409
|
+
}
|
|
410
|
+
declare const TRON_ZERO_ADDRESS: TronAddress;
|
|
411
|
+
declare function isTronBase58Address(value: string): value is TronAddress;
|
|
412
|
+
declare function isTronHexAddress(value: string): value is TronHexAddress;
|
|
413
|
+
declare function assertTronAddress(value: string, label?: string): TronAddress;
|
|
414
|
+
declare function assertTronHexAddress(value: string, label?: string): TronHexAddress;
|
|
415
|
+
declare function toTronHexAddress(address: TronAddress | string, codec: TronAddressCodec): TronHexAddress;
|
|
416
|
+
declare function toTronBase58Address(hex: TronHexAddress | string, codec: TronAddressCodec): TronAddress;
|
|
417
|
+
|
|
418
|
+
declare function parseUnits(value: string, decimals: number): bigint;
|
|
419
|
+
declare function formatUnits(value: bigint, decimals: number): string;
|
|
420
|
+
|
|
421
|
+
declare const SDK_ERROR_CODES: {
|
|
422
|
+
readonly SDK_INVALID_ARGUMENT: "SDK_INVALID_ARGUMENT";
|
|
423
|
+
readonly SDK_UNSUPPORTED_NETWORK: "SDK_UNSUPPORTED_NETWORK";
|
|
424
|
+
readonly SDK_WALLET_CAPABILITY_ERROR: "SDK_WALLET_CAPABILITY_ERROR";
|
|
425
|
+
readonly SDK_WALLET_ACCOUNT_MISMATCH: "SDK_WALLET_ACCOUNT_MISMATCH";
|
|
426
|
+
readonly SDK_WALLET_REJECTED: "SDK_WALLET_REJECTED";
|
|
427
|
+
readonly SDK_RUNTIME_ERROR: "SDK_RUNTIME_ERROR";
|
|
428
|
+
readonly SDK_API_ERROR: "SDK_API_ERROR";
|
|
429
|
+
readonly SDK_NO_ROUTE: "SDK_NO_ROUTE";
|
|
430
|
+
readonly SDK_CONTRACT_ERROR: "SDK_CONTRACT_ERROR";
|
|
431
|
+
readonly SDK_TX_BUILD_ERROR: "SDK_TX_BUILD_ERROR";
|
|
432
|
+
readonly SDK_TX_BROADCAST_ERROR: "SDK_TX_BROADCAST_ERROR";
|
|
433
|
+
};
|
|
434
|
+
type SDKErrorCode = keyof typeof SDK_ERROR_CODES;
|
|
435
|
+
type Network = 'mainnet' | 'nile';
|
|
436
|
+
declare class SDKError<TCode extends string = SDKErrorCode> extends Error {
|
|
437
|
+
readonly code: TCode;
|
|
438
|
+
readonly context: Record<string, unknown> | undefined;
|
|
439
|
+
constructor(code: TCode, message: string, context?: Record<string, unknown>);
|
|
440
|
+
}
|
|
441
|
+
declare function normalizeSDKError<TCode extends string>(error: unknown, code: TCode, message: string, context?: Record<string, unknown>): SDKError<string>;
|
|
442
|
+
declare function sdkInvariant<TCode extends string>(condition: unknown, code: TCode, message: string, context?: Record<string, unknown>): asserts condition;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Protocol identifiers intentionally remain open so protocol packages can
|
|
446
|
+
* publish stable identifiers without coupling core to every integration.
|
|
447
|
+
*/
|
|
448
|
+
type ProtocolId = string;
|
|
449
|
+
type TransactionIntentDomain = 'swap' | 'liquidity' | 'position' | 'pump' | 'migration';
|
|
450
|
+
interface TransactionIntentScope<Domain extends TransactionIntentDomain = TransactionIntentDomain> {
|
|
451
|
+
readonly domain: Domain;
|
|
452
|
+
readonly protocol: ProtocolId;
|
|
453
|
+
readonly operation?: string;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* A notification-ready token amount. `value` is a non-localized decimal in
|
|
457
|
+
* token units; presentation concerns such as grouping belong to consumers.
|
|
458
|
+
*/
|
|
459
|
+
interface IntentAmount {
|
|
460
|
+
readonly value: string;
|
|
461
|
+
readonly symbol: string;
|
|
462
|
+
}
|
|
463
|
+
type TransactionIntent = {
|
|
464
|
+
readonly kind: 'approve';
|
|
465
|
+
readonly scope: TransactionIntentScope;
|
|
466
|
+
readonly tokenSymbol: string;
|
|
467
|
+
} | {
|
|
468
|
+
readonly kind: 'swap';
|
|
469
|
+
readonly scope: TransactionIntentScope<'swap'>;
|
|
470
|
+
readonly from: IntentAmount;
|
|
471
|
+
readonly to: IntentAmount;
|
|
472
|
+
readonly recipient?: TronAddress;
|
|
473
|
+
} | {
|
|
474
|
+
readonly kind: 'wrap' | 'unwrap';
|
|
475
|
+
readonly scope: TransactionIntentScope<'swap'>;
|
|
476
|
+
readonly amount: string;
|
|
477
|
+
} | {
|
|
478
|
+
readonly kind: 'create-pool';
|
|
479
|
+
readonly scope: TransactionIntentScope<'liquidity'>;
|
|
480
|
+
readonly poolId: string;
|
|
481
|
+
} | {
|
|
482
|
+
readonly kind: 'add-liquidity';
|
|
483
|
+
readonly scope: TransactionIntentScope<'liquidity'>;
|
|
484
|
+
readonly positionId?: string;
|
|
485
|
+
} | {
|
|
486
|
+
readonly kind: 'remove-liquidity';
|
|
487
|
+
readonly scope: TransactionIntentScope<'liquidity' | 'position'>;
|
|
488
|
+
readonly positionId?: string;
|
|
489
|
+
} | {
|
|
490
|
+
readonly kind: 'collect-fees';
|
|
491
|
+
readonly scope: TransactionIntentScope<'position'>;
|
|
492
|
+
readonly positionId: string;
|
|
493
|
+
} | {
|
|
494
|
+
readonly kind: 'pump-buy' | 'pump-sell';
|
|
495
|
+
readonly scope: TransactionIntentScope<'pump'>;
|
|
496
|
+
readonly token: TronAddress;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
type TransactionActionType = 'approve' | 'typed-data-signature' | 'contract-call' | 'deferred-contract-call' | 'http-request';
|
|
500
|
+
type TransactionActionStatus = 'planned';
|
|
501
|
+
type TransactionActionExecutor = 'runtime' | 'wallet-signature' | 'api';
|
|
502
|
+
/**
|
|
503
|
+
* Receipt level required before an action is considered ready for its dependents.
|
|
504
|
+
*
|
|
505
|
+
* - `included`: the transaction has been included and executed in the FullNode's
|
|
506
|
+
* latest head. This is suitable for dependencies such as approve -> swap, but
|
|
507
|
+
* the containing block is not yet irreversible and may theoretically be
|
|
508
|
+
* reorganized.
|
|
509
|
+
* - `solidified`: the receipt is visible from the SolidityNode's solidified
|
|
510
|
+
* state. This is irreversible/final, but normally takes materially longer.
|
|
511
|
+
*/
|
|
512
|
+
type TransactionReceiptFinality = 'included' | 'solidified';
|
|
513
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
514
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
515
|
+
interface JsonObject {
|
|
516
|
+
readonly [key: string]: JsonValue;
|
|
517
|
+
}
|
|
518
|
+
type JsonArray = readonly JsonValue[];
|
|
519
|
+
interface ContractParameterComponent {
|
|
520
|
+
readonly name?: string;
|
|
521
|
+
readonly type: string;
|
|
522
|
+
readonly components?: readonly ContractParameterComponent[];
|
|
523
|
+
}
|
|
524
|
+
interface ContractParameter {
|
|
525
|
+
readonly type: string;
|
|
526
|
+
readonly value: unknown;
|
|
527
|
+
readonly components?: readonly ContractParameterComponent[];
|
|
528
|
+
}
|
|
529
|
+
interface TokenRequirement {
|
|
530
|
+
readonly token: TronAddress;
|
|
531
|
+
readonly amount: string;
|
|
532
|
+
readonly spender: TronAddress;
|
|
533
|
+
readonly approval: 'approve-or-permit2';
|
|
534
|
+
}
|
|
535
|
+
interface HttpRequestSpec {
|
|
536
|
+
readonly method: 'GET' | 'POST';
|
|
537
|
+
readonly url: string;
|
|
538
|
+
readonly headers?: Record<string, string>;
|
|
539
|
+
readonly body?: unknown;
|
|
540
|
+
}
|
|
541
|
+
interface BaseTransactionAction {
|
|
542
|
+
readonly id: string;
|
|
543
|
+
readonly type: TransactionActionType;
|
|
544
|
+
readonly status: TransactionActionStatus;
|
|
545
|
+
readonly execute: TransactionActionExecutor;
|
|
546
|
+
/**
|
|
547
|
+
* Wait for this receipt level before continuing. When omitted, successful
|
|
548
|
+
* broadcast is sufficient and execution continues without polling a receipt.
|
|
549
|
+
*/
|
|
550
|
+
readonly waitForReceipt?: TransactionReceiptFinality;
|
|
551
|
+
readonly metadata?: Record<string, unknown>;
|
|
552
|
+
}
|
|
553
|
+
interface ContractCallAction extends BaseTransactionAction {
|
|
554
|
+
readonly type: 'contract-call' | 'approve';
|
|
555
|
+
readonly execute: 'runtime';
|
|
556
|
+
readonly intent?: TransactionIntent;
|
|
557
|
+
readonly target: TronAddress;
|
|
558
|
+
readonly functionSelector: string;
|
|
559
|
+
readonly parameters?: readonly ContractParameter[];
|
|
560
|
+
readonly abiFunction?: unknown;
|
|
561
|
+
readonly rawParameter?: string;
|
|
562
|
+
readonly callValue?: bigint;
|
|
563
|
+
readonly feeLimit?: number;
|
|
564
|
+
readonly tokenRequirements?: readonly TokenRequirement[];
|
|
565
|
+
}
|
|
566
|
+
interface DeferredContractCallMaterialization {
|
|
567
|
+
readonly kind: string;
|
|
568
|
+
readonly data: JsonObject;
|
|
569
|
+
}
|
|
570
|
+
interface DeferredContractCallAction extends BaseTransactionAction {
|
|
571
|
+
readonly type: 'deferred-contract-call';
|
|
572
|
+
readonly execute: 'runtime';
|
|
573
|
+
readonly intent?: TransactionIntent;
|
|
574
|
+
readonly materialization: DeferredContractCallMaterialization;
|
|
575
|
+
}
|
|
576
|
+
interface TypedDataSignatureAction extends BaseTransactionAction {
|
|
577
|
+
readonly type: 'typed-data-signature';
|
|
578
|
+
readonly execute: 'wallet-signature';
|
|
579
|
+
readonly typedData: unknown;
|
|
580
|
+
}
|
|
581
|
+
interface HttpRequestAction extends BaseTransactionAction {
|
|
582
|
+
readonly type: 'http-request';
|
|
583
|
+
readonly execute: 'api';
|
|
584
|
+
readonly request: HttpRequestSpec;
|
|
585
|
+
}
|
|
586
|
+
type TransactionAction = ContractCallAction | DeferredContractCallAction | TypedDataSignatureAction | HttpRequestAction;
|
|
587
|
+
declare function createContractCallAction(input: {
|
|
588
|
+
id: string;
|
|
589
|
+
target: TronAddress;
|
|
590
|
+
functionSelector: string;
|
|
591
|
+
parameters?: readonly ContractParameter[];
|
|
592
|
+
abiFunction?: unknown;
|
|
593
|
+
rawParameter?: string;
|
|
594
|
+
callValue?: bigint;
|
|
595
|
+
feeLimit?: number;
|
|
596
|
+
tokenRequirements?: readonly TokenRequirement[];
|
|
597
|
+
waitForReceipt?: TransactionReceiptFinality;
|
|
598
|
+
metadata?: Record<string, unknown>;
|
|
599
|
+
intent?: TransactionIntent;
|
|
600
|
+
}): ContractCallAction;
|
|
601
|
+
declare function createApproveAction(input: {
|
|
602
|
+
id: string;
|
|
603
|
+
target: TronAddress;
|
|
604
|
+
spender: string;
|
|
605
|
+
amount: string;
|
|
606
|
+
feeLimit?: number;
|
|
607
|
+
metadata?: Record<string, unknown>;
|
|
608
|
+
intent?: TransactionIntent;
|
|
609
|
+
}): ContractCallAction;
|
|
610
|
+
declare function createDeferredContractCallAction(input: {
|
|
611
|
+
id: string;
|
|
612
|
+
materialization: DeferredContractCallMaterialization;
|
|
613
|
+
waitForReceipt?: TransactionReceiptFinality;
|
|
614
|
+
metadata?: Record<string, unknown>;
|
|
615
|
+
intent?: TransactionIntent;
|
|
616
|
+
}): DeferredContractCallAction;
|
|
617
|
+
declare function createTypedDataSignatureAction(input: {
|
|
618
|
+
id: string;
|
|
619
|
+
typedData: unknown;
|
|
620
|
+
metadata?: Record<string, unknown>;
|
|
621
|
+
}): TypedDataSignatureAction;
|
|
622
|
+
declare function createHttpRequestAction(input: {
|
|
623
|
+
id: string;
|
|
624
|
+
request: HttpRequestSpec;
|
|
625
|
+
metadata?: Record<string, unknown>;
|
|
626
|
+
}): HttpRequestAction;
|
|
627
|
+
|
|
628
|
+
export { ARGENT_WALLET_DETECTOR_ADDRESS, AVERAGE_BLOCK_TIMES_SECONDS, type BaseTransactionAction, type BigintIsh, CHAIN_TO_ADDRESSES_MAP, ChainId, type ContractCallAction, type ContractParameter, type ContractParameterComponent, type Currency, CurrencyAmount, type DeferredContractCallAction, type DeferredContractCallMaterialization, ENS_REGISTRAR_ADDRESSES, Ether, Fraction, GOVERNANCE_ALPHA_V0_ADDRESSES, GOVERNANCE_ALPHA_V1_ADDRESSES, GOVERNANCE_BRAVO_ADDRESSES, type HttpRequestAction, type HttpRequestSpec, type IntentAmount, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, MERKLE_DISTRIBUTOR_ADDRESS, MIXED_ROUTE_QUOTER_V1_ADDRESSES, MULTICALL_ADDRESSES, MaxUint256, NONFUNGIBLE_POSITION_MANAGER_ADDRESSES, NativeCurrency, NativeCurrencyName, type Network, Percent, Price, type ProtocolId, QUOTER_ADDRESSES, Rounding, SDKError, type SDKErrorCode, SDK_ERROR_CODES, SOCKS_CONTROLLER_ADDRESSES, SUPPORTED_CHAINS, SWAP_ROUTER_02_ADDRESSES, type SupportedChainsType, TICK_LENS_ADDRESSES, TIMELOCK_ADDRESSES, TRON_ZERO_ADDRESS, Token, type TokenRequirement, TradeType, type TransactionAction, type TransactionActionExecutor, type TransactionActionStatus, type TransactionActionType, type TransactionIntent, type TransactionIntentDomain, type TransactionIntentScope, type TransactionReceiptFinality, type TronAddress, type TronAddressCodec, type TronHexAddress, type TypedDataSignatureAction, UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS, UNI_ADDRESSES, V2_FACTORY_ADDRESS, V2_FACTORY_ADDRESSES, V2_ROUTER_ADDRESS, V2_ROUTER_ADDRESSES, V3_CORE_FACTORY_ADDRESSES, V3_MIGRATOR_ADDRESSES, WETH9, WTRX, assertTronAddress, assertTronHexAddress, computePriceImpact, computeZksyncCreate2Address, createApproveAction, createContractCallAction, createDeferredContractCallAction, createHttpRequestAction, createTypedDataSignatureAction, formatUnits, getAverageBlockTimeSecs, isTronBase58Address, isTronHexAddress, normalizeSDKError, parseUnits, sdkInvariant, secondsToBlocks, sortedInsert, sqrt, toTronBase58Address, toTronHexAddress, validateAndParseAddress };
|