Skip to content

Commit

Permalink
fix: subgraph for latest smart contracts + clean up fixes in deployme…
Browse files Browse the repository at this point in the history
…nt (#427)

* patch fix subgraph for latest smart contracts

* fix subgraph to handle distinction between totalUnits authorized and totalUnits outstanding

* update comments

* exclude ESCROW address from member list

* fix coupon onboarding deploy

* fix setting dao configs

* remove deprecated deploymentArgs setting in network config files

* include test tokens in Ganache deployment
  • Loading branch information
jdville03 authored Nov 10, 2021
1 parent b3f3373 commit e6250ad
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 122 deletions.
2 changes: 0 additions & 2 deletions migrations/configs/ganache.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
const disabled: Array<string> = [
// Utility & Test Contracts disabled by default
"OLToken",
"TestToken1",
"TestToken2",
"TestFairShareCalc",
"PixelNFT",
"ProxToken",
Expand Down
32 changes: 10 additions & 22 deletions migrations/configs/goerli.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { adaptersIdsMap } from "../../utils/dao-ids-util";
import { contracts as defaultContracts } from "./contracts.config";
import { getNetworkDetails } from "../../utils/deployment-util";
import {
contracts as defaultContracts,
ContractConfig,
} from "./contracts.config";

const disabled: Array<string> = [
// Utility & Test Contracts disabled by default
Expand All @@ -14,22 +15,9 @@ const disabled: Array<string> = [
"MockDao",
];

export const contracts = defaultContracts
.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
})
.map((c) => {
if (adaptersIdsMap.COUPON_MANAGER_ADAPTER === c.id) {
const chainDetails = getNetworkDetails("goerli");
return {
...c,
deploymentArgs: {
chainId: chainDetails?.chainId,
},
};
}
return c;
});
export const contracts: Array<ContractConfig> = defaultContracts.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
});
28 changes: 7 additions & 21 deletions migrations/configs/harmony.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { adaptersIdsMap } from "../../utils/dao-ids-util";
import {
contracts as defaultContracts,
ContractConfig,
} from "./contracts.config";
import { getNetworkDetails } from "../../utils/deployment-util";

const disabled: Array<String> = [
// Utility & Test Contracts disabled by default
Expand All @@ -22,22 +21,9 @@ const disabled: Array<String> = [
"DistributeContract",
];

export const contracts = defaultContracts
.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
})
.map((c) => {
if (adaptersIdsMap.COUPON_MANAGER_ADAPTER === c.id) {
const chainDetails = getNetworkDetails("harmony");
return {
...c,
deploymentArgs: {
chainId: chainDetails?.chainId,
},
};
}
return c;
});
export const contracts: Array<ContractConfig> = defaultContracts.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
});
32 changes: 10 additions & 22 deletions migrations/configs/harmonytest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { adaptersIdsMap } from "../../utils/dao-ids-util";
import { contracts as defaultContracts } from "./contracts.config";
import { getNetworkDetails } from "../../utils/deployment-util";
import {
contracts as defaultContracts,
ContractConfig,
} from "./contracts.config";

const disabled: Array<string> = [
// Utility & Test Contracts disabled by default
Expand All @@ -14,22 +15,9 @@ const disabled: Array<string> = [
"MockDao",
];

export const contracts = defaultContracts
.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
})
.map((c) => {
if (adaptersIdsMap.COUPON_MANAGER_ADAPTER === c.id) {
const chainDetails = getNetworkDetails("harmonytest");
return {
...c,
deploymentArgs: {
chainId: chainDetails?.chainId,
},
};
}
return c;
});
export const contracts: Array<ContractConfig> = defaultContracts.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
});
28 changes: 7 additions & 21 deletions migrations/configs/mainnet.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { adaptersIdsMap } from "../../utils/dao-ids-util";
import {
contracts as defaultContracts,
ContractConfig,
} from "./contracts.config";
import { getNetworkDetails } from "../../utils/deployment-util";

const disabled: Array<String> = [
// Utility & Test Contracts disabled by default
Expand All @@ -22,22 +21,9 @@ const disabled: Array<String> = [
"DistributeContract",
];

export const contracts = defaultContracts
.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
})
.map((c) => {
if (adaptersIdsMap.COUPON_MANAGER_ADAPTER === c.id) {
const chainDetails = getNetworkDetails("mainnet");
return {
...c,
deploymentArgs: {
chainId: chainDetails?.chainId,
},
};
}
return c;
});
export const contracts: Array<ContractConfig> = defaultContracts.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
});
32 changes: 10 additions & 22 deletions migrations/configs/rinkeby.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { adaptersIdsMap } from "../../utils/dao-ids-util";
import { contracts as defaultContracts } from "./contracts.config";
import { getNetworkDetails } from "../../utils/deployment-util";
import {
contracts as defaultContracts,
ContractConfig,
} from "./contracts.config";

const disabled: Array<string> = [
// Utility & Test Contracts disabled by default
Expand All @@ -14,22 +15,9 @@ const disabled: Array<string> = [
"MockDao",
];

export const contracts = defaultContracts
.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
})
.map((c) => {
if (adaptersIdsMap.COUPON_MANAGER_ADAPTER === c.id) {
const chainDetails = getNetworkDetails("rinkeby");
return {
...c,
deploymentArgs: {
chainId: chainDetails?.chainId,
},
};
}
return c;
});
export const contracts: Array<ContractConfig> = defaultContracts.map((c) => {
if (disabled.find((e) => e === c.name)) {
return { ...c, enabled: false };
}
return c;
});
3 changes: 3 additions & 0 deletions subgraph/mappings/core/dao-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export let TOTAL: Address = Address.fromString(
export let MEMBER_COUNT: Address = Address.fromString(
"0x00000000000000000000000000000000decafbad"
);
export let ESCROW: Address = Address.fromString(
"0x0000000000000000000000000000000000004bec"
);

// adapter/extension names hashed (lowercase)

Expand Down
21 changes: 16 additions & 5 deletions subgraph/mappings/extensions/bank-extension-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
Extension,
} from "../../generated/schema";
import {
ERC20_EXTENSION_ID,
ESCROW,
GUILD,
UNITS,
TOTAL,
MEMBER_COUNT,
ERC20_EXTENSION_ID,
TOTAL,
UNITS,
} from "../core/dao-constants";

function internalTransfer(
Expand All @@ -38,9 +39,11 @@ function internalTransfer(
TOTAL.toHex() != memberAddress.toHex() &&
GUILD.toHex() != memberAddress.toHex() &&
MEMBER_COUNT.toHex() != memberAddress.toHex() &&
ESCROW.toHex() != memberAddress.toHex() &&
TOTAL.toHex() != tokenAddress.toHex() &&
GUILD.toHex() != tokenAddress.toHex() &&
MEMBER_COUNT.toHex() != tokenAddress.toHex()
MEMBER_COUNT.toHex() != tokenAddress.toHex() &&
ESCROW.toHex() != tokenAddress.toHex()
) {
// check if the DAO has an ERC20 extension and assign members balance
internalERC20Balance(daoAddress, memberAddress);
Expand Down Expand Up @@ -85,12 +88,20 @@ function internalTransfer(
member.save();
}

// get totalUnits in the dao
// get total units minted for the DAO
let balanceOfTotalUnits = bankRegistry.balanceOf(TOTAL, UNITS);
// get balance of units owned by the guild bank
let balanceOfGuildUnits = bankRegistry.balanceOf(GUILD, UNITS);
// get total units issued and outstanding in the DAO (not owned by guild bank)
let balanceOfTotalUnitsIssued = balanceOfTotalUnits.minus(
balanceOfGuildUnits
);

let dao = TributeDao.load(daoAddress.toHexString());

if (dao != null) {
dao.totalUnits = balanceOfTotalUnits.toString();
dao.totalUnitsIssued = balanceOfTotalUnitsIssued.toString();

dao.save();
}
Expand Down
6 changes: 3 additions & 3 deletions subgraph/mappings/helpers/proposal-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ function managing(
let proposal = Proposal.load(daoProposalId);

if (proposal) {
proposal.adapterId = data.value0;
proposal.adapterAddress = data.value1;
proposal.adapterOrExtensionId = data.value0;
proposal.adapterOrExtensionAddr = data.value1;

proposal.adapterAddress = adapterAdddress;
proposal.adapterOrExtensionAddr = adapterAdddress;

// @todo
// let keys: Bytes[] = [];
Expand Down
2 changes: 1 addition & 1 deletion subgraph/mappings/helpers/vote-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export function loadProposalAndSaveVoteResults(
proposal.gracePeriodStartingTime = voteResults.value6;
proposal.isChallenged = voteResults.value7;
proposal.stepRequested = voteResults.value8;
proposal.forceFailed = voteResults.value9;
// @todo its a mapping, not generated in schema
// proposal.fallbackVotes = voteResults.value10;
proposal.forceFailed = voteResults.value9;
proposal.fallbackVotesCount = voteResults.value10;

proposal.votingState = voteState.toString();
Expand Down
7 changes: 6 additions & 1 deletion subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ type TributeDao @entity {
"The DAO creator address"
creator: Bytes
createdAt: String
"Total units minted for the DAO"
totalUnits: String
"Total units issued and outstanding"
totalUnitsIssued: String
"The bank of the DAO"
bank: Bank! @derivedFrom(field: "tributeDao")
"List of registered adapters"
Expand Down Expand Up @@ -119,6 +122,8 @@ type Proposal @entity {

# MANAGING; proposal details
"Additional details for the managing proposal"
adapterOrExtensionId: Bytes
adapterOrExtensionAddr: Bytes
keys: [Bytes!]
values: [BigInt!]

Expand All @@ -134,8 +139,8 @@ type Proposal @entity {
gracePeriodStartingTime: BigInt
isChallenged: Boolean
stepRequested: BigInt
# fallbackVotes: BigInt
forceFailed: Boolean
# fallbackVotes: BigInt
fallbackVotesCount: BigInt

# ONCHAIN VOTES: additional info
Expand Down
4 changes: 2 additions & 2 deletions utils/deployment-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,11 @@ const configureDao = async ({
.then(() =>
contractConfigs.daoConfigs.reduce(
(q, configEntry) =>
q.then(() => {
q.then(async () => {
const configValues = configEntry.map((configName) =>
readConfigValue(configName, contractConfigs.name)
);
return adapter
return await adapter
.configureDao(...configValues, {
from: options.owner,
})
Expand Down

0 comments on commit e6250ad

Please sign in to comment.