Skip to content

Commit

Permalink
tidy: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
linkielink committed Dec 13, 2024
1 parent 6b9c8a4 commit a8f7fd5
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/adaptors/mars-protocol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,42 @@ async function apy() {
await getApyDataForAsset(assetParams, chain);
} while (startAfter);

// fetch perps vault data
if (contractAddresses[chain].perps) {
async function getApyDataForPerpsVault(chain) {
if (!contractAddresses[chain].perps) return;

const perpsVault = await queryContract({
contract: contractAddresses[chain].perps,
chain,
data: { vault: {} },
});
const perpsDenomAsset = tokenInfos.data.find(
(token) => token.denom === perpsDenom[chain]
);
if (!perpsDenomAsset) return;
const perpsTotalBalance = new BigNumber(
perpsVault.total_balance
).shiftedBy(-perpsDenomAsset.decimals);

const perpsVaultApyData = await axios.get(perpsVaultApi[chain]);
const apyBase = perpsVaultApyData.data.projected_apy;
if (!apyBase) return;

apyData.push({
pool: `mars-cpv-${perpsDenom[chain]}-${chain}`.toLowerCase(),
symbol: 'USDC',
project: 'mars',
chain: `${chain.charAt(0).toUpperCase()}${chain.slice(1)}`,
tvlUsd: perpsTotalBalance.times(perpsDenomAsset.price).toNumber(),
apyBase,
poolMeta: '10 days unstaking',
url:
chain === 'osmosis'
? 'https://osmosis.marsprotocol.io/perps-vault/'
: 'https://neutron.marsprotocol.io/perps-vault/',
});
if (perpsVault && perpsVaultApyData) {
const perpsAsset = tokenInfos.data.find(
(token) => token.denom === perpsDenom[chain]
);
if (!perpsAsset) return;
const perpsTotalBalance = new BigNumber(
perpsVault['total_balance']
).shiftedBy(-perpsAsset.decimals);

const apyBase = perpsVaultApyData.data.projected_apy;
if (!apyBase) return;

apyData.push({
pool: `mars-cpv-${perpsDenom[chain]}-${chain}`.toLowerCase(),
symbol: 'USDC',
project: 'mars',
chain: `${chain.charAt(0).toUpperCase()}${chain.slice(1)}`,
tvlUsd: perpsTotalBalance.times(perpsAsset.price).toNumber(),
apyBase,
poolMeta: '10 days unstaking',
url:
chain === 'osmosis'
? 'https://osmosis.marsprotocol.io/perps-vault/'
: 'https://neutron.marsprotocol.io/perps-vault/',
});
}
}

async function getApyDataForAsset(assetParams, chain) {
Expand Down

0 comments on commit a8f7fd5

Please sign in to comment.