@gala-chain/gswap-sdk 0.0.9 → 1.0.0-rc.3
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 +63 -35
- package/dist/browser/index.js +2 -24
- package/dist/browser/index.js.map +1 -1
- package/dist/index.cjs +2033 -1345
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1008 -774
- package/dist/index.d.ts +1008 -774
- package/dist/index.mjs +2012 -1337
- package/dist/index.mjs.map +1 -1
- package/package.json +37 -26
package/dist/index.d.ts
CHANGED
|
@@ -1,140 +1,213 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
type: string;
|
|
19
|
-
additionalKey: string;
|
|
3
|
+
/** Pool metadata returned by GalaChainDex. */
|
|
4
|
+
interface PoolInfo {
|
|
5
|
+
token0: string;
|
|
6
|
+
token1: string;
|
|
7
|
+
fee: number;
|
|
8
|
+
name?: string;
|
|
9
|
+
token0Key: string;
|
|
10
|
+
token1Key: string;
|
|
11
|
+
tickSpacing: number;
|
|
12
|
+
protocolFees: number;
|
|
13
|
+
tradingFees: number;
|
|
14
|
+
creator?: string;
|
|
15
|
+
isPrivate?: boolean;
|
|
16
|
+
flippedFromRequest?: boolean;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
18
|
+
/** Pool summary returned by the backend pool-list route. */
|
|
19
|
+
interface PoolListInfo {
|
|
20
|
+
contractVersion: 'v2';
|
|
21
|
+
token0: string;
|
|
22
|
+
token1: string;
|
|
23
|
+
token0CompositeKey?: string | undefined;
|
|
24
|
+
token1CompositeKey?: string | undefined;
|
|
25
|
+
fee: number;
|
|
26
|
+
poolName: string;
|
|
27
|
+
poolRef: string;
|
|
28
|
+
tickSpacing: number;
|
|
29
|
+
protocolFees: number;
|
|
30
|
+
tradingFees: number;
|
|
31
|
+
creator?: string | undefined;
|
|
32
|
+
price?: string | undefined;
|
|
33
|
+
sqrtPrice?: string | undefined;
|
|
34
|
+
tick?: number | undefined;
|
|
35
|
+
token0Tvl?: string | undefined;
|
|
36
|
+
token1Tvl?: string | undefined;
|
|
37
|
+
tvlUsd?: number | undefined;
|
|
38
|
+
volume1d?: number | undefined;
|
|
39
|
+
volume7d?: number | undefined;
|
|
40
|
+
volume30d?: number | undefined;
|
|
41
|
+
trades1d?: number | undefined;
|
|
42
|
+
fee24h?: number | undefined;
|
|
43
|
+
apr1d?: number | undefined;
|
|
44
|
+
token0Price?: number | undefined;
|
|
45
|
+
token1Price?: number | undefined;
|
|
47
46
|
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
/** Current pool price state. */
|
|
48
|
+
interface Slot0 {
|
|
49
|
+
token0: string;
|
|
50
|
+
token1: string;
|
|
51
|
+
fee: number;
|
|
52
|
+
price: string;
|
|
53
|
+
sqrtPrice: string;
|
|
54
|
+
tick: number;
|
|
55
|
+
flippedFromRequest?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** Full raw composite pool snapshot returned by the contract. */
|
|
58
|
+
interface CompositePool {
|
|
59
|
+
pool: PoolInfo;
|
|
60
|
+
currentTradingPrice: Slot0;
|
|
61
|
+
initializedTicks?: Array<{
|
|
62
|
+
pool: string;
|
|
63
|
+
lexigraphicTickIndex: string;
|
|
64
|
+
}>;
|
|
65
|
+
reverseInitializedTicks?: Array<{
|
|
66
|
+
pool: string;
|
|
67
|
+
lexigraphicTickIndex: string;
|
|
68
|
+
}>;
|
|
69
|
+
positionBoundaries?: unknown[];
|
|
70
|
+
positions?: Array<{
|
|
71
|
+
pool: string;
|
|
72
|
+
lexigraphicTickIndexLow: string;
|
|
73
|
+
lexigraphicTickIndexHigh: string;
|
|
74
|
+
owner: string;
|
|
75
|
+
liquidity: string;
|
|
76
|
+
}>;
|
|
77
|
+
token0TradingSymbol?: {
|
|
78
|
+
symbol: string;
|
|
79
|
+
decimals: number;
|
|
80
|
+
};
|
|
81
|
+
token1TradingSymbol?: {
|
|
82
|
+
symbol: string;
|
|
83
|
+
decimals: number;
|
|
84
|
+
};
|
|
85
|
+
token0LiquidityBalance?: TokenBalance;
|
|
86
|
+
token1LiquidityBalance?: TokenBalance;
|
|
87
|
+
token0ProtocolFeesBalance?: TokenBalance;
|
|
88
|
+
token1ProtocolFeesBalance?: TokenBalance;
|
|
89
|
+
}
|
|
90
|
+
/** A token balance embedded in a composite pool result. */
|
|
91
|
+
interface TokenBalance {
|
|
92
|
+
collection?: string;
|
|
93
|
+
category?: string;
|
|
94
|
+
type?: string;
|
|
95
|
+
additionalKey?: string;
|
|
96
|
+
quantity?: string;
|
|
97
|
+
owner?: string;
|
|
98
|
+
}
|
|
99
|
+
/** A normalized current-contract liquidity position. */
|
|
100
|
+
interface Position {
|
|
101
|
+
pool: string;
|
|
66
102
|
token0Symbol: string;
|
|
67
|
-
/** Symbol/ticker for token1 (e.g., "USDC") */
|
|
68
103
|
token1Symbol: string;
|
|
69
|
-
|
|
104
|
+
token0CompositeKey?: string;
|
|
105
|
+
token1CompositeKey?: string;
|
|
70
106
|
fee: number;
|
|
71
|
-
/** Amount of liquidity provided in this position */
|
|
72
|
-
liquidity: BigNumber;
|
|
73
|
-
/** Lower tick boundary of the position's price range */
|
|
74
107
|
tickLower: number;
|
|
75
|
-
/** Upper tick boundary of the position's price range */
|
|
76
108
|
tickUpper: number;
|
|
77
|
-
|
|
78
|
-
|
|
109
|
+
owner: string;
|
|
110
|
+
liquidity: string;
|
|
111
|
+
amount0: string;
|
|
112
|
+
amount1: string;
|
|
113
|
+
inRange: boolean;
|
|
114
|
+
currentTick?: number;
|
|
115
|
+
sqrtPrice?: string;
|
|
116
|
+
fees0?: string;
|
|
117
|
+
fees1?: string;
|
|
79
118
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
*/
|
|
84
|
-
interface GetPositionResult {
|
|
85
|
-
/** Fee tier of the pool (e.g., 500 for 0.05%, 3000 for 0.3%) */
|
|
119
|
+
/** Quote response returned by `/v2/trade/quote`. */
|
|
120
|
+
interface QuoteResult {
|
|
121
|
+
contractVersion: 'v2';
|
|
86
122
|
fee: number;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
/** Token class key for the second token in the pair (ordered by token address) */
|
|
104
|
-
token1ClassKey: GalaChainTokenClassKey;
|
|
105
|
-
/** Amount of token0 fees accumulated and owed to the position owner */
|
|
106
|
-
tokensOwed0: BigNumber;
|
|
107
|
-
/** Amount of token1 fees accumulated and owed to the position owner */
|
|
108
|
-
tokensOwed1: BigNumber;
|
|
123
|
+
amountIn: string;
|
|
124
|
+
amountOut: string;
|
|
125
|
+
currentSqrtPrice?: string;
|
|
126
|
+
newSqrtPrice?: string;
|
|
127
|
+
newTick: number;
|
|
128
|
+
tradingFees: string;
|
|
129
|
+
protocolFees: string;
|
|
130
|
+
totalFees: string;
|
|
131
|
+
feeTokenSymbol: string;
|
|
132
|
+
token0Symbol: string;
|
|
133
|
+
token1Symbol: string;
|
|
134
|
+
tokenInIsToken0: boolean;
|
|
135
|
+
feeTier: number;
|
|
136
|
+
currentPrice?: BigNumber;
|
|
137
|
+
newPrice?: BigNumber;
|
|
138
|
+
priceImpact?: BigNumber;
|
|
109
139
|
}
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
140
|
+
/** The executed trade as reported by the ApplyRequests result (contract Trade response). */
|
|
141
|
+
interface TradeExecution {
|
|
142
|
+
token0: string;
|
|
143
|
+
token1: string;
|
|
144
|
+
fee: number;
|
|
145
|
+
sell0Qty?: string;
|
|
146
|
+
sell1Qty?: string;
|
|
147
|
+
buy0Qty?: string;
|
|
148
|
+
buy1Qty?: string;
|
|
149
|
+
tradingFees?: string;
|
|
150
|
+
protocolFees?: string;
|
|
151
|
+
totalFees?: string;
|
|
152
|
+
}
|
|
153
|
+
/** Terminal outcome of a queued RequestTrade, read from apply-results. */
|
|
154
|
+
interface AppliedTrade {
|
|
155
|
+
uniqueKey: string;
|
|
156
|
+
/** The ApplyRequests transaction that executed the trade (x-apply-transaction-id), when reported. */
|
|
157
|
+
transactionId: string | null;
|
|
158
|
+
/** Block of the ApplyRequests transaction (x-apply-block-number), when reported. */
|
|
159
|
+
blockNumber: number | null;
|
|
160
|
+
/** The RequestTrade transaction that queued it, when the gateway reported one. */
|
|
161
|
+
requestTransactionId: string | null;
|
|
162
|
+
result: TradeExecution;
|
|
163
|
+
}
|
|
164
|
+
/** A token balance returned by the backend user-assets route. */
|
|
114
165
|
interface UserAsset {
|
|
115
|
-
/** URL to the token's icon/image */
|
|
116
166
|
image: string;
|
|
117
|
-
/** Human-readable name of the token */
|
|
118
167
|
name: string;
|
|
119
|
-
/** Number of decimal places this token uses */
|
|
120
168
|
decimals: number;
|
|
121
|
-
/** Whether this token has been verified/approved */
|
|
122
169
|
verify: boolean;
|
|
123
|
-
/** Trading symbol for the token */
|
|
124
170
|
symbol: string;
|
|
125
|
-
/** User's balance of this token as a decimal string */
|
|
126
171
|
quantity: string;
|
|
127
172
|
}
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
* Contains paginated list of tokens and their balances.
|
|
131
|
-
*/
|
|
132
|
-
interface GetUserAssetsResult {
|
|
133
|
-
/** Array of tokens owned by the user */
|
|
173
|
+
/** User token balances returned by the backend. */
|
|
174
|
+
interface UserAssetsResult {
|
|
134
175
|
tokens: UserAsset[];
|
|
135
|
-
/** Total number of different tokens the user owns */
|
|
136
176
|
count: number;
|
|
137
177
|
}
|
|
178
|
+
/** Backend add-liquidity estimate. */
|
|
179
|
+
interface AddLiquidityEstimate {
|
|
180
|
+
amount0: string;
|
|
181
|
+
amount1: string;
|
|
182
|
+
liquidity: string;
|
|
183
|
+
token0Symbol: string;
|
|
184
|
+
token1Symbol: string;
|
|
185
|
+
tickLower: number;
|
|
186
|
+
tickUpper: number;
|
|
187
|
+
amountIsCanonicalToken0: boolean;
|
|
188
|
+
}
|
|
189
|
+
/** Backend remove-liquidity estimate. */
|
|
190
|
+
interface RemoveLiquidityEstimate {
|
|
191
|
+
amount0: string;
|
|
192
|
+
amount1: string;
|
|
193
|
+
}
|
|
194
|
+
/** A symbol registry entry returned by FetchTokenTradingSymbols. */
|
|
195
|
+
interface TradingSymbol {
|
|
196
|
+
symbol: string;
|
|
197
|
+
collection: string;
|
|
198
|
+
category: string;
|
|
199
|
+
type: string;
|
|
200
|
+
additionalKey: string;
|
|
201
|
+
decimals: number;
|
|
202
|
+
}
|
|
203
|
+
/** Result envelope returned by the chain gateway for a submitted write; queued RequestTrade has no result. */
|
|
204
|
+
interface ChainSubmissionResult {
|
|
205
|
+
transactionId?: string;
|
|
206
|
+
blockNumber?: number | null;
|
|
207
|
+
mode: 'sync' | 'queued';
|
|
208
|
+
result?: unknown;
|
|
209
|
+
uniqueKey?: string;
|
|
210
|
+
}
|
|
138
211
|
|
|
139
212
|
type FetchReturnValue = Awaited<ReturnType<typeof fetch>>;
|
|
140
213
|
interface HTTPResponse {
|
|
@@ -142,15 +215,22 @@ interface HTTPResponse {
|
|
|
142
215
|
status: FetchReturnValue['status'];
|
|
143
216
|
json: FetchReturnValue['json'];
|
|
144
217
|
text: FetchReturnValue['text'];
|
|
218
|
+
headers?: {
|
|
219
|
+
get(name: string): string | null;
|
|
220
|
+
} | Record<string, string | undefined>;
|
|
145
221
|
}
|
|
146
222
|
type HttpRequestor = (uri: string, options?: Parameters<typeof fetch>[1]) => Promise<HTTPResponse>;
|
|
147
223
|
|
|
148
224
|
declare class HttpClient {
|
|
149
225
|
private readonly httpRequestor;
|
|
150
|
-
|
|
226
|
+
private readonly timeoutMs;
|
|
227
|
+
/** Create an HTTP client around fetch or an injected requestor. */
|
|
228
|
+
constructor(httpRequestor?: HttpRequestor, timeoutMs?: number);
|
|
151
229
|
private sendRequest;
|
|
230
|
+
/** Send a JSON POST request and decode its response. */
|
|
152
231
|
sendPostRequest<TReturnType>(baseUrl: string, basePath: string, endpoint: string, body: unknown): Promise<TReturnType>;
|
|
153
|
-
|
|
232
|
+
/** Send a GET request with URL-encoded query parameters and decode its response. */
|
|
233
|
+
sendGetRequest<TReturnType>(baseUrl: string, basePath: string, endpoint: string, params?: Record<string, string>, options?: Pick<RequestInit, 'signal'>): Promise<TReturnType>;
|
|
154
234
|
}
|
|
155
235
|
|
|
156
236
|
/**
|
|
@@ -176,826 +256,980 @@ declare class Assets {
|
|
|
176
256
|
* });
|
|
177
257
|
* ```
|
|
178
258
|
*/
|
|
179
|
-
getUserAssets(ownerAddress: string, page?: number, limit?: number): Promise<
|
|
259
|
+
getUserAssets(ownerAddress: string, page?: number, limit?: number): Promise<UserAssetsResult>;
|
|
180
260
|
}
|
|
181
261
|
|
|
182
|
-
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
readonly transactionId: string;
|
|
195
|
-
readonly
|
|
196
|
-
readonly
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Waits for the transaction to be confirmed.
|
|
205
|
-
* This should be called immediately after receiving the PendingTransaction
|
|
206
|
-
* to ensure proper event handling. If you delay calling this method and the
|
|
207
|
-
* transaction confirms before you call this method, an error will be thrown.
|
|
262
|
+
/** Result of one position-confirmation poll. */
|
|
263
|
+
type PositionConfirmationResult = {
|
|
264
|
+
confirmed: true;
|
|
265
|
+
position: Position | null;
|
|
266
|
+
} | {
|
|
267
|
+
confirmed: false;
|
|
268
|
+
position?: Position | null;
|
|
269
|
+
};
|
|
270
|
+
/** A submitted v2 transaction whose confirmation mode is explicit in the gateway response. */
|
|
271
|
+
declare class SubmittedTransaction<TConfirmation = AppliedTrade | Position | null> {
|
|
272
|
+
readonly method: string;
|
|
273
|
+
readonly uniqueKey: string;
|
|
274
|
+
readonly transactionId: string | null;
|
|
275
|
+
readonly blockNumber: number | null;
|
|
276
|
+
readonly mode: 'sync' | 'queued';
|
|
277
|
+
/** The synchronous gateway result, or `undefined` when `mode === 'queued'`. */
|
|
278
|
+
readonly result: unknown;
|
|
279
|
+
private readonly backendBaseUrl;
|
|
280
|
+
private readonly requestor;
|
|
281
|
+
private readonly requestTimeoutMs;
|
|
282
|
+
private readonly positionConfirmation;
|
|
283
|
+
/** Construct a submitted transaction from a successful gateway response.
|
|
208
284
|
*
|
|
209
|
-
* @
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* const transaction = new SubmittedTransaction({
|
|
288
|
+
* method: 'RequestTrade', mode: 'queued', uniqueKey: 'swap-1',
|
|
289
|
+
* transactionId: 'request-tx', result: undefined,
|
|
290
|
+
* dexBackendBaseUrl: 'https://dex.example', httpRequestor,
|
|
291
|
+
* });
|
|
292
|
+
* ```
|
|
210
293
|
*/
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
294
|
+
constructor(options: {
|
|
295
|
+
method: string;
|
|
296
|
+
uniqueKey: string;
|
|
297
|
+
transactionId: string | null;
|
|
298
|
+
mode: 'sync' | 'queued';
|
|
299
|
+
result: unknown;
|
|
300
|
+
dexBackendBaseUrl: string;
|
|
301
|
+
httpRequestor: HttpRequestor;
|
|
302
|
+
blockNumber?: number | null | undefined;
|
|
303
|
+
requestTimeoutMs?: number | undefined;
|
|
304
|
+
positionConfirmation?: ((signal: AbortSignal) => Promise<PositionConfirmationResult>) | undefined;
|
|
305
|
+
});
|
|
306
|
+
/** Confirm a queued RequestTrade or prove the affected position for a liquidity write.
|
|
307
|
+
*
|
|
308
|
+
* For RequestTrade, calling this method is required to learn the outcome: the queued
|
|
309
|
+
* acknowledgement proves acceptance, not execution.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* const applied = await submitted.confirm({ initialDelayMs: 3_000 });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
confirm(options?: ConfirmOptions): Promise<TConfirmation>;
|
|
317
|
+
private confirmApplied;
|
|
318
|
+
private readAppliedResult;
|
|
319
|
+
/** Confirm a liquidity write against the position's observable effect.
|
|
320
|
+
*
|
|
321
|
+
* @returns The position after the write, or `null` for a confirmed full close.
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* const position = await submitted.confirm({ timeoutMs: 60_000 });
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
private confirmPosition;
|
|
216
328
|
}
|
|
217
|
-
|
|
218
329
|
/**
|
|
219
|
-
*
|
|
330
|
+
* Controls timeout and polling behavior for confirmation.
|
|
331
|
+
*
|
|
332
|
+
* - `timeoutMs` (default 60 000): overall deadline, counted from the `confirm()` call and
|
|
333
|
+
* including `initialDelayMs`. At least one read is always made.
|
|
334
|
+
* - `pollIntervalMs` (default 2 000, minimum 500): base interval, doubled with jitter up to 8 s.
|
|
335
|
+
* - `initialDelayMs`: wait before the first read. Defaults to 3 000 for a queued RequestTrade
|
|
336
|
+
* (the AutoApplier needs a few seconds) and 0 for liquidity writes (already executed).
|
|
220
337
|
*/
|
|
221
|
-
interface
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
338
|
+
interface ConfirmOptions {
|
|
339
|
+
timeoutMs?: number | undefined;
|
|
340
|
+
pollIntervalMs?: number | undefined;
|
|
341
|
+
initialDelayMs?: number | undefined;
|
|
225
342
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
343
|
+
|
|
344
|
+
/** Options for a chain-gateway client. */
|
|
345
|
+
interface ChainGatewayOptions {
|
|
346
|
+
dexBackendBaseUrl: string;
|
|
347
|
+
httpRequestor?: HttpRequestor | undefined;
|
|
348
|
+
walletAddress?: string | undefined;
|
|
349
|
+
chainCallTimeoutMs?: number | undefined;
|
|
350
|
+
}
|
|
351
|
+
/** Optional attribution and operation-specific confirmation hooks for a write. */
|
|
352
|
+
interface ChainSubmitOptions {
|
|
353
|
+
walletAddress?: string | undefined;
|
|
354
|
+
positionConfirmation?: ((signal: AbortSignal) => Promise<PositionConfirmationResult>) | undefined;
|
|
355
|
+
}
|
|
356
|
+
/** Thin client for backend-routed v2 writes: synchronous liquidity writes and queued RequestTrade. */
|
|
357
|
+
declare class ChainGateway {
|
|
358
|
+
private readonly requestor;
|
|
359
|
+
private readonly walletAddress;
|
|
360
|
+
private readonly chainCallTimeoutMs;
|
|
361
|
+
readonly requestTimeoutMs: number;
|
|
362
|
+
readonly dexBackendBaseUrl: string;
|
|
363
|
+
/** Create a chain gateway client. */
|
|
364
|
+
constructor(options: ChainGatewayOptions);
|
|
365
|
+
/** Submit a signed v2 DTO through the chain gateway. */
|
|
366
|
+
submit(method: 'RequestTrade', signedBody: Record<string, unknown>, options?: ChainSubmitOptions): Promise<SubmittedTransaction<AppliedTrade>>;
|
|
367
|
+
submit(method: string, signedBody: Record<string, unknown>, options?: ChainSubmitOptions): Promise<SubmittedTransaction<Position | null>>;
|
|
368
|
+
/** Expose the requestor for sibling read services that share this gateway transport. */
|
|
369
|
+
get httpRequestor(): HttpRequestor;
|
|
235
370
|
}
|
|
371
|
+
|
|
236
372
|
/**
|
|
237
|
-
*
|
|
373
|
+
* Fee tiers for pools.
|
|
238
374
|
*/
|
|
239
|
-
declare
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
375
|
+
declare enum FEE_TIER {
|
|
376
|
+
/** No trading fee. */
|
|
377
|
+
PERCENT_00_00 = 0,
|
|
378
|
+
/** 0.05% fee tier */
|
|
379
|
+
PERCENT_00_05 = 500,
|
|
380
|
+
/** 0.3% fee tier */
|
|
381
|
+
PERCENT_00_30 = 3000,
|
|
382
|
+
/** 1.0% fee tier */
|
|
383
|
+
PERCENT_01_00 = 10000
|
|
246
384
|
}
|
|
385
|
+
/** Tick spacing required by the current GalaChainDex contract for each fee tier. */
|
|
386
|
+
declare const TICK_SPACING_BY_FEE: Readonly<Record<FEE_TIER, number>>;
|
|
387
|
+
/** All fee tiers supported by the current GalaChainDex contract. */
|
|
388
|
+
declare const ALL_FEE_TIERS: readonly FEE_TIER[];
|
|
247
389
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
private readonly httpClient;
|
|
254
|
-
constructor(bundlerBaseUrl: string, bundlingAPIBasePath: string, transactionWaitTimeoutMs: number, signer: GalaChainSigner | undefined, httpClient: HttpClient);
|
|
255
|
-
signObject<TInputType extends Record<string, unknown>>(methodName: string, toSign: TInputType): Promise<TInputType & {
|
|
256
|
-
signature: string;
|
|
257
|
-
}>;
|
|
258
|
-
sendBundlerRequest(method: string, body: Record<string, unknown>, stringsInstructions: string[]): Promise<PendingTransaction>;
|
|
259
|
-
hasSigner(): boolean;
|
|
390
|
+
interface GalaChainTokenClassKey {
|
|
391
|
+
collection: string;
|
|
392
|
+
category: string;
|
|
393
|
+
type: string;
|
|
394
|
+
additionalKey: string;
|
|
260
395
|
}
|
|
261
396
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
transactionId: string;
|
|
278
|
-
};
|
|
397
|
+
/** A symbol or a GalaChain token class key accepted by v2 operations. */
|
|
398
|
+
type TokenRef = string | GalaChainTokenClassKey;
|
|
399
|
+
/** Return two trading symbols in the contract's plain-string order. */
|
|
400
|
+
declare function orderSymbols(a: string, b: string): [string, string];
|
|
401
|
+
/** Read an ordered symbol pair from a tuple or object returned by a boundary helper.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* const pair = readOrderedSymbols(['GALA', 'GUSDC']);
|
|
406
|
+
* console.log(pair.token0);
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
declare function readOrderedSymbols(value: unknown): {
|
|
410
|
+
token0: string;
|
|
411
|
+
token1: string;
|
|
279
412
|
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
declare abstract class TradeEventEmitter extends EventEmitter {
|
|
286
|
-
abstract connect(): Promise<void>;
|
|
287
|
-
abstract disconnect(): void;
|
|
288
|
-
abstract isConnected(): boolean;
|
|
289
|
-
}
|
|
290
|
-
declare class EventSocketClient extends TradeEventEmitter {
|
|
291
|
-
private socket;
|
|
292
|
-
private readonly bundlerUrl;
|
|
293
|
-
constructor(bundlerUrl: string);
|
|
294
|
-
connect(): Promise<void>;
|
|
295
|
-
disconnect(): void;
|
|
296
|
-
isConnected(): boolean;
|
|
297
|
-
}
|
|
413
|
+
/** Return the `$`-joined composite key used by GalaChain object identities. */
|
|
414
|
+
declare function compositeKeyOf(token: GalaChainTokenClassKey): string;
|
|
415
|
+
/** Parse a pipe- or dollar-separated token class key. */
|
|
416
|
+
declare function parseTokenClassKey(tokenClassKey: TokenRef): GalaChainTokenClassKey;
|
|
298
417
|
|
|
299
|
-
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
private
|
|
305
|
-
private
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
*
|
|
418
|
+
/** Symbol registry client for the current GalaChainDex contract. */
|
|
419
|
+
declare class Symbols {
|
|
420
|
+
private readonly gateway;
|
|
421
|
+
private cachedSymbols;
|
|
422
|
+
private cachedAt;
|
|
423
|
+
private refreshInFlight;
|
|
424
|
+
private readonly http;
|
|
425
|
+
/** Create a symbol service backed by the swap backend. */
|
|
426
|
+
constructor(gateway: Pick<ChainGateway, 'httpRequestor' | 'dexBackendBaseUrl'> & {
|
|
427
|
+
requestTimeoutMs?: number | undefined;
|
|
428
|
+
});
|
|
429
|
+
/** List all registered GalaChainDex trading symbols, cached for 60 seconds. */
|
|
430
|
+
list(): Promise<TradingSymbol[]>;
|
|
431
|
+
/** Invalidate the cached symbol registry after a write changes registration state.
|
|
432
|
+
*
|
|
314
433
|
* @example
|
|
315
|
-
* ```
|
|
316
|
-
*
|
|
434
|
+
* ```ts
|
|
435
|
+
* gSwap.symbols.invalidate();
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
invalidate(): void;
|
|
439
|
+
/** Force one registry refresh, bypassing the cache.
|
|
317
440
|
*
|
|
318
|
-
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```ts
|
|
443
|
+
* const symbols = await gSwap.symbols.refresh();
|
|
319
444
|
* ```
|
|
320
445
|
*/
|
|
321
|
-
|
|
446
|
+
refresh(): Promise<TradingSymbol[]>;
|
|
447
|
+
/** Resolve a symbol or token class key to its registered symbol metadata. */
|
|
448
|
+
resolve(ref: TokenRef): Promise<TradingSymbol>;
|
|
449
|
+
/** Resolve and put two token references in canonical trading-symbol order. */
|
|
450
|
+
orderPair(a: TokenRef, b: TokenRef): Promise<{
|
|
451
|
+
token0: TradingSymbol;
|
|
452
|
+
token1: TradingSymbol;
|
|
453
|
+
flipped: boolean;
|
|
454
|
+
}>;
|
|
455
|
+
}
|
|
456
|
+
/** Alias exported for callers that use the contract's shorter type name. */
|
|
457
|
+
type TokenClassKey = GalaChainTokenClassKey;
|
|
458
|
+
|
|
459
|
+
type PoolGateway = Pick<ChainGateway, 'httpRequestor' | 'dexBackendBaseUrl'> & {
|
|
460
|
+
requestTimeoutMs?: number | undefined;
|
|
461
|
+
};
|
|
462
|
+
type PoolSymbols = Pick<Symbols, 'resolve'>;
|
|
463
|
+
/** Read-only pool and current-price access for the current GalaChainDex contract. */
|
|
464
|
+
declare class Pools {
|
|
465
|
+
private readonly gateway;
|
|
466
|
+
private readonly symbols;
|
|
322
467
|
/**
|
|
323
|
-
*
|
|
468
|
+
* Creates a pool service.
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* const pools = new Pools(gateway, symbols);
|
|
473
|
+
* ```
|
|
324
474
|
*/
|
|
325
|
-
|
|
475
|
+
constructor(gateway: PoolGateway, symbols: PoolSymbols);
|
|
476
|
+
private readonly http;
|
|
326
477
|
/**
|
|
327
|
-
*
|
|
328
|
-
*
|
|
478
|
+
* Fetches every current-contract pool from the swap backend.
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```ts
|
|
482
|
+
* const pools = await service.getPools();
|
|
483
|
+
* console.log(pools.length);
|
|
484
|
+
* ```
|
|
329
485
|
*/
|
|
330
|
-
|
|
486
|
+
getPools(options?: {
|
|
487
|
+
signal?: AbortSignal | undefined;
|
|
488
|
+
}): Promise<PoolListInfo[]>;
|
|
331
489
|
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* @
|
|
490
|
+
* Fetches one pool from the backend, preserving whether the request order was flipped.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```ts
|
|
494
|
+
* const pool = await service.getPool('GUSDC', 'GALA', 3000);
|
|
495
|
+
* console.log(pool.flippedFromRequest);
|
|
496
|
+
* ```
|
|
335
497
|
*/
|
|
336
|
-
|
|
498
|
+
getPool(token0: TokenRef, token1: TokenRef, fee: FEE_TIER): Promise<PoolInfo>;
|
|
337
499
|
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* @
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
500
|
+
* Fetches the current sqrt price, price, and tick for one pool.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```ts
|
|
504
|
+
* const slot0 = await service.getSlot0('GALA', 'GUSDC', 3000);
|
|
505
|
+
* console.log(slot0.tick);
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
getSlot0(token0: TokenRef, token1: TokenRef, fee: FEE_TIER): Promise<Slot0>;
|
|
347
509
|
/**
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* @
|
|
510
|
+
* Fetches the complete chain composite pool snapshot, in canonical symbol order.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```ts
|
|
514
|
+
* const composite = await service.getCompositePool('GALA', 'GUSDC', 3000);
|
|
515
|
+
* console.log(composite.positions?.length ?? 0);
|
|
516
|
+
* ```
|
|
351
517
|
*/
|
|
352
|
-
|
|
518
|
+
getCompositePool(token0: TokenRef, token1: TokenRef, fee: FEE_TIER): Promise<CompositePool>;
|
|
519
|
+
private backendParams;
|
|
520
|
+
private getBackend;
|
|
353
521
|
}
|
|
354
522
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
amount1: BigNumber;
|
|
364
|
-
currentSqrtPrice: SqrtPrice;
|
|
365
|
-
newSqrtPrice: SqrtPrice;
|
|
366
|
-
}
|
|
367
|
-
interface GetPoolDataRawResponse {
|
|
368
|
-
bitmap: Record<string, string>;
|
|
369
|
-
fee: number;
|
|
370
|
-
feeGrowthGlobal0: string;
|
|
371
|
-
feeGrowthGlobal1: string;
|
|
372
|
-
grossPoolLiquidity: string;
|
|
373
|
-
liquidity: string;
|
|
374
|
-
maxLiquidityPerTick: string;
|
|
375
|
-
protocolFees: number;
|
|
376
|
-
protocolFeesToken0: string;
|
|
377
|
-
protocolFeesToken1: string;
|
|
378
|
-
sqrtPrice: string;
|
|
379
|
-
tickSpacing: number;
|
|
380
|
-
token0: string;
|
|
381
|
-
token0ClassKey: {
|
|
382
|
-
additionalKey: string;
|
|
383
|
-
category: string;
|
|
384
|
-
collection: string;
|
|
385
|
-
type: string;
|
|
386
|
-
};
|
|
387
|
-
token1: string;
|
|
388
|
-
token1ClassKey: {
|
|
389
|
-
additionalKey: string;
|
|
390
|
-
category: string;
|
|
391
|
-
collection: string;
|
|
392
|
-
type: string;
|
|
393
|
-
};
|
|
523
|
+
/** The signing schemes supported by the Gala Wallet signer. */
|
|
524
|
+
type GalaWalletScheme = 'native' | 'personal-sign';
|
|
525
|
+
/** The request surface used by an EIP-1193 browser wallet. */
|
|
526
|
+
interface BrowserWalletProvider {
|
|
527
|
+
request(args: {
|
|
528
|
+
method: string;
|
|
529
|
+
params?: unknown[];
|
|
530
|
+
}): Promise<unknown>;
|
|
394
531
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
token1: string;
|
|
416
|
-
token1ClassKey: {
|
|
417
|
-
additionalKey: string;
|
|
418
|
-
category: string;
|
|
419
|
-
collection: string;
|
|
420
|
-
type: string;
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
interface TransactionPendingResponse {
|
|
424
|
-
data: string;
|
|
425
|
-
message: string;
|
|
426
|
-
error: boolean;
|
|
532
|
+
type SignedDto<T extends Record<string, unknown>> = T & {
|
|
533
|
+
signature: string;
|
|
534
|
+
};
|
|
535
|
+
/**
|
|
536
|
+
* A signer for complete GalaChain write bodies.
|
|
537
|
+
*
|
|
538
|
+
* Implementations return the DTO fields together with the signature that belongs in the
|
|
539
|
+
* gateway request body. Signer identity is recovered from that signature; implementations do
|
|
540
|
+
* not add signer hints, typed-data metadata, or a domain.
|
|
541
|
+
*/
|
|
542
|
+
interface GalaChainSigner {
|
|
543
|
+
/**
|
|
544
|
+
* Signs a DTO for a named GalaChain contract method.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```typescript
|
|
548
|
+
* const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
signObject<T extends Record<string, unknown>>(methodName: string, dto: T): Promise<SignedDto<T>>;
|
|
427
552
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
553
|
+
/**
|
|
554
|
+
* A GalaChain native signer backed by a secp256k1 private key.
|
|
555
|
+
*
|
|
556
|
+
* Native signing produces the bare GalaChain signature format, without a personal-sign prefix
|
|
557
|
+
* or EIP-712 metadata. The private-key identity is recovered by the chain.
|
|
558
|
+
*/
|
|
559
|
+
declare class PrivateKeySigner implements GalaChainSigner {
|
|
560
|
+
private readonly keyBuffer;
|
|
434
561
|
/**
|
|
435
|
-
*
|
|
562
|
+
* Creates a native signer from a hex or base64 secp256k1 private key.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```typescript
|
|
566
|
+
* const signer = new PrivateKeySigner('1'.padStart(64, '0'));
|
|
567
|
+
* const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });
|
|
568
|
+
* ```
|
|
436
569
|
*/
|
|
437
|
-
|
|
570
|
+
constructor(privateKey: string);
|
|
438
571
|
/**
|
|
439
|
-
*
|
|
572
|
+
* Signs the DTO with GalaChain native signing.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* const signed = await signer.signObject('RequestTrade', {
|
|
577
|
+
* token0: 'GALA',
|
|
578
|
+
* token1: 'GUSDC',
|
|
579
|
+
* fee: 3000,
|
|
580
|
+
* });
|
|
581
|
+
* ```
|
|
440
582
|
*/
|
|
441
|
-
|
|
442
|
-
|
|
583
|
+
signObject<T extends Record<string, unknown>>(_methodName: string, dto: T): Promise<SignedDto<T>>;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* A Gala Wallet signer using native GalaChain signing, with an opt-in personal-sign mode and
|
|
587
|
+
* automatic fallback for older wallets.
|
|
588
|
+
*
|
|
589
|
+
* The selected Ethereum account is passed to Gala Wallet. Personal-sign resolves the bare
|
|
590
|
+
* `eth|` identity; the legacy EIP-712 `eth_signTypedData` path is not used. The fallback calls
|
|
591
|
+
* `gala_signChainDto([serialize({ ...dto, prefix }), walletAddress, methodName])`.
|
|
592
|
+
*/
|
|
593
|
+
declare class GalaWalletSigner implements GalaChainSigner {
|
|
594
|
+
/** The wallet address supplied to Gala Wallet for each signing request. */
|
|
595
|
+
readonly walletAddress: string;
|
|
596
|
+
/** The scheme currently used, including any automatic native-to-personal fallback. */
|
|
597
|
+
effectiveScheme: GalaWalletScheme;
|
|
443
598
|
/**
|
|
444
|
-
*
|
|
445
|
-
*
|
|
599
|
+
* Creates a Gala Wallet signer.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* const signer = new GalaWalletSigner('0x0123456789012345678901234567890123456789');
|
|
604
|
+
* const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });
|
|
605
|
+
* ```
|
|
606
|
+
*
|
|
607
|
+
* @param walletAddress - The selected Ethereum account (`0x` plus 40 hex digits); Gala Wallet's
|
|
608
|
+
* `eth|0x...` form is also accepted and normalized.
|
|
609
|
+
* @param options - Select native signing or personal-sign explicitly.
|
|
446
610
|
*/
|
|
447
|
-
|
|
611
|
+
constructor(walletAddress: string, options?: {
|
|
612
|
+
scheme?: GalaWalletScheme | undefined;
|
|
613
|
+
});
|
|
614
|
+
/**
|
|
615
|
+
* Signs a DTO through `gala_signChainDto`.
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```typescript
|
|
619
|
+
* const signed = await signer.signObject('AddLiquidity', {
|
|
620
|
+
* token0: 'GALA',
|
|
621
|
+
* token1: 'GUSDC',
|
|
622
|
+
* tickLower: -60,
|
|
623
|
+
* tickUpper: 60,
|
|
624
|
+
* });
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
signObject<T extends Record<string, unknown>>(methodName: string, dto: T): Promise<SignedDto<T>>;
|
|
448
628
|
}
|
|
449
|
-
|
|
450
629
|
/**
|
|
451
|
-
*
|
|
630
|
+
* A personal-sign signer for MetaMask and other EIP-1193 browser wallets.
|
|
631
|
+
*
|
|
632
|
+
* The chain recovers this signature using the EIP-191 wrap applied by the wallet to
|
|
633
|
+
* `personal_sign`. This is the browser-wallet path used by the v2 frontend and resolves the
|
|
634
|
+
* bare `eth|` identity.
|
|
452
635
|
*/
|
|
453
|
-
declare
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
636
|
+
declare class BrowserWalletSigner implements GalaChainSigner {
|
|
637
|
+
private readonly provider;
|
|
638
|
+
/**
|
|
639
|
+
* Creates a browser-wallet signer.
|
|
640
|
+
*
|
|
641
|
+
* Defaults to `personal_sign` — unchanged from every existing integration, since it only ever
|
|
642
|
+
* resolves the bare `eth|` identity and changing that silently would be a real behavior
|
|
643
|
+
* break for anyone already depending on it. Pass `{ scheme: 'eip712' }` to correctly resolve
|
|
644
|
+
* a registered `client|` alias instead, for `RequestTrade`/`AddLiquidity`/`RemoveLiquidity`/
|
|
645
|
+
* `CollectPositionFees` (`EIP712_CAPABLE_METHODS`) — `CreatePool` and any other method still
|
|
646
|
+
* falls back to `personal_sign` even in `'eip712'` mode, since its EIP-712 signing is a
|
|
647
|
+
* separate, unsolved chain-side problem.
|
|
648
|
+
*
|
|
649
|
+
* @example
|
|
650
|
+
* ```typescript
|
|
651
|
+
* const signer = new BrowserWalletSigner(window.ethereum, '0x0123456789012345678901234567890123456789');
|
|
652
|
+
* const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });
|
|
653
|
+
* ```
|
|
654
|
+
* @example
|
|
655
|
+
* ```typescript
|
|
656
|
+
* // Correctly resolves a registered client| alias instead of the bare eth| address.
|
|
657
|
+
* const signer = new BrowserWalletSigner(window.ethereum, walletAddress, { scheme: 'eip712' });
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
constructor(provider: BrowserWalletProvider, walletAddress: string, options?: {
|
|
661
|
+
scheme?: 'personal-sign' | 'eip712';
|
|
662
|
+
});
|
|
663
|
+
readonly walletAddress: string;
|
|
664
|
+
private readonly scheme;
|
|
665
|
+
/**
|
|
666
|
+
* Signs the DTO with `eth_signTypedData_v4` (when constructed with `{ scheme: 'eip712' }` and
|
|
667
|
+
* `methodName` is in `EIP712_CAPABLE_METHODS`) or the EIP-1193 `personal_sign` method
|
|
668
|
+
* (otherwise — the default).
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
* ```typescript
|
|
672
|
+
* const signed = await signer.signObject('RequestTrade', {
|
|
673
|
+
* token0: 'GALA',
|
|
674
|
+
* token1: 'GUSDC',
|
|
675
|
+
* fee: 3000,
|
|
676
|
+
* });
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
signObject<T extends Record<string, unknown>>(methodName: string, dto: T): Promise<SignedDto<T>>;
|
|
460
680
|
}
|
|
461
681
|
|
|
682
|
+
interface Branding<BrandT> {
|
|
683
|
+
_type: BrandT;
|
|
684
|
+
}
|
|
685
|
+
type Brand<T, BrandT> = T & Branding<BrandT>;
|
|
686
|
+
|
|
687
|
+
type NumericAmount = string | BigNumber;
|
|
688
|
+
type SqrtPrice = Brand<BigNumber, 'SqrtPrice'>;
|
|
689
|
+
type SqrtPriceIn = Brand<NumericAmount, 'SqrtPriceIn'> | SqrtPrice;
|
|
690
|
+
type Price = Brand<BigNumber, 'Price'>;
|
|
691
|
+
type PriceIn = Brand<NumericAmount, 'PriceIn'> | Price;
|
|
692
|
+
|
|
693
|
+
type PositionGateway = Pick<ChainGateway, 'httpRequestor' | 'dexBackendBaseUrl'> & {
|
|
694
|
+
submit: (method: string, signedBody: Record<string, unknown>, options?: ChainSubmitOptions) => Promise<SubmittedTransaction<Position | null>>;
|
|
695
|
+
requestTimeoutMs?: number | undefined;
|
|
696
|
+
};
|
|
697
|
+
type PositionSymbols = Pick<Symbols, 'resolve' | 'orderPair'> & {
|
|
698
|
+
invalidate?: () => void;
|
|
699
|
+
};
|
|
462
700
|
/**
|
|
463
|
-
*
|
|
701
|
+
* Manages current-contract concentrated-liquidity positions.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* const positions = gSwap.positions;
|
|
706
|
+
* const mine = await positions.getUserPositions('client|012345678901234567890123');
|
|
707
|
+
* console.log(mine.length);
|
|
708
|
+
* ```
|
|
464
709
|
*/
|
|
465
710
|
declare class Positions {
|
|
466
|
-
private readonly
|
|
467
|
-
private readonly
|
|
468
|
-
private readonly
|
|
469
|
-
private readonly
|
|
470
|
-
|
|
471
|
-
private readonly
|
|
472
|
-
constructor(gatewayBaseUrl: string, dexContractBasePath: string, bundlerService: Bundler, poolService: Pools, httpClient: HttpClient, options?: {
|
|
473
|
-
walletAddress?: string | undefined;
|
|
474
|
-
} | undefined);
|
|
711
|
+
private readonly gateway;
|
|
712
|
+
private readonly symbols;
|
|
713
|
+
private readonly signer?;
|
|
714
|
+
private readonly walletAddress?;
|
|
715
|
+
constructor(gateway: PositionGateway, symbols: PositionSymbols, signer?: GalaChainSigner | undefined, walletAddress?: string | undefined);
|
|
716
|
+
private readonly http;
|
|
475
717
|
/**
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
* @param
|
|
479
|
-
* @
|
|
480
|
-
* @returns User positions and pagination bookmark
|
|
718
|
+
* Gets all current-contract positions owned by an address.
|
|
719
|
+
*
|
|
720
|
+
* @param owner - GalaChain owner identity.
|
|
721
|
+
* @returns Enriched positions from the v2 trade backend.
|
|
481
722
|
* @example
|
|
482
723
|
* ```typescript
|
|
483
|
-
* const positions = await gSwap.positions.getUserPositions('
|
|
484
|
-
* console.log(positions);
|
|
724
|
+
* const positions = await gSwap.positions.getUserPositions('client|012345678901234567890123');
|
|
485
725
|
* ```
|
|
486
726
|
*/
|
|
487
|
-
getUserPositions(
|
|
488
|
-
bookmark: string;
|
|
489
|
-
positions: GetUserPositionsResult[];
|
|
490
|
-
}>;
|
|
727
|
+
getUserPositions(owner: string): Promise<Position[]>;
|
|
491
728
|
/**
|
|
492
|
-
* Gets
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
* @param
|
|
496
|
-
* @
|
|
497
|
-
* @param position.fee - The pool fee tier.
|
|
498
|
-
* @param position.tickLower - The lower tick of the position range.
|
|
499
|
-
* @param position.tickUpper - The upper tick of the position range.
|
|
500
|
-
* @returns Detailed position information.
|
|
729
|
+
* Gets one position, normalizing a caller-supplied reversed pair to canonical symbol order.
|
|
730
|
+
* Reversed pairs also invert the price axis, so `[lower, upper]` becomes `[-upper, -lower]`.
|
|
731
|
+
*
|
|
732
|
+
* @param args - Pair, owner, fee, and position tick range.
|
|
733
|
+
* @returns The position, or `null` when the backend returns 404.
|
|
501
734
|
* @example
|
|
502
735
|
* ```typescript
|
|
503
|
-
* const position = await gSwap.positions.getPosition(
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
* fee: 500,
|
|
507
|
-
* tickLower: -6000,
|
|
508
|
-
* tickUpper: 6000
|
|
736
|
+
* const position = await gSwap.positions.getPosition({
|
|
737
|
+
* token0: 'GALA', token1: 'GUSDC', owner: 'client|012345678901234567890123',
|
|
738
|
+
* fee: 3000, tickLower: -19200, tickUpper: 12000,
|
|
509
739
|
* });
|
|
510
|
-
* console.log('Position:', position);
|
|
511
740
|
* ```
|
|
512
741
|
*/
|
|
513
|
-
getPosition(
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
fee:
|
|
742
|
+
getPosition(args: {
|
|
743
|
+
token0: TokenRef;
|
|
744
|
+
token1: TokenRef;
|
|
745
|
+
fee: FEE_TIER;
|
|
746
|
+
owner: string;
|
|
517
747
|
tickLower: number;
|
|
518
748
|
tickUpper: number;
|
|
519
|
-
}): Promise<
|
|
749
|
+
}, signal?: AbortSignal): Promise<Position | null>;
|
|
520
750
|
/**
|
|
521
|
-
* Estimates the token
|
|
522
|
-
*
|
|
523
|
-
* @param args
|
|
524
|
-
* @
|
|
525
|
-
* @param args.token0 - The first token in the pair.
|
|
526
|
-
* @param args.token1 - The second token in the pair.
|
|
527
|
-
* @param args.fee - The pool fee tier.
|
|
528
|
-
* @param args.tickLower - The lower tick of the position range.
|
|
529
|
-
* @param args.tickUpper - The upper tick of the position range.
|
|
530
|
-
* @param args.amount - The amount of liquidity to remove.
|
|
531
|
-
* @returns Estimated token amounts that would be received.
|
|
751
|
+
* Estimates the other token amount and resulting liquidity for a deposit.
|
|
752
|
+
*
|
|
753
|
+
* @param args - Pair, tick range, deposit amount, and the amount's caller-side token index.
|
|
754
|
+
* @returns Backend liquidity estimate.
|
|
532
755
|
* @example
|
|
533
756
|
* ```typescript
|
|
534
|
-
* const
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* token0: 'GALA|Unit|none|none',
|
|
538
|
-
* token1: 'GUSDT|Unit|none|none',
|
|
539
|
-
* fee: 3000,
|
|
540
|
-
* tickLower: -41100,
|
|
541
|
-
* tickUpper: -40080,
|
|
542
|
-
* amount: '1491.973332758921980256'
|
|
757
|
+
* const estimate = await gSwap.positions.estimateAddLiquidity({
|
|
758
|
+
* token0: 'GALA', token1: 'GUSDC', fee: 3000,
|
|
759
|
+
* tickLower: -19200, tickUpper: 12000, amount: '100', amountIsToken0: true,
|
|
543
760
|
* });
|
|
544
|
-
* console.log('Estimated tokens:', estimation);
|
|
545
761
|
* ```
|
|
546
762
|
*/
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
token1: GalaChainTokenClassKey | string;
|
|
552
|
-
fee: number;
|
|
763
|
+
estimateAddLiquidity(args: {
|
|
764
|
+
token0: TokenRef;
|
|
765
|
+
token1: TokenRef;
|
|
766
|
+
fee: FEE_TIER;
|
|
553
767
|
tickLower: number;
|
|
554
768
|
tickUpper: number;
|
|
555
769
|
amount: NumericAmount;
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
amount1: BigNumber;
|
|
559
|
-
}>;
|
|
770
|
+
amountIsToken0: boolean;
|
|
771
|
+
}): Promise<AddLiquidityEstimate>;
|
|
560
772
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* @param
|
|
564
|
-
* @returns
|
|
773
|
+
* Estimates token amounts released by burning liquidity.
|
|
774
|
+
*
|
|
775
|
+
* @param args - Pair, tick range, fee tier, and liquidity quantity.
|
|
776
|
+
* @returns Estimated token0 and token1 quantities.
|
|
565
777
|
* @example
|
|
566
778
|
* ```typescript
|
|
567
|
-
* const
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
* }
|
|
571
|
-
* console.log('Position not found');
|
|
572
|
-
* }
|
|
779
|
+
* const estimate = await gSwap.positions.estimateRemoveLiquidity({
|
|
780
|
+
* token0: 'GALA', token1: 'GUSDC', fee: 3000,
|
|
781
|
+
* tickLower: -19200, tickUpper: 12000, liquidity: '1000',
|
|
782
|
+
* });
|
|
573
783
|
* ```
|
|
574
784
|
*/
|
|
575
|
-
|
|
785
|
+
estimateRemoveLiquidity(args: {
|
|
786
|
+
token0: TokenRef;
|
|
787
|
+
token1: TokenRef;
|
|
788
|
+
fee: FEE_TIER;
|
|
789
|
+
tickLower: number;
|
|
790
|
+
tickUpper: number;
|
|
791
|
+
liquidity: NumericAmount;
|
|
792
|
+
}): Promise<RemoveLiquidityEstimate>;
|
|
576
793
|
/**
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
* @param args
|
|
580
|
-
* @
|
|
581
|
-
* @param args.token0 - The first token in the pair.
|
|
582
|
-
* @param args.token1 - The second token in the pair.
|
|
583
|
-
* @param args.fee - The pool fee tier.
|
|
584
|
-
* @param args.tickLower - The lower tick of the position range.
|
|
585
|
-
* @param args.tickUpper - The upper tick of the position range.
|
|
586
|
-
* @param args.amount0Desired - Desired (also maximum) amount of token0 to add.
|
|
587
|
-
* @param args.amount1Desired - Desired (also maximum) amount of token1 to add.
|
|
588
|
-
* @param args.amount0Min - Minimum amount of token0 to add (slippage protection).
|
|
589
|
-
* @param args.amount1Min - Minimum amount of token1 to add (slippage protection).
|
|
590
|
-
* @returns Pending transaction.
|
|
794
|
+
* Adds liquidity using an explicit tick range. Exactly one canonical deposit field is emitted.
|
|
795
|
+
*
|
|
796
|
+
* @param args - Pair, fee, range, deposit amount, and caller-side token index.
|
|
797
|
+
* @returns The synchronously submitted transaction.
|
|
591
798
|
* @example
|
|
592
799
|
* ```typescript
|
|
593
|
-
* const
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
* token0: 'GALA|Unit|none|none',
|
|
597
|
-
* token1: 'GUSDC|Unit|none|none',
|
|
598
|
-
* fee: 500,
|
|
599
|
-
* tickSpacing: 10,
|
|
600
|
-
* tickLower: -6000,
|
|
601
|
-
* tickUpper: 6000,
|
|
602
|
-
* amount0Desired: '100',
|
|
603
|
-
* amount1Desired: '50',
|
|
604
|
-
* amount0Min: '95',
|
|
605
|
-
* amount1Min: '47.5'
|
|
800
|
+
* const tx = await gSwap.positions.addLiquidityByTicks({
|
|
801
|
+
* token0: 'GALA', token1: 'GUSDC', fee: 3000,
|
|
802
|
+
* tickLower: -19200, tickUpper: 12000, amount: '100', amountIsToken0: true,
|
|
606
803
|
* });
|
|
607
|
-
*
|
|
804
|
+
* await tx.confirm();
|
|
608
805
|
* ```
|
|
609
806
|
*/
|
|
610
807
|
addLiquidityByTicks(args: {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
token0: GalaChainTokenClassKey | string;
|
|
614
|
-
token1: GalaChainTokenClassKey | string;
|
|
808
|
+
token0: TokenRef;
|
|
809
|
+
token1: TokenRef;
|
|
615
810
|
fee: FEE_TIER;
|
|
616
811
|
tickLower: number;
|
|
617
812
|
tickUpper: number;
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
amount1Min: NumericAmount;
|
|
622
|
-
}): Promise<PendingTransaction>;
|
|
813
|
+
amount: NumericAmount;
|
|
814
|
+
amountIsToken0: boolean;
|
|
815
|
+
}): Promise<SubmittedTransaction<Position | null>>;
|
|
623
816
|
/**
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* @param args
|
|
628
|
-
* @
|
|
629
|
-
* @param args.token1 - The second token in the pair.
|
|
630
|
-
* @param args.fee - The pool fee tier.
|
|
631
|
-
* @param args.tickSpacing - The tick spacing for the pool.
|
|
632
|
-
* @param args.minPrice - The minimum price for the position range.
|
|
633
|
-
* @param args.maxPrice - The maximum price for the position range.
|
|
634
|
-
* @param args.amount0Desired - Desired (also maximum) amount of token0 to add.
|
|
635
|
-
* @param args.amount1Desired - Desired (also maximum) amount of token1 to add.
|
|
636
|
-
* @param args.amount0Min - Minimum amount of token0 to add (slippage protection).
|
|
637
|
-
* @param args.amount1Min - Minimum amount of token1 to add (slippage protection).
|
|
638
|
-
* @returns Pending transaction.
|
|
817
|
+
* Adds liquidity from prices, flooring the lower tick and ceiling the upper tick to fee spacing.
|
|
818
|
+
* The resulting range is therefore no narrower than the requested price interval.
|
|
819
|
+
*
|
|
820
|
+
* @param args - Pair, fee, price range, deposit amount, and caller-side token index.
|
|
821
|
+
* @returns The synchronously submitted transaction.
|
|
639
822
|
* @example
|
|
640
823
|
* ```typescript
|
|
641
|
-
* const
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* token0: 'GALA|Unit|none|none',
|
|
645
|
-
* token1: 'GUSDC|Unit|none|none',
|
|
646
|
-
* fee: 500,
|
|
647
|
-
* tickSpacing: 10,
|
|
648
|
-
* minPrice: '0.45',
|
|
649
|
-
* maxPrice: '0.55',
|
|
650
|
-
* amount0Desired: '100',
|
|
651
|
-
* amount1Desired: '50',
|
|
652
|
-
* amount0Min: '95',
|
|
653
|
-
* amount1Min: '47.5'
|
|
824
|
+
* const tx = await gSwap.positions.addLiquidityByPrice({
|
|
825
|
+
* token0: 'GALA', token1: 'GUSDC', fee: 3000,
|
|
826
|
+
* minPrice: '0.14', maxPrice: '0.16', amount: '100', amountIsToken0: true,
|
|
654
827
|
* });
|
|
655
|
-
* console.log('Liquidity added with price range:', result);
|
|
656
828
|
* ```
|
|
657
829
|
*/
|
|
658
830
|
addLiquidityByPrice(args: {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
token1: GalaChainTokenClassKey | string;
|
|
663
|
-
fee: number;
|
|
664
|
-
tickSpacing: number;
|
|
831
|
+
token0: TokenRef;
|
|
832
|
+
token1: TokenRef;
|
|
833
|
+
fee: FEE_TIER;
|
|
665
834
|
minPrice: PriceIn;
|
|
666
835
|
maxPrice: PriceIn;
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
amount1Min: NumericAmount;
|
|
671
|
-
}): Promise<PendingTransaction>;
|
|
836
|
+
amount: NumericAmount;
|
|
837
|
+
amountIsToken0: boolean;
|
|
838
|
+
}): Promise<SubmittedTransaction<Position | null>>;
|
|
672
839
|
/**
|
|
673
|
-
* Removes liquidity
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
* @param args
|
|
677
|
-
* @
|
|
678
|
-
* @param args.token1 - The second token in the pair.
|
|
679
|
-
* @param args.fee - The pool fee tier.
|
|
680
|
-
* @param args.tickLower - The lower tick of the position range.
|
|
681
|
-
* @param args.tickUpper - The upper tick of the position range.
|
|
682
|
-
* @param args.amount - The amount of liquidity to remove.
|
|
683
|
-
* @param args.amount0Min - Minimum amount of token0 to receive (slippage protection, optional).
|
|
684
|
-
* @param args.amount1Min - Minimum amount of token1 to receive (slippage protection, optional).
|
|
685
|
-
* @returns Pending transaction.
|
|
840
|
+
* Removes liquidity by withdrawing at most one canonical token quantity.
|
|
841
|
+
* Omitting both amounts closes the position and sweeps all accrued fees.
|
|
842
|
+
*
|
|
843
|
+
* @param args - Pair, fee, range, and optional caller-side withdrawal amount.
|
|
844
|
+
* @returns The synchronously submitted transaction.
|
|
686
845
|
* @example
|
|
687
846
|
* ```typescript
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* positionId: 'position-123',
|
|
692
|
-
* token0: 'GALA|Unit|none|none',
|
|
693
|
-
* token1: 'GUSDC|Unit|none|none',
|
|
694
|
-
* fee: 500,
|
|
695
|
-
* tickLower: -6000,
|
|
696
|
-
* tickUpper: 6000,
|
|
697
|
-
* amount: '50000000000000000000', // 50% of position liquidity
|
|
698
|
-
* amount0Min: '45',
|
|
699
|
-
* amount1Min: '22'
|
|
847
|
+
* const tx = await gSwap.positions.removeLiquidity({
|
|
848
|
+
* token0: 'GALA', token1: 'GUSDC', fee: 3000,
|
|
849
|
+
* tickLower: -19200, tickUpper: 12000,
|
|
700
850
|
* });
|
|
701
|
-
* console.log('Liquidity removed:', result);
|
|
702
851
|
* ```
|
|
703
852
|
*/
|
|
704
853
|
removeLiquidity(args: {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
token1: GalaChainTokenClassKey | string;
|
|
709
|
-
fee: number;
|
|
854
|
+
token0: TokenRef;
|
|
855
|
+
token1: TokenRef;
|
|
856
|
+
fee: FEE_TIER;
|
|
710
857
|
tickLower: number;
|
|
711
858
|
tickUpper: number;
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}): Promise<PendingTransaction>;
|
|
859
|
+
amount0?: NumericAmount | undefined;
|
|
860
|
+
amount1?: NumericAmount | undefined;
|
|
861
|
+
}): Promise<SubmittedTransaction<Position | null>>;
|
|
716
862
|
/**
|
|
717
|
-
* Collects
|
|
718
|
-
*
|
|
719
|
-
* @param args
|
|
720
|
-
* @
|
|
721
|
-
* @param args.token0 - The first token in the pair.
|
|
722
|
-
* @param args.token1 - The second token in the pair.
|
|
723
|
-
* @param args.fee - The pool fee tier.
|
|
724
|
-
* @param args.tickLower - The lower tick of the position range.
|
|
725
|
-
* @param args.tickUpper - The upper tick of the position range.
|
|
726
|
-
* @param args.amount0Requested - Desired amount of token0 fees to collect.
|
|
727
|
-
* @param args.amount1Requested - Desired amount of token1 fees to collect.
|
|
728
|
-
* @returns Pending transaction.
|
|
863
|
+
* Collects all accrued fees for a position; the contract does not support partial collection.
|
|
864
|
+
*
|
|
865
|
+
* @param args - Pair, fee, and tick range identifying the position.
|
|
866
|
+
* @returns The synchronously submitted transaction.
|
|
729
867
|
* @example
|
|
730
868
|
* ```typescript
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
* positionId: 'position-123',
|
|
735
|
-
* token0: 'GALA|Unit|none|none',
|
|
736
|
-
* token1: 'GUSDC|Unit|none|none',
|
|
737
|
-
* fee: 500,
|
|
738
|
-
* tickLower: -6000,
|
|
739
|
-
* tickUpper: 6000,
|
|
740
|
-
* amount0Requested: '1000000000000000000', // Max fees available
|
|
741
|
-
* amount1Requested: '500000000' // Max fees available
|
|
869
|
+
* const tx = await gSwap.positions.collectPositionFees({
|
|
870
|
+
* token0: 'GALA', token1: 'GUSDC', fee: 3000,
|
|
871
|
+
* tickLower: -19200, tickUpper: 12000,
|
|
742
872
|
* });
|
|
743
|
-
* console.log('Fees collected:', result);
|
|
744
873
|
* ```
|
|
745
874
|
*/
|
|
746
875
|
collectPositionFees(args: {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
token1: GalaChainTokenClassKey | string;
|
|
751
|
-
fee: number;
|
|
876
|
+
token0: TokenRef;
|
|
877
|
+
token1: TokenRef;
|
|
878
|
+
fee: FEE_TIER;
|
|
752
879
|
tickLower: number;
|
|
753
880
|
tickUpper: number;
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
881
|
+
}): Promise<SubmittedTransaction<Position | null>>;
|
|
882
|
+
/**
|
|
883
|
+
* Creates a pool, resolving registered trading symbols and falling back to class collections.
|
|
884
|
+
* Reversed symbol order inverts the supplied starting price or square-root price.
|
|
885
|
+
*
|
|
886
|
+
* @param args - Token class keys or references, fee, exactly one starting price field, and privacy options.
|
|
887
|
+
* @returns The synchronously submitted transaction.
|
|
888
|
+
* @example
|
|
889
|
+
* ```typescript
|
|
890
|
+
* const tx = await gSwap.positions.createPool({
|
|
891
|
+
* token0: 'GALA|Unit|none|none', token1: 'GUSDC|Unit|none|none', fee: 3000,
|
|
892
|
+
* startingPrice: '0.15',
|
|
893
|
+
* });
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
896
|
+
createPool(args: {
|
|
897
|
+
token0: TokenRef;
|
|
898
|
+
token1: TokenRef;
|
|
899
|
+
fee: FEE_TIER;
|
|
900
|
+
startingPrice?: NumericAmount | undefined;
|
|
901
|
+
startingSqrtPrice?: NumericAmount | undefined;
|
|
902
|
+
isPrivate?: boolean | undefined;
|
|
903
|
+
privateAccess?: string[] | undefined;
|
|
904
|
+
}): Promise<SubmittedTransaction<Position | null>>;
|
|
905
|
+
private submit;
|
|
906
|
+
/**
|
|
907
|
+
* Builds a confirmation closure that proves the write's own effect, not just that a
|
|
908
|
+
* position row exists (true before most of these writes run too, for any operation on a
|
|
909
|
+
* pre-existing position — existence alone would false-confirm before the write executes,
|
|
910
|
+
* and would never confirm a full close, whose whole point is that the position stops
|
|
911
|
+
* existing).
|
|
912
|
+
*
|
|
913
|
+
* The "before" state is captured lazily, on the confirmation closure's own first poll —
|
|
914
|
+
* not eagerly here in `submit()` — so confirming a write never adds an extra round-trip to
|
|
915
|
+
* the write itself; the cost of establishing the baseline is paid by `confirm()`, only if
|
|
916
|
+
* and when the caller actually asks to confirm.
|
|
917
|
+
*/
|
|
918
|
+
private buildPositionConfirmation;
|
|
919
|
+
private get;
|
|
920
|
+
private getNullable;
|
|
921
|
+
private isNotFound;
|
|
922
|
+
private mapPosition;
|
|
923
|
+
private requestToken;
|
|
924
|
+
private canonicalTicks;
|
|
925
|
+
private tickSpacing;
|
|
926
|
+
private rejectNumber;
|
|
927
|
+
private uniqueKey;
|
|
928
|
+
private resolveCreateToken;
|
|
929
|
+
private tryParseClassKey;
|
|
760
930
|
}
|
|
761
931
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
*/
|
|
932
|
+
type QuoteSymbols = Pick<Symbols, 'resolve'>;
|
|
933
|
+
/** Read-only quote service backed by the v2 offline quote engine. */
|
|
765
934
|
declare class Quoting {
|
|
766
|
-
private readonly
|
|
767
|
-
private readonly
|
|
768
|
-
private readonly
|
|
769
|
-
constructor(gatewayBaseUrl: string, dexContractBasePath: string, httpClient?: HttpClient);
|
|
935
|
+
private readonly dexBackendBaseUrl;
|
|
936
|
+
private readonly http;
|
|
937
|
+
private readonly symbols;
|
|
770
938
|
/**
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
* @
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*/
|
|
778
|
-
|
|
939
|
+
* Creates a quote service.
|
|
940
|
+
*
|
|
941
|
+
* @example
|
|
942
|
+
* ```ts
|
|
943
|
+
* const quoting = new Quoting('https://swap-backend.stage.defi.ovh.gala.com', http, symbols);
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
constructor(dexBackendBaseUrl: string, http: HttpClient, symbols: QuoteSymbols);
|
|
779
947
|
/**
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
* @
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
private getSingleQuoteExactInput;
|
|
790
|
-
private getSingleQuoteExactOutput;
|
|
791
|
-
private sendQuoteRequest;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
/**
|
|
795
|
-
* Service for handling token swap operations.
|
|
796
|
-
*/
|
|
797
|
-
declare class Swaps {
|
|
798
|
-
private readonly bundlerService;
|
|
799
|
-
private readonly options?;
|
|
800
|
-
constructor(bundlerService: Bundler, options?: {
|
|
801
|
-
walletAddress?: string | undefined;
|
|
802
|
-
} | undefined);
|
|
948
|
+
* Quotes the output for a positive exact-input amount.
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* ```ts
|
|
952
|
+
* const quote = await quoting.quoteExactInput('GALA', 'GUSDC', '100');
|
|
953
|
+
* console.log(quote.amountOut);
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
quoteExactInput(tokenIn: TokenRef, tokenOut: TokenRef, amountIn: NumericAmount, fee?: FEE_TIER): Promise<QuoteResult>;
|
|
803
957
|
/**
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
* @param tokenIn - The input token to sell.
|
|
807
|
-
* @param tokenOut - The output token to buy.
|
|
808
|
-
* @param fee - The pool fee tier.
|
|
809
|
-
* @param amount - Swap parameters specifying either exact input or exact output.
|
|
810
|
-
* @param amount.exactIn - For exact input swaps, the exact amount of input tokens to sell.
|
|
811
|
-
* @param amount.amountOutMinimum - For exact input swaps, the minimum amount of output tokens to buy (slippage protection).
|
|
812
|
-
* @param amount.exactOut - For exact output swaps, the exact amount of output tokens to buy.
|
|
813
|
-
* @param amount.amountInMaximum - For exact output swaps, the maximum amount of input tokens to sell (slippage protection).
|
|
814
|
-
* @returns Pending transaction.
|
|
958
|
+
* Quotes the input for a positive exact-output amount.
|
|
959
|
+
*
|
|
815
960
|
* @example
|
|
816
|
-
* ```
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
* 'eth|123...abc', // your wallet address
|
|
824
|
-
* );
|
|
825
|
-
* console.log('Swap successful:', result);
|
|
826
|
-
* ```
|
|
827
|
-
*/
|
|
828
|
-
swap(tokenIn: GalaChainTokenClassKey | string, tokenOut: GalaChainTokenClassKey | string, fee: number, amount: {
|
|
829
|
-
exactIn: NumericAmount;
|
|
830
|
-
amountOutMinimum?: NumericAmount;
|
|
831
|
-
} | {
|
|
832
|
-
exactOut: NumericAmount;
|
|
833
|
-
amountInMaximum?: NumericAmount;
|
|
834
|
-
}, walletAddress?: string): Promise<PendingTransaction>;
|
|
961
|
+
* ```ts
|
|
962
|
+
* const quote = await quoting.quoteExactOutput('GALA', 'GUSDC', '10', 3000);
|
|
963
|
+
* console.log(quote.amountIn);
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
quoteExactOutput(tokenIn: TokenRef, tokenOut: TokenRef, amountOut: NumericAmount, fee?: FEE_TIER): Promise<QuoteResult>;
|
|
967
|
+
private quote;
|
|
835
968
|
}
|
|
836
969
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
970
|
+
type SwapAmount = {
|
|
971
|
+
exactIn: NumericAmount;
|
|
972
|
+
exactOut?: undefined;
|
|
973
|
+
amountOutMinimum?: NumericAmount | undefined;
|
|
974
|
+
amountInMaximum?: undefined;
|
|
975
|
+
} | {
|
|
976
|
+
exactIn?: undefined;
|
|
977
|
+
exactOut: NumericAmount;
|
|
978
|
+
amountOutMinimum?: undefined;
|
|
979
|
+
amountInMaximum?: NumericAmount | undefined;
|
|
980
|
+
};
|
|
981
|
+
interface SwapGateway {
|
|
982
|
+
submit: (method: 'RequestTrade', signedBody: Record<string, unknown>, options?: ChainSubmitOptions) => Promise<SubmittedTransaction<AppliedTrade>>;
|
|
847
983
|
readonly dexBackendBaseUrl: string;
|
|
848
|
-
readonly
|
|
849
|
-
readonly
|
|
984
|
+
readonly httpRequestor: HttpRequestor;
|
|
985
|
+
readonly requestTimeoutMs: number;
|
|
986
|
+
}
|
|
987
|
+
type SwapSymbols = Pick<Symbols, 'resolve'>;
|
|
988
|
+
/** Executes queued current-contract RequestTrade operations through the Chain Gateway. */
|
|
989
|
+
declare class Swaps {
|
|
990
|
+
private readonly gateway;
|
|
991
|
+
private readonly symbols;
|
|
992
|
+
private readonly signer?;
|
|
993
|
+
private readonly walletAddress?;
|
|
850
994
|
/**
|
|
851
|
-
*
|
|
852
|
-
* Use this to get quotes for token swaps without executing transactions.
|
|
995
|
+
* Creates a swap service.
|
|
853
996
|
*
|
|
854
997
|
* @example
|
|
855
|
-
* ```
|
|
856
|
-
*
|
|
857
|
-
* const quote = await gSwap.quoting.quoteExactInput(tokenA, tokenB, amount);
|
|
998
|
+
* ```ts
|
|
999
|
+
* const swaps = new Swaps(gateway, symbols, signer, 'client|alice');
|
|
858
1000
|
* ```
|
|
859
1001
|
*/
|
|
860
|
-
|
|
1002
|
+
constructor(gateway: SwapGateway, symbols: SwapSymbols, signer?: GalaChainSigner | undefined, walletAddress?: string | undefined);
|
|
861
1003
|
/**
|
|
862
|
-
*
|
|
863
|
-
*
|
|
1004
|
+
* Signs and submits an exact-input or exact-output RequestTrade DTO. The returned transaction
|
|
1005
|
+
* is QUEUED; call `await tx.confirm()` to obtain the executed trade or chain rejection.
|
|
864
1006
|
*
|
|
865
1007
|
* @example
|
|
866
|
-
* ```
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* // Add liquidity to a position using price range
|
|
871
|
-
* const result = await gSwap.positions.addLiquidityByPrice({
|
|
872
|
-
* walletAddress: 'eth|123...abc',
|
|
873
|
-
* positionId: '',
|
|
874
|
-
* token0: 'GALA|Unit|none|none',
|
|
875
|
-
* token1: 'GUSDC|Unit|none|none',
|
|
876
|
-
* fee: 500,
|
|
877
|
-
* tickSpacing: 10,
|
|
878
|
-
* minPrice: '0.45',
|
|
879
|
-
* maxPrice: '0.55',
|
|
880
|
-
* amount0Desired: '100',
|
|
881
|
-
* amount1Desired: '50',
|
|
882
|
-
* amount0Min: '95',
|
|
883
|
-
* amount1Min: '47.5'
|
|
1008
|
+
* ```ts
|
|
1009
|
+
* const submitted = await swaps.swap('GALA', 'GUSDC', 3000, {
|
|
1010
|
+
* exactIn: '100',
|
|
1011
|
+
* amountOutMinimum: '14',
|
|
884
1012
|
* });
|
|
885
1013
|
* ```
|
|
886
1014
|
*/
|
|
887
|
-
|
|
1015
|
+
swap(tokenIn: TokenRef, tokenOut: TokenRef, fee: FEE_TIER, amount: SwapAmount): Promise<SubmittedTransaction<AppliedTrade>>;
|
|
888
1016
|
/**
|
|
889
|
-
*
|
|
890
|
-
*
|
|
1017
|
+
* Confirm a swap by its durable `uniqueKey` without resubmitting it. This is the recovery
|
|
1018
|
+
* path after a `CONFIRMATION_TIMEOUT`, a `SUBMISSION_OUTCOME_UNKNOWN`, a `409` replay
|
|
1019
|
+
* conflict, or a process restart: it reads the same apply-results record that
|
|
1020
|
+
* `SubmittedTransaction.confirm()` reads (retained for 7 days) and resolves the applied trade
|
|
1021
|
+
* or throws the chain's rejection. The first read happens immediately unless
|
|
1022
|
+
* `initialDelayMs` is given.
|
|
891
1023
|
*
|
|
892
1024
|
* @example
|
|
893
|
-
* ```
|
|
894
|
-
*
|
|
895
|
-
* const result = await gSwap.swaps.swap(
|
|
896
|
-
* 'GALA|Unit|none|none',
|
|
897
|
-
* 'GUSDC|Unit|none|none',
|
|
898
|
-
* 500,
|
|
899
|
-
* { exactIn: '100', amountOutMinimum: '45' },
|
|
900
|
-
* 'eth|123...abc', // your wallet address
|
|
901
|
-
* );
|
|
1025
|
+
* ```ts
|
|
1026
|
+
* const applied = await swaps.confirmSwap('gswap-sdk-2f1c…');
|
|
902
1027
|
* ```
|
|
903
1028
|
*/
|
|
1029
|
+
confirmSwap(uniqueKey: string, options?: ConfirmOptions): Promise<AppliedTrade>;
|
|
1030
|
+
private buildRequestTradeDto;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/** SDK deployment environment. */
|
|
1034
|
+
type GSwapEnv = 'prod' | 'stage';
|
|
1035
|
+
/** Backend URL used by one SDK deployment environment. */
|
|
1036
|
+
interface GSwapEnvironmentConfig {
|
|
1037
|
+
dexBackendBaseUrl: string;
|
|
1038
|
+
}
|
|
1039
|
+
/** Built-in GalaSwap deployment environments. */
|
|
1040
|
+
declare const GSWAP_ENVIRONMENTS: Readonly<Record<GSwapEnv, GSwapEnvironmentConfig>>;
|
|
1041
|
+
|
|
1042
|
+
/** Options for constructing a backend-routed SDK client. */
|
|
1043
|
+
interface GSwapOptions {
|
|
1044
|
+
signer?: GalaChainSigner | undefined;
|
|
1045
|
+
walletAddress?: string | undefined;
|
|
1046
|
+
env?: GSwapEnv | undefined;
|
|
1047
|
+
dexBackendBaseUrl?: string | undefined;
|
|
1048
|
+
httpRequestor?: HttpRequestor | undefined;
|
|
1049
|
+
chainCallTimeoutMs?: number | undefined;
|
|
1050
|
+
}
|
|
1051
|
+
/** Main entry point for the current GalaChainDex SDK. */
|
|
1052
|
+
declare class GSwap {
|
|
1053
|
+
readonly dexBackendBaseUrl: string;
|
|
1054
|
+
readonly chainCallTimeoutMs: number;
|
|
1055
|
+
readonly signer: GalaChainSigner | undefined;
|
|
1056
|
+
readonly walletAddress: string | undefined;
|
|
1057
|
+
readonly gateway: ChainGateway;
|
|
1058
|
+
readonly symbols: Symbols;
|
|
1059
|
+
readonly quoting: Quoting;
|
|
1060
|
+
readonly pools: Pools;
|
|
1061
|
+
readonly positions: Positions;
|
|
904
1062
|
readonly swaps: Swaps;
|
|
905
|
-
/**
|
|
906
|
-
* User asset management operations.
|
|
907
|
-
* Use this to retrieve user token balances and asset information.
|
|
908
|
-
*
|
|
909
|
-
* @example
|
|
910
|
-
* ```typescript
|
|
911
|
-
* // Get user assets with pagination
|
|
912
|
-
* const assets = await gSwap.assets.getUserAssets('eth|123...abc', 1, 20);
|
|
913
|
-
* console.log(`User has ${assets.count} different tokens`);
|
|
914
|
-
* ```
|
|
915
|
-
*/
|
|
916
1063
|
readonly assets: Assets;
|
|
917
1064
|
/**
|
|
918
|
-
*
|
|
919
|
-
* Use this to manage event streaming and transaction status updates.
|
|
1065
|
+
* Create an SDK client for prod or stage.
|
|
920
1066
|
*
|
|
921
1067
|
* @example
|
|
922
1068
|
* ```typescript
|
|
923
|
-
*
|
|
924
|
-
* await
|
|
925
|
-
*
|
|
926
|
-
* // Check if socket is connected
|
|
927
|
-
* const isConnected = GSwap.events.eventSocketConnected();
|
|
1069
|
+
* const gSwap = new GSwap({ env: 'stage' });
|
|
1070
|
+
* const symbols = await gSwap.symbols.list();
|
|
928
1071
|
* ```
|
|
929
1072
|
*/
|
|
930
|
-
|
|
931
|
-
private readonly httpClient;
|
|
932
|
-
private readonly httpRequestor;
|
|
933
|
-
private readonly bundler;
|
|
934
|
-
readonly pools: Pools;
|
|
935
|
-
/**
|
|
936
|
-
* Creates a new SDK instance.
|
|
937
|
-
* @param options - Customization options.
|
|
938
|
-
* @param options.signer - The signer to use for authenticated operations. Required if you use any functionality that creates transactions (such as swapping). Not required for readonly operations.
|
|
939
|
-
* @param options.gatewayBaseUrl - Base URL for the GalaChain Gateway API.
|
|
940
|
-
* @param options.dexContractBasePath - Base path for DEX contract API endpoints, within the GalaChain Gateway API.
|
|
941
|
-
* @param options.tokenContractBasePath - Base path for token contract API endpoints, within the GalaChain Gateway API.
|
|
942
|
-
* @param options.bundlerBaseUrl - Base URL for the DEX transaction bundling API.
|
|
943
|
-
* @param options.bundlingAPIBasePath - Base path for transaction bundling API endpoints.
|
|
944
|
-
* @param options.dexBackendBaseUrl - Base URL for the DEX backend API (for user assets and other data).
|
|
945
|
-
* @param options.httpRequestor - Custom HTTP requestor to use for API calls. Defaults to the global `fetch` function.
|
|
946
|
-
* @param options.transactionWaitTimeoutMs - Timeout in milliseconds for waiting for transactions to complete. Defaults to 300,000 milliseconds (five minutes).
|
|
947
|
-
* @param options.walletAddress - Optional default wallet address for operations that require a wallet address (e.x. swapping). If not provided, you must specify the wallet address in each method call.
|
|
948
|
-
*/
|
|
949
|
-
constructor(options?: {
|
|
950
|
-
signer?: GalaChainSigner | undefined;
|
|
951
|
-
gatewayBaseUrl?: string | undefined;
|
|
952
|
-
dexContractBasePath?: string | undefined;
|
|
953
|
-
tokenContractBasePath?: string | undefined;
|
|
954
|
-
bundlerBaseUrl?: string | undefined;
|
|
955
|
-
bundlingAPIBasePath?: string | undefined;
|
|
956
|
-
dexBackendBaseUrl?: string | undefined;
|
|
957
|
-
transactionWaitTimeoutMs?: number | undefined;
|
|
958
|
-
walletAddress?: string | undefined;
|
|
959
|
-
httpRequestor?: HttpRequestor | undefined;
|
|
960
|
-
});
|
|
1073
|
+
constructor(options?: GSwapOptions);
|
|
961
1074
|
}
|
|
962
1075
|
|
|
1076
|
+
/** Error raised by the SDK for validation, gateway, chain, or transaction failures. */
|
|
963
1077
|
declare class GSwapSDKError extends Error {
|
|
964
1078
|
readonly code: string;
|
|
965
1079
|
readonly details?: Record<string, unknown> | undefined;
|
|
966
|
-
|
|
1080
|
+
readonly chainMessage: string | undefined;
|
|
1081
|
+
readonly retryAfterMs: number | undefined;
|
|
1082
|
+
constructor(message: string, code: string, details?: Record<string, unknown> | undefined, chainMessage?: string, retryAfterMs?: number);
|
|
1083
|
+
/** Create the standard missing-signer error. */
|
|
967
1084
|
static noSignerError(): GSwapSDKError;
|
|
968
|
-
|
|
969
|
-
static
|
|
970
|
-
|
|
971
|
-
static transactionWaitFailedError(txId: string, detail: Record<string, unknown>): GSwapSDKError;
|
|
972
|
-
static socketConnectionRequiredError(): GSwapSDKError;
|
|
1085
|
+
/** Create the error used when confirming a position write without a configured wallet address. */
|
|
1086
|
+
static noWalletAddressError(): GSwapSDKError;
|
|
1087
|
+
/** Create the error used when no pool can quote the requested pair. */
|
|
973
1088
|
static noPoolAvailableError(tokenIn: GalaChainTokenClassKey | string, tokenOut: GalaChainTokenClassKey | string, fee?: number): GSwapSDKError;
|
|
1089
|
+
/** Create the error used when a pool lacks liquidity for a quote. */
|
|
1090
|
+
static insufficientLiquidityError(tokenIn: GalaChainTokenClassKey | string, tokenOut: GalaChainTokenClassKey | string, fee?: number): GSwapSDKError;
|
|
1091
|
+
/** Convert a chain-gateway bounce into a typed SDK error. */
|
|
1092
|
+
static fromGatewayBounce(code: string, message: string, status: number, retryAfterMs?: number): GSwapSDKError;
|
|
1093
|
+
/** Convert a GalaChain `Status: 0` response into a typed SDK error. */
|
|
1094
|
+
static fromChainError(errorKey: string, message: string, details?: Record<string, unknown>): GSwapSDKError;
|
|
1095
|
+
/** Create the error used when a token is not registered by the current DEX contract. */
|
|
1096
|
+
static unknownTokenError(token: GalaChainTokenClassKey | string): GSwapSDKError;
|
|
1097
|
+
/** Create the error used when apply-results confirmation does not arrive in time. */
|
|
1098
|
+
static confirmationTimeoutError(uniqueKey: string, cause?: unknown): GSwapSDKError;
|
|
1099
|
+
/** Convert an unexpected HTTP response into an SDK error. */
|
|
1100
|
+
static fromErrorResponse(url: string, response: HTTPResponse): Promise<GSwapSDKError>;
|
|
974
1101
|
}
|
|
1102
|
+
/** Narrow an object property without trusting a cast at a network boundary. */
|
|
1103
|
+
declare function getObjectProperty(value: unknown, property: string): Record<string, unknown> | undefined;
|
|
1104
|
+
/** Read a string property from an unknown object. */
|
|
1105
|
+
declare function getStringProperty(value: unknown, property: string): string | undefined;
|
|
1106
|
+
/** Parse a response body, preserving non-JSON text for error reporting. */
|
|
1107
|
+
declare function parseJson(text: string): unknown;
|
|
975
1108
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1109
|
+
/** Common identity fields for v2 pool writes. */
|
|
1110
|
+
interface V2PoolWriteBase {
|
|
1111
|
+
token0: string;
|
|
1112
|
+
token1: string;
|
|
1113
|
+
fee: FEE_TIER;
|
|
1114
|
+
uniqueKey: string;
|
|
1115
|
+
}
|
|
1116
|
+
/** A v2 RequestTrade with exactly one selected trade-side quantity. */
|
|
1117
|
+
type RequestTradeDTO = V2PoolWriteBase & ({
|
|
1118
|
+
sell0Qty: string;
|
|
1119
|
+
sell1Qty?: never;
|
|
1120
|
+
buy0Qty?: never;
|
|
1121
|
+
buy1Qty?: never;
|
|
985
1122
|
} | {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1123
|
+
sell0Qty?: never;
|
|
1124
|
+
sell1Qty: string;
|
|
1125
|
+
buy0Qty?: never;
|
|
1126
|
+
buy1Qty?: never;
|
|
1127
|
+
} | {
|
|
1128
|
+
sell0Qty?: never;
|
|
1129
|
+
sell1Qty?: never;
|
|
1130
|
+
buy0Qty: string;
|
|
1131
|
+
buy1Qty?: never;
|
|
1132
|
+
} | {
|
|
1133
|
+
sell0Qty?: never;
|
|
1134
|
+
sell1Qty?: never;
|
|
1135
|
+
buy0Qty?: never;
|
|
1136
|
+
buy1Qty: string;
|
|
1137
|
+
}) & {
|
|
1138
|
+
amountOutMinimum?: string | undefined;
|
|
1139
|
+
amountInMaximum?: string | undefined;
|
|
991
1140
|
};
|
|
1141
|
+
/** A v2 liquidity deposit with exactly one selected deposit quantity. */
|
|
1142
|
+
type AddLiquidityDTO = V2PoolWriteBase & {
|
|
1143
|
+
tickLower: number;
|
|
1144
|
+
tickUpper: number;
|
|
1145
|
+
} & ({
|
|
1146
|
+
depositQuantityToken0: string;
|
|
1147
|
+
depositQuantityToken1?: never;
|
|
1148
|
+
} | {
|
|
1149
|
+
depositQuantityToken0?: never;
|
|
1150
|
+
depositQuantityToken1: string;
|
|
1151
|
+
});
|
|
1152
|
+
/** A v2 liquidity withdrawal; omitting both quantities closes the position. */
|
|
1153
|
+
type RemoveLiquidityDTO = V2PoolWriteBase & {
|
|
1154
|
+
tickLower: number;
|
|
1155
|
+
tickUpper: number;
|
|
1156
|
+
} & ({
|
|
1157
|
+
withdrawalQuantityToken0: string;
|
|
1158
|
+
withdrawalQuantityToken1?: never;
|
|
1159
|
+
} | {
|
|
1160
|
+
withdrawalQuantityToken0?: never;
|
|
1161
|
+
withdrawalQuantityToken1: string;
|
|
1162
|
+
} | {
|
|
1163
|
+
withdrawalQuantityToken0?: never;
|
|
1164
|
+
withdrawalQuantityToken1?: never;
|
|
1165
|
+
});
|
|
1166
|
+
/** A v2 request to sweep all fees from one position. */
|
|
1167
|
+
interface CollectPositionFeesDTO extends V2PoolWriteBase {
|
|
1168
|
+
tickLower: number;
|
|
1169
|
+
tickUpper: number;
|
|
1170
|
+
}
|
|
1171
|
+
/** A v2 pool creation request with exactly one initial-price representation. */
|
|
1172
|
+
type CreatePoolDTO = {
|
|
1173
|
+
token0Key: GalaChainTokenClassKey;
|
|
1174
|
+
token1Key: GalaChainTokenClassKey;
|
|
1175
|
+
token0Symbol: string;
|
|
1176
|
+
token1Symbol: string;
|
|
1177
|
+
fee: FEE_TIER;
|
|
1178
|
+
isPrivate?: boolean | undefined;
|
|
1179
|
+
privateAccess?: string[] | undefined;
|
|
1180
|
+
uniqueKey: string;
|
|
1181
|
+
} & ({
|
|
1182
|
+
startingPrice: string;
|
|
1183
|
+
startingSqrtPrice?: never;
|
|
1184
|
+
} | {
|
|
1185
|
+
startingPrice?: never;
|
|
1186
|
+
startingSqrtPrice: string;
|
|
1187
|
+
});
|
|
1188
|
+
/** Optional page cursor accepted by chain read methods. */
|
|
1189
|
+
interface PageDTO {
|
|
1190
|
+
limit?: number | undefined;
|
|
1191
|
+
bookmark?: string | undefined;
|
|
1192
|
+
}
|
|
1193
|
+
/** Fetch all registered trading symbols. */
|
|
1194
|
+
type FetchTokenTradingSymbolsDTO = PageDTO;
|
|
1195
|
+
/** Fetch a composite pool snapshot. */
|
|
1196
|
+
interface FetchCompositePoolDataDTO {
|
|
1197
|
+
token0: string;
|
|
1198
|
+
token1: string;
|
|
1199
|
+
fee: FEE_TIER;
|
|
1200
|
+
}
|
|
1201
|
+
/** Fetch one current trading price, or all prices when no pair is supplied. */
|
|
1202
|
+
type FetchCurrentTradingPricesDTO = Partial<FetchCompositePoolDataDTO> & PageDTO;
|
|
1203
|
+
/** Fetch pools, optionally narrowed to one pair and paged. */
|
|
1204
|
+
type FetchPoolsDTO = Partial<FetchCompositePoolDataDTO> & PageDTO;
|
|
1205
|
+
/** Fetch all liquidity positions, optionally narrowed to a pool reference. */
|
|
1206
|
+
interface FetchLiquidityPositionsDTO extends PageDTO {
|
|
1207
|
+
pool?: string | undefined;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/** Minimum tick supported by GalaChainDex. */
|
|
1211
|
+
declare const GC_MIN_TICK = -887272;
|
|
1212
|
+
/** Maximum tick supported by GalaChainDex. */
|
|
1213
|
+
declare const GC_MAX_TICK = 887272;
|
|
1214
|
+
/** Convert a tick to the corresponding square-root price. */
|
|
1215
|
+
declare function tickToSqrtPrice(tick: number): BigNumber;
|
|
1216
|
+
/** Return the greatest tick whose square-root price is no greater than the input. */
|
|
1217
|
+
declare function sqrtPriceToTick(sqrtPrice: BigNumber.Value): number;
|
|
1218
|
+
/** Return the greatest integer tick whose token1/token0 price is no greater than `price`. */
|
|
1219
|
+
declare function tickFromPrice(price: BigNumber.Value): number;
|
|
1220
|
+
/** Align a tick down to the nearest multiple of a positive spacing. */
|
|
1221
|
+
declare function alignTickDown(tick: number, spacing: number): number;
|
|
1222
|
+
/** Align a tick up to the nearest multiple of a positive spacing. */
|
|
1223
|
+
declare function alignTickUp(tick: number, spacing: number): number;
|
|
1224
|
+
/** Validate a position range against the global tick bounds and fee-tier spacing. */
|
|
1225
|
+
declare function assertTickRange(lower: number, upper: number, fee: FEE_TIER): void;
|
|
992
1226
|
|
|
993
1227
|
declare function validateNumericAmount(amount: NumericAmount, parameterName: string, allowZero?: boolean): void;
|
|
994
1228
|
declare function validatePriceValues(spotPrice: NumericAmount, lowerPrice: NumericAmount, upperPrice: NumericAmount): void;
|
|
995
1229
|
declare function validateTokenDecimals(decimals: number, parameterName: string): void;
|
|
996
1230
|
declare function validateTickRange(tickLower: number, tickUpper: number): void;
|
|
997
|
-
declare function validateFee(fee: number):
|
|
1231
|
+
declare function validateFee(fee: number): asserts fee is FEE_TIER;
|
|
998
1232
|
declare function validateTickSpacing(tickSpacing: number): void;
|
|
999
1233
|
declare function validateWalletAddress(address?: string): asserts address is string;
|
|
1000
1234
|
|
|
1001
|
-
export { Assets,
|
|
1235
|
+
export { ALL_FEE_TIERS, type AddLiquidityDTO, type AddLiquidityEstimate, type AppliedTrade, Assets, type BrowserWalletProvider, BrowserWalletSigner, ChainGateway, type ChainGatewayOptions, type ChainSubmissionResult, type ChainSubmitOptions, type CollectPositionFeesDTO, type CompositePool, type ConfirmOptions, type CreatePoolDTO, FEE_TIER, type FetchCompositePoolDataDTO, type FetchCurrentTradingPricesDTO, type FetchLiquidityPositionsDTO, type FetchPoolsDTO, type FetchTokenTradingSymbolsDTO, GC_MAX_TICK, GC_MIN_TICK, GSWAP_ENVIRONMENTS, GSwap, type GSwapEnv, type GSwapEnvironmentConfig, type GSwapOptions, GSwapSDKError, type GalaChainSigner, type GalaChainTokenClassKey, type GalaWalletScheme, GalaWalletSigner, type NumericAmount, type PageDTO, type PoolInfo, type PoolListInfo, Pools, type Position, type PositionConfirmationResult, Positions, type Price, type PriceIn, PrivateKeySigner, type QuoteResult, Quoting, type RemoveLiquidityDTO, type RemoveLiquidityEstimate, type RequestTradeDTO, type Slot0, type SqrtPrice, type SqrtPriceIn, SubmittedTransaction, type SwapAmount, Swaps, Symbols, TICK_SPACING_BY_FEE, type TokenBalance, type TokenClassKey, type TokenRef, type TradeExecution, type TradingSymbol, type UserAsset, type UserAssetsResult, type V2PoolWriteBase, alignTickDown, alignTickUp, assertTickRange, compositeKeyOf, getObjectProperty, getStringProperty, orderSymbols, parseJson, parseTokenClassKey, readOrderedSymbols, sqrtPriceToTick, tickFromPrice, tickToSqrtPrice, validateFee, validateNumericAmount, validatePriceValues, validateTickRange, validateTickSpacing, validateTokenDecimals, validateWalletAddress };
|