@chainflip/sdk 1.6.3 → 1.6.5
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/swap.d.mts +17 -13
- package/dist/swap.d.ts +17 -13
- package/dist/swap.js +309 -293
- package/dist/swap.mjs +77 -61
- package/package.json +1 -1
package/dist/swap.d.mts
CHANGED
|
@@ -85,17 +85,17 @@ type QuoteDetails = {
|
|
|
85
85
|
lowLiquidityWarning: boolean | undefined;
|
|
86
86
|
estimatedDurationSeconds: number;
|
|
87
87
|
estimatedPrice: string;
|
|
88
|
+
dcaParams?: {
|
|
89
|
+
numberOfChunks: number;
|
|
90
|
+
chunkIntervalBlocks: number;
|
|
91
|
+
};
|
|
92
|
+
type: QuoteType;
|
|
88
93
|
};
|
|
89
94
|
type BoostedQuoteDetails = QuoteDetails & {
|
|
90
95
|
estimatedBoostFeeBps: number;
|
|
91
96
|
};
|
|
92
97
|
type QuoteQueryResponse = QuoteDetails & {
|
|
93
98
|
boostQuote?: BoostedQuoteDetails;
|
|
94
|
-
dcaParams?: {
|
|
95
|
-
numberOfChunks: number;
|
|
96
|
-
chunkIntervalBlocks: number;
|
|
97
|
-
};
|
|
98
|
-
type: QuoteType;
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
interface ExecuteSwapParams {
|
|
@@ -366,7 +366,7 @@ interface DepositChannelFields {
|
|
|
366
366
|
depositAddress: string;
|
|
367
367
|
srcChainExpiryBlock: string;
|
|
368
368
|
estimatedExpiryTime: number;
|
|
369
|
-
expectedDepositAmount: string;
|
|
369
|
+
expectedDepositAmount: string | undefined;
|
|
370
370
|
isExpired: boolean;
|
|
371
371
|
openedThroughBackend: boolean;
|
|
372
372
|
affiliateBrokers: AffiliateBroker[];
|
|
@@ -385,12 +385,12 @@ interface DepositFields {
|
|
|
385
385
|
}
|
|
386
386
|
type ChunkInfo = {
|
|
387
387
|
inputAmount: string;
|
|
388
|
-
intermediateAmount
|
|
389
|
-
outputAmount
|
|
388
|
+
intermediateAmount: string | undefined;
|
|
389
|
+
outputAmount: string | undefined;
|
|
390
390
|
scheduledAt: number;
|
|
391
391
|
scheduledBlockIndex: string;
|
|
392
|
-
executedAt
|
|
393
|
-
executedBlockIndex
|
|
392
|
+
executedAt: number | undefined;
|
|
393
|
+
executedBlockIndex: string | undefined;
|
|
394
394
|
retryCount: number;
|
|
395
395
|
};
|
|
396
396
|
type PickRequired<T> = {
|
|
@@ -402,13 +402,13 @@ interface SwapFields {
|
|
|
402
402
|
swappedInputAmount: string;
|
|
403
403
|
swappedIntermediateAmount: string;
|
|
404
404
|
swappedOutputAmount: string;
|
|
405
|
-
regular
|
|
406
|
-
dca
|
|
405
|
+
regular: ChunkInfo | undefined;
|
|
406
|
+
dca: {
|
|
407
407
|
lastExecutedChunk: ChunkInfo | null;
|
|
408
408
|
currentChunk: PickRequired<ChunkInfo> | null;
|
|
409
409
|
executedChunks: number;
|
|
410
410
|
remainingChunks: number;
|
|
411
|
-
};
|
|
411
|
+
} | undefined;
|
|
412
412
|
}
|
|
413
413
|
interface EgressFields {
|
|
414
414
|
amount: string;
|
|
@@ -475,6 +475,9 @@ type SwapSDKOptions = {
|
|
|
475
475
|
commissionBps: number;
|
|
476
476
|
};
|
|
477
477
|
rpcUrl?: string;
|
|
478
|
+
enabledFeatures?: {
|
|
479
|
+
dca?: boolean;
|
|
480
|
+
};
|
|
478
481
|
};
|
|
479
482
|
declare class SwapSDK {
|
|
480
483
|
private readonly options;
|
|
@@ -482,6 +485,7 @@ declare class SwapSDK {
|
|
|
482
485
|
private readonly trpc;
|
|
483
486
|
private stateChainEnvironment?;
|
|
484
487
|
private supportedAssets?;
|
|
488
|
+
private dcaEnabled;
|
|
485
489
|
constructor(options?: SwapSDKOptions);
|
|
486
490
|
getChains(sourceChain?: Chain): Promise<ChainData[]>;
|
|
487
491
|
private getStateChainEnvironment;
|
package/dist/swap.d.ts
CHANGED
|
@@ -85,17 +85,17 @@ type QuoteDetails = {
|
|
|
85
85
|
lowLiquidityWarning: boolean | undefined;
|
|
86
86
|
estimatedDurationSeconds: number;
|
|
87
87
|
estimatedPrice: string;
|
|
88
|
+
dcaParams?: {
|
|
89
|
+
numberOfChunks: number;
|
|
90
|
+
chunkIntervalBlocks: number;
|
|
91
|
+
};
|
|
92
|
+
type: QuoteType;
|
|
88
93
|
};
|
|
89
94
|
type BoostedQuoteDetails = QuoteDetails & {
|
|
90
95
|
estimatedBoostFeeBps: number;
|
|
91
96
|
};
|
|
92
97
|
type QuoteQueryResponse = QuoteDetails & {
|
|
93
98
|
boostQuote?: BoostedQuoteDetails;
|
|
94
|
-
dcaParams?: {
|
|
95
|
-
numberOfChunks: number;
|
|
96
|
-
chunkIntervalBlocks: number;
|
|
97
|
-
};
|
|
98
|
-
type: QuoteType;
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
interface ExecuteSwapParams {
|
|
@@ -366,7 +366,7 @@ interface DepositChannelFields {
|
|
|
366
366
|
depositAddress: string;
|
|
367
367
|
srcChainExpiryBlock: string;
|
|
368
368
|
estimatedExpiryTime: number;
|
|
369
|
-
expectedDepositAmount: string;
|
|
369
|
+
expectedDepositAmount: string | undefined;
|
|
370
370
|
isExpired: boolean;
|
|
371
371
|
openedThroughBackend: boolean;
|
|
372
372
|
affiliateBrokers: AffiliateBroker[];
|
|
@@ -385,12 +385,12 @@ interface DepositFields {
|
|
|
385
385
|
}
|
|
386
386
|
type ChunkInfo = {
|
|
387
387
|
inputAmount: string;
|
|
388
|
-
intermediateAmount
|
|
389
|
-
outputAmount
|
|
388
|
+
intermediateAmount: string | undefined;
|
|
389
|
+
outputAmount: string | undefined;
|
|
390
390
|
scheduledAt: number;
|
|
391
391
|
scheduledBlockIndex: string;
|
|
392
|
-
executedAt
|
|
393
|
-
executedBlockIndex
|
|
392
|
+
executedAt: number | undefined;
|
|
393
|
+
executedBlockIndex: string | undefined;
|
|
394
394
|
retryCount: number;
|
|
395
395
|
};
|
|
396
396
|
type PickRequired<T> = {
|
|
@@ -402,13 +402,13 @@ interface SwapFields {
|
|
|
402
402
|
swappedInputAmount: string;
|
|
403
403
|
swappedIntermediateAmount: string;
|
|
404
404
|
swappedOutputAmount: string;
|
|
405
|
-
regular
|
|
406
|
-
dca
|
|
405
|
+
regular: ChunkInfo | undefined;
|
|
406
|
+
dca: {
|
|
407
407
|
lastExecutedChunk: ChunkInfo | null;
|
|
408
408
|
currentChunk: PickRequired<ChunkInfo> | null;
|
|
409
409
|
executedChunks: number;
|
|
410
410
|
remainingChunks: number;
|
|
411
|
-
};
|
|
411
|
+
} | undefined;
|
|
412
412
|
}
|
|
413
413
|
interface EgressFields {
|
|
414
414
|
amount: string;
|
|
@@ -475,6 +475,9 @@ type SwapSDKOptions = {
|
|
|
475
475
|
commissionBps: number;
|
|
476
476
|
};
|
|
477
477
|
rpcUrl?: string;
|
|
478
|
+
enabledFeatures?: {
|
|
479
|
+
dca?: boolean;
|
|
480
|
+
};
|
|
478
481
|
};
|
|
479
482
|
declare class SwapSDK {
|
|
480
483
|
private readonly options;
|
|
@@ -482,6 +485,7 @@ declare class SwapSDK {
|
|
|
482
485
|
private readonly trpc;
|
|
483
486
|
private stateChainEnvironment?;
|
|
484
487
|
private supportedAssets?;
|
|
488
|
+
private dcaEnabled;
|
|
485
489
|
constructor(options?: SwapSDKOptions);
|
|
486
490
|
getChains(sourceChain?: Chain): Promise<ChainData[]>;
|
|
487
491
|
private getStateChainEnvironment;
|
package/dist/swap.js
CHANGED
|
@@ -6224,238 +6224,6 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
6224
6224
|
ZodError
|
|
6225
6225
|
});
|
|
6226
6226
|
|
|
6227
|
-
// ../shared/src/enums.ts
|
|
6228
|
-
var arrayToMap = /* @__PURE__ */ __name((array) => Object.fromEntries(array.map((key) => [
|
|
6229
|
-
key,
|
|
6230
|
-
key
|
|
6231
|
-
])), "arrayToMap");
|
|
6232
|
-
var InternalAssets = arrayToMap([
|
|
6233
|
-
"Flip",
|
|
6234
|
-
"Usdc",
|
|
6235
|
-
"Dot",
|
|
6236
|
-
"Eth",
|
|
6237
|
-
"Btc",
|
|
6238
|
-
"Usdt",
|
|
6239
|
-
"ArbUsdc",
|
|
6240
|
-
"ArbEth",
|
|
6241
|
-
"Sol",
|
|
6242
|
-
"SolUsdc"
|
|
6243
|
-
]);
|
|
6244
|
-
var Chains = arrayToMap([
|
|
6245
|
-
"Bitcoin",
|
|
6246
|
-
"Ethereum",
|
|
6247
|
-
"Polkadot",
|
|
6248
|
-
"Arbitrum",
|
|
6249
|
-
"Solana"
|
|
6250
|
-
]);
|
|
6251
|
-
var Assets = arrayToMap([
|
|
6252
|
-
"FLIP",
|
|
6253
|
-
"USDC",
|
|
6254
|
-
"DOT",
|
|
6255
|
-
"ETH",
|
|
6256
|
-
"BTC",
|
|
6257
|
-
"USDT",
|
|
6258
|
-
"SOL"
|
|
6259
|
-
]);
|
|
6260
|
-
var ChainflipNetworks = arrayToMap([
|
|
6261
|
-
"backspin",
|
|
6262
|
-
"sisyphos",
|
|
6263
|
-
"perseverance",
|
|
6264
|
-
"mainnet"
|
|
6265
|
-
]);
|
|
6266
|
-
var isTestnet = /* @__PURE__ */ __name((network) => network !== ChainflipNetworks.mainnet, "isTestnet");
|
|
6267
|
-
var assetConstants = {
|
|
6268
|
-
[InternalAssets.Eth]: {
|
|
6269
|
-
chain: Chains.Ethereum,
|
|
6270
|
-
asset: Assets.ETH,
|
|
6271
|
-
name: "Ether",
|
|
6272
|
-
decimals: 18,
|
|
6273
|
-
contractId: 1
|
|
6274
|
-
},
|
|
6275
|
-
[InternalAssets.Flip]: {
|
|
6276
|
-
chain: Chains.Ethereum,
|
|
6277
|
-
asset: Assets.FLIP,
|
|
6278
|
-
name: "FLIP",
|
|
6279
|
-
decimals: 18,
|
|
6280
|
-
contractId: 2
|
|
6281
|
-
},
|
|
6282
|
-
[InternalAssets.Usdc]: {
|
|
6283
|
-
chain: Chains.Ethereum,
|
|
6284
|
-
asset: Assets.USDC,
|
|
6285
|
-
name: "USDC",
|
|
6286
|
-
decimals: 6,
|
|
6287
|
-
contractId: 3
|
|
6288
|
-
},
|
|
6289
|
-
[InternalAssets.Usdt]: {
|
|
6290
|
-
chain: Chains.Ethereum,
|
|
6291
|
-
asset: Assets.USDT,
|
|
6292
|
-
name: "USDT",
|
|
6293
|
-
decimals: 6,
|
|
6294
|
-
contractId: 8
|
|
6295
|
-
},
|
|
6296
|
-
[InternalAssets.Dot]: {
|
|
6297
|
-
chain: Chains.Polkadot,
|
|
6298
|
-
asset: Assets.DOT,
|
|
6299
|
-
name: "Polkadot",
|
|
6300
|
-
decimals: 10,
|
|
6301
|
-
contractId: 4
|
|
6302
|
-
},
|
|
6303
|
-
[InternalAssets.Btc]: {
|
|
6304
|
-
chain: Chains.Bitcoin,
|
|
6305
|
-
asset: Assets.BTC,
|
|
6306
|
-
name: "Bitcoin",
|
|
6307
|
-
decimals: 8,
|
|
6308
|
-
contractId: 5
|
|
6309
|
-
},
|
|
6310
|
-
[InternalAssets.ArbEth]: {
|
|
6311
|
-
chain: Chains.Arbitrum,
|
|
6312
|
-
asset: Assets.ETH,
|
|
6313
|
-
name: "Arbitrum Ether",
|
|
6314
|
-
decimals: 18,
|
|
6315
|
-
contractId: 6
|
|
6316
|
-
},
|
|
6317
|
-
[InternalAssets.ArbUsdc]: {
|
|
6318
|
-
chain: Chains.Arbitrum,
|
|
6319
|
-
asset: Assets.USDC,
|
|
6320
|
-
name: "Arbitrum USDC",
|
|
6321
|
-
decimals: 6,
|
|
6322
|
-
contractId: 7
|
|
6323
|
-
},
|
|
6324
|
-
[InternalAssets.Sol]: {
|
|
6325
|
-
chain: Chains.Solana,
|
|
6326
|
-
asset: Assets.SOL,
|
|
6327
|
-
name: "Solana",
|
|
6328
|
-
decimals: 9,
|
|
6329
|
-
contractId: 9
|
|
6330
|
-
},
|
|
6331
|
-
[InternalAssets.SolUsdc]: {
|
|
6332
|
-
chain: Chains.Solana,
|
|
6333
|
-
asset: Assets.USDC,
|
|
6334
|
-
name: "Solana USDC",
|
|
6335
|
-
decimals: 6,
|
|
6336
|
-
contractId: 10
|
|
6337
|
-
}
|
|
6338
|
-
};
|
|
6339
|
-
var chainConstants = {
|
|
6340
|
-
[Chains.Ethereum]: {
|
|
6341
|
-
assets: [
|
|
6342
|
-
Assets.ETH,
|
|
6343
|
-
Assets.FLIP,
|
|
6344
|
-
Assets.USDC,
|
|
6345
|
-
Assets.USDT
|
|
6346
|
-
],
|
|
6347
|
-
gasAsset: Assets.ETH,
|
|
6348
|
-
contractId: 1,
|
|
6349
|
-
blockTimeSeconds: 12
|
|
6350
|
-
},
|
|
6351
|
-
[Chains.Polkadot]: {
|
|
6352
|
-
assets: [
|
|
6353
|
-
Assets.DOT
|
|
6354
|
-
],
|
|
6355
|
-
gasAsset: Assets.DOT,
|
|
6356
|
-
contractId: 2,
|
|
6357
|
-
blockTimeSeconds: 6
|
|
6358
|
-
},
|
|
6359
|
-
[Chains.Bitcoin]: {
|
|
6360
|
-
assets: [
|
|
6361
|
-
Assets.BTC
|
|
6362
|
-
],
|
|
6363
|
-
gasAsset: Assets.BTC,
|
|
6364
|
-
contractId: 3,
|
|
6365
|
-
blockTimeSeconds: 10 * 60
|
|
6366
|
-
},
|
|
6367
|
-
[Chains.Arbitrum]: {
|
|
6368
|
-
assets: [
|
|
6369
|
-
Assets.ETH,
|
|
6370
|
-
Assets.USDC
|
|
6371
|
-
],
|
|
6372
|
-
gasAsset: Assets.ETH,
|
|
6373
|
-
contractId: 4,
|
|
6374
|
-
blockTimeSeconds: 0.26
|
|
6375
|
-
},
|
|
6376
|
-
[Chains.Solana]: {
|
|
6377
|
-
assets: [
|
|
6378
|
-
Assets.SOL,
|
|
6379
|
-
Assets.USDC
|
|
6380
|
-
],
|
|
6381
|
-
gasAsset: Assets.SOL,
|
|
6382
|
-
contractId: 5,
|
|
6383
|
-
blockTimeSeconds: (400 + 800) / 2 / 1e3
|
|
6384
|
-
}
|
|
6385
|
-
};
|
|
6386
|
-
function isValidAssetAndChain(assetAndChain2) {
|
|
6387
|
-
const { asset: asset2, chain: chain2 } = assetAndChain2;
|
|
6388
|
-
if (!(chain2 in Chains)) return false;
|
|
6389
|
-
const validAssets = chainConstants[chain2].assets;
|
|
6390
|
-
return validAssets.includes(asset2);
|
|
6391
|
-
}
|
|
6392
|
-
__name(isValidAssetAndChain, "isValidAssetAndChain");
|
|
6393
|
-
var readChainAssetValue = /* @__PURE__ */ __name((map, asset2) => {
|
|
6394
|
-
const { chain: chain2, asset: symbol } = assetConstants[asset2];
|
|
6395
|
-
const chainValues = map[chain2];
|
|
6396
|
-
return chainValues[symbol];
|
|
6397
|
-
}, "readChainAssetValue");
|
|
6398
|
-
function getInternalAsset(asset2, assert3 = true) {
|
|
6399
|
-
if (!isValidAssetAndChain(asset2)) {
|
|
6400
|
-
if (assert3) {
|
|
6401
|
-
throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset2)}`);
|
|
6402
|
-
}
|
|
6403
|
-
return null;
|
|
6404
|
-
}
|
|
6405
|
-
const map = {
|
|
6406
|
-
[Chains.Ethereum]: {
|
|
6407
|
-
[Assets.USDC]: InternalAssets.Usdc,
|
|
6408
|
-
[Assets.FLIP]: InternalAssets.Flip,
|
|
6409
|
-
[Assets.ETH]: InternalAssets.Eth,
|
|
6410
|
-
[Assets.USDT]: InternalAssets.Usdt
|
|
6411
|
-
},
|
|
6412
|
-
[Chains.Bitcoin]: {
|
|
6413
|
-
[Assets.BTC]: InternalAssets.Btc
|
|
6414
|
-
},
|
|
6415
|
-
[Chains.Polkadot]: {
|
|
6416
|
-
[Assets.DOT]: InternalAssets.Dot
|
|
6417
|
-
},
|
|
6418
|
-
[Chains.Arbitrum]: {
|
|
6419
|
-
[Assets.USDC]: InternalAssets.ArbUsdc,
|
|
6420
|
-
[Assets.ETH]: InternalAssets.ArbEth
|
|
6421
|
-
},
|
|
6422
|
-
[Chains.Solana]: {
|
|
6423
|
-
[Assets.SOL]: InternalAssets.Sol,
|
|
6424
|
-
[Assets.USDC]: InternalAssets.SolUsdc
|
|
6425
|
-
}
|
|
6426
|
-
};
|
|
6427
|
-
const chain2 = map[asset2.chain];
|
|
6428
|
-
return chain2[asset2.asset];
|
|
6429
|
-
}
|
|
6430
|
-
__name(getInternalAsset, "getInternalAsset");
|
|
6431
|
-
function getInternalAssets({ srcAsset, srcChain, destAsset, destChain }, assert3 = true) {
|
|
6432
|
-
return {
|
|
6433
|
-
srcAsset: getInternalAsset({
|
|
6434
|
-
asset: srcAsset,
|
|
6435
|
-
chain: srcChain
|
|
6436
|
-
}, assert3),
|
|
6437
|
-
destAsset: getInternalAsset({
|
|
6438
|
-
asset: destAsset,
|
|
6439
|
-
chain: destChain
|
|
6440
|
-
}, assert3)
|
|
6441
|
-
};
|
|
6442
|
-
}
|
|
6443
|
-
__name(getInternalAssets, "getInternalAssets");
|
|
6444
|
-
function getAssetAndChain(internalAsset, prefix) {
|
|
6445
|
-
const { chain: chain2, asset: asset2 } = assetConstants[internalAsset];
|
|
6446
|
-
if (prefix) {
|
|
6447
|
-
return {
|
|
6448
|
-
[`${prefix}Asset`]: asset2,
|
|
6449
|
-
[`${prefix}Chain`]: chain2
|
|
6450
|
-
};
|
|
6451
|
-
}
|
|
6452
|
-
return {
|
|
6453
|
-
chain: chain2,
|
|
6454
|
-
asset: asset2
|
|
6455
|
-
};
|
|
6456
|
-
}
|
|
6457
|
-
__name(getAssetAndChain, "getAssetAndChain");
|
|
6458
|
-
|
|
6459
6227
|
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_assert.js
|
|
6460
6228
|
function isBytes(a) {
|
|
6461
6229
|
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
|
@@ -6925,6 +6693,238 @@ var isValidSolanaAddress = /* @__PURE__ */ __name((address) => {
|
|
|
6925
6693
|
}
|
|
6926
6694
|
}, "isValidSolanaAddress");
|
|
6927
6695
|
|
|
6696
|
+
// ../shared/src/enums.ts
|
|
6697
|
+
var arrayToMap = /* @__PURE__ */ __name((array) => Object.fromEntries(array.map((key) => [
|
|
6698
|
+
key,
|
|
6699
|
+
key
|
|
6700
|
+
])), "arrayToMap");
|
|
6701
|
+
var InternalAssets = arrayToMap([
|
|
6702
|
+
"Flip",
|
|
6703
|
+
"Usdc",
|
|
6704
|
+
"Dot",
|
|
6705
|
+
"Eth",
|
|
6706
|
+
"Btc",
|
|
6707
|
+
"Usdt",
|
|
6708
|
+
"ArbUsdc",
|
|
6709
|
+
"ArbEth",
|
|
6710
|
+
"Sol",
|
|
6711
|
+
"SolUsdc"
|
|
6712
|
+
]);
|
|
6713
|
+
var Chains = arrayToMap([
|
|
6714
|
+
"Bitcoin",
|
|
6715
|
+
"Ethereum",
|
|
6716
|
+
"Polkadot",
|
|
6717
|
+
"Arbitrum",
|
|
6718
|
+
"Solana"
|
|
6719
|
+
]);
|
|
6720
|
+
var Assets = arrayToMap([
|
|
6721
|
+
"FLIP",
|
|
6722
|
+
"USDC",
|
|
6723
|
+
"DOT",
|
|
6724
|
+
"ETH",
|
|
6725
|
+
"BTC",
|
|
6726
|
+
"USDT",
|
|
6727
|
+
"SOL"
|
|
6728
|
+
]);
|
|
6729
|
+
var ChainflipNetworks = arrayToMap([
|
|
6730
|
+
"backspin",
|
|
6731
|
+
"sisyphos",
|
|
6732
|
+
"perseverance",
|
|
6733
|
+
"mainnet"
|
|
6734
|
+
]);
|
|
6735
|
+
var isTestnet = /* @__PURE__ */ __name((network) => network !== ChainflipNetworks.mainnet, "isTestnet");
|
|
6736
|
+
var assetConstants = {
|
|
6737
|
+
[InternalAssets.Eth]: {
|
|
6738
|
+
chain: Chains.Ethereum,
|
|
6739
|
+
asset: Assets.ETH,
|
|
6740
|
+
name: "Ether",
|
|
6741
|
+
decimals: 18,
|
|
6742
|
+
contractId: 1
|
|
6743
|
+
},
|
|
6744
|
+
[InternalAssets.Flip]: {
|
|
6745
|
+
chain: Chains.Ethereum,
|
|
6746
|
+
asset: Assets.FLIP,
|
|
6747
|
+
name: "FLIP",
|
|
6748
|
+
decimals: 18,
|
|
6749
|
+
contractId: 2
|
|
6750
|
+
},
|
|
6751
|
+
[InternalAssets.Usdc]: {
|
|
6752
|
+
chain: Chains.Ethereum,
|
|
6753
|
+
asset: Assets.USDC,
|
|
6754
|
+
name: "USDC",
|
|
6755
|
+
decimals: 6,
|
|
6756
|
+
contractId: 3
|
|
6757
|
+
},
|
|
6758
|
+
[InternalAssets.Usdt]: {
|
|
6759
|
+
chain: Chains.Ethereum,
|
|
6760
|
+
asset: Assets.USDT,
|
|
6761
|
+
name: "USDT",
|
|
6762
|
+
decimals: 6,
|
|
6763
|
+
contractId: 8
|
|
6764
|
+
},
|
|
6765
|
+
[InternalAssets.Dot]: {
|
|
6766
|
+
chain: Chains.Polkadot,
|
|
6767
|
+
asset: Assets.DOT,
|
|
6768
|
+
name: "Polkadot",
|
|
6769
|
+
decimals: 10,
|
|
6770
|
+
contractId: 4
|
|
6771
|
+
},
|
|
6772
|
+
[InternalAssets.Btc]: {
|
|
6773
|
+
chain: Chains.Bitcoin,
|
|
6774
|
+
asset: Assets.BTC,
|
|
6775
|
+
name: "Bitcoin",
|
|
6776
|
+
decimals: 8,
|
|
6777
|
+
contractId: 5
|
|
6778
|
+
},
|
|
6779
|
+
[InternalAssets.ArbEth]: {
|
|
6780
|
+
chain: Chains.Arbitrum,
|
|
6781
|
+
asset: Assets.ETH,
|
|
6782
|
+
name: "Arbitrum Ether",
|
|
6783
|
+
decimals: 18,
|
|
6784
|
+
contractId: 6
|
|
6785
|
+
},
|
|
6786
|
+
[InternalAssets.ArbUsdc]: {
|
|
6787
|
+
chain: Chains.Arbitrum,
|
|
6788
|
+
asset: Assets.USDC,
|
|
6789
|
+
name: "Arbitrum USDC",
|
|
6790
|
+
decimals: 6,
|
|
6791
|
+
contractId: 7
|
|
6792
|
+
},
|
|
6793
|
+
[InternalAssets.Sol]: {
|
|
6794
|
+
chain: Chains.Solana,
|
|
6795
|
+
asset: Assets.SOL,
|
|
6796
|
+
name: "Solana",
|
|
6797
|
+
decimals: 9,
|
|
6798
|
+
contractId: 9
|
|
6799
|
+
},
|
|
6800
|
+
[InternalAssets.SolUsdc]: {
|
|
6801
|
+
chain: Chains.Solana,
|
|
6802
|
+
asset: Assets.USDC,
|
|
6803
|
+
name: "Solana USDC",
|
|
6804
|
+
decimals: 6,
|
|
6805
|
+
contractId: 10
|
|
6806
|
+
}
|
|
6807
|
+
};
|
|
6808
|
+
var chainConstants = {
|
|
6809
|
+
[Chains.Ethereum]: {
|
|
6810
|
+
assets: [
|
|
6811
|
+
Assets.ETH,
|
|
6812
|
+
Assets.FLIP,
|
|
6813
|
+
Assets.USDC,
|
|
6814
|
+
Assets.USDT
|
|
6815
|
+
],
|
|
6816
|
+
gasAsset: Assets.ETH,
|
|
6817
|
+
contractId: 1,
|
|
6818
|
+
blockTimeSeconds: 12
|
|
6819
|
+
},
|
|
6820
|
+
[Chains.Polkadot]: {
|
|
6821
|
+
assets: [
|
|
6822
|
+
Assets.DOT
|
|
6823
|
+
],
|
|
6824
|
+
gasAsset: Assets.DOT,
|
|
6825
|
+
contractId: 2,
|
|
6826
|
+
blockTimeSeconds: 6
|
|
6827
|
+
},
|
|
6828
|
+
[Chains.Bitcoin]: {
|
|
6829
|
+
assets: [
|
|
6830
|
+
Assets.BTC
|
|
6831
|
+
],
|
|
6832
|
+
gasAsset: Assets.BTC,
|
|
6833
|
+
contractId: 3,
|
|
6834
|
+
blockTimeSeconds: 10 * 60
|
|
6835
|
+
},
|
|
6836
|
+
[Chains.Arbitrum]: {
|
|
6837
|
+
assets: [
|
|
6838
|
+
Assets.ETH,
|
|
6839
|
+
Assets.USDC
|
|
6840
|
+
],
|
|
6841
|
+
gasAsset: Assets.ETH,
|
|
6842
|
+
contractId: 4,
|
|
6843
|
+
blockTimeSeconds: 0.26
|
|
6844
|
+
},
|
|
6845
|
+
[Chains.Solana]: {
|
|
6846
|
+
assets: [
|
|
6847
|
+
Assets.SOL,
|
|
6848
|
+
Assets.USDC
|
|
6849
|
+
],
|
|
6850
|
+
gasAsset: Assets.SOL,
|
|
6851
|
+
contractId: 5,
|
|
6852
|
+
blockTimeSeconds: (400 + 800) / 2 / 1e3
|
|
6853
|
+
}
|
|
6854
|
+
};
|
|
6855
|
+
function isValidAssetAndChain(assetAndChain2) {
|
|
6856
|
+
const { asset: asset2, chain: chain2 } = assetAndChain2;
|
|
6857
|
+
if (!(chain2 in Chains)) return false;
|
|
6858
|
+
const validAssets = chainConstants[chain2].assets;
|
|
6859
|
+
return validAssets.includes(asset2);
|
|
6860
|
+
}
|
|
6861
|
+
__name(isValidAssetAndChain, "isValidAssetAndChain");
|
|
6862
|
+
var readChainAssetValue = /* @__PURE__ */ __name((map, asset2) => {
|
|
6863
|
+
const { chain: chain2, asset: symbol } = assetConstants[asset2];
|
|
6864
|
+
const chainValues = map[chain2];
|
|
6865
|
+
return chainValues[symbol];
|
|
6866
|
+
}, "readChainAssetValue");
|
|
6867
|
+
function getInternalAsset(asset2, assert3 = true) {
|
|
6868
|
+
if (!isValidAssetAndChain(asset2)) {
|
|
6869
|
+
if (assert3) {
|
|
6870
|
+
throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset2)}`);
|
|
6871
|
+
}
|
|
6872
|
+
return null;
|
|
6873
|
+
}
|
|
6874
|
+
const map = {
|
|
6875
|
+
[Chains.Ethereum]: {
|
|
6876
|
+
[Assets.USDC]: InternalAssets.Usdc,
|
|
6877
|
+
[Assets.FLIP]: InternalAssets.Flip,
|
|
6878
|
+
[Assets.ETH]: InternalAssets.Eth,
|
|
6879
|
+
[Assets.USDT]: InternalAssets.Usdt
|
|
6880
|
+
},
|
|
6881
|
+
[Chains.Bitcoin]: {
|
|
6882
|
+
[Assets.BTC]: InternalAssets.Btc
|
|
6883
|
+
},
|
|
6884
|
+
[Chains.Polkadot]: {
|
|
6885
|
+
[Assets.DOT]: InternalAssets.Dot
|
|
6886
|
+
},
|
|
6887
|
+
[Chains.Arbitrum]: {
|
|
6888
|
+
[Assets.USDC]: InternalAssets.ArbUsdc,
|
|
6889
|
+
[Assets.ETH]: InternalAssets.ArbEth
|
|
6890
|
+
},
|
|
6891
|
+
[Chains.Solana]: {
|
|
6892
|
+
[Assets.SOL]: InternalAssets.Sol,
|
|
6893
|
+
[Assets.USDC]: InternalAssets.SolUsdc
|
|
6894
|
+
}
|
|
6895
|
+
};
|
|
6896
|
+
const chain2 = map[asset2.chain];
|
|
6897
|
+
return chain2[asset2.asset];
|
|
6898
|
+
}
|
|
6899
|
+
__name(getInternalAsset, "getInternalAsset");
|
|
6900
|
+
function getInternalAssets({ srcAsset, srcChain, destAsset, destChain }, assert3 = true) {
|
|
6901
|
+
return {
|
|
6902
|
+
srcAsset: getInternalAsset({
|
|
6903
|
+
asset: srcAsset,
|
|
6904
|
+
chain: srcChain
|
|
6905
|
+
}, assert3),
|
|
6906
|
+
destAsset: getInternalAsset({
|
|
6907
|
+
asset: destAsset,
|
|
6908
|
+
chain: destChain
|
|
6909
|
+
}, assert3)
|
|
6910
|
+
};
|
|
6911
|
+
}
|
|
6912
|
+
__name(getInternalAssets, "getInternalAssets");
|
|
6913
|
+
function getAssetAndChain(internalAsset, prefix) {
|
|
6914
|
+
const { chain: chain2, asset: asset2 } = assetConstants[internalAsset];
|
|
6915
|
+
if (prefix) {
|
|
6916
|
+
return {
|
|
6917
|
+
[`${prefix}Asset`]: asset2,
|
|
6918
|
+
[`${prefix}Chain`]: chain2
|
|
6919
|
+
};
|
|
6920
|
+
}
|
|
6921
|
+
return {
|
|
6922
|
+
chain: chain2,
|
|
6923
|
+
asset: asset2
|
|
6924
|
+
};
|
|
6925
|
+
}
|
|
6926
|
+
__name(getAssetAndChain, "getAssetAndChain");
|
|
6927
|
+
|
|
6928
6928
|
// ../shared/src/guards.ts
|
|
6929
6929
|
var isString2 = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
|
|
6930
6930
|
var isNotNullish = /* @__PURE__ */ __name((value) => value !== null && value !== void 0, "isNotNullish");
|
|
@@ -7001,6 +7001,7 @@ var string = z.string({
|
|
|
7001
7001
|
var number = z.number({
|
|
7002
7002
|
errorMap: errorMap2
|
|
7003
7003
|
});
|
|
7004
|
+
var booleanString = string.regex(/^(true|false)$/i).transform((v) => v.toLowerCase() === "true");
|
|
7004
7005
|
var numericString = string.regex(/^[0-9]+$/);
|
|
7005
7006
|
var numericOrEmptyString = string.regex(/^[0-9]*$/);
|
|
7006
7007
|
var hexString = string.refine((v) => /^0x[0-9a-f]*$/i.test(v));
|
|
@@ -7134,7 +7135,8 @@ z.object({
|
|
|
7134
7135
|
destChain: chain,
|
|
7135
7136
|
destAsset: asset,
|
|
7136
7137
|
amount: numericString.transform((n) => BigInt(n)),
|
|
7137
|
-
brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional()
|
|
7138
|
+
brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional(),
|
|
7139
|
+
dcaEnabled: booleanString
|
|
7138
7140
|
}).transform((args, ctx) => {
|
|
7139
7141
|
const { srcAsset, destAsset } = getInternalAssets(args, false);
|
|
7140
7142
|
if (srcAsset === null) {
|
|
@@ -7161,7 +7163,8 @@ z.object({
|
|
|
7161
7163
|
srcAsset,
|
|
7162
7164
|
destAsset,
|
|
7163
7165
|
amount: args.amount,
|
|
7164
|
-
brokerCommissionBps: args.brokerCommissionBps
|
|
7166
|
+
brokerCommissionBps: args.brokerCommissionBps,
|
|
7167
|
+
dcaEnabled: args.dcaEnabled
|
|
7165
7168
|
};
|
|
7166
7169
|
});
|
|
7167
7170
|
var ccmParamsSchema = z.object({
|
|
@@ -7189,6 +7192,15 @@ var fillOrKillParams = z.object({
|
|
|
7189
7192
|
refundAddress: z.string(),
|
|
7190
7193
|
minPriceX128: numericString
|
|
7191
7194
|
});
|
|
7195
|
+
var ensureDcaWithFok = /* @__PURE__ */ __name((args, ctx) => {
|
|
7196
|
+
if (args.dcaParams && !args.fillOrKillParams) {
|
|
7197
|
+
ctx.addIssue({
|
|
7198
|
+
code: "custom",
|
|
7199
|
+
message: "dcaParams requires fillOrKillParams"
|
|
7200
|
+
});
|
|
7201
|
+
return z.NEVER;
|
|
7202
|
+
}
|
|
7203
|
+
}, "ensureDcaWithFok");
|
|
7192
7204
|
z.object({
|
|
7193
7205
|
srcAsset: asset,
|
|
7194
7206
|
destAsset: asset,
|
|
@@ -7202,45 +7214,56 @@ z.object({
|
|
|
7202
7214
|
srcAddress: z.string().optional(),
|
|
7203
7215
|
fillOrKillParams: fillOrKillParams.optional(),
|
|
7204
7216
|
dcaParams: dcaParams.optional()
|
|
7205
|
-
}).transform(({ amount, ...rest }) => ({
|
|
7217
|
+
}).superRefine(ensureDcaWithFok).transform(({ amount, ...rest }) => ({
|
|
7206
7218
|
...rest,
|
|
7207
7219
|
expectedDepositAmount: amount
|
|
7208
7220
|
}));
|
|
7209
7221
|
|
|
7210
7222
|
// ../shared/src/broker.ts
|
|
7211
|
-
var
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7223
|
+
var paramOrder = [
|
|
7224
|
+
"srcAsset",
|
|
7225
|
+
"destAsset",
|
|
7226
|
+
"destAddress",
|
|
7227
|
+
"commissionBps",
|
|
7228
|
+
"ccmParams",
|
|
7229
|
+
"maxBoostFeeBps",
|
|
7230
|
+
"affiliates",
|
|
7231
|
+
"fillOrKillParams",
|
|
7232
|
+
"dcaParams"
|
|
7233
|
+
];
|
|
7234
|
+
var validateRequest = /* @__PURE__ */ __name((network, params) => {
|
|
7235
|
+
const parsed = z.object({
|
|
7236
|
+
srcAsset: assetAndChain,
|
|
7237
|
+
destAsset: assetAndChain,
|
|
7238
|
+
destAddress: z.union([
|
|
7239
|
+
numericString,
|
|
7240
|
+
hexString,
|
|
7241
|
+
btcAddress(network),
|
|
7242
|
+
solanaAddress
|
|
7243
|
+
]),
|
|
7244
|
+
commissionBps: z.number().optional().default(0),
|
|
7245
|
+
ccmParams: ccmParamsSchema.transform(({ message, ...rest }) => ({
|
|
7246
|
+
message,
|
|
7247
|
+
cf_parameters: rest.cfParameters,
|
|
7248
|
+
gas_budget: rest.gasBudget
|
|
7249
|
+
})).optional(),
|
|
7250
|
+
maxBoostFeeBps: z.number().optional(),
|
|
7251
|
+
affiliates: z.array(affiliateBroker).optional(),
|
|
7252
|
+
fillOrKillParams: fillOrKillParams.transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
|
|
7253
|
+
retry_duration: retryDurationBlocks,
|
|
7254
|
+
refund_address: refundAddress,
|
|
7255
|
+
min_price: `0x${BigInt(minPriceX128).toString(16)}`
|
|
7256
|
+
})).optional(),
|
|
7257
|
+
dcaParams: dcaParams.transform(({ numberOfChunks, chunkIntervalBlocks }) => ({
|
|
7258
|
+
number_of_chunks: numberOfChunks,
|
|
7259
|
+
chunk_interval: chunkIntervalBlocks
|
|
7260
|
+
})).optional()
|
|
7261
|
+
}).superRefine(ensureDcaWithFok).parse(params);
|
|
7262
|
+
if (parsed.destAsset.chain === "Polkadot") {
|
|
7263
|
+
parsed.destAddress = parsed.destAddress.startsWith("0x") ? z.string().length(66).parse(parsed.destAddress) : ss582__namespace.toPublicKey(parsed.destAddress);
|
|
7264
|
+
}
|
|
7265
|
+
return paramOrder.map((key) => parsed[key]);
|
|
7266
|
+
}, "validateRequest");
|
|
7244
7267
|
var validateResponse = /* @__PURE__ */ __name((network, response) => z.object({
|
|
7245
7268
|
address: z.union([
|
|
7246
7269
|
dotAddress,
|
|
@@ -7260,30 +7283,18 @@ var validateResponse = /* @__PURE__ */ __name((network, response) => z.object({
|
|
|
7260
7283
|
channelOpeningFee: channel_opening_fee
|
|
7261
7284
|
})).parse(response), "validateResponse");
|
|
7262
7285
|
async function requestSwapDepositAddress(swapRequest, opts, chainflipNetwork2) {
|
|
7263
|
-
const { srcAsset, srcChain, destAsset, destChain, destAddress } = swapRequest;
|
|
7264
7286
|
const client = new rpc.HttpClient(opts.url);
|
|
7265
|
-
const params = validateRequest(chainflipNetwork2,
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
{
|
|
7271
|
-
asset: destAsset,
|
|
7272
|
-
chain: destChain
|
|
7273
|
-
},
|
|
7274
|
-
submitAddress(destChain, destAddress),
|
|
7275
|
-
swapRequest.commissionBps ?? 0,
|
|
7276
|
-
swapRequest.ccmParams,
|
|
7277
|
-
swapRequest.maxBoostFeeBps,
|
|
7278
|
-
swapRequest.affiliates,
|
|
7279
|
-
swapRequest.fillOrKillParams && {
|
|
7280
|
-
...swapRequest.fillOrKillParams,
|
|
7281
|
-
refundAddress: submitAddress(srcChain, swapRequest.fillOrKillParams.refundAddress)
|
|
7287
|
+
const params = validateRequest(chainflipNetwork2, {
|
|
7288
|
+
...swapRequest,
|
|
7289
|
+
srcAsset: {
|
|
7290
|
+
asset: swapRequest.srcAsset,
|
|
7291
|
+
chain: swapRequest.srcChain
|
|
7282
7292
|
},
|
|
7283
|
-
|
|
7284
|
-
|
|
7293
|
+
destAsset: {
|
|
7294
|
+
asset: swapRequest.destAsset,
|
|
7295
|
+
chain: swapRequest.destChain
|
|
7285
7296
|
}
|
|
7286
|
-
|
|
7297
|
+
});
|
|
7287
7298
|
const response = await client.sendRequest("broker_requestSwapDepositAddress", ...params);
|
|
7288
7299
|
return validateResponse(chainflipNetwork2, response);
|
|
7289
7300
|
}
|
|
@@ -10287,7 +10298,7 @@ var getChainData = /* @__PURE__ */ __name((chain2, network, env) => ({
|
|
|
10287
10298
|
}), "getChainData");
|
|
10288
10299
|
|
|
10289
10300
|
// package.json
|
|
10290
|
-
var version = "1.6.
|
|
10301
|
+
var version = "1.6.5";
|
|
10291
10302
|
|
|
10292
10303
|
// src/swap/consts.ts
|
|
10293
10304
|
var CF_SDK_VERSION_HEADERS = {
|
|
@@ -10309,7 +10320,8 @@ var getQuote = /* @__PURE__ */ __name(async (baseUrl, quoteRequest, { signal })
|
|
|
10309
10320
|
destAsset: returnedRequestData.destAsset,
|
|
10310
10321
|
...brokerCommissionBps && {
|
|
10311
10322
|
brokerCommissionBps: String(brokerCommissionBps)
|
|
10312
|
-
}
|
|
10323
|
+
},
|
|
10324
|
+
dcaEnabled: "false"
|
|
10313
10325
|
};
|
|
10314
10326
|
const { data } = await axios__default.default.get("/quote", {
|
|
10315
10327
|
baseURL: baseUrl,
|
|
@@ -10332,7 +10344,8 @@ var getQuoteV2 = /* @__PURE__ */ __name(async (baseUrl, quoteRequest, { signal }
|
|
|
10332
10344
|
destAsset: returnedRequestData.destAsset,
|
|
10333
10345
|
...brokerCommissionBps && {
|
|
10334
10346
|
brokerCommissionBps: String(brokerCommissionBps)
|
|
10335
|
-
}
|
|
10347
|
+
},
|
|
10348
|
+
dcaEnabled: String(quoteRequest.dcaEnabled)
|
|
10336
10349
|
};
|
|
10337
10350
|
const { data } = await axios__default.default.get("/v2/quote", {
|
|
10338
10351
|
baseURL: baseUrl,
|
|
@@ -10370,6 +10383,7 @@ var _SwapSDK = class _SwapSDK {
|
|
|
10370
10383
|
__publicField(this, "trpc");
|
|
10371
10384
|
__publicField(this, "stateChainEnvironment");
|
|
10372
10385
|
__publicField(this, "supportedAssets");
|
|
10386
|
+
__publicField(this, "dcaEnabled", false);
|
|
10373
10387
|
const network = options.network ?? ChainflipNetworks.perseverance;
|
|
10374
10388
|
this.options = {
|
|
10375
10389
|
...options,
|
|
@@ -10390,6 +10404,7 @@ var _SwapSDK = class _SwapSDK {
|
|
|
10390
10404
|
})
|
|
10391
10405
|
]
|
|
10392
10406
|
});
|
|
10407
|
+
this.dcaEnabled = options.enabledFeatures?.dca ?? false;
|
|
10393
10408
|
}
|
|
10394
10409
|
async getChains(sourceChain) {
|
|
10395
10410
|
if (sourceChain && !(sourceChain in Chains)) throw new Error(`unsupported source chain "${sourceChain}"`);
|
|
@@ -10437,7 +10452,8 @@ var _SwapSDK = class _SwapSDK {
|
|
|
10437
10452
|
const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
|
|
10438
10453
|
return getQuoteV2(this.options.backendUrl, {
|
|
10439
10454
|
...remainingRequest,
|
|
10440
|
-
brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps
|
|
10455
|
+
brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps,
|
|
10456
|
+
dcaEnabled: this.dcaEnabled
|
|
10441
10457
|
}, options);
|
|
10442
10458
|
}
|
|
10443
10459
|
async requestDepositAddress(depositAddressRequest) {
|
package/dist/swap.mjs
CHANGED
|
@@ -6726,6 +6726,7 @@ var string = z.string({
|
|
|
6726
6726
|
var number = z.number({
|
|
6727
6727
|
errorMap: errorMap2
|
|
6728
6728
|
});
|
|
6729
|
+
var booleanString = string.regex(/^(true|false)$/i).transform((v) => v.toLowerCase() === "true");
|
|
6729
6730
|
var numericString = string.regex(/^[0-9]+$/);
|
|
6730
6731
|
var numericOrEmptyString = string.regex(/^[0-9]*$/);
|
|
6731
6732
|
var hexString = string.refine((v) => /^0x[0-9a-f]*$/i.test(v));
|
|
@@ -6859,7 +6860,8 @@ z.object({
|
|
|
6859
6860
|
destChain: chain,
|
|
6860
6861
|
destAsset: asset,
|
|
6861
6862
|
amount: numericString.transform((n) => BigInt(n)),
|
|
6862
|
-
brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional()
|
|
6863
|
+
brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional(),
|
|
6864
|
+
dcaEnabled: booleanString
|
|
6863
6865
|
}).transform((args, ctx) => {
|
|
6864
6866
|
const { srcAsset, destAsset } = getInternalAssets(args, false);
|
|
6865
6867
|
if (srcAsset === null) {
|
|
@@ -6886,7 +6888,8 @@ z.object({
|
|
|
6886
6888
|
srcAsset,
|
|
6887
6889
|
destAsset,
|
|
6888
6890
|
amount: args.amount,
|
|
6889
|
-
brokerCommissionBps: args.brokerCommissionBps
|
|
6891
|
+
brokerCommissionBps: args.brokerCommissionBps,
|
|
6892
|
+
dcaEnabled: args.dcaEnabled
|
|
6890
6893
|
};
|
|
6891
6894
|
});
|
|
6892
6895
|
var ccmParamsSchema = z.object({
|
|
@@ -6914,6 +6917,15 @@ var fillOrKillParams = z.object({
|
|
|
6914
6917
|
refundAddress: z.string(),
|
|
6915
6918
|
minPriceX128: numericString
|
|
6916
6919
|
});
|
|
6920
|
+
var ensureDcaWithFok = /* @__PURE__ */ __name((args, ctx) => {
|
|
6921
|
+
if (args.dcaParams && !args.fillOrKillParams) {
|
|
6922
|
+
ctx.addIssue({
|
|
6923
|
+
code: "custom",
|
|
6924
|
+
message: "dcaParams requires fillOrKillParams"
|
|
6925
|
+
});
|
|
6926
|
+
return z.NEVER;
|
|
6927
|
+
}
|
|
6928
|
+
}, "ensureDcaWithFok");
|
|
6917
6929
|
z.object({
|
|
6918
6930
|
srcAsset: asset,
|
|
6919
6931
|
destAsset: asset,
|
|
@@ -6927,45 +6939,56 @@ z.object({
|
|
|
6927
6939
|
srcAddress: z.string().optional(),
|
|
6928
6940
|
fillOrKillParams: fillOrKillParams.optional(),
|
|
6929
6941
|
dcaParams: dcaParams.optional()
|
|
6930
|
-
}).transform(({ amount, ...rest }) => ({
|
|
6942
|
+
}).superRefine(ensureDcaWithFok).transform(({ amount, ...rest }) => ({
|
|
6931
6943
|
...rest,
|
|
6932
6944
|
expectedDepositAmount: amount
|
|
6933
6945
|
}));
|
|
6934
6946
|
|
|
6935
6947
|
// ../shared/src/broker.ts
|
|
6936
|
-
var
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6948
|
+
var paramOrder = [
|
|
6949
|
+
"srcAsset",
|
|
6950
|
+
"destAsset",
|
|
6951
|
+
"destAddress",
|
|
6952
|
+
"commissionBps",
|
|
6953
|
+
"ccmParams",
|
|
6954
|
+
"maxBoostFeeBps",
|
|
6955
|
+
"affiliates",
|
|
6956
|
+
"fillOrKillParams",
|
|
6957
|
+
"dcaParams"
|
|
6958
|
+
];
|
|
6959
|
+
var validateRequest = /* @__PURE__ */ __name((network, params) => {
|
|
6960
|
+
const parsed = z.object({
|
|
6961
|
+
srcAsset: assetAndChain,
|
|
6962
|
+
destAsset: assetAndChain,
|
|
6963
|
+
destAddress: z.union([
|
|
6964
|
+
numericString,
|
|
6965
|
+
hexString,
|
|
6966
|
+
btcAddress(network),
|
|
6967
|
+
solanaAddress
|
|
6968
|
+
]),
|
|
6969
|
+
commissionBps: z.number().optional().default(0),
|
|
6970
|
+
ccmParams: ccmParamsSchema.transform(({ message, ...rest }) => ({
|
|
6971
|
+
message,
|
|
6972
|
+
cf_parameters: rest.cfParameters,
|
|
6973
|
+
gas_budget: rest.gasBudget
|
|
6974
|
+
})).optional(),
|
|
6975
|
+
maxBoostFeeBps: z.number().optional(),
|
|
6976
|
+
affiliates: z.array(affiliateBroker).optional(),
|
|
6977
|
+
fillOrKillParams: fillOrKillParams.transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
|
|
6978
|
+
retry_duration: retryDurationBlocks,
|
|
6979
|
+
refund_address: refundAddress,
|
|
6980
|
+
min_price: `0x${BigInt(minPriceX128).toString(16)}`
|
|
6981
|
+
})).optional(),
|
|
6982
|
+
dcaParams: dcaParams.transform(({ numberOfChunks, chunkIntervalBlocks }) => ({
|
|
6983
|
+
number_of_chunks: numberOfChunks,
|
|
6984
|
+
chunk_interval: chunkIntervalBlocks
|
|
6985
|
+
})).optional()
|
|
6986
|
+
}).superRefine(ensureDcaWithFok).parse(params);
|
|
6987
|
+
if (parsed.destAsset.chain === "Polkadot") {
|
|
6988
|
+
parsed.destAddress = parsed.destAddress.startsWith("0x") ? z.string().length(66).parse(parsed.destAddress) : ss582.toPublicKey(parsed.destAddress);
|
|
6989
|
+
}
|
|
6990
|
+
return paramOrder.map((key) => parsed[key]);
|
|
6991
|
+
}, "validateRequest");
|
|
6969
6992
|
var validateResponse = /* @__PURE__ */ __name((network, response) => z.object({
|
|
6970
6993
|
address: z.union([
|
|
6971
6994
|
dotAddress,
|
|
@@ -6985,30 +7008,18 @@ var validateResponse = /* @__PURE__ */ __name((network, response) => z.object({
|
|
|
6985
7008
|
channelOpeningFee: channel_opening_fee
|
|
6986
7009
|
})).parse(response), "validateResponse");
|
|
6987
7010
|
async function requestSwapDepositAddress(swapRequest, opts, chainflipNetwork2) {
|
|
6988
|
-
const { srcAsset, srcChain, destAsset, destChain, destAddress } = swapRequest;
|
|
6989
7011
|
const client = new HttpClient(opts.url);
|
|
6990
|
-
const params = validateRequest(chainflipNetwork2,
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
7012
|
+
const params = validateRequest(chainflipNetwork2, {
|
|
7013
|
+
...swapRequest,
|
|
7014
|
+
srcAsset: {
|
|
7015
|
+
asset: swapRequest.srcAsset,
|
|
7016
|
+
chain: swapRequest.srcChain
|
|
6994
7017
|
},
|
|
6995
|
-
{
|
|
6996
|
-
asset: destAsset,
|
|
6997
|
-
chain: destChain
|
|
6998
|
-
},
|
|
6999
|
-
submitAddress(destChain, destAddress),
|
|
7000
|
-
swapRequest.commissionBps ?? 0,
|
|
7001
|
-
swapRequest.ccmParams,
|
|
7002
|
-
swapRequest.maxBoostFeeBps,
|
|
7003
|
-
swapRequest.affiliates,
|
|
7004
|
-
swapRequest.fillOrKillParams && {
|
|
7005
|
-
...swapRequest.fillOrKillParams,
|
|
7006
|
-
refundAddress: submitAddress(srcChain, swapRequest.fillOrKillParams.refundAddress)
|
|
7007
|
-
},
|
|
7008
|
-
swapRequest.dcaParams && {
|
|
7009
|
-
...swapRequest.dcaParams
|
|
7018
|
+
destAsset: {
|
|
7019
|
+
asset: swapRequest.destAsset,
|
|
7020
|
+
chain: swapRequest.destChain
|
|
7010
7021
|
}
|
|
7011
|
-
|
|
7022
|
+
});
|
|
7012
7023
|
const response = await client.sendRequest("broker_requestSwapDepositAddress", ...params);
|
|
7013
7024
|
return validateResponse(chainflipNetwork2, response);
|
|
7014
7025
|
}
|
|
@@ -8562,7 +8573,7 @@ var getChainData = /* @__PURE__ */ __name((chain2, network, env) => ({
|
|
|
8562
8573
|
}), "getChainData");
|
|
8563
8574
|
|
|
8564
8575
|
// package.json
|
|
8565
|
-
var version = "1.6.
|
|
8576
|
+
var version = "1.6.5";
|
|
8566
8577
|
|
|
8567
8578
|
// src/swap/consts.ts
|
|
8568
8579
|
var CF_SDK_VERSION_HEADERS = {
|
|
@@ -8584,7 +8595,8 @@ var getQuote = /* @__PURE__ */ __name(async (baseUrl, quoteRequest, { signal })
|
|
|
8584
8595
|
destAsset: returnedRequestData.destAsset,
|
|
8585
8596
|
...brokerCommissionBps && {
|
|
8586
8597
|
brokerCommissionBps: String(brokerCommissionBps)
|
|
8587
|
-
}
|
|
8598
|
+
},
|
|
8599
|
+
dcaEnabled: "false"
|
|
8588
8600
|
};
|
|
8589
8601
|
const { data } = await axios.get("/quote", {
|
|
8590
8602
|
baseURL: baseUrl,
|
|
@@ -8607,7 +8619,8 @@ var getQuoteV2 = /* @__PURE__ */ __name(async (baseUrl, quoteRequest, { signal }
|
|
|
8607
8619
|
destAsset: returnedRequestData.destAsset,
|
|
8608
8620
|
...brokerCommissionBps && {
|
|
8609
8621
|
brokerCommissionBps: String(brokerCommissionBps)
|
|
8610
|
-
}
|
|
8622
|
+
},
|
|
8623
|
+
dcaEnabled: String(quoteRequest.dcaEnabled)
|
|
8611
8624
|
};
|
|
8612
8625
|
const { data } = await axios.get("/v2/quote", {
|
|
8613
8626
|
baseURL: baseUrl,
|
|
@@ -8645,6 +8658,7 @@ var _SwapSDK = class _SwapSDK {
|
|
|
8645
8658
|
__publicField(this, "trpc");
|
|
8646
8659
|
__publicField(this, "stateChainEnvironment");
|
|
8647
8660
|
__publicField(this, "supportedAssets");
|
|
8661
|
+
__publicField(this, "dcaEnabled", false);
|
|
8648
8662
|
const network = options.network ?? ChainflipNetworks.perseverance;
|
|
8649
8663
|
this.options = {
|
|
8650
8664
|
...options,
|
|
@@ -8665,6 +8679,7 @@ var _SwapSDK = class _SwapSDK {
|
|
|
8665
8679
|
})
|
|
8666
8680
|
]
|
|
8667
8681
|
});
|
|
8682
|
+
this.dcaEnabled = options.enabledFeatures?.dca ?? false;
|
|
8668
8683
|
}
|
|
8669
8684
|
async getChains(sourceChain) {
|
|
8670
8685
|
if (sourceChain && !(sourceChain in Chains)) throw new Error(`unsupported source chain "${sourceChain}"`);
|
|
@@ -8712,7 +8727,8 @@ var _SwapSDK = class _SwapSDK {
|
|
|
8712
8727
|
const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
|
|
8713
8728
|
return getQuoteV2(this.options.backendUrl, {
|
|
8714
8729
|
...remainingRequest,
|
|
8715
|
-
brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps
|
|
8730
|
+
brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps,
|
|
8731
|
+
dcaEnabled: this.dcaEnabled
|
|
8716
8732
|
}, options);
|
|
8717
8733
|
}
|
|
8718
8734
|
async requestDepositAddress(depositAddressRequest) {
|