Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

token-2022: Add transfer fee types and instructions #2608

Merged
merged 10 commits into from
Dec 14, 2021

Conversation

joncinque
Copy link
Contributor

Problem

It isn't possible to assess fees on token transfers.

Solution

Add new account types for Mints / Accounts with transfer fees, along with an over-type to handle any type, see UberMint for more info.

Add instructions for initializing mints with transfer fees, setting fees, transferring tokens, and transferring withheld tokens.

@joncinque joncinque requested a review from mvines December 1, 2021 23:12
Copy link
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

Thanks, this is a great start.

Something to 📌: the ATA program will need to change slightly to support the new account type as well.

token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
@joncinque
Copy link
Contributor Author

All right, I think this covers all of the feedback. Thanks for taking such a quick / close look at all this!

token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
@joncinque
Copy link
Contributor Author

I've added in the mixin concept as just structs and instructions, let me know if this is clear or needs more detail.

@joncinque
Copy link
Contributor Author

Ok, one more round of improvements!

Copy link
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

This is feeling really good. I have moar comments but I think we're very close now!

token/program-2022/src/instruction.rs Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

moar review!!1!

token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
@joncinque
Copy link
Contributor Author

One more round!

mvines
mvines previously approved these changes Dec 7, 2021
Copy link
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

I'm just down to pedantic nits, which means :shipit:! This is all feeling pretty tidy to me

@CriesofCarrots - it'd be great if you're able to give this a final once over as well

token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Awesome, looks good. I think the extension approach works well, and I didn't catch any fundamental issues with the design for fees and mint-closing; just added a few small comments/questions. (Apologies if some/all came up in previous threads! I wish I'd been following more closely)

token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/instruction.rs Show resolved Hide resolved
token/program-2022/src/instruction.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
/// 1. `[writable]` The destination account.
/// 2. `[]` The mint's `fee_withdraw_authority`'s multisignature owner/delegate.
/// 3. ..3+M `[signer]` M signer accounts.
HarvestWithheldTokensFromMint,
Copy link
Contributor

Choose a reason for hiding this comment

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

I got confused here. Based on the doc and instruction name -- esp the word "Harvest" -- I thought this instruction was the same as HarvestWithheldTokensToMint, except it sends the tokens to an account instead of the mint. But since no source accounts are provided, I must be wrong.

Perhaps this should be WithdrawWithheldTokensFromMint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes a lot of sense, we use the term WithdrawWithheld everywhere else. The idea is there's one instruction to harvest from accounts to the mint, and another to withdraw from the mint to an account.

For better parallelization, we should probably also add a Withdraw instruction to withdraw straight from a bunch of accounts and into another one, which wouldn't require a writable mint. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I like that idea. The withdraw to mint operation is really just to facilitate emptying all the withheld tokens before closing an account. If we can assert that an account with 0 tokens will always have 0 withheld tokens then we could remove withdrawing to mint entirely

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

If we can assert that an account with 0 tokens will always have 0 withheld tokens then we could remove withdrawing to mint entirely

I can't come up with a model that guarantees this 🤔

Copy link
Contributor

@CriesofCarrots CriesofCarrots Dec 8, 2021

Choose a reason for hiding this comment

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

Excellent, these changes allay all my confusion :)

I can't come up with a model that guarantees this 🤔

I was going to suggest moving the sender's withheld_amount to the destination account, but I think I just duplicated the same thought process you two already did here

token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
token/program-2022/src/state.rs Outdated Show resolved Hide resolved
@mergify mergify bot dismissed mvines’s stale review December 8, 2021 00:23

Pull request has been modified.

mvines
mvines previously approved these changes Dec 9, 2021
decimals: u8,
/// Expected fee assessed on this transfer, calculated off-chain based on
/// the transfer_fee_basis_points and maximum_fee of the mint.
fee: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

If the mint doesn't include an MintTransferFee extension, should we still allow this instruction to be used but the fee must be 0?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems reasonable to me

CriesofCarrots
CriesofCarrots previously approved these changes Dec 9, 2021
Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

lgtm, when clippy is happy!
Sorry about the #[allow(deprecated)]s needed

@joncinque joncinque changed the title WIP token-2022: Add transfer fee accounts and instructions token-2022: Add transfer fee types and instructions Dec 14, 2021
@joncinque joncinque marked this pull request as ready for review December 14, 2021 21:37
@mergify mergify bot dismissed stale reviews from mvines and CriesofCarrots December 14, 2021 21:38

Pull request has been modified.

@joncinque
Copy link
Contributor Author

Merging this round of changes so we have a base to iterate on, thanks for reviews!

@joncinque joncinque merged commit 2cd68d3 into solana-labs:master Dec 14, 2021
@joncinque joncinque deleted the token-fee branch December 15, 2021 22:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants