A reminder on how reflection tokens like safemoon work is every ones balance is simply an equation instead of a fixed number. That way everyone's balance can be instantly updated with no gas needed when someone sells their coin. My question is is this possible on solona?
3 Answers
Sure! The SPL token program includes instructions called AmountToUiAmount
and UiAmountToAmount
: https://github.com/solana-labs/solana-program-library/blob/6ed80b3a353042df7a60353fa38d9460628b40de/token/program/src/instruction.rs#L442-L471
These instructions convert from some "base" amount of tokens in an account to a "UI" amount. So for example, if you have 10,500,000,000 base tokens, and the token has 9 decimal places, the UI amount would be 10.5.
You could fork the program and write these converters to do any math that you want!
Note that if you need more data from the outside than the mint and the account in question, it might be more difficult for outside people to use. Also, it's very difficult to get adoption of new token programs on Solana at the moment, but it's technically possible.
-
this is what chat cpt told me. "Reflection tokens on Ethereum work by automatically redistributing a portion of transaction fees to all token holders, which is facilitated by the stateful nature of Ethereum smart contracts. Solana’s architecture, being stateless, requires explicit read and write operations to account data for each transaction, which would involve computing power and transaction fees12.– OPPCommented Dec 6, 2023 at 3:42
-
Balances aren't stored the same way in Solana as they are stored on the EVM. In Solana, token balance is stored in a token account, not on the state of a contract. The end goal of safemoon's reflection token, if I'm not mistaken, is to reward holders of the token with transaction fees, right? You MAY be able to implement something similar using a transfer hook. Let me know if you're successful!
-
here's what chatgpt told me "However, while a transfer hook could allow for additional actions to be taken during a token transfer, it does not change the fundamental way that Solana handles account balances and state. In Solana, each account’s balance is still a discrete value stored in the account data, and updating this balance requires explicit read and write operations1."– OPPCommented Dec 6, 2023 at 3:51
Token 2022 will allow you to hook transfer instructions and to implement your own logic. It even supports tax logic by default but I am not sure if it's really what you're looking for. https://spl.solana.com/token-2022#extensions