Inspiration
cadCAD is a framework for simulating complex systems in Python.
tokenspice is a framework for simulating complex systems on the Ethereum blockchain.
Combining the two, we introduce solsim: a framework for simulating complex dynamical systems—e.g. DeFi protocols, DAO governance, cryptocurrencies—built on the Solana blockchain.
What it does
solsim integrates with anchorpy and solana-py to interface with Solana programs via Python.
It then simulates the behavior of these programs, collects results, and exposes these results in a manner amenable to the Python data science stack.
For example, imagine a smart contract AMM that powers a Solana DEX. Numerous agents interact with this contract in simple and intuitive ways. However, in the long-run, how will the system behave as a whole? How much liquidity will it maintain? How does this liquidity vary over time? What agent behaviors would cause this liquidity to evaporate, i.e. cause the DEX to crash itself? Crucially, can we anticipate these behaviors before launch?
How we built it
Standing on the shoulders of giants anchorpy, solana-py, cadCAD, and tokenspice, we built a slim and unopinionated framework for simulating complex dynamical systems on the Solana blockchain. Simply, a given system is a collection of one or more smart contracts with which users interact.
Using solsim, you define your system, in Python, how you see fit.
Then,
- Implement
initialStepandstepmethods. - From each, return the current state, i.e. a dictionary mapping variables to current values.
- Specify the variables you'd like to "watch."
- Instantiate a Simulation, call .run().
- Receive a pandas DataFrame containing values of "watched" variables at each step in time.
Challenges we ran into
Finding a clean pattern for deploying the Solana programs that comprise a complex system is an ongoing challenge. For example, answering questions like:
- Should we bundle example systems with solsim?
- Should solsim have functionality to deploy these systems to localnet?
- Should it do this via Anchor? Solana CLI?
- Should we simulate the behavior of systems deployed to devnet?
These are ongoing questions and challenges.
Accomplishments that we're proud of
solsim was built in a weekend! We look forward to continuing long-term development at a sustainable pace.
What we learned
Composability is amazing! Ultimately, with solsim, one can simulate the behavior of any system deployed to a cluster to which they have access, e.g. devnet and above. In this sense, programs on blockchains continue to prove themselves as "open APIs, accessible to all."
What's next for solsim
Our rough roadmap is as follows:
- Continue to add simulation features, e.g. parameter search, Monte-Carlo runs, etc.
- Continue to make our software more robust, e.g. adding CI and publishing workflows on GitHub.
- Build a GitBook of documentation.
- Engage with the data science, complex systems, and Solana communities.
Thanks
We thank the judges for their time and consideration!
Log in or sign up for Devpost to join the conversation.