Skip to content

Commit

Permalink
add bamk-4 multisig reserves
Browse files Browse the repository at this point in the history
  • Loading branch information
remjx committed Oct 1, 2024
1 parent 5ed94bd commit 69785bb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
93 changes: 86 additions & 7 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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: {
Expand All @@ -222,15 +232,44 @@ async function getData() {
})
if (!susdeBacking3Response.ok) {
console.error(
'Error fetching susdeBacking',
'Error fetching susdeBacking3',
susdeBacking3Response.status,
susdeBacking3Response.statusText
)
return {}
}
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',
{
Expand Down Expand Up @@ -276,7 +315,6 @@ async function getData() {
}),
next: { revalidate: 600 }
})

if (!susdeUnstaking1Response.ok) {
console.error(
'Error fetching susdeUnstakingResponse',
Expand Down Expand Up @@ -319,7 +357,6 @@ async function getData() {
}),
next: { revalidate: 600 }
})

if (!susdeUnstaking3Response.ok) {
console.error(
'Error fetching susdeUnstaking3Response',
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 69785bb

Please sign in to comment.