@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/cjs/index.js
CHANGED
|
@@ -62464,8 +62464,12 @@ function fromSystemPrecision(amount, decimals) {
|
|
|
62464
62464
|
return convertAmountPrecision(amount, SYSTEM_PRECISION, decimals);
|
|
62465
62465
|
}
|
|
62466
62466
|
function swapToVUsd(amount, tokenInfo) {
|
|
62467
|
-
const
|
|
62468
|
-
|
|
62467
|
+
const amountValue = Big(amount);
|
|
62468
|
+
if (amountValue.lte(0)) {
|
|
62469
|
+
return Big(0);
|
|
62470
|
+
}
|
|
62471
|
+
const fee = amountValue.times(tokenInfo.feeShare);
|
|
62472
|
+
const amountWithoutFee = amountValue.minus(fee);
|
|
62469
62473
|
const inSystemPrecision = toSystemPrecision(
|
|
62470
62474
|
amountWithoutFee,
|
|
62471
62475
|
tokenInfo.decimals
|
|
@@ -62476,8 +62480,12 @@ function swapToVUsd(amount, tokenInfo) {
|
|
|
62476
62480
|
return Big(poolInfo.vUsdBalance).minus(vUsdNewAmount).round(0, 0);
|
|
62477
62481
|
}
|
|
62478
62482
|
function swapFromVUsd(amount, tokenInfo) {
|
|
62483
|
+
const amountValue = Big(amount);
|
|
62484
|
+
if (amountValue.lte(0)) {
|
|
62485
|
+
return Big(0);
|
|
62486
|
+
}
|
|
62479
62487
|
const poolInfo = tokenInfo.poolInfo;
|
|
62480
|
-
const vUsdBalance =
|
|
62488
|
+
const vUsdBalance = amountValue.plus(poolInfo.vUsdBalance);
|
|
62481
62489
|
const newAmount = getY(vUsdBalance, poolInfo.aValue, poolInfo.dValue);
|
|
62482
62490
|
const result = fromSystemPrecision(
|
|
62483
62491
|
Big(poolInfo.tokenBalance).minus(newAmount),
|
|
@@ -62487,6 +62495,9 @@ function swapFromVUsd(amount, tokenInfo) {
|
|
|
62487
62495
|
return Big(result).minus(fee).round(0, 0);
|
|
62488
62496
|
}
|
|
62489
62497
|
function swapToVUsdReverse(amount, tokenInfo) {
|
|
62498
|
+
if (Big(amount).lte(0)) {
|
|
62499
|
+
return Big(0);
|
|
62500
|
+
}
|
|
62490
62501
|
const poolInfo = tokenInfo.poolInfo;
|
|
62491
62502
|
const vUsdNewAmount = Big(poolInfo.vUsdBalance).minus(amount);
|
|
62492
62503
|
const tokenBalance = getY(vUsdNewAmount, poolInfo.aValue, poolInfo.dValue);
|
|
@@ -62498,14 +62509,17 @@ function swapToVUsdReverse(amount, tokenInfo) {
|
|
|
62498
62509
|
const reversedFeeShare = Big(tokenInfo.feeShare).div(
|
|
62499
62510
|
Big(1).minus(tokenInfo.feeShare)
|
|
62500
62511
|
);
|
|
62501
|
-
const fee = Big(amountWithoutFee).times(reversedFeeShare);
|
|
62512
|
+
const fee = Big(amountWithoutFee).times(reversedFeeShare).round(0, Big.roundUp);
|
|
62502
62513
|
return Big(amountWithoutFee).plus(fee).round(0, 0);
|
|
62503
62514
|
}
|
|
62504
62515
|
function swapFromVUsdReverse(amount, tokenInfo) {
|
|
62516
|
+
if (Big(amount).lte(0)) {
|
|
62517
|
+
return Big(0);
|
|
62518
|
+
}
|
|
62505
62519
|
const reversedFeeShare = Big(tokenInfo.feeShare).div(
|
|
62506
62520
|
Big(1).minus(tokenInfo.feeShare)
|
|
62507
62521
|
);
|
|
62508
|
-
const fee = Big(amount).times(reversedFeeShare);
|
|
62522
|
+
const fee = Big(amount).times(reversedFeeShare).round(0, Big.roundUp);
|
|
62509
62523
|
const amountWithFee = Big(amount).plus(fee);
|
|
62510
62524
|
const inSystemPrecision = toSystemPrecision(
|
|
62511
62525
|
amountWithFee,
|
|
@@ -62533,9 +62547,9 @@ function getY(x, a, d) {
|
|
|
62533
62547
|
const commonPartBig = Big(4).times(a).times(Big(d).minus(x)).minus(d);
|
|
62534
62548
|
const dCubed = Big(d).pow(3);
|
|
62535
62549
|
const commonPartSquared = commonPartBig.pow(2);
|
|
62536
|
-
const sqrtBig = Big(x).times(Big(x).times(commonPartSquared).plus(Big(4).times(a).times(dCubed))).sqrt();
|
|
62550
|
+
const sqrtBig = Big(x).times(Big(x).times(commonPartSquared).plus(Big(4).times(a).times(dCubed))).sqrt().round(0, 0);
|
|
62537
62551
|
const dividerBig = Big(8).times(a).times(x);
|
|
62538
|
-
return commonPartBig.times(x).plus(sqrtBig).div(dividerBig);
|
|
62552
|
+
return commonPartBig.times(x).plus(sqrtBig).div(dividerBig).round(0, 0).plus(1);
|
|
62539
62553
|
}
|
|
62540
62554
|
|
|
62541
62555
|
// src/bridge/models/bridge.model.ts
|
|
@@ -66181,8 +66195,8 @@ var AllbridgeCoreSdk = class {
|
|
|
66181
66195
|
amountToBeReceivedFloat,
|
|
66182
66196
|
destinationChainToken.decimals
|
|
66183
66197
|
);
|
|
66184
|
-
const
|
|
66185
|
-
const resultInt = swapToVUsdReverse(
|
|
66198
|
+
const vUsd = swapFromVUsdReverse(amountToBeReceived, destinationChainToken);
|
|
66199
|
+
const resultInt = swapToVUsdReverse(vUsd, sourceChainToken);
|
|
66186
66200
|
if (resultInt.lte(0)) {
|
|
66187
66201
|
throw new InsufficientPoolLiquidity();
|
|
66188
66202
|
}
|