An example of a Solana program built with Seahorse. It is an automated marked maker program. Users can add liquidity, remove liquidity and swap tokens using the program.
A constant product automated market maker (CPMM) uses a constant product formula (xy=k) to determine the prices of assets traded on the platform, providing a stable trading environment. CPMMs are often used in decentralized finance (DeFi) applications.
- Install solana, anchor and seahorse.
- After project is created,
cd
to program folder. - Run
seahorse init <program-name>
command to create new seahorse project. - Run
seahorse build
to build the program. The first build might take few minutes. - After the build is complete, start writing the program in
<program-name>.py
file underprograms_py
folder.
Solana program states are stored in data accounts.
Here we have a pool
account which is used for storing a pair of tokens.
Instructions are functions where logic of the program is stored. We can create new accounts, create tokens, mint and transfer tokens with instructions. Instructions can be called from client programs.
There are three instructions in this program.
create_pool
-> Create a new pool account for a pair of tokens.add_liquidity
-> Users can add liquidity to the pool for a specific pair of tokens and mint lp tokens. The lp tokens value are proportional to the value of added tokens.remove_liquidity
-> Users can remove liquidity from the pool.swap
-> Swap between two pairs of tokens.
Run anchor test
command to run test programs on solana localhost.