Skip to content

Add lockups adjustment#1

Open
vasyafromrussia wants to merge 11 commits intomainfrom
feature/recall
Open

Add lockups adjustment#1
vasyafromrussia wants to merge 11 commits intomainfrom
feature/recall

Conversation

@vasyafromrussia
Copy link
Copy Markdown
Collaborator

No description provided.

Comment on lines +59 to +68
for index in lockup_indices.clone() {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");
require!(lockup.is_adjustable, "Lockup is not adjustable");

total_balance += lockup.schedule.total_balance();

original_schedules.push((index, lockup.schedule));
lockup.schedule = Schedule::new_unlocked(0);
self.lockups.replace(index as _, &lockup);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
for index in lockup_indices.clone() {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");
require!(lockup.is_adjustable, "Lockup is not adjustable");
total_balance += lockup.schedule.total_balance();
original_schedules.push((index, lockup.schedule));
lockup.schedule = Schedule::new_unlocked(0);
self.lockups.replace(index as _, &lockup);
}
for index in &lockup_indices {
let mut lockup = self.lockups.get(*index as _).expect("Lockup not found");
require!(lockup.is_adjustable, "Lockup is not adjustable");
total_balance += lockup.schedule.total_balance();
original_schedules.push((*index, lockup.schedule));
lockup.schedule = Schedule::new_unlocked(0);
self.lockups.replace(*index as _, &lockup);
}

Comment on lines +99 to +106
fn after_lockup_adjustment(&mut self, lockup_index: LockupIndex, schedule: Schedule) {
if is_promise_success() {
return;
}

let mut lockup = self.lockups.get(lockup_index as _).expect("Lockup not found");
lockup.schedule = schedule;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this code restore old schedule in case of failure? Maybe it is better to rename schedule variable here to something like schedule_before_adjustment?

Comment on lines +108 to +130
fn after_lockups_revoke(&mut self, original_schedules: Vec<(LockupIndex, Schedule)>) {
if is_promise_success() {
for (index, _) in original_schedules {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");

let mut account_lockups = self
.account_lockups
.get(&lockup.account_id)
.expect("Account lockups not found");
account_lockups.remove(&index);
self.account_lockups.insert(&lockup.account_id, &account_lockups);

lockup.account_id = env::current_account_id();
self.lockups.replace(index as _, &lockup);
}
} else {
for (index, schedule) in original_schedules {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");
lockup.schedule = schedule;
self.lockups.replace(index as _, &lockup);
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit]
I'm not sure if this improves the readability that much. You can ignore this if you don't like it)

Suggested change
fn after_lockups_revoke(&mut self, original_schedules: Vec<(LockupIndex, Schedule)>) {
if is_promise_success() {
for (index, _) in original_schedules {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");
let mut account_lockups = self
.account_lockups
.get(&lockup.account_id)
.expect("Account lockups not found");
account_lockups.remove(&index);
self.account_lockups.insert(&lockup.account_id, &account_lockups);
lockup.account_id = env::current_account_id();
self.lockups.replace(index as _, &lockup);
}
} else {
for (index, schedule) in original_schedules {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");
lockup.schedule = schedule;
self.lockups.replace(index as _, &lockup);
}
}
}
fn after_lockups_revoke(&mut self, original_schedules: Vec<(LockupIndex, Schedule)>) {
if !is_promise_success() {
for (index, schedule) in original_schedules {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");
lockup.schedule = schedule;
self.lockups.replace(index as _, &lockup);
}
return;
}
for (index, _) in original_schedules {
let mut lockup = self.lockups.get(index as _).expect("Lockup not found");
let mut account_lockups = self
.account_lockups
.get(&lockup.account_id)
.expect("Account lockups not found");
account_lockups.remove(&index);
self.account_lockups.insert(&lockup.account_id, &account_lockups);
lockup.account_id = env::current_account_id();
self.lockups.replace(index as _, &lockup);
}
}

Comment on lines +71 to +72
// let holding_contract_init_result = context.utils().call("new").max_gas().transact().await?.into_result()?;
// println!("Initialized holding contract: {:?}", holding_contract_init_result);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be removed?

Comment on lines +37 to +49
let result = self
.user_account()
.expect("User account is required")
.call(self.contract.id(), "terminate")
.args_json(json!({
"lockup_index": lockup_index,
"hashed_schedule": hashed_schedule,
"termination_timestamp": termination_timestamp
}))
.max_gas()
.deposit(NearToken::from_yoctonear(1))
.transact()
.await?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I updated integration utils in this repo and you can use new interface for such calls. You can rebase to main and use them

@VladasZ VladasZ force-pushed the main branch 2 times, most recently from 3063e6f to 652fa96 Compare December 19, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants