Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beets staking module integration [stS token] #35

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
69f8c90
beets-lst: scaffolding
coccoinomane Jan 20, 2025
3f2189b
feat: beets-lst stake function
coccoinomane Jan 20, 2025
9f494be
feat: unstake function
coccoinomane Jan 22, 2025
3e89e2b
test: askBeets script
coccoinomane Jan 22, 2025
9faecd5
feat: askBeets can now send TXs
coccoinomane Jan 22, 2025
938e0ee
test: askBeets can now make multiple tool calls
coccoinomane Jan 22, 2025
4f95224
docs: add askBeets to README
coccoinomane Jan 23, 2025
bdf5a91
chore: rename stS balance getter
coccoinomane Jan 23, 2025
ad51247
feat: enabled fractional staking of S
coccoinomane Jan 23, 2025
a43e668
feat: function getTotalStakedSonic
coccoinomane Jan 23, 2025
d4b9488
feat: function getTotalStakedSonicInProtocol
coccoinomane Jan 23, 2025
068488b
fix: bug in unstake that would unstake less than asked
coccoinomane Jan 23, 2025
475acb5
refactor: actions on top of getters
coccoinomane Jan 23, 2025
61c5437
feat: exchange rates between S and stS
coccoinomane Jan 23, 2025
2b23630
feat: getter to show all pending and unclaimed withdrawals
coccoinomane Jan 23, 2025
f8c3a57
minor: include TX in unstake output
coccoinomane Jan 23, 2025
afaa4e3
feat: withdrawal actions
coccoinomane Jan 23, 2025
afa753c
minor: Implement minimum deposit & unstake limits
coccoinomane Jan 24, 2025
bfcc698
minor: removed 'claim' in favor of 'withdraw'
coccoinomane Jan 24, 2025
b77e20d
Revert "docs: add askBeets to README" (wrong README)
coccoinomane Jan 24, 2025
2fe0c2c
docs: add askBeets to the beets project README
coccoinomane Jan 24, 2025
3fd0e99
feat: Add data analysis capability to askBeets agent
coccoinomane Jan 24, 2025
b9b95b8
feat: getNextWithdrawal action
coccoinomane Jan 24, 2025
d3594a5
docs: fix typo in README
coccoinomane Jan 24, 2025
1ae7453
docs: improve readme
coccoinomane Jan 25, 2025
a902450
docs: README.md improvement
coccoinomane Jan 26, 2025
453af7c
feat: getStakingApr tool
coccoinomane Jan 29, 2025
76b5f13
refac: moved files for new heyanon guidelines
coccoinomane Feb 20, 2025
47a5734
refac: adapted codebase to heyanon sdk v2
coccoinomane Feb 20, 2025
9500563
refac: follow new HeyAnon guidelines
coccoinomane Feb 21, 2025
5504bf9
feat: getBeetsCapabilities tool
coccoinomane Feb 21, 2025
fe9f6bb
Merge branch 'main' into feature/beets-lst
coccoinomane Feb 21, 2025
97449f7
docs: fix internal links in README
coccoinomane Mar 10, 2025
4029d83
docs: add help subsection to "common commands" in README
coccoinomane Mar 10, 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
7 changes: 7 additions & 0 deletions projects/beets-lst/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Variables for running askBeets.ts

# OpenAI API Key
OPENAI_API_KEY=your_openai_api_key_here

# Private key of a test wallet, without the initial 0x
PRIVATE_KEY=your_wallet_private_key_here
6 changes: 6 additions & 0 deletions projects/beets-lst/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.vscode
.env
src/contracts
src/requests
dist
6 changes: 6 additions & 0 deletions projects/beets-lst/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"printWidth": 180
}
105 changes: 105 additions & 0 deletions projects/beets-lst/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Beets LST - Liquid staking on Sonic

Beets LST allows you to access Sonic staking rewards while maintaining full liquidity of your assets. Maximize your DeFi potential: stS tokens are always liquid and composable, allowing you to earn staking rewards while simultaneously participating in lending markets, liquidity pools, and other DeFi opportunities. Your rewards never stop - even while your assets are put to work across the ecosystem.

## What Beets LST can do for you

- **Flexible Staking & Unstaking**: Easily convert between Sonic (S) and staked Sonic (stS) tokens. Unstaking initiates a 14-day cooldown period, after which tokens can be withdrawn.

- **Liquid Staking Tokens**: Receive stS tokens that represent your staked position, which remain fully liquid and can be used across DeFi while earning staking rewards.

- **Safe and decentralized**: Your staked assets are automatically distributed across carefully selected validators, providing enhanced decentralization and risk management.

- **Real-time Exchange Rates**: Track the value of your staked positions with accurate exchange rates between S and stS tokens, which reflect your accrued staking rewards.

- **Streamlined Withdrawals**: Manage multiple withdrawal requests efficiently, with the ability to track pending withdrawals and withdraw all available tokens in a single transaction once the cooldown period completes.

## Supported Networks

- SONIC

## Common Tasks

1. **Staking**
- Stake 100 S in @beets-lst
- Stake half of my Sonic in @beets-lst
- How much do I have staked in @beets-lst?
- Show my position in @beets-lst
1. **Unstaking**
- Unstake 100 stS from @beets-lst
- Unstake half of my stS from @beets-lst
- Unstake all from @beets-lst
1. **Withdrawing**
- Withdraw all from @beets-lst
- Withdraw <withdraw_id> from @beets-lst
- How long before I can withdraw from @beets-lst?
- Show my pending withdrawals on @beets-lst
1. **Info and alerts**
- What is the APR of staking Sonic on @beets-lst?
- Alert me when my withdrawal is ready @beets-lst
- How much Sonic does @beets-lst hold?
- How much is worth my staked Sonic on @beets-lst?
1. **Help**
- What can I do on @beets-lst?

## Available Functions

- [stake](src/functions/stake.ts)
- [unStake](src/functions/unStake.ts)
- [withdraw](src/functions/withdraw.ts)
- [withdrawAll](src/functions/withdrawAll.ts)
- [getSonicBalance](src/functions/getSonicBalance.ts)
- [getStakedSonicBalance](src/functions/getStakedSonicBalance.ts)
- [getOpenWithdrawRequests](src/functions/getOpenWithdrawRequests.ts)
- [getProtocolSonicToStakedSonicExchangeRate](src/functions/getProtocolSonicToStakedSonicExchangeRate.ts)
- [getProtocolStakedSonicToSonicExchangeRate](src/functions/getProtocolStakedSonicToSonicExchangeRate.ts)
- [getTotalSonicInProtocol](src/functions/getTotalSonicInProtocol.ts)
- [getTotalStakedSonicInProtocol](src/functions/getTotalStakedSonicInProtocol.ts)

## Installation

```bash
pnpm add @heyanon/beets-lst
```

## Contracts and transactions

- Liquid staking proxy contract: https://sonicscan.org/address/0xe5da20f15420ad15de0fa650600afc998bbe3955
- Liquid staking implementation contract: https://sonicscan.org/address/0xd5f7fc8ba92756a34693baa386edcc8dd5b3f141
- Liquid staking helper contract: https://sonicscan.org/address/0x52b16e3d7d25ba64f242e59f9a74799ecc432d78
- Stake Sonic TX (`deposit`): https://sonicscan.org/tx/0x19545670b77c9ab7e1eabdab292c1aa9d0abd6e11777ab3147f343cb900c728b
- Initiate unstake TX (`undelegateMany`): https://sonicscan.org/tx/0xb64c4fd6ae4667a3b7ce9d6ba9679fbd2c591173a0895a5616adc3b039b10c27
- Withdraw Sonic TX (`withdraw`): https://sonicscan.org/tx/0xb93b07384ccbace4236d07fac46874039821c84707f69fbee101e9ae5506f470

## Test with the askBeets agent

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

```bash
cd projects/beets-lst
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 "What can I do on Beets LST?"
pnpm ask "Stake 100 S in @beets-lst"
pnpm ask "Unstake all of my stS from @beets-lst"
pnpm ask "How long before I can withdraw from @beets-lst?"
```

To debug the actual LLM responses, run `askBeets` with `--verbose` flag:

```bash
pnpm ask "Stake 100 S in @beets-lst" --verbose
```

## Future improvements

- Warn the user if swapping is more convenient than unstaking and staking.
- Getter to show the dollar value of the user position.
- Getter to show the user's position: Sonic Balance, stS balance, staking APR, pending withdrawals, dollar value.
49 changes: 49 additions & 0 deletions projects/beets-lst/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@projects/beets-lst",
"version": "1.0.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/index.mjs",
"files": [
"dist"
],
"engines": {
"node": ">=18.x"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"start": "tsup --watch",
"build": "tsup",
"test": "vitest --run",
"lint": "tsdx lint",
"prepare": "pnpm run build",
"size": "size-limit",
"analyze": "size-limit --why",
"format": "prettier --write \"*/**/*.ts\"",
"ask": "tsup src/ask_beets/run.ts && node dist/run.js"
},
"dependencies": {
"@balancer/sdk": "^2.1.3",
"@heyanon/sdk": "^2.0.2",
"axios": "^1.7.9",
"chalk": "4",
"viem": "2.22.9",
"vitest": "^2.1.8"
},
"devDependencies": {
"@size-limit/preset-small-lib": "^9.0.0",
"@types/big.js": "^6.2.0",
"@types/jest": "^29.5.12",
"@types/node": "^22.13.4",
"dotenv": "^16.4.7",
"openai": "^4.80.0",
"prettier": "^3.4.2",
"tsdx": "^0.14.1",
"tslib": "^2.6.2",
"tsup": "^7.2.0",
"typescript": "^5.7.3"
}
}
Loading