@gvnrdao/dh-sdk 0.0.312 → 0.0.313

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.mjs CHANGED
@@ -94,13 +94,15 @@ var init_deployment_addresses = __esm({
94
94
  PositionDelegateRegistry: "0x482369De283622E7b05731875ec137d4E3D208F9",
95
95
  FeeRecipientRegistry: "0x95795F8403DDb629E8527B2934C4e71f5fC0C374",
96
96
  BitcoinWithdrawalAddressRegistry: "0x6376D392097F0A81e51BD83960A97EA20eaf1dbe",
97
- CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7"
97
+ CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
98
+ AgentDelegationRegistry: "0xA6040Ee7c52220634C6cC565885d6956C95Faaf5",
99
+ DHAgentDelegate: "0x3Ea189b22Db147A7c79fF3FD8AaDfA8B0Bd0f4FB"
98
100
  },
99
101
  upgraded: {
100
102
  PositionManager: {
101
- previousImplementation: "0x1B113E63FA5b1Cd0cCaf28CACE83EAb9621c8e8A",
102
- newImplementation: "0x3a493909920DF104D4048c2c20270B9DAFC81716",
103
- upgradedAt: "2026-07-03T20:18:00.987Z",
103
+ previousImplementation: "0x3a493909920DF104D4048c2c20270B9DAFC81716",
104
+ newImplementation: "0x607a80aee6eF425C7eC7bA5230E5FAFC95B0388F",
105
+ upgradedAt: "2026-07-23T23:55:25.994Z",
104
106
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
105
107
  reason: "Shared upgrade script: PositionManager implementation update"
106
108
  },
@@ -327,7 +329,7 @@ var init_deployment_addresses = __esm({
327
329
  CIRCUIT_BREAKER_MODULE_IMPL: "0xF6277dEF72D51312CC99616B5380f34Eb7603D75",
328
330
  ADMIN_MODULE_IMPL: "0xBBA86246169f81a307Fafff02C1e3D8456aab973",
329
331
  POSITION_MANAGER_VIEWS_IMPL: "0xA455B542cFb36AF8451fc420dB89e590E5c87cef",
330
- POSITION_MANAGER_IMPL: "0x3a493909920DF104D4048c2c20270B9DAFC81716",
332
+ POSITION_MANAGER_IMPL: "0x607a80aee6eF425C7eC7bA5230E5FAFC95B0388F",
331
333
  SIMPLE_PSM_V2: "0x19EcF7BA26e054fd4Ff06009A03070103dbBB058",
332
334
  SIMPLE_PSM_V2_IMPL: "0xE38010BE47B389922A1cd4b533470F0af7d20101",
333
335
  UCD_TOKEN_IMPL: "0xa6C8C4cfc7DD3dCE5F1259A4a1eAf8461aA8CeC8",
@@ -358,7 +360,10 @@ var init_deployment_addresses = __esm({
358
360
  BITCOIN_WITHDRAWAL_ADDRESS_REGISTRY: "0x6376D392097F0A81e51BD83960A97EA20eaf1dbe",
359
361
  BITCOIN_WITHDRAWAL_ADDRESS_REGISTRY_IMPL: "0xFF270BC4470dBA80430Bd1a3a66EB691599354fA",
360
362
  CARRY_AGENT_REGISTRY: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
361
- CARRY_AGENT_REGISTRY_IMPL: "0x1b11a3D5e46F3672E643c997f0d569DFf0b64a01"
363
+ CARRY_AGENT_REGISTRY_IMPL: "0x1b11a3D5e46F3672E643c997f0d569DFf0b64a01",
364
+ AGENT_DELEGATION_REGISTRY: "0xA6040Ee7c52220634C6cC565885d6956C95Faaf5",
365
+ AGENT_DELEGATION_REGISTRY_IMPL: "0x4cCB77306A1EE0F1F686EeF83B66eD8796E6dd90",
366
+ DH_AGENT_DELEGATE: "0x3Ea189b22Db147A7c79fF3FD8AaDfA8B0Bd0f4FB"
362
367
  }
363
368
  };
364
369
  SEPOLIA_CONTRACTS = {
@@ -387,7 +392,9 @@ var init_deployment_addresses = __esm({
387
392
  PositionDelegateRegistry: "0x482369De283622E7b05731875ec137d4E3D208F9",
388
393
  FeeRecipientRegistry: "0x95795F8403DDb629E8527B2934C4e71f5fC0C374",
389
394
  BitcoinWithdrawalAddressRegistry: "0x6376D392097F0A81e51BD83960A97EA20eaf1dbe",
390
- CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7"
395
+ CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
396
+ AgentDelegationRegistry: "0xA6040Ee7c52220634C6cC565885d6956C95Faaf5",
397
+ DHAgentDelegate: "0x3Ea189b22Db147A7c79fF3FD8AaDfA8B0Bd0f4FB"
391
398
  };
392
399
  MAINNET_DEPLOYMENT = {
393
400
  network: "mainnet",
@@ -1309,30 +1316,30 @@ var require_pkg_src = __commonJS({
1309
1316
  }
1310
1317
  },
1311
1318
  btcTransactionSigner: {
1312
- cid: "QmSJkQAw5SJ39EGEwzWZJ39ApNN4834VgKS5rhm25YCgfk",
1319
+ cid: "QmZFzjpdwpiBxHPv3t1mhjv8hfPRD1hPZGJ7jUU9w6V2Ca",
1313
1320
  authorizedCidHex: cidToHex(
1314
- "QmSJkQAw5SJ39EGEwzWZJ39ApNN4834VgKS5rhm25YCgfk"
1321
+ "QmZFzjpdwpiBxHPv3t1mhjv8hfPRD1hPZGJ7jUU9w6V2Ca"
1315
1322
  ),
1316
1323
  name: "Btc Transaction Signer",
1317
1324
  description: "Production Btc Transaction Signer",
1318
1325
  version: "1.1.1",
1319
1326
  deployed: true,
1320
- deployedAt: 1784316496778,
1321
- size: 63679,
1322
- hash: "b12aa725797af5ef07f8e6945f05741f583d6e479a4670b1121e97c58fe63191"
1327
+ deployedAt: 1785173232972,
1328
+ size: 66562,
1329
+ hash: "13639ec13bfed381c3c9d81e17e37917446ba30d04d4d8e45809a6868139c3cb"
1323
1330
  },
1324
1331
  ucdMintValidator: {
1325
- cid: "QmYVRMfiSC641JPbE819szSDw3YrG6uSrZc27CZkyYTGtW",
1332
+ cid: "Qmb1TPCaNYRTHsnhZrE1J4BtVYNWBnWSneXRqyAco1XKku",
1326
1333
  authorizedCidHex: cidToHex(
1327
- "QmYVRMfiSC641JPbE819szSDw3YrG6uSrZc27CZkyYTGtW"
1334
+ "Qmb1TPCaNYRTHsnhZrE1J4BtVYNWBnWSneXRqyAco1XKku"
1328
1335
  ),
1329
1336
  name: "Ucd Mint Validator",
1330
1337
  description: "Production Ucd Mint Validator",
1331
1338
  version: "1.2.1",
1332
1339
  deployed: true,
1333
- deployedAt: 1784316505431,
1334
- size: 80381,
1335
- hash: "132a0a8e6e9a1b85d02e00c0e57eaa371d825717255a28c9e644e4b521760026",
1340
+ deployedAt: 1785173240530,
1341
+ size: 81596,
1342
+ hash: "fdaa7abb4ad28ae1f20f5cd6e3e03e5a8787fd6ac05938f51070ed16844f80f5",
1336
1343
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1337
1344
  pkp: {
1338
1345
  publicKey: "0x041ab17cd91fc5c0b761eea6092d032807561b621b82c488826776e04a9158d61ba64d809a4729f0501289d980732cb06d8dfd06999dd9c8efd2f495dad78b31bb",
@@ -1340,17 +1347,17 @@ var require_pkg_src = __commonJS({
1340
1347
  }
1341
1348
  },
1342
1349
  processPaymentValidator: {
1343
- cid: "QmadmdFDH6sS7YLusUuuLkkt7n51iUj1bJ5KKTLhmro2iQ",
1350
+ cid: "QmWSSAgmLtfVsRawHU2Uf72Xw4hM5T5Jcx2n7EVmEHQD1E",
1344
1351
  authorizedCidHex: cidToHex(
1345
- "QmadmdFDH6sS7YLusUuuLkkt7n51iUj1bJ5KKTLhmro2iQ"
1352
+ "QmWSSAgmLtfVsRawHU2Uf72Xw4hM5T5Jcx2n7EVmEHQD1E"
1346
1353
  ),
1347
1354
  name: "Process Payment Validator",
1348
1355
  description: "Production Process Payment Validator",
1349
1356
  version: "1.2.1",
1350
1357
  deployed: true,
1351
- deployedAt: 1784316520125,
1352
- size: 76534,
1353
- hash: "dbdf43d3f1636e0ee883d349ca28f24c5c38ed7e062b76ca75498aaf5fe594ea",
1358
+ deployedAt: 1785173245463,
1359
+ size: 77593,
1360
+ hash: "0f1015e51702abd9834e295ea12ac8dbd906909d25f72ad6a509c061e625c75d",
1354
1361
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1355
1362
  pkp: {
1356
1363
  publicKey: "0x04cfccb9b6c7addc79469c0e9fafebef4c70801302c62cdb26b610723a9b8527d23f98a40158c7340d83fd0e62d02b5ec74c12f7a86d98e8c6973b4811110f19ad",
@@ -1358,17 +1365,17 @@ var require_pkg_src = __commonJS({
1358
1365
  }
1359
1366
  },
1360
1367
  extendPositionValidator: {
1361
- cid: "QmespREceysQ7WPqGKg1VpHB3hf8zsreMY8HSjiQ2xoAN4",
1368
+ cid: "QmZyx9qUVyWu7deCJFLZxB1WDVRBgobs1Vm6m4ECGMbpkS",
1362
1369
  authorizedCidHex: cidToHex(
1363
- "QmespREceysQ7WPqGKg1VpHB3hf8zsreMY8HSjiQ2xoAN4"
1370
+ "QmZyx9qUVyWu7deCJFLZxB1WDVRBgobs1Vm6m4ECGMbpkS"
1364
1371
  ),
1365
1372
  name: "Extend Position Validator",
1366
1373
  description: "Production Extend Position Validator",
1367
1374
  version: "1.2.1",
1368
1375
  deployed: true,
1369
- deployedAt: 1784316534278,
1370
- size: 74352,
1371
- hash: "c17bfc9abef16f2372316a14c14281e2acc98afdd1662d095360f1d1c5383f1d",
1376
+ deployedAt: 1785173255906,
1377
+ size: 75372,
1378
+ hash: "545dc96a7e9b4d0aaadf239127b804a92df60b6b5b2fbb3203ef7de9ad97980a",
1372
1379
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1373
1380
  pkp: {
1374
1381
  publicKey: "0x04e52338f6a0c3362800f1a94c4c8f08be5030dde0fa217388c53d1c1a4790f4443c9f2886b2d2d8f4b75a9a156e9b028011b1a1cf7648da0e556aa980ec692836",
@@ -1376,17 +1383,17 @@ var require_pkg_src = __commonJS({
1376
1383
  }
1377
1384
  },
1378
1385
  btcWithdrawal: {
1379
- cid: "QmexvpfHPacjsVcqNHHLyJhSnnAPLgbWmWd9N3NDLDvYds",
1386
+ cid: "QmXKsozVz832mvU5xgvFnAAms1kfQrHAKj1areHfkDkoK7",
1380
1387
  authorizedCidHex: cidToHex(
1381
- "QmexvpfHPacjsVcqNHHLyJhSnnAPLgbWmWd9N3NDLDvYds"
1388
+ "QmXKsozVz832mvU5xgvFnAAms1kfQrHAKj1areHfkDkoK7"
1382
1389
  ),
1383
1390
  name: "Btc Withdrawal",
1384
1391
  description: "Production Btc Withdrawal",
1385
- version: "1.2.3",
1392
+ version: "1.2.1",
1386
1393
  deployed: true,
1387
- deployedAt: 1784585746901,
1388
- size: 92027,
1389
- hash: "7b4f4eab1f0c08b8b5b1c9cdb1064dd403ec13f57765919f62dec67fb8ba3c69",
1394
+ deployedAt: 1785173260209,
1395
+ size: 92692,
1396
+ hash: "18ade8e4f0c79896eee613d16c86de135f1d3daaa0fa056bcdbcaa0dff793c77",
1390
1397
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1391
1398
  pkp: {
1392
1399
  publicKey: "0x043616787c5432415c24378c4ef48de2bcd6bb7b575b837e3cff09171802662da7105d79586c7659677a0ecbaddac4cce06cb2a11f69a16fa0c4d7002ac7d51a4d",
@@ -1394,17 +1401,17 @@ var require_pkg_src = __commonJS({
1394
1401
  }
1395
1402
  },
1396
1403
  liquidationValidator: {
1397
- cid: "QmZJnGq2HEYW1XYZPSodyRCrbDhTcLDT8x4z76EiPg8Xcx",
1404
+ cid: "Qme6aGADhiszkQbZL977E6nmBacd2PEB7K9Hs8puVrscNx",
1398
1405
  authorizedCidHex: cidToHex(
1399
- "QmZJnGq2HEYW1XYZPSodyRCrbDhTcLDT8x4z76EiPg8Xcx"
1406
+ "Qme6aGADhiszkQbZL977E6nmBacd2PEB7K9Hs8puVrscNx"
1400
1407
  ),
1401
1408
  name: "Liquidation Validator",
1402
1409
  description: "Production Liquidation Validator",
1403
1410
  version: "1.2.1",
1404
1411
  deployed: true,
1405
- deployedAt: 1784316560010,
1406
- size: 66523,
1407
- hash: "f74d0163c47d7db04d1547f72c3a9bc1e5b499669089cc6464479a361462ce81",
1412
+ deployedAt: 1785173262533,
1413
+ size: 66846,
1414
+ hash: "b35ee7706d733d625faa4dbe37f73c8e20f0c1befa897cd7875e827de52003de",
1408
1415
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1409
1416
  pkp: {
1410
1417
  publicKey: "0x041a241de58976c13e3d7ca5a18e494f7330151e3818706135d50176e78ffb673e58b11f0b67a87c73fade6c6b27d6e7a7377ea9f4c10bf31880f1d725f18cc6f8",
@@ -1430,17 +1437,17 @@ var require_pkg_src = __commonJS({
1430
1437
  }
1431
1438
  },
1432
1439
  loanVaultBtcBalance: {
1433
- cid: "QmVKSkgY8e5X6v6yRD4H2wpU2oX2kbeKYh4fjPepg71mqu",
1440
+ cid: "QmaeQoHYvcMYobNbu9hQavGDudi8AXoW9tg3YHrvy1g2A4",
1434
1441
  authorizedCidHex: cidToHex(
1435
- "QmVKSkgY8e5X6v6yRD4H2wpU2oX2kbeKYh4fjPepg71mqu"
1442
+ "QmaeQoHYvcMYobNbu9hQavGDudi8AXoW9tg3YHrvy1g2A4"
1436
1443
  ),
1437
1444
  name: "Loan Vault Btc Balance",
1438
1445
  description: "Production Loan Vault Btc Balance",
1439
1446
  version: "1.2.1",
1440
1447
  deployed: true,
1441
- deployedAt: 1784316574669,
1442
- size: 56477,
1443
- hash: "917535f2911055b2ade2204fd868dd8b7294c7ade23e82aea488aeb0872e35d7",
1448
+ deployedAt: 1785173271802,
1449
+ size: 56800,
1450
+ hash: "a059133214e6ba0a73d655a15600c4b33e361fb340c98f8eecaf8ab7b95aaf83",
1444
1451
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1445
1452
  pkp: {
1446
1453
  publicKey: "0x043616787c5432415c24378c4ef48de2bcd6bb7b575b837e3cff09171802662da7105d79586c7659677a0ecbaddac4cce06cb2a11f69a16fa0c4d7002ac7d51a4d",
@@ -1454,17 +1461,17 @@ var require_pkg_src = __commonJS({
1454
1461
  // Requires BitcoinProviderRegistry.addAllowedCid(chainId, keccak256(utf8(cid)))
1455
1462
  // on each target chain (the action decrypts registry slots). No OAR entry.
1456
1463
  btcAddressBalance: {
1457
- cid: "QmcYFLDbhQArk5gQK44Xj8CnYEAbnaNsei92sUHpRuFmZA",
1464
+ cid: "QmUXUtU9r1HhQVYgkXPN5s19SKXanhn4pMsCtFEP3GK4Kj",
1458
1465
  authorizedCidHex: cidToHex(
1459
- "QmcYFLDbhQArk5gQK44Xj8CnYEAbnaNsei92sUHpRuFmZA"
1466
+ "QmUXUtU9r1HhQVYgkXPN5s19SKXanhn4pMsCtFEP3GK4Kj"
1460
1467
  ),
1461
1468
  name: "Btc Address Balance",
1462
1469
  description: "Address-only signed total BTC balance via registry consensus (no positionId, no price)",
1463
1470
  version: "0.2.1",
1464
1471
  deployed: true,
1465
- deployedAt: 1784316590403,
1466
- size: 26986,
1467
- hash: "49fb14265f3208916f12806df04492900bd08fb1b14d9651ee6278cd9ae4a428",
1472
+ deployedAt: 1785173280221,
1473
+ size: 27309,
1474
+ hash: "f0d08938713d9d89a56a3a386cacbc2b57afd5ad367ea82d827d40e1bfc70989",
1468
1475
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1469
1476
  pkp: {
1470
1477
  publicKey: "0x0498cbb31facfa26e3ec83ccdabfe4fe341ca0282e0c3cb81da7113723b9726e1e49efa92165cc3faa66ced4454cea56dbab12267852d6525a55d7c4f128b912cd",
@@ -1498,17 +1505,17 @@ var require_pkg_src = __commonJS({
1498
1505
  hash: "03ee5be239c91c735d2c95db89a0d1b77e602cfc18af8eb64b3281fddcd90a72"
1499
1506
  },
1500
1507
  staleSpendRecoveryValidator: {
1501
- cid: "QmcLrhiM1JwVi5w3QFxBYi1V4DaFT3Kk9MhPywyMnTsEwK",
1508
+ cid: "QmXQWT8V4wjuvH8BbC7xrkYxsVu5AKfvfWcS7jnYfrexYm",
1502
1509
  authorizedCidHex: cidToHex(
1503
- "QmcLrhiM1JwVi5w3QFxBYi1V4DaFT3Kk9MhPywyMnTsEwK"
1510
+ "QmXQWT8V4wjuvH8BbC7xrkYxsVu5AKfvfWcS7jnYfrexYm"
1504
1511
  ),
1505
1512
  name: "Stale Spend Recovery Validator",
1506
1513
  description: "Production Stale Spend Recovery Validator",
1507
1514
  version: "1.1.2",
1508
1515
  deployed: true,
1509
- deployedAt: 1784316604502,
1510
- size: 36785,
1511
- hash: "28bfe44970541fefe3bae8bd54f25e8775d7cc61b5832a40ba1c18587b6b6358",
1516
+ deployedAt: 1785173285829,
1517
+ size: 37108,
1518
+ hash: "04de5fc5b6f5131dc1544e3d3d187a1f9ef9616ffd12483d119f9102b3671791",
1512
1519
  validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
1513
1520
  pkp: {
1514
1521
  publicKey: "0x046da0ad6da7dd4a0063cbeac6f2bdb6a9889c2178b23470833356a8ee5630f7f0eee0db348d9d9aaaadd23eccf0063c8f68ee5e446abe30b882bf1de4c932bc21",
@@ -1516,17 +1523,17 @@ var require_pkg_src = __commonJS({
1516
1523
  }
1517
1524
  },
1518
1525
  btcUtxoInvalidator: {
1519
- cid: "QmRue1EAjuJwCDTtTH4czdkkmDEfNpT7iudvwtjaRs6AdA",
1526
+ cid: "Qmc9W2dgGpRax5Q2nXw8ciGF9RHjWj1y9v2MMWNbrCwnZb",
1520
1527
  authorizedCidHex: cidToHex(
1521
- "QmRue1EAjuJwCDTtTH4czdkkmDEfNpT7iudvwtjaRs6AdA"
1528
+ "Qmc9W2dgGpRax5Q2nXw8ciGF9RHjWj1y9v2MMWNbrCwnZb"
1522
1529
  ),
1523
1530
  name: "Btc Utxo Invalidator",
1524
1531
  description: "Production Btc Utxo Invalidator",
1525
1532
  version: "1.0.0",
1526
1533
  deployed: true,
1527
- deployedAt: 1784801043540,
1528
- size: 60717,
1529
- hash: "2ca9736edf3d54bba7445491920cba28429029c32a2f2830cad831a37a3cb310"
1534
+ deployedAt: 1785173292828,
1535
+ size: 61410,
1536
+ hash: "9ca3817ea626b4ebca184e20cae827a8a982f48d6cd1497e81bb4469aa282627"
1530
1537
  }
1531
1538
  };
1532
1539
  function getDeploymentsForNetwork(network) {
@@ -2272,7 +2279,7 @@ ${errorReport}`);
2272
2279
  }
2273
2280
  init_debug_logger();
2274
2281
  init_session_signature_cache();
2275
- var import_ethers17 = __require("ethers");
2282
+ var import_ethers18 = __require("ethers");
2276
2283
  var EXPIRED_LOAN_MIN_LIQUIDATION_THRESHOLD_BPS = 11e3;
2277
2284
  var GRACE_PERIOD_DAYS = 30;
2278
2285
  var SATOSHIS_PER_BITCOIN = 100000000n;
@@ -5046,6 +5053,7 @@ ${auth.clientId}`;
5046
5053
  ],
5047
5054
  allowArbitraryBitcoinProvider: true,
5048
5055
  allowArbitraryEvmRpc: true,
5056
+ pinContractAddresses: false,
5049
5057
  allowDevSinglePriceProvider: true,
5050
5058
  minBitcoinBalanceConfirmations: 1,
5051
5059
  minBitcoinSpendConfirmations: 1,
@@ -5066,6 +5074,7 @@ ${auth.clientId}`;
5066
5074
  ],
5067
5075
  allowArbitraryBitcoinProvider: false,
5068
5076
  allowArbitraryEvmRpc: false,
5077
+ pinContractAddresses: true,
5069
5078
  allowDevSinglePriceProvider: false,
5070
5079
  minBitcoinBalanceConfirmations: 1,
5071
5080
  minBitcoinSpendConfirmations: 1,
@@ -5086,6 +5095,7 @@ ${auth.clientId}`;
5086
5095
  ],
5087
5096
  allowArbitraryBitcoinProvider: false,
5088
5097
  allowArbitraryEvmRpc: false,
5098
+ pinContractAddresses: true,
5089
5099
  allowDevSinglePriceProvider: false,
5090
5100
  minBitcoinBalanceConfirmations: 6,
5091
5101
  minBitcoinSpendConfirmations: 6,
@@ -5102,12 +5112,12 @@ ${auth.clientId}`;
5102
5112
  }
5103
5113
  async function executeVaultSnapshot(params) {
5104
5114
  global.ethers = {
5105
- ...import_ethers17.ethers,
5115
+ ...import_ethers18.ethers,
5106
5116
  providers: {
5107
- StaticJsonRpcProvider: import_ethers17.ethers.JsonRpcProvider
5117
+ StaticJsonRpcProvider: import_ethers18.ethers.JsonRpcProvider
5108
5118
  },
5109
- Contract: import_ethers17.ethers.Contract,
5110
- utils: import_ethers17.ethers
5119
+ Contract: import_ethers18.ethers.Contract,
5120
+ utils: import_ethers18.ethers
5111
5121
  // v6 moved utils to top level
5112
5122
  };
5113
5123
  global.Lit = {
@@ -5379,7 +5389,9 @@ function getSepoliaConfig() {
5379
5389
  feeRecipientRegistry: SEPOLIA_CONTRACTS.FeeRecipientRegistry || "",
5380
5390
  positionDelegateRegistry: SEPOLIA_CONTRACTS.PositionDelegateRegistry || "",
5381
5391
  bitcoinWithdrawalAddressRegistry: SEPOLIA_CONTRACTS.BitcoinWithdrawalAddressRegistry || "",
5382
- carryAgentRegistry: SEPOLIA_CONTRACTS.CarryAgentRegistry || ""
5392
+ carryAgentRegistry: SEPOLIA_CONTRACTS.CarryAgentRegistry || "",
5393
+ agentDelegationRegistry: SEPOLIA_CONTRACTS.AgentDelegationRegistry || "",
5394
+ dhAgentDelegate: SEPOLIA_CONTRACTS.DHAgentDelegate || ""
5383
5395
  },
5384
5396
  subgraphs: {
5385
5397
  // Lazy getter for the same module-init snapshot reason as serviceEndpoint.
@@ -5420,7 +5432,9 @@ function getMainnetConfig() {
5420
5432
  feeRecipientRegistry: MAINNET_CONTRACTS.FeeRecipientRegistry || "",
5421
5433
  positionDelegateRegistry: MAINNET_CONTRACTS.PositionDelegateRegistry || "",
5422
5434
  bitcoinWithdrawalAddressRegistry: MAINNET_CONTRACTS.BitcoinWithdrawalAddressRegistry || "",
5423
- carryAgentRegistry: MAINNET_CONTRACTS.CarryAgentRegistry || ""
5435
+ carryAgentRegistry: MAINNET_CONTRACTS.CarryAgentRegistry || "",
5436
+ agentDelegationRegistry: MAINNET_CONTRACTS.AgentDelegationRegistry || "",
5437
+ dhAgentDelegate: MAINNET_CONTRACTS.DHAgentDelegate || ""
5424
5438
  },
5425
5439
  subgraphs: {
5426
5440
  diamondHandsUrl: "https://gateway-arbitrum.network.thegraph.com/api/subgraphs/id/CCTPsdYqco2jChDLLBQTbdJWwoukVoMt1cXeR9ti6r9A"
@@ -5565,7 +5579,7 @@ var init_network_configs = __esm({
5565
5579
  });
5566
5580
 
5567
5581
  // src/modules/diamond-hands-sdk.ts
5568
- import { Contract as Contract6, Interface as Interface4, JsonRpcProvider, AbiCoder as AbiCoder2, keccak256 as keccak2566, solidityPackedKeccak256 as solidityPackedKeccak2565, toUtf8Bytes as toUtf8Bytes6, getBytes as getBytes5, zeroPadValue as zeroPadValue5, toBeHex as toBeHex2, parseEther, formatEther, formatUnits, computeAddress, Signature, ZeroHash, ZeroAddress as ZeroAddress3, MaxUint256 } from "ethers";
5582
+ import { Contract as Contract9, Interface as Interface5, JsonRpcProvider, AbiCoder as AbiCoder2, keccak256 as keccak2566, solidityPackedKeccak256 as solidityPackedKeccak2565, toUtf8Bytes as toUtf8Bytes6, getBytes as getBytes5, zeroPadValue as zeroPadValue5, toBeHex as toBeHex2, parseEther, formatEther, formatUnits, computeAddress, Signature, ZeroHash, ZeroAddress as ZeroAddress3, MaxUint256 } from "ethers";
5569
5583
 
5570
5584
  // src/types/result.ts
5571
5585
  function success(value) {
@@ -9083,7 +9097,7 @@ function createPKPManager(config) {
9083
9097
  }
9084
9098
 
9085
9099
  // src/modules/loan/loan-creator.module.ts
9086
- import { Interface as Interface2, zeroPadValue as zeroPadValue4, toBeHex, SigningKey } from "ethers";
9100
+ import { Contract as Contract3, Interface as Interface2, zeroPadValue as zeroPadValue4, toBeHex, SigningKey } from "ethers";
9087
9101
  var import_dh_lit_actions = __toESM(require_pkg_src());
9088
9102
  var LoanCreator = class {
9089
9103
  config;
@@ -9346,7 +9360,14 @@ var LoanCreator = class {
9346
9360
  if (!positionIdResult.success) {
9347
9361
  return failure(positionIdResult.error);
9348
9362
  }
9349
- const positionId = positionIdResult.value;
9363
+ const confirmedIdResult = await this.confirmPositionId(
9364
+ receipt,
9365
+ positionIdResult.value
9366
+ );
9367
+ if (!confirmedIdResult.success) {
9368
+ return failure(confirmedIdResult.error);
9369
+ }
9370
+ const positionId = confirmedIdResult.value;
9350
9371
  const result = {
9351
9372
  success: true,
9352
9373
  transactionHash: receipt.hash,
@@ -9497,8 +9518,9 @@ var LoanCreator = class {
9497
9518
  hash: tx.hash
9498
9519
  });
9499
9520
  }
9521
+ const confirmations = await this.createPositionConfirmations();
9500
9522
  const receipt = await Promise.race([
9501
- tx.wait(1),
9523
+ tx.wait(confirmations),
9502
9524
  new Promise(
9503
9525
  (_, reject) => setTimeout(
9504
9526
  () => reject(new Error("Transaction confirmation timeout")),
@@ -9620,6 +9642,88 @@ var LoanCreator = class {
9620
9642
  );
9621
9643
  }
9622
9644
  }
9645
+ /**
9646
+ * Confirmation depth to wait for before trusting `positionId` from a receipt.
9647
+ *
9648
+ * Deeper is safer but slower, so local chains (instant mining, no reorgs) stay at 1.
9649
+ * Override with `createPositionConfirmations` when a chain needs more.
9650
+ */
9651
+ async createPositionConfirmations() {
9652
+ const configured = this.config.createPositionConfirmations;
9653
+ if (typeof configured === "number" && configured >= 1)
9654
+ return configured;
9655
+ try {
9656
+ const network = await this.config.contractManager.getProvider().getNetwork();
9657
+ const chainId = Number(network.chainId);
9658
+ if (chainId === 31337 || chainId === 1337)
9659
+ return 1;
9660
+ } catch {
9661
+ }
9662
+ return 3;
9663
+ }
9664
+ /**
9665
+ * Re-read the receipt after confirmations and re-derive `positionId`, so a reorg
9666
+ * cannot leave the caller holding an id that never survived to the canonical chain.
9667
+ *
9668
+ * Returns the authoritative id. If the re-read disagrees with what was first
9669
+ * extracted, the fresh value wins and the divergence is logged loudly — silently
9670
+ * returning a phantom id is how this surfaced as a `PositionNotFound()` hundreds of
9671
+ * lines downstream, long after the real cause.
9672
+ */
9673
+ async confirmPositionId(receipt, extractedId) {
9674
+ let authoritativeId = extractedId;
9675
+ try {
9676
+ const provider = this.config.contractManager.getProvider();
9677
+ const fresh = await provider.getTransactionReceipt(receipt.hash);
9678
+ if (!fresh) {
9679
+ return failure(
9680
+ new SDKError({
9681
+ message: `Loan creation receipt ${receipt.hash} is no longer on-chain after confirmation (dropped or reorged). The position, if any, must be rediscovered before use.`,
9682
+ category: "CONTRACT" /* CONTRACT */,
9683
+ severity: "HIGH" /* HIGH */,
9684
+ originalError: new Error("Receipt vanished after confirmation")
9685
+ })
9686
+ );
9687
+ }
9688
+ const reExtracted = this.extractPositionId(
9689
+ fresh
9690
+ );
9691
+ if (reExtracted.success && reExtracted.value !== extractedId) {
9692
+ log.warn(
9693
+ "\u26A0\uFE0F positionId changed after confirmation \u2014 the block was reorged and the transaction re-executed with a different block.timestamp/positionCounter. Using the canonical value.",
9694
+ { transactionHash: receipt.hash, before: extractedId, after: reExtracted.value }
9695
+ );
9696
+ authoritativeId = reExtracted.value;
9697
+ }
9698
+ } catch (e) {
9699
+ log.warn("Could not re-read loan creation receipt for confirmation", {
9700
+ error: e?.message ?? String(e)
9701
+ });
9702
+ }
9703
+ const coreAddress = this.config.contractManager.getContractAddresses().positionManagerCore;
9704
+ if (coreAddress) {
9705
+ try {
9706
+ const core = new Contract3(
9707
+ coreAddress,
9708
+ [
9709
+ "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status))"
9710
+ ],
9711
+ this.config.contractManager.getProvider()
9712
+ );
9713
+ await core.getFunction("getPositionDetails")(authoritativeId);
9714
+ } catch {
9715
+ return failure(
9716
+ new SDKError({
9717
+ message: `Loan creation reported positionId ${authoritativeId}, but no such position exists on-chain (tx ${receipt.hash}). This usually means the block was reorged after the receipt was read. Retry loan creation; do not use this id.`,
9718
+ category: "CONTRACT" /* CONTRACT */,
9719
+ severity: "HIGH" /* HIGH */,
9720
+ originalError: new Error("positionId not found on-chain after creation")
9721
+ })
9722
+ );
9723
+ }
9724
+ }
9725
+ return success(authoritativeId);
9726
+ }
9623
9727
  /**
9624
9728
  * Extract position ID from transaction receipt
9625
9729
  */
@@ -9736,7 +9840,7 @@ var LoanStatus = /* @__PURE__ */ ((LoanStatus2) => {
9736
9840
  })(LoanStatus || {});
9737
9841
 
9738
9842
  // src/modules/loan/loan-query.module.ts
9739
- import { Contract as Contract3 } from "ethers";
9843
+ import { Contract as Contract4 } from "ethers";
9740
9844
  var POSITION_CORE_ABI = [
9741
9845
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
9742
9846
  ];
@@ -10034,7 +10138,7 @@ var LoanQuery = class {
10034
10138
  const isChipotlePkpId2 = typeof rawId === "string" && rawId.length === 40 && !rawId.toLowerCase().startsWith("04");
10035
10139
  if (isChipotlePkpId2) {
10036
10140
  if (this.config.positionManagerCoreAddress && this.config.provider) {
10037
- const pmContract = new Contract3(
10141
+ const pmContract = new Contract4(
10038
10142
  this.config.positionManagerCoreAddress,
10039
10143
  POSITION_CORE_ABI,
10040
10144
  this.config.provider
@@ -13439,7 +13543,7 @@ var DiamondHandsGraph = class {
13439
13543
 
13440
13544
  // src/contracts/typechain-contracts/factories/src/psm/SimplePSMV2__factory.ts
13441
13545
  import {
13442
- Contract as Contract5,
13546
+ Contract as Contract6,
13443
13547
  ContractFactory,
13444
13548
  Interface as Interface3
13445
13549
  } from "ethers";
@@ -16033,205 +16137,1984 @@ var SimplePSMV2__factory = class extends ContractFactory {
16033
16137
  return new Interface3(_abi);
16034
16138
  }
16035
16139
  static connect(address, runner) {
16036
- return new Contract5(address, _abi, runner);
16140
+ return new Contract6(address, _abi, runner);
16037
16141
  }
16038
16142
  };
16039
16143
 
16040
- // src/modules/mock/mock-token-manager.module.ts
16041
- var MockTokenManager = class {
16042
- config;
16043
- constructor(config) {
16044
- this.config = config;
16045
- if (this.isProductionNetwork()) {
16046
- log.warn("\u26A0\uFE0F MockTokenManager initialized on production network", {
16047
- network: config.network
16048
- });
16049
- }
16050
- }
16051
- /**
16052
- * Mint mock BTC tokens
16053
- *
16054
- * @param amount - Amount to mint in satoshis
16055
- * @param recipient - Recipient address
16056
- * @returns Transaction result
16057
- */
16058
- async mintMockBTC(amount, recipient) {
16059
- if (this.config.debug) {
16060
- log.info("\u{1FA99} Minting mock BTC", {
16061
- amount: amount.toString(),
16062
- recipient
16063
- });
16064
- }
16065
- if (this.isProductionNetwork()) {
16066
- return failure(
16067
- new SDKError({
16068
- message: "Cannot mint mock tokens on production network",
16069
- category: "CONFIGURATION" /* CONFIGURATION */,
16070
- severity: "HIGH" /* HIGH */,
16071
- originalError: new Error("Production network detected")
16072
- })
16073
- );
16074
- }
16075
- return tryCatchAsync(
16076
- async () => {
16077
- const signerResult = this.config.contractManager.getSigner();
16078
- if (!signerResult.success) {
16079
- throw signerResult.error;
16080
- }
16081
- throw new Error("Mock BTC contract not yet integrated");
16082
- },
16083
- (error) => new SDKError({
16084
- message: "Failed to mint mock BTC",
16085
- category: "CONTRACT" /* CONTRACT */,
16086
- severity: "MEDIUM" /* MEDIUM */,
16087
- originalError: error instanceof Error ? error : new Error(String(error)),
16088
- context: { amount: amount.toString(), recipient }
16089
- })
16090
- );
16091
- }
16092
- /**
16093
- * Approve mock BTC spending
16094
- *
16095
- * @param spender - Spender address
16096
- * @param amount - Amount to approve in satoshis
16097
- * @returns Transaction result
16098
- */
16099
- async approveMockBTC(spender, amount) {
16100
- if (this.config.debug) {
16101
- log.info("\u2705 Approving mock BTC spending", {
16102
- spender,
16103
- amount: amount.toString()
16104
- });
16105
- }
16106
- if (this.isProductionNetwork()) {
16107
- return failure(
16108
- new SDKError({
16109
- message: "Cannot approve mock tokens on production network",
16110
- category: "CONFIGURATION" /* CONFIGURATION */,
16111
- severity: "HIGH" /* HIGH */,
16112
- originalError: new Error("Production network detected")
16113
- })
16114
- );
16115
- }
16116
- return tryCatchAsync(
16117
- async () => {
16118
- const signerResult = this.config.contractManager.getSigner();
16119
- if (!signerResult.success) {
16120
- throw signerResult.error;
16121
- }
16122
- throw new Error("Mock BTC contract not yet integrated");
16123
- },
16124
- (error) => new SDKError({
16125
- message: "Failed to approve mock BTC",
16126
- category: "CONTRACT" /* CONTRACT */,
16127
- severity: "MEDIUM" /* MEDIUM */,
16128
- originalError: error instanceof Error ? error : new Error(String(error)),
16129
- context: { spender, amount: amount.toString() }
16130
- })
16131
- );
16132
- }
16133
- /**
16134
- * Get mock BTC balance
16135
- *
16136
- * @param address - Address to query
16137
- * @returns Balance in satoshis
16138
- */
16139
- async getMockBTCBalance(address) {
16140
- if (this.config.debug) {
16141
- log.info("\u{1F50D} Querying mock BTC balance", { address });
16142
- }
16143
- return tryCatchAsync(
16144
- async () => {
16145
- throw new Error("Mock BTC contract not yet integrated");
16144
+ // src/contracts/typechain-contracts/factories/src/agent/AgentDelegationRegistry__factory.ts
16145
+ import {
16146
+ Contract as Contract7,
16147
+ ContractFactory as ContractFactory2,
16148
+ Interface as Interface4
16149
+ } from "ethers";
16150
+ var _abi2 = [
16151
+ {
16152
+ inputs: [],
16153
+ stateMutability: "nonpayable",
16154
+ type: "constructor"
16155
+ },
16156
+ {
16157
+ inputs: [],
16158
+ name: "AccessControlBadConfirmation",
16159
+ type: "error"
16160
+ },
16161
+ {
16162
+ inputs: [
16163
+ {
16164
+ internalType: "address",
16165
+ name: "account",
16166
+ type: "address"
16146
16167
  },
16147
- (error) => new SDKError({
16148
- message: "Failed to get mock BTC balance",
16149
- category: "CONTRACT" /* CONTRACT */,
16150
- severity: "MEDIUM" /* MEDIUM */,
16151
- originalError: error instanceof Error ? error : new Error(String(error)),
16152
- context: { address }
16153
- })
16154
- );
16155
- }
16156
- /**
16157
- * Check if current network is production (mainnet)
16158
- */
16159
- isProductionNetwork() {
16160
- return this.config.network.toLowerCase().includes("mainnet");
16161
- }
16162
- };
16163
- function createMockTokenManager(config) {
16164
- try {
16165
- const manager = new MockTokenManager(config);
16166
- return success(manager);
16167
- } catch (error) {
16168
- return failure(
16169
- new SDKError({
16170
- message: "Failed to create MockTokenManager",
16171
- category: "INITIALIZATION" /* INITIALIZATION */,
16172
- severity: "HIGH" /* HIGH */,
16173
- originalError: error instanceof Error ? error : new Error(String(error))
16174
- })
16175
- );
16176
- }
16177
- }
16178
-
16179
- // src/modules/diamond-hands-sdk.ts
16180
- var import_dh_lit_actions2 = __toESM(require_pkg_src());
16181
- import { LitOps, broadcastSignedBitcoinTransaction } from "@gvnrdao/dh-lit-ops";
16182
-
16183
- // src/utils/telegram-messaging.utils.ts
16184
- var TelegramBot = null;
16185
- try {
16186
- if (typeof window === "undefined" && typeof global !== "undefined") {
16187
- TelegramBot = __require("node-telegram-bot-api");
16188
- }
16189
- } catch (error) {
16190
- log.warn("Telegram bot API not available", {
16191
- error: error instanceof Error ? error.message : String(error)
16192
- });
16193
- }
16194
- function formatMintMessage(mintAmount, loanId, txHash) {
16195
- return `\u2705 DH SDK: ${mintAmount} UCD was minted for loan id: ${loanId} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
16196
- }
16197
- function formatPartialPaymentMessage(paymentAmount, loanId, txHash) {
16198
- return `\u2705 DH SDK: ${paymentAmount} UCD was repaid for loan id: ${loanId} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
16199
- }
16200
- function formatPartialPaymentFailureMessage(paymentAmount, loanId, txHash) {
16201
- const baseMessage = `\u274C DH SDK: FAILED to repay ${paymentAmount} UCD for loan id: ${loanId}`;
16202
- if (txHash) {
16203
- return `${baseMessage} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
16204
- }
16205
- return baseMessage;
16206
- }
16207
- function formatLoanCreationMessage(positionId, pkpId, vaultAddress) {
16208
- const vault = vaultAddress || "unknown";
16209
- return `\u2705 DH SDK: A new loan was created Id: ${positionId} Pkp: ${pkpId} Regtest BTC vault: ${vault}`;
16210
- }
16211
- function formatBTCWithdrawalFailureMessage(withdrawalAmount, btcVault, btcDestinationAddress, loanId) {
16212
- const formattedAmount = formatBTCAmount(withdrawalAmount);
16213
- return `\u274C DH SDK: BTC withdrawal FAILED: ${formattedAmount} from ${btcVault} to ${btcDestinationAddress} for loan id: ${loanId}`;
16214
- }
16215
- function formatLoanRenewalMessage(positionId, txHash) {
16216
- return `\u2705 DH SDK: Loan id ${positionId} was successfully renewed. Tx: https://sepolia.etherscan.io/tx/${txHash}`;
16217
- }
16218
- function formatLoanRenewalFailureMessage(loanId, error) {
16219
- return `\u274C DH SDK: FAILED to renew loan id ${loanId} ${error}`;
16220
- }
16221
- function formatBalanceConfirmationMessage(loanId) {
16222
- return `\u2705 DH SDK: Loan id: ${loanId} was updated to PENDING_MINT`;
16223
- }
16224
- function formatBalanceConfirmationFailureMessage(loanId) {
16225
- return `\u274C DH SDK: FAILED to update to PENDING_MINT for loan id ${loanId}`;
16226
- }
16227
- function formatBTCWithdrawalSuccessMessage(withdrawalAmount, btcVault, btcDestinationAddress, loanId, btcTxId) {
16228
- const formattedAmount = formatBTCAmount(withdrawalAmount);
16229
- const txSuffix = btcTxId ? ` (tx: ${btcTxId})` : "";
16230
- return `\u2705 DH SDK: BTC withdrawal SUCCEEDED: ${formattedAmount} sent from ${btcVault} to ${btcDestinationAddress} for loan id: ${loanId}${txSuffix}`;
16231
- }
16232
- function formatLiquidationSkippedMessage(loanId, ratio, threshold, btcVault, btcVaultBalance, ucdDebt, btcPrice) {
16233
- const formattedPrice = formatBTCPrice(btcPrice);
16234
- const formattedBalance = formatBTCAmount(btcVaultBalance);
16168
+ {
16169
+ internalType: "bytes32",
16170
+ name: "neededRole",
16171
+ type: "bytes32"
16172
+ }
16173
+ ],
16174
+ name: "AccessControlUnauthorizedAccount",
16175
+ type: "error"
16176
+ },
16177
+ {
16178
+ inputs: [
16179
+ {
16180
+ internalType: "address",
16181
+ name: "target",
16182
+ type: "address"
16183
+ }
16184
+ ],
16185
+ name: "AddressEmptyCode",
16186
+ type: "error"
16187
+ },
16188
+ {
16189
+ inputs: [],
16190
+ name: "AgentAddressReused",
16191
+ type: "error"
16192
+ },
16193
+ {
16194
+ inputs: [],
16195
+ name: "AgentIsActiveUseRotate",
16196
+ type: "error"
16197
+ },
16198
+ {
16199
+ inputs: [],
16200
+ name: "AgentNotActive",
16201
+ type: "error"
16202
+ },
16203
+ {
16204
+ inputs: [],
16205
+ name: "CannotUpgradeToSelf",
16206
+ type: "error"
16207
+ },
16208
+ {
16209
+ inputs: [
16210
+ {
16211
+ internalType: "address",
16212
+ name: "implementation",
16213
+ type: "address"
16214
+ }
16215
+ ],
16216
+ name: "ERC1967InvalidImplementation",
16217
+ type: "error"
16218
+ },
16219
+ {
16220
+ inputs: [],
16221
+ name: "ERC1967NonPayable",
16222
+ type: "error"
16223
+ },
16224
+ {
16225
+ inputs: [],
16226
+ name: "EnforcedPause",
16227
+ type: "error"
16228
+ },
16229
+ {
16230
+ inputs: [],
16231
+ name: "ExceedsMaxTtl",
16232
+ type: "error"
16233
+ },
16234
+ {
16235
+ inputs: [],
16236
+ name: "ExpectedPause",
16237
+ type: "error"
16238
+ },
16239
+ {
16240
+ inputs: [],
16241
+ name: "FailedCall",
16242
+ type: "error"
16243
+ },
16244
+ {
16245
+ inputs: [],
16246
+ name: "FloorBelowProtocolMin",
16247
+ type: "error"
16248
+ },
16249
+ {
16250
+ inputs: [],
16251
+ name: "ImplementationNotDeployed",
16252
+ type: "error"
16253
+ },
16254
+ {
16255
+ inputs: [],
16256
+ name: "InvalidAddress",
16257
+ type: "error"
16258
+ },
16259
+ {
16260
+ inputs: [],
16261
+ name: "InvalidFloor",
16262
+ type: "error"
16263
+ },
16264
+ {
16265
+ inputs: [],
16266
+ name: "InvalidInitialization",
16267
+ type: "error"
16268
+ },
16269
+ {
16270
+ inputs: [],
16271
+ name: "InvalidPositionId",
16272
+ type: "error"
16273
+ },
16274
+ {
16275
+ inputs: [],
16276
+ name: "NoActiveAgent",
16277
+ type: "error"
16278
+ },
16279
+ {
16280
+ inputs: [],
16281
+ name: "NotAdminModule",
16282
+ type: "error"
16283
+ },
16284
+ {
16285
+ inputs: [],
16286
+ name: "NotAuthorizedConsumer",
16287
+ type: "error"
16288
+ },
16289
+ {
16290
+ inputs: [],
16291
+ name: "NotBorrowerOrRegistrar",
16292
+ type: "error"
16293
+ },
16294
+ {
16295
+ inputs: [],
16296
+ name: "NotContract",
16297
+ type: "error"
16298
+ },
16299
+ {
16300
+ inputs: [],
16301
+ name: "NotInitializing",
16302
+ type: "error"
16303
+ },
16304
+ {
16305
+ inputs: [],
16306
+ name: "NotUserOrRegistrar",
16307
+ type: "error"
16308
+ },
16309
+ {
16310
+ inputs: [],
16311
+ name: "PositionNotActive",
16312
+ type: "error"
16313
+ },
16314
+ {
16315
+ inputs: [],
16316
+ name: "PositionNotDelegable",
16317
+ type: "error"
16318
+ },
16319
+ {
16320
+ inputs: [],
16321
+ name: "RenewalCapReached",
16322
+ type: "error"
16323
+ },
16324
+ {
16325
+ inputs: [],
16326
+ name: "ScopeNotGranted",
16327
+ type: "error"
16328
+ },
16329
+ {
16330
+ inputs: [],
16331
+ name: "UUPSUnauthorizedCallContext",
16332
+ type: "error"
16333
+ },
16334
+ {
16335
+ inputs: [
16336
+ {
16337
+ internalType: "bytes32",
16338
+ name: "slot",
16339
+ type: "bytes32"
16340
+ }
16341
+ ],
16342
+ name: "UUPSUnsupportedProxiableUUID",
16343
+ type: "error"
16344
+ },
16345
+ {
16346
+ inputs: [],
16347
+ name: "UnauthorizedUnpause",
16348
+ type: "error"
16349
+ },
16350
+ {
16351
+ inputs: [],
16352
+ name: "UnexpectedRoleGrantFailure",
16353
+ type: "error"
16354
+ },
16355
+ {
16356
+ inputs: [],
16357
+ name: "ValidUntilInPast",
16358
+ type: "error"
16359
+ },
16360
+ {
16361
+ anonymous: false,
16362
+ inputs: [
16363
+ {
16364
+ indexed: true,
16365
+ internalType: "address",
16366
+ name: "oldAdminModule",
16367
+ type: "address"
16368
+ },
16369
+ {
16370
+ indexed: true,
16371
+ internalType: "address",
16372
+ name: "newAdminModule",
16373
+ type: "address"
16374
+ }
16375
+ ],
16376
+ name: "AdminModuleUpdated",
16377
+ type: "event"
16378
+ },
16379
+ {
16380
+ anonymous: false,
16381
+ inputs: [
16382
+ {
16383
+ indexed: false,
16384
+ internalType: "uint32",
16385
+ name: "oldBps",
16386
+ type: "uint32"
16387
+ },
16388
+ {
16389
+ indexed: false,
16390
+ internalType: "uint32",
16391
+ name: "newBps",
16392
+ type: "uint32"
16393
+ }
16394
+ ],
16395
+ name: "AgentMintFloorMinUpdated",
16396
+ type: "event"
16397
+ },
16398
+ {
16399
+ anonymous: false,
16400
+ inputs: [
16401
+ {
16402
+ indexed: true,
16403
+ internalType: "address",
16404
+ name: "user",
16405
+ type: "address"
16406
+ },
16407
+ {
16408
+ indexed: true,
16409
+ internalType: "address",
16410
+ name: "agent",
16411
+ type: "address"
16412
+ },
16413
+ {
16414
+ indexed: false,
16415
+ internalType: "uint64",
16416
+ name: "validUntil",
16417
+ type: "uint64"
16418
+ }
16419
+ ],
16420
+ name: "AgentRegistered",
16421
+ type: "event"
16422
+ },
16423
+ {
16424
+ anonymous: false,
16425
+ inputs: [
16426
+ {
16427
+ indexed: true,
16428
+ internalType: "address",
16429
+ name: "user",
16430
+ type: "address"
16431
+ },
16432
+ {
16433
+ indexed: true,
16434
+ internalType: "address",
16435
+ name: "agent",
16436
+ type: "address"
16437
+ },
16438
+ {
16439
+ indexed: false,
16440
+ internalType: "bytes32",
16441
+ name: "reason",
16442
+ type: "bytes32"
16443
+ }
16444
+ ],
16445
+ name: "AgentRevoked",
16446
+ type: "event"
16447
+ },
16448
+ {
16449
+ anonymous: false,
16450
+ inputs: [
16451
+ {
16452
+ indexed: true,
16453
+ internalType: "address",
16454
+ name: "user",
16455
+ type: "address"
16456
+ },
16457
+ {
16458
+ indexed: true,
16459
+ internalType: "address",
16460
+ name: "oldAgent",
16461
+ type: "address"
16462
+ },
16463
+ {
16464
+ indexed: true,
16465
+ internalType: "address",
16466
+ name: "newAgent",
16467
+ type: "address"
16468
+ },
16469
+ {
16470
+ indexed: false,
16471
+ internalType: "uint64",
16472
+ name: "validUntil",
16473
+ type: "uint64"
16474
+ }
16475
+ ],
16476
+ name: "AgentRotated",
16477
+ type: "event"
16478
+ },
16479
+ {
16480
+ anonymous: false,
16481
+ inputs: [
16482
+ {
16483
+ indexed: true,
16484
+ internalType: "address",
16485
+ name: "previous",
16486
+ type: "address"
16487
+ },
16488
+ {
16489
+ indexed: true,
16490
+ internalType: "address",
16491
+ name: "next",
16492
+ type: "address"
16493
+ }
16494
+ ],
16495
+ name: "AuthorizedConsumerUpdated",
16496
+ type: "event"
16497
+ },
16498
+ {
16499
+ anonymous: false,
16500
+ inputs: [
16501
+ {
16502
+ indexed: true,
16503
+ internalType: "bytes32",
16504
+ name: "positionId",
16505
+ type: "bytes32"
16506
+ },
16507
+ {
16508
+ indexed: true,
16509
+ internalType: "address",
16510
+ name: "borrower",
16511
+ type: "address"
16512
+ }
16513
+ ],
16514
+ name: "AutoMintDisabled",
16515
+ type: "event"
16516
+ },
16517
+ {
16518
+ anonymous: false,
16519
+ inputs: [
16520
+ {
16521
+ indexed: true,
16522
+ internalType: "bytes32",
16523
+ name: "positionId",
16524
+ type: "bytes32"
16525
+ },
16526
+ {
16527
+ indexed: true,
16528
+ internalType: "address",
16529
+ name: "borrower",
16530
+ type: "address"
16531
+ },
16532
+ {
16533
+ indexed: false,
16534
+ internalType: "uint32",
16535
+ name: "minCollateralRatioBps",
16536
+ type: "uint32"
16537
+ }
16538
+ ],
16539
+ name: "AutoMintEnabled",
16540
+ type: "event"
16541
+ },
16542
+ {
16543
+ anonymous: false,
16544
+ inputs: [
16545
+ {
16546
+ indexed: true,
16547
+ internalType: "bytes32",
16548
+ name: "positionId",
16549
+ type: "bytes32"
16550
+ },
16551
+ {
16552
+ indexed: true,
16553
+ internalType: "address",
16554
+ name: "borrower",
16555
+ type: "address"
16556
+ }
16557
+ ],
16558
+ name: "AutoRenewDisabled",
16559
+ type: "event"
16560
+ },
16561
+ {
16562
+ anonymous: false,
16563
+ inputs: [
16564
+ {
16565
+ indexed: true,
16566
+ internalType: "bytes32",
16567
+ name: "positionId",
16568
+ type: "bytes32"
16569
+ },
16570
+ {
16571
+ indexed: true,
16572
+ internalType: "address",
16573
+ name: "borrower",
16574
+ type: "address"
16575
+ },
16576
+ {
16577
+ indexed: false,
16578
+ internalType: "uint32",
16579
+ name: "maxRenewals",
16580
+ type: "uint32"
16581
+ },
16582
+ {
16583
+ indexed: false,
16584
+ internalType: "uint40",
16585
+ name: "maxEndTimestamp",
16586
+ type: "uint40"
16587
+ }
16588
+ ],
16589
+ name: "AutoRenewEnabled",
16590
+ type: "event"
16591
+ },
16592
+ {
16593
+ anonymous: false,
16594
+ inputs: [
16595
+ {
16596
+ indexed: true,
16597
+ internalType: "bytes32",
16598
+ name: "positionId",
16599
+ type: "bytes32"
16600
+ },
16601
+ {
16602
+ indexed: true,
16603
+ internalType: "address",
16604
+ name: "borrower",
16605
+ type: "address"
16606
+ }
16607
+ ],
16608
+ name: "AutoRepayDisabled",
16609
+ type: "event"
16610
+ },
16611
+ {
16612
+ anonymous: false,
16613
+ inputs: [
16614
+ {
16615
+ indexed: true,
16616
+ internalType: "bytes32",
16617
+ name: "positionId",
16618
+ type: "bytes32"
16619
+ },
16620
+ {
16621
+ indexed: true,
16622
+ internalType: "address",
16623
+ name: "borrower",
16624
+ type: "address"
16625
+ }
16626
+ ],
16627
+ name: "AutoRepayEnabled",
16628
+ type: "event"
16629
+ },
16630
+ {
16631
+ anonymous: false,
16632
+ inputs: [
16633
+ {
16634
+ indexed: true,
16635
+ internalType: "address",
16636
+ name: "caller",
16637
+ type: "address"
16638
+ },
16639
+ {
16640
+ indexed: false,
16641
+ internalType: "uint256",
16642
+ name: "timestamp",
16643
+ type: "uint256"
16644
+ }
16645
+ ],
16646
+ name: "ContractPaused",
16647
+ type: "event"
16648
+ },
16649
+ {
16650
+ anonymous: false,
16651
+ inputs: [
16652
+ {
16653
+ indexed: true,
16654
+ internalType: "address",
16655
+ name: "caller",
16656
+ type: "address"
16657
+ },
16658
+ {
16659
+ indexed: false,
16660
+ internalType: "uint256",
16661
+ name: "timestamp",
16662
+ type: "uint256"
16663
+ }
16664
+ ],
16665
+ name: "ContractUnpaused",
16666
+ type: "event"
16667
+ },
16668
+ {
16669
+ anonymous: false,
16670
+ inputs: [
16671
+ {
16672
+ indexed: true,
16673
+ internalType: "address",
16674
+ name: "oldImplementation",
16675
+ type: "address"
16676
+ },
16677
+ {
16678
+ indexed: true,
16679
+ internalType: "address",
16680
+ name: "newImplementation",
16681
+ type: "address"
16682
+ },
16683
+ {
16684
+ indexed: false,
16685
+ internalType: "string",
16686
+ name: "version",
16687
+ type: "string"
16688
+ },
16689
+ {
16690
+ indexed: false,
16691
+ internalType: "uint256",
16692
+ name: "timestamp",
16693
+ type: "uint256"
16694
+ }
16695
+ ],
16696
+ name: "ContractUpgraded",
16697
+ type: "event"
16698
+ },
16699
+ {
16700
+ anonymous: false,
16701
+ inputs: [
16702
+ {
16703
+ indexed: false,
16704
+ internalType: "uint64",
16705
+ name: "version",
16706
+ type: "uint64"
16707
+ }
16708
+ ],
16709
+ name: "Initialized",
16710
+ type: "event"
16711
+ },
16712
+ {
16713
+ anonymous: false,
16714
+ inputs: [
16715
+ {
16716
+ indexed: false,
16717
+ internalType: "uint64",
16718
+ name: "oldTtl",
16719
+ type: "uint64"
16720
+ },
16721
+ {
16722
+ indexed: false,
16723
+ internalType: "uint64",
16724
+ name: "newTtl",
16725
+ type: "uint64"
16726
+ }
16727
+ ],
16728
+ name: "MaxAgentTtlUpdated",
16729
+ type: "event"
16730
+ },
16731
+ {
16732
+ anonymous: false,
16733
+ inputs: [
16734
+ {
16735
+ indexed: true,
16736
+ internalType: "bytes32",
16737
+ name: "positionId",
16738
+ type: "bytes32"
16739
+ },
16740
+ {
16741
+ indexed: false,
16742
+ internalType: "uint32",
16743
+ name: "oldFloorBps",
16744
+ type: "uint32"
16745
+ },
16746
+ {
16747
+ indexed: false,
16748
+ internalType: "uint32",
16749
+ name: "newFloorBps",
16750
+ type: "uint32"
16751
+ }
16752
+ ],
16753
+ name: "MintCollateralFloorUpdated",
16754
+ type: "event"
16755
+ },
16756
+ {
16757
+ anonymous: false,
16758
+ inputs: [
16759
+ {
16760
+ indexed: false,
16761
+ internalType: "address",
16762
+ name: "account",
16763
+ type: "address"
16764
+ }
16765
+ ],
16766
+ name: "Paused",
16767
+ type: "event"
16768
+ },
16769
+ {
16770
+ anonymous: false,
16771
+ inputs: [
16772
+ {
16773
+ indexed: true,
16774
+ internalType: "bytes32",
16775
+ name: "positionId",
16776
+ type: "bytes32"
16777
+ },
16778
+ {
16779
+ indexed: false,
16780
+ internalType: "uint32",
16781
+ name: "renewalsUsed",
16782
+ type: "uint32"
16783
+ }
16784
+ ],
16785
+ name: "RenewalRecorded",
16786
+ type: "event"
16787
+ },
16788
+ {
16789
+ anonymous: false,
16790
+ inputs: [
16791
+ {
16792
+ indexed: true,
16793
+ internalType: "bytes32",
16794
+ name: "role",
16795
+ type: "bytes32"
16796
+ },
16797
+ {
16798
+ indexed: true,
16799
+ internalType: "bytes32",
16800
+ name: "previousAdminRole",
16801
+ type: "bytes32"
16802
+ },
16803
+ {
16804
+ indexed: true,
16805
+ internalType: "bytes32",
16806
+ name: "newAdminRole",
16807
+ type: "bytes32"
16808
+ }
16809
+ ],
16810
+ name: "RoleAdminChanged",
16811
+ type: "event"
16812
+ },
16813
+ {
16814
+ anonymous: false,
16815
+ inputs: [
16816
+ {
16817
+ indexed: true,
16818
+ internalType: "bytes32",
16819
+ name: "role",
16820
+ type: "bytes32"
16821
+ },
16822
+ {
16823
+ indexed: true,
16824
+ internalType: "address",
16825
+ name: "account",
16826
+ type: "address"
16827
+ },
16828
+ {
16829
+ indexed: true,
16830
+ internalType: "address",
16831
+ name: "sender",
16832
+ type: "address"
16833
+ }
16834
+ ],
16835
+ name: "RoleGranted",
16836
+ type: "event"
16837
+ },
16838
+ {
16839
+ anonymous: false,
16840
+ inputs: [
16841
+ {
16842
+ indexed: true,
16843
+ internalType: "bytes32",
16844
+ name: "role",
16845
+ type: "bytes32"
16846
+ },
16847
+ {
16848
+ indexed: true,
16849
+ internalType: "address",
16850
+ name: "account",
16851
+ type: "address"
16852
+ },
16853
+ {
16854
+ indexed: true,
16855
+ internalType: "address",
16856
+ name: "sender",
16857
+ type: "address"
16858
+ }
16859
+ ],
16860
+ name: "RoleRevoked",
16861
+ type: "event"
16862
+ },
16863
+ {
16864
+ anonymous: false,
16865
+ inputs: [
16866
+ {
16867
+ indexed: false,
16868
+ internalType: "address",
16869
+ name: "account",
16870
+ type: "address"
16871
+ }
16872
+ ],
16873
+ name: "Unpaused",
16874
+ type: "event"
16875
+ },
16876
+ {
16877
+ anonymous: false,
16878
+ inputs: [
16879
+ {
16880
+ indexed: true,
16881
+ internalType: "address",
16882
+ name: "implementation",
16883
+ type: "address"
16884
+ }
16885
+ ],
16886
+ name: "Upgraded",
16887
+ type: "event"
16888
+ },
16889
+ {
16890
+ inputs: [],
16891
+ name: "DEFAULT_ADMIN_ROLE",
16892
+ outputs: [
16893
+ {
16894
+ internalType: "bytes32",
16895
+ name: "",
16896
+ type: "bytes32"
16897
+ }
16898
+ ],
16899
+ stateMutability: "view",
16900
+ type: "function"
16901
+ },
16902
+ {
16903
+ inputs: [],
16904
+ name: "EMERGENCY_PAUSE_ROLE",
16905
+ outputs: [
16906
+ {
16907
+ internalType: "bytes32",
16908
+ name: "",
16909
+ type: "bytes32"
16910
+ }
16911
+ ],
16912
+ stateMutability: "view",
16913
+ type: "function"
16914
+ },
16915
+ {
16916
+ inputs: [],
16917
+ name: "REGISTRAR_ROLE",
16918
+ outputs: [
16919
+ {
16920
+ internalType: "bytes32",
16921
+ name: "",
16922
+ type: "bytes32"
16923
+ }
16924
+ ],
16925
+ stateMutability: "view",
16926
+ type: "function"
16927
+ },
16928
+ {
16929
+ inputs: [],
16930
+ name: "SCOPE_MINT",
16931
+ outputs: [
16932
+ {
16933
+ internalType: "uint32",
16934
+ name: "",
16935
+ type: "uint32"
16936
+ }
16937
+ ],
16938
+ stateMutability: "view",
16939
+ type: "function"
16940
+ },
16941
+ {
16942
+ inputs: [],
16943
+ name: "SCOPE_RENEW",
16944
+ outputs: [
16945
+ {
16946
+ internalType: "uint32",
16947
+ name: "",
16948
+ type: "uint32"
16949
+ }
16950
+ ],
16951
+ stateMutability: "view",
16952
+ type: "function"
16953
+ },
16954
+ {
16955
+ inputs: [],
16956
+ name: "SCOPE_REPAY",
16957
+ outputs: [
16958
+ {
16959
+ internalType: "uint32",
16960
+ name: "",
16961
+ type: "uint32"
16962
+ }
16963
+ ],
16964
+ stateMutability: "view",
16965
+ type: "function"
16966
+ },
16967
+ {
16968
+ inputs: [],
16969
+ name: "UPGRADE_INTERFACE_VERSION",
16970
+ outputs: [
16971
+ {
16972
+ internalType: "string",
16973
+ name: "",
16974
+ type: "string"
16975
+ }
16976
+ ],
16977
+ stateMutability: "view",
16978
+ type: "function"
16979
+ },
16980
+ {
16981
+ inputs: [],
16982
+ name: "VERSION",
16983
+ outputs: [
16984
+ {
16985
+ internalType: "string",
16986
+ name: "",
16987
+ type: "string"
16988
+ }
16989
+ ],
16990
+ stateMutability: "view",
16991
+ type: "function"
16992
+ },
16993
+ {
16994
+ inputs: [],
16995
+ name: "adminModule",
16996
+ outputs: [
16997
+ {
16998
+ internalType: "address",
16999
+ name: "",
17000
+ type: "address"
17001
+ }
17002
+ ],
17003
+ stateMutability: "view",
17004
+ type: "function"
17005
+ },
17006
+ {
17007
+ inputs: [],
17008
+ name: "agentMintFloorMinBps",
17009
+ outputs: [
17010
+ {
17011
+ internalType: "uint32",
17012
+ name: "",
17013
+ type: "uint32"
17014
+ }
17015
+ ],
17016
+ stateMutability: "view",
17017
+ type: "function"
17018
+ },
17019
+ {
17020
+ inputs: [
17021
+ {
17022
+ internalType: "address",
17023
+ name: "user",
17024
+ type: "address"
17025
+ }
17026
+ ],
17027
+ name: "agentOf",
17028
+ outputs: [
17029
+ {
17030
+ components: [
17031
+ {
17032
+ internalType: "address",
17033
+ name: "agent",
17034
+ type: "address"
17035
+ },
17036
+ {
17037
+ internalType: "uint64",
17038
+ name: "validUntil",
17039
+ type: "uint64"
17040
+ },
17041
+ {
17042
+ internalType: "enum IAgentDelegateRegistryBase.AgentStatus",
17043
+ name: "status",
17044
+ type: "uint8"
17045
+ },
17046
+ {
17047
+ internalType: "uint64",
17048
+ name: "registeredAt",
17049
+ type: "uint64"
17050
+ },
17051
+ {
17052
+ internalType: "uint64",
17053
+ name: "revokedAt",
17054
+ type: "uint64"
17055
+ }
17056
+ ],
17057
+ internalType: "struct IAgentDelegateRegistryBase.AgentRecord",
17058
+ name: "",
17059
+ type: "tuple"
17060
+ }
17061
+ ],
17062
+ stateMutability: "view",
17063
+ type: "function"
17064
+ },
17065
+ {
17066
+ inputs: [],
17067
+ name: "authorizedConsumer",
17068
+ outputs: [
17069
+ {
17070
+ internalType: "address",
17071
+ name: "",
17072
+ type: "address"
17073
+ }
17074
+ ],
17075
+ stateMutability: "view",
17076
+ type: "function"
17077
+ },
17078
+ {
17079
+ inputs: [
17080
+ {
17081
+ internalType: "bytes32",
17082
+ name: "positionId",
17083
+ type: "bytes32"
17084
+ },
17085
+ {
17086
+ internalType: "address",
17087
+ name: "caller",
17088
+ type: "address"
17089
+ }
17090
+ ],
17091
+ name: "canMint",
17092
+ outputs: [
17093
+ {
17094
+ internalType: "bool",
17095
+ name: "ok",
17096
+ type: "bool"
17097
+ },
17098
+ {
17099
+ internalType: "enum IAgentDelegationRegistry.DenyReason",
17100
+ name: "reason",
17101
+ type: "uint8"
17102
+ },
17103
+ {
17104
+ internalType: "uint32",
17105
+ name: "effectiveFloorBps",
17106
+ type: "uint32"
17107
+ }
17108
+ ],
17109
+ stateMutability: "view",
17110
+ type: "function"
17111
+ },
17112
+ {
17113
+ inputs: [
17114
+ {
17115
+ internalType: "bytes32",
17116
+ name: "positionId",
17117
+ type: "bytes32"
17118
+ },
17119
+ {
17120
+ internalType: "address",
17121
+ name: "caller",
17122
+ type: "address"
17123
+ }
17124
+ ],
17125
+ name: "canRenew",
17126
+ outputs: [
17127
+ {
17128
+ internalType: "bool",
17129
+ name: "ok",
17130
+ type: "bool"
17131
+ },
17132
+ {
17133
+ internalType: "enum IAgentDelegationRegistry.DenyReason",
17134
+ name: "reason",
17135
+ type: "uint8"
17136
+ }
17137
+ ],
17138
+ stateMutability: "view",
17139
+ type: "function"
17140
+ },
17141
+ {
17142
+ inputs: [
17143
+ {
17144
+ internalType: "bytes32",
17145
+ name: "positionId",
17146
+ type: "bytes32"
17147
+ },
17148
+ {
17149
+ internalType: "address",
17150
+ name: "caller",
17151
+ type: "address"
17152
+ }
17153
+ ],
17154
+ name: "canRepay",
17155
+ outputs: [
17156
+ {
17157
+ internalType: "bool",
17158
+ name: "ok",
17159
+ type: "bool"
17160
+ },
17161
+ {
17162
+ internalType: "enum IAgentDelegationRegistry.DenyReason",
17163
+ name: "reason",
17164
+ type: "uint8"
17165
+ }
17166
+ ],
17167
+ stateMutability: "view",
17168
+ type: "function"
17169
+ },
17170
+ {
17171
+ inputs: [],
17172
+ name: "core",
17173
+ outputs: [
17174
+ {
17175
+ internalType: "contract IPositionManagerCore",
17176
+ name: "",
17177
+ type: "address"
17178
+ }
17179
+ ],
17180
+ stateMutability: "view",
17181
+ type: "function"
17182
+ },
17183
+ {
17184
+ inputs: [
17185
+ {
17186
+ internalType: "bytes32",
17187
+ name: "positionId",
17188
+ type: "bytes32"
17189
+ }
17190
+ ],
17191
+ name: "disableAutoMint",
17192
+ outputs: [],
17193
+ stateMutability: "nonpayable",
17194
+ type: "function"
17195
+ },
17196
+ {
17197
+ inputs: [
17198
+ {
17199
+ internalType: "bytes32",
17200
+ name: "positionId",
17201
+ type: "bytes32"
17202
+ }
17203
+ ],
17204
+ name: "disableAutoRenew",
17205
+ outputs: [],
17206
+ stateMutability: "nonpayable",
17207
+ type: "function"
17208
+ },
17209
+ {
17210
+ inputs: [
17211
+ {
17212
+ internalType: "bytes32",
17213
+ name: "positionId",
17214
+ type: "bytes32"
17215
+ }
17216
+ ],
17217
+ name: "disableAutoRepay",
17218
+ outputs: [],
17219
+ stateMutability: "nonpayable",
17220
+ type: "function"
17221
+ },
17222
+ {
17223
+ inputs: [
17224
+ {
17225
+ internalType: "bytes32",
17226
+ name: "positionId",
17227
+ type: "bytes32"
17228
+ },
17229
+ {
17230
+ internalType: "uint32",
17231
+ name: "minCollateralRatioBps",
17232
+ type: "uint32"
17233
+ }
17234
+ ],
17235
+ name: "enableAutoMint",
17236
+ outputs: [],
17237
+ stateMutability: "nonpayable",
17238
+ type: "function"
17239
+ },
17240
+ {
17241
+ inputs: [
17242
+ {
17243
+ internalType: "bytes32",
17244
+ name: "positionId",
17245
+ type: "bytes32"
17246
+ },
17247
+ {
17248
+ internalType: "uint32",
17249
+ name: "maxRenewals",
17250
+ type: "uint32"
17251
+ },
17252
+ {
17253
+ internalType: "uint40",
17254
+ name: "maxEndTimestamp",
17255
+ type: "uint40"
17256
+ }
17257
+ ],
17258
+ name: "enableAutoRenew",
17259
+ outputs: [],
17260
+ stateMutability: "nonpayable",
17261
+ type: "function"
17262
+ },
17263
+ {
17264
+ inputs: [
17265
+ {
17266
+ internalType: "bytes32",
17267
+ name: "positionId",
17268
+ type: "bytes32"
17269
+ }
17270
+ ],
17271
+ name: "enableAutoRepay",
17272
+ outputs: [],
17273
+ stateMutability: "nonpayable",
17274
+ type: "function"
17275
+ },
17276
+ {
17277
+ inputs: [
17278
+ {
17279
+ internalType: "bytes32",
17280
+ name: "positionId",
17281
+ type: "bytes32"
17282
+ }
17283
+ ],
17284
+ name: "getLoanGrant",
17285
+ outputs: [
17286
+ {
17287
+ components: [
17288
+ {
17289
+ internalType: "address",
17290
+ name: "borrower",
17291
+ type: "address"
17292
+ },
17293
+ {
17294
+ internalType: "uint32",
17295
+ name: "scopeBits",
17296
+ type: "uint32"
17297
+ },
17298
+ {
17299
+ internalType: "uint32",
17300
+ name: "maxRenewals",
17301
+ type: "uint32"
17302
+ },
17303
+ {
17304
+ internalType: "uint32",
17305
+ name: "renewalsUsed",
17306
+ type: "uint32"
17307
+ },
17308
+ {
17309
+ internalType: "uint40",
17310
+ name: "maxEndTimestamp",
17311
+ type: "uint40"
17312
+ },
17313
+ {
17314
+ internalType: "uint32",
17315
+ name: "minCollateralRatioBps",
17316
+ type: "uint32"
17317
+ }
17318
+ ],
17319
+ internalType: "struct IAgentDelegationRegistry.LoanGrant",
17320
+ name: "",
17321
+ type: "tuple"
17322
+ }
17323
+ ],
17324
+ stateMutability: "view",
17325
+ type: "function"
17326
+ },
17327
+ {
17328
+ inputs: [
17329
+ {
17330
+ internalType: "bytes32",
17331
+ name: "role",
17332
+ type: "bytes32"
17333
+ }
17334
+ ],
17335
+ name: "getRoleAdmin",
17336
+ outputs: [
17337
+ {
17338
+ internalType: "bytes32",
17339
+ name: "",
17340
+ type: "bytes32"
17341
+ }
17342
+ ],
17343
+ stateMutability: "view",
17344
+ type: "function"
17345
+ },
17346
+ {
17347
+ inputs: [
17348
+ {
17349
+ internalType: "bytes32",
17350
+ name: "role",
17351
+ type: "bytes32"
17352
+ },
17353
+ {
17354
+ internalType: "uint256",
17355
+ name: "index",
17356
+ type: "uint256"
17357
+ }
17358
+ ],
17359
+ name: "getRoleMember",
17360
+ outputs: [
17361
+ {
17362
+ internalType: "address",
17363
+ name: "",
17364
+ type: "address"
17365
+ }
17366
+ ],
17367
+ stateMutability: "view",
17368
+ type: "function"
17369
+ },
17370
+ {
17371
+ inputs: [
17372
+ {
17373
+ internalType: "bytes32",
17374
+ name: "role",
17375
+ type: "bytes32"
17376
+ }
17377
+ ],
17378
+ name: "getRoleMemberCount",
17379
+ outputs: [
17380
+ {
17381
+ internalType: "uint256",
17382
+ name: "",
17383
+ type: "uint256"
17384
+ }
17385
+ ],
17386
+ stateMutability: "view",
17387
+ type: "function"
17388
+ },
17389
+ {
17390
+ inputs: [
17391
+ {
17392
+ internalType: "bytes32",
17393
+ name: "role",
17394
+ type: "bytes32"
17395
+ }
17396
+ ],
17397
+ name: "getRoleMembers",
17398
+ outputs: [
17399
+ {
17400
+ internalType: "address[]",
17401
+ name: "",
17402
+ type: "address[]"
17403
+ }
17404
+ ],
17405
+ stateMutability: "view",
17406
+ type: "function"
17407
+ },
17408
+ {
17409
+ inputs: [
17410
+ {
17411
+ internalType: "bytes32",
17412
+ name: "role",
17413
+ type: "bytes32"
17414
+ },
17415
+ {
17416
+ internalType: "address",
17417
+ name: "account",
17418
+ type: "address"
17419
+ }
17420
+ ],
17421
+ name: "grantRole",
17422
+ outputs: [],
17423
+ stateMutability: "nonpayable",
17424
+ type: "function"
17425
+ },
17426
+ {
17427
+ inputs: [
17428
+ {
17429
+ internalType: "bytes32",
17430
+ name: "role",
17431
+ type: "bytes32"
17432
+ },
17433
+ {
17434
+ internalType: "address",
17435
+ name: "account",
17436
+ type: "address"
17437
+ }
17438
+ ],
17439
+ name: "hasRole",
17440
+ outputs: [
17441
+ {
17442
+ internalType: "bool",
17443
+ name: "",
17444
+ type: "bool"
17445
+ }
17446
+ ],
17447
+ stateMutability: "view",
17448
+ type: "function"
17449
+ },
17450
+ {
17451
+ inputs: [
17452
+ {
17453
+ internalType: "address",
17454
+ name: "admin",
17455
+ type: "address"
17456
+ },
17457
+ {
17458
+ internalType: "address",
17459
+ name: "adminModule_",
17460
+ type: "address"
17461
+ },
17462
+ {
17463
+ internalType: "address",
17464
+ name: "registrar",
17465
+ type: "address"
17466
+ },
17467
+ {
17468
+ internalType: "address",
17469
+ name: "pauser",
17470
+ type: "address"
17471
+ },
17472
+ {
17473
+ internalType: "contract IPositionManagerCore",
17474
+ name: "core_",
17475
+ type: "address"
17476
+ }
17477
+ ],
17478
+ name: "initialize",
17479
+ outputs: [],
17480
+ stateMutability: "nonpayable",
17481
+ type: "function"
17482
+ },
17483
+ {
17484
+ inputs: [
17485
+ {
17486
+ internalType: "uint32",
17487
+ name: "floorMinBps",
17488
+ type: "uint32"
17489
+ }
17490
+ ],
17491
+ name: "initializeV2",
17492
+ outputs: [],
17493
+ stateMutability: "nonpayable",
17494
+ type: "function"
17495
+ },
17496
+ {
17497
+ inputs: [
17498
+ {
17499
+ internalType: "address",
17500
+ name: "user",
17501
+ type: "address"
17502
+ }
17503
+ ],
17504
+ name: "isAgentActive",
17505
+ outputs: [
17506
+ {
17507
+ internalType: "bool",
17508
+ name: "",
17509
+ type: "bool"
17510
+ }
17511
+ ],
17512
+ stateMutability: "view",
17513
+ type: "function"
17514
+ },
17515
+ {
17516
+ inputs: [
17517
+ {
17518
+ internalType: "address",
17519
+ name: "",
17520
+ type: "address"
17521
+ }
17522
+ ],
17523
+ name: "keyOfAgent",
17524
+ outputs: [
17525
+ {
17526
+ internalType: "bytes32",
17527
+ name: "",
17528
+ type: "bytes32"
17529
+ }
17530
+ ],
17531
+ stateMutability: "view",
17532
+ type: "function"
17533
+ },
17534
+ {
17535
+ inputs: [],
17536
+ name: "maxAgentTtl",
17537
+ outputs: [
17538
+ {
17539
+ internalType: "uint64",
17540
+ name: "",
17541
+ type: "uint64"
17542
+ }
17543
+ ],
17544
+ stateMutability: "view",
17545
+ type: "function"
17546
+ },
17547
+ {
17548
+ inputs: [],
17549
+ name: "pause",
17550
+ outputs: [],
17551
+ stateMutability: "nonpayable",
17552
+ type: "function"
17553
+ },
17554
+ {
17555
+ inputs: [],
17556
+ name: "paused",
17557
+ outputs: [
17558
+ {
17559
+ internalType: "bool",
17560
+ name: "",
17561
+ type: "bool"
17562
+ }
17563
+ ],
17564
+ stateMutability: "view",
17565
+ type: "function"
17566
+ },
17567
+ {
17568
+ inputs: [],
17569
+ name: "proxiableUUID",
17570
+ outputs: [
17571
+ {
17572
+ internalType: "bytes32",
17573
+ name: "",
17574
+ type: "bytes32"
17575
+ }
17576
+ ],
17577
+ stateMutability: "view",
17578
+ type: "function"
17579
+ },
17580
+ {
17581
+ inputs: [
17582
+ {
17583
+ internalType: "bytes32",
17584
+ name: "positionId",
17585
+ type: "bytes32"
17586
+ }
17587
+ ],
17588
+ name: "recordRenewal",
17589
+ outputs: [],
17590
+ stateMutability: "nonpayable",
17591
+ type: "function"
17592
+ },
17593
+ {
17594
+ inputs: [
17595
+ {
17596
+ internalType: "address",
17597
+ name: "user",
17598
+ type: "address"
17599
+ },
17600
+ {
17601
+ internalType: "address",
17602
+ name: "agent",
17603
+ type: "address"
17604
+ },
17605
+ {
17606
+ internalType: "uint64",
17607
+ name: "validUntil",
17608
+ type: "uint64"
17609
+ }
17610
+ ],
17611
+ name: "registerAgent",
17612
+ outputs: [],
17613
+ stateMutability: "nonpayable",
17614
+ type: "function"
17615
+ },
17616
+ {
17617
+ inputs: [
17618
+ {
17619
+ internalType: "bytes32",
17620
+ name: "role",
17621
+ type: "bytes32"
17622
+ },
17623
+ {
17624
+ internalType: "address",
17625
+ name: "callerConfirmation",
17626
+ type: "address"
17627
+ }
17628
+ ],
17629
+ name: "renounceRole",
17630
+ outputs: [],
17631
+ stateMutability: "nonpayable",
17632
+ type: "function"
17633
+ },
17634
+ {
17635
+ inputs: [
17636
+ {
17637
+ internalType: "address",
17638
+ name: "user",
17639
+ type: "address"
17640
+ },
17641
+ {
17642
+ internalType: "bytes32",
17643
+ name: "reason",
17644
+ type: "bytes32"
17645
+ }
17646
+ ],
17647
+ name: "revokeAgent",
17648
+ outputs: [],
17649
+ stateMutability: "nonpayable",
17650
+ type: "function"
17651
+ },
17652
+ {
17653
+ inputs: [
17654
+ {
17655
+ internalType: "bytes32",
17656
+ name: "role",
17657
+ type: "bytes32"
17658
+ },
17659
+ {
17660
+ internalType: "address",
17661
+ name: "account",
17662
+ type: "address"
17663
+ }
17664
+ ],
17665
+ name: "revokeRole",
17666
+ outputs: [],
17667
+ stateMutability: "nonpayable",
17668
+ type: "function"
17669
+ },
17670
+ {
17671
+ inputs: [
17672
+ {
17673
+ internalType: "address",
17674
+ name: "user",
17675
+ type: "address"
17676
+ },
17677
+ {
17678
+ internalType: "address",
17679
+ name: "newAgent",
17680
+ type: "address"
17681
+ },
17682
+ {
17683
+ internalType: "uint64",
17684
+ name: "validUntil",
17685
+ type: "uint64"
17686
+ }
17687
+ ],
17688
+ name: "rotateAgent",
17689
+ outputs: [],
17690
+ stateMutability: "nonpayable",
17691
+ type: "function"
17692
+ },
17693
+ {
17694
+ inputs: [
17695
+ {
17696
+ internalType: "address",
17697
+ name: "newAdminModule",
17698
+ type: "address"
17699
+ }
17700
+ ],
17701
+ name: "setAdminModule",
17702
+ outputs: [],
17703
+ stateMutability: "nonpayable",
17704
+ type: "function"
17705
+ },
17706
+ {
17707
+ inputs: [
17708
+ {
17709
+ internalType: "uint32",
17710
+ name: "bps",
17711
+ type: "uint32"
17712
+ }
17713
+ ],
17714
+ name: "setAgentMintFloorMin",
17715
+ outputs: [],
17716
+ stateMutability: "nonpayable",
17717
+ type: "function"
17718
+ },
17719
+ {
17720
+ inputs: [
17721
+ {
17722
+ internalType: "address",
17723
+ name: "consumer",
17724
+ type: "address"
17725
+ }
17726
+ ],
17727
+ name: "setAuthorizedConsumer",
17728
+ outputs: [],
17729
+ stateMutability: "nonpayable",
17730
+ type: "function"
17731
+ },
17732
+ {
17733
+ inputs: [
17734
+ {
17735
+ internalType: "uint64",
17736
+ name: "newMaxAgentTtl",
17737
+ type: "uint64"
17738
+ }
17739
+ ],
17740
+ name: "setMaxAgentTtl",
17741
+ outputs: [],
17742
+ stateMutability: "nonpayable",
17743
+ type: "function"
17744
+ },
17745
+ {
17746
+ inputs: [
17747
+ {
17748
+ internalType: "bytes32",
17749
+ name: "positionId",
17750
+ type: "bytes32"
17751
+ },
17752
+ {
17753
+ internalType: "uint32",
17754
+ name: "newFloorBps",
17755
+ type: "uint32"
17756
+ }
17757
+ ],
17758
+ name: "setMintCollateralFloor",
17759
+ outputs: [],
17760
+ stateMutability: "nonpayable",
17761
+ type: "function"
17762
+ },
17763
+ {
17764
+ inputs: [
17765
+ {
17766
+ internalType: "bytes4",
17767
+ name: "interfaceId",
17768
+ type: "bytes4"
17769
+ }
17770
+ ],
17771
+ name: "supportsInterface",
17772
+ outputs: [
17773
+ {
17774
+ internalType: "bool",
17775
+ name: "",
17776
+ type: "bool"
17777
+ }
17778
+ ],
17779
+ stateMutability: "view",
17780
+ type: "function"
17781
+ },
17782
+ {
17783
+ inputs: [],
17784
+ name: "unpause",
17785
+ outputs: [],
17786
+ stateMutability: "nonpayable",
17787
+ type: "function"
17788
+ },
17789
+ {
17790
+ inputs: [
17791
+ {
17792
+ internalType: "address",
17793
+ name: "newImplementation",
17794
+ type: "address"
17795
+ },
17796
+ {
17797
+ internalType: "bytes",
17798
+ name: "data",
17799
+ type: "bytes"
17800
+ }
17801
+ ],
17802
+ name: "upgradeToAndCall",
17803
+ outputs: [],
17804
+ stateMutability: "payable",
17805
+ type: "function"
17806
+ },
17807
+ {
17808
+ inputs: [
17809
+ {
17810
+ internalType: "address",
17811
+ name: "agent",
17812
+ type: "address"
17813
+ }
17814
+ ],
17815
+ name: "userOfAgent",
17816
+ outputs: [
17817
+ {
17818
+ internalType: "address",
17819
+ name: "",
17820
+ type: "address"
17821
+ }
17822
+ ],
17823
+ stateMutability: "view",
17824
+ type: "function"
17825
+ }
17826
+ ];
17827
+ var _bytecode2 = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161308690816100f0823960805181818161121b015261140e0152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe608080604052600436101561001357600080fd5b60003560e01c90816301ffc9a7146120b4575080630d33f3c2146120905780630f3f4a94146120445780631459457a14611cfd578063188787e814611c2b57806318c38b8914611b1a5780631b02993114611aa65780631d44454114611a0b578063248a9ca3146119e55780632ec22d4c1461191c5780632f0647ce1461189d5780632f2ff15d1461186c57806336568abe14611826578063392f1087146117db5780633f4ba83a146116e35780633f5aadc9146116745780634f1ef28614611392578063523403631461129b5780635273b6f61461127257806352d1902d14611208578063554c4f4b14611178578063561b7f8a146110145780635bc26aea14610f875780635c975abb14610f575780636289d18c14610ed65780636711cc0b14610eba5780636e852a7814610da95780637e35bf6e14610d755780638343f67414610d485780638456cb5914610c525780638f33527f14610c185780639010d07c14610bc457806391d1485414610b6a5780639b9d30c114610b41578063a19af3f614610a7c578063a217fddf14610a60578063a3246ad31461099e578063a878086414610982578063ac3c0e3014610875578063ad3cb1cc1461082e578063b3fad6381461074b578063c34e9c261461072f578063c6fbbb87146105dd578063ca15c873146105a4578063d547741f1461056c578063dd71d99a1461052a578063e0922fa11461047d578063e187828314610454578063f2f4eb261461042b578063f68e955314610402578063fd437d39146102945763ffa1ad741461025b57600080fd5b3461028f57600036600319011261028f5761028b610277612282565b60405191829160208352602083019061225d565b0390f35b600080fd5b3461028f57606036600319011261028f576102ad612137565b6102b5612121565b906102be612224565b336000908152600080516020612f9a833981519152602052604090205490919060ff16156103db576001600160a01b031660008181526001602052604090208054939060e085901c60ff1660038110156103c5576001036103b45781600160209261034b877fc5d5c5bbf10444998e0ea6d4725e79027b574e1c14ec929279e8a9a95c6c6e919688612c79565b818060a01b038316828060a01b031982541617815561036a878261243b565b0180546001600160401b031916426001600160401b03908116919091179091556001600160a01b0391821660008181526002855260409081902087905551969091168652951693a4005b632437e77160e11b60005260046000fd5b634e487b7160e01b600052602160045260246000fd5b63e2517d3f60e01b6000523360045260008051602061301a83398151915260245260446000fd5b3461028f57600036600319011261028f57602060405160008051602061301a8339815191528152f35b3461028f57600036600319011261028f576003546040516001600160a01b039091168152602090f35b3461028f57600036600319011261028f576004546040516001600160a01b039091168152602090f35b3461028f57602036600319011261028f576004356001600160401b0381169081810361028f576000546001600160a01b038116330361051957600160a01b600160e01b0319811660a092831b600160a01b600160e01b031617600055604080519190921c6001600160401b0316815260208101929092527f9c195448332abd01f716db873b329752ea02f19d33f7e311fb0daf082c4edd0391a1005b6349db3bd360e01b60005260046000fd5b3461028f57602036600319011261028f576001600160a01b0361054b612137565b166000526002602052602060018060a01b0360406000205416604051908152f35b3461028f57604036600319011261028f576105a260043561058b612121565b9061059d61059882612302565b612a2c565b612abe565b005b3461028f57602036600319011261028f57600435600052600080516020612f1a8339815191526020526020604060002054604051908152f35b3461028f57602036600319011261028f5760043560018060a01b036004541633141580610708575b6106f757600081815260056020526040902080546001600160a01b038116156106e65760018160a01c16156106e65763ffffffff8160c01c1680151590816106d8575b506106c75760e01c6001019063ffffffff82116106b15780546001600160e01b031660e083901b6001600160e01b03191617905560405163ffffffff90911681527f859a3b34c0d733a1033c6089d4d18643a0705b707970a0d0d79c84423f089da190602090a2005b634e487b7160e01b600052601160045260246000fd5b638a6ea6bf60e01b60005260046000fd5b90508160e01c101584610648565b6360eb6c2360e01b60005260046000fd5b634b95b20b60e11b60005260046000fd5b50336000908152600080516020612f9a833981519152602052604090205460ff1615610605565b3461028f57600036600319011261028f57602060405160028152f35b3461028f57602036600319011261028f57600060a060405161076c816121cb565b8281528260208201528260408201528260608201528260808201520152600435600052600560205260c0604060002063ffffffff604051916107ad836121cb565b64ffffffffff8154938360018060a01b03861695868352816020840195818360a01c168752816001604087019282868e1c168452606088019560e01c86520154978160a060808901988a8c168a52019960281c1689526040519a8b52511660208a0152511660408801525116606086015251166080840152511660a0820152f35b3461028f57600036600319011261028f5761028b604080519061085181836121e6565b60058252640352e302e360dc1b60208301525191829160208352602083019061225d565b3461028f57602036600319011261028f5761088e612137565b6000608060405161089e8161219a565b828152826020820152826040820152826060820152015260018060a01b0316600052600160205260406000206040516108d68161219a565b81546001600160a01b038116825260a081901c6001600160401b03166020830190815292604083019160e01c60ff169060038210156103c557908252600101546001600160401b0380821660608501908152604092831c821660808601908152925194516001600160a01b03168552945116602084015290519260038410156103c557604083019390935291516001600160401b0390811660608301529151909116608082015260a090f35b3461028f57600036600319011261028f57602060405160018152f35b3461028f57602036600319011261028f57600435600052600080516020612f1a83398151915260205260406000206040518060208354918281520190819360005260206000209060005b818110610a4a57505050816109fe9103826121e6565b6040519182916020830190602084525180915260408301919060005b818110610a28575050500390f35b82516001600160a01b0316845285945060209384019390920191600101610a1a565b82548452602090930192600192830192016109e8565b3461028f57600036600319011261028f57602060405160008152f35b3461028f57604036600319011261028f57600435610a98612174565b90610aa1612639565b63ffffffff600654169163ffffffff811692808410908115610b38575b50610b275760206001610b147f1da95b87b4c773f68c1447ffc5644e41a8a8887d55065beb64852014cf7140be93610af586612684565b9390610b0e600463ffffffff835460a01c1617826122a5565b016122c8565b6040519485526001600160a01b031693a3005b634346c13160e01b60005260046000fd5b90501584610abe565b3461028f57600036600319011261028f576020604051600080516020612f5a8339815191528152f35b3461028f57604036600319011261028f57610b83612121565b600435600052600080516020612ffa83398151915260205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b3461028f57604036600319011261028f57600435600052600080516020612f1a8339815191526020526020610bff6024356040600020612d46565b905460405160039290921b1c6001600160a01b03168152f35b3461028f57602036600319011261028f576001600160a01b03610c39612137565b1660005260026020526020604060002054604051908152f35b3461028f57600036600319011261028f573360009081527f0ac8cc3d209806126662940717264973110c39045b305f6ba49613325a615e09602052604090205460ff1615610d2157610ca2612639565b600160ff1960008051602061303a83398151915254161760008051602061303a833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a2005b63e2517d3f60e01b60005233600452600080516020612f5a83398151915260245260446000fd5b3461028f57600036600319011261028f5760005460405160a09190911c6001600160401b03168152602090f35b3461028f57604036600319011261028f57610d99610d91612121565b6004356123a5565b9061028b6040519283928361215a565b3461028f57604036600319011261028f57610dc2612137565b336000908152600080516020612f9a833981519152602052604090205460ff161580610ea7575b610e97576001600160a01b03166000818152600160205260409020805460e01c60ff1660038110156103c5576001036103b457805460ff60e01b198116600160e11b1782556001919091018054600160401b600160801b03191642604090811b600160401b600160801b0316919091179091555160243581526001600160a01b0390911691907fc0499cc07ed9d734deec6857802d3f0fa8d5afaf79a7008beb8ba7bef62a271b90602090a3005b62fca64560e31b60005260046000fd5b50336001600160a01b0382161415610de9565b3461028f57600036600319011261028f57602060405160048152f35b3461028f57602036600319011261028f57610eef612187565b6000546001600160a01b031633036105195763ffffffff8116908115610f4657600080516020612fda83398151915291610f4163ffffffff9260065492841984161760065560405193849316836122eb565b0390a1005b6338f3377360e21b60005260046000fd5b3461028f57600036600319011261028f57602060ff60008051602061303a83398151915254166040519015158152f35b3461028f57602036600319011261028f57610fa0612137565b6000546001600160a01b0381169033829003610519576001600160a01b038316928315611003573b15610ff2576001600160a01b03191682176000908155600080516020612fba8339815191529080a3005b636f7c43f160e01b60005260046000fd5b63e6c4247b60e01b60005260046000fd5b3461028f57606036600319011261028f5761102d612137565b611035612121565b61103d612224565b91611046612639565b336000908152600080516020612f9a833981519152602052604090205460ff161580611165575b610e97576001600160a01b03166000818152600160205260409020805491929160e01c60ff1660038110156103c55760011461115457816020916110d3867ff223dc085722c94c84dcf67427e225799be616382a2a484d378f8921c69a20339587612c79565b80546001600160a01b0319166001600160a01b0383161781556110f6868261243b565b6001810180546001600160801b031916426001600160401b0390811691909117909155815460ff60e01b1916600160e01b179091556001600160a01b03919091166000818152600284526040908190208690555195909116855293a3005b639d2c8fdf60e01b60005260046000fd5b50336001600160a01b038216141561106d565b3461028f57602036600319011261028f576001600160a01b03611199612137565b166000526001602052604060002060ff60008051602061303a833981519152541615806111ec575b602091816111d5575b506040519015158152f35b5460a01c6001600160401b031642109050826111ca565b5060ff815460e01c169060038210156103c557906001146111c1565b3461028f57600036600319011261028f577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163003611261576020604051600080516020612f7a8339815191528152f35b63703e46dd60e11b60005260046000fd5b3461028f57600036600319011261028f576000546040516001600160a01b039091168152602090f35b3461028f57602036600319011261028f57600435600081815260056020526040902080546001600160a01b0381169291908315908115611383575b506106e657336000908152600080516020612f9a833981519152602052604090205460ff161580611379575b611368578061131e63fffffffe611341935460a01c16826122a5565b80546001600160c01b0316815560018101805464ffffffffff1916905582612a02565b7fa5ffbdba01b15df97334e34ad816b9986b6057a5ddc97aba93b7e8ccd21759ed600080a3005b630a606ec360e11b60005260046000fd5b5082331415611302565b6001915060a01c1615846112d6565b604036600319011261028f576113a6612137565b602435906001600160401b03821161028f573660238301121561028f578160040135906113d282612209565b916113e060405193846121e6565b8083526020830193366024838301011161028f57816000926024602093018737840101526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016308114908115611651575b50611261576000546001600160a01b03163303610519576001600160a01b03811692831561100357813b156116405730841461163157600080516020612f7a8339815191525484611488612282565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f6114be6040519260408452604084019061225d565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa600091816115fd575b5061150e5785634c9c8ce360e01b60005260045260246000fd5b9081600080516020612f7a8339815191528793036115e95750833b156115d4576001600160a01b0319168117600080516020612f7a833981519152557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28251156115b957600080916105a2945190845af43d156115b1573d9161159483612209565b926115a260405194856121e6565b83523d6000602085013e612eb8565b606091612eb8565b505050346115c357005b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60005260045260246000fd5b632a87526960e21b60005260045260246000fd5b9091506020813d602011611629575b81611619602093836121e6565b8101031261028f575190876114f4565b3d915061160c565b614e8d60eb1b60005260046000fd5b632e07c4bd60e11b60005260046000fd5b600080516020612f7a833981519152546001600160a01b03161415905084611439565b3461028f57602036600319011261028f57600435611690612639565b6116b261169c82612684565b9190600263ffffffff825460a01c1617906122a5565b6001600160a01b0316907fc2713e691344add4705edc62a0ee5aede95ba66ad68f97316efef9cb50644edd600080a3005b3461028f57600036600319011261028f57336000908152600080516020612f9a833981519152602052604090205460ff1615806117c6575b6117b55760008051602061303a8339815191525460ff8116156117a45760ff191660008051602061303a833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a2005b638dfc202b60e01b60005260046000fd5b63659a07b360e11b60005260046000fd5b506000546001600160a01b031633141561171b565b3461028f57604036600319011261028f57606061181e63ffffffff611809611801612121565b600435612323565b9193906040519415158552602085019061214d565b166040820152f35b3461028f57604036600319011261028f5761183f612121565b336001600160a01b0382160361185b576105a290600435612abe565b63334bd91960e11b60005260046000fd5b3461028f57604036600319011261028f576105a260043561188b612121565b9061189861059882612302565b612a76565b3461028f57602036600319011261028f576004356118eb6118bd82612990565b91906118d363fffffffb825460a01c16826122a5565b60018101805463ffffffff60281b1916905583612a02565b6001600160a01b0316907f09cb4ec44cdef8489412844b9682f87f7900758fa2bd7e039113e9125e538e0f600080a3005b3461028f57602036600319011261028f57600435600081815260056020526040902080546001600160a01b03811692919083159081156119d6575b506106e657336000908152600080516020612f9a833981519152602052604090205460ff1615806119cc575b611368578061199f63fffffffd6119a5935460a01c16826122a5565b82612a02565b7fb390ab029eab314bd18190ebe73d7e5c1c336beaa5c83ac22578378dc9ccc405600080a3005b5082331415611983565b6002915060a01c161584611957565b3461028f57602036600319011261028f576020611a03600435612302565b604051908152f35b3461028f57604036600319011261028f57600435611a27612174565b63ffffffff600654168063ffffffff831610908115611a9d575b50610b27577e8a218591d4362499c38c38eb1c12e7a7cc97a9068818d1fe6046a42ba4a5ba906001611a7284612990565b5001611a898263ffffffff835460281c16926122c8565b611a98604051928392836122eb565b0390a2005b90501583611a41565b3461028f57602036600319011261028f57611abf612137565b6000546001600160a01b0316330361051957600480546001600160a01b039283166001600160a01b0319821681179092559091167f8556037c5648b2d5b51736f07a8fa4d099812ef06abf79a5731be619b111e4d4600080a3005b3461028f57602036600319011261028f57611b33612187565b60008051602061305a8339815191525460ff8160401c16908115611c13575b50611c025760008051602061305a833981519152805460026001600160401b0319821681179092556000546001600160481b031990911690911791906001600160a01b031633036105195763ffffffff168015610f4657604081600080516020612fda8339815191529263ffffffff196006541617600655815190600082526020820152a160008051602061305a83398151915255600080516020612f3a833981519152602060405160028152a1005b63f92ee8a960e01b60005260046000fd5b60026001600160401b03919091161015905082611b52565b3461028f57606036600319011261028f57600435611c47612174565b9060443564ffffffffff811680910361028f57604060017ef8e9f2101420b089a9228a3e9fa546f669754196824e19ec1adab7cab1f2e992611c87612639565b611c9085612684565b9290611ca88263ffffffff835460a01c1617826122a5565b805463ffffffff60c01b60c08a901b1663ffffffff60c01b199091161760e083901b83900316815501805464ffffffffff191682179055825163ffffffff909616865260208601526001600160a01b031693a3005b3461028f5760a036600319011261028f57611d16612137565b611d1e612121565b906044356001600160a01b03811680820361028f576064356001600160a01b0381169182820361028f576084356001600160a01b038116949085900361028f5760008051602061305a83398151915254604081901c60ff161596906001600160401b03168015908161203c575b6001149081612032575b159081612029575b50611c025760008051602061305a83398151915280546001600160401b031916600117905586612004575b611dd0612b02565b611dd8612b02565b611de0612b02565b611de8612b02565b6001600160a01b038116908115611003578315611003578515611003576001600160a01b038916988915611003573b15610ff257611e27906000612b30565b9081611fbd575b5015611f0257611e4c9060008051602061301a833981519152612b30565b9081611f68575b5015611f0257611e7190600080516020612f5a833981519152612b30565b9081611f13575b5015611f0257600080546001600160a01b031916841781556040519390600080516020612fba8339815191528180a3801561100357803b15610ff257600380546001600160a01b031916919091179055611ece57005b60008051602061305a833981519152805460ff60401b1916905560018152600080516020612f3a83398151915290602090a1005b63cf5a8e3360e01b60005260046000fd5b600080516020612f5a833981519152600052600080516020612f1a833981519152602052611f61907ffff5b43478fa6840382eb63777e0da6941d320b940e3f70f0ea4780feff95827612d74565b5084611e78565b60008051602061301a833981519152600052600080516020612f1a833981519152602052611fb6907f32d31393d541a265984ec379cddd8b1fcbe5f2b0eb8ad81dddfead454f135eaa612d74565b5086611e53565b60008052600080516020612f1a833981519152602052611ffd907f615f0f9e84155bea8cc509fe18befeb1baf65611e38a6ba60964480fb29dfd44612d74565b5088611e2e565b60008051602061305a833981519152805460ff60401b1916600160401b179055611dc8565b90501589611d9d565b303b159150611d95565b889150611d8b565b3461028f57604036600319011261028f57612075612060612121565b60043560005260056020526040600020612464565b600a8110156103c55761028b9060405191818392158361215a565b3461028f57600036600319011261028f57602063ffffffff60065416604051908152f35b3461028f57602036600319011261028f576004359063ffffffff60e01b821680920361028f57602091635a05180f60e01b81149081156120f6575b5015158152f35b637965db0b60e01b811491508115612110575b50836120ef565b6301ffc9a760e01b14905083612109565b602435906001600160a01b038216820361028f57565b600435906001600160a01b038216820361028f57565b90600a8210156103c55752565b9015158152604081019291612172916020019061214d565b565b6024359063ffffffff8216820361028f57565b6004359063ffffffff8216820361028f57565b60a081019081106001600160401b038211176121b557604052565b634e487b7160e01b600052604160045260246000fd5b60c081019081106001600160401b038211176121b557604052565b601f909101601f19168101906001600160401b038211908210176121b557604052565b6001600160401b0381116121b557601f01601f191660200190565b604435906001600160401b038216820361028f57565b60005b83811061224d5750506000910152565b818101518382015260200161223d565b906020916122768151809281855285808601910161223a565b601f01601f1916010190565b604051906122916040836121e6565b6005825264312e312e3160d81b6020830152565b805463ffffffff60a01b191660a09290921b63ffffffff60a01b16919091179055565b805463ffffffff60281b191660289290921b63ffffffff60281b16919091179055565b63ffffffff91821681529116602082015260400190565b600052600080516020612ffa83398151915260205260016040600020015490565b600052600560205261233a60406000209182612521565b600a8110156103c5578061239b5750600163ffffffff91015460281c1663ffffffff6006541681158015612393575b6123865780821061237f57505b60019160009190565b9050612376565b5050600090600390600090565b508015612369565b6000929091508290565b60005260056020526123bc604060002091826125ad565b600a8110156103c557806124335750805463ffffffff8160c01c168015159182612425575b505061241c576001015464ffffffffff168015159081612411575b5061240957600190600090565b600090600990565b9050421015386123fc565b50600090600890565b60e01c1015905038806123e1565b600092909150565b8054600160a01b600160e01b03191660a09290921b600160a01b600160e01b0316919091179055565b60ff60008051602061303a833981519152541661251a57546001600160a01b0381169081156125125760a01c6002161561250b5760005260016020526040600020549060ff8260e01c1660038110156103c5578015612503576002146124fc574260a083901c6001600160401b031611156124f5576001600160a01b039081169116036124f057600090565b600790565b5050600690565b5050600590565b505050600490565b5050600390565b505050600290565b5050600190565b60ff60008051602061303a833981519152541661251a57546001600160a01b0381169081156125125760a01c6004161561250b5760005260016020526040600020549060ff8260e01c1660038110156103c5578015612503576002146124fc574260a083901c6001600160401b031611156124f5576001600160a01b039081169116036124f057600090565b60ff60008051602061303a833981519152541661251a57546001600160a01b0381169081156125125760a01c6001161561250b5760005260016020526040600020549060ff8260e01c1660038110156103c5578015612503576002146124fc574260a083901c6001600160401b031611156124f5576001600160a01b039081169116036124f057600090565b60ff60008051602061303a833981519152541661265257565b63d93c066560e01b60005260046000fd5b519064ffffffffff8216820361028f57565b519061ffff8216820361028f57565b801561297f57600354604051638d34875560e01b8152600481018390529190600090839060249082906001600160a01b03165afa918215612973576000926127c8575b506080820151336000908152600080516020612f9a83398151915260205260409020546001600160a01b03909116929060ff1615806127be575b61136857610120015160088110156103c5576003811490600082156127b0575b821561279f575b505061278e5781600052600160205260ff60406000205460e01c1660038110156103c55760010361277d57600090815260056020526040902080546001600160a01b0319166001600160a01b03831617815591565b632e68d1d360e21b60005260046000fd5b63e9f6db8560e01b60005260046000fd5b9091506103c5576007143880612728565b506005811491506000612721565b5082331415612701565b90913d8082843e6127d981846121e6565b820191602081840312612953578051906001600160401b03821161295b5701906101a08284031261295057604051926101a084016001600160401b0381118582101761295f5760409081528351855260208085015190860152838101519085015260608301516001600160401b03811161295b57830181601f8201121561295b5780519061286682612209565b9261287460405194856121e6565b828452602083830101116129575790612893916020808501910161223a565b606084015260808201516001600160a01b03811681036129535760808401526128be60a08301612663565b60a08401526128cf60c08301612663565b60c08401526128e060e08301612675565b60e08401526128f26101008301612663565b610100840152610120820151906008821015612950575061294391610180916101208501526129246101408201612663565b6101408501526129376101608201612675565b61016085015201612663565b61018082015290386126c7565b80fd5b5080fd5b8380fd5b8280fd5b634e487b7160e01b83526041600452602483fd5b6040513d6000823e3d90fd5b637bb0b62160e01b60005260046000fd5b6000908152600560205260409020805490916001600160a01b0382169182159081156129f3575b506106e657336000908152600080516020612f9a833981519152602052604090205460ff1615806129e9575b61136857565b50813314156129e3565b6004915060a01c1615386129b7565b905460a01c63ffffffff1615612a155750565b600052600560205260006001604082208281550155565b6000818152600080516020612ffa8339815191526020908152604080832033845290915290205460ff1615612a5e5750565b63e2517d3f60e01b6000523360045260245260446000fd5b612a808282612b30565b9182612a8b57505090565b6000918252600080516020612f1a8339815191526020526040909120612aba916001600160a01b031690612d74565b5090565b612ac88282612bd9565b9182612ad357505090565b6000918252600080516020612f1a8339815191526020526040909120612aba916001600160a01b031690612de5565b60ff60008051602061305a8339815191525460401c1615612b1f57565b631afcd79f60e31b60005260046000fd5b6000818152600080516020612ffa833981519152602090815260408083206001600160a01b038616845290915290205460ff16612bd2576000818152600080516020612ffa833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5050600090565b6000818152600080516020612ffa833981519152602090815260408083206001600160a01b038616845290915290205460ff1615612bd2576000818152600080516020612ffa833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b9081158015612d35575b611003576001600160a01b0316600090815260026020526040902054801515919082612d2a575b5050612d19576001600160401b031642811115612d085760005460a01c6001600160401b03168015159182612cf3575b5050612ce257565b63e774e7b560e01b60005260046000fd5b9091504281039081116106b157113880612cda565b63efa7aefd60e01b60005260046000fd5b633b53f64f60e21b60005260046000fd5b141590503880612caa565b506001600160a01b03811615612c83565b8054821015612d5e5760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b6001810190826000528160205260406000205415600014612ddd578054600160401b8110156121b557612dc8612db1826001879401855584612d46565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b505050600090565b9060018201918160005282602052604060002054801515600014612eaf5760001981018181116106b15782546000198101919082116106b157818103612e78575b50505080548015612e62576000190190612e408282612d46565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b612e98612e88612db19386612d46565b90549060031b1c92839286612d46565b905560005283602052604060002055388080612e26565b50505050600090565b90612ede5750805115612ecd57602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580612f10575b612eef575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15612ee756fec1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e82371705932000c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc07966f2ab141347034724e9b2a472c2f77f5cd745aeba27cacba797b8fcb708617dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846cd37bc77615afefc793aa17d75d4249a9b517ba91b0e54a49c9c4a44b3d7e228302dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800edcc084d3dcd65a1f7f23c65c46722faca6953d28e43150a467cf43e5c309238cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c6343000822000a";
17828
+ var isSuperArgs2 = (xs) => xs.length > 1;
17829
+ var AgentDelegationRegistry__factory = class extends ContractFactory2 {
17830
+ constructor(...args) {
17831
+ if (isSuperArgs2(args)) {
17832
+ super(...args);
17833
+ } else {
17834
+ super(_abi2, _bytecode2, args[0]);
17835
+ }
17836
+ }
17837
+ getDeployTransaction(overrides) {
17838
+ return super.getDeployTransaction(overrides || {});
17839
+ }
17840
+ deploy(overrides) {
17841
+ return super.deploy(overrides || {});
17842
+ }
17843
+ connect(runner) {
17844
+ return super.connect(runner);
17845
+ }
17846
+ static bytecode = _bytecode2;
17847
+ static abi = _abi2;
17848
+ static createInterface() {
17849
+ return new Interface4(_abi2);
17850
+ }
17851
+ static connect(address, runner) {
17852
+ return new Contract7(
17853
+ address,
17854
+ _abi2,
17855
+ runner
17856
+ );
17857
+ }
17858
+ };
17859
+
17860
+ // src/utils/position-delegate.utils.ts
17861
+ import { Contract as Contract8 } from "ethers";
17862
+ var POSITION_DELEGATE_REGISTRY_ABI = [
17863
+ "function positionDelegate(bytes32 positionId) view returns (address)",
17864
+ "function setPositionDelegate(bytes32 positionId, address newDelegate) external",
17865
+ "event PositionDelegateUpdated(bytes32 indexed positionId, address indexed oldDelegate, address indexed newDelegate)"
17866
+ ];
17867
+ async function setPositionDelegate(positionId, delegate, signer, registryAddress) {
17868
+ const registry = new Contract8(
17869
+ registryAddress,
17870
+ POSITION_DELEGATE_REGISTRY_ABI,
17871
+ signer
17872
+ );
17873
+ return registry["setPositionDelegate"](positionId, delegate);
17874
+ }
17875
+ async function getPositionDelegate(positionId, provider, registryAddress) {
17876
+ const registry = new Contract8(
17877
+ registryAddress,
17878
+ POSITION_DELEGATE_REGISTRY_ABI,
17879
+ provider
17880
+ );
17881
+ return registry["positionDelegate"](positionId);
17882
+ }
17883
+
17884
+ // src/utils/agent-delegation.utils.ts
17885
+ async function mintAgentPkp(params) {
17886
+ const { serviceEndpoint, authHeader, timeoutMs = 3e4 } = params;
17887
+ if (!serviceEndpoint) {
17888
+ throw new Error(
17889
+ "serviceEndpoint is required to mint an agent PKP (SDK must be in service mode)"
17890
+ );
17891
+ }
17892
+ const url = `${serviceEndpoint}/api/lit/pkp/mint-agent`;
17893
+ const controller = new AbortController();
17894
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
17895
+ try {
17896
+ const headers = {
17897
+ "Content-Type": "application/json",
17898
+ ...authHeader ? await authHeader() : {}
17899
+ };
17900
+ const response = await fetch(url, {
17901
+ method: "POST",
17902
+ headers,
17903
+ body: "{}",
17904
+ signal: controller.signal
17905
+ });
17906
+ if (!response.ok) {
17907
+ throw new Error(
17908
+ `Agent PKP mint failed (${response.status}): ${await response.text()}`
17909
+ );
17910
+ }
17911
+ const data = await response.json();
17912
+ if (!data.success || !data.walletAddress) {
17913
+ throw new Error(
17914
+ `Agent PKP mint returned no address: ${data.error ?? JSON.stringify(data)}`
17915
+ );
17916
+ }
17917
+ return data.walletAddress;
17918
+ } finally {
17919
+ clearTimeout(timeout);
17920
+ }
17921
+ }
17922
+
17923
+ // src/modules/mock/mock-token-manager.module.ts
17924
+ var MockTokenManager = class {
17925
+ config;
17926
+ constructor(config) {
17927
+ this.config = config;
17928
+ if (this.isProductionNetwork()) {
17929
+ log.warn("\u26A0\uFE0F MockTokenManager initialized on production network", {
17930
+ network: config.network
17931
+ });
17932
+ }
17933
+ }
17934
+ /**
17935
+ * Mint mock BTC tokens
17936
+ *
17937
+ * @param amount - Amount to mint in satoshis
17938
+ * @param recipient - Recipient address
17939
+ * @returns Transaction result
17940
+ */
17941
+ async mintMockBTC(amount, recipient) {
17942
+ if (this.config.debug) {
17943
+ log.info("\u{1FA99} Minting mock BTC", {
17944
+ amount: amount.toString(),
17945
+ recipient
17946
+ });
17947
+ }
17948
+ if (this.isProductionNetwork()) {
17949
+ return failure(
17950
+ new SDKError({
17951
+ message: "Cannot mint mock tokens on production network",
17952
+ category: "CONFIGURATION" /* CONFIGURATION */,
17953
+ severity: "HIGH" /* HIGH */,
17954
+ originalError: new Error("Production network detected")
17955
+ })
17956
+ );
17957
+ }
17958
+ return tryCatchAsync(
17959
+ async () => {
17960
+ const signerResult = this.config.contractManager.getSigner();
17961
+ if (!signerResult.success) {
17962
+ throw signerResult.error;
17963
+ }
17964
+ throw new Error("Mock BTC contract not yet integrated");
17965
+ },
17966
+ (error) => new SDKError({
17967
+ message: "Failed to mint mock BTC",
17968
+ category: "CONTRACT" /* CONTRACT */,
17969
+ severity: "MEDIUM" /* MEDIUM */,
17970
+ originalError: error instanceof Error ? error : new Error(String(error)),
17971
+ context: { amount: amount.toString(), recipient }
17972
+ })
17973
+ );
17974
+ }
17975
+ /**
17976
+ * Approve mock BTC spending
17977
+ *
17978
+ * @param spender - Spender address
17979
+ * @param amount - Amount to approve in satoshis
17980
+ * @returns Transaction result
17981
+ */
17982
+ async approveMockBTC(spender, amount) {
17983
+ if (this.config.debug) {
17984
+ log.info("\u2705 Approving mock BTC spending", {
17985
+ spender,
17986
+ amount: amount.toString()
17987
+ });
17988
+ }
17989
+ if (this.isProductionNetwork()) {
17990
+ return failure(
17991
+ new SDKError({
17992
+ message: "Cannot approve mock tokens on production network",
17993
+ category: "CONFIGURATION" /* CONFIGURATION */,
17994
+ severity: "HIGH" /* HIGH */,
17995
+ originalError: new Error("Production network detected")
17996
+ })
17997
+ );
17998
+ }
17999
+ return tryCatchAsync(
18000
+ async () => {
18001
+ const signerResult = this.config.contractManager.getSigner();
18002
+ if (!signerResult.success) {
18003
+ throw signerResult.error;
18004
+ }
18005
+ throw new Error("Mock BTC contract not yet integrated");
18006
+ },
18007
+ (error) => new SDKError({
18008
+ message: "Failed to approve mock BTC",
18009
+ category: "CONTRACT" /* CONTRACT */,
18010
+ severity: "MEDIUM" /* MEDIUM */,
18011
+ originalError: error instanceof Error ? error : new Error(String(error)),
18012
+ context: { spender, amount: amount.toString() }
18013
+ })
18014
+ );
18015
+ }
18016
+ /**
18017
+ * Get mock BTC balance
18018
+ *
18019
+ * @param address - Address to query
18020
+ * @returns Balance in satoshis
18021
+ */
18022
+ async getMockBTCBalance(address) {
18023
+ if (this.config.debug) {
18024
+ log.info("\u{1F50D} Querying mock BTC balance", { address });
18025
+ }
18026
+ return tryCatchAsync(
18027
+ async () => {
18028
+ throw new Error("Mock BTC contract not yet integrated");
18029
+ },
18030
+ (error) => new SDKError({
18031
+ message: "Failed to get mock BTC balance",
18032
+ category: "CONTRACT" /* CONTRACT */,
18033
+ severity: "MEDIUM" /* MEDIUM */,
18034
+ originalError: error instanceof Error ? error : new Error(String(error)),
18035
+ context: { address }
18036
+ })
18037
+ );
18038
+ }
18039
+ /**
18040
+ * Check if current network is production (mainnet)
18041
+ */
18042
+ isProductionNetwork() {
18043
+ return this.config.network.toLowerCase().includes("mainnet");
18044
+ }
18045
+ };
18046
+ function createMockTokenManager(config) {
18047
+ try {
18048
+ const manager = new MockTokenManager(config);
18049
+ return success(manager);
18050
+ } catch (error) {
18051
+ return failure(
18052
+ new SDKError({
18053
+ message: "Failed to create MockTokenManager",
18054
+ category: "INITIALIZATION" /* INITIALIZATION */,
18055
+ severity: "HIGH" /* HIGH */,
18056
+ originalError: error instanceof Error ? error : new Error(String(error))
18057
+ })
18058
+ );
18059
+ }
18060
+ }
18061
+
18062
+ // src/modules/diamond-hands-sdk.ts
18063
+ var import_dh_lit_actions2 = __toESM(require_pkg_src());
18064
+ import { LitOps, broadcastSignedBitcoinTransaction } from "@gvnrdao/dh-lit-ops";
18065
+
18066
+ // src/utils/telegram-messaging.utils.ts
18067
+ var TelegramBot = null;
18068
+ try {
18069
+ if (typeof window === "undefined" && typeof global !== "undefined") {
18070
+ TelegramBot = __require("node-telegram-bot-api");
18071
+ }
18072
+ } catch (error) {
18073
+ log.warn("Telegram bot API not available", {
18074
+ error: error instanceof Error ? error.message : String(error)
18075
+ });
18076
+ }
18077
+ function formatMintMessage(mintAmount, loanId, txHash) {
18078
+ return `\u2705 DH SDK: ${mintAmount} UCD was minted for loan id: ${loanId} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
18079
+ }
18080
+ function formatPartialPaymentMessage(paymentAmount, loanId, txHash) {
18081
+ return `\u2705 DH SDK: ${paymentAmount} UCD was repaid for loan id: ${loanId} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
18082
+ }
18083
+ function formatPartialPaymentFailureMessage(paymentAmount, loanId, txHash) {
18084
+ const baseMessage = `\u274C DH SDK: FAILED to repay ${paymentAmount} UCD for loan id: ${loanId}`;
18085
+ if (txHash) {
18086
+ return `${baseMessage} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
18087
+ }
18088
+ return baseMessage;
18089
+ }
18090
+ function formatLoanCreationMessage(positionId, pkpId, vaultAddress) {
18091
+ const vault = vaultAddress || "unknown";
18092
+ return `\u2705 DH SDK: A new loan was created Id: ${positionId} Pkp: ${pkpId} Regtest BTC vault: ${vault}`;
18093
+ }
18094
+ function formatBTCWithdrawalFailureMessage(withdrawalAmount, btcVault, btcDestinationAddress, loanId) {
18095
+ const formattedAmount = formatBTCAmount(withdrawalAmount);
18096
+ return `\u274C DH SDK: BTC withdrawal FAILED: ${formattedAmount} from ${btcVault} to ${btcDestinationAddress} for loan id: ${loanId}`;
18097
+ }
18098
+ function formatLoanRenewalMessage(positionId, txHash) {
18099
+ return `\u2705 DH SDK: Loan id ${positionId} was successfully renewed. Tx: https://sepolia.etherscan.io/tx/${txHash}`;
18100
+ }
18101
+ function formatLoanRenewalFailureMessage(loanId, error) {
18102
+ return `\u274C DH SDK: FAILED to renew loan id ${loanId} ${error}`;
18103
+ }
18104
+ function formatBalanceConfirmationMessage(loanId) {
18105
+ return `\u2705 DH SDK: Loan id: ${loanId} was updated to PENDING_MINT`;
18106
+ }
18107
+ function formatBalanceConfirmationFailureMessage(loanId) {
18108
+ return `\u274C DH SDK: FAILED to update to PENDING_MINT for loan id ${loanId}`;
18109
+ }
18110
+ function formatBTCWithdrawalSuccessMessage(withdrawalAmount, btcVault, btcDestinationAddress, loanId, btcTxId) {
18111
+ const formattedAmount = formatBTCAmount(withdrawalAmount);
18112
+ const txSuffix = btcTxId ? ` (tx: ${btcTxId})` : "";
18113
+ return `\u2705 DH SDK: BTC withdrawal SUCCEEDED: ${formattedAmount} sent from ${btcVault} to ${btcDestinationAddress} for loan id: ${loanId}${txSuffix}`;
18114
+ }
18115
+ function formatLiquidationSkippedMessage(loanId, ratio, threshold, btcVault, btcVaultBalance, ucdDebt, btcPrice) {
18116
+ const formattedPrice = formatBTCPrice(btcPrice);
18117
+ const formattedBalance = formatBTCAmount(btcVaultBalance);
16235
18118
  return `\u2139\uFE0F DH SDK: Loan Id ${loanId} was not liquidated as the collateral ratio of ${ratio}% was above the liquidation threshold of ${threshold}%; BTC vault ${btcVault} balance is ${formattedBalance}, UCD Debt of ${ucdDebt} and BTC Price of ${formattedPrice}`;
16236
18119
  }
16237
18120
  function formatLiquidationSuccessMessage(loanId, ratio, threshold, btcVault, btcVaultBalance, ucdDebt, btcPrice) {
@@ -17939,7 +19822,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
17939
19822
  const coreAbi = [
17940
19823
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
17941
19824
  ];
17942
- const positionCore = new Contract6(
19825
+ const positionCore = new Contract9(
17943
19826
  coreAddress,
17944
19827
  coreAbi,
17945
19828
  this.getSignerOrThrow().provider
@@ -17995,7 +19878,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
17995
19878
  "function getCurrentQuantum() view returns (uint256)",
17996
19879
  "function isQuantumValid(bytes32,uint256) view returns (bool)"
17997
19880
  ];
17998
- const registry = new Contract6(
19881
+ const registry = new Contract9(
17999
19882
  registryAddress,
18000
19883
  registryAbi,
18001
19884
  this.getSignerOrThrow().provider
@@ -18111,7 +19994,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
18111
19994
  });
18112
19995
  }
18113
19996
  const signatureHexMint = finalSignature.startsWith("0x") ? finalSignature : "0x" + finalSignature;
18114
- const mintIface = new Interface4(positionManagerAbi);
19997
+ const mintIface = new Interface5(positionManagerAbi);
18115
19998
  const mintCalldata = mintIface.encodeFunctionData("mintUCD", [
18116
19999
  positionIdBytes32,
18117
20000
  validationResponse.mintAmount,
@@ -18147,7 +20030,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
18147
20030
  if (viewsAddress) {
18148
20031
  let diagnosis = null;
18149
20032
  try {
18150
- const views = new Contract6(
20033
+ const views = new Contract9(
18151
20034
  viewsAddress,
18152
20035
  [
18153
20036
  "function diagnoseMintUCD(bytes32,uint256,uint256,uint256,uint256,uint256,bytes32,bytes32,bytes32,uint256,bytes) view returns (string)"
@@ -18257,7 +20140,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
18257
20140
  if (receipt.logs && receipt.logs.length > 0) {
18258
20141
  for (const receiptLog of receipt.logs) {
18259
20142
  if (receiptLog.topics && receiptLog.topics[0] === "0x08c379a0") {
18260
- const iface = new Interface4([
20143
+ const iface = new Interface5([
18261
20144
  "error Error(string)"
18262
20145
  ]);
18263
20146
  const decoded = iface.decodeErrorResult("Error", receiptLog.data);
@@ -18274,7 +20157,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
18274
20157
  const minimalAbi = [
18275
20158
  "event UCDMintedWithAuthorization(bytes32 indexed positionId, address indexed borrower, uint256 mintAmount, uint256 mintFee, uint256 newDebt, uint256 newCollateral, uint256 btcPrice, uint256 quantumTimestamp, bytes32 authorizedSpendsHash)"
18276
20159
  ];
18277
- const iface = new Interface4(minimalAbi);
20160
+ const iface = new Interface5(minimalAbi);
18278
20161
  for (const receiptLog of receipt.logs) {
18279
20162
  const parsed = (() => {
18280
20163
  const logIface = iface;
@@ -18863,7 +20746,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
18863
20746
  }
18864
20747
  const loanOpsForUcd = loanOpsForUcdResult.value;
18865
20748
  const ucdTokenAddress = await loanOpsForUcd.ucdToken();
18866
- const ucdToken = new Contract6(
20749
+ const ucdToken = new Contract9(
18867
20750
  ucdTokenAddress,
18868
20751
  [
18869
20752
  "function balanceOf(address) view returns (uint256)",
@@ -19408,7 +21291,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
19408
21291
  if (!signatureBytes.startsWith("0x")) {
19409
21292
  signatureBytes = "0x" + signatureBytes;
19410
21293
  }
19411
- const extendIface = new Interface4([
21294
+ const extendIface = new Interface5([
19412
21295
  "function extendPosition(bytes32 positionId, uint256 selectedTerm, uint256 quantumTimestamp, uint256 btcPrice, uint256 availableBTCBalance, uint256 proRataRenewalFee, bytes calldata extensionValidatorSignature) external returns (bool)"
19413
21296
  ]);
19414
21297
  const extendCalldata = extendIface.encodeFunctionData("extendPosition", [
@@ -20020,7 +21903,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
20020
21903
  };
20021
21904
  }
20022
21905
  const ucdTokenAddress = await loanOps.ucdToken();
20023
- const ucdToken = new Contract6(
21906
+ const ucdToken = new Contract9(
20024
21907
  ucdTokenAddress,
20025
21908
  [
20026
21909
  "function balanceOf(address) view returns (uint256)",
@@ -20030,15 +21913,22 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
20030
21913
  signer
20031
21914
  );
20032
21915
  const signerAddress = await signer.getAddress();
21916
+ let fundsSource = signerAddress;
21917
+ try {
21918
+ const posView = await this.getPositionDetailsView(request.positionId);
21919
+ if (posView?.borrower)
21920
+ fundsSource = posView.borrower;
21921
+ } catch {
21922
+ }
21923
+ const isSelfRepay = fundsSource.toLowerCase() === signerAddress.toLowerCase();
20033
21924
  const [balance, allowance] = await Promise.all([
20034
- ucdToken["balanceOf"](signerAddress),
20035
- ucdToken["allowance"](signerAddress, positionManagerAddress)
21925
+ ucdToken["balanceOf"](fundsSource),
21926
+ ucdToken["allowance"](fundsSource, positionManagerAddress)
20036
21927
  ]);
20037
21928
  if (this.config.debug) {
21929
+ log.info(` UCD funds source: ${fundsSource}${isSelfRepay ? " (self)" : " (borrower; agent submitting)"}`);
20038
21930
  log.info(` UCD Balance: ${formatEther(balance)} UCD`);
20039
- log.info(
20040
- ` UCD Allowance: ${formatEther(allowance)} UCD`
20041
- );
21931
+ log.info(` UCD Allowance: ${formatEther(allowance)} UCD`);
20042
21932
  log.info(` Required: ${request.paymentAmount} UCD`);
20043
21933
  }
20044
21934
  if (balance < paymentAmountWei) {
@@ -20046,15 +21936,18 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
20046
21936
  success: false,
20047
21937
  error: `Insufficient UCD balance: ${formatEther(
20048
21938
  balance
20049
- )} UCD (need ${request.paymentAmount} UCD)`
21939
+ )} UCD (need ${request.paymentAmount} UCD)${isSelfRepay ? "" : ` \u2014 borrower ${fundsSource} lacks funds`}`
20050
21940
  };
20051
21941
  }
20052
21942
  if (allowance < paymentAmountWei) {
21943
+ if (!isSelfRepay) {
21944
+ return {
21945
+ success: false,
21946
+ error: `Borrower ${fundsSource} has insufficient UCD allowance to PositionManager (${formatEther(allowance)} UCD, need ${request.paymentAmount}). The borrower must approve PositionManager before a delegated agent can repay.`
21947
+ };
21948
+ }
20053
21949
  if (this.config.debug) {
20054
- log.info(
20055
- " Insufficient allowance, sending approval transaction...",
20056
- {}
20057
- );
21950
+ log.info(" Insufficient allowance, sending approval transaction...", {});
20058
21951
  }
20059
21952
  const approveTx = await ucdToken["approve"](
20060
21953
  positionManagerAddress,
@@ -20062,16 +21955,13 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
20062
21955
  );
20063
21956
  if (this.config.debug) {
20064
21957
  log.info(` Approval tx sent: ${approveTx.hash}`);
20065
- log.info(" Waiting for approval confirmation...", {});
20066
21958
  }
20067
21959
  await approveTx.wait();
20068
21960
  if (this.config.debug) {
20069
21961
  log.info(" \u2705 UCD approval confirmed", {});
20070
21962
  }
20071
- } else {
20072
- if (this.config.debug) {
20073
- log.info(" \u2705 Sufficient allowance already exists", {});
20074
- }
21963
+ } else if (this.config.debug) {
21964
+ log.info(" \u2705 Sufficient allowance already exists", {});
20075
21965
  }
20076
21966
  let auth;
20077
21967
  try {
@@ -20313,7 +22203,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
20313
22203
  const paymentSigner = this.getSignerOrThrow();
20314
22204
  const paymentFrom = await paymentSigner.getAddress();
20315
22205
  const paymentProvider = contractManager.getProvider();
20316
- const paymentIface = new Interface4([
22206
+ const paymentIface = new Interface5([
20317
22207
  "function makePayment(bytes32 positionId, uint256 paymentAmount, uint256 quantumTimestamp, uint256 btcPrice, bytes calldata paymentValidatorSignature) external returns (bool)"
20318
22208
  ]);
20319
22209
  const paymentCalldata = paymentIface.encodeFunctionData("makePayment", [
@@ -20630,7 +22520,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
20630
22520
  const pkpId = position.pkpId;
20631
22521
  if (litValidatorAddr && pkpId) {
20632
22522
  try {
20633
- const litValidator = new Contract6(
22523
+ const litValidator = new Contract9(
20634
22524
  litValidatorAddr,
20635
22525
  ["function pkpOwners(bytes32) view returns (address)"],
20636
22526
  this.getProviderOrThrow()
@@ -21053,7 +22943,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
21053
22943
  utxoVout: withdrawalParams.utxoVout
21054
22944
  });
21055
22945
  }
21056
- const withdrawIface = new Interface4([
22946
+ const withdrawIface = new Interface5([
21057
22947
  "function withdrawBTC((bytes32 positionId, bytes32 actionHash, bytes32 authorizedSpendsHash, bytes32 ucdDebtHash, bytes32 contractBundleHash, string withdrawalAddress, uint256 totalDeduction, uint256 newCollateral, uint256 quantumTimestamp, uint256 btcPrice, string utxoTxid, uint32 utxoVout) params, bytes withdrawalValidatorSignature, bytes btcSpendAuthSignature) external returns (bool)"
21058
22948
  ]);
21059
22949
  const withdrawCalldata = withdrawIface.encodeFunctionData("withdrawBTC", [
@@ -21615,7 +23505,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
21615
23505
  const btcSpendAuthorizerAbi = [
21616
23506
  "function getAuthorizedSpends(bytes32) view returns (tuple(string txid, uint32 vout, uint256 satoshis, string targetAddress, uint256 targetAmount, uint256 authorizedAt)[])"
21617
23507
  ];
21618
- const btcSpendAuthorizer = new Contract6(
23508
+ const btcSpendAuthorizer = new Contract9(
21619
23509
  btcSpendAuthorizerAddress,
21620
23510
  btcSpendAuthorizerAbi,
21621
23511
  this.getProviderOrThrow()
@@ -21701,7 +23591,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
21701
23591
  const abi = [
21702
23592
  "function getAuthorizedSpends(bytes32) view returns (tuple(string txid, uint32 vout, uint256 satoshis, string targetAddress, uint256 targetAmount, uint256 authorizedAt)[])"
21703
23593
  ];
21704
- const contract = new Contract6(
23594
+ const contract = new Contract9(
21705
23595
  btcSpendAuthorizerAddress,
21706
23596
  abi,
21707
23597
  this.getProviderOrThrow()
@@ -21888,7 +23778,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
21888
23778
  error: attRes.error ?? attRes.reason ?? `LIT recovery attestation rejected${attRes.failedStep ? ` at step ${attRes.failedStep}` : ""}`
21889
23779
  };
21890
23780
  }
21891
- const btcSpendAuthorizer = new Contract6(
23781
+ const btcSpendAuthorizer = new Contract9(
21892
23782
  btcSpendAuthorizerAddress,
21893
23783
  [
21894
23784
  "function cancelStaleSpendWithProof(bytes32 positionId, bytes32 utxoKey, uint256 authorizedAt, string calldata invalidatorTxid, uint256 attestationTimestamp, bytes calldata litSignature) external"
@@ -22578,7 +24468,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
22578
24468
  "function allowance(address owner, address spender) view returns (uint256)",
22579
24469
  "function approve(address spender, uint256 amount) returns (bool)"
22580
24470
  ];
22581
- const stablecoin = new Contract6(params.stablecoinAddress, erc20Abi, params.signer);
24471
+ const stablecoin = new Contract9(params.stablecoinAddress, erc20Abi, params.signer);
22582
24472
  const allowance = await stablecoin.allowance(signerAddress, psmAddress);
22583
24473
  if (allowance < params.amountWei) {
22584
24474
  const approveTx = await stablecoin.approve(psmAddress, MaxUint256);
@@ -22616,7 +24506,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
22616
24506
  "function allowance(address owner, address spender) view returns (uint256)",
22617
24507
  "function approve(address spender, uint256 amount) returns (bool)"
22618
24508
  ];
22619
- const ucdToken = new Contract6(ucdAddress, erc20Abi, params.signer);
24509
+ const ucdToken = new Contract9(ucdAddress, erc20Abi, params.signer);
22620
24510
  const allowance = await ucdToken.allowance(signerAddress, ucdControllerAddress);
22621
24511
  if (allowance < params.ucdAmountWei) {
22622
24512
  const approveTx = await ucdToken.approve(ucdControllerAddress, MaxUint256);
@@ -22638,6 +24528,132 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
22638
24528
  * @throws if timeout is reached before subgraph catches up
22639
24529
  */
22640
24530
  // ============================================================================
24531
+ // HIGH-LEVEL API - Agent Delegation (auto-renew) — SEPOLIA ONLY
24532
+ // ============================================================================
24533
+ /** Guard: the AgentDelegationRegistry MVP is deployed on Sepolia only. */
24534
+ async assertAgentDelegationSepolia() {
24535
+ const chainId = Number((await this.getProviderOrThrow().getNetwork()).chainId);
24536
+ if (chainId !== 11155111) {
24537
+ throw new SDKError({
24538
+ message: `Agent auto-renew delegation is Sepolia-only (chainId 11155111); got ${chainId}`,
24539
+ category: "NETWORK" /* NETWORK */,
24540
+ severity: "HIGH" /* HIGH */
24541
+ });
24542
+ }
24543
+ const addr = this.config.contractAddresses?.agentDelegationRegistry;
24544
+ if (!addr) {
24545
+ throw new SDKError({
24546
+ message: "AgentDelegationRegistry address not configured \u2014 provide contractAddresses.agentDelegationRegistry",
24547
+ category: "CONFIGURATION" /* CONFIGURATION */,
24548
+ severity: "HIGH" /* HIGH */
24549
+ });
24550
+ }
24551
+ return addr;
24552
+ }
24553
+ /**
24554
+ * Read a position's auto-renew delegation state (used to drive the Enable/Disable toggle).
24555
+ * Pure view — no signer required.
24556
+ */
24557
+ async getAutoRenewStatus(positionId, user) {
24558
+ const addr = await this.assertAgentDelegationSepolia();
24559
+ const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
24560
+ const pid = this.toBytes32(positionId);
24561
+ const grant = await registry.getLoanGrant(pid);
24562
+ const enabled = grant.borrower !== "0x0000000000000000000000000000000000000000" && (Number(grant.scopeBits) & 1) !== 0;
24563
+ const agentActive = user ? await registry.isAgentActive(user) : null;
24564
+ const canRenew = user ? await registry.canRenew(pid, user).then((r) => ({ ok: r.ok, reason: Number(r.reason) })) : null;
24565
+ return {
24566
+ enabled,
24567
+ borrower: grant.borrower,
24568
+ maxRenewals: Number(grant.maxRenewals),
24569
+ renewalsUsed: Number(grant.renewalsUsed),
24570
+ agentActive,
24571
+ canRenew
24572
+ };
24573
+ }
24574
+ /**
24575
+ * Enable auto-renew delegation for a position. Orchestrates the first-time setup: if the
24576
+ * borrower has no active agent, mints a fresh per-user agent PKP (via lit-ops-server) and
24577
+ * registers it, then records the position's renew grant. Borrower-signed.
24578
+ */
24579
+ async enableAutoRenew(positionId, options) {
24580
+ const addr = await this.assertAgentDelegationSepolia();
24581
+ const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
24582
+ if (!pdrAddr) {
24583
+ throw new SDKError({
24584
+ message: "PositionDelegateRegistry address not configured \u2014 required to authorize the renewal agent (contractAddresses.positionDelegateRegistry)",
24585
+ category: "CONFIGURATION" /* CONFIGURATION */,
24586
+ severity: "HIGH" /* HIGH */
24587
+ });
24588
+ }
24589
+ const signer = this.getSignerOrThrow();
24590
+ const user = await signer.getAddress();
24591
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
24592
+ const pid = this.toBytes32(positionId);
24593
+ let agentAddress;
24594
+ const hasActiveAgent = await registry.isAgentActive(user);
24595
+ if (hasActiveAgent) {
24596
+ agentAddress = (await registry.agentOf(user)).agent;
24597
+ } else {
24598
+ agentAddress = await mintAgentPkp({
24599
+ serviceEndpoint: this.config.serviceEndpoint,
24600
+ authHeader: this.serverSession ? () => this.serverSession.getAuthHeader() : void 0
24601
+ });
24602
+ const validitySeconds = options?.agentValiditySeconds ?? 90 * 24 * 60 * 60;
24603
+ const validUntil = Math.floor(Date.now() / 1e3) + validitySeconds;
24604
+ const regTx = await registry.registerAgent(user, agentAddress, validUntil);
24605
+ await regTx.wait();
24606
+ }
24607
+ const currentDelegate = await getPositionDelegate(pid, signer, pdrAddr).catch(
24608
+ () => null
24609
+ );
24610
+ if (!currentDelegate || currentDelegate.toLowerCase() !== agentAddress.toLowerCase()) {
24611
+ const delTx = await setPositionDelegate(pid, agentAddress, signer, pdrAddr);
24612
+ await delTx.wait();
24613
+ }
24614
+ const tx = await registry.enableAutoRenew(
24615
+ pid,
24616
+ options?.maxRenewals ?? 0,
24617
+ options?.maxEndTimestamp ?? 0
24618
+ );
24619
+ const receipt = await tx.wait();
24620
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0, agentAddress };
24621
+ }
24622
+ /** Disable auto-renew delegation for a position (clears the grant). Borrower-signed. */
24623
+ async disableAutoRenew(positionId) {
24624
+ const addr = await this.assertAgentDelegationSepolia();
24625
+ const signer = this.getSignerOrThrow();
24626
+ const user = await signer.getAddress();
24627
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
24628
+ const pid = this.toBytes32(positionId);
24629
+ const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
24630
+ if (!pdrAddr) {
24631
+ throw new SDKError({
24632
+ message: "PositionDelegateRegistry address not configured \u2014 required to clear the renewal agent's Gate-1 authorization (contractAddresses.positionDelegateRegistry)",
24633
+ category: "CONFIGURATION" /* CONFIGURATION */,
24634
+ severity: "HIGH" /* HIGH */
24635
+ });
24636
+ }
24637
+ {
24638
+ const [currentDelegate, userAgent] = await Promise.all([
24639
+ getPositionDelegate(pid, signer, pdrAddr).catch(() => null),
24640
+ registry.agentOf(user).then((a) => a.agent).catch(() => null)
24641
+ ]);
24642
+ if (currentDelegate && userAgent && currentDelegate.toLowerCase() === userAgent.toLowerCase()) {
24643
+ const clearTx = await setPositionDelegate(
24644
+ pid,
24645
+ "0x0000000000000000000000000000000000000000",
24646
+ signer,
24647
+ pdrAddr
24648
+ );
24649
+ await clearTx.wait();
24650
+ }
24651
+ }
24652
+ const tx = await registry.disableAutoRenew(pid);
24653
+ const receipt = await tx.wait();
24654
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
24655
+ }
24656
+ // ============================================================================
22641
24657
  // HIGH-LEVEL API - Bitcoin Operations
22642
24658
  // ============================================================================
22643
24659
  /**
@@ -23299,7 +25315,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23299
25315
  const coreModuleAbi = [
23300
25316
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
23301
25317
  ];
23302
- const coreModule = new Contract6(
25318
+ const coreModule = new Contract9(
23303
25319
  coreModuleAddress,
23304
25320
  coreModuleAbi,
23305
25321
  provider
@@ -23366,7 +25382,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23366
25382
  const corePositionAbi = [
23367
25383
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
23368
25384
  ];
23369
- const corePositionContract = new Contract6(
25385
+ const corePositionContract = new Contract9(
23370
25386
  coreAddress,
23371
25387
  corePositionAbi,
23372
25388
  provider
@@ -23445,7 +25461,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23445
25461
  throw new Error("loanOperationsManager address not configured");
23446
25462
  }
23447
25463
  const runner = this.config.contractSigner || this.getProviderOrThrow();
23448
- const contract = new Contract6(
25464
+ const contract = new Contract9(
23449
25465
  addr.loanOperationsManager,
23450
25466
  [
23451
25467
  "function getProtocolConfig() external view returns (uint256 liquidationThreshold, uint256 minimumLoanValueUcd, uint256 minimumLoanValueWei, uint256 maxSingleLoanValueUcd)"
@@ -23835,30 +25851,6 @@ var EventHelpers = {
23835
25851
  });
23836
25852
  }
23837
25853
  };
23838
-
23839
- // src/utils/position-delegate.utils.ts
23840
- import { Contract as Contract7 } from "ethers";
23841
- var POSITION_DELEGATE_REGISTRY_ABI = [
23842
- "function positionDelegate(bytes32 positionId) view returns (address)",
23843
- "function setPositionDelegate(bytes32 positionId, address newDelegate) external",
23844
- "event PositionDelegateUpdated(bytes32 indexed positionId, address indexed oldDelegate, address indexed newDelegate)"
23845
- ];
23846
- async function setPositionDelegate(positionId, delegate, signer, registryAddress) {
23847
- const registry = new Contract7(
23848
- registryAddress,
23849
- POSITION_DELEGATE_REGISTRY_ABI,
23850
- signer
23851
- );
23852
- return registry["setPositionDelegate"](positionId, delegate);
23853
- }
23854
- async function getPositionDelegate(positionId, provider, registryAddress) {
23855
- const registry = new Contract7(
23856
- registryAddress,
23857
- POSITION_DELEGATE_REGISTRY_ABI,
23858
- provider
23859
- );
23860
- return registry["positionDelegate"](positionId);
23861
- }
23862
25854
  export {
23863
25855
  ALL_CONTRACTS,
23864
25856
  ALL_DEPLOYMENTS,