Skip to content

Commit

Permalink
add new backing account
Browse files Browse the repository at this point in the history
  • Loading branch information
remjx committed Aug 22, 2024
1 parent a8321bb commit 113dd6a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
93 changes: 49 additions & 44 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SEASON_1_BAMK_PER_BLOCK,
USDT_CONTRACT_ADDRESS_MAINNET,
USDE_CONTRACT_ADDRESS_MAINNET,
ETHENA_BACKING_ACCOUNT_2,
} from '@/lib/constants'
import { MagicEdenBamkData, NusdRuneData } from '@/types'
import { RuneNameHeading } from '@/components/ui/RuneNameHeading'
Expand Down Expand Up @@ -57,33 +58,46 @@ async function getData() {
const erc20BalanceOfMethodId = keccak256('balanceOf(address)')
.substring(0, 10)
.padEnd(34, '0')
const usdeBackingResponse = 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: USDE_CONTRACT_ADDRESS_MAINNET,
data: erc20BalanceOfMethodId + ETHENA_BACKING_ACCOUNT.substring(2)
},
'latest'
],
id: 1
}),
next: { revalidate: 600 }
})
function getErc20Balance(address: string, contract: string) {
return 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: contract,
data: erc20BalanceOfMethodId + address.substring(2)
},
'latest'
],
id: 1
}),
next: { revalidate: 600 }
})
}
const usdeBackingResponse = await getErc20Balance(ETHENA_BACKING_ACCOUNT, USDE_CONTRACT_ADDRESS_MAINNET)
if (!usdeBackingResponse.ok) {
console.error(
'Error fetching usdeBacking',
usdeBackingResponse.status,
usdeBackingResponse.statusText
)
}
const usdeBalance = BigInt((await usdeBackingResponse.json()).result) / BigInt(10 ** 18)
const usdeBackingAmount = BigInt((await usdeBackingResponse.json()).result) / BigInt(10 ** 18)
const usdeBacking2Response = await getErc20Balance(ETHENA_BACKING_ACCOUNT_2, USDE_CONTRACT_ADDRESS_MAINNET)
if (!usdeBacking2Response.ok) {
console.error(
'Error fetching usdeBacking2',
usdeBacking2Response.status,
usdeBacking2Response.statusText
)
}
const usdeBacking2Amount = BigInt((await usdeBacking2Response.json()).result) / BigInt(10 ** 18)
const usdeBalance = usdeBackingAmount + usdeBacking2Amount
const usdePrice = await fetch(
'https://api.coingecko.com/api/v3/simple/price?ids=ethena-usde&vs_currencies=usd',
{
Expand All @@ -104,33 +118,25 @@ async function getData() {
}
} = await usdePrice.json()

const usdtBackingResponse = 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: USDT_CONTRACT_ADDRESS_MAINNET,
data: erc20BalanceOfMethodId + ETHENA_BACKING_ACCOUNT.substring(2)
},
'latest'
],
id: 1
}),
next: { revalidate: 600 }
})
const usdtBackingResponse = await getErc20Balance(ETHENA_BACKING_ACCOUNT, USDT_CONTRACT_ADDRESS_MAINNET)
if (!usdtBackingResponse.ok) {
console.error(
'Error fetching usdeBacking',
usdeBackingResponse.status,
usdeBackingResponse.statusText
'Error fetching usdtBacking',
usdtBackingResponse.status,
usdtBackingResponse.statusText
)
}
const usdtBackingAmount = BigInt((await usdtBackingResponse.json()).result) / BigInt(10 ** 6)
const usdtBacking2Response = await getErc20Balance(ETHENA_BACKING_ACCOUNT_2, USDT_CONTRACT_ADDRESS_MAINNET)
if (!usdtBacking2Response.ok) {
console.error(
'Error fetching usdtBacking2',
usdtBacking2Response.status,
usdtBacking2Response.statusText
)
}
const usdtBalance = BigInt((await usdtBackingResponse.json()).result) / BigInt(10 ** 6)
const usdtBacking2Amount = BigInt((await usdtBacking2Response.json()).result) / BigInt(10 ** 6)
const usdtBalance = usdtBackingAmount + usdtBacking2Amount
const usdtPrice = await fetch(
'https://api.coingecko.com/api/v3/simple/price?ids=tether&vs_currencies=usd',
{
Expand Down Expand Up @@ -248,7 +254,6 @@ async function getData() {
const usdtValue = usdtPriceData['tether'].usd * Number(usdtBalance)
const usdeUnstakingValue = usdePriceData['ethena-usde'].usd * usdeUnstakingBalance
const backingUSDValue = susdeValue + usdeValue + usdeUnstakingValue + usdtValue
// Log the values inside a console group
console.group('Backing USD Value Details');
console.log('susdeValue:', susdeValue);
console.log('usdeValue:', usdeValue);
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const SEASON_1_TOTAL_BLOCKS = 41_972;
export const BAMK_TOTAL_SUPPLY = 21_000_000_000;
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_SUSDE_TOKEN_CONTRACT = '0x9D39A5DE30e57443BfF2A8307A4256c8797A3497';
export const USDF_CONTRACT_ADDRESS_SEPOLIA = '0x214056de4728BFfa28833fD258631C499D5042b9';
export const USDE_CONTRACT_ADDRESS_MAINNET = '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3';
Expand Down

0 comments on commit 113dd6a

Please sign in to comment.