← Blog

The Solana Deeds #7: Put your dollars with the better of two lenders

A tool that compares the USDC rate at Kamino and Jupiter Lend, deposits with the higher one and takes it back out, tested on a fork of Solana mainnet with Surfpool. Two rates that weren't the same kind of number, a rate refused for being a minute old, and why switching lenders took 103 days to pay back.

Nissan Dookeran10 min readSolanaCoding AgentsAgent Workflows

Picture two savings counters on the same street. Each has a board outside with today's interest rate, and the boards keep changing. You read both and hand your dollars to the one showing more. They give you a receipt. It stays in your pocket, and it's what gets your money back.

On Solana the dollars are USDC, a token worth one US dollar. The counters are two lending programs, Kamino and Jupiter Lend. The receipt is the lender's own token, which sits in your wallet.

I wanted my dollars to earn the better of the two rates without me checking two apps. So for Deed #7 we built a tool that reads both rates, deposits with the higher one, shows the position and takes it all back out. A fifth command says whether moving to the other lender would pay for itself. Deed #6 was an API that charged a tenth of a cent a call. This one is about where idle dollars sit.

It runs on a copy of Solana mainnet on my laptop, with a test wallet, so no real money is involved. The demo is about five minutes.

Were the two rates even the same kind of number?

No, and the first version didn't notice.

Kamino's number came from its SDK's APY: the supply rate compounded every slot, as if the interest were reinvested all year. Jupiter Lend's API gives a simple yearly rate. So Kamino looked better than it was.

Claude measured it before changing anything. On a fork with a million USDC at each lender and the clock moved forward 86,401 seconds, Kamino showed 4.133%. Its deposit earned at 4.0015% a year. Kamino's simple rate, supply APR plus rewards APR, was 4.0011%, within 0.0004 points of what was earned. The APY was 3% too high.

Now both are APR. Kamino's is its supply APR plus the rewards APR it is paying now. Jupiter's is supplyRate plus rewardsRate from its API, checked against the API's own total. A test on the fork deposits at each lender, moves the clock a day and checks what the deposit earned against the rate.

Kamino matches. Jupiter Lend doesn't quite. In every run its deposit earned about 1.4% less than its published rate: 4.3467% against 4.41% in one. That's 0.06 points, and we haven't found why. The fork's clock moved the full day, and Jupiter's own read library computes the same supply rate from mainnet's state as the API gives. How Jupiter splits interest between depositors, and how its rewards pay out over time, weren't checked.

The gap between the lenders was about 0.4 points on the day, so it didn't change which one won. In a close call it could. The test allows Jupiter two parts in a hundred and Kamino one. I approved that after seeing the numbers.

Why refuse a rate that's a minute old?

A photo of the board from a minute ago isn't the board.

If either rate can't be read, or was read more than 60 seconds ago, the router refuses, names the lender and sends nothing. One rate known and one unknown is refused as well. The known one doesn't win by default.

In the recorded run, handed the same rates 61 seconds later, it said:

Refused (RATE_STALE): Kamino's rate is stale: read 62s ago, the limit is 60s

This matters more on a page than in a terminal, because a page leaves rates sitting on screen. I asked for a page because clicking is a better way to learn this than typing. Its server keeps the last twenty readings by id, and a deposit names the reading the page showed. That's what makes "stale" real in a browser, and the page can't supply rates of its own.

How do you test against real lenders without real money?

The lenders' real markets are on Solana mainnet, where the money is real. I'm not practising with real money, and the agent that built this isn't allowed a mainnet key. So everything ran on a fork.

A fork is a copy of the network running on your own machine. Surfpool, the fork used here, starts nearly empty. The first time anything asks for an account, it fetches that account from mainnet and keeps a copy. So the lenders' real programs run on it, against real state, and every transaction goes to the copy.

A fork also takes cheatcodes, commands a real network would never accept. One writes a token balance straight into an account, so the test wallet starts with 100 USDC that nobody sent. Another moves the clock. Surfpool calls that time travel, and it only goes forward. Interest takes time and a test can't wait a day, so the tests jump a day and the lenders work out a day's interest as if it had passed.

Some answers need a transaction you don't want to send. What is a Jupiter position worth right now? The router builds the full withdrawal and asks the fork to simulate it. It says what would come back, and nothing changes. The first version used the API's conversion rate instead, which describes mainnet. On a fork a day ahead, that undervalued a fresh 100 USDC deposit by 12,125 base units, about 1.2 cents.

And before anything signs, the code asks one question only Surfpool answers, and checks the RPC is on this machine. The genesis hash can't do that job: a fork reports mainnet's. A real network can't say yes, so the code won't sign there.

What happens between a click and the lender?

The path from a click to the lender's program: the page and the commands both ask the router, which compares, deposits and withdraws. The router reads Jupiter Lend's rate from Jupiter's API and Kamino's from the Kamino program. It sends one transaction, checked to use only the wallet's own accounts, to the Surfpool fork, where the Kamino program and the Jupiter program both run.

The page or the commands ask the router. It reads Kamino's rate from the chain through Kamino's SDK, and Jupiter's from Jupiter's API. It builds one transaction for the lender that reads higher, and the fork runs it against the real program.

Kamino's deposit is built locally. Jupiter's arrives from its API as ready-made instructions for the wallet to sign. The first version signed them as they arrived. Now each is checked against what was asked for before anything signs: one instruction, Jupiter's lending program, deposit or redeem, the amount, the wallet as the only signer and the wallet's own token accounts. To test that, Claude wrapped Jupiter's real API so its answers sent the tokens to another wallet. Deposit and withdrawal both refused, with nothing signed.

One run, recorded on 24 November: Kamino 4.047% APR, Jupiter Lend 4.410% (4.160% supply plus 0.250% rewards). Jupiter was higher, so 100 USDC went there. The fork's clock moved a day, and the withdrawal brought back 100.012111 USDC. Those signatures only ever existed on that fork. No explorer will find them.

When is switching lenders worth it?

This is the part I tripped over while recording the video, so first, who "you" are here: the saver using this tool, not a trader. It only checks whether a move would pay for itself. That's arithmetic on today's rates, and it isn't financial advice.

recommend reads both rates and has the RPC price the two transactions a move needs. It adds rent if the wallet has no token account at the other lender yet, and converts SOL to dollars with the oracle price Kamino already loads. It signs nothing.

With 100 USDC at Kamino on 24 November, Jupiter Lend paid 0.373 points more: $0.001021 a day. Moving would have cost $0.1056. Network fees were $0.000705 of that, and $0.1049 was rent, a deposit Solana holds for each new account. That's 103 days to earn it back, against a 30-day horizon, so the advice was stay. On a million USDC the same move pays for itself in under a day.

Rent comes back when an account is closed. This tool never closes one, so it counts rent as a cost. For a small holder, the first move to a lender is the expensive one.

What broke?

Every test passed, and then the first real command failed. deposit 100, typed twelve seconds after the fork started, died inside Jupiter's program with LIBRARY_MATH_ERROR.

Surfpool's default clock only moves when a transaction lands. The accounts it fetched from mainnet kept arriving newer than that clock. So the lender saw its own last update in the future, and its interest arithmetic got a negative elapsed time. That last step is our inference; we didn't read the program's source. The tests had only ever deposited in the fork's first second, so none of them could see it.

The fix started as a failing test, a deposit made twenty seconds after the fork starts. Then the fork's clock was set to run in real time, a minute ahead.

The page had a quieter one. Its first build re-read both rates every second, because a default argument made a new clock function on every render. Nothing looked wrong. It showed up as read times six seconds apart in one screenshot, which a single read couldn't produce, and as Jupiter's rate limit used up by the time the keyboard run reached Withdraw. The test written afterwards fails with the fault put back.

Who did what?

Claude built it, and I directed. I asked for the page, and for it to use Vercel's UI SDK. Claude took that to mean the AI SDK's UI package, marked it as a guess and asked. I meant ui-sdk.dev, a beta library of interface behaviours. The page is built with it, and every control works from the keyboard.

I narrated all 14 scenes of the video myself. A synthetic voice read the drafts so I could hear each line first; it isn't in the video. The page in the video was captured from my browser tab, driven from the keyboard by the agent.

What's still open

It runs on a fork on my laptop. There's no wallet connection and no path to a real deposit; that would need a real wallet and more review. Two lenders, USDC only. Jupiter's 1.4% shortfall is unexplained. Jupiter's rate is mainnet's, from its API, while Kamino's is the fork's own state. Both lenders round in their own favour, so a withdrawal in the same minute returns a few millionths of a dollar less than went in. Four dependency advisories are open, all under the Kamino SDK. The UI SDK is a beta, pinned exactly.

Nobody but Claude has reviewed the code.

The source is public as a snapshot, with 152 tests that make no network call. pnpm run reproduce needs no key and no account: it starts its own fork of mainnet, gives a wallet 100 USDC, runs the whole thing against the real lenders and prints PASS or FAIL beside nine checks.