|
| 1 | +import { Cl, cvToValue } from "@stacks/transactions"; |
| 2 | + |
| 3 | +export const actionProposalsContractName = "aibtc-action-proposals"; |
| 4 | +export const coreProposalsContractName = "aibtc-core-proposals"; |
| 5 | + |
| 6 | +export function getDaoTokens(deployer: string, address: string) { |
| 7 | + const tokenContractName = "aibtc-token"; |
| 8 | + const tokenContractAddress = `${deployer}.${tokenContractName}`; |
| 9 | + const tokenDexContractName = "aibtc-token-dex"; |
| 10 | + const tokenDexContractAddress = `${deployer}.${tokenDexContractName}`; |
| 11 | + const tokenTreasuryContractName = "aibtc-treasury"; |
| 12 | + const treasuryContractAddress = `${deployer}.${tokenTreasuryContractName}`; |
| 13 | + |
| 14 | + const getTotalSupplyReceipt = simnet.callReadOnlyFn( |
| 15 | + tokenContractAddress, |
| 16 | + "get-total-supply", |
| 17 | + [], |
| 18 | + deployer |
| 19 | + ); |
| 20 | + const totalSupply = cvToValue(getTotalSupplyReceipt.result); |
| 21 | + |
| 22 | + const getTreasuryBalanceReceipt = simnet.callReadOnlyFn( |
| 23 | + tokenContractAddress, |
| 24 | + "get-balance", |
| 25 | + [Cl.principal(treasuryContractAddress)], |
| 26 | + deployer |
| 27 | + ); |
| 28 | + const treasuryBalance = cvToValue(getTreasuryBalanceReceipt.result); |
| 29 | + |
| 30 | + const getTokenDexBalanceReceipt = simnet.callReadOnlyFn( |
| 31 | + tokenContractAddress, |
| 32 | + "get-balance", |
| 33 | + [Cl.principal(tokenDexContractAddress)], |
| 34 | + deployer |
| 35 | + ); |
| 36 | + const tokenDexBalance = cvToValue(getTokenDexBalanceReceipt.result); |
| 37 | + |
| 38 | + const liquidTokenSupply = |
| 39 | + parseInt(totalSupply.value) - |
| 40 | + parseInt(treasuryBalance.value) - |
| 41 | + parseInt(tokenDexBalance.value); |
| 42 | + |
| 43 | + console.log("BEFORE BUY"); |
| 44 | + console.log("totalSupply", totalSupply); |
| 45 | + console.log("treasuryBalance", treasuryBalance); |
| 46 | + console.log("tokenDexBalance", tokenDexBalance); |
| 47 | + console.log("liquidTokenSupply", liquidTokenSupply); |
| 48 | + |
| 49 | + const getDaoTokensReceipt = simnet.callPublicFn( |
| 50 | + tokenDexContractAddress, |
| 51 | + "buy", |
| 52 | + [Cl.principal(tokenContractAddress), Cl.uint(1000000000)], // 1000 STX buy test |
| 53 | + address |
| 54 | + ); |
| 55 | + |
| 56 | + const getTreasuryBalanceReceipt2 = simnet.callReadOnlyFn( |
| 57 | + tokenContractAddress, |
| 58 | + "get-balance", |
| 59 | + [Cl.principal(treasuryContractAddress)], |
| 60 | + deployer |
| 61 | + ); |
| 62 | + |
| 63 | + const getTokenDexBalanceReceipt2 = simnet.callReadOnlyFn( |
| 64 | + tokenContractAddress, |
| 65 | + "get-balance", |
| 66 | + [Cl.principal(tokenDexContractAddress)], |
| 67 | + deployer |
| 68 | + ); |
| 69 | + |
| 70 | + const getTotalSupplyReceipt2 = simnet.callReadOnlyFn( |
| 71 | + tokenContractAddress, |
| 72 | + "get-total-supply", |
| 73 | + [], |
| 74 | + deployer |
| 75 | + ); |
| 76 | + |
| 77 | + const addressBalanceReceipt = simnet.callReadOnlyFn( |
| 78 | + tokenContractAddress, |
| 79 | + "get-balance", |
| 80 | + [Cl.principal(address)], |
| 81 | + deployer |
| 82 | + ); |
| 83 | + |
| 84 | + const totalSupply2 = cvToValue(getTotalSupplyReceipt2.result); |
| 85 | + const treasuryBalance2 = cvToValue(getTreasuryBalanceReceipt2.result); |
| 86 | + const tokenDexBalance2 = cvToValue(getTokenDexBalanceReceipt2.result); |
| 87 | + |
| 88 | + const liquidTokenSupply2 = |
| 89 | + parseInt(totalSupply2.value) - |
| 90 | + parseInt(treasuryBalance2.value) - |
| 91 | + parseInt(tokenDexBalance2.value); |
| 92 | + |
| 93 | + console.log("AFTER BUY"); |
| 94 | + console.log("totalSupply2", totalSupply2); |
| 95 | + console.log("treasuryBalance2", treasuryBalance2); |
| 96 | + console.log("tokenDexBalance2", tokenDexBalance2); |
| 97 | + console.log("liquidTokenSupply2", liquidTokenSupply2); |
| 98 | + |
| 99 | + const addressBalance = cvToValue(addressBalanceReceipt.result); |
| 100 | + const addressVotingPower = |
| 101 | + parseInt(addressBalance.value) / parseInt(totalSupply2.value); |
| 102 | + |
| 103 | + console.log("ADDRESS INFO"); |
| 104 | + console.log("addressBalance", addressBalance); |
| 105 | + console.log("addressBalance voting power", addressVotingPower); |
| 106 | + |
| 107 | + return getDaoTokensReceipt; |
| 108 | +} |
| 109 | + |
| 110 | +export function constructDao(deployer: string) { |
| 111 | + const baseDaoContractName = "aibtcdev-base-dao"; |
| 112 | + const baseDaoContractAddress = `${deployer}.${baseDaoContractName}`; |
| 113 | + const bootstrapContractName = "aibtc-base-bootstrap-initialization"; |
| 114 | + const bootstrapContractAddress = `${deployer}.${bootstrapContractName}`; |
| 115 | + |
| 116 | + const constructDaoReceipt = simnet.callPublicFn( |
| 117 | + baseDaoContractAddress, |
| 118 | + "construct", |
| 119 | + [Cl.principal(bootstrapContractAddress)], |
| 120 | + deployer |
| 121 | + ); |
| 122 | + |
| 123 | + return constructDaoReceipt; |
| 124 | +} |
| 125 | + |
| 126 | +export function passCoreProposal( |
| 127 | + proposalContractAddress: string, |
| 128 | + deployer: string |
| 129 | +) { |
| 130 | + // create-proposal |
| 131 | + const createProposalReceipt = simnet.callPublicFn( |
| 132 | + `${deployer}.${coreProposalsContractName}`, |
| 133 | + "create-proposal", |
| 134 | + [Cl.principal(proposalContractAddress)], |
| 135 | + deployer |
| 136 | + ); |
| 137 | + // temporary |
| 138 | + return createProposalReceipt; |
| 139 | + // vote-on-proposal |
| 140 | + // conclude-proposal |
| 141 | +} |
| 142 | + |
| 143 | +export function passActionProposal( |
| 144 | + proposalContractAddress: string, |
| 145 | + sender: string |
| 146 | +) { |
| 147 | + // propose-action |
| 148 | + // vote-on-proposal |
| 149 | + // conclude-propsal |
| 150 | +} |
0 commit comments