@atomiqlabs/lp-lib 16.0.6 → 16.0.8
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/swaps/assertions/FromBtcAmountAssertions.js +6 -1
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.js +5 -0
- package/dist/swaps/spv_vault_swap/SpvVaults.js +5 -2
- package/package.json +1 -1
- package/src/swaps/assertions/FromBtcAmountAssertions.ts +6 -1
- package/src/swaps/escrow/tobtc_abstract/ToBtcAbs.ts +5 -0
- package/src/swaps/spv_vault_swap/SpvVaults.ts +4 -2
|
@@ -138,7 +138,7 @@ class FromBtcAmountAssertions extends AmountAssertions_1.AmountAssertions {
|
|
|
138
138
|
this.checkBtcAmountInBounds(requestedAmount.amount);
|
|
139
139
|
amountBD = requestedAmount.amount - amountBDgas;
|
|
140
140
|
swapFee = fees.baseFee + ((amountBD * fees.feePPM + 999999n) / 1000000n);
|
|
141
|
-
if (amountBD < 0n) {
|
|
141
|
+
if (amountBD - swapFee < 0n) {
|
|
142
142
|
throw {
|
|
143
143
|
code: 20003,
|
|
144
144
|
msg: "Amount too low!",
|
|
@@ -163,6 +163,11 @@ class FromBtcAmountAssertions extends AmountAssertions_1.AmountAssertions {
|
|
|
163
163
|
totalInToken = await this.swapPricing.getFromBtcSwapAmount(amountBD - swapFee, requestedAmount.token, chainIdentifier, null, requestedAmount.pricePrefetch);
|
|
164
164
|
signal.throwIfAborted();
|
|
165
165
|
}
|
|
166
|
+
if (totalInToken < 0n)
|
|
167
|
+
throw {
|
|
168
|
+
code: 20003,
|
|
169
|
+
msg: "Amount too low!"
|
|
170
|
+
};
|
|
166
171
|
return {
|
|
167
172
|
amountBD,
|
|
168
173
|
swapFee,
|
|
@@ -586,6 +586,11 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
586
586
|
return resp;
|
|
587
587
|
}, abortController.signal);
|
|
588
588
|
metadata.times.priceCalculated = Date.now();
|
|
589
|
+
if (amountBD < 600n)
|
|
590
|
+
throw {
|
|
591
|
+
code: "20019",
|
|
592
|
+
msg: "Swap output amount is below bitcoin dust (600 sats)!"
|
|
593
|
+
};
|
|
589
594
|
const claimHash = this.getHash(chainIdentifier, parsedBody.address, parsedBody.confirmations, parsedBody.nonce, amountBD).toString("hex");
|
|
590
595
|
//Add grace period another time, so the user has 1 hour to commit
|
|
591
596
|
const expirySeconds = this.getExpiryFromCLTV(parsedBody.confirmationTarget, parsedBody.confirmations) + this.config.gracePeriod;
|
|
@@ -120,7 +120,7 @@ class SpvVaults {
|
|
|
120
120
|
return Object.keys(this.vaultStorage.data)
|
|
121
121
|
.map(key => this.vaultStorage.data[key])
|
|
122
122
|
.filter(val => chainId == null ? true : val.chainId === chainId)
|
|
123
|
-
.filter(val => val.data.getOwner() === this.chains.chains[val.chainId]?.signer?.getAddress())
|
|
123
|
+
.filter(val => this.chains.chains[val.chainId] != null && val.data.getOwner() === this.chains.chains[val.chainId]?.signer?.getAddress())
|
|
124
124
|
.filter(val => token == null ? true : val.data.getTokenData()[0].token === token);
|
|
125
125
|
}
|
|
126
126
|
async fundVault(vault, tokenAmounts) {
|
|
@@ -296,7 +296,10 @@ class SpvVaults {
|
|
|
296
296
|
const claimWithdrawals = [];
|
|
297
297
|
let promises = [];
|
|
298
298
|
for (let vault of vaults) {
|
|
299
|
-
const
|
|
299
|
+
const chainData = this.chains.chains[vault.chainId];
|
|
300
|
+
if (chainData == null)
|
|
301
|
+
continue;
|
|
302
|
+
const { signer, spvVaultContract, chainInterface } = chainData;
|
|
300
303
|
if (vault.data.getOwner() !== signer.getAddress())
|
|
301
304
|
continue;
|
|
302
305
|
if (vault.state === SpvVault_1.SpvVaultState.BTC_INITIATED) {
|
package/package.json
CHANGED
|
@@ -201,7 +201,7 @@ export class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
201
201
|
this.checkBtcAmountInBounds(requestedAmount.amount);
|
|
202
202
|
amountBD = requestedAmount.amount - amountBDgas;
|
|
203
203
|
swapFee = fees.baseFee + ((amountBD * fees.feePPM + 999_999n) / 1000000n);
|
|
204
|
-
if(amountBD < 0n) {
|
|
204
|
+
if(amountBD - swapFee < 0n) {
|
|
205
205
|
throw {
|
|
206
206
|
code: 20003,
|
|
207
207
|
msg: "Amount too low!",
|
|
@@ -229,6 +229,11 @@ export class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
229
229
|
signal.throwIfAborted();
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
if(totalInToken < 0n) throw {
|
|
233
|
+
code: 20003,
|
|
234
|
+
msg: "Amount too low!"
|
|
235
|
+
};
|
|
236
|
+
|
|
232
237
|
return {
|
|
233
238
|
amountBD,
|
|
234
239
|
swapFee,
|
|
@@ -708,6 +708,11 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
708
708
|
}, abortController.signal);
|
|
709
709
|
metadata.times.priceCalculated = Date.now();
|
|
710
710
|
|
|
711
|
+
if(amountBD < 600n) throw {
|
|
712
|
+
code: "20019",
|
|
713
|
+
msg: "Swap output amount is below bitcoin dust (600 sats)!"
|
|
714
|
+
};
|
|
715
|
+
|
|
711
716
|
const claimHash = this.getHash(chainIdentifier, parsedBody.address, parsedBody.confirmations, parsedBody.nonce, amountBD).toString("hex");
|
|
712
717
|
|
|
713
718
|
//Add grace period another time, so the user has 1 hour to commit
|
|
@@ -162,7 +162,7 @@ export class SpvVaults {
|
|
|
162
162
|
return Object.keys(this.vaultStorage.data)
|
|
163
163
|
.map(key => this.vaultStorage.data[key])
|
|
164
164
|
.filter(val => chainId==null ? true : val.chainId===chainId)
|
|
165
|
-
.filter(val => val.data.getOwner()===this.chains.chains[val.chainId]?.signer?.getAddress())
|
|
165
|
+
.filter(val => this.chains.chains[val.chainId]!=null && val.data.getOwner()===this.chains.chains[val.chainId]?.signer?.getAddress())
|
|
166
166
|
.filter(val => token==null ? true : val.data.getTokenData()[0].token===token);
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -351,7 +351,9 @@ export class SpvVaults {
|
|
|
351
351
|
let promises: Promise<void>[] = [];
|
|
352
352
|
|
|
353
353
|
for(let vault of vaults) {
|
|
354
|
-
const
|
|
354
|
+
const chainData = this.chains.chains[vault.chainId];
|
|
355
|
+
if(chainData==null) continue;
|
|
356
|
+
const {signer, spvVaultContract, chainInterface} = chainData;
|
|
355
357
|
if(vault.data.getOwner()!==signer.getAddress()) continue;
|
|
356
358
|
|
|
357
359
|
if(vault.state===SpvVaultState.BTC_INITIATED) {
|