Skip to content
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

Allow native SOL to be represented as a token #67

Closed
wants to merge 1 commit into from

Conversation

mvines
Copy link
Member

@mvines mvines commented Jun 30, 2020

TODO:

  • Implementation and tests
  • JS bindings
  • Remove Burn instruction (file a follow-up issue)
  • Remove signer from NewAccount (file a follow-up issue)

/// 0. `[signer]` Owner of the token account.
/// 1. `[writable]` Token account to release.
/// 2. `[writable]` Destination account to receive the full SOL balance of the account.
ReleaseAccount,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReleaseAccount works for non-wrapped token accounts as well, and thus is effectively a replacement for Burn(u64) but also:

  1. Prevents a zero-balance token account that floats around forever
  2. Assumes that we'll redefine the supply field according to Add rent awareness to spl-token #66 (comment) such that it never decreases

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have the requirement to partial burn tokens from an account then we should remove the burn instruction :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, totally agree! And you can still do a partial burn by transferring to a new token account then ReleaseAccounting it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though that is a two-step process (one transaction), will have a performance impact depending on how fast folks want to burn stuff

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is unlikely to be an issue, but let's see what comes out of that slack thread.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok fine, no changes to Burn since partial burns seem to be a little popular.

For a normal non-wrapped token, we could:

  1. Consider ReleaseAccount to also act as a full Burn
  2. Require the non-wrapped token have a zero token balance before ReleaseAccount can be called on it
  3. Only allow ReleaseAccount on wrapped tokens, which means a rent-exempt non-wrapped token account will always live forever.

I prefer 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer 1 also

@@ -85,6 +85,17 @@ pub enum TokenInstruction {
/// 2. `[writable]` Token being burned.
/// 3. Optional: `[writable]` Source account if key 1 is a delegate account.
Burn(u64),

/// Wrap SOL into a token account. The full lamport balance in the new account will be wrapped
/// 0. `[writable]` New wrapped account being created.
Copy link
Member Author

@mvines mvines Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I dropped the signer requirement (NewAccount should do the same IMO). Requiring a signer here means the token account can't be a derived account (aka CreateAccountWithSeed).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can wrap my account without permission?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but only if you leave it in as State::Unallocated (ie, you don't create and initialize your account in an atomic transaction)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That footgun should probably be well documented

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll add a comment here. The Rust/JS bindings should do the right thing. Note that Vote and Stake account initialization behave this way too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment, also renamed to InitializeWrappedAccount since it's not actually creating the account but only initializing it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for Initialize. This feels a lot more consistent with our native programs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#70

@@ -0,0 +1,3 @@

/// The token type for wrapped native SOL
solana_sdk::declare_id!("So11111111111111111111111111111111111111111");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no Mint account for wrapped SOL. But the Account::token value is set to So11111111111111111111111111111111111111111 so that the Transfer instruction can do the right thing if it's wrapped and for RPC inspection.

@jackcmay
Copy link
Contributor

jackcmay commented Jul 8, 2020

Replaced by #112

@jackcmay jackcmay closed this Jul 8, 2020
andrewsource147 pushed a commit to MeteoraAg/solana-program-library that referenced this pull request May 20, 2022
andrewsource147 pushed a commit to MeteoraAg/solana-program-library that referenced this pull request May 20, 2022
* fix ci solana version (solana-labs#67)

* Update switchboard-program to v0.2.0 (solana-labs#66)

* oracleless repay (solana-labs#64)

* oracleless repay

* lint

* the easy way

* updated test to make sure interest accumulates before repay

Co-authored-by: 0xkiplet <98113383+0xkiplet@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants