crosslightning-sdk-base
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -41,2 +41,12 @@ /// <reference types="node" /> | ||
}>; | ||
payOnchainExactIn(address: string, tokenAmount: BN, confirmationTarget: number, confirmations: number, url: string, requiredToken?: TokenAddress, requiredClaimerKey?: string, requiredBaseFee?: BN, requiredFeePPM?: BN): Promise<{ | ||
networkFee: BN; | ||
swapFee: BN; | ||
totalFee: BN; | ||
data: T; | ||
prefix: string; | ||
timeout: string; | ||
signature: string; | ||
nonce: number; | ||
}>; | ||
payLightning(bolt11PayReq: string, expirySeconds: number, maxFee: BN, url: string, requiredToken?: TokenAddress, requiredClaimerKey?: string, requiredBaseFee?: BN, requiredFeePPM?: BN): Promise<{ | ||
@@ -43,0 +53,0 @@ confidence: string; |
@@ -170,2 +170,111 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
payOnchainExactIn(address, tokenAmount, confirmationTarget, confirmations, url, requiredToken, requiredClaimerKey, requiredBaseFee, requiredFeePPM) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const firstPart = new BN(Math.floor((Date.now() / 1000)) - 700000000); | ||
const nonceBuffer = Buffer.concat([ | ||
Buffer.from(firstPart.toArray("be", 5)), | ||
randomBytes(3) | ||
]); | ||
const nonce = new BN(nonceBuffer, "be"); | ||
let outputScript; | ||
try { | ||
outputScript = bitcoin.address.toOutputScript(address, this.options.bitcoinNetwork); | ||
} | ||
catch (e) { | ||
throw new UserError("Invalid address specified"); | ||
} | ||
const response = yield fetch(url + "/payInvoiceExactIn", { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
address, | ||
amount: tokenAmount.toString(10), | ||
confirmationTarget, | ||
confirmations, | ||
nonce: nonce.toString(10), | ||
token: requiredToken == null ? null : requiredToken.toString(), | ||
offerer: this.swapContract.getAddress() | ||
}), | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
if (response.status !== 200) { | ||
let resp; | ||
try { | ||
resp = yield response.text(); | ||
} | ||
catch (e) { | ||
throw new Error(response.statusText); | ||
} | ||
throw new Error(resp); | ||
} | ||
let jsonBody = yield response.json(); | ||
const amount = new BN(jsonBody.data.amount); | ||
const swapFee = new BN(jsonBody.data.swapFee); | ||
const networkFee = new BN(jsonBody.data.networkFee); | ||
const totalFee = new BN(jsonBody.data.totalFee); | ||
if (!totalFee.eq(swapFee.add(networkFee))) { | ||
throw new IntermediaryError("Invalid totalFee returned"); | ||
} | ||
const total = new BN(jsonBody.data.total); | ||
if (!total.eq(tokenAmount)) { | ||
throw new IntermediaryError("Invalid total returned"); | ||
} | ||
const data = new this.swapDataDeserializer(jsonBody.data.data); | ||
this.swapContract.setUsAsOfferer(data); | ||
if (this.WBTC_ADDRESS != null) { | ||
if (!total.eq(amount.add(totalFee))) { | ||
throw new IntermediaryError("Invalid total returned"); | ||
} | ||
if (!data.isToken(this.WBTC_ADDRESS)) { | ||
throw new IntermediaryError("Invalid data returned - token"); | ||
} | ||
} | ||
else { | ||
if (requiredToken != null) | ||
if (!data.isToken(requiredToken)) { | ||
throw new IntermediaryError("Invalid data returned - token"); | ||
} | ||
if (this.swapPrice != null && requiredBaseFee != null && requiredFeePPM != null) { | ||
if (!(yield this.swapPrice.isValidAmountSend(amount, requiredBaseFee, requiredFeePPM, total.sub(networkFee), data.getToken()))) { | ||
throw new IntermediaryError("Fee too high"); | ||
} | ||
} | ||
} | ||
const hash = this.swapContract.getHashForOnchain(outputScript, amount, nonce).toString("hex"); | ||
console.log("Generated hash: ", hash); | ||
const payStatus = yield this.swapContract.getPaymentHashStatus(hash); | ||
if (payStatus !== SwapCommitStatus.NOT_COMMITED) { | ||
throw new UserError("Invoice already being paid for or paid"); | ||
} | ||
if (!data.getAmount().eq(total) || | ||
data.getHash() !== hash || | ||
!data.getEscrowNonce().eq(nonce) || | ||
data.getConfirmations() !== confirmations || | ||
data.getType() !== ChainSwapType.CHAIN_NONCED) { | ||
throw new IntermediaryError("Invalid data returned"); | ||
} | ||
if (requiredClaimerKey != null) { | ||
if (data.getClaimer() !== requiredClaimerKey) | ||
throw new IntermediaryError("Invalid data returned"); | ||
} | ||
try { | ||
yield this.swapContract.isValidClaimInitAuthorization(data, jsonBody.data.timeout, jsonBody.data.prefix, jsonBody.data.signature, jsonBody.data.nonce); | ||
} | ||
catch (e) { | ||
if (e instanceof SignatureVerificationError) { | ||
throw new IntermediaryError(e.message); | ||
} | ||
throw e; | ||
} | ||
return { | ||
networkFee: new BN(jsonBody.data.networkFee), | ||
swapFee: new BN(jsonBody.data.swapFee), | ||
totalFee: new BN(jsonBody.data.totalFee), | ||
data, | ||
prefix: jsonBody.data.prefix, | ||
timeout: jsonBody.data.timeout, | ||
signature: jsonBody.data.signature, | ||
nonce: jsonBody.data.nonce | ||
}; | ||
}); | ||
} | ||
payLightning(bolt11PayReq, expirySeconds, maxFee, url, requiredToken, requiredClaimerKey, requiredBaseFee, requiredFeePPM) { | ||
@@ -172,0 +281,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -110,2 +110,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const txResult = yield this.wrapper.contract.swapContract.init(this.data, this.timeout, this.prefix, this.signature, this.nonce, null, !noWaitForConfirmation, abortSignal); | ||
this.commitTxId = txResult; | ||
yield this.save(); | ||
//Maybe don't wait for TX but instead subscribe to logs, this would improve the experience when user speeds up the transaction by replacing it. | ||
@@ -201,2 +203,4 @@ if (!noWaitForConfirmation) { | ||
const txResult = yield this.wrapper.contract.swapContract.claimWithSecret(this.data, this.secret.toString("hex"), true, true, !noWaitForConfirmation, abortSignal); | ||
this.claimTxId = txResult; | ||
yield this.save(); | ||
if (!noWaitForConfirmation) { | ||
@@ -295,2 +299,5 @@ yield this.waitTillClaimed(abortSignal); | ||
const txResult = yield this.wrapper.contract.swapContract.initAndClaimWithSecret(this.data, this.timeout, this.prefix, this.signature, this.nonce, this.secret.toString("hex"), true, abortSignal); | ||
this.commitTxId = txResult[0] || this.commitTxId; | ||
this.claimTxId = txResult[1] || this.claimTxId; | ||
yield this.save(); | ||
yield this.waitTillClaimed(abortSignal); | ||
@@ -297,0 +304,0 @@ console.log("Claim tx confirmed!"); |
@@ -134,2 +134,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const txResult = yield this.wrapper.contract.swapContract.init(this.data, this.timeout, this.prefix, this.signature, this.nonce, this.getTxoHash(), !noWaitForConfirmation, abortSignal); | ||
this.commitTxId = txResult; | ||
yield this.save(); | ||
//Maybe don't wait for TX but instead subscribe to logs, this would improve the experience when user speeds up the transaction by replacing it. | ||
@@ -231,3 +233,5 @@ if (!noWaitForConfirmation) { | ||
}, this.vout, null, this.wrapper.synchronizer, true, !noWaitForConfirmation, abortSignal); | ||
this.claimTxId = txResult; | ||
if (!noWaitForConfirmation) { | ||
yield this.save(); | ||
yield this.waitTillClaimed(abortSignal); | ||
@@ -234,0 +238,0 @@ return txResult; |
@@ -18,2 +18,4 @@ /// <reference types="node" /> | ||
protected readonly wrapper: IBTCxtoSolWrapper<T>; | ||
commitTxId: string; | ||
claimTxId: string; | ||
/** | ||
@@ -20,0 +22,0 @@ * Swap's event emitter |
@@ -24,2 +24,4 @@ import * as BN from "bn.js"; | ||
this.nonce = urlOrObject.nonce; | ||
this.commitTxId = urlOrObject.commitTxId; | ||
this.claimTxId = urlOrObject.claimTxId; | ||
} | ||
@@ -56,3 +58,5 @@ } | ||
signature: this.signature, | ||
nonce: this.nonce | ||
nonce: this.nonce, | ||
commitTxId: this.commitTxId, | ||
claimTxId: this.claimTxId | ||
}; | ||
@@ -59,0 +63,0 @@ } |
@@ -8,2 +8,8 @@ /// <reference types="node" /> | ||
/** | ||
* Transaction IDs for the swap on the smart chain side | ||
*/ | ||
commitTxId: string; | ||
refundTxId?: string; | ||
claimTxId?: string; | ||
/** | ||
* Returns hash identifier of the swap | ||
@@ -10,0 +16,0 @@ */ |
@@ -21,2 +21,4 @@ /// <reference types="node" /> | ||
readonly wrapper: ISolToBTCxWrapper<T>; | ||
commitTxId: string; | ||
refundTxId: string; | ||
/** | ||
@@ -23,0 +25,0 @@ * Swap's event emitter |
@@ -36,2 +36,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.nonce = prOrObject.nonce; | ||
this.commitTxId = prOrObject.commitTxId; | ||
this.refundTxId = prOrObject.refundTxId; | ||
} | ||
@@ -68,2 +70,4 @@ } | ||
const txResult = yield this.wrapper.contract.swapContract.initPayIn(this.data, this.timeout, this.prefix, this.signature, this.nonce, !noWaitForConfirmation, abortSignal); | ||
this.commitTxId = txResult; | ||
yield this.save(); | ||
if (!noWaitForConfirmation) { | ||
@@ -182,2 +186,4 @@ yield this.waitTillCommited(abortSignal); | ||
} | ||
this.refundTxId = txResult; | ||
yield this.save(); | ||
if (!noWaitForConfirmation) { | ||
@@ -260,3 +266,5 @@ yield this.waitTillRefunded(abortSignal); | ||
signature: this.signature, | ||
nonce: this.nonce | ||
nonce: this.nonce, | ||
commitTxId: this.commitTxId, | ||
refundTxId: this.refundTxId, | ||
}; | ||
@@ -263,0 +271,0 @@ } |
@@ -16,3 +16,3 @@ import { SoltoBTCSwap } from "./SoltoBTCSwap"; | ||
/** | ||
* Returns a newly created swap, paying for 'bolt11PayRequest' - a bitcoin LN invoice | ||
* Returns a newly created swap, paying for 'address' - a bitcoin address | ||
* | ||
@@ -31,2 +31,16 @@ * @param address Bitcoin on-chain address you wish to pay to | ||
/** | ||
* Returns a newly created swap, paying for 'address' - a bitcoin address, with exactly specified swap input instead of output | ||
* | ||
* @param address Bitcoin on-chain address you wish to pay to | ||
* @param amount Amount of token to send, in base units | ||
* @param confirmationTarget Time preference of the transaction (in how many blocks should it confirm) | ||
* @param confirmations Confirmations required for intermediary to claim the funds from PTLC (this determines the safety of swap) | ||
* @param url Intermediary/Counterparty swap service url | ||
* @param requiredToken Token that we want to send | ||
* @param requiredKey Required key of the Intermediary | ||
* @param requiredBaseFee Desired base fee reported by the swap intermediary | ||
* @param requiredFeePPM Desired proportional fee report by the swap intermediary | ||
*/ | ||
createExactIn(address: string, amount: BN, confirmationTarget: number, confirmations: number, url: string, requiredToken?: TokenAddress, requiredKey?: string, requiredBaseFee?: BN, requiredFeePPM?: BN): Promise<SoltoBTCSwap<T>>; | ||
/** | ||
* Initializes the wrapper, be sure to call this before taking any other actions. | ||
@@ -33,0 +47,0 @@ * Checks if any swaps are already refundable |
@@ -23,3 +23,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
/** | ||
* Returns a newly created swap, paying for 'bolt11PayRequest' - a bitcoin LN invoice | ||
* Returns a newly created swap, paying for 'address' - a bitcoin address | ||
* | ||
@@ -48,2 +48,26 @@ * @param address Bitcoin on-chain address you wish to pay to | ||
/** | ||
* Returns a newly created swap, paying for 'address' - a bitcoin address, with exactly specified swap input instead of output | ||
* | ||
* @param address Bitcoin on-chain address you wish to pay to | ||
* @param amount Amount of token to send, in base units | ||
* @param confirmationTarget Time preference of the transaction (in how many blocks should it confirm) | ||
* @param confirmations Confirmations required for intermediary to claim the funds from PTLC (this determines the safety of swap) | ||
* @param url Intermediary/Counterparty swap service url | ||
* @param requiredToken Token that we want to send | ||
* @param requiredKey Required key of the Intermediary | ||
* @param requiredBaseFee Desired base fee reported by the swap intermediary | ||
* @param requiredFeePPM Desired proportional fee report by the swap intermediary | ||
*/ | ||
createExactIn(address, amount, confirmationTarget, confirmations, url, requiredToken, requiredKey, requiredBaseFee, requiredFeePPM) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.isInitialized) | ||
throw new Error("Not initialized, call init() first!"); | ||
const result = yield this.contract.payOnchainExactIn(address, amount, confirmationTarget, confirmations, url, requiredToken, requiredKey, requiredBaseFee, requiredFeePPM); | ||
const swap = new SoltoBTCSwap(this, address, amount, confirmationTarget, result.networkFee, result.swapFee, result.totalFee, result.data, result.prefix, result.timeout, result.signature, result.nonce, url); | ||
yield swap.save(); | ||
this.swapData[result.data.getHash()] = swap; | ||
return swap; | ||
}); | ||
} | ||
/** | ||
* Initializes the wrapper, be sure to call this before taking any other actions. | ||
@@ -50,0 +74,0 @@ * Checks if any swaps are already refundable |
{ | ||
"name": "crosslightning-sdk-base", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "CrossLightning SDK chain-agnostic base", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -97,3 +97,13 @@ import * as BN from "bn.js"; | ||
async payOnchain(address: string, amount: BN, confirmationTarget: number, confirmations: number, url: string, requiredToken?: TokenAddress, requiredClaimerKey?: string, requiredBaseFee?: BN, requiredFeePPM?: BN): Promise<{ | ||
async payOnchain( | ||
address: string, | ||
amount: BN, | ||
confirmationTarget: number, | ||
confirmations: number, | ||
url: string, | ||
requiredToken?: TokenAddress, | ||
requiredClaimerKey?: string, | ||
requiredBaseFee?: BN, | ||
requiredFeePPM?: BN | ||
): Promise<{ | ||
networkFee: BN, | ||
@@ -226,3 +236,156 @@ swapFee: BN, | ||
async payLightning(bolt11PayReq: string, expirySeconds: number, maxFee: BN, url: string, requiredToken?: TokenAddress, requiredClaimerKey?: string, requiredBaseFee?: BN, requiredFeePPM?: BN): Promise<{ | ||
async payOnchainExactIn( | ||
address: string, | ||
tokenAmount: BN, | ||
confirmationTarget: number, | ||
confirmations: number, | ||
url: string, | ||
requiredToken?: TokenAddress, | ||
requiredClaimerKey?: string, | ||
requiredBaseFee?: BN, | ||
requiredFeePPM?: BN | ||
): Promise<{ | ||
networkFee: BN, | ||
swapFee: BN, | ||
totalFee: BN, | ||
data: T, | ||
prefix: string, | ||
timeout: string, | ||
signature: string, | ||
nonce: number | ||
}> { | ||
const firstPart = new BN(Math.floor((Date.now()/1000)) - 700000000); | ||
const nonceBuffer = Buffer.concat([ | ||
Buffer.from(firstPart.toArray("be", 5)), | ||
randomBytes(3) | ||
]); | ||
const nonce = new BN(nonceBuffer, "be"); | ||
let outputScript; | ||
try { | ||
outputScript = bitcoin.address.toOutputScript(address, this.options.bitcoinNetwork); | ||
} catch (e) { | ||
throw new UserError("Invalid address specified"); | ||
} | ||
const response: Response = await fetch(url+"/payInvoiceExactIn", { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
address, | ||
amount: tokenAmount.toString(10), | ||
confirmationTarget, | ||
confirmations, | ||
nonce: nonce.toString(10), | ||
token: requiredToken==null ? null : requiredToken.toString(), | ||
offerer: this.swapContract.getAddress() | ||
}), | ||
headers: {'Content-Type': 'application/json'} | ||
}); | ||
if(response.status!==200) { | ||
let resp: string; | ||
try { | ||
resp = await response.text(); | ||
} catch (e) { | ||
throw new Error(response.statusText); | ||
} | ||
throw new Error(resp); | ||
} | ||
let jsonBody: any = await response.json(); | ||
const amount = new BN(jsonBody.data.amount); | ||
const swapFee = new BN(jsonBody.data.swapFee); | ||
const networkFee = new BN(jsonBody.data.networkFee); | ||
const totalFee = new BN(jsonBody.data.totalFee); | ||
if(!totalFee.eq(swapFee.add(networkFee))){ | ||
throw new IntermediaryError("Invalid totalFee returned"); | ||
} | ||
const total = new BN(jsonBody.data.total); | ||
if(!total.eq(tokenAmount)) { | ||
throw new IntermediaryError("Invalid total returned"); | ||
} | ||
const data: T = new this.swapDataDeserializer(jsonBody.data.data); | ||
this.swapContract.setUsAsOfferer(data); | ||
if(this.WBTC_ADDRESS!=null) { | ||
if(!total.eq(amount.add(totalFee))){ | ||
throw new IntermediaryError("Invalid total returned"); | ||
} | ||
if(!data.isToken(this.WBTC_ADDRESS)) { | ||
throw new IntermediaryError("Invalid data returned - token"); | ||
} | ||
} else { | ||
if(requiredToken!=null) if(!data.isToken(requiredToken)) { | ||
throw new IntermediaryError("Invalid data returned - token"); | ||
} | ||
if(this.swapPrice!=null && requiredBaseFee!=null && requiredFeePPM!=null) { | ||
if(!(await this.swapPrice.isValidAmountSend(amount, requiredBaseFee, requiredFeePPM, total.sub(networkFee), data.getToken()))) { | ||
throw new IntermediaryError("Fee too high"); | ||
} | ||
} | ||
} | ||
const hash = this.swapContract.getHashForOnchain(outputScript, amount, nonce).toString("hex"); | ||
console.log("Generated hash: ", hash); | ||
const payStatus = await this.swapContract.getPaymentHashStatus(hash); | ||
if(payStatus!==SwapCommitStatus.NOT_COMMITED) { | ||
throw new UserError("Invoice already being paid for or paid"); | ||
} | ||
if( | ||
!data.getAmount().eq(total) || | ||
data.getHash()!==hash || | ||
!data.getEscrowNonce().eq(nonce) || | ||
data.getConfirmations()!==confirmations || | ||
data.getType()!==ChainSwapType.CHAIN_NONCED | ||
) { | ||
throw new IntermediaryError("Invalid data returned"); | ||
} | ||
if(requiredClaimerKey!=null) { | ||
if(data.getClaimer()!==requiredClaimerKey) throw new IntermediaryError("Invalid data returned"); | ||
} | ||
try { | ||
await this.swapContract.isValidClaimInitAuthorization(data, jsonBody.data.timeout, jsonBody.data.prefix, jsonBody.data.signature, jsonBody.data.nonce); | ||
} catch (e) { | ||
if(e instanceof SignatureVerificationError) { | ||
throw new IntermediaryError(e.message); | ||
} | ||
throw e; | ||
} | ||
return { | ||
networkFee: new BN(jsonBody.data.networkFee), | ||
swapFee: new BN(jsonBody.data.swapFee), | ||
totalFee: new BN(jsonBody.data.totalFee), | ||
data, | ||
prefix: jsonBody.data.prefix, | ||
timeout: jsonBody.data.timeout, | ||
signature: jsonBody.data.signature, | ||
nonce: jsonBody.data.nonce | ||
}; | ||
} | ||
async payLightning( | ||
bolt11PayReq: string, | ||
expirySeconds: number, | ||
maxFee: BN, | ||
url: string, | ||
requiredToken?: TokenAddress, | ||
requiredClaimerKey?: string, | ||
requiredBaseFee?: BN, | ||
requiredFeePPM?: BN | ||
): Promise<{ | ||
confidence: string, | ||
@@ -229,0 +392,0 @@ maxFee: BN, |
@@ -129,2 +129,5 @@ import * as bolt11 from "bolt11"; | ||
this.commitTxId = txResult; | ||
await this.save(); | ||
//Maybe don't wait for TX but instead subscribe to logs, this would improve the experience when user speeds up the transaction by replacing it. | ||
@@ -223,2 +226,5 @@ | ||
this.claimTxId = txResult; | ||
await this.save(); | ||
if(!noWaitForConfirmation) { | ||
@@ -329,2 +335,6 @@ await this.waitTillClaimed(abortSignal); | ||
this.commitTxId = txResult[0] || this.commitTxId; | ||
this.claimTxId = txResult[1] || this.claimTxId; | ||
await this.save(); | ||
await this.waitTillClaimed(abortSignal); | ||
@@ -331,0 +341,0 @@ |
@@ -182,2 +182,5 @@ import {IBTCxtoSolSwap} from "../IBTCxtoSolSwap"; | ||
this.commitTxId = txResult; | ||
await this.save(); | ||
//Maybe don't wait for TX but instead subscribe to logs, this would improve the experience when user speeds up the transaction by replacing it. | ||
@@ -284,3 +287,6 @@ | ||
this.claimTxId = txResult; | ||
if(!noWaitForConfirmation) { | ||
await this.save(); | ||
await this.waitTillClaimed(abortSignal); | ||
@@ -299,3 +305,2 @@ return txResult; | ||
this.state = BTCtoSolNewSwapState.CLAIM_CLAIMED; | ||
await this.save(); | ||
@@ -302,0 +307,0 @@ |
@@ -24,2 +24,5 @@ | ||
commitTxId: string; | ||
claimTxId: string; | ||
/** | ||
@@ -63,2 +66,4 @@ * Swap's event emitter | ||
this.nonce = urlOrObject.nonce; | ||
this.commitTxId = urlOrObject.commitTxId; | ||
this.claimTxId = urlOrObject.claimTxId; | ||
} | ||
@@ -211,3 +216,5 @@ } | ||
signature: this.signature, | ||
nonce: this.nonce | ||
nonce: this.nonce, | ||
commitTxId: this.commitTxId, | ||
claimTxId: this.claimTxId | ||
}; | ||
@@ -214,0 +221,0 @@ } |
@@ -8,2 +8,9 @@ import {SwapType} from "./SwapType"; | ||
/** | ||
* Transaction IDs for the swap on the smart chain side | ||
*/ | ||
commitTxId: string; | ||
refundTxId?: string; | ||
claimTxId?: string; | ||
/** | ||
* Returns hash identifier of the swap | ||
@@ -10,0 +17,0 @@ */ |
@@ -28,2 +28,5 @@ | ||
commitTxId: string; | ||
refundTxId: string; | ||
/** | ||
@@ -75,2 +78,4 @@ * Swap's event emitter | ||
this.nonce = prOrObject.nonce; | ||
this.commitTxId = prOrObject.commitTxId; | ||
this.refundTxId = prOrObject.refundTxId; | ||
} | ||
@@ -139,2 +144,5 @@ } | ||
this.commitTxId = txResult; | ||
await this.save(); | ||
if(!noWaitForConfirmation) { | ||
@@ -257,2 +265,5 @@ await this.waitTillCommited(abortSignal); | ||
this.refundTxId = txResult; | ||
await this.save(); | ||
if(!noWaitForConfirmation) { | ||
@@ -335,3 +346,5 @@ await this.waitTillRefunded(abortSignal); | ||
signature: this.signature, | ||
nonce: this.nonce | ||
nonce: this.nonce, | ||
commitTxId: this.commitTxId, | ||
refundTxId: this.refundTxId, | ||
}; | ||
@@ -338,0 +351,0 @@ } |
@@ -22,3 +22,3 @@ import {SoltoBTCSwap} from "./SoltoBTCSwap"; | ||
/** | ||
* Returns a newly created swap, paying for 'bolt11PayRequest' - a bitcoin LN invoice | ||
* Returns a newly created swap, paying for 'address' - a bitcoin address | ||
* | ||
@@ -65,2 +65,44 @@ * @param address Bitcoin on-chain address you wish to pay to | ||
/** | ||
* Returns a newly created swap, paying for 'address' - a bitcoin address, with exactly specified swap input instead of output | ||
* | ||
* @param address Bitcoin on-chain address you wish to pay to | ||
* @param amount Amount of token to send, in base units | ||
* @param confirmationTarget Time preference of the transaction (in how many blocks should it confirm) | ||
* @param confirmations Confirmations required for intermediary to claim the funds from PTLC (this determines the safety of swap) | ||
* @param url Intermediary/Counterparty swap service url | ||
* @param requiredToken Token that we want to send | ||
* @param requiredKey Required key of the Intermediary | ||
* @param requiredBaseFee Desired base fee reported by the swap intermediary | ||
* @param requiredFeePPM Desired proportional fee report by the swap intermediary | ||
*/ | ||
async createExactIn(address: string, amount: BN, confirmationTarget: number, confirmations: number, url: string, requiredToken?: TokenAddress, requiredKey?: string, requiredBaseFee?: BN, requiredFeePPM?: BN): Promise<SoltoBTCSwap<T>> { | ||
if(!this.isInitialized) throw new Error("Not initialized, call init() first!"); | ||
const result = await this.contract.payOnchainExactIn(address, amount, confirmationTarget, confirmations, url, requiredToken, requiredKey, requiredBaseFee, requiredFeePPM); | ||
const swap = new SoltoBTCSwap( | ||
this, | ||
address, | ||
amount, | ||
confirmationTarget, | ||
result.networkFee, | ||
result.swapFee, | ||
result.totalFee, | ||
result.data, | ||
result.prefix, | ||
result.timeout, | ||
result.signature, | ||
result.nonce, | ||
url | ||
); | ||
await swap.save(); | ||
this.swapData[result.data.getHash()] = swap; | ||
return swap; | ||
} | ||
/** | ||
* Initializes the wrapper, be sure to call this before taking any other actions. | ||
@@ -67,0 +109,0 @@ * Checks if any swaps are already refundable |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
421484
9493