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 359 #1156

Merged
merged 5 commits into from
Aug 24, 2023
Merged

Mex 359 #1156

Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions src/config/devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"lockedTokenWrapper": "erd1qqqqqqqqqqqqqpgq9ej9vcnr38l69rgkc735kgv0qlu2ptrsd8ssu9rwtu",
"escrow": "erd1qqqqqqqqqqqqqpgqz0wkk0j6y4h0mcxfxsg023j4x5sfgrmz0n4s4swp7a",
"governance": {
"oldEnergy": [
"erd1qqqqqqqqqqqqqpgqdt9aady5jp7av97m7rqxh6e5ywyqsplz2jps5mw02n"
],
"energy": [],
"tokenSnapshot": [
"erd1qqqqqqqqqqqqqpgq2rkrhef99hhk3ynfcxevcj86axr3sgmcczfstkmdwr"
Expand Down
3 changes: 3 additions & 0 deletions src/config/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"lockedTokenWrapper": "erd1qqqqqqqqqqqqqpgqu64gygjs5ted4rupaewaszyhaxl9lv7m2jpsw47nzr",
"escrow": "erd1qqqqqqqqqqqqqpgqeh4yv09rmyg4xgn5ma03mvm4v5gndu8w2jpsglz3cn",
"governance": {
"oldEnergy": [
"erd1qqqqqqqqqqqqqpgqdt9aady5jp7av97m7rqxh6e5ywyqsplz2jps5mw02n"
],
"energy": [],
"tokenSnapshot": [
"erd1qqqqqqqqqqqqqpgq7cywmem5g66ad49rce0ctu6yqmscmp9v7j6q7cded4"
Expand Down
3 changes: 3 additions & 0 deletions src/config/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"lockedTokenWrapper": "erd1qqqqqqqqqqqqqpgq97fctvqlskzu0str05muew2qyjttp8kfkp2sl9k0gx",
"escrow": "erd1qqqqqqqqqqqqqpgqeh4yv09rmyg4xgn5ma03mvm4v5gndu8w2jpsglz3cn",
"governance": {
"oldEnergy": [
"erd1qqqqqqqqqqqqqpgqdt9aady5jp7av97m7rqxh6e5ywyqsplz2jps5mw02n"
],
"energy": [],
"tokenSnapshot": [
"erd1qqqqqqqqqqqqqpgq7cywmem5g66ad49rce0ctu6yqmscmp9v7j6q7cded4"
Expand Down
37 changes: 37 additions & 0 deletions src/modules/governance/entities/lkmex.proposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { DescriptionV1, GovernanceProposalStatus } from '../models/governance.proposal.model';
import { ProposalVotes } from '../models/governance.proposal.votes.model';

export class GovernanceLKMEXProposal {
description = new DescriptionV1({
title: 'Maiar DEX to transform Into xExchange with New MEX 2.0 Economic Model',
shortDescription:
'xExchange (Maiar DEX 2.0) presents a set of significant improvements and benefits, while correcting the most important limitations residing in the previous economics model.',
strapiId: 0,
version: 1,
});
votes = new ProposalVotes({
upVotes: '3615976209993',
downVotes: '210776056445',
downVetoVotes: '0',
abstainVotes: '274849971635',
totalVotes: '4101602200000',
upPercentage: '0.88',
downPercentage: '0.05',
downVetoPercentage: '0',
abstainPercentage: '0.06',
quorum: '0',
});
status = GovernanceProposalStatus.Succeeded;
turnoutPercentage = '60.83';
proposalId = 1;

toJSOSN() {
return {
proposalId: this.proposalId,
description: this.description,
votes: this.votes,
status: this.status,
turnoutPercentage: this.turnoutPercentage,
};
}
}
3 changes: 2 additions & 1 deletion src/modules/governance/governance.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './resolvers/governance.contract.resolver';
import { GovernanceSetterService } from './services/governance.setter.service';
import { GovernanceQueryResolver } from './resolvers/governance.query.resolver';
import { GovernanceProposalResolver } from './resolvers/governance.proposal.resolver';
import { GovernanceLKMEXProposalResolver, GovernanceProposalResolver } from './resolvers/governance.proposal.resolver';
import { ElasticService } from 'src/helpers/elastic.service';

@Module({
Expand All @@ -45,6 +45,7 @@ import { ElasticService } from 'src/helpers/elastic.service';
GovernanceEnergyContractResolver,
GovernanceTokenSnapshotContractResolver,
GovernanceProposalResolver,
GovernanceLKMEXProposalResolver,
ElasticService,
],
exports: [
Expand Down
14 changes: 13 additions & 1 deletion src/modules/governance/models/governance.contract.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field, Int, ObjectType } from '@nestjs/graphql';
import { GovernanceProposalModel } from './governance.proposal.model';
import { GovernanceLKMEXProposalModel, GovernanceProposalModel } from './governance.proposal.model';
import { EsdtToken } from '../../tokens/models/esdtToken.model';

@ObjectType()
Expand Down Expand Up @@ -44,3 +44,15 @@ export class GovernanceEnergyContract extends GovernanceTokenSnapshotContract {
Object.assign(this, init);
}
}

@ObjectType()
export class GovernanceOldEnergyContract {
@Field()
address: string;
@Field(() => [GovernanceLKMEXProposalModel])
proposals: GovernanceLKMEXProposalModel[];

constructor(init: Partial<GovernanceOldEnergyContract>) {
Object.assign(this, init);
}
}
24 changes: 24 additions & 0 deletions src/modules/governance/models/governance.proposal.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,27 @@ export class GovernanceProposalModel {
Object.assign(this, init);
}
}

@ObjectType()
export class GovernanceLKMEXProposalModel {
@Field()
contractAddress: string;
@Field()
proposalId: number;
@Field( () => GovernanceDescriptionUnion)
description: typeof GovernanceDescriptionUnion;
@Field( () => ProposalVotes )
votes: ProposalVotes;
@Field()
status: GovernanceProposalStatus;
@Field()
hasVoted?: boolean;
@Field()
userVoteType?: VoteType;
@Field()
turnoutPercentage: string;

constructor(init: Partial<GovernanceLKMEXProposalModel>) {
Object.assign(this, init);
}
}
9 changes: 8 additions & 1 deletion src/modules/governance/models/governance.union.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createUnionType } from '@nestjs/graphql';
import { GovernanceEnergyContract, GovernanceTokenSnapshotContract } from './governance.contract.model';
import {
GovernanceEnergyContract,
GovernanceOldEnergyContract,
GovernanceTokenSnapshotContract,
} from './governance.contract.model';
import { DescriptionV0, DescriptionV1 } from './governance.proposal.model';

export const GovernanceUnion = createUnionType({
Expand All @@ -8,13 +12,16 @@ export const GovernanceUnion = createUnionType({
[
GovernanceTokenSnapshotContract,
GovernanceEnergyContract,
GovernanceOldEnergyContract,
] as const,
resolveType(governance) {
switch (governance.constructor.name) {
case GovernanceTokenSnapshotContract.name:
return GovernanceTokenSnapshotContract;
case GovernanceEnergyContract.name:
return GovernanceEnergyContract;
case GovernanceOldEnergyContract.name:
return GovernanceOldEnergyContract;
}
},
});
Expand Down
34 changes: 33 additions & 1 deletion src/modules/governance/resolvers/governance.proposal.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Parent, ResolveField, Resolver } from '@nestjs/graphql';
import { GovernanceProposalModel, GovernanceProposalStatus, VoteType } from '../models/governance.proposal.model';
import {
GovernanceLKMEXProposalModel,
GovernanceProposalModel,
GovernanceProposalStatus,
VoteType,
} from '../models/governance.proposal.model';
import { ProposalVotes } from '../models/governance.proposal.votes.model';
import { GovernanceService } from '../services/governance.service';
import { UseGuards } from '@nestjs/common';
Expand Down Expand Up @@ -77,3 +82,30 @@ export class GovernanceProposalResolver {
return new BigNumber(userQuorum).integerValue().toFixed();
}
}

@Resolver(() => GovernanceLKMEXProposalModel)
export class GovernanceLKMEXProposalResolver {
constructor(
private readonly governanceService: GovernanceService,
) {
}

@UseGuards(JwtOrNativeAuthGuard)
@ResolveField()
async hasVoted(
@AuthUser() user: UserAuthResult,
@Parent() governanceProposal: GovernanceLKMEXProposalModel
): Promise<boolean> {
const userVoteType = await this.governanceService.userVote(governanceProposal.contractAddress, governanceProposal.proposalId, user.address);
return userVoteType !== VoteType.NotVoted;
}

@UseGuards(JwtOrNativeAuthGuard)
@ResolveField()
async userVoteType(
@AuthUser() user: UserAuthResult,
@Parent() governanceProposal: GovernanceLKMEXProposalModel
): Promise<VoteType> {
return this.governanceService.userVote(governanceProposal.contractAddress, governanceProposal.proposalId, user.address);
}
}
16 changes: 15 additions & 1 deletion src/modules/governance/services/governance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { GovernanceContractsFiltersArgs } from '../models/governance.contracts.f
import { GovernanceUnion } from '../models/governance.union';
import { TokenGetterService } from '../../tokens/services/token.getter.service';
import { EsdtToken } from '../../tokens/models/esdtToken.model';
import { GovernanceEnergyContract, GovernanceTokenSnapshotContract } from '../models/governance.contract.model';
import {
GovernanceEnergyContract,
GovernanceOldEnergyContract,
GovernanceTokenSnapshotContract,
} from '../models/governance.contract.model';
import { GovernanceTokenSnapshotAbiService } from './governance.abi.service';
import { VoteType } from '../models/governance.proposal.model';
import { GovernanceComputeService } from './governance.compute.service';
import { GovernanceLKMEXProposal } from '../entities/lkmex.proposal';

@Injectable()
export class GovernanceService {
Expand Down Expand Up @@ -45,6 +50,15 @@ export class GovernanceService {
}),
);
break;
case GovernanceType.OLD_ENERGY:
governance.push(new GovernanceOldEnergyContract({
address,
proposals: [{
contractAddress: address,
...new GovernanceLKMEXProposal().toJSOSN(),
}],
}));
break;
}

}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { registerEnumType } from '@nestjs/graphql';

export enum GovernanceType {
ENERGY = 'energy',
OLD_ENERGY = 'oldEnergy',
TOKEN_SNAPSHOT = 'tokenSnapshot',
}

Expand All @@ -15,6 +16,8 @@ const toTypeEnum = (type: string): GovernanceType => {
return GovernanceType.ENERGY;
case GovernanceType.TOKEN_SNAPSHOT.toString():
return GovernanceType.TOKEN_SNAPSHOT;
case GovernanceType.OLD_ENERGY.toString():
return GovernanceType.OLD_ENERGY;
default:
return undefined;
}
Expand Down
Loading