ToBTCSwap<T>
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:38
Escrow based (PrTLC) swap for Smart chains -> Bitcoin
Extends
IToBTCSwap<T,ToBTCDefinition<T>>
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends ChainType | ChainType |
Constructors
Constructor
new ToBTCSwap<T>(wrapper, serializedObject): ToBTCSwap<T>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:59
Parameters
| Parameter | Type |
|---|---|
wrapper | ToBTCWrapper<T> |
serializedObject | any |
Returns
ToBTCSwap<T>
Overrides
Constructor
new ToBTCSwap<T>(wrapper, init): ToBTCSwap<T>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:60
Parameters
| Parameter | Type |
|---|---|
wrapper | ToBTCWrapper<T> |
init | ToBTCSwapInit<T["Data"]> |
Returns
ToBTCSwap<T>
Overrides
Properties
chainIdentifier
readonly chainIdentifier: T["ChainId"];
Defined in: atomiq-sdk/src/swaps/ISwap.ts:148
Smart chain identifier string corresponding to this swap
Inherited from
createdAt
createdAt: number;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:156
A UNIX milliseconds timestamps of when this swap was created
Inherited from
events
readonly events: EventEmitter<{
swapState: [ToBTCSwap<T>];
}>;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:140
Event emitter emitting "swapState" event when swap's state changes
Inherited from
exactIn
readonly exactIn: boolean;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:152
Whether a swap is an exact input swap
Inherited from
url?
readonly optional url: string;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:144
URL of the intermediary (LP) used for this swap, already has the swap service specific path appended
Inherited from
TYPE
protected readonly TYPE: TO_BTC = SwapType.TO_BTC;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:39
Swap type
Overrides
Methods
_verifyQuoteDefinitelyExpired()
_verifyQuoteDefinitelyExpired(): Promise<boolean>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts:178
Checks if the swap's quote is expired for good (i.e. the swap strictly cannot be committed on-chain anymore)
Returns
Promise<boolean>
Inherited from
IToBTCSwap._verifyQuoteDefinitelyExpired
_verifyQuoteValid()
_verifyQuoteValid(): Promise<boolean>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts:189
Checks if the swap's quote is still valid
Returns
Promise<boolean>
Inherited from
commit()
commit(
_signer,
abortSignal?,
skipChecks?,
onBeforeTxSent?): Promise<string>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:614
Initiates (commits) the escrow on the smart chain side
Parameters
| Parameter | Type | Description |
|---|---|---|
_signer | T["Signer"] | T["NativeSigner"] | Signer to sign the transactions with, must be the same as used in the initialization |
abortSignal? | AbortSignal | Abort signal |
skipChecks? | boolean | Skip checks like making sure init signature is still valid and swap wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you can use skipChecks=true) |
onBeforeTxSent? | (txId) => void | Callback called before the transactions are broadcasted |
Returns
Promise<string>
Inherited from
execute()
execute(
signer,
callbacks?,
options?): Promise<boolean>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:498
Executes the swap with the provided smart chain wallet/signer
Parameters
| Parameter | Type | Description |
|---|---|---|
signer | T["Signer"] | T["NativeSigner"] | Smart chain wallet/signer to use to sign the transaction on the source chain |
callbacks? | { onSourceTransactionConfirmed?: (sourceTxId) => void; onSourceTransactionSent?: (sourceTxId) => void; onSwapSettled?: (destinationTxId) => void; } | Callbacks to track the progress of the swap |
callbacks.onSourceTransactionConfirmed? | (sourceTxId) => void | - |
callbacks.onSourceTransactionSent? | (sourceTxId) => void | - |
callbacks.onSwapSettled? | (destinationTxId) => void | - |
options? | { abortSignal?: AbortSignal; maxWaitTillSwapProcessedSeconds?: number; paymentCheckIntervalSeconds?: number; } | Optional options for the swap like feeRate, AbortSignal, and timeouts/intervals |
options.abortSignal? | AbortSignal | - |
options.maxWaitTillSwapProcessedSeconds? | number | - |
options.paymentCheckIntervalSeconds? | number | - |
Returns
Promise<boolean>
Whether the swap was successfully processed by the LP, in case false is returned
the user can refund their funds back on the source chain by calling refund
Inherited from
getBitcoinFeeRate()
getBitcoinFeeRate(): number;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:182
Returns fee rate of the output bitcoin transaction in sats/vB as reported by the intermediary (LP)
Returns
number
getClaimHash()
getClaimHash(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSwap.ts:123
Returns the claim data hash specifying the claim path of the escrow - i.e. hash passed to the claim handler
Returns
string
Inherited from
getCurrentActions()
getCurrentActions(options?): Promise<SwapExecutionAction<T>[]>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:567
Returns a state-dependent set of actions for the user to execute, or empty array if there is currently no action required from the user to execute.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { refundSmartChainSigner?: string | T["Signer"] | T["NativeSigner"]; skipChecks?: boolean; } | - |
options.refundSmartChainSigner? | string | T["Signer"] | T["NativeSigner"] | Optional smart chain signer to use when creating refunds transactions |
options.skipChecks? | boolean | Skip checks like making sure init signature is still valid and swap wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you can use skipChecks=true) |
Returns
Promise<SwapExecutionAction<T>[]>
Inherited from
getDirection()
getDirection(): SwapDirection;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:506
Returns the direction of the swap
Returns
Inherited from
getEscrowClaimTxId()
getEscrowClaimTxId(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSwap.ts:144
Returns the smart chain transaction ID of the tx that claimed (settled) the escrow
Returns
string
Inherited from
getEscrowHash()
getEscrowHash(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSwap.ts:116
Returns the escrow hash - i.e. hash of the escrow data
Returns
string
Inherited from
getEscrowInitTxId()
getEscrowInitTxId(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSwap.ts:137
Returns the smart chain transaction ID of the tx that initiated the escrow
Returns
string
Inherited from
getEscrowRefundTxId()
getEscrowRefundTxId(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSwap.ts:151
Returns the smart chain transaction ID of the tx that refunded the escrow
Returns
string
Inherited from
IToBTCSwap.getEscrowRefundTxId
getExpiry()
getExpiry(): number;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:314
Returns the time (in UNIX milliseconds) at which the swap expires and the user is able to unilaterally refund it with the refund or txsRefund function.
Returns
number
Inherited from
getFee()
getFee(): Fee<T["ChainId"], SCToken<T["ChainId"]>, BtcToken>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:381
Returns total fee for the swap, the fee is represented in source currency & destination currency, but is paid only once
Returns
Fee<T["ChainId"], SCToken<T["ChainId"]>, BtcToken>
Inherited from
getFeeBreakdown()
getFeeBreakdown(): [{
fee: Fee<T["ChainId"], SCToken<T["ChainId"]>, BtcToken>;
type: SWAP;
}, {
fee: Fee<T["ChainId"], SCToken<T["ChainId"]>, BtcToken>;
type: NETWORK_OUTPUT;
}];
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:400
Returns the breakdown of all the fees paid
Returns
[{
fee: Fee<T["ChainId"], SCToken<T["ChainId"]>, BtcToken>;
type: SWAP;
}, {
fee: Fee<T["ChainId"], SCToken<T["ChainId"]>, BtcToken>;
type: NETWORK_OUTPUT;
}]
Inherited from
getId()
getId(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSwap.ts:130
Returns the ID of the swap, as used in the storage
Returns
string
Inherited from
getInput()
getInput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:426
Returns input amount of the swap, user needs to pay this much
Returns
TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>
Inherited from
getInputAddress()
getInputAddress(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:243
Returns source address of the swap
Returns
string
Inherited from
getInputToken()
getInputToken(): SCToken<T["ChainId"]>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:419
Returns the input token of the swap
Returns
SCToken<T["ChainId"]>
Inherited from
getInputTxId()
getInputTxId(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:250
Returns swap input transaction ID on the source chain
Returns
string
Inherited from
getInputWithoutFee()
getInputWithoutFee(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:436
Returns input amount of the swap without the fees (swap fee, network fee)
Returns
TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>
Inherited from
getOutput()
getOutput(): TokenAmount<T["ChainId"], BtcToken<false>>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:157
Returns output amount of the swap, user receives this much
Returns
TokenAmount<T["ChainId"], BtcToken<false>>
Overrides
getOutputAddress()
getOutputAddress(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:168
Returns destination address of the swap
Returns
string
Overrides
getOutputToken()
getOutputToken(): BtcToken<false>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:150
Returns the output token of the swap
Returns
BtcToken<false>
Overrides
getOutputTxId()
getOutputTxId(): string;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:175
Returns swap output transaction ID on the destination chain
Returns
string
Overrides
getPriceInfo()
getPriceInfo(): object;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:346
Returns pricing info about the swap
Returns
object
| Name | Type | Defined in |
|---|---|---|
difference | PercentagePPM | atomiq-sdk/src/swaps/ISwap.ts:349 |
marketPrice? | number | atomiq-sdk/src/swaps/ISwap.ts:347 |
swapPrice | number | atomiq-sdk/src/swaps/ISwap.ts:348 |
Inherited from
getQuoteExpiry()
getQuoteExpiry(): number;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:492
Returns quote expiry in UNIX millis
Returns
number
Inherited from
getRefundNetworkFee()
getRefundNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:826
Get the estimated smart chain transaction fee of the refund transaction
Returns
Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>
Inherited from
IToBTCSwap.getRefundNetworkFee
getSmartChainNetworkFee()
getSmartChainNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts:115
Returns the transaction fee paid on the smart chain side to initiate the escrow
Returns
Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>
Inherited from
IToBTCSwap.getSmartChainNetworkFee
getState()
getState(): ToBTCSwapState;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:513
Returns the current state of the swap
Returns
Inherited from
getStateInfo()
getStateInfo(): SwapStateInfo<ToBTCSwapState>;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:520
Returns the current state of the swap along with the human-readable description of the state
Returns
Inherited from
getType()
getType(): SwapType;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:499
Returns the type of the swap
Returns
Inherited from
hasEnoughBalance()
hasEnoughBalance(): Promise<{
balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
enoughBalance: boolean;
required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
}>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:446
Checks if the initiator/sender on the source chain has enough balance to go through with the swap
Returns
Promise<{
balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
enoughBalance: boolean;
required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
}>
Inherited from
hasEnoughForTxFees()
hasEnoughForTxFees(): Promise<{
balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
enoughBalance: boolean;
required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
}>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:468
Checks if the initiator/sender on the source chain has enough native token balance to cover the transaction fee of initiating the swap
Returns
Promise<{
balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
enoughBalance: boolean;
required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
}>
Inherited from
hasValidPrice()
hasValidPrice(): boolean;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:338
Checks if the pricing for the swap is valid, according to max allowed price difference set in the ISwapPrice
Returns
boolean
Inherited from
isFailed()
isFailed(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:299
Returns whether the swap failed (e.g. was refunded)
Returns
boolean
Inherited from
isFinished()
isFinished(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:264
Returns whether the swap is finished and in its terminal state (this can mean successful, refunded or failed)
Returns
boolean
Inherited from
isInitiated()
isInitiated(): boolean;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:485
Whether a swap was initialized, a swap is considered initialized on first interaction with it, i.e. calling commit() on a Smart chain -> Bitcoin swaps, calling waitForPayment() or similar on the other direction. Not initiated swaps are not saved to the persistent storage by default (see SwapperOptions.saveUninitializedSwaps)
Returns
boolean
Inherited from
isInProgress()
isInProgress(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:306
Returns whether the swap is currently being processed
Returns
boolean
Inherited from
isQuoteExpired()
isQuoteExpired(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:278
Checks whether the swap's quote has definitely expired and cannot be committed anymore, we can remove such swap
Returns
boolean
Inherited from
isQuoteSoftExpired()
isQuoteSoftExpired(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:285
Checks whether the swap's quote is soft expired (this means there is not enough time buffer for it to commit, but it still can happen)
Returns
boolean
Inherited from
isRefundable()
isRefundable(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:271
Checks whether a swap is currently refundable
Returns
boolean
Inherited from
isSuccessful()
isSuccessful(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:292
Returns whether the swap finished successful
Returns
boolean
Inherited from
refreshPriceData()
refreshPriceData(): Promise<void>;
Defined in: atomiq-sdk/src/swaps/ISwap.ts:305
Re-fetches & revalidates the price data based on the current market prices
Returns
Promise<void>
Inherited from
refund()
refund(_signer, abortSignal?): Promise<string>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:881
Refunds the swap if the swap is in refundable state, you can check so with isRefundable
Parameters
| Parameter | Type | Description |
|---|---|---|
_signer | T["Signer"] | T["NativeSigner"] | Signer to sign the transactions with, must be the same as used in the initialization |
abortSignal? | AbortSignal | Abort signal |
Returns
Promise<string>
Inherited from
requiresAction()
requiresAction(): boolean;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:257
Checks whether there is some action required from the user for this swap - can mean either refundable or claimable
Returns
boolean
Inherited from
serialize()
serialize(): any;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts:193
Serializes the swap to a JSON stringifiable representation (i.e. no bigints, buffers etc.)
Returns
any
Overrides
txsCommit()
txsCommit(skipChecks?): Promise<T["TX"][]>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:595
Returns transactions for initiating (committing) the escrow on the smart chain side. After sending the transactions manually be sure to call the waitTillCommited function to wait till the initiation transaction is observed, processed by the SDK and state of the swap properly updated.
Parameters
| Parameter | Type | Description |
|---|---|---|
skipChecks? | boolean | Skip checks like making sure init signature is still valid and swap wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you can use skipChecks=true) |
Returns
Promise<T["TX"][]>
Inherited from
txsExecute()
txsExecute(options?): Promise<[SwapExecutionActionCommit<T>]>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:543
Returns a list of steps or transactions required to finish and settle the swap
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { skipChecks?: boolean; } | Additional options for executing the swap |
options.skipChecks? | boolean | Skip checks like making sure init signature is still valid and swap wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you can use skipChecks=true) |
Returns
Promise<[SwapExecutionActionCommit<T>]>
Inherited from
txsRefund()
txsRefund(_signer?): Promise<T["TX"][]>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:842
Returns transactions for refunding the swap if the swap is in refundable state, you can check so with isRefundable. After sending the transaction manually be sure to call the waitTillRefunded function to wait till the refund transaction is observed, processed by the SDK and state of the swap properly updated.
Parameters
| Parameter | Type | Description |
|---|---|---|
_signer? | string | T["Signer"] | T["NativeSigner"] | Address of the signer to create the refund transactions for |
Returns
Promise<T["TX"][]>
Inherited from
waitForPayment()
waitForPayment(
maxWaitTimeSeconds?,
checkIntervalSeconds?,
abortSignal?): Promise<boolean>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:759
A blocking promise resolving when swap was concluded by the intermediary (LP), rejecting in case of failure
Parameters
| Parameter | Type | Description |
|---|---|---|
maxWaitTimeSeconds? | number | Maximum time in seconds to wait for the swap to be settled, an error is thrown if the swap is taking too long to claim |
checkIntervalSeconds? | number | How often to poll the intermediary for answer |
abortSignal? | AbortSignal | Abort signal |
Returns
Promise<boolean>
true if swap was successful, false if swap failed and we can refund
Throws
If a swap is determined expired by the intermediary, but it is actually still valid
Throws
If the swap should be cooperatively refundable but the intermediary returned invalid refund signature
Throws
When swap expires or if the swap has invalid state (must be ToBTCSwapState.COMMITED)
Inherited from
waitTillCommited()
waitTillCommited(abortSignal?): Promise<void>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:639
Waits till a swap is initiated (committed) on-chain, should be called after sending the commit transactions (txsCommit) manually to wait till the SDK processes the escrow initialization and updates the swap state accordingly
Parameters
| Parameter | Type | Description |
|---|---|---|
abortSignal? | AbortSignal | AbortSignal |
Returns
Promise<void>
Inherited from
waitTillRefunded()
waitTillRefunded(abortSignal?): Promise<void>;
Defined in: atomiq-sdk/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts:899
Waits till a swap is refunded, should be called after sending the refund transactions manually to wait till the SDK processes the refund and updates the swap state accordingly
Parameters
| Parameter | Type | Description |
|---|---|---|
abortSignal? | AbortSignal | AbortSignal |
Returns
Promise<void>