diff --git a/packages/namada/NamadaChain.ts b/packages/namada/NamadaChain.ts index 35bf9d3059..579579ec61 100644 --- a/packages/namada/NamadaChain.ts +++ b/packages/namada/NamadaChain.ts @@ -172,4 +172,16 @@ export default class NamadaChain extends CW.Chain { fetchTotalStaked (epoch?: Epoch) { return this.getConnection().fetchTotalStakedImpl(epoch) } + fetchDenomination (token: string) { + return this.getConnection().fetchDenominationImpl(token) + } + fetchTotalSupply (token: string) { + return this.getConnection().fetchTotalSupplyImpl(token) + } + fetchEffectiveNativeSupply () { + return this.getConnection().fetchEffectiveNativeSupplyImpl() + } + fetchStakingRewardsRate () { + return this.getConnection().fetchStakingRewardsRateImpl() + } } diff --git a/packages/namada/NamadaConnection.ts b/packages/namada/NamadaConnection.ts index f514e58614..a8753809c0 100644 --- a/packages/namada/NamadaConnection.ts +++ b/packages/namada/NamadaConnection.ts @@ -156,6 +156,18 @@ export default class NamadaConnection extends CW.Connection { fetchBondWithSlashingImpl (delegator: string, validator: string, epoch?: Epoch.Epoch) { return PoS.fetchBondWithSlashing(this, delegator, validator, epoch) } + fetchDenominationImpl (token: string) { + return Token.fetchDenomination(this, token) + } + fetchTotalSupplyImpl (token: string) { + return Token.fetchTotalSupply(this, token) + } + fetchEffectiveNativeSupplyImpl () { + return Token.fetchEffectiveNativeSupply(this) + } + fetchStakingRewardsRateImpl () { + return Token.fetchStakingRewardsRate(this) + } } export function fetchStorageValue ( diff --git a/packages/namada/NamadaToken.ts b/packages/namada/NamadaToken.ts new file mode 100644 index 0000000000..bfc7ebd804 --- /dev/null +++ b/packages/namada/NamadaToken.ts @@ -0,0 +1,19 @@ +import { decode, u64 } from '@hackbg/borshest' +import type { NamadaConnection as Connection } from './namada-connection' + +export async function fetchDenomination (connection: Connection, token: string) { + const binary = await connection.abciQuery(`/vp/token/denomination/${token}`) + return connection.decode.denomination(binary) +} +export async function fetchTotalSupply (connection: Connection, token: string) { + const binary = await connection.abciQuery(`/vp/token/total_supply/${token}`) + return decode(u64, binary) +} +export async function fetchEffectiveNativeSupply (connection: Connection) { + const binary = await connection.abciQuery(`/vp/token/effective_native_supply`) + return decode(u64, binary) +} +export async function fetchStakingRewardsRate (connection: Connection) { + const binary = await connection.abciQuery(`/vp/token/staking_rewards_rate`) + return connection.decode.pos_rewards_rates(binary) +}