npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vires.finance/dapp

v0.0.147

Published

vires.finance smart contract interactions

Downloads

95

Readme

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