@atomiqlabs/lp-lib 14.0.0-dev.15 → 14.0.0-dev.16
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.
|
@@ -108,11 +108,15 @@ class FromBtcAmountAssertions extends AmountAssertions_1.AmountAssertions {
|
|
|
108
108
|
amountBDgas = _amountBDgas;
|
|
109
109
|
}
|
|
110
110
|
let amountBD;
|
|
111
|
+
let swapFee;
|
|
111
112
|
if (!requestedAmount.input) {
|
|
112
113
|
amountBD = await this.swapPricing.getToBtcSwapAmount(requestedAmount.amount, requestedAmount.token, chainIdentifier, true, requestedAmount.pricePrefetch);
|
|
113
114
|
signal.throwIfAborted();
|
|
114
115
|
// amt = (amt+base_fee)/(1-fee)
|
|
115
|
-
|
|
116
|
+
const denominator = (1000000n - fees.feePPM);
|
|
117
|
+
const _amountBD = ((amountBD + fees.baseFee) * 1000000n + denominator - 1n) / denominator;
|
|
118
|
+
swapFee = _amountBD - amountBD;
|
|
119
|
+
amountBD = _amountBD;
|
|
116
120
|
const tooLow = amountBD < (this.config.min * 95n / 100n);
|
|
117
121
|
const tooHigh = amountBD > (this.config.max * 105n / 100n);
|
|
118
122
|
if (tooLow || tooHigh) {
|
|
@@ -133,6 +137,7 @@ class FromBtcAmountAssertions extends AmountAssertions_1.AmountAssertions {
|
|
|
133
137
|
else {
|
|
134
138
|
this.checkBtcAmountInBounds(requestedAmount.amount);
|
|
135
139
|
amountBD = requestedAmount.amount - amountBDgas;
|
|
140
|
+
swapFee = fees.baseFee + ((amountBD * fees.feePPM + 999999n) / 1000000n);
|
|
136
141
|
if (amountBD < 0n) {
|
|
137
142
|
throw {
|
|
138
143
|
code: 20003,
|
|
@@ -144,7 +149,6 @@ class FromBtcAmountAssertions extends AmountAssertions_1.AmountAssertions {
|
|
|
144
149
|
};
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
|
-
const swapFee = fees.baseFee + (amountBD * fees.feePPM / 1000000n);
|
|
148
152
|
const swapFeeInToken = await this.swapPricing.getFromBtcSwapAmount(swapFee, requestedAmount.token, chainIdentifier, true, requestedAmount.pricePrefetch);
|
|
149
153
|
signal.throwIfAborted();
|
|
150
154
|
const gasSwapFeeInToken = gasTokenAmount == null ?
|
package/package.json
CHANGED
|
@@ -166,12 +166,16 @@ export class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
let amountBD: bigint;
|
|
169
|
+
let swapFee: bigint;
|
|
169
170
|
if(!requestedAmount.input) {
|
|
170
171
|
amountBD = await this.swapPricing.getToBtcSwapAmount(requestedAmount.amount, requestedAmount.token, chainIdentifier, true, requestedAmount.pricePrefetch);
|
|
171
172
|
signal.throwIfAborted();
|
|
172
173
|
|
|
173
174
|
// amt = (amt+base_fee)/(1-fee)
|
|
174
|
-
|
|
175
|
+
const denominator = (1000000n - fees.feePPM);
|
|
176
|
+
const _amountBD = ((amountBD + fees.baseFee) * 1000000n + denominator - 1n) / denominator;
|
|
177
|
+
swapFee = _amountBD - amountBD;
|
|
178
|
+
amountBD = _amountBD;
|
|
175
179
|
|
|
176
180
|
const tooLow = amountBD < (this.config.min * 95n / 100n);
|
|
177
181
|
const tooHigh = amountBD > (this.config.max * 105n / 100n);
|
|
@@ -196,6 +200,7 @@ export class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
196
200
|
} else {
|
|
197
201
|
this.checkBtcAmountInBounds(requestedAmount.amount);
|
|
198
202
|
amountBD = requestedAmount.amount - amountBDgas;
|
|
203
|
+
swapFee = fees.baseFee + ((amountBD * fees.feePPM + 999_999n) / 1000000n);
|
|
199
204
|
if(amountBD < 0n) {
|
|
200
205
|
throw {
|
|
201
206
|
code: 20003,
|
|
@@ -208,7 +213,6 @@ export class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
208
213
|
}
|
|
209
214
|
}
|
|
210
215
|
|
|
211
|
-
const swapFee = fees.baseFee + (amountBD * fees.feePPM / 1000000n);
|
|
212
216
|
const swapFeeInToken = await this.swapPricing.getFromBtcSwapAmount(swapFee, requestedAmount.token, chainIdentifier, true, requestedAmount.pricePrefetch);
|
|
213
217
|
signal.throwIfAborted();
|
|
214
218
|
|