Too often I get asked, “How do you start contributing to a DAO?“ Most people assume you need to be a dev to contribute to a DAO, but code is just one of the many things which DAOs need. Crucial to DAO operations is figuring out what needs to be done to get our functions as decentralized, as autonomous, and as organized as possible. One such task was to design the AirSwap V4 staking contract.
The AirSwap protocols consist of DAO and DEX components. The DAO builds the DEX, which then funds the DAO. Core to the AirSwap DAO protocol is the staking contract. By staking AST, members signal their intent to participate in governance and help steer the protocol to become the standard peer-to-peer trading system. A good staking contract design needs to be intuitive and accessible (gas-wise) to enable smaller stakers to participate in the AirSwap ecosystem as well.

Staking in AirSwap is a linear vesting over a period of 20 weeks. This logic is pretty simple, until you consider multiple stakes being vested at the same time. For example, Alice stakes 100 AST at week 0, 200 AST at week 1 and 500 AST at week 7. How many tokens are unlocked at week 10?
To allow the contract to unlock the correct number of tokens would require looping over each stake and calculating how much tokens are vested as a function of
Initial staked amount
Initial time of stake
Current block time
Each loop requires additional gas each time the function is called. This means small stakers cannot slowly accumulate their positions without requiring a huge amount of gas to unstake later.
Over the course of spring 2023, I worked with smartcontrart to radically redesigned the staking contract based on a set of heuristics that the user would expect.
Max duration = 20 weeks.
Deposits should not change available staking balance.
Deposits should increase the time left to unstake.
Withdrawals should decrease the available staking balance.
Withdrawals should NOT change the time left to unstake.
Our final design tracked 3 variables for each staking address (vs 2 variables per staking tx): Staked balance, time of initial stake, time of full vest. Instead of creating a new stake for each tx, additional stakes simply increase the time to full vest (up to 20 weeks) based on the additional amount staked relative to its current balance.
With the changes, we no longer need to loop over every single staking tx made but can simply update 3 variables. Our new dynamic staking contract has now been implemented in AirSwap V4, resulting in significant gas savings to DAO members!
You don’t need to be a dev to help out in DAOs! In AirSwap we had marketers, operations, designers, and devs all working together to promote our mission of fully decentralized peer-to-peer swap protocols.
It’s fun and you get to learn loads! If anyone wants to check out what AirSwap is doing, head over to our discord and just chat with the folks there
Too often I get asked, “How do you start contributing to a DAO?“ Most people assume you need to be a dev to contribute to a DAO, but code is just one of the many things which DAOs need. Crucial to DAO operations is figuring out what needs to be done to get our functions as decentralized, as autonomous, and as organized as possible. One such task was to design the AirSwap V4 staking contract.
The AirSwap protocols consist of DAO and DEX components. The DAO builds the DEX, which then funds the DAO. Core to the AirSwap DAO protocol is the staking contract. By staking AST, members signal their intent to participate in governance and help steer the protocol to become the standard peer-to-peer trading system. A good staking contract design needs to be intuitive and accessible (gas-wise) to enable smaller stakers to participate in the AirSwap ecosystem as well.

Staking in AirSwap is a linear vesting over a period of 20 weeks. This logic is pretty simple, until you consider multiple stakes being vested at the same time. For example, Alice stakes 100 AST at week 0, 200 AST at week 1 and 500 AST at week 7. How many tokens are unlocked at week 10?
To allow the contract to unlock the correct number of tokens would require looping over each stake and calculating how much tokens are vested as a function of
Initial staked amount
Initial time of stake
Current block time
Each loop requires additional gas each time the function is called. This means small stakers cannot slowly accumulate their positions without requiring a huge amount of gas to unstake later.
Over the course of spring 2023, I worked with smartcontrart to radically redesigned the staking contract based on a set of heuristics that the user would expect.
Max duration = 20 weeks.
Deposits should not change available staking balance.
Deposits should increase the time left to unstake.
Withdrawals should decrease the available staking balance.
Withdrawals should NOT change the time left to unstake.
Our final design tracked 3 variables for each staking address (vs 2 variables per staking tx): Staked balance, time of initial stake, time of full vest. Instead of creating a new stake for each tx, additional stakes simply increase the time to full vest (up to 20 weeks) based on the additional amount staked relative to its current balance.
With the changes, we no longer need to loop over every single staking tx made but can simply update 3 variables. Our new dynamic staking contract has now been implemented in AirSwap V4, resulting in significant gas savings to DAO members!
You don’t need to be a dev to help out in DAOs! In AirSwap we had marketers, operations, designers, and devs all working together to promote our mission of fully decentralized peer-to-peer swap protocols.
It’s fun and you get to learn loads! If anyone wants to check out what AirSwap is doing, head over to our discord and just chat with the folks there
<100 subscribers
<100 subscribers
Share Dialog
Share Dialog
No comments yet