From 69785bbac3469444d490e38795f82050bed4dcf1 Mon Sep 17 00:00:00 2001 From: remjx <35121685+remjx@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:48:50 -0400 Subject: [PATCH] add bamk-4 multisig reserves --- src/app/page.tsx | 93 ++++++++++++++++++++++++++++++++++++++++---- src/lib/constants.ts | 1 + 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index b8fad97..ef011fc 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -11,6 +11,7 @@ import { USDE_CONTRACT_ADDRESS_MAINNET, ETHENA_BACKING_ACCOUNT_2, ETHENA_BACKING_ACCOUNT_3, + ETHENA_BACKING_ACCOUNT_4, } from '@/lib/constants' import { MagicEdenBamkData, NusdRuneData } from '@/types' import { RuneNameHeading } from '@/components/ui/RuneNameHeading' @@ -110,7 +111,17 @@ async function getData() { return {} } const usdeBacking3Amount = BigInt((await usdeBacking3Response.json()).result) / BigInt(10 ** 18) - const usdeBalance = usdeBackingAmount + usdeBacking2Amount + usdeBacking3Amount + const usdeBacking4Response = await getErc20Balance(ETHENA_BACKING_ACCOUNT_4, USDE_CONTRACT_ADDRESS_MAINNET) + if (!usdeBacking4Response.ok) { + console.error( + 'Error fetching usdeBacking4', + usdeBacking4Response.status, + usdeBacking4Response.statusText + ) + return {} + } + const usdeBacking4Amount = BigInt((await usdeBacking4Response.json()).result) / BigInt(10 ** 18) + const usdeBalance = usdeBackingAmount + usdeBacking2Amount + usdeBacking3Amount + usdeBacking4Amount const usdePrice = await fetch( 'https://api.coingecko.com/api/v3/simple/price?ids=ethena-usde&vs_currencies=usd', { @@ -200,7 +211,6 @@ async function getData() { return {} } const susde1Balance = BigInt((await susdeBacking1Response.json()).result) / BigInt(10 ** 18) - const susdeBacking3Response = await fetch(`https://mainnet.infura.io/v3/${INFURA_API_KEY}`, { method: 'POST', headers: { @@ -222,7 +232,7 @@ async function getData() { }) if (!susdeBacking3Response.ok) { console.error( - 'Error fetching susdeBacking', + 'Error fetching susdeBacking3', susdeBacking3Response.status, susdeBacking3Response.statusText ) @@ -230,7 +240,36 @@ async function getData() { } const susde3Balance = BigInt((await susdeBacking3Response.json()).result) / BigInt(10 ** 18) - const susdeBalance = susde1Balance + susde3Balance; + const susdeBacking4Response = await fetch(`https://mainnet.infura.io/v3/${INFURA_API_KEY}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'eth_call', + params: [ + { + to: ETHENA_SUSDE_TOKEN_CONTRACT, + data: erc20BalanceOfMethodId + ETHENA_BACKING_ACCOUNT_4.substring(2) + }, + 'latest' + ], + id: 1 + }), + next: { revalidate: 600 } + }) + if (!susdeBacking4Response.ok) { + console.error( + 'Error fetching susdeBacking4', + susdeBacking4Response.status, + susdeBacking4Response.statusText + ) + return {} + } + const susde4Balance = BigInt((await susdeBacking4Response.json()).result) / BigInt(10 ** 18) + + const susdeBalance = susde1Balance + susde3Balance + susde4Balance; const susdePrice = await fetch( 'https://api.coingecko.com/api/v3/simple/price?ids=ethena-staked-usde&vs_currencies=usd', { @@ -276,7 +315,6 @@ async function getData() { }), next: { revalidate: 600 } }) - if (!susdeUnstaking1Response.ok) { console.error( 'Error fetching susdeUnstakingResponse', @@ -319,7 +357,6 @@ async function getData() { }), next: { revalidate: 600 } }) - if (!susdeUnstaking3Response.ok) { console.error( 'Error fetching susdeUnstaking3Response', @@ -339,10 +376,52 @@ async function getData() { return {} } + let usdeUnstaking4Balance = 0 + const paddedAddress4 = ETHENA_BACKING_ACCOUNT_4.toLowerCase() + .replace('0x', '') + .padStart(64, '0') + const susdeUnstaking4Response = await fetch(`https://mainnet.infura.io/v3/${INFURA_API_KEY}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'eth_call', + params: [ + { + to: ETHENA_SUSDE_TOKEN_CONTRACT, + data: `${methodId}${paddedAddress4}` + }, + 'latest' + ], + id: 4 + }), + next: { revalidate: 600 } + }) + if (!susdeUnstaking4Response.ok) { + console.error( + 'Error fetching susdeUnstaking4Response', + susdeUnstaking4Response.status, + susdeUnstaking4Response.statusText + ) + return {} + } + const response4Json = await susdeUnstaking4Response.json() + const result4 = response4Json.result + if (result4) { + const cooldownEndDate = new Date(Number(hexToNumberString(result4.slice(0, 66))) * 1000) + const underlyingAmount = hexToNumberString('0x' + result4.slice(66)) + usdeUnstaking4Balance = Number(underlyingAmount) / 10 ** 18 + } else { + console.error('Error fetching cooldown4 amount', response4Json) + return {} + } + const susdeValue = susdePriceData['ethena-staked-usde'].usd * Number(susdeBalance) const usdeValue = usdePriceData['ethena-usde'].usd * Number(usdeBalance) const usdtValue = usdtPriceData['tether'].usd * Number(usdtBalance) - const usdeUnstakingValue = usdePriceData['ethena-usde'].usd * (usdeUnstaking1Balance + usdeUnstaking3Balance) + const usdeUnstakingValue = usdePriceData['ethena-usde'].usd * (usdeUnstaking1Balance + usdeUnstaking3Balance + usdeUnstaking4Balance) const backingUSDValue = susdeValue + usdeValue + usdeUnstakingValue + usdtValue console.group('Backing USD Value Details'); console.log('susdeValue:', susdeValue); diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 5f0391d..c44168a 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -11,6 +11,7 @@ export const BAMK_PREMINED_SUPPLY = 19_688_375_000; export const ETHENA_BACKING_ACCOUNT = '0xA284e606624e60d5e218cC2061bd85eD3E4f073f'; export const ETHENA_BACKING_ACCOUNT_2 = '0x6656F9769ccD9cC88E3088e47E8a4f3215798af2'; export const ETHENA_BACKING_ACCOUNT_3 = '0x77b3898979f3947D8BFc931E6b6389a99d6727a9'; +export const ETHENA_BACKING_ACCOUNT_4 = '0xA1203607eCa4d5fe43aDb362D3b5E201183A5948'; export const ETHENA_SUSDE_TOKEN_CONTRACT = '0x9D39A5DE30e57443BfF2A8307A4256c8797A3497'; export const USDF_CONTRACT_ADDRESS_SEPOLIA = '0x214056de4728BFfa28833fD258631C499D5042b9'; export const USDE_CONTRACT_ADDRESS_MAINNET = '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3';