@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.mjs CHANGED
@@ -96,7 +96,8 @@ var init_deployment_addresses = __esm({
96
96
  BitcoinWithdrawalAddressRegistry: "0x6376D392097F0A81e51BD83960A97EA20eaf1dbe",
97
97
  CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
98
98
  AgentDelegationRegistry: "0x6AE7fc6bE0925126b9D25b1B7Ce5AD5d127ec025",
99
- DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF"
99
+ DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF",
100
+ AgentModuleFactory: "0x1Fd3aCa2C030Cf77ce28Af9694D3Bb3034ACa2E5"
100
101
  },
101
102
  upgraded: {
102
103
  PositionManager: {
@@ -391,7 +392,8 @@ var init_deployment_addresses = __esm({
391
392
  BitcoinWithdrawalAddressRegistry: "0x6376D392097F0A81e51BD83960A97EA20eaf1dbe",
392
393
  CarryAgentRegistry: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
393
394
  AgentDelegationRegistry: "0x6AE7fc6bE0925126b9D25b1B7Ce5AD5d127ec025",
394
- DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF"
395
+ DHAgentDelegate: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF",
396
+ AgentModuleFactory: "0x1Fd3aCa2C030Cf77ce28Af9694D3Bb3034ACa2E5"
395
397
  };
396
398
  MAINNET_DEPLOYMENT = {
397
399
  network: "mainnet",
@@ -628,7 +630,7 @@ var init_deployment_addresses = __esm({
628
630
  LOCALHOST_DEPLOYMENT = {
629
631
  network: "localhost",
630
632
  chainId: 1337,
631
- timestamp: "2026-07-20T19:45:58.514Z",
633
+ timestamp: "2026-07-23T17:13:42.777Z",
632
634
  deployer: "",
633
635
  contracts: {
634
636
  MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
@@ -648,6 +650,30 @@ var init_deployment_addresses = __esm({
648
650
  PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
649
651
  OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
650
652
  PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
653
+ },
654
+ latestEnv: {
655
+ UCD_TOKEN: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
656
+ UCD_CONTROLLER: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
657
+ POSITION_MANAGER: "0x851356ae760d987E095750cCeb3bC6014560891C",
658
+ PKP_VALIDATION_REGISTRY: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A",
659
+ PKP_VALIDATION_CID_V1: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
660
+ PKP_VALIDATION_CID_V3: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
661
+ PKP_ETH_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
662
+ OPERATION_AUTHORIZATION_REGISTRY: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
663
+ UCD_MINT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
664
+ UCD_MINT_VALIDATOR_VERSION: 1,
665
+ BTC_WITHDRAWAL_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
666
+ BTC_WITHDRAWAL_VALIDATOR_VERSION: 3,
667
+ UPDATE_BALANCE_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
668
+ UPDATE_BALANCE_VALIDATOR_VERSION: 1,
669
+ PROCESS_PAYMENT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
670
+ PROCESS_PAYMENT_VALIDATOR_VERSION: 1,
671
+ EXTEND_POSITION_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
672
+ EXTEND_POSITION_VALIDATOR_VERSION: 1,
673
+ POSITION_MANAGER_CORE_MODULE: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
674
+ LOAN_OPERATIONS_MANAGER_MODULE: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
675
+ TERM_MANAGER_MODULE: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
676
+ COMMUNITY_MANAGER_MODULE: ""
651
677
  }
652
678
  };
653
679
  LOCALHOST_CONTRACTS = {
@@ -2326,7 +2352,7 @@ ${errorReport}`);
2326
2352
  }
2327
2353
  init_debug_logger();
2328
2354
  init_session_signature_cache();
2329
- var import_ethers18 = __require("ethers");
2355
+ var import_ethers19 = __require("ethers");
2330
2356
  var EXPIRED_LOAN_MIN_LIQUIDATION_THRESHOLD_BPS = 11e3;
2331
2357
  var GRACE_PERIOD_DAYS = 30;
2332
2358
  var SATOSHIS_PER_BITCOIN = 100000000n;
@@ -5159,12 +5185,12 @@ ${auth.clientId}`;
5159
5185
  }
5160
5186
  async function executeVaultSnapshot(params) {
5161
5187
  global.ethers = {
5162
- ...import_ethers18.ethers,
5188
+ ...import_ethers19.ethers,
5163
5189
  providers: {
5164
- StaticJsonRpcProvider: import_ethers18.ethers.JsonRpcProvider
5190
+ StaticJsonRpcProvider: import_ethers19.ethers.JsonRpcProvider
5165
5191
  },
5166
- Contract: import_ethers18.ethers.Contract,
5167
- utils: import_ethers18.ethers
5192
+ Contract: import_ethers19.ethers.Contract,
5193
+ utils: import_ethers19.ethers
5168
5194
  // v6 moved utils to top level
5169
5195
  };
5170
5196
  global.Lit = {
@@ -5438,7 +5464,8 @@ function getSepoliaConfig() {
5438
5464
  bitcoinWithdrawalAddressRegistry: SEPOLIA_CONTRACTS.BitcoinWithdrawalAddressRegistry || "",
5439
5465
  carryAgentRegistry: SEPOLIA_CONTRACTS.CarryAgentRegistry || "",
5440
5466
  agentDelegationRegistry: SEPOLIA_CONTRACTS.AgentDelegationRegistry || "",
5441
- dhAgentDelegate: SEPOLIA_CONTRACTS.DHAgentDelegate || ""
5467
+ dhAgentDelegate: SEPOLIA_CONTRACTS.DHAgentDelegate || "",
5468
+ agentModuleFactory: SEPOLIA_CONTRACTS.AgentModuleFactory || ""
5442
5469
  },
5443
5470
  subgraphs: {
5444
5471
  // Lazy getter for the same module-init snapshot reason as serviceEndpoint.
@@ -5481,7 +5508,9 @@ function getMainnetConfig() {
5481
5508
  bitcoinWithdrawalAddressRegistry: MAINNET_CONTRACTS.BitcoinWithdrawalAddressRegistry || "",
5482
5509
  carryAgentRegistry: MAINNET_CONTRACTS.CarryAgentRegistry || "",
5483
5510
  agentDelegationRegistry: MAINNET_CONTRACTS.AgentDelegationRegistry || "",
5484
- dhAgentDelegate: MAINNET_CONTRACTS.DHAgentDelegate || ""
5511
+ dhAgentDelegate: MAINNET_CONTRACTS.DHAgentDelegate || "",
5512
+ // Empty on mainnet until the factory is deployed there — the ceremony is Sepolia-only.
5513
+ agentModuleFactory: MAINNET_CONTRACTS.AgentModuleFactory || ""
5485
5514
  },
5486
5515
  subgraphs: {
5487
5516
  diamondHandsUrl: "https://gateway-arbitrum.network.thegraph.com/api/subgraphs/id/CCTPsdYqco2jChDLLBQTbdJWwoukVoMt1cXeR9ti6r9A"
@@ -7250,7 +7279,7 @@ var defaultHttpGetJson = async (url) => {
7250
7279
  }
7251
7280
  return { status: res.status, body };
7252
7281
  };
7253
- async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = defaultHttpGetJson) {
7282
+ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = defaultHttpGetJson, opts) {
7254
7283
  const base = esploraBaseUrl.replace(/\/+$/, "");
7255
7284
  const fundingRes = await httpGetJson(`${base}/tx/${spend.txid}`);
7256
7285
  if (fundingRes.status === 404) {
@@ -7282,20 +7311,28 @@ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = def
7282
7311
  };
7283
7312
  }
7284
7313
  const onChainOutputValue = output.value;
7285
- if (onChainOutputValue !== spend.satoshis) {
7286
- return {
7287
- spend,
7288
- status: "CORRUPT",
7289
- onChainOutputValue,
7290
- reason: `Authorization declares ${spend.satoshis} sats for ${spend.txid}:${spend.vout} but the on-chain output is ${onChainOutputValue} sats`
7291
- };
7314
+ if (opts?.vaultAddress) {
7315
+ const outputAddress = (output.scriptpubkey_address ?? "").toLowerCase();
7316
+ if (outputAddress !== opts.vaultAddress.toLowerCase()) {
7317
+ return {
7318
+ spend,
7319
+ status: "CORRUPT",
7320
+ onChainOutputValue,
7321
+ reason: `Authorized outpoint ${spend.txid}:${spend.vout} pays ${output.scriptpubkey_address ?? "an unknown script"}, not the vault ${opts.vaultAddress}`
7322
+ };
7323
+ }
7324
+ } else {
7325
+ log.warn(
7326
+ "Withdrawal reconciliation: no vaultAddress supplied \u2014 skipping the vault-ownership check",
7327
+ { txid: spend.txid, vout: spend.vout }
7328
+ );
7292
7329
  }
7293
- if (spend.targetAmount > onChainOutputValue) {
7330
+ if (spend.targetAmount >= spend.satoshis) {
7294
7331
  return {
7295
7332
  spend,
7296
7333
  status: "CORRUPT",
7297
7334
  onChainOutputValue,
7298
- reason: `Authorized targetAmount ${spend.targetAmount} sats exceeds the ${onChainOutputValue}-sat output it is authorized against`
7335
+ reason: `Authorized targetAmount ${spend.targetAmount} sats is not below the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
7299
7336
  };
7300
7337
  }
7301
7338
  const outspendRes = await httpGetJson(
@@ -7791,13 +7828,13 @@ function isValidBase58CheckAddress(address) {
7791
7828
  return BASE58_VERSIONS_MAINNET.has(version) || BASE58_VERSIONS_TEST.has(version);
7792
7829
  }
7793
7830
  function isValidBech32Address(address) {
7794
- const lower = address.toLowerCase();
7795
- if (lower !== address && address !== address.toUpperCase()) {
7831
+ const lower2 = address.toLowerCase();
7832
+ if (lower2 !== address && address !== address.toUpperCase()) {
7796
7833
  return false;
7797
7834
  }
7798
7835
  const tryDecode = (codec) => {
7799
7836
  try {
7800
- const decoded = codec.decode(lower);
7837
+ const decoded = codec.decode(lower2);
7801
7838
  if (!BECH32_HRPS.has(decoded.prefix))
7802
7839
  return false;
7803
7840
  if (decoded.words.length < 1)
@@ -11852,7 +11889,7 @@ var GraphClient = class {
11852
11889
  });
11853
11890
  clearTimeout(timeout);
11854
11891
  if (!res.ok) {
11855
- if (res.status === 429 || res.status >= 500) {
11892
+ if (res.status >= 500) {
11856
11893
  await this.backoff(attempt);
11857
11894
  continue;
11858
11895
  }
@@ -11861,12 +11898,7 @@ var GraphClient = class {
11861
11898
  }
11862
11899
  const data = await res.json();
11863
11900
  if (data.errors?.length) {
11864
- const errMsg = JSON.stringify(data.errors);
11865
- if (errMsg.includes("rate limit") && attempt < this.maxRetries) {
11866
- await this.backoff(attempt);
11867
- continue;
11868
- }
11869
- throw new Error(`GraphQL errors: ${errMsg}`);
11901
+ throw new Error(`GraphQL errors: ${JSON.stringify(data.errors)}`);
11870
11902
  }
11871
11903
  return data.data ?? null;
11872
11904
  } catch (err) {
@@ -16782,6 +16814,50 @@ var _abi2 = [
16782
16814
  name: "AutoRepayEnabled",
16783
16815
  type: "event"
16784
16816
  },
16817
+ {
16818
+ anonymous: false,
16819
+ inputs: [
16820
+ {
16821
+ indexed: true,
16822
+ internalType: "bytes32",
16823
+ name: "positionId",
16824
+ type: "bytes32"
16825
+ },
16826
+ {
16827
+ indexed: true,
16828
+ internalType: "address",
16829
+ name: "borrower",
16830
+ type: "address"
16831
+ }
16832
+ ],
16833
+ name: "AutoWithdrawDisabled",
16834
+ type: "event"
16835
+ },
16836
+ {
16837
+ anonymous: false,
16838
+ inputs: [
16839
+ {
16840
+ indexed: true,
16841
+ internalType: "bytes32",
16842
+ name: "positionId",
16843
+ type: "bytes32"
16844
+ },
16845
+ {
16846
+ indexed: true,
16847
+ internalType: "address",
16848
+ name: "borrower",
16849
+ type: "address"
16850
+ },
16851
+ {
16852
+ indexed: false,
16853
+ internalType: "uint32",
16854
+ name: "minWithdrawRatioBps",
16855
+ type: "uint32"
16856
+ }
16857
+ ],
16858
+ name: "AutoWithdrawEnabled",
16859
+ type: "event"
16860
+ },
16785
16861
  {
16786
16862
  anonymous: false,
16787
16863
  inputs: [
@@ -17100,6 +17176,19 @@ var _abi2 = [
17100
17176
  stateMutability: "view",
17101
17177
  type: "function"
17102
17178
  },
17179
+ {
17180
+ inputs: [],
17181
+ name: "SCOPE_WITHDRAW",
17182
+ outputs: [
17183
+ {
17184
+ internalType: "uint32",
17185
+ name: "",
17186
+ type: "uint32"
17187
+ }
17188
+ ],
17189
+ stateMutability: "view",
17190
+ type: "function"
17191
+ },
17103
17192
  {
17104
17193
  inputs: [],
17105
17194
  name: "UPGRADE_INTERFACE_VERSION",
@@ -17290,6 +17379,40 @@ var _abi2 = [
17290
17379
  stateMutability: "view",
17291
17380
  type: "function"
17292
17381
  },
17382
+ {
17383
+ inputs: [
17384
+ {
17385
+ internalType: "bytes32",
17386
+ name: "positionId",
17387
+ type: "bytes32"
17388
+ },
17389
+ {
17390
+ internalType: "address",
17391
+ name: "caller",
17392
+ type: "address"
17393
+ }
17394
+ ],
17395
+ name: "canWithdraw",
17396
+ outputs: [
17397
+ {
17398
+ internalType: "bool",
17399
+ name: "ok",
17400
+ type: "bool"
17401
+ },
17402
+ {
17403
+ internalType: "enum IAgentDelegationRegistry.DenyReason",
17404
+ name: "reason",
17405
+ type: "uint8"
17406
+ },
17407
+ {
17408
+ internalType: "uint32",
17409
+ name: "effectiveFloorBps",
17410
+ type: "uint32"
17411
+ }
17412
+ ],
17413
+ stateMutability: "view",
17414
+ type: "function"
17415
+ },
17293
17416
  {
17294
17417
  inputs: [],
17295
17418
  name: "core",
@@ -17342,6 +17465,19 @@ var _abi2 = [
17342
17465
  stateMutability: "nonpayable",
17343
17466
  type: "function"
17344
17467
  },
17468
+ {
17469
+ inputs: [
17470
+ {
17471
+ internalType: "bytes32",
17472
+ name: "positionId",
17473
+ type: "bytes32"
17474
+ }
17475
+ ],
17476
+ name: "disableAutoWithdraw",
17477
+ outputs: [],
17478
+ stateMutability: "nonpayable",
17479
+ type: "function"
17480
+ },
17345
17481
  {
17346
17482
  inputs: [
17347
17483
  {
@@ -17386,6 +17522,24 @@ var _abi2 = [
17386
17522
  stateMutability: "nonpayable",
17387
17523
  type: "function"
17388
17524
  },
17525
+ {
17526
+ inputs: [
17527
+ {
17528
+ internalType: "bytes32",
17529
+ name: "positionId",
17530
+ type: "bytes32"
17531
+ },
17532
+ {
17533
+ internalType: "uint32",
17534
+ name: "minWithdrawRatioBps",
17535
+ type: "uint32"
17536
+ }
17537
+ ],
17538
+ name: "enableAutoWithdraw",
17539
+ outputs: [],
17540
+ stateMutability: "nonpayable",
17541
+ type: "function"
17542
+ },
17389
17543
  {
17390
17544
  inputs: [
17391
17545
  {
@@ -17412,6 +17566,11 @@ var _abi2 = [
17412
17566
  internalType: "uint32",
17413
17567
  name: "minCollateralRatioBps",
17414
17568
  type: "uint32"
17569
+ },
17570
+ {
17571
+ internalType: "uint32",
17572
+ name: "minWithdrawRatioBps",
17573
+ type: "uint32"
17415
17574
  }
17416
17575
  ],
17417
17576
  internalType: "struct IAgentDelegationRegistry.LoanGrant",
@@ -17896,7 +18055,7 @@ var _abi2 = [
17896
18055
  type: "function"
17897
18056
  }
17898
18057
  ];
17899
- var _bytecode2 = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b604051612d3290816100f0823960805181818161101d01526112020152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe608080604052600436101561001357600080fd5b60003560e01c90816301ffc9a714611dec575080630d33f3c214611dc85780630f3f4a9414611d7d5780631459457a146119d757806318c38b89146118c65780631d444541146117f5578063248a9ca3146117cf5780632ec22d4c1461170e5780632f0647ce146116935780632f2ff15d1461166257806336568abe1461161c578063392f1087146115cf5780633f4ba83a146114d75780633f5aadc9146114685780634f1ef28614611186578063523403631461109d5780635273b6f61461107457806352d1902d1461100a578063554c4f4b14610f7a578063561b7f8a14610e4e5780635bc26aea14610dc15780635c975abb14610d915780636289d18c14610d105780636711cc0b14610cf45780636e852a7814610bf35780637e35bf6e14610bbf5780638343f67414610b925780638456cb5914610a9c5780638f33527f14610a625780639010d07c14610a0e57806391d14854146109b45780639b9d30c11461098b578063a19af3f6146108c9578063a217fddf146108ad578063a3246ad3146107eb578063a8780864146107cf578063ac3c0e30146106c2578063ad3cb1cc1461067b578063b3fad638146105ef578063c34e9c26146105d3578063ca15c8731461059a578063d547741f14610562578063dd71d99a14610520578063e0922fa114610473578063efa9b4ae14610404578063f2f4eb26146103db578063f68e9553146103b2578063fd437d39146102735763ffa1ad741461023a57600080fd5b3461026e57600036600319011261026e5761026a610256611fb9565b604051918291602083526020830190611f94565b0390f35b600080fd5b3461026e57606036600319011261026e5761028c611e6f565b610294611e59565b9061029d611f5b565b906102a661247b565b6001600160a01b0316338190036103a25780600052600160205260406000209283549360ff8560e01c16600381101561038c5760010361037b57816001602092610312877fc5d5c5bbf10444998e0ea6d4725e79027b574e1c14ec929279e8a9a95c6c6e919688612929565b818060a01b038316828060a01b03198254161781556103318782612111565b0180546001600160401b031916426001600160401b03908116919091179091556001600160a01b0391821660008181526002855260409081902087905551969091168652951693a4005b632437e77160e11b60005260046000fd5b634e487b7160e01b600052602160045260246000fd5b62fca64560e31b60005260046000fd5b3461026e57600036600319011261026e576020604051600080516020612cc68339815191528152f35b3461026e57600036600319011261026e576003546040516001600160a01b039091168152602090f35b3461026e57602036600319011261026e5760043561042061247b565b61044261042c826124c6565b9190600163ffffffff825460a01c161790612037565b6001600160a01b0316907f812690e0a9dff5bf3add998111b8af5c8299608d859025bfe35662060ab4267d600080a3005b3461026e57602036600319011261026e576004356001600160401b0381169081810361026e576000546001600160a01b038116330361050f57600160a01b600160e01b0319811660a092831b600160a01b600160e01b031617600055604080519190921c6001600160401b0316815260208101929092527f9c195448332abd01f716db873b329752ea02f19d33f7e311fb0daf082c4edd0391a1005b6349db3bd360e01b60005260046000fd5b3461026e57602036600319011261026e576001600160a01b03610541611e6f565b166000526002602052602060018060a01b0360406000205416604051908152f35b3461026e57604036600319011261026e57610598600435610581611e59565b9061059361058e82612016565b6123a5565b612437565b005b3461026e57602036600319011261026e57600435600052600080516020612bc68339815191526020526020604060002054604051908152f35b3461026e57600036600319011261026e57602060405160028152f35b3461026e57602036600319011261026e5760006040805161060f81611f02565b828152826020820152015260043560005260046020526060604060002063ffffffff6040519161063e83611f02565b548160018060a01b038216938481528160406020830192828660a01c168452019360c01c1683526040519485525116602084015251166040820152f35b3461026e57600036600319011261026e5761026a604080519061069e8183611f1d565b60058252640352e302e360dc1b602083015251918291602083526020830190611f94565b3461026e57602036600319011261026e576106db611e6f565b600060806040516106eb81611ed1565b828152826020820152826040820152826060820152015260018060a01b03166000526001602052604060002060405161072381611ed1565b81546001600160a01b038116825260a081901c6001600160401b03166020830190815292604083019160e01c60ff1690600382101561038c57908252600101546001600160401b0380821660608501908152604092831c821660808601908152925194516001600160a01b031685529451166020840152905192600384101561038c57604083019390935291516001600160401b0390811660608301529151909116608082015260a090f35b3461026e57600036600319011261026e57602060405160018152f35b3461026e57602036600319011261026e57600435600052600080516020612bc683398151915260205260406000206040518060208354918281520190819360005260206000209060005b818110610897575050508161084b910382611f1d565b6040519182916020830190602084525180915260408301919060005b818110610875575050500390f35b82516001600160a01b0316845285945060209384019390920191600101610867565b8254845260209093019260019283019201610835565b3461026e57600036600319011261026e57602060405160008152f35b3461026e57604036600319011261026e576004356108e5611ebe565b906108ee61247b565b63ffffffff600554169163ffffffff811692808410908115610982575b506109715760207f1da95b87b4c773f68c1447ffc5644e41a8a8887d55065beb64852014cf7140be9161095e610940856124c6565b9290610959600463ffffffff835460a01c161782612037565b611fdc565b6040519485526001600160a01b031693a3005b634346c13160e01b60005260046000fd5b9050158461090b565b3461026e57600036600319011261026e576020604051600080516020612c068339815191528152f35b3461026e57604036600319011261026e576109cd611e59565b600435600052600080516020612ca683398151915260205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b3461026e57604036600319011261026e57600435600052600080516020612bc68339815191526020526020610a4960243560406000206129f2565b905460405160039290921b1c6001600160a01b03168152f35b3461026e57602036600319011261026e576001600160a01b03610a83611e6f565b1660005260026020526020604060002054604051908152f35b3461026e57600036600319011261026e573360009081527f0ac8cc3d209806126662940717264973110c39045b305f6ba49613325a615e09602052604090205460ff1615610b6b57610aec61247b565b600160ff19600080516020612ce6833981519152541617600080516020612ce6833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a2005b63e2517d3f60e01b60005233600452600080516020612c0683398151915260245260446000fd5b3461026e57600036600319011261026e5760005460405160a09190911c6001600160401b03168152602090f35b3461026e57604036600319011261026e57610be3610bdb611e59565b6004356120de565b9061026a60405192839283611e8f565b3461026e57604036600319011261026e57610c0c611e6f565b336000908152600080516020612c46833981519152602052604090205460ff161580610ce1575b6103a2576001600160a01b03166000818152600160205260409020805460e01c60ff16600381101561038c5760010361037b57805460ff60e01b198116600160e11b1782556001919091018054600160401b600160801b03191642604090811b600160401b600160801b0316919091179091555160243581526001600160a01b0390911691907fc0499cc07ed9d734deec6857802d3f0fa8d5afaf79a7008beb8ba7bef62a271b90602090a3005b50336001600160a01b0382161415610c33565b3461026e57600036600319011261026e57602060405160048152f35b3461026e57602036600319011261026e57610d29611eab565b6000546001600160a01b0316330361050f5763ffffffff8116908115610d8057600080516020612c8683398151915291610d7b63ffffffff926005549284198416176005556040519384931683611fff565b0390a1005b6338f3377360e21b60005260046000fd5b3461026e57600036600319011261026e57602060ff600080516020612ce683398151915254166040519015158152f35b3461026e57602036600319011261026e57610dda611e6f565b6000546001600160a01b038116903382900361050f576001600160a01b038316928315610e3d573b15610e2c576001600160a01b03191682176000908155600080516020612c668339815191529080a3005b636f7c43f160e01b60005260046000fd5b63e6c4247b60e01b60005260046000fd5b3461026e57606036600319011261026e57610e67611e6f565b610e6f611e59565b610e77611f5b565b91610e8061247b565b6001600160a01b031690338290036103a257816000526001602052604060002060ff815460e01c16600381101561038c57600114610f695781602091610ee8867ff223dc085722c94c84dcf67427e225799be616382a2a484d378f8921c69a20339587612929565b80546001600160a01b0319166001600160a01b038316178155610f0b8682612111565b6001810180546001600160801b031916426001600160401b0390811691909117909155815460ff60e01b1916600160e01b179091556001600160a01b03919091166000818152600284526040908190208690555195909116855293a3005b639d2c8fdf60e01b60005260046000fd5b3461026e57602036600319011261026e576001600160a01b03610f9b611e6f565b166000526001602052604060002060ff600080516020612ce683398151915254161580610fee575b60209181610fd7575b506040519015158152f35b5460a01c6001600160401b03164210905082610fcc565b5060ff815460e01c1690600382101561038c5790600114610fc3565b3461026e57600036600319011261026e577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163003611063576020604051600080516020612c268339815191528152f35b63703e46dd60e11b60005260046000fd5b3461026e57600036600319011261026e576000546040516001600160a01b039091168152602090f35b3461026e57602036600319011261026e57600435604060008281526004602052209081549160018060a01b038316928315908115611177575b5061116657336000908152600080516020612c46833981519152602052604090205460ff16158061115c575b61114b578061111e63fffffffe611124935460a01c1682612037565b82612381565b7fa5ffbdba01b15df97334e34ad816b9986b6057a5ddc97aba93b7e8ccd21759ed600080a3005b630a606ec360e11b60005260046000fd5b5082331415611102565b6360eb6c2360e01b60005260046000fd5b6001915060a01c1615846110d6565b604036600319011261026e5761119a611e6f565b602435906001600160401b03821161026e573660238301121561026e578160040135906111c682611f40565b916111d46040519384611f1d565b8083526020830193366024838301011161026e57816000926024602093018737840101526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016308114908115611445575b50611063576000546001600160a01b0316330361050f576001600160a01b038116928315610e3d57813b156114345730841461142557600080516020612c26833981519152548461127c611fb9565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f6112b260405192604084526040840190611f94565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa600091816113f1575b506113025785634c9c8ce360e01b60005260045260246000fd5b9081600080516020612c268339815191528793036113dd5750833b156113c8576001600160a01b0319168117600080516020612c26833981519152557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28251156113ad5760008091610598945190845af43d156113a5573d9161138883611f40565b926113966040519485611f1d565b83523d6000602085013e612b64565b606091612b64565b505050346113b757005b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60005260045260246000fd5b632a87526960e21b60005260045260246000fd5b9091506020813d60201161141d575b8161140d60209383611f1d565b8101031261026e575190876112e8565b3d9150611400565b614e8d60eb1b60005260046000fd5b632e07c4bd60e11b60005260046000fd5b600080516020612c26833981519152546001600160a01b0316141590508461122d565b3461026e57602036600319011261026e5760043561148461247b565b6114a6611490826124c6565b9190600263ffffffff825460a01c161790612037565b6001600160a01b0316907fc2713e691344add4705edc62a0ee5aede95ba66ad68f97316efef9cb50644edd600080a3005b3461026e57600036600319011261026e57336000908152600080516020612c46833981519152602052604090205460ff1615806115ba575b6115a957600080516020612ce68339815191525460ff8116156115985760ff1916600080516020612ce6833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a2005b638dfc202b60e01b60005260046000fd5b63659a07b360e11b60005260046000fd5b506000546001600160a01b031633141561150f565b3461026e57604036600319011261026e57606063ffffffff6115fa6115f2611e59565b60043561205a565b90604093929351931515845261160f81611e85565b6020840152166040820152f35b3461026e57604036600319011261026e57611635611e59565b336001600160a01b038216036116515761059890600435612437565b63334bd91960e11b60005260046000fd5b3461026e57604036600319011261026e57610598600435611681611e59565b9061168e61058e82612016565b6123ef565b3461026e57602036600319011261026e576004356116dd6116b38261230f565b91906116c963fffffffb825460a01c1682612037565b805463ffffffff60c01b1916815583612381565b6001600160a01b0316907f09cb4ec44cdef8489412844b9682f87f7900758fa2bd7e039113e9125e538e0f600080a3005b3461026e57602036600319011261026e57600435604060008281526004602052209081549160018060a01b0383169283159081156117c0575b5061116657336000908152600080516020612c46833981519152602052604090205460ff1615806117b6575b61114b578061111e63fffffffd61178f935460a01c1682612037565b7fb390ab029eab314bd18190ebe73d7e5c1c336beaa5c83ac22578378dc9ccc405600080a3005b5082331415611773565b6002915060a01c161584611747565b3461026e57602036600319011261026e5760206117ed600435612016565b604051908152f35b3461026e57604036600319011261026e57600435611811611ebe565b63ffffffff600554169063ffffffff8116918083109081156118bd575b506109715761183c8361230f565b909263ffffffff845460c01c16809260018060a01b031633141591826118b2575b50506118a15761188d827e8a218591d4362499c38c38eb1c12e7a7cc97a9068818d1fe6046a42ba4a5ba94611fdc565b61189c60405192839283611fff565b0390a2005b634e80a40760e11b60005260046000fd5b11159050818661185d565b9050158461182e565b3461026e57602036600319011261026e576118df611eab565b600080516020612d068339815191525460ff8160401c169081156119bf575b506119ae57600080516020612d06833981519152805460026001600160401b0319821681179092556000546001600160481b031990911690911791906001600160a01b0316330361050f5763ffffffff168015610d8057604081600080516020612c868339815191529263ffffffff196005541617600555815190600082526020820152a1600080516020612d0683398151915255600080516020612be6833981519152602060405160028152a1005b63f92ee8a960e01b60005260046000fd5b60026001600160401b039190911610159050826118fe565b3461026e5760a036600319011261026e576119f0611e6f565b6119f8611e59565b906044356001600160a01b03811680820361026e576064356001600160a01b0381169182820361026e576084356001600160a01b038116949085900361026e57600080516020612d0683398151915254604081901c60ff161596906001600160401b031680159081611d75575b6001149081611d6b575b159081611d62575b506119ae57600080516020612d0683398151915280546001600160401b031916600117905586611d3d575b611aaa6127b2565b611ab26127b2565b611aba6127b2565b611ac26127b2565b6001600160a01b038116908115610e3d578315610e3d578515610e3d576001600160a01b038916988915610e3d573b15610e2c57858414611d2c5762aa36a746148015611d21575b8015611d16575b1580611d04575b610e2c57611b279060006127e0565b9081611cbd575b5015611c0257611b4c90600080516020612cc68339815191526127e0565b9081611c68575b5015611c0257611b7190600080516020612c068339815191526127e0565b9081611c13575b5015611c0257600080546001600160a01b031916841781556040519390600080516020612c668339815191528180a38015610e3d57803b15610e2c57600380546001600160a01b031916919091179055611bce57005b600080516020612d06833981519152805460ff60401b1916905560018152600080516020612be683398151915290602090a1005b63cf5a8e3360e01b60005260046000fd5b600080516020612c06833981519152600052600080516020612bc6833981519152602052611c61907ffff5b43478fa6840382eb63777e0da6941d320b940e3f70f0ea4780feff95827612a20565b5084611b78565b600080516020612cc6833981519152600052600080516020612bc6833981519152602052611cb6907f32d31393d541a265984ec379cddd8b1fcbe5f2b0eb8ad81dddfead454f135eaa612a20565b5086611b53565b60008052600080516020612bc6833981519152602052611cfd907f615f0f9e84155bea8cc509fe18befeb1baf65611e38a6ba60964480fb29dfd44612a20565b5088611b2e565b50823b1580611b185750843b15611b18565b50617a694614611b11565b506105394614611b0a565b638135316560e01b60005260046000fd5b600080516020612d06833981519152805460ff60401b1916600160401b179055611aa2565b90501589611a77565b303b159150611a6f565b889150611a65565b3461026e57604036600319011261026e5761026a611db1611d9c611e59565b6004356000526004602052604060002061213a565b611dba81611e85565b604051918183921583611e8f565b3461026e57600036600319011261026e57602063ffffffff60055416604051908152f35b3461026e57602036600319011261026e576004359063ffffffff60e01b821680920361026e57602091635a05180f60e01b8114908115611e2e575b5015158152f35b637965db0b60e01b811491508115611e48575b5083611e27565b6301ffc9a760e01b14905083611e41565b602435906001600160a01b038216820361026e57565b600435906001600160a01b038216820361026e57565b6008111561038c57565b901515815260408101929190602090611ea783611e85565b0152565b6004359063ffffffff8216820361026e57565b6024359063ffffffff8216820361026e57565b60a081019081106001600160401b03821117611eec57604052565b634e487b7160e01b600052604160045260246000fd5b606081019081106001600160401b03821117611eec57604052565b601f909101601f19168101906001600160401b03821190821017611eec57604052565b6001600160401b038111611eec57601f01601f191660200190565b604435906001600160401b038216820361026e57565b60005b838110611f845750506000910152565b8181015183820152602001611f74565b90602091611fad81518092818552858086019101611f71565b601f01601f1916010190565b60405190611fc8604083611f1d565b60058252640322e302e360dc1b6020830152565b805463ffffffff60c01b191660c09290921b63ffffffff60c01b16919091179055565b63ffffffff91821681529116602082015260400190565b600052600080516020612ca683398151915260205260016040600020015490565b805463ffffffff60a01b191660a09290921b63ffffffff60a01b16919091179055565b9190916000526004602052612074604060002092836121f7565b9161207e83611e85565b826120d45763ffffffff9192505460c01c1663ffffffff60055416811580156120cc575b6120bf578082106120b857505b60019160009190565b90506120af565b5050600090600390600090565b5080156120a2565b5060009190600090565b906120f59160005260046020526040600020612283565b6120fe81611e85565b8061210c5750600190600090565b600091565b8054600160a01b600160e01b03191660a09290921b600160a01b600160e01b0316919091179055565b60ff600080516020612ce683398151915254166121f057546001600160a01b0381169081156121e85760a01c600216156121e15760005260016020526040600020549060ff8260e01c16600381101561038c5780156121d9576002146121d2574260a083901c6001600160401b031611156121cb576001600160a01b039081169116036121c657600090565b600790565b5050600690565b5050600590565b505050600490565b5050600390565b505050600290565b5050600190565b60ff600080516020612ce683398151915254166121f057546001600160a01b0381169081156121e85760a01c600416156121e15760005260016020526040600020549060ff8260e01c16600381101561038c5780156121d9576002146121d2574260a083901c6001600160401b031611156121cb576001600160a01b039081169116036121c657600090565b60ff600080516020612ce683398151915254166121f057546001600160a01b0381169081156121e85760a01c600116156121e15760005260016020526040600020549060ff8260e01c16600381101561038c5780156121d9576002146121d2574260a083901c6001600160401b031611156121cb576001600160a01b039081169116036121c657600090565b6000908152600460205260409020805490916001600160a01b038216918215908115612372575b5061116657336000908152600080516020612c46833981519152602052604090205460ff161580612368575b61114b57565b5081331415612362565b6004915060a01c161538612336565b905460a01c63ffffffff16156123945750565b600052600460205260006040812055565b6000818152600080516020612ca68339815191526020908152604080832033845290915290205460ff16156123d75750565b63e2517d3f60e01b6000523360045260245260446000fd5b6123f982826127e0565b918261240457505090565b6000918252600080516020612bc68339815191526020526040909120612433916001600160a01b031690612a20565b5090565b6124418282612889565b918261244c57505090565b6000918252600080516020612bc68339815191526020526040909120612433916001600160a01b031690612a91565b60ff600080516020612ce6833981519152541661249457565b63d93c066560e01b60005260046000fd5b519064ffffffffff8216820361026e57565b519061ffff8216820361026e57565b80156127a157600354604051638d34875560e01b8152600481018390529190600090839060249082906001600160a01b03165afa918215612795576000926125ea575b5060808201516001600160a01b0316913383900361114b57610120015161252f81611e85565b61253881611e85565b600381149081156125d5575b81156125c1575b506125b05781600052600160205260ff60406000205460e01c16600381101561038c5760010361259f57600090815260046020526040902080546001600160a01b0319166001600160a01b03831617815591565b632e68d1d360e21b60005260046000fd5b63e9f6db8560e01b60005260046000fd5b600791506125ce81611e85565b143861254b565b90506125e081611e85565b6005811490612544565b90913d8082843e6125fb8184611f1d565b820191602081840312612775578051906001600160401b03821161277d5701906101a08284031261277257604051926101a084016001600160401b038111858210176127815760409081528351855260208085015190860152838101519085015260608301516001600160401b03811161277d57830181601f8201121561277d5780519061268882611f40565b926126966040519485611f1d565b8284526020838301011161277957906126b59160208085019101611f71565b606084015260808201516001600160a01b03811681036127755760808401526126e060a083016124a5565b60a08401526126f160c083016124a5565b60c084015261270260e083016124b7565b60e084015261271461010083016124a5565b6101008401526101208201519060088210156127725750612765916101809161012085015261274661014082016124a5565b61014085015261275961016082016124b7565b610160850152016124a5565b6101808201529038612509565b80fd5b5080fd5b8380fd5b8280fd5b634e487b7160e01b83526041600452602483fd5b6040513d6000823e3d90fd5b637bb0b62160e01b60005260046000fd5b60ff600080516020612d068339815191525460401c16156127cf57565b631afcd79f60e31b60005260046000fd5b6000818152600080516020612ca6833981519152602090815260408083206001600160a01b038616845290915290205460ff16612882576000818152600080516020612ca6833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5050600090565b6000818152600080516020612ca6833981519152602090815260408083206001600160a01b038616845290915290205460ff1615612882576000818152600080516020612ca6833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b1580156129e1575b610e3d576001600160a01b03166000908152600260205260409020546129d0576001600160401b0316428111156129bf5760005460a01c6001600160401b03168015159182612994575b505061298357565b63e774e7b560e01b60005260046000fd5b9091504281039081116129a95711388061297b565b634e487b7160e01b600052601160045260246000fd5b63efa7aefd60e01b60005260046000fd5b633b53f64f60e21b60005260046000fd5b506001600160a01b03811615612931565b8054821015612a0a5760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b6001810190826000528160205260406000205415600014612a89578054600160401b811015611eec57612a74612a5d8260018794018555846129f2565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b505050600090565b9060018201918160005282602052604060002054801515600014612b5b5760001981018181116129a95782546000198101919082116129a957818103612b24575b50505080548015612b0e576000190190612aec82826129f2565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b612b44612b34612a5d93866129f2565b90549060031b1c928392866129f2565b905560005283602052604060002055388080612ad2565b50505050600090565b90612b8a5750805115612b7957602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580612bbc575b612b9b575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15612b9356fec1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e82371705932000c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc07966f2ab141347034724e9b2a472c2f77f5cd745aeba27cacba797b8fcb708617dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846cd37bc77615afefc793aa17d75d4249a9b517ba91b0e54a49c9c4a44b3d7e228302dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800edcc084d3dcd65a1f7f23c65c46722faca6953d28e43150a467cf43e5c309238cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c6343000822000a";
18058
+ var _bytecode2 = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161304c90816100f0823960805181818161114401526113290152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe608080604052600436101561001357600080fd5b60003560e01c90816301ffc9a714611ff7575080630d33f3c214611fd35780630f3f4a9414611f885780631459457a14611be257806318c38b8914611ad15780631d44454114611a005780632106764c146119d9578063248a9ca3146119b35780632ec22d4c146118f25780632f0647ce146118775780632f2ff15d14611846578063324207441461177257806336568abe1461172c578063392f1087146116f65780633f4ba83a146115fe5780633f5aadc91461158f5780634f1ef286146112ad57806352340363146111c45780635273b6f61461119b57806352d1902d14611131578063554c4f4b146110a1578063561b7f8a14610f755780635bc26aea14610ee85780635c975abb14610eb85780636289d18c14610e375780636711cc0b14610e1b5780636e852a7814610d1a5780637e35bf6e14610ce65780638343f67414610cb95780638456cb5914610bc35780638f33527f14610b895780639010d07c14610b3557806391d1485414610adb5780639b9d30c114610ab2578063a19af3f614610a01578063a217fddf146109e5578063a3246ad314610923578063a878086414610907578063ac3c0e30146107fa578063ad3cb1cc146107b3578063b3fad6381461070e578063c34e9c26146106f2578063c86deb31146106d6578063ca15c8731461069d578063d547741f14610665578063dd71d99a14610623578063e0922fa114610576578063efa9b4ae14610507578063f2f4eb26146104de578063f68e9553146104b5578063f94f67ab146103de578063fd437d391461029f5763ffa1ad741461026657600080fd5b3461029a57600036600319011261029a576102966102826121ed565b6040519182916020835260208301906121c8565b0390f35b600080fd5b3461029a57606036600319011261029a576102b861207a565b6102c0612064565b906102c961218f565b906102d2612795565b6001600160a01b0316338190036103ce5780600052600160205260406000209283549360ff8560e01c1660038110156103b8576001036103a75781600160209261033e877fc5d5c5bbf10444998e0ea6d4725e79027b574e1c14ec929279e8a9a95c6c6e919688612c43565b818060a01b038316828060a01b031982541617815561035d878261239f565b0180546001600160401b031916426001600160401b03908116919091179091556001600160a01b0391821660008181526002855260409081902087905551969091168652951693a4005b632437e77160e11b60005260046000fd5b634e487b7160e01b600052602160045260246000fd5b62fca64560e31b60005260046000fd5b3461029a57604036600319011261029a576004356103fa6120c9565b90610403612795565b63ffffffff600554169163ffffffff8116928084109081156104ac575b5061049b5760207f6b7727cc9c3df4a29acf0afe01594c1b7e845d20f40f4a14e4c292164a9ed8e191610452846127e0565b9161046a600863ffffffff845460a01c1617836122e3565b81546001600160e01b031660e09190911b6001600160e01b0319161790556040519485526001600160a01b031693a3005b634346c13160e01b60005260046000fd5b90501584610420565b3461029a57600036600319011261029a576020604051600080516020612fe08339815191528152f35b3461029a57600036600319011261029a576003546040516001600160a01b039091168152602090f35b3461029a57602036600319011261029a57600435610523612795565b61054561052f826127e0565b9190600163ffffffff825460a01c1617906122e3565b6001600160a01b0316907f812690e0a9dff5bf3add998111b8af5c8299608d859025bfe35662060ab4267d600080a3005b3461029a57602036600319011261029a576004356001600160401b0381169081810361029a576000546001600160a01b038116330361061257600160a01b600160e01b0319811660a092831b600160a01b600160e01b031617600055604080519190921c6001600160401b0316815260208101929092527f9c195448332abd01f716db873b329752ea02f19d33f7e311fb0daf082c4edd0391a1005b6349db3bd360e01b60005260046000fd5b3461029a57602036600319011261029a576001600160a01b0361064461207a565b166000526002602052602060018060a01b0360406000205416604051908152f35b3461029a57604036600319011261029a5761069b600435610684612064565b90610696610691826122c2565b6126bf565b612751565b005b3461029a57602036600319011261029a57600435600052600080516020612ee08339815191526020526020604060002054604051908152f35b3461029a57600036600319011261029a57602060405160088152f35b3461029a57600036600319011261029a57602060405160028152f35b3461029a57602036600319011261029a576000606060405161072f81612136565b828152826020820152826040820152015260043560005260046020526080604060002063ffffffff6040519161076483612136565b548160018060a01b038216938481528160208201818560a01c16815260606040840193838760c01c168552019460e01c8552604051968752511660208601525116604084015251166060820152f35b3461029a57600036600319011261029a5761029660408051906107d68183612151565b60058252640352e302e360dc1b6020830152519182916020835260208301906121c8565b3461029a57602036600319011261029a5761081361207a565b6000608060405161082381612105565b828152826020820152826040820152826060820152015260018060a01b03166000526001602052604060002060405161085b81612105565b81546001600160a01b038116825260a081901c6001600160401b03166020830190815292604083019160e01c60ff169060038210156103b857908252600101546001600160401b0380821660608501908152604092831c821660808601908152925194516001600160a01b03168552945116602084015290519260038410156103b857604083019390935291516001600160401b0390811660608301529151909116608082015260a090f35b3461029a57600036600319011261029a57602060405160018152f35b3461029a57602036600319011261029a57600435600052600080516020612ee083398151915260205260406000206040518060208354918281520190819360005260206000209060005b8181106109cf5750505081610983910382612151565b6040519182916020830190602084525180915260408301919060005b8181106109ad575050500390f35b82516001600160a01b031684528594506020938401939092019160010161099f565b825484526020909301926001928301920161096d565b3461029a57600036600319011261029a57602060405160008152f35b3461029a57604036600319011261029a57600435610a1d6120c9565b90610a26612795565b63ffffffff600554169163ffffffff811692808410908115610aa9575b5061049b5760207f1da95b87b4c773f68c1447ffc5644e41a8a8887d55065beb64852014cf7140be91610a96610a78856127e0565b9290610a91600463ffffffff835460a01c1617826122e3565b612210565b6040519485526001600160a01b031693a3005b90501584610a43565b3461029a57600036600319011261029a576020604051600080516020612f208339815191528152f35b3461029a57604036600319011261029a57610af4612064565b600435600052600080516020612fc083398151915260205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b3461029a57604036600319011261029a57600435600052600080516020612ee08339815191526020526020610b706024356040600020612d0c565b905460405160039290921b1c6001600160a01b03168152f35b3461029a57602036600319011261029a576001600160a01b03610baa61207a565b1660005260026020526020604060002054604051908152f35b3461029a57600036600319011261029a573360009081527f0ac8cc3d209806126662940717264973110c39045b305f6ba49613325a615e09602052604090205460ff1615610c9257610c13612795565b600160ff19600080516020613000833981519152541617600080516020613000833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a2005b63e2517d3f60e01b60005233600452600080516020612f2083398151915260245260446000fd5b3461029a57600036600319011261029a5760005460405160a09190911c6001600160401b03168152602090f35b3461029a57604036600319011261029a57610d0a610d02612064565b60043561236c565b906102966040519283928361209a565b3461029a57604036600319011261029a57610d3361207a565b336000908152600080516020612f60833981519152602052604090205460ff161580610e08575b6103ce576001600160a01b03166000818152600160205260409020805460e01c60ff1660038110156103b8576001036103a757805460ff60e01b198116600160e11b1782556001919091018054600160401b600160801b03191642604090811b600160401b600160801b0316919091179091555160243581526001600160a01b0390911691907fc0499cc07ed9d734deec6857802d3f0fa8d5afaf79a7008beb8ba7bef62a271b90602090a3005b50336001600160a01b0382161415610d5a565b3461029a57600036600319011261029a57602060405160048152f35b3461029a57602036600319011261029a57610e506120b6565b6000546001600160a01b031633036106125763ffffffff8116908115610ea757600080516020612fa083398151915291610ea263ffffffff926005549284198416176005556040519384931683612233565b0390a1005b6338f3377360e21b60005260046000fd5b3461029a57600036600319011261029a57602060ff60008051602061300083398151915254166040519015158152f35b3461029a57602036600319011261029a57610f0161207a565b6000546001600160a01b0381169033829003610612576001600160a01b038316928315610f64573b15610f53576001600160a01b03191682176000908155600080516020612f808339815191529080a3005b636f7c43f160e01b60005260046000fd5b63e6c4247b60e01b60005260046000fd5b3461029a57606036600319011261029a57610f8e61207a565b610f96612064565b610f9e61218f565b91610fa7612795565b6001600160a01b031690338290036103ce57816000526001602052604060002060ff815460e01c1660038110156103b857600114611090578160209161100f867ff223dc085722c94c84dcf67427e225799be616382a2a484d378f8921c69a20339587612c43565b80546001600160a01b0319166001600160a01b038316178155611032868261239f565b6001810180546001600160801b031916426001600160401b0390811691909117909155815460ff60e01b1916600160e01b179091556001600160a01b03919091166000818152600284526040908190208690555195909116855293a3005b639d2c8fdf60e01b60005260046000fd5b3461029a57602036600319011261029a576001600160a01b036110c261207a565b166000526001602052604060002060ff60008051602061300083398151915254161580611115575b602091816110fe575b506040519015158152f35b5460a01c6001600160401b031642109050826110f3565b5060ff815460e01c169060038210156103b857906001146110ea565b3461029a57600036600319011261029a577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316300361118a576020604051600080516020612f408339815191528152f35b63703e46dd60e11b60005260046000fd5b3461029a57600036600319011261029a576000546040516001600160a01b039091168152602090f35b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b03831692831590811561129e575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff161580611283575b611272578061124563fffffffe61124b935460a01c16826122e3565b8261269b565b7fa5ffbdba01b15df97334e34ad816b9986b6057a5ddc97aba93b7e8ccd21759ed600080a3005b630a606ec360e11b60005260046000fd5b5082331415611229565b6360eb6c2360e01b60005260046000fd5b6001915060a01c1615846111fd565b604036600319011261029a576112c161207a565b602435906001600160401b03821161029a573660238301121561029a578160040135906112ed82612174565b916112fb6040519384612151565b8083526020830193366024838301011161029a57816000926024602093018737840101526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630811490811561156c575b5061118a576000546001600160a01b03163303610612576001600160a01b038116928315610f6457813b1561155b5730841461154c57600080516020612f4083398151915254846113a36121ed565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f6113d9604051926040845260408401906121c8565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa60009181611518575b506114295785634c9c8ce360e01b60005260045260246000fd5b9081600080516020612f408339815191528793036115045750833b156114ef576001600160a01b0319168117600080516020612f40833981519152557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28251156114d4576000809161069b945190845af43d156114cc573d916114af83612174565b926114bd6040519485612151565b83523d6000602085013e612e7e565b606091612e7e565b505050346114de57005b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60005260045260246000fd5b632a87526960e21b60005260045260246000fd5b9091506020813d602011611544575b8161153460209383612151565b8101031261029a5751908761140f565b3d9150611527565b614e8d60eb1b60005260046000fd5b632e07c4bd60e11b60005260046000fd5b600080516020612f40833981519152546001600160a01b03161415905084611354565b3461029a57602036600319011261029a576004356115ab612795565b6115cd6115b7826127e0565b9190600263ffffffff825460a01c1617906122e3565b6001600160a01b0316907fc2713e691344add4705edc62a0ee5aede95ba66ad68f97316efef9cb50644edd600080a3005b3461029a57600036600319011261029a57336000908152600080516020612f60833981519152602052604090205460ff1615806116e1575b6116d0576000805160206130008339815191525460ff8116156116bf5760ff1916600080516020613000833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a2005b638dfc202b60e01b60005260046000fd5b63659a07b360e11b60005260046000fd5b506000546001600160a01b0316331415611636565b3461029a57604036600319011261029a5761029661171d611715612064565b600435612306565b604093919351938493846120dc565b3461029a57604036600319011261029a57611745612064565b336001600160a01b038216036117615761069b90600435612751565b63334bd91960e11b60005260046000fd5b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b038316928315908115611837575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff16158061182d575b61127257806117f363fffffff7611806935460a01c16826122e3565b80546001600160e01b031681558261269b565b7f054490ec6650e07db9b97a06ea31d44cebd44b390c9975a380055e1b4d3cac21600080a3005b50823314156117d7565b6008915060a01c1615846117ab565b3461029a57604036600319011261029a5761069b600435611865612064565b90611872610691826122c2565b612709565b3461029a57602036600319011261029a576004356118c161189782612629565b91906118ad63fffffffb825460a01c16826122e3565b805463ffffffff60c01b191681558361269b565b6001600160a01b0316907f09cb4ec44cdef8489412844b9682f87f7900758fa2bd7e039113e9125e538e0f600080a3005b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b0383169283159081156119a4575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff16158061199a575b611272578061124563fffffffd611973935460a01c16826122e3565b7fb390ab029eab314bd18190ebe73d7e5c1c336beaa5c83ac22578378dc9ccc405600080a3005b5082331415611957565b6002915060a01c16158461192b565b3461029a57602036600319011261029a5760206119d16004356122c2565b604051908152f35b3461029a57604036600319011261029a5761029661171d6119f8612064565b60043561224a565b3461029a57604036600319011261029a57600435611a1c6120c9565b63ffffffff600554169063ffffffff811691808310908115611ac8575b5061049b57611a4783612629565b909263ffffffff845460c01c16809260018060a01b03163314159182611abd575b5050611aac57611a98827e8a218591d4362499c38c38eb1c12e7a7cc97a9068818d1fe6046a42ba4a5ba94612210565b611aa760405192839283612233565b0390a2005b634e80a40760e11b60005260046000fd5b111590508186611a68565b90501584611a39565b3461029a57602036600319011261029a57611aea6120b6565b6000805160206130208339815191525460ff8160401c16908115611bca575b50611bb957600080516020613020833981519152805460026001600160401b0319821681179092556000546001600160481b031990911690911791906001600160a01b031633036106125763ffffffff168015610ea757604081600080516020612fa08339815191529263ffffffff196005541617600555815190600082526020820152a160008051602061302083398151915255600080516020612f00833981519152602060405160028152a1005b63f92ee8a960e01b60005260046000fd5b60026001600160401b03919091161015905082611b09565b3461029a5760a036600319011261029a57611bfb61207a565b611c03612064565b906044356001600160a01b03811680820361029a576064356001600160a01b0381169182820361029a576084356001600160a01b038116949085900361029a5760008051602061302083398151915254604081901c60ff161596906001600160401b031680159081611f80575b6001149081611f76575b159081611f6d575b50611bb95760008051602061302083398151915280546001600160401b031916600117905586611f48575b611cb5612acc565b611cbd612acc565b611cc5612acc565b611ccd612acc565b6001600160a01b038116908115610f64578315610f64578515610f64576001600160a01b038916988915610f64573b15610f5357858414611f375762aa36a746148015611f2c575b8015611f21575b1580611f0f575b610f5357611d32906000612afa565b9081611ec8575b5015611e0d57611d5790600080516020612fe0833981519152612afa565b9081611e73575b5015611e0d57611d7c90600080516020612f20833981519152612afa565b9081611e1e575b5015611e0d57600080546001600160a01b031916841781556040519390600080516020612f808339815191528180a38015610f6457803b15610f5357600380546001600160a01b031916919091179055611dd957005b600080516020613020833981519152805460ff60401b1916905560018152600080516020612f0083398151915290602090a1005b63cf5a8e3360e01b60005260046000fd5b600080516020612f20833981519152600052600080516020612ee0833981519152602052611e6c907ffff5b43478fa6840382eb63777e0da6941d320b940e3f70f0ea4780feff95827612d3a565b5084611d83565b600080516020612fe0833981519152600052600080516020612ee0833981519152602052611ec1907f32d31393d541a265984ec379cddd8b1fcbe5f2b0eb8ad81dddfead454f135eaa612d3a565b5086611d5e565b60008052600080516020612ee0833981519152602052611f08907f615f0f9e84155bea8cc509fe18befeb1baf65611e38a6ba60964480fb29dfd44612d3a565b5088611d39565b50823b1580611d235750843b15611d23565b50617a694614611d1c565b506105394614611d15565b638135316560e01b60005260046000fd5b600080516020613020833981519152805460ff60401b1916600160401b179055611cad565b90501589611c82565b303b159150611c7a565b889150611c70565b3461029a57604036600319011261029a57610296611fbc611fa7612064565b600435600052600460205260406000206123c8565b611fc581612090565b60405191818392158361209a565b3461029a57600036600319011261029a57602063ffffffff60055416604051908152f35b3461029a57602036600319011261029a576004359063ffffffff60e01b821680920361029a57602091635a05180f60e01b8114908115612039575b5015158152f35b637965db0b60e01b811491508115612053575b5083612032565b6301ffc9a760e01b1490508361204c565b602435906001600160a01b038216820361029a57565b600435906001600160a01b038216820361029a57565b600811156103b857565b9015158152604081019291906020906120b283612090565b0152565b6004359063ffffffff8216820361029a57565b6024359063ffffffff8216820361029a57565b91604091949363ffffffff916060850196151585526120fa81612090565b602085015216910152565b60a081019081106001600160401b0382111761212057604052565b634e487b7160e01b600052604160045260246000fd5b608081019081106001600160401b0382111761212057604052565b601f909101601f19168101906001600160401b0382119082101761212057604052565b6001600160401b03811161212057601f01601f191660200190565b604435906001600160401b038216820361029a57565b60005b8381106121b85750506000910152565b81810151838201526020016121a8565b906020916121e1815180928185528580860191016121a5565b601f01601f1916010190565b604051906121fc604083612151565b60058252640322e312e360dc1b6020830152565b805463ffffffff60c01b191660c09290921b63ffffffff60c01b16919091179055565b63ffffffff91821681529116602082015260400190565b600052600460205261226160406000209182612485565b61226a81612090565b806122b857505460e01c63ffffffff60055416811580156122b0575b6122a35780821061229c57505b60019160009190565b9050612293565b5050600090600390600090565b508015612286565b6000929091508290565b600052600080516020612fc083398151915260205260016040600020015490565b805463ffffffff60a01b191660a09290921b63ffffffff60a01b16919091179055565b919091600052600460205261232060406000209283612511565b9161232a83612090565b826123625763ffffffff9192505460c01c1663ffffffff60055416811580156122b0576122a35780821061229c575060019160009190565b5060009190600090565b90612383916000526004602052604060002061259d565b61238c81612090565b8061239a5750600190600090565b600091565b8054600160a01b600160e01b03191660a09290921b600160a01b600160e01b0316919091179055565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6002161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b600790565b5050600690565b5050600590565b505050600490565b5050600390565b505050600290565b5050600190565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6008161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6004161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6001161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b6000908152600460205260409020805490916001600160a01b03821691821590811561268c575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff161580612682575b61127257565b508133141561267c565b6004915060a01c161538612650565b905460a01c63ffffffff16156126ae5750565b600052600460205260006040812055565b6000818152600080516020612fc08339815191526020908152604080832033845290915290205460ff16156126f15750565b63e2517d3f60e01b6000523360045260245260446000fd5b6127138282612afa565b918261271e57505090565b6000918252600080516020612ee0833981519152602052604090912061274d916001600160a01b031690612d3a565b5090565b61275b8282612ba3565b918261276657505090565b6000918252600080516020612ee0833981519152602052604090912061274d916001600160a01b031690612dab565b60ff60008051602061300083398151915254166127ae57565b63d93c066560e01b60005260046000fd5b519064ffffffffff8216820361029a57565b519061ffff8216820361029a57565b8015612abb57600354604051638d34875560e01b8152600481018390529190600090839060249082906001600160a01b03165afa918215612aaf57600092612904575b5060808201516001600160a01b0316913383900361127257610120015161284981612090565b61285281612090565b600381149081156128ef575b81156128db575b506128ca5781600052600160205260ff60406000205460e01c1660038110156103b8576001036128b957600090815260046020526040902080546001600160a01b0319166001600160a01b03831617815591565b632e68d1d360e21b60005260046000fd5b63e9f6db8560e01b60005260046000fd5b600791506128e881612090565b1438612865565b90506128fa81612090565b600581149061285e565b90913d8082843e6129158184612151565b820191602081840312612a8f578051906001600160401b038211612a975701906101a082840312612a8c57604051926101a084016001600160401b03811185821017612a9b5760409081528351855260208085015190860152838101519085015260608301516001600160401b038111612a9757830181601f82011215612a97578051906129a282612174565b926129b06040519485612151565b82845260208383010111612a9357906129cf91602080850191016121a5565b606084015260808201516001600160a01b0381168103612a8f5760808401526129fa60a083016127bf565b60a0840152612a0b60c083016127bf565b60c0840152612a1c60e083016127d1565b60e0840152612a2e61010083016127bf565b610100840152610120820151906008821015612a8c5750612a7f9161018091610120850152612a6061014082016127bf565b610140850152612a7361016082016127d1565b610160850152016127bf565b6101808201529038612823565b80fd5b5080fd5b8380fd5b8280fd5b634e487b7160e01b83526041600452602483fd5b6040513d6000823e3d90fd5b637bb0b62160e01b60005260046000fd5b60ff6000805160206130208339815191525460401c1615612ae957565b631afcd79f60e31b60005260046000fd5b6000818152600080516020612fc0833981519152602090815260408083206001600160a01b038616845290915290205460ff16612b9c576000818152600080516020612fc0833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5050600090565b6000818152600080516020612fc0833981519152602090815260408083206001600160a01b038616845290915290205460ff1615612b9c576000818152600080516020612fc0833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b158015612cfb575b610f64576001600160a01b0316600090815260026020526040902054612cea576001600160401b031642811115612cd95760005460a01c6001600160401b03168015159182612cae575b5050612c9d57565b63e774e7b560e01b60005260046000fd5b909150428103908111612cc357113880612c95565b634e487b7160e01b600052601160045260246000fd5b63efa7aefd60e01b60005260046000fd5b633b53f64f60e21b60005260046000fd5b506001600160a01b03811615612c4b565b8054821015612d245760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b6001810190826000528160205260406000205415600014612da3578054600160401b81101561212057612d8e612d77826001879401855584612d0c565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b505050600090565b9060018201918160005282602052604060002054801515600014612e75576000198101818111612cc3578254600019810191908211612cc357818103612e3e575b50505080548015612e28576000190190612e068282612d0c565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b612e5e612e4e612d779386612d0c565b90549060031b1c92839286612d0c565b905560005283602052604060002055388080612dec565b50505050600090565b90612ea45750805115612e9357602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580612ed6575b612eb5575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15612ead56fec1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e82371705932000c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc07966f2ab141347034724e9b2a472c2f77f5cd745aeba27cacba797b8fcb708617dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846cd37bc77615afefc793aa17d75d4249a9b517ba91b0e54a49c9c4a44b3d7e228302dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800edcc084d3dcd65a1f7f23c65c46722faca6953d28e43150a467cf43e5c309238cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c6343000822000a";
17900
18059
  var isSuperArgs2 = (xs) => xs.length > 1;
17901
18060
  var AgentDelegationRegistry__factory = class extends ContractFactory2 {
17902
18061
  constructor(...args) {
@@ -18541,6 +18700,158 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
18541
18700
  return;
18542
18701
  await this.serverSession.adoptLoginPayload(payload);
18543
18702
  }
18703
+ /**
18704
+ * Build the Safe-delegation ceremony for a multi-sig Safe (Phase 1 of
18705
+ * multi-sig support): asks lit-ops-server to mint (or recover) the Safe's
18706
+ * agent PKP and returns the exact call batch the Safe's owners must execute
18707
+ * (AgentModuleFactory.deploy → safe.enableModule → registerAgent), derived
18708
+ * from live chain state so a half-done ceremony resumes.
18709
+ *
18710
+ * Service-mode only — the server holds the Chipotle account that mints the
18711
+ * PKP and it gates the route to current Safe owners. `knownAgentAddress` is
18712
+ * the caller-persisted agent from an earlier prepare whose ceremony has not
18713
+ * landed yet; echoing it back prevents a duplicate mint after a server
18714
+ * restart.
18715
+ */
18716
+ async prepareSafeAgentModule(request) {
18717
+ if (this.config.mode !== "service") {
18718
+ throw new Error(
18719
+ "prepareSafeAgentModule requires service mode \u2014 the agent PKP is minted by lit-ops-server's Chipotle account and cannot be minted standalone"
18720
+ );
18721
+ }
18722
+ const PREPARE_CLIENT_TIMEOUT_MS = 3e4;
18723
+ const abort = new AbortController();
18724
+ const abortTimer = setTimeout(() => abort.abort(), PREPARE_CLIENT_TIMEOUT_MS);
18725
+ let resp;
18726
+ try {
18727
+ resp = await fetch(
18728
+ `${this.config.serviceEndpoint}/api/lit/safe/agent-module/prepare`,
18729
+ {
18730
+ method: "POST",
18731
+ headers: {
18732
+ "Content-Type": "application/json",
18733
+ ...await this.getAuthHeader()
18734
+ },
18735
+ signal: abort.signal,
18736
+ body: JSON.stringify({
18737
+ safeAddress: request.safeAddress,
18738
+ ...request.knownAgentAddress ? { knownAgentAddress: request.knownAgentAddress } : {}
18739
+ })
18740
+ }
18741
+ );
18742
+ } catch (fetchErr) {
18743
+ throw abort.signal.aborted ? new Error(
18744
+ `prepareSafeAgentModule timed out after ${PREPARE_CLIENT_TIMEOUT_MS}ms \u2014 the delegation server did not answer`
18745
+ ) : fetchErr;
18746
+ } finally {
18747
+ clearTimeout(abortTimer);
18748
+ }
18749
+ const data = await resp.json().catch(() => null);
18750
+ if (!resp.ok || !data?.success) {
18751
+ throw new Error(
18752
+ `prepareSafeAgentModule failed (${resp.status}): ${data?.error ?? "no error detail from server"}`
18753
+ );
18754
+ }
18755
+ return {
18756
+ status: data.status,
18757
+ agentAddress: data.agentAddress,
18758
+ moduleAddress: data.moduleAddress,
18759
+ validUntil: data.validUntil,
18760
+ calls: data.calls
18761
+ };
18762
+ }
18763
+ /**
18764
+ * Shared transport for `/agent-module/{authorize,execute}`.
18765
+ *
18766
+ * Both routes run the agent PKP's key inside a Lit Action, gated on the
18767
+ * caller's session being a CURRENT Safe owner (M-8c). Service-mode only, for
18768
+ * the same reason as {@link prepareSafeAgentModule}: the key lives in the
18769
+ * server's Chipotle account and has no standalone equivalent.
18770
+ */
18771
+ async postAgentModuleRoute(mode, body) {
18772
+ if (this.config.mode !== "service") {
18773
+ throw new Error(
18774
+ `agentModule${mode === "authorize" ? "Authorize" : "Execute"} requires service mode \u2014 the agent PKP is held by lit-ops-server's Chipotle account`
18775
+ );
18776
+ }
18777
+ const AGENT_MODULE_CLIENT_TIMEOUT_MS = 45e3;
18778
+ const abort = new AbortController();
18779
+ const abortTimer = setTimeout(
18780
+ () => abort.abort(),
18781
+ AGENT_MODULE_CLIENT_TIMEOUT_MS
18782
+ );
18783
+ let resp;
18784
+ try {
18785
+ resp = await fetch(
18786
+ `${this.config.serviceEndpoint}/api/lit/agent-module/${mode}`,
18787
+ {
18788
+ method: "POST",
18789
+ headers: {
18790
+ "Content-Type": "application/json",
18791
+ ...await this.getAuthHeader()
18792
+ },
18793
+ signal: abort.signal,
18794
+ body: JSON.stringify(body)
18795
+ }
18796
+ );
18797
+ } catch (fetchErr) {
18798
+ throw abort.signal.aborted ? new Error(
18799
+ `agent-module ${mode} timed out after ${AGENT_MODULE_CLIENT_TIMEOUT_MS}ms \u2014 the delegation server did not answer`
18800
+ ) : fetchErr;
18801
+ } finally {
18802
+ clearTimeout(abortTimer);
18803
+ }
18804
+ const data = await resp.json().catch(() => null);
18805
+ if (!resp.ok || !data?.success) {
18806
+ throw new Error(
18807
+ `agent-module ${mode} failed (${resp.status}): ${data?.error ?? "no error detail from server"}`
18808
+ );
18809
+ }
18810
+ return data;
18811
+ }
18812
+ /**
18813
+ * The agent signs the borrower authorization envelope for `op` on `positionId`.
18814
+ *
18815
+ * The returned `{ timestamp, signature }` feeds the SDK's PRECOMPUTED
18816
+ * authorization path (`generateExtendAuthorization` and siblings) — the same
18817
+ * path Safe/EIP-1271 borrowers already use. It is NOT a generic message
18818
+ * signer: the Lit Action REBUILDS the envelope from these fields rather than
18819
+ * signing anything the caller supplies, which is what stops a delegated agent
18820
+ * key being turned into an arbitrary oracle.
18821
+ *
18822
+ * `timestamp` must be quantum-aligned by the caller
18823
+ * (`calculateNextQuantumTimestamp()`) and must be the SAME value later passed
18824
+ * to the protocol call, or the validator recovers a different signer.
18825
+ */
18826
+ async agentModuleAuthorize(request) {
18827
+ return this.postAgentModuleRoute("authorize", {
18828
+ safeAddress: request.safeAddress,
18829
+ positionId: request.positionId,
18830
+ op: request.op,
18831
+ timestamp: request.timestamp,
18832
+ ...request.amount !== void 0 ? { amount: request.amount } : {},
18833
+ ...request.selectedTerm !== void 0 ? { selectedTerm: request.selectedTerm } : {}
18834
+ });
18835
+ }
18836
+ /**
18837
+ * The agent signs `module.execute(target, innerData)` as a raw EIP-1559
18838
+ * transaction. Returns the SIGNED transaction — the caller broadcasts it, so
18839
+ * the tx hash and receipt come from the caller's own provider.
18840
+ *
18841
+ * `tx` fields are caller-supplied because the Lit Action runs on many nodes
18842
+ * and reconciles results: anything fetched in-action (nonce, gas) would
18843
+ * differ per node and fail consensus.
18844
+ */
18845
+ async agentModuleExecute(request) {
18846
+ return this.postAgentModuleRoute("execute", {
18847
+ safeAddress: request.safeAddress,
18848
+ positionId: request.positionId,
18849
+ op: request.op,
18850
+ target: request.target,
18851
+ innerData: request.innerData,
18852
+ tx: request.tx
18853
+ });
18854
+ }
18544
18855
  /**
18545
18856
  * Audit H-9: invalidate the LoanQuery cache so subsequent reads return
18546
18857
  * the post-write state. We clear the entire loan-query cache (not just
@@ -19570,7 +19881,12 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
19570
19881
  ...this.config.contractAddresses?.btcSpendAuthorizer ? { BTCSpendAuthorizer: this.config.contractAddresses.btcSpendAuthorizer } : {},
19571
19882
  ...this.config.contractAddresses?.bitcoinProviderRegistry ? { BitcoinProviderRegistry: this.config.contractAddresses.bitcoinProviderRegistry } : {},
19572
19883
  // Required for Safe-as-borrower auth verification (third arm).
19573
- ...this.config.contractAddresses?.positionDelegateRegistry ? { PositionDelegateRegistry: this.config.contractAddresses.positionDelegateRegistry } : {}
19884
+ ...this.config.contractAddresses?.positionDelegateRegistry ? { PositionDelegateRegistry: this.config.contractAddresses.positionDelegateRegistry } : {},
19885
+ // Required for the Safe-agent scoped mint grant (canMint) — without
19886
+ // this the LIT Action's agent-grant arm is skipped entirely and a
19887
+ // delegated agent signer falls through to the borrower/EIP-1271
19888
+ // arms, which reject it.
19889
+ ...this.config.contractAddresses?.agentDelegationRegistry ? { AgentDelegationRegistry: this.config.contractAddresses.agentDelegationRegistry } : {}
19574
19890
  };
19575
19891
  if (this.config.debug) {
19576
19892
  log.info(" Contract addresses passed to LIT Action:", {});
@@ -21227,7 +21543,12 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
21227
21543
  // Required for the LIT Action verifier's third auth arm in
21228
21544
  // Safe-as-borrower flows. See diamond-hands-sdk.ts:5786 for the same
21229
21545
  // pattern in the withdraw flow.
21230
- PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || ""
21546
+ PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || "",
21547
+ // Required for the Safe-agent scoped renew grant (canRenew) — without
21548
+ // this the LIT Action's agent-grant arm is skipped entirely and a
21549
+ // delegated agent signer falls through to the borrower/EIP-1271 arms,
21550
+ // which reject it.
21551
+ AgentDelegationRegistry: this.config.contractAddresses?.agentDelegationRegistry || ""
21231
21552
  };
21232
21553
  if (!contracts.PositionManager) {
21233
21554
  throw new Error("PositionManager address is required");
@@ -21964,7 +22285,12 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
21964
22285
  BTCSpendAuthorizer: this.config.contractAddresses?.btcSpendAuthorizer || "",
21965
22286
  BitcoinProviderRegistry: this.config.contractAddresses?.bitcoinProviderRegistry || "",
21966
22287
  // Required for Safe-as-borrower auth verification (third arm).
21967
- PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || ""
22288
+ PositionDelegateRegistry: this.config.contractAddresses?.positionDelegateRegistry || "",
22289
+ // Required for the Safe-agent scoped repay grant (canRepay) —
22290
+ // without this the LIT Action's agent-grant arm is skipped entirely
22291
+ // and a delegated agent signer falls through to the
22292
+ // borrower/EIP-1271 arms, which reject it.
22293
+ AgentDelegationRegistry: this.config.contractAddresses?.agentDelegationRegistry || ""
21968
22294
  };
21969
22295
  if (this.config.debug) {
21970
22296
  log.info(" Contract addresses:", {});
@@ -23232,6 +23558,11 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23232
23558
  * The service path's post-broadcast CRIT-2 re-verification exists to catch
23233
23559
  * a LYING SERVER; here the broadcast happens locally from the signatures we
23234
23560
  * just obtained, so the esplora-returned txid is already first-hand.
23561
+ *
23562
+ * Multi-UTXO consolidation in standalone mode requires the caller to supply
23563
+ * `request.utxos` explicitly — `fetchConfirmedVaultUtxos` is service-mode
23564
+ * only, so there is no automatic gather here; without the set, a multi-UTXO
23565
+ * vault fails in the signer with its "Insufficient UTXO value" error.
23235
23566
  */
23236
23567
  async executeBTCWithdrawalStandalonePhase2(request, envelope, txid, vout, chainId) {
23237
23568
  const positionDetails = await this.getPositionDetailsView(
@@ -23438,6 +23769,35 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23438
23769
  const network = await this.getProviderOrThrow().getNetwork();
23439
23770
  const chainId = Number(network.chainId);
23440
23771
  const signer = this.getSignerOrThrow();
23772
+ let executionUtxos = request.utxos;
23773
+ if (!executionUtxos || executionUtxos.length === 0) {
23774
+ const gathered = await this.fetchConfirmedVaultUtxos(request.positionId);
23775
+ if (gathered.length > 0) {
23776
+ const normTxid = (t) => String(t).toLowerCase().replace(/^0x/, "");
23777
+ const byOutpoint = /* @__PURE__ */ new Map();
23778
+ for (const u of gathered) {
23779
+ byOutpoint.set(`${normTxid(u.txid)}:${u.vout}`, {
23780
+ txid: normTxid(u.txid),
23781
+ vout: Number(u.vout),
23782
+ value: Number(u.value)
23783
+ });
23784
+ }
23785
+ if (!byOutpoint.has(`${normTxid(txid)}:${vout}`)) {
23786
+ return {
23787
+ success: false,
23788
+ 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`
23789
+ };
23790
+ }
23791
+ if (byOutpoint.size > 1) {
23792
+ executionUtxos = Array.from(byOutpoint.values());
23793
+ if (this.config.debug) {
23794
+ log.info("\u{1F9E9} Multi-UTXO withdrawal: gathered full input set", {
23795
+ inputs: executionUtxos.length
23796
+ });
23797
+ }
23798
+ }
23799
+ }
23800
+ }
23441
23801
  const envelope = await buildBtcExecuteEnvelope({
23442
23802
  positionId: request.positionId,
23443
23803
  txid,
@@ -23448,7 +23808,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
23448
23808
  networkFee: request.networkFee,
23449
23809
  chainId,
23450
23810
  signer,
23451
- ...request.utxos ? { utxos: request.utxos } : {}
23811
+ ...executionUtxos ? { utxos: executionUtxos } : {}
23452
23812
  });
23453
23813
  if (this.config.mode !== "service") {
23454
23814
  return await this.executeBTCWithdrawalStandalonePhase2(
@@ -24663,6 +25023,49 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24663
25023
  }
24664
25024
  return addr;
24665
25025
  }
25026
+ /**
25027
+ * `LoanGrant` fields that EVERY deployed registry version returns.
25028
+ *
25029
+ * Deliberately omits `minWithdrawRatioBps` — see {@link readLoanGrant}.
25030
+ */
25031
+ static LOAN_GRANT_PREFIX_IFACE = new Interface5([
25032
+ "function getLoanGrant(bytes32 positionId) view returns (address borrower, uint32 scopeBits, uint32 minCollateralRatioBps)"
25033
+ ]);
25034
+ /**
25035
+ * Read a position's grant, decoding only the struct prefix that every deployed registry
25036
+ * version shares.
25037
+ *
25038
+ * `LoanGrant` gained a fourth member (`minWithdrawRatioBps`) in registry v2.1.0, and the
25039
+ * typechain bindings are generated from that source — but Sepolia (`0x6AE7fc6b…`) and mainnet
25040
+ * (`0x54853b7E…`) both run v2.0.0, whose `getLoanGrant` returns three words. Decoding that
25041
+ * with the generated four-field decoder fails `BAD_DATA` on every live chain, which is what
25042
+ * took the Agents tab down. The first three members are identical in both layouts, and ethers
25043
+ * ignores the trailing static word on a v2.1.0 registry, so this decoder is correct against
25044
+ * both. Nothing in this SDK reads `minWithdrawRatioBps`: WITHDRAW is not a scope it grants.
25045
+ */
25046
+ async readLoanGrant(registryAddress, pid) {
25047
+ const iface = _DiamondHandsSDK.LOAN_GRANT_PREFIX_IFACE;
25048
+ const data = await this.getProviderOrThrow().call({
25049
+ to: registryAddress,
25050
+ data: iface.encodeFunctionData("getLoanGrant", [pid])
25051
+ });
25052
+ if (getBytes5(data).length < 96) {
25053
+ throw new SDKError({
25054
+ message: `AgentDelegationRegistry at ${registryAddress} returned ${getBytes5(data).length} bytes for getLoanGrant(bytes32) \u2014 expected at least 96. Wrong address, or a registry version this SDK does not support.`,
25055
+ category: "CONTRACT" /* CONTRACT */,
25056
+ severity: "HIGH" /* HIGH */
25057
+ });
25058
+ }
25059
+ const [borrower, scopeBits, minCollateralRatioBps] = iface.decodeFunctionResult(
25060
+ "getLoanGrant",
25061
+ data
25062
+ );
25063
+ return {
25064
+ borrower,
25065
+ scopeBits: Number(scopeBits),
25066
+ minCollateralRatioBps: Number(minCollateralRatioBps)
25067
+ };
25068
+ }
24666
25069
  /**
24667
25070
  * Read a position's auto-renew delegation state (used to drive the Enable/Disable toggle).
24668
25071
  * Pure view — no signer required.
@@ -24671,8 +25074,8 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24671
25074
  const addr = this.agentDelegationRegistryOrThrow();
24672
25075
  const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
24673
25076
  const pid = this.toBytes32(positionId);
24674
- const grant = await registry.getLoanGrant(pid);
24675
- const enabled = grant.borrower !== "0x0000000000000000000000000000000000000000" && (Number(grant.scopeBits) & 1) !== 0;
25077
+ const grant = await this.readLoanGrant(addr, pid);
25078
+ const enabled = grant.borrower !== "0x0000000000000000000000000000000000000000" && (grant.scopeBits & 1) !== 0;
24676
25079
  const agentActive = user ? await registry.isAgentActive(user) : null;
24677
25080
  const canRenew = user ? await registry.canRenew(pid, user).then((r) => ({ ok: r.ok, reason: Number(r.reason) })) : null;
24678
25081
  return {
@@ -24683,16 +25086,58 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24683
25086
  };
24684
25087
  }
24685
25088
  /**
24686
- * Enable auto-renew delegation for a position. Orchestrates the first-time setup: if the
24687
- * borrower has no active agent, mints a fresh per-user agent PKP (via lit-ops-server) and
24688
- * registers it, then records the position's renew grant. Borrower-signed.
25089
+ * Read every delegation scope a position has granted, plus the mint floor and the protocol
25090
+ * minimum the UI must clamp its editor to. Pure view — no signer required.
25091
+ *
25092
+ * Superset of `getAutoRenewStatus`, which predates the multi-scope UI and is kept for
25093
+ * callers that only care about renew.
24689
25094
  */
24690
- async enableAutoRenew(positionId, options) {
25095
+ async getDelegationStatus(positionId, user) {
25096
+ const addr = this.agentDelegationRegistryOrThrow();
25097
+ const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
25098
+ const pid = this.toBytes32(positionId);
25099
+ const [grant, protocolMin] = await Promise.all([
25100
+ this.readLoanGrant(addr, pid),
25101
+ registry.agentMintFloorMinBps().then(Number)
25102
+ ]);
25103
+ const hasGrant = grant.borrower !== "0x0000000000000000000000000000000000000000";
25104
+ const scopes = grant.scopeBits;
25105
+ const mintEnabled = hasGrant && (scopes & 4) !== 0;
25106
+ const floor = grant.minCollateralRatioBps;
25107
+ const agent = user ? await registry.agentOf(user) : null;
25108
+ return {
25109
+ renewEnabled: hasGrant && (scopes & 1) !== 0,
25110
+ repayEnabled: hasGrant && (scopes & 2) !== 0,
25111
+ mintEnabled,
25112
+ minCollateralRatioBps: mintEnabled ? floor : 0,
25113
+ effectiveMintFloorBps: mintEnabled ? Math.max(floor, protocolMin) : 0,
25114
+ protocolMinFloorBps: protocolMin,
25115
+ borrower: grant.borrower,
25116
+ agentActive: user ? await registry.isAgentActive(user) : null,
25117
+ agentValidUntil: agent ? Number(agent.validUntil) : null
25118
+ };
25119
+ }
25120
+ /** Governance floor-of-floors for agent mints (bps). The UI's minimum for the floor editor. */
25121
+ async getAgentMintFloorMinBps() {
25122
+ const addr = this.agentDelegationRegistryOrThrow();
25123
+ const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
25124
+ return Number(await registry.agentMintFloorMinBps());
25125
+ }
25126
+ /**
25127
+ * Shared enable-path preamble for EVERY scope: resolve the registry, ensure the borrower has
25128
+ * an active agent (minting + registering a per-user PKP on first use), and make that agent the
25129
+ * position's Gate-1 delegate. Returns the signer-connected registry and the agent address.
25130
+ *
25131
+ * Every `enableAuto*` runs this: the registry reverts `NoActiveAgent` without an agent, and
25132
+ * `lit-ops-server.isPositionDelegate` 403s the agent on the execute routes without Gate 1 —
25133
+ * so a scope enabled without this preamble would look on but never execute.
25134
+ */
25135
+ async prepareAgentDelegation(pid, options) {
24691
25136
  const addr = this.agentDelegationRegistryOrThrow();
24692
25137
  const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
24693
25138
  if (!pdrAddr) {
24694
25139
  throw new SDKError({
24695
- message: "PositionDelegateRegistry address not configured \u2014 required to authorize the renewal agent (contractAddresses.positionDelegateRegistry)",
25140
+ message: "PositionDelegateRegistry address not configured \u2014 required to authorize the agent (contractAddresses.positionDelegateRegistry)",
24696
25141
  category: "CONFIGURATION" /* CONFIGURATION */,
24697
25142
  severity: "HIGH" /* HIGH */
24698
25143
  });
@@ -24700,7 +25145,6 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24700
25145
  const signer = this.getSignerOrThrow();
24701
25146
  const user = await signer.getAddress();
24702
25147
  const registry = AgentDelegationRegistry__factory.connect(addr, signer);
24703
- const pid = this.toBytes32(positionId);
24704
25148
  let agentAddress;
24705
25149
  const hasActiveAgent = await registry.isAgentActive(user);
24706
25150
  if (hasActiveAgent) {
@@ -24722,6 +25166,54 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24722
25166
  const delTx = await setPositionDelegate(pid, agentAddress, signer, pdrAddr);
24723
25167
  await delTx.wait();
24724
25168
  }
25169
+ return { registry, agentAddress };
25170
+ }
25171
+ /**
25172
+ * Shared disable-path epilogue: drop the position's Gate-1 delegate, but ONLY once no scope
25173
+ * remains. Scopes compose, so clearing Gate 1 on every disable would silently break the
25174
+ * surviving ones server-side (the agent would 403 on the execute routes while its remaining
25175
+ * grant still reads as enabled on-chain).
25176
+ *
25177
+ * Also refuses to clobber a delegate registered for anything other than this user's agent.
25178
+ */
25179
+ async clearGate1IfNoScopesRemain(pid) {
25180
+ const addr = this.agentDelegationRegistryOrThrow();
25181
+ const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
25182
+ if (!pdrAddr) {
25183
+ throw new SDKError({
25184
+ message: "PositionDelegateRegistry address not configured \u2014 required to clear the agent's Gate-1 authorization (contractAddresses.positionDelegateRegistry)",
25185
+ category: "CONFIGURATION" /* CONFIGURATION */,
25186
+ severity: "HIGH" /* HIGH */
25187
+ });
25188
+ }
25189
+ const signer = this.getSignerOrThrow();
25190
+ const user = await signer.getAddress();
25191
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25192
+ const grant = await this.readLoanGrant(addr, pid);
25193
+ if (grant.scopeBits !== 0)
25194
+ return;
25195
+ const [currentDelegate, userAgent] = await Promise.all([
25196
+ getPositionDelegate(pid, signer, pdrAddr),
25197
+ registry.agentOf(user).then((a) => a.agent)
25198
+ ]);
25199
+ if (currentDelegate !== ZeroAddress3 && currentDelegate.toLowerCase() === userAgent.toLowerCase()) {
25200
+ const clearTx = await setPositionDelegate(
25201
+ pid,
25202
+ "0x0000000000000000000000000000000000000000",
25203
+ signer,
25204
+ pdrAddr
25205
+ );
25206
+ await clearTx.wait();
25207
+ }
25208
+ }
25209
+ /**
25210
+ * Enable auto-renew delegation for a position. Orchestrates the first-time setup: if the
25211
+ * borrower has no active agent, mints a fresh per-user agent PKP (via lit-ops-server) and
25212
+ * registers it, then records the position's renew grant. Borrower-signed.
25213
+ */
25214
+ async enableAutoRenew(positionId, options) {
25215
+ const pid = this.toBytes32(positionId);
25216
+ const { registry, agentAddress } = await this.prepareAgentDelegation(pid, options);
24725
25217
  const tx = await registry.enableAutoRenew(pid);
24726
25218
  const receipt = await tx.wait();
24727
25219
  return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0, agentAddress };
@@ -24730,35 +25222,102 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
24730
25222
  async disableAutoRenew(positionId) {
24731
25223
  const addr = this.agentDelegationRegistryOrThrow();
24732
25224
  const signer = this.getSignerOrThrow();
24733
- const user = await signer.getAddress();
24734
25225
  const registry = AgentDelegationRegistry__factory.connect(addr, signer);
24735
25226
  const pid = this.toBytes32(positionId);
24736
- const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
24737
- if (!pdrAddr) {
25227
+ const tx = await registry.disableAutoRenew(pid);
25228
+ const receipt = await tx.wait();
25229
+ await this.clearGate1IfNoScopesRemain(pid);
25230
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25231
+ }
25232
+ /**
25233
+ * Enable auto-repay delegation: the agent may repay this position's debt on the borrower's
25234
+ * behalf. Deliberately uncapped in the registry — repay only ever burns the borrower's own
25235
+ * debt from the borrower's own funds, and the ERC-20 allowance to PositionManager (never
25236
+ * granted to the agent) is the natural bound. Borrower-signed.
25237
+ */
25238
+ async enableAutoRepay(positionId, options) {
25239
+ const pid = this.toBytes32(positionId);
25240
+ const { registry, agentAddress } = await this.prepareAgentDelegation(pid, options);
25241
+ const tx = await registry.enableAutoRepay(pid);
25242
+ const receipt = await tx.wait();
25243
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0, agentAddress };
25244
+ }
25245
+ /** Disable auto-repay delegation for a position. Borrower-signed. */
25246
+ async disableAutoRepay(positionId) {
25247
+ const addr = this.agentDelegationRegistryOrThrow();
25248
+ const signer = this.getSignerOrThrow();
25249
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25250
+ const pid = this.toBytes32(positionId);
25251
+ const tx = await registry.disableAutoRepay(pid);
25252
+ const receipt = await tx.wait();
25253
+ await this.clearGate1IfNoScopesRemain(pid);
25254
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25255
+ }
25256
+ /**
25257
+ * Enable auto-mint delegation with a post-mint collateral-ratio floor (bps) the mint validator
25258
+ * enforces. `minCollateralRatioBps` must be at or above the governance minimum
25259
+ * (`getAgentMintFloorMinBps()`, 15000 = 150%) — checked here so the caller gets a readable
25260
+ * error instead of a `FloorBelowProtocolMin` revert after signing. Borrower-signed.
25261
+ */
25262
+ async enableAutoMint(positionId, minCollateralRatioBps, options) {
25263
+ const pid = this.toBytes32(positionId);
25264
+ await this.assertMintFloorAtOrAboveProtocolMin(minCollateralRatioBps);
25265
+ const { registry, agentAddress } = await this.prepareAgentDelegation(pid, options);
25266
+ const tx = await registry.enableAutoMint(pid, minCollateralRatioBps);
25267
+ const receipt = await tx.wait();
25268
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0, agentAddress };
25269
+ }
25270
+ /** Disable auto-mint delegation for a position (also zeroes its mint floor). Borrower-signed. */
25271
+ async disableAutoMint(positionId) {
25272
+ const addr = this.agentDelegationRegistryOrThrow();
25273
+ const signer = this.getSignerOrThrow();
25274
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25275
+ const pid = this.toBytes32(positionId);
25276
+ const tx = await registry.disableAutoMint(pid);
25277
+ const receipt = await tx.wait();
25278
+ await this.clearGate1IfNoScopesRemain(pid);
25279
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25280
+ }
25281
+ /**
25282
+ * Change an existing mint grant's collateral floor in place — no disable/re-enable dance.
25283
+ * MINT must already be granted; the new floor must clear the governance minimum. Note the
25284
+ * borrower may move it in either direction (above the minimum); only `REGISTRAR_ROLE` is
25285
+ * restricted to raising. Borrower-signed.
25286
+ */
25287
+ async setMintCollateralFloor(positionId, newFloorBps) {
25288
+ const addr = this.agentDelegationRegistryOrThrow();
25289
+ await this.assertMintFloorAtOrAboveProtocolMin(newFloorBps);
25290
+ const signer = this.getSignerOrThrow();
25291
+ const registry = AgentDelegationRegistry__factory.connect(addr, signer);
25292
+ const pid = this.toBytes32(positionId);
25293
+ const tx = await registry.setMintCollateralFloor(pid, newFloorBps);
25294
+ const receipt = await tx.wait();
25295
+ return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
25296
+ }
25297
+ /** Pre-flight the registry's `FloorBelowProtocolMin` guard with a message a user can act on. */
25298
+ async assertMintFloorAtOrAboveProtocolMin(floorBps) {
25299
+ if (!Number.isInteger(floorBps) || floorBps <= 0) {
25300
+ throw new SDKError({
25301
+ message: `Invalid collateral floor: ${floorBps} bps \u2014 must be a positive integer`,
25302
+ category: "VALIDATION" /* VALIDATION */,
25303
+ severity: "MEDIUM" /* MEDIUM */
25304
+ });
25305
+ }
25306
+ const protocolMin = await this.getAgentMintFloorMinBps();
25307
+ if (protocolMin === 0) {
24738
25308
  throw new SDKError({
24739
- message: "PositionDelegateRegistry address not configured \u2014 required to clear the renewal agent's Gate-1 authorization (contractAddresses.positionDelegateRegistry)",
25309
+ message: "Agent minting is not configured on this network (agentMintFloorMinBps is 0) \u2014 the registry would reject every mint grant",
24740
25310
  category: "CONFIGURATION" /* CONFIGURATION */,
24741
25311
  severity: "HIGH" /* HIGH */
24742
25312
  });
24743
25313
  }
24744
- {
24745
- const [currentDelegate, userAgent] = await Promise.all([
24746
- getPositionDelegate(pid, signer, pdrAddr).catch(() => null),
24747
- registry.agentOf(user).then((a) => a.agent).catch(() => null)
24748
- ]);
24749
- if (currentDelegate && userAgent && currentDelegate.toLowerCase() === userAgent.toLowerCase()) {
24750
- const clearTx = await setPositionDelegate(
24751
- pid,
24752
- "0x0000000000000000000000000000000000000000",
24753
- signer,
24754
- pdrAddr
24755
- );
24756
- await clearTx.wait();
24757
- }
25314
+ if (floorBps < protocolMin) {
25315
+ throw new SDKError({
25316
+ message: `Collateral floor ${floorBps / 100}% is below the protocol minimum of ${protocolMin / 100}%`,
25317
+ category: "VALIDATION" /* VALIDATION */,
25318
+ severity: "MEDIUM" /* MEDIUM */
25319
+ });
24758
25320
  }
24759
- const tx = await registry.disableAutoRenew(pid);
24760
- const receipt = await tx.wait();
24761
- return { hash: tx.hash, blockNumber: receipt?.blockNumber ?? 0 };
24762
25321
  }
24763
25322
  // ============================================================================
24764
25323
  // HIGH-LEVEL API - Bitcoin Operations
@@ -25958,6 +26517,146 @@ var EventHelpers = {
25958
26517
  });
25959
26518
  }
25960
26519
  };
26520
+
26521
+ // src/utils/safe-agent-delegation.utils.ts
26522
+ init_deployment_addresses();
26523
+ import { Contract as Contract10, Interface as Interface6 } from "ethers";
26524
+ var SAFE_ABI = [
26525
+ "function getModulesPaginated(address start, uint256 pageSize) view returns (address[] modules, address next)"
26526
+ ];
26527
+ var MODULE_ABI = [
26528
+ "function safe() view returns (address)",
26529
+ "function agent() view returns (address)",
26530
+ "function positionManager() view returns (address)"
26531
+ ];
26532
+ var FACTORY_ABI = ["function isFromFactory(address) view returns (bool)"];
26533
+ var REGISTRY_ABI = [
26534
+ "function agentOf(address user) view returns (address agent, uint64 validUntil, uint8 status, uint64 registeredAt, uint64 revokedAt)"
26535
+ ];
26536
+ var MODULE_LIST_SENTINEL = "0x0000000000000000000000000000000000000001";
26537
+ var MODULE_PAGE_SIZE = 50;
26538
+ var lower = (v) => v.trim().toLowerCase();
26539
+ async function classifyModule(provider, moduleAddress, safeAddress, positionManager, factoryAddress) {
26540
+ const module = new Contract10(moduleAddress, MODULE_ABI, provider);
26541
+ let boundSafe;
26542
+ try {
26543
+ boundSafe = await module.safe();
26544
+ } catch {
26545
+ return null;
26546
+ }
26547
+ if (lower(boundSafe) !== lower(safeAddress))
26548
+ return false;
26549
+ let modulePm;
26550
+ try {
26551
+ modulePm = await module.positionManager();
26552
+ } catch {
26553
+ return false;
26554
+ }
26555
+ if (lower(modulePm) !== lower(positionManager))
26556
+ return false;
26557
+ if (!factoryAddress)
26558
+ return null;
26559
+ try {
26560
+ const factory = new Contract10(factoryAddress, FACTORY_ABI, provider);
26561
+ return await factory.isFromFactory(moduleAddress) === true;
26562
+ } catch {
26563
+ return null;
26564
+ }
26565
+ }
26566
+ async function getSafeAgentDelegation(params) {
26567
+ const { safeAddress, chainId, provider } = params;
26568
+ const normalized = lower(safeAddress);
26569
+ const unknown = {
26570
+ safeAddress: normalized,
26571
+ chainId,
26572
+ status: "unknown",
26573
+ moduleAddress: null,
26574
+ agentAddress: null,
26575
+ validUntil: null,
26576
+ truncated: false
26577
+ };
26578
+ const contracts = Object.values(ALL_DEPLOYMENTS).find(
26579
+ (deployment) => deployment.chainId === chainId
26580
+ )?.contracts;
26581
+ const positionManager = contracts?.PositionManager;
26582
+ if (!positionManager)
26583
+ return unknown;
26584
+ const factoryAddress = contracts?.AgentModuleFactory;
26585
+ const registryAddress = contracts?.AgentDelegationRegistry;
26586
+ let modules;
26587
+ let next;
26588
+ try {
26589
+ const safe = new Contract10(safeAddress, SAFE_ABI, provider);
26590
+ const page = await safe.getModulesPaginated(
26591
+ MODULE_LIST_SENTINEL,
26592
+ MODULE_PAGE_SIZE
26593
+ );
26594
+ modules = [...page[0]];
26595
+ next = page[1];
26596
+ } catch {
26597
+ return unknown;
26598
+ }
26599
+ const truncated = BigInt(next) > BigInt(MODULE_LIST_SENTINEL);
26600
+ let indeterminate = false;
26601
+ for (const moduleAddress of modules) {
26602
+ const verdict = await classifyModule(
26603
+ provider,
26604
+ moduleAddress,
26605
+ normalized,
26606
+ positionManager,
26607
+ factoryAddress
26608
+ );
26609
+ if (verdict === null) {
26610
+ indeterminate = true;
26611
+ continue;
26612
+ }
26613
+ if (!verdict)
26614
+ continue;
26615
+ let agentAddress = null;
26616
+ try {
26617
+ agentAddress = await new Contract10(
26618
+ moduleAddress,
26619
+ MODULE_ABI,
26620
+ provider
26621
+ ).agent();
26622
+ } catch {
26623
+ }
26624
+ if (!registryAddress) {
26625
+ indeterminate = true;
26626
+ continue;
26627
+ }
26628
+ let validUntil;
26629
+ let status;
26630
+ try {
26631
+ const record = await new Contract10(
26632
+ registryAddress,
26633
+ REGISTRY_ABI,
26634
+ provider
26635
+ ).agentOf(safeAddress);
26636
+ status = Number(record[2]);
26637
+ validUntil = Number(record[1]);
26638
+ } catch {
26639
+ indeterminate = true;
26640
+ continue;
26641
+ }
26642
+ const now = Math.floor(Date.now() / 1e3);
26643
+ if (status !== 1 || validUntil <= now) {
26644
+ return { ...unknown, status: "not-delegated", truncated };
26645
+ }
26646
+ return {
26647
+ safeAddress: normalized,
26648
+ chainId,
26649
+ status: "delegated",
26650
+ moduleAddress,
26651
+ agentAddress: agentAddress ? lower(agentAddress) : null,
26652
+ validUntil,
26653
+ truncated
26654
+ };
26655
+ }
26656
+ if (truncated || indeterminate)
26657
+ return { ...unknown, truncated };
26658
+ return { ...unknown, status: "not-delegated" };
26659
+ }
25961
26660
  export {
25962
26661
  ALL_CONTRACTS,
25963
26662
  ALL_DEPLOYMENTS,
@@ -26019,6 +26718,7 @@ export {
26019
26718
  getDelegateStatus,
26020
26719
  getDeploymentByNetwork,
26021
26720
  getPositionDelegate,
26721
+ getSafeAgentDelegation,
26022
26722
  isClosePositionAuth,
26023
26723
  isCreateLoanAuth,
26024
26724
  isExtendTermAuth,