near/contracts: clamp upgrade repayment delta to 0
This ensures that the refund amount is at most the attached deposit when upgrading the contract.
This commit is contained in:
parent
446cbaaa53
commit
6168dd8ab3
|
@ -48,6 +48,8 @@ use {
|
|||
pub mod byte_utils;
|
||||
pub mod state;
|
||||
|
||||
use std::cmp::max;
|
||||
|
||||
use crate::byte_utils::{
|
||||
get_string_from_32,
|
||||
ByteUtils,
|
||||
|
@ -791,6 +793,8 @@ impl NFTBridge {
|
|||
) {
|
||||
let delta = (env::storage_usage() as i128 - storage_used as i128)
|
||||
* env::storage_byte_cost() as i128;
|
||||
let delta = max(0, delta);
|
||||
|
||||
let refund = attached_deposit as i128 - delta;
|
||||
if refund > 0 {
|
||||
env::log_str(&format!(
|
||||
|
|
|
@ -40,6 +40,8 @@ use {
|
|||
pub mod byte_utils;
|
||||
pub mod state;
|
||||
|
||||
use std::cmp::max;
|
||||
|
||||
use crate::byte_utils::{
|
||||
get_string_from_32,
|
||||
ByteUtils,
|
||||
|
@ -1709,6 +1711,8 @@ impl TokenBridge {
|
|||
));
|
||||
let delta = (env::storage_usage() as i128 - storage_used as i128)
|
||||
* env::storage_byte_cost() as i128;
|
||||
let delta = max(0, delta);
|
||||
|
||||
let refund = attached_deposit as i128 - delta;
|
||||
if refund > 0 {
|
||||
env::log_str(&format!(
|
||||
|
|
|
@ -26,6 +26,8 @@ pub mod byte_utils;
|
|||
|
||||
pub mod state;
|
||||
|
||||
use std::cmp::max;
|
||||
|
||||
use crate::byte_utils::{
|
||||
get_string_from_32,
|
||||
ByteUtils,
|
||||
|
@ -582,6 +584,8 @@ impl Wormhole {
|
|||
) {
|
||||
let delta = (env::storage_usage() as i128 - storage_used as i128)
|
||||
* env::storage_byte_cost() as i128;
|
||||
let delta = max(0, delta);
|
||||
|
||||
let refund = attached_deposit as i128 - delta;
|
||||
if refund > 0 {
|
||||
env::log_str(&format!(
|
||||
|
|
Loading…
Reference in New Issue