Module sui_system::storage_fund
- Struct
StorageFund - Function
new - Function
advance_epoch - Function
total_object_storage_rebates - Function
total_balance
use std::address;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::type_name;
use std::vector;
use sui::accumulator;
use sui::address;
use sui::bag;
use sui::balance;
use sui::coin;
use sui::config;
use sui::deny_list;
use sui::dynamic_field;
use sui::dynamic_object_field;
use sui::event;
use sui::hex;
use sui::object;
use sui::party;
use sui::sui;
use sui::table;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::url;
use sui::vec_map;
use sui::vec_set;
Struct StorageFund
스토리지 기금을 나타내는 struct이며, 두 개의 Balance를 포함한다:
는 현재 온체인에 저장된 모든 object의total_object_storage_rebatesstorage_rebate합과 같아야 한다는 불변식을 가진다. 이 불변식을 유지하기 위해 이 balance의 유입은 transaction에서 징수한 storage charge뿐이며 유출은 transaction의 storage rebate뿐이고, 여기에는 transaction sender에게 환불되는 부분과 환불되지 않고 분리되어non_refundable_balance로 들어가는 부분이 모두 포함된다.non_refundable_balance는 기금에서 인출되지 않아야 하는 storage fund의 나머지 유입을 포함한다.
public struct StorageFund has store
Click to open
Fields
-
total_object_storage_rebates: sui::balance::Balance<sui::sui::SUI> -
non_refundable_balance: sui::balance::Balance<sui::sui::SUI>
Function new
genesis 시점에
sui_system이 호출한다.
public(package) fun new(initial_fund: sui::balance::Balance<sui::sui::SUI>): sui_system::storage_fund::StorageFund
Click to open
Implementation
public(package) fun new(initial_fund: Balance<SUI>): StorageFund {
StorageFund {
// 시작 시점에는 아직 스토리지에 object가 없다.
total_object_storage_rebates: balance::zero(),
non_refundable_balance: initial_fund,
}
}
Function advance_epoch
epoch 변경 시점에 storage fund의 유입과 유출을 처리하기 위해
sui_system이 호출한다.
public(package) fun advance_epoch(self: &mut sui_system::storage_fund::StorageFund, storage_charges: sui::balance::Balance<sui::sui::SUI>, storage_fund_reinvestment: sui::balance::Balance<sui::sui::SUI>, leftover_staking_rewards: sui::balance::Balance<sui::sui::SUI>, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64): sui::balance::Balance<sui::sui::SUI>
Click to open
Implementation
public(package) fun advance_epoch(
self: &mut StorageFund,
storage_charges: Balance<SUI>,
storage_fund_reinvestment: Balance<SUI>,
leftover_staking_rewards: Balance<SUI>,
storage_rebate_amount: u64,
non_refundable_storage_fee_amount: u64,
): Balance<SUI> {
// 재투자분과 잔여 보상은 환불 대상이 아니므로 non-refundable balance로 들어간다.
self.non_refundable_balance.join(storage_fund_reinvestment);
self.non_refundable_balance.join(leftover_staking_rewards);
// 해당 epoch의 storage charge는 새로 생성된 object의 storage rebate와
// epoch 중 수정된 object의 새로운 storage rebate에서 오므로
// charge를 `total_object_storage_rebates`에 넣는다.
self.total_object_storage_rebates.join(storage_charges);
// storage rebate의 환불 불가 부분을 분리해 non-refundable balance에 넣는다.
let non_refundable_storage_fee = self
.total_object_storage_rebates
.split(non_refundable_storage_fee_amount);
self.non_refundable_balance.join(non_refundable_storage_fee);
// `storage_rebates`에는 삭제된 object의 이미 환불된 rebate와 수정된 object의 기존 rebate가 포함되며
// `total_object_storage_rebates`에서 빠져야 한다.
let storage_rebate = self.total_object_storage_rebates.split(storage_rebate_amount);
// storage rebate는 이미 개별 transaction sender의 gas coin으로 반환되었으므로
// epoch 변경의 마지막 단계에서 소각될 balance를 반환한다.
storage_rebate
}
Function total_object_storage_rebates
public fun total_object_storage_rebates(self: &sui_system::storage_fund::StorageFund): u64
Click to open
Implementation
public fun total_object_storage_rebates(self: &StorageFund): u64 {
self.total_object_storage_rebates.value()
}
Function total_balance
public fun total_balance(self: &sui_system::storage_fund::StorageFund): u64
Click to open
Implementation
public fun total_balance(self: &StorageFund): u64 {
self.total_object_storage_rebates.value() + self.non_refundable_balance.value()
}