-
Notifications
You must be signed in to change notification settings - Fork 2
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 lockups adjustment #1
base: main
Are you sure you want to change the base?
Conversation
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |
} |
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; | ||
} |
There was a problem hiding this comment.
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
?
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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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)
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); | |
} | |
} |
// let holding_contract_init_result = context.utils().call("new").max_gas().transact().await?.into_result()?; | ||
// println!("Initialized holding contract: {:?}", holding_contract_init_result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed?
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?; |
There was a problem hiding this comment.
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
3063e6f
to
652fa96
Compare
No description provided.