coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.68k stars 1.35k forks source link

examples: Create SPL token program #115

Open armaniferrante opened 3 years ago

armaniferrante commented 3 years ago

Would be cool to have a copy of the SPL token program written in Anchor.

jon-chuang commented 3 years ago

I'd love to work on this

armaniferrante commented 3 years ago

Awesome. Open a PR!

petscheit commented 3 years ago

Is anybody working on this? Would be very interested to look at a WIP to get a better grasp

jon-chuang commented 3 years ago

hey @armaniferrante , what's the difference between this and anchor-spl?

armaniferrante commented 3 years ago

anchor_spl provides a CPI client for interacting with the existing spl token program (and other programs).

This issue is to rewrite the existing spl token program as an example for educational purposes.

petscheit commented 3 years ago

I'm interested to work on this and have started implementing the mint and account initialization. I used the same fields used in the solana-program-library. So far I'm unable to add the initialized mint to sollet and also don't see supply etc. on my local explorer when looking at the mint account. Is this by design and tokens are only recognized in the wallet and explorer when created with the solana token program?

armaniferrante commented 3 years ago

I'm interested to work on this and have started implementing the mint and account initialization. I used the same fields used in the solana-program-library. So far I'm unable to add the initialized mint to sollet and also don't see supply etc. on my local explorer when looking at the mint account. Is this by design and tokens are only recognized in the wallet and explorer when created with the solana token program?

Correct. It's currently the case that the only tokens recognized by wallets are from the SPL token program. So tokens created by other programs, even if they implement the same interface won't be recognized at the moment.

petscheit commented 3 years ago

I see. I've been poking around sollet trying to integrate a custom tokens, but am stuck on the associated token program. Dont really understand what it is used for and how is compares to the way associated accounts are handled in anchor. Are there any plans to update sollet in the near future? Also, is serum able to handle custom tokens or is that also something that needs to be worked on?

armaniferrante commented 3 years ago

The associated program is needed because its an addon to a previously existing SPL token program. In theory, if you were to rewrite the SPL token program from scratch, you can just use associated accounts directly in the token program, as is handled in Anchor (I'd also recommend making all token accounts associated with a user and a mint).

Both sollet and serum can handle custom tokens.