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

Commit

Permalink
feat(sushiswap): Add xSUSHI and Meowshi dependencies on dependees (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich committed Jun 28, 2022
1 parent fa9c8b9 commit 600e10b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/apps/aave-v2/polygon/aave-v2.supply.token-fetcher.ts
Expand Up @@ -22,6 +22,7 @@ export class PolygonAaveV2SupplyTokenFetcher implements PositionFetcher<AppToken
appId,
groupId,
network,
dependencies: [{ appId: 'sushiswap', groupIds: ['x-sushi'], network }],
protocolDataProviderAddress: '0x7551b5d2763519d4e37e8b81929d336de671d46d',
resolveTokenAddress: ({ reserveTokenAddressesData }) => reserveTokenAddressesData.aTokenAddress,
resolveLendingRate: ({ reserveData }) => reserveData.liquidityRate,
Expand Down
Expand Up @@ -25,7 +25,10 @@ export class EthereumBadgerClaimableContractPositionFetcher implements PositionF
appId,
groupId,
network,
dependencies: [{ appId: BADGER_DEFINITION.id, groupIds: [BADGER_DEFINITION.groups.vault.id], network }],
dependencies: [
{ appId: BADGER_DEFINITION.id, groupIds: [BADGER_DEFINITION.groups.vault.id], network },
{ appId: 'sushiswap', groupIds: ['x-sushi'], network },
],
rewardTokenAddresses: [
'0x3472a5a71965499acd81997a54bba8d852c6e53d',
'0x8798249c2e607446efb7ad49ec89dd1865ff4272',
Expand Down
Expand Up @@ -45,6 +45,7 @@ export class EthereumBancorV3TokenFetcher implements PositionFetcher<AppTokenPos
appId,
groupId,
network,
dependencies: [{ appId: 'sushiswap', groupIds: ['x-sushi'], network }],
resolveVaultAddresses: () => vaults,
resolveContract: ({ address, network }) => this.contractFactory.poolToken({ address, network }),
resolveUnderlyingTokenAddress: ({ multicall, contract }) =>
Expand Down
Expand Up @@ -43,6 +43,7 @@ export class EthereumRariFuseSupplyTokenFetcher implements PositionFetcher<AppTo
},
{ appId: OLYMPUS_DEFINITION.id, groupIds: [OLYMPUS_DEFINITION.groups.gOhm.id], network },
{ appId: 'mstable', groupIds: ['imusd'], network },
{ appId: 'sushiswap', groupIds: ['x-sushi'], network },
);

const markets = await Promise.all(
Expand Down
Expand Up @@ -24,6 +24,7 @@ export class EthereumSushiSwapBentoBoxContractPositionFetcher implements Positio
bentoBoxAddress: '0xf5bce5077908a1b7370b9ae04adc565ebd643966',
network,
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox',
dependencies: [{ appId: 'sushiswap', groupIds: ['x-sushi', 'meowshi'], network }],
});
}
}
Expand Up @@ -9,6 +9,7 @@ import { getTokenImg } from '~app-toolkit/helpers/presentation/image.present';
import { Cache } from '~cache/cache.decorator';
import { ContractType } from '~position/contract.interface';
import { ContractPosition } from '~position/position.interface';
import { AppGroupsDefinition } from '~position/position.service';
import { supplied } from '~position/position.utils';
import { Network } from '~types/network.interface';

Expand All @@ -33,6 +34,7 @@ type SushiswapBentoBoxGetPositionParams = {
bentoBoxAddress: string;
network: Network;
subgraphUrl: string;
dependencies?: AppGroupsDefinition[];
};

const appId = SUSHISWAP_BENTOBOX_DEFINITION.id;
Expand All @@ -57,9 +59,11 @@ export class SushiSwapBentoBoxContractPositionHelper {
return response.tokens ?? [];
}

async getPositions({ bentoBoxAddress, network, subgraphUrl }: SushiswapBentoBoxGetPositionParams) {
async getPositions({ bentoBoxAddress, network, subgraphUrl, dependencies = [] }: SushiswapBentoBoxGetPositionParams) {
const multicall = this.appToolkit.getMulticall(network);
const prices = await this.appToolkit.getBaseTokenPrices(network);
const baseTokens = await this.appToolkit.getBaseTokenPrices(network);
const appTokens = await this.appToolkit.getAppTokenPositions(...dependencies);
const allTokens = [...appTokens, ...baseTokens];

// Get all configured tokens in this Bentobox
const bentoBoxTokens = await this.getBentoBoxTokens({ url: subgraphUrl, network });
Expand All @@ -68,29 +72,29 @@ export class SushiSwapBentoBoxContractPositionHelper {
bentoBoxTokens.map(async token => {
const tokenAddress = token.id.toLowerCase();

const baseToken = prices.find(p => p.address === tokenAddress);
if (!baseToken) return null;
const underlyingToken = allTokens.find(p => p.address === tokenAddress);
if (!underlyingToken) return null;

const tokenContract = this.sushiSwapBentoBoxContractFactory.erc20({ address: tokenAddress, network });
const balanceOfRaw = await multicall.wrap(tokenContract).balanceOf(bentoBoxAddress);
const balanceOf = Number(balanceOfRaw) / 10 ** baseToken.decimals;
const liquidity = balanceOf * baseToken.price;
const balanceOf = Number(balanceOfRaw) / 10 ** underlyingToken.decimals;
const liquidity = balanceOf * underlyingToken.price;

const position: ContractPosition = {
type: ContractType.POSITION,
address: bentoBoxAddress,
network,
address: baseToken.address,
appId,
groupId,
tokens: [supplied(baseToken)],
tokens: [supplied(underlyingToken)],
dataProps: {
liquidity,
},
displayProps: {
statsItems: [{ label: 'Liquidity', value: buildDollarDisplayItem(liquidity) }],
label: `${baseToken.symbol} Deposit`,
secondaryLabel: buildDollarDisplayItem(baseToken.price),
images: [getTokenImg(baseToken.address, network)],
label: `${underlyingToken.symbol} Deposit`,
secondaryLabel: buildDollarDisplayItem(underlyingToken.price),
images: [getTokenImg(underlyingToken.address, network)],
},
};

Expand Down

0 comments on commit 600e10b

Please sign in to comment.