DA0-DA0 / dao-contracts

CosmWasm smart contracts for Interchain DAOs.
https://docs.daodao.zone
BSD 3-Clause "New" or "Revised" License
202 stars 132 forks source link

OmniFlix NFT (x/onft) staked voting module #838

Open NoahSaso opened 3 weeks ago

NoahSaso commented 3 weeks ago

This PR upgrades cw-multi-test to v0.20.1 so that we can add custom Stargate query and message handlers to mock Omniflix's x/onft module.

dao-voting-onft-staked

This is a basic implementation of an NFT staking contract that supports OmniFlix's NFT standard: x/onft.

Staked tokens can be unbonded with a configurable unbonding period. Staked balances can be queried at any arbitrary height by external contracts. This contract implements the interface needed to be a DAO DAO voting module.

Stake process

Unlike the base cw721 smart contract, the x/onft SDK module doesn't support executing a smart contract on NFT transfer, so the stake process is broken up into three steps:

  1. The sender calls PrepareStake to inform this staking contract of the NFTs that are about to be staked. This will succeed only if the sender currently owns the NFT(s).
  2. The sender then transfers the NFT(s) to the staking contract.
  3. The sender calls ConfirmStake on this staking contract which confirms the NFTs were transferred to it and registers the stake.

In case this process is interrupted, or executed incorrectly (e.g. the sender accidentally transfers an NFT to the staking contract without first preparing it), there is also a CancelStake action to help recover NFTs. If called by:

The recipient field only applies when the sender is the DAO. In the other cases, the NFT(s) will always be sent back to the sender. Note: if the NFTs were sent to the staking contract, but no stake was prepared, only the DAO will be able to correct this and send them somewhere.

The PrepareStake step overrides any previous PrepareStake calls as long as the new sender owns the NFT(s) and the first stake was never confirmed (which should be impossible if someone else now owns the NFT(s)). Thus there is no combination of messages or steps where someone can stake nor prevent stake when it would otherwise be valid. A stake is only ever confirmed if it was prepared and transferred by the same address confirming, and the DAO can always recover an NFT that accidentally skipped the preparation step.

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 99.50025% with 10 lines in your changes missing coverage. Please review.

Project coverage is 96.39%. Comparing base (87485be) to head (ba5fce5). Report is 2 commits behind head on development.

Files Patch % Lines
...oting-onft-staked/src/testing/omniflix_stargate.rs 96.00% 5 Missing :warning:
...s/voting/dao-voting-onft-staked/src/testing/app.rs 80.00% 3 Missing :warning:
contracts/voting/dao-voting-onft-staked/src/msg.rs 80.00% 1 Missing :warning:
...voting/dao-voting-onft-staked/src/testing/tests.rs 99.88% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## development #838 +/- ## =============================================== + Coverage 96.26% 96.39% +0.13% =============================================== Files 209 229 +20 Lines 53514 57986 +4472 =============================================== + Hits 51513 55898 +4385 - Misses 2001 2088 +87 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.