@gvnrdao/dh-sdk 0.0.331 → 0.0.333
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/browser/dist/browser.js +1 -1
- package/dist/graphs/diamond-hands.d.ts +37 -0
- package/dist/index.js +396 -187
- package/dist/index.mjs +420 -211
- package/dist/modules/loan/loan-query.module.d.ts +8 -0
- package/dist/modules/withdrawal-address/withdrawal-address.module.d.ts +23 -0
- package/dist/utils/borrower-authorization-712.d.ts +81 -0
- package/dist/utils/extend-authorization.utils.d.ts +16 -15
- package/dist/utils/mint-authorization.utils.d.ts +50 -43
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1105,6 +1105,9 @@ var require_pkg_src = __commonJS({
|
|
|
1105
1105
|
});
|
|
1106
1106
|
var index_exports = {};
|
|
1107
1107
|
__export2(index_exports, {
|
|
1108
|
+
BORROWER_AUTHORIZATION_ENCODE_TYPES: () => BORROWER_AUTHORIZATION_ENCODE_TYPES,
|
|
1109
|
+
BORROWER_AUTHORIZATION_FIELDS: () => BORROWER_AUTHORIZATION_FIELDS,
|
|
1110
|
+
BORROWER_AUTHORIZATION_PRIMARY_TYPES: () => BORROWER_AUTHORIZATION_PRIMARY_TYPES,
|
|
1108
1111
|
CHIPOTLE_DEPLOYMENTS: () => CHIPOTLE_DEPLOYMENTS,
|
|
1109
1112
|
DEFAULT_CACHE_CONFIG: () => DEFAULT_CACHE_CONFIG,
|
|
1110
1113
|
DEFAULT_DEBUG_CONFIG: () => DEFAULT_DEBUG_CONFIG,
|
|
@@ -1117,6 +1120,8 @@ var require_pkg_src = __commonJS({
|
|
|
1117
1120
|
PerformanceTracker: () => PerformanceTracker,
|
|
1118
1121
|
RetryStrategy: () => RetryStrategy,
|
|
1119
1122
|
analyzeError: () => analyzeError,
|
|
1123
|
+
borrowerAuthorizationTypes: () => borrowerAuthorizationTypes,
|
|
1124
|
+
buildBorrowerAuthorizationDomain: () => buildBorrowerAuthorizationDomain,
|
|
1120
1125
|
calculateDelay: () => calculateDelay,
|
|
1121
1126
|
cidToHex: () => cidToHex,
|
|
1122
1127
|
classifyError: () => classifyError,
|
|
@@ -1363,30 +1368,30 @@ var require_pkg_src = __commonJS({
|
|
|
1363
1368
|
}
|
|
1364
1369
|
},
|
|
1365
1370
|
btcTransactionSigner: {
|
|
1366
|
-
cid: "
|
|
1371
|
+
cid: "QmVi1BYdxvCX3QUhXwPtP6FjWMzqSPtXzrS54YsXjTgjYf",
|
|
1367
1372
|
authorizedCidHex: cidToHex(
|
|
1368
|
-
"
|
|
1373
|
+
"QmVi1BYdxvCX3QUhXwPtP6FjWMzqSPtXzrS54YsXjTgjYf"
|
|
1369
1374
|
),
|
|
1370
1375
|
name: "Btc Transaction Signer",
|
|
1371
1376
|
description: "Production Btc Transaction Signer",
|
|
1372
1377
|
version: "1.1.1",
|
|
1373
1378
|
deployed: true,
|
|
1374
|
-
deployedAt:
|
|
1375
|
-
size:
|
|
1376
|
-
hash: "
|
|
1379
|
+
deployedAt: 1787923905597,
|
|
1380
|
+
size: 70646,
|
|
1381
|
+
hash: "37c3bb72a660c8275d92e1b73f9482742d86b64789480b9246304c0ca1bab47a"
|
|
1377
1382
|
},
|
|
1378
1383
|
ucdMintValidator: {
|
|
1379
|
-
cid: "
|
|
1384
|
+
cid: "QmUWR5fLiyimLT9TPXpYx3HgwNwkvR6MxjZ7hdeYCFodbc",
|
|
1380
1385
|
authorizedCidHex: cidToHex(
|
|
1381
|
-
"
|
|
1386
|
+
"QmUWR5fLiyimLT9TPXpYx3HgwNwkvR6MxjZ7hdeYCFodbc"
|
|
1382
1387
|
),
|
|
1383
1388
|
name: "Ucd Mint Validator",
|
|
1384
1389
|
description: "Production Ucd Mint Validator",
|
|
1385
1390
|
version: "1.2.1",
|
|
1386
1391
|
deployed: true,
|
|
1387
|
-
deployedAt:
|
|
1388
|
-
size:
|
|
1389
|
-
hash: "
|
|
1392
|
+
deployedAt: 1787923919527,
|
|
1393
|
+
size: 86197,
|
|
1394
|
+
hash: "c2d80939746cc37f65ef2f63c6a3215b929214a63f10c78144e1f5c98320dabf",
|
|
1390
1395
|
validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
|
|
1391
1396
|
pkp: {
|
|
1392
1397
|
publicKey: "0x041ab17cd91fc5c0b761eea6092d032807561b621b82c488826776e04a9158d61ba64d809a4729f0501289d980732cb06d8dfd06999dd9c8efd2f495dad78b31bb",
|
|
@@ -1394,17 +1399,17 @@ var require_pkg_src = __commonJS({
|
|
|
1394
1399
|
}
|
|
1395
1400
|
},
|
|
1396
1401
|
processPaymentValidator: {
|
|
1397
|
-
cid: "
|
|
1402
|
+
cid: "QmXmXuMRAjMLdgKGyTf9KQdGwYrDp8DxkiF44TvSXDf7wF",
|
|
1398
1403
|
authorizedCidHex: cidToHex(
|
|
1399
|
-
"
|
|
1404
|
+
"QmXmXuMRAjMLdgKGyTf9KQdGwYrDp8DxkiF44TvSXDf7wF"
|
|
1400
1405
|
),
|
|
1401
1406
|
name: "Process Payment Validator",
|
|
1402
1407
|
description: "Production Process Payment Validator",
|
|
1403
1408
|
version: "1.2.1",
|
|
1404
1409
|
deployed: true,
|
|
1405
|
-
deployedAt:
|
|
1406
|
-
size:
|
|
1407
|
-
hash: "
|
|
1410
|
+
deployedAt: 1787923987153,
|
|
1411
|
+
size: 82217,
|
|
1412
|
+
hash: "13defa19614215ab3b1fe88955d69e530d13a09475396af932fe0e213637da2f",
|
|
1408
1413
|
validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
|
|
1409
1414
|
pkp: {
|
|
1410
1415
|
publicKey: "0x04cfccb9b6c7addc79469c0e9fafebef4c70801302c62cdb26b610723a9b8527d23f98a40158c7340d83fd0e62d02b5ec74c12f7a86d98e8c6973b4811110f19ad",
|
|
@@ -1412,17 +1417,17 @@ var require_pkg_src = __commonJS({
|
|
|
1412
1417
|
}
|
|
1413
1418
|
},
|
|
1414
1419
|
extendPositionValidator: {
|
|
1415
|
-
cid: "
|
|
1420
|
+
cid: "QmU8h99EEVEsQkxroXiYqLsKZw9gNjE6N5CcTpE9aUc12m",
|
|
1416
1421
|
authorizedCidHex: cidToHex(
|
|
1417
|
-
"
|
|
1422
|
+
"QmU8h99EEVEsQkxroXiYqLsKZw9gNjE6N5CcTpE9aUc12m"
|
|
1418
1423
|
),
|
|
1419
1424
|
name: "Extend Position Validator",
|
|
1420
1425
|
description: "Production Extend Position Validator",
|
|
1421
1426
|
version: "1.2.1",
|
|
1422
1427
|
deployed: true,
|
|
1423
|
-
deployedAt:
|
|
1424
|
-
size:
|
|
1425
|
-
hash: "
|
|
1428
|
+
deployedAt: 1787923999294,
|
|
1429
|
+
size: 79975,
|
|
1430
|
+
hash: "31c1aaf883ef22f37681ddb0a4a949be5c05304b6aef178989475a2da935ef9a",
|
|
1426
1431
|
validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
|
|
1427
1432
|
pkp: {
|
|
1428
1433
|
publicKey: "0x04e52338f6a0c3362800f1a94c4c8f08be5030dde0fa217388c53d1c1a4790f4443c9f2886b2d2d8f4b75a9a156e9b028011b1a1cf7648da0e556aa980ec692836",
|
|
@@ -1430,17 +1435,17 @@ var require_pkg_src = __commonJS({
|
|
|
1430
1435
|
}
|
|
1431
1436
|
},
|
|
1432
1437
|
btcWithdrawal: {
|
|
1433
|
-
cid: "
|
|
1438
|
+
cid: "QmZQWET9pzrVD4gwQuSzYZmqa24JrUNtnnGFDd513sxMCY",
|
|
1434
1439
|
authorizedCidHex: cidToHex(
|
|
1435
|
-
"
|
|
1440
|
+
"QmZQWET9pzrVD4gwQuSzYZmqa24JrUNtnnGFDd513sxMCY"
|
|
1436
1441
|
),
|
|
1437
1442
|
name: "Btc Withdrawal",
|
|
1438
1443
|
description: "Production Btc Withdrawal",
|
|
1439
1444
|
version: "1.2.7",
|
|
1440
1445
|
deployed: true,
|
|
1441
|
-
deployedAt:
|
|
1442
|
-
size:
|
|
1443
|
-
hash: "
|
|
1446
|
+
deployedAt: 1787924017769,
|
|
1447
|
+
size: 100069,
|
|
1448
|
+
hash: "4f8e27414e4da235e63d6ae1325c63f3d2fb956464515a21aa007a99935f0f13",
|
|
1444
1449
|
validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
|
|
1445
1450
|
pkp: {
|
|
1446
1451
|
publicKey: "0x043616787c5432415c24378c4ef48de2bcd6bb7b575b837e3cff09171802662da7105d79586c7659677a0ecbaddac4cce06cb2a11f69a16fa0c4d7002ac7d51a4d",
|
|
@@ -1552,30 +1557,30 @@ var require_pkg_src = __commonJS({
|
|
|
1552
1557
|
hash: "03ee5be239c91c735d2c95db89a0d1b77e602cfc18af8eb64b3281fddcd90a72"
|
|
1553
1558
|
},
|
|
1554
1559
|
agentModuleExecutor: {
|
|
1555
|
-
cid: "
|
|
1560
|
+
cid: "QmcD65vuremot5fsHVgp9JBAmei6gAaEtm5mdtLP7Yt9Kf",
|
|
1556
1561
|
authorizedCidHex: cidToHex(
|
|
1557
|
-
"
|
|
1562
|
+
"QmcD65vuremot5fsHVgp9JBAmei6gAaEtm5mdtLP7Yt9Kf"
|
|
1558
1563
|
),
|
|
1559
1564
|
name: "Agent Module Executor",
|
|
1560
1565
|
description: "Production Agent Module Executor",
|
|
1561
1566
|
version: "1.1.1",
|
|
1562
1567
|
deployed: true,
|
|
1563
|
-
deployedAt:
|
|
1564
|
-
size:
|
|
1565
|
-
hash: "
|
|
1568
|
+
deployedAt: 1787924032013,
|
|
1569
|
+
size: 13878,
|
|
1570
|
+
hash: "a7f0204700912e26e5a354bee13a1242a2baa218643b3bb22d28481f67f9baf4"
|
|
1566
1571
|
},
|
|
1567
1572
|
staleSpendRecoveryValidator: {
|
|
1568
|
-
cid: "
|
|
1573
|
+
cid: "QmNuwo4PT4AikAmhMdZgPWCb2mJDwWa9TnUqrqvofjbrT8",
|
|
1569
1574
|
authorizedCidHex: cidToHex(
|
|
1570
|
-
"
|
|
1575
|
+
"QmNuwo4PT4AikAmhMdZgPWCb2mJDwWa9TnUqrqvofjbrT8"
|
|
1571
1576
|
),
|
|
1572
1577
|
name: "Stale Spend Recovery Validator",
|
|
1573
1578
|
description: "Production Stale Spend Recovery Validator",
|
|
1574
1579
|
version: "1.1.2",
|
|
1575
1580
|
deployed: true,
|
|
1576
|
-
deployedAt:
|
|
1577
|
-
size:
|
|
1578
|
-
hash: "
|
|
1581
|
+
deployedAt: 1787924048772,
|
|
1582
|
+
size: 41424,
|
|
1583
|
+
hash: "3c5f028d2bef4344768462993616d45e30d9d44ef126e04d6eb579821d57d99c",
|
|
1579
1584
|
validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
|
|
1580
1585
|
pkp: {
|
|
1581
1586
|
publicKey: "0x046da0ad6da7dd4a0063cbeac6f2bdb6a9889c2178b23470833356a8ee5630f7f0eee0db348d9d9aaaadd23eccf0063c8f68ee5e446abe30b882bf1de4c932bc21",
|
|
@@ -1583,17 +1588,17 @@ var require_pkg_src = __commonJS({
|
|
|
1583
1588
|
}
|
|
1584
1589
|
},
|
|
1585
1590
|
btcUtxoInvalidator: {
|
|
1586
|
-
cid: "
|
|
1591
|
+
cid: "QmaNGeWut7EiGwW4zUc2sFSt7RY5NWFgxYboyG333TwrJf",
|
|
1587
1592
|
authorizedCidHex: cidToHex(
|
|
1588
|
-
"
|
|
1593
|
+
"QmaNGeWut7EiGwW4zUc2sFSt7RY5NWFgxYboyG333TwrJf"
|
|
1589
1594
|
),
|
|
1590
1595
|
name: "Btc Utxo Invalidator",
|
|
1591
1596
|
description: "Production Btc Utxo Invalidator",
|
|
1592
1597
|
version: "1.0.0",
|
|
1593
1598
|
deployed: true,
|
|
1594
|
-
deployedAt:
|
|
1595
|
-
size:
|
|
1596
|
-
hash: "
|
|
1599
|
+
deployedAt: 1787924133241,
|
|
1600
|
+
size: 66026,
|
|
1601
|
+
hash: "603bc50920d7f1dee77086f2c518d9e2922ab3858a419d3fbea8221ea3a6d9e9"
|
|
1597
1602
|
}
|
|
1598
1603
|
};
|
|
1599
1604
|
function getDeploymentsForNetwork(network) {
|
|
@@ -2354,6 +2359,101 @@ ${errorReport}`);
|
|
|
2354
2359
|
var SECONDS_PER_DAY = 86400;
|
|
2355
2360
|
var DAYS_PER_MONTH = 30;
|
|
2356
2361
|
var LIT_ACTION_ETH_RPC_TIMEOUT_MS = 8e3;
|
|
2362
|
+
var PINNED_CONTRACT_ADDRESSES = {
|
|
2363
|
+
1: {
|
|
2364
|
+
PositionManager: "0x12A1836e56139ccaD8722B89519d84233efc224B",
|
|
2365
|
+
LoanOperationsManagerModule: "0x2561974A40F1AEed1251d0A090A83cF8536FB9E9",
|
|
2366
|
+
BTCSpendAuthorizer: "0xfBbF108486fa07F1B06a811C5b66ed68DD9c508a",
|
|
2367
|
+
BitcoinProviderRegistry: "0x4ab3Fb96e02893Ed6FAa61bad1918390c8DbbFFC",
|
|
2368
|
+
LITActionValidator: "0xD2c5d59c2CC5c409AC65ce0A817236aeC6869512",
|
|
2369
|
+
PositionDelegateRegistry: "0xf0aa2678aD4F60f49e8F7725089B5E86B7F8FE4C"
|
|
2370
|
+
},
|
|
2371
|
+
11155111: {
|
|
2372
|
+
PositionManager: "0x68e0507D982AEBF1D1C1Af8FBbd842327e2deeFF",
|
|
2373
|
+
LoanOperationsManagerModule: "0x3e05e760a87715207b7F4e8fD35EF7559BcA72C0",
|
|
2374
|
+
BTCSpendAuthorizer: "0xd7E9Eb5eE53f1d9ee55Dc162bBC7486bE437B6bD",
|
|
2375
|
+
BitcoinProviderRegistry: "0xbfA0c48B070D0a9A9CD27469AeacFD2d4261cEE2",
|
|
2376
|
+
LITActionValidator: "0x54eECd7C90F8A8fac27749Ba30BbE8AFBAccc856",
|
|
2377
|
+
PositionDelegateRegistry: "0x482369De283622E7b05731875ec137d4E3D208F9"
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
function getPinnedContractAddresses(chainId) {
|
|
2381
|
+
return PINNED_CONTRACT_ADDRESSES[chainId] ?? null;
|
|
2382
|
+
}
|
|
2383
|
+
var PROTOCOL_EIP712_DOMAIN_NAME = "DiamondHands.Protocol";
|
|
2384
|
+
var PROTOCOL_EIP712_DOMAIN_VERSION = "1";
|
|
2385
|
+
var BORROWER_AUTHORIZATION_PRIMARY_TYPES = {
|
|
2386
|
+
MINT: "MintRequest",
|
|
2387
|
+
REPAY: "RepayRequest",
|
|
2388
|
+
RENEW: "RenewRequest",
|
|
2389
|
+
WITHDRAW: "WithdrawRequest"
|
|
2390
|
+
};
|
|
2391
|
+
var BORROWER_AUTHORIZATION_FIELDS = {
|
|
2392
|
+
MintRequest: [
|
|
2393
|
+
{ name: "positionId", type: "bytes32" },
|
|
2394
|
+
{ name: "mintAmount", type: "uint256" },
|
|
2395
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
2396
|
+
],
|
|
2397
|
+
RepayRequest: [
|
|
2398
|
+
{ name: "positionId", type: "bytes32" },
|
|
2399
|
+
{ name: "paymentAmount", type: "uint256" },
|
|
2400
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
2401
|
+
],
|
|
2402
|
+
RenewRequest: [
|
|
2403
|
+
{ name: "positionId", type: "bytes32" },
|
|
2404
|
+
{ name: "selectedTerm", type: "uint256" },
|
|
2405
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
2406
|
+
],
|
|
2407
|
+
WithdrawRequest: [
|
|
2408
|
+
{ name: "positionId", type: "bytes32" },
|
|
2409
|
+
{ name: "totalDeduction", type: "uint256" },
|
|
2410
|
+
{ name: "withdrawalAddress", type: "string" },
|
|
2411
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
2412
|
+
]
|
|
2413
|
+
};
|
|
2414
|
+
var BORROWER_AUTHORIZATION_ENCODE_TYPES = {
|
|
2415
|
+
MintRequest: "MintRequest(bytes32 positionId,uint256 mintAmount,uint256 quantumTimestamp)",
|
|
2416
|
+
RepayRequest: "RepayRequest(bytes32 positionId,uint256 paymentAmount,uint256 quantumTimestamp)",
|
|
2417
|
+
RenewRequest: "RenewRequest(bytes32 positionId,uint256 selectedTerm,uint256 quantumTimestamp)",
|
|
2418
|
+
WithdrawRequest: "WithdrawRequest(bytes32 positionId,uint256 totalDeduction,string withdrawalAddress,uint256 quantumTimestamp)"
|
|
2419
|
+
};
|
|
2420
|
+
function borrowerAuthorizationTypes(primaryType) {
|
|
2421
|
+
const fields = BORROWER_AUTHORIZATION_FIELDS[primaryType];
|
|
2422
|
+
if (!fields) {
|
|
2423
|
+
throw new Error(
|
|
2424
|
+
`Unknown borrower authorization primary type "${primaryType}"; expected one of ${Object.keys(BORROWER_AUTHORIZATION_FIELDS).join(", ")}`
|
|
2425
|
+
);
|
|
2426
|
+
}
|
|
2427
|
+
return { [primaryType]: fields.map((field) => ({ ...field })) };
|
|
2428
|
+
}
|
|
2429
|
+
function buildBorrowerAuthorizationDomain(chainId, verifyingContractOverride) {
|
|
2430
|
+
if (!Number.isInteger(chainId) || chainId <= 0) {
|
|
2431
|
+
throw new Error(
|
|
2432
|
+
`Borrower authorization domain requires a positive integer chainId, got ${String(chainId)}`
|
|
2433
|
+
);
|
|
2434
|
+
}
|
|
2435
|
+
const pinned = getPinnedContractAddresses(chainId);
|
|
2436
|
+
const pinnedLom = pinned?.LoanOperationsManagerModule;
|
|
2437
|
+
if (pinnedLom && verifyingContractOverride) {
|
|
2438
|
+
if (pinnedLom.toLowerCase() !== verifyingContractOverride.toLowerCase()) {
|
|
2439
|
+
throw new Error(
|
|
2440
|
+
`Refusing a caller-supplied verifyingContract that contradicts the pin for chainId ${chainId}: caller ${verifyingContractOverride}, pinned ${pinnedLom}`
|
|
2441
|
+
);
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
const verifyingContract = pinnedLom ?? verifyingContractOverride;
|
|
2445
|
+
if (!verifyingContract) {
|
|
2446
|
+
throw new Error(
|
|
2447
|
+
`No pinned LoanOperationsManagerModule for chainId ${chainId} and no verifyingContract supplied; refusing to build a borrower authorization domain without one`
|
|
2448
|
+
);
|
|
2449
|
+
}
|
|
2450
|
+
return {
|
|
2451
|
+
name: PROTOCOL_EIP712_DOMAIN_NAME,
|
|
2452
|
+
version: PROTOCOL_EIP712_DOMAIN_VERSION,
|
|
2453
|
+
chainId,
|
|
2454
|
+
verifyingContract
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2357
2457
|
var EVMChain = /* @__PURE__ */ ((EVMChain3) => {
|
|
2358
2458
|
EVMChain3["SEPOLIA"] = "sepolia";
|
|
2359
2459
|
EVMChain3["ETHEREUM"] = "ethereum";
|
|
@@ -6247,7 +6347,7 @@ function validateSDKConfig(config) {
|
|
|
6247
6347
|
}
|
|
6248
6348
|
|
|
6249
6349
|
// src/utils/mint-authorization.utils.ts
|
|
6250
|
-
var
|
|
6350
|
+
var import_ethers3 = require("ethers");
|
|
6251
6351
|
|
|
6252
6352
|
// src/utils/quantum-timing.ts
|
|
6253
6353
|
var QUANTUM_WINDOW_SECONDS = 60;
|
|
@@ -6354,6 +6454,80 @@ async function awaitSafeSubmissionWindowOnChain(signatureQuantum, chainNow, slee
|
|
|
6354
6454
|
return { waited: waitedSeconds > 0, waitedSeconds };
|
|
6355
6455
|
}
|
|
6356
6456
|
|
|
6457
|
+
// src/utils/borrower-authorization-712.ts
|
|
6458
|
+
var import_ethers2 = require("ethers");
|
|
6459
|
+
init_deployment_addresses();
|
|
6460
|
+
var BORROWER_AUTHORIZATION_712_DOMAIN_NAME = "DiamondHands.Protocol";
|
|
6461
|
+
var BORROWER_AUTHORIZATION_712_DOMAIN_VERSION = "1";
|
|
6462
|
+
var BORROWER_AUTHORIZATION_712_FIELDS = {
|
|
6463
|
+
MintRequest: [
|
|
6464
|
+
{ name: "positionId", type: "bytes32" },
|
|
6465
|
+
{ name: "mintAmount", type: "uint256" },
|
|
6466
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
6467
|
+
],
|
|
6468
|
+
RepayRequest: [
|
|
6469
|
+
{ name: "positionId", type: "bytes32" },
|
|
6470
|
+
{ name: "paymentAmount", type: "uint256" },
|
|
6471
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
6472
|
+
],
|
|
6473
|
+
RenewRequest: [
|
|
6474
|
+
{ name: "positionId", type: "bytes32" },
|
|
6475
|
+
{ name: "selectedTerm", type: "uint256" },
|
|
6476
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
6477
|
+
],
|
|
6478
|
+
WithdrawRequest: [
|
|
6479
|
+
{ name: "positionId", type: "bytes32" },
|
|
6480
|
+
{ name: "totalDeduction", type: "uint256" },
|
|
6481
|
+
{ name: "withdrawalAddress", type: "string" },
|
|
6482
|
+
{ name: "quantumTimestamp", type: "uint256" }
|
|
6483
|
+
]
|
|
6484
|
+
};
|
|
6485
|
+
function borrowerAuthorization712Types(primaryType) {
|
|
6486
|
+
const fields = BORROWER_AUTHORIZATION_712_FIELDS[primaryType];
|
|
6487
|
+
if (!fields) {
|
|
6488
|
+
throw new Error(
|
|
6489
|
+
`Unknown borrower authorization primary type "${primaryType}"; expected one of ` + Object.keys(BORROWER_AUTHORIZATION_712_FIELDS).join(", ")
|
|
6490
|
+
);
|
|
6491
|
+
}
|
|
6492
|
+
return { [primaryType]: fields.map((field) => ({ ...field })) };
|
|
6493
|
+
}
|
|
6494
|
+
function buildBorrowerAuthorization712Domain(chainId) {
|
|
6495
|
+
if (!Number.isInteger(chainId) || chainId <= 0) {
|
|
6496
|
+
throw new Error(
|
|
6497
|
+
`Borrower authorization domain requires a positive integer chainId, got ${String(chainId)}`
|
|
6498
|
+
);
|
|
6499
|
+
}
|
|
6500
|
+
const deployment = Object.values(ALL_DEPLOYMENTS).find(
|
|
6501
|
+
(d) => d.chainId === chainId
|
|
6502
|
+
);
|
|
6503
|
+
const verifyingContract = deployment?.contracts?.LoanOperationsManagerModule;
|
|
6504
|
+
if (!verifyingContract) {
|
|
6505
|
+
throw new Error(
|
|
6506
|
+
`No LoanOperationsManagerModule deployment known for chainId ${chainId}; refusing to build a borrower authorization domain without one`
|
|
6507
|
+
);
|
|
6508
|
+
}
|
|
6509
|
+
return {
|
|
6510
|
+
name: BORROWER_AUTHORIZATION_712_DOMAIN_NAME,
|
|
6511
|
+
version: BORROWER_AUTHORIZATION_712_DOMAIN_VERSION,
|
|
6512
|
+
chainId,
|
|
6513
|
+
verifyingContract
|
|
6514
|
+
};
|
|
6515
|
+
}
|
|
6516
|
+
async function signBorrowerAuthorization712(signer, primaryType, chainId, message) {
|
|
6517
|
+
const signTypedData = signer.signTypedData;
|
|
6518
|
+
if (typeof signTypedData !== "function") {
|
|
6519
|
+
throw new Error(
|
|
6520
|
+
`Signer has no signTypedData \u2014 cannot produce an EIP-712 ${primaryType}. Wallets without typed-data support must supply the signature via an authorizationProvider instead of a connected signer.`
|
|
6521
|
+
);
|
|
6522
|
+
}
|
|
6523
|
+
return signTypedData.call(
|
|
6524
|
+
signer,
|
|
6525
|
+
buildBorrowerAuthorization712Domain(chainId),
|
|
6526
|
+
borrowerAuthorization712Types(primaryType),
|
|
6527
|
+
message
|
|
6528
|
+
);
|
|
6529
|
+
}
|
|
6530
|
+
|
|
6357
6531
|
// src/utils/mint-authorization.utils.ts
|
|
6358
6532
|
var PKP_NFT_ABI = [
|
|
6359
6533
|
"function getPubkey(uint256 tokenId) external view returns (bytes memory)"
|
|
@@ -6367,29 +6541,11 @@ async function generateMintAuthorization(positionId, amount, chainId, signerOrPr
|
|
|
6367
6541
|
const signer = signerOrPrecomputed;
|
|
6368
6542
|
const timestamp = calculateNextQuantumTimestamp();
|
|
6369
6543
|
const action = "mint-ucd";
|
|
6370
|
-
const
|
|
6371
|
-
const types = [
|
|
6372
|
-
"bytes32",
|
|
6373
|
-
// positionId
|
|
6374
|
-
"uint256",
|
|
6375
|
-
// timestamp
|
|
6376
|
-
"uint256",
|
|
6377
|
-
// chainId
|
|
6378
|
-
"uint256",
|
|
6379
|
-
// amount
|
|
6380
|
-
"bytes32"
|
|
6381
|
-
// actionHash
|
|
6382
|
-
];
|
|
6383
|
-
const values = [
|
|
6544
|
+
const signature = await signBorrowerAuthorization712(signer, "MintRequest", chainId, {
|
|
6384
6545
|
positionId,
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
actionHash
|
|
6389
|
-
];
|
|
6390
|
-
const messageHash = (0, import_ethers2.solidityPackedKeccak256)(types, values);
|
|
6391
|
-
const messageHashBytes = (0, import_ethers2.getBytes)(messageHash);
|
|
6392
|
-
const signature = await signer.signMessage(messageHashBytes);
|
|
6546
|
+
mintAmount: amount.toString(),
|
|
6547
|
+
quantumTimestamp: timestamp
|
|
6548
|
+
});
|
|
6393
6549
|
return {
|
|
6394
6550
|
positionId,
|
|
6395
6551
|
timestamp,
|
|
@@ -6426,44 +6582,17 @@ async function generatePaymentAuthorization(positionId, amount, chainId, signerO
|
|
|
6426
6582
|
throw new Error(`timestamp must be a number, got ${typeof timestamp}`);
|
|
6427
6583
|
}
|
|
6428
6584
|
const action = "make-payment";
|
|
6429
|
-
const actionHash = (0, import_ethers2.keccak256)((0, import_ethers2.toUtf8Bytes)(action));
|
|
6430
|
-
if (typeof actionHash !== "string") {
|
|
6431
|
-
throw new Error(`actionHash must be a string, got ${typeof actionHash}`);
|
|
6432
|
-
}
|
|
6433
|
-
const types = [
|
|
6434
|
-
"bytes32",
|
|
6435
|
-
// positionId
|
|
6436
|
-
"uint256",
|
|
6437
|
-
// timestamp
|
|
6438
|
-
"uint256",
|
|
6439
|
-
// chainId
|
|
6440
|
-
"uint256",
|
|
6441
|
-
// amount
|
|
6442
|
-
"bytes32"
|
|
6443
|
-
// actionHash
|
|
6444
|
-
];
|
|
6445
6585
|
const amountStr = amount.toString();
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
}
|
|
6451
|
-
const values = [positionId, timestamp, chainId, amountStr, actionHash];
|
|
6452
|
-
for (let i = 0; i < values.length; i++) {
|
|
6453
|
-
if (typeof values[i] === "object" && values[i] !== null) {
|
|
6454
|
-
throw new Error(
|
|
6455
|
-
`Value at index ${i} is an object: ${JSON.stringify(values[i])}`
|
|
6456
|
-
);
|
|
6457
|
-
}
|
|
6458
|
-
}
|
|
6459
|
-
const messageHash = (0, import_ethers2.solidityPackedKeccak256)(types, values);
|
|
6460
|
-
const messageHashBytes = (0, import_ethers2.getBytes)(messageHash);
|
|
6461
|
-
const signature = await signer.signMessage(messageHashBytes);
|
|
6586
|
+
const signature = await signBorrowerAuthorization712(signer, "RepayRequest", chainId, {
|
|
6587
|
+
positionId,
|
|
6588
|
+
paymentAmount: amountStr,
|
|
6589
|
+
quantumTimestamp: timestamp
|
|
6590
|
+
});
|
|
6462
6591
|
return {
|
|
6463
6592
|
positionId,
|
|
6464
6593
|
timestamp,
|
|
6465
6594
|
chainId,
|
|
6466
|
-
amount:
|
|
6595
|
+
amount: amountStr,
|
|
6467
6596
|
action,
|
|
6468
6597
|
signature
|
|
6469
6598
|
};
|
|
@@ -6532,7 +6661,7 @@ async function getPKPPublicKeyFromTokenId(pkpTokenId, provider, pkpNftContractAd
|
|
|
6532
6661
|
`pkpNftContractAddress is required for getPKPPublicKeyFromTokenId`
|
|
6533
6662
|
);
|
|
6534
6663
|
}
|
|
6535
|
-
const pkpNft = new
|
|
6664
|
+
const pkpNft = new import_ethers3.Contract(
|
|
6536
6665
|
pkpNftContractAddress,
|
|
6537
6666
|
PKP_NFT_ABI,
|
|
6538
6667
|
provider
|
|
@@ -6550,32 +6679,12 @@ async function generateWithdrawAuthorization(positionId, amount, chainId, signer
|
|
|
6550
6679
|
const signer = signerOrPrecomputed;
|
|
6551
6680
|
const timestamp = calculateNextQuantumTimestamp();
|
|
6552
6681
|
const action = "withdraw-btc";
|
|
6553
|
-
const
|
|
6554
|
-
const types = [
|
|
6555
|
-
"bytes32",
|
|
6556
|
-
// positionId
|
|
6557
|
-
"uint256",
|
|
6558
|
-
// timestamp
|
|
6559
|
-
"uint256",
|
|
6560
|
-
// chainId
|
|
6561
|
-
"uint256",
|
|
6562
|
-
// amount (in satoshis)
|
|
6563
|
-
"string",
|
|
6564
|
-
// destinationAddress (Bitcoin address)
|
|
6565
|
-
"bytes32"
|
|
6566
|
-
// actionHash
|
|
6567
|
-
];
|
|
6568
|
-
const values = [
|
|
6682
|
+
const signature = await signBorrowerAuthorization712(signer, "WithdrawRequest", chainId, {
|
|
6569
6683
|
positionId,
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
actionHash
|
|
6575
|
-
];
|
|
6576
|
-
const messageHash = (0, import_ethers2.solidityPackedKeccak256)(types, values);
|
|
6577
|
-
const messageHashBytes = (0, import_ethers2.getBytes)(messageHash);
|
|
6578
|
-
const signature = await signer.signMessage(messageHashBytes);
|
|
6684
|
+
totalDeduction: amount.toString(),
|
|
6685
|
+
withdrawalAddress: destinationAddress,
|
|
6686
|
+
quantumTimestamp: timestamp
|
|
6687
|
+
});
|
|
6579
6688
|
return {
|
|
6580
6689
|
positionId,
|
|
6581
6690
|
timestamp,
|
|
@@ -6589,7 +6698,7 @@ async function generateBalanceConfirmationAuthorization(positionId, chainId, sig
|
|
|
6589
6698
|
const timestamp = calculateNextQuantumTimestamp();
|
|
6590
6699
|
const caller = await signer.getAddress();
|
|
6591
6700
|
const action = "confirm-balance";
|
|
6592
|
-
const actionHash = (0,
|
|
6701
|
+
const actionHash = (0, import_ethers3.keccak256)((0, import_ethers3.toUtf8Bytes)(action));
|
|
6593
6702
|
const types = [
|
|
6594
6703
|
"bytes32",
|
|
6595
6704
|
// positionId
|
|
@@ -6603,8 +6712,8 @@ async function generateBalanceConfirmationAuthorization(positionId, chainId, sig
|
|
|
6603
6712
|
// actionHash
|
|
6604
6713
|
];
|
|
6605
6714
|
const values = [positionId, timestamp, chainId, caller, actionHash];
|
|
6606
|
-
const messageHash = (0,
|
|
6607
|
-
const messageHashBytes = (0,
|
|
6715
|
+
const messageHash = (0, import_ethers3.solidityPackedKeccak256)(types, values);
|
|
6716
|
+
const messageHashBytes = (0, import_ethers3.getBytes)(messageHash);
|
|
6608
6717
|
const signature = await signer.signMessage(messageHashBytes);
|
|
6609
6718
|
return {
|
|
6610
6719
|
positionId,
|
|
@@ -6617,7 +6726,6 @@ async function generateBalanceConfirmationAuthorization(positionId, chainId, sig
|
|
|
6617
6726
|
}
|
|
6618
6727
|
|
|
6619
6728
|
// src/utils/extend-authorization.utils.ts
|
|
6620
|
-
var import_ethers3 = require("ethers");
|
|
6621
6729
|
async function generateExtendAuthorization(positionId, newTerm, chainId, signerOrPrecomputed) {
|
|
6622
6730
|
if (typeof signerOrPrecomputed === "object" && "signature" in signerOrPrecomputed && !("signMessage" in signerOrPrecomputed)) {
|
|
6623
6731
|
const { timestamp: timestamp2, signature: signature2 } = signerOrPrecomputed;
|
|
@@ -6627,29 +6735,11 @@ async function generateExtendAuthorization(positionId, newTerm, chainId, signerO
|
|
|
6627
6735
|
const signer = signerOrPrecomputed;
|
|
6628
6736
|
const timestamp = calculateNextQuantumTimestamp();
|
|
6629
6737
|
const action = "extend-position";
|
|
6630
|
-
const
|
|
6631
|
-
const types = [
|
|
6632
|
-
"bytes32",
|
|
6633
|
-
// positionId
|
|
6634
|
-
"uint256",
|
|
6635
|
-
// timestamp
|
|
6636
|
-
"uint256",
|
|
6637
|
-
// chainId
|
|
6638
|
-
"uint256",
|
|
6639
|
-
// newTerm (extension term in months)
|
|
6640
|
-
"bytes32"
|
|
6641
|
-
// actionHash
|
|
6642
|
-
];
|
|
6643
|
-
const values = [
|
|
6738
|
+
const signature = await signBorrowerAuthorization712(signer, "RenewRequest", chainId, {
|
|
6644
6739
|
positionId,
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
actionHash
|
|
6649
|
-
];
|
|
6650
|
-
const messageHash = (0, import_ethers3.solidityPackedKeccak256)(types, values);
|
|
6651
|
-
const messageHashBytes = (0, import_ethers3.getBytes)(messageHash);
|
|
6652
|
-
const signature = await signer.signMessage(messageHashBytes);
|
|
6740
|
+
selectedTerm: newTerm,
|
|
6741
|
+
quantumTimestamp: timestamp
|
|
6742
|
+
});
|
|
6653
6743
|
return {
|
|
6654
6744
|
positionId,
|
|
6655
6745
|
timestamp,
|
|
@@ -10264,6 +10354,10 @@ function normalizePkpId(pkpId) {
|
|
|
10264
10354
|
}
|
|
10265
10355
|
return pkpId;
|
|
10266
10356
|
}
|
|
10357
|
+
function isNormalizedChipotlePkpId(pkpId) {
|
|
10358
|
+
const rawId = pkpId.startsWith("0x") ? pkpId.slice(2) : pkpId;
|
|
10359
|
+
return rawId.length === 40;
|
|
10360
|
+
}
|
|
10267
10361
|
function padPkpIdForSubgraph(pkpId) {
|
|
10268
10362
|
const raw = pkpId.startsWith("0x") ? pkpId.slice(2) : pkpId;
|
|
10269
10363
|
if (raw.length === 40) {
|
|
@@ -10548,7 +10642,7 @@ var LoanQuery = class {
|
|
|
10548
10642
|
batch.map(async (loan) => {
|
|
10549
10643
|
try {
|
|
10550
10644
|
const rawId = loan.pkpId?.startsWith("0x") ? loan.pkpId.slice(2) : loan.pkpId;
|
|
10551
|
-
const isChipotlePkpId2 = typeof rawId === "string" && rawId
|
|
10645
|
+
const isChipotlePkpId2 = typeof rawId === "string" && isNormalizedChipotlePkpId(rawId);
|
|
10552
10646
|
if (isChipotlePkpId2) {
|
|
10553
10647
|
if (this.config.positionManagerCoreAddress && this.config.provider) {
|
|
10554
10648
|
const pmContract = new import_ethers12.Contract(
|
|
@@ -10875,6 +10969,7 @@ function createLoanQuery(config) {
|
|
|
10875
10969
|
|
|
10876
10970
|
// src/modules/withdrawal-address/withdrawal-address.module.ts
|
|
10877
10971
|
var import_ethers13 = require("ethers");
|
|
10972
|
+
var STATIC_CALL_DIAGNOSTIC_TIMEOUT_MS = 5e3;
|
|
10878
10973
|
var WithdrawalAddressModule = class {
|
|
10879
10974
|
config;
|
|
10880
10975
|
graphClient;
|
|
@@ -10919,13 +11014,17 @@ var WithdrawalAddressModule = class {
|
|
|
10919
11014
|
const reg = this.getRegistry();
|
|
10920
11015
|
if (!reg.success)
|
|
10921
11016
|
return reg;
|
|
11017
|
+
const normalized = normalizeBitcoinAddress(btcAddress);
|
|
10922
11018
|
try {
|
|
10923
|
-
const tx = await reg.value.addAddress(
|
|
10924
|
-
normalizeBitcoinAddress(btcAddress)
|
|
10925
|
-
);
|
|
11019
|
+
const tx = await reg.value.addAddress(normalized);
|
|
10926
11020
|
return success(tx);
|
|
10927
11021
|
} catch (error) {
|
|
10928
|
-
return this.txFailure(
|
|
11022
|
+
return this.txFailure(
|
|
11023
|
+
"addAddress",
|
|
11024
|
+
error,
|
|
11025
|
+
btcAddress,
|
|
11026
|
+
await this.staticCallDiagnostic(reg.value, "addAddress", normalized)
|
|
11027
|
+
);
|
|
10929
11028
|
}
|
|
10930
11029
|
}
|
|
10931
11030
|
/** Remove a Bitcoin address from the caller's allowlist (effective immediately). */
|
|
@@ -10933,13 +11032,17 @@ var WithdrawalAddressModule = class {
|
|
|
10933
11032
|
const reg = this.getRegistry();
|
|
10934
11033
|
if (!reg.success)
|
|
10935
11034
|
return reg;
|
|
11035
|
+
const normalized = normalizeBitcoinAddress(btcAddress);
|
|
10936
11036
|
try {
|
|
10937
|
-
const tx = await reg.value.removeAddress(
|
|
10938
|
-
normalizeBitcoinAddress(btcAddress)
|
|
10939
|
-
);
|
|
11037
|
+
const tx = await reg.value.removeAddress(normalized);
|
|
10940
11038
|
return success(tx);
|
|
10941
11039
|
} catch (error) {
|
|
10942
|
-
return this.txFailure(
|
|
11040
|
+
return this.txFailure(
|
|
11041
|
+
"removeAddress",
|
|
11042
|
+
error,
|
|
11043
|
+
btcAddress,
|
|
11044
|
+
await this.staticCallDiagnostic(reg.value, "removeAddress", normalized)
|
|
11045
|
+
);
|
|
10943
11046
|
}
|
|
10944
11047
|
}
|
|
10945
11048
|
/**
|
|
@@ -11035,16 +11138,59 @@ var WithdrawalAddressModule = class {
|
|
|
11035
11138
|
}
|
|
11036
11139
|
return success(void 0);
|
|
11037
11140
|
}
|
|
11038
|
-
|
|
11141
|
+
/**
|
|
11142
|
+
* Ask the node for the reason a failed write did not carry.
|
|
11143
|
+
*
|
|
11144
|
+
* A failing `eth_estimateGas` frequently answers with NOTHING to decode — ethers renders that
|
|
11145
|
+
* as `missing revert data ... data=null, reason=null, revert=null`, which names no cause and
|
|
11146
|
+
* cannot distinguish "the contract rejected this" from "the RPC hiccuped". An `eth_call` of the
|
|
11147
|
+
* same calldata usually does carry the revert reason or custom-error selector, so this runs one
|
|
11148
|
+
* and folds the answer into the reported error.
|
|
11149
|
+
*
|
|
11150
|
+
* Three deliberate properties:
|
|
11151
|
+
*
|
|
11152
|
+
* 1. It runs ONLY after the write has already failed. Gating the write on a static call would
|
|
11153
|
+
* let a flaky endpoint — precisely the condition this exists to diagnose — block an add that
|
|
11154
|
+
* would otherwise have succeeded.
|
|
11155
|
+
* 2. It costs NO extra signature. `staticCall` is `eth_call`: a node read, never a wallet prompt.
|
|
11156
|
+
* 3. It can never throw. A diagnostic that escapes would replace the real cause with itself.
|
|
11157
|
+
* (The `try/catch` here is the authorized exception to CLAUDE.md's forbidden-patterns rule;
|
|
11158
|
+
* it swallows nothing — every branch returns text that is reported alongside the original.)
|
|
11159
|
+
*
|
|
11160
|
+
* A static call that SUCCEEDS is itself a finding: the contract accepts this call, so the
|
|
11161
|
+
* failure lay outside contract logic (RPC, gas, or nonce).
|
|
11162
|
+
*/
|
|
11163
|
+
async staticCallDiagnostic(registry, op, normalizedAddress) {
|
|
11164
|
+
try {
|
|
11165
|
+
await Promise.race([
|
|
11166
|
+
registry[op].staticCall(normalizedAddress),
|
|
11167
|
+
// The failure being diagnosed is often an unresponsive endpoint, so the diagnostic must
|
|
11168
|
+
// not inherit that hang — the user is waiting on this error message.
|
|
11169
|
+
new Promise(
|
|
11170
|
+
(_, reject) => setTimeout(
|
|
11171
|
+
() => reject(new Error("static call timed out after 5s")),
|
|
11172
|
+
STATIC_CALL_DIAGNOSTIC_TIMEOUT_MS
|
|
11173
|
+
)
|
|
11174
|
+
)
|
|
11175
|
+
]);
|
|
11176
|
+
return "static call SUCCEEDED \u2014 the contract accepts this call, so the failure was not contract logic (RPC, gas, or nonce)";
|
|
11177
|
+
} catch (diagnostic) {
|
|
11178
|
+
const code = typeof diagnostic === "object" && diagnostic !== null ? diagnostic.code : void 0;
|
|
11179
|
+
const msg = diagnostic instanceof Error ? diagnostic.message : String(diagnostic);
|
|
11180
|
+
return typeof code === "string" ? `static call reverted [${code}]: ${msg}` : `static call failed: ${msg}`;
|
|
11181
|
+
}
|
|
11182
|
+
}
|
|
11183
|
+
txFailure(op, error, context, diagnostic) {
|
|
11039
11184
|
const msg = error instanceof Error ? error.message : String(error);
|
|
11185
|
+
const detail = diagnostic ? `${msg} \u2014 ${diagnostic}` : msg;
|
|
11040
11186
|
return failure(
|
|
11041
11187
|
new SDKError({
|
|
11042
11188
|
code: `SDK_WITHDRAWAL_REGISTRY_${op.toUpperCase()}_FAILED`,
|
|
11043
|
-
message: `WithdrawalAddressRegistry.${op} failed: ${
|
|
11189
|
+
message: `WithdrawalAddressRegistry.${op} failed: ${detail}`,
|
|
11044
11190
|
category: "CONTRACT" /* CONTRACT */,
|
|
11045
11191
|
severity: "MEDIUM" /* MEDIUM */,
|
|
11046
11192
|
originalError: error instanceof Error ? error : new Error(String(error)),
|
|
11047
|
-
context: { op, context }
|
|
11193
|
+
context: { op, context, diagnostic }
|
|
11048
11194
|
})
|
|
11049
11195
|
);
|
|
11050
11196
|
}
|
|
@@ -12135,6 +12281,47 @@ function normalizePkpId2(pkpId) {
|
|
|
12135
12281
|
}
|
|
12136
12282
|
return pkpId;
|
|
12137
12283
|
}
|
|
12284
|
+
function applyLoanEventsFilter(events, opts) {
|
|
12285
|
+
const { wantsEvent, fromTimestamp, toTimestamp, fromBlock, toBlock, limit } = opts;
|
|
12286
|
+
const inBounds = (e) => {
|
|
12287
|
+
const ts = e?.timestamp;
|
|
12288
|
+
const bn = e?.blockNumber;
|
|
12289
|
+
try {
|
|
12290
|
+
if (fromTimestamp !== void 0 && ts !== void 0 && BigInt(ts) < BigInt(fromTimestamp))
|
|
12291
|
+
return false;
|
|
12292
|
+
if (toTimestamp !== void 0 && ts !== void 0 && BigInt(ts) > BigInt(toTimestamp))
|
|
12293
|
+
return false;
|
|
12294
|
+
if (fromBlock !== void 0 && bn !== void 0 && BigInt(bn) < BigInt(fromBlock))
|
|
12295
|
+
return false;
|
|
12296
|
+
if (toBlock !== void 0 && bn !== void 0 && BigInt(bn) > BigInt(toBlock))
|
|
12297
|
+
return false;
|
|
12298
|
+
} catch {
|
|
12299
|
+
return true;
|
|
12300
|
+
}
|
|
12301
|
+
return true;
|
|
12302
|
+
};
|
|
12303
|
+
const narrow = (list, kind) => wantsEvent(kind) ? (list ?? []).filter(inBounds).slice(0, limit) : [];
|
|
12304
|
+
const single = (value, kind) => value && wantsEvent(kind) && inBounds(value) ? value : void 0;
|
|
12305
|
+
const filtered = {
|
|
12306
|
+
...events,
|
|
12307
|
+
positionCreated: single(events.positionCreated, "positionCreated"),
|
|
12308
|
+
payments: narrow(events.payments, "payment"),
|
|
12309
|
+
statusUpdates: narrow(events.statusUpdates, "status"),
|
|
12310
|
+
liquidation: single(events.liquidation, "liquidation"),
|
|
12311
|
+
mints: narrow(events.mints, "mint"),
|
|
12312
|
+
withdrawals: narrow(events.withdrawals, "withdrawal"),
|
|
12313
|
+
renewals: narrow(events.renewals, "renewal"),
|
|
12314
|
+
operationFailures: narrow(events.operationFailures, "operationFailure"),
|
|
12315
|
+
mintRequests: narrow(events.mintRequests, "mintRequest"),
|
|
12316
|
+
burnRequests: narrow(events.burnRequests, "burnRequest"),
|
|
12317
|
+
collateralEvents: narrow(events.collateralEvents, "collateralEvent"),
|
|
12318
|
+
mintingFees: narrow(events.mintingFees, "mintingFee"),
|
|
12319
|
+
renewalFees: narrow(events.renewalFees, "renewalFee"),
|
|
12320
|
+
totalEvents: 0
|
|
12321
|
+
};
|
|
12322
|
+
filtered.totalEvents = (filtered.positionCreated ? 1 : 0) + (filtered.liquidation ? 1 : 0) + filtered.payments.length + filtered.statusUpdates.length + filtered.mints.length + filtered.withdrawals.length + filtered.renewals.length + filtered.operationFailures.length + filtered.mintRequests.length + filtered.burnRequests.length + filtered.collateralEvents.length + filtered.mintingFees.length + filtered.renewalFees.length;
|
|
12323
|
+
return filtered;
|
|
12324
|
+
}
|
|
12138
12325
|
function hasLoanEventsFilter(filter) {
|
|
12139
12326
|
if (!filter)
|
|
12140
12327
|
return false;
|
|
@@ -13291,32 +13478,24 @@ var DiamondHandsGraph = class {
|
|
|
13291
13478
|
limit = 1e3,
|
|
13292
13479
|
orderDirection = "desc"
|
|
13293
13480
|
} = filter || {};
|
|
13481
|
+
const wantsEvent = (kind) => !eventTypes || eventTypes.includes(kind);
|
|
13482
|
+
const hasBounds = fromTimestamp !== void 0 || toTimestamp !== void 0 || fromBlock !== void 0 || toBlock !== void 0;
|
|
13483
|
+
const pageSize = hasBounds ? THE_GRAPH_MAX_BATCH_SIZE : limit;
|
|
13484
|
+
const buildPositionWhereClause = () => `where: { position: "${positionId.toLowerCase()}" }`;
|
|
13294
13485
|
const shouldQuery = {
|
|
13295
|
-
positionCreated:
|
|
13296
|
-
payment:
|
|
13297
|
-
status:
|
|
13298
|
-
liquidation:
|
|
13299
|
-
mint:
|
|
13300
|
-
withdrawal:
|
|
13301
|
-
renewal:
|
|
13302
|
-
operationFailure:
|
|
13303
|
-
mintRequest:
|
|
13304
|
-
burnRequest:
|
|
13305
|
-
collateralEvent:
|
|
13306
|
-
mintingFee:
|
|
13307
|
-
renewalFee:
|
|
13308
|
-
};
|
|
13309
|
-
const buildPositionWhereClause = () => {
|
|
13310
|
-
const conditions = [`position: "${positionId.toLowerCase()}"`];
|
|
13311
|
-
if (fromTimestamp)
|
|
13312
|
-
conditions.push(`timestamp_gte: "${fromTimestamp}"`);
|
|
13313
|
-
if (toTimestamp)
|
|
13314
|
-
conditions.push(`timestamp_lte: "${toTimestamp}"`);
|
|
13315
|
-
if (fromBlock)
|
|
13316
|
-
conditions.push(`blockNumber_gte: "${fromBlock}"`);
|
|
13317
|
-
if (toBlock)
|
|
13318
|
-
conditions.push(`blockNumber_lte: "${toBlock}"`);
|
|
13319
|
-
return `where: { ${conditions.join(", ")} }`;
|
|
13486
|
+
positionCreated: true,
|
|
13487
|
+
payment: true,
|
|
13488
|
+
status: true,
|
|
13489
|
+
liquidation: true,
|
|
13490
|
+
mint: true,
|
|
13491
|
+
withdrawal: true,
|
|
13492
|
+
renewal: true,
|
|
13493
|
+
operationFailure: true,
|
|
13494
|
+
mintRequest: true,
|
|
13495
|
+
burnRequest: true,
|
|
13496
|
+
collateralEvent: true,
|
|
13497
|
+
mintingFee: true,
|
|
13498
|
+
renewalFee: true
|
|
13320
13499
|
};
|
|
13321
13500
|
const query = `
|
|
13322
13501
|
query GetLoanEvents($positionId: Bytes!, $limit: Int!, $orderDirection: OrderDirection!) {
|
|
@@ -13552,11 +13731,41 @@ var DiamondHandsGraph = class {
|
|
|
13552
13731
|
`;
|
|
13553
13732
|
const variables = {
|
|
13554
13733
|
positionId: positionId.toLowerCase(),
|
|
13555
|
-
limit,
|
|
13734
|
+
limit: pageSize,
|
|
13556
13735
|
orderDirection
|
|
13557
13736
|
};
|
|
13558
13737
|
const result = await this.client.execute(query, variables);
|
|
13559
|
-
|
|
13738
|
+
if (hasBounds) {
|
|
13739
|
+
const collections = [
|
|
13740
|
+
["payments", result.position?.payments],
|
|
13741
|
+
["statusUpdates", result.position?.statusUpdates],
|
|
13742
|
+
["withdrawals", result.position?.withdrawals],
|
|
13743
|
+
["renewals", result.position?.renewals],
|
|
13744
|
+
["operationFailures", result.position?.operationFailures],
|
|
13745
|
+
["mintRequests", result.position?.mintRequests],
|
|
13746
|
+
["burnRequests", result.position?.burnRequests],
|
|
13747
|
+
["mintingFees", result.position?.mintingFees],
|
|
13748
|
+
["renewalFees", result.position?.renewalFees],
|
|
13749
|
+
["mints", result.ucdmintEvents],
|
|
13750
|
+
["collateralEvents", result.collateralEvents]
|
|
13751
|
+
];
|
|
13752
|
+
const saturated = collections.filter(([, list]) => (list?.length ?? 0) >= pageSize).map(([name]) => name);
|
|
13753
|
+
if (saturated.length > 0) {
|
|
13754
|
+
log.warn(
|
|
13755
|
+
"[DiamondHandsGraph] bounded getLoanEvents page saturated \u2014 the filtered history may be incomplete",
|
|
13756
|
+
{ positionId, pageSize, saturated }
|
|
13757
|
+
);
|
|
13758
|
+
}
|
|
13759
|
+
}
|
|
13760
|
+
const assembled = this.assembleLoanEvents(positionId, result);
|
|
13761
|
+
return applyLoanEventsFilter(assembled, {
|
|
13762
|
+
wantsEvent,
|
|
13763
|
+
fromTimestamp,
|
|
13764
|
+
toTimestamp,
|
|
13765
|
+
fromBlock,
|
|
13766
|
+
toBlock,
|
|
13767
|
+
limit
|
|
13768
|
+
});
|
|
13560
13769
|
}
|
|
13561
13770
|
/**
|
|
13562
13771
|
* Map one position's raw event payload into `LoanEvents`.
|