Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MEX-527] Bulk get methods #1535

Open
wants to merge 4 commits into
base: feat/memory-store
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/modules/farm/base-module/services/farm.abi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ export class FarmAbiService
return response.firstValue.valueOf().toString();
}

async getAllFarmingTokenIds(farmAddresses: string[]): Promise<string[]> {
return await getAllKeys<string>(
this.cacheService,
farmAddresses,
'farm.farmingTokenID',
this.farmingTokenID.bind(this),
CacheTtlInfo.Token,
);
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand Down
7 changes: 2 additions & 5 deletions src/modules/farm/base-module/services/farm.base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,10 @@ export abstract class FarmServiceBase {
}

async getAllFarmingTokens(farmAddresses: string[]): Promise<EsdtToken[]> {
const farmingTokenIDs = await getAllKeys<string>(
this.cachingService,
const farmingTokenIDs = await this.farmAbi.getAllFarmingTokenIds(
farmAddresses,
'farm.farmingTokenID',
this.farmAbi.farmingTokenID.bind(this.farmAbi),
CacheTtlInfo.Token,
);

return this.tokenService.getAllTokensMetadata(farmingTokenIDs);
}

Expand Down
21 changes: 21 additions & 0 deletions src/modules/farm/v2/services/farm.v2.compute.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { WeeklyRewardsSplittingComputeService } from 'src/submodules/weekly-rewa
import { IFarmComputeServiceV2 } from './interfaces';
import { WeekTimekeepingAbiService } from 'src/submodules/week-timekeeping/services/week-timekeeping.abi.service';
import { computeValueUSD } from 'src/utils/token.converters';
import { getAllKeys } from 'src/utils/get.many.utils';

@Injectable()
export class FarmComputeServiceV2
Expand Down Expand Up @@ -98,6 +99,16 @@ export class FarmComputeServiceV2
.toFixed();
}

async getAllBaseAPR(farmAddresses: string[]): Promise<string[]> {
return await getAllKeys<string>(
this.cachingService,
farmAddresses,
'farm.farmBaseAPR',
this.farmBaseAPR.bind(this),
CacheTtlInfo.ContractState,
);
}

async computeMintedRewards(farmAddress: string): Promise<BigNumber> {
const [toBeMinted, boostedYieldsRewardsPercenatage] = await Promise.all(
[
Expand Down Expand Up @@ -620,4 +631,14 @@ export class FarmComputeServiceV2

return bnRawMaxBoostedApr.toFixed();
}

async getAllMaxBoostedAPR(farmAddresses: string[]): Promise<string[]> {
return await getAllKeys<string>(
this.cachingService,
farmAddresses,
'farm.maxBoostedApr',
this.maxBoostedApr.bind(this),
CacheTtlInfo.ContractState,
);
}
}
10 changes: 10 additions & 0 deletions src/modules/pair/mocks/pair.abi.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ export class PairAbiServiceMock implements IPairAbiService {
async firstTokenID(pairAddress: string): Promise<string> {
return PairsData(pairAddress).firstToken.identifier;
}
async getAllFirstTokenID(pairAddresses: string[]): Promise<string[]> {
return pairAddresses.map(
(pairAddress) => PairsData(pairAddress).firstToken.identifier,
);
}
async secondTokenID(pairAddress: string): Promise<string> {
return PairsData(pairAddress).secondToken.identifier;
}
async getAllSecondTokenID(pairAddresses: string[]): Promise<string[]> {
return pairAddresses.map(
(pairAddress) => PairsData(pairAddress).secondToken.identifier,
);
}
async lpTokenID(pairAddress: string): Promise<string> {
return PairsData(pairAddress)?.liquidityPoolToken.identifier;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/pair/pair.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class PairResolver {

@ResolveField()
async feesUSD24h(@Parent() parent: PairModel): Promise<string> {
return this.pairCompute.feesUSD(parent.address, '24h');
return this.pairComputeLoader.feesUSD24hLoader.load(parent.address);
}

@ResolveField()
Expand Down
16 changes: 2 additions & 14 deletions src/modules/pair/services/pair.abi.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ export class PairAbiLoader {

public readonly totalFeePercentLoader = new DataLoader<string, number>(
async (addresses: string[]) => {
return getAllKeys<number>(
this.cacheService,
addresses,
'pair.totalFeePercent',
this.pairAbi.totalFeePercent.bind(this.pairAbi),
CacheTtlInfo.ContractState,
);
return this.pairAbi.getAllTotalFeePercent(addresses);
},
{
cache: false,
Expand All @@ -75,13 +69,7 @@ export class PairAbiLoader {

public readonly specialFeePercentLoader = new DataLoader<string, number>(
async (addresses: string[]) => {
return getAllKeys<number>(
this.cacheService,
addresses,
'pair.specialFeePercent',
this.pairAbi.specialFeePercent.bind(this.pairAbi),
CacheTtlInfo.ContractState,
);
return this.pairAbi.getAllSpecialFeePercent(addresses);
},
{
cache: false,
Expand Down
40 changes: 40 additions & 0 deletions src/modules/pair/services/pair.abi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export class PairAbiService
return response.firstValue.valueOf().toString();
}

async getAllFirstTokenID(pairAddresses: string[]): Promise<string[]> {
return await getAllKeys<string>(
this.cachingService,
pairAddresses,
'pair.firstTokenID',
this.firstTokenID.bind(this),
CacheTtlInfo.Token,
);
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand All @@ -85,6 +95,16 @@ export class PairAbiService
return response.firstValue.valueOf().toString();
}

async getAllSecondTokenID(pairAddresses: string[]): Promise<string[]> {
return await getAllKeys<string>(
this.cachingService,
pairAddresses,
'pair.secondTokenID',
this.secondTokenID.bind(this),
CacheTtlInfo.Token,
);
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand Down Expand Up @@ -241,6 +261,16 @@ export class PairAbiService
return response.firstValue.valueOf().toNumber();
}

async getAllTotalFeePercent(pairAddresses: string[]): Promise<number[]> {
return await getAllKeys<number>(
this.cachingService,
pairAddresses,
'pair.totalFeePercent',
this.totalFeePercent.bind(this),
CacheTtlInfo.ContractState,
);
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand All @@ -267,6 +297,16 @@ export class PairAbiService
return response.firstValue.valueOf().toNumber();
}

async getAllSpecialFeePercent(pairAddresses: string[]): Promise<number[]> {
return await getAllKeys<number>(
this.cachingService,
pairAddresses,
'pair.specialFeePercent',
this.specialFeePercent.bind(this),
CacheTtlInfo.ContractState,
);
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand Down
17 changes: 10 additions & 7 deletions src/modules/pair/services/pair.compute.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ export class PairComputeLoader {
},
);

public readonly feesUSD24hLoader = new DataLoader<string, string>(
async (addresses: string[]) => {
return await this.pairCompute.getAllFeesUSD(addresses);
},
{
cache: false,
},
);

public readonly previous24hFeesUSDLoader = new DataLoader<string, string>(
async (addresses: string[]) => {
return await getAllKeys(
Expand Down Expand Up @@ -206,13 +215,7 @@ export class PairComputeLoader {

public readonly typeLoader = new DataLoader<string, string>(
async (addresses: string[]) => {
return await getAllKeys(
this.cacheService,
addresses,
'pair.type',
this.pairCompute.type.bind(this.pairCompute),
CacheTtlInfo.ContractState,
);
return await this.pairCompute.getAllType(addresses);
},
{
cache: false,
Expand Down
Loading
Loading