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

Commit

Permalink
fix(multicall): Remove unnecessary multicall declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin committed Sep 28, 2023
1 parent dccb50a commit 2f01163
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/app-toolkit/app-toolkit.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IAppToolkit {

getNetworkProvider(network: Network): StaticJsonRpcProvider;

getMulticall(network: Network, batchSize: number): IMulticallWrapper;
getMulticall(network: Network, batchSize?: number): IMulticallWrapper;

// Base Tokens

Expand Down
2 changes: 1 addition & 1 deletion src/app-toolkit/app-toolkit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class AppToolkit implements IAppToolkit {
return this.networkProviderService.getProvider(network);
}

getMulticall(network: Network, batchSize: number) {
getMulticall(network: Network, batchSize = 250) {
return this.multicallService.getMulticall(network, batchSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MetaType } from '~position/position.interface';
import { isSupplied } from '~position/position.utils';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
GetDefinitionsParams,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
Expand Down Expand Up @@ -38,8 +39,7 @@ export abstract class AcrossStakingContractPositionFetcher extends ContractPosit
return this.contractFactory.acrossStaking({ address, network: this.network });
}

async getDefinitions(): Promise<AcrossStakingContractPositionDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<AcrossStakingContractPositionDefinition[]> {
const appTokens = await this.appToolkit.getAppTokenPositions({
appId: this.appId,
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DefaultDataProps } from '~position/display.interface';
import { MetaType } from '~position/position.interface';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
GetDefinitionsParams,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
Expand Down Expand Up @@ -40,8 +41,7 @@ export class EthereumCleverFarmingContractPositionFetcher extends ContractPositi
return this.contractFactory.cleverGauge({ address, network: this.network });
}

async getDefinitions(): Promise<CleverFarmingContractPositionDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<CleverFarmingContractPositionDefinition[]> {
const gaugeAddresses = [
'0xc5022291ca8281745d173bb855dcd34dda67f2f0', // abcCVX
'0x86e917ad6cb44f9e6c8d9fa012acf0d0cfcf114f', // CLEV/ETH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MetaType } from '~position/position.interface';
import { isSupplied } from '~position/position.utils';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
GetDefinitionsParams,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
Expand Down Expand Up @@ -44,8 +45,7 @@ export class PolygonConvexLpFarmContractPositionFetcher extends ContractPosition
return this.contractFactory.convexRewardPool({ address, network: this.network });
}

async getDefinitions(): Promise<ConvexLpFarmDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<ConvexLpFarmDefinition[]> {
const depositContract = this.contractFactory.convexBoosterSidechain({
address: this.boosterContractAddress,
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ export abstract class DolomiteContractPositionTemplatePositionFetcher extends Cu
async getDataProps(
params: GetDataPropsParams<DolomiteMargin, DolomiteDataProps, DolomiteContractPositionDefinition>,
): Promise<DolomiteDataProps> {
const multicall = this.appToolkit.getMulticall(this.network);
return mapTokensToDolomiteDataProps(params, this.isFetchingDolomiteBalances(), multicall);
return mapTokensToDolomiteDataProps(params, this.isFetchingDolomiteBalances(), params.multicall);
}

async getLabel(_params: GetDisplayPropsParams<DolomiteMargin>): Promise<string> {
Expand Down
7 changes: 3 additions & 4 deletions src/apps/gearbox/ethereum/gearbox.lending.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePosition
async getLiquidity(
params: GetDataPropsParams<DieselToken, DefaultAppTokenDataProps, GearboxLendingDefinition>,
): Promise<number> {
const multicall = this.appToolkit.getMulticall(network);
const poolContract = this._getPoolContract(params.definition);
const [liquidity, underlyingToken] = await Promise.all([
multicall.wrap(poolContract).expectedLiquidity(),
multicall.wrap(poolContract).underlyingToken(),
params.multicall.wrap(poolContract).expectedLiquidity(),
params.multicall.wrap(poolContract).underlyingToken(),
]);
const underlyingTokenDecimals = await this.gearboxContractFactory
.erc20({ address: underlyingToken, network })
Expand All @@ -105,8 +104,8 @@ export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePosition
async getPricePerShare({
contract: dieselTokenContract,
definition,
multicall,
}: GetPricePerShareParams<DieselToken, DefaultAppTokenDataProps, GearboxLendingDefinition>) {
const multicall = this.appToolkit.getMulticall(network);
const poolContract = this._getPoolContract(definition);

const [underlying, underlyingToken, dieselTokenTotalSupply, dieselTokenDecimals] = await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DefaultDataProps } from '~position/display.interface';
import { MetaType } from '~position/position.interface';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
GetDefinitionsParams,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
Expand Down Expand Up @@ -39,8 +40,7 @@ export class EthereumIdleBestYieldContractPositionFetcher extends ContractPositi
return this.contractFactory.idleToken({ address, network: this.network });
}

async getDefinitions(): Promise<IdleBestYieldTokenDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<IdleBestYieldTokenDefinition[]> {
const appTokens = await this.appToolkit.getAppTokenPositions({
appId: this.appId,
groupIds: ['vault'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isClaimable } from '~position/position.utils';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
GetDataPropsParams,
GetDefinitionsParams,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
Expand Down Expand Up @@ -69,9 +70,7 @@ export class EthereumInverseFirmLoanContractPositionFetcher extends ContractPosi
return this.contractFactory.simpleMarket({ network: this.network, address });
}

async getDefinitions(): Promise<InverseFirmLoanContractPositionDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);

async getDefinitions({ multicall }: GetDefinitionsParams): Promise<InverseFirmLoanContractPositionDefinition[]> {
const dolaBorrowRightContract = this.contractFactory.dbr({
address: this.dbrAddress,
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DefaultAppTokenDataProps,
DefaultAppTokenDefinition,
GetAddressesParams,
GetDefinitionsParams,
GetPricePerShareParams,
GetUnderlyingTokensParams,
UnderlyingTokenDefinition,
Expand Down Expand Up @@ -42,8 +43,7 @@ export class PolygonMetavaultTradeMvlpTokenFetcher extends AppTokenTemplatePosit
return this.contractFactory.erc20({ network: this.network, address });
}

async getDefinitions(): Promise<MetavaultTradeMvlpTokenDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<MetavaultTradeMvlpTokenDefinition[]> {
const mvlpManagerContract = this.contractFactory.metavaultTradeMvlpManager({
address: this.mvlpManagerAddress,
network: this.network,
Expand Down
4 changes: 2 additions & 2 deletions src/apps/mycelium/arbitrum/mycelium.mlp.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DefaultAppTokenDataProps,
DefaultAppTokenDefinition,
GetAddressesParams,
GetDefinitionsParams,
GetPricePerShareParams,
GetUnderlyingTokensParams,
UnderlyingTokenDefinition,
Expand Down Expand Up @@ -42,8 +43,7 @@ export class ArbitrumMyceliumMlpTokenFetcher extends AppTokenTemplatePositionFet
return this.contractFactory.erc20({ network: this.network, address });
}

async getDefinitions(): Promise<MyceliumMlpTokenDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<MyceliumMlpTokenDefinition[]> {
const mlpManagerContract = this.contractFactory.myceliumMlpManager({
address: this.mlpManagerAddress,
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { compact, range } from 'lodash';
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { ZERO_ADDRESS } from '~app-toolkit/constants/address';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { GetDefinitionsParams } from '~position/template/app-token.template.types';
import {
GetMasterChefDataPropsParams,
GetMasterChefTokenBalancesParams,
MasterChefContractPositionDefinition,
MasterChefTemplateContractPositionFetcher,
} from '~position/template/master-chef.template.contract-position-fetcher';

Expand All @@ -31,8 +33,7 @@ export class BinanceSmartChainPancakeSwapBoostedFarmV2ContractPositionFetcher ex
return this.contractFactory.pancakeswapChefV2({ address, network: this.network });
}

async getDefinitions() {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<MasterChefContractPositionDefinition[]> {
const chefV2 = this.contractFactory.pancakeswapChefV2({ address: this.chefAddress, network: this.network });
const poolLength = await chefV2.poolLength();

Expand Down
6 changes: 4 additions & 2 deletions src/apps/phuture/common/phuture.index.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DefaultAppTokenDataProps,
GetDataPropsParams,
GetDisplayPropsParams,
GetUnderlyingTokensParams,
} from '~position/template/app-token.template.types';

import { PhutureContractFactory, PhutureManagedIndex } from '../contracts';
Expand Down Expand Up @@ -38,8 +39,9 @@ export abstract class PhutureIndexTokenFetcher extends AppTokenTemplatePositionF
return [this.managerAddress];
}

async getUnderlyingTokenDefinitions() {
const multicall = this.appToolkit.getMulticall(this.network);
async getUnderlyingTokenDefinitions({
multicall,
}: GetUnderlyingTokensParams<PhutureManagedIndex, PhutureIndexAppTokenDefinition>) {
const managerContract = this.contractFactory.phutureManagedIndex({
address: this.managerAddress,
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export class OptimismPikaProtocolV3VaultContractPositionFetcher extends Contract
return `Staked ${getLabelFromToken(contractPosition.tokens[0])}`;
}

async getTokenBalancesPerPosition({ address, contract }: GetTokenBalancesParams<PikaProtocolV3Vault>) {
const multicall = this.appToolkit.getMulticall(this.network);
async getTokenBalancesPerPosition({ address, contract, multicall }: GetTokenBalancesParams<PikaProtocolV3Vault>) {
const rewardContract = this.contractFactory.pikaProtocolV3Rewards({
address: '0x939c11c596b851447e5220584d37f12854ba02ae',
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export class OptimismPikaProtocolVaultContractPositionFetcher extends ContractPo
return `Staked ${getLabelFromToken(contractPosition.tokens[0])}`;
}

async getTokenBalancesPerPosition({ address, contract }: GetTokenBalancesParams<PikaProtocolVault>) {
const multicall = this.appToolkit.getMulticall(this.network);
async getTokenBalancesPerPosition({ address, contract, multicall }: GetTokenBalancesParams<PikaProtocolVault>) {
const rewardContract = this.contractFactory.pikaProtocolVaultReward({
address: '0x58488bb666d2da33f8e8938dbdd582d2481d4183',
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { ZERO_ADDRESS } from '~app-toolkit/constants/address';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { DefaultDataProps } from '~position/display.interface';
import { MetaType } from '~position/position.interface';
import { GetDisplayPropsParams, GetTokenDefinitionsParams } from '~position/template/contract-position.template.types';
import {
GetDefinitionsParams,
GetDisplayPropsParams,
GetTokenDefinitionsParams,
} from '~position/template/contract-position.template.types';

import { VotingRewardsContractPositionFetcher } from '../common/ramses.voting-rewards.contract-position-fetcher';
import { RamsesBribe } from '../contracts';
Expand All @@ -23,14 +27,13 @@ export class ArbitrumRamsesBribeContractPositionFetcher extends VotingRewardsCon
return this.contractFactory.ramsesBribe({ address, network: this.network });
}

async getDefinitions(): Promise<RamsesBribeDefinition[]> {
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<RamsesBribeDefinition[]> {
const pools = await this.appToolkit.getAppTokenPositions({
appId: this.appId,
network: this.network,
groupIds: ['pool'],
});

const multicall = this.appToolkit.getMulticall(this.network);
const ramsesVoter = this.contractFactory.ramsesVoter({ network: this.network, address: this.voterAddress });

const gauges = await Promise.all(pools.map(p => multicall.wrap(ramsesVoter).gauges(p.address)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ export class EthereumReserveProtocolCooldownContractPositionFetcher extends Cont
return getLabelFromToken(contractPosition.tokens[0]);
}

async getTokenBalancesPerPosition({ address, contract }: GetTokenBalancesParams<StakedRsr>): Promise<BigNumberish[]> {
async getTokenBalancesPerPosition({
address,
contract,
multicall,
}: GetTokenBalancesParams<StakedRsr>): Promise<BigNumberish[]> {
// Get FacadeRead
const multicall = this.appToolkit.getMulticall(this.network);
const facadeRead = multicall.wrap(
this.contractFactory.facadeRead({
network: this.network,
Expand Down
4 changes: 2 additions & 2 deletions src/apps/sentiment/arbitrum/sentiment.supply.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.te
import {
DefaultAppTokenDataProps,
GetAddressesParams,
GetDefinitionsParams,
GetDisplayPropsParams,
GetPricePerShareParams,
GetUnderlyingTokensParams,
Expand Down Expand Up @@ -39,8 +40,7 @@ export class ArbitrumSentimentSupplyTokenFetcher extends AppTokenTemplatePositio
return this.contractFactory.sentimentLToken({ network: this.network, address });
}

async getDefinitions(): Promise<SentimentSupplyAppTokenDefinition[]> {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<SentimentSupplyAppTokenDefinition[]> {
const registryContract = this.contractFactory.sentimentRegistry({
address: '0x17b07cfbab33c0024040e7c299f8048f4a49679b',
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { PositionTemplate } from '~app-toolkit/decorators/position-template.deco
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import {
DefaultAppTokenDefinition,
GetAddressesParams,
GetDefinitionsParams,
GetDisplayPropsParams,
GetPricePerShareParams,
GetUnderlyingTokensParams,
Expand All @@ -30,8 +32,7 @@ export class OptimismVelodromeV2PoolTokenFetcher extends AppTokenTemplatePositio
return this.contractFactory.velodromeV2Pool({ address, network: this.network });
}

async getDefinitions() {
const multicall = this.appToolkit.getMulticall(this.network);
async getDefinitions({ multicall }: GetDefinitionsParams): Promise<DefaultAppTokenDefinition[]> {
const factoryContract = this.contractFactory.velodromeV2PoolFactory({
address: '0xf1046053aa5682b4f9a81b5481394da16be5ff5a',
network: this.network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export abstract class VendorFinancePoolV2ContractPositionFetcher extends Contrac
async getTokenBalancesPerPosition({
address,
contractPosition,
multicall,
}: GetTokenBalancesParams<VendorFinancePoolV2, VendorFinancePoolDataProps>) {
const collateralToken = contractPosition.tokens[0]!;
const lentToken = contractPosition.tokens[1]!;
Expand All @@ -148,7 +149,6 @@ export abstract class VendorFinancePoolV2ContractPositionFetcher extends Contrac

// --- Borrower logic ----
const startKey = '0x'.padEnd(66, '0');
const multicall = this.appToolkit.getMulticall(this.network);
const positionTracker = multicall.wrap(
this.contractFactory.vendorFinancePositionTracker({
address: this.positionTrackerAddr,
Expand Down
10 changes: 6 additions & 4 deletions src/position/template/app-token.template.position-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export abstract class AppTokenTemplatePositionFetcher<

minLiquidity = 1000;

batchSize = 250;

constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) {}

// 1. Get token contract instance
Expand Down Expand Up @@ -160,7 +162,7 @@ export abstract class AppTokenTemplatePositionFetcher<
}

async getPositionsForBatch(definitions: R[]) {
const multicall = this.appToolkit.getMulticall(this.network);
const multicall = this.appToolkit.getMulticall(this.network, this.batchSize);
const tokenLoader = this.appToolkit.getTokenDependencySelector({
tags: { network: this.network, context: `${this.appId}__template` },
});
Expand Down Expand Up @@ -312,7 +314,7 @@ export abstract class AppTokenTemplatePositionFetcher<
// Default (adapted) Template Runner
// Note: This will be removed in favour of an orchestrator at a higher level once all groups are migrated
async getPositions(): Promise<AppTokenPosition<V>[]> {
const multicall = this.appToolkit.getMulticall(this.network);
const multicall = this.appToolkit.getMulticall(this.network, this.batchSize);
const tokenLoader = this.appToolkit.getTokenDependencySelector({
tags: { network: this.network, context: `${this.appId}__template` },
});
Expand Down Expand Up @@ -346,7 +348,7 @@ export abstract class AppTokenTemplatePositionFetcher<
}

async getBalances(_address: string): Promise<AppTokenPositionBalance<V>[]> {
const multicall = this.appToolkit.getMulticall(this.network);
const multicall = this.appToolkit.getMulticall(this.network, this.batchSize);
const address = await this.getAccountAddress(_address);
const appTokens = await this.getPositionsForBalances();
if (address === ZERO_ADDRESS) return [];
Expand All @@ -363,7 +365,7 @@ export abstract class AppTokenTemplatePositionFetcher<
}

async getRawBalances(_address: string): Promise<RawAppTokenBalance[]> {
const multicall = this.appToolkit.getMulticall(this.network);
const multicall = this.appToolkit.getMulticall(this.network, this.batchSize);
const address = await this.getAccountAddress(_address);
if (address === ZERO_ADDRESS) return [];

Expand Down
Loading

0 comments on commit 2f01163

Please sign in to comment.