Skip to content

Commit

Permalink
Merge pull request #65 from PotLock/feat/donation-ft
Browse files Browse the repository at this point in the history
Donation contract FT support
  • Loading branch information
lachlanglen authored Mar 19, 2024
2 parents f57a9b7 + 168285b commit c996000
Show file tree
Hide file tree
Showing 10 changed files with 740 additions and 103 deletions.
8 changes: 4 additions & 4 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/donation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
near-sdk = "4.1.1"
# near-sdk = "5.0.0-alpha.2"
# [profile.release] # removed as added to root Cargo.toml
# codegen-units = 1
# # Tell `rustc` to optimize for small code size.
Expand Down
21 changes: 21 additions & 0 deletions contracts/donation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ pub struct Donation {
}
```

### Storage

The storage-related methods (`storage_deposit`, `storage_withdraw` and `storage_balance_of`) are utilized for fungible token (FT) donations, where the user must prepay storage on this Donation contract - to cover the storage of the Donation data - before calling `ft_transfer_call` on the FT contract.

This is a simplified version of the [Storage Management standard](https://nomicon.io/Standards/StorageManagement).

### Contract Source Metadata

_NB: Below implemented as per NEP 0330 (https://github.com/near/NEPs/blob/master/neps/nep-0330.md), with addition of `commit_hash`_
Expand Down Expand Up @@ -120,6 +126,13 @@ pub fn donate(
) -> Donation


// STORAGE

pub fn storage_deposit(&mut self) -> U128

pub fn storage_withdraw(&mut self, amount: Option<U128>) -> U128


// OWNER

#[payable]
Expand All @@ -145,6 +158,7 @@ pub fn self_set_source_metadata(&mut self, source_metadata: ContractSourceMetada

pub fn get_config(&self) -> Config


// DONATIONS
pub fn get_donations(&self, from_index: Option<u128>, limit: Option<u64>) -> Vec<Donation>

Expand All @@ -171,10 +185,17 @@ pub fn get_donations_for_ft(
limit: Option<u64>,
) -> Vec<Donation>


// STORAGE

pub fn storage_balance_of(&self, account_id: &AccountId) -> U128


// OWNER

pub fn get_owner(&self) -> AccountId


// SOURCE METADATA

pub fn get_contract_source_metadata(&self) -> Option<ContractSourceMetadata>
Expand Down
Binary file modified contracts/donation/out/main.wasm
Binary file not shown.
7 changes: 7 additions & 0 deletions contracts/donation/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
use crate::*;

pub const MAX_PROTOCOL_FEE_BASIS_POINTS: u32 = 1000;
pub const MAX_REFERRAL_FEE_BASIS_POINTS: u32 = 200;

pub const EVENT_JSON_PREFIX: &str = "EVENT_JSON:";

pub const TGAS: u64 = 1_000_000_000_000; // 1 TGAS
pub const XCC_GAS_DEFAULT: u64 = TGAS * 10; // 10 TGAS
pub const NO_DEPOSIT: Balance = 0;
pub const ONE_YOCTO: Balance = 1;
Loading

0 comments on commit c996000

Please sign in to comment.