@ring-protocol/ringearnsdk
v0.0.10
Published
EarnSDK — unified DeFi yield aggregation for Ethereum and Solana
Readme
@ring-protocol/ringearnsdk
Unified DeFi yield aggregation SDK for Ethereum and Solana.
Install
npm install @ring-protocol/ringearnsdk viem wagmiviem and wagmi are peer dependencies.
Quick Start
import { RingEarn } from '@ring-protocol/ringearnsdk'
import { mainnet } from 'viem/chains'
import { createPublicClient, http } from 'viem'
const ring = new RingEarn({
chain: mainnet,
publicClient: createPublicClient({
chain: mainnet,
transport: http(),
}),
})
// Query all positions across protocols
const positions = await ring.getPositions('0x...')
// Get total yield summary
const summary = await ring.getTotalYield('0x...')
// Stake ETH via Lido
const lido = await ring.lido()
await lido.stakeEth({
amount: 1000000000000000000n, // 1 ETH
account: '0x...',
})
// Simulate yield for 30 days
const sim = await ring.simulate('lido-steth', 1000000000000000000n, 30)React Hooks
npm install @ring-protocol/ringearnsdk/reactimport { useYield, useStake } from '@ring-protocol/ringearnsdk/react'
function YieldCard({ config, address }) {
const { data, isLoading, refetch } = useYield(config, address)
if (isLoading) return <div>Loading...</div>
return (
<div>
<p>Total Balance: ${data?.totalBalanceUsd}</p>
<p>Weighted APY: {data?.weightedApy}%</p>
<button onClick={refetch}>Refresh</button>
</div>
)
}Vue Composables
npm install @ring-protocol/ringearnsdk/vue<script setup>
import { useYield } from '@ring-protocol/ringearnsdk/vue'
const { data, isLoading, refetch } = useYield(config, address)
</script>
<template>
<div v-if="isLoading">Loading...</div>
<div v-else>
<p>Total Balance: ${{ data?.totalBalanceUsd }}</p>
<p>Weighted APY: {{ data?.weightedApy }}%</p>
<button @click="refetch">Refresh</button>
</div>
</template>API
new RingEarn(config)
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| chain | Chain | Yes | Viem chain object |
| publicClient | PublicClient | Yes | Viem public client |
| walletClient | WalletClient | No | Viem wallet client (for transactions) |
| rpcUrl | string | No | Custom RPC URL |
| cacheSize | number | No | Max cache entries (default: 100) |
| cacheTtlMs | number | No | Cache TTL in ms (default: 30000) |
Core Methods
ring.getPositions(address)— Query all positions across protocolsring.getTotalYield(address)— Get aggregated yield summaryring.simulate(strategyId, amount, days)— Simulate yield projectionring.compareStrategies(strategyIds, amount, days)— Compare multiple strategiesring.batch(operations)— Execute multiple operations in a single transactionring.clearCache()— Clear the in-memory cache
Adapters
Adapters are lazy-loaded on first access.
await ring.lido()— Lido staking adapterstakeEth({ amount, account, referral? })unstakeStEth({ amount, account })getStEthBalance(address)getRewards(address)
await ring.morpho()— Morpho vault adaptersupply({ vault, assets, account })withdraw({ vault, assets, account })getPosition(address, vault)getVaultApy(vault)
Release Workflow
This project uses Changesets for version management.
1. Create a changeset
After making changes, run:
pnpm changesetSelect the packages to bump and describe the changes.
2. Version packages
When ready to release, run:
pnpm versionThis will:
- Bump versions in
package.json - Update
CHANGELOG.md - Remove consumed changeset files
3. Publish
pnpm releaseThis runs pnpm build && changeset publish, which builds the project and then calls npm publish to publish to the npm registry.
Note on 2FA / OTP If your npm account has two-factor authentication enabled for publishing,
pnpm releasewill fail with anEOTPerror because Changesets cannot prompt for an OTP interactively.In that case, get the 6-digit OTP code from your authenticator app and run:
pnpm build && pnpm changeset publish --otp=<your-otp-code>
Full release flow
# 1. Make changes, commit them
# 2. Create changeset
pnpm changeset
# 3. Commit the changeset
git add .changeset/*.md && git commit -m "chore: add changeset"
# 4. When ready to release
pnpm version
git add . && git commit -m "chore: version packages"
# 5. Publish
pnpm release
# 6. Push tags
git push --follow-tagsLicense
MIT
