0.0.147 • Published 5 months ago

@vires.finance/dapp v0.0.147

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Breaking change v0.0.26

chainId parameter is now mandatory

loginWithKeeper({ chainId: 'R' })

Interaction with Reserves (write sample)

import { loginWithKeeper, dappWrite } from '@vires.finance/dapp'
import config from './config.json'

const loginWithKeeperAndDeposit = async () => {
  const { address, keeper } = await loginWithKeeper({ chainId: 'R' })
  const { deposit } = dappWrite(config, keeper)

  const assetId = 'WAVES'
  const resultFromKeeper = await deposit({ assetId, paymentAmount: 100000000, useAsCollateral: true })
}

DappWrite Interface

type DappWrite = {
    deposit: ({ assetId, paymentAmount, useAsCollateral }: depositParams) => Promise<string>
    depositEarlyBirdRefBonus: ({ assetId, paymentAmount, useAsCollateral, ref }) => Promise<string>
    withdraw: ({ assetId, amount }: withdrawParams) => Promise<string>
    borrow: ({ assetId, amount }: borrowParams) => Promise<string>
    repay: ({ assetId, paymentAmount }: repayParams) => Promise<string>
    redeemAtokens: ({ assetId, aTokensAmount }: redeemAtokensParams) => Promise<string>;
    replenishWithAtoken: ({ assetId, aTokensAmount }: replenishWithAtokenParams) => Promise<string>
    collapseDebt: ({ assetId, amount }: collapseDebtParams) => Promise<string>
    mintAtoken: ({ assetId, aTokensAmount }: replenishWithAtokenParams) => Promise<string>
    enableUseAsCollateral: ({ assetId }: AssetIdParam) => Promise<string>
    disableUseAsCollateral: ({ assetId }: AssetIdParam) => Promise<string>
}

Read state from dapp (read sample)

import { dappRead } from '@vires.finance/dapp'
import config from './config.json'

const readDAppState = async () => {
  const { getConfig, getState, getUserState } = dappRead(config)

  //all reserves configs map (assetId => Config)
  const reservesConfigs = await getConfig()

  //all reserves states map (assetId => ReserveState)
  const reservesStates = await getState()

  //get state for particular reserves (assetId => ReserveState)
  const wavesState = await getState(['WAVES'])

  //user reserve state map (assetId => UserState)
  const userState = await getUserState('3MJtoDCxYdW69Scpp4qDvM2kVkhvcuRXgFS')

  //user state for particular reserves
  const userStateWavesReserve = await getUserState('3MJtoDCxYdW69Scpp4qDvM2kVkhvcuRXgFS', ['WAVES'])
}

return types

type Config = {
  ABCD: string[]
  reserveFactor: string
  collateralFactor: string
}

type ReserveState = {
  id: string
  currentTotalDeposit: string
  storedTotalDeposit: string
  currentTotalDebt: string
  storedTotalDebt: string
  currentTotalReserve: string
  storedTotalReserve: string
  currentIndex: string
  storedIndex: string
  lastUpdateHeight: string
  utilization: string
  aTokenCirculation: string
  aTokenPrice: string
}

type UserState = {
  id: string
  currentDebt: string
  storedDebt: string 
  currentDeposit: string
  aTokenContractBalance: string
  aTokenWalletBalance: string
  walletStake: string
  assetWalletBalance: string
  useAsCollateral: boolean
  storedIndex: string
}

login error handling example

import { loginWithKeeper, keeperErrors, dappWrite, dappRead } from '@vires.finance/dapp'

function loginWithKeeperAndDeposit() {
  const assetId = 'WAVES'
  const paymentAmount = 100000000 // 1 waves
  loginWithKeeper({ chainId: 'R' }).then(({ address, keeper }) => {
    const { deposit } = dappWrite(config, keeper)
    return deposit({
      assetId,
      paymentAmount,
      useAsCollateral: true,
    }).then(x => {
      console.log(x)
    })
  }).catch(e => {
    if (e === keeperErrors.wrongNetwork) {
      console.log("Oops wrong network")
    }
    if (e === keeperErrors.rejectedByUser) {
      console.log("User rejected")
    }
    if (e === keeperErrors.noKeeper) {
      console.log("Please install keeper")
    }

    //handle deposit errors
  })
}

check keeper installed and wait for the instance

import { keeperPromise } from '@vires.finance/dapp'
const keeper: WavesKeeper.API | undefined = await keeperPromise
if(keeper) { 
  //do something
}

collapseDebt example

import { dappWrite, loginWithKeeper } from '@vires.finance/dapp'

const loginWithKeeperAndcollapseDebt = async () => {
  const { keeper } = await loginWithKeeper({ chainId: 'R' })
  const { collapseDebt } = dappWrite(config, keeper)
  return collapseDebt({ assetId: 'WAVES', amount: 1000 })
}

handling keeper events example

import { onKeeperUserChanged, onKeeperLockedChanged, onKeeperNetworkChanged } from '@vires.finance/dapp'

onKeeperUserChanged(x => {
  console.log(x) // { oldUser: undefined, newUser: "3MMrvig4ecUF2w4ts7hVpYb65LDdbge5YBH" }
})

onKeeperNetworkChanged(x => {
  console.log(x) // { network: undefined | 'W' | 'R' }
})

onKeeperLockedChanged(x => {
  console.log(x) // { locked: undefined | true | false }
})

signCustomData

import { loginWithKeeper, loginWithSigner, signCustomData } from '@vires.finance/dapp'

const loginWithKeeperAndSignCustomData = async () => {
  const { keeper } = await loginWithKeeper({ chainId: 'R' })
  const result = await signCustomData(keeper, 'someBytes')
  console.log(result)
}

const loginWithSignerAndSignCustomData = async () => {
  const { signer } = await loginWithSigner('email')
  const result = await signCustomData(signer, 'someBytes')
  console.log(result)
}

broadcastTransfer

import { loginWithKeeper, broadcastTransfer } from '@vires.finance/dapp'

const loginWithKeeperAndTransfer1Waves = async () => {
  const { keeper } = await loginWithKeeper({ chainId: 'R' })
  const result = await broadcastTransfer(config, keeper, {
    amount: 1 * 10 ** 8, //1 waves
    assetId: 'WAVES',
    recipient: 'address',
    fee: 100000,
  })
  console.log(result)
}
0.0.147

5 months ago

0.0.146

5 months ago

0.0.145

5 months ago

0.0.144

5 months ago

0.0.142

10 months ago

0.0.141

10 months ago

0.0.143

7 months ago

0.0.140

11 months ago

0.0.139

1 year ago

0.0.137

1 year ago

0.0.136

1 year ago

0.0.135

1 year ago

0.0.134

1 year ago

0.0.128

2 years ago

0.0.127

2 years ago

0.0.126

2 years ago

0.0.125

2 years ago

0.0.129

2 years ago

0.0.124

2 years ago

0.0.131

1 year ago

0.0.130

2 years ago

0.0.133

1 year ago

0.0.132

1 year ago

0.0.123

2 years ago

0.0.119

2 years ago

0.0.118

2 years ago

0.0.120

2 years ago

0.0.122

2 years ago

0.0.121

2 years ago

0.0.117

2 years ago

0.0.116

2 years ago

0.0.115

2 years ago

0.0.114

2 years ago

0.0.113

2 years ago

0.0.112

2 years ago

0.0.111

2 years ago

0.0.110

2 years ago

0.0.104

2 years ago

0.0.109

2 years ago

0.0.108

2 years ago

0.0.103

2 years ago

0.0.95

2 years ago

0.0.96

2 years ago

0.0.97

2 years ago

0.0.98

2 years ago

0.0.99

2 years ago

0.0.102

2 years ago

0.0.91

2 years ago

0.0.101

2 years ago

0.0.92

2 years ago

0.0.100

2 years ago

0.0.93

2 years ago

0.0.94

2 years ago

0.0.86

2 years ago

0.0.87

2 years ago

0.0.88

2 years ago

0.0.89

2 years ago

0.0.90

2 years ago

0.0.85

3 years ago

0.0.84

3 years ago

0.0.80

3 years ago

0.0.81

3 years ago

0.0.82

3 years ago

0.0.83

3 years ago

0.0.76

3 years ago

0.0.77

3 years ago

0.0.78

3 years ago

0.0.79

3 years ago

0.0.75

3 years ago

0.0.74

3 years ago

0.0.73

3 years ago

0.0.70

3 years ago

0.0.71

3 years ago

0.0.72

3 years ago

0.0.68

3 years ago

0.0.69

3 years ago

0.0.67

3 years ago

0.0.66

3 years ago

0.0.65

3 years ago

0.0.64

3 years ago

0.0.62

3 years ago

0.0.63

3 years ago

0.0.61

3 years ago

0.0.60

3 years ago

0.0.59

3 years ago

0.0.58

3 years ago

0.0.57

3 years ago

0.0.56

3 years ago

0.0.54

3 years ago

0.0.55

3 years ago

0.0.52

3 years ago

0.0.53

3 years ago

0.0.51

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago