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

Commit

Permalink
feat(rocket-pool): Remove duplicate positions, create positions (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Jul 18, 2022
1 parent cdc0cbd commit 9079a75
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 426 deletions.
22 changes: 0 additions & 22 deletions src/apps/rocket-pool/arbitrum/rocket-pool.balance-fetcher.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/apps/rocket-pool/arbitrum/rocket-pool.reth.token-fetcher.ts

This file was deleted.

96 changes: 39 additions & 57 deletions src/apps/rocket-pool/ethereum/rocket-pool.balance-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,72 @@
import { Inject } from '@nestjs/common';
import { drillBalance } from '~app-toolkit';

import { drillBalance } from '~app-toolkit';
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
import { isSupplied } from '~position/position.utils';
import { Network } from '~types/network.interface';
import { RocketPoolContractFactory } from '../contracts';
import { RocketPoolRethBalanceHelper } from '../helpers/rocket-pool.reth.balance-helper';

import { RocketPoolContractFactory } from '../contracts';
import { ROCKET_POOL_DEFINITION } from '../rocket-pool.definition';

const appId = ROCKET_POOL_DEFINITION.id;
const rplGroupId = ROCKET_POOL_DEFINITION.groups.rpl.id;
const network = Network.ETHEREUM_MAINNET;

const rocketTokenRPLAddress = '0xD33526068D116cE69F19A9ee46F0bd304F21A51f';
const rocketNodeStakingAddress = '0x3019227b2b8493e45Bf5d25302139c9a2713BF15';
const rocketDAONodeTrustedAddress = '0xb8e783882b11Ff4f6Cef3C501EA0f4b960152cc9';

@Register.BalanceFetcher(ROCKET_POOL_DEFINITION.id, network)
export class EthereumRocketPoolBalanceFetcher implements BalanceFetcher {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(RocketPoolContractFactory) private readonly rocketPoolContractFactory: RocketPoolContractFactory,
@Inject(RocketPoolRethBalanceHelper) private readonly rocketPoolRethBalanceHelper: RocketPoolRethBalanceHelper,
) {}

async getBalances(address: string) {
const rpl = (
await this.appToolkit.getAppTokenPositions({
appId,
network,
groupIds: [rplGroupId],
})
).find(token => token.address == rocketTokenRPLAddress)!;

return presentBalanceFetcherResponse([
{
label: 'Rocket Pool Protocol Token',
assets: [
...(await this.getWalletBalances(address)),
await this.getStakedBalance(address, rpl),
await this.getOracleDdaoBondBalance(address, rpl),
],
async getStakedBalances(address: string) {
return this.appToolkit.helpers.contractPositionBalanceHelper.getContractPositionBalances({
address,
appId: ROCKET_POOL_DEFINITION.id,
groupId: ROCKET_POOL_DEFINITION.groups.staking.id,
network: Network.ETHEREUM_MAINNET,
resolveBalances: async ({ address, contractPosition }) => {
const token = contractPosition.tokens.find(isSupplied)!;
const contract = this.rocketPoolContractFactory.rocketNodeStaking(contractPosition);
const balanceRaw = await contract.getNodeRPLStake(address);
const tokenBalance = drillBalance(token, balanceRaw.toString());
return [tokenBalance];
},
...(await this.rocketPoolRethBalanceHelper.getBalances(address)),
]);
});
}

async getWalletBalances(address: string) {
return await this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
async getOracleDaoBondBalances(address: string) {
return this.appToolkit.helpers.contractPositionBalanceHelper.getContractPositionBalances({
address,
appId: ROCKET_POOL_DEFINITION.id,
groupId: ROCKET_POOL_DEFINITION.groups.rpl.id,
groupId: ROCKET_POOL_DEFINITION.groups.oracleDaoBond.id,
network: Network.ETHEREUM_MAINNET,
resolveBalances: async ({ address, contractPosition }) => {
const token = contractPosition.tokens.find(isSupplied)!;
const contract = this.rocketPoolContractFactory.rocketDaoNodeTrusted(contractPosition);
const balanceRaw = await contract.getMemberRPLBondAmount(address);
const tokenBalance = drillBalance(token, balanceRaw.toString());
return [tokenBalance];
},
});
}

async getStakedBalance(address: string, token: AppTokenPosition) {
const contract = this.rocketPoolContractFactory.rocketNodeStaking({ address: rocketNodeStakingAddress, network });
const balanceRaw = (await contract.getNodeRPLStake(address)).toString();
const tokenBalance = drillBalance(token as AppTokenPosition, balanceRaw);
return {
...tokenBalance,
displayProps: {
...tokenBalance.displayProps,
label: 'RPL Staked',
},
};
}
async getBalances(address: string) {
const [stakedBalances, oracleDaoBondBalances] = await Promise.all([
this.getStakedBalances(address),
this.getOracleDaoBondBalances(address),
]);

async getOracleDdaoBondBalance(address: string, token: AppTokenPosition) {
const contract = this.rocketPoolContractFactory.rocketDaoNodeTrusted({
address: rocketDAONodeTrustedAddress,
network,
});
const balanceRaw = (await contract.getMemberRPLBondAmount(address)).toString();
const tokenBalance = drillBalance(token as AppTokenPosition, balanceRaw);
return {
...tokenBalance,
displayProps: {
...tokenBalance.displayProps,
return presentBalanceFetcherResponse([
{
label: 'Staking',
assets: [...stakedBalances],
},
{
label: 'Oracle DAO Bond',
assets: [...oracleDaoBondBalances],
},
};
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { ContractType } from '~position/contract.interface';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { supplied } from '~position/position.utils';
import { Network } from '~types/network.interface';

import { ROCKET_POOL_DEFINITION } from '../rocket-pool.definition';

const appId = ROCKET_POOL_DEFINITION.id;
const groupId = ROCKET_POOL_DEFINITION.groups.oracleDaoBond.id;
const network = Network.ETHEREUM_MAINNET;
const rocketDAONodeTrustedAddress = '0xb8e783882b11ff4f6cef3c501ea0f4b960152cc9';
const rocketTokenRPLAddress = '0xd33526068d116ce69f19a9ee46f0bd304f21a51f';

@Register.ContractPositionFetcher({ appId, groupId, network })
export class EthereumRocketPoolOracleDaoBondContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {}

async getPositions() {
const baseTokens = await this.appToolkit.getBaseTokenPrices(network);
const rpl = baseTokens.find(v => v.address === rocketTokenRPLAddress)!;

const position: ContractPosition = {
type: ContractType.POSITION,
address: rocketDAONodeTrustedAddress,
network,
appId,
groupId,
tokens: [supplied(rpl)],
dataProps: {},
displayProps: {
label: `Oracle DAO Bond`,
images: getImagesFromToken(rpl),
},
};

return [position];
}
}
29 changes: 0 additions & 29 deletions src/apps/rocket-pool/ethereum/rocket-pool.reth.token-fetcher.ts

This file was deleted.

76 changes: 0 additions & 76 deletions src/apps/rocket-pool/ethereum/rocket-pool.rpl.token-fetcher.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { ContractType } from '~position/contract.interface';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { supplied } from '~position/position.utils';
import { Network } from '~types/network.interface';

import { ROCKET_POOL_DEFINITION } from '../rocket-pool.definition';

const appId = ROCKET_POOL_DEFINITION.id;
const groupId = ROCKET_POOL_DEFINITION.groups.staking.id;
const network = Network.ETHEREUM_MAINNET;
const rocketNodeStakingAddress = '0x3019227b2b8493e45bf5d25302139c9a2713bf15';
const rocketTokenRPLAddress = '0xd33526068d116ce69f19a9ee46f0bd304f21a51f';

@Register.ContractPositionFetcher({ appId, groupId, network })
export class EthereumRocketPoolStakingContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {}

async getPositions() {
const baseTokens = await this.appToolkit.getBaseTokenPrices(network);
const rpl = baseTokens.find(v => v.address === rocketTokenRPLAddress)!;

const position: ContractPosition = {
type: ContractType.POSITION,
address: rocketNodeStakingAddress,
network,
appId,
groupId,
tokens: [supplied(rpl)],
dataProps: {},
displayProps: {
label: `Staked ${rpl.symbol}`,
images: getImagesFromToken(rpl),
},
};

return [position];
}
}
Loading

0 comments on commit 9079a75

Please sign in to comment.