2

In Pinocchio 0.10.1, Rent::get()?.minimum_balance(DATA_LEN) has been deprecated.

So I am trying to use the Rent::try_minimum_balance()

  let rent = Rent::from_account_view(my_account)?;// fails to run at 
//unlikely(account_view.address() != &RENT_ID) inside the from_account_view().
//What is RENT_ID?

  let rent = Rent::from_bytes(my_account.borrow_unchecked())?;
  // causes the lamports below to be 0 
  let lamports = Rent::try_minimum_balance(&rent, Mint22::BASE_LEN)?;

How to make rent from a given account ?

And what if such my_account does not exist yet?

Docs: https://docs.rs/pinocchio/latest/pinocchio/sysvars/rent/struct.Rent.html

1 Answer 1

1

You have to pass the rent sysvar account (which has account address RENT_ID) to get the Rent struct first, then use that to get the required rent based on how many bytes of data your account will hold:

// rent_account_sysvar has address RENT_ID
let rent_sysvar = Rent::from_account_view(rent_account_sysvar)?;
// my_account_len is how many bytes are/will be stored inside my_account
let rent_for_my_account = rent_sysvar.try_minimum_balance(my_account_len)?;
3
  • rent_account_sysvar's address is SysvarRent111111111111111111111111111111111 Thank you Commented 10 hours ago
  • is Rent::from_bytes(account.borrow_unchecked()) used for existing accounts? Commented 9 hours ago
  • Rent::from_bytes is for when you got the rent sysvar data via some other means and want to convert it to a Rent struct. To calculate rent for foreign accounts it's always with the byte length like I showed in my answer. Commented 34 mins ago

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.