Skip to content

Feat/auto execute #27

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

Merged
merged 5 commits into from
Jun 18, 2024
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
14 changes: 14 additions & 0 deletions contracts/virtualPersona/AgentDAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,23 @@ contract AgentDAO is
}
}

if (support == 1) {
_tryAutoExecute(proposalId);
}

return weight;
}

// Auto execute when forVotes == totalSupply
function _tryAutoExecute(uint256 proposalId) internal {
(, uint256 forVotes, ) = proposalVotes(proposalId);
if (
forVotes == token().getPastTotalSupply(proposalSnapshot(proposalId))
) {
execute(proposalId);
}
}

function _updateMaturity(
address account,
uint256 proposalId,
Expand Down
71 changes: 13 additions & 58 deletions test/agentDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { parseEther, formatEther } = require("ethers");
const getExecuteCallData = (factory, proposalId) => {
return factory.interface.encodeFunctionData("executeApplication", [
proposalId,
false
false,
]);
};

Expand Down Expand Up @@ -197,7 +197,9 @@ describe("AgentDAO", function () {
const { agentFactory, applicationId } = base;

const { founder } = await getAccounts();
await agentFactory.connect(founder).executeApplication(applicationId, false);
await agentFactory
.connect(founder)
.executeApplication(applicationId, false);

const factoryFilter = agentFactory.filters.NewPersona;
const factoryEvents = await agentFactory.queryFilter(factoryFilter, -1);
Expand All @@ -218,62 +220,9 @@ describe("AgentDAO", function () {
};
}

async function createContribution(
coreId,
maturity,
parentId,
isModel,
datasetId,
desc,
base,
account
) {
const { founder } = await getAccounts();
const { agent, serviceNft, contributionNft, minter } = base;
const agentDAO = await ethers.getContractAt("AgentDAO", agent.dao);

const descHash = getDescHash(desc);

const mintCalldata = await getMintServiceCalldata(
serviceNft,
agent.virtualId,
descHash
);

await agentDAO.propose([serviceNft.target], [0], [mintCalldata], desc);
const filter = agentDAO.filters.ProposalCreated;
const events = await agentDAO.queryFilter(filter, -1);
const event = events[0];
const proposalId = event.args[0];

await contributionNft.mint(
account,
agent.virtualId,
coreId,
TOKEN_URI,
proposalId,
parentId,
isModel,
datasetId
);

const voteParams = isModel
? abi.encode(["uint256", "uint8[] memory"], [maturity, [0, 1, 1, 0, 2]])
: "0x";
await agentDAO
.connect(founder)
.castVoteWithReasonAndParams(proposalId, 1, "lfg", voteParams);
await mine(600);

await agentDAO.execute(proposalId);
await minter.mint(proposalId);

return proposalId;
}

before(async function () {});

it("should allow early execution when forVotes == totalSupply", async function () {
it("should auto early execution when forVotes == totalSupply", async function () {
const base = await loadFixture(deployWithAgent);
const { founder, deployer } = await getAccounts();
const {
Expand All @@ -300,11 +249,17 @@ describe("AgentDAO", function () {
const event = events[0];
const proposalId = event.args[0];

// Proposal not executed yet
await expect(serviceNft.ownerOf(proposalId)).to.be.reverted;

await mine(10);
await agentDAO.castVoteWithReasonAndParams(proposalId, 1, "lfg", "0x");

// Proposal should be auto executed
expect(await serviceNft.ownerOf(proposalId)).to.equal(agent.tba);
const state = await agentDAO.state(proposalId);
expect(state).to.equal(4n);
await expect(agentDAO.execute(proposalId)).to.not.rejected;
expect(state).to.equal(7n);
await expect(agentDAO.execute(proposalId)).to.be.reverted;
});

it("should not allow early execution when forVotes < totalSupply although met quorum", async function () {
Expand Down
4 changes: 0 additions & 4 deletions test/contribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ describe("Contribution", function () {

await mine(600);

await agentDAO.execute(proposalId);
if (isModel) {
await minter.mint(proposalId);
}
Expand Down Expand Up @@ -546,7 +545,6 @@ describe("Contribution", function () {
await mine(1);
await agentDAO.connect(founder).castVote(proposalId, 1);
await mine(1);
await agentDAO.execute(proposalId);

// No agent token minted for dataset contribution
const c1 = await createContribution(
Expand Down Expand Up @@ -693,8 +691,6 @@ describe("Contribution", function () {

await mine(1);
await agentDAO.connect(founder).castVote(proposalId, 1);
await mine(1);
await agentDAO.execute(proposalId);

// No agent token minted for dataset contribution
const c1 = await createContribution(
Expand Down
Loading