-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1452 from multiversx/MEX-509-farms-data-loader
[MEX-509] Farms data loader
- Loading branch information
Showing
34 changed files
with
644 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/modules/farm/base-module/services/farm.abi.loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { Injectable, Scope } from '@nestjs/common'; | ||
import { FarmServiceBase } from './farm.base.service'; | ||
import DataLoader from 'dataloader'; | ||
import { EsdtToken } from 'src/modules/tokens/models/esdtToken.model'; | ||
import { NftCollection } from 'src/modules/tokens/models/nftCollection.model'; | ||
import { FarmAbiService } from './farm.abi.service'; | ||
import { CacheService } from '@multiversx/sdk-nestjs-cache'; | ||
import { getAllKeys } from 'src/utils/get.many.utils'; | ||
|
||
@Injectable({ | ||
scope: Scope.REQUEST, | ||
}) | ||
export class FarmAbiLoader { | ||
constructor( | ||
protected readonly farmAbi: FarmAbiService, | ||
protected readonly farmService: FarmServiceBase, | ||
protected readonly cacheService: CacheService, | ||
) {} | ||
|
||
public readonly farmedTokenLoader = new DataLoader<string, EsdtToken>( | ||
async (addresses: string[]) => { | ||
return await this.farmService.getAllFarmedTokens(addresses); | ||
}, | ||
); | ||
|
||
public readonly farmTokenLoader = new DataLoader<string, NftCollection>( | ||
async (addresses: string[]) => { | ||
return await this.farmService.getAllFarmTokens(addresses); | ||
}, | ||
); | ||
|
||
public readonly farmingTokenLoader = new DataLoader<string, EsdtToken>( | ||
async (addresses: string[]) => { | ||
return await this.farmService.getAllFarmingTokens(addresses); | ||
}, | ||
); | ||
|
||
public readonly produceRewardsEnabledLoader = new DataLoader< | ||
string, | ||
boolean | ||
>(async (addresses: string[]) => { | ||
return await getAllKeys<boolean>( | ||
this.cacheService, | ||
addresses, | ||
'farm.produceRewardsEnabled', | ||
this.farmAbi.produceRewardsEnabled.bind(this.farmAbi), | ||
); | ||
}); | ||
|
||
public readonly perBlockRewardsLoader = new DataLoader<string, string>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<string>( | ||
this.cacheService, | ||
addresses, | ||
'farm.perBlockRewards', | ||
this.farmAbi.rewardsPerBlock.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
|
||
public readonly farmTokenSupplyLoader = new DataLoader<string, string>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<string>( | ||
this.cacheService, | ||
addresses, | ||
'farm.farmTokenSupply', | ||
this.farmAbi.farmTokenSupply.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
|
||
public readonly penaltyPercentLoader = new DataLoader<string, number>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<number>( | ||
this.cacheService, | ||
addresses, | ||
'farm.penaltyPercent', | ||
this.farmAbi.penaltyPercent.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
|
||
public readonly minimumFarmingEpochsLoader = new DataLoader<string, number>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<number>( | ||
this.cacheService, | ||
addresses, | ||
'farm.minimumFarmingEpochs', | ||
this.farmAbi.minimumFarmingEpochs.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
|
||
public readonly rewardPerShareLoader = new DataLoader<string, string>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<string>( | ||
this.cacheService, | ||
addresses, | ||
'farm.rewardPerShare', | ||
this.farmAbi.rewardPerShare.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
|
||
public readonly rewardReserveLoader = new DataLoader<string, string>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<string>( | ||
this.cacheService, | ||
addresses, | ||
'farm.rewardReserve', | ||
this.farmAbi.rewardReserve.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
|
||
public readonly lastRewardBlockNonceLoader = new DataLoader<string, number>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<number>( | ||
this.cacheService, | ||
addresses, | ||
'farm.lastRewardBlockNonce', | ||
this.farmAbi.lastRewardBlockNonce.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
|
||
public readonly divisionSafetyConstantLoader = new DataLoader< | ||
string, | ||
string | ||
>(async (addresses: string[]) => { | ||
return await getAllKeys<string>( | ||
this.cacheService, | ||
addresses, | ||
'farm.divisionSafetyConstant', | ||
this.farmAbi.divisionSafetyConstant.bind(this.farmAbi), | ||
); | ||
}); | ||
|
||
public readonly stateLoader = new DataLoader<string, string>( | ||
async (addresses: string[]) => { | ||
return await getAllKeys<string>( | ||
this.cacheService, | ||
addresses, | ||
'farm.state', | ||
this.farmAbi.state.bind(this.farmAbi), | ||
); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.