@allbridge/bridge-core-sdk 0.4.1 → 0.4.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/browser/index.js +23 -9
- package/dist/browser/index.js.map +2 -2
- package/dist/cjs/index.js +23 -9
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/index.js +23 -9
- package/dist/esm/index.js.map +2 -2
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/calculation/index.js +29 -7
- package/dist/src/utils/calculation/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -62454,8 +62454,12 @@ function fromSystemPrecision(amount, decimals) {
|
|
|
62454
62454
|
return convertAmountPrecision(amount, SYSTEM_PRECISION, decimals);
|
|
62455
62455
|
}
|
|
62456
62456
|
function swapToVUsd(amount, tokenInfo) {
|
|
62457
|
-
const
|
|
62458
|
-
|
|
62457
|
+
const amountValue = Big(amount);
|
|
62458
|
+
if (amountValue.lte(0)) {
|
|
62459
|
+
return Big(0);
|
|
62460
|
+
}
|
|
62461
|
+
const fee = amountValue.times(tokenInfo.feeShare);
|
|
62462
|
+
const amountWithoutFee = amountValue.minus(fee);
|
|
62459
62463
|
const inSystemPrecision = toSystemPrecision(
|
|
62460
62464
|
amountWithoutFee,
|
|
62461
62465
|
tokenInfo.decimals
|
|
@@ -62466,8 +62470,12 @@ function swapToVUsd(amount, tokenInfo) {
|
|
|
62466
62470
|
return Big(poolInfo.vUsdBalance).minus(vUsdNewAmount).round(0, 0);
|
|
62467
62471
|
}
|
|
62468
62472
|
function swapFromVUsd(amount, tokenInfo) {
|
|
62473
|
+
const amountValue = Big(amount);
|
|
62474
|
+
if (amountValue.lte(0)) {
|
|
62475
|
+
return Big(0);
|
|
62476
|
+
}
|
|
62469
62477
|
const poolInfo = tokenInfo.poolInfo;
|
|
62470
|
-
const vUsdBalance =
|
|
62478
|
+
const vUsdBalance = amountValue.plus(poolInfo.vUsdBalance);
|
|
62471
62479
|
const newAmount = getY(vUsdBalance, poolInfo.aValue, poolInfo.dValue);
|
|
62472
62480
|
const result = fromSystemPrecision(
|
|
62473
62481
|
Big(poolInfo.tokenBalance).minus(newAmount),
|
|
@@ -62477,6 +62485,9 @@ function swapFromVUsd(amount, tokenInfo) {
|
|
|
62477
62485
|
return Big(result).minus(fee).round(0, 0);
|
|
62478
62486
|
}
|
|
62479
62487
|
function swapToVUsdReverse(amount, tokenInfo) {
|
|
62488
|
+
if (Big(amount).lte(0)) {
|
|
62489
|
+
return Big(0);
|
|
62490
|
+
}
|
|
62480
62491
|
const poolInfo = tokenInfo.poolInfo;
|
|
62481
62492
|
const vUsdNewAmount = Big(poolInfo.vUsdBalance).minus(amount);
|
|
62482
62493
|
const tokenBalance = getY(vUsdNewAmount, poolInfo.aValue, poolInfo.dValue);
|
|
@@ -62488,14 +62499,17 @@ function swapToVUsdReverse(amount, tokenInfo) {
|
|
|
62488
62499
|
const reversedFeeShare = Big(tokenInfo.feeShare).div(
|
|
62489
62500
|
Big(1).minus(tokenInfo.feeShare)
|
|
62490
62501
|
);
|
|
62491
|
-
const fee = Big(amountWithoutFee).times(reversedFeeShare);
|
|
62502
|
+
const fee = Big(amountWithoutFee).times(reversedFeeShare).round(0, Big.roundUp);
|
|
62492
62503
|
return Big(amountWithoutFee).plus(fee).round(0, 0);
|
|
62493
62504
|
}
|
|
62494
62505
|
function swapFromVUsdReverse(amount, tokenInfo) {
|
|
62506
|
+
if (Big(amount).lte(0)) {
|
|
62507
|
+
return Big(0);
|
|
62508
|
+
}
|
|
62495
62509
|
const reversedFeeShare = Big(tokenInfo.feeShare).div(
|
|
62496
62510
|
Big(1).minus(tokenInfo.feeShare)
|
|
62497
62511
|
);
|
|
62498
|
-
const fee = Big(amount).times(reversedFeeShare);
|
|
62512
|
+
const fee = Big(amount).times(reversedFeeShare).round(0, Big.roundUp);
|
|
62499
62513
|
const amountWithFee = Big(amount).plus(fee);
|
|
62500
62514
|
const inSystemPrecision = toSystemPrecision(
|
|
62501
62515
|
amountWithFee,
|
|
@@ -62523,9 +62537,9 @@ function getY(x, a, d) {
|
|
|
62523
62537
|
const commonPartBig = Big(4).times(a).times(Big(d).minus(x)).minus(d);
|
|
62524
62538
|
const dCubed = Big(d).pow(3);
|
|
62525
62539
|
const commonPartSquared = commonPartBig.pow(2);
|
|
62526
|
-
const sqrtBig = Big(x).times(Big(x).times(commonPartSquared).plus(Big(4).times(a).times(dCubed))).sqrt();
|
|
62540
|
+
const sqrtBig = Big(x).times(Big(x).times(commonPartSquared).plus(Big(4).times(a).times(dCubed))).sqrt().round(0, 0);
|
|
62527
62541
|
const dividerBig = Big(8).times(a).times(x);
|
|
62528
|
-
return commonPartBig.times(x).plus(sqrtBig).div(dividerBig);
|
|
62542
|
+
return commonPartBig.times(x).plus(sqrtBig).div(dividerBig).round(0, 0).plus(1);
|
|
62529
62543
|
}
|
|
62530
62544
|
|
|
62531
62545
|
// src/bridge/models/bridge.model.ts
|
|
@@ -66171,8 +66185,8 @@ var AllbridgeCoreSdk = class {
|
|
|
66171
66185
|
amountToBeReceivedFloat,
|
|
66172
66186
|
destinationChainToken.decimals
|
|
66173
66187
|
);
|
|
66174
|
-
const
|
|
66175
|
-
const resultInt = swapToVUsdReverse(
|
|
66188
|
+
const vUsd = swapFromVUsdReverse(amountToBeReceived, destinationChainToken);
|
|
66189
|
+
const resultInt = swapToVUsdReverse(vUsd, sourceChainToken);
|
|
66176
66190
|
if (resultInt.lte(0)) {
|
|
66177
66191
|
throw new InsufficientPoolLiquidity();
|
|
66178
66192
|
}
|