metaplex-foundation / js

A JavaScript SDK for interacting with Metaplex's programs
355 stars 182 forks source link

Candy Machine: Zero-decimal SPL Tokens #234

Closed cosimo-rip closed 1 year ago

cosimo-rip commented 2 years ago

Hi there! I've been working with the candy machine plugin, and in testing, believe I've come across an issue with SPL token-based mints.

I think the library does not handle SPL tokens with varying decimals. In this instance, I have an SPL token with zero decimals, and when setting a price of 1, the resulting candy machine (through create or update methods) ends up deployed with a resulting price of 1,000,000,000 (off by a factor of 10^9).

At first I was working with the JSON based methods like createFromJsonConfig. Since price is just a number there I was simply providing price: 1.

I assumed I might need to move to the lower level create method for more control, and tried to solve this by doing: price: token(myPrice, 0, "CUSTOM")

But alas, in both cases price came out as 1,000,000,000.

Checked out the tests for guidance and noticed that SPL tokens are always generated with mx.tokens().createTokenWithMint(), so I'm wondering if this is just an unexplored case. https://github.com/metaplex-foundation/js/blob/8d2183d84f8ce4e6f383b8578f84df6cdc5d1049/packages/js/test/plugins/candyMachineModule/createCandyMachine.test.ts#L130

I also see here that the price is assumed to always be compatible with lamports(): https://github.com/metaplex-foundation/js/blob/8d2183d84f8ce4e6f383b8578f84df6cdc5d1049/packages/js/src/plugins/candyMachineModule/CandyMachine.ts#L139

Please let me know if I'm doing something wrong! (Also, FWIW, Sugar CLI works fine with zero-decimal tokens).

lorisleiva commented 1 year ago

Thanks again for your contribution, I will publish this with the next breaking change version since the main branch already contains breaking changes. Hopefully, that should be this week. 🤞

lorisleiva commented 1 year ago

Version 0.16.0 contains your changes. 🎉

cosimo-rip commented 1 year ago

perfect timing! skullana fest thanks you 😉