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

Commit

Permalink
fix(balance): Remove dependencies on Studio implementations of Multic…
Browse files Browse the repository at this point in the history
…allService and PositionService (#873)

* fix(balance): Remove dependencies on Studio implementations of MulticallService and PositionService

* fix(balances): Dependencies
  • Loading branch information
immasandwich authored Jul 12, 2022
1 parent 094a6e8 commit 21aa047
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/balance/balance.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { DiscoveryModule } from '@nestjs/core';

import { AppToolkitModule } from '~app-toolkit/app-toolkit.module';
import { AppModule } from '~app/app.module';
import { MulticallModule } from '~multicall/multicall.module';
import { NetworkProviderModule } from '~network-provider/network-provider.module';
import { PositionModule } from '~position/position.module';

Expand All @@ -15,7 +15,7 @@ import { DefaultContractPositionBalanceFetcherFactory } from './default.contract
import { DefaultTokenBalanceFetcherFactory } from './default.token-balance-fetcher.factory';

@Module({
imports: [DiscoveryModule, MulticallModule, NetworkProviderModule, PositionModule, AppModule],
imports: [DiscoveryModule, PositionModule, NetworkProviderModule, AppModule, AppToolkitModule],
providers: [
BalanceFetcherRegistry,
BalancePresenterRegistry,
Expand Down
18 changes: 6 additions & 12 deletions src/balance/default.token-balance-fetcher.factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Inject, Injectable } from '@nestjs/common';

import { drillBalance } from '~app-toolkit';
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { ContractFactory } from '~contract';
import { MulticallService } from '~multicall/multicall.service';
import { NetworkProviderService } from '~network-provider/network-provider.service';
import { PositionBalanceFetcher } from '~position/position-balance-fetcher.interface';
import { AppTokenPositionBalance } from '~position/position-balance.interface';
import { PositionService } from '~position/position.service';
import { Network } from '~types';

type BuildTokenBalanceFetcherParams = {
Expand All @@ -20,24 +19,19 @@ export class DefaultTokenBalanceFetcherFactory {
private readonly contractFactory: ContractFactory;

constructor(
@Inject(PositionService) private readonly positionService: PositionService,
@Inject(MulticallService) private readonly multicallService: MulticallService,
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(NetworkProviderService) private readonly networkProviderService: NetworkProviderService,
) {
this.contractFactory = new ContractFactory((network: Network) => this.networkProviderService.getProvider(network));
}

build({ appId, groupId, network }: BuildTokenBalanceFetcherParams) {
const klass = class DefaultTokenBalanceFetcher implements PositionBalanceFetcher<AppTokenPositionBalance> {
constructor(
readonly positionService: PositionService,
readonly multicallService: MulticallService,
readonly contractFactory: ContractFactory,
) {}
constructor(readonly appToolkit: IAppToolkit, readonly contractFactory: ContractFactory) {}

async getBalances(address: string) {
const multicall = this.multicallService.getMulticall(network);
const tokens = await this.positionService.getAppTokenPositions({ network, appId, groupIds: [groupId] });
const multicall = this.appToolkit.getMulticall(network);
const tokens = await this.appToolkit.getAppTokenPositions({ network, appId, groupIds: [groupId] });

const tokenBalances = Promise.all(
tokens.map(async token => {
Expand All @@ -52,7 +46,7 @@ export class DefaultTokenBalanceFetcherFactory {
}
};

const instance = new klass(this.positionService, this.multicallService, this.contractFactory);
const instance = new klass(this.appToolkit, this.contractFactory);
return instance;
}
}

0 comments on commit 21aa047

Please sign in to comment.