Skip to content

Commit

Permalink
Cosmos native staking (#787)
Browse files Browse the repository at this point in the history
* Wooooooo

Co-authored-by: Reece Williams <[email protected]>
Co-authored-by: Jake Hartnell <[email protected]>

* Start Delegation Changes & Happy Path

* Fix errors

Co-authored-by: Jake Hartnell <[email protected]>
Co-authored-by: Reece Williams <[email protected]>

* Calculate Voting Power

* Pass Tests & Add Schema

* Format

---------

Co-authored-by: Reece Williams <[email protected]>
Co-authored-by: Jake Hartnell <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent c85b764 commit 8cc4888
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 1,294 deletions.
4 changes: 2 additions & 2 deletions contracts/voting/dao-voting-cosmos-staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dao-voting-cosmos-staking"
authors = ["Callum Anderson <[email protected]>", "Noah Saso <[email protected]>", "Jake Hartnell <[email protected]>"]
authors = ["Callum Anderson <[email protected]>", "Noah Saso <[email protected]>", "Jake Hartnell <[email protected]>", "Joel Smith <[email protected]>", "Reece Williams <[email protected]>"]
description = "A DAO DAO voting module based on native Cosmos Staking."
edition = { workspace = true }
license = { workspace = true }
Expand Down Expand Up @@ -47,4 +47,4 @@ dao-proposal-single = { workspace = true }
dao-proposal-hook-counter = { workspace = true }
dao-test-custom-factory = { workspace = true }
dao-testing = { workspace = true, features = ["test-tube"] }
serde = { workspace = true }
serde = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
{
"contract_name": "dao-voting-cosmos-staking",
"contract_version": "2.4.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"additionalProperties": false
},
"execute": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"type": "string",
"enum": []
},
"query": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"oneOf": [
{
"type": "object",
"required": [
"get_config"
],
"properties": {
"get_config": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"get_hooks"
],
"properties": {
"get_hooks": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"is_active"
],
"properties": {
"is_active": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns the voting power for an address at a given height.",
"type": "object",
"required": [
"voting_power_at_height"
],
"properties": {
"voting_power_at_height": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"type": "string"
},
"height": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns the total voting power at a given block heigh.",
"type": "object",
"required": [
"total_power_at_height"
],
"properties": {
"total_power_at_height": {
"type": "object",
"properties": {
"height": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns the address of the DAO this module belongs to.",
"type": "object",
"required": [
"dao"
],
"properties": {
"dao": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns contract version info.",
"type": "object",
"required": [
"info"
],
"properties": {
"info": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
"migrate": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"type": "object",
"additionalProperties": false
},
"sudo": null,
"responses": {
"dao": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Addr",
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"get_config": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Config",
"type": "object",
"properties": {
"unstaking_duration": {
"anyOf": [
{
"$ref": "#/definitions/Duration"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false,
"definitions": {
"Duration": {
"description": "Duration is a delta of time. You can add it to a BlockInfo or Expiration to move that further in the future. Note that an height-based Duration and a time-based Expiration cannot be combined",
"oneOf": [
{
"type": "object",
"required": [
"height"
],
"properties": {
"height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Time in seconds",
"type": "object",
"required": [
"time"
],
"properties": {
"time": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
]
}
}
},
"get_hooks": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "GetHooksResponse",
"type": "object",
"required": [
"hooks"
],
"properties": {
"hooks": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
},
"info": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InfoResponse",
"type": "object",
"required": [
"info"
],
"properties": {
"info": {
"$ref": "#/definitions/ContractVersion"
}
},
"additionalProperties": false,
"definitions": {
"ContractVersion": {
"type": "object",
"required": [
"contract",
"version"
],
"properties": {
"contract": {
"description": "contract is the crate name of the implementing contract, eg. `crate:cw20-base` we will use other prefixes for other languages, and their standard global namespacing",
"type": "string"
},
"version": {
"description": "version is any string that this implementation knows. It may be simple counter \"1\", \"2\". or semantic version on release tags \"v0.7.0\", or some custom feature flag list. the only code that needs to understand the version parsing is code that knows how to migrate from the given contract (and is tied to it's implementation somehow)",
"type": "string"
}
},
"additionalProperties": false
}
}
},
"is_active": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Boolean",
"type": "boolean"
},
"total_power_at_height": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "TotalPowerAtHeightResponse",
"type": "object",
"required": [
"height",
"power"
],
"properties": {
"height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"power": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false,
"definitions": {
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
},
"voting_power_at_height": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VotingPowerAtHeightResponse",
"type": "object",
"required": [
"height",
"power"
],
"properties": {
"height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"power": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false,
"definitions": {
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
}
}
}
Loading

0 comments on commit 8cc4888

Please sign in to comment.