Skip to content

Commit bd24d4d

Browse files
committed
near: address both refund logic issues
1 parent f3dce0e commit bd24d4d

File tree

1 file changed

+6
-4
lines changed
  • target_chains/near/receiver/src

1 file changed

+6
-4
lines changed

target_chains/near/receiver/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl Pyth {
589589
/// Checks storage usage invariants and additionally refunds the caller if they overpay.
590590
fn refund_storage_usage(
591591
&self,
592-
refunder: AccountId,
592+
recipient: AccountId,
593593
before: StorageUsage,
594594
after: StorageUsage,
595595
deposit: Balance,
@@ -606,13 +606,15 @@ impl Pyth {
606606

607607
// Otherwise we refund whatever is left over.
608608
if deposit - cost > 0 {
609-
Promise::new(refunder).transfer(cost);
609+
Promise::new(recipient).transfer(deposit - cost);
610610
}
611611
} else {
612-
// Handle storage decrease if checked_sub fails. We know storage used now is <=
612+
// If checked_sub fails we have a storage decrease, we want to refund them the cost of
613+
// the amount reduced, as well the original deposit they sent.
613614
let refund = Balance::from(before - after);
614615
let refund = refund * env::storage_byte_cost();
615-
Promise::new(refunder).transfer(refund);
616+
let refund = refund + deposit;
617+
Promise::new(recipient).transfer(refund);
616618
}
617619

618620
Ok(())

0 commit comments

Comments
 (0)