@varla/sdk 1.11.1 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +74 -0
- package/FRONTEND.md +138 -0
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -19,3 +19,77 @@ Published package: **@varla/sdk**
|
|
|
19
19
|
- Actions: `@varla/sdk/actions`
|
|
20
20
|
- Events/indexer: `@varla/sdk/events`
|
|
21
21
|
- Utilities: `@varla/sdk/batch`, `@varla/sdk/format`
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Frontend-oriented view helpers (quick map)
|
|
26
|
+
|
|
27
|
+
> Tip: prefer **subpath imports** so it’s obvious what you’re using:
|
|
28
|
+
>
|
|
29
|
+
> ```ts
|
|
30
|
+
> import * as views from "@varla/sdk/views";
|
|
31
|
+
> import * as actions from "@varla/sdk/actions";
|
|
32
|
+
> ```
|
|
33
|
+
|
|
34
|
+
### Lend page (pool / lenders)
|
|
35
|
+
|
|
36
|
+
- **User supplied amount (current value)** + shares + withdrawable
|
|
37
|
+
- `views.readLenderSnapshot({ pool, user })` →
|
|
38
|
+
`{ shares, assets, maxWithdrawAssets, maxRedeemShares }`
|
|
39
|
+
- Notes:
|
|
40
|
+
- `assets` is the **current underlying value** of the user’s ERC4626 shares (principal + interest).
|
|
41
|
+
- `maxWithdrawAssets` is the **available-to-withdraw right now** (liquidity + reserve aware).
|
|
42
|
+
|
|
43
|
+
- **Available-to-withdraw only**
|
|
44
|
+
- `views.readMaxWithdraw({ pool, user })` → `{ maxWithdrawAssets }`
|
|
45
|
+
|
|
46
|
+
- **Pool share price (assets per share)**
|
|
47
|
+
- `views.readPoolSharePrice({ pool })` → `{ assetsPerShareWad }`
|
|
48
|
+
|
|
49
|
+
- **Pool utilization + rates**
|
|
50
|
+
- `views.readPoolSnapshot({ pool })` or `views.readPoolRates({ pool })`
|
|
51
|
+
|
|
52
|
+
- **Pool safety score**
|
|
53
|
+
- `views.readPoolHealthScore({ pool })` →
|
|
54
|
+
- `{ kind: "no-liquidity" }` when the pool has 0 assets (prevents showing a misleading 100)
|
|
55
|
+
- `{ kind: "ok", utilizationWad, scoreBps }` otherwise
|
|
56
|
+
|
|
57
|
+
### Borrow page (core / borrower risk)
|
|
58
|
+
|
|
59
|
+
- **Account overview (portfolio, debt, HF, max borrow)**
|
|
60
|
+
- `views.readAccountSnapshot({ core, user })`
|
|
61
|
+
- or `views.readBorrowLimits({ core, user })` when you only need limits + HF
|
|
62
|
+
|
|
63
|
+
- **Max LTV vs tier naming (avoid ambiguity)**
|
|
64
|
+
- `views.readTieredLtvConfig({ core })` → `{ tier0, tier1, tier2 }` (maps 1:1 to CONSERVATIVE/MODERATE/RISK)
|
|
65
|
+
- For an actual position, prefer effective LTV:
|
|
66
|
+
- `views.readLtvForPosition({ core, positionId })` → `{ ltvWad }`
|
|
67
|
+
|
|
68
|
+
- **Liquidation threshold / params**
|
|
69
|
+
- `views.readHealthFactor({ core, user })` → `{ healthFactor, canBeLiquidated }`
|
|
70
|
+
- `views.readLiquidationConfig({ core })` and `views.readTierLiquidationConfig({ core, tier })`
|
|
71
|
+
|
|
72
|
+
### Home page / “Top opportunities” (suggested inputs)
|
|
73
|
+
|
|
74
|
+
The SDK can provide raw primitives; **ranking is app-side**:
|
|
75
|
+
- `views.readPoolRates({ pool })` (supplyAPY, utilization)
|
|
76
|
+
- `views.readPoolCaps({ pool })` (capacity constraints)
|
|
77
|
+
- `views.readPoolHealthScore({ pool })` (simple risk signal)
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Not provided by the SDK (by design)
|
|
82
|
+
|
|
83
|
+
- **“Interest accrued / lender earnings” for a user**
|
|
84
|
+
- ERC4626 does not track principal per-user.
|
|
85
|
+
- To show “interest accrued”, you need a cost basis, e.g.:
|
|
86
|
+
- app-side tracking of deposits/withdrawals, or
|
|
87
|
+
- an indexer that reconstructs deposits/withdrawals from events.
|
|
88
|
+
|
|
89
|
+
- **Borrow “net rate”**
|
|
90
|
+
- `borrowRate` and pool `supplyAPY` are available, but “net” is product-specific
|
|
91
|
+
(depends on whether you consider collateral yield, whether user is also a lender, etc.).
|
|
92
|
+
|
|
93
|
+
- **Cooldown period**
|
|
94
|
+
- As of `contracts/VarlaPool.sol` in this repo, there is **no cooldown / withdraw delay** view.
|
|
95
|
+
- If a cooldown is introduced later, we can add `views.readPoolConfig({ pool })`.
|
package/FRONTEND.md
CHANGED
|
@@ -98,6 +98,144 @@ const snap = await views.readAccountSnapshot({
|
|
|
98
98
|
|
|
99
99
|
---
|
|
100
100
|
|
|
101
|
+
## 3.1) Lend page cookbook (pool / lenders)
|
|
102
|
+
|
|
103
|
+
> Recommended imports:
|
|
104
|
+
>
|
|
105
|
+
> ```ts
|
|
106
|
+
> import * as views from "@varla/sdk/views";
|
|
107
|
+
> ```
|
|
108
|
+
|
|
109
|
+
### User supplied amount (current value)
|
|
110
|
+
|
|
111
|
+
Use `readLenderSnapshot`:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const lender = await views.readLenderSnapshot({ pool: c.pool, user: userAddress });
|
|
115
|
+
|
|
116
|
+
// lender.assets is the current underlying value of the user’s ERC4626 shares
|
|
117
|
+
// (principal + interest), *not* a tracked principal amount.
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Return shape:
|
|
121
|
+
- `shares`: ERC4626 vault share balance
|
|
122
|
+
- `assets`: `convertToAssets(shares)` (current redeemable underlying)
|
|
123
|
+
|
|
124
|
+
### Available to withdraw (overview chart)
|
|
125
|
+
|
|
126
|
+
If you only need withdrawable amount:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
const { maxWithdrawAssets } = await views.readMaxWithdraw({ pool: c.pool, user: userAddress });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Or use `readLenderSnapshot` and read `maxWithdrawAssets`.
|
|
133
|
+
|
|
134
|
+
### Pool share price (charting)
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
const { assetsPerShareWad } = await views.readPoolSharePrice({ pool: c.pool });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Pool rates + utilization
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const poolRates = await views.readPoolRates({ pool: c.pool });
|
|
144
|
+
// { utilization, borrowRate, supplyAPY, availableLiquidity, maxBorrow }
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Lender earnings / “interest accrued”
|
|
148
|
+
|
|
149
|
+
The SDK does **not** currently provide `readLenderEarnings(pool, user)`.
|
|
150
|
+
|
|
151
|
+
Reason: ERC4626 does not store a per-user principal (cost basis), so “interest accrued”
|
|
152
|
+
cannot be derived purely from the vault without historical data.
|
|
153
|
+
|
|
154
|
+
Recommended approach:
|
|
155
|
+
- Track deposits/withdrawals in your app (or an indexer) to build a cost basis.
|
|
156
|
+
- Compute earnings as (example):
|
|
157
|
+
- `earnings = currentAssets - (sumDeposits - sumWithdrawals)`
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 3.2) Borrow page cookbook (core / borrower risk)
|
|
162
|
+
|
|
163
|
+
### Account overview
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
const snap = await views.readAccountSnapshot({ core: c.core, user: userAddress });
|
|
167
|
+
// { portfolioValue, collateralValue, debt, healthFactor, maxBorrow }
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Max LTV clarification (defaults vs effective)
|
|
171
|
+
|
|
172
|
+
The protocol exposes **default LTV per risk tier**:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const tiers = await views.readTieredLtvConfig({ core: c.core });
|
|
176
|
+
// { tier0, tier1, tier2 } == { conservative, moderate, risk }
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Important: `tier2`/`risk` is **not universally “the max LTV”**; it’s the default
|
|
180
|
+
for the tier-2 risk category.
|
|
181
|
+
|
|
182
|
+
For a specific collateral position, prefer the **effective** LTV:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const { ltvWad } = await views.readLtvForPosition({ core: c.core, positionId });
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Liquidation threshold
|
|
189
|
+
|
|
190
|
+
Liquidation eligibility is best represented by health factor:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
const hf = await views.readHealthFactor({ core: c.core, user: userAddress });
|
|
194
|
+
// { healthFactor, canBeLiquidated }
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
For parameters behind liquidation incentives/fees:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
const liq = await views.readLiquidationConfig({ core: c.core });
|
|
201
|
+
const liqTier0 = await views.readTierLiquidationConfig({ core: c.core, tier: 0 });
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 3.3) Pool safety score (lend page)
|
|
207
|
+
|
|
208
|
+
If your UI currently does:
|
|
209
|
+
`(1 - utilization) * 100`, it will misleadingly show **100** when the pool has no liquidity.
|
|
210
|
+
|
|
211
|
+
Prefer the SDK helper:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
const score = await views.readPoolHealthScore({ pool: c.pool });
|
|
215
|
+
|
|
216
|
+
if (score.kind === "no-liquidity") {
|
|
217
|
+
// show "N/A" or "—"
|
|
218
|
+
} else {
|
|
219
|
+
// score.scoreBps is 0..10_000
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Current formula used by the SDK:
|
|
224
|
+
- if `totalAssets == 0` → `{ kind: "no-liquidity" }`
|
|
225
|
+
- else `scoreBps = (1 - utilizationWad) * 10_000` (clamped to [0..10_000])
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 3.4) Home page “top opportunities”
|
|
230
|
+
|
|
231
|
+
The SDK provides primitives, but **ranking is app-side**:
|
|
232
|
+
|
|
233
|
+
- `views.readPoolRates({ pool })` (supply APY, utilization)
|
|
234
|
+
- `views.readPoolCaps({ pool })` (capacity constraints)
|
|
235
|
+
- `views.readPoolHealthScore({ pool })` (simple risk signal)
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
101
239
|
## 4) Writes (simulate-first) with wagmi
|
|
102
240
|
|
|
103
241
|
The SDK write helpers return simulated requests; **you send them with your wallet client**.
|