|
| 1 | +// this is required because of the `ext_contract` macro |
| 2 | +#[cfg(feature = "market-wasm")] |
| 3 | +pub use market_interfaces::*; |
| 4 | + |
| 5 | +/// Interfaces that we need the market to be aware of |
| 6 | +#[cfg(feature = "market-wasm")] |
| 7 | +#[allow(clippy::too_many_arguments)] |
| 8 | +mod market_interfaces { |
| 9 | + use near_sdk::json_types::{ |
| 10 | + U128, |
| 11 | + U64, |
| 12 | + }; |
| 13 | + use near_sdk::{ |
| 14 | + self, |
| 15 | + ext_contract, |
| 16 | + AccountId, |
| 17 | + Promise, |
| 18 | + }; |
| 19 | + |
| 20 | + use crate::market_data::TokenListing; |
| 21 | + |
| 22 | + #[ext_contract(ext_self)] |
| 23 | + pub trait ExtSelf { |
| 24 | + fn resolve_nft_payout( |
| 25 | + &mut self, |
| 26 | + token_key: String, |
| 27 | + token: TokenListing, |
| 28 | + others_keep: U128, |
| 29 | + market_keeps: U128, |
| 30 | + ) -> Promise; |
| 31 | + } |
| 32 | + |
| 33 | + #[ext_contract(nft_contract)] |
| 34 | + /// Impl of NEP-171. Note that the impl makes the assumption that `TokenId` has |
| 35 | + /// type `String`, where this contract internally uses `u64`, which is more |
| 36 | + /// efficient. ref: |
| 37 | + /// https://github.com/near/NEPs/blob/master/specs/Standards/NonFungibleToken/Core.md |
| 38 | + pub trait NFTContract { |
| 39 | + /// Transfer the token and get the payout data. |
| 40 | + fn nft_transfer_payout( |
| 41 | + &mut self, |
| 42 | + receiver_id: AccountId, |
| 43 | + token_id: U64, |
| 44 | + approval_id: u64, |
| 45 | + balance: U128, |
| 46 | + max_len_payout: u32, |
| 47 | + ) -> Promise; |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +#[cfg(feature = "store-wasm")] |
| 52 | +pub use store_interfaces::*; |
| 53 | + |
| 54 | +/// Interfaces that we need the store to be aware of |
| 55 | +#[cfg(feature = "store-wasm")] |
| 56 | +#[allow(clippy::too_many_arguments)] |
| 57 | +mod store_interfaces { |
| 58 | + use near_sdk::json_types::U64; |
| 59 | + use near_sdk::{ |
| 60 | + self, |
| 61 | + ext_contract, |
| 62 | + AccountId, |
| 63 | + Promise, |
| 64 | + }; |
| 65 | + |
| 66 | + /// Non-Fungible Token Approval NEP 178. Ref: |
| 67 | + /// https://github.com/near/NEPs/blobß/master/specs/Standards/NonFungibleToken/ApprovalManagement.md |
| 68 | + #[ext_contract(ext_on_approve)] |
| 69 | + pub trait NonFungibleOnApprove { |
| 70 | + /// Approved Account Contract Interface If a contract that gets approved to |
| 71 | + /// transfer NFTs wants to, it can implement nft_on_approve to update its own |
| 72 | + /// state when granted approval for a token: Respond to notification that |
| 73 | + /// contract has been granted approval for a token. |
| 74 | + /// |
| 75 | + /// Notes |
| 76 | + /// * Contract knows the token contract ID from `predecessor_account_id` |
| 77 | + /// |
| 78 | + /// Arguments: |
| 79 | + /// * `token_id`: the token to which this contract has been granted approval |
| 80 | + /// * `owner_id`: the owner of the token |
| 81 | + /// * `approval_id`: the approval ID stored by NFT contract for this approval. |
| 82 | + /// Expected to be a number within the 2^53 limit representable by JSON. |
| 83 | + /// * `msg`: specifies information needed by the approved contract in order to |
| 84 | + /// handle the approval. Can indicate both a fn to call and the |
| 85 | + /// parameters to pass to that fn. |
| 86 | + fn nft_on_approve( |
| 87 | + &mut self, |
| 88 | + token_id: U64, |
| 89 | + owner_id: AccountId, |
| 90 | + approval_id: u64, |
| 91 | + msg: String, |
| 92 | + ); |
| 93 | + fn nft_on_batch_approve( |
| 94 | + &mut self, |
| 95 | + tokens: Vec<U64>, |
| 96 | + approvals: Vec<U64>, |
| 97 | + owner_id: AccountId, |
| 98 | + msg: String, |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + /// Impl of NEP-171 resolve transfer. ref: |
| 103 | + /// https://github.com/near/NEPs/blob/master/specs/Standards/NonFungibleToken/Core.md |
| 104 | + #[ext_contract(ext_on_transfer)] |
| 105 | + pub trait NonFungibleOnTransfer { |
| 106 | + /// Take some action after receiving a non-fungible token. |
| 107 | + /// |
| 108 | + /// Requirements: * Contract MUST restrict calls to this function to a set of |
| 109 | + /// allow-listed NFT contracts. |
| 110 | + /// |
| 111 | + /// Arguments: |
| 112 | + /// * `sender_id`: the sender of `nft_transfer_call`. |
| 113 | + /// * `previous_owner_id`: the account that owned the NFT prior to it being |
| 114 | + /// transfered to this contract, which can differ from `sender_id` if using |
| 115 | + /// Approval Management extension. |
| 116 | + /// * `token_id`: the `token_id` argument given to `nft_transfer_call` |
| 117 | + /// * `msg`: information necessary for this contract to know how to process the |
| 118 | + /// request. This may include method names and/or arguments. |
| 119 | + /// |
| 120 | + /// Returns true if token should be returned to `sender_id`. |
| 121 | + fn nft_on_transfer( |
| 122 | + &mut self, |
| 123 | + sender_id: AccountId, |
| 124 | + previous_owner_id: AccountId, |
| 125 | + token_id: U64, |
| 126 | + msg: String, |
| 127 | + ) -> Promise; |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +#[cfg(feature = "factory-wasm")] |
| 132 | +pub use factory_interfaces::*; |
| 133 | + |
| 134 | +/// Interfaces that we need the factory to be aware of |
| 135 | +#[cfg(feature = "factory-wasm")] |
| 136 | +#[allow(clippy::too_many_arguments)] |
| 137 | +mod factory_interfaces { |
| 138 | + use near_sdk::json_types::U128; |
| 139 | + use near_sdk::{ |
| 140 | + self, |
| 141 | + ext_contract, |
| 142 | + AccountId, |
| 143 | + }; |
| 144 | + |
| 145 | + use crate::common::NFTContractMetadata; |
| 146 | + |
| 147 | + #[ext_contract(factory_self)] |
| 148 | + pub trait OnCreateCallback { |
| 149 | + fn on_create( |
| 150 | + &mut self, |
| 151 | + store_creator_id: AccountId, |
| 152 | + metadata: NFTContractMetadata, |
| 153 | + owner_id: AccountId, |
| 154 | + store_account_id: AccountId, |
| 155 | + attached_deposit: U128, |
| 156 | + ); |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +// TODO: Is this used anywhere? -> nope |
| 161 | +// --------------------------- nft core interface --------------------------- // |
| 162 | + |
| 163 | +/// Impl of NEP-171. Note that the impl makes the assumption that `TokenId` has |
| 164 | +/// type `String`, where this contract internally uses `u64`, which is more |
| 165 | +/// efficient. ref: |
| 166 | +/// https://github.com/near/NEPs/blob/master/specs/Standards/NonFungibleToken/Core.md |
| 167 | +pub trait NonFungibleContractCore { |
| 168 | + /// Simple transfer. Transfer a given `token_id` from current owner to |
| 169 | + /// `receiver_id`. |
| 170 | + /// |
| 171 | + /// Requirements |
| 172 | + /// * Caller of the method must attach a deposit of 1 yoctoⓃ for security purposes |
| 173 | + /// * Contract MUST panic if called by someone other than token owner or, |
| 174 | + /// if using Approval Management, one of the approved accounts |
| 175 | + /// * `approval_id` is for use with Approval Management extension, see |
| 176 | + /// that document for full explanation. |
| 177 | + /// * If using Approval Management, contract MUST nullify approved accounts on |
| 178 | + /// successful transfer. |
| 179 | + /// |
| 180 | + /// Arguments: |
| 181 | + /// * `receiver_id`: the valid NEAR account receiving the token |
| 182 | + /// * `token_id`: the token to transfer |
| 183 | + /// * `approval_id`: expected approval ID. A number smaller than |
| 184 | + /// 2^53, and therefore representable as JSON. See Approval Management |
| 185 | + /// standard for full explanation. |
| 186 | + /// * `memo` (optional): for use cases that may benefit from indexing or |
| 187 | + /// providing information for a transfer |
| 188 | + //#[payable] |
| 189 | + fn nft_transfer( |
| 190 | + &mut self, |
| 191 | + receiver_id: near_sdk::AccountId, |
| 192 | + token_id: near_sdk::json_types::U64, |
| 193 | + approval_id: Option<near_sdk::json_types::U64>, |
| 194 | + memo: Option<String>, |
| 195 | + ); |
| 196 | + |
| 197 | + /// Returns `true` if the token was transferred from the sender's account. |
| 198 | + /// |
| 199 | + /// Transfer token and call a method on a receiver contract. A successful |
| 200 | + /// workflow will end in a success execution outcome to the callback on the NFT |
| 201 | + /// contract at the method `nft_resolve_transfer`. |
| 202 | + /// |
| 203 | + /// You can think of this as being similar to attaching native NEAR tokens to a |
| 204 | + /// function call. It allows you to attach any Non-Fungible Token in a call to a |
| 205 | + /// receiver contract. |
| 206 | + /// |
| 207 | + /// Requirements: |
| 208 | + /// * Caller of the method must attach a deposit of 1 yoctoⓃ for security |
| 209 | + /// purposes |
| 210 | + /// * Contract MUST panic if called by someone other than token owner or, |
| 211 | + /// if using Approval Management, one of the approved accounts |
| 212 | + /// * The receiving contract must implement `ft_on_transfer` according to the |
| 213 | + /// standard. If it does not, FT contract's `ft_resolve_transfer` MUST deal |
| 214 | + /// with the resulting failed cross-contract call and roll back the transfer. |
| 215 | + /// * Contract MUST implement the behavior described in `ft_resolve_transfer` |
| 216 | + /// * `approval_id` is for use with Approval Management extension, see |
| 217 | + /// that document for full explanation. |
| 218 | + /// * If using Approval Management, contract MUST nullify approved accounts on |
| 219 | + /// successful transfer. |
| 220 | + /// |
| 221 | + /// Arguments: |
| 222 | + /// * `receiver_id`: the valid NEAR account receiving the token. |
| 223 | + /// * `token_id`: the token to send. |
| 224 | + /// * `approval_id`: expected approval ID. A number smaller than |
| 225 | + /// 2^53, and therefore representable as JSON. See Approval Management |
| 226 | + /// standard for full explanation. |
| 227 | + /// * `memo` (optional): for use cases that may benefit from indexing or |
| 228 | + /// providing information for a transfer. |
| 229 | + /// * `msg`: specifies information needed by the receiving contract in |
| 230 | + /// order to properly handle the transfer. Can indicate both a function to |
| 231 | + /// call and the parameters to pass to that function. |
| 232 | + //#[payable] |
| 233 | + fn nft_transfer_call( |
| 234 | + &mut self, |
| 235 | + receiver_id: near_sdk::AccountId, |
| 236 | + token_id: near_sdk::json_types::U64, |
| 237 | + approval_id: Option<near_sdk::json_types::U64>, |
| 238 | + memo: Option<String>, |
| 239 | + msg: String, |
| 240 | + ) -> near_sdk::Promise; |
| 241 | + |
| 242 | + /// Returns the token with the given `token_id` or `None` if no such token. |
| 243 | + fn nft_token( |
| 244 | + &self, |
| 245 | + token_id: near_sdk::json_types::U64, |
| 246 | + ) -> Option<crate::token::Token>; |
| 247 | +} |
0 commit comments