Skip to content

Commit 85cfe9d

Browse files
committed
debug: add logging because at-block get-balance returns 0
1 parent 54c4c1d commit 85cfe9d

File tree

3 files changed

+103
-30
lines changed

3 files changed

+103
-30
lines changed

contracts/dao/extensions/aibtc-core-proposals.clar

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
createdAt: uint, ;; block height
4747
caller: principal, ;; contract caller
4848
creator: principal, ;; proposal creator (tx-sender)
49-
startBlock: uint, ;; block height
50-
endBlock: uint, ;; block height
49+
startBlockStx: uint, ;; block height for at-block calls
50+
startBlock: uint, ;; burn block height
51+
endBlock: uint, ;; burn block height
5152
votesFor: uint, ;; total votes for
5253
votesAgainst: uint, ;; total votes against
5354
liquidTokens: uint, ;; liquid tokens
@@ -97,6 +98,7 @@
9798
createdAt: burn-block-height,
9899
caller: contract-caller,
99100
creator: tx-sender,
101+
startBlockStx: block-height,
100102
startBlock: burn-block-height,
101103
endBlock: (+ burn-block-height VOTING_PERIOD),
102104
votesFor: u0,
@@ -112,7 +114,7 @@
112114
(
113115
(proposalContract (contract-of proposal))
114116
(proposalRecord (unwrap! (map-get? Proposals proposalContract) ERR_PROPOSAL_NOT_FOUND))
115-
(proposalBlock (get startBlock proposalRecord))
117+
(proposalBlock (get startBlockStx proposalRecord))
116118
(proposalBlockHash (unwrap! (get-block-hash proposalBlock) ERR_RETRIEVING_START_BLOCK_HASH))
117119
(senderBalanceResponse (at-block proposalBlockHash (contract-call? .aibtc-token get-balance tx-sender)))
118120
(senderBalance (unwrap-panic senderBalanceResponse))
@@ -194,7 +196,7 @@
194196
(let
195197
(
196198
(proposalRecord (unwrap! (map-get? Proposals (contract-of proposal)) ERR_PROPOSAL_NOT_FOUND))
197-
(proposalBlockHash (unwrap! (get-block-hash (get startBlock proposalRecord)) ERR_RETRIEVING_START_BLOCK_HASH))
199+
(proposalBlockHash (unwrap! (get-block-hash (get startBlockStx proposalRecord)) ERR_RETRIEVING_START_BLOCK_HASH))
198200
)
199201
(at-block proposalBlockHash (contract-call? .aibtc-token get-balance who))
200202
)

tests/dao/extensions/aibtc-onchain-messaging.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ describe(`extension: ${contractName}`, () => {
7474
console.log("proposalReceipt");
7575
console.log(proposalReceipt);
7676

77+
const proposalDetails = simnet.callReadOnlyFn(
78+
`${deployer}.aibtc-core-proposals`,
79+
"get-proposal",
80+
[Cl.principal(proposalContractAddress)],
81+
deployer
82+
);
83+
84+
console.log("proposalDetails");
85+
console.log(cvToValue(proposalDetails.result));
86+
87+
simnet.mineEmptyBlocks(100);
88+
7789
const votingPowerReceipt = simnet.callReadOnlyFn(
7890
`${deployer}.aibtc-core-proposals`,
7991
"get-voting-power",
@@ -94,7 +106,17 @@ describe(`extension: ${contractName}`, () => {
94106
console.log("addressBalanceReceipt");
95107
console.log(cvToValue(addressBalanceReceipt.result));
96108

97-
expect(proposalReceipt.result).toBeOk(Cl.bool(true));
109+
const voteReceipt = simnet.callPublicFn(
110+
`${deployer}.aibtc-core-proposals`,
111+
"vote-on-proposal",
112+
[Cl.principal(proposalContractAddress), Cl.bool(true)],
113+
deployer
114+
);
115+
116+
console.log("voteReceipt");
117+
console.log(voteReceipt);
118+
119+
expect(voteReceipt.result).toBeOk(Cl.bool(true));
98120
});
99121

100122
/*

tests/test-utilities.ts

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { Cl, cvToValue } from "@stacks/transactions";
33
export const actionProposalsContractName = "aibtc-action-proposals";
44
export const coreProposalsContractName = "aibtc-core-proposals";
55

6+
function getPercentageOfSupply(amount: number, totalSupply: number) {
7+
const rawPercentage = (amount / totalSupply) * 100;
8+
const percentage = rawPercentage.toFixed(2);
9+
return `${percentage}% supply`;
10+
}
11+
612
export function getDaoTokens(deployer: string, address: string) {
713
const tokenContractName = "aibtc-token";
814
const tokenContractAddress = `${deployer}.${tokenContractName}`;
@@ -17,34 +23,48 @@ export function getDaoTokens(deployer: string, address: string) {
1723
[],
1824
deployer
1925
);
20-
const totalSupply = cvToValue(getTotalSupplyReceipt.result);
26+
const totalSupply = parseInt(cvToValue(getTotalSupplyReceipt.result).value);
2127

2228
const getTreasuryBalanceReceipt = simnet.callReadOnlyFn(
2329
tokenContractAddress,
2430
"get-balance",
2531
[Cl.principal(treasuryContractAddress)],
2632
deployer
2733
);
28-
const treasuryBalance = cvToValue(getTreasuryBalanceReceipt.result);
34+
const treasuryBalance = parseInt(
35+
cvToValue(getTreasuryBalanceReceipt.result).value
36+
);
2937

3038
const getTokenDexBalanceReceipt = simnet.callReadOnlyFn(
3139
tokenContractAddress,
3240
"get-balance",
3341
[Cl.principal(tokenDexContractAddress)],
3442
deployer
3543
);
36-
const tokenDexBalance = cvToValue(getTokenDexBalanceReceipt.result);
44+
const tokenDexBalance = parseInt(
45+
cvToValue(getTokenDexBalanceReceipt.result).value
46+
);
3747

38-
const liquidTokenSupply =
39-
parseInt(totalSupply.value) -
40-
parseInt(treasuryBalance.value) -
41-
parseInt(tokenDexBalance.value);
48+
const liquidTokenSupply = totalSupply - treasuryBalance - tokenDexBalance;
4249

4350
console.log("BEFORE BUY");
51+
console.log("=========================");
4452
console.log("totalSupply", totalSupply);
45-
console.log("treasuryBalance", treasuryBalance);
46-
console.log("tokenDexBalance", tokenDexBalance);
47-
console.log("liquidTokenSupply", liquidTokenSupply);
53+
console.log(
54+
"treasuryBalance",
55+
treasuryBalance,
56+
getPercentageOfSupply(treasuryBalance, totalSupply)
57+
);
58+
console.log(
59+
"tokenDexBalance",
60+
tokenDexBalance,
61+
getPercentageOfSupply(tokenDexBalance, totalSupply)
62+
);
63+
console.log(
64+
"liquidTokenSupply",
65+
liquidTokenSupply,
66+
getPercentageOfSupply(liquidTokenSupply, totalSupply)
67+
);
4868

4969
const getDaoTokensReceipt = simnet.callPublicFn(
5070
tokenDexContractAddress,
@@ -81,28 +101,57 @@ export function getDaoTokens(deployer: string, address: string) {
81101
deployer
82102
);
83103

84-
const totalSupply2 = cvToValue(getTotalSupplyReceipt2.result);
85-
const treasuryBalance2 = cvToValue(getTreasuryBalanceReceipt2.result);
86-
const tokenDexBalance2 = cvToValue(getTokenDexBalanceReceipt2.result);
104+
const totalSupply2 = parseInt(cvToValue(getTotalSupplyReceipt2.result).value);
105+
const treasuryBalance2 = parseInt(
106+
cvToValue(getTreasuryBalanceReceipt2.result).value
107+
);
108+
const tokenDexBalance2 = parseInt(
109+
cvToValue(getTokenDexBalanceReceipt2.result).value
110+
);
87111

88-
const liquidTokenSupply2 =
89-
parseInt(totalSupply2.value) -
90-
parseInt(treasuryBalance2.value) -
91-
parseInt(tokenDexBalance2.value);
112+
const liquidTokenSupply2 = totalSupply2 - treasuryBalance2 - tokenDexBalance2;
92113

93114
console.log("AFTER BUY");
115+
console.log("=========================");
94116
console.log("totalSupply2", totalSupply2);
95-
console.log("treasuryBalance2", treasuryBalance2);
96-
console.log("tokenDexBalance2", tokenDexBalance2);
97-
console.log("liquidTokenSupply2", liquidTokenSupply2);
117+
console.log(
118+
"treasuryBalance2",
119+
treasuryBalance2,
120+
getPercentageOfSupply(treasuryBalance2, totalSupply2)
121+
);
122+
console.log(
123+
"tokenDexBalance2",
124+
tokenDexBalance2,
125+
getPercentageOfSupply(tokenDexBalance2, totalSupply2)
126+
);
127+
console.log(
128+
"liquidTokenSupply2",
129+
liquidTokenSupply2,
130+
getPercentageOfSupply(liquidTokenSupply2, totalSupply2)
131+
);
98132

99-
const addressBalance = cvToValue(addressBalanceReceipt.result);
100-
const addressVotingPower =
101-
parseInt(addressBalance.value) / parseInt(totalSupply2.value);
133+
const addressBalance = parseInt(
134+
cvToValue(addressBalanceReceipt.result).value
135+
);
136+
const addressVotingPower = addressBalance / liquidTokenSupply2;
102137

103138
console.log("ADDRESS INFO");
104-
console.log("addressBalance", addressBalance);
105-
console.log("addressBalance voting power", addressVotingPower);
139+
console.log("=========================");
140+
console.log(
141+
"addressBalance",
142+
addressBalance,
143+
getPercentageOfSupply(addressBalance, totalSupply2)
144+
);
145+
console.log(
146+
"addressBalance voting power calculated",
147+
addressVotingPower,
148+
getPercentageOfSupply(addressBalance, liquidTokenSupply2)
149+
);
150+
151+
/*
152+
;; if VOTING_QUORUM <= ((votesFor * 100) / liquidTokens)
153+
(votePassed (<= VOTING_QUORUM (/ (* (get votesFor proposalRecord) u100) (get liquidTokens proposalRecord))))
154+
*/
106155

107156
return getDaoTokensReceipt;
108157
}

0 commit comments

Comments
 (0)