Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions contracts/src/goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub fn create_goal_save(
add_goal_to_user(env, &user, goal_id);
increment_next_goal_id(env);

// Award deposit points
storage::award_deposit_points(env, user.clone(), initial_deposit)?;

// Extend TTL for new goal save and user data
ttl::extend_goal_ttl(env, goal_id);
ttl::extend_user_plan_list_ttl(env, &DataKey::UserGoalSaves(user.clone()));
Expand Down Expand Up @@ -180,6 +183,9 @@ pub fn deposit_to_goal_save(
}
}

// Award deposit points
storage::award_deposit_points(env, user.clone(), amount)?;

Ok(())
}

Expand Down Expand Up @@ -982,11 +988,13 @@ mod tests {

client.deposit_to_goal_save(&user, &goal_id, &1_000);
let rewards_after_completion = client.get_user_rewards(&user);
assert_eq!(rewards_after_completion.total_points, 250);
// Base points: (4000 + 1000) * 10 = 50000
// Completion bonus: 250
assert_eq!(rewards_after_completion.total_points, 50250);

let _ = client.withdraw_completed_goal_save(&user, &goal_id);
let rewards_after_withdraw = client.get_user_rewards(&user);
assert_eq!(rewards_after_withdraw.total_points, 250);
assert_eq!(rewards_after_withdraw.total_points, 50250);
}

#[test]
Expand All @@ -1004,7 +1012,8 @@ mod tests {
assert!(!goal_save.is_completed);

let rewards = client.get_user_rewards(&user);
assert_eq!(rewards.total_points, 0);
// Base points: 4999 * 10 = 49990
assert_eq!(rewards.total_points, 49990);
}

#[test]
Expand All @@ -1022,7 +1031,9 @@ mod tests {
assert!(goal.is_completed);

let rewards = client.get_user_rewards(&user);
assert_eq!(rewards.total_points, 250);
// Base points: 5000 * 10 = 50000
// Completion bonus: 250
assert_eq!(rewards.total_points, 50250);
}

#[test]
Expand Down Expand Up @@ -1055,6 +1066,7 @@ mod tests {
let _ = client.break_goal_save(&user, &goal_id);

let rewards = client.get_user_rewards(&user);
assert_eq!(rewards.total_points, 0);
// Base points: 2000 * 10 = 20000
assert_eq!(rewards.total_points, 20000);
}
}
3 changes: 3 additions & 0 deletions contracts/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ pub fn contribute_to_group_save(
env.storage().persistent().set(&plan_key, &plan);
}

// Award deposit points
crate::rewards::storage::award_deposit_points(env, user.clone(), amount)?;

// Extend TTL on contribution
ttl::extend_group_ttl(env, group_id);
ttl::extend_user_ttl(env, &user);
Expand Down
13 changes: 9 additions & 4 deletions contracts/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn create_lock_save(
user_data.savings_count += 1;
env.storage().persistent().set(&user_key, &user_data);

storage::award_deposit_points(env, user.clone(), amount)?;
storage::award_long_lock_bonus(env, user.clone(), amount, duration)?;

// Extend TTL for new lock save and user data
Expand Down Expand Up @@ -288,7 +289,8 @@ mod tests {

let rewards = client.get_user_rewards(&user);
// base points = 1000 * 10 = 10000, bonus = 20% = 2000
assert_eq!(rewards.total_points, 2_000);
// base points = 1000 * 10 = 10000, bonus = 20% = 2000
assert_eq!(rewards.total_points, 12_000);
}

#[test]
Expand All @@ -303,7 +305,8 @@ mod tests {
client.create_lock_save(&user, &amount, &LONG_LOCK_BONUS_THRESHOLD_SECS);

let rewards = client.get_user_rewards(&user);
assert_eq!(rewards.total_points, 0);
// base points = 1000 * 10 = 10000
assert_eq!(rewards.total_points, 10_000);
}

#[test]
Expand All @@ -319,7 +322,8 @@ mod tests {
client.create_lock_save(&user, &amount, &below_threshold);

let rewards = client.get_user_rewards(&user);
assert_eq!(rewards.total_points, 0);
// base points = 1000 * 10 = 10000
assert_eq!(rewards.total_points, 10_000);
}

#[test]
Expand Down Expand Up @@ -357,6 +361,7 @@ mod tests {
let _ = client.withdraw_lock_save(&user, &lock_id);

let rewards = client.get_user_rewards(&user);
assert_eq!(rewards.total_points, 2_000);
// base points = 1000 * 10 = 10000, bonus = 2000
assert_eq!(rewards.total_points, 12_000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,49 @@
"min_temp_entry_ttl": 16,
"max_entry_ttl": 6312000,
"ledger_entries": [
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "AllUsers"
}
]
},
"durability": "persistent"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "AllUsers"
}
]
},
"durability": "persistent",
"val": {
"vec": [
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
}
}
},
"ext": "v0"
},
4095
]
],
[
{
"contract_data": {
Expand Down Expand Up @@ -546,15 +589,15 @@
"symbol": "current_streak"
},
"val": {
"u32": 0
"u32": 1
}
},
{
"key": {
"symbol": "daily_points_earned"
},
"val": {
"u128": "0"
"u128": "20000"
}
},
{
Expand All @@ -578,15 +621,15 @@
"symbol": "lifetime_deposited"
},
"val": {
"i128": "0"
"i128": "2000"
}
},
{
"key": {
"symbol": "total_points"
},
"val": {
"u128": "0"
"u128": "20000"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,49 @@
"min_temp_entry_ttl": 16,
"max_entry_ttl": 6312000,
"ledger_entries": [
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "AllUsers"
}
]
},
"durability": "persistent"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "AllUsers"
}
]
},
"durability": "persistent",
"val": {
"vec": [
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
}
}
},
"ext": "v0"
},
4095
]
],
[
{
"contract_data": {
Expand Down Expand Up @@ -529,15 +572,15 @@
"symbol": "current_streak"
},
"val": {
"u32": 0
"u32": 1
}
},
{
"key": {
"symbol": "daily_points_earned"
},
"val": {
"u128": "0"
"u128": "50000"
}
},
{
Expand All @@ -561,15 +604,15 @@
"symbol": "lifetime_deposited"
},
"val": {
"i128": "0"
"i128": "5000"
}
},
{
"key": {
"symbol": "total_points"
},
"val": {
"u128": "250"
"u128": "50250"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,49 @@
"min_temp_entry_ttl": 16,
"max_entry_ttl": 6312000,
"ledger_entries": [
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "AllUsers"
}
]
},
"durability": "persistent"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "AllUsers"
}
]
},
"durability": "persistent",
"val": {
"vec": [
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
}
}
},
"ext": "v0"
},
4095
]
],
[
{
"contract_data": {
Expand Down Expand Up @@ -576,15 +619,15 @@
"symbol": "current_streak"
},
"val": {
"u32": 0
"u32": 2
}
},
{
"key": {
"symbol": "daily_points_earned"
},
"val": {
"u128": "0"
"u128": "50000"
}
},
{
Expand All @@ -608,15 +651,15 @@
"symbol": "lifetime_deposited"
},
"val": {
"i128": "0"
"i128": "5000"
}
},
{
"key": {
"symbol": "total_points"
},
"val": {
"u128": "250"
"u128": "50250"
}
}
]
Expand Down
Loading