CosmosContracts / juno

Open Source Platform for Interoperable Smart Contracts
Apache License 2.0
311 stars 171 forks source link

feat: CosmWasm modules #772

Open Reecepbcups opened 1 year ago

Reecepbcups commented 1 year ago

summary

Allow a contract to be uploaded through governance access to begin & end blockers.

logic flow

considerations

hacky (but simple) solution

future v2

issues

JakeHartnell commented 1 year ago

Nice! Kind of like the way twasm does it with the concept of privileges.

There are two new messages able to be called by governance:

Example usage in a contract: https://github.com/confio/poe-contracts/blob/main/contracts/tgrade-validator-voting/src/contract.rs#L260-L283

The nice thing about this approach is that it can easily be extended for functionality beyond BeginBlocker and EndBlocker. Here is the full list of privileges supported by twasm.

See the tg-bindings package for more inspiration: https://github.com/confio/poe-contracts/blob/main/packages/bindings/src/msg.rs

Most twasm logic lives in the privileges keeper: https://github.com/confio/tgrade/blob/main/x/twasm/keeper/privileged.go#L21C1-L21C1

Another nice thing about this approach is that the contract can be uploaded prior to the gov prop, as well as being able to do additional setup (or cleanup) upon being given privileges or having them removed.

Really think we should give twasm a good review as there is a lot of great prior art in there. Would be a great thing to upstream at some point too. Moreover, the design is robust enough to support more complex CW modules. Even if we don't support everything initially, would be good to have a pattern that can support more complexity in the future.

Here's another great example of a Tgrade smart contract utilizing BeginBlocker: https://github.com/confio/poe-contracts/blob/b7a8dbafd89cd70401dced518366f520b7089ff6/contracts/tgrade-valset/src/contract.rs#L679

Gas limits is a good call.