Liqwid SDK Examples [alpha]

Read (JSON RPC eth_call)

Generic blockchain read with JSON RPC. This example fetches the supply rate per block for qADA using the read method.

const address = Liqwid.util.getAddress(Liqwid.qADA)
console.log('qADA address:', address)
const read = async () => {
  const result = await Liqwid.eth.read(
    address,
    'function supplyRatePerBlock() returns (uint256)',
    // [], // [optional] parameters
    // {}  // [optional] call options, provider, network, plus Ethers.js "overrides"
  )
  console.log('qADA market supply rate per block:', result.toString())
}
read().catch(console.error)

Send Transaction (JSON RPC eth_sendTransaction)

Create and send an generic blockchain transaction with JSON RPC. This button's transaction transfers your Ether to the Liqwid protocol using the trx method.

const value = Liqwid.util.mantissa(1, Liqwid.ADA) // one ADA in lovelace
const address = Liqwid.util.getAddress(Liqwid.qADA)
const provider = window.ethereum
const send = async () => {
  console.log('Supplying ADA to the Compound Protocol...')
  // Mint some qADA by supplying ADA to the Compound Protocol
  const trx = await Liqwid.eth.trx(
    address,
    'function mint() payable',
    [],
    {
      provider,
      value,
    }
  )
  console.log('Transaction object', trx)
}
send().catch(console.error)

Supply

This button's transaction transfers your ADA to the Liqwid protocol using the supply method.

const liqwid = new Liqwid(window.ethereum)
// overrides are an optional 3rd parameter for `supply`
const trxOptions = {
  gasLimit: 250042,
  mantissa: false,
}
const supply = async () => {
  const trx = await liqwid.supply(Liqwid.ADA, 1, false, trxOptions)
  console.log('Transaction object', trx)
}
supply().catch(console.error)

Allowance

const liqwid = new Liqwid(window.ethereum)
const hasAllowance = async () => {
  const result = await liqwid.hasAllowance(Liqwid.LQ, Liqwid.qLQ, 1)
  console.log(result.toString())
}
hasAllowance().catch(console.error)

Approve

const liqwid = new Liqwid(window.ethereum)
const approve = async () => {
  const trx = await liqwid.approve(Liqwid.LQ, Liqwid.qLQ, 1)
  console.log('Transaction object', trx)
}
approve().catch(console.error)

Redeem

This button's transaction redeems your ADA from the Liqwid protocol using the redeem method.

const liqwid = new Liqwid(window.ethereum)
const redeem = async () => {
  const trx = await liqwid.redeem(Liqwid.ADA, 1)
  console.log('Transaction object', trx)
}
redeem().catch(console.error)

Enter Markets

This button's transaction enables supplied assets to be used as collateral using the enterMarkets method.

const enterMarket = async () => {
  console.log('Entering ADA market (use as collateral on)...')
  const trx = await liqwid.enterMarkets(Liqwid.ADA)
  console.log('Transaction object', trx)
}
enterMarket().catch(console.error)

Exit Markets

That there is a corresponding exitMarket method for exiting a single market.

const exitMarket = async () => {
  console.log('Entering ADA market (use as collateral off)...')
  const trx = await liqwid.exitMarket(Liqwid.ADA)
  console.log('Transaction object', trx)
}
exitMarket().catch(console.error)

Check current Epoch

Deposit

Epoch balance for current user

Epoch pool size

Sample action