Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oSnap #6097

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

oSnap #6097

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions projects/osnap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const sdk = require("@defillama/sdk");
const { getConfig } = require("./utils");

const ethAddress = "0x0000000000000000000000000000000000000000";

async function tvl(_, _1, _2, api) {
const balances = {};

const url =
"https://raw.githubusercontent.com/UMAprotocol/protocol/master/packages/core/config/adapters/defiLlama/oSnap.json";
const config = await getConfig(url);

const { tokens, avatars } = config[api.chain];

await Promise.all(
avatars.map(async (avatar) => {
const {
excludedTokens,
tokens: avatarTokens,
address: avatarAddress,
} = avatar;
// eth balance
const { output: balance } = await sdk.api.eth.getBalance({
target: avatarAddress,
block: api.block,
});
await sdk.util.sumSingleBalance(balances, ethAddress, balance);

// combine avatar tokens and global tokens and remove excluded tokens
const filteredTokens = [
...new Set(
[...tokens, ...avatarTokens].filter(
(t) => !excludedTokens.includes(t)
)
),
];

// erc20 balances
await Promise.all(
filteredTokens.map(async (token) => {
const balance = await api.api.call({
abi: "erc20:balanceOf",
target: token,
params: [avatarAddress],
});
await sdk.util.sumSingleBalance(balances, token, balance, api.chain);
})
);
})
);

return balances;
}

module.exports = {
timetravel: false,
methodology:
"Calculates the total value held by the Avatars of all deployed OGs modules",
ethereum: {
tvl,
},
polygon: {
tvl,
},
avax: {
tvl,
},
arbitrum: {
tvl,
},
optimism: {
tvl,
},
xdai: {
tvl,
},
};
10 changes: 10 additions & 0 deletions projects/osnap/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const axios = require("axios");

async function getConfig(url) {
const { data: json } = await axios.get(url);
return json;
}

module.exports = {
getConfig,
};