@owney/sdk 0.7.7-beta.1 → 0.7.7-beta.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.
Files changed (3) hide show
  1. package/dist/index.cjs +107 -13
  2. package/dist/index.js +107 -13
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -879,6 +879,12 @@ var ZyfaiAgent = class {
879
879
  connectedAddress = null;
880
880
  connectedChainId = null;
881
881
  smartWalletCache = /* @__PURE__ */ new Map();
882
+ /**
883
+ * `${eoa}:${chainId}` keys we have already tried createSessionKey for. Guards
884
+ * against re-running it on every activation/deposit when Zyfai's
885
+ * `hasActiveSessionKey` does not flip to true — see ensureSessionKey.
886
+ */
887
+ sessionKeyAttempts = /* @__PURE__ */ new Set();
882
888
  connectAuthPromise = null;
883
889
  rpcUrls;
884
890
  publicClients = /* @__PURE__ */ new Map();
@@ -1354,6 +1360,10 @@ var ZyfaiAgent = class {
1354
1360
  try {
1355
1361
  const { portfolio } = await this.sdk.getPositions(ownerAddress);
1356
1362
  const raw = portfolio;
1363
+ debugLog("zyfai:onboard", "wallet state from getPositions", {
1364
+ predeployed: raw?.predeployed,
1365
+ hasActiveSessionKey: raw?.hasActiveSessionKey
1366
+ });
1357
1367
  return {
1358
1368
  predeployed: raw?.predeployed,
1359
1369
  hasActiveSessionKey: raw?.hasActiveSessionKey
@@ -1368,14 +1378,38 @@ var ZyfaiAgent = class {
1368
1378
  }
1369
1379
  async isPredeployedPoolWallet(ownerAddress, smartWallet) {
1370
1380
  const { predeployed } = await this.readWalletState(ownerAddress);
1371
- if (typeof predeployed === "boolean") return predeployed;
1381
+ if (typeof predeployed === "boolean") {
1382
+ debugLog(
1383
+ "zyfai:onboard",
1384
+ `wallet class: ${predeployed ? "PREDEPLOYED (new flow)" : "OLD (legacy flow)"}`,
1385
+ { source: "getPositions.predeployed", predeployed }
1386
+ );
1387
+ return predeployed;
1388
+ }
1372
1389
  const internals = this.sdk;
1373
1390
  if (typeof internals.isPredeployed === "boolean") {
1391
+ debugLog(
1392
+ "zyfai:onboard",
1393
+ `wallet class: ${internals.isPredeployed ? "PREDEPLOYED (new flow)" : "OLD (legacy flow)"}`,
1394
+ {
1395
+ source: "login response (cached)",
1396
+ predeployed: internals.isPredeployed
1397
+ }
1398
+ );
1374
1399
  return internals.isPredeployed;
1375
1400
  }
1376
1401
  try {
1377
1402
  const byEoa = await this.sdk.getSmartWalletByEOA(ownerAddress);
1378
- return typeof byEoa?.smartWallet === "string" && byEoa.smartWallet.toLowerCase() === smartWallet.toLowerCase();
1403
+ const isPool = typeof byEoa?.smartWallet === "string" && byEoa.smartWallet.toLowerCase() === smartWallet.toLowerCase();
1404
+ debugLog(
1405
+ "zyfai:onboard",
1406
+ `wallet class: ${isPool ? "PREDEPLOYED (new flow)" : "OLD (legacy flow)"}`,
1407
+ {
1408
+ source: "getSmartWalletByEOA fallback",
1409
+ poolRecord: byEoa?.smartWallet
1410
+ }
1411
+ );
1412
+ return isPool;
1379
1413
  } catch (error) {
1380
1414
  console.warn(
1381
1415
  "[zyfai] getSmartWalletByEOA failed; assuming a legacy wallet:",
@@ -1413,7 +1447,17 @@ var ZyfaiAgent = class {
1413
1447
  ownerAddress,
1414
1448
  chainId
1415
1449
  );
1416
- if (!wallet.isDeployed) return;
1450
+ debugLog("zyfai:onboard", `activation check on chain ${chainId}`, {
1451
+ smartWallet: wallet.address,
1452
+ isDeployed: wallet.isDeployed
1453
+ });
1454
+ if (!wallet.isDeployed) {
1455
+ debugLog(
1456
+ "zyfai:onboard",
1457
+ "Safe not deployed on this chain; activation does nothing (deposit owns deploys)"
1458
+ );
1459
+ return;
1460
+ }
1417
1461
  const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
1418
1462
  await this.ensureSessionKey(
1419
1463
  ownerAddress,
@@ -1429,23 +1473,50 @@ var ZyfaiAgent = class {
1429
1473
  }
1430
1474
  }
1431
1475
  async ensureSessionKey(ownerAddress, chainId, smartWallet, hasActiveSessionKey) {
1476
+ const attemptKey = `${ownerAddress.toLowerCase()}:${chainId}`;
1477
+ if (this.sessionKeyAttempts.has(attemptKey)) {
1478
+ debugLog(
1479
+ "zyfai:onboard",
1480
+ "session key: already attempted this session, skipping",
1481
+ { chainId }
1482
+ );
1483
+ return;
1484
+ }
1432
1485
  try {
1433
- if (hasActiveSessionKey === false) {
1434
- console.warn(
1435
- `[zyfai] no session key on record for ${ownerAddress}; creating one for chain ${chainId}.`
1486
+ if (hasActiveSessionKey === true) {
1487
+ debugLog(
1488
+ "zyfai:onboard",
1489
+ "session key: already on record -> nothing to do",
1490
+ { chainId }
1436
1491
  );
1437
- await this.sdk.createSessionKey(ownerAddress, chainId);
1438
1492
  return;
1439
1493
  }
1440
- const installed = await this.readSmartSessionsInstalled(
1441
- chainId,
1442
- smartWallet
1443
- );
1444
- if (installed) return;
1494
+ if (hasActiveSessionKey === void 0) {
1495
+ const installed = await this.readSmartSessionsInstalled(
1496
+ chainId,
1497
+ smartWallet
1498
+ );
1499
+ debugLog(
1500
+ "zyfai:onboard",
1501
+ `session key: Zyfai state unavailable; on-chain validator ${installed ? "INSTALLED" : "MISSING"}`,
1502
+ { smartWallet, chainId }
1503
+ );
1504
+ if (installed) return;
1505
+ }
1506
+ this.sessionKeyAttempts.add(attemptKey);
1445
1507
  console.warn(
1446
- `[zyfai] Safe ${smartWallet} has no smart-sessions validator on chain ${chainId}; creating a session key so the agent can allocate.`
1508
+ `[zyfai] no session key for ${smartWallet} on chain ${chainId}; creating one so the agent can allocate.`
1447
1509
  );
1510
+ debugLog("zyfai:onboard", "session key: calling createSessionKey", {
1511
+ chainId,
1512
+ smartWallet,
1513
+ hasActiveSessionKey
1514
+ });
1448
1515
  await this.sdk.createSessionKey(ownerAddress, chainId);
1516
+ debugLog("zyfai:onboard", "session key: createSessionKey succeeded", {
1517
+ chainId,
1518
+ smartWallet
1519
+ });
1449
1520
  } catch (error) {
1450
1521
  console.warn(
1451
1522
  "[zyfai] createSessionKey skipped (non-fatal):",
@@ -1483,7 +1554,17 @@ var ZyfaiAgent = class {
1483
1554
  */
1484
1555
  async ensureWalletDeployed(ownerAddress, chainId) {
1485
1556
  const wallet = await this.sdk.getSmartWalletAddress(ownerAddress, chainId);
1557
+ debugLog("zyfai:onboard", `--- deposit onboarding, chain ${chainId} ---`, {
1558
+ eoa: ownerAddress,
1559
+ smartWallet: wallet.address,
1560
+ isDeployed: wallet.isDeployed,
1561
+ isOwner: wallet.isOwner
1562
+ });
1486
1563
  if (wallet.isDeployed) {
1564
+ debugLog(
1565
+ "zyfai:onboard",
1566
+ "Safe already has code -> no deploy needed, checking the session key"
1567
+ );
1487
1568
  const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
1488
1569
  await this.ensureSessionKey(
1489
1570
  ownerAddress,
@@ -1506,14 +1587,27 @@ var ZyfaiAgent = class {
1506
1587
  this.sdk.deploySafe(ownerAddress, chainId, "aggressive", true)
1507
1588
  );
1508
1589
  const [first, second] = poolFirst ? [deployAsPool, deployAsLegacy] : [deployAsLegacy, deployAsPool];
1590
+ debugLog(
1591
+ "zyfai:onboard",
1592
+ `Safe has no code on chain ${chainId} -> deploying via ${poolFirst ? "deployOnChains (pool path)" : "deploySafe(createSessionKey=true) (legacy path)"}`
1593
+ );
1509
1594
  try {
1510
1595
  await first();
1596
+ debugLog(
1597
+ "zyfai:onboard",
1598
+ `${poolFirst ? "deployOnChains" : "deploySafe"} succeeded`
1599
+ );
1511
1600
  } catch (error) {
1512
1601
  console.warn(
1513
1602
  `[zyfai] ${poolFirst ? "deployOnChains" : "deploySafe"} failed on chain ${chainId}; trying the other deploy path:`,
1514
1603
  error instanceof Error ? error.message : String(error)
1515
1604
  );
1605
+ debugLog(
1606
+ "zyfai:onboard",
1607
+ `falling back to ${poolFirst ? "deploySafe (legacy path)" : "deployOnChains (pool path)"}`
1608
+ );
1516
1609
  await second();
1610
+ debugLog("zyfai:onboard", "fallback deploy path succeeded");
1517
1611
  }
1518
1612
  const redeployed = await this.sdk.getSmartWalletAddress(
1519
1613
  ownerAddress,
package/dist/index.js CHANGED
@@ -846,6 +846,12 @@ var ZyfaiAgent = class {
846
846
  connectedAddress = null;
847
847
  connectedChainId = null;
848
848
  smartWalletCache = /* @__PURE__ */ new Map();
849
+ /**
850
+ * `${eoa}:${chainId}` keys we have already tried createSessionKey for. Guards
851
+ * against re-running it on every activation/deposit when Zyfai's
852
+ * `hasActiveSessionKey` does not flip to true — see ensureSessionKey.
853
+ */
854
+ sessionKeyAttempts = /* @__PURE__ */ new Set();
849
855
  connectAuthPromise = null;
850
856
  rpcUrls;
851
857
  publicClients = /* @__PURE__ */ new Map();
@@ -1321,6 +1327,10 @@ var ZyfaiAgent = class {
1321
1327
  try {
1322
1328
  const { portfolio } = await this.sdk.getPositions(ownerAddress);
1323
1329
  const raw = portfolio;
1330
+ debugLog("zyfai:onboard", "wallet state from getPositions", {
1331
+ predeployed: raw?.predeployed,
1332
+ hasActiveSessionKey: raw?.hasActiveSessionKey
1333
+ });
1324
1334
  return {
1325
1335
  predeployed: raw?.predeployed,
1326
1336
  hasActiveSessionKey: raw?.hasActiveSessionKey
@@ -1335,14 +1345,38 @@ var ZyfaiAgent = class {
1335
1345
  }
1336
1346
  async isPredeployedPoolWallet(ownerAddress, smartWallet) {
1337
1347
  const { predeployed } = await this.readWalletState(ownerAddress);
1338
- if (typeof predeployed === "boolean") return predeployed;
1348
+ if (typeof predeployed === "boolean") {
1349
+ debugLog(
1350
+ "zyfai:onboard",
1351
+ `wallet class: ${predeployed ? "PREDEPLOYED (new flow)" : "OLD (legacy flow)"}`,
1352
+ { source: "getPositions.predeployed", predeployed }
1353
+ );
1354
+ return predeployed;
1355
+ }
1339
1356
  const internals = this.sdk;
1340
1357
  if (typeof internals.isPredeployed === "boolean") {
1358
+ debugLog(
1359
+ "zyfai:onboard",
1360
+ `wallet class: ${internals.isPredeployed ? "PREDEPLOYED (new flow)" : "OLD (legacy flow)"}`,
1361
+ {
1362
+ source: "login response (cached)",
1363
+ predeployed: internals.isPredeployed
1364
+ }
1365
+ );
1341
1366
  return internals.isPredeployed;
1342
1367
  }
1343
1368
  try {
1344
1369
  const byEoa = await this.sdk.getSmartWalletByEOA(ownerAddress);
1345
- return typeof byEoa?.smartWallet === "string" && byEoa.smartWallet.toLowerCase() === smartWallet.toLowerCase();
1370
+ const isPool = typeof byEoa?.smartWallet === "string" && byEoa.smartWallet.toLowerCase() === smartWallet.toLowerCase();
1371
+ debugLog(
1372
+ "zyfai:onboard",
1373
+ `wallet class: ${isPool ? "PREDEPLOYED (new flow)" : "OLD (legacy flow)"}`,
1374
+ {
1375
+ source: "getSmartWalletByEOA fallback",
1376
+ poolRecord: byEoa?.smartWallet
1377
+ }
1378
+ );
1379
+ return isPool;
1346
1380
  } catch (error) {
1347
1381
  console.warn(
1348
1382
  "[zyfai] getSmartWalletByEOA failed; assuming a legacy wallet:",
@@ -1380,7 +1414,17 @@ var ZyfaiAgent = class {
1380
1414
  ownerAddress,
1381
1415
  chainId
1382
1416
  );
1383
- if (!wallet.isDeployed) return;
1417
+ debugLog("zyfai:onboard", `activation check on chain ${chainId}`, {
1418
+ smartWallet: wallet.address,
1419
+ isDeployed: wallet.isDeployed
1420
+ });
1421
+ if (!wallet.isDeployed) {
1422
+ debugLog(
1423
+ "zyfai:onboard",
1424
+ "Safe not deployed on this chain; activation does nothing (deposit owns deploys)"
1425
+ );
1426
+ return;
1427
+ }
1384
1428
  const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
1385
1429
  await this.ensureSessionKey(
1386
1430
  ownerAddress,
@@ -1396,23 +1440,50 @@ var ZyfaiAgent = class {
1396
1440
  }
1397
1441
  }
1398
1442
  async ensureSessionKey(ownerAddress, chainId, smartWallet, hasActiveSessionKey) {
1443
+ const attemptKey = `${ownerAddress.toLowerCase()}:${chainId}`;
1444
+ if (this.sessionKeyAttempts.has(attemptKey)) {
1445
+ debugLog(
1446
+ "zyfai:onboard",
1447
+ "session key: already attempted this session, skipping",
1448
+ { chainId }
1449
+ );
1450
+ return;
1451
+ }
1399
1452
  try {
1400
- if (hasActiveSessionKey === false) {
1401
- console.warn(
1402
- `[zyfai] no session key on record for ${ownerAddress}; creating one for chain ${chainId}.`
1453
+ if (hasActiveSessionKey === true) {
1454
+ debugLog(
1455
+ "zyfai:onboard",
1456
+ "session key: already on record -> nothing to do",
1457
+ { chainId }
1403
1458
  );
1404
- await this.sdk.createSessionKey(ownerAddress, chainId);
1405
1459
  return;
1406
1460
  }
1407
- const installed = await this.readSmartSessionsInstalled(
1408
- chainId,
1409
- smartWallet
1410
- );
1411
- if (installed) return;
1461
+ if (hasActiveSessionKey === void 0) {
1462
+ const installed = await this.readSmartSessionsInstalled(
1463
+ chainId,
1464
+ smartWallet
1465
+ );
1466
+ debugLog(
1467
+ "zyfai:onboard",
1468
+ `session key: Zyfai state unavailable; on-chain validator ${installed ? "INSTALLED" : "MISSING"}`,
1469
+ { smartWallet, chainId }
1470
+ );
1471
+ if (installed) return;
1472
+ }
1473
+ this.sessionKeyAttempts.add(attemptKey);
1412
1474
  console.warn(
1413
- `[zyfai] Safe ${smartWallet} has no smart-sessions validator on chain ${chainId}; creating a session key so the agent can allocate.`
1475
+ `[zyfai] no session key for ${smartWallet} on chain ${chainId}; creating one so the agent can allocate.`
1414
1476
  );
1477
+ debugLog("zyfai:onboard", "session key: calling createSessionKey", {
1478
+ chainId,
1479
+ smartWallet,
1480
+ hasActiveSessionKey
1481
+ });
1415
1482
  await this.sdk.createSessionKey(ownerAddress, chainId);
1483
+ debugLog("zyfai:onboard", "session key: createSessionKey succeeded", {
1484
+ chainId,
1485
+ smartWallet
1486
+ });
1416
1487
  } catch (error) {
1417
1488
  console.warn(
1418
1489
  "[zyfai] createSessionKey skipped (non-fatal):",
@@ -1450,7 +1521,17 @@ var ZyfaiAgent = class {
1450
1521
  */
1451
1522
  async ensureWalletDeployed(ownerAddress, chainId) {
1452
1523
  const wallet = await this.sdk.getSmartWalletAddress(ownerAddress, chainId);
1524
+ debugLog("zyfai:onboard", `--- deposit onboarding, chain ${chainId} ---`, {
1525
+ eoa: ownerAddress,
1526
+ smartWallet: wallet.address,
1527
+ isDeployed: wallet.isDeployed,
1528
+ isOwner: wallet.isOwner
1529
+ });
1453
1530
  if (wallet.isDeployed) {
1531
+ debugLog(
1532
+ "zyfai:onboard",
1533
+ "Safe already has code -> no deploy needed, checking the session key"
1534
+ );
1454
1535
  const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
1455
1536
  await this.ensureSessionKey(
1456
1537
  ownerAddress,
@@ -1473,14 +1554,27 @@ var ZyfaiAgent = class {
1473
1554
  this.sdk.deploySafe(ownerAddress, chainId, "aggressive", true)
1474
1555
  );
1475
1556
  const [first, second] = poolFirst ? [deployAsPool, deployAsLegacy] : [deployAsLegacy, deployAsPool];
1557
+ debugLog(
1558
+ "zyfai:onboard",
1559
+ `Safe has no code on chain ${chainId} -> deploying via ${poolFirst ? "deployOnChains (pool path)" : "deploySafe(createSessionKey=true) (legacy path)"}`
1560
+ );
1476
1561
  try {
1477
1562
  await first();
1563
+ debugLog(
1564
+ "zyfai:onboard",
1565
+ `${poolFirst ? "deployOnChains" : "deploySafe"} succeeded`
1566
+ );
1478
1567
  } catch (error) {
1479
1568
  console.warn(
1480
1569
  `[zyfai] ${poolFirst ? "deployOnChains" : "deploySafe"} failed on chain ${chainId}; trying the other deploy path:`,
1481
1570
  error instanceof Error ? error.message : String(error)
1482
1571
  );
1572
+ debugLog(
1573
+ "zyfai:onboard",
1574
+ `falling back to ${poolFirst ? "deploySafe (legacy path)" : "deployOnChains (pool path)"}`
1575
+ );
1483
1576
  await second();
1577
+ debugLog("zyfai:onboard", "fallback deploy path succeeded");
1484
1578
  }
1485
1579
  const redeployed = await this.sdk.getSmartWalletAddress(
1486
1580
  ownerAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.7-beta.1",
3
+ "version": "0.7.7-beta.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",