@@ -3,6 +3,12 @@ import { Cl, cvToValue } from "@stacks/transactions";
3
3
export const actionProposalsContractName = "aibtc-action-proposals" ;
4
4
export const coreProposalsContractName = "aibtc-core-proposals" ;
5
5
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
+
6
12
export function getDaoTokens ( deployer : string , address : string ) {
7
13
const tokenContractName = "aibtc-token" ;
8
14
const tokenContractAddress = `${ deployer } .${ tokenContractName } ` ;
@@ -17,34 +23,48 @@ export function getDaoTokens(deployer: string, address: string) {
17
23
[ ] ,
18
24
deployer
19
25
) ;
20
- const totalSupply = cvToValue ( getTotalSupplyReceipt . result ) ;
26
+ const totalSupply = parseInt ( cvToValue ( getTotalSupplyReceipt . result ) . value ) ;
21
27
22
28
const getTreasuryBalanceReceipt = simnet . callReadOnlyFn (
23
29
tokenContractAddress ,
24
30
"get-balance" ,
25
31
[ Cl . principal ( treasuryContractAddress ) ] ,
26
32
deployer
27
33
) ;
28
- const treasuryBalance = cvToValue ( getTreasuryBalanceReceipt . result ) ;
34
+ const treasuryBalance = parseInt (
35
+ cvToValue ( getTreasuryBalanceReceipt . result ) . value
36
+ ) ;
29
37
30
38
const getTokenDexBalanceReceipt = simnet . callReadOnlyFn (
31
39
tokenContractAddress ,
32
40
"get-balance" ,
33
41
[ Cl . principal ( tokenDexContractAddress ) ] ,
34
42
deployer
35
43
) ;
36
- const tokenDexBalance = cvToValue ( getTokenDexBalanceReceipt . result ) ;
44
+ const tokenDexBalance = parseInt (
45
+ cvToValue ( getTokenDexBalanceReceipt . result ) . value
46
+ ) ;
37
47
38
- const liquidTokenSupply =
39
- parseInt ( totalSupply . value ) -
40
- parseInt ( treasuryBalance . value ) -
41
- parseInt ( tokenDexBalance . value ) ;
48
+ const liquidTokenSupply = totalSupply - treasuryBalance - tokenDexBalance ;
42
49
43
50
console . log ( "BEFORE BUY" ) ;
51
+ console . log ( "=========================" ) ;
44
52
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
+ ) ;
48
68
49
69
const getDaoTokensReceipt = simnet . callPublicFn (
50
70
tokenDexContractAddress ,
@@ -81,28 +101,57 @@ export function getDaoTokens(deployer: string, address: string) {
81
101
deployer
82
102
) ;
83
103
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
+ ) ;
87
111
88
- const liquidTokenSupply2 =
89
- parseInt ( totalSupply2 . value ) -
90
- parseInt ( treasuryBalance2 . value ) -
91
- parseInt ( tokenDexBalance2 . value ) ;
112
+ const liquidTokenSupply2 = totalSupply2 - treasuryBalance2 - tokenDexBalance2 ;
92
113
93
114
console . log ( "AFTER BUY" ) ;
115
+ console . log ( "=========================" ) ;
94
116
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
+ ) ;
98
132
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 ;
102
137
103
138
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
+ */
106
155
107
156
return getDaoTokensReceipt ;
108
157
}
0 commit comments