From 599abbb55808179238151ea3fa7d997587e75816 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 15 Jul 2024 14:10:32 +0200 Subject: [PATCH] regen schemas --- .../schema/dao-rewards-distributor.json | 323 +++++++++++++----- .../dao-rewards-distributor/src/contract.rs | 13 +- 2 files changed, 246 insertions(+), 90 deletions(-) diff --git a/contracts/distribution/dao-rewards-distributor/schema/dao-rewards-distributor.json b/contracts/distribution/dao-rewards-distributor/schema/dao-rewards-distributor.json index 37f979a11..3b2a1aef0 100644 --- a/contracts/distribution/dao-rewards-distributor/schema/dao-rewards-distributor.json +++ b/contracts/distribution/dao-rewards-distributor/schema/dao-rewards-distributor.json @@ -139,31 +139,30 @@ ], "properties": { "register_reward_denom": { + "$ref": "#/definitions/RegisterRewardDenomMsg" + } + }, + "additionalProperties": false + }, + { + "description": "updates the reward emission rate for a registered denom", + "type": "object", + "required": [ + "update_reward_emission_rate" + ], + "properties": { + "update_reward_emission_rate": { "type": "object", "required": [ "denom", - "emission_rate", - "hook_caller", - "vp_contract" + "emission_rate" ], "properties": { "denom": { - "$ref": "#/definitions/UncheckedDenom" + "type": "string" }, "emission_rate": { "$ref": "#/definitions/RewardEmissionRate" - }, - "hook_caller": { - "type": "string" - }, - "vp_contract": { - "type": "string" - }, - "withdraw_destination": { - "type": [ - "string", - "null" - ] } }, "additionalProperties": false @@ -450,6 +449,36 @@ } ] }, + "RegisterRewardDenomMsg": { + "type": "object", + "required": [ + "denom", + "emission_rate", + "hook_caller", + "vp_contract" + ], + "properties": { + "denom": { + "$ref": "#/definitions/UncheckedDenom" + }, + "emission_rate": { + "$ref": "#/definitions/RewardEmissionRate" + }, + "hook_caller": { + "type": "string" + }, + "vp_contract": { + "type": "string" + }, + "withdraw_destination": { + "type": [ + "string", + "null" + ] + } + }, + "additionalProperties": false + }, "RewardEmissionRate": { "description": "defines how many tokens (amount) should be distributed per amount of time (duration). e.g. 5udenom per hour.", "type": "object", @@ -673,39 +702,29 @@ "description": "the state of a denom's reward distribution", "type": "object", "required": [ + "active_epoch_config", "denom", - "emission_rate", - "ends_at", "funded_amount", + "historic_epoch_configs", "hook_caller", "last_update", - "started_at", - "total_earned_puvp", "vp_contract", "withdraw_destination" ], "properties": { - "denom": { - "description": "validated denom (native or cw20)", - "allOf": [ - { - "$ref": "#/definitions/Denom" - } - ] - }, - "emission_rate": { - "description": "reward emission rate", + "active_epoch_config": { + "description": "current denom distribution epoch configuration", "allOf": [ { - "$ref": "#/definitions/RewardEmissionRate" + "$ref": "#/definitions/EpochConfig" } ] }, - "ends_at": { - "description": "the time when all funded rewards are allocated to users and thus the distribution period ends.", + "denom": { + "description": "validated denom (native or cw20)", "allOf": [ { - "$ref": "#/definitions/Expiration" + "$ref": "#/definitions/Denom" } ] }, @@ -717,6 +736,13 @@ } ] }, + "historic_epoch_configs": { + "description": "historic denom distribution epochs", + "type": "array", + "items": { + "$ref": "#/definitions/EpochConfig" + } + }, "hook_caller": { "description": "address that will update the reward split when the voting power distribution changes", "allOf": [ @@ -733,22 +759,6 @@ } ] }, - "started_at": { - "description": "the time when the current reward distribution period started. period finishes iff it reaches its end.", - "allOf": [ - { - "$ref": "#/definitions/Expiration" - } - ] - }, - "total_earned_puvp": { - "description": "total rewards earned per unit voting power from started_at to last_update", - "allOf": [ - { - "$ref": "#/definitions/Uint256" - } - ] - }, "vp_contract": { "description": "address to query the voting power", "allOf": [ @@ -772,6 +782,33 @@ "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" }, + "BlockInfo": { + "type": "object", + "required": [ + "chain_id", + "height", + "time" + ], + "properties": { + "chain_id": { + "type": "string" + }, + "height": { + "description": "The height of a block is the number of blocks preceding it in the blockchain.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "time": { + "description": "Absolute time of the block creation in seconds since the UNIX epoch (00:00:00 on 1970-01-01 UTC).\n\nThe source of this is the [BFT Time in Tendermint](https://github.com/tendermint/tendermint/blob/58dc1726/spec/consensus/bft-time.md), which has the same nanosecond precision as the `Timestamp` type.\n\n# Examples\n\nUsing chrono:\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; # extern crate chrono; use chrono::NaiveDateTime; let seconds = env.block.time.seconds(); let nsecs = env.block.time.subsec_nanos(); let dt = NaiveDateTime::from_timestamp(seconds as i64, nsecs as u32); ```\n\nCreating a simple millisecond-precision timestamp (as used in JavaScript):\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; let millis = env.block.time.nanos() / 1_000_000; ```", + "allOf": [ + { + "$ref": "#/definitions/Timestamp" + } + ] + } + } + }, "Denom": { "oneOf": [ { @@ -834,6 +871,61 @@ } ] }, + "EpochConfig": { + "type": "object", + "required": [ + "emission_rate", + "ends_at", + "started_at", + "total_earned_puvp" + ], + "properties": { + "emission_rate": { + "description": "reward emission rate", + "allOf": [ + { + "$ref": "#/definitions/RewardEmissionRate" + } + ] + }, + "ends_at": { + "description": "the time when all funded rewards are allocated to users and thus the distribution period ends.", + "allOf": [ + { + "$ref": "#/definitions/Expiration" + } + ] + }, + "finish_height": { + "description": "finish block height", + "anyOf": [ + { + "$ref": "#/definitions/BlockInfo" + }, + { + "type": "null" + } + ] + }, + "started_at": { + "description": "the time when the current reward distribution period started. period finishes iff it reaches its end.", + "allOf": [ + { + "$ref": "#/definitions/Expiration" + } + ] + }, + "total_earned_puvp": { + "description": "total rewards earned per unit voting power from started_at to last_update", + "allOf": [ + { + "$ref": "#/definitions/Uint256" + } + ] + } + }, + "additionalProperties": false + }, "Expiration": { "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", "oneOf": [ @@ -1109,6 +1201,33 @@ "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" }, + "BlockInfo": { + "type": "object", + "required": [ + "chain_id", + "height", + "time" + ], + "properties": { + "chain_id": { + "type": "string" + }, + "height": { + "description": "The height of a block is the number of blocks preceding it in the blockchain.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "time": { + "description": "Absolute time of the block creation in seconds since the UNIX epoch (00:00:00 on 1970-01-01 UTC).\n\nThe source of this is the [BFT Time in Tendermint](https://github.com/tendermint/tendermint/blob/58dc1726/spec/consensus/bft-time.md), which has the same nanosecond precision as the `Timestamp` type.\n\n# Examples\n\nUsing chrono:\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; # extern crate chrono; use chrono::NaiveDateTime; let seconds = env.block.time.seconds(); let nsecs = env.block.time.subsec_nanos(); let dt = NaiveDateTime::from_timestamp(seconds as i64, nsecs as u32); ```\n\nCreating a simple millisecond-precision timestamp (as used in JavaScript):\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; let millis = env.block.time.nanos() / 1_000_000; ```", + "allOf": [ + { + "$ref": "#/definitions/Timestamp" + } + ] + } + } + }, "Denom": { "oneOf": [ { @@ -1141,39 +1260,29 @@ "description": "the state of a denom's reward distribution", "type": "object", "required": [ + "active_epoch_config", "denom", - "emission_rate", - "ends_at", "funded_amount", + "historic_epoch_configs", "hook_caller", "last_update", - "started_at", - "total_earned_puvp", "vp_contract", "withdraw_destination" ], "properties": { - "denom": { - "description": "validated denom (native or cw20)", - "allOf": [ - { - "$ref": "#/definitions/Denom" - } - ] - }, - "emission_rate": { - "description": "reward emission rate", + "active_epoch_config": { + "description": "current denom distribution epoch configuration", "allOf": [ { - "$ref": "#/definitions/RewardEmissionRate" + "$ref": "#/definitions/EpochConfig" } ] }, - "ends_at": { - "description": "the time when all funded rewards are allocated to users and thus the distribution period ends.", + "denom": { + "description": "validated denom (native or cw20)", "allOf": [ { - "$ref": "#/definitions/Expiration" + "$ref": "#/definitions/Denom" } ] }, @@ -1185,6 +1294,13 @@ } ] }, + "historic_epoch_configs": { + "description": "historic denom distribution epochs", + "type": "array", + "items": { + "$ref": "#/definitions/EpochConfig" + } + }, "hook_caller": { "description": "address that will update the reward split when the voting power distribution changes", "allOf": [ @@ -1201,22 +1317,6 @@ } ] }, - "started_at": { - "description": "the time when the current reward distribution period started. period finishes iff it reaches its end.", - "allOf": [ - { - "$ref": "#/definitions/Expiration" - } - ] - }, - "total_earned_puvp": { - "description": "total rewards earned per unit voting power from started_at to last_update", - "allOf": [ - { - "$ref": "#/definitions/Uint256" - } - ] - }, "vp_contract": { "description": "address to query the voting power", "allOf": [ @@ -1270,6 +1370,61 @@ } ] }, + "EpochConfig": { + "type": "object", + "required": [ + "emission_rate", + "ends_at", + "started_at", + "total_earned_puvp" + ], + "properties": { + "emission_rate": { + "description": "reward emission rate", + "allOf": [ + { + "$ref": "#/definitions/RewardEmissionRate" + } + ] + }, + "ends_at": { + "description": "the time when all funded rewards are allocated to users and thus the distribution period ends.", + "allOf": [ + { + "$ref": "#/definitions/Expiration" + } + ] + }, + "finish_height": { + "description": "finish block height", + "anyOf": [ + { + "$ref": "#/definitions/BlockInfo" + }, + { + "type": "null" + } + ] + }, + "started_at": { + "description": "the time when the current reward distribution period started. period finishes iff it reaches its end.", + "allOf": [ + { + "$ref": "#/definitions/Expiration" + } + ] + }, + "total_earned_puvp": { + "description": "total rewards earned per unit voting power from started_at to last_update", + "allOf": [ + { + "$ref": "#/definitions/Uint256" + } + ] + } + }, + "additionalProperties": false + }, "Expiration": { "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", "oneOf": [ diff --git a/contracts/distribution/dao-rewards-distributor/src/contract.rs b/contracts/distribution/dao-rewards-distributor/src/contract.rs index b78965c63..161013d14 100644 --- a/contracts/distribution/dao-rewards-distributor/src/contract.rs +++ b/contracts/distribution/dao-rewards-distributor/src/contract.rs @@ -194,19 +194,20 @@ fn execute_shutdown( let reward_duration_scalar = ends_at - started_at; // find the % of reward_duration that remains from current block - let passed_units_since_start = match reward_state.active_epoch_config.emission_rate.duration { - Duration::Height(_) => Uint128::from(env.block.height - started_at), - Duration::Time(_) => Uint128::from(env.block.time.seconds() - started_at), - }; + let passed_scalar_units_since_start = + match reward_state.active_epoch_config.emission_rate.duration { + Duration::Height(_) => env.block.height - started_at, + Duration::Time(_) => env.block.time.seconds() - started_at, + }; // get the fraction of what part of rewards duration is in the past // and sub from 1 to get the remaining rewards let remaining_reward_duration_fraction = Decimal::one() .checked_sub(Decimal::from_ratio( - passed_units_since_start, + passed_scalar_units_since_start, reward_duration_scalar, )) - .map_err(|e| ContractError::Std(StdError::overflow(e)))?; + .map_err(|e| ContractError::Std(e.into()))?; // to get the clawback msg let clawback_msg = get_transfer_msg(