diff --git a/contracts/voting_escrow/src/contract.rs b/contracts/voting_escrow/src/contract.rs index f02bfc8..4953893 100644 --- a/contracts/voting_escrow/src/contract.rs +++ b/contracts/voting_escrow/src/contract.rs @@ -3,21 +3,23 @@ use astroport::asset::{addr_opt_validate, validate_native_denom}; use cosmwasm_std::entry_point; use cosmwasm_std::{ attr, coins, ensure, ensure_eq, to_json_binary, wasm_execute, BankMsg, Binary, CosmosMsg, Deps, - DepsMut, Empty, Env, MessageInfo, Response, StdError, StdResult, Uint128, + DepsMut, Empty, Env, MessageInfo, Order, Response, StdError, StdResult, Uint128, }; use cw2::set_contract_version; use cw20::{BalanceResponse, Logo, LogoInfo, MarketingInfoResponse, TokenInfoResponse}; use cw20_base::contract::{execute_update_marketing, query_marketing_info}; use cw20_base::state::{MinterData, TokenInfo, LOGO, MARKETING_INFO, TOKEN_INFO}; +use cw_storage_plus::Bound; use cw_utils::must_pay; use astroport_governance::emissions_controller; +use astroport_governance::emissions_controller::consts::MAX_PAGE_LIMIT; use astroport_governance::voting_escrow::{ Config, ExecuteMsg, InstantiateMsg, LockInfoResponse, QueryMsg, }; use crate::error::ContractError; -use crate::state::{get_total_vp, Lock, CONFIG, PRIVILEGED}; +use crate::state::{get_total_vp, Lock, CONFIG, LOCKED, PRIVILEGED}; /// Contract name that is used for migration. pub const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); @@ -299,6 +301,36 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { QueryMsg::TokenInfo {} => to_json_binary(&query_token_info(deps, env)?), QueryMsg::MarketingInfo {} => to_json_binary(&query_marketing_info(deps)?), QueryMsg::PrivilegedList {} => to_json_binary(&PRIVILEGED.load(deps.storage)?), + QueryMsg::UsersLockInfo { + limit, + start_after, + timestamp, + } => { + let limit = limit.unwrap_or(MAX_PAGE_LIMIT) as usize; + let start_after = addr_opt_validate(deps.api, &start_after)?; + let user_infos = LOCKED + .keys( + deps.storage, + start_after.as_ref().map(Bound::exclusive), + None, + Order::Ascending, + ) + .take(limit) + .map(|user| { + user.and_then(|user| { + let lock_info_resp: LockInfoResponse = Lock::load_at_ts( + deps.storage, + env.block.time.seconds(), + &user, + timestamp, + )? + .into(); + Ok((user, lock_info_resp)) + }) + }) + .collect::>>()?; + Ok(to_json_binary(&user_infos)?) + } } } diff --git a/contracts/voting_escrow/tests/voting_escrow_integration.rs b/contracts/voting_escrow/tests/voting_escrow_integration.rs index 2214b6d..9450450 100644 --- a/contracts/voting_escrow/tests/voting_escrow_integration.rs +++ b/contracts/voting_escrow/tests/voting_escrow_integration.rs @@ -263,6 +263,22 @@ fn test_general_queries() { let user_vp = helper.user_vp(&user1, None).unwrap(); assert_eq!(user_vp, cw20_bal_resp.balance); + let lock_info = helper.lock_info(&user1).unwrap(); + + let users_list: Vec<(Addr, LockInfoResponse)> = helper + .app + .wrap() + .query_wasm_smart( + &helper.vxastro_contract, + &QueryMsg::UsersLockInfo { + limit: Some(10), + start_after: None, + timestamp: None, + }, + ) + .unwrap(); + assert_eq!(users_list, vec![(user1.clone(), lock_info)]); + let marketing_info: MarketingInfoResponse = helper .app .wrap() diff --git a/packages/astroport-governance/src/voting_escrow.rs b/packages/astroport-governance/src/voting_escrow.rs index 1d02856..fbb36d7 100644 --- a/packages/astroport-governance/src/voting_escrow.rs +++ b/packages/astroport-governance/src/voting_escrow.rs @@ -96,6 +96,13 @@ pub enum QueryMsg { /// Return the list of addresses that are allowed to instantly unlock xASTRO #[returns(Vec)] PrivilegedList {}, + /// Returns paginated list of users with their respective LockInfo + #[returns(Vec<(Addr, LockInfoResponse)>)] + UsersLockInfo { + limit: Option, + start_after: Option, + timestamp: Option, + }, } /// This structure stores the main parameters for the voting escrow contract. diff --git a/schemas/astroport-voting-escrow/astroport-voting-escrow.json b/schemas/astroport-voting-escrow/astroport-voting-escrow.json index 33c2672..c648fc5 100644 --- a/schemas/astroport-voting-escrow/astroport-voting-escrow.json +++ b/schemas/astroport-voting-escrow/astroport-voting-escrow.json @@ -502,6 +502,44 @@ } }, "additionalProperties": false + }, + { + "description": "Returns paginated list of users with their respective LockInfo", + "type": "object", + "required": [ + "users_lock_info" + ], + "properties": { + "users_lock_info": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint8", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + }, + "timestamp": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false } ] }, @@ -748,6 +786,82 @@ "title": "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" + }, + "users_lock_info": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Array_of_Tuple_of_Addr_and_LockInfoResponse", + "type": "array", + "items": { + "type": "array", + "items": [ + { + "$ref": "#/definitions/Addr" + }, + { + "$ref": "#/definitions/LockInfoResponse" + } + ], + "maxItems": 2, + "minItems": 2 + }, + "definitions": { + "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" + }, + "LockInfoResponse": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "description": "The total number of xASTRO tokens that were deposited in the vxASTRO position", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "unlock_status": { + "description": "Unlocking status. None for positions in locked state", + "anyOf": [ + { + "$ref": "#/definitions/UnlockStatus" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + "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" + }, + "UnlockStatus": { + "type": "object", + "required": [ + "end", + "hub_confirmed" + ], + "properties": { + "end": { + "description": "The timestamp when position will be unlocked.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "hub_confirmed": { + "description": "Whether The Hub confirmed unlocking", + "type": "boolean" + } + }, + "additionalProperties": false + } + } } } } diff --git a/schemas/astroport-voting-escrow/raw/query.json b/schemas/astroport-voting-escrow/raw/query.json index 56ea9f4..491fcac 100644 --- a/schemas/astroport-voting-escrow/raw/query.json +++ b/schemas/astroport-voting-escrow/raw/query.json @@ -156,6 +156,44 @@ } }, "additionalProperties": false + }, + { + "description": "Returns paginated list of users with their respective LockInfo", + "type": "object", + "required": [ + "users_lock_info" + ], + "properties": { + "users_lock_info": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint8", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + }, + "timestamp": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false } ] } diff --git a/schemas/astroport-voting-escrow/raw/response_to_users_lock_info.json b/schemas/astroport-voting-escrow/raw/response_to_users_lock_info.json new file mode 100644 index 0000000..e332485 --- /dev/null +++ b/schemas/astroport-voting-escrow/raw/response_to_users_lock_info.json @@ -0,0 +1,76 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Array_of_Tuple_of_Addr_and_LockInfoResponse", + "type": "array", + "items": { + "type": "array", + "items": [ + { + "$ref": "#/definitions/Addr" + }, + { + "$ref": "#/definitions/LockInfoResponse" + } + ], + "maxItems": 2, + "minItems": 2 + }, + "definitions": { + "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" + }, + "LockInfoResponse": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "description": "The total number of xASTRO tokens that were deposited in the vxASTRO position", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "unlock_status": { + "description": "Unlocking status. None for positions in locked state", + "anyOf": [ + { + "$ref": "#/definitions/UnlockStatus" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + "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" + }, + "UnlockStatus": { + "type": "object", + "required": [ + "end", + "hub_confirmed" + ], + "properties": { + "end": { + "description": "The timestamp when position will be unlocked.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "hub_confirmed": { + "description": "Whether The Hub confirmed unlocking", + "type": "boolean" + } + }, + "additionalProperties": false + } + } +}