General purpose Solana program to purchase a token for a set amount of SOL. Created to be used as an on-chain whitelist for a candy machine.
Overview
Doorman is a Solana program created to enable a whitelist of allowed address access to a candy machine. It's a simple mechanism to accept payment for custom SPL token, and can be used standalone for that purpose. But the steps to set it up as a whitelist mechanism for a candy machine are:
- create a new mint
- set up a separate candy machine for the whitelist, which is configured to accept the new mint token instead of SOL
- set up a doorman with a vault containing the mint tokens
- add whitelist addresses to the doorman's list
- a user can now pay SOL for a mint token, which can then be used in the candy machine
- when this happens, the address is removed from the whitelist
Status
Doorman was deployed to production and resides at D8bTW1sgKaSki1TBUwxarPySLp3TNVgB2bwRVbbTLYeV (https://solscan.io/account/D8bTW1sgKaSki1TBUwxarPySLp3TNVgB2bwRVbbTLYeV). The code has been audited and used in production, though the audits haven't been rigorous. The deployed version is capable of supporting a whitelist size up to 1111 entries long. One thing to note is that the deployed version is not currently reflected in the master branch. It was deployed from a separate branch, which I haven't had time to properly merge back into master yet. If you're interested in using Doorman, just reach out and I can help you out.
Apologies if this documentation is incomplete. Reach out to me on Twitter if you have any questions, comments, suggestions, etc: @silostack
Alternatively, come hang out in the Kaizen Corps #dev-chat Discord channel. I'm there all day: https://discord.gg/UE7JMaybGf
Configuration
A doorman is set up with the following:
- a go live date
- a list of whitelisted addresses
- a cost in SOL for a mint token
- a treasury for the program to send the SOL to
Setup (just doorman)
This is a standard Anchor program so standard instructions apply.
The /scripts directory contains a bunch of scripts that can be run to test everything out on a running solana-test-validator. Here's the steps to try it out:
- fire up a localnet:
-test-validator - deploy:
deploy - initialize:
run initialize
- copy the 3 accounts that the initialize script spit out into the config.js file
- edit the add_addresses.js file with an address you'd like to put on the whitelist
run add-address
- now update Anchor.toml and change the wallet to the address that was whitelisted
- run a test mint:
run test-mint
Also worth noting is that you can run the tests against your running localnet validator instead of the test firing up its own using:
test --skip-local-validator
Full Setup w/Candy Machine
Here's the full list of steps to set up a candy machine + doorman on devnet.
- create a mint:
-token create-token --decimals 0
- create a token account for it:
-token create-account BNbYgmELT2o1VbGcg5vq7EK2AWL7UmLe9dhizMdGy8Pg
- mint some tokens into the account:
-token mint BNbYgmELT2o1VbGcg5vq7EK2AWL7UmLe9dhizMdGy8Pg 10000 - now go through steps to set up your candy machine, making sure to specify the mint + spl token account that you just created, when executing the createcandymachine command
- go into doorman, and update the following fields in .env with the ones you just saved above:
- get ready to initialize your doorman
- now initialize doorman:
run initialize
- if you want, you can update doorman's config:
run update-config - add any addresses you'd like to whitelist to the addy.txt file and run:
run add-addresses - update app/src/utils/config.js to use devnet
- now fire up the /app:
start - if the wallet you're connecting with has been properly added, you should see the message "Your address is on the whitelist!"
- click the "purchase mint token" button to purchase a minting token with SOL
- then click the "mint" button to mint an nft using the token you just purchased
TODO
This still needs a ton of work. Here's a very incomplete list of things that I need to add. PRs super welcome:- add multiple addresses at the same time
- current whitelist size is limited to around 300 atm. this is due to account size limitations when constructing
- address removal
- add a button to perform the purchase + mint in a single transaction
- easier mint token account creation for the payer ..?
- store bumps ..?
- switch back to PDA for config ..?
- consolidate the config for the anchor scripts into .env or something
- fix up the UI so it doesn't look like ass ..?
Help
Would love some help on this. I know there's already a lot of devs out there looking for on-chain whitelist capability. And of course... tips are always appreciated: 7VyBHkyQw266uF5RfBTHAeuCWt8bSV12Xp8jfPsgj7fa
Credits & Resources
- all the great examples from Anchor
- the source code in Metaplex
- good explanation of PDAs: https://www.brianfriel.xyz/understanding-program-derived-addresses/
- i straight lifted the mint token account/authority stuff from: https://hackmd.io/@ironaddicteddog/anchorexampleescrow
- https://github.com/exiled-apes/candy-machine-mint was a great starter
- help from https://github.com/hogyzen12