Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vires.finance/dapp

Package Overview
Dependencies
Maintainers
3
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vires.finance/dapp

vires.finance smart contract interactions

  • 0.0.64
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-96.91%
Maintainers
3
Weekly downloads
 
Created
Source

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)
}

Keywords

FAQs

Package last updated on 13 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc