@gvnrdao/dh-sdk 0.0.320 → 0.0.323

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.js CHANGED
@@ -90,7 +90,8 @@ var init_deployment_addresses = __esm({
90
90
  BitcoinWithdrawalAddressRegistry: "0x6376D392097F0A81e51BD83960A97EA20eaf1dbe",
91
91
  CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
92
92
  AgentDelegationRegistry: "0x6AE7fc6bE0925126b9D25b1B7Ce5AD5d127ec025",
93
- DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF"
93
+ DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF",
94
+ AgentModuleFactory: "0x1Fd3aCa2C030Cf77ce28Af9694D3Bb3034ACa2E5"
94
95
  },
95
96
  upgraded: {
96
97
  PositionManager: {
@@ -385,7 +386,8 @@ var init_deployment_addresses = __esm({
385
386
  BitcoinWithdrawalAddressRegistry: "0x6376D392097F0A81e51BD83960A97EA20eaf1dbe",
386
387
  CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
387
388
  AgentDelegationRegistry: "0x6AE7fc6bE0925126b9D25b1B7Ce5AD5d127ec025",
388
- DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF"
389
+ DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF",
390
+ AgentModuleFactory: "0x1Fd3aCa2C030Cf77ce28Af9694D3Bb3034ACa2E5"
389
391
  };
390
392
  MAINNET_DEPLOYMENT = {
391
393
  network: "mainnet",
@@ -622,7 +624,7 @@ var init_deployment_addresses = __esm({
622
624
  LOCALHOST_DEPLOYMENT = {
623
625
  network: "localhost",
624
626
  chainId: 1337,
625
- timestamp: "2026-07-20T19:45:58.514Z",
627
+ timestamp: "2026-07-23T17:13:42.777Z",
626
628
  deployer: "",
627
629
  contracts: {
628
630
  MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
@@ -642,6 +644,30 @@ var init_deployment_addresses = __esm({
642
644
  PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
643
645
  OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
644
646
  PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
647
+ },
648
+ latestEnv: {
649
+ UCD_TOKEN: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
650
+ UCD_CONTROLLER: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
651
+ POSITION_MANAGER: "0x851356ae760d987E095750cCeb3bC6014560891C",
652
+ PKP_VALIDATION_REGISTRY: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A",
653
+ PKP_VALIDATION_CID_V1: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
654
+ PKP_VALIDATION_CID_V3: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
655
+ PKP_ETH_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
656
+ OPERATION_AUTHORIZATION_REGISTRY: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
657
+ UCD_MINT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
658
+ UCD_MINT_VALIDATOR_VERSION: 1,
659
+ BTC_WITHDRAWAL_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
660
+ BTC_WITHDRAWAL_VALIDATOR_VERSION: 3,
661
+ UPDATE_BALANCE_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
662
+ UPDATE_BALANCE_VALIDATOR_VERSION: 1,
663
+ PROCESS_PAYMENT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
664
+ PROCESS_PAYMENT_VALIDATOR_VERSION: 1,
665
+ EXTEND_POSITION_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
666
+ EXTEND_POSITION_VALIDATOR_VERSION: 1,
667
+ POSITION_MANAGER_CORE_MODULE: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
668
+ LOAN_OPERATIONS_MANAGER_MODULE: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
669
+ TERM_MANAGER_MODULE: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
670
+ COMMUNITY_MANAGER_MODULE: ""
645
671
  }
646
672
  };
647
673
  LOCALHOST_CONTRACTS = {
@@ -2320,7 +2346,7 @@ ${errorReport}`);
2320
2346
  }
2321
2347
  init_debug_logger();
2322
2348
  init_session_signature_cache();
2323
- var import_ethers18 = require("ethers");
2349
+ var import_ethers19 = require("ethers");
2324
2350
  var EXPIRED_LOAN_MIN_LIQUIDATION_THRESHOLD_BPS = 11e3;
2325
2351
  var GRACE_PERIOD_DAYS = 30;
2326
2352
  var SATOSHIS_PER_BITCOIN = 100000000n;
@@ -5153,12 +5179,12 @@ ${auth.clientId}`;
5153
5179
  }
5154
5180
  async function executeVaultSnapshot(params) {
5155
5181
  global.ethers = {
5156
- ...import_ethers18.ethers,
5182
+ ...import_ethers19.ethers,
5157
5183
  providers: {
5158
- StaticJsonRpcProvider: import_ethers18.ethers.JsonRpcProvider
5184
+ StaticJsonRpcProvider: import_ethers19.ethers.JsonRpcProvider
5159
5185
  },
5160
- Contract: import_ethers18.ethers.Contract,
5161
- utils: import_ethers18.ethers
5186
+ Contract: import_ethers19.ethers.Contract,
5187
+ utils: import_ethers19.ethers
5162
5188
  // v6 moved utils to top level
5163
5189
  };
5164
5190
  global.Lit = {
@@ -5432,7 +5458,8 @@ function getSepoliaConfig() {
5432
5458
  bitcoinWithdrawalAddressRegistry: SEPOLIA_CONTRACTS.BitcoinWithdrawalAddressRegistry || "",
5433
5459
  carryAgentRegistry: SEPOLIA_CONTRACTS.CarryAgentRegistry || "",
5434
5460
  agentDelegationRegistry: SEPOLIA_CONTRACTS.AgentDelegationRegistry || "",
5435
- dhAgentDelegate: SEPOLIA_CONTRACTS.DHAgentDelegate || ""
5461
+ dhAgentDelegate: SEPOLIA_CONTRACTS.DHAgentDelegate || "",
5462
+ agentModuleFactory: SEPOLIA_CONTRACTS.AgentModuleFactory || ""
5436
5463
  },
5437
5464
  subgraphs: {
5438
5465
  // Lazy getter for the same module-init snapshot reason as serviceEndpoint.
@@ -5475,7 +5502,9 @@ function getMainnetConfig() {
5475
5502
  bitcoinWithdrawalAddressRegistry: MAINNET_CONTRACTS.BitcoinWithdrawalAddressRegistry || "",
5476
5503
  carryAgentRegistry: MAINNET_CONTRACTS.CarryAgentRegistry || "",
5477
5504
  agentDelegationRegistry: MAINNET_CONTRACTS.AgentDelegationRegistry || "",
5478
- dhAgentDelegate: MAINNET_CONTRACTS.DHAgentDelegate || ""
5505
+ dhAgentDelegate: MAINNET_CONTRACTS.DHAgentDelegate || "",
5506
+ // Empty on mainnet until the factory is deployed there — the ceremony is Sepolia-only.
5507
+ agentModuleFactory: MAINNET_CONTRACTS.AgentModuleFactory || ""
5479
5508
  },
5480
5509
  subgraphs: {
5481
5510
  diamondHandsUrl: "https://gateway-arbitrum.network.thegraph.com/api/subgraphs/id/CCTPsdYqco2jChDLLBQTbdJWwoukVoMt1cXeR9ti6r9A"
@@ -5682,6 +5711,7 @@ __export(src_exports, {
5682
5711
  getDelegateStatus: () => getDelegateStatus,
5683
5712
  getDeploymentByNetwork: () => getDeploymentByNetwork,
5684
5713
  getPositionDelegate: () => getPositionDelegate,
5714
+ getSafeAgentDelegation: () => getSafeAgentDelegation,
5685
5715
  isClosePositionAuth: () => isClosePositionAuth,
5686
5716
  isCreateLoanAuth: () => isCreateLoanAuth,
5687
5717
  isExtendTermAuth: () => isExtendTermAuth,
@@ -7338,7 +7368,7 @@ var defaultHttpGetJson = async (url) => {
7338
7368
  }
7339
7369
  return { status: res.status, body };
7340
7370
  };
7341
- async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = defaultHttpGetJson) {
7371
+ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = defaultHttpGetJson, opts) {
7342
7372
  const base = esploraBaseUrl.replace(/\/+$/, "");
7343
7373
  const fundingRes = await httpGetJson(`${base}/tx/${spend.txid}`);
7344
7374
  if (fundingRes.status === 404) {
@@ -7370,20 +7400,28 @@ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = def
7370
7400
  };
7371
7401
  }
7372
7402
  const onChainOutputValue = output.value;
7373
- if (onChainOutputValue !== spend.satoshis) {
7374
- return {
7375
- spend,
7376
- status: "CORRUPT",
7377
- onChainOutputValue,
7378
- reason: `Authorization declares ${spend.satoshis} sats for ${spend.txid}:${spend.vout} but the on-chain output is ${onChainOutputValue} sats`
7379
- };
7403
+ if (opts?.vaultAddress) {
7404
+ const outputAddress = (output.scriptpubkey_address ?? "").toLowerCase();
7405
+ if (outputAddress !== opts.vaultAddress.toLowerCase()) {
7406
+ return {
7407
+ spend,
7408
+ status: "CORRUPT",
7409
+ onChainOutputValue,
7410
+ reason: `Authorized outpoint ${spend.txid}:${spend.vout} pays ${output.scriptpubkey_address ?? "an unknown script"}, not the vault ${opts.vaultAddress}`
7411
+ };
7412
+ }
7413
+ } else {
7414
+ log.warn(
7415
+ "Withdrawal reconciliation: no vaultAddress supplied \u2014 skipping the vault-ownership check",
7416
+ { txid: spend.txid, vout: spend.vout }
7417
+ );
7380
7418
  }
7381
- if (spend.targetAmount > onChainOutputValue) {
7419
+ if (spend.targetAmount >= spend.satoshis) {
7382
7420
  return {
7383
7421
  spend,
7384
7422
  status: "CORRUPT",
7385
7423
  onChainOutputValue,
7386
- reason: `Authorized targetAmount ${spend.targetAmount} sats exceeds the ${onChainOutputValue}-sat output it is authorized against`
7424
+ reason: `Authorized targetAmount ${spend.targetAmount} sats is not below the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
7387
7425
  };
7388
7426
  }
7389
7427
  const outspendRes = await httpGetJson(
@@ -7873,13 +7911,13 @@ function isValidBase58CheckAddress(address) {
7873
7911
  return BASE58_VERSIONS_MAINNET.has(version) || BASE58_VERSIONS_TEST.has(version);
7874
7912
  }
7875
7913
  function isValidBech32Address(address) {
7876
- const lower = address.toLowerCase();
7877
- if (lower !== address && address !== address.toUpperCase()) {
7914
+ const lower2 = address.toLowerCase();
7915
+ if (lower2 !== address && address !== address.toUpperCase()) {
7878
7916
  return false;
7879
7917
  }
7880
7918
  const tryDecode = (codec) => {
7881
7919
  try {
7882
- const decoded = codec.decode(lower);
7920
+ const decoded = codec.decode(lower2);
7883
7921
  if (!BECH32_HRPS.has(decoded.prefix))
7884
7922
  return false;
7885
7923
  if (decoded.words.length < 1)
@@ -11934,7 +11972,7 @@ var GraphClient = class {
11934
11972
  });
11935
11973
  clearTimeout(timeout);
11936
11974
  if (!res.ok) {
11937
- if (res.status === 429 || res.status >= 500) {
11975
+ if (res.status >= 500) {
11938
11976
  await this.backoff(attempt);
11939
11977
  continue;
11940
11978
  }
@@ -11943,12 +11981,7 @@ var GraphClient = class {
11943
11981
  }
11944
11982
  const data = await res.json();
11945
11983
  if (data.errors?.length) {
11946
- const errMsg = JSON.stringify(data.errors);
11947
- if (errMsg.includes("rate limit") && attempt < this.maxRetries) {
11948
- await this.backoff(attempt);
11949
- continue;
11950
- }
11951
- throw new Error(`GraphQL errors: ${errMsg}`);
11984
+ throw new Error(`GraphQL errors: ${JSON.stringify(data.errors)}`);
11952
11985
  }
11953
11986
  return data.data ?? null;
11954
11987
  } catch (err) {
@@ -16856,6 +16889,50 @@ var _abi2 = [
16856
16889
  name: "AutoRepayEnabled",
16857
16890
  type: "event"
16858
16891
  },
16892
+ {
16893
+ anonymous: false,
16894
+ inputs: [
16895
+ {
16896
+ indexed: true,
16897
+ internalType: "bytes32",
16898
+ name: "positionId",
16899
+ type: "bytes32"
16900
+ },
16901
+ {
16902
+ indexed: true,
16903
+ internalType: "address",
16904
+ name: "borrower",
16905
+ type: "address"
16906
+ }
16907
+ ],
16908
+ name: "AutoWithdrawDisabled",
16909
+ type: "event"
16910
+ },
16911
+ {
16912
+ anonymous: false,
16913
+ inputs: [
16914
+ {
16915
+ indexed: true,
16916
+ internalType: "bytes32",
16917
+ name: "positionId",
16918
+ type: "bytes32"
16919
+ },
16920
+ {
16921
+ indexed: true,
16922
+ internalType: "address",
16923
+ name: "borrower",
16924
+ type: "address"
16925
+ },
16926
+ {
16927
+ indexed: false,
16928
+ internalType: "uint32",
16929
+ name: "minWithdrawRatioBps",
16930
+ type: "uint32"
16931
+ }
16932
+ ],
16933
+ name: "AutoWithdrawEnabled",
16934
+ type: "event"
16935
+ },
16859
16936
  {
16860
16937
  anonymous: false,
16861
16938
  inputs: [
@@ -17174,6 +17251,19 @@ var _abi2 = [
17174
17251
  stateMutability: "view",
17175
17252
  type: "function"
17176
17253
  },
17254
+ {
17255
+ inputs: [],
17256
+ name: "SCOPE_WITHDRAW",
17257
+ outputs: [
17258
+ {
17259
+ internalType: "uint32",
17260
+ name: "",
17261
+ type: "uint32"
17262
+ }
17263
+ ],
17264
+ stateMutability: "view",
17265
+ type: "function"
17266
+ },
17177
17267
  {
17178
17268
  inputs: [],
17179
17269
  name: "UPGRADE_INTERFACE_VERSION",
@@ -17364,6 +17454,40 @@ var _abi2 = [
17364
17454
  stateMutability: "view",
17365
17455
  type: "function"
17366
17456
  },
17457
+ {
17458
+ inputs: [
17459
+ {
17460
+ internalType: "bytes32",
17461
+ name: "positionId",
17462
+ type: "bytes32"
17463
+ },
17464
+ {
17465
+ internalType: "address",
17466
+ name: "caller",
17467
+ type: "address"
17468
+ }
17469
+ ],
17470
+ name: "canWithdraw",
17471
+ outputs: [
17472
+ {
17473
+ internalType: "bool",
17474
+ name: "ok",
17475
+ type: "bool"
17476
+ },
17477
+ {
17478
+ internalType: "enum IAgentDelegationRegistry.DenyReason",
17479
+ name: "reason",
17480
+ type: "uint8"
17481
+ },
17482
+ {
17483
+ internalType: "uint32",
17484
+ name: "effectiveFloorBps",
17485
+ type: "uint32"
17486
+ }
17487
+ ],
17488
+ stateMutability: "view",
17489
+ type: "function"
17490
+ },
17367
17491
  {
17368
17492
  inputs: [],
17369
17493
  name: "core",
@@ -17416,6 +17540,19 @@ var _abi2 = [
17416
17540
  stateMutability: "nonpayable",
17417
17541
  type: "function"
17418
17542
  },
17543
+ {
17544
+ inputs: [
17545
+ {
17546
+ internalType: "bytes32",
17547
+ name: "positionId",
17548
+ type: "bytes32"
17549
+ }
17550
+ ],
17551
+ name: "disableAutoWithdraw",
17552
+ outputs: [],
17553
+ stateMutability: "nonpayable",
17554
+ type: "function"
17555
+ },
17419
17556
  {
17420
17557
  inputs: [
17421
17558
  {
@@ -17460,6 +17597,24 @@ var _abi2 = [
17460
17597
  stateMutability: "nonpayable",
17461
17598
  type: "function"
17462
17599
  },
17600
+ {
17601
+ inputs: [
17602
+ {
17603
+ internalType: "bytes32",
17604
+ name: "positionId",
17605
+ type: "bytes32"
17606
+ },
17607
+ {
17608
+ internalType: "uint32",
17609
+ name: "minWithdrawRatioBps",
17610
+ type: "uint32"
17611
+ }
17612
+ ],
17613
+ name: "enableAutoWithdraw",
17614
+ outputs: [],
17615
+ stateMutability: "nonpayable",
17616
+ type: "function"
17617
+ },
17463
17618
  {
17464
17619
  inputs: [
17465
17620
  {
@@ -17486,6 +17641,11 @@ var _abi2 = [
17486
17641
  internalType: "uint32",
17487
17642
  name: "minCollateralRatioBps",
17488
17643
  type: "uint32"
17644
+ },
17645
+ {
17646
+ internalType: "uint32",
17647
+ name: "minWithdrawRatioBps",
17648
+ type: "uint32"
17489
17649
  }
17490
17650
  ],
17491
17651
  internalType: "struct IAgentDelegationRegistry.LoanGrant",
@@ -17970,7 +18130,7 @@ var _abi2 = [
17970
18130
  type: "function"
17971
18131
  }
17972
18132
  ];
17973
- var _bytecode2 = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b604051612d3290816100f0823960805181818161101d01526112020152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe608080604052600436101561001357600080fd5b60003560e01c90816301ffc9a714611dec575080630d33f3c214611dc85780630f3f4a9414611d7d5780631459457a146119d757806318c38b89146118c65780631d444541146117f5578063248a9ca3146117cf5780632ec22d4c1461170e5780632f0647ce146116935780632f2ff15d1461166257806336568abe1461161c578063392f1087146115cf5780633f4ba83a146114d75780633f5aadc9146114685780634f1ef28614611186578063523403631461109d5780635273b6f61461107457806352d1902d1461100a578063554c4f4b14610f7a578063561b7f8a14610e4e5780635bc26aea14610dc15780635c975abb14610d915780636289d18c14610d105780636711cc0b14610cf45780636e852a7814610bf35780637e35bf6e14610bbf5780638343f67414610b925780638456cb5914610a9c5780638f33527f14610a625780639010d07c14610a0e57806391d14854146109b45780639b9d30c11461098b578063a19af3f6146108c9578063a217fddf146108ad578063a3246ad3146107eb578063a8780864146107cf578063ac3c0e30146106c2578063ad3cb1cc1461067b578063b3fad638146105ef578063c34e9c26146105d3578063ca15c8731461059a578063d547741f14610562578063dd71d99a14610520578063e0922fa114610473578063efa9b4ae14610404578063f2f4eb26146103db578063f68e9553146103b2578063fd437d39146102735763ffa1ad741461023a57600080fd5b3461026e57600036600319011261026e5761026a610256611fb9565b604051918291602083526020830190611f94565b0390f35b600080fd5b3461026e57606036600319011261026e5761028c611e6f565b610294611e59565b9061029d611f5b565b906102a661247b565b6001600160a01b0316338190036103a25780600052600160205260406000209283549360ff8560e01c16600381101561038c5760010361037b57816001602092610312877fc5d5c5bbf10444998e0ea6d4725e79027b574e1c14ec929279e8a9a95c6c6e919688612929565b818060a01b038316828060a01b03198254161781556103318782612111565b0180546001600160401b031916426001600160401b03908116919091179091556001600160a01b0391821660008181526002855260409081902087905551969091168652951693a4005b632437e77160e11b60005260046000fd5b634e487b7160e01b600052602160045260246000fd5b62fca64560e31b60005260046000fd5b3461026e57600036600319011261026e576020604051600080516020612cc68339815191528152f35b3461026e57600036600319011261026e576003546040516001600160a01b039091168152602090f35b3461026e57602036600319011261026e5760043561042061247b565b61044261042c826124c6565b9190600163ffffffff825460a01c161790612037565b6001600160a01b0316907f812690e0a9dff5bf3add998111b8af5c8299608d859025bfe35662060ab4267d600080a3005b3461026e57602036600319011261026e576004356001600160401b0381169081810361026e576000546001600160a01b038116330361050f57600160a01b600160e01b0319811660a092831b600160a01b600160e01b031617600055604080519190921c6001600160401b0316815260208101929092527f9c195448332abd01f716db873b329752ea02f19d33f7e311fb0daf082c4edd0391a1005b6349db3bd360e01b60005260046000fd5b3461026e57602036600319011261026e576001600160a01b03610541611e6f565b166000526002602052602060018060a01b0360406000205416604051908152f35b3461026e57604036600319011261026e57610598600435610581611e59565b9061059361058e82612016565b6123a5565b612437565b005b3461026e57602036600319011261026e57600435600052600080516020612bc68339815191526020526020604060002054604051908152f35b3461026e57600036600319011261026e57602060405160028152f35b3461026e57602036600319011261026e5760006040805161060f81611f02565b828152826020820152015260043560005260046020526060604060002063ffffffff6040519161063e83611f02565b548160018060a01b038216938481528160406020830192828660a01c168452019360c01c1683526040519485525116602084015251166040820152f35b3461026e57600036600319011261026e5761026a604080519061069e8183611f1d565b60058252640352e302e360dc1b602083015251918291602083526020830190611f94565b3461026e57602036600319011261026e576106db611e6f565b600060806040516106eb81611ed1565b828152826020820152826040820152826060820152015260018060a01b03166000526001602052604060002060405161072381611ed1565b81546001600160a01b038116825260a081901c6001600160401b03166020830190815292604083019160e01c60ff1690600382101561038c57908252600101546001600160401b0380821660608501908152604092831c821660808601908152925194516001600160a01b031685529451166020840152905192600384101561038c57604083019390935291516001600160401b0390811660608301529151909116608082015260a090f35b3461026e57600036600319011261026e57602060405160018152f35b3461026e57602036600319011261026e57600435600052600080516020612bc683398151915260205260406000206040518060208354918281520190819360005260206000209060005b818110610897575050508161084b910382611f1d565b6040519182916020830190602084525180915260408301919060005b818110610875575050500390f35b82516001600160a01b0316845285945060209384019390920191600101610867565b8254845260209093019260019283019201610835565b3461026e57600036600319011261026e57602060405160008152f35b3461026e57604036600319011261026e576004356108e5611ebe565b906108ee61247b565b63ffffffff600554169163ffffffff811692808410908115610982575b506109715760207f1da95b87b4c773f68c1447ffc5644e41a8a8887d55065beb64852014cf7140be9161095e610940856124c6565b9290610959600463ffffffff835460a01c161782612037565b611fdc565b6040519485526001600160a01b031693a3005b634346c13160e01b60005260046000fd5b9050158461090b565b3461026e57600036600319011261026e576020604051600080516020612c068339815191528152f35b3461026e57604036600319011261026e576109cd611e59565b600435600052600080516020612ca683398151915260205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b3461026e57604036600319011261026e57600435600052600080516020612bc68339815191526020526020610a4960243560406000206129f2565b905460405160039290921b1c6001600160a01b03168152f35b3461026e57602036600319011261026e576001600160a01b03610a83611e6f565b1660005260026020526020604060002054604051908152f35b3461026e57600036600319011261026e573360009081527f0ac8cc3d209806126662940717264973110c39045b305f6ba49613325a615e09602052604090205460ff1615610b6b57610aec61247b565b600160ff19600080516020612ce6833981519152541617600080516020612ce6833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a2005b63e2517d3f60e01b60005233600452600080516020612c0683398151915260245260446000fd5b3461026e57600036600319011261026e5760005460405160a09190911c6001600160401b03168152602090f35b3461026e57604036600319011261026e57610be3610bdb611e59565b6004356120de565b9061026a60405192839283611e8f565b3461026e57604036600319011261026e57610c0c611e6f565b336000908152600080516020612c46833981519152602052604090205460ff161580610ce1575b6103a2576001600160a01b03166000818152600160205260409020805460e01c60ff16600381101561038c5760010361037b57805460ff60e01b198116600160e11b1782556001919091018054600160401b600160801b03191642604090811b600160401b600160801b0316919091179091555160243581526001600160a01b0390911691907fc0499cc07ed9d734deec6857802d3f0fa8d5afaf79a7008beb8ba7bef62a271b90602090a3005b50336001600160a01b0382161415610c33565b3461026e57600036600319011261026e57602060405160048152f35b3461026e57602036600319011261026e57610d29611eab565b6000546001600160a01b0316330361050f5763ffffffff8116908115610d8057600080516020612c8683398151915291610d7b63ffffffff926005549284198416176005556040519384931683611fff565b0390a1005b6338f3377360e21b60005260046000fd5b3461026e57600036600319011261026e57602060ff600080516020612ce683398151915254166040519015158152f35b3461026e57602036600319011261026e57610dda611e6f565b6000546001600160a01b038116903382900361050f576001600160a01b038316928315610e3d573b15610e2c576001600160a01b03191682176000908155600080516020612c668339815191529080a3005b636f7c43f160e01b60005260046000fd5b63e6c4247b60e01b60005260046000fd5b3461026e57606036600319011261026e57610e67611e6f565b610e6f611e59565b610e77611f5b565b91610e8061247b565b6001600160a01b031690338290036103a257816000526001602052604060002060ff815460e01c16600381101561038c57600114610f695781602091610ee8867ff223dc085722c94c84dcf67427e225799be616382a2a484d378f8921c69a20339587612929565b80546001600160a01b0319166001600160a01b038316178155610f0b8682612111565b6001810180546001600160801b031916426001600160401b0390811691909117909155815460ff60e01b1916600160e01b179091556001600160a01b03919091166000818152600284526040908190208690555195909116855293a3005b639d2c8fdf60e01b60005260046000fd5b3461026e57602036600319011261026e576001600160a01b03610f9b611e6f565b166000526001602052604060002060ff600080516020612ce683398151915254161580610fee575b60209181610fd7575b506040519015158152f35b5460a01c6001600160401b03164210905082610fcc565b5060ff815460e01c1690600382101561038c5790600114610fc3565b3461026e57600036600319011261026e577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163003611063576020604051600080516020612c268339815191528152f35b63703e46dd60e11b60005260046000fd5b3461026e57600036600319011261026e576000546040516001600160a01b039091168152602090f35b3461026e57602036600319011261026e57600435604060008281526004602052209081549160018060a01b038316928315908115611177575b5061116657336000908152600080516020612c46833981519152602052604090205460ff16158061115c575b61114b578061111e63fffffffe611124935460a01c1682612037565b82612381565b7fa5ffbdba01b15df97334e34ad816b9986b6057a5ddc97aba93b7e8ccd21759ed600080a3005b630a606ec360e11b60005260046000fd5b5082331415611102565b6360eb6c2360e01b60005260046000fd5b6001915060a01c1615846110d6565b604036600319011261026e5761119a611e6f565b602435906001600160401b03821161026e573660238301121561026e578160040135906111c682611f40565b916111d46040519384611f1d565b8083526020830193366024838301011161026e57816000926024602093018737840101526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016308114908115611445575b50611063576000546001600160a01b0316330361050f576001600160a01b038116928315610e3d57813b156114345730841461142557600080516020612c26833981519152548461127c611fb9565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f6112b260405192604084526040840190611f94565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa600091816113f1575b506113025785634c9c8ce360e01b60005260045260246000fd5b9081600080516020612c268339815191528793036113dd5750833b156113c8576001600160a01b0319168117600080516020612c26833981519152557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28251156113ad5760008091610598945190845af43d156113a5573d9161138883611f40565b926113966040519485611f1d565b83523d6000602085013e612b64565b606091612b64565b505050346113b757005b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60005260045260246000fd5b632a87526960e21b60005260045260246000fd5b9091506020813d60201161141d575b8161140d60209383611f1d565b8101031261026e575190876112e8565b3d9150611400565b614e8d60eb1b60005260046000fd5b632e07c4bd60e11b60005260046000fd5b600080516020612c26833981519152546001600160a01b0316141590508461122d565b3461026e57602036600319011261026e5760043561148461247b565b6114a6611490826124c6565b9190600263ffffffff825460a01c161790612037565b6001600160a01b0316907fc2713e691344add4705edc62a0ee5aede95ba66ad68f97316efef9cb50644edd600080a3005b3461026e57600036600319011261026e57336000908152600080516020612c46833981519152602052604090205460ff1615806115ba575b6115a957600080516020612ce68339815191525460ff8116156115985760ff1916600080516020612ce6833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a2005b638dfc202b60e01b60005260046000fd5b63659a07b360e11b60005260046000fd5b506000546001600160a01b031633141561150f565b3461026e57604036600319011261026e57606063ffffffff6115fa6115f2611e59565b60043561205a565b90604093929351931515845261160f81611e85565b6020840152166040820152f35b3461026e57604036600319011261026e57611635611e59565b336001600160a01b038216036116515761059890600435612437565b63334bd91960e11b60005260046000fd5b3461026e57604036600319011261026e57610598600435611681611e59565b9061168e61058e82612016565b6123ef565b3461026e57602036600319011261026e576004356116dd6116b38261230f565b91906116c963fffffffb825460a01c1682612037565b805463ffffffff60c01b1916815583612381565b6001600160a01b0316907f09cb4ec44cdef8489412844b9682f87f7900758fa2bd7e039113e9125e538e0f600080a3005b3461026e57602036600319011261026e57600435604060008281526004602052209081549160018060a01b0383169283159081156117c0575b5061116657336000908152600080516020612c46833981519152602052604090205460ff1615806117b6575b61114b578061111e63fffffffd61178f935460a01c1682612037565b7fb390ab029eab314bd18190ebe73d7e5c1c336beaa5c83ac22578378dc9ccc405600080a3005b5082331415611773565b6002915060a01c161584611747565b3461026e57602036600319011261026e5760206117ed600435612016565b604051908152f35b3461026e57604036600319011261026e57600435611811611ebe565b63ffffffff600554169063ffffffff8116918083109081156118bd575b506109715761183c8361230f565b909263ffffffff845460c01c16809260018060a01b031633141591826118b2575b50506118a15761188d827e8a218591d4362499c38c38eb1c12e7a7cc97a9068818d1fe6046a42ba4a5ba94611fdc565b61189c60405192839283611fff565b0390a2005b634e80a40760e11b60005260046000fd5b11159050818661185d565b9050158461182e565b3461026e57602036600319011261026e576118df611eab565b600080516020612d068339815191525460ff8160401c169081156119bf575b506119ae57600080516020612d06833981519152805460026001600160401b0319821681179092556000546001600160481b031990911690911791906001600160a01b0316330361050f5763ffffffff168015610d8057604081600080516020612c868339815191529263ffffffff196005541617600555815190600082526020820152a1600080516020612d0683398151915255600080516020612be6833981519152602060405160028152a1005b63f92ee8a960e01b60005260046000fd5b60026001600160401b039190911610159050826118fe565b3461026e5760a036600319011261026e576119f0611e6f565b6119f8611e59565b906044356001600160a01b03811680820361026e576064356001600160a01b0381169182820361026e576084356001600160a01b038116949085900361026e57600080516020612d0683398151915254604081901c60ff161596906001600160401b031680159081611d75575b6001149081611d6b575b159081611d62575b506119ae57600080516020612d0683398151915280546001600160401b031916600117905586611d3d575b611aaa6127b2565b611ab26127b2565b611aba6127b2565b611ac26127b2565b6001600160a01b038116908115610e3d578315610e3d578515610e3d576001600160a01b038916988915610e3d573b15610e2c57858414611d2c5762aa36a746148015611d21575b8015611d16575b1580611d04575b610e2c57611b279060006127e0565b9081611cbd575b5015611c0257611b4c90600080516020612cc68339815191526127e0565b9081611c68575b5015611c0257611b7190600080516020612c068339815191526127e0565b9081611c13575b5015611c0257600080546001600160a01b031916841781556040519390600080516020612c668339815191528180a38015610e3d57803b15610e2c57600380546001600160a01b031916919091179055611bce57005b600080516020612d06833981519152805460ff60401b1916905560018152600080516020612be683398151915290602090a1005b63cf5a8e3360e01b60005260046000fd5b600080516020612c06833981519152600052600080516020612bc6833981519152602052611c61907ffff5b43478fa6840382eb63777e0da6941d320b940e3f70f0ea4780feff95827612a20565b5084611b78565b600080516020612cc6833981519152600052600080516020612bc6833981519152602052611cb6907f32d31393d541a265984ec379cddd8b1fcbe5f2b0eb8ad81dddfead454f135eaa612a20565b5086611b53565b60008052600080516020612bc6833981519152602052611cfd907f615f0f9e84155bea8cc509fe18befeb1baf65611e38a6ba60964480fb29dfd44612a20565b5088611b2e565b50823b1580611b185750843b15611b18565b50617a694614611b11565b506105394614611b0a565b638135316560e01b60005260046000fd5b600080516020612d06833981519152805460ff60401b1916600160401b179055611aa2565b90501589611a77565b303b159150611a6f565b889150611a65565b3461026e57604036600319011261026e5761026a611db1611d9c611e59565b6004356000526004602052604060002061213a565b611dba81611e85565b604051918183921583611e8f565b3461026e57600036600319011261026e57602063ffffffff60055416604051908152f35b3461026e57602036600319011261026e576004359063ffffffff60e01b821680920361026e57602091635a05180f60e01b8114908115611e2e575b5015158152f35b637965db0b60e01b811491508115611e48575b5083611e27565b6301ffc9a760e01b14905083611e41565b602435906001600160a01b038216820361026e57565b600435906001600160a01b038216820361026e57565b6008111561038c57565b901515815260408101929190602090611ea783611e85565b0152565b6004359063ffffffff8216820361026e57565b6024359063ffffffff8216820361026e57565b60a081019081106001600160401b03821117611eec57604052565b634e487b7160e01b600052604160045260246000fd5b606081019081106001600160401b03821117611eec57604052565b601f909101601f19168101906001600160401b03821190821017611eec57604052565b6001600160401b038111611eec57601f01601f191660200190565b604435906001600160401b038216820361026e57565b60005b838110611f845750506000910152565b8181015183820152602001611f74565b90602091611fad81518092818552858086019101611f71565b601f01601f1916010190565b60405190611fc8604083611f1d565b60058252640322e302e360dc1b6020830152565b805463ffffffff60c01b191660c09290921b63ffffffff60c01b16919091179055565b63ffffffff91821681529116602082015260400190565b600052600080516020612ca683398151915260205260016040600020015490565b805463ffffffff60a01b191660a09290921b63ffffffff60a01b16919091179055565b9190916000526004602052612074604060002092836121f7565b9161207e83611e85565b826120d45763ffffffff9192505460c01c1663ffffffff60055416811580156120cc575b6120bf578082106120b857505b60019160009190565b90506120af565b5050600090600390600090565b5080156120a2565b5060009190600090565b906120f59160005260046020526040600020612283565b6120fe81611e85565b8061210c5750600190600090565b600091565b8054600160a01b600160e01b03191660a09290921b600160a01b600160e01b0316919091179055565b60ff600080516020612ce683398151915254166121f057546001600160a01b0381169081156121e85760a01c600216156121e15760005260016020526040600020549060ff8260e01c16600381101561038c5780156121d9576002146121d2574260a083901c6001600160401b031611156121cb576001600160a01b039081169116036121c657600090565b600790565b5050600690565b5050600590565b505050600490565b5050600390565b505050600290565b5050600190565b60ff600080516020612ce683398151915254166121f057546001600160a01b0381169081156121e85760a01c600416156121e15760005260016020526040600020549060ff8260e01c16600381101561038c5780156121d9576002146121d2574260a083901c6001600160401b031611156121cb576001600160a01b039081169116036121c657600090565b60ff600080516020612ce683398151915254166121f057546001600160a01b0381169081156121e85760a01c600116156121e15760005260016020526040600020549060ff8260e01c16600381101561038c5780156121d9576002146121d2574260a083901c6001600160401b031611156121cb576001600160a01b039081169116036121c657600090565b6000908152600460205260409020805490916001600160a01b038216918215908115612372575b5061116657336000908152600080516020612c46833981519152602052604090205460ff161580612368575b61114b57565b5081331415612362565b6004915060a01c161538612336565b905460a01c63ffffffff16156123945750565b600052600460205260006040812055565b6000818152600080516020612ca68339815191526020908152604080832033845290915290205460ff16156123d75750565b63e2517d3f60e01b6000523360045260245260446000fd5b6123f982826127e0565b918261240457505090565b6000918252600080516020612bc68339815191526020526040909120612433916001600160a01b031690612a20565b5090565b6124418282612889565b918261244c57505090565b6000918252600080516020612bc68339815191526020526040909120612433916001600160a01b031690612a91565b60ff600080516020612ce6833981519152541661249457565b63d93c066560e01b60005260046000fd5b519064ffffffffff8216820361026e57565b519061ffff8216820361026e57565b80156127a157600354604051638d34875560e01b8152600481018390529190600090839060249082906001600160a01b03165afa918215612795576000926125ea575b5060808201516001600160a01b0316913383900361114b57610120015161252f81611e85565b61253881611e85565b600381149081156125d5575b81156125c1575b506125b05781600052600160205260ff60406000205460e01c16600381101561038c5760010361259f57600090815260046020526040902080546001600160a01b0319166001600160a01b03831617815591565b632e68d1d360e21b60005260046000fd5b63e9f6db8560e01b60005260046000fd5b600791506125ce81611e85565b143861254b565b90506125e081611e85565b6005811490612544565b90913d8082843e6125fb8184611f1d565b820191602081840312612775578051906001600160401b03821161277d5701906101a08284031261277257604051926101a084016001600160401b038111858210176127815760409081528351855260208085015190860152838101519085015260608301516001600160401b03811161277d57830181601f8201121561277d5780519061268882611f40565b926126966040519485611f1d565b8284526020838301011161277957906126b59160208085019101611f71565b606084015260808201516001600160a01b03811681036127755760808401526126e060a083016124a5565b60a08401526126f160c083016124a5565b60c084015261270260e083016124b7565b60e084015261271461010083016124a5565b6101008401526101208201519060088210156127725750612765916101809161012085015261274661014082016124a5565b61014085015261275961016082016124b7565b610160850152016124a5565b6101808201529038612509565b80fd5b5080fd5b8380fd5b8280fd5b634e487b7160e01b83526041600452602483fd5b6040513d6000823e3d90fd5b637bb0b62160e01b60005260046000fd5b60ff600080516020612d068339815191525460401c16156127cf57565b631afcd79f60e31b60005260046000fd5b6000818152600080516020612ca6833981519152602090815260408083206001600160a01b038616845290915290205460ff16612882576000818152600080516020612ca6833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5050600090565b6000818152600080516020612ca6833981519152602090815260408083206001600160a01b038616845290915290205460ff1615612882576000818152600080516020612ca6833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b1580156129e1575b610e3d576001600160a01b03166000908152600260205260409020546129d0576001600160401b0316428111156129bf5760005460a01c6001600160401b03168015159182612994575b505061298357565b63e774e7b560e01b60005260046000fd5b9091504281039081116129a95711388061297b565b634e487b7160e01b600052601160045260246000fd5b63efa7aefd60e01b60005260046000fd5b633b53f64f60e21b60005260046000fd5b506001600160a01b03811615612931565b8054821015612a0a5760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b6001810190826000528160205260406000205415600014612a89578054600160401b811015611eec57612a74612a5d8260018794018555846129f2565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b505050600090565b9060018201918160005282602052604060002054801515600014612b5b5760001981018181116129a95782546000198101919082116129a957818103612b24575b50505080548015612b0e576000190190612aec82826129f2565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b612b44612b34612a5d93866129f2565b90549060031b1c928392866129f2565b905560005283602052604060002055388080612ad2565b50505050600090565b90612b8a5750805115612b7957602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580612bbc575b612b9b575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15612b9356fec1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e82371705932000c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc07966f2ab141347034724e9b2a472c2f77f5cd745aeba27cacba797b8fcb708617dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846cd37bc77615afefc793aa17d75d4249a9b517ba91b0e54a49c9c4a44b3d7e228302dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800edcc084d3dcd65a1f7f23c65c46722faca6953d28e43150a467cf43e5c309238cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c6343000822000a";
18133
+ var _bytecode2 = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161304c90816100f0823960805181818161114401526113290152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe608080604052600436101561001357600080fd5b60003560e01c90816301ffc9a714611ff7575080630d33f3c214611fd35780630f3f4a9414611f885780631459457a14611be257806318c38b8914611ad15780631d44454114611a005780632106764c146119d9578063248a9ca3146119b35780632ec22d4c146118f25780632f0647ce146118775780632f2ff15d14611846578063324207441461177257806336568abe1461172c578063392f1087146116f65780633f4ba83a146115fe5780633f5aadc91461158f5780634f1ef286146112ad57806352340363146111c45780635273b6f61461119b57806352d1902d14611131578063554c4f4b146110a1578063561b7f8a14610f755780635bc26aea14610ee85780635c975abb14610eb85780636289d18c14610e375780636711cc0b14610e1b5780636e852a7814610d1a5780637e35bf6e14610ce65780638343f67414610cb95780638456cb5914610bc35780638f33527f14610b895780639010d07c14610b3557806391d1485414610adb5780639b9d30c114610ab2578063a19af3f614610a01578063a217fddf146109e5578063a3246ad314610923578063a878086414610907578063ac3c0e30146107fa578063ad3cb1cc146107b3578063b3fad6381461070e578063c34e9c26146106f2578063c86deb31146106d6578063ca15c8731461069d578063d547741f14610665578063dd71d99a14610623578063e0922fa114610576578063efa9b4ae14610507578063f2f4eb26146104de578063f68e9553146104b5578063f94f67ab146103de578063fd437d391461029f5763ffa1ad741461026657600080fd5b3461029a57600036600319011261029a576102966102826121ed565b6040519182916020835260208301906121c8565b0390f35b600080fd5b3461029a57606036600319011261029a576102b861207a565b6102c0612064565b906102c961218f565b906102d2612795565b6001600160a01b0316338190036103ce5780600052600160205260406000209283549360ff8560e01c1660038110156103b8576001036103a75781600160209261033e877fc5d5c5bbf10444998e0ea6d4725e79027b574e1c14ec929279e8a9a95c6c6e919688612c43565b818060a01b038316828060a01b031982541617815561035d878261239f565b0180546001600160401b031916426001600160401b03908116919091179091556001600160a01b0391821660008181526002855260409081902087905551969091168652951693a4005b632437e77160e11b60005260046000fd5b634e487b7160e01b600052602160045260246000fd5b62fca64560e31b60005260046000fd5b3461029a57604036600319011261029a576004356103fa6120c9565b90610403612795565b63ffffffff600554169163ffffffff8116928084109081156104ac575b5061049b5760207f6b7727cc9c3df4a29acf0afe01594c1b7e845d20f40f4a14e4c292164a9ed8e191610452846127e0565b9161046a600863ffffffff845460a01c1617836122e3565b81546001600160e01b031660e09190911b6001600160e01b0319161790556040519485526001600160a01b031693a3005b634346c13160e01b60005260046000fd5b90501584610420565b3461029a57600036600319011261029a576020604051600080516020612fe08339815191528152f35b3461029a57600036600319011261029a576003546040516001600160a01b039091168152602090f35b3461029a57602036600319011261029a57600435610523612795565b61054561052f826127e0565b9190600163ffffffff825460a01c1617906122e3565b6001600160a01b0316907f812690e0a9dff5bf3add998111b8af5c8299608d859025bfe35662060ab4267d600080a3005b3461029a57602036600319011261029a576004356001600160401b0381169081810361029a576000546001600160a01b038116330361061257600160a01b600160e01b0319811660a092831b600160a01b600160e01b031617600055604080519190921c6001600160401b0316815260208101929092527f9c195448332abd01f716db873b329752ea02f19d33f7e311fb0daf082c4edd0391a1005b6349db3bd360e01b60005260046000fd5b3461029a57602036600319011261029a576001600160a01b0361064461207a565b166000526002602052602060018060a01b0360406000205416604051908152f35b3461029a57604036600319011261029a5761069b600435610684612064565b90610696610691826122c2565b6126bf565b612751565b005b3461029a57602036600319011261029a57600435600052600080516020612ee08339815191526020526020604060002054604051908152f35b3461029a57600036600319011261029a57602060405160088152f35b3461029a57600036600319011261029a57602060405160028152f35b3461029a57602036600319011261029a576000606060405161072f81612136565b828152826020820152826040820152015260043560005260046020526080604060002063ffffffff6040519161076483612136565b548160018060a01b038216938481528160208201818560a01c16815260606040840193838760c01c168552019460e01c8552604051968752511660208601525116604084015251166060820152f35b3461029a57600036600319011261029a5761029660408051906107d68183612151565b60058252640352e302e360dc1b6020830152519182916020835260208301906121c8565b3461029a57602036600319011261029a5761081361207a565b6000608060405161082381612105565b828152826020820152826040820152826060820152015260018060a01b03166000526001602052604060002060405161085b81612105565b81546001600160a01b038116825260a081901c6001600160401b03166020830190815292604083019160e01c60ff169060038210156103b857908252600101546001600160401b0380821660608501908152604092831c821660808601908152925194516001600160a01b03168552945116602084015290519260038410156103b857604083019390935291516001600160401b0390811660608301529151909116608082015260a090f35b3461029a57600036600319011261029a57602060405160018152f35b3461029a57602036600319011261029a57600435600052600080516020612ee083398151915260205260406000206040518060208354918281520190819360005260206000209060005b8181106109cf5750505081610983910382612151565b6040519182916020830190602084525180915260408301919060005b8181106109ad575050500390f35b82516001600160a01b031684528594506020938401939092019160010161099f565b825484526020909301926001928301920161096d565b3461029a57600036600319011261029a57602060405160008152f35b3461029a57604036600319011261029a57600435610a1d6120c9565b90610a26612795565b63ffffffff600554169163ffffffff811692808410908115610aa9575b5061049b5760207f1da95b87b4c773f68c1447ffc5644e41a8a8887d55065beb64852014cf7140be91610a96610a78856127e0565b9290610a91600463ffffffff835460a01c1617826122e3565b612210565b6040519485526001600160a01b031693a3005b90501584610a43565b3461029a57600036600319011261029a576020604051600080516020612f208339815191528152f35b3461029a57604036600319011261029a57610af4612064565b600435600052600080516020612fc083398151915260205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b3461029a57604036600319011261029a57600435600052600080516020612ee08339815191526020526020610b706024356040600020612d0c565b905460405160039290921b1c6001600160a01b03168152f35b3461029a57602036600319011261029a576001600160a01b03610baa61207a565b1660005260026020526020604060002054604051908152f35b3461029a57600036600319011261029a573360009081527f0ac8cc3d209806126662940717264973110c39045b305f6ba49613325a615e09602052604090205460ff1615610c9257610c13612795565b600160ff19600080516020613000833981519152541617600080516020613000833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a2005b63e2517d3f60e01b60005233600452600080516020612f2083398151915260245260446000fd5b3461029a57600036600319011261029a5760005460405160a09190911c6001600160401b03168152602090f35b3461029a57604036600319011261029a57610d0a610d02612064565b60043561236c565b906102966040519283928361209a565b3461029a57604036600319011261029a57610d3361207a565b336000908152600080516020612f60833981519152602052604090205460ff161580610e08575b6103ce576001600160a01b03166000818152600160205260409020805460e01c60ff1660038110156103b8576001036103a757805460ff60e01b198116600160e11b1782556001919091018054600160401b600160801b03191642604090811b600160401b600160801b0316919091179091555160243581526001600160a01b0390911691907fc0499cc07ed9d734deec6857802d3f0fa8d5afaf79a7008beb8ba7bef62a271b90602090a3005b50336001600160a01b0382161415610d5a565b3461029a57600036600319011261029a57602060405160048152f35b3461029a57602036600319011261029a57610e506120b6565b6000546001600160a01b031633036106125763ffffffff8116908115610ea757600080516020612fa083398151915291610ea263ffffffff926005549284198416176005556040519384931683612233565b0390a1005b6338f3377360e21b60005260046000fd5b3461029a57600036600319011261029a57602060ff60008051602061300083398151915254166040519015158152f35b3461029a57602036600319011261029a57610f0161207a565b6000546001600160a01b0381169033829003610612576001600160a01b038316928315610f64573b15610f53576001600160a01b03191682176000908155600080516020612f808339815191529080a3005b636f7c43f160e01b60005260046000fd5b63e6c4247b60e01b60005260046000fd5b3461029a57606036600319011261029a57610f8e61207a565b610f96612064565b610f9e61218f565b91610fa7612795565b6001600160a01b031690338290036103ce57816000526001602052604060002060ff815460e01c1660038110156103b857600114611090578160209161100f867ff223dc085722c94c84dcf67427e225799be616382a2a484d378f8921c69a20339587612c43565b80546001600160a01b0319166001600160a01b038316178155611032868261239f565b6001810180546001600160801b031916426001600160401b0390811691909117909155815460ff60e01b1916600160e01b179091556001600160a01b03919091166000818152600284526040908190208690555195909116855293a3005b639d2c8fdf60e01b60005260046000fd5b3461029a57602036600319011261029a576001600160a01b036110c261207a565b166000526001602052604060002060ff60008051602061300083398151915254161580611115575b602091816110fe575b506040519015158152f35b5460a01c6001600160401b031642109050826110f3565b5060ff815460e01c169060038210156103b857906001146110ea565b3461029a57600036600319011261029a577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316300361118a576020604051600080516020612f408339815191528152f35b63703e46dd60e11b60005260046000fd5b3461029a57600036600319011261029a576000546040516001600160a01b039091168152602090f35b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b03831692831590811561129e575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff161580611283575b611272578061124563fffffffe61124b935460a01c16826122e3565b8261269b565b7fa5ffbdba01b15df97334e34ad816b9986b6057a5ddc97aba93b7e8ccd21759ed600080a3005b630a606ec360e11b60005260046000fd5b5082331415611229565b6360eb6c2360e01b60005260046000fd5b6001915060a01c1615846111fd565b604036600319011261029a576112c161207a565b602435906001600160401b03821161029a573660238301121561029a578160040135906112ed82612174565b916112fb6040519384612151565b8083526020830193366024838301011161029a57816000926024602093018737840101526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630811490811561156c575b5061118a576000546001600160a01b03163303610612576001600160a01b038116928315610f6457813b1561155b5730841461154c57600080516020612f4083398151915254846113a36121ed565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f6113d9604051926040845260408401906121c8565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa60009181611518575b506114295785634c9c8ce360e01b60005260045260246000fd5b9081600080516020612f408339815191528793036115045750833b156114ef576001600160a01b0319168117600080516020612f40833981519152557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28251156114d4576000809161069b945190845af43d156114cc573d916114af83612174565b926114bd6040519485612151565b83523d6000602085013e612e7e565b606091612e7e565b505050346114de57005b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60005260045260246000fd5b632a87526960e21b60005260045260246000fd5b9091506020813d602011611544575b8161153460209383612151565b8101031261029a5751908761140f565b3d9150611527565b614e8d60eb1b60005260046000fd5b632e07c4bd60e11b60005260046000fd5b600080516020612f40833981519152546001600160a01b03161415905084611354565b3461029a57602036600319011261029a576004356115ab612795565b6115cd6115b7826127e0565b9190600263ffffffff825460a01c1617906122e3565b6001600160a01b0316907fc2713e691344add4705edc62a0ee5aede95ba66ad68f97316efef9cb50644edd600080a3005b3461029a57600036600319011261029a57336000908152600080516020612f60833981519152602052604090205460ff1615806116e1575b6116d0576000805160206130008339815191525460ff8116156116bf5760ff1916600080516020613000833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a2005b638dfc202b60e01b60005260046000fd5b63659a07b360e11b60005260046000fd5b506000546001600160a01b0316331415611636565b3461029a57604036600319011261029a5761029661171d611715612064565b600435612306565b604093919351938493846120dc565b3461029a57604036600319011261029a57611745612064565b336001600160a01b038216036117615761069b90600435612751565b63334bd91960e11b60005260046000fd5b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b038316928315908115611837575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff16158061182d575b61127257806117f363fffffff7611806935460a01c16826122e3565b80546001600160e01b031681558261269b565b7f054490ec6650e07db9b97a06ea31d44cebd44b390c9975a380055e1b4d3cac21600080a3005b50823314156117d7565b6008915060a01c1615846117ab565b3461029a57604036600319011261029a5761069b600435611865612064565b90611872610691826122c2565b612709565b3461029a57602036600319011261029a576004356118c161189782612629565b91906118ad63fffffffb825460a01c16826122e3565b805463ffffffff60c01b191681558361269b565b6001600160a01b0316907f09cb4ec44cdef8489412844b9682f87f7900758fa2bd7e039113e9125e538e0f600080a3005b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b0383169283159081156119a4575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff16158061199a575b611272578061124563fffffffd611973935460a01c16826122e3565b7fb390ab029eab314bd18190ebe73d7e5c1c336beaa5c83ac22578378dc9ccc405600080a3005b5082331415611957565b6002915060a01c16158461192b565b3461029a57602036600319011261029a5760206119d16004356122c2565b604051908152f35b3461029a57604036600319011261029a5761029661171d6119f8612064565b60043561224a565b3461029a57604036600319011261029a57600435611a1c6120c9565b63ffffffff600554169063ffffffff811691808310908115611ac8575b5061049b57611a4783612629565b909263ffffffff845460c01c16809260018060a01b03163314159182611abd575b5050611aac57611a98827e8a218591d4362499c38c38eb1c12e7a7cc97a9068818d1fe6046a42ba4a5ba94612210565b611aa760405192839283612233565b0390a2005b634e80a40760e11b60005260046000fd5b111590508186611a68565b90501584611a39565b3461029a57602036600319011261029a57611aea6120b6565b6000805160206130208339815191525460ff8160401c16908115611bca575b50611bb957600080516020613020833981519152805460026001600160401b0319821681179092556000546001600160481b031990911690911791906001600160a01b031633036106125763ffffffff168015610ea757604081600080516020612fa08339815191529263ffffffff196005541617600555815190600082526020820152a160008051602061302083398151915255600080516020612f00833981519152602060405160028152a1005b63f92ee8a960e01b60005260046000fd5b60026001600160401b03919091161015905082611b09565b3461029a5760a036600319011261029a57611bfb61207a565b611c03612064565b906044356001600160a01b03811680820361029a576064356001600160a01b0381169182820361029a576084356001600160a01b038116949085900361029a5760008051602061302083398151915254604081901c60ff161596906001600160401b031680159081611f80575b6001149081611f76575b159081611f6d575b50611bb95760008051602061302083398151915280546001600160401b031916600117905586611f48575b611cb5612acc565b611cbd612acc565b611cc5612acc565b611ccd612acc565b6001600160a01b038116908115610f64578315610f64578515610f64576001600160a01b038916988915610f64573b15610f5357858414611f375762aa36a746148015611f2c575b8015611f21575b1580611f0f575b610f5357611d32906000612afa565b9081611ec8575b5015611e0d57611d5790600080516020612fe0833981519152612afa565b9081611e73575b5015611e0d57611d7c90600080516020612f20833981519152612afa565b9081611e1e575b5015611e0d57600080546001600160a01b031916841781556040519390600080516020612f808339815191528180a38015610f6457803b15610f5357600380546001600160a01b031916919091179055611dd957005b600080516020613020833981519152805460ff60401b1916905560018152600080516020612f0083398151915290602090a1005b63cf5a8e3360e01b60005260046000fd5b600080516020612f20833981519152600052600080516020612ee0833981519152602052611e6c907ffff5b43478fa6840382eb63777e0da6941d320b940e3f70f0ea4780feff95827612d3a565b5084611d83565b600080516020612fe0833981519152600052600080516020612ee0833981519152602052611ec1907f32d31393d541a265984ec379cddd8b1fcbe5f2b0eb8ad81dddfead454f135eaa612d3a565b5086611d5e565b60008052600080516020612ee0833981519152602052611f08907f615f0f9e84155bea8cc509fe18befeb1baf65611e38a6ba60964480fb29dfd44612d3a565b5088611d39565b50823b1580611d235750843b15611d23565b50617a694614611d1c565b506105394614611d15565b638135316560e01b60005260046000fd5b600080516020613020833981519152805460ff60401b1916600160401b179055611cad565b90501589611c82565b303b159150611c7a565b889150611c70565b3461029a57604036600319011261029a57610296611fbc611fa7612064565b600435600052600460205260406000206123c8565b611fc581612090565b60405191818392158361209a565b3461029a57600036600319011261029a57602063ffffffff60055416604051908152f35b3461029a57602036600319011261029a576004359063ffffffff60e01b821680920361029a57602091635a05180f60e01b8114908115612039575b5015158152f35b637965db0b60e01b811491508115612053575b5083612032565b6301ffc9a760e01b1490508361204c565b602435906001600160a01b038216820361029a57565b600435906001600160a01b038216820361029a57565b600811156103b857565b9015158152604081019291906020906120b283612090565b0152565b6004359063ffffffff8216820361029a57565b6024359063ffffffff8216820361029a57565b91604091949363ffffffff916060850196151585526120fa81612090565b602085015216910152565b60a081019081106001600160401b0382111761212057604052565b634e487b7160e01b600052604160045260246000fd5b608081019081106001600160401b0382111761212057604052565b601f909101601f19168101906001600160401b0382119082101761212057604052565b6001600160401b03811161212057601f01601f191660200190565b604435906001600160401b038216820361029a57565b60005b8381106121b85750506000910152565b81810151838201526020016121a8565b906020916121e1815180928185528580860191016121a5565b601f01601f1916010190565b604051906121fc604083612151565b60058252640322e312e360dc1b6020830152565b805463ffffffff60c01b191660c09290921b63ffffffff60c01b16919091179055565b63ffffffff91821681529116602082015260400190565b600052600460205261226160406000209182612485565b61226a81612090565b806122b857505460e01c63ffffffff60055416811580156122b0575b6122a35780821061229c57505b60019160009190565b9050612293565b5050600090600390600090565b508015612286565b6000929091508290565b600052600080516020612fc083398151915260205260016040600020015490565b805463ffffffff60a01b191660a09290921b63ffffffff60a01b16919091179055565b919091600052600460205261232060406000209283612511565b9161232a83612090565b826123625763ffffffff9192505460c01c1663ffffffff60055416811580156122b0576122a35780821061229c575060019160009190565b5060009190600090565b90612383916000526004602052604060002061259d565b61238c81612090565b8061239a5750600190600090565b600091565b8054600160a01b600160e01b03191660a09290921b600160a01b600160e01b0316919091179055565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6002161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b600790565b5050600690565b5050600590565b505050600490565b5050600390565b505050600290565b5050600190565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6008161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6004161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6001161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b6000908152600460205260409020805490916001600160a01b03821691821590811561268c575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff161580612682575b61127257565b508133141561267c565b6004915060a01c161538612650565b905460a01c63ffffffff16156126ae5750565b600052600460205260006040812055565b6000818152600080516020612fc08339815191526020908152604080832033845290915290205460ff16156126f15750565b63e2517d3f60e01b6000523360045260245260446000fd5b6127138282612afa565b918261271e57505090565b6000918252600080516020612ee0833981519152602052604090912061274d916001600160a01b031690612d3a565b5090565b61275b8282612ba3565b918261276657505090565b6000918252600080516020612ee0833981519152602052604090912061274d916001600160a01b031690612dab565b60ff60008051602061300083398151915254166127ae57565b63d93c066560e01b60005260046000fd5b519064ffffffffff8216820361029a57565b519061ffff8216820361029a57565b8015612abb57600354604051638d34875560e01b8152600481018390529190600090839060249082906001600160a01b03165afa918215612aaf57600092612904575b5060808201516001600160a01b0316913383900361127257610120015161284981612090565b61285281612090565b600381149081156128ef575b81156128db575b506128ca5781600052600160205260ff60406000205460e01c1660038110156103b8576001036128b957600090815260046020526040902080546001600160a01b0319166001600160a01b03831617815591565b632e68d1d360e21b60005260046000fd5b63e9f6db8560e01b60005260046000fd5b600791506128e881612090565b1438612865565b90506128fa81612090565b600581149061285e565b90913d8082843e6129158184612151565b820191602081840312612a8f578051906001600160401b038211612a975701906101a082840312612a8c57604051926101a084016001600160401b03811185821017612a9b5760409081528351855260208085015190860152838101519085015260608301516001600160401b038111612a9757830181601f82011215612a97578051906129a282612174565b926129b06040519485612151565b82845260208383010111612a9357906129cf91602080850191016121a5565b606084015260808201516001600160a01b0381168103612a8f5760808401526129fa60a083016127bf565b60a0840152612a0b60c083016127bf565b60c0840152612a1c60e083016127d1565b60e0840152612a2e61010083016127bf565b610100840152610120820151906008821015612a8c5750612a7f9161018091610120850152612a6061014082016127bf565b610140850152612a7361016082016127d1565b610160850152016127bf565b6101808201529038612823565b80fd5b5080fd5b8380fd5b8280fd5b634e487b7160e01b83526041600452602483fd5b6040513d6000823e3d90fd5b637bb0b62160e01b60005260046000fd5b60ff6000805160206130208339815191525460401c1615612ae957565b631afcd79f60e31b60005260046000fd5b6000818152600080516020612fc0833981519152602090815260408083206001600160a01b038616845290915290205460ff16612b9c576000818152600080516020612fc0833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5050600090565b6000818152600080516020612fc0833981519152602090815260408083206001600160a01b038616845290915290205460ff1615612b9c576000818152600080516020612fc0833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b158015612cfb575b610f64576001600160a01b0316600090815260026020526040902054612cea576001600160401b031642811115612cd95760005460a01c6001600160401b03168015159182612cae575b5050612c9d57565b63e774e7b560e01b60005260046000fd5b909150428103908111612cc357113880612c95565b634e487b7160e01b600052601160045260246000fd5b63efa7aefd60e01b60005260046000fd5b633b53f64f60e21b60005260046000fd5b506001600160a01b03811615612c4b565b8054821015612d245760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b6001810190826000528160205260406000205415600014612da3578054600160401b81101561212057612d8e612d77826001879401855584612d0c565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b505050600090565b9060018201918160005282602052604060002054801515600014612e75576000198101818111612cc3578254600019810191908211612cc357818103612e3e575b50505080548015612e28576000190190612e068282612d0c565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b612e5e612e4e612d779386612d0c565b90549060031b1c92839286612d0c565b905560005283602052604060002055388080612dec565b50505050600090565b90612ea45750805115612e9357602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580612ed6575b612eb5575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15612ead56fec1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e82371705932000c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc07966f2ab141347034724e9b2a472c2f77f5cd745aeba27cacba797b8fcb708617dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846cd37bc77615afefc793aa17d75d4249a9b517ba91b0e54a49c9c4a44b3d7e228302dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800edcc084d3dcd65a1f7f23c65c46722faca6953d28e43150a467cf43e5c309238cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c6343000822000a";
17974
18134
  var isSuperArgs2 = (xs) => xs.length > 1;
17975
18135
  var AgentDelegationRegistry__factory = class extends import_ethers15.ContractFactory {
17976
18136
  constructor(...args) {
@@ -18615,6 +18775,158 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
18615
18775
  return;
18616
18776
  await this.serverSession.adoptLoginPayload(payload);
18617
18777
  }
18778
+ /**
18779
+ * Build the Safe-delegation ceremony for a multi-sig Safe (Phase 1 of
18780
+ * multi-sig support): asks lit-ops-server to mint (or recover) the Safe's
18781
+ * agent PKP and returns the exact call batch the Safe's owners must execute
18782
+ * (AgentModuleFactory.deploy → safe.enableModule → registerAgent), derived
18783
+ * from live chain state so a half-done ceremony resumes.
18784
+ *
18785
+ * Service-mode only — the server holds the Chipotle account that mints the
18786
+ * PKP and it gates the route to current Safe owners. `knownAgentAddress` is
18787
+ * the caller-persisted agent from an earlier prepare whose ceremony has not
18788
+ * landed yet; echoing it back prevents a duplicate mint after a server
18789
+ * restart.
18790
+ */
18791
+ async prepareSafeAgentModule(request) {
18792
+ if (this.config.mode !== "service") {
18793
+ throw new Error(
18794
+ "prepareSafeAgentModule requires service mode \u2014 the agent PKP is minted by lit-ops-server's Chipotle account and cannot be minted standalone"
18795
+ );
18796
+ }
18797
+ const PREPARE_CLIENT_TIMEOUT_MS = 3e4;
18798
+ const abort = new AbortController();
18799
+ const abortTimer = setTimeout(() => abort.abort(), PREPARE_CLIENT_TIMEOUT_MS);
18800
+ let resp;
18801
+ try {
18802
+ resp = await fetch(
18803
+ `${this.config.serviceEndpoint}/api/lit/safe/agent-module/prepare`,
18804
+ {
18805
+ method: "POST",
18806
+ headers: {
18807
+ "Content-Type": "application/json",
18808
+ ...await this.getAuthHeader()
18809
+ },
18810
+ signal: abort.signal,
18811
+ body: JSON.stringify({
18812
+ safeAddress: request.safeAddress,
18813
+ ...request.knownAgentAddress ? { knownAgentAddress: request.knownAgentAddress } : {}
18814
+ })
18815
+ }
18816
+ );
18817
+ } catch (fetchErr) {
18818
+ throw abort.signal.aborted ? new Error(
18819
+ `prepareSafeAgentModule timed out after ${PREPARE_CLIENT_TIMEOUT_MS}ms \u2014 the delegation server did not answer`
18820
+ ) : fetchErr;
18821
+ } finally {
18822
+ clearTimeout(abortTimer);
18823
+ }
18824
+ const data = await resp.json().catch(() => null);
18825
+ if (!resp.ok || !data?.success) {
18826
+ throw new Error(
18827
+ `prepareSafeAgentModule failed (${resp.status}): ${data?.error ?? "no error detail from server"}`
18828
+ );
18829
+ }
18830
+ return {
18831
+ status: data.status,
18832
+ agentAddress: data.agentAddress,
18833
+ moduleAddress: data.moduleAddress,
18834
+ validUntil: data.validUntil,
18835
+ calls: data.calls
18836
+ };
18837
+ }
18838
+ /**
18839
+ * Shared transport for `/agent-module/{authorize,execute}`.
18840
+ *
18841
+ * Both routes run the agent PKP's key inside a Lit Action, gated on the
18842
+ * caller's session being a CURRENT Safe owner (M-8c). Service-mode only, for
18843
+ * the same reason as {@link prepareSafeAgentModule}: the key lives in the
18844
+ * server's Chipotle account and has no standalone equivalent.
18845
+ */
18846
+ async postAgentModuleRoute(mode, body) {
18847
+ if (this.config.mode !== "service") {
18848
+ throw new Error(
18849
+ `agentModule${mode === "authorize" ? "Authorize" : "Execute"} requires service mode \u2014 the agent PKP is held by lit-ops-server's Chipotle account`
18850
+ );
18851
+ }
18852
+ const AGENT_MODULE_CLIENT_TIMEOUT_MS = 45e3;
18853
+ const abort = new AbortController();
18854
+ const abortTimer = setTimeout(
18855
+ () => abort.abort(),
18856
+ AGENT_MODULE_CLIENT_TIMEOUT_MS
18857
+ );
18858
+ let resp;
18859
+ try {
18860
+ resp = await fetch(
18861
+ `${this.config.serviceEndpoint}/api/lit/agent-module/${mode}`,
18862
+ {
18863
+ method: "POST",
18864
+ headers: {
18865
+ "Content-Type": "application/json",
18866
+ ...await this.getAuthHeader()
18867
+ },
18868
+ signal: abort.signal,
18869
+ body: JSON.stringify(body)
18870
+ }
18871
+ );
18872
+ } catch (fetchErr) {
18873
+ throw abort.signal.aborted ? new Error(
18874
+ `agent-module ${mode} timed out after ${AGENT_MODULE_CLIENT_TIMEOUT_MS}ms \u2014 the delegation server did not answer`
18875
+ ) : fetchErr;
18876
+ } finally {
18877
+ clearTimeout(abortTimer);
18878
+ }
18879
+ const data = await resp.json().catch(() => null);
18880
+ if (!resp.ok || !data?.success) {
18881
+ throw new Error(
18882
+ `agent-module ${mode} failed (${resp.status}): ${data?.error ?? "no error detail from server"}`
18883
+ );
18884
+ }
18885
+ return data;
18886
+ }
18887
+ /**
18888
+ * The agent signs the borrower authorization envelope for `op` on `positionId`.
18889
+ *
18890
+ * The returned `{ timestamp, signature }` feeds the SDK's PRECOMPUTED
18891
+ * authorization path (`generateExtendAuthorization` and siblings) — the same
18892
+ * path Safe/EIP-1271 borrowers already use. It is NOT a generic message
18893
+ * signer: the Lit Action REBUILDS the envelope from these fields rather than
18894
+ * signing anything the caller supplies, which is what stops a delegated agent
18895
+ * key being turned into an arbitrary oracle.
18896
+ *
18897
+ * `timestamp` must be quantum-aligned by the caller
18898
+ * (`calculateNextQuantumTimestamp()`) and must be the SAME value later passed
18899
+ * to the protocol call, or the validator recovers a different signer.
18900
+ */
18901
+ async agentModuleAuthorize(request) {
18902
+ return this.postAgentModuleRoute("authorize", {
18903
+ safeAddress: request.safeAddress,
18904
+ positionId: request.positionId,
18905
+ op: request.op,
18906
+ timestamp: request.timestamp,
18907
+ ...request.amount !== void 0 ? { amount: request.amount } : {},
18908
+ ...request.selectedTerm !== void 0 ? { selectedTerm: request.selectedTerm } : {}
18909
+ });
18910
+ }
18911
+ /**
18912
+ * The agent signs `module.execute(target, innerData)` as a raw EIP-1559
18913
+ * transaction. Returns the SIGNED transaction — the caller broadcasts it, so
18914
+ * the tx hash and receipt come from the caller's own provider.
18915
+ *
18916
+ * `tx` fields are caller-supplied because the Lit Action runs on many nodes
18917
+ * and reconciles results: anything fetched in-action (nonce, gas) would
18918
+ * differ per node and fail consensus.
18919
+ */
18920
+ async agentModuleExecute(request) {
18921
+ return this.postAgentModuleRoute("execute", {
18922
+ safeAddress: request.safeAddress,
18923
+ positionId: request.positionId,
18924
+ op: request.op,
18925
+ target: request.target,
18926
+ innerData: request.innerData,
18927
+ tx: request.tx
18928
+ });
18929
+ }
18618
18930
  /**
18619
18931
  * Audit H-9: invalidate the LoanQuery cache so subsequent reads return
18620
18932
  * the post-write state. We clear the entire loan-query cache (not just
@@ -19644,7 +19956,12 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
19644
19956
  ...this.config.contractAddresses?.btcSpendAuthorizer ? { BTCSpendAuthorizer: this.config.contractAddresses.btcSpendAuthorizer } : {},
19645
19957
  ...this.config.contractAddresses?.bitcoinProviderRegistry ? { BitcoinProviderRegistry: this.config.contractAddresses.bitcoinProviderRegistry } : {},
19646
19958
  // Required for Safe-as-borrower auth verification (third arm).
19647
- ...this.config.contractAddresses?.positionDelegateRegistry ? { PositionDelegateRegistry: this.config.contractAddresses.positionDelegateRegistry } : {}
19959
+ ...this.config.contractAddresses?.positionDelegateRegistry ? { PositionDelegateRegistry: this.config.contractAddresses.positionDelegateRegistry } : {},
19960
+ // Required for the Safe-agent scoped mint grant (canMint) — without
19961
+ // this the LIT Action's agent-grant arm is skipped entirely and a
19962
+ // delegated agent signer falls through to the borrower/EIP-1271
19963
+ // arms, which reject it.
19964
+ ...this.config.contractAddresses?.agentDelegationRegistry ? { AgentDelegationRegistry: this.config.contractAddresses.agentDelegationRegistry } : {}
19648
19965
  };
19649
19966
  if (this.config.debug) {
19650
19967
  log.info(" Contract addresses passed to LIT Action:", {});
@@ -21301,7 +21618,12 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
21301
21618
  // Required for the LIT Action verifier's third auth arm in
21302
21619
  // Safe-as-borrower flows. See diamond-hands-sdk.ts:5786 for the same
21303
21620
  // pattern in the withdraw flow.
21304
- PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || ""
21621
+ PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || "",
21622
+ // Required for the Safe-agent scoped renew grant (canRenew) — without
21623
+ // this the LIT Action's agent-grant arm is skipped entirely and a
21624
+ // delegated agent signer falls through to the borrower/EIP-1271 arms,
21625
+ // which reject it.
21626
+ AgentDelegationRegistry: this.config.contractAddresses?.agentDelegationRegistry || ""
21305
21627
  };
21306
21628
  if (!contracts.PositionManager) {
21307
21629
  throw new Error("PositionManager address is required");
@@ -22038,7 +22360,12 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
22038
22360
  BTCSpendAuthorizer: this.config.contractAddresses?.btcSpendAuthorizer || "",
22039
22361
  BitcoinProviderRegistry: this.config.contractAddresses?.bitcoinProviderRegistry || "",
22040
22362
  // Required for Safe-as-borrower auth verification (third arm).
22041
- PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || ""
22363
+ PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || "",
22364
+ // Required for the Safe-agent scoped repay grant (canRepay) —
22365
+ // without this the LIT Action's agent-grant arm is skipped entirely
22366
+ // and a delegated agent signer falls through to the
22367
+ // borrower/EIP-1271 arms, which reject it.
22368
+ AgentDelegationRegistry: this.config.contractAddresses?.agentDelegationRegistry || ""
22042
22369
  };
22043
22370
  if (this.config.debug) {
22044
22371
  log.info(" Contract addresses:", {});
@@ -23306,6 +23633,11 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23306
23633
  * The service path's post-broadcast CRIT-2 re-verification exists to catch
23307
23634
  * a LYING SERVER; here the broadcast happens locally from the signatures we
23308
23635
  * just obtained, so the esplora-returned txid is already first-hand.
23636
+ *
23637
+ * Multi-UTXO consolidation in standalone mode requires the caller to supply
23638
+ * `request.utxos` explicitly — `fetchConfirmedVaultUtxos` is service-mode
23639
+ * only, so there is no automatic gather here; without the set, a multi-UTXO
23640
+ * vault fails in the signer with its "Insufficient UTXO value" error.
23309
23641
  */
23310
23642
  async executeBTCWithdrawalStandalonePhase2(request, envelope, txid, vout, chainId) {
23311
23643
  const positionDetails = await this.getPositionDetailsView(
@@ -23512,6 +23844,35 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23512
23844
  const network = await this.getProviderOrThrow().getNetwork();
23513
23845
  const chainId = Number(network.chainId);
23514
23846
  const signer = this.getSignerOrThrow();
23847
+ let executionUtxos = request.utxos;
23848
+ if (!executionUtxos || executionUtxos.length === 0) {
23849
+ const gathered = await this.fetchConfirmedVaultUtxos(request.positionId);
23850
+ if (gathered.length > 0) {
23851
+ const normTxid = (t) => String(t).toLowerCase().replace(/^0x/, "");
23852
+ const byOutpoint = /* @__PURE__ */ new Map();
23853
+ for (const u of gathered) {
23854
+ byOutpoint.set(`${normTxid(u.txid)}:${u.vout}`, {
23855
+ txid: normTxid(u.txid),
23856
+ vout: Number(u.vout),
23857
+ value: Number(u.value)
23858
+ });
23859
+ }
23860
+ if (!byOutpoint.has(`${normTxid(txid)}:${vout}`)) {
23861
+ return {
23862
+ success: false,
23863
+ error: `Authorized outpoint ${txid}:${vout} is missing from the vault's confirmed UTXO set \u2014 refusing to execute against an incoherent view of the vault`
23864
+ };
23865
+ }
23866
+ if (byOutpoint.size > 1) {
23867
+ executionUtxos = Array.from(byOutpoint.values());
23868
+ if (this.config.debug) {
23869
+ log.info("\u{1F9E9} Multi-UTXO withdrawal: gathered full input set", {
23870
+ inputs: executionUtxos.length
23871
+ });
23872
+ }
23873
+ }
23874
+ }
23875
+ }
23515
23876
  const envelope = await buildBtcExecuteEnvelope({
23516
23877
  positionId: request.positionId,
23517
23878
  txid,
@@ -23522,7 +23883,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23522
23883
  networkFee: request.networkFee,
23523
23884
  chainId,
23524
23885
  signer,
23525
- ...request.utxos ? { utxos: request.utxos } : {}
23886
+ ...executionUtxos ? { utxos: executionUtxos } : {}
23526
23887
  });
23527
23888
  if (this.config.mode !== "service") {
23528
23889
  return await this.executeBTCWithdrawalStandalonePhase2(
@@ -24737,6 +25098,49 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24737
25098
  }
24738
25099
  return addr;
24739
25100
  }
25101
+ /**
25102
+ * `LoanGrant` fields that EVERY deployed registry version returns.
25103
+ *
25104
+ * Deliberately omits `minWithdrawRatioBps` — see {@link readLoanGrant}.
25105
+ */
25106
+ static LOAN_GRANT_PREFIX_IFACE = new import_ethers17.Interface([
25107
+ "function getLoanGrant(bytes32 positionId) view returns (address borrower, uint32 scopeBits, uint32 minCollateralRatioBps)"
25108
+ ]);
25109
+ /**
25110
+ * Read a position's grant, decoding only the struct prefix that every deployed registry
25111
+ * version shares.
25112
+ *
25113
+ * `LoanGrant` gained a fourth member (`minWithdrawRatioBps`) in registry v2.1.0, and the
25114
+ * typechain bindings are generated from that source — but Sepolia (`0x6AE7fc6b…`) and mainnet
25115
+ * (`0x54853b7E…`) both run v2.0.0, whose `getLoanGrant` returns three words. Decoding that
25116
+ * with the generated four-field decoder fails `BAD_DATA` on every live chain, which is what
25117
+ * took the Agents tab down. The first three members are identical in both layouts, and ethers
25118
+ * ignores the trailing static word on a v2.1.0 registry, so this decoder is correct against
25119
+ * both. Nothing in this SDK reads `minWithdrawRatioBps`: WITHDRAW is not a scope it grants.
25120
+ */
25121
+ async readLoanGrant(registryAddress, pid) {
25122
+ const iface = _DiamondHandsSDK.LOAN_GRANT_PREFIX_IFACE;
25123
+ const data = await this.getProviderOrThrow().call({
25124
+ to: registryAddress,
25125
+ data: iface.encodeFunctionData("getLoanGrant", [pid])
25126
+ });
25127
+ if ((0, import_ethers17.getBytes)(data).length < 96) {
25128
+ throw new SDKError({
25129
+ message: `AgentDelegationRegistry at ${registryAddress} returned ${(0, import_ethers17.getBytes)(data).length} bytes for getLoanGrant(bytes32) \u2014 expected at least 96. Wrong address, or a registry version this SDK does not support.`,
25130
+ category: "CONTRACT" /* CONTRACT */,
25131
+ severity: "HIGH" /* HIGH */
25132
+ });
25133
+ }
25134
+ const [borrower, scopeBits, minCollateralRatioBps] = iface.decodeFunctionResult(
25135
+ "getLoanGrant",
25136
+ data
25137
+ );
25138
+ return {
25139
+ borrower,
25140
+ scopeBits: Number(scopeBits),
25141
+ minCollateralRatioBps: Number(minCollateralRatioBps)
25142
+ };
25143
+ }
24740
25144
  /**
24741
25145
  * Read a position's auto-renew delegation state (used to drive the Enable/Disable toggle).
24742
25146
  * Pure view — no signer required.
@@ -24745,8 +25149,8 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24745
25149
  const addr = this.agentDelegationRegistryOrThrow();
24746
25150
  const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
24747
25151
  const pid = this.toBytes32(positionId);
24748
- const grant = await registry.getLoanGrant(pid);
24749
- const enabled = grant.borrower !== "0x0000000000000000000000000000000000000000" && (Number(grant.scopeBits) & 1) !== 0;
25152
+ const grant = await this.readLoanGrant(addr, pid);
25153
+ const enabled = grant.borrower !== "0x0000000000000000000000000000000000000000" && (grant.scopeBits & 1) !== 0;
24750
25154
  const agentActive = user ? await registry.isAgentActive(user) : null;
24751
25155
  const canRenew = user ? await registry.canRenew(pid, user).then((r) => ({ ok: r.ok, reason: Number(r.reason) })) : null;
24752
25156
  return {
@@ -24757,16 +25161,58 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24757
25161
  };
24758
25162
  }
24759
25163
  /**
24760
- * Enable auto-renew delegation for a position. Orchestrates the first-time setup: if the
24761
- * borrower has no active agent, mints a fresh per-user agent PKP (via lit-ops-server) and
24762
- * registers it, then records the position's renew grant. Borrower-signed.
25164
+ * Read every delegation scope a position has granted, plus the mint floor and the protocol
25165
+ * minimum the UI must clamp its editor to. Pure view no signer required.
25166
+ *
25167
+ * Superset of `getAutoRenewStatus`, which predates the multi-scope UI and is kept for
25168
+ * callers that only care about renew.
24763
25169
  */
24764
- async enableAutoRenew(positionId, options) {
25170
+ async getDelegationStatus(positionId, user) {
25171
+ const addr = this.agentDelegationRegistryOrThrow();
25172
+ const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
25173
+ const pid = this.toBytes32(positionId);
25174
+ const [grant, protocolMin] = await Promise.all([
25175
+ this.readLoanGrant(addr, pid),
25176
+ registry.agentMintFloorMinBps().then(Number)
25177
+ ]);
25178
+ const hasGrant = grant.borrower !== "0x0000000000000000000000000000000000000000";
25179
+ const scopes = grant.scopeBits;
25180
+ const mintEnabled = hasGrant && (scopes & 4) !== 0;
25181
+ const floor = grant.minCollateralRatioBps;
25182
+ const agent = user ? await registry.agentOf(user) : null;
25183
+ return {
25184
+ renewEnabled: hasGrant && (scopes & 1) !== 0,
25185
+ repayEnabled: hasGrant && (scopes & 2) !== 0,
25186
+ mintEnabled,
25187
+ minCollateralRatioBps: mintEnabled ? floor : 0,
25188
+ effectiveMintFloorBps: mintEnabled ? Math.max(floor, protocolMin) : 0,
25189
+ protocolMinFloorBps: protocolMin,
25190
+ borrower: grant.borrower,
25191
+ agentActive: user ? await registry.isAgentActive(user) : null,
25192
+ agentValidUntil: agent ? Number(agent.validUntil) : null
25193
+ };
25194
+ }
25195
+ /** Governance floor-of-floors for agent mints (bps). The UI's minimum for the floor editor. */
25196
+ async getAgentMintFloorMinBps() {
25197
+ const addr = this.agentDelegationRegistryOrThrow();
25198
+ const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
25199
+ return Number(await registry.agentMintFloorMinBps());
25200
+ }
25201
+ /**
25202
+ * Shared enable-path preamble for EVERY scope: resolve the registry, ensure the borrower has
25203
+ * an active agent (minting + registering a per-user PKP on first use), and make that agent the
25204
+ * position's Gate-1 delegate. Returns the signer-connected registry and the agent address.
25205
+ *
25206
+ * Every `enableAuto*` runs this: the registry reverts `NoActiveAgent` without an agent, and
25207
+ * `lit-ops-server.isPositionDelegate` 403s the agent on the execute routes without Gate 1 —
25208
+ * so a scope enabled without this preamble would look on but never execute.
25209
+ */
25210
+ async prepareAgentDelegation(pid, options) {
24765
25211
  const addr = this.agentDelegationRegistryOrThrow();
24766
25212
  const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
24767
25213
  if (!pdrAddr) {
24768
25214
  throw new SDKError({
24769
- message: "PositionDelegateRegistry address not configured \u2014 required to authorize the renewal agent (contractAddresses.positionDelegateRegistry)",
25215
+ message: "PositionDelegateRegistry address not configured \u2014 required to authorize the agent (contractAddresses.positionDelegateRegistry)",
24770
25216
  category: "CONFIGURATION" /* CONFIGURATION */,
24771
25217
  severity: "HIGH" /* HIGH */
24772
25218
  });
@@ -24774,7 +25220,6 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24774
25220
  const signer = this.getSignerOrThrow();
24775
25221
  const user = await signer.getAddress();
24776
25222
  const registry = AgentDelegationRegistry__factory.connect(addr, signer);
24777
- const pid = this.toBytes32(positionId);
24778
25223
  let agentAddress;
24779
25224
  const hasActiveAgent = await registry.isAgentActive(user);
24780
25225
  if (hasActiveAgent) {
@@ -24796,6 +25241,54 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24796
25241
  const delTx = await setPositionDelegate(pid, agentAddress, signer, pdrAddr);
24797
25242
  await delTx.wait();
24798
25243
  }
25244
+ return { registry, agentAddress };
25245
+ }
25246
+ /**
25247
+ * Shared disable-path epilogue: drop the position's Gate-1 delegate, but ONLY once no scope
25248
+ * remains. Scopes compose, so clearing Gate 1 on every disable would silently break the
25249
+ * surviving ones server-side (the agent would 403 on the execute routes while its remaining
25250
+ * grant still reads as enabled on-chain).
25251
+ *
25252
+ * Also refuses to clobber a delegate registered for anything other than this user's agent.
25253
+ */
25254
+ async clearGate1IfNoScopesRemain(pid) {
25255
+ const addr = this.agentDelegationRegistryOrThrow();
25256
+ const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
25257
+ if (!pdrAddr) {
25258
+ throw new SDKError({
25259
+ message: "PositionDelegateRegistry address not configured \u2014 required to clear the agent's Gate-1 authorization (contractAddresses.positionDelegateRegistry)",
25260
+ category: "CONFIGURATION" /* CONFIGURATION */,
25261
+ severity: "HIGH" /* HIGH */
25262
+ });
25263
+ }
25264
+ const signer = this.getSignerOrThrow();
25265
+ const user = await signer.getAddress();
25266
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25267
+ const grant = await this.readLoanGrant(addr, pid);
25268
+ if (grant.scopeBits !== 0)
25269
+ return;
25270
+ const [currentDelegate, userAgent] = await Promise.all([
25271
+ getPositionDelegate(pid, signer, pdrAddr),
25272
+ registry.agentOf(user).then((a) => a.agent)
25273
+ ]);
25274
+ if (currentDelegate !== import_ethers17.ZeroAddress && currentDelegate.toLowerCase() === userAgent.toLowerCase()) {
25275
+ const clearTx = await setPositionDelegate(
25276
+ pid,
25277
+ "0x0000000000000000000000000000000000000000",
25278
+ signer,
25279
+ pdrAddr
25280
+ );
25281
+ await clearTx.wait();
25282
+ }
25283
+ }
25284
+ /**
25285
+ * Enable auto-renew delegation for a position. Orchestrates the first-time setup: if the
25286
+ * borrower has no active agent, mints a fresh per-user agent PKP (via lit-ops-server) and
25287
+ * registers it, then records the position's renew grant. Borrower-signed.
25288
+ */
25289
+ async enableAutoRenew(positionId, options) {
25290
+ const pid = this.toBytes32(positionId);
25291
+ const { registry, agentAddress } = await this.prepareAgentDelegation(pid, options);
24799
25292
  const tx = await registry.enableAutoRenew(pid);
24800
25293
  const receipt = await tx.wait();
24801
25294
  return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0, agentAddress };
@@ -24804,35 +25297,102 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24804
25297
  async disableAutoRenew(positionId) {
24805
25298
  const addr = this.agentDelegationRegistryOrThrow();
24806
25299
  const signer = this.getSignerOrThrow();
24807
- const user = await signer.getAddress();
24808
25300
  const registry = AgentDelegationRegistry__factory.connect(addr, signer);
24809
25301
  const pid = this.toBytes32(positionId);
24810
- const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
24811
- if (!pdrAddr) {
25302
+ const tx = await registry.disableAutoRenew(pid);
25303
+ const receipt = await tx.wait();
25304
+ await this.clearGate1IfNoScopesRemain(pid);
25305
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25306
+ }
25307
+ /**
25308
+ * Enable auto-repay delegation: the agent may repay this position's debt on the borrower's
25309
+ * behalf. Deliberately uncapped in the registry — repay only ever burns the borrower's own
25310
+ * debt from the borrower's own funds, and the ERC-20 allowance to PositionManager (never
25311
+ * granted to the agent) is the natural bound. Borrower-signed.
25312
+ */
25313
+ async enableAutoRepay(positionId, options) {
25314
+ const pid = this.toBytes32(positionId);
25315
+ const { registry, agentAddress } = await this.prepareAgentDelegation(pid, options);
25316
+ const tx = await registry.enableAutoRepay(pid);
25317
+ const receipt = await tx.wait();
25318
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0, agentAddress };
25319
+ }
25320
+ /** Disable auto-repay delegation for a position. Borrower-signed. */
25321
+ async disableAutoRepay(positionId) {
25322
+ const addr = this.agentDelegationRegistryOrThrow();
25323
+ const signer = this.getSignerOrThrow();
25324
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25325
+ const pid = this.toBytes32(positionId);
25326
+ const tx = await registry.disableAutoRepay(pid);
25327
+ const receipt = await tx.wait();
25328
+ await this.clearGate1IfNoScopesRemain(pid);
25329
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25330
+ }
25331
+ /**
25332
+ * Enable auto-mint delegation with a post-mint collateral-ratio floor (bps) the mint validator
25333
+ * enforces. `minCollateralRatioBps` must be at or above the governance minimum
25334
+ * (`getAgentMintFloorMinBps()`, 15000 = 150%) — checked here so the caller gets a readable
25335
+ * error instead of a `FloorBelowProtocolMin` revert after signing. Borrower-signed.
25336
+ */
25337
+ async enableAutoMint(positionId, minCollateralRatioBps, options) {
25338
+ const pid = this.toBytes32(positionId);
25339
+ await this.assertMintFloorAtOrAboveProtocolMin(minCollateralRatioBps);
25340
+ const { registry, agentAddress } = await this.prepareAgentDelegation(pid, options);
25341
+ const tx = await registry.enableAutoMint(pid, minCollateralRatioBps);
25342
+ const receipt = await tx.wait();
25343
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0, agentAddress };
25344
+ }
25345
+ /** Disable auto-mint delegation for a position (also zeroes its mint floor). Borrower-signed. */
25346
+ async disableAutoMint(positionId) {
25347
+ const addr = this.agentDelegationRegistryOrThrow();
25348
+ const signer = this.getSignerOrThrow();
25349
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25350
+ const pid = this.toBytes32(positionId);
25351
+ const tx = await registry.disableAutoMint(pid);
25352
+ const receipt = await tx.wait();
25353
+ await this.clearGate1IfNoScopesRemain(pid);
25354
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25355
+ }
25356
+ /**
25357
+ * Change an existing mint grant's collateral floor in place — no disable/re-enable dance.
25358
+ * MINT must already be granted; the new floor must clear the governance minimum. Note the
25359
+ * borrower may move it in either direction (above the minimum); only `REGISTRAR_ROLE` is
25360
+ * restricted to raising. Borrower-signed.
25361
+ */
25362
+ async setMintCollateralFloor(positionId, newFloorBps) {
25363
+ const addr = this.agentDelegationRegistryOrThrow();
25364
+ await this.assertMintFloorAtOrAboveProtocolMin(newFloorBps);
25365
+ const signer = this.getSignerOrThrow();
25366
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25367
+ const pid = this.toBytes32(positionId);
25368
+ const tx = await registry.setMintCollateralFloor(pid, newFloorBps);
25369
+ const receipt = await tx.wait();
25370
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25371
+ }
25372
+ /** Pre-flight the registry's `FloorBelowProtocolMin` guard with a message a user can act on. */
25373
+ async assertMintFloorAtOrAboveProtocolMin(floorBps) {
25374
+ if (!Number.isInteger(floorBps) || floorBps <= 0) {
25375
+ throw new SDKError({
25376
+ message: `Invalid collateral floor: ${floorBps} bps \u2014 must be a positive integer`,
25377
+ category: "VALIDATION" /* VALIDATION */,
25378
+ severity: "MEDIUM" /* MEDIUM */
25379
+ });
25380
+ }
25381
+ const protocolMin = await this.getAgentMintFloorMinBps();
25382
+ if (protocolMin === 0) {
24812
25383
  throw new SDKError({
24813
- message: "PositionDelegateRegistry address not configured \u2014 required to clear the renewal agent's Gate-1 authorization (contractAddresses.positionDelegateRegistry)",
25384
+ message: "Agent minting is not configured on this network (agentMintFloorMinBps is 0) \u2014 the registry would reject every mint grant",
24814
25385
  category: "CONFIGURATION" /* CONFIGURATION */,
24815
25386
  severity: "HIGH" /* HIGH */
24816
25387
  });
24817
25388
  }
24818
- {
24819
- const [currentDelegate, userAgent] = await Promise.all([
24820
- getPositionDelegate(pid, signer, pdrAddr).catch(() => null),
24821
- registry.agentOf(user).then((a) => a.agent).catch(() => null)
24822
- ]);
24823
- if (currentDelegate && userAgent && currentDelegate.toLowerCase() === userAgent.toLowerCase()) {
24824
- const clearTx = await setPositionDelegate(
24825
- pid,
24826
- "0x0000000000000000000000000000000000000000",
24827
- signer,
24828
- pdrAddr
24829
- );
24830
- await clearTx.wait();
24831
- }
25389
+ if (floorBps < protocolMin) {
25390
+ throw new SDKError({
25391
+ message: `Collateral floor ${floorBps / 100}% is below the protocol minimum of ${protocolMin / 100}%`,
25392
+ category: "VALIDATION" /* VALIDATION */,
25393
+ severity: "MEDIUM" /* MEDIUM */
25394
+ });
24832
25395
  }
24833
- const tx = await registry.disableAutoRenew(pid);
24834
- const receipt = await tx.wait();
24835
- return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
24836
25396
  }
24837
25397
  // ============================================================================
24838
25398
  // HIGH-LEVEL API - Bitcoin Operations
@@ -26032,6 +26592,146 @@ var EventHelpers = {
26032
26592
  });
26033
26593
  }
26034
26594
  };
26595
+
26596
+ // src/utils/safe-agent-delegation.utils.ts
26597
+ var import_ethers18 = require("ethers");
26598
+ init_deployment_addresses();
26599
+ var SAFE_ABI = [
26600
+ "function getModulesPaginated(address start, uint256 pageSize) view returns (address[] modules, address next)"
26601
+ ];
26602
+ var MODULE_ABI = [
26603
+ "function safe() view returns (address)",
26604
+ "function agent() view returns (address)",
26605
+ "function positionManager() view returns (address)"
26606
+ ];
26607
+ var FACTORY_ABI = ["function isFromFactory(address) view returns (bool)"];
26608
+ var REGISTRY_ABI = [
26609
+ "function agentOf(address user) view returns (address agent, uint64 validUntil, uint8 status, uint64 registeredAt, uint64 revokedAt)"
26610
+ ];
26611
+ var MODULE_LIST_SENTINEL = "0x0000000000000000000000000000000000000001";
26612
+ var MODULE_PAGE_SIZE = 50;
26613
+ var lower = (v) => v.trim().toLowerCase();
26614
+ async function classifyModule(provider, moduleAddress, safeAddress, positionManager, factoryAddress) {
26615
+ const module2 = new import_ethers18.Contract(moduleAddress, MODULE_ABI, provider);
26616
+ let boundSafe;
26617
+ try {
26618
+ boundSafe = await module2.safe();
26619
+ } catch {
26620
+ return null;
26621
+ }
26622
+ if (lower(boundSafe) !== lower(safeAddress))
26623
+ return false;
26624
+ let modulePm;
26625
+ try {
26626
+ modulePm = await module2.positionManager();
26627
+ } catch {
26628
+ return false;
26629
+ }
26630
+ if (lower(modulePm) !== lower(positionManager))
26631
+ return false;
26632
+ if (!factoryAddress)
26633
+ return null;
26634
+ try {
26635
+ const factory = new import_ethers18.Contract(factoryAddress, FACTORY_ABI, provider);
26636
+ return await factory.isFromFactory(moduleAddress) === true;
26637
+ } catch {
26638
+ return null;
26639
+ }
26640
+ }
26641
+ async function getSafeAgentDelegation(params) {
26642
+ const { safeAddress, chainId, provider } = params;
26643
+ const normalized = lower(safeAddress);
26644
+ const unknown = {
26645
+ safeAddress: normalized,
26646
+ chainId,
26647
+ status: "unknown",
26648
+ moduleAddress: null,
26649
+ agentAddress: null,
26650
+ validUntil: null,
26651
+ truncated: false
26652
+ };
26653
+ const contracts = Object.values(ALL_DEPLOYMENTS).find(
26654
+ (deployment) => deployment.chainId === chainId
26655
+ )?.contracts;
26656
+ const positionManager = contracts?.PositionManager;
26657
+ if (!positionManager)
26658
+ return unknown;
26659
+ const factoryAddress = contracts?.AgentModuleFactory;
26660
+ const registryAddress = contracts?.AgentDelegationRegistry;
26661
+ let modules;
26662
+ let next;
26663
+ try {
26664
+ const safe = new import_ethers18.Contract(safeAddress, SAFE_ABI, provider);
26665
+ const page = await safe.getModulesPaginated(
26666
+ MODULE_LIST_SENTINEL,
26667
+ MODULE_PAGE_SIZE
26668
+ );
26669
+ modules = [...page[0]];
26670
+ next = page[1];
26671
+ } catch {
26672
+ return unknown;
26673
+ }
26674
+ const truncated = BigInt(next) > BigInt(MODULE_LIST_SENTINEL);
26675
+ let indeterminate = false;
26676
+ for (const moduleAddress of modules) {
26677
+ const verdict = await classifyModule(
26678
+ provider,
26679
+ moduleAddress,
26680
+ normalized,
26681
+ positionManager,
26682
+ factoryAddress
26683
+ );
26684
+ if (verdict === null) {
26685
+ indeterminate = true;
26686
+ continue;
26687
+ }
26688
+ if (!verdict)
26689
+ continue;
26690
+ let agentAddress = null;
26691
+ try {
26692
+ agentAddress = await new import_ethers18.Contract(
26693
+ moduleAddress,
26694
+ MODULE_ABI,
26695
+ provider
26696
+ ).agent();
26697
+ } catch {
26698
+ }
26699
+ if (!registryAddress) {
26700
+ indeterminate = true;
26701
+ continue;
26702
+ }
26703
+ let validUntil;
26704
+ let status;
26705
+ try {
26706
+ const record = await new import_ethers18.Contract(
26707
+ registryAddress,
26708
+ REGISTRY_ABI,
26709
+ provider
26710
+ ).agentOf(safeAddress);
26711
+ status = Number(record[2]);
26712
+ validUntil = Number(record[1]);
26713
+ } catch {
26714
+ indeterminate = true;
26715
+ continue;
26716
+ }
26717
+ const now = Math.floor(Date.now() / 1e3);
26718
+ if (status !== 1 || validUntil <= now) {
26719
+ return { ...unknown, status: "not-delegated", truncated };
26720
+ }
26721
+ return {
26722
+ safeAddress: normalized,
26723
+ chainId,
26724
+ status: "delegated",
26725
+ moduleAddress,
26726
+ agentAddress: agentAddress ? lower(agentAddress) : null,
26727
+ validUntil,
26728
+ truncated
26729
+ };
26730
+ }
26731
+ if (truncated || indeterminate)
26732
+ return { ...unknown, truncated };
26733
+ return { ...unknown, status: "not-delegated" };
26734
+ }
26035
26735
  // Annotate the CommonJS export names for ESM import in node:
26036
26736
  0 && (module.exports = {
26037
26737
  ALL_CONTRACTS,
@@ -26093,6 +26793,7 @@ var EventHelpers = {
26093
26793
  getDelegateStatus,
26094
26794
  getDeploymentByNetwork,
26095
26795
  getPositionDelegate,
26796
+ getSafeAgentDelegation,
26096
26797
  isClosePositionAuth,
26097
26798
  isCreateLoanAuth,
26098
26799
  isExtendTermAuth,