crosslightning-intermediary
Advanced tools
Comparing version 10.1.0-beta9 to 10.2.0
@@ -55,4 +55,4 @@ "use strict"; | ||
chains[chainIdentifier] = { | ||
address: singleChain.swapContract.getAddress(), | ||
signature: yield singleChain.swapContract.getDataSignature(envelopeBuffer) | ||
address: singleChain.signer.getAddress(), | ||
signature: yield singleChain.swapContract.getDataSignature(singleChain.signer, envelopeBuffer) | ||
}; | ||
@@ -59,0 +59,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { BitcoinRpc, SwapData, TokenAddress } from "crosslightning-base"; | ||
import { BitcoinRpc, SwapData } from "crosslightning-base"; | ||
import { FromBtcLnRequestType, FromBtcRequestType, ISwapPrice, MultichainData, RequestData, SwapHandler, ToBtcLnRequestType, ToBtcRequestType } from ".."; | ||
@@ -60,3 +60,3 @@ import { SwapHandlerSwap } from "../swaps/SwapHandlerSwap"; | ||
[chainId: string]: { | ||
address: TokenAddress; | ||
address: string; | ||
decimals: number; | ||
@@ -75,3 +75,3 @@ }; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -86,3 +86,3 @@ maxInBtc: BN; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -97,3 +97,3 @@ maxInBtc: BN; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -108,3 +108,3 @@ maxInBtc: BN; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -111,0 +111,0 @@ maxInBtc: BN; |
@@ -1,2 +0,2 @@ | ||
import { BitcoinRpc, SwapData, TokenAddress } from "crosslightning-base"; | ||
import { BitcoinRpc, SwapData } from "crosslightning-base"; | ||
import { IPlugin, PluginQuote, QuoteAmountTooHigh, QuoteAmountTooLow, QuoteSetFees, QuoteThrow, ToBtcPluginQuote } from "./IPlugin"; | ||
@@ -31,3 +31,3 @@ import { FromBtcLnRequestType, FromBtcRequestType, ISwapPrice, MultichainData, RequestData, SwapHandler, ToBtcLnRequestType, ToBtcRequestType } from ".."; | ||
[chainId: string]: { | ||
address: TokenAddress; | ||
address: string; | ||
decimals: number; | ||
@@ -46,3 +46,3 @@ }; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -57,3 +57,3 @@ maxInBtc: BN; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -70,3 +70,3 @@ maxInBtc: BN; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -84,3 +84,3 @@ maxInBtc: BN; | ||
amount: BN; | ||
}, token: TokenAddress, constraints: { | ||
}, chainIdentifier: string, token: string, constraints: { | ||
minInBtc: BN; | ||
@@ -87,0 +87,0 @@ maxInBtc: BN; |
@@ -126,3 +126,3 @@ "use strict"; | ||
} | ||
static onHandlePostFromBtcQuote(request, requestedAmount, token, constraints, fees, pricePrefetchPromise) { | ||
static onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -132,3 +132,3 @@ for (let plugin of PluginManager.plugins.values()) { | ||
if (plugin.onHandlePostFromBtcQuote != null) { | ||
const result = yield plugin.onHandlePostFromBtcQuote(request, requestedAmount, token, constraints, fees, pricePrefetchPromise); | ||
const result = yield plugin.onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise); | ||
if (result != null) { | ||
@@ -158,3 +158,3 @@ if ((0, IPlugin_1.isQuoteSetFees)(result)) | ||
} | ||
static onHandlePreFromBtcQuote(request, requestedAmount, token, constraints, fees) { | ||
static onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -164,3 +164,3 @@ for (let plugin of PluginManager.plugins.values()) { | ||
if (plugin.onHandlePreFromBtcQuote != null) { | ||
const result = yield plugin.onHandlePreFromBtcQuote(request, requestedAmount, token, constraints, fees); | ||
const result = yield plugin.onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees); | ||
if (result != null) { | ||
@@ -185,3 +185,3 @@ if ((0, IPlugin_1.isQuoteSetFees)(result)) | ||
} | ||
static onHandlePostToBtcQuote(request, requestedAmount, token, constraints, fees, pricePrefetchPromise) { | ||
static onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -192,3 +192,3 @@ for (let plugin of PluginManager.plugins.values()) { | ||
let networkFeeData; | ||
const result = yield plugin.onHandlePostToBtcQuote(request, requestedAmount, token, constraints, { | ||
const result = yield plugin.onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, { | ||
baseFeeInBtc: fees.baseFeeInBtc, | ||
@@ -225,3 +225,3 @@ feePPM: fees.feePPM, | ||
} | ||
static onHandlePreToBtcQuote(request, requestedAmount, token, constraints, fees) { | ||
static onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -231,3 +231,3 @@ for (let plugin of PluginManager.plugins.values()) { | ||
if (plugin.onHandlePreToBtcQuote != null) { | ||
const result = yield plugin.onHandlePreToBtcQuote(request, requestedAmount, token, constraints, fees); | ||
const result = yield plugin.onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees); | ||
if (result != null) { | ||
@@ -234,0 +234,0 @@ if ((0, IPlugin_1.isQuoteSetFees)(result)) |
@@ -59,3 +59,4 @@ "use strict"; | ||
const parsedOutputScript = bitcoin.address.toOutputScript(address, this.config.bitcoinNetwork); | ||
return this.getContract(chainIdentifier).getHashForOnchain(parsedOutputScript, amount, new BN(0)); | ||
const { swapContract } = this.getChain(chainIdentifier); | ||
return swapContract.getHashForOnchain(parsedOutputScript, amount, new BN(0)); | ||
} | ||
@@ -73,3 +74,3 @@ /** | ||
const currentTime = new BN(Math.floor(Date.now() / 1000) - this.config.maxSkew); | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const { swapContract } = this.getChain(swap.chainIdentifier); | ||
//Once authorization expires in CREATED state, the user can no more commit it on-chain | ||
@@ -139,3 +140,3 @@ if (swap.state === FromBtcSwapAbs_1.FromBtcSwapState.CREATED) { | ||
for (let refundSwap of refundSwaps) { | ||
const swapContract = this.getContract(refundSwap.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(refundSwap.chainIdentifier); | ||
const unlock = refundSwap.lock(swapContract.refundTimeout); | ||
@@ -145,3 +146,3 @@ if (unlock == null) | ||
this.swapLogger.debug(refundSwap, "refundSwaps(): initiate refund of swap"); | ||
yield swapContract.refund(refundSwap.data, true, false, true); | ||
yield swapContract.refund(signer, refundSwap.data, true, false, { waitForConfirmation: true }); | ||
this.swapLogger.info(refundSwap, "refundSwaps(): swap refunded, address: " + refundSwap.address); | ||
@@ -161,3 +162,4 @@ //The swap should be removed by the event handler | ||
const swapData = yield event.swapData(); | ||
if (!this.getContract(chainIdentifier).areWeOfferer(swapData)) | ||
const { signer } = this.getChain(chainIdentifier); | ||
if (!swapData.isOfferer(signer.getAddress())) | ||
return; | ||
@@ -244,4 +246,4 @@ //Only process requests that don't pay in from the program | ||
getDummySwapData(chainIdentifier, useToken, address) { | ||
const swapContract = this.getContract(chainIdentifier); | ||
return swapContract.createSwapData(crosslightning_base_1.ChainSwapType.CHAIN, swapContract.getAddress(), address, useToken, null, null, null, null, new BN(0), this.config.confirmations, false, true, null, null); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
return swapContract.createSwapData(crosslightning_base_1.ChainSwapType.CHAIN, signer.getAddress(), address, useToken, null, null, null, null, new BN(0), this.config.confirmations, false, true, null, null); | ||
} | ||
@@ -259,3 +261,3 @@ /** | ||
const chainIdentifier = (_a = req.query.chain) !== null && _a !== void 0 ? _a : this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
metadata.times.requestReceived = Date.now(); | ||
@@ -302,3 +304,3 @@ /** | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
//Check request params | ||
@@ -342,3 +344,3 @@ this.checkSequence(parsedBody.sequence); | ||
//Create swap data | ||
const data = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.CHAIN, swapContract.getAddress(), parsedBody.address, useToken, totalInToken, paymentHash.toString("hex"), parsedBody.sequence, expiry, new BN(0), this.config.confirmations, false, true, totalSecurityDeposit, totalClaimerBounty); | ||
const data = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.CHAIN, signer.getAddress(), parsedBody.address, useToken, totalInToken, paymentHash.toString("hex"), parsedBody.sequence, expiry, new BN(0), this.config.confirmations, false, true, totalSecurityDeposit, totalClaimerBounty); | ||
data.setTxoHash(this.getTxoHash(receiveAddress, amountBD, this.config.bitcoinNetwork).toString("hex")); | ||
@@ -363,3 +365,3 @@ abortController.signal.throwIfAborted(); | ||
btcAddress: receiveAddress, | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
swapFee: swapFeeInToken.toString(10), | ||
@@ -366,0 +368,0 @@ total: totalInToken.toString(10), |
import { SwapHandlerSwap } from "./SwapHandlerSwap"; | ||
import { SwapData, TokenAddress } from "crosslightning-base"; | ||
import { SwapData } from "crosslightning-base"; | ||
import { RequestData, SwapBaseConfig, SwapHandler } from "./SwapHandler"; | ||
@@ -21,3 +21,3 @@ import * as BN from "bn.js"; | ||
*/ | ||
protected getFromBtcPricePrefetches(chainIdentifier: string, useToken: TokenAddress, abortController: AbortController): { | ||
protected getFromBtcPricePrefetches(chainIdentifier: string, useToken: string, abortController: AbortController): { | ||
pricePrefetchPromise: Promise<BN>; | ||
@@ -41,3 +41,3 @@ securityDepositPricePrefetchPromise: Promise<BN>; | ||
*/ | ||
protected getBalancePrefetch(chainIdentifier: string, useToken: TokenAddress, abortController: AbortController): Promise<BN>; | ||
protected getBalancePrefetch(chainIdentifier: string, useToken: string, abortController: AbortController): Promise<BN>; | ||
/** | ||
@@ -63,3 +63,3 @@ * Checks if we have enough balance of the token in the swap vault | ||
amount: BN; | ||
}, useToken: TokenAddress): Promise<{ | ||
}, useToken: string): Promise<{ | ||
baseFee: BN; | ||
@@ -85,3 +85,3 @@ feePPM: BN; | ||
feePPM: BN; | ||
}, useToken: TokenAddress, signal: AbortSignal, pricePrefetchPromise?: Promise<BN>): Promise<{ | ||
}, useToken: string, signal: AbortSignal, pricePrefetchPromise?: Promise<BN>): Promise<{ | ||
amountBD: BN; | ||
@@ -88,0 +88,0 @@ swapFee: BN; |
@@ -33,3 +33,3 @@ "use strict"; | ||
}); | ||
const swapContract = this.getContract(chainIdentifier); | ||
const { swapContract } = this.getChain(chainIdentifier); | ||
const securityDepositPricePrefetchPromise = useToken.toString() === swapContract.getNativeCurrencyAddress().toString() ? | ||
@@ -54,3 +54,3 @@ pricePrefetchPromise : | ||
//Solana workaround | ||
const swapContract = this.getContract(chainIdentifier); | ||
const { swapContract } = this.getChain(chainIdentifier); | ||
if (swapContract.getRawRefundFee != null) { | ||
@@ -88,4 +88,5 @@ try { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
try { | ||
return yield this.getContract(chainIdentifier).getBalance(useToken, true); | ||
return yield swapContract.getBalance(signer.getAddress(), useToken, true); | ||
} | ||
@@ -129,3 +130,3 @@ catch (e) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield PluginManager_1.PluginManager.onHandlePreFromBtcQuote(request, requestedAmount, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: this.config.baseFee, feePPM: this.config.feePPM }); | ||
const res = yield PluginManager_1.PluginManager.onHandlePreFromBtcQuote(request, requestedAmount, request.chainIdentifier, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: this.config.baseFee, feePPM: this.config.feePPM }); | ||
if (res != null) { | ||
@@ -162,3 +163,3 @@ this.handlePluginErrorResponses(res); | ||
const chainIdentifier = request.chainIdentifier; | ||
const res = yield PluginManager_1.PluginManager.onHandlePostFromBtcQuote(request, requestedAmount, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: fees.baseFee, feePPM: fees.feePPM }, pricePrefetchPromise); | ||
const res = yield PluginManager_1.PluginManager.onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: fees.baseFee, feePPM: fees.feePPM }, pricePrefetchPromise); | ||
signal.throwIfAborted(); | ||
@@ -256,3 +257,4 @@ if (res != null) { | ||
metadata.times.refundFeeFetched = Date.now(); | ||
const swapValueInNativeCurrency = yield this.swapPricing.getFromBtcSwapAmount(amountBD.sub(swapFee), this.getContract(chainIdentifier).getNativeCurrencyAddress(), chainIdentifier, true, securityDepositPricePrefetchPromise); | ||
const { swapContract } = this.getChain(chainIdentifier); | ||
const swapValueInNativeCurrency = yield this.swapPricing.getFromBtcSwapAmount(amountBD.sub(swapFee), swapContract.getNativeCurrencyAddress(), chainIdentifier, true, securityDepositPricePrefetchPromise); | ||
signal.throwIfAborted(); | ||
@@ -280,2 +282,3 @@ const apyPPM = new BN(Math.floor(this.config.securityDepositAPY * 1000000)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
const prefetchedSignData = signDataPrefetchPromise != null ? yield signDataPrefetchPromise : null; | ||
@@ -291,3 +294,3 @@ if (prefetchedSignData != null) | ||
this.logger.debug("getFromBtcSignatureData(): using fee rate from client: ", feeRate); | ||
const sigData = yield this.getContract(chainIdentifier).getInitSignature(swapObject, this.config.authorizationTimeout, prefetchedSignData, feeRate); | ||
const sigData = yield swapContract.getInitSignature(signer, swapObject, this.config.authorizationTimeout, prefetchedSignData, feeRate); | ||
abortSignal.throwIfAborted(); | ||
@@ -294,0 +297,0 @@ return sigData; |
@@ -37,3 +37,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const { swapContract } = this.getChain(swap.chainIdentifier); | ||
if (swap.state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.CREATED) { | ||
@@ -73,3 +73,3 @@ //Check if already paid | ||
const parsedPR = bolt11.decode(swap.pr); | ||
const isAuthorizationExpired = yield swapContract.isInitAuthorizationExpired(swap.data, swap.timeout, swap.prefix, swap.signature); | ||
const isAuthorizationExpired = yield swapContract.isInitAuthorizationExpired(swap.data, swap); | ||
if (isAuthorizationExpired) { | ||
@@ -110,3 +110,3 @@ const isCommited = yield swapContract.isCommited(swap.data); | ||
for (let refundSwap of refundSwaps) { | ||
const swapContract = this.getContract(refundSwap.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(refundSwap.chainIdentifier); | ||
const unlock = refundSwap.lock(swapContract.refundTimeout); | ||
@@ -116,3 +116,3 @@ if (unlock == null) | ||
this.swapLogger.debug(refundSwap, "refundSwaps(): initiate refund of swap"); | ||
yield swapContract.refund(refundSwap.data, true, false, true); | ||
yield swapContract.refund(signer, refundSwap.data, true, false, { waitForConfirmation: true }); | ||
this.swapLogger.info(refundSwap, "refundsSwaps(): swap refunded, invoice: " + refundSwap.pr); | ||
@@ -207,4 +207,4 @@ yield refundSwap.setState(FromBtcLnSwapAbs_1.FromBtcLnSwapState.REFUNDED); | ||
const swapData = yield event.swapData(); | ||
const swapContract = this.getContract(chainIdentifier); | ||
if (!swapContract.areWeOfferer(swapData)) | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
if (!swapData.isOfferer(signer.getAddress())) | ||
return; | ||
@@ -300,3 +300,3 @@ if (swapData.isPayIn()) | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.swapLogger.debug(invoiceData, "htlcReceived(): invoice: " + invoice); | ||
this.swapLogger.debug(invoiceData, "htlcReceived(): invoice: ", invoice); | ||
if (invoiceData.metadata != null) | ||
@@ -330,5 +330,5 @@ invoiceData.metadata.times.htlcReceived = Date.now(); | ||
} | ||
const swapContract = this.getContract(invoiceData.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(invoiceData.chainIdentifier); | ||
//Create real swap data | ||
const payInvoiceObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, swapContract.getAddress(), invoiceData.data.getClaimer(), useToken, sendAmount, invoice.id, new BN(0), new BN(Math.floor(Date.now() / 1000)).add(expiryTimeout), new BN(0), 0, false, true, invoiceData.data.getSecurityDeposit(), new BN(0)); | ||
const payInvoiceObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, signer.getAddress(), invoiceData.data.getClaimer(), useToken, sendAmount, invoice.id, new BN(0), new BN(Math.floor(Date.now() / 1000)).add(expiryTimeout), new BN(0), 0, false, true, invoiceData.data.getSecurityDeposit(), new BN(0)); | ||
abortController.signal.throwIfAborted(); | ||
@@ -338,3 +338,3 @@ if (invoiceData.metadata != null) | ||
//Sign swap data | ||
const sigData = yield swapContract.getInitSignature(payInvoiceObject, this.config.authorizationTimeout, signDataPrefetchPromise == null ? null : yield signDataPrefetchPromise, invoiceData.feeRate); | ||
const sigData = yield swapContract.getInitSignature(signer, payInvoiceObject, this.config.authorizationTimeout, signDataPrefetchPromise == null ? null : yield signDataPrefetchPromise, invoiceData.feeRate); | ||
//No need to check abortController anymore since all pending promises are resolved by now | ||
@@ -497,4 +497,4 @@ if (invoiceData.metadata != null) | ||
getDummySwapData(chainIdentifier, useToken, address, paymentHash) { | ||
const swapContract = this.getContract(chainIdentifier); | ||
return swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, swapContract.getAddress(), address, useToken, null, paymentHash, new BN(0), null, null, 0, false, true, null, new BN(0)); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
return swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, signer.getAddress(), address, useToken, null, paymentHash, new BN(0), null, null, 0, false, true, null, new BN(0)); | ||
} | ||
@@ -532,3 +532,4 @@ /** | ||
} | ||
if (!this.getContract(chainIdentifier).isValidAddress(address)) | ||
const { swapContract } = this.getChain(chainIdentifier); | ||
if (!swapContract.isValidAddress(address)) | ||
throw { | ||
@@ -568,3 +569,3 @@ _httpStatus: 200, | ||
const chainIdentifier = (_a = req.query.chain) !== null && _a !== void 0 ? _a : this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
metadata.times.requestReceived = Date.now(); | ||
@@ -611,3 +612,3 @@ /** | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
//Check request params | ||
@@ -657,3 +658,3 @@ this.checkDescriptionHash(parsedBody.descriptionHash); | ||
//Create swap data | ||
createdSwap.data = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, swapContract.getAddress(), parsedBody.address, useToken, totalInToken, parsedBody.paymentHash, new BN(0), null, null, 0, false, true, totalSecurityDeposit, new BN(0)); | ||
createdSwap.data = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, signer.getAddress(), parsedBody.address, useToken, totalInToken, parsedBody.paymentHash, new BN(0), null, null, 0, false, true, totalSecurityDeposit, new BN(0)); | ||
abortController.signal.throwIfAborted(); | ||
@@ -678,3 +679,3 @@ metadata.times.swapCreated = Date.now(); | ||
total: totalInToken.toString(10), | ||
intermediaryKey: swapContract.getAddress(), | ||
intermediaryKey: signer.getAddress(), | ||
securityDeposit: totalSecurityDeposit.toString(10) | ||
@@ -720,5 +721,5 @@ } | ||
}; | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(swap.chainIdentifier); | ||
if (swap.state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.RECEIVED) { | ||
if (yield swapContract.isInitAuthorizationExpired(swap.data, swap.timeout, swap.prefix, swap.signature)) | ||
if (yield swapContract.isInitAuthorizationExpired(swap.data, swap)) | ||
throw { | ||
@@ -757,3 +758,3 @@ _httpStatus: 200, | ||
data: { | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
data: swap.serialize().data, | ||
@@ -760,0 +761,0 @@ nonce: swap.nonce, |
import * as BN from "bn.js"; | ||
import { TokenAddress } from "crosslightning-base"; | ||
export type ISwapPriceCoinsMap<T extends { | ||
@@ -23,4 +22,4 @@ decimals: number; | ||
protected abstract getPrice(tokenData: T): Promise<BN>; | ||
getTokenData(tokenAddress: TokenAddress, chainId: string): T; | ||
preFetchPrice(token: TokenAddress, chainId: string): Promise<BN>; | ||
getTokenData(tokenAddress: string, chainId: string): T; | ||
preFetchPrice(token: string, chainId: string): Promise<BN>; | ||
/** | ||
@@ -35,3 +34,3 @@ * Returns amount of satoshis that are equivalent to {fromAmount} of {fromToken} | ||
*/ | ||
getToBtcSwapAmount(fromAmount: BN, fromToken: TokenAddress, tokenChainIdentification: string, roundUp?: boolean, preFetch?: Promise<BN>): Promise<BN>; | ||
getToBtcSwapAmount(fromAmount: BN, fromToken: string, tokenChainIdentification: string, roundUp?: boolean, preFetch?: Promise<BN>): Promise<BN>; | ||
/** | ||
@@ -46,3 +45,3 @@ * Returns amount of {toToken} that are equivalent to {fromAmount} satoshis | ||
*/ | ||
getFromBtcSwapAmount(fromAmount: BN, toToken: TokenAddress, tokenChainIdentification: string, roundUp?: boolean, preFetch?: Promise<BN>): Promise<BN>; | ||
getFromBtcSwapAmount(fromAmount: BN, toToken: string, tokenChainIdentification: string, roundUp?: boolean, preFetch?: Promise<BN>): Promise<BN>; | ||
} |
import { Express, Request } from "express"; | ||
import { ISwapPrice } from "./ISwapPrice"; | ||
import { BtcRelay, ChainEvents, ClaimEvent, InitializeEvent, RefundEvent, SwapContract, SwapData, SwapEvent } from "crosslightning-base"; | ||
import { ChainType, ClaimEvent, InitializeEvent, RefundEvent, SwapData, SwapEvent } from "crosslightning-base"; | ||
import { AuthenticatedLnd } from "lightning"; | ||
@@ -44,7 +44,8 @@ import { SwapHandlerSwap } from "./SwapHandlerSwap"; | ||
}; | ||
export type ChainData<T extends SwapData = SwapData> = { | ||
swapContract: SwapContract<T, any, any, any>; | ||
chainEvents: ChainEvents<T>; | ||
export type ChainData<T extends ChainType = ChainType> = { | ||
signer: T["Signer"]; | ||
swapContract: T["Contract"]; | ||
chainEvents: T["Events"]; | ||
allowedTokens: string[]; | ||
btcRelay?: BtcRelay<any, any, any>; | ||
btcRelay?: T["BtcRelay"]; | ||
}; | ||
@@ -88,3 +89,2 @@ export type RequestData<T> = { | ||
protected getChain(identifier: string): ChainData; | ||
protected getContract(identifier: string): SwapContract<any, any, any, any>; | ||
protected abstract processPastSwaps(): Promise<void>; | ||
@@ -91,0 +91,0 @@ /** |
@@ -58,5 +58,2 @@ "use strict"; | ||
getChain(identifier) { | ||
return this.chains.chains[identifier]; | ||
} | ||
getContract(identifier) { | ||
if (this.chains.chains[identifier] == null) | ||
@@ -67,3 +64,3 @@ throw { | ||
}; | ||
return this.chains.chains[identifier].swapContract; | ||
return this.chains.chains[identifier]; | ||
} | ||
@@ -216,3 +213,4 @@ /** | ||
getSignDataPrefetch(chainIdentifier, abortController, responseStream) { | ||
let signDataPrefetchPromise = this.getContract(chainIdentifier).preFetchBlockDataForSignatures != null ? this.getContract(chainIdentifier).preFetchBlockDataForSignatures().catch(e => { | ||
const { swapContract } = this.getChain(chainIdentifier); | ||
let signDataPrefetchPromise = swapContract.preFetchBlockDataForSignatures != null ? swapContract.preFetchBlockDataForSignatures().catch(e => { | ||
this.logger.error("getSignDataPrefetch(): signDataPrefetch: ", e); | ||
@@ -219,0 +217,0 @@ abortController.abort(e); |
@@ -62,3 +62,4 @@ "use strict"; | ||
const parsedOutputScript = bitcoin.address.toOutputScript(address, bitcoinNetwork); | ||
return this.getContract(chainIdentifier).getHashForOnchain(parsedOutputScript, amount, nonce); | ||
const { swapContract } = this.getChain(chainIdentifier); | ||
return swapContract.getHashForOnchain(parsedOutputScript, amount, nonce); | ||
} | ||
@@ -245,3 +246,3 @@ /** | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(swap.chainIdentifier); | ||
const blockHeader = yield this.bitcoinRpc.getBlockHeader(tx.blockhash); | ||
@@ -254,3 +255,5 @@ //Set flag that we are sending the transaction already, so we don't end up with race condition | ||
this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout); | ||
const result = yield swapContract.claimWithTxData(swap.data, blockHeader.getHeight(), tx, vout, null, null, false, true); | ||
const result = yield swapContract.claimWithTxData(signer, swap.data, blockHeader.getHeight(), tx, vout, null, null, false, { | ||
waitForConfirmation: true | ||
}); | ||
this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout + " address: " + swap.address); | ||
@@ -270,3 +273,3 @@ if (swap.metadata != null) | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(swap.chainIdentifier); | ||
const timestamp = new BN(Math.floor(Date.now() / 1000)).sub(new BN(this.config.maxSkew)); | ||
@@ -301,3 +304,3 @@ if (swap.state === ToBtcSwapAbs_1.ToBtcSwapState.SAVED && swap.signatureExpiry != null) { | ||
if (!isCommited) { | ||
const status = yield swapContract.getCommitStatus(swap.data); | ||
const status = yield swapContract.getCommitStatus(signer.getAddress(), swap.data); | ||
if (status === crosslightning_base_1.SwapCommitStatus.PAID) { | ||
@@ -841,3 +844,3 @@ this.swapLogger.info(swap, "processPastSwap(state=BTC_SENT): swap claimed (detected from processPastSwap), address: " + swap.address); | ||
const chainIdentifier = (_a = req.query.chain) !== null && _a !== void 0 ? _a : this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
metadata.times.requestReceived = Date.now(); | ||
@@ -885,3 +888,3 @@ /** | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
const responseStream = res.responseStream; | ||
@@ -911,3 +914,3 @@ this.checkNonceValid(parsedBody.nonce); | ||
const sequence = new BN((0, crypto_1.randomBytes)(8)); | ||
const payObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.CHAIN_NONCED, parsedBody.offerer, swapContract.getAddress(), useToken, totalInToken, paymentHash, sequence, minRequiredExpiry, parsedBody.nonce, parsedBody.confirmations, true, false, new BN(0), new BN(0)); | ||
const payObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.CHAIN_NONCED, parsedBody.offerer, signer.getAddress(), useToken, totalInToken, paymentHash, sequence, minRequiredExpiry, parsedBody.nonce, parsedBody.confirmations, true, false, new BN(0), new BN(0)); | ||
abortController.signal.throwIfAborted(); | ||
@@ -928,3 +931,3 @@ metadata.times.swapCreated = Date.now(); | ||
amount: amountBD.toString(10), | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
satsPervByte: networkFeeData.satsPerVbyte.toString(10), | ||
@@ -968,3 +971,3 @@ networkFee: networkFeeInToken.toString(10), | ||
}; | ||
const swapContract = this.getContract(payment.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(payment.chainIdentifier); | ||
this.checkExpired(payment); | ||
@@ -993,3 +996,3 @@ if (payment.state === ToBtcSwapAbs_1.ToBtcSwapState.COMMITED) | ||
}; | ||
const refundResponse = yield swapContract.getRefundSignature(payment.data, this.config.authorizationTimeout); | ||
const refundResponse = yield swapContract.getRefundSignature(signer, payment.data, this.config.authorizationTimeout); | ||
//Double check the state after promise result | ||
@@ -1006,3 +1009,3 @@ if (payment.state !== ToBtcSwapAbs_1.ToBtcSwapState.NON_PAYABLE) | ||
data: { | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
prefix: refundResponse.prefix, | ||
@@ -1009,0 +1012,0 @@ timeout: refundResponse.timeout, |
import { RequestData, SwapBaseConfig, SwapHandler } from "./SwapHandler"; | ||
import { SwapHandlerSwap } from "./SwapHandlerSwap"; | ||
import { SwapData, TokenAddress } from "crosslightning-base"; | ||
import { SwapData } from "crosslightning-base"; | ||
import * as BN from "bn.js"; | ||
@@ -32,3 +32,3 @@ import { ServerParamEncoder } from "../utils/paramcoders/server/ServerParamEncoder"; | ||
amount: BN; | ||
}, useToken: TokenAddress): Promise<{ | ||
}, useToken: string): Promise<{ | ||
baseFee: BN; | ||
@@ -58,3 +58,3 @@ feePPM: BN; | ||
feePPM: BN; | ||
}, useToken: TokenAddress, getNetworkFee: (amount: BN) => Promise<T>, signal: AbortSignal, pricePrefetchPromise?: Promise<BN>): Promise<{ | ||
}, useToken: string, getNetworkFee: (amount: BN) => Promise<T>, signal: AbortSignal, pricePrefetchPromise?: Promise<BN>): Promise<{ | ||
amountBD: BN; | ||
@@ -76,3 +76,3 @@ networkFeeData: T; | ||
*/ | ||
protected getToBtcPrefetches(chainIdentifier: string, token: TokenAddress, responseStream: ServerParamEncoder, abortController: AbortController): { | ||
protected getToBtcPrefetches(chainIdentifier: string, token: string, responseStream: ServerParamEncoder, abortController: AbortController): { | ||
pricePrefetchPromise?: Promise<BN>; | ||
@@ -79,0 +79,0 @@ signDataPrefetchPromise?: Promise<any>; |
@@ -27,4 +27,4 @@ "use strict"; | ||
this.logger.debug("checkVaultInitialized(): checking vault exists for chain: " + chainIdentifier + " token: " + token); | ||
const swapContract = this.getContract(chainIdentifier); | ||
const reputation = yield swapContract.getIntermediaryReputation(swapContract.getAddress(), swapContract.toTokenAddress(token)); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
const reputation = yield swapContract.getIntermediaryReputation(signer.getAddress(), token); | ||
this.logger.debug("checkVaultInitialized(): vault state, chain: " + chainIdentifier + " token: " + token + " exists: " + (reputation != null)); | ||
@@ -55,3 +55,3 @@ if (reputation != null) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield PluginManager_1.PluginManager.onHandlePreToBtcQuote(request, requestedAmount, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: this.config.baseFee, feePPM: this.config.feePPM }); | ||
const res = yield PluginManager_1.PluginManager.onHandlePreToBtcQuote(request, requestedAmount, request.chainIdentifier, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: this.config.baseFee, feePPM: this.config.feePPM }); | ||
if (res != null) { | ||
@@ -91,3 +91,3 @@ this.handlePluginErrorResponses(res); | ||
const chainIdentifier = request.chainIdentifier; | ||
const res = yield PluginManager_1.PluginManager.onHandlePostToBtcQuote(request, requestedAmount, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: fees.baseFee, feePPM: fees.feePPM, networkFeeGetter: getNetworkFee }, pricePrefetchPromise); | ||
const res = yield PluginManager_1.PluginManager.onHandlePostToBtcQuote(request, requestedAmount, request.chainIdentifier, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: fees.baseFee, feePPM: fees.feePPM, networkFeeGetter: getNetworkFee }, pricePrefetchPromise); | ||
signal.throwIfAborted(); | ||
@@ -229,3 +229,4 @@ if (res != null) { | ||
this.logger.debug("getToBtcSignatureData(): using fee rate from client: ", feeRate); | ||
const sigData = yield this.getContract(chainIdentifier).getClaimInitSignature(swapObject, this.config.authorizationTimeout, prefetchedSignData, feeRate); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
const sigData = yield swapContract.getInitSignature(signer, swapObject, this.config.authorizationTimeout, prefetchedSignData, feeRate); | ||
abortSignal.throwIfAborted(); | ||
@@ -232,0 +233,0 @@ return sigData; |
@@ -6,3 +6,3 @@ import * as BN from "bn.js"; | ||
import { ISwapPrice } from "../ISwapPrice"; | ||
import { ClaimEvent, InitializeEvent, RefundEvent, SwapData, TokenAddress } from "crosslightning-base"; | ||
import { ClaimEvent, InitializeEvent, RefundEvent, SwapData } from "crosslightning-base"; | ||
import { AuthenticatedLnd } from "lightning"; | ||
@@ -41,3 +41,3 @@ import { IIntermediaryStorage } from "../../storage/IIntermediaryStorage"; | ||
swapFee: BN; | ||
token: TokenAddress; | ||
token: string; | ||
swapExpiry: BN; | ||
@@ -44,0 +44,0 @@ offerer: string; |
@@ -182,3 +182,3 @@ "use strict"; | ||
throw new Error("Invalid swap state, needs payment pre-image!"); | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(swap.chainIdentifier); | ||
//Set flag that we are sending the transaction already, so we don't end up with race condition | ||
@@ -190,3 +190,5 @@ const unlock = swap.lock(swapContract.claimWithSecretTimeout); | ||
this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, secret: " + swap.secret); | ||
const success = yield swapContract.claimWithSecret(swap.data, swap.secret, false, false, true); | ||
const success = yield swapContract.claimWithSecret(signer, swap.data, swap.secret, false, false, { | ||
waitForConfirmation: true | ||
}); | ||
this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, secret: " + swap.secret + " invoice: " + swap.pr); | ||
@@ -221,3 +223,3 @@ if (swap.metadata != null) | ||
} | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(swap.chainIdentifier); | ||
if (lnPaymentStatus.is_confirmed) { | ||
@@ -233,3 +235,3 @@ //Save pre-image & real network fee | ||
if (!isCommited) { | ||
const status = yield swapContract.getCommitStatus(swap.data); | ||
const status = yield swapContract.getCommitStatus(signer.getAddress(), swap.data); | ||
if (status === crosslightning_base_1.SwapCommitStatus.PAID) { | ||
@@ -740,5 +742,5 @@ //This is alright, we got the money | ||
const sequence = new BN((0, crypto_1.randomBytes)(8)); | ||
const swapContract = this.getContract(parsedAuth.chainIdentifier); | ||
const { swapContract, signer } = this.getChain(parsedAuth.chainIdentifier); | ||
//Create swap data | ||
const payObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, parsedAuth.offerer, swapContract.getAddress(), swapContract.toTokenAddress(parsedAuth.token), parsedAuth.total, parsedPR.tagsObject.payment_hash, sequence, parsedAuth.swapExpiry, new BN(0), 0, true, false, new BN(0), new BN(0)); | ||
const payObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, parsedAuth.offerer, signer.getAddress(), parsedAuth.token, parsedAuth.total, parsedPR.tagsObject.payment_hash, sequence, parsedAuth.swapExpiry, new BN(0), 0, true, false, new BN(0), new BN(0)); | ||
metadata.times.swapCreated = Date.now(); | ||
@@ -767,3 +769,3 @@ //Sign swap data | ||
confidence: halfConfidence ? parsedAuth.confidence / 2000000 : parsedAuth.confidence / 1000000, | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
routingFeeSats: parsedAuth.quotedNetworkFee.toString(10), | ||
@@ -782,3 +784,3 @@ data: payObject.serialize(), | ||
const chainIdentifier = (_a = req.query.chain) !== null && _a !== void 0 ? _a : this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const { swapContract, signer } = this.getChain(chainIdentifier); | ||
metadata.times.requestReceived = Date.now(); | ||
@@ -824,3 +826,3 @@ /** | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
const responseStream = res.responseStream; | ||
@@ -897,3 +899,3 @@ const currentTimestamp = new BN(Math.floor(Date.now() / 1000)); | ||
//Create swap data | ||
const payObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, parsedBody.offerer, swapContract.getAddress(), useToken, totalInToken, parsedPR.tagsObject.payment_hash, sequence, parsedBody.expiryTimestamp, new BN(0), 0, true, false, new BN(0), new BN(0)); | ||
const payObject = yield swapContract.createSwapData(crosslightning_base_1.ChainSwapType.HTLC, parsedBody.offerer, signer.getAddress(), useToken, totalInToken, parsedPR.tagsObject.payment_hash, sequence, parsedBody.expiryTimestamp, new BN(0), 0, true, false, new BN(0), new BN(0)); | ||
abortController.signal.throwIfAborted(); | ||
@@ -921,3 +923,3 @@ metadata.times.swapCreated = Date.now(); | ||
confidence: halfConfidence ? networkFeeData.confidence / 2000000 : networkFeeData.confidence / 1000000, | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
routingFeeSats: networkFeeData.networkFee.toString(10), | ||
@@ -959,5 +961,5 @@ data: payObject.serialize(), | ||
}; | ||
const swapContract = this.getContract(data.chainIdentifier); | ||
const { signer, swapContract } = this.getChain(data.chainIdentifier); | ||
if (data.state === ToBtcLnSwapAbs_1.ToBtcLnSwapState.NON_PAYABLE) { | ||
const refundSigData = yield swapContract.getRefundSignature(data.data, this.config.authorizationTimeout); | ||
const refundSigData = yield swapContract.getRefundSignature(signer, data.data, this.config.authorizationTimeout); | ||
//Double check the state after promise result | ||
@@ -974,3 +976,3 @@ if (data.state !== ToBtcLnSwapAbs_1.ToBtcLnSwapState.NON_PAYABLE) | ||
data: { | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
prefix: refundSigData.prefix, | ||
@@ -977,0 +979,0 @@ timeout: refundSigData.timeout, |
{ | ||
"name": "crosslightning-intermediary", | ||
"version": "10.1.0-beta9", | ||
"version": "10.2.0", | ||
"description": "Main functionality implementation for intermediary node, easily extensible to any chain", | ||
@@ -29,4 +29,4 @@ "main": "./dist/index.js", | ||
"bolt11": "1.4.1", | ||
"crosslightning-base": "6.0.3", | ||
"crosslightning-server-base": "1.0.2", | ||
"crosslightning-base": "7.1.0", | ||
"crosslightning-server-base": "1.0.3", | ||
"express": "4.18.2", | ||
@@ -33,0 +33,0 @@ "lightning": "10.2.1", |
@@ -1,2 +0,1 @@ | ||
import {SwapContract, SwapData} from "crosslightning-base"; | ||
import {Express} from "express"; | ||
@@ -87,4 +86,4 @@ import {MultichainData, SwapHandler, SwapHandlerInfoType, SwapHandlerType} from "../swaps/SwapHandler"; | ||
chains[chainIdentifier] = { | ||
address: singleChain.swapContract.getAddress(), | ||
signature: await singleChain.swapContract.getDataSignature(envelopeBuffer) | ||
address: singleChain.signer.getAddress(), | ||
signature: await singleChain.swapContract.getDataSignature(singleChain.signer, envelopeBuffer) | ||
}; | ||
@@ -91,0 +90,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import {BitcoinRpc, SwapData, TokenAddress} from "crosslightning-base"; | ||
import {BitcoinRpc, SwapData} from "crosslightning-base"; | ||
import { | ||
@@ -92,3 +92,3 @@ FromBtcLnRequestType, | ||
[chainId: string]: { | ||
address: TokenAddress, | ||
address: string, | ||
decimals: number | ||
@@ -115,3 +115,4 @@ } | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -123,3 +124,4 @@ fees: {baseFeeInBtc: BN, feePPM: BN} | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -133,3 +135,4 @@ fees: {baseFeeInBtc: BN, feePPM: BN}, | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -141,3 +144,4 @@ fees: {baseFeeInBtc: BN, feePPM: BN} | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -144,0 +148,0 @@ fees: {baseFeeInBtc: BN, feePPM: BN, networkFeeGetter: (amount: BN) => Promise<BN>}, |
@@ -1,2 +0,2 @@ | ||
import {BitcoinRpc, SwapData, TokenAddress} from "crosslightning-base"; | ||
import {BitcoinRpc, SwapData} from "crosslightning-base"; | ||
import { | ||
@@ -75,3 +75,3 @@ IPlugin, isPluginQuote, isQuoteAmountTooHigh, isQuoteAmountTooLow, isQuoteSetFees, | ||
[chainId: string]: { | ||
address: TokenAddress, | ||
address: string, | ||
decimals: number | ||
@@ -169,3 +169,4 @@ } | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -178,3 +179,3 @@ fees: {baseFeeInBtc: BN, feePPM: BN}, | ||
if(plugin.onHandlePostFromBtcQuote!=null) { | ||
const result = await plugin.onHandlePostFromBtcQuote(request, requestedAmount, token, constraints, fees, pricePrefetchPromise); | ||
const result = await plugin.onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise); | ||
if(result!=null) { | ||
@@ -201,3 +202,4 @@ if(isQuoteSetFees(result)) return result; | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -209,3 +211,3 @@ fees: {baseFeeInBtc: BN, feePPM: BN} | ||
if(plugin.onHandlePreFromBtcQuote!=null) { | ||
const result = await plugin.onHandlePreFromBtcQuote(request, requestedAmount, token, constraints, fees); | ||
const result = await plugin.onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees); | ||
if(result!=null) { | ||
@@ -228,3 +230,4 @@ if(isQuoteSetFees(result)) return result; | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -238,3 +241,3 @@ fees: {baseFeeInBtc: BN, feePPM: BN, networkFeeGetter: (amount: BN) => Promise<T>}, | ||
let networkFeeData: T; | ||
const result = await plugin.onHandlePostToBtcQuote(request, requestedAmount, token, constraints, { | ||
const result = await plugin.onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, { | ||
baseFeeInBtc: fees.baseFeeInBtc, | ||
@@ -271,3 +274,4 @@ feePPM: fees.feePPM, | ||
requestedAmount: {input: boolean, amount: BN}, | ||
token: TokenAddress, | ||
chainIdentifier: string, | ||
token: string, | ||
constraints: {minInBtc: BN, maxInBtc: BN}, | ||
@@ -279,3 +283,3 @@ fees: {baseFeeInBtc: BN, feePPM: BN} | ||
if(plugin.onHandlePreToBtcQuote!=null) { | ||
const result = await plugin.onHandlePreToBtcQuote(request, requestedAmount, token, constraints, fees); | ||
const result = await plugin.onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees); | ||
if(result!=null) { | ||
@@ -282,0 +286,0 @@ if(isQuoteSetFees(result)) return result; |
@@ -12,4 +12,3 @@ import * as BN from "bn.js"; | ||
RefundEvent, | ||
SwapData, | ||
TokenAddress | ||
SwapData | ||
} from "crosslightning-base"; | ||
@@ -90,3 +89,4 @@ import {AuthenticatedLnd} from "lightning"; | ||
const parsedOutputScript = bitcoin.address.toOutputScript(address, this.config.bitcoinNetwork); | ||
return this.getContract(chainIdentifier).getHashForOnchain(parsedOutputScript, amount, new BN(0)); | ||
const {swapContract} = this.getChain(chainIdentifier); | ||
return swapContract.getHashForOnchain(parsedOutputScript, amount, new BN(0)); | ||
} | ||
@@ -105,3 +105,3 @@ | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const {swapContract} = this.getChain(swap.chainIdentifier); | ||
@@ -176,7 +176,7 @@ //Once authorization expires in CREATED state, the user can no more commit it on-chain | ||
for(let refundSwap of refundSwaps) { | ||
const swapContract = this.getContract(refundSwap.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(refundSwap.chainIdentifier); | ||
const unlock = refundSwap.lock(swapContract.refundTimeout); | ||
if(unlock==null) continue; | ||
this.swapLogger.debug(refundSwap, "refundSwaps(): initiate refund of swap"); | ||
await swapContract.refund(refundSwap.data, true, false, true); | ||
await swapContract.refund(signer, refundSwap.data, true, false, {waitForConfirmation: true}); | ||
this.swapLogger.info(refundSwap, "refundSwaps(): swap refunded, address: "+refundSwap.address); | ||
@@ -195,3 +195,5 @@ //The swap should be removed by the event handler | ||
if (!this.getContract(chainIdentifier).areWeOfferer(swapData)) return; | ||
const {signer} = this.getChain(chainIdentifier); | ||
if (!swapData.isOfferer(signer.getAddress())) return; | ||
//Only process requests that don't pay in from the program | ||
@@ -277,7 +279,7 @@ if (swapData.isPayIn()) return; | ||
private getDummySwapData(chainIdentifier: string, useToken: TokenAddress, address: string): Promise<SwapData> { | ||
const swapContract = this.getContract(chainIdentifier); | ||
private getDummySwapData(chainIdentifier: string, useToken: string, address: string): Promise<SwapData> { | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
return swapContract.createSwapData( | ||
ChainSwapType.CHAIN, | ||
swapContract.getAddress(), | ||
signer.getAddress(), | ||
address, | ||
@@ -313,3 +315,3 @@ useToken, | ||
const chainIdentifier = req.query.chain as string ?? this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
@@ -357,3 +359,3 @@ metadata.times.requestReceived = Date.now(); | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
@@ -419,3 +421,3 @@ //Check request params | ||
ChainSwapType.CHAIN, | ||
swapContract.getAddress(), | ||
signer.getAddress(), | ||
parsedBody.address, | ||
@@ -458,3 +460,3 @@ useToken, | ||
btcAddress: receiveAddress, | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
swapFee: swapFeeInToken.toString(10), | ||
@@ -461,0 +463,0 @@ total: totalInToken.toString(10), |
import {SwapHandlerSwap} from "./SwapHandlerSwap"; | ||
import {SwapData, TokenAddress} from "crosslightning-base"; | ||
import {SwapData} from "crosslightning-base"; | ||
import {RequestData, SwapBaseConfig, SwapHandler} from "./SwapHandler"; | ||
@@ -33,3 +33,3 @@ import * as BN from "bn.js"; | ||
*/ | ||
protected getFromBtcPricePrefetches(chainIdentifier: string, useToken: TokenAddress, abortController: AbortController): { | ||
protected getFromBtcPricePrefetches(chainIdentifier: string, useToken: string, abortController: AbortController): { | ||
pricePrefetchPromise: Promise<BN>, | ||
@@ -43,3 +43,3 @@ securityDepositPricePrefetchPromise: Promise<BN> | ||
}); | ||
const swapContract = this.getContract(chainIdentifier); | ||
const {swapContract} = this.getChain(chainIdentifier); | ||
const securityDepositPricePrefetchPromise: Promise<BN> = useToken.toString()===swapContract.getNativeCurrencyAddress().toString() ? | ||
@@ -65,6 +65,6 @@ pricePrefetchPromise : | ||
//Solana workaround | ||
const swapContract = this.getContract(chainIdentifier); | ||
if ((swapContract as any).getRawRefundFee != null) { | ||
const {swapContract} = this.getChain(chainIdentifier); | ||
if (swapContract.getRawRefundFee != null) { | ||
try { | ||
return await (swapContract as any).getRawRefundFee(dummySwapData); | ||
return await swapContract.getRawRefundFee(dummySwapData); | ||
} catch (e) { | ||
@@ -94,5 +94,6 @@ this.logger.error("getBaseSecurityDepositPrefetch(): pre-fetch error: ", e); | ||
*/ | ||
protected async getBalancePrefetch(chainIdentifier: string, useToken: TokenAddress, abortController: AbortController): Promise<BN> { | ||
protected async getBalancePrefetch(chainIdentifier: string, useToken: string, abortController: AbortController): Promise<BN> { | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
try { | ||
return await this.getContract(chainIdentifier).getBalance(useToken, true); | ||
return await swapContract.getBalance(signer.getAddress(), useToken, true); | ||
} catch (e) { | ||
@@ -137,3 +138,3 @@ this.logger.error("getBalancePrefetch(): balancePrefetch error: ", e); | ||
requestedAmount: {input: boolean, amount: BN}, | ||
useToken: TokenAddress | ||
useToken: string | ||
): Promise<{baseFee: BN, feePPM: BN}> { | ||
@@ -143,2 +144,3 @@ const res = await PluginManager.onHandlePreFromBtcQuote( | ||
requestedAmount, | ||
request.chainIdentifier, | ||
useToken, | ||
@@ -179,3 +181,3 @@ {minInBtc: this.config.min, maxInBtc: this.config.max}, | ||
fees: {baseFee: BN, feePPM: BN}, | ||
useToken: TokenAddress, | ||
useToken: string, | ||
signal: AbortSignal, | ||
@@ -194,2 +196,3 @@ pricePrefetchPromise: Promise<BN> = Promise.resolve(null) | ||
requestedAmount, | ||
chainIdentifier, | ||
useToken, | ||
@@ -308,5 +311,7 @@ {minInBtc: this.config.min, maxInBtc: this.config.max}, | ||
const {swapContract} = this.getChain(chainIdentifier); | ||
const swapValueInNativeCurrency = await this.swapPricing.getFromBtcSwapAmount( | ||
amountBD.sub(swapFee), | ||
this.getContract(chainIdentifier).getNativeCurrencyAddress(), | ||
swapContract.getNativeCurrencyAddress(), | ||
chainIdentifier, | ||
@@ -353,2 +358,4 @@ true, | ||
}> { | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
const prefetchedSignData = signDataPrefetchPromise!=null ? await signDataPrefetchPromise : null; | ||
@@ -365,3 +372,4 @@ if(prefetchedSignData!=null) this.logger.debug("getFromBtcSignatureData(): pre-fetched signature data: ", prefetchedSignData); | ||
this.logger.debug("getFromBtcSignatureData(): using fee rate from client: ", feeRate); | ||
const sigData = await this.getContract(chainIdentifier).getInitSignature( | ||
const sigData = await swapContract.getInitSignature( | ||
signer, | ||
swapObject, | ||
@@ -368,0 +376,0 @@ this.config.authorizationTimeout, |
@@ -14,4 +14,3 @@ import * as BN from "bn.js"; | ||
RefundEvent, | ||
SwapData, | ||
TokenAddress | ||
SwapData | ||
} from "crosslightning-base"; | ||
@@ -66,3 +65,3 @@ import {AuthenticatedLnd} from "lightning"; | ||
protected async processPastSwap(swap: FromBtcLnSwapAbs): Promise<"REFUND" | "SETTLE" | "CANCEL" | null> { | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const {swapContract} = this.getChain(swap.chainIdentifier); | ||
if(swap.state===FromBtcLnSwapState.CREATED) { | ||
@@ -107,3 +106,3 @@ //Check if already paid | ||
const isAuthorizationExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap.timeout, swap.prefix, swap.signature); | ||
const isAuthorizationExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap); | ||
if(isAuthorizationExpired) { | ||
@@ -147,3 +146,3 @@ const isCommited = await swapContract.isCommited(swap.data); | ||
for(let refundSwap of refundSwaps) { | ||
const swapContract = this.getContract(refundSwap.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(refundSwap.chainIdentifier); | ||
const unlock = refundSwap.lock(swapContract.refundTimeout); | ||
@@ -153,3 +152,3 @@ if(unlock==null) continue; | ||
this.swapLogger.debug(refundSwap, "refundSwaps(): initiate refund of swap"); | ||
await swapContract.refund(refundSwap.data, true, false, true); | ||
await swapContract.refund(signer, refundSwap.data, true, false, {waitForConfirmation: true}); | ||
this.swapLogger.info(refundSwap, "refundsSwaps(): swap refunded, invoice: "+refundSwap.pr); | ||
@@ -243,4 +242,4 @@ | ||
const swapContract = this.getContract(chainIdentifier); | ||
if (!swapContract.areWeOfferer(swapData)) return; | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
if (!swapData.isOfferer(signer.getAddress())) return; | ||
if (swapData.isPayIn()) return; | ||
@@ -333,6 +332,6 @@ | ||
private async htlcReceived(invoiceData: FromBtcLnSwapAbs, invoice: any) { | ||
this.swapLogger.debug(invoiceData, "htlcReceived(): invoice: "+invoice); | ||
this.swapLogger.debug(invoiceData, "htlcReceived(): invoice: ", invoice); | ||
if(invoiceData.metadata!=null) invoiceData.metadata.times.htlcReceived = Date.now(); | ||
const useToken: TokenAddress = invoiceData.data.getToken(); | ||
const useToken = invoiceData.data.getToken(); | ||
const sendAmount: BN = invoiceData.data.getAmount(); | ||
@@ -364,3 +363,3 @@ | ||
const swapContract = this.getContract(invoiceData.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(invoiceData.chainIdentifier); | ||
@@ -370,3 +369,3 @@ //Create real swap data | ||
ChainSwapType.HTLC, | ||
swapContract.getAddress(), | ||
signer.getAddress(), | ||
invoiceData.data.getClaimer(), | ||
@@ -390,2 +389,3 @@ useToken, | ||
const sigData = await swapContract.getInitSignature( | ||
signer, | ||
payInvoiceObject, | ||
@@ -557,7 +557,7 @@ this.config.authorizationTimeout, | ||
private getDummySwapData(chainIdentifier: string, useToken: TokenAddress, address: string, paymentHash: string) { | ||
const swapContract = this.getContract(chainIdentifier); | ||
private getDummySwapData(chainIdentifier: string, useToken: string, address: string, paymentHash: string) { | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
return swapContract.createSwapData( | ||
ChainSwapType.HTLC, | ||
swapContract.getAddress(), | ||
signer.getAddress(), | ||
address, | ||
@@ -607,3 +607,4 @@ useToken, | ||
} | ||
if(!this.getContract(chainIdentifier).isValidAddress(address)) throw { | ||
const {swapContract} = this.getChain(chainIdentifier); | ||
if(!swapContract.isValidAddress(address)) throw { | ||
_httpStatus: 200, | ||
@@ -648,3 +649,3 @@ code: 10001, | ||
const chainIdentifier = req.query.chain as string ?? this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
@@ -694,3 +695,3 @@ metadata.times.requestReceived = Date.now(); | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
@@ -763,3 +764,3 @@ //Check request params | ||
ChainSwapType.HTLC, | ||
swapContract.getAddress(), | ||
signer.getAddress(), | ||
parsedBody.address, | ||
@@ -802,3 +803,3 @@ useToken, | ||
total: totalInToken.toString(10), | ||
intermediaryKey: swapContract.getAddress(), | ||
intermediaryKey: signer.getAddress(), | ||
securityDeposit: totalSecurityDeposit.toString(10) | ||
@@ -853,6 +854,6 @@ } | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(swap.chainIdentifier); | ||
if (swap.state === FromBtcLnSwapState.RECEIVED) { | ||
if (await swapContract.isInitAuthorizationExpired(swap.data, swap.timeout, swap.prefix, swap.signature)) throw { | ||
if (await swapContract.isInitAuthorizationExpired(swap.data, swap)) throw { | ||
_httpStatus: 200, | ||
@@ -890,3 +891,3 @@ code: 10001, | ||
data: { | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
data: swap.serialize().data, | ||
@@ -893,0 +894,0 @@ nonce: swap.nonce, |
import * as BN from "bn.js"; | ||
import {TokenAddress} from "crosslightning-base"; | ||
@@ -25,3 +24,3 @@ export type ISwapPriceCoinsMap<T extends {decimals: number}> = { | ||
getTokenData(tokenAddress: TokenAddress, chainId: string): T { | ||
getTokenData(tokenAddress: string, chainId: string): T { | ||
const chainTokens = this.coinsMap[chainId]; | ||
@@ -37,3 +36,3 @@ if(chainTokens==null) throw new Error("Chain not found"); | ||
preFetchPrice(token: TokenAddress, chainId: string): Promise<BN> { | ||
preFetchPrice(token: string, chainId: string): Promise<BN> { | ||
const coin = this.getTokenData(token, chainId); | ||
@@ -54,3 +53,3 @@ return this.getPrice(coin); | ||
fromAmount:BN, | ||
fromToken: TokenAddress, | ||
fromToken: string, | ||
tokenChainIdentification: string, | ||
@@ -82,3 +81,3 @@ roundUp?: boolean, | ||
fromAmount:BN, | ||
toToken: TokenAddress, | ||
toToken: string, | ||
tokenChainIdentification: string, | ||
@@ -85,0 +84,0 @@ roundUp?: boolean, |
import {Express, Request, Response} from "express"; | ||
import {ISwapPrice} from "./ISwapPrice"; | ||
import { | ||
BtcRelay, | ||
ChainEvents, | ||
AbstractSigner, | ||
ChainType, | ||
ClaimEvent, | ||
@@ -10,4 +10,3 @@ InitializeEvent, RefundEvent, | ||
SwapData, | ||
SwapEvent, | ||
TokenAddress | ||
SwapEvent | ||
} from "crosslightning-base"; | ||
@@ -63,7 +62,8 @@ import {AuthenticatedLnd} from "lightning"; | ||
export type ChainData<T extends SwapData = SwapData> = { | ||
swapContract: SwapContract<T, any, any, any>, | ||
chainEvents: ChainEvents<T>, | ||
export type ChainData<T extends ChainType = ChainType> = { | ||
signer: T["Signer"], | ||
swapContract: T["Contract"], | ||
chainEvents: T["Events"], | ||
allowedTokens: string[], | ||
btcRelay?: BtcRelay<any, any, any> | ||
btcRelay?: T["BtcRelay"] | ||
} | ||
@@ -133,6 +133,2 @@ | ||
protected getChain(identifier: string): ChainData { | ||
return this.chains.chains[identifier]; | ||
} | ||
protected getContract(identifier: string): SwapContract<any, any, any, any> { | ||
if(this.chains.chains[identifier]==null) | ||
@@ -143,3 +139,3 @@ throw { | ||
}; | ||
return this.chains.chains[identifier].swapContract; | ||
return this.chains.chains[identifier]; | ||
} | ||
@@ -326,3 +322,4 @@ | ||
protected getSignDataPrefetch(chainIdentifier: string, abortController: AbortController, responseStream?: ServerParamEncoder): Promise<any> { | ||
let signDataPrefetchPromise: Promise<any> = this.getContract(chainIdentifier).preFetchBlockDataForSignatures!=null ? this.getContract(chainIdentifier).preFetchBlockDataForSignatures().catch(e => { | ||
const {swapContract} = this.getChain(chainIdentifier); | ||
let signDataPrefetchPromise: Promise<any> = swapContract.preFetchBlockDataForSignatures!=null ? swapContract.preFetchBlockDataForSignatures().catch(e => { | ||
this.logger.error("getSignDataPrefetch(): signDataPrefetch: ", e); | ||
@@ -329,0 +326,0 @@ abortController.abort(e); |
@@ -15,4 +15,3 @@ import {Express, Request, Response} from "express"; | ||
SwapCommitStatus, | ||
SwapData, | ||
TokenAddress | ||
SwapData | ||
} from "crosslightning-base"; | ||
@@ -133,3 +132,4 @@ import {BitcoinRpc, BtcBlock} from "crosslightning-base/dist"; | ||
const parsedOutputScript = bitcoin.address.toOutputScript(address, bitcoinNetwork); | ||
return this.getContract(chainIdentifier).getHashForOnchain(parsedOutputScript, amount, nonce); | ||
const {swapContract} = this.getChain(chainIdentifier); | ||
return swapContract.getHashForOnchain(parsedOutputScript, amount, nonce); | ||
} | ||
@@ -343,3 +343,3 @@ | ||
private async tryClaimSwap(tx: {blockhash: string, confirmations: number, txid: string, hex: string}, swap: ToBtcSwapAbs, vout: number): Promise<boolean> { | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(swap.chainIdentifier); | ||
@@ -354,3 +354,5 @@ const blockHeader = await this.bitcoinRpc.getBlockHeader(tx.blockhash); | ||
this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout); | ||
const result = await swapContract.claimWithTxData(swap.data, blockHeader.getHeight(), tx, vout, null, null, false, true); | ||
const result = await swapContract.claimWithTxData(signer, swap.data, blockHeader.getHeight(), tx, vout, null, null, false, { | ||
waitForConfirmation: true | ||
}); | ||
this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout+" address: "+swap.address); | ||
@@ -367,3 +369,3 @@ if(swap.metadata!=null) swap.metadata.times.txClaimed = Date.now(); | ||
protected async processPastSwap(swap: ToBtcSwapAbs) { | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(swap.chainIdentifier); | ||
@@ -401,3 +403,3 @@ const timestamp = new BN(Math.floor(Date.now()/1000)).sub(new BN(this.config.maxSkew)); | ||
if(!isCommited) { | ||
const status = await swapContract.getCommitStatus(swap.data); | ||
const status = await swapContract.getCommitStatus(signer.getAddress(), swap.data); | ||
if(status===SwapCommitStatus.PAID) { | ||
@@ -976,3 +978,3 @@ this.swapLogger.info(swap, "processPastSwap(state=BTC_SENT): swap claimed (detected from processPastSwap), address: "+swap.address); | ||
const chainIdentifier = req.query.chain as string ?? this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
@@ -1021,3 +1023,3 @@ metadata.times.requestReceived = Date.now(); | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
@@ -1066,3 +1068,3 @@ const responseStream = res.responseStream; | ||
parsedBody.offerer, | ||
swapContract.getAddress(), | ||
signer.getAddress(), | ||
useToken, | ||
@@ -1112,3 +1114,3 @@ totalInToken, | ||
amount: amountBD.toString(10), | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
satsPervByte: networkFeeData.satsPerVbyte.toString(10), | ||
@@ -1157,3 +1159,3 @@ networkFee: networkFeeInToken.toString(10), | ||
const swapContract = this.getContract(payment.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(payment.chainIdentifier); | ||
@@ -1184,3 +1186,3 @@ this.checkExpired(payment); | ||
const refundResponse = await swapContract.getRefundSignature(payment.data, this.config.authorizationTimeout); | ||
const refundResponse = await swapContract.getRefundSignature(signer, payment.data, this.config.authorizationTimeout); | ||
@@ -1199,3 +1201,3 @@ //Double check the state after promise result | ||
data: { | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
prefix: refundResponse.prefix, | ||
@@ -1202,0 +1204,0 @@ timeout: refundResponse.timeout, |
import {RequestData, SwapBaseConfig, SwapHandler} from "./SwapHandler"; | ||
import {SwapHandlerSwap} from "./SwapHandlerSwap"; | ||
import {SwapData, TokenAddress} from "crosslightning-base"; | ||
import {SwapData} from "crosslightning-base"; | ||
import * as BN from "bn.js"; | ||
@@ -34,4 +34,4 @@ import {ServerParamEncoder} from "../utils/paramcoders/server/ServerParamEncoder"; | ||
this.logger.debug("checkVaultInitialized(): checking vault exists for chain: "+chainIdentifier+" token: "+token); | ||
const swapContract = this.getContract(chainIdentifier); | ||
const reputation = await swapContract.getIntermediaryReputation(swapContract.getAddress(), swapContract.toTokenAddress(token)); | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
const reputation = await swapContract.getIntermediaryReputation(signer.getAddress(), token); | ||
this.logger.debug("checkVaultInitialized(): vault state, chain: "+chainIdentifier+" token: "+token+" exists: "+(reputation!=null)); | ||
@@ -61,3 +61,3 @@ if(reputation!=null) { | ||
requestedAmount: {input: boolean, amount: BN}, | ||
useToken: TokenAddress | ||
useToken: string | ||
): Promise<{baseFee: BN, feePPM: BN}> { | ||
@@ -67,2 +67,3 @@ const res = await PluginManager.onHandlePreToBtcQuote( | ||
requestedAmount, | ||
request.chainIdentifier, | ||
useToken, | ||
@@ -107,3 +108,3 @@ {minInBtc: this.config.min, maxInBtc: this.config.max}, | ||
fees: {baseFee: BN, feePPM: BN}, | ||
useToken: TokenAddress, | ||
useToken: string, | ||
getNetworkFee: (amount: BN) => Promise<T>, | ||
@@ -126,2 +127,3 @@ signal: AbortSignal, | ||
requestedAmount, | ||
request.chainIdentifier, | ||
useToken, | ||
@@ -251,3 +253,3 @@ {minInBtc: this.config.min, maxInBtc: this.config.max}, | ||
*/ | ||
protected getToBtcPrefetches(chainIdentifier: string, token: TokenAddress, responseStream: ServerParamEncoder, abortController: AbortController): { | ||
protected getToBtcPrefetches(chainIdentifier: string, token: string, responseStream: ServerParamEncoder, abortController: AbortController): { | ||
pricePrefetchPromise?: Promise<BN>, | ||
@@ -300,3 +302,5 @@ signDataPrefetchPromise?: Promise<any> | ||
this.logger.debug("getToBtcSignatureData(): using fee rate from client: ", feeRate); | ||
const sigData = await this.getContract(chainIdentifier).getClaimInitSignature( | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
const sigData = await swapContract.getInitSignature( | ||
signer, | ||
swapObject, | ||
@@ -303,0 +307,0 @@ this.config.authorizationTimeout, |
@@ -14,4 +14,3 @@ import * as BN from "bn.js"; | ||
SwapCommitStatus, | ||
SwapData, | ||
TokenAddress | ||
SwapData | ||
} from "crosslightning-base"; | ||
@@ -104,3 +103,3 @@ import {AuthenticatedLnd} from "lightning"; | ||
token: TokenAddress, | ||
token: string, | ||
swapExpiry: BN, | ||
@@ -271,3 +270,3 @@ offerer: string, | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(swap.chainIdentifier); | ||
@@ -280,3 +279,5 @@ //Set flag that we are sending the transaction already, so we don't end up with race condition | ||
this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, secret: "+swap.secret); | ||
const success = await swapContract.claimWithSecret(swap.data, swap.secret, false, false, true); | ||
const success = await swapContract.claimWithSecret(signer, swap.data, swap.secret, false, false, { | ||
waitForConfirmation: true | ||
}); | ||
this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, secret: "+swap.secret+" invoice: "+swap.pr); | ||
@@ -310,3 +311,3 @@ if(swap.metadata!=null) swap.metadata.times.txClaimed = Date.now(); | ||
const swapContract = this.getContract(swap.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(swap.chainIdentifier); | ||
@@ -324,3 +325,3 @@ if(lnPaymentStatus.is_confirmed) { | ||
if(!isCommited) { | ||
const status = await swapContract.getCommitStatus(swap.data); | ||
const status = await swapContract.getCommitStatus(signer.getAddress(), swap.data); | ||
if(status===SwapCommitStatus.PAID) { | ||
@@ -868,3 +869,3 @@ //This is alright, we got the money | ||
const swapContract = this.getContract(parsedAuth.chainIdentifier); | ||
const {swapContract, signer} = this.getChain(parsedAuth.chainIdentifier); | ||
@@ -875,4 +876,4 @@ //Create swap data | ||
parsedAuth.offerer, | ||
swapContract.getAddress(), | ||
swapContract.toTokenAddress(parsedAuth.token), | ||
signer.getAddress(), | ||
parsedAuth.token, | ||
parsedAuth.total, | ||
@@ -925,3 +926,3 @@ parsedPR.tagsObject.payment_hash, | ||
confidence: halfConfidence ? parsedAuth.confidence/2000000 : parsedAuth.confidence/1000000, | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
@@ -951,3 +952,3 @@ routingFeeSats: parsedAuth.quotedNetworkFee.toString(10), | ||
const chainIdentifier = req.query.chain as string ?? this.chains.default; | ||
const swapContract = this.getContract(chainIdentifier); | ||
const {swapContract, signer} = this.getChain(chainIdentifier); | ||
@@ -995,3 +996,3 @@ metadata.times.requestReceived = Date.now(); | ||
}; | ||
const useToken = swapContract.toTokenAddress(parsedBody.token); | ||
const useToken = parsedBody.token; | ||
@@ -1096,3 +1097,3 @@ const responseStream = res.responseStream; | ||
parsedBody.offerer, | ||
swapContract.getAddress(), | ||
signer.getAddress(), | ||
useToken, | ||
@@ -1137,3 +1138,3 @@ totalInToken, | ||
confidence: halfConfidence ? networkFeeData.confidence/2000000 : networkFeeData.confidence/1000000, | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
@@ -1181,5 +1182,5 @@ routingFeeSats: networkFeeData.networkFee.toString(10), | ||
const swapContract = this.getContract(data.chainIdentifier); | ||
const {signer, swapContract} = this.getChain(data.chainIdentifier); | ||
if(data.state===ToBtcLnSwapState.NON_PAYABLE) { | ||
const refundSigData = await swapContract.getRefundSignature(data.data, this.config.authorizationTimeout); | ||
const refundSigData = await swapContract.getRefundSignature(signer, data.data, this.config.authorizationTimeout); | ||
@@ -1198,3 +1199,3 @@ //Double check the state after promise result | ||
data: { | ||
address: swapContract.getAddress(), | ||
address: signer.getAddress(), | ||
prefix: refundSigData.prefix, | ||
@@ -1201,0 +1202,0 @@ timeout: refundSigData.timeout, |
import {Request, Response} from "express"; | ||
import * as QueryString from "qs"; | ||
import {ServerParamEncoder} from "./paramcoders/server/ServerParamEncoder"; | ||
@@ -4,0 +3,0 @@ import * as BN from "bn.js"; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
692339
123
15211
+ Addedcrosslightning-base@7.1.0(transitive)
+ Addedcrosslightning-server-base@1.0.3(transitive)
- Removedcrosslightning-base@6.0.3(transitive)
- Removedcrosslightning-server-base@1.0.2(transitive)
Updatedcrosslightning-base@7.1.0