@owney/sdk 0.5.4 → 0.5.5
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 +128 -25
- package/dist/index.js +119 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
32
32
|
|
|
33
33
|
// src/agents/zyfai/zyfai.agent.ts
|
|
34
34
|
var import_sdk = require("@zyfai/sdk");
|
|
35
|
+
var import_viem = require("viem");
|
|
36
|
+
var import_chains = require("viem/chains");
|
|
35
37
|
|
|
36
38
|
// src/types/config.ts
|
|
37
39
|
var P_SUPPORTED_CHAINS = {
|
|
@@ -309,11 +311,12 @@ function mapEntries(rawEntries, chainId) {
|
|
|
309
311
|
}
|
|
310
312
|
];
|
|
311
313
|
}
|
|
314
|
+
const mappedAction = (entry.action ? actionMap[entry.action] : void 0) ?? entry.action;
|
|
312
315
|
const rawAmount = entry?.positions?.[0]?.amount;
|
|
313
|
-
const hasAmount = typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
|
|
316
|
+
const hasAmount = mappedAction !== "Withdraw" && typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
|
|
314
317
|
return {
|
|
315
318
|
agent: "zyfai",
|
|
316
|
-
action:
|
|
319
|
+
action: mappedAction,
|
|
317
320
|
date: entry.date || "",
|
|
318
321
|
newApy: newApy === null ? null : String(newApy),
|
|
319
322
|
oldApy: oldApy === null ? null : String(oldApy),
|
|
@@ -405,6 +408,33 @@ function computeAllocationApy(positions) {
|
|
|
405
408
|
return { totalApy, apyByChainAndAsset };
|
|
406
409
|
}
|
|
407
410
|
|
|
411
|
+
// src/agents/zyfai/zyfai.withdraw-amount.ts
|
|
412
|
+
var TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
|
413
|
+
function topicToAddress(topic) {
|
|
414
|
+
return `0x${(topic ?? "").slice(-40)}`.toLowerCase();
|
|
415
|
+
}
|
|
416
|
+
function extractWithdrawnAmount(logs, recipient, token, decimals) {
|
|
417
|
+
const wantRecipient = recipient.toLowerCase();
|
|
418
|
+
const wantToken = token.toLowerCase();
|
|
419
|
+
let total = 0n;
|
|
420
|
+
let matched = false;
|
|
421
|
+
for (const log of logs) {
|
|
422
|
+
if (log.address.toLowerCase() !== wantToken)
|
|
423
|
+
continue;
|
|
424
|
+
if ((log.topics[0] ?? "").toLowerCase() !== TRANSFER_TOPIC)
|
|
425
|
+
continue;
|
|
426
|
+
if (topicToAddress(log.topics[2]) !== wantRecipient)
|
|
427
|
+
continue;
|
|
428
|
+
if (!log.data || log.data === "0x")
|
|
429
|
+
continue;
|
|
430
|
+
total += BigInt(log.data);
|
|
431
|
+
matched = true;
|
|
432
|
+
}
|
|
433
|
+
if (!matched)
|
|
434
|
+
return void 0;
|
|
435
|
+
return String(hexToDecimal(`0x${total.toString(16)}`, decimals));
|
|
436
|
+
}
|
|
437
|
+
|
|
408
438
|
// src/agents/zyfai/zyfai.history-cursor.ts
|
|
409
439
|
var InvalidHistoryCursorError = class extends Error {
|
|
410
440
|
code = "invalid_cursor";
|
|
@@ -503,6 +533,7 @@ var DEFAULT_ZYFAI_RPC_URLS = {
|
|
|
503
533
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
504
534
|
42161: "https://arb-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V"
|
|
505
535
|
};
|
|
536
|
+
var VIEM_CHAIN = { 8453: import_chains.base, 42161: import_chains.arbitrum };
|
|
506
537
|
var ZyfaiAgent = class {
|
|
507
538
|
id = "zyfai";
|
|
508
539
|
supportedChainIds = [8453, 42161];
|
|
@@ -523,13 +554,83 @@ var ZyfaiAgent = class {
|
|
|
523
554
|
connectedChainId = null;
|
|
524
555
|
smartWalletCache = /* @__PURE__ */ new Map();
|
|
525
556
|
connectAuthPromise = null;
|
|
557
|
+
rpcUrls;
|
|
558
|
+
publicClients = /* @__PURE__ */ new Map();
|
|
559
|
+
// txHash -> resolved withdrawn amount. Receipts are immutable, so a
|
|
560
|
+
// successful decode is cached forever; failures are NOT cached so a transient
|
|
561
|
+
// RPC error retries on the next fetch.
|
|
562
|
+
withdrawAmountCache = /* @__PURE__ */ new Map();
|
|
526
563
|
constructor(apiKey, rpcUrls) {
|
|
564
|
+
this.rpcUrls = rpcUrls ?? DEFAULT_ZYFAI_RPC_URLS;
|
|
527
565
|
this.sdk = new import_sdk.ZyfaiSDK({
|
|
528
566
|
apiKey,
|
|
529
|
-
rpcUrls: rpcUrls
|
|
567
|
+
rpcUrls: this.rpcUrls
|
|
530
568
|
});
|
|
531
569
|
this.installAuthCache();
|
|
532
570
|
}
|
|
571
|
+
getPublicClient(chainId) {
|
|
572
|
+
const cached = this.publicClients.get(chainId);
|
|
573
|
+
if (cached)
|
|
574
|
+
return cached;
|
|
575
|
+
const client = (0, import_viem.createPublicClient)({
|
|
576
|
+
chain: VIEM_CHAIN[chainId],
|
|
577
|
+
transport: (0, import_viem.http)(this.rpcUrls[chainId])
|
|
578
|
+
});
|
|
579
|
+
this.publicClients.set(chainId, client);
|
|
580
|
+
return client;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Fills in the true withdrawn amount for `Withdraw` entries by decoding the
|
|
584
|
+
* USDC `Transfer` that lands in the user's wallet on-chain. The Zyfai history
|
|
585
|
+
* payload only reports the *remaining* position for a partial withdraw (see
|
|
586
|
+
* the note in `mapEntries`), so without this the UI shows the leftover
|
|
587
|
+
* balance instead of the amount withdrawn.
|
|
588
|
+
*
|
|
589
|
+
* Mutates `entries` in place. Runs all lookups concurrently and is tolerant
|
|
590
|
+
* of RPC failures: an entry whose amount can't be resolved keeps
|
|
591
|
+
* `amount: undefined`, which consumers render as a hidden/retryable row
|
|
592
|
+
* rather than a wrong number.
|
|
593
|
+
*/
|
|
594
|
+
async resolveWithdrawnAmounts(entries, chainId, recipient) {
|
|
595
|
+
const asset = SupportedAssets.find(
|
|
596
|
+
(a) => a.chainId === chainId && a.symbol === "USDC"
|
|
597
|
+
);
|
|
598
|
+
if (!asset)
|
|
599
|
+
return;
|
|
600
|
+
const withdrawals = entries.filter(
|
|
601
|
+
(e) => e.action === "Withdraw" && e.transactions[0]?.txHashes[0]
|
|
602
|
+
);
|
|
603
|
+
if (withdrawals.length === 0)
|
|
604
|
+
return;
|
|
605
|
+
const client = this.getPublicClient(chainId);
|
|
606
|
+
await Promise.all(
|
|
607
|
+
withdrawals.map(async (entry) => {
|
|
608
|
+
const tx = entry.transactions[0];
|
|
609
|
+
const txHash = tx.txHashes[0];
|
|
610
|
+
const cached = this.withdrawAmountCache.get(txHash);
|
|
611
|
+
if (cached !== void 0) {
|
|
612
|
+
tx.amount = cached;
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
try {
|
|
616
|
+
const receipt = await client.getTransactionReceipt({
|
|
617
|
+
hash: txHash
|
|
618
|
+
});
|
|
619
|
+
const amount = extractWithdrawnAmount(
|
|
620
|
+
receipt.logs,
|
|
621
|
+
recipient,
|
|
622
|
+
asset.address,
|
|
623
|
+
asset.decimals
|
|
624
|
+
);
|
|
625
|
+
if (amount !== void 0) {
|
|
626
|
+
this.withdrawAmountCache.set(txHash, amount);
|
|
627
|
+
tx.amount = amount;
|
|
628
|
+
}
|
|
629
|
+
} catch {
|
|
630
|
+
}
|
|
631
|
+
})
|
|
632
|
+
);
|
|
633
|
+
}
|
|
533
634
|
/**
|
|
534
635
|
* Patches `sdk.authenticateUser` so a fresh page can reuse the JWT from a
|
|
535
636
|
* prior session instead of triggering a new SIWE prompt. Runs inside
|
|
@@ -780,8 +881,10 @@ var ZyfaiAgent = class {
|
|
|
780
881
|
toDate,
|
|
781
882
|
rawOffset: firstOvershoot ? firstOvershoot.rawIdx : offset
|
|
782
883
|
}) : void 0;
|
|
884
|
+
const data = mapEntries(pageData, validChainId);
|
|
885
|
+
await this.resolveWithdrawnAmounts(data, validChainId, state.walletAddress);
|
|
783
886
|
return {
|
|
784
|
-
data
|
|
887
|
+
data,
|
|
785
888
|
hasMore,
|
|
786
889
|
nextCursor
|
|
787
890
|
};
|
|
@@ -872,7 +975,7 @@ async function withFailureReporting(apiKey, agentType, fn) {
|
|
|
872
975
|
}
|
|
873
976
|
|
|
874
977
|
// src/lib/helpers/withdraw-helper.ts
|
|
875
|
-
var
|
|
978
|
+
var import_viem2 = require("viem");
|
|
876
979
|
function projectAgentBalancesForAsset(agents, aggregated, chainId, asset, decimals) {
|
|
877
980
|
const target = asset.toUpperCase();
|
|
878
981
|
return agents.map((agent) => {
|
|
@@ -882,7 +985,7 @@ function projectAgentBalancesForAsset(agents, aggregated, chainId, asset, decima
|
|
|
882
985
|
);
|
|
883
986
|
if (!tokenBalance)
|
|
884
987
|
return { agent, balance: 0n };
|
|
885
|
-
return { agent, balance: (0,
|
|
988
|
+
return { agent, balance: (0, import_viem2.parseUnits)(tokenBalance.amount, decimals) };
|
|
886
989
|
});
|
|
887
990
|
}
|
|
888
991
|
function planProportionalShares(balances, requested, totalAvailable) {
|
|
@@ -998,11 +1101,11 @@ function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
|
998
1101
|
}
|
|
999
1102
|
|
|
1000
1103
|
// src/client.ts
|
|
1001
|
-
var
|
|
1002
|
-
var
|
|
1104
|
+
var import_viem4 = require("viem");
|
|
1105
|
+
var import_chains2 = require("viem/chains");
|
|
1003
1106
|
|
|
1004
1107
|
// src/lib/transfer-auth.ts
|
|
1005
|
-
var
|
|
1108
|
+
var import_viem3 = require("viem");
|
|
1006
1109
|
var ERC20_META_ABI = [
|
|
1007
1110
|
{ type: "function", name: "name", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "string" }] },
|
|
1008
1111
|
{ type: "function", name: "version", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "string" }] }
|
|
@@ -1034,16 +1137,16 @@ async function readTokenMeta(publicClient, token) {
|
|
|
1034
1137
|
function randomAuthNonce() {
|
|
1035
1138
|
const bytes = new Uint8Array(32);
|
|
1036
1139
|
globalThis.crypto.getRandomValues(bytes);
|
|
1037
|
-
return (0,
|
|
1140
|
+
return (0, import_viem3.bytesToHex)(bytes);
|
|
1038
1141
|
}
|
|
1039
1142
|
|
|
1040
1143
|
// src/lib/sponsor-client.ts
|
|
1041
1144
|
var ROUTING_API_BASE_URL3 = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
1042
1145
|
async function postSponsorTransferAuth(input) {
|
|
1043
|
-
const
|
|
1146
|
+
const base3 = input.baseUrl ?? ROUTING_API_BASE_URL3;
|
|
1044
1147
|
let res;
|
|
1045
1148
|
try {
|
|
1046
|
-
res = await fetch(`${
|
|
1149
|
+
res = await fetch(`${base3}/api/v1/sponsor/erc20-transfer-auth`, {
|
|
1047
1150
|
method: "POST",
|
|
1048
1151
|
headers: { "content-type": "application/json", "x-owney-api-key": input.apiKey },
|
|
1049
1152
|
body: JSON.stringify(input.body)
|
|
@@ -1146,9 +1249,9 @@ var SPONSORED_USDC_BY_CHAIN = {
|
|
|
1146
1249
|
8453: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
1147
1250
|
42161: "0xaf88d065e77c8cc2239327c5edb3a432268e5831"
|
|
1148
1251
|
};
|
|
1149
|
-
var
|
|
1150
|
-
8453:
|
|
1151
|
-
42161:
|
|
1252
|
+
var VIEM_CHAIN2 = {
|
|
1253
|
+
8453: import_chains2.base,
|
|
1254
|
+
42161: import_chains2.arbitrum
|
|
1152
1255
|
};
|
|
1153
1256
|
var OwneySDK = class {
|
|
1154
1257
|
agents = /* @__PURE__ */ new Map();
|
|
@@ -1261,14 +1364,14 @@ var OwneySDK = class {
|
|
|
1261
1364
|
// Casts work around viem's chain-narrowed Client vs the generic
|
|
1262
1365
|
// PublicClient/WalletClient param types — structurally identical at
|
|
1263
1366
|
// runtime, but the two share a name TS treats as unrelated.
|
|
1264
|
-
getPublicClient: (cid) => (0,
|
|
1265
|
-
chain:
|
|
1266
|
-
transport: (0,
|
|
1367
|
+
getPublicClient: (cid) => (0, import_viem4.createPublicClient)({
|
|
1368
|
+
chain: VIEM_CHAIN2[cid],
|
|
1369
|
+
transport: (0, import_viem4.custom)(provider)
|
|
1267
1370
|
}),
|
|
1268
|
-
getWalletClient: (cid) => (0,
|
|
1371
|
+
getWalletClient: (cid) => (0, import_viem4.createWalletClient)({
|
|
1269
1372
|
account: owner,
|
|
1270
|
-
chain:
|
|
1271
|
-
transport: (0,
|
|
1373
|
+
chain: VIEM_CHAIN2[cid],
|
|
1374
|
+
transport: (0, import_viem4.custom)(provider)
|
|
1272
1375
|
})
|
|
1273
1376
|
});
|
|
1274
1377
|
return this.cachedSponsoredCallback;
|
|
@@ -2128,7 +2231,7 @@ var OwneySDK = class {
|
|
|
2128
2231
|
};
|
|
2129
2232
|
|
|
2130
2233
|
// src/agents/zyfai/zyfai.siwx.ts
|
|
2131
|
-
var
|
|
2234
|
+
var import_viem5 = require("viem");
|
|
2132
2235
|
var import_siwe = require("siwe");
|
|
2133
2236
|
var import_sdk2 = require("@zyfai/sdk");
|
|
2134
2237
|
|
|
@@ -2210,7 +2313,7 @@ function buildSIWXConfig(deps) {
|
|
|
2210
2313
|
issuedAt,
|
|
2211
2314
|
toString() {
|
|
2212
2315
|
return new import_siwe.SiweMessage({
|
|
2213
|
-
address: (0,
|
|
2316
|
+
address: (0, import_viem5.getAddress)(accountAddress),
|
|
2214
2317
|
chainId: numericChainId(chainId),
|
|
2215
2318
|
domain,
|
|
2216
2319
|
uri,
|
|
@@ -2286,9 +2389,9 @@ function buildSIWXConfig(deps) {
|
|
|
2286
2389
|
}
|
|
2287
2390
|
function createOwneySIWX(config) {
|
|
2288
2391
|
const zyfai = new import_sdk2.ZyfaiSDK({ apiKey: config.apiKey });
|
|
2289
|
-
const
|
|
2392
|
+
const http2 = zyfai.httpClient;
|
|
2290
2393
|
return buildSIWXConfig({
|
|
2291
|
-
post: (url, data) =>
|
|
2394
|
+
post: (url, data) => http2.post(url, data),
|
|
2292
2395
|
referralSource: config.referralSource
|
|
2293
2396
|
});
|
|
2294
2397
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/agents/zyfai/zyfai.agent.ts
|
|
2
2
|
import { ZyfaiSDK } from "@zyfai/sdk";
|
|
3
|
+
import { createPublicClient, http } from "viem";
|
|
4
|
+
import { base, arbitrum } from "viem/chains";
|
|
3
5
|
|
|
4
6
|
// src/types/config.ts
|
|
5
7
|
var P_SUPPORTED_CHAINS = {
|
|
@@ -277,11 +279,12 @@ function mapEntries(rawEntries, chainId) {
|
|
|
277
279
|
}
|
|
278
280
|
];
|
|
279
281
|
}
|
|
282
|
+
const mappedAction = (entry.action ? actionMap[entry.action] : void 0) ?? entry.action;
|
|
280
283
|
const rawAmount = entry?.positions?.[0]?.amount;
|
|
281
|
-
const hasAmount = typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
|
|
284
|
+
const hasAmount = mappedAction !== "Withdraw" && typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
|
|
282
285
|
return {
|
|
283
286
|
agent: "zyfai",
|
|
284
|
-
action:
|
|
287
|
+
action: mappedAction,
|
|
285
288
|
date: entry.date || "",
|
|
286
289
|
newApy: newApy === null ? null : String(newApy),
|
|
287
290
|
oldApy: oldApy === null ? null : String(oldApy),
|
|
@@ -373,6 +376,33 @@ function computeAllocationApy(positions) {
|
|
|
373
376
|
return { totalApy, apyByChainAndAsset };
|
|
374
377
|
}
|
|
375
378
|
|
|
379
|
+
// src/agents/zyfai/zyfai.withdraw-amount.ts
|
|
380
|
+
var TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
|
381
|
+
function topicToAddress(topic) {
|
|
382
|
+
return `0x${(topic ?? "").slice(-40)}`.toLowerCase();
|
|
383
|
+
}
|
|
384
|
+
function extractWithdrawnAmount(logs, recipient, token, decimals) {
|
|
385
|
+
const wantRecipient = recipient.toLowerCase();
|
|
386
|
+
const wantToken = token.toLowerCase();
|
|
387
|
+
let total = 0n;
|
|
388
|
+
let matched = false;
|
|
389
|
+
for (const log of logs) {
|
|
390
|
+
if (log.address.toLowerCase() !== wantToken)
|
|
391
|
+
continue;
|
|
392
|
+
if ((log.topics[0] ?? "").toLowerCase() !== TRANSFER_TOPIC)
|
|
393
|
+
continue;
|
|
394
|
+
if (topicToAddress(log.topics[2]) !== wantRecipient)
|
|
395
|
+
continue;
|
|
396
|
+
if (!log.data || log.data === "0x")
|
|
397
|
+
continue;
|
|
398
|
+
total += BigInt(log.data);
|
|
399
|
+
matched = true;
|
|
400
|
+
}
|
|
401
|
+
if (!matched)
|
|
402
|
+
return void 0;
|
|
403
|
+
return String(hexToDecimal(`0x${total.toString(16)}`, decimals));
|
|
404
|
+
}
|
|
405
|
+
|
|
376
406
|
// src/agents/zyfai/zyfai.history-cursor.ts
|
|
377
407
|
var InvalidHistoryCursorError = class extends Error {
|
|
378
408
|
code = "invalid_cursor";
|
|
@@ -471,6 +501,7 @@ var DEFAULT_ZYFAI_RPC_URLS = {
|
|
|
471
501
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
472
502
|
42161: "https://arb-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V"
|
|
473
503
|
};
|
|
504
|
+
var VIEM_CHAIN = { 8453: base, 42161: arbitrum };
|
|
474
505
|
var ZyfaiAgent = class {
|
|
475
506
|
id = "zyfai";
|
|
476
507
|
supportedChainIds = [8453, 42161];
|
|
@@ -491,13 +522,83 @@ var ZyfaiAgent = class {
|
|
|
491
522
|
connectedChainId = null;
|
|
492
523
|
smartWalletCache = /* @__PURE__ */ new Map();
|
|
493
524
|
connectAuthPromise = null;
|
|
525
|
+
rpcUrls;
|
|
526
|
+
publicClients = /* @__PURE__ */ new Map();
|
|
527
|
+
// txHash -> resolved withdrawn amount. Receipts are immutable, so a
|
|
528
|
+
// successful decode is cached forever; failures are NOT cached so a transient
|
|
529
|
+
// RPC error retries on the next fetch.
|
|
530
|
+
withdrawAmountCache = /* @__PURE__ */ new Map();
|
|
494
531
|
constructor(apiKey, rpcUrls) {
|
|
532
|
+
this.rpcUrls = rpcUrls ?? DEFAULT_ZYFAI_RPC_URLS;
|
|
495
533
|
this.sdk = new ZyfaiSDK({
|
|
496
534
|
apiKey,
|
|
497
|
-
rpcUrls: rpcUrls
|
|
535
|
+
rpcUrls: this.rpcUrls
|
|
498
536
|
});
|
|
499
537
|
this.installAuthCache();
|
|
500
538
|
}
|
|
539
|
+
getPublicClient(chainId) {
|
|
540
|
+
const cached = this.publicClients.get(chainId);
|
|
541
|
+
if (cached)
|
|
542
|
+
return cached;
|
|
543
|
+
const client = createPublicClient({
|
|
544
|
+
chain: VIEM_CHAIN[chainId],
|
|
545
|
+
transport: http(this.rpcUrls[chainId])
|
|
546
|
+
});
|
|
547
|
+
this.publicClients.set(chainId, client);
|
|
548
|
+
return client;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Fills in the true withdrawn amount for `Withdraw` entries by decoding the
|
|
552
|
+
* USDC `Transfer` that lands in the user's wallet on-chain. The Zyfai history
|
|
553
|
+
* payload only reports the *remaining* position for a partial withdraw (see
|
|
554
|
+
* the note in `mapEntries`), so without this the UI shows the leftover
|
|
555
|
+
* balance instead of the amount withdrawn.
|
|
556
|
+
*
|
|
557
|
+
* Mutates `entries` in place. Runs all lookups concurrently and is tolerant
|
|
558
|
+
* of RPC failures: an entry whose amount can't be resolved keeps
|
|
559
|
+
* `amount: undefined`, which consumers render as a hidden/retryable row
|
|
560
|
+
* rather than a wrong number.
|
|
561
|
+
*/
|
|
562
|
+
async resolveWithdrawnAmounts(entries, chainId, recipient) {
|
|
563
|
+
const asset = SupportedAssets.find(
|
|
564
|
+
(a) => a.chainId === chainId && a.symbol === "USDC"
|
|
565
|
+
);
|
|
566
|
+
if (!asset)
|
|
567
|
+
return;
|
|
568
|
+
const withdrawals = entries.filter(
|
|
569
|
+
(e) => e.action === "Withdraw" && e.transactions[0]?.txHashes[0]
|
|
570
|
+
);
|
|
571
|
+
if (withdrawals.length === 0)
|
|
572
|
+
return;
|
|
573
|
+
const client = this.getPublicClient(chainId);
|
|
574
|
+
await Promise.all(
|
|
575
|
+
withdrawals.map(async (entry) => {
|
|
576
|
+
const tx = entry.transactions[0];
|
|
577
|
+
const txHash = tx.txHashes[0];
|
|
578
|
+
const cached = this.withdrawAmountCache.get(txHash);
|
|
579
|
+
if (cached !== void 0) {
|
|
580
|
+
tx.amount = cached;
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
try {
|
|
584
|
+
const receipt = await client.getTransactionReceipt({
|
|
585
|
+
hash: txHash
|
|
586
|
+
});
|
|
587
|
+
const amount = extractWithdrawnAmount(
|
|
588
|
+
receipt.logs,
|
|
589
|
+
recipient,
|
|
590
|
+
asset.address,
|
|
591
|
+
asset.decimals
|
|
592
|
+
);
|
|
593
|
+
if (amount !== void 0) {
|
|
594
|
+
this.withdrawAmountCache.set(txHash, amount);
|
|
595
|
+
tx.amount = amount;
|
|
596
|
+
}
|
|
597
|
+
} catch {
|
|
598
|
+
}
|
|
599
|
+
})
|
|
600
|
+
);
|
|
601
|
+
}
|
|
501
602
|
/**
|
|
502
603
|
* Patches `sdk.authenticateUser` so a fresh page can reuse the JWT from a
|
|
503
604
|
* prior session instead of triggering a new SIWE prompt. Runs inside
|
|
@@ -748,8 +849,10 @@ var ZyfaiAgent = class {
|
|
|
748
849
|
toDate,
|
|
749
850
|
rawOffset: firstOvershoot ? firstOvershoot.rawIdx : offset
|
|
750
851
|
}) : void 0;
|
|
852
|
+
const data = mapEntries(pageData, validChainId);
|
|
853
|
+
await this.resolveWithdrawnAmounts(data, validChainId, state.walletAddress);
|
|
751
854
|
return {
|
|
752
|
-
data
|
|
855
|
+
data,
|
|
753
856
|
hasMore,
|
|
754
857
|
nextCursor
|
|
755
858
|
};
|
|
@@ -967,11 +1070,11 @@ function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
|
967
1070
|
|
|
968
1071
|
// src/client.ts
|
|
969
1072
|
import {
|
|
970
|
-
createPublicClient,
|
|
1073
|
+
createPublicClient as createPublicClient2,
|
|
971
1074
|
createWalletClient,
|
|
972
1075
|
custom
|
|
973
1076
|
} from "viem";
|
|
974
|
-
import { base, arbitrum } from "viem/chains";
|
|
1077
|
+
import { base as base2, arbitrum as arbitrum2 } from "viem/chains";
|
|
975
1078
|
|
|
976
1079
|
// src/lib/transfer-auth.ts
|
|
977
1080
|
import { bytesToHex } from "viem";
|
|
@@ -1012,10 +1115,10 @@ function randomAuthNonce() {
|
|
|
1012
1115
|
// src/lib/sponsor-client.ts
|
|
1013
1116
|
var ROUTING_API_BASE_URL3 = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
1014
1117
|
async function postSponsorTransferAuth(input) {
|
|
1015
|
-
const
|
|
1118
|
+
const base3 = input.baseUrl ?? ROUTING_API_BASE_URL3;
|
|
1016
1119
|
let res;
|
|
1017
1120
|
try {
|
|
1018
|
-
res = await fetch(`${
|
|
1121
|
+
res = await fetch(`${base3}/api/v1/sponsor/erc20-transfer-auth`, {
|
|
1019
1122
|
method: "POST",
|
|
1020
1123
|
headers: { "content-type": "application/json", "x-owney-api-key": input.apiKey },
|
|
1021
1124
|
body: JSON.stringify(input.body)
|
|
@@ -1118,9 +1221,9 @@ var SPONSORED_USDC_BY_CHAIN = {
|
|
|
1118
1221
|
8453: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
1119
1222
|
42161: "0xaf88d065e77c8cc2239327c5edb3a432268e5831"
|
|
1120
1223
|
};
|
|
1121
|
-
var
|
|
1122
|
-
8453:
|
|
1123
|
-
42161:
|
|
1224
|
+
var VIEM_CHAIN2 = {
|
|
1225
|
+
8453: base2,
|
|
1226
|
+
42161: arbitrum2
|
|
1124
1227
|
};
|
|
1125
1228
|
var OwneySDK = class {
|
|
1126
1229
|
agents = /* @__PURE__ */ new Map();
|
|
@@ -1233,13 +1336,13 @@ var OwneySDK = class {
|
|
|
1233
1336
|
// Casts work around viem's chain-narrowed Client vs the generic
|
|
1234
1337
|
// PublicClient/WalletClient param types — structurally identical at
|
|
1235
1338
|
// runtime, but the two share a name TS treats as unrelated.
|
|
1236
|
-
getPublicClient: (cid) =>
|
|
1237
|
-
chain:
|
|
1339
|
+
getPublicClient: (cid) => createPublicClient2({
|
|
1340
|
+
chain: VIEM_CHAIN2[cid],
|
|
1238
1341
|
transport: custom(provider)
|
|
1239
1342
|
}),
|
|
1240
1343
|
getWalletClient: (cid) => createWalletClient({
|
|
1241
1344
|
account: owner,
|
|
1242
|
-
chain:
|
|
1345
|
+
chain: VIEM_CHAIN2[cid],
|
|
1243
1346
|
transport: custom(provider)
|
|
1244
1347
|
})
|
|
1245
1348
|
});
|
|
@@ -2258,9 +2361,9 @@ function buildSIWXConfig(deps) {
|
|
|
2258
2361
|
}
|
|
2259
2362
|
function createOwneySIWX(config) {
|
|
2260
2363
|
const zyfai = new ZyfaiSDK2({ apiKey: config.apiKey });
|
|
2261
|
-
const
|
|
2364
|
+
const http2 = zyfai.httpClient;
|
|
2262
2365
|
return buildSIWXConfig({
|
|
2263
|
-
post: (url, data) =>
|
|
2366
|
+
post: (url, data) => http2.post(url, data),
|
|
2264
2367
|
referralSource: config.referralSource
|
|
2265
2368
|
});
|
|
2266
2369
|
}
|