@owney/sdk 0.7.1 → 0.7.3
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/README.md +2 -0
- package/dist/index.cjs +28 -10
- package/dist/index.js +28 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -210,6 +210,7 @@ console.log(results.agentResult.zyfai.type); // "full"
|
|
|
210
210
|
### `getBalances(agentId?)`
|
|
211
211
|
|
|
212
212
|
Get the user's balances for a specific agent, or aggregated across all agents.
|
|
213
|
+
Balances are shown after any applicable performance fees have been deducted.
|
|
213
214
|
|
|
214
215
|
| Param | Type | Description |
|
|
215
216
|
| --------- | -------------------- | ------------------------------------ |
|
|
@@ -236,6 +237,7 @@ console.log(allBalances.agentBalances.zyfai.totalBalanceAsset); // "usdc"
|
|
|
236
237
|
### `getEarnings(agentId?)`
|
|
237
238
|
|
|
238
239
|
Get the user's on-chain earnings for a specific agent, or aggregated across all agents.
|
|
240
|
+
Earnings are shown after any applicable performance fees have been deducted.
|
|
239
241
|
|
|
240
242
|
| Param | Type | Description |
|
|
241
243
|
| --------- | -------------------- | ------------------------------------ |
|
package/dist/index.cjs
CHANGED
|
@@ -158,6 +158,14 @@ function hexToDecimal(hex, decimals = 6) {
|
|
|
158
158
|
const remainder = parsed % divisor;
|
|
159
159
|
return Number(whole) + Number(remainder) / Number(divisor);
|
|
160
160
|
}
|
|
161
|
+
function normalizeDecimalPlace(value, decimals = 6) {
|
|
162
|
+
const parsed = BigInt(value);
|
|
163
|
+
if (decimals <= 0) return Number(parsed);
|
|
164
|
+
const divisor = BigInt(10 ** decimals);
|
|
165
|
+
const whole = parsed / divisor;
|
|
166
|
+
const remainder = parsed % divisor;
|
|
167
|
+
return Number(whole) + Number(remainder) / Number(divisor);
|
|
168
|
+
}
|
|
161
169
|
var DayFilterMapping = {
|
|
162
170
|
"30D": 30,
|
|
163
171
|
"14D": 14,
|
|
@@ -216,10 +224,10 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
216
224
|
const tokens = [];
|
|
217
225
|
for (const [chainIdKey, tokensBySymbol] of Object.entries(portfolioByChain)) {
|
|
218
226
|
const positionChainId = Number(chainIdKey);
|
|
219
|
-
for (const [symbol, { balance, decimals }] of Object.entries(
|
|
227
|
+
for (const [symbol, { balance, balanceWithFee, decimals }] of Object.entries(
|
|
220
228
|
tokensBySymbol ?? {}
|
|
221
229
|
)) {
|
|
222
|
-
const amount = hexToDecimal(balance
|
|
230
|
+
const amount = hexToDecimal(balanceWithFee ?? balance ?? "0", decimals);
|
|
223
231
|
totalBalance += amount;
|
|
224
232
|
tokens.push({
|
|
225
233
|
chain: CHAIN_ID_TO_NAME[positionChainId] ?? "BASE",
|
|
@@ -235,15 +243,23 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
235
243
|
protocolId: p.protocol_id,
|
|
236
244
|
pool: p.pool,
|
|
237
245
|
asset: p.token_symbol ?? "",
|
|
238
|
-
//
|
|
239
|
-
//
|
|
246
|
+
// Fee-adjusted underlying amounts are decimal base-unit strings. The
|
|
247
|
+
// legacy `amount` fallback is hex. Runtime
|
|
240
248
|
// getBalances payloads often carry one (e.g. 18 for WETH) — prefer that
|
|
241
|
-
// when present, otherwise fall back to the per-symbol lookup
|
|
242
|
-
// non-6-decimal assets like WETH don't render 1e12 too large.
|
|
249
|
+
// when present, otherwise fall back to the per-symbol lookup.
|
|
243
250
|
amount: String(
|
|
244
|
-
|
|
251
|
+
p.underlyingAmountWithFee ?? p.underlyingAmount ? normalizeDecimalPlace(
|
|
252
|
+
p.underlyingAmountWithFee ?? p.underlyingAmount ?? "0",
|
|
253
|
+
tokenDecimals(
|
|
254
|
+
p.token_symbol,
|
|
255
|
+
p.decimals
|
|
256
|
+
)
|
|
257
|
+
) : hexToDecimal(
|
|
245
258
|
p.amount || "0",
|
|
246
|
-
tokenDecimals(
|
|
259
|
+
tokenDecimals(
|
|
260
|
+
p.token_symbol,
|
|
261
|
+
p.decimals
|
|
262
|
+
)
|
|
247
263
|
)
|
|
248
264
|
),
|
|
249
265
|
apy: p.pool_apy,
|
|
@@ -267,7 +283,7 @@ function sumTokenEarnings(tokens) {
|
|
|
267
283
|
return Object.values(tokens).reduce((sum, val) => sum + Number(val), 0);
|
|
268
284
|
}
|
|
269
285
|
function mapEarnings(raw, smartWallet) {
|
|
270
|
-
const totalEarningsByChain = raw.data.totalEarningsByChain;
|
|
286
|
+
const totalEarningsByChain = raw.data.totalEarningsByChainWithFee ?? raw.data.totalEarningsByChain ?? {};
|
|
271
287
|
const tokens = [];
|
|
272
288
|
for (const [chainIdKey, tokensBySymbol] of Object.entries(
|
|
273
289
|
totalEarningsByChain
|
|
@@ -285,7 +301,9 @@ function mapEarnings(raw, smartWallet) {
|
|
|
285
301
|
}
|
|
286
302
|
return {
|
|
287
303
|
smartWallet,
|
|
288
|
-
lifetimeEarnings: sumTokenEarnings(
|
|
304
|
+
lifetimeEarnings: sumTokenEarnings(
|
|
305
|
+
raw.data.totalEarningsByTokenWithFee ?? raw.data.totalEarningsByToken
|
|
306
|
+
),
|
|
289
307
|
tokens
|
|
290
308
|
};
|
|
291
309
|
}
|
package/dist/index.js
CHANGED
|
@@ -125,6 +125,14 @@ function hexToDecimal(hex, decimals = 6) {
|
|
|
125
125
|
const remainder = parsed % divisor;
|
|
126
126
|
return Number(whole) + Number(remainder) / Number(divisor);
|
|
127
127
|
}
|
|
128
|
+
function normalizeDecimalPlace(value, decimals = 6) {
|
|
129
|
+
const parsed = BigInt(value);
|
|
130
|
+
if (decimals <= 0) return Number(parsed);
|
|
131
|
+
const divisor = BigInt(10 ** decimals);
|
|
132
|
+
const whole = parsed / divisor;
|
|
133
|
+
const remainder = parsed % divisor;
|
|
134
|
+
return Number(whole) + Number(remainder) / Number(divisor);
|
|
135
|
+
}
|
|
128
136
|
var DayFilterMapping = {
|
|
129
137
|
"30D": 30,
|
|
130
138
|
"14D": 14,
|
|
@@ -183,10 +191,10 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
183
191
|
const tokens = [];
|
|
184
192
|
for (const [chainIdKey, tokensBySymbol] of Object.entries(portfolioByChain)) {
|
|
185
193
|
const positionChainId = Number(chainIdKey);
|
|
186
|
-
for (const [symbol, { balance, decimals }] of Object.entries(
|
|
194
|
+
for (const [symbol, { balance, balanceWithFee, decimals }] of Object.entries(
|
|
187
195
|
tokensBySymbol ?? {}
|
|
188
196
|
)) {
|
|
189
|
-
const amount = hexToDecimal(balance
|
|
197
|
+
const amount = hexToDecimal(balanceWithFee ?? balance ?? "0", decimals);
|
|
190
198
|
totalBalance += amount;
|
|
191
199
|
tokens.push({
|
|
192
200
|
chain: CHAIN_ID_TO_NAME[positionChainId] ?? "BASE",
|
|
@@ -202,15 +210,23 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
202
210
|
protocolId: p.protocol_id,
|
|
203
211
|
pool: p.pool,
|
|
204
212
|
asset: p.token_symbol ?? "",
|
|
205
|
-
//
|
|
206
|
-
//
|
|
213
|
+
// Fee-adjusted underlying amounts are decimal base-unit strings. The
|
|
214
|
+
// legacy `amount` fallback is hex. Runtime
|
|
207
215
|
// getBalances payloads often carry one (e.g. 18 for WETH) — prefer that
|
|
208
|
-
// when present, otherwise fall back to the per-symbol lookup
|
|
209
|
-
// non-6-decimal assets like WETH don't render 1e12 too large.
|
|
216
|
+
// when present, otherwise fall back to the per-symbol lookup.
|
|
210
217
|
amount: String(
|
|
211
|
-
|
|
218
|
+
p.underlyingAmountWithFee ?? p.underlyingAmount ? normalizeDecimalPlace(
|
|
219
|
+
p.underlyingAmountWithFee ?? p.underlyingAmount ?? "0",
|
|
220
|
+
tokenDecimals(
|
|
221
|
+
p.token_symbol,
|
|
222
|
+
p.decimals
|
|
223
|
+
)
|
|
224
|
+
) : hexToDecimal(
|
|
212
225
|
p.amount || "0",
|
|
213
|
-
tokenDecimals(
|
|
226
|
+
tokenDecimals(
|
|
227
|
+
p.token_symbol,
|
|
228
|
+
p.decimals
|
|
229
|
+
)
|
|
214
230
|
)
|
|
215
231
|
),
|
|
216
232
|
apy: p.pool_apy,
|
|
@@ -234,7 +250,7 @@ function sumTokenEarnings(tokens) {
|
|
|
234
250
|
return Object.values(tokens).reduce((sum, val) => sum + Number(val), 0);
|
|
235
251
|
}
|
|
236
252
|
function mapEarnings(raw, smartWallet) {
|
|
237
|
-
const totalEarningsByChain = raw.data.totalEarningsByChain;
|
|
253
|
+
const totalEarningsByChain = raw.data.totalEarningsByChainWithFee ?? raw.data.totalEarningsByChain ?? {};
|
|
238
254
|
const tokens = [];
|
|
239
255
|
for (const [chainIdKey, tokensBySymbol] of Object.entries(
|
|
240
256
|
totalEarningsByChain
|
|
@@ -252,7 +268,9 @@ function mapEarnings(raw, smartWallet) {
|
|
|
252
268
|
}
|
|
253
269
|
return {
|
|
254
270
|
smartWallet,
|
|
255
|
-
lifetimeEarnings: sumTokenEarnings(
|
|
271
|
+
lifetimeEarnings: sumTokenEarnings(
|
|
272
|
+
raw.data.totalEarningsByTokenWithFee ?? raw.data.totalEarningsByToken
|
|
273
|
+
),
|
|
256
274
|
tokens
|
|
257
275
|
};
|
|
258
276
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owney/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test:watch": "vitest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@zyfai/sdk": "0.2.
|
|
26
|
+
"@zyfai/sdk": "0.2.48",
|
|
27
27
|
"siwe": "^3.0.0",
|
|
28
28
|
"viem": "^2.48.1"
|
|
29
29
|
},
|