From 68038a6841df33095e90de483bc4f473660fdaf7 Mon Sep 17 00:00:00 2001 From: Kian Bradley Date: Thu, 12 Sep 2024 11:52:24 -0700 Subject: [PATCH] Ondo USDY: fix mantle and cosmos chain balances The Mantle balance for USDY references an 'unreleased' address pointing to an unknown multisig. This should be removed, as we consider all tokens on Mantle to be in circulation. The Noble and Injective balances have been reworked to use native RPCs and fetch balances using the IBC channel balances. This is a lot more scalable, and I was able to add Osmosis as well. --- .../ondo-us-dollar-yield/index.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/adapters/peggedAssets/ondo-us-dollar-yield/index.ts b/src/adapters/peggedAssets/ondo-us-dollar-yield/index.ts index db15cd3d..0b1365c8 100644 --- a/src/adapters/peggedAssets/ondo-us-dollar-yield/index.ts +++ b/src/adapters/peggedAssets/ondo-us-dollar-yield/index.ts @@ -5,42 +5,41 @@ const retry = require("async-retry"); import { addChainExports } from "../helper/getSupply"; import { sumSingleBalance } from '../helper/generalUtil'; - -async function injectiveBridged() { +async function nobleNative() { return async function ( _timestamp: number, _ethBlock: number, _chainBlocks: ChainBlocks ) { - const issuance = await retry(async (_bail: any) => - axios.get("https://injective-nuxt-api.vercel.app/api/tokens") - ); - - const targetDenom = "ibc/93EAE5F9D6C14BFAC8DD1AFDBE95501055A7B22C5D8FA8C986C31D6EFADCA8A9"; - const targetToken = issuance?.data?.supply?.find( - (token: any) => token.denom === targetDenom + const supplyData = await retry(async (_bail: any) => + axios.get("https://noble-api.polkachu.com/cosmos/bank/v1beta1/supply/ausdy") ); - const circulatingSupply = targetToken ? targetToken.amount / 1e18 : 0; - let balances = {} + const circulatingSupply = supplyData?.data?.amount?.amount / 1e18; + let balances = {}; sumSingleBalance(balances, "peggedUSD", circulatingSupply, "issued", false); return balances; }; } -async function nobleBridged() { +async function bridgedFromNoble(channel: string) { return async function ( _timestamp: number, _ethBlock: number, _chainBlocks: ChainBlocks ) { - const issuance = await retry(async (_bail: any) => - axios.get("https://ondo.finance/api/v1/assets") + // Fetch the escrow address for the given IBC channel + const escrowResponse = await retry(async (_bail: any) => + axios.get(`https://noble-api.polkachu.com/ibc/apps/transfer/v1/channels/${channel}/ports/transfer/escrow_address`) ); + const escrowAddress = escrowResponse?.data?.escrow_address; - const tokens = issuance?.data?.assets[0].tvlUsd.noble; - const circulatingSupply = tokens / issuance?.data?.assets[0].priceUsd; + // Fetch the balance of the escrow address + const balanceResponse = await retry(async (_bail: any) => + axios.get(`https://noble-api.polkachu.com/cosmos/bank/v1beta1/balances/${escrowAddress}/by_denom?denom=ausdy`) + ); + const circulatingSupply = balanceResponse?.data?.balance?.amount / 1e18; let balances = {}; sumSingleBalance(balances, "peggedUSD", circulatingSupply, "issued", false); return balances; @@ -56,7 +55,6 @@ const chainContracts = { }, mantle: { issued: "0x5bE26527e817998A7206475496fDE1E68957c5A6", - unreleased: ["0x94FEC56BBEcEaCC71c9e61623ACE9F8e1B1cf473"], }, sui: { issued: [ @@ -80,12 +78,14 @@ const chainContracts = { const adapter: PeggedIssuanceAdapter = { ...addChainExports(chainContracts), noble: { - minted: nobleBridged() + minted: nobleNative() }, injective: { - noble: injectiveBridged(), + noble: bridgedFromNoble("channel-31"), }, + osmosis: { + noble: bridgedFromNoble("channel-1"), + } }; export default adapter; -