To interact with Acala or Karura from Javascript you can use @polkadot/api along with @acala-network/api. You can learn more about @polkadot/api [here]. (https://polkadot.js.org/docs/api).
We do also provide a Stablecoin SDK which provides more some automation around stablecoins.
These functions only read information from the chain, and thus don't require signing transactions with a private key. Read more about state queries here: State queries docs
Get Vault for specific Account for given Collateral Type
Returns amount of collateral and amount of minted stablecoin as debit for specific collateral type and account.
Note ⚠️debit reflects the only amount of minted kUSD. The amount of debt is higher as it includes accumulated interest. To calculate the total amount to payback you need to use debitExchangeRate parameter (the example for fetching debitExchangeRate is shown below).
This parameter is used to calculate the debt. The amount of minted kUSD should be multiplied by this parameter. As the Interest rate is accumulated depends on block number, it makes sense to fetch this parameter for a certain block.
These transactions write data on-chain and require a private key to sign the transaction. To perform run test code snippets ensure that you have SEED_PHRASE environment variable defined in your .env file.
Create and manage the Vault
All operations: creating a vault, adding/removing collateral, borrowing, paying back kUSD can be done using a single method: honzon.adjustLoan
Arguments
Name
Type
currencyId
CurrencyId
collateral CurrencyId
collateral_adjustment
Signed Amount
positive means to deposit collateral currency into Vault, negative means withdraw collateral currency from the Vault
debit_adjustment
Signed Amount
positive means to mint some amount of stablecoin to the caller; negative means that caller will pay back stablecoin to the Vault
Example
Note ⚠️ the supply amount should be denormalised with KAR decimals for this example
Removes permission to transfer caller's loan to another Account (to). This method can be used to decline previously given permission.
Returns Extrinsic type that should be signed with a private key.
Arguments
Name
Type
currencyId
CurrencyId
collateral CurrencyId
to
AccountId
removes permission to transfer loan for this accountId
Example:
Removes permissions for ALL accounts to transfer the vault
Removes permission to transfer caller's vault to ALL accounts for all Collateral types. This method can be used to decline previously given permission.
Returns Extrinsic type that should be signed with a private key.
Example:
Transfering Vault to another account
Transfers Vault to the caller's account if it has permissions (if authorize was called previously by from account).
Returns Extrinsic type that should be signed with a private key.
Arguments
Name
Type
currencyId
CurrencyId
collateral CurrencyId
from
AccountId
transfers collateral from this account to the caller
Example:
Closing caller's Vault by swapping collateral in DeX
This action can be done with adjustLoan, but there is a shortcut created for this purpose which is applied only to safe vaults (where the collateral ratio is above liquidation level) and where the debt amount is positive.
This method closes the caller's Vault by selling a sufficient amount of collateral on Karura Dex.
Returns Extrinsic type that should be signed with a private key.
Arguments
Name
Type
currencyId
CurrencyId
collateral CurrencyId
max_collateral_amount
number
the maximum collateral that's allowed to be swapped in DeX to pay back the Vault
maybe_path
CurrencyId[]
swap path that can be used for swapping collateral for kUSD in DeX