@atomiqlabs/lp-lib 17.5.0 → 17.5.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/prices/CoinGeckoSwapPrice.d.ts +1 -1
- package/dist/prices/CoinGeckoSwapPrice.js +3 -3
- package/dist/prices/ISwapPrice.d.ts +1 -1
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +6 -0
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +6 -0
- package/package.json +1 -1
- package/src/prices/CoinGeckoSwapPrice.ts +3 -3
- package/src/prices/ISwapPrice.ts +1 -1
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +6 -0
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +6 -0
|
@@ -10,7 +10,7 @@ class CoinGeckoSwapPrice extends ISwapPrice_1.ISwapPrice {
|
|
|
10
10
|
this.url = url || "https://api.coingecko.com/api/v3";
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Returns coin price in
|
|
13
|
+
* Returns coin price in uSat (sats-per-token * 1_000_000)
|
|
14
14
|
*
|
|
15
15
|
* @param coin
|
|
16
16
|
*/
|
|
@@ -18,7 +18,7 @@ class CoinGeckoSwapPrice extends ISwapPrice_1.ISwapPrice {
|
|
|
18
18
|
const coinId = coin.coinId;
|
|
19
19
|
if (coinId.startsWith("$fixed-")) {
|
|
20
20
|
const amt = parseFloat(coinId.substring(7));
|
|
21
|
-
return BigInt(Math.floor(amt *
|
|
21
|
+
return BigInt(Math.floor(amt * 1000000));
|
|
22
22
|
}
|
|
23
23
|
const cachedValue = this.cache[coinId];
|
|
24
24
|
if (cachedValue != null && cachedValue.expiry > Date.now()) {
|
|
@@ -40,7 +40,7 @@ class CoinGeckoSwapPrice extends ISwapPrice_1.ISwapPrice {
|
|
|
40
40
|
}
|
|
41
41
|
let jsonBody = await response.json();
|
|
42
42
|
const amt = jsonBody[coinId].sats;
|
|
43
|
-
const result = BigInt(Math.floor(amt *
|
|
43
|
+
const result = BigInt(Math.floor(amt * 1000000));
|
|
44
44
|
this.cache[coinId] = {
|
|
45
45
|
price: result,
|
|
46
46
|
expiry: Date.now() + CACHE_DURATION
|
|
@@ -13,7 +13,7 @@ export declare abstract class ISwapPrice<T extends {
|
|
|
13
13
|
protected coinsMap: ISwapPriceCoinsMap<T>;
|
|
14
14
|
protected constructor(coinsMap: ISwapPriceCoinsMap<T>);
|
|
15
15
|
/**
|
|
16
|
-
* Returns coin price in
|
|
16
|
+
* Returns coin price in uSat (sats-per-token * 1_000_000)
|
|
17
17
|
*
|
|
18
18
|
* @param tokenData
|
|
19
19
|
*/
|
|
@@ -26,6 +26,12 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
26
26
|
this.config.invoiceTimeoutSeconds = this.config.invoiceTimeoutSeconds || 90;
|
|
27
27
|
this.lightning = lightning;
|
|
28
28
|
this.LightningAssertions = new LightningAssertions_1.LightningAssertions(this.logger, lightning);
|
|
29
|
+
for (let chain in this.allowedTokens) {
|
|
30
|
+
//Remove chains that don't support from btcln auto swaps
|
|
31
|
+
const { swapContract } = this.getChain(chain);
|
|
32
|
+
if (!swapContract.supportsInitWithoutClaimer)
|
|
33
|
+
this.allowedTokens[chain].clear();
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
async processPastSwap(swap) {
|
|
31
37
|
const { swapContract, signer } = this.getChain(swap.chainIdentifier);
|
|
@@ -41,6 +41,12 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
|
41
41
|
this.AmountAssertions = new FromBtcAmountAssertions_1.FromBtcAmountAssertions(config, swapPricing);
|
|
42
42
|
this.Vaults = new SpvVaults_1.SpvVaults(vaultStorage, bitcoin, spvVaultSigner, bitcoinRpc, this.chains, config);
|
|
43
43
|
this.stickyAddresses = stickyAddresses;
|
|
44
|
+
for (let chain in this.allowedTokens) {
|
|
45
|
+
//Remove chains that don't support spv vault swaps
|
|
46
|
+
const { spvVaultContract } = this.getChain(chain);
|
|
47
|
+
if (spvVaultContract == null)
|
|
48
|
+
this.allowedTokens[chain].clear();
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
async getStickyAddress(chainId, address) {
|
|
46
52
|
if (this.stickyAddresses == null)
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ export class CoinGeckoSwapPrice extends ISwapPrice<{coinId: string, decimals: nu
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Returns coin price in
|
|
30
|
+
* Returns coin price in uSat (sats-per-token * 1_000_000)
|
|
31
31
|
*
|
|
32
32
|
* @param coin
|
|
33
33
|
*/
|
|
@@ -35,7 +35,7 @@ export class CoinGeckoSwapPrice extends ISwapPrice<{coinId: string, decimals: nu
|
|
|
35
35
|
const coinId = coin.coinId;
|
|
36
36
|
if(coinId.startsWith("$fixed-")) {
|
|
37
37
|
const amt: number = parseFloat(coinId.substring(7));
|
|
38
|
-
return BigInt(Math.floor(amt*
|
|
38
|
+
return BigInt(Math.floor(amt*1000000));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const cachedValue = this.cache[coinId];
|
|
@@ -62,7 +62,7 @@ export class CoinGeckoSwapPrice extends ISwapPrice<{coinId: string, decimals: nu
|
|
|
62
62
|
|
|
63
63
|
const amt: number = jsonBody[coinId].sats;
|
|
64
64
|
|
|
65
|
-
const result = BigInt(Math.floor(amt*
|
|
65
|
+
const result = BigInt(Math.floor(amt*1000000));
|
|
66
66
|
|
|
67
67
|
this.cache[coinId] = {
|
|
68
68
|
price: result,
|
package/src/prices/ISwapPrice.ts
CHANGED
|
@@ -67,6 +67,12 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
67
67
|
this.config.invoiceTimeoutSeconds = this.config.invoiceTimeoutSeconds || 90;
|
|
68
68
|
this.lightning = lightning;
|
|
69
69
|
this.LightningAssertions = new LightningAssertions(this.logger, lightning);
|
|
70
|
+
|
|
71
|
+
for(let chain in this.allowedTokens) {
|
|
72
|
+
//Remove chains that don't support from btcln auto swaps
|
|
73
|
+
const {swapContract} = this.getChain(chain);
|
|
74
|
+
if(!swapContract.supportsInitWithoutClaimer) this.allowedTokens[chain].clear();
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
protected async processPastSwap(swap: FromBtcLnAutoSwap): Promise<"REFUND" | "SETTLE" | null> {
|
|
@@ -121,6 +121,12 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
|
|
|
121
121
|
this.AmountAssertions = new FromBtcAmountAssertions(config, swapPricing);
|
|
122
122
|
this.Vaults = new SpvVaults(vaultStorage, bitcoin, spvVaultSigner, bitcoinRpc, this.chains, config);
|
|
123
123
|
this.stickyAddresses = stickyAddresses;
|
|
124
|
+
|
|
125
|
+
for(let chain in this.allowedTokens) {
|
|
126
|
+
//Remove chains that don't support spv vault swaps
|
|
127
|
+
const {spvVaultContract} = this.getChain(chain);
|
|
128
|
+
if(spvVaultContract==null) this.allowedTokens[chain].clear();
|
|
129
|
+
}
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
private async getStickyAddress(chainId: string, address: string): Promise<string | undefined> {
|