Hi all.
I am actually planning to make a dao smart contract and dao token in agorand is there any reference git link or video anything that anyone can share.
Hi,
In my dapp I am putting all the stake collected by voting in a staking account.
Now I want to distribute this collected stake to all the yes voter based on how much they had staked.
How can I do that. Will I have to save the addresses of all the voters for the?
The simplest solution is to store, for each user, how much they stake and the vote they made in their local storage.
Then to distribute the stake to all the yes voter, you will need to ask each yes voter to make a transaction to get back their stake. The smart contract will check their local storage and check they voted yes. They will compute the amount to distribute using the amount they staked and the total amount staked (that you need to store in global storage).
Note: since global storage is limited to 64 key/value, you cannot store all the addresses there, instead you need to use local storage of each user. If you don’t know what “local storage” and “global storage” mean, please read Smart contract details - Algorand Developer Portal
Okay I will try this.
Thanks a lot!
Hi.
I am facing some issue in token transfer for the dao can anyone please check this If what I have done makes sense.
I am trying to transfer tokens to a specific staking tokens and these tokens are the ones participants put on stake while voting.
If((Btoi(Txn.application_args[2]) >= App.globalGet(min_stake_per_address))).Then(
Seq(
If((Btoi(Txn.application_args[2]) <= App.globalGet(max_stake_per_address))).Then(
If(Btoi(Txn.application_args[1]) == Int(1)).Then(
Seq(
App.globalPut(Bytes("Yes_count"), yes_count.load() + Btoi(Txn.application_args[2]))
InnerTxnBuilder.Begin(),
InnerTxnBuilder.SetFields(
{
TxnField.type_enum: TxnType.AssetTransfer,
TxnField.xfer_asset: token_ID,
TxnField.sender: Global.current_application_address(),
TxnField.asset_receiver: App.globalGet(staking_account),
TxnField.asset_amount: App.globalGet(proposal_amount),
}
),
InnerTxnBuilder.Submit(),
)
),
.Else(
App.globalPut(Bytes("No_count"), no_count.load() + Btoi(Txn.application_args[2]))
)
),
)
),
Approve(),
)
Is there anyother better way to do it?
Here are some comments:
- instead of nested
If
, I strongly recommend usingAssert
like:
Seq([
Assert(Btoi(Txn.application_args[2]) >= App.globalGet(min_stake_per_address)),
Assert(Btoi(Txn.application_args[2]) <= App.globalGet(max_stake_per_address)),
...
- How do you prevent the user from voting multiple times?
- When counting the no votes, it does not verify that
Txn.application_args[2]
is valid.
Hi.
Okay I’ll try with ‘Assert’
Also is there any limit on how many asserts can be used?
- To avoid multiple voing what I am doing is the when particpant votes lets say he has 5 tokens then he can only vote that much my depositing that many tokens.
- And for no count I have taken a flag of accept which timebeing i am giving from postman. If the flag is no the no count are getting added.
No limits apart from the program size and cost limits.
See The Algorand Virtual Machine (AVM) and TEAL. - Algorand Developer Portal and Algorand parameter tables - Algorand Developer Portal
Great thanks!
I’ll try that!