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

Use enterprise-facade contract for dao & proposal indexers #140

Merged
merged 3 commits into from
Oct 5, 2023
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
9 changes: 1 addition & 8 deletions indexers/enterprise/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,5 @@
"esbuild": "^0.14.54",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0"
},
"generate-types": {
"contracts": [
"enterprise",
"enterprise-factory"
],
"output": "src/types/contracts"
}
}
}
4 changes: 3 additions & 1 deletion indexers/enterprise/src/collectors/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { EventCollector } from '@apps-shared/indexers/collectors';
import { EventStoreTableInitializer, StateTableInitializer } from '@apps-shared/indexers/initializers';
import { Runner } from '@apps-shared/indexers/indexers';
import {
NetworkName,
createDynamoDBClient,
createEventStore,
createLCDClient,
createState,
daoContractAddressRecord,
fetchAll,
} from '@apps-shared/indexers/utils';
import { BlockListener } from '@apps-shared/indexers/services/block-listener';
Expand All @@ -23,7 +25,7 @@ const state = createState('collector:enterprise-events');

const genesis = Environment.getGenesis();

const enterpriseFactoryAddress = Environment.getContractAddress('enterprise-factory');
const enterpriseFactoryAddress = daoContractAddressRecord['enterprise-factory'][process.env.NETWORK as NetworkName];

class EnterpriseEventCollector implements Runnable {
private enterpriseAddresses: string[] = [];
Expand Down
14 changes: 11 additions & 3 deletions indexers/enterprise/src/indexers/daos/Indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import { EventIndexer, IndexFnOptions } from 'indexers/EventIndexer';
import { LCDClient } from '@terra-money/feather.js';
import { DaoEntity } from './types';
import { TableNames, DAOS_PK_NAME, DAOS_SK_NAME } from 'initializers';
import { batch, createLCDClient } from '@apps-shared/indexers/utils';
import { NetworkName, batch, createLCDClient, daoContractAddressRecord } from '@apps-shared/indexers/utils';
import { KeySelector } from '@apps-shared/indexers/services/persistence';
import { fetchByHeight } from '@apps-shared/indexers/services/event-store';
import { EnterpriseEventPK, ExecuteProposalEvent, InstantiateDaoEvent } from 'types/events';
import { enterprise } from 'types/contracts';
import Big from 'big.js';
import { DaoInfoResponse, QueryMsg } from 'types/enterprise_facade';

export const PK: KeySelector<DaoEntity> = (data) => data.address;

export const SK = 'dao';

const enterpriseFacadeAddress = daoContractAddressRecord['enterprise-facade'][process.env.NETWORK as NetworkName];

export class Indexer extends EventIndexer<DaoEntity> {
constructor() {
super({
Expand Down Expand Up @@ -45,7 +47,13 @@ export class Indexer extends EventIndexer<DaoEntity> {
};

private fetchDAO = async (lcd: LCDClient, address: string): Promise<DaoEntity> => {
const response = await lcd.wasm.contractQuery<enterprise.DaoInfoResponse>(address, { dao_info: {} });
const msg: QueryMsg = {
dao_info: {
contract: address,
},
};

const response = await lcd.wasm.contractQuery<DaoInfoResponse>(enterpriseFacadeAddress, msg);
const created = 'creation_date' in response ? Math.trunc(Big(response.creation_date).div(1000000).toNumber()) : 0;

return {
Expand Down
8 changes: 4 additions & 4 deletions indexers/enterprise/src/indexers/daos/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { enterprise } from 'types/contracts';
import { DaoType, DaoCouncil, Duration } from 'types/enterprise_facade';

export type DaoEntity = {
_type: string;
address: string;
type: enterprise.DaoType;
type: DaoType;
name: string;
description?: string;
lowerCaseName: string;
Expand All @@ -12,7 +12,7 @@ export type DaoEntity = {
enterpriseFactoryContract: string;
created: number;
codeVersionId: string;
council: enterprise.DaoCouncil;
council: DaoCouncil;
socials: {
discord_username?: string;
github_username?: string;
Expand All @@ -23,7 +23,7 @@ export type DaoEntity = {
quorum: number;
threshold: number;
vetoThreshold: number;
unlockingPeriod: enterprise.Duration;
unlockingPeriod: Duration;
voteDuration: number;
minimumDeposit?: string;
};
Expand Down
16 changes: 11 additions & 5 deletions indexers/enterprise/src/indexers/proposals/Indexer.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { EventIndexer, IndexFnOptions } from 'indexers/EventIndexer';
import { Entity, ProposalKey } from './types';
import { TableNames, DAOS_PK_NAME, DAOS_SK_NAME } from 'initializers';
import { batch, createLCDClient } from '@apps-shared/indexers/utils';
import { NetworkName, batch, createLCDClient, daoContractAddressRecord } from '@apps-shared/indexers/utils';
import { KeySelector } from '@apps-shared/indexers/services/persistence';
import { fetchByHeight } from '@apps-shared/indexers/services/event-store';
import { DaoEvents, EnterpriseEventPK } from 'types/events';
import { enterprise } from 'types/contracts';
import { getProposalFromContract } from './getProposalFromContract';
import { QueryMsg, ProposalsResponse } from 'types/enterprise_facade';

export const PK: KeySelector<Entity> = (data) => data.daoAddress;

export const SK: KeySelector<Entity> = (data) => `proposal:${data.id}`;

const enterpriseFacadeAddress = daoContractAddressRecord['enterprise-facade'][process.env.NETWORK as NetworkName];

export class Indexer extends EventIndexer<Entity> {
constructor() {
super({
Expand Down Expand Up @@ -71,11 +73,15 @@ export class Indexer extends EventIndexer<Entity> {
daoAddresses.map(async (daoAddress) => {
try {
this.logger.info(`Getting proposals for ${daoAddress} DAO.`);
const { proposals } = await lcd.wasm.contractQuery<enterprise.ProposalsResponse>(daoAddress, {
const query: QueryMsg = {
proposals: {
filter: 'in_progress',
contract: daoAddress,
params: {
filter: 'in_progress',
},
},
});
};
const { proposals } = await lcd.wasm.contractQuery<ProposalsResponse>(enterpriseFacadeAddress, query);
proposals.forEach(({ proposal }) => {
const key: ProposalKey = { daoAddress, id: proposal.id };
if (!proposalsKeys.some((k) => k.daoAddress === key.daoAddress && k.id === key.id)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import { createLCDClient, Logger } from "@apps-shared/indexers/utils";
import { enterprise } from "types/contracts";
import { createLCDClient, daoContractAddressRecord, Logger, NetworkName } from '@apps-shared/indexers/utils';
import Big from 'big.js';
import { Entity } from "./types";
import { Entity } from './types';
import { QueryMsg, ProposalResponse } from 'types/enterprise_facade';

interface GetProposalParams {
daoAddress: string
id: number
logger: Logger
daoAddress: string;
id: number;
logger: Logger;
}

const enterpriseFacadeAddress = daoContractAddressRecord['enterprise-facade'][process.env.NETWORK as NetworkName];

export const getProposalFromContract = async ({ daoAddress, id, logger }: GetProposalParams): Promise<Entity> => {
const lcd = createLCDClient();

logger.info(`Fetching proposal with id ${id} for ${daoAddress} DAO.`);

const response = await lcd.wasm.contractQuery<enterprise.ProposalResponse>(daoAddress, {
const msg: QueryMsg = {
proposal: {
proposal_id: id,
contract: daoAddress,
params: {
proposal_id: id,
},
},
});
};

const response = await lcd.wasm.contractQuery<ProposalResponse>(enterpriseFacadeAddress, msg);

logger.info(`Received proposal response: ${response}.`);

Expand Down Expand Up @@ -50,6 +57,6 @@ export const getProposalFromContract = async ({ daoAddress, id, logger }: GetPro
vetoVotes,
totalVotes: response.total_votes_available,
type: response.proposal.proposal_type,
proposer: response.proposal.proposer
proposer: response.proposal.proposer,
};
}
};
10 changes: 5 additions & 5 deletions indexers/enterprise/src/indexers/proposals/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { enterprise } from 'types/contracts';
import { Expiration, ProposalStatus, ProposalAction, ProposalType } from 'types/enterprise_facade';

export type Entity = {
_type: string;
Expand All @@ -9,15 +9,15 @@ export type Entity = {
started_at: number;
title: string;
description: string;
expires: enterprise.Expiration;
status: enterprise.ProposalStatus;
proposalActions: enterprise.ProposalAction[];
expires: Expiration;
status: ProposalStatus;
proposalActions: ProposalAction[];
yesVotes: string;
noVotes: string;
abstainVotes: string;
vetoVotes: string;
totalVotes: string;
type: enterprise.ProposalType;
type: ProposalType;
proposer?: string;
};

Expand Down
Loading
Loading