@chainflip/sdk 2.1.0 → 2.1.1
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.cjs +16 -42
- package/dist/swap.d.cts +1 -2
- package/dist/swap.d.ts +1 -2
- package/dist/swap.js +16 -42
- package/package.json +1 -1
package/dist/swap.cjs
CHANGED
|
@@ -694,30 +694,22 @@ var blocksPerMinute = 60 / consts.CHAINFLIP_BLOCK_TIME_SECONDS;
|
|
|
694
694
|
function parseFoKParams(params, quote) {
|
|
695
695
|
const srcAsset = chainflip.getInternalAsset(quote.srcAsset);
|
|
696
696
|
const destAsset = chainflip.getInternalAsset(quote.destAsset);
|
|
697
|
-
const
|
|
698
|
-
const livePriceProtectionEnabled = typeof params.livePriceSlippageTolerancePercent === "string" || typeof params.livePriceSlippageTolerancePercent === "number";
|
|
699
|
-
const livePriceProtectionAvailable = isNotNullish(
|
|
700
|
-
quote.recommendedLivePriceSlippageTolerancePercent
|
|
701
|
-
);
|
|
702
|
-
if (livePriceProtectionEnabled && !livePriceProtectionAvailable) {
|
|
703
|
-
throw new Error("Live price protection is not available for this asset pair");
|
|
704
|
-
}
|
|
697
|
+
const lppAvailable = isNotNullish(quote.recommendedLivePriceSlippageTolerancePercent);
|
|
705
698
|
let minPrice;
|
|
706
|
-
let
|
|
707
|
-
if (
|
|
708
|
-
if (
|
|
709
|
-
|
|
710
|
-
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
711
|
-
assert(
|
|
712
|
-
livePriceSlippageTolerancePercent.gte(0) && livePriceSlippageTolerancePercent.lte(100),
|
|
713
|
-
"Live price slippage tolerance must be between 0 and 100 inclusive"
|
|
714
|
-
);
|
|
715
|
-
} else if (quote.recommendedLivePriceSlippageTolerancePercent) {
|
|
716
|
-
livePriceSlippageTolerancePercent = new BigNumber2__default.default(
|
|
717
|
-
quote.recommendedLivePriceSlippageTolerancePercent
|
|
718
|
-
);
|
|
719
|
-
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
699
|
+
let lpp = null;
|
|
700
|
+
if (isNotNullish(params.livePriceSlippageTolerancePercent)) {
|
|
701
|
+
if (!lppAvailable) {
|
|
702
|
+
throw new Error("Live price protection is not available for this asset pair");
|
|
720
703
|
}
|
|
704
|
+
lpp = new BigNumber2__default.default(params.livePriceSlippageTolerancePercent);
|
|
705
|
+
assert(!lpp.isNaN(), "Invalid live price slippage tolerance");
|
|
706
|
+
assert(
|
|
707
|
+
lpp.gte(0) && lpp.lte(100),
|
|
708
|
+
"Live price slippage tolerance must be between 0 and 100 inclusive"
|
|
709
|
+
);
|
|
710
|
+
} else if (quote.recommendedLivePriceSlippageTolerancePercent) {
|
|
711
|
+
lpp = new BigNumber2__default.default(quote.recommendedLivePriceSlippageTolerancePercent);
|
|
712
|
+
assert(!lpp.isNaN(), "Invalid live price slippage tolerance");
|
|
721
713
|
}
|
|
722
714
|
if ("minPrice" in params) {
|
|
723
715
|
assert(
|
|
@@ -740,7 +732,7 @@ function parseFoKParams(params, quote) {
|
|
|
740
732
|
throw new Error("Either minPrice or slippageTolerancePercent must be provided");
|
|
741
733
|
}
|
|
742
734
|
const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
|
|
743
|
-
const maxOraclePriceSlippage =
|
|
735
|
+
const maxOraclePriceSlippage = lpp?.multipliedBy(100).toNumber() ?? null;
|
|
744
736
|
const parsed = {
|
|
745
737
|
retryDurationBlocks,
|
|
746
738
|
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
|
|
@@ -933,7 +925,7 @@ var getChainData = (chain2, network, env) => ({
|
|
|
933
925
|
|
|
934
926
|
// package.json
|
|
935
927
|
var package_default = {
|
|
936
|
-
version: "2.1.
|
|
928
|
+
version: "2.1.1"};
|
|
937
929
|
|
|
938
930
|
// src/swap/consts.ts
|
|
939
931
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
|
@@ -1181,7 +1173,6 @@ var SwapSDK = class {
|
|
|
1181
1173
|
ccmParams,
|
|
1182
1174
|
amount: quote.depositAmount
|
|
1183
1175
|
};
|
|
1184
|
-
await this.checkLivePriceProtectionRequirement(depositAddressRequest, quote);
|
|
1185
1176
|
let response;
|
|
1186
1177
|
if (this.options.broker) {
|
|
1187
1178
|
const result = await requestSwapDepositAddress(
|
|
@@ -1272,7 +1263,6 @@ var SwapSDK = class {
|
|
|
1272
1263
|
commissionBps: brokerCommissionBps,
|
|
1273
1264
|
affiliates
|
|
1274
1265
|
};
|
|
1275
|
-
await this.checkLivePriceProtectionRequirement(vaultSwapRequest, quote);
|
|
1276
1266
|
if (this.options.broker) {
|
|
1277
1267
|
assert(
|
|
1278
1268
|
!vaultSwapRequest.brokerAccount,
|
|
@@ -1334,7 +1324,6 @@ var SwapSDK = class {
|
|
|
1334
1324
|
commissionBps: await this.getCommissionBps(brokerCommissionBps),
|
|
1335
1325
|
affiliates
|
|
1336
1326
|
};
|
|
1337
|
-
await this.checkLivePriceProtectionRequirement(requestParams, quote);
|
|
1338
1327
|
if (this.options.broker) {
|
|
1339
1328
|
assert(
|
|
1340
1329
|
!brokerAccount,
|
|
@@ -1381,21 +1370,6 @@ var SwapSDK = class {
|
|
|
1381
1370
|
}
|
|
1382
1371
|
return res.body;
|
|
1383
1372
|
}
|
|
1384
|
-
async checkLivePriceProtectionRequirement(request, quote) {
|
|
1385
|
-
if (!this.dcaV2Enabled || quote.type !== "DCA") return;
|
|
1386
|
-
const { assets: assets2 } = await this.cache.read("networkInfo");
|
|
1387
|
-
const srcAsset = chainflip.getInternalAsset(request.srcAsset);
|
|
1388
|
-
const destAsset = chainflip.getInternalAsset(request.destAsset);
|
|
1389
|
-
if (![srcAsset, destAsset].every(
|
|
1390
|
-
(asset2) => assets2.find((a) => a.asset === asset2)?.livePriceProtectionEnabled
|
|
1391
|
-
)) {
|
|
1392
|
-
return;
|
|
1393
|
-
}
|
|
1394
|
-
if (isNotNullish(request.fillOrKillParams.maxOraclePriceSlippage)) return;
|
|
1395
|
-
throw new Error(
|
|
1396
|
-
"Max oracle price slippage must be set in FillOrKillParams when live price protection is enabled for both assets in DCA V2"
|
|
1397
|
-
);
|
|
1398
|
-
}
|
|
1399
1373
|
};
|
|
1400
1374
|
var arrayToMap = (array) => Object.fromEntries(array.map((item) => [item, item]));
|
|
1401
1375
|
var ChainflipNetworks = arrayToMap(chainflip.chainflipNetworks);
|
package/dist/swap.d.cts
CHANGED
|
@@ -298,7 +298,7 @@ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
|
|
|
298
298
|
type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
|
|
299
299
|
type BoostQuote = RegularBoostQuote | DCABoostQuote;
|
|
300
300
|
type FillOrKillParams = {
|
|
301
|
-
livePriceSlippageTolerancePercent?: string | number
|
|
301
|
+
livePriceSlippageTolerancePercent?: string | number;
|
|
302
302
|
refundAddress: string;
|
|
303
303
|
refundCcmMetadata?: CcmParams | null;
|
|
304
304
|
} & ({
|
|
@@ -683,7 +683,6 @@ declare class SwapSDK {
|
|
|
683
683
|
channelOpeningFee: string;
|
|
684
684
|
estimatedExpiryTime?: number | undefined;
|
|
685
685
|
}>;
|
|
686
|
-
private checkLivePriceProtectionRequirement;
|
|
687
686
|
}
|
|
688
687
|
|
|
689
688
|
/**
|
package/dist/swap.d.ts
CHANGED
|
@@ -298,7 +298,7 @@ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
|
|
|
298
298
|
type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
|
|
299
299
|
type BoostQuote = RegularBoostQuote | DCABoostQuote;
|
|
300
300
|
type FillOrKillParams = {
|
|
301
|
-
livePriceSlippageTolerancePercent?: string | number
|
|
301
|
+
livePriceSlippageTolerancePercent?: string | number;
|
|
302
302
|
refundAddress: string;
|
|
303
303
|
refundCcmMetadata?: CcmParams | null;
|
|
304
304
|
} & ({
|
|
@@ -683,7 +683,6 @@ declare class SwapSDK {
|
|
|
683
683
|
channelOpeningFee: string;
|
|
684
684
|
estimatedExpiryTime?: number | undefined;
|
|
685
685
|
}>;
|
|
686
|
-
private checkLivePriceProtectionRequirement;
|
|
687
686
|
}
|
|
688
687
|
|
|
689
688
|
/**
|
package/dist/swap.js
CHANGED
|
@@ -653,30 +653,22 @@ var blocksPerMinute = 60 / CHAINFLIP_BLOCK_TIME_SECONDS;
|
|
|
653
653
|
function parseFoKParams(params, quote) {
|
|
654
654
|
const srcAsset = getInternalAsset(quote.srcAsset);
|
|
655
655
|
const destAsset = getInternalAsset(quote.destAsset);
|
|
656
|
-
const
|
|
657
|
-
const livePriceProtectionEnabled = typeof params.livePriceSlippageTolerancePercent === "string" || typeof params.livePriceSlippageTolerancePercent === "number";
|
|
658
|
-
const livePriceProtectionAvailable = isNotNullish(
|
|
659
|
-
quote.recommendedLivePriceSlippageTolerancePercent
|
|
660
|
-
);
|
|
661
|
-
if (livePriceProtectionEnabled && !livePriceProtectionAvailable) {
|
|
662
|
-
throw new Error("Live price protection is not available for this asset pair");
|
|
663
|
-
}
|
|
656
|
+
const lppAvailable = isNotNullish(quote.recommendedLivePriceSlippageTolerancePercent);
|
|
664
657
|
let minPrice;
|
|
665
|
-
let
|
|
666
|
-
if (
|
|
667
|
-
if (
|
|
668
|
-
|
|
669
|
-
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
670
|
-
assert(
|
|
671
|
-
livePriceSlippageTolerancePercent.gte(0) && livePriceSlippageTolerancePercent.lte(100),
|
|
672
|
-
"Live price slippage tolerance must be between 0 and 100 inclusive"
|
|
673
|
-
);
|
|
674
|
-
} else if (quote.recommendedLivePriceSlippageTolerancePercent) {
|
|
675
|
-
livePriceSlippageTolerancePercent = new BigNumber2(
|
|
676
|
-
quote.recommendedLivePriceSlippageTolerancePercent
|
|
677
|
-
);
|
|
678
|
-
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
658
|
+
let lpp = null;
|
|
659
|
+
if (isNotNullish(params.livePriceSlippageTolerancePercent)) {
|
|
660
|
+
if (!lppAvailable) {
|
|
661
|
+
throw new Error("Live price protection is not available for this asset pair");
|
|
679
662
|
}
|
|
663
|
+
lpp = new BigNumber2(params.livePriceSlippageTolerancePercent);
|
|
664
|
+
assert(!lpp.isNaN(), "Invalid live price slippage tolerance");
|
|
665
|
+
assert(
|
|
666
|
+
lpp.gte(0) && lpp.lte(100),
|
|
667
|
+
"Live price slippage tolerance must be between 0 and 100 inclusive"
|
|
668
|
+
);
|
|
669
|
+
} else if (quote.recommendedLivePriceSlippageTolerancePercent) {
|
|
670
|
+
lpp = new BigNumber2(quote.recommendedLivePriceSlippageTolerancePercent);
|
|
671
|
+
assert(!lpp.isNaN(), "Invalid live price slippage tolerance");
|
|
680
672
|
}
|
|
681
673
|
if ("minPrice" in params) {
|
|
682
674
|
assert(
|
|
@@ -699,7 +691,7 @@ function parseFoKParams(params, quote) {
|
|
|
699
691
|
throw new Error("Either minPrice or slippageTolerancePercent must be provided");
|
|
700
692
|
}
|
|
701
693
|
const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
|
|
702
|
-
const maxOraclePriceSlippage =
|
|
694
|
+
const maxOraclePriceSlippage = lpp?.multipliedBy(100).toNumber() ?? null;
|
|
703
695
|
const parsed = {
|
|
704
696
|
retryDurationBlocks,
|
|
705
697
|
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
|
|
@@ -787,7 +779,7 @@ var getChainData = (chain2, network, env) => ({
|
|
|
787
779
|
|
|
788
780
|
// package.json
|
|
789
781
|
var package_default = {
|
|
790
|
-
version: "2.1.
|
|
782
|
+
version: "2.1.1"};
|
|
791
783
|
|
|
792
784
|
// src/swap/consts.ts
|
|
793
785
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
|
@@ -1035,7 +1027,6 @@ var SwapSDK = class {
|
|
|
1035
1027
|
ccmParams,
|
|
1036
1028
|
amount: quote.depositAmount
|
|
1037
1029
|
};
|
|
1038
|
-
await this.checkLivePriceProtectionRequirement(depositAddressRequest, quote);
|
|
1039
1030
|
let response;
|
|
1040
1031
|
if (this.options.broker) {
|
|
1041
1032
|
const result = await requestSwapDepositAddress(
|
|
@@ -1126,7 +1117,6 @@ var SwapSDK = class {
|
|
|
1126
1117
|
commissionBps: brokerCommissionBps,
|
|
1127
1118
|
affiliates
|
|
1128
1119
|
};
|
|
1129
|
-
await this.checkLivePriceProtectionRequirement(vaultSwapRequest, quote);
|
|
1130
1120
|
if (this.options.broker) {
|
|
1131
1121
|
assert(
|
|
1132
1122
|
!vaultSwapRequest.brokerAccount,
|
|
@@ -1188,7 +1178,6 @@ var SwapSDK = class {
|
|
|
1188
1178
|
commissionBps: await this.getCommissionBps(brokerCommissionBps),
|
|
1189
1179
|
affiliates
|
|
1190
1180
|
};
|
|
1191
|
-
await this.checkLivePriceProtectionRequirement(requestParams, quote);
|
|
1192
1181
|
if (this.options.broker) {
|
|
1193
1182
|
assert(
|
|
1194
1183
|
!brokerAccount,
|
|
@@ -1235,21 +1224,6 @@ var SwapSDK = class {
|
|
|
1235
1224
|
}
|
|
1236
1225
|
return res.body;
|
|
1237
1226
|
}
|
|
1238
|
-
async checkLivePriceProtectionRequirement(request, quote) {
|
|
1239
|
-
if (!this.dcaV2Enabled || quote.type !== "DCA") return;
|
|
1240
|
-
const { assets: assets2 } = await this.cache.read("networkInfo");
|
|
1241
|
-
const srcAsset = getInternalAsset(request.srcAsset);
|
|
1242
|
-
const destAsset = getInternalAsset(request.destAsset);
|
|
1243
|
-
if (![srcAsset, destAsset].every(
|
|
1244
|
-
(asset2) => assets2.find((a) => a.asset === asset2)?.livePriceProtectionEnabled
|
|
1245
|
-
)) {
|
|
1246
|
-
return;
|
|
1247
|
-
}
|
|
1248
|
-
if (isNotNullish(request.fillOrKillParams.maxOraclePriceSlippage)) return;
|
|
1249
|
-
throw new Error(
|
|
1250
|
-
"Max oracle price slippage must be set in FillOrKillParams when live price protection is enabled for both assets in DCA V2"
|
|
1251
|
-
);
|
|
1252
|
-
}
|
|
1253
1227
|
};
|
|
1254
1228
|
var arrayToMap = (array) => Object.fromEntries(array.map((item) => [item, item]));
|
|
1255
1229
|
var ChainflipNetworks = arrayToMap(chainflipNetworks);
|