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

fix: refactored solace's helpers to be injectable + enabled solace TVL #692

Merged
merged 3 commits into from
Jun 23, 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
47 changes: 0 additions & 47 deletions src/apps/solace/ethereum/helpers/getBondBalance.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/apps/solace/ethereum/helpers/getPolicyBalance.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/apps/solace/ethereum/helpers/getScpBalance.ts

This file was deleted.

55 changes: 0 additions & 55 deletions src/apps/solace/ethereum/helpers/getXSLockerBalance.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/apps/solace/ethereum/helpers/getXSolaceV1Balance.ts

This file was deleted.

92 changes: 74 additions & 18 deletions src/apps/solace/ethereum/solace.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,94 @@ import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { Network } from '~types/network.interface';

import { SolaceContractFactory } from '../contracts';
import { SolaceBondBalanceHelper } from '../helpers/SolaceBondBalanceHelper';
import { SolacePolicyBalanceHelper } from '../helpers/SolacePolicyBalanceHelper';
import { SolaceXSBalanceHelper } from '../helpers/SolaceXSBalanceHelper';
import { SOLACE_DEFINITION } from '../solace.definition';

import getBondBalance from './helpers/getBondBalance';
import getPolicyBalance from './helpers/getPolicyBalance';
import getScpBalance from './helpers/getScpBalance';
import getXSLockerBalance from './helpers/getXSLockerBalance';
import getXSolaceV1Balance from './helpers/getXSolaceV1Balance';

const network = Network.ETHEREUM_MAINNET;

@Register.BalanceFetcher(SOLACE_DEFINITION.id, network)
export class EthereumSolaceBalanceFetcher implements BalanceFetcher {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(SolaceContractFactory) private readonly solaceContractFactory: SolaceContractFactory,
@Inject(SolaceBondBalanceHelper)
private readonly solaceBondBalanceHelper: SolaceBondBalanceHelper,
@Inject(SolacePolicyBalanceHelper)
private readonly solacePolicyBalanceHelper: SolacePolicyBalanceHelper,
@Inject(SolaceXSBalanceHelper)
private readonly solaceXSBalanceHelper: SolaceXSBalanceHelper,
) {}

async getScpBalance(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
address,
appId: SOLACE_DEFINITION.id,
groupId: SOLACE_DEFINITION.groups.scp.id,
network,
});
}

async getXSolaceV1Balance(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
address,
appId: SOLACE_DEFINITION.id,
groupId: SOLACE_DEFINITION.groups.xsolacev1.id,
network,
});
}

async getXSLockerBalance(address: string) {
return this.solaceXSBalanceHelper.getBalances({
address,
network,
});
}

async getBondBalance(address: string) {
return this.solaceBondBalanceHelper.getBalances({
address,
network,
});
}

async getPolicyBalance(address: string) {
return this.solacePolicyBalanceHelper.getBalances({
address,
network,
});
}

async getBalances(address: string) {
const [scpBal, xsolaceBal, xslockerBal, bondBal, policyBal] = await Promise.all([
getScpBalance(address, this.appToolkit),
getXSolaceV1Balance(address, this.appToolkit),
getXSLockerBalance(address, this.appToolkit, this.solaceContractFactory),
getBondBalance(address, this.appToolkit, this.solaceContractFactory),
getPolicyBalance(address, this.appToolkit, this.solaceContractFactory),
this.getScpBalance(address),
this.getXSolaceV1Balance(address),
this.getXSLockerBalance(address),
this.getBondBalance(address),
this.getPolicyBalance(address),
]);

return presentBalanceFetcherResponse([
{ label: 'SCP', assets: scpBal },
{ label: 'xSOLACEv1', assets: xsolaceBal },
{ label: 'xsLocker', assets: xslockerBal },
{ label: 'Bonds', assets: bondBal },
{ label: 'Policies', assets: policyBal },
{
label: 'SCP',
assets: scpBal,
},
{
label: 'xSOLACEv1',
assets: xsolaceBal,
},
{
label: 'xsLocker',
assets: xslockerBal,
},
{
label: 'Bonds',
assets: bondBal,
},
{
label: 'Policies',
assets: policyBal,
},
]);
}
}
Loading