Skip to content
Open
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
3 changes: 2 additions & 1 deletion contracts/agent/aibtc-agent-account.clar
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
(votingContract <action-proposal-voting-trait>)
(action <action-trait>)
(parameters (buff 2048))
(memo (optional (string-ascii 1024)))
(memo (optional (buff 4096)))
)
(begin
(asserts! (use-proposals-allowed) ERR_OPERATION_NOT_ALLOWED)
Expand All @@ -186,6 +186,7 @@
proposalContract: (contract-of votingContract),
action: (contract-of action),
parameters: parameters,
memo: memo,
sender: tx-sender,
caller: contract-caller,
},
Expand Down
68 changes: 33 additions & 35 deletions contracts/dao/extensions/aibtc-action-proposal-voting.clar
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,19 @@
;; data vars
;;

(define-data-var state
{
proposalCount: uint,
concludedProposalCount: uint,
executedProposalCount: uint,
lastProposalStacksBlock: uint,
lastProposalBitcoinBlock: uint,
}
{
proposalCount: u0,
concludedProposalCount: u0,
executedProposalCount: u0,
lastProposalStacksBlock: DEPLOYED_STACKS_BLOCK,
lastProposalBitcoinBlock: DEPLOYED_BITCOIN_BLOCK,
}
)
(define-data-var state {
proposalCount: uint,
concludedProposalCount: uint,
executedProposalCount: uint,
lastProposalStacksBlock: uint,
lastProposalBitcoinBlock: uint,
} {
proposalCount: u0,
concludedProposalCount: u0,
executedProposalCount: u0,
lastProposalStacksBlock: DEPLOYED_STACKS_BLOCK,
lastProposalBitcoinBlock: DEPLOYED_BITCOIN_BLOCK,
})

;; data maps
;;
Expand All @@ -103,7 +100,7 @@
caller: principal,
creator: principal,
liquidTokens: uint,
memo: (optional (string-ascii 1024)),
memo: (optional (buff 4096)),
;; from ProposalBlocks
createdBtc: uint,
createdStx: uint,
Expand Down Expand Up @@ -147,7 +144,7 @@
(define-public (create-action-proposal
(action <action-trait>)
(parameters (buff 2048))
(memo (optional (string-ascii 1024)))
(memo (optional (buff 4096)))
)
(let (
(currentState (var-get state))
Expand Down Expand Up @@ -223,11 +220,13 @@
ERR_SAVING_PROPOSAL
)
;; set last proposal created block height and increment proposal count
(var-set state (merge currentState {
lastProposalBitcoinBlock: createdBtc,
lastProposalStacksBlock: createdStx,
proposalCount: newId,
}))
(var-set state
(merge currentState {
lastProposalBitcoinBlock: createdBtc,
lastProposalStacksBlock: createdStx,
proposalCount: newId,
})
)
;; transfer the proposal bond to this contract
;; /g/.aibtc-faktory/dao_contract_token
(try! (contract-call? .aibtc-faktory transfer VOTING_BOND contract-caller SELF none))
Expand Down Expand Up @@ -474,9 +473,7 @@
;; proposal is past voting period
(asserts! (>= burnBlock voteEnd) ERR_PROPOSAL_VOTING_ACTIVE)
;; proposal is past execution delay
(asserts! (>= burnBlock execStart)
ERR_PROPOSAL_EXECUTION_DELAY
)
(asserts! (>= burnBlock execStart) ERR_PROPOSAL_EXECUTION_DELAY)
;; action must be the same as the one in proposal
(asserts! (is-eq (get action proposal) actionContract) ERR_INVALID_ACTION)
;; print conclusion event
Expand Down Expand Up @@ -522,13 +519,15 @@
)
(let ((currentState (var-get state)))
;; update proposal counts
(var-set state (merge currentState {
concludedProposalCount: (+ (get concludedProposalCount currentState) u1),
executedProposalCount: (if tryToExecute
(+ (get executedProposalCount currentState) u1)
(get executedProposalCount currentState)
),
}))
(var-set state
(merge currentState {
concludedProposalCount: (+ (get concludedProposalCount currentState) u1),
executedProposalCount: (if tryToExecute
(+ (get executedProposalCount currentState) u1)
(get executedProposalCount currentState)
),
})
)
;; try to execute the action if the proposal passed
(ok (if tryToExecute
;; try to run the action
Expand Down Expand Up @@ -577,8 +576,7 @@

(define-read-only (get-proposal (proposalId uint))
(match (map-get? Proposals proposalId)
proposal
(let (
proposal (let (
(createdBtc (get createdBtc proposal))
(voteStart (+ createdBtc VOTING_DELAY))
(voteEnd (+ voteStart VOTING_PERIOD))
Expand Down
2 changes: 1 addition & 1 deletion contracts/traits/aibtc-agent-account-traits.clar
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

(define-trait aibtc-account-proposals (
(create-action-proposal
(<dao-action-proposal-trait> <dao-action-trait> (buff 2048) (optional (string-ascii 1024)))
(<dao-action-proposal-trait> <dao-action-trait> (buff 2048) (optional (buff 4096)))
(response bool uint)
)
(vote-on-action-proposal
Expand Down
2 changes: 1 addition & 1 deletion contracts/traits/aibtc-dao-traits.clar
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
;; a voting contract to vote on whitelisted pre-defined actions
(define-trait action-proposal-voting (
(create-action-proposal
(<action> (buff 2048) (optional (string-ascii 1024)))
(<action> (buff 2048) (optional (buff 4096)))
(response bool uint)
)
(vote-on-action-proposal
Expand Down
93 changes: 93 additions & 0 deletions tests/contracts/agent/aibtc-agent-account-proposals-single.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Cl, cvToValue } from "@stacks/transactions";
import { describe, expect, it } from "vitest";
import { ErrCodeAgentAccount } from "../../../utilities/contract-error-codes";
import { setupFullContractRegistry } from "../../../utilities/contract-registry";
import { convertSIP019PrintEvent } from "../../../utilities/contract-helpers";
import {
completePrelaunch,
constructDao,
formatSerializedBuffer,
fundAgentAccount,
PROPOSAL_MESSAGE,
TEST_MEMO_BUFF,
} from "../../../utilities/dao-helpers";
import { dbgLog } from "../../../utilities/debug-logging";
import { AGENT_ACCOUNT_APPROVAL_TYPES } from "../../../utilities/agent-account-types";

// setup accounts
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;

// setup contract info for tests
const registry = setupFullContractRegistry();

const contractAddress = registry.getContractAddressByTypeAndSubtype(
"AGENT",
"AGENT_ACCOUNT"
);
const contractName = contractAddress.split(".")[1];

const actionProposalsContractAddress =
registry.getContractAddressByTypeAndSubtype(
"EXTENSIONS",
"ACTION_PROPOSAL_VOTING"
);
const sendMessageActionContractAddress =
registry.getContractAddressByTypeAndSubtype("ACTIONS", "SEND_MESSAGE");

describe(`public functions: ${contractName}`, () => {
////////////////////////////////////////
// create-action-proposal() tests
////////////////////////////////////////
it("create-action-proposal() emits the correct notification event", () => {
// arrange
const message = Cl.stringUtf8(PROPOSAL_MESSAGE);
const expectedEvent = {
notification: "aibtc-agent-account/create-action-proposal",
payload: {
proposalContract: actionProposalsContractAddress,
action: sendMessageActionContractAddress,
parameters: cvToValue(formatSerializedBuffer(message)),
memo: cvToValue(TEST_MEMO_BUFF),
sender: deployer,
caller: deployer,
},
};
completePrelaunch(deployer);
fundAgentAccount(contractAddress, deployer);
constructDao(deployer);

// approve the proposal contract
const approveReceipt = simnet.callPublicFn(
contractAddress,
"approve-contract",
[
Cl.principal(actionProposalsContractAddress),
Cl.uint(AGENT_ACCOUNT_APPROVAL_TYPES.VOTING),
],
deployer
);
expect(approveReceipt.result).toBeOk(Cl.bool(true));

// act
const receipt = simnet.callPublicFn(
contractAddress,
"create-action-proposal",
[
Cl.principal(actionProposalsContractAddress),
Cl.principal(sendMessageActionContractAddress),
formatSerializedBuffer(message),
TEST_MEMO_BUFF,
],
deployer
);

// assert
expect(receipt.result).toBeOk(Cl.bool(true));
const event = receipt.events[0];
expect(event).toBeDefined();
const printEvent = convertSIP019PrintEvent(receipt.events[0]);
dbgLog(printEvent, { titleBefore: "create-action-proposal() event" });
expect(printEvent).toStrictEqual(expectedEvent);
});
});
Loading
Loading