Skip to content

Commit

Permalink
feat(vxASTRO): add paginated list of vxASTRO holders
Browse files Browse the repository at this point in the history
  • Loading branch information
epanchee committed Dec 9, 2024
1 parent 0795721 commit 58ee731
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 2 deletions.
36 changes: 34 additions & 2 deletions contracts/voting_escrow/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -299,6 +301,36 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
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::<StdResult<Vec<_>>>()?;
Ok(to_json_binary(&user_infos)?)
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions contracts/voting_escrow/tests/voting_escrow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions packages/astroport-governance/src/voting_escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ pub enum QueryMsg {
/// Return the list of addresses that are allowed to instantly unlock xASTRO
#[returns(Vec<Addr>)]
PrivilegedList {},
/// Returns paginated list of users with their respective LockInfo
#[returns(Vec<(Addr, LockInfoResponse)>)]
UsersLockInfo {
limit: Option<u8>,
start_after: Option<String>,
timestamp: Option<u64>,
},
}

/// This structure stores the main parameters for the voting escrow contract.
Expand Down
114 changes: 114 additions & 0 deletions schemas/astroport-voting-escrow/astroport-voting-escrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
},
Expand Down Expand Up @@ -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
}
}
}
}
}
38 changes: 38 additions & 0 deletions schemas/astroport-voting-escrow/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 58ee731

Please sign in to comment.