Skip to content

Commit 2db43b1

Browse files
authored
Merge pull request #56 from PotLock/fix/small-updates
Fix/small updates
2 parents 1f279e4 + 52e6ddf commit 2db43b1

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

contracts/pot/README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub struct ProtocolConfigProviderResult {
180180
```
181181

182182
### Applications
183+
183184
```rs
184185
pub type ProjectId = AccountId;
185186
pub type ApplicationId = ProjectId; // Applications are indexed by ProjectId
@@ -209,17 +210,18 @@ pub enum ApplicationStatus {
209210
```
210211

211212
### Donations
213+
212214
```rs
213215
pub type DonationId = u64; // auto-incrementing ID for donations
214216

215217
pub struct Donation {
216-
/// ID of the donor
218+
/// ID of the donor
217219
pub donor_id: AccountId,
218-
/// Amount donated
220+
/// Amount donated
219221
pub total_amount: u128,
220222
/// Amount after all fees/expenses (incl. storage)
221223
pub net_amount: u128,
222-
/// Optional message from the donor
224+
/// Optional message from the donor
223225
pub message: Option<String>,
224226
/// Timestamp when the donation was made
225227
pub donated_at: TimestampMs,
@@ -241,13 +243,13 @@ pub struct Donation {
241243
pub struct DonationExternal {
242244
/// ID of the donation
243245
pub id: DonationId,
244-
/// ID of the donor
246+
/// ID of the donor
245247
pub donor_id: AccountId,
246-
/// Amount donated
248+
/// Amount donated
247249
pub total_amount: U128,
248250
/// Amount after all fees/expenses (incl. storage)
249251
pub net_amount: U128,
250-
/// Optional message from the donor
252+
/// Optional message from the donor
251253
pub message: Option<String>,
252254
/// Timestamp when the donation was made
253255
pub donated_at: TimestampMs,
@@ -523,6 +525,7 @@ pub fn donate(
523525
referrer_id: Option<AccountId>,
524526
matching_pool: Option<bool>,
525527
bypass_protocol_fee: Option<bool>, // Allows donor to bypass protocol fee if they wish. Defaults to "false".
528+
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.
526529
) -> DonationExternal
527530

528531

@@ -729,4 +732,4 @@ pub fn get_payouts_challenges(
729732

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

732-
```
735+
```

contracts/pot/out/main.wasm

922 Bytes
Binary file not shown.

contracts/pot/src/donations.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ impl Contract {
236236
referrer_id: Option<AccountId>,
237237
matching_pool: Option<bool>,
238238
bypass_protocol_fee: Option<bool>,
239+
custom_chef_fee_basis_points: Option<u32>,
239240
) -> PromiseOrValue<DonationExternal> {
240241
if let Some(project_id) = project_id.clone() {
241242
self.assert_approved_application(&project_id);
@@ -278,6 +279,7 @@ impl Contract {
278279
referrer_id,
279280
is_matching_pool,
280281
bypass_protocol_fee,
282+
custom_chef_fee_basis_points,
281283
)
282284
}
283285

@@ -289,6 +291,7 @@ impl Contract {
289291
referrer_id: Option<AccountId>,
290292
matching_pool: bool,
291293
bypass_protocol_fee: Option<bool>,
294+
custom_chef_fee_basis_points: Option<u32>,
292295
) -> PromiseOrValue<DonationExternal> {
293296
let caller_id = env::predecessor_account_id();
294297
if matching_pool {
@@ -305,6 +308,7 @@ impl Contract {
305308
referrer_id.clone(),
306309
matching_pool,
307310
bypass_protocol_fee,
311+
custom_chef_fee_basis_points,
308312
)
309313
} else {
310314
if let Some(sybil_wrapper_provider) = self.sybil_wrapper_provider.get() {
@@ -325,6 +329,7 @@ impl Contract {
325329
referrer_id.clone(),
326330
matching_pool,
327331
bypass_protocol_fee,
332+
custom_chef_fee_basis_points,
328333
),
329334
))
330335
} else {
@@ -336,6 +341,7 @@ impl Contract {
336341
referrer_id.clone(),
337342
matching_pool,
338343
bypass_protocol_fee,
344+
custom_chef_fee_basis_points
339345
)
340346
}
341347
}
@@ -351,6 +357,7 @@ impl Contract {
351357
referrer_id: Option<AccountId>,
352358
matching_pool: bool,
353359
bypass_protocol_fee: Option<bool>,
360+
custom_chef_fee_basis_points: Option<u32>,
354361
#[callback_result] call_result: Result<bool, PromiseError>,
355362
) -> PromiseOrValue<DonationExternal> {
356363
if call_result.is_err() {
@@ -381,6 +388,7 @@ impl Contract {
381388
referrer_id,
382389
matching_pool,
383390
bypass_protocol_fee,
391+
custom_chef_fee_basis_points,
384392
)
385393
}
386394
}
@@ -394,6 +402,7 @@ impl Contract {
394402
referrer_id: Option<AccountId>,
395403
matching_pool: bool,
396404
bypass_protocol_fee: Option<bool>,
405+
custom_chef_fee_basis_points: Option<u32>,
397406
) -> PromiseOrValue<DonationExternal> {
398407
if bypass_protocol_fee.unwrap_or(false) {
399408
// bypass protocol fee
@@ -405,6 +414,7 @@ impl Contract {
405414
message.clone(),
406415
referrer_id.clone(),
407416
matching_pool,
417+
custom_chef_fee_basis_points,
408418
))
409419
} else if let Some(protocol_config_provider) = self.protocol_config_provider.get() {
410420
let (contract_id, method_name) = protocol_config_provider.decompose();
@@ -420,6 +430,7 @@ impl Contract {
420430
message,
421431
referrer_id,
422432
matching_pool,
433+
custom_chef_fee_basis_points,
423434
),
424435
))
425436
} else {
@@ -432,6 +443,7 @@ impl Contract {
432443
message.clone(),
433444
referrer_id.clone(),
434445
matching_pool,
446+
custom_chef_fee_basis_points,
435447
))
436448
}
437449
}
@@ -445,6 +457,7 @@ impl Contract {
445457
message: Option<String>,
446458
referrer_id: Option<AccountId>,
447459
matching_pool: bool,
460+
custom_chef_fee_basis_points: Option<u32>,
448461
#[callback_result] call_result: Result<ProtocolConfigProviderResult, PromiseError>,
449462
) -> DonationExternal {
450463
if call_result.is_err() {
@@ -459,6 +472,7 @@ impl Contract {
459472
message,
460473
referrer_id,
461474
matching_pool,
475+
custom_chef_fee_basis_points,
462476
)
463477
} else {
464478
let protocol_config_provider_result = call_result.unwrap();
@@ -474,6 +488,7 @@ impl Contract {
474488
message,
475489
referrer_id,
476490
matching_pool,
491+
custom_chef_fee_basis_points,
477492
)
478493
}
479494
}
@@ -488,6 +503,7 @@ impl Contract {
488503
message: Option<String>,
489504
referrer_id: Option<AccountId>,
490505
matching_pool: bool,
506+
custom_chef_fee_basis_points: Option<u32>,
491507
) -> DonationExternal {
492508
let initial_storage_usage = env::storage_usage();
493509

@@ -497,15 +513,14 @@ impl Contract {
497513
deposit, protocol_fee,
498514
));
499515

500-
// subtract chef fee
501-
// TODO: consider adding to Donation struct
516+
// subtract chef fee, unless bypassed
502517
let mut chef_fee: Option<U128> = None;
503518
let mut chef_id: Option<AccountId> = None;
504519
if let Some(chef) = self.chef.get() {
505-
// chef fee only applies to public round donations
506-
if !matching_pool {
520+
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
521+
if chef_fee_basis_points > 0 {
507522
let chef_fee_amount =
508-
self.calculate_fee(remainder, self.chef_fee_basis_points, false);
523+
self.calculate_fee(remainder, chef_fee_basis_points, false);
509524
chef_fee = Some(U128::from(chef_fee_amount));
510525
chef_id = Some(chef);
511526
remainder = remainder.checked_sub(chef_fee_amount).expect(&format!(

contracts/pot_factory/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub struct ContractConfigExternal {
4343
```
4444

4545
### Protocol Config
46+
4647
```rs
4748
/// Ephemeral-only (used in views) - intended as the result type for Pots querying for protocol fees configuration
4849
pub struct ProtocolConfig {
@@ -195,7 +196,7 @@ pub fn new(
195196

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

200201

201202
// OWNER / ADMIN
@@ -260,4 +261,4 @@ pub fn get_protocol_config(&self) -> ProtocolConfig
260261
// SOURCE METADATA
261262

262263
pub fn get_contract_source_metadata(&self) -> Option<ContractSourceMetadata>
263-
```
264+
```

contracts/pot_factory/out/main.wasm

1.79 KB
Binary file not shown.

contracts/pot_factory/src/pot.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ pub struct PotArgs {
6565
impl Contract {
6666
/// Deploy a new Pot. A `None` response indicates an unsuccessful deployment.
6767
#[payable]
68-
pub fn deploy_pot(&mut self, mut pot_args: PotArgs) -> Promise {
68+
pub fn deploy_pot(&mut self, mut pot_args: PotArgs, pot_handle: Option<String>) -> Promise {
6969
// TODO: add protocol_config_provider to pot_args
7070
if self.require_whitelist {
7171
self.assert_admin_or_whitelisted_deployer();
7272
}
73-
let pot_account_id_str = format!(
74-
"{}.{}",
75-
slugify(&pot_args.pot_name),
76-
env::current_account_id()
77-
);
73+
74+
let handle = pot_handle.unwrap_or_else(|| slugify(&pot_args.pot_name));
75+
let pot_account_id_str = format!("{}.{}", handle, env::current_account_id());
7876
assert!(
7977
env::is_valid_account_id(pot_account_id_str.as_bytes()),
8078
"Pot Account ID {} is invalid",

0 commit comments

Comments
 (0)