# Going further in Solana: Writing my first Vault and Escrow Programs

After [last week's launch](https://kevgathuku.dev/what-i-learned-minting-my-first-spl-token-and-nft-on-solana) into the Solana world through [Turbin3](https://turbin3.org/), I'm back with some new adventures. In the past week I ended up writing a working [vault](https://github.com/kevgathuku/turbine_vault) and [escrow](https://github.com/kevgathuku/turbine_escrow) program, the equivalent of “Hello World” in the Solana ecosystem.

Let’s dive into some lessons from this experience.

#### Love - Hate relationship with Rust 🦀

Rust is a first class citizen in the Solana world. The hardest part of writing Solana programs with Anchor was getting used to the Rust syntax and the infamous compiler errors. Having worked mainly with untyped languages, this took some time to get used to and it's still tough.\
\
On the bright side, after the struggle to fix all the compiler errors, there is a brief moment of bliss when it finally works and all the red squiggly lines are gone from the editor 🤩 😌 🎸

#### GitHub Actions was a pain 🛵

Setting up Anchor tests to automatically run on GitHub Actions was a struggle. Dealing with anchor and rust versions mismatches, outdated install commands, but in the end the tests did finally run.

Here is how it went trying to setup anchor tests on the [vault program](https://github.com/kevgathuku/turbine_vault)

![Struggling with getting GitHub Actions to run anchor tests](https://cdn.hashnode.com/uploads/covers/5c3dea018af588415cdc51f6/4006e563-ef09-462e-b9a9-ea3205aa9ecf.png align="center")

This is also where working with an AI agent was quite helpful. Let’s talk more about that next.

#### AI agents Workflow 🤖

Not using AI agents for any kind of programming task is a lost opportunity for learning. They are great at debugging failures, reading the actual source to validate why something is not working, and getting to something that works.

On the flip side, there is little training data on languages like Rust and ecosystems like Solana and Anchor. Quoting the AI agent directly:

> General languages dominate by orders of magnitude. JavaScript/TypeScript, Python, and Java are most of public code; Rust itself is a small slice of that.
>
> Solana is a slice of a slice. The chain launched in 2020, Anchor in 2021 — there’s simply less code in existence, with less history, fewer tutorials, and fewer Stack Overflow threads than anything mainstream.
>
> Anchor has a recency problem on top. It broke APIs across the 0.2x → 0.3x → 1.x jumps (#\[account\] discriminators, InterfaceAccount, the 1.x re-exports). Older patterns are overrepresented in whatever data exists, so memory defaults to stale Anchor more often than it defaults to stale React.

So with this context, everything had to be validated. The upside is that Anchor has good tests integration with [LiteSVM](https://www.litesvm.com/) and it was possible to verify most behaviour and edge cases with tests. You also have the choice to write tests with TypeScript. I stuck with Rust though. I've learned to trust the strict compiler more.

Related to this, when dealing with crypto and programs that deal with real value in general, you absolutely need to understand the code you are writing, especially if working with AI agents. If you need a reason why check <https://web3isgoinggreat.com/>

This is what the AI agent had to say about our sessions

> 1. Verify, don't assume. Your most common move is a question, not a statement: "Is this needed?", "Does it make sense?", "Isn't this redundant?", "Is there a need for this struct?" You  treat every suggestion - including mine - as guilty until proven innocent.
> 2. Mechanism over recipe. You rarely ask how; you ask why it works that way. PDA signer seeds, init-before-constraints ordering, why close = maker moves rent, what COption is for. You build mental models, then reason from them.
> 3. Hold ideas lightly. You proposed the nested fixture, then questioned it; asked for the take_c struct, then asked to revert it; had me inline a helper you'd asked to extract. No sunk-cost attachment - each reversal came with a sharper criterion than before

I wasn’t totally innocent though. I have been reckless a more than a few times 😅

> 4\. Tight loop over careful planning.
>
> You move fast and let the suite arbitrate: paste a sketch, run the tests, read the failure. It works because the loop is seconds long. The honest edge: several of your edits arrived unverified. Each was caught within minutes, but the pattern is real: your hands sometimes outrun your eyes, and you spend the test suite’s time on what a re-read would have caught.

I treat the AI agent more like an energetic co-worker who doesn't mind explaining something for the 30th time. I’ve learned a lot from the back and forth and I think the final product has ended up better as a result.

NB: \
I found this amazing [socratic-tutor skill](https://github.com/janestreet/agent_skills) from JaneStreet which turns the agent into a teacher, testing your understanding of concepts without any of the usual flattery. It's almost as strict as the Rust compiler 🦾\
It has helped me identify and fix gaps in my understanding of the underlying concepts. Worth trying it out if you actually want a deep understanding of concepts and not just offload all the work to the agent.

#### Wrapping it up 🍬

I didn’t plan to write so much about AI but it seems there was a lot to unpack there

If Solana and Anchor programs are the kind of things you find interesting, feel free to check out the [vault](https://github.com/kevgathuku/turbine_vault) and [escrow](https://github.com/kevgathuku/turbine_escrow) programs on GitHub. Future posts might dive deeper into the code but that needs more socratic learning first 😆
