Vault#

class defichain.node.Vault(node)#
closevault(vaultId: str, to: str, inputs: [{}] = None) str#

Close vault transaction.

Parameters:
  • vaultId (str) – (required) Vault to be closed

  • to (str) – (required) Any valid address to receive collaterals and half fee back

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.vault.closevault("84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2", "mwSDMvn1Hoc8DsoB7AkLv7nxdrf5Ja4jsF")
createvault(ownerAddress: str, loanSchemeId: str = '', inputs: [{}] = None) str#

Creates a vault transaction.

Parameters:
  • ownerAddress (str) – (required) Any valid address

  • loanSchemeId (str) – (optional) Unique identifier of the loan scheme (8 chars max). If empty, the default loan scheme will be selected

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.vault.createvault("2MzfSNCkjgCbNLen14CYrVtwGomfDA5AGYv")
deposittovault(vaultId: str, _from: str, amount: str, inputs: [{}] = None) str#

Deposit collateral token amount to vault.

Parameters:
  • vaultId (str) – (required) Vault id

  • _from (str) – (required) Address containing collateral

  • amount (str) – (required) Amount of collateral in amount@symbol format

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.vault.deposittovault("84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2i", "mwSDMvn1Hoc8DsoB7AkLv7nxdrf5Ja4jsF", "1@DFI")
estimatecollateral(loanAmounts: str, targetRatio: float, tokens: {} = None) str#

Returns amount of collateral tokens needed to take an amount of loan tokens for a target collateral ratio.

Parameters:
  • loanAmounts (str) – (required) Amount as json string, or array. Example: ‘[ “amount@token” ]’

  • targetRatio (float) – (required) Target collateral ratio

  • tokens – (optional) Object with collateral token as key and their percent split as value

Returns:

{…} (json) – array of <amount@token> strings

Example:
>>> node.vault.estimatecollateral("1@DUSD", 200)
estimateloan(vaultId: str, tokens: {}, targetRatio: int | None = None) {}#

Returns amount of loan tokens a vault can take depending on a target collateral ratio.

Parameters:
  • vaultId (str) – (required) vault hex id

  • tokens (json) – (required) Object with loans token as key and their percent split as value

  • targetRatio (float) – (required) Target collateral ratio

Returns:

{…} (json) – array of <amount@token> strings

Example:
>>> node.vault.estimateloan("5474b2e9bfa96446e5ef3c9594634e1aa22d3a0722cb79084d61253acbdf87bf", {"DUSD": 1}, 200)
estimatevault(collateralAmounts: str, loanAmounts: str) {}#

Returns estimated vault for given collateral and loan amounts.

Parameters:
  • collateralAmounts (str) – (required) Collateral amounts as json string, or array. Example: ‘[ “amount@token” ]’

  • loanAmounts (str) – (required) Loan amounts as json string, or array. Example: ‘[ “amount@token” ]’

Returns:

{…} (json) – returns estimate vault for given collateral and loan amounts

{
    "collateralValue" : n.nnnnnnnn,        (amount) The total collateral value in USD
    "loanValue" : n.nnnnnnnn,              (amount) The total loan value in USD
    "informativeRatio" : n.nnnnnnnn,       (amount) Informative ratio with 8 digit precision
    "collateralRatio" : n,                 (uint) Ratio as unsigned int
}

Example:
>>> node.vault.estimatevault(["1000.00000000@DFI"], ["10@DUSD"])
getvault(vaultId: str, verbose: bool = False) {}#

Returns information about vault.

Parameters:
  • vaultId (str) – (required) vault hex id

  • verbose (bool) – (optional) Verbose vault information

Returns:

{…} (json) – vault data in json form

Example:
>>> node.vault.getvault("5474b2e9bfa96446e5ef3c9594634e1aa22d3a0722cb79084d61253acbdf87bf")
listauctionhistory(identifier: str = 'mine', maxBlockHeight: int | None = None, vaultId: str | None = None, index: int | None = None, limit: int | None = None) [{}]#

Returns information about auction history.

Parameters:
  • identifier (str) – (optional) Single account ID (CScript or address) or vaultId or reserved words: “mine” - to list history for all owned accounts or “all” to list whole DB (default = “mine”).

  • maxBlockHeight (int) – (optional) Optional height to iterate from (downto genesis block)

  • vaultId (str) – (optional) Vault id

  • index (int) – (optional) Batch index

  • limit (int) – (optional) Maximum number of orders to return

Returns:

[{},{}…] (json array) – Objects with auction history information

Example:
>>> node.vault.listauctionhistory("all")
listauctions(vaultId: str | None = None, height: int | None = None, including_start: bool | None = None, limit: int = 100) [{}]#

List all available auctions.

Parameters:
  • vaultId (str) – (optional) Vault id

  • height (int) – (optional) Height to iterate from

  • including_start (bool) – (optional) If true, then iterate including starting position

  • limit (int) – (optional) Maximum number of orders to return

Returns:

[{…}] (json array) Json object with auction information

Example:
>>> node.vault.listauctions()
listvaulthistory(vaultId: str, maxBlockHeight: int | None = None, depth: int | None = None, token: str | None = None, txtype: str | None = None, limit: int = 100) [{}]#

Returns the history of the specified vault

Parameters:
  • vaultId (str) – (required) Vault to get history for

  • maxBlockHeight (int) – (optional) Optional height to iterate from (down to genesis block)

  • depth (int) – (optional) Maximum depth, from the genesis block is the default

  • token (str) – (optional) Filter by token

  • txtype (str) – (optional) Filter by transaction type, supported letter from {CustomTxType}

  • limit (int) – (optional) Maximum number of records to return, 100 by default

Returns:

[{…}] – (json array) Objects with vault history information

Example:
>>> node.vault.listvaulthistory("84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2")
listvaults(ownerAddress: str | None = None, loanSchemeId: str | None = None, state: str = 'unknown', verbose: bool = False, start: str | None = None, including_start: bool | None = None, limit: int = 100) [{}]#

List all available vaults.

Parameters:
  • ownerAddress (str) – (optional) Address of the vault owner

  • loanSchemeId (str) – (optional) Vault’s loan scheme id

  • state (str) – (optional) Wether the vault is under a given state.

  • verbose (bool) – (optional) Flag for verbose list (default = false), otherwise only ids, ownerAddress, loanSchemeIds and state are listed

  • start (str) – (optional) Optional first key to iterate from, in lexicographical order. Typically it’s set to last ID from previous request.

  • including_start (bool) – (optional) If true, then iterate including starting position.

  • limit (int) – (optional) Maximum number of orders to return

Returns:

[{…}] (json array) – Json object with vault information

Example:
>>> node.vault.listvaults()
paybackwithcollateral(vaultId: str) str#

Payback vault’s loans with vault’s collaterals.

Parameters:

vaultId (str) – (required) vault hex id

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.vault.paybackwithcollateral("5474b2e9bfa96446e5ef3c9594634e1aa22d3a0722cb79084d61253acbdf87bf")
placeauctionbid(vaultId: str, index: int, _from: str, amount: str, inputs: [{}] = None) str#

Bid to vault in auction.

Parameters:
  • vaultId (str) – (required) Vault id

  • index (int) – (required) Auction index

  • _from (str) – (required) Address to get tokens. If “from” value is: “*” (star), it’s means auto-selection accounts from wallet

  • amount (str) – (required) Amount of amount@symbol format

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.vault.placeauctionbid("84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2", 0, "mwSDMvn1Hoc8DsoB7AkLv7nxdrf5Ja4jsF", "100@TSLA")
updatevault(vaultId: str, ownerAddress: str = None, loanSchemeId: str = None, inputs: [{}] = None) str#

Creates (and submits to local node and network) an update vault transaction, and saves vault updates to database.

The last optional argument (may be empty array) is an array of specific UTXOs to spend.

Parameters:
  • vaultId (str) – (required) Vault id

  • ownerAddress (str) – (optional) Vault’s owner address

  • loanSchemeId (str) – (optional) Vault’s loan scheme id

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.vault.updatevault("84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2", {"ownerAddress": "mwSDMvn1Hoc8DsoB7AkLv7nxdrf5Ja4jsF"})
withdrawfromvault(vaultId: str, to: str, amount: str, inputs: [{}] = None) str#

Withdraw collateral token amount from vault.

Parameters:
  • vaultId (str) – (required) Vault id

  • to (str) – (required) Destination address for withdraw of collateral

  • amount (str) – (required) Amount of collateral in amount@symbol format

  • inputs (json array) – (optional) Inputs

Returns:

“hash” (string) – The hex-encoded hash of broadcasted transaction

Example:
>>> node.vault.withdrawfromvault("84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2i", "mwSDMvn1Hoc8DsoB7AkLv7nxdrf5Ja4jsF", "1@DFI")