Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

fix(umami): Fix name/pps, add TVL/APR/APY #700

Merged
merged 5 commits into from
Jun 22, 2022
Merged
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
59 changes: 51 additions & 8 deletions src/apps/umami/arbitrum/umami.compound.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Inject } from '@nestjs/common';
import axios from 'axios';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present';
import {
buildDollarDisplayItem,
buildPercentageDisplayItem,
} from '~app-toolkit/helpers/presentation/display-item.present';
import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { CacheOnInterval } from '~cache/cache-on-interval.decorator';
import { ContractType } from '~position/contract.interface';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
Expand All @@ -16,13 +21,42 @@ const appId = UMAMI_DEFINITION.id;
const groupId = UMAMI_DEFINITION.groups.compound.id;
const network = Network.ARBITRUM_MAINNET;

type UmamiMarinateApiObject = {
apy: string;
};

type UmamiCompounderApiObject = {
tvl: number;
};

export type UmamiApiDatas = {
marinate: UmamiMarinateApiObject;
mUmamiCompounder: UmamiCompounderApiObject;
};

@Register.TokenPositionFetcher({ appId, groupId, network })
export class ArbitrumUmamiCompoundTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(UmamiContractFactory) private readonly umamiContractFactory: UmamiContractFactory,
) {}

@CacheOnInterval({
key: `studio:${network}:${appId}:${groupId}:informations`,
timeout: 15 * 60 * 1000,
})
async getUmamiInformations() {
const data = await axios.get<UmamiApiDatas>('https://horseysauce.xyz/').then(v => v.data);

const { marinate, mUmamiCompounder } = data;
const { apy } = marinate;
const { tvl } = mUmamiCompounder;
return {
apy,
tvl,
};
}

async getPositions() {
const mUMAMI_ADDRESS = '0x2AdAbD6E8Ce3e82f52d9998a7f64a90d294A92A4'.toLowerCase();
const cmUMAMI_ADDRESS = '0x1922C36F3bc762Ca300b4a46bB2102F84B1684aB'.toLowerCase();
Expand Down Expand Up @@ -52,16 +86,27 @@ export class ArbitrumUmamiCompoundTokenFetcher implements PositionFetcher<AppTok

if (!underlyingToken) return [];

const { apy, tvl } = await this.getUmamiInformations();

const supply = Number(supplyRaw) / 10 ** decimals;
const reserve = Number(balanceRaw) / 10 ** decimals;
const pricePerShare = reserve / supply;
const price = pricePerShare * underlyingToken.price;
const tokens = [underlyingToken];

const label = `Compounding Marinated UMAMI`;
const label = `Compounding Marinating UMAMI`;
const images = getImagesFromToken(underlyingToken);
const secondaryLabel = buildDollarDisplayItem(price);
const tertiaryLabel = `${pricePerShare}`;

const statsItems = [
{
label: 'Liquidity',
value: buildDollarDisplayItem(tvl),
},
{
label: 'APY',
value: buildPercentageDisplayItem(parseFloat(apy)),
},
];

const token: AppTokenPosition = {
type: ContractType.APP_TOKEN,
Expand All @@ -75,14 +120,12 @@ export class ArbitrumUmamiCompoundTokenFetcher implements PositionFetcher<AppTok
pricePerShare,
price,
tokens,
dataProps: {
pricePerShare: `${pricePerShare}`,
},
dataProps: {},
displayProps: {
label,
images,
secondaryLabel,
tertiaryLabel,
statsItems,
},
};
return [token];
Expand Down
47 changes: 46 additions & 1 deletion src/apps/umami/arbitrum/umami.marinate.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Inject } from '@nestjs/common';
import axios from 'axios';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present';
import {
buildDollarDisplayItem,
buildPercentageDisplayItem,
} from '~app-toolkit/helpers/presentation/display-item.present';
import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { CacheOnInterval } from '~cache/cache-on-interval.decorator';
import { ContractType } from '~position/contract.interface';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
Expand All @@ -16,13 +21,38 @@ const appId = UMAMI_DEFINITION.id;
const groupId = UMAMI_DEFINITION.groups.marinate.id;
const network = Network.ARBITRUM_MAINNET;

type UmamiMarinateApiObject = {
apr: string;
marinateTVL: string;
};

export type UmamiApiDatas = {
marinate: UmamiMarinateApiObject;
};

@Register.TokenPositionFetcher({ appId, groupId, network })
export class ArbitrumUmamiMarinateTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(UmamiContractFactory) private readonly umamiContractFactory: UmamiContractFactory,
) {}

@CacheOnInterval({
key: `studio:${network}:${appId}:${groupId}:informations`,
timeout: 15 * 60 * 1000,
})
async getUmamiInformations() {
const data = await axios.get<UmamiApiDatas>('https://horseysauce.xyz/').then(v => v.data);

const { marinate } = data;
const { apr, marinateTVL } = marinate;

return {
apr,
marinateTVL,
};
}

async getPositions() {
const UMAMI_ADDRESS = '0x1622bF67e6e5747b81866fE0b85178a93C7F86e3'.toLowerCase();
const mUMAMI_ADDRESS = '0x2AdAbD6E8Ce3e82f52d9998a7f64a90d294A92A4'.toLowerCase();
Expand All @@ -43,13 +73,27 @@ export class ArbitrumUmamiMarinateTokenFetcher implements PositionFetcher<AppTok
const baseTokenDependencies = await this.appToolkit.getBaseTokenPrices(network);
const underlyingToken = baseTokenDependencies.find(v => v.address === UMAMI_ADDRESS);
if (!underlyingToken) return [];

const { apr, marinateTVL } = await this.getUmamiInformations();

const tokens = [underlyingToken];
const pricePerShare = 1.0;
const price = pricePerShare * underlyingToken.price;
const label = `Marinating UMAMI`;
const images = getImagesFromToken(underlyingToken);
const secondaryLabel = buildDollarDisplayItem(price);

const statsItems = [
{
label: 'Liquidity',
value: buildDollarDisplayItem(parseFloat(marinateTVL)),
},
{
label: 'APR',
value: buildPercentageDisplayItem(parseFloat(apr)),
},
];
Clonescody marked this conversation as resolved.
Show resolved Hide resolved

const token: AppTokenPosition = {
type: ContractType.APP_TOKEN,
appId,
Expand All @@ -67,6 +111,7 @@ export class ArbitrumUmamiMarinateTokenFetcher implements PositionFetcher<AppTok
label,
images,
secondaryLabel,
statsItems,
},
};
return [token];
Expand Down
Binary file added src/apps/umami/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/apps/umami/umami.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Network } from '~types/network.interface';

export const UMAMI_DEFINITION = appDefinition({
id: 'umami',
name: 'umami',
name: 'Umami Finance',
description:
'Umami’s expanding menu of strategy vaults and staking options offers sustainable, risk-hedged passive income in WETH and USDC sourced from across Arbitrum’s DeFi ecosystem.',
url: 'https://umami.finance/',
Expand Down