Breaking change v0.0.26
chainId parameter is now mandatory
loginWithKeeper({ chainId: 'R' })
Interaction with Reserves (write sample)
import { loginWithKeeper, dappWrite } from '@lombardini.io/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>
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 }: 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 '@lombardini.io/dapp'
import config from './config.json'
const readDAppState = async () => {
const { getConfig, getState, getUserState } = dappRead(config)
const reservesConfigs = await getConfig()
const reservesStates = await getState()
const wavesState = await getState(['WAVES'])
const userState = await getUserState('3MJtoDCxYdW69Scpp4qDvM2kVkhvcuRXgFS')
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, loginWithKeeperErrors, dappWrite, dappRead } from '@lombardini.io/dapp'
function loginWithKeeperAndDeposit() {
const assetId = 'WAVES'
const paymentAmount = 100000000
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 === loginWithKeeperErrors.wrongNetwork) {
console.log("Oops wrong network")
}
if (e === loginWithKeeperErrors.rejectedByUser) {
console.log("User rejected")
}
if (e === loginWithKeeperErrors.noKeeper) {
console.log("Please install keeper")
}
})
}