levana_perpswap_cosmos/contracts/
position_token.rs

1//! Messages for the perps position token contract.
2//!
3//! The position token is a proxy providing a CW721 (NFT) interface for all
4//! positions within a single market.
5pub mod entry;
6pub mod events;
7
8use cosmwasm_schema::cw_serde;
9use cosmwasm_std::{Addr, Binary, BlockInfo};
10use cw_utils::Expiration;
11
12/// copied/adapted from the cw721-base reference
13#[cw_serde]
14pub struct Approval {
15    /// Account that can transfer/send the token
16    pub spender: Addr,
17    /// When the Approval expires (maybe Expiration::never)
18    pub expires: Expiration,
19}
20
21impl Approval {
22    /// Is the given approval expired at the given block?
23    pub fn is_expired(&self, block: &BlockInfo) -> bool {
24        self.expires.is_expired(block)
25    }
26}
27
28/// copied/adapted from the cw721-base reference
29#[cw_serde]
30pub struct FullTokenInfo {
31    /// The owner of the newly minted NFT
32    pub owner: Addr,
33    /// Approvals are stored here, as we clear them all upon transfer and cannot accumulate much
34    pub approvals: Vec<Approval>,
35
36    /// metadata, as per spec
37    pub extension: Metadata,
38}
39
40/// NFT standard metadata
41#[cw_serde]
42#[derive(Default)]
43pub struct Metadata {
44    /// Unused by perps
45    pub image: Option<String>,
46    /// Unused by perps
47    pub image_data: Option<String>,
48    /// Unused by perps
49    pub external_url: Option<String>,
50    /// Unused by perps
51    pub description: Option<String>,
52    /// Unused by perps
53    pub name: Option<String>,
54    /// Characteristics of the position
55    pub attributes: Option<Vec<Trait>>,
56    /// Unused by perps
57    pub background_color: Option<String>,
58    /// Unused by perps
59    pub animation_url: Option<String>,
60    /// Unused by perps
61    pub youtube_url: Option<String>,
62}
63
64/// NFT-standard traits, used to express information on the position
65#[cw_serde]
66#[derive(Eq, Default)]
67pub struct Trait {
68    /// Unused by pers
69    pub display_type: Option<String>,
70    /// The type of data contained in this trait.
71    pub trait_type: String,
72    /// The value for the given trait type.
73    pub value: String,
74}
75
76/// Cw721ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg
77#[cw_serde]
78pub struct Cw721ReceiveMsg {
79    /// Sender of the NFT
80    pub sender: String,
81    /// Position ID transferred
82    pub token_id: String,
83    /// Binary message for the receiving contract to execute.
84    pub msg: Binary,
85}