Skip to content

Commit

Permalink
wormhole breakdown
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x committed Dec 27, 2023
1 parent cfd62df commit 5dd7854
Showing 1 changed file with 55 additions and 94 deletions.
149 changes: 55 additions & 94 deletions projects/wormhole.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,61 @@
const { get } = require('./helper/http')
const BigNumber = require("bignumber.js");
const url = 'https://europe-west3-wormhole-message-db-mainnet.cloudfunctions.net/tvl'
let _response
const sdk = require('@defillama/sdk')
const { get } = require("./helper/http");
const url =
"https://europe-west3-wormhole-message-db-mainnet.cloudfunctions.net/tvl";
let _response;
const { sumSingleBalance } = require("@defillama/sdk/build/generalUtil");

function fetch(chainId) {
return async () => {
if (!_response) _response = get(url)
const res = await _response
if (chainId in res.AllTime) {
const tvl = res.AllTime[chainId]["*"].Notional
return new BigNumber(tvl).toFixed(2)
} else {
sdk.log('Chain no longer supported: %s', chainId)
return BigNumber(0).toFixed(2)
}
}
}
const chainMap = {
solana: "1",
ethereum: "2",
terra: "3",
bsc: "4",
polygon: "5",
avax: "6",
oasis: "7",
algorand: "8",
aurora: "9",
fantom: "10",
karura: "11",
acala: "12",
klaytn: "13",
celo: "14",
near: "15",
moonbeam: "16",
terra2: "18",
injective: "19",
sui: "21",
aptos: "22",
arbitrum: "23",
optimism: "24",
xpla: "28",
base: "30",
};

module.exports = {
methodology: "USD value of native assets currently held by Portal contracts. Token prices sourced from CoinGecko.",
solana: {
fetch: fetch("1")
},
ethereum: {
fetch: fetch("2")
},
terra: {
fetch: fetch("3")
},
bsc: {
fetch: fetch("4")
},
polygon: {
fetch: fetch("5")
},
avax: {
fetch: fetch("6")
},
oasis: {
fetch: fetch("7")
},
algorand: {
fetch: fetch("8")
},
aurora: {
fetch: fetch("9")
},
fantom: {
fetch: fetch("10")
},
karura: {
fetch: fetch("11")
},
acala: {
fetch: fetch("12")
},
klaytn: {
fetch: fetch("13")
},
celo: {
fetch: fetch("14")
},
near: {
fetch: fetch("15")
},
moonbeam: {
fetch: fetch("16")
},
terra2: {
fetch: fetch("18")
},
injective: {
fetch: fetch("19")
},
sui: {
fetch: fetch("21")
},
aptos: {
fetch: fetch("22")
},
arbitrum: {
fetch: fetch("23")
},
optimism: {
fetch: fetch("24")
},
xpla: {
fetch: fetch("28")
},
base: {
fetch: fetch("30")
},
fetch: fetch("*"),
timetravel: false,
methodology:
"USD value of native assets currently held by Portal contracts. Token prices sourced from CoinGecko.",
hallmarks: [
[1652008803, "UST depeg"],
[Math.floor(new Date('2022-02-02') / 1e3), 'Hacked: Signature Exploit'],
[Math.floor(new Date("2022-02-02") / 1e3), "Hacked: Signature Exploit"],
],
}
};

Object.keys(chainMap).forEach((chain) => {
module.exports[chain] = {
tvl: async () => {
if (!_response) _response = get(url);
const res = await _response;
const chainId = chainMap[chain];
if (!(chainId in res.AllTime)) return;

const balances = {};
Object.values(res.AllTime[chainId]).map((c) => {
sumSingleBalance(balances, c.CoinGeckoId, c.Amount, "");
});

return balances;
},
};
});
// node test.js projects/wormhole.js

0 comments on commit 5dd7854

Please sign in to comment.