Skip to content

Commit

Permalink
Merge pull request #56 from PotLock/fix/small-updates
Browse files Browse the repository at this point in the history
Fix/small updates
  • Loading branch information
lachlanglen authored Feb 16, 2024
2 parents 1f279e4 + 52e6ddf commit 2db43b1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
17 changes: 10 additions & 7 deletions contracts/pot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub struct ProtocolConfigProviderResult {
```

### Applications

```rs
pub type ProjectId = AccountId;
pub type ApplicationId = ProjectId; // Applications are indexed by ProjectId
Expand Down Expand Up @@ -209,17 +210,18 @@ pub enum ApplicationStatus {
```

### Donations

```rs
pub type DonationId = u64; // auto-incrementing ID for donations

pub struct Donation {
/// ID of the donor
/// ID of the donor
pub donor_id: AccountId,
/// Amount donated
/// Amount donated
pub total_amount: u128,
/// Amount after all fees/expenses (incl. storage)
pub net_amount: u128,
/// Optional message from the donor
/// Optional message from the donor
pub message: Option<String>,
/// Timestamp when the donation was made
pub donated_at: TimestampMs,
Expand All @@ -241,13 +243,13 @@ pub struct Donation {
pub struct DonationExternal {
/// ID of the donation
pub id: DonationId,
/// ID of the donor
/// ID of the donor
pub donor_id: AccountId,
/// Amount donated
/// Amount donated
pub total_amount: U128,
/// Amount after all fees/expenses (incl. storage)
pub net_amount: U128,
/// Optional message from the donor
/// Optional message from the donor
pub message: Option<String>,
/// Timestamp when the donation was made
pub donated_at: TimestampMs,
Expand Down Expand Up @@ -523,6 +525,7 @@ pub fn donate(
referrer_id: Option<AccountId>,
matching_pool: Option<bool>,
bypass_protocol_fee: Option<bool>, // Allows donor to bypass protocol fee if they wish. Defaults to "false".
custom_chef_fee_basis_points: Option<u32>, // Allows donor to set custom chef fee % if they wish. If provided value is greater than self.chef_fee_basis_points, the smaller value will be used.
) -> DonationExternal


Expand Down Expand Up @@ -729,4 +732,4 @@ pub fn get_payouts_challenges(

pub fn get_contract_source_metadata(&self) -> Option<ContractSourceMetadata>

```
```
Binary file modified contracts/pot/out/main.wasm
Binary file not shown.
25 changes: 20 additions & 5 deletions contracts/pot/src/donations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ impl Contract {
referrer_id: Option<AccountId>,
matching_pool: Option<bool>,
bypass_protocol_fee: Option<bool>,
custom_chef_fee_basis_points: Option<u32>,
) -> PromiseOrValue<DonationExternal> {
if let Some(project_id) = project_id.clone() {
self.assert_approved_application(&project_id);
Expand Down Expand Up @@ -278,6 +279,7 @@ impl Contract {
referrer_id,
is_matching_pool,
bypass_protocol_fee,
custom_chef_fee_basis_points,
)
}

Expand All @@ -289,6 +291,7 @@ impl Contract {
referrer_id: Option<AccountId>,
matching_pool: bool,
bypass_protocol_fee: Option<bool>,
custom_chef_fee_basis_points: Option<u32>,
) -> PromiseOrValue<DonationExternal> {
let caller_id = env::predecessor_account_id();
if matching_pool {
Expand All @@ -305,6 +308,7 @@ impl Contract {
referrer_id.clone(),
matching_pool,
bypass_protocol_fee,
custom_chef_fee_basis_points,
)
} else {
if let Some(sybil_wrapper_provider) = self.sybil_wrapper_provider.get() {
Expand All @@ -325,6 +329,7 @@ impl Contract {
referrer_id.clone(),
matching_pool,
bypass_protocol_fee,
custom_chef_fee_basis_points,
),
))
} else {
Expand All @@ -336,6 +341,7 @@ impl Contract {
referrer_id.clone(),
matching_pool,
bypass_protocol_fee,
custom_chef_fee_basis_points
)
}
}
Expand All @@ -351,6 +357,7 @@ impl Contract {
referrer_id: Option<AccountId>,
matching_pool: bool,
bypass_protocol_fee: Option<bool>,
custom_chef_fee_basis_points: Option<u32>,
#[callback_result] call_result: Result<bool, PromiseError>,
) -> PromiseOrValue<DonationExternal> {
if call_result.is_err() {
Expand Down Expand Up @@ -381,6 +388,7 @@ impl Contract {
referrer_id,
matching_pool,
bypass_protocol_fee,
custom_chef_fee_basis_points,
)
}
}
Expand All @@ -394,6 +402,7 @@ impl Contract {
referrer_id: Option<AccountId>,
matching_pool: bool,
bypass_protocol_fee: Option<bool>,
custom_chef_fee_basis_points: Option<u32>,
) -> PromiseOrValue<DonationExternal> {
if bypass_protocol_fee.unwrap_or(false) {
// bypass protocol fee
Expand All @@ -405,6 +414,7 @@ impl Contract {
message.clone(),
referrer_id.clone(),
matching_pool,
custom_chef_fee_basis_points,
))
} else if let Some(protocol_config_provider) = self.protocol_config_provider.get() {
let (contract_id, method_name) = protocol_config_provider.decompose();
Expand All @@ -420,6 +430,7 @@ impl Contract {
message,
referrer_id,
matching_pool,
custom_chef_fee_basis_points,
),
))
} else {
Expand All @@ -432,6 +443,7 @@ impl Contract {
message.clone(),
referrer_id.clone(),
matching_pool,
custom_chef_fee_basis_points,
))
}
}
Expand All @@ -445,6 +457,7 @@ impl Contract {
message: Option<String>,
referrer_id: Option<AccountId>,
matching_pool: bool,
custom_chef_fee_basis_points: Option<u32>,
#[callback_result] call_result: Result<ProtocolConfigProviderResult, PromiseError>,
) -> DonationExternal {
if call_result.is_err() {
Expand All @@ -459,6 +472,7 @@ impl Contract {
message,
referrer_id,
matching_pool,
custom_chef_fee_basis_points,
)
} else {
let protocol_config_provider_result = call_result.unwrap();
Expand All @@ -474,6 +488,7 @@ impl Contract {
message,
referrer_id,
matching_pool,
custom_chef_fee_basis_points,
)
}
}
Expand All @@ -488,6 +503,7 @@ impl Contract {
message: Option<String>,
referrer_id: Option<AccountId>,
matching_pool: bool,
custom_chef_fee_basis_points: Option<u32>,
) -> DonationExternal {
let initial_storage_usage = env::storage_usage();

Expand All @@ -497,15 +513,14 @@ impl Contract {
deposit, protocol_fee,
));

// subtract chef fee
// TODO: consider adding to Donation struct
// subtract chef fee, unless bypassed
let mut chef_fee: Option<U128> = None;
let mut chef_id: Option<AccountId> = None;
if let Some(chef) = self.chef.get() {
// chef fee only applies to public round donations
if !matching_pool {
let chef_fee_basis_points = std::cmp::min(custom_chef_fee_basis_points.unwrap_or(self.chef_fee_basis_points), self.chef_fee_basis_points); // can't provide a chef fee basis points greater than the contract's
if chef_fee_basis_points > 0 {
let chef_fee_amount =
self.calculate_fee(remainder, self.chef_fee_basis_points, false);
self.calculate_fee(remainder, chef_fee_basis_points, false);
chef_fee = Some(U128::from(chef_fee_amount));
chef_id = Some(chef);
remainder = remainder.checked_sub(chef_fee_amount).expect(&format!(
Expand Down
5 changes: 3 additions & 2 deletions contracts/pot_factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct ContractConfigExternal {
```

### Protocol Config

```rs
/// Ephemeral-only (used in views) - intended as the result type for Pots querying for protocol fees configuration
pub struct ProtocolConfig {
Expand Down Expand Up @@ -195,7 +196,7 @@ pub fn new(

/// Deploy a new Pot. A `None` response indicates an unsuccessful deployment.
#[payable]
pub fn deploy_pot(&mut self, mut pot_args: PotArgs) -> Option<PotExternal>
pub fn deploy_pot(&mut self, mut pot_args: PotArgs, pot_handle: Option<String>) -> Option<PotExternal>


// OWNER / ADMIN
Expand Down Expand Up @@ -260,4 +261,4 @@ pub fn get_protocol_config(&self) -> ProtocolConfig
// SOURCE METADATA

pub fn get_contract_source_metadata(&self) -> Option<ContractSourceMetadata>
```
```
Binary file modified contracts/pot_factory/out/main.wasm
Binary file not shown.
10 changes: 4 additions & 6 deletions contracts/pot_factory/src/pot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,14 @@ pub struct PotArgs {
impl Contract {
/// Deploy a new Pot. A `None` response indicates an unsuccessful deployment.
#[payable]
pub fn deploy_pot(&mut self, mut pot_args: PotArgs) -> Promise {
pub fn deploy_pot(&mut self, mut pot_args: PotArgs, pot_handle: Option<String>) -> Promise {
// TODO: add protocol_config_provider to pot_args
if self.require_whitelist {
self.assert_admin_or_whitelisted_deployer();
}
let pot_account_id_str = format!(
"{}.{}",
slugify(&pot_args.pot_name),
env::current_account_id()
);

let handle = pot_handle.unwrap_or_else(|| slugify(&pot_args.pot_name));
let pot_account_id_str = format!("{}.{}", handle, env::current_account_id());
assert!(
env::is_valid_account_id(pot_account_id_str.as_bytes()),
"Pot Account ID {} is invalid",
Expand Down

0 comments on commit 2db43b1

Please sign in to comment.