@owney/sdk 0.6.5-beta.0 → 0.6.5-beta.1
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/dist/index.cjs +59 -13
- package/dist/index.js +59 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -153,6 +153,20 @@ var DayFilterMapping = {
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
// src/agents/zyfai/zyfai.mapper.ts
|
|
156
|
+
var DECIMALS_BY_SYMBOL = {
|
|
157
|
+
usdc: 6,
|
|
158
|
+
usdt: 6,
|
|
159
|
+
weth: 18,
|
|
160
|
+
eth: 18,
|
|
161
|
+
cbeth: 18,
|
|
162
|
+
wbtc: 8,
|
|
163
|
+
cbbtc: 8
|
|
164
|
+
};
|
|
165
|
+
function tokenDecimals(symbol, explicit) {
|
|
166
|
+
if (typeof explicit === "number" && Number.isFinite(explicit))
|
|
167
|
+
return explicit;
|
|
168
|
+
return DECIMALS_BY_SYMBOL[(symbol ?? "").toLowerCase()] ?? 6;
|
|
169
|
+
}
|
|
156
170
|
function mapDeposit(raw) {
|
|
157
171
|
return {
|
|
158
172
|
txHash: raw.txHash,
|
|
@@ -210,9 +224,16 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
210
224
|
pool: p.pool,
|
|
211
225
|
asset: p.token_symbol ?? "",
|
|
212
226
|
// Position amount is hex-encoded base units (like the token balances
|
|
213
|
-
// above).
|
|
214
|
-
//
|
|
215
|
-
|
|
227
|
+
// above). `PositionSlot` doesn't type a `decimals` field, but runtime
|
|
228
|
+
// getBalances payloads often carry one (e.g. 18 for WETH) — prefer that
|
|
229
|
+
// when present, otherwise fall back to the per-symbol lookup so
|
|
230
|
+
// non-6-decimal assets like WETH don't render 1e12 too large.
|
|
231
|
+
amount: String(
|
|
232
|
+
hexToDecimal(
|
|
233
|
+
p.amount || "0",
|
|
234
|
+
tokenDecimals(p.token_symbol, p.decimals)
|
|
235
|
+
)
|
|
236
|
+
),
|
|
216
237
|
apy: p.pool_apy,
|
|
217
238
|
tvl: p.pool_tvl,
|
|
218
239
|
// PositionSlot has no `liquidity` field yet; Zyfai will add it. Narrow
|
|
@@ -335,7 +356,15 @@ function mapEntries(rawEntries, chainId) {
|
|
|
335
356
|
fromPool: from.pool,
|
|
336
357
|
toPool: to.pool,
|
|
337
358
|
tokenSymbol: matched?.token_symbol ?? "",
|
|
338
|
-
amount: matched ? String(
|
|
359
|
+
amount: matched ? String(
|
|
360
|
+
hexToDecimal(
|
|
361
|
+
matched.amount || "0x",
|
|
362
|
+
tokenDecimals(
|
|
363
|
+
matched.token_symbol,
|
|
364
|
+
matched.decimals
|
|
365
|
+
)
|
|
366
|
+
)
|
|
367
|
+
) : "",
|
|
339
368
|
status: "success"
|
|
340
369
|
}
|
|
341
370
|
];
|
|
@@ -354,7 +383,12 @@ function mapEntries(rawEntries, chainId) {
|
|
|
354
383
|
txHashes: entry.transactionHash ? [entry.transactionHash] : [],
|
|
355
384
|
chainId: entry.chainId,
|
|
356
385
|
tokenSymbol: entry?.positions?.[0]?.token_symbol,
|
|
357
|
-
amount: hasAmount ? String(
|
|
386
|
+
amount: hasAmount ? String(
|
|
387
|
+
hexToDecimal(
|
|
388
|
+
rawAmount,
|
|
389
|
+
tokenDecimals(entry?.positions?.[0]?.token_symbol)
|
|
390
|
+
)
|
|
391
|
+
) : void 0
|
|
358
392
|
}
|
|
359
393
|
],
|
|
360
394
|
rebalanceLog
|
|
@@ -631,22 +665,24 @@ var ZyfaiAgent = class {
|
|
|
631
665
|
}
|
|
632
666
|
/**
|
|
633
667
|
* Fills in the true withdrawn amount for `Withdraw` entries by decoding the
|
|
634
|
-
*
|
|
668
|
+
* on-chain `Transfer` that lands in the user's wallet. The Zyfai history
|
|
635
669
|
* payload only reports the *remaining* position for a partial withdraw (see
|
|
636
670
|
* the note in `mapEntries`), so without this the UI shows the leftover
|
|
637
671
|
* balance instead of the amount withdrawn.
|
|
638
672
|
*
|
|
673
|
+
* The withdrawn asset varies per entry (USDC or WETH), so it's resolved
|
|
674
|
+
* from `tx.tokenSymbol` (set by `mapEntries` from the entry's own
|
|
675
|
+
* position) rather than assumed to always be USDC. Zyfai sometimes
|
|
676
|
+
* denominates WETH as lowercase "eth" — that's normalized to WETH.
|
|
677
|
+
* Entries with no symbol (older payload shapes) fall back to USDC to
|
|
678
|
+
* preserve prior behavior.
|
|
679
|
+
*
|
|
639
680
|
* Mutates `entries` in place. Runs all lookups concurrently and is tolerant
|
|
640
681
|
* of RPC failures: an entry whose amount can't be resolved keeps
|
|
641
682
|
* `amount: undefined`, which consumers render as a hidden/retryable row
|
|
642
683
|
* rather than a wrong number.
|
|
643
684
|
*/
|
|
644
685
|
async resolveWithdrawnAmounts(entries, chainId, recipient) {
|
|
645
|
-
const asset = SupportedAssets.find(
|
|
646
|
-
(a) => a.chainId === chainId && a.symbol === "USDC"
|
|
647
|
-
);
|
|
648
|
-
if (!asset)
|
|
649
|
-
return;
|
|
650
686
|
const withdrawals = entries.filter(
|
|
651
687
|
(e) => e.action === "Withdraw" && e.transactions[0]?.txHashes[0]
|
|
652
688
|
);
|
|
@@ -657,7 +693,17 @@ var ZyfaiAgent = class {
|
|
|
657
693
|
withdrawals.map(async (entry) => {
|
|
658
694
|
const tx = entry.transactions[0];
|
|
659
695
|
const txHash = tx.txHashes[0];
|
|
660
|
-
const
|
|
696
|
+
const rawSymbol = tx.tokenSymbol;
|
|
697
|
+
const normalizedSymbol = rawSymbol ? rawSymbol.toLowerCase() === "eth" ? "WETH" : rawSymbol.toUpperCase() : "USDC";
|
|
698
|
+
const asset = SupportedAssets.find(
|
|
699
|
+
(a) => a.chainId === chainId && a.symbol === normalizedSymbol
|
|
700
|
+
) ?? SupportedAssets.find(
|
|
701
|
+
(a) => a.chainId === chainId && a.symbol === "USDC"
|
|
702
|
+
);
|
|
703
|
+
if (!asset)
|
|
704
|
+
return;
|
|
705
|
+
const cacheKey = `${txHash}:${asset.address}`;
|
|
706
|
+
const cached = this.withdrawAmountCache.get(cacheKey);
|
|
661
707
|
if (cached !== void 0) {
|
|
662
708
|
tx.amount = cached;
|
|
663
709
|
return;
|
|
@@ -673,7 +719,7 @@ var ZyfaiAgent = class {
|
|
|
673
719
|
asset.decimals
|
|
674
720
|
);
|
|
675
721
|
if (amount !== void 0) {
|
|
676
|
-
this.withdrawAmountCache.set(
|
|
722
|
+
this.withdrawAmountCache.set(cacheKey, amount);
|
|
677
723
|
tx.amount = amount;
|
|
678
724
|
}
|
|
679
725
|
} catch {
|
package/dist/index.js
CHANGED
|
@@ -121,6 +121,20 @@ var DayFilterMapping = {
|
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
// src/agents/zyfai/zyfai.mapper.ts
|
|
124
|
+
var DECIMALS_BY_SYMBOL = {
|
|
125
|
+
usdc: 6,
|
|
126
|
+
usdt: 6,
|
|
127
|
+
weth: 18,
|
|
128
|
+
eth: 18,
|
|
129
|
+
cbeth: 18,
|
|
130
|
+
wbtc: 8,
|
|
131
|
+
cbbtc: 8
|
|
132
|
+
};
|
|
133
|
+
function tokenDecimals(symbol, explicit) {
|
|
134
|
+
if (typeof explicit === "number" && Number.isFinite(explicit))
|
|
135
|
+
return explicit;
|
|
136
|
+
return DECIMALS_BY_SYMBOL[(symbol ?? "").toLowerCase()] ?? 6;
|
|
137
|
+
}
|
|
124
138
|
function mapDeposit(raw) {
|
|
125
139
|
return {
|
|
126
140
|
txHash: raw.txHash,
|
|
@@ -178,9 +192,16 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
178
192
|
pool: p.pool,
|
|
179
193
|
asset: p.token_symbol ?? "",
|
|
180
194
|
// Position amount is hex-encoded base units (like the token balances
|
|
181
|
-
// above).
|
|
182
|
-
//
|
|
183
|
-
|
|
195
|
+
// above). `PositionSlot` doesn't type a `decimals` field, but runtime
|
|
196
|
+
// getBalances payloads often carry one (e.g. 18 for WETH) — prefer that
|
|
197
|
+
// when present, otherwise fall back to the per-symbol lookup so
|
|
198
|
+
// non-6-decimal assets like WETH don't render 1e12 too large.
|
|
199
|
+
amount: String(
|
|
200
|
+
hexToDecimal(
|
|
201
|
+
p.amount || "0",
|
|
202
|
+
tokenDecimals(p.token_symbol, p.decimals)
|
|
203
|
+
)
|
|
204
|
+
),
|
|
184
205
|
apy: p.pool_apy,
|
|
185
206
|
tvl: p.pool_tvl,
|
|
186
207
|
// PositionSlot has no `liquidity` field yet; Zyfai will add it. Narrow
|
|
@@ -303,7 +324,15 @@ function mapEntries(rawEntries, chainId) {
|
|
|
303
324
|
fromPool: from.pool,
|
|
304
325
|
toPool: to.pool,
|
|
305
326
|
tokenSymbol: matched?.token_symbol ?? "",
|
|
306
|
-
amount: matched ? String(
|
|
327
|
+
amount: matched ? String(
|
|
328
|
+
hexToDecimal(
|
|
329
|
+
matched.amount || "0x",
|
|
330
|
+
tokenDecimals(
|
|
331
|
+
matched.token_symbol,
|
|
332
|
+
matched.decimals
|
|
333
|
+
)
|
|
334
|
+
)
|
|
335
|
+
) : "",
|
|
307
336
|
status: "success"
|
|
308
337
|
}
|
|
309
338
|
];
|
|
@@ -322,7 +351,12 @@ function mapEntries(rawEntries, chainId) {
|
|
|
322
351
|
txHashes: entry.transactionHash ? [entry.transactionHash] : [],
|
|
323
352
|
chainId: entry.chainId,
|
|
324
353
|
tokenSymbol: entry?.positions?.[0]?.token_symbol,
|
|
325
|
-
amount: hasAmount ? String(
|
|
354
|
+
amount: hasAmount ? String(
|
|
355
|
+
hexToDecimal(
|
|
356
|
+
rawAmount,
|
|
357
|
+
tokenDecimals(entry?.positions?.[0]?.token_symbol)
|
|
358
|
+
)
|
|
359
|
+
) : void 0
|
|
326
360
|
}
|
|
327
361
|
],
|
|
328
362
|
rebalanceLog
|
|
@@ -599,22 +633,24 @@ var ZyfaiAgent = class {
|
|
|
599
633
|
}
|
|
600
634
|
/**
|
|
601
635
|
* Fills in the true withdrawn amount for `Withdraw` entries by decoding the
|
|
602
|
-
*
|
|
636
|
+
* on-chain `Transfer` that lands in the user's wallet. The Zyfai history
|
|
603
637
|
* payload only reports the *remaining* position for a partial withdraw (see
|
|
604
638
|
* the note in `mapEntries`), so without this the UI shows the leftover
|
|
605
639
|
* balance instead of the amount withdrawn.
|
|
606
640
|
*
|
|
641
|
+
* The withdrawn asset varies per entry (USDC or WETH), so it's resolved
|
|
642
|
+
* from `tx.tokenSymbol` (set by `mapEntries` from the entry's own
|
|
643
|
+
* position) rather than assumed to always be USDC. Zyfai sometimes
|
|
644
|
+
* denominates WETH as lowercase "eth" — that's normalized to WETH.
|
|
645
|
+
* Entries with no symbol (older payload shapes) fall back to USDC to
|
|
646
|
+
* preserve prior behavior.
|
|
647
|
+
*
|
|
607
648
|
* Mutates `entries` in place. Runs all lookups concurrently and is tolerant
|
|
608
649
|
* of RPC failures: an entry whose amount can't be resolved keeps
|
|
609
650
|
* `amount: undefined`, which consumers render as a hidden/retryable row
|
|
610
651
|
* rather than a wrong number.
|
|
611
652
|
*/
|
|
612
653
|
async resolveWithdrawnAmounts(entries, chainId, recipient) {
|
|
613
|
-
const asset = SupportedAssets.find(
|
|
614
|
-
(a) => a.chainId === chainId && a.symbol === "USDC"
|
|
615
|
-
);
|
|
616
|
-
if (!asset)
|
|
617
|
-
return;
|
|
618
654
|
const withdrawals = entries.filter(
|
|
619
655
|
(e) => e.action === "Withdraw" && e.transactions[0]?.txHashes[0]
|
|
620
656
|
);
|
|
@@ -625,7 +661,17 @@ var ZyfaiAgent = class {
|
|
|
625
661
|
withdrawals.map(async (entry) => {
|
|
626
662
|
const tx = entry.transactions[0];
|
|
627
663
|
const txHash = tx.txHashes[0];
|
|
628
|
-
const
|
|
664
|
+
const rawSymbol = tx.tokenSymbol;
|
|
665
|
+
const normalizedSymbol = rawSymbol ? rawSymbol.toLowerCase() === "eth" ? "WETH" : rawSymbol.toUpperCase() : "USDC";
|
|
666
|
+
const asset = SupportedAssets.find(
|
|
667
|
+
(a) => a.chainId === chainId && a.symbol === normalizedSymbol
|
|
668
|
+
) ?? SupportedAssets.find(
|
|
669
|
+
(a) => a.chainId === chainId && a.symbol === "USDC"
|
|
670
|
+
);
|
|
671
|
+
if (!asset)
|
|
672
|
+
return;
|
|
673
|
+
const cacheKey = `${txHash}:${asset.address}`;
|
|
674
|
+
const cached = this.withdrawAmountCache.get(cacheKey);
|
|
629
675
|
if (cached !== void 0) {
|
|
630
676
|
tx.amount = cached;
|
|
631
677
|
return;
|
|
@@ -641,7 +687,7 @@ var ZyfaiAgent = class {
|
|
|
641
687
|
asset.decimals
|
|
642
688
|
);
|
|
643
689
|
if (amount !== void 0) {
|
|
644
|
-
this.withdrawAmountCache.set(
|
|
690
|
+
this.withdrawAmountCache.set(cacheKey, amount);
|
|
645
691
|
tx.amount = amount;
|
|
646
692
|
}
|
|
647
693
|
} catch {
|