Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9e7c7cf
feat: skeleton for Convex Finance integration
coccoinomane Oct 13, 2025
e34d0bf
feat: implemented Convex Curve client
coccoinomane Oct 13, 2025
364529a
feat: tool findLpInfo
coccoinomane Oct 13, 2025
f8b73d8
ux: enrich info on Convex LP tokens
coccoinomane Oct 15, 2025
da4fdaa
refac: rename tool to findConvexLpInfo
coccoinomane Oct 15, 2025
9aed428
feat: findConvexLvInfo tool
coccoinomane Oct 15, 2025
2a40a61
ux: improved performance of USD values retrieval
coccoinomane Oct 17, 2025
7027cf4
feat: tool getMyPositionsPortfolio
coccoinomane Oct 17, 2025
f583a59
ux: introduced multicall batches to avoid gas limits
coccoinomane Oct 17, 2025
491be6e
feat: compute actual on-chain APR
coccoinomane Oct 17, 2025
5eeabbf
feat: now including also CVX apy
coccoinomane Oct 18, 2025
b66edc7
ux: add APR breakdown to lp info tool
coccoinomane Oct 18, 2025
bfdd220
refac: made enrichConvexToken work for both lps and vaults
coccoinomane Oct 20, 2025
9f830bf
refac: memoized token helper + include base APR for lending
coccoinomane Oct 20, 2025
c8e4335
ux: unified lps and vaults format functions
coccoinomane Oct 20, 2025
7f55b05
ux: improved portfolio output
coccoinomane Oct 20, 2025
945e22b
ux: limit output of portfolio tool to save tokens
coccoinomane Oct 20, 2025
e82dedb
tool: new flags for agent: --debug-viem and --rpc
coccoinomane Oct 20, 2025
31b0b0f
fix: add missing logging helper
coccoinomane Oct 20, 2025
282bd20
feat: tool getBestYieldForToken
coccoinomane Oct 20, 2025
8784670
ux: apy calculation
coccoinomane Oct 22, 2025
c3a312e
ux: reduced min tvl
coccoinomane Oct 22, 2025
e924871
ux: change names to find & yield tools
coccoinomane Oct 22, 2025
e9c8168
remove: dropped support for Arbitrum and Polygon
coccoinomane Oct 22, 2025
33c88fa
feat: deposit tools
coccoinomane Oct 22, 2025
9923f1b
feat: surface opportunities to deposit owned Curve tokens in Convex
coccoinomane Oct 23, 2025
724faca
ux: some minor ux improvements
coccoinomane Oct 23, 2025
4fd7e19
fix: avoid the assistant to pick the first pool to deposit into
coccoinomane Oct 23, 2025
eddbeca
feat: tool withdraw
coccoinomane Oct 24, 2025
7316638
feat: unstaked tokens support in withdraw function
coccoinomane Oct 24, 2025
85a4151
ux: improved llm understanding on Curve vs Convex tokens
coccoinomane Oct 24, 2025
8d6d151
refac: created booster.ts and poolAndVaults.ts helpers
coccoinomane Oct 24, 2025
f253a26
docs: add docstrings to tools
coccoinomane Oct 25, 2025
ed50a0c
refac: new getConvexTokenToolHelper.ts helper
coccoinomane Oct 25, 2025
81b9ad0
ux: improved pool & vault match by name
coccoinomane Oct 25, 2025
18cc0ce
refac: rewards helper to fetch claimable rewards from the blockchain
coccoinomane Oct 26, 2025
17fda2e
feat: show claimable rewards in portfolio & find tools
coccoinomane Oct 26, 2025
a3d9fc1
feat: claim rewards tool
coccoinomane Oct 26, 2025
59d94f0
feat: get APR from extra reward tokens
coccoinomane Oct 27, 2025
83e8f86
ux: include gauge-killed pools in results
coccoinomane Oct 27, 2025
049409a
ux: harmonize showing claimable rewards across tools
coccoinomane Oct 27, 2025
cf46974
refac: introduced formatting function for claimable rewards
coccoinomane Oct 27, 2025
060e2c3
fix: bug whereby only one pool match was returned
coccoinomane Oct 27, 2025
1aa8e8f
ux: optimized speed of reward fetching
coccoinomane Oct 27, 2025
d740fca
ux: add Curve deposit info to getPool and getVault output
coccoinomane Oct 29, 2025
33095c8
ux: add Curve deposit info to deposit tools
coccoinomane Oct 29, 2025
8d2b975
docs: improved README + specified cvxCRV staking is not supported
coccoinomane Oct 29, 2025
ad220b1
ux: made a Curve/Convex message less ambiguous
coccoinomane Oct 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions projects/convex/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Variables for running ask-convex (that is, agent.ts)

# OpenAI API Key
OPENAI_API_KEY=your_openai_api_key_here

# DeepSeek API Key. If set, will be used instead of OpenAI.
DEEPSEEK_API_KEY=your_deepseek_api_key_here

# Private key of a test wallet, without the initial 0x
PRIVATE_KEY=your_wallet_private_key_here
5 changes: 5 additions & 0 deletions projects/convex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.vscode
.env
dist
ignore
6 changes: 6 additions & 0 deletions projects/convex/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"printWidth": 180
}
136 changes: 136 additions & 0 deletions projects/convex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Convex Finance Yield Maximization

Convex Finance allows you to maximize yield from [Curve Finance](https://curve.fi/), [Frax Finance](https://frax.com/) and other Decentralized Finance platforms. More information on Convex Finance can be found on their own academy page: https://www.convexfinance.com/academy

## Worth noting

- This integration only supports Curve Finance on Ethereum, which as of Oct 2025 represents more than 90% of Convex total TVL.

- Convex has a very limited APYs, which I implemented in [./src/client.ts](./src/client.ts). Most of the data fetching operations performed by this integration are done directly on the blockchain. In particular, the portfolio & opportunities tools perform many about 30-40 RPC multicalls each: make sure to use a good RPC provider to avoid rate limiting errors.

- Computing accurate APYs was tricky, for more details see:
- https://discord.com/channels/820795644494610432/864157305566527508/1428627572274630727
- https://docs.convexfinance.com/convexfinanceintegration/cvx-minting
- https://etherscan.io/address/0x5Fba69a794F395184b5760DAf1134028608e5Cd1#readContract
- https://discord.com/channels/820795644494610432/864157305566527508/880860136523059210

## Examples of commands

### Portfolio dashboard

- Show all my positions on Ethereum on Convex
- Show my LP positions on Ethereum on Convex
- Do I have any Curve positions I can deposit on Convex?
- My total TVL on Ethereum on Convex
- Value of my CRV+cvxCRV position on Ethereum on Convex?
- Value of my WETH lending vault on Ethereum on Convex?

Please note that the portfolio tool will also surface Curve LP tokens that are not yet deposited on Convex, and suggest to deposit them.

### Yield opportunities

- Best yields for WETH on Convex on Ethereum?
- Show me lending opportunities for BTC on Convex on Ethereum
- Convex pools with USDe on Ethereum
- APY of the Convex FRAX+USDe pool on Ethereum on Convex
- Am I better off lending my WETH or LPing it on Convex on Ethereum?

### Deposit Curve tokens into Convex

- Deposit all of my USDC-USDT liquidity on Convex on Ethereum
- Deposit 50% of my ETH-stETH liquidity on Convex on Ethereum
- Deposit 0.1 LP tokens in Convex pool crv+cvxCRV on Ethereum
- Deposit \$100 worth of CRV+cvxCRV on Convex on Ethereum
- Deposit my Curve sreUSD lending position on Convex

Please note that the tool will deposit & stake the tokens in one transaction.

### Withdraw Curve tokens from Convex

- Withdraw all of my liquidity from ETH-stETH Convex pool on Ethereum
- Withdraw half of my liquidity from ETH-stETH Convex pool on Ethereum
- Withdraw my sreUSD lending position from Convex
- Withdraw only my unstaked tokens from ETH-stETH Convex pool on Ethereum

Please note that:

- The tool will unstake & withdraw the tokens in one transaction.
- Any existing rewards will be claimed too.
- By default, the percentage refers to the staked amount of tokens. However, if the tool detects unstaked tokens as well, it will ask the user if they want to withdraw them too.

## Claim rewards

- Show my claimable rewards on Convex on Ethereum
- Claim all rewards on Convex on Ethereum
- Claim rewards from pool CRV+cvxCRV on Convex on Ethereum

### CRV and CVX staking

- NOT IMPLEMENTED: How much CRV I have staked on Convex?
- NOT IMPLEMENTED: Value of my locked CVX position on Convex
- NOT IMPLEMENTED: Convert and stake my CRV on Convex
- NOT IMPLEMENTED: Stake and lock 100 CVX on Convex
- NOT IMPLEMENTED: Give me APY of Convex CRV staking on Ethereum

Please note that when (and if) we will implement CRV to cvxCRV conversion, we should be mindful that, as of Oct 2025, cvxCRV is heavily depegged from CRV, see [here](https://www.defiwars.xyz/projects/convex) and [here](https://d.pr/i/gFtnBU).

## Convex protocol KB

- The main features supported by Convex Finance are:
- [Stake your Curve positions](https://curve.convexfinance.com/stake), be it a liquidity position or a Lending Vault crvUSD token, to earn max-boosted rewards
- [Convert your CRV tokens](https://curve.convexfinance.com/stake) to cvxCRV, a liquid token that, once staked, accrues Curve platform revenue without the need to lock your CRV
- [Stake your CVX tokens](https://curve.convexfinance.com/stake#stake-cvx) to earn a share of Convex platform revenue
- [Lock your CVX tokens](https://www.convexfinance.com/lock-cvx) to earn a share of of Convex platform revenue and to gain voting weights, which can earn you incentives via [Votium app](https://votium.app/).
- A Convex LP token is a deposit/receipt token that the user receives in exchange for depositing Curve liquidity on Convex
- After obtaining a Convex LP token, it can then be further staked on Convex to earn boosted CRV and (sometimes) CVX rewards; this
is the whole point of it.
- One can also deposit & stake Curve lending positions (a.k.a. Llamalend lending vaults). Again, after depositing the Curve lending vault token one obtains from Convex a receipt token.
- In summary:
- you deposit Curve LP tokens to obtain Convex LP tokens
- you deposit Curve/Llamalend lending vault tokens to obtain Convex LV tokens
- you stake Convex LP or LV tokens to earn boosted CRV and (sometimes) CVX rewards
- At the smart contract level, Convex does not make a difference between LP and lending vault tokens. They are just positions that can earn rewards. Both belong to the same entity and are indexed by the same sequential pool ID (\_pid); see [Convex (very terse) docs](https://docs.convexfinance.com/convexfinanceintegration/booster) for more details.
- To obtain a lending position suitable for being deposited on Curve, the user has to deposit their crvUSD tokens in a Llamalend vault (e.g. https://www.curve.finance/lend/ethereum/markets/one-way-market-12/vault/deposit).
- Each Llamalend vault has a specific collateral (e.g. WETH) hence Convex LV tokens shown on Convex UI always contain a token name (screenshot > https://d.pr/i/DpYS2p)

## Test with the local agent

I've built a simple agent called `ask-convex` to test the integration. To run it, you need to configure .env:

```bash
cd projects/convex
pnpm install
cp .env.example .env
# insert test wallet private key into .env
# insert OpenAI or DeepSeek key into .env
```

and then you can ask questions directly:

```bash
pnpm ask-convex "What can I do on Convex?"
pnpm ask-convex "Stake my USDC-USDT liquidity on Curve LP on Convex"
```

Options:

- `--debug-llm`: Show the actual LLM responses
- `--debug-tools`: Show the output of every tool call
- `--debug-viem`: Show the output of every blockchain call
- `--rpc <url>`: Custom RPC URL to use for blockchain interactions

## Useful links

- [Curve Staking page](https://curve.convexfinance.com/stake)
- [Curve Claim page](https://curve.convexfinance.com/claim)
- [Lock CVX page](https://www.convexfinance.com/lock-cvx)
- [Votium app for bribes/incentives](https://votium.app/)

## Transactions

- [Deposit and stake LP](https://etherscan.io/tx/0x6daf22d6cae0029d483f87619a0a75777162a7dc15a01f38d41960f748aa213a)
- [Unstake and withdraw LP](https://etherscan.io/tx/0xc17f5a231c1afc73407576364bdc14281c87843ddb0f379b52f5b607facf1027)
- [Claim all rewards](https://etherscan.io/tx/0x976883b4e27d5646774ece1978668d7a94788751c8df5d3dcfe6c97d4753ece6)
- [Stake CVX](https://etherscan.io/tx/0x75b94bb910aa80eb4e74f05835e8eb1b66ab806cc1519cf61ac12e2a2ae31ab3)
- [Lock CVX](https://etherscan.io/tx/0xabb682980876276e4ebf9a60a15b4c19d96467b1d5e1a6903ebbc221f33740fa)
- [Stake crvUSD Lending Vault token](https://etherscan.io/tx/0xbc6d38aedf85ca04aeaf77929d1757ff9c28ee2ffec89e879b9fa68fd5e7b807)
15 changes: 15 additions & 0 deletions projects/convex/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Bug fixes

- APY from endpoint (https://d.pr/i/kcIny1) are slightly higher than APY on frontend (https://d.pr/i/i0LrWY). Maybe [copy formula from Google Sheet](https://discord.com/channels/820795644494610432/864157305566527508/880860136523059210)?

## Features

## Minor

## Future

- Optionally have the claimRewards tool to lock CVX (see ClaimZap.sol)
- Should we allow the user to stake already deposited tokens? E.g. by adding a "stakeUnstakedTokens" parameter to deposit tools?
- The assistant always sets minTvl to zero in portfolio tool, should we enforce the minimum value?
- Implement cvxCRV staking, CVX staking, CVX locking
- Implement CRV -> cvxCRV conversion, taking care of cvxCRV depegging (see [here](https://www.defiwars.xyz/projects/convex) and [here](https://d.pr/i/gFtnBU))
Loading