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

Issue/326 2 #350

Merged
merged 1 commit into from
Oct 12, 2022
Merged
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
80 changes: 6 additions & 74 deletions src/modules/explorer/pages/ProposalDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from "lodash"
import { Button, Grid, Theme, Tooltip, Typography, useMediaQuery } from "@material-ui/core"
import { styled, useTheme } from "@material-ui/styles"
import ReactHtmlParser from "react-html-parser"
Expand Down Expand Up @@ -138,81 +139,10 @@ export const ProposalDetails: React.FC = () => {
const { account } = useTezos()
const canDropProposal = useCanDropProposal(daoId, proposalId)
const { data: agoraPost } = useAgoraTopic(Number(proposal?.metadata?.agoraPostId))
const [code, setCode] = React.useState<string>(`
const allowances = new MichelsonMap();
const ledger = new MichelsonMap();
ledger.set('tz1btkXVkVFWLgXa66sbRJa8eeUSwvQFX4kP', { allowances, balance: '100' });

const opknownBigMapContract = await tezos.contract.originate({
code: knownBigMapContract,
storage: {
ledger,
owner: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
totalSupply: '100',
},
});

const opknownBigMapContract = await tezos.contract.originate({
code: knownBigMapContract,
storage: {
ledger,
owner: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
totalSupply: '100',
},
});

const opknownBigMapContract = await tezos.contract.originate({
code: knownBigMapContract,
storage: {
ledger,
owner: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
totalSupply: '100',
},
});

const opknownBigMapContract = await tezos.contract.originate({
code: knownBigMapContract,
storage: {
ledger,
owner: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
totalSupply: '100',
},
});
}`)

const quorumThreshold = proposal?.quorumThreshold || new BigNumber(0)
const { mutate: mutateUnstake } = useUnstakeVotes()

const getLambdaProposalInfo = useCallback(() => {
const info = {
type: "",
title: "",
code: ""
}

if (!isLambdaProposal) {
return info
}

const lambdaProposal = proposal as LambdaProposal
if (!!lambdaProposal.metadata.add_handler) {
info.type = "add_handler"
info.title = "Add Handler"
info.code = JSON.stringify(lambdaProposal.metadata.add_handler, null, 2)
} else if (!!lambdaProposal.metadata.remove_handler) {
info.type = "remove_handler"
info.title = "Remove Handler"
info.code = JSON.stringify(lambdaProposal.metadata.remove_handler, null, 2)
} else if (!!lambdaProposal.metadata.execute_handler) {
info.type = "execute_handler"
info.title = "Execute Handler"
info.code = JSON.stringify(lambdaProposal.metadata.execute_handler, null, 2)
}

return info
}, [proposal, isLambdaProposal])
const lambdaProposalInfo = getLambdaProposalInfo()

const onClickVote = (support: boolean) => {
setVoteIsSupport(support)
setOpenVote(true)
Expand Down Expand Up @@ -343,8 +273,8 @@ export const ProposalDetails: React.FC = () => {
</ViewCodeButton>
<CodeVisor
open={openVisor}
code={lambdaProposalInfo.code}
title={lambdaProposalInfo.title}
code={JSON.stringify((proposal as LambdaProposal).metadata.lambdaHandler, null, 2)}
title={_.startCase((proposal as LambdaProposal).metadata.lambdaType)}
handleClose={() => setOpenVisor(false)}
/>
</Grid>
Expand Down Expand Up @@ -573,7 +503,9 @@ export const ProposalDetails: React.FC = () => {
<InfoItem color="textPrimary">Parameter 2: {"Mock 1300"}</InfoItem>
</Grid>
<Grid item container direction="row">
<InfoItem color="textPrimary">Type: {lambdaProposalInfo.title}</InfoItem>
<InfoItem color="textPrimary">
Lambda Type: {_.startCase((proposal as LambdaProposal).metadata.lambdaType)}
</InfoItem>
</Grid>
</Grid>
</>
Expand Down
136 changes: 75 additions & 61 deletions src/services/indexer/dao/mappers/proposal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import treasuryProposeCode from "services/contracts/baseDAO/treasuryDAO/michelso
import registryProposeCode from "services/contracts/baseDAO/registryDAO/michelson/propose"
import lambdaProposeCode from "services/contracts/baseDAO/registryDAO/michelson/proposelambda"
import { Schema } from "@taquito/michelson-encoder"
import { Parser, Expr, unpackDataBytes } from "@taquito/michel-codec"
import { Parser, Expr, unpackDataBytes, MichelsonType } from "@taquito/michel-codec"
import { parseUnits } from "services/contracts/utils"
import { ProposalDTO } from "services/indexer/types"
import { PMLambdaProposal, PMRegistryProposal, PMTreasuryProposal } from "services/contracts/baseDAO/registryDAO/types"
Expand All @@ -23,19 +23,62 @@ export enum IndexerStatus {
export enum ProposalStatus {
PENDING = "pending",
ACTIVE = "active",

PASSED = "passed",
REJECTED = "rejected",

NO_QUORUM = "no quorum",

EXECUTABLE = "executable",

DROPPED = "dropped",
EXPIRED = "expired",
EXECUTED = "executed"
}

export interface Transfer {
amount: BigNumber
beneficiary: string
type: "XTZ" | "FA2"
}

export interface FA2Transfer extends Transfer {
contractAddress: string
tokenId: string
}

interface BaseProposalMetadata {
config: { key: "frozen_extra_value" | "slash_scale_value"; value: BigNumber }[]
update_guardian: string
update_contract_delegate: string
agoraPostId: string
}

const baseProposalMetadata: BaseProposalMetadata = {
config: [],
update_guardian: "",
update_contract_delegate: "",
agoraPostId: "-1"
}

function getBaseMetadata(
proposalMetadataDTO: PMTreasuryProposal | PMRegistryProposal | PMLambdaProposal
): BaseProposalMetadata {
const values = { ...baseProposalMetadata }

if ("update_contract_delegate" in proposalMetadataDTO) {
values.update_contract_delegate = proposalMetadataDTO.update_contract_delegate
}

if ("update_guardian" in proposalMetadataDTO) {
values.update_guardian = proposalMetadataDTO.update_guardian
}

if ("configuration_proposal" in proposalMetadataDTO) {
values.config = Object.entries(proposalMetadataDTO.configuration_proposal)
.filter(([_, value]) => !!value)
.map(([key, value]) => ({ key: key as BaseProposalMetadata["config"][number]["key"], value }))
}

return values
}

const INDEXER_TO_PROPOSAL_STATUS_MAP: Record<IndexerStatus, ProposalStatus> = {
created: ProposalStatus.PENDING,
rejected_and_flushed: ProposalStatus.DROPPED,
Expand Down Expand Up @@ -296,9 +339,8 @@ export class RegistryProposal extends Proposal {
}

interface LambdaProposalMetadata extends BaseProposalMetadata {
add_handler?: Record<string, any>
remove_handler?: Record<string, any>
execute_handler?: Record<string, any>
lambdaType: "add_handler" | "remove_handler" | "execute_handler" | ""
lambdaHandler: Record<string, any>
}

export class LambdaProposal extends Proposal {
Expand All @@ -310,72 +352,44 @@ export class LambdaProposal extends Proposal {
}

const parser = new Parser()
const micheline = parser.parseMichelineExpression(lambdaProposeCode) as Expr
const schema = new Schema(micheline as Expr)
const typ = parser.parseMichelineExpression(lambdaProposeCode) as Expr
const schema = new Schema(typ)

const unpackedMetadata = unpackDataBytes({ bytes: this.packedMetadata }, micheline as any) as any
const unpackedMetadata = unpackDataBytes({ bytes: this.packedMetadata }, typ as MichelsonType)
const proposalMetadataDTO: PMLambdaProposal = schema.Execute(unpackedMetadata)

const lambdaMetadata: LambdaProposalMetadata = getBaseMetadata(proposalMetadataDTO)
const baseMetadata: BaseProposalMetadata = getBaseMetadata(proposalMetadataDTO)
const lambdaMetadata: LambdaProposalMetadata = {
...baseMetadata,
lambdaType: "",
lambdaHandler: {}
}

if ("add_handler" in proposalMetadataDTO) {
lambdaMetadata.add_handler = proposalMetadataDTO.add_handler
lambdaMetadata.lambdaType = "add_handler"
lambdaMetadata.lambdaHandler = proposalMetadataDTO.add_handler
}

if ("remove_handler" in proposalMetadataDTO) {
lambdaMetadata.remove_handler = proposalMetadataDTO.remove_handler
lambdaMetadata.lambdaType = "remove_handler"
lambdaMetadata.lambdaHandler = proposalMetadataDTO.remove_handler
}

if ("execute_handler" in proposalMetadataDTO) {
lambdaMetadata.execute_handler = proposalMetadataDTO.execute_handler
lambdaMetadata.lambdaType = "execute_handler"
lambdaMetadata.lambdaHandler = proposalMetadataDTO.execute_handler
try {
lambdaMetadata.lambdaHandler.unpacked_argument = unpackDataBytes(
{ bytes: lambdaMetadata.lambdaHandler.packed_argument },
parser.parseMichelineExpression(lambdaMetadata.lambdaHandler.packed_argument) as MichelsonType
)
} catch (error) {
lambdaMetadata.lambdaHandler.unpacked_argument = {}
} finally {
delete lambdaMetadata.lambdaHandler.packed_argument
}
}

this.cachedMetadata = { ...lambdaMetadata }
return this.cachedMetadata
}
}

export interface Transfer {
amount: BigNumber
beneficiary: string
type: "XTZ" | "FA2"
}

export interface FA2Transfer extends Transfer {
contractAddress: string
tokenId: string
}

interface BaseProposalMetadata {
config: { key: "frozen_extra_value" | "slash_scale_value"; value: BigNumber }[]
update_guardian: string
update_contract_delegate: string
agoraPostId: string
}

function getBaseMetadata(
proposalMetadataDTO: PMTreasuryProposal | PMRegistryProposal | PMLambdaProposal
): BaseProposalMetadata {
const values: BaseProposalMetadata = {
config: [],
update_guardian: "",
update_contract_delegate: "",
agoraPostId: "-1"
}

if ("update_contract_delegate" in proposalMetadataDTO) {
values.update_contract_delegate = proposalMetadataDTO.update_contract_delegate
}

if ("update_guardian" in proposalMetadataDTO) {
values.update_guardian = proposalMetadataDTO.update_guardian
}

if ("configuration_proposal" in proposalMetadataDTO) {
values.config = Object.entries(proposalMetadataDTO.configuration_proposal)
.filter(([_, value]) => !!value)
.map(([key, value]) => ({ key: key as BaseProposalMetadata["config"][number]["key"], value }))
}

return values
}