@chainflip/sdk 2.0.2-dev.0 → 2.0.2-dev.2
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 +13 -9
- package/dist/swap.d.cts +1 -1
- package/dist/swap.d.ts +1 -1
- package/dist/swap.js +13 -9
- package/package.json +1 -1
package/dist/swap.cjs
CHANGED
|
@@ -940,7 +940,7 @@ var getChainData = (chain2, network, env) => ({
|
|
|
940
940
|
|
|
941
941
|
// package.json
|
|
942
942
|
var package_default = {
|
|
943
|
-
version: "2.0.2-dev.
|
|
943
|
+
version: "2.0.2-dev.2"};
|
|
944
944
|
|
|
945
945
|
// src/swap/consts.ts
|
|
946
946
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
|
@@ -1191,7 +1191,7 @@ var SwapSDK = class {
|
|
|
1191
1191
|
ccmParams,
|
|
1192
1192
|
amount: quote.depositAmount
|
|
1193
1193
|
};
|
|
1194
|
-
await this.checkLivePriceProtectionRequirement(depositAddressRequest);
|
|
1194
|
+
await this.checkLivePriceProtectionRequirement(depositAddressRequest, quote);
|
|
1195
1195
|
let response;
|
|
1196
1196
|
if (this.options.broker) {
|
|
1197
1197
|
const result = await requestSwapDepositAddress(
|
|
@@ -1282,7 +1282,7 @@ var SwapSDK = class {
|
|
|
1282
1282
|
commissionBps: brokerCommissionBps,
|
|
1283
1283
|
affiliates
|
|
1284
1284
|
};
|
|
1285
|
-
await this.checkLivePriceProtectionRequirement(vaultSwapRequest);
|
|
1285
|
+
await this.checkLivePriceProtectionRequirement(vaultSwapRequest, quote);
|
|
1286
1286
|
if (this.options.broker) {
|
|
1287
1287
|
assert(
|
|
1288
1288
|
!vaultSwapRequest.brokerAccount,
|
|
@@ -1344,7 +1344,7 @@ var SwapSDK = class {
|
|
|
1344
1344
|
commissionBps: await this.getCommissionBps(brokerCommissionBps),
|
|
1345
1345
|
affiliates
|
|
1346
1346
|
};
|
|
1347
|
-
await this.checkLivePriceProtectionRequirement(requestParams);
|
|
1347
|
+
await this.checkLivePriceProtectionRequirement(requestParams, quote);
|
|
1348
1348
|
if (this.options.broker) {
|
|
1349
1349
|
assert(
|
|
1350
1350
|
!brokerAccount,
|
|
@@ -1391,8 +1391,8 @@ var SwapSDK = class {
|
|
|
1391
1391
|
}
|
|
1392
1392
|
return res.body;
|
|
1393
1393
|
}
|
|
1394
|
-
async checkLivePriceProtectionRequirement(request) {
|
|
1395
|
-
if (!this.dcaV2Enabled) return;
|
|
1394
|
+
async checkLivePriceProtectionRequirement(request, quote) {
|
|
1395
|
+
if (!this.dcaV2Enabled || quote.type !== "DCA") return;
|
|
1396
1396
|
const { assets: assets2 } = await this.cache.read("networkInfo");
|
|
1397
1397
|
const srcAsset = chainflip.getInternalAsset(request.srcAsset);
|
|
1398
1398
|
const destAsset = chainflip.getInternalAsset(request.destAsset);
|
|
@@ -1406,9 +1406,13 @@ var SwapSDK = class {
|
|
|
1406
1406
|
"Max oracle price slippage must be set in FillOrKillParams when live price protection is enabled for both assets in DCA V2"
|
|
1407
1407
|
);
|
|
1408
1408
|
}
|
|
1409
|
-
async calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent,
|
|
1409
|
+
async calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent, brokerCommissionBpsInput, quote) {
|
|
1410
1410
|
assert(slippageTolerancePercent >= 0, "slippageTolerancePercent must be non-negative");
|
|
1411
|
-
assert(
|
|
1411
|
+
assert(
|
|
1412
|
+
brokerCommissionBpsInput === void 0 || brokerCommissionBpsInput >= 0,
|
|
1413
|
+
"brokerCommissionBps must be non-negative"
|
|
1414
|
+
);
|
|
1415
|
+
const brokerCommissionBps = await this.getCommissionBps(brokerCommissionBpsInput);
|
|
1412
1416
|
const { assets: assets2 } = await this.cache.read("networkInfo");
|
|
1413
1417
|
const srcAsset = chainflip.getInternalAsset(quote.srcAsset);
|
|
1414
1418
|
const destAsset = chainflip.getInternalAsset(quote.destAsset);
|
|
@@ -1422,7 +1426,7 @@ var SwapSDK = class {
|
|
|
1422
1426
|
const networkFeeBps = Math.max(
|
|
1423
1427
|
Number(chainflip.readAssetValue(networkFeeRates, srcAsset)),
|
|
1424
1428
|
Number(chainflip.readAssetValue(networkFeeRates, destAsset))
|
|
1425
|
-
);
|
|
1429
|
+
) / 100;
|
|
1426
1430
|
return slippageTolerancePercent + networkFeeBps / 100 + brokerCommissionBps / 100;
|
|
1427
1431
|
}
|
|
1428
1432
|
};
|
package/dist/swap.d.cts
CHANGED
|
@@ -702,7 +702,7 @@ declare class SwapSDK {
|
|
|
702
702
|
estimatedExpiryTime?: number | undefined;
|
|
703
703
|
}>;
|
|
704
704
|
private checkLivePriceProtectionRequirement;
|
|
705
|
-
calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent: number,
|
|
705
|
+
calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent: number, brokerCommissionBpsInput: number | undefined, quote: Pick<Quote | BoostQuote, 'srcAsset' | 'destAsset' | 'isOnChain'>): Promise<number | false>;
|
|
706
706
|
}
|
|
707
707
|
|
|
708
708
|
/**
|
package/dist/swap.d.ts
CHANGED
|
@@ -702,7 +702,7 @@ declare class SwapSDK {
|
|
|
702
702
|
estimatedExpiryTime?: number | undefined;
|
|
703
703
|
}>;
|
|
704
704
|
private checkLivePriceProtectionRequirement;
|
|
705
|
-
calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent: number,
|
|
705
|
+
calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent: number, brokerCommissionBpsInput: number | undefined, quote: Pick<Quote | BoostQuote, 'srcAsset' | 'destAsset' | 'isOnChain'>): Promise<number | false>;
|
|
706
706
|
}
|
|
707
707
|
|
|
708
708
|
/**
|
package/dist/swap.js
CHANGED
|
@@ -745,7 +745,7 @@ var getChainData = (chain2, network, env) => ({
|
|
|
745
745
|
|
|
746
746
|
// package.json
|
|
747
747
|
var package_default = {
|
|
748
|
-
version: "2.0.2-dev.
|
|
748
|
+
version: "2.0.2-dev.2"};
|
|
749
749
|
|
|
750
750
|
// src/swap/consts.ts
|
|
751
751
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
|
@@ -996,7 +996,7 @@ var SwapSDK = class {
|
|
|
996
996
|
ccmParams,
|
|
997
997
|
amount: quote.depositAmount
|
|
998
998
|
};
|
|
999
|
-
await this.checkLivePriceProtectionRequirement(depositAddressRequest);
|
|
999
|
+
await this.checkLivePriceProtectionRequirement(depositAddressRequest, quote);
|
|
1000
1000
|
let response;
|
|
1001
1001
|
if (this.options.broker) {
|
|
1002
1002
|
const result = await requestSwapDepositAddress(
|
|
@@ -1087,7 +1087,7 @@ var SwapSDK = class {
|
|
|
1087
1087
|
commissionBps: brokerCommissionBps,
|
|
1088
1088
|
affiliates
|
|
1089
1089
|
};
|
|
1090
|
-
await this.checkLivePriceProtectionRequirement(vaultSwapRequest);
|
|
1090
|
+
await this.checkLivePriceProtectionRequirement(vaultSwapRequest, quote);
|
|
1091
1091
|
if (this.options.broker) {
|
|
1092
1092
|
assert(
|
|
1093
1093
|
!vaultSwapRequest.brokerAccount,
|
|
@@ -1149,7 +1149,7 @@ var SwapSDK = class {
|
|
|
1149
1149
|
commissionBps: await this.getCommissionBps(brokerCommissionBps),
|
|
1150
1150
|
affiliates
|
|
1151
1151
|
};
|
|
1152
|
-
await this.checkLivePriceProtectionRequirement(requestParams);
|
|
1152
|
+
await this.checkLivePriceProtectionRequirement(requestParams, quote);
|
|
1153
1153
|
if (this.options.broker) {
|
|
1154
1154
|
assert(
|
|
1155
1155
|
!brokerAccount,
|
|
@@ -1196,8 +1196,8 @@ var SwapSDK = class {
|
|
|
1196
1196
|
}
|
|
1197
1197
|
return res.body;
|
|
1198
1198
|
}
|
|
1199
|
-
async checkLivePriceProtectionRequirement(request) {
|
|
1200
|
-
if (!this.dcaV2Enabled) return;
|
|
1199
|
+
async checkLivePriceProtectionRequirement(request, quote) {
|
|
1200
|
+
if (!this.dcaV2Enabled || quote.type !== "DCA") return;
|
|
1201
1201
|
const { assets: assets2 } = await this.cache.read("networkInfo");
|
|
1202
1202
|
const srcAsset = getInternalAsset(request.srcAsset);
|
|
1203
1203
|
const destAsset = getInternalAsset(request.destAsset);
|
|
@@ -1211,9 +1211,13 @@ var SwapSDK = class {
|
|
|
1211
1211
|
"Max oracle price slippage must be set in FillOrKillParams when live price protection is enabled for both assets in DCA V2"
|
|
1212
1212
|
);
|
|
1213
1213
|
}
|
|
1214
|
-
async calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent,
|
|
1214
|
+
async calculateLivePriceSlippageTolerancePercent(slippageTolerancePercent, brokerCommissionBpsInput, quote) {
|
|
1215
1215
|
assert(slippageTolerancePercent >= 0, "slippageTolerancePercent must be non-negative");
|
|
1216
|
-
assert(
|
|
1216
|
+
assert(
|
|
1217
|
+
brokerCommissionBpsInput === void 0 || brokerCommissionBpsInput >= 0,
|
|
1218
|
+
"brokerCommissionBps must be non-negative"
|
|
1219
|
+
);
|
|
1220
|
+
const brokerCommissionBps = await this.getCommissionBps(brokerCommissionBpsInput);
|
|
1217
1221
|
const { assets: assets2 } = await this.cache.read("networkInfo");
|
|
1218
1222
|
const srcAsset = getInternalAsset(quote.srcAsset);
|
|
1219
1223
|
const destAsset = getInternalAsset(quote.destAsset);
|
|
@@ -1227,7 +1231,7 @@ var SwapSDK = class {
|
|
|
1227
1231
|
const networkFeeBps = Math.max(
|
|
1228
1232
|
Number(readAssetValue(networkFeeRates, srcAsset)),
|
|
1229
1233
|
Number(readAssetValue(networkFeeRates, destAsset))
|
|
1230
|
-
);
|
|
1234
|
+
) / 100;
|
|
1231
1235
|
return slippageTolerancePercent + networkFeeBps / 100 + brokerCommissionBps / 100;
|
|
1232
1236
|
}
|
|
1233
1237
|
};
|