Skip to content

Commit

Permalink
MEX-404: cleanup farm staking model
Browse files Browse the repository at this point in the history
Signed-off-by: Claudiu Lataretu <[email protected]>
  • Loading branch information
claudiulataretu committed Oct 10, 2023
1 parent ef7de9e commit a5086bd
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 109 deletions.
10 changes: 0 additions & 10 deletions src/modules/staking/mocks/staking.abi.service.mock.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import BigNumber from 'bignumber.js';
import { IStakingAbiService } from '../services/interfaces';
import { StakingAbiService } from '../services/staking.abi.service';
import { Address } from '@multiversx/sdk-core/out';

export class StakingAbiServiceMock implements IStakingAbiService {
async pairContractAddress(stakeAddress: string): Promise<string> {
return Address.Zero().bech32();
}
async farmTokenID(stakeAddress: string): Promise<string> {
return 'STAKETOK-1111';
}
Expand Down Expand Up @@ -46,12 +42,6 @@ export class StakingAbiServiceMock implements IStakingAbiService {
async produceRewardsEnabled(stakeAddress: string): Promise<boolean> {
return true;
}
burnGasLimit(stakeAddress: string): Promise<string> {
throw new Error('Method not implemented.');
}
transferExecGasLimit(stakeAddress: string): Promise<string> {
throw new Error('Method not implemented.');
}
state(stakeAddress: string): Promise<string> {
throw new Error('Method not implemented.');
}
Expand Down
6 changes: 0 additions & 6 deletions src/modules/staking/models/staking.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export class StakingModel {
@Field()
farmTokenSupply: string;
@Field()
pairContractManagedAddress: string;
@Field()
rewardPerShare: string;
@Field()
accumulatedRewards: string;
Expand All @@ -40,10 +38,6 @@ export class StakingModel {
produceRewardsEnabled: boolean;
@Field({ nullable: true })
lockedAssetFactoryManagedAddress: string;
@Field({ nullable: true })
burnGasLimit: string;
@Field({ nullable: true })
transferExecGasLimit: string;
@Field()
state: string;
@Field({ description: 'Timekeeping for boosted rewards' })
Expand Down
3 changes: 0 additions & 3 deletions src/modules/staking/services/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BigNumber from 'bignumber.js';

export interface IStakingAbiService {
pairContractAddress(stakeAddress: string): Promise<string>;
farmTokenID(stakeAddress: string): Promise<string>;
farmingTokenID(stakeAddress: string): Promise<string>;
rewardTokenID(stakeAddress: string): Promise<string>;
Expand All @@ -16,8 +15,6 @@ export interface IStakingAbiService {
lastRewardBlockNonce(stakeAddress: string): Promise<number>;
divisionSafetyConstant(stakeAddress: string): Promise<number>;
produceRewardsEnabled(stakeAddress: string): Promise<boolean>;
burnGasLimit(stakeAddress: string): Promise<string>;
transferExecGasLimit(stakeAddress: string): Promise<string>;
state(stakeAddress: string): Promise<string>;
calculateRewardsForGivenPosition(
stakeAddress: string,
Expand Down
67 changes: 0 additions & 67 deletions src/modules/staking/services/staking.abi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,6 @@ export class StakingAbiService
super(mxProxy);
}

@ErrorLoggerAsync({
logArgs: true,
})
@GetOrSetCache({
baseKey: 'stake',
remoteTtl: Constants.oneHour(),
})
async pairContractAddress(stakeAddress: string): Promise<string> {
return await this.getPairContractAddressRaw(stakeAddress);
}

async getPairContractAddressRaw(stakeAddress: string): Promise<string> {
try {
const contract = await this.mxProxy.getStakingSmartContract(
stakeAddress,
);
const interaction: Interaction =
contract.methodsExplicit.getPairContractManagedAddress();
const response = await this.getGenericData(interaction);
return response.firstValue.valueOf().hex32();
} catch {
return undefined;
}
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand Down Expand Up @@ -338,48 +313,6 @@ export class StakingAbiService
return response === '01';
}

@ErrorLoggerAsync({
logArgs: true,
})
@GetOrSetCache({
baseKey: 'stake',
remoteTtl: Constants.oneHour(),
})
async burnGasLimit(stakeAddress: string): Promise<string> {
return await this.getBurnGasLimitRaw(stakeAddress);
}

async getBurnGasLimitRaw(stakeAddress: string): Promise<string> {
const contract = await this.mxProxy.getStakingSmartContract(
stakeAddress,
);
const interaction: Interaction =
contract.methodsExplicit.getBurnGasLimit();
const response = await this.getGenericData(interaction);
return response.firstValue.valueOf();
}

@ErrorLoggerAsync({
logArgs: true,
})
@GetOrSetCache({
baseKey: 'stake',
remoteTtl: Constants.oneHour(),
})
async transferExecGasLimit(stakeAddress: string): Promise<string> {
return await this.getTransferExecGasLimitRaw(stakeAddress);
}

async getTransferExecGasLimitRaw(stakeAddress: string): Promise<string> {
const contract = await this.mxProxy.getStakingSmartContract(
stakeAddress,
);
const interaction: Interaction =
contract.methodsExplicit.getTransferExecGasLimit();
const response = await this.getGenericData(interaction);
return response.firstValue.valueOf();
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand Down
24 changes: 1 addition & 23 deletions src/modules/staking/staking.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { UseGuards } from '@nestjs/common';
import {
Args,
Int,
Parent,
Query,
ResolveField,
Resolver,
} from '@nestjs/graphql';
import { Args, Parent, Query, ResolveField, Resolver } from '@nestjs/graphql';
import { AuthUser } from '../auth/auth.user';
import { UserAuthResult } from '../auth/user.auth.result';
import { TransactionModel } from 'src/models/transaction.model';
Expand Down Expand Up @@ -120,21 +113,6 @@ export class StakingResolver {
return this.stakingAbi.lockedAssetFactoryAddress(parent.address);
}

@ResolveField()
async pairContractManagedAddress(@Parent() parent: StakingModel) {
return this.stakingAbi.pairContractAddress(parent.address);
}

@ResolveField()
async burnGasLimit(@Parent() parent: StakingModel) {
return this.stakingAbi.burnGasLimit(parent.address);
}

@ResolveField()
async transferExecGasLimit(@Parent() parent: StakingModel) {
return this.stakingAbi.transferExecGasLimit(parent.address);
}

@ResolveField()
async state(@Parent() parent: StakingModel) {
return this.stakingAbi.state(parent.address);
Expand Down

0 comments on commit a5086bd

Please sign in to comment.