Skip to content

Commit

Permalink
added legacy flag to NFT claims response
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 1, 2024
1 parent 84a74c2 commit 4c4eab5
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1019,14 +1019,25 @@
"NftClaim": {
"type": "object",
"required": [
"legacy",
"release_at",
"token_id"
],
"properties": {
"legacy": {
"description": "Whether the claim is a legacy claim.",
"type": "boolean"
},
"release_at": {
"$ref": "#/definitions/Expiration"
"description": "The expiration time of the claim.",
"allOf": [
{
"$ref": "#/definitions/Expiration"
}
]
},
"token_id": {
"description": "The token ID of the NFT being claimed.",
"type": "string"
}
},
Expand Down
22 changes: 17 additions & 5 deletions contracts/voting/dao-voting-cw721-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use dao_voting::threshold::{
ActiveThresholdResponse,
};

use crate::msg::{ClaimType, ExecuteMsg, InstantiateMsg, MigrateMsg, NftContract, QueryMsg};
use crate::msg::{
ClaimType, ExecuteMsg, InstantiateMsg, MigrateMsg, NftClaim, NftClaimsResponse, NftContract,
QueryMsg,
};
use crate::state::{
register_staked_nft, register_unstaked_nfts, Config, ACTIVE_THRESHOLD, CONFIG, DAO, HOOKS,
INITIAL_NFTS, LEGACY_NFT_CLAIMS, NFT_BALANCES, NFT_CLAIMS, STAKED_NFTS_PER_OWNER,
Expand Down Expand Up @@ -348,7 +351,6 @@ pub fn execute_claim_nfts(
ClaimType::All => {
let token_ids = NFT_CLAIMS
.query_claims(deps.as_ref(), &info.sender, None, None)?
.nft_claims
.into_iter()
.filter(|nft| nft.release_at.is_expired(&env.block))
.map(|nft| nft.token_id)
Expand Down Expand Up @@ -648,18 +650,28 @@ pub fn query_nft_claims(
.query_claims(deps, &addr)?
.nft_claims
.into_iter()
.map(|c| cw721_controllers::NftClaim::new(c.token_id, c.release_at))
.map(|c| NftClaim {
token_id: c.token_id,
release_at: c.release_at,
legacy: true,
})
.collect::<Vec<_>>();

// paginate all new claims
let claims = NFT_CLAIMS
.query_claims(deps, &addr, start_after.as_ref(), limit)?
.nft_claims;
.into_iter()
.map(|c| NftClaim {
token_id: c.token_id,
release_at: c.release_at,
legacy: false,
})
.collect::<Vec<_>>();

// combine legacy and new claims
let nft_claims = legacy_claims.into_iter().chain(claims).collect();

to_json_binary(&cw721_controllers::NftClaimsResponse { nft_claims })
to_json_binary(&NftClaimsResponse { nft_claims })
}

pub fn query_hooks(deps: Deps) -> StdResult<Binary> {
Expand Down
19 changes: 17 additions & 2 deletions contracts/voting/dao-voting-cw721-staked/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Binary;
use cw721::Cw721ReceiveMsg;
use cw721::{Cw721ReceiveMsg, Expiration};
use cw_utils::Duration;
use dao_dao_macros::{active_query, voting_module_query};
use dao_voting::threshold::{ActiveThreshold, ActiveThresholdResponse};

Check warning on line 6 in contracts/voting/dao-voting-cw721-staked/src/msg.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ActiveThresholdResponse`

Check warning on line 6 in contracts/voting/dao-voting-cw721-staked/src/msg.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ActiveThresholdResponse`
Expand Down Expand Up @@ -89,7 +89,7 @@ pub enum ClaimType {
pub enum QueryMsg {
#[returns(crate::state::Config)]
Config {},
#[returns(::cw721_controllers::NftClaimsResponse)]
#[returns(NftClaimsResponse)]
NftClaims {
address: String,
start_after: Option<String>,
Expand All @@ -108,5 +108,20 @@ pub enum QueryMsg {
ActiveThreshold {},
}

#[cw_serde]
pub struct NftClaimsResponse {
pub nft_claims: Vec<NftClaim>,
}

#[cw_serde]
pub struct NftClaim {
/// The token ID of the NFT being claimed.
pub token_id: String,
/// The expiration time of the claim.
pub release_at: Expiration,
/// Whether the claim is a legacy claim.
pub legacy: bool,
}

#[cw_serde]
pub struct MigrateMsg {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use cosmwasm_std::{Addr, StdResult, Uint128};
use cw721_controllers::NftClaimsResponse;
use cw_controllers::HooksResponse;
use cw_multi_test::App;
use dao_interface::voting::{
InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse,
};

use crate::{msg::QueryMsg, state::Config};
use crate::{
msg::{NftClaimsResponse, QueryMsg},
state::Config,
};

pub fn query_config(app: &App, module: &Addr) -> StdResult<Config> {
let config = app.wrap().query_wasm_smart(module, &QueryMsg::Config {})?;
Expand Down
35 changes: 23 additions & 12 deletions contracts/voting/dao-voting-cw721-staked/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use cosmwasm_std::{
to_json_binary, to_json_vec, Addr, Coin, Decimal, Empty, Storage, Uint128, WasmMsg,
};
use cw721_base::msg::{ExecuteMsg as Cw721ExecuteMsg, InstantiateMsg as Cw721InstantiateMsg};
use cw721_controllers::{NftClaim, NftClaimsResponse};
use cw_multi_test::{next_block, App, BankSudo, Executor, SudoMsg};
use cw_storage_plus::Map;
use cw_utils::Duration;
Expand All @@ -17,7 +16,9 @@ use dao_voting::threshold::{ActiveThreshold, ActiveThresholdResponse};
use crate::testing::execute::{claim_legacy_nfts, claim_specific_nfts};
use crate::{
contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION},
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, NftContract, QueryMsg},
msg::{
ExecuteMsg, InstantiateMsg, MigrateMsg, NftClaim, NftClaimsResponse, NftContract, QueryMsg,
},
testing::{
execute::{
claim_nfts, mint_and_stake_nft, mint_nft, stake_nft, unstake_nfts, update_config,
Expand Down Expand Up @@ -196,7 +197,8 @@ fn test_update_config() -> anyhow::Result<()> {
NftClaimsResponse {
nft_claims: vec![NftClaim {
token_id: "1".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 3)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 3),
legacy: false,
}]
}
);
Expand All @@ -218,7 +220,8 @@ fn test_update_config() -> anyhow::Result<()> {
NftClaimsResponse {
nft_claims: vec![NftClaim {
token_id: "1".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 3)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 3),
legacy: false,
}]
}
);
Expand All @@ -233,11 +236,13 @@ fn test_update_config() -> anyhow::Result<()> {
nft_claims: vec![
NftClaim {
token_id: "1".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 3)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 3),
legacy: false,
},
NftClaim {
token_id: "2".to_string(),
release_at: Duration::Time(1).after(&app.block_info())
release_at: Duration::Time(1).after(&app.block_info()),
legacy: false,
}
]
}
Expand Down Expand Up @@ -288,7 +293,8 @@ fn test_claims() -> anyhow::Result<()> {
claims.nft_claims,
vec![NftClaim {
token_id: "2".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1),
legacy: false,
}]
);

Expand Down Expand Up @@ -353,7 +359,8 @@ pub fn test_legacy_claims_work() -> anyhow::Result<()> {
claims.nft_claims,
vec![NftClaim {
token_id: "4".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1),
legacy: true,
}]
);

Expand Down Expand Up @@ -382,7 +389,8 @@ pub fn test_legacy_claims_work() -> anyhow::Result<()> {
claims.nft_claims,
vec![NftClaim {
token_id: "2".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1),
legacy: false,
}]
);

Expand Down Expand Up @@ -411,7 +419,8 @@ pub fn test_legacy_claims_work() -> anyhow::Result<()> {
claims.nft_claims,
vec![NftClaim {
token_id: "3".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1),
legacy: false,
}]
);

Expand Down Expand Up @@ -440,11 +449,13 @@ pub fn test_legacy_claims_work() -> anyhow::Result<()> {
vec![
NftClaim {
token_id: "5".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1),
legacy: true,
},
NftClaim {
token_id: "1".to_string(),
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1)
release_at: cw_utils::Expiration::AtHeight(app.block_info().height + 1),
legacy: false,
}
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,14 +999,25 @@
"NftClaim": {
"type": "object",
"required": [
"legacy",
"release_at",
"token_id"
],
"properties": {
"legacy": {
"description": "Whether the claim is a legacy claim.",
"type": "boolean"
},
"release_at": {
"$ref": "#/definitions/Expiration"
"description": "The expiration time of the claim.",
"allOf": [
{
"$ref": "#/definitions/Expiration"
}
]
},
"token_id": {
"description": "The token ID of the NFT being claimed.",
"type": "string"
}
},
Expand Down
22 changes: 17 additions & 5 deletions contracts/voting/dao-voting-onft-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use dao_voting::threshold::{
ActiveThresholdResponse,
};

use crate::msg::{ClaimType, ExecuteMsg, InstantiateMsg, MigrateMsg, OnftCollection, QueryMsg};
use crate::msg::{
ClaimType, ExecuteMsg, InstantiateMsg, MigrateMsg, NftClaim, NftClaimsResponse, OnftCollection,
QueryMsg,
};
use crate::omniflix::{get_onft_transfer_msg, query_onft_owner, query_onft_supply};
use crate::state::{
register_staked_nfts, register_unstaked_nfts, Config, ACTIVE_THRESHOLD, CONFIG, DAO, HOOKS,
Expand Down Expand Up @@ -405,7 +408,6 @@ pub fn execute_claim_nfts(
ClaimType::All => {
let token_ids = NFT_CLAIMS
.query_claims(deps.as_ref(), &info.sender, None, None)?
.nft_claims
.into_iter()
.filter(|nft| nft.release_at.is_expired(&env.block))
.map(|nft| nft.token_id)
Expand Down Expand Up @@ -694,18 +696,28 @@ pub fn query_nft_claims(
.query_claims(deps, &addr)?
.nft_claims
.into_iter()
.map(|c| cw721_controllers::NftClaim::new(c.token_id, c.release_at))
.map(|c| NftClaim {
token_id: c.token_id,
release_at: c.release_at,
legacy: true,
})
.collect::<Vec<_>>();

// paginate all new claims
let claims = NFT_CLAIMS
.query_claims(deps, &addr, start_after.as_ref(), limit)?
.nft_claims;
.into_iter()
.map(|c| NftClaim {
token_id: c.token_id,
release_at: c.release_at,
legacy: false,
})
.collect::<Vec<_>>();

// combine legacy and new claims
let nft_claims = legacy_claims.into_iter().chain(claims).collect();

to_json_binary(&cw721_controllers::NftClaimsResponse { nft_claims })
to_json_binary(&NftClaimsResponse { nft_claims })
}

pub fn query_hooks(deps: Deps) -> StdResult<Binary> {
Expand Down
19 changes: 17 additions & 2 deletions contracts/voting/dao-voting-onft-staked/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cw_utils::Duration;
use cw_utils::{Duration, Expiration};
use dao_dao_macros::{active_query, voting_module_query};
use dao_voting::threshold::{ActiveThreshold, ActiveThresholdResponse};

Check warning on line 4 in contracts/voting/dao-voting-onft-staked/src/msg.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ActiveThresholdResponse`

Expand Down Expand Up @@ -110,7 +110,7 @@ pub enum ClaimType {
pub enum QueryMsg {
#[returns(crate::state::Config)]
Config {},
#[returns(::cw721_controllers::NftClaimsResponse)]
#[returns(NftClaimsResponse)]
NftClaims {
address: String,
start_after: Option<String>,
Expand All @@ -129,5 +129,20 @@ pub enum QueryMsg {
ActiveThreshold {},
}

#[cw_serde]
pub struct NftClaimsResponse {
pub nft_claims: Vec<NftClaim>,
}

#[cw_serde]
pub struct NftClaim {
/// The token ID of the NFT being claimed.
pub token_id: String,
/// The expiration time of the claim.
pub release_at: Expiration,
/// Whether the claim is a legacy claim.
pub legacy: bool,
}

#[cw_serde]
pub struct MigrateMsg {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use cosmwasm_std::{Addr, StdResult, Uint128};
use cw721_controllers::NftClaimsResponse;
use cw_controllers::HooksResponse;
use dao_interface::voting::{
InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse,
};
use omniflix_std::types::omniflix::onft::v1beta1::{QueryOnftRequest, QueryOnftResponse};

use crate::{msg::QueryMsg, state::Config};
use crate::{
msg::{NftClaimsResponse, QueryMsg},
state::Config,
};

use super::app::OmniflixApp;

Expand Down
Loading

0 comments on commit 4c4eab5

Please sign in to comment.