Skip to main content

OnchainForGasSwap<T>

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:103

Trusted swap for Bitcoin -> Smart chains, to be used for minor amounts to get gas tokens on the destination chain, which is only needed for Solana, which still uses legacy swaps

Extends

Type Parameters

Type ParameterDefault type
T extends ChainTypeChainType

Implements

Constructors

Constructor

new OnchainForGasSwap<T>(wrapper, init): OnchainForGasSwap<T>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:154

Parameters

ParameterType
wrapperOnchainForGasWrapper<T>
initOnchainForGasSwapInit

Returns

OnchainForGasSwap<T>

Overrides

ISwap.constructor

Constructor

new OnchainForGasSwap<T>(wrapper, obj): OnchainForGasSwap<T>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:155

Parameters

ParameterType
wrapperOnchainForGasWrapper<T>
objany

Returns

OnchainForGasSwap<T>

Overrides

ISwap.constructor

Properties

chainIdentifier

readonly chainIdentifier: T["ChainId"];

Defined in: atomiq-sdk/src/swaps/ISwap.ts:168

Smart chain identifier string corresponding to this swap

Inherited from

ISwap.chainIdentifier


createdAt

createdAt: number;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:176

A UNIX milliseconds timestamps of when this swap was created

Inherited from

ISwap.createdAt


events

readonly events: EventEmitter<{
swapState: [OnchainForGasSwap<T>];
}>;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:160

Event emitter emitting "swapState" event when swap's state changes

Inherited from

ISwap.events


exactIn

readonly exactIn: boolean;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:172

Whether a swap is an exact input swap

Inherited from

ISwap.exactIn


url?

readonly optional url: string;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:164

URL of the intermediary (LP) used for this swap, already has the swap service specific path appended

Inherited from

ISwap.url


TYPE

protected readonly TYPE: TRUSTED_FROM_BTC = SwapType.TRUSTED_FROM_BTC;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:104

Swap type

Overrides

ISwap.TYPE

Methods

estimateBitcoinFee()

estimateBitcoinFee(_bitcoinWallet, feeRate?): Promise<TokenAmount<BtcToken<false>, true>>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:528

Estimates a bitcoin on-chain fee paid for the bitcoin swap transaction

Parameters

ParameterTypeDescription
_bitcoinWallet| IBitcoinWallet | MinimalBitcoinWalletInterfaceSender's bitcoin wallet
feeRate?numberOptional fee rate in sats/vB for the transaction

Returns

Promise<TokenAmount<BtcToken<false>, true>>

Implementation of

IBTCWalletSwap.estimateBitcoinFee


execute()

execute(): Promise<boolean>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:595

Returns

Promise<boolean>

Remarks

Not supported

Overrides

ISwap.execute


getAddress()

getAddress(): string;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:263

An address to which the user needs to send funds on the source chain

Returns

string

Implementation of

IAddressSwap.getAddress


getDirection()

getDirection(): SwapDirection;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:560

Returns the direction of the swap

Returns

SwapDirection

Inherited from

ISwap.getDirection


getExecutionAction()

getExecutionAction(options?): Promise<never>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:564

Returns a current state-dependent action for the user to execute, or undefined if there is no more action required for this swap - this means that the swap is probably finished (either expired, failed or settled).

Parameters

ParameterTypeDescription
options?{ bitcoinWallet?: MinimalBitcoinWalletInterface; }Optional options argument for the additional action context (i.e. passing bitcoin wallet info to get funded PSBTs or passing the externally-generated swap secret), see the actual type in the respective swap classes
options.bitcoinWallet?MinimalBitcoinWalletInterfaceOptional bitcoin wallet address specification to return a funded PSBT, if not provided an address is returned instead.

Returns

Promise<never>

Overrides

ISwap.getExecutionAction


getExecutionStatus()

getExecutionStatus(): Promise<never>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:580

Returns the current action and the full execution steps for a given swap. Prefer this to calling getExecutionSteps and getExecutionAction separately - if called sequentially they might return the respective steps/actions in different states if you hit the state transition boundary.

Returns

Promise<never>

Overrides

ISwap.getExecutionStatus


getExecutionSteps()

getExecutionSteps(): Promise<never>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:573

Returns a list of execution steps the user has to go through for a given swap, to see the possible execution steps check out SwapExecutionStep.

Returns

Promise<never>

Overrides

ISwap.getExecutionSteps


getFee()

getFee(): Fee<T["ChainId"], BtcToken<false>, SCToken<T["ChainId"]>>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:427

Returns total fee for the swap, the fee is represented in source currency & destination currency, but is paid only once

Returns

Fee<T["ChainId"], BtcToken<false>, SCToken<T["ChainId"]>>

Overrides

ISwap.getFee


getFeeBreakdown()

getFeeBreakdown(): [{
fee: Fee<T["ChainId"], BtcToken<false>, SCToken<T["ChainId"]>>;
type: SWAP;
}];

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:434

Returns the breakdown of all the fees paid

Returns

[{ fee: Fee<T["ChainId"], BtcToken<false>, SCToken<T["ChainId"]>>; type: SWAP; }]

Overrides

ISwap.getFeeBreakdown


getFundedPsbt()

getFundedPsbt(
_bitcoinWallet,
feeRate?,
additionalOutputs?): Promise<{
psbt: Transaction;
psbtBase64: string;
psbtHex: string;
signInputs: number[];
}>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:451

Returns the PSBT that is already funded with wallet's UTXOs (runs a coin-selection algorithm to choose UTXOs to use), also returns inputs indices that need to be signed by the wallet before submitting the PSBT back to the SDK with submitPsbt

Parameters

ParameterTypeDescription
_bitcoinWallet| IBitcoinWallet | MinimalBitcoinWalletInterfaceSender's bitcoin wallet
feeRate?numberOptional fee rate in sats/vB for the transaction
additionalOutputs?( | { amount: bigint; outputScript: Uint8Array; } | { address: string; amount: bigint; })[]additional outputs to add to the PSBT - can be used to collect fees from users

Returns

Promise<{ psbt: Transaction; psbtBase64: string; psbtHex: string; signInputs: number[]; }>

Implementation of

IBTCWalletSwap.getFundedPsbt


getHyperlink(): string;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:270

A hyperlink representation of the address + amount that the user needs to sends on the source chain. This is suitable to be displayed in a form of QR code.

Returns

string

Implementation of

IAddressSwap.getHyperlink


getId()

getId(): string;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:256

Returns the ID of the swap, as used in the storage

Returns

string

Overrides

ISwap.getId


getInput()

getInput(): TokenAmount<BtcToken<false>, true>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:381

Returns input amount of the swap, user needs to pay this much

Returns

TokenAmount<BtcToken<false>, true>

Overrides

ISwap.getInput


getInputAddress()

getInputAddress(): string;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:234

Returns source address of the swap

Returns

string

Overrides

ISwap.getInputAddress


getInputToken()

getInputToken(): BtcToken<false>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:374

Returns the input token of the swap

Returns

BtcToken<false>

Overrides

ISwap.getInputToken


getInputTxId()

getInputTxId(): string;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:242

Returns swap input transaction ID on the source chain

Returns

string

Overrides

ISwap.getInputTxId


getInputWithoutFee()

getInputWithoutFee(): TokenAmount<BtcToken<false>, true>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:388

Returns input amount of the swap without the fees (swap fee, network fee)

Returns

TokenAmount<BtcToken<false>, true>

Overrides

ISwap.getInputWithoutFee


getOutput()

getOutput(): TokenAmount<SCToken<T["ChainId"]>, true>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:364

Returns output amount of the swap, user receives this much

Returns

TokenAmount<SCToken<T["ChainId"]>, true>

Overrides

ISwap.getOutput


getOutputAddress()

getOutputAddress(): string;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:227

Returns destination address of the swap

Returns

string

Overrides

ISwap.getOutputAddress


getOutputToken()

getOutputToken(): SCToken<T["ChainId"]>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:357

Returns the output token of the swap

Returns

SCToken<T["ChainId"]>

Overrides

ISwap.getOutputToken


getOutputTxId()

getOutputTxId(): string;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:249

Returns swap output transaction ID on the destination chain

Returns

string

Overrides

ISwap.getOutputTxId


getPriceInfo()

getPriceInfo(): object;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:388

Returns pricing info about the swap

Returns

object

NameTypeDefined in
differencePercentagePPMatomiq-sdk/src/swaps/ISwap.ts:391
marketPrice?numberatomiq-sdk/src/swaps/ISwap.ts:389
swapPricenumberatomiq-sdk/src/swaps/ISwap.ts:390

Inherited from

ISwap.getPriceInfo


getQuoteExpiry()

getQuoteExpiry(): number;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:546

Returns quote expiry in UNIX millis

Returns

number

Inherited from

ISwap.getQuoteExpiry


getRequiredConfirmationsCount()

getRequiredConfirmationsCount(): number;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:444

Returns the number of confirmations required for the bitcoin transaction for this swap to complete and settle

Returns

number

Implementation of

IBTCWalletSwap.getRequiredConfirmationsCount


getState()

getState(): OnchainForGasSwapState;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:567

Returns the current state of the swap

Returns

OnchainForGasSwapState

Inherited from

ISwap.getState


getStateInfo()

getStateInfo(): SwapStateInfo<OnchainForGasSwapState>;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:574

Returns the current state of the swap along with the human-readable description of the state

Returns

SwapStateInfo<OnchainForGasSwapState>

Inherited from

ISwap.getStateInfo


getType()

getType(): SwapType;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:553

Returns the type of the swap

Returns

SwapType

Inherited from

ISwap.getType


hasValidPrice()

hasValidPrice(): boolean;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:380

Checks if the pricing for the swap is valid, according to max allowed price difference set in the ISwapPrice

Returns

boolean

Inherited from

ISwap.hasValidPrice


isFailed()

isFailed(): boolean;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:305

Returns whether the swap failed (e.g. was refunded)

Returns

boolean

Overrides

ISwap.isFailed


isFinished()

isFinished(): boolean;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:284

Returns whether the swap is finished and in its terminal state (this can mean successful, refunded or failed)

Returns

boolean

Overrides

ISwap.isFinished


isInitiated()

isInitiated(): boolean;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:539

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

ISwap.isInitiated


isInProgress()

isInProgress(): boolean;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:319

Returns whether the swap is currently being processed

Returns

boolean

Overrides

ISwap.isInProgress


isQuoteExpired()

isQuoteExpired(): boolean;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:291

Checks whether the swap's quote has definitely expired and cannot be committed anymore, we can remove such swap

Returns

boolean

Overrides

ISwap.isQuoteExpired


isQuoteSoftExpired()

isQuoteSoftExpired(): boolean;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:298

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

Overrides

ISwap.isQuoteSoftExpired


isSuccessful()

isSuccessful(): boolean;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:312

Returns whether the swap finished successful

Returns

boolean

Overrides

ISwap.isSuccessful


refreshPriceData()

refreshPriceData(): Promise<void>;

Defined in: atomiq-sdk/src/swaps/ISwap.ts:336

Re-fetches & revalidates the price data based on the current market prices

Returns

Promise<void>

Inherited from

ISwap.refreshPriceData


requestRefund()

requestRefund(refundAddress?, abortSignal?): Promise<void>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:778

Requests a refund after the swap failed, this also waits till the refund is actually sent by the intermediary (LP). The swap must be in OnchainForGasSwapState.REFUNDABLE state

Parameters

ParameterTypeDescription
refundAddress?stringBitcoin address to receive the refund to
abortSignal?AbortSignalAbort signal

Returns

Promise<void>


requiresAction()

requiresAction(): boolean;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:277

Checks whether there is some action required from the user for this swap - can mean either refundable or claimable

Returns

boolean

Overrides

ISwap.requiresAction


sendBitcoinTransaction()

sendBitcoinTransaction(wallet, feeRate?): Promise<string>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:538

Sends a swap bitcoin transaction via the passed bitcoin wallet

Parameters

ParameterTypeDescription
wallet| IBitcoinWallet | MinimalBitcoinWalletInterfaceWithSignerSender's bitcoin wallet
feeRate?numberOptional fee rate in sats/vB for the transaction

Returns

Promise<string>

Implementation of

IBTCWalletSwap.sendBitcoinTransaction


serialize()

serialize(): any;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:790

Serializes the swap to a JSON stringifiable representation (i.e. no bigints, buffers etc.)

Returns

any

Overrides

ISwap.serialize


submitPsbt()

submitPsbt(_psbt): Promise<string>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:503

Submits a PSBT signed by the wallet back to the SDK

Parameters

ParameterTypeDescription
_psbtanyA PSBT, either a Transaction object or a hex or base64 encoded PSBT string

Returns

Promise<string>

Implementation of

IBTCWalletSwap.submitPsbt


waitForBitcoinTransaction()

waitForBitcoinTransaction(
updateCallback?,
checkIntervalSeconds?,
abortSignal?): Promise<string>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:703

Waits till the bitcoin transaction gets the required number of confirmations

Parameters

ParameterTypeDefault valueDescription
updateCallback?(txId?, confirmations?, targetConfirmations?, txEtaMs?) => voidundefinedCallback called when txId is found, and also called with subsequent confirmations
checkIntervalSeconds?number5How often to check the bitcoin transaction
abortSignal?AbortSignalundefinedAbort signal

Returns

Promise<string>

Throws

if in invalid state

Implementation of

IBTCWalletSwap.waitForBitcoinTransaction


waitTillRefunded()

waitTillRefunded(checkIntervalSeconds?, abortSignal?): Promise<void>;

Defined in: atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasSwap.ts:751

Waits till the LP processes a refund for a failed swap. The swap must be in OnchainForGasSwapState.REFUNDABLE state

Parameters

ParameterTypeDescription
checkIntervalSeconds?numberHow often to check (default 5 seconds)
abortSignal?AbortSignalAbort signal

Returns

Promise<void>