Skip to main content

SpvVaultContract<TX, Signer, ChainId, WithdrawalTX, Data>

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:20

Represents an SPV vault (UTXO-controlled vault) contract, exposes operations on the vaults

Type Parameters

Type ParameterDefault type
TXany
Signer extends AbstractSignerAbstractSigner
ChainId extends stringstring
WithdrawalTX extends SpvWithdrawalTransactionDataSpvWithdrawalTransactionData
Data extends SpvVaultData<WithdrawalTX>SpvVaultData<WithdrawalTX>

Properties

chainId

readonly chainId: ChainId;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:31

Chain identifier string

Methods

checkWithdrawalTx()

checkWithdrawalTx(tx): Promise<void>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:237

Checks if given withdrawal tx is valid and correctly parses on-chain, throws error when there is any issue with the validation

Parameters

ParameterTypeDescription
txWithdrawalTX

Returns

Promise<void>


claim()

claim(
signer,
vault,
txs,
synchronizer?,
initAta?,
txOptions?): Promise<string>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:105

Signs & sends transactions for claiming the funds from a specific vault

Parameters

ParameterTypeDescription
signerSignerSigner to use for the transaction
vaultDataVault to claim from
txsobject[]
synchronizer?RelaySynchronizer<any, TX, any>Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
initAta?booleanWhether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
txOptions?TransactionConfirmationOptionsTransaction options

Returns

Promise<string>


createVaultData()

createVaultData(
owner,
vaultId,
utxo,
confirmations,
tokenData): Promise<Data>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:140

Creates vault data for a new vault

Parameters

ParameterTypeDescription
ownerstringVault owner
vaultIdbigintVault ID
utxostringUtxo on which to assign the vault initially
confirmationsnumberRequired number of bitcoin confirmations to be able to withdraw funds from the vault
tokenDataSpvVaultTokenData[]Data about the tokens in the vault

Returns

Promise<Data>


deposit()

deposit(
signer,
vault,
rawAmounts,
txOptions?): Promise<string>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:59

Signs & sends transactions for depositing funds to a specific spv vault

Parameters

ParameterTypeDescription
signerSignerSigner to use for the transaction (can be any)
vaultDataVault to deposit to
rawAmountsbigint[]Raw amounts to deposit (these are unscaled)
txOptions?TransactionConfirmationOptionsTransaction options

Returns

Promise<string>


fromOpReturnData()

fromOpReturnData(data): object;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:253

Parses withdrawal params from OP_RETURN data

Parameters

ParameterTypeDescription
dataBufferdata as specified in the OP_RETURN output of the transaction

Returns

object

NameTypeDefined in
executionHash?stringatomiq-base/src/spv_swap/SpvVaultContract.ts:253
rawAmountsbigint[]atomiq-base/src/spv_swap/SpvVaultContract.ts:253
recipientstringatomiq-base/src/spv_swap/SpvVaultContract.ts:253

frontLiquidity()

frontLiquidity(
signer,
vault,
realWithdrawalTx,
withdrawSequence,
txOptions?): Promise<string>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:81

Signs & sends transactions for fronting liquidity for a specific withdrawal btc transaction

Parameters

ParameterTypeDescription
signerSignerSigner to use for the transaction (payer of the fronted liquidity)
vaultDataVault to deposit to
realWithdrawalTxWithdrawalTXReal withdrawal transaction data
withdrawSequencenumberSequence number of the withdrawal that is being fronted, this used as race condition prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
txOptions?TransactionConfirmationOptionsTransaction options

Returns

Promise<string>


getAllVaults()

getAllVaults(owner?): Promise<Data[]>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:192

Returns all currently opened vaults NOTE: This will take a long time, since the implementation will have to go through all the prior events

Parameters

ParameterType
owner?string

Returns

Promise<Data[]>


getClaimFee()

getClaimFee(
signer,
vault?,
withdrawalData?,
feeRate?): Promise<bigint>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:263

Returns the fee in native token base units to claim the swap

Parameters

ParameterTypeDescription
signerstringSigner claiming the swap
vault?Data
withdrawalData?WithdrawalTXWithdrawal to claim
feeRate?stringOptional fee rate (fetched on-demand if not provided)

Returns

Promise<bigint>


getFronterAddress()

getFronterAddress(
owner,
vaultId,
withdrawal): Promise<string>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:149

Returns the party which currently fronted the withdrawal transaction

Parameters

ParameterTypeDescription
ownerstringOwner of the vault
vaultIdbigintVault ID
withdrawalWithdrawalTXWithdrawal transaction to check the fronting for

Returns

Promise<string>


getFronterAddresses()

getFronterAddresses(withdrawals): Promise<{
[btcTxId: string]: string;
}>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:156

Returns the parties which currently fronted the withdrawal transactions

Parameters

ParameterTypeDescription
withdrawalsobject[]withdrawals to query

Returns

Promise<{ [btcTxId: string]: string; }>


getFrontFee()

getFrontFee(
signer,
vault?,
withdrawalData?,
feeRate?): Promise<bigint>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:283

Returns the fee in native token base units to claim the swap

Parameters

ParameterTypeDescription
signerstringSigner claiming the swap
vault?Data
withdrawalData?WithdrawalTXWithdrawal to claim
feeRate?stringOptional fee rate (fetched on-demand if not provided)

Returns

Promise<bigint>


getHistoricalWithdrawalStates()?

optional getHistoricalWithdrawalStates(recipient, startBlockheight?): Promise<{
latestBlockheight?: number;
withdrawals: {
[btcTxId: string]: SpvWithdrawalFrontedState | SpvWithdrawalClaimedState;
};
}>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:217

Returns the full history as fetched from the chain for a specific recipient

Parameters

ParameterTypeDescription
recipientstringA recipient to check the history for
startBlockheight?number

Returns

Promise<{ latestBlockheight?: number; withdrawals: { [btcTxId: string]: SpvWithdrawalFrontedState | SpvWithdrawalClaimedState; }; }>


getMultipleVaultData()

getMultipleVaultData(vaults): Promise<{
[owner: string]: object;
}>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:171

Returns current vault data for multiple vaults

Parameters

ParameterTypeDescription
vaultsobject[]Vault data to query

Returns

Promise<{ [owner: string]: object; }>


getRawClaimFee()?

optional getRawClaimFee(
signer,
vault?,
withdrawalData?,
feeRate?): Promise<bigint>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:273

Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap

Parameters

ParameterTypeDescription
signerstringSigner claiming the swap
vault?Data
withdrawalData?WithdrawalTXWithdrawal to claim
feeRate?stringOptional fee rate (fetched on-demand if not provided)

Returns

Promise<bigint>


getRawFrontFee()?

optional getRawFrontFee(
signer,
vault?,
withdrawalData?,
feeRate?): Promise<bigint>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:293

Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap

Parameters

ParameterTypeDescription
signerstringSigner claiming the swap
vault?Data
withdrawalData?WithdrawalTXWithdrawal to claim
feeRate?stringOptional fee rate (fetched on-demand if not provided)

Returns

Promise<bigint>


getVaultData()

getVaultData(owner, vaultId): Promise<Data>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:164

Returns current vault data

Parameters

ParameterTypeDescription
ownerstringOwner of the vault
vaultIdbigintVault ID

Returns

Promise<Data>


getVaultLatestUtxo()

getVaultLatestUtxo(owner, vaultId): Promise<string>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:179

Returns the latest utxo of a vault (or null if vault closed or not found)

Parameters

ParameterTypeDescription
ownerstringOwner of the vault
vaultIdbigintVault ID

Returns

Promise<string>


getVaultLatestUtxos()

getVaultLatestUtxos(vaults): Promise<{
[owner: string]: object;
}>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:186

Returns the latest utxos of for multiple vaults (or null if vault closed or not found)

Parameters

ParameterTypeDescription
vaultsobject[]Vault data to query

Returns

Promise<{ [owner: string]: object; }>


getWithdrawalData()

getWithdrawalData(btcTx): Promise<WithdrawalTX>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:229

Parses withdrawal data from the parsed bitcoin transaction

Parameters

ParameterTypeDescription
btcTxBtcTx

Returns

Promise<WithdrawalTX>


getWithdrawalState()

getWithdrawalState(withdrawalTx, scStartBlockheight?): Promise<SpvWithdrawalState>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:201

Returns current state of the withdrawal, optionally only check withdrawals from the provided block height

Parameters

ParameterTypeDescription
withdrawalTxWithdrawalTX
scStartBlockheight?number

Returns

Promise<SpvWithdrawalState>


getWithdrawalStates()

getWithdrawalStates(withdrawalTxs): Promise<{
[btcTxId: string]: SpvWithdrawalState;
}>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:209

Returns current state of the withdrawals, optionally only check withdrawals from the provided block height

Parameters

ParameterTypeDescription
withdrawalTxsobject[]Object with the withdrawal tx to check + an optional start blockheight

Returns

Promise<{ [btcTxId: string]: SpvWithdrawalState; }>


open()

open(
signer,
vault,
txOptions?): Promise<string>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:40

Signs & sends transactions for opening a specific spv vault

Parameters

ParameterTypeDescription
signerSignerSigner to use for the transaction (must match owner in vault)
vaultDataVault to init
txOptions?TransactionConfirmationOptionsTransaction options

Returns

Promise<string>


toOpReturnData()

toOpReturnData(
recipient,
rawAmounts,
executionHash?): Buffer;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:246

Serializes the withdrawal params to the OP_RETURN data

Parameters

ParameterTypeDescription
recipientstringRecipient of the withdrawn tokens
rawAmountsbigint[]Raw amount of tokens to withdraw
executionHash?stringOptional execution hash of the actions to execute

Returns

Buffer


txsClaim()

txsClaim(
signer,
vault,
txs,
synchronizer?,
initAta?,
feeRate?): Promise<TX[]>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:123

Returns the unsigned transactions for claiming the funds from a specific vault

Parameters

ParameterTypeDescription
signerstringSigner to use for the transaction
vaultDataVault to claim from
txsobject[]
synchronizer?RelaySynchronizer<any, TX, any>Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
initAta?booleanWhether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
feeRate?stringFee rate to use for the transaction

Returns

Promise<TX[]>


txsDeposit()

txsDeposit(
signer,
vault,
rawAmounts,
feeRate?): Promise<TX[]>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:69

Returns the unsigned transactions for depositing funds to a specific spv vault

Parameters

ParameterTypeDescription
signerstringSigner to use for the transaction (can be any)
vaultDataVault to deposit to
rawAmountsbigint[]Raw amounts to deposit (these are unscaled)
feeRate?stringFee rate to use for the transaction

Returns

Promise<TX[]>


txsFrontLiquidity()

txsFrontLiquidity(
signer,
vault,
realWithdrawalTx,
withdrawSequence,
feeRate?): Promise<TX[]>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:93

Returns the unsigned transactions for fronting liquidity for a specific withdrawal btc transaction

Parameters

ParameterTypeDescription
signerstringSigner to use for the transaction (payer of the fronted liquidity)
vaultDataVault to deposit to
realWithdrawalTxWithdrawalTXReal withdrawal transaction data
withdrawSequencenumberSequence number of the withdrawal that is being fronted, this used as race condition prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
feeRate?stringFee rate to use for the transaction

Returns

Promise<TX[]>


txsOpen()

txsOpen(
signer,
vault,
feeRate?): Promise<TX[]>;

Defined in: atomiq-base/src/spv_swap/SpvVaultContract.ts:49

Returns the unsigned transactions for opening a specific spv vault

Parameters

ParameterTypeDescription
signerstringSigner to use for the transaction (must match owner in vault)
vaultDataVault to init
feeRate?stringFee rate to use for the transaction

Returns

Promise<TX[]>