Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add assertion to check existence of shareholder in the contract #27

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,19 @@ module supra_framework::vesting_without_staking {
}

public entry fun vest_individual(contract_address: address, shareholder_address: address) acquires VestingContract {
assert_active_vesting_contract(contract_address);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjoshisupra why we removed this check as the vesting contract can be terminated at the end of vest_individual. It will cause a problem when call vest method who will call vest_individual in a loop.

//extract beneficiary address
//check if contract exist, active and shareholder is a member of the contract
assert_shareholder_exists(contract_address,shareholder_address);

let vesting_signer = account::create_signer_with_capability(&borrow_global<VestingContract>(contract_address).signer_cap);
//extract beneficiary address
let beneficiary = beneficiary(contract_address,shareholder_address);
{
let vesting_contract = borrow_global_mut<VestingContract>(contract_address);
// Short-circuit if vesting hasn't started yet.
if (vesting_contract.vesting_schedule.start_timestamp_secs > timestamp::now_seconds()) {
return
};

let vesting_record = simple_map::borrow_mut(&mut vesting_contract.shareholders,&shareholder_address);

// Check if the next vested period has already passed. If not, short-circuit since there's nothing to vest.
Expand Down Expand Up @@ -649,6 +651,11 @@ module supra_framework::vesting_without_staking {
fun assert_vesting_contract_exists(contract_address: address) {
assert!(exists<VestingContract>(contract_address), error::not_found(EVESTING_CONTRACT_NOT_FOUND));
}

fun assert_shareholder_exists(contract_address: address, shareholder_address: address) acquires VestingContract {
assert_active_vesting_contract(contract_address);
assert!(simple_map::contains_key(&borrow_global<VestingContract>(contract_address).shareholders,&shareholder_address), error::not_found(ESHAREHOLDER_NOT_EXIST));
}

fun assert_active_vesting_contract(contract_address: address) acquires VestingContract {
assert_vesting_contract_exists(contract_address);
Expand Down