Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JSHan94 committed Mar 14, 2024
1 parent f82835d commit 45393d0
Showing 1 changed file with 111 additions and 36 deletions.
147 changes: 111 additions & 36 deletions precompile/modules/initia_stdlib/sources/vip/vesting.move
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,57 @@ module initia_std::vip_vesting {
// Events
//

#[event]
struct VestingClaimEvent has drop, store {
account: address,
bridge_id: u64,
// claimed stage.
stage: u64,
// newly vested reward amount.
vesting_reward_amount: u64,
// accumulated claimed vesting reward that was previously distributed.
vested_reward_amount: u64,
// vesting changes
vesting_changes: vector<VestingChange>,
}
// #[event]
// struct UserVestingCreateEvent has drop, store {
// account: address,
// bridge_id: u64,
// stage: u64,
// vesting_reward_amount: u64,
// }

// #[event]
// struct OperatorVestingCreateEvent has drop, store {
// account: address,
// bridge_id: u64,
// stage: u64,
// vesting_reward_amount: u64,
// }

// #[event]
// struct UserVestingFinalizedEvent has drop, store {
// account: address,
// bridge_id: u64,
// stage: u64,
// remaining_reward: u64,
// }

// #[event]
// struct OperatorVestingFinalizedEvent has drop, store {
// account: address,
// bridge_id: u64,
// stage: u64,
// remaining_reward: u64,
// }

// #[event]
// struct UserVestingClaimEvent has drop, store {
// account: address,
// bridge_id: u64,
// stage: u64,
// vesting_reward_amount: u64,
// vested_reward_amount: u64,
// vesting_changes: vector<VestingChange>,
// }

// #[event]
// struct OperatorVestingClaimEvent has drop, store {
// account: address,
// bridge_id: u64,
// stage: u64,
// vesting_reward_amount: u64,
// vested_reward_amount: u64,
// vesting_changes: vector<VestingChange>,
// }

//
// Implementations
Expand Down Expand Up @@ -146,7 +184,8 @@ module initia_std::vip_vesting {
let vesting_store_addr = get_vesting_store_address<Vesting>(account_addr, bridge_id);
let vesting_store = borrow_global_mut<VestingStore<Vesting>>(vesting_store_addr);
assert!(table::contains(&vesting_store.claimed_stages, table_key::encode_u64(stage)), error::unavailable(EVESTING_NOT_CLAIMED));

std::debug::print(&vesting_store.vestings);
std::debug::print(table::borrow(&vesting_store.vestings, table_key::encode_u64(stage)));
let vesting = table::remove(&mut vesting_store.vestings, table_key::encode_u64(stage));
table::add(&mut vesting_store.vestings_finalized, table_key::encode_u64(stage), vesting);
}
Expand Down Expand Up @@ -262,6 +301,14 @@ module initia_std::vip_vesting {
// move vesting if end stage is over or the left reward is empty
if ( stage > value.end_stage || value.remaining_reward == 0) {
finalize_vesting<UserVesting>(account_addr, bridge_id, value.start_stage);
// event::emit(
// UserVestingFinalizedEvent {
// account: account_addr,
// bridge_id,
// stage: value.start_stage,
// remaining_reward: value.remaining_reward,
// }
// );
continue
};

Expand Down Expand Up @@ -300,6 +347,14 @@ module initia_std::vip_vesting {
// move vesting if end stage is over or the left reward is empty
if ( stage > value.end_stage || value.remaining_reward == 0) {
finalize_vesting<OperatorVesting>(account_addr, bridge_id, value.start_stage);
// event::emit(
// OperatorVestingFinalizedEvent {
// account: account_addr,
// bridge_id,
// stage: value.start_stage,
// remaining_reward: value.remaining_reward,
// }
// );
continue
};

Expand Down Expand Up @@ -382,6 +437,15 @@ module initia_std::vip_vesting {
minimum_score,
});

// event::emit(
// UserVestingCreateEvent {
// account: account_addr,
// bridge_id,
// stage: start_stage,
// vesting_reward_amount,
// }
// );

vesting_reward_amount
}

Expand All @@ -401,6 +465,15 @@ module initia_std::vip_vesting {
end_stage,
});

// event::emit(
// OperatorVestingCreateEvent {
// account: account_addr,
// bridge_id,
// stage: start_stage,
// vesting_reward_amount: stage_reward,
// }
// );

stage_reward
}

Expand Down Expand Up @@ -499,7 +572,9 @@ module initia_std::vip_vesting {
);


let vesting_reward_amount = 0;
let vesting_reward_amount = 0;

// if l2_score is less than 0, do not create new position
if (l2_score >= 0) {
vesting_reward_amount = add_user_vesting(
account_addr,
Expand All @@ -512,16 +587,16 @@ module initia_std::vip_vesting {
);
};

event::emit(
VestingClaimEvent {
account: account_addr,
bridge_id,
stage: start_stage,
vesting_reward_amount,
vested_reward_amount: fungible_asset::amount(&vested_reward),
vesting_changes,
}
);
// event::emit(
// UserVestingClaimEvent {
// account: account_addr,
// bridge_id,
// stage: start_stage,
// vesting_reward_amount,
// vested_reward_amount: fungible_asset::amount(&vested_reward),
// vesting_changes,
// }
// );

vested_reward
}
Expand All @@ -531,7 +606,7 @@ module initia_std::vip_vesting {
bridge_id: u64,
start_stage: u64,
end_stage: u64,
): FungibleAsset acquires VestingStore{
): FungibleAsset acquires VestingStore {
let (vested_reward, vesting_changes) = claim_previous_operator_vestings(
account_addr,
bridge_id,
Expand All @@ -545,16 +620,16 @@ module initia_std::vip_vesting {
end_stage,
);

event::emit(
VestingClaimEvent {
account: account_addr,
bridge_id,
stage: start_stage,
vesting_reward_amount,
vested_reward_amount: fungible_asset::amount(&vested_reward),
vesting_changes,
}
);
// event::emit(
// OperatorVestingClaimEvent {
// account: account_addr,
// bridge_id,
// stage: start_stage,
// vesting_reward_amount,
// vested_reward_amount: fungible_asset::amount(&vested_reward),
// vesting_changes,
// }
// );

vested_reward
}
Expand Down

0 comments on commit 45393d0

Please sign in to comment.