@flashnet/sdk 0.3.12-rc.2 → 0.3.12-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/dist/cjs/src/client/FlashnetClient.d.ts +40 -19
- package/dist/cjs/src/client/FlashnetClient.d.ts.map +1 -1
- package/dist/cjs/src/client/FlashnetClient.js +144 -228
- package/dist/cjs/src/client/FlashnetClient.js.map +1 -1
- package/dist/cjs/src/types/index.d.ts +5 -5
- package/dist/cjs/src/types/index.d.ts.map +1 -1
- package/dist/cjs/src/types/index.js.map +1 -1
- package/dist/esm/src/client/FlashnetClient.d.ts +40 -19
- package/dist/esm/src/client/FlashnetClient.d.ts.map +1 -1
- package/dist/esm/src/client/FlashnetClient.js +144 -228
- package/dist/esm/src/client/FlashnetClient.js.map +1 -1
- package/dist/esm/src/types/index.d.ts +5 -5
- package/dist/esm/src/types/index.d.ts.map +1 -1
- package/dist/esm/src/types/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IssuerSparkWallet } from "@buildonspark/issuer-sdk";
|
|
2
2
|
import type { SparkWallet } from "@buildonspark/spark-sdk";
|
|
3
|
-
import { type AddLiquidityResponse, type AllLpPositionsResponse, type ClientEnvironment, type ConfirmDepositResponse, type
|
|
3
|
+
import { type AddLiquidityResponse, type AllLpPositionsResponse, type ClientEnvironment, type ConfirmDepositResponse, type CreatePoolResponse, type ExecuteRouteSwapResponse, type FlashnetClientConfig, type FlashnetClientCustomConfig, type FlashnetClientEnvironmentConfig, type FlashnetClientLegacyConfig, type GetHostFeesResponse, type GetHostResponse, type GetIntegratorFeesResponse, type GetPoolHostFeesResponse, type ListGlobalSwapsQuery, type ListGlobalSwapsResponse, type ListPoolSwapsQuery, type ListPoolSwapsResponse, type ListPoolsQuery, type ListPoolsResponse, type ListUserSwapsQuery, type ListUserSwapsResponse, type LpPositionDetailsResponse, type NetworkType, type PoolDetailsResponse, type RegisterHostResponse, type RemoveLiquidityResponse, type SettlementPingResponse, type SimulateAddLiquidityRequest, type SimulateAddLiquidityResponse, type SimulateRemoveLiquidityRequest, type SimulateRemoveLiquidityResponse, type SimulateRouteSwapRequest, type SimulateRouteSwapResponse, type SimulateSwapRequest, type SimulateSwapResponse, type SparkNetworkType, type SwapResponse, type TransferAssetRecipient, type WithdrawHostFeesResponse, type WithdrawIntegratorFeesResponse } from "../types";
|
|
4
4
|
import { type SparkHumanReadableTokenIdentifier } from "../utils/tokenAddress";
|
|
5
5
|
export interface TokenBalance {
|
|
6
6
|
balance: bigint;
|
|
@@ -23,6 +23,14 @@ export interface WalletBalance {
|
|
|
23
23
|
export interface FlashnetClientOptions {
|
|
24
24
|
autoAuthenticate?: boolean;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Helper type for fixed lists
|
|
28
|
+
*/
|
|
29
|
+
type Tuple<T, N extends number, Acc extends readonly T[] = []> = Acc["length"] extends N ? Acc : Tuple<T, N, [...Acc, T]>;
|
|
30
|
+
/**
|
|
31
|
+
* Helper type that works for both fixed and unknown length lists
|
|
32
|
+
*/
|
|
33
|
+
type TupleArray<T, N extends number | unknown> = N extends number ? Tuple<T, N> & T[] : T[];
|
|
26
34
|
/**
|
|
27
35
|
* FlashnetClient - A comprehensive client for interacting with Flashnet AMM
|
|
28
36
|
*
|
|
@@ -121,7 +129,14 @@ export declare class FlashnetClient {
|
|
|
121
129
|
/**
|
|
122
130
|
* Check if wallet has sufficient balance for an operation
|
|
123
131
|
*/
|
|
124
|
-
|
|
132
|
+
checkBalance(params: {
|
|
133
|
+
balancesToCheck: {
|
|
134
|
+
assetAddress: string;
|
|
135
|
+
amount: string | bigint;
|
|
136
|
+
}[];
|
|
137
|
+
errorPrefix?: string;
|
|
138
|
+
walletBalance?: WalletBalance;
|
|
139
|
+
}): Promise<void>;
|
|
125
140
|
/**
|
|
126
141
|
* List pools with optional filters
|
|
127
142
|
*/
|
|
@@ -155,7 +170,7 @@ export declare class FlashnetClient {
|
|
|
155
170
|
/**
|
|
156
171
|
* Create a single-sided pool with automatic initial deposit
|
|
157
172
|
*
|
|
158
|
-
* This method creates a single-sided pool and automatically handles the initial deposit.
|
|
173
|
+
* This method creates a single-sided pool and by default automatically handles the initial deposit.
|
|
159
174
|
* The initial reserve amount will be transferred to the pool and confirmed.
|
|
160
175
|
*/
|
|
161
176
|
createSingleSidedPool(params: {
|
|
@@ -167,23 +182,8 @@ export declare class FlashnetClient {
|
|
|
167
182
|
lpFeeRateBps: number;
|
|
168
183
|
totalHostFeeRateBps: number;
|
|
169
184
|
hostNamespace?: string;
|
|
185
|
+
disableInitialDeposit?: boolean;
|
|
170
186
|
}): Promise<CreatePoolResponse>;
|
|
171
|
-
/**
|
|
172
|
-
* Create a single-sided pool without automatic initial deposit
|
|
173
|
-
*
|
|
174
|
-
* This method creates a single-sided pool.
|
|
175
|
-
* The initial reserve amount will be transferred to the pool and confirmed.
|
|
176
|
-
*/
|
|
177
|
-
createSingleSidedPoolNoInitialDeposit(params: {
|
|
178
|
-
assetAAddress: string;
|
|
179
|
-
assetBAddress: string;
|
|
180
|
-
assetAInitialReserve: string;
|
|
181
|
-
assetAPctSoldAtGraduation: number;
|
|
182
|
-
targetBRaisedAtGraduation: string;
|
|
183
|
-
lpFeeRateBps: number;
|
|
184
|
-
totalHostFeeRateBps: number;
|
|
185
|
-
hostNamespace?: string;
|
|
186
|
-
}): Promise<CreatePoolNoInitialDepsoitResponse>;
|
|
187
187
|
/**
|
|
188
188
|
* Confirm initial deposit for single-sided pool
|
|
189
189
|
*
|
|
@@ -208,6 +208,17 @@ export declare class FlashnetClient {
|
|
|
208
208
|
integratorFeeRateBps?: number;
|
|
209
209
|
integratorPublicKey?: string;
|
|
210
210
|
}): Promise<SwapResponse>;
|
|
211
|
+
executeSwapIntent(params: {
|
|
212
|
+
poolId: string;
|
|
213
|
+
transferId: string;
|
|
214
|
+
assetInAddress: string;
|
|
215
|
+
assetOutAddress: string;
|
|
216
|
+
amountIn: string;
|
|
217
|
+
maxSlippageBps: number;
|
|
218
|
+
minAmountOut: string;
|
|
219
|
+
integratorFeeRateBps?: number;
|
|
220
|
+
integratorPublicKey?: string;
|
|
221
|
+
}): Promise<SwapResponse>;
|
|
211
222
|
/**
|
|
212
223
|
* Simulate a route swap (multi-hop swap)
|
|
213
224
|
*/
|
|
@@ -340,6 +351,15 @@ export declare class FlashnetClient {
|
|
|
340
351
|
* Ping the settlement service
|
|
341
352
|
*/
|
|
342
353
|
ping(): Promise<SettlementPingResponse>;
|
|
354
|
+
/**
|
|
355
|
+
* Performs asset transfer using generalized asset address for both BTC and tokens.
|
|
356
|
+
*/
|
|
357
|
+
transferAsset(recipient: TransferAssetRecipient, checkBalanceErrorPrefix?: string): Promise<string>;
|
|
358
|
+
/**
|
|
359
|
+
* Performs asset transfers using generalized asset addresses for both BTC and tokens.
|
|
360
|
+
* Supports optional generic to hardcode recipients length so output list can be typed with same length.
|
|
361
|
+
*/
|
|
362
|
+
transferAssets<N extends number | unknown = unknown>(recipients: TupleArray<TransferAssetRecipient, N>, checkBalanceErrorPrefix?: string): Promise<TupleArray<string, N>>;
|
|
343
363
|
/**
|
|
344
364
|
* Helper method to add initial liquidity after pool creation
|
|
345
365
|
*/
|
|
@@ -349,4 +369,5 @@ export declare class FlashnetClient {
|
|
|
349
369
|
*/
|
|
350
370
|
cleanup(): Promise<void>;
|
|
351
371
|
}
|
|
372
|
+
export {};
|
|
352
373
|
//# sourceMappingURL=FlashnetClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlashnetClient.d.ts","sourceRoot":"","sources":["../../../../src/client/FlashnetClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAS3D,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,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BjC;;OAEG;YACW,mBAAmB;IAiEjC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -250,14 +250,27 @@ class FlashnetClient {
|
|
|
250
250
|
/**
|
|
251
251
|
* Check if wallet has sufficient balance for an operation
|
|
252
252
|
*/
|
|
253
|
-
async checkBalance(
|
|
254
|
-
const balance = await this.getBalance();
|
|
253
|
+
async checkBalance(params) {
|
|
254
|
+
const balance = params.walletBalance ?? (await this.getBalance());
|
|
255
|
+
// Check balance
|
|
256
|
+
const requirements = {
|
|
257
|
+
tokens: new Map(),
|
|
258
|
+
};
|
|
259
|
+
for (const balance of params.balancesToCheck) {
|
|
260
|
+
if (balance.assetAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
261
|
+
requirements.btc = BigInt(balance.amount);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
requirements.tokens?.set(balance.assetAddress, BigInt(balance.amount));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
255
267
|
// Check BTC balance
|
|
256
268
|
if (requirements.btc && balance.balance < requirements.btc) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
269
|
+
throw new Error([
|
|
270
|
+
params.errorPrefix ?? "",
|
|
271
|
+
`Insufficient BTC balance. `,
|
|
272
|
+
`Required: ${requirements.btc} sats, Available: ${balance.balance} sats`,
|
|
273
|
+
].join(""));
|
|
261
274
|
}
|
|
262
275
|
// Check token balances
|
|
263
276
|
if (requirements.tokens) {
|
|
@@ -268,14 +281,14 @@ class FlashnetClient {
|
|
|
268
281
|
balance.tokenBalances.get(hrKey);
|
|
269
282
|
const available = effectiveTokenBalance?.balance ?? 0n;
|
|
270
283
|
if (available < requiredAmount) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
284
|
+
throw new Error([
|
|
285
|
+
params.errorPrefix ?? "",
|
|
286
|
+
`Insufficient token balance for ${tokenPubkey}. `,
|
|
287
|
+
`Required: ${requiredAmount}, Available: ${available}`,
|
|
288
|
+
].join(""));
|
|
275
289
|
}
|
|
276
290
|
}
|
|
277
291
|
}
|
|
278
|
-
return { sufficient: true };
|
|
279
292
|
}
|
|
280
293
|
// ===== Pool Operations =====
|
|
281
294
|
/**
|
|
@@ -314,26 +327,19 @@ class FlashnetClient {
|
|
|
314
327
|
await this.ensureInitialized();
|
|
315
328
|
// Check if we need to add initial liquidity
|
|
316
329
|
if (params.initialLiquidity) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
requirements.tokens?.set(params.assetBAddress, params.initialLiquidity.assetBAmount);
|
|
332
|
-
}
|
|
333
|
-
const balanceCheck = await this.checkBalance(requirements);
|
|
334
|
-
if (!balanceCheck.sufficient) {
|
|
335
|
-
throw new Error(`Insufficient balance for initial liquidity: ${balanceCheck.message}`);
|
|
336
|
-
}
|
|
330
|
+
await this.checkBalance({
|
|
331
|
+
balancesToCheck: [
|
|
332
|
+
{
|
|
333
|
+
assetAddress: params.assetAAddress,
|
|
334
|
+
amount: params.initialLiquidity.assetAAmount,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
assetAddress: params.assetBAddress,
|
|
338
|
+
amount: params.initialLiquidity.assetBAmount,
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
errorPrefix: "Insufficient balance for initial liquidity: ",
|
|
342
|
+
});
|
|
337
343
|
}
|
|
338
344
|
// Generate intent
|
|
339
345
|
const nonce = index$2.generateNonce();
|
|
@@ -369,31 +375,10 @@ class FlashnetClient {
|
|
|
369
375
|
/**
|
|
370
376
|
* Create a single-sided pool with automatic initial deposit
|
|
371
377
|
*
|
|
372
|
-
* This method creates a single-sided pool and automatically handles the initial deposit.
|
|
378
|
+
* This method creates a single-sided pool and by default automatically handles the initial deposit.
|
|
373
379
|
* The initial reserve amount will be transferred to the pool and confirmed.
|
|
374
380
|
*/
|
|
375
381
|
async createSingleSidedPool(params) {
|
|
376
|
-
const createResponse = await this.createSingleSidedPoolNoInitialDeposit(params);
|
|
377
|
-
try {
|
|
378
|
-
const assetATransferId = await createResponse.transferInitialDeposit();
|
|
379
|
-
const confirmResponse = await this.confirmInitialDeposit(createResponse.poolId, assetATransferId);
|
|
380
|
-
if (!confirmResponse.confirmed) {
|
|
381
|
-
throw new Error(`Failed to confirm initial deposit: ${confirmResponse.message}`);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
catch (error) {
|
|
385
|
-
// If initial deposit fails, we should inform the user
|
|
386
|
-
throw new Error(`Pool created with ID ${createResponse.poolId}, but initial deposit failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
387
|
-
}
|
|
388
|
-
return createResponse;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Create a single-sided pool without automatic initial deposit
|
|
392
|
-
*
|
|
393
|
-
* This method creates a single-sided pool.
|
|
394
|
-
* The initial reserve amount will be transferred to the pool and confirmed.
|
|
395
|
-
*/
|
|
396
|
-
async createSingleSidedPoolNoInitialDeposit(params) {
|
|
397
382
|
await this.ensureInitialized();
|
|
398
383
|
// check that assetAPctSoldAtGraduation is between 0 and 100 - no decimals
|
|
399
384
|
if (params.assetAPctSoldAtGraduation < 0 ||
|
|
@@ -403,20 +388,15 @@ class FlashnetClient {
|
|
|
403
388
|
if (!params.hostNamespace && params.totalHostFeeRateBps < 10) {
|
|
404
389
|
throw new Error(`Host fee must be greater than 10 bps when no host namespace is provided`);
|
|
405
390
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
const balanceCheck = await this.checkBalance(requirements);
|
|
417
|
-
if (!balanceCheck.sufficient) {
|
|
418
|
-
throw new Error(`Insufficient balance for pool creation: ${balanceCheck.message}`);
|
|
419
|
-
}
|
|
391
|
+
await this.checkBalance({
|
|
392
|
+
balancesToCheck: [
|
|
393
|
+
{
|
|
394
|
+
assetAddress: params.assetAInitialReserve,
|
|
395
|
+
amount: params.assetAInitialReserve,
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
errorPrefix: "Insufficient balance for pool creation: ",
|
|
399
|
+
});
|
|
420
400
|
// Generate intent
|
|
421
401
|
const nonce = index$2.generateNonce();
|
|
422
402
|
const intentMessage = intents.generatePoolInitializationIntentMessage({
|
|
@@ -447,32 +427,30 @@ class FlashnetClient {
|
|
|
447
427
|
signature: Buffer.from(signature).toString("hex"),
|
|
448
428
|
};
|
|
449
429
|
const createResponse = await this.typedApi.createSingleSidedPool(request);
|
|
450
|
-
|
|
451
|
-
|
|
430
|
+
if (params.disableInitialDeposit) {
|
|
431
|
+
return createResponse;
|
|
432
|
+
}
|
|
433
|
+
try {
|
|
452
434
|
// Transfer initial reserve to the pool using new address encoding
|
|
453
435
|
const lpSparkAddress = sparkAddress.encodeSparkAddressNew({
|
|
454
|
-
identityPublicKey: poolId,
|
|
436
|
+
identityPublicKey: createResponse.poolId,
|
|
455
437
|
network: this.sparkNetwork,
|
|
456
438
|
});
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return await this._wallet.transferTokens({
|
|
466
|
-
tokenIdentifier: this.toHumanReadableTokenIdentifier(params.assetAAddress),
|
|
467
|
-
tokenAmount: BigInt(params.assetAInitialReserve),
|
|
468
|
-
receiverSparkAddress: lpSparkAddress,
|
|
469
|
-
});
|
|
439
|
+
const assetATransferId = await this.transferAsset({
|
|
440
|
+
receiverSparkAddress: lpSparkAddress,
|
|
441
|
+
assetAddress: params.assetAAddress,
|
|
442
|
+
amount: params.assetAInitialReserve,
|
|
443
|
+
});
|
|
444
|
+
const confirmResponse = await this.confirmInitialDeposit(createResponse.poolId, assetATransferId);
|
|
445
|
+
if (!confirmResponse.confirmed) {
|
|
446
|
+
throw new Error(`Failed to confirm initial deposit: ${confirmResponse.message}`);
|
|
470
447
|
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
// If initial deposit fails, we should inform the user
|
|
451
|
+
throw new Error(`Pool created with ID ${createResponse.poolId}, but initial deposit failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
452
|
+
}
|
|
453
|
+
return createResponse;
|
|
476
454
|
}
|
|
477
455
|
/**
|
|
478
456
|
* Confirm initial deposit for single-sided pool
|
|
@@ -513,46 +491,30 @@ class FlashnetClient {
|
|
|
513
491
|
*/
|
|
514
492
|
async executeSwap(params) {
|
|
515
493
|
await this.ensureInitialized();
|
|
516
|
-
// Check balance
|
|
517
|
-
const requirements = {
|
|
518
|
-
tokens: new Map(),
|
|
519
|
-
};
|
|
520
|
-
if (params.assetInAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
521
|
-
requirements.btc = BigInt(params.amountIn);
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
-
requirements.tokens?.set(params.assetInAddress, BigInt(params.amountIn));
|
|
525
|
-
}
|
|
526
|
-
const balanceCheck = await this.checkBalance(requirements);
|
|
527
|
-
if (!balanceCheck.sufficient) {
|
|
528
|
-
throw new Error(`Insufficient balance for swap: ${balanceCheck.message}`);
|
|
529
|
-
}
|
|
530
494
|
// Transfer assets to pool using new address encoding
|
|
531
495
|
const lpSparkAddress = sparkAddress.encodeSparkAddressNew({
|
|
532
496
|
identityPublicKey: params.poolId,
|
|
533
497
|
network: this.sparkNetwork,
|
|
534
498
|
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
});
|
|
549
|
-
}
|
|
499
|
+
const transferId = await this.transferAsset({
|
|
500
|
+
receiverSparkAddress: lpSparkAddress,
|
|
501
|
+
assetAddress: params.assetInAddress,
|
|
502
|
+
amount: params.amountIn,
|
|
503
|
+
}, "Insufficient balance for swap: ");
|
|
504
|
+
const response = await this.executeSwapIntent({
|
|
505
|
+
...params,
|
|
506
|
+
transferId,
|
|
507
|
+
});
|
|
508
|
+
return response;
|
|
509
|
+
}
|
|
510
|
+
async executeSwapIntent(params) {
|
|
511
|
+
await this.ensureInitialized();
|
|
550
512
|
// Generate swap intent
|
|
551
513
|
const nonce = index$2.generateNonce();
|
|
552
514
|
const intentMessage = intents.generatePoolSwapIntentMessage({
|
|
553
515
|
userPublicKey: this.publicKey,
|
|
554
516
|
lpIdentityPublicKey: params.poolId,
|
|
555
|
-
assetInSparkTransferId: transferId,
|
|
517
|
+
assetInSparkTransferId: params.transferId,
|
|
556
518
|
assetInTokenPublicKey: this.toHexTokenIdentifier(params.assetInAddress),
|
|
557
519
|
assetOutTokenPublicKey: this.toHexTokenIdentifier(params.assetOutAddress),
|
|
558
520
|
amountIn: params.amountIn.toString(),
|
|
@@ -572,7 +534,7 @@ class FlashnetClient {
|
|
|
572
534
|
amountIn: params.amountIn.toString(),
|
|
573
535
|
maxSlippageBps: params.maxSlippageBps?.toString(),
|
|
574
536
|
minAmountOut: params.minAmountOut,
|
|
575
|
-
assetInSparkTransferId: transferId,
|
|
537
|
+
assetInSparkTransferId: params.transferId,
|
|
576
538
|
totalIntegratorFeeRateBps: params.integratorFeeRateBps?.toString() || "0",
|
|
577
539
|
integratorPublicKey: params.integratorPublicKey || "",
|
|
578
540
|
nonce,
|
|
@@ -601,20 +563,6 @@ class FlashnetClient {
|
|
|
601
563
|
*/
|
|
602
564
|
async executeRouteSwap(params) {
|
|
603
565
|
await this.ensureInitialized();
|
|
604
|
-
// Check balance for initial asset
|
|
605
|
-
const requirements = {
|
|
606
|
-
tokens: new Map(),
|
|
607
|
-
};
|
|
608
|
-
if (params.initialAssetAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
609
|
-
requirements.btc = BigInt(params.inputAmount);
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
requirements.tokens?.set(params.initialAssetAddress, BigInt(params.inputAmount));
|
|
613
|
-
}
|
|
614
|
-
const balanceCheck = await this.checkBalance(requirements);
|
|
615
|
-
if (!balanceCheck.sufficient) {
|
|
616
|
-
throw new Error(`Insufficient balance for route swap: ${balanceCheck.message}`);
|
|
617
|
-
}
|
|
618
566
|
// Validate hops array
|
|
619
567
|
if (!params.hops.length) {
|
|
620
568
|
throw new Error("Route swap requires at least one hop");
|
|
@@ -628,21 +576,11 @@ class FlashnetClient {
|
|
|
628
576
|
identityPublicKey: firstPoolId,
|
|
629
577
|
network: this.sparkNetwork,
|
|
630
578
|
});
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
});
|
|
637
|
-
initialTransferId = transfer.id;
|
|
638
|
-
}
|
|
639
|
-
else {
|
|
640
|
-
initialTransferId = await this._wallet.transferTokens({
|
|
641
|
-
tokenIdentifier: this.toHumanReadableTokenIdentifier(params.initialAssetAddress),
|
|
642
|
-
tokenAmount: BigInt(params.inputAmount),
|
|
643
|
-
receiverSparkAddress: lpSparkAddress,
|
|
644
|
-
});
|
|
645
|
-
}
|
|
579
|
+
const initialTransferId = await this.transferAsset({
|
|
580
|
+
receiverSparkAddress: lpSparkAddress,
|
|
581
|
+
assetAddress: params.initialAssetAddress,
|
|
582
|
+
amount: params.inputAmount,
|
|
583
|
+
}, "Insufficient balance for route swap: ");
|
|
646
584
|
// Prepare hops for validation
|
|
647
585
|
const hops = params.hops.map((hop) => ({
|
|
648
586
|
lpIdentityPublicKey: hop.poolId,
|
|
@@ -721,63 +659,23 @@ class FlashnetClient {
|
|
|
721
659
|
await this.ensureInitialized();
|
|
722
660
|
// Get pool details to know which assets we're dealing with
|
|
723
661
|
const pool = await this.getPool(params.poolId);
|
|
724
|
-
// Check balance
|
|
725
|
-
const requirements = {
|
|
726
|
-
tokens: new Map(),
|
|
727
|
-
};
|
|
728
|
-
if (pool.assetAAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
729
|
-
requirements.btc = BigInt(params.assetAAmount);
|
|
730
|
-
}
|
|
731
|
-
else {
|
|
732
|
-
requirements.tokens?.set(pool.assetAAddress, BigInt(params.assetAAmount));
|
|
733
|
-
}
|
|
734
|
-
if (pool.assetBAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
735
|
-
requirements.btc = (requirements.btc || 0n) + BigInt(params.assetBAmount);
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
738
|
-
requirements.tokens?.set(pool.assetBAddress, BigInt(params.assetBAmount));
|
|
739
|
-
}
|
|
740
|
-
const balanceCheck = await this.checkBalance(requirements);
|
|
741
|
-
if (!balanceCheck.sufficient) {
|
|
742
|
-
throw new Error(`Insufficient balance for adding liquidity: ${balanceCheck.message}`);
|
|
743
|
-
}
|
|
744
662
|
// Transfer assets to pool using new address encoding
|
|
745
663
|
const lpSparkAddress = sparkAddress.encodeSparkAddressNew({
|
|
746
664
|
identityPublicKey: params.poolId,
|
|
747
665
|
network: this.sparkNetwork,
|
|
748
666
|
});
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
if (pool.assetAAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
752
|
-
const transfer = await this._wallet.transfer({
|
|
753
|
-
amountSats: Number(params.assetAAmount),
|
|
667
|
+
const [assetATransferId, assetBTransferId] = await this.transferAssets([
|
|
668
|
+
{
|
|
754
669
|
receiverSparkAddress: lpSparkAddress,
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
assetATransferId = await this._wallet.transferTokens({
|
|
760
|
-
tokenIdentifier: this.toHumanReadableTokenIdentifier(pool.assetAAddress),
|
|
761
|
-
tokenAmount: BigInt(params.assetAAmount),
|
|
670
|
+
assetAddress: pool.assetAAddress,
|
|
671
|
+
amount: params.assetAAmount,
|
|
672
|
+
},
|
|
673
|
+
{
|
|
762
674
|
receiverSparkAddress: lpSparkAddress,
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
if (pool.assetBAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
768
|
-
const transfer = await this._wallet.transfer({
|
|
769
|
-
amountSats: Number(params.assetBAmount),
|
|
770
|
-
receiverSparkAddress: lpSparkAddress,
|
|
771
|
-
});
|
|
772
|
-
assetBTransferId = transfer.id;
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
assetBTransferId = await this._wallet.transferTokens({
|
|
776
|
-
tokenIdentifier: this.toHumanReadableTokenIdentifier(pool.assetBAddress),
|
|
777
|
-
tokenAmount: BigInt(params.assetBAmount),
|
|
778
|
-
receiverSparkAddress: lpSparkAddress,
|
|
779
|
-
});
|
|
780
|
-
}
|
|
675
|
+
assetAddress: pool.assetBAddress,
|
|
676
|
+
amount: params.assetBAmount,
|
|
677
|
+
},
|
|
678
|
+
], "Insufficient balance for adding liquidity: ");
|
|
781
679
|
// Generate add liquidity intent
|
|
782
680
|
const nonce = index$2.generateNonce();
|
|
783
681
|
const intentMessage = intents.generateAddLiquidityIntentMessage({
|
|
@@ -1046,6 +944,44 @@ class FlashnetClient {
|
|
|
1046
944
|
return this.typedApi.ping();
|
|
1047
945
|
}
|
|
1048
946
|
// ===== Helper Methods =====
|
|
947
|
+
/**
|
|
948
|
+
* Performs asset transfer using generalized asset address for both BTC and tokens.
|
|
949
|
+
*/
|
|
950
|
+
async transferAsset(recipient, checkBalanceErrorPrefix) {
|
|
951
|
+
const transferIds = await this.transferAssets([recipient], checkBalanceErrorPrefix);
|
|
952
|
+
return transferIds[0];
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Performs asset transfers using generalized asset addresses for both BTC and tokens.
|
|
956
|
+
* Supports optional generic to hardcode recipients length so output list can be typed with same length.
|
|
957
|
+
*/
|
|
958
|
+
async transferAssets(recipients, checkBalanceErrorPrefix) {
|
|
959
|
+
if (checkBalanceErrorPrefix) {
|
|
960
|
+
await this.checkBalance({
|
|
961
|
+
balancesToCheck: recipients,
|
|
962
|
+
errorPrefix: checkBalanceErrorPrefix,
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
const transferIds = [];
|
|
966
|
+
for (const recipient of recipients) {
|
|
967
|
+
if (recipient.assetAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
968
|
+
const transfer = await this._wallet.transfer({
|
|
969
|
+
amountSats: Number(recipient.amount),
|
|
970
|
+
receiverSparkAddress: recipient.receiverSparkAddress,
|
|
971
|
+
});
|
|
972
|
+
transferIds.push(transfer.id);
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
const transferId = await this._wallet.transferTokens({
|
|
976
|
+
tokenIdentifier: this.toHumanReadableTokenIdentifier(recipient.assetAddress),
|
|
977
|
+
tokenAmount: BigInt(recipient.amount),
|
|
978
|
+
receiverSparkAddress: recipient.receiverSparkAddress,
|
|
979
|
+
});
|
|
980
|
+
transferIds.push(transferId);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return transferIds;
|
|
984
|
+
}
|
|
1049
985
|
/**
|
|
1050
986
|
* Helper method to add initial liquidity after pool creation
|
|
1051
987
|
*/
|
|
@@ -1054,38 +990,18 @@ class FlashnetClient {
|
|
|
1054
990
|
identityPublicKey: poolId,
|
|
1055
991
|
network: this.sparkNetwork,
|
|
1056
992
|
});
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
if (assetAAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
1060
|
-
const transfer = await this._wallet.transfer({
|
|
1061
|
-
amountSats: Number(assetAAmount),
|
|
1062
|
-
receiverSparkAddress: lpSparkAddress,
|
|
1063
|
-
});
|
|
1064
|
-
assetATransferId = transfer.id;
|
|
1065
|
-
}
|
|
1066
|
-
else {
|
|
1067
|
-
assetATransferId = await this._wallet.transferTokens({
|
|
1068
|
-
tokenIdentifier: this.toHumanReadableTokenIdentifier(assetAAddress),
|
|
1069
|
-
tokenAmount: BigInt(assetAAmount),
|
|
993
|
+
const [assetATransferId, assetBTransferId] = await this.transferAssets([
|
|
994
|
+
{
|
|
1070
995
|
receiverSparkAddress: lpSparkAddress,
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
if (assetBAddress === index$1.BTC_ASSET_PUBKEY) {
|
|
1076
|
-
const transfer = await this._wallet.transfer({
|
|
1077
|
-
amountSats: Number(assetBAmount),
|
|
996
|
+
assetAddress: assetAAddress,
|
|
997
|
+
amount: assetAAmount,
|
|
998
|
+
},
|
|
999
|
+
{
|
|
1078
1000
|
receiverSparkAddress: lpSparkAddress,
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
assetBTransferId = await this._wallet.transferTokens({
|
|
1084
|
-
tokenIdentifier: this.toHumanReadableTokenIdentifier(assetBAddress),
|
|
1085
|
-
tokenAmount: BigInt(assetBAmount),
|
|
1086
|
-
receiverSparkAddress: lpSparkAddress,
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1001
|
+
assetAddress: assetBAddress,
|
|
1002
|
+
amount: assetBAmount,
|
|
1003
|
+
},
|
|
1004
|
+
]);
|
|
1089
1005
|
// Add liquidity
|
|
1090
1006
|
const nonce = index$2.generateNonce();
|
|
1091
1007
|
const intentMessage = intents.generateAddLiquidityIntentMessage({
|