@gvnrdao/dh-sdk 0.0.130 → 0.0.131
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 +3 -3
- package/dist/index.d.mts +39 -4
- package/dist/index.d.ts +39 -4
- package/dist/index.js +415 -131
- package/dist/index.mjs +414 -130
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12754,48 +12754,48 @@ var init_deployment_addresses = __esm({
|
|
|
12754
12754
|
LOCALHOST_DEPLOYMENT = {
|
|
12755
12755
|
"network": "localhost",
|
|
12756
12756
|
"chainId": 31337,
|
|
12757
|
-
"timestamp": "2025-12-
|
|
12757
|
+
"timestamp": "2025-12-11T16:44:37.280Z",
|
|
12758
12758
|
"deployer": "",
|
|
12759
12759
|
"contracts": {
|
|
12760
|
-
"UpgradeValidator": "
|
|
12760
|
+
"UpgradeValidator": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
|
|
12761
12761
|
"UCDToken": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
12762
12762
|
"UCDController": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
12763
|
-
"PriceFeedConsumer": "
|
|
12764
|
-
"BTCProofValidator": "
|
|
12765
|
-
"UCDMintingRewards": "
|
|
12766
|
-
"PositionManagerCoreModule": "
|
|
12767
|
-
"TermManagerModule": "
|
|
12768
|
-
"LoanOperationsManagerModule": "
|
|
12769
|
-
"CollateralManagerModule": "
|
|
12770
|
-
"LiquidationManagerModule": "
|
|
12771
|
-
"CircuitBreakerModule": "
|
|
12772
|
-
"CommunityManagerModule": "
|
|
12773
|
-
"AdminModule": "
|
|
12774
|
-
"PositionManagerViews": "
|
|
12775
|
-
"PositionManager": "
|
|
12776
|
-
"OperationAuthorizationRegistry": "
|
|
12777
|
-
"PKPValidation": "
|
|
12763
|
+
"PriceFeedConsumer": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
|
|
12764
|
+
"BTCProofValidator": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
|
|
12765
|
+
"UCDMintingRewards": "0x9A676e781A523b5d0C0e43731313A708CB607508",
|
|
12766
|
+
"PositionManagerCoreModule": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
12767
|
+
"TermManagerModule": "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
12768
|
+
"LoanOperationsManagerModule": "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
|
|
12769
|
+
"CollateralManagerModule": "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
|
|
12770
|
+
"LiquidationManagerModule": "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
|
|
12771
|
+
"CircuitBreakerModule": "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
12772
|
+
"CommunityManagerModule": "0xc5a5C42992dECbae36851359345FE25997F5C42d",
|
|
12773
|
+
"AdminModule": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
|
|
12774
|
+
"PositionManagerViews": "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
|
|
12775
|
+
"PositionManager": "0x9E545E3C0baAB3E08CdfD552C960A1050f373042",
|
|
12776
|
+
"OperationAuthorizationRegistry": "0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00",
|
|
12777
|
+
"PKPValidation": "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
|
|
12778
12778
|
}
|
|
12779
12779
|
};
|
|
12780
12780
|
LOCALHOST_CONTRACTS = {
|
|
12781
|
-
"UpgradeValidator": "
|
|
12781
|
+
"UpgradeValidator": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
|
|
12782
12782
|
"UCDToken": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
12783
12783
|
"UCDController": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
12784
|
-
"PriceFeedConsumer": "
|
|
12785
|
-
"BTCProofValidator": "
|
|
12786
|
-
"UCDMintingRewards": "
|
|
12787
|
-
"PositionManagerCoreModule": "
|
|
12788
|
-
"TermManagerModule": "
|
|
12789
|
-
"LoanOperationsManagerModule": "
|
|
12790
|
-
"CollateralManagerModule": "
|
|
12791
|
-
"LiquidationManagerModule": "
|
|
12792
|
-
"CircuitBreakerModule": "
|
|
12793
|
-
"CommunityManagerModule": "
|
|
12794
|
-
"AdminModule": "
|
|
12795
|
-
"PositionManagerViews": "
|
|
12796
|
-
"PositionManager": "
|
|
12797
|
-
"OperationAuthorizationRegistry": "
|
|
12798
|
-
"PKPValidation": "
|
|
12784
|
+
"PriceFeedConsumer": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
|
|
12785
|
+
"BTCProofValidator": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
|
|
12786
|
+
"UCDMintingRewards": "0x9A676e781A523b5d0C0e43731313A708CB607508",
|
|
12787
|
+
"PositionManagerCoreModule": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
12788
|
+
"TermManagerModule": "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
12789
|
+
"LoanOperationsManagerModule": "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
|
|
12790
|
+
"CollateralManagerModule": "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
|
|
12791
|
+
"LiquidationManagerModule": "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
|
|
12792
|
+
"CircuitBreakerModule": "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
12793
|
+
"CommunityManagerModule": "0xc5a5C42992dECbae36851359345FE25997F5C42d",
|
|
12794
|
+
"AdminModule": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
|
|
12795
|
+
"PositionManagerViews": "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
|
|
12796
|
+
"PositionManager": "0x9E545E3C0baAB3E08CdfD552C960A1050f373042",
|
|
12797
|
+
"OperationAuthorizationRegistry": "0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00",
|
|
12798
|
+
"PKPValidation": "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
|
|
12799
12799
|
};
|
|
12800
12800
|
ALL_DEPLOYMENTS = {
|
|
12801
12801
|
sepolia: SEPOLIA_DEPLOYMENT,
|
|
@@ -12943,7 +12943,7 @@ function getSepoliaConfig() {
|
|
|
12943
12943
|
operationAuthorizationRegistry: SEPOLIA_CONTRACTS.OperationAuthorizationRegistry || ""
|
|
12944
12944
|
},
|
|
12945
12945
|
subgraphs: {
|
|
12946
|
-
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/
|
|
12946
|
+
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/v0.3.0-1765544881"
|
|
12947
12947
|
},
|
|
12948
12948
|
// litNetwork: "datil-test",
|
|
12949
12949
|
debug: true
|
|
@@ -12997,8 +12997,14 @@ function getLocalhostConfig() {
|
|
|
12997
12997
|
);
|
|
12998
12998
|
logNetworkConfig("log", "[NetworkConfig] Localhost contracts:", {
|
|
12999
12999
|
PositionManager: getAddress3("POSITION_MANAGER_ADDRESS", "PositionManager"),
|
|
13000
|
-
PositionManagerCore: getAddress3(
|
|
13001
|
-
|
|
13000
|
+
PositionManagerCore: getAddress3(
|
|
13001
|
+
"POSITION_MANAGER_CORE_ADDRESS",
|
|
13002
|
+
"PositionManagerCoreModule"
|
|
13003
|
+
),
|
|
13004
|
+
LoanOperationsManagerModule: getAddress3(
|
|
13005
|
+
"LOAN_OPERATIONS_MANAGER_ADDRESS",
|
|
13006
|
+
"LoanOperationsManagerModule"
|
|
13007
|
+
),
|
|
13002
13008
|
TermManagerModule: getAddress3("TERM_MANAGER_ADDRESS", "TermManagerModule"),
|
|
13003
13009
|
UCDToken: getAddress3("UCD_TOKEN_ADDRESS", "UCDToken")
|
|
13004
13010
|
});
|
|
@@ -13009,23 +13015,53 @@ function getLocalhostConfig() {
|
|
|
13009
13015
|
name: "localhost",
|
|
13010
13016
|
rpcUrls: ["http://localhost:8545"],
|
|
13011
13017
|
contractAddresses: {
|
|
13012
|
-
positionManager: getAddress3(
|
|
13013
|
-
|
|
13014
|
-
|
|
13018
|
+
positionManager: getAddress3(
|
|
13019
|
+
"POSITION_MANAGER_ADDRESS",
|
|
13020
|
+
"PositionManager"
|
|
13021
|
+
),
|
|
13022
|
+
positionManagerCore: getAddress3(
|
|
13023
|
+
"POSITION_MANAGER_CORE_ADDRESS",
|
|
13024
|
+
"PositionManagerCoreModule"
|
|
13025
|
+
),
|
|
13026
|
+
positionManagerViews: getAddress3(
|
|
13027
|
+
"POSITION_MANAGER_VIEWS_ADDRESS",
|
|
13028
|
+
"PositionManagerViews"
|
|
13029
|
+
),
|
|
13015
13030
|
simplePsmV2: getAddress3("SIMPLE_PSM_V2_ADDRESS", "SimplePSMV2"),
|
|
13016
|
-
loanOperationsManager: getAddress3(
|
|
13031
|
+
loanOperationsManager: getAddress3(
|
|
13032
|
+
"LOAN_OPERATIONS_MANAGER_ADDRESS",
|
|
13033
|
+
"LoanOperationsManagerModule"
|
|
13034
|
+
),
|
|
13017
13035
|
termManager: getAddress3("TERM_MANAGER_ADDRESS", "TermManagerModule"),
|
|
13018
|
-
circuitBreaker: getAddress3(
|
|
13019
|
-
|
|
13020
|
-
|
|
13036
|
+
circuitBreaker: getAddress3(
|
|
13037
|
+
"CIRCUIT_BREAKER_ADDRESS",
|
|
13038
|
+
"CircuitBreakerModule"
|
|
13039
|
+
),
|
|
13040
|
+
communityManager: getAddress3(
|
|
13041
|
+
"COMMUNITY_MANAGER_ADDRESS",
|
|
13042
|
+
"CommunityManagerModule"
|
|
13043
|
+
),
|
|
13044
|
+
liquidationManager: getAddress3(
|
|
13045
|
+
"LIQUIDATION_MANAGER_ADDRESS",
|
|
13046
|
+
"LiquidationManagerModule"
|
|
13047
|
+
),
|
|
13021
13048
|
ucdToken: getAddress3("UCD_TOKEN_ADDRESS", "UCDToken"),
|
|
13022
13049
|
ucdController: getAddress3("UCD_CONTROLLER_ADDRESS", "UCDController"),
|
|
13023
|
-
btcProofValidator: getAddress3(
|
|
13024
|
-
|
|
13025
|
-
|
|
13050
|
+
btcProofValidator: getAddress3(
|
|
13051
|
+
"BTC_PROOF_VALIDATOR_ADDRESS",
|
|
13052
|
+
"BTCProofValidator"
|
|
13053
|
+
),
|
|
13054
|
+
priceFeedConsumer: getAddress3(
|
|
13055
|
+
"PRICE_FEED_CONSUMER_ADDRESS",
|
|
13056
|
+
"PriceFeedConsumer"
|
|
13057
|
+
),
|
|
13058
|
+
operationAuthorizationRegistry: getAddress3(
|
|
13059
|
+
"OPERATION_AUTHORIZATION_REGISTRY_ADDRESS",
|
|
13060
|
+
"OperationAuthorizationRegistry"
|
|
13061
|
+
)
|
|
13026
13062
|
},
|
|
13027
13063
|
subgraphs: {
|
|
13028
|
-
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/
|
|
13064
|
+
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/v0.3.0-1765544881"
|
|
13029
13065
|
},
|
|
13030
13066
|
litNetwork: "datil",
|
|
13031
13067
|
debug: true
|
|
@@ -41881,38 +41917,86 @@ var ContractManager = class {
|
|
|
41881
41917
|
}
|
|
41882
41918
|
const contractRunner = runner;
|
|
41883
41919
|
const contracts = {
|
|
41884
|
-
positionManager:
|
|
41885
|
-
|
|
41886
|
-
|
|
41887
|
-
|
|
41888
|
-
|
|
41889
|
-
|
|
41890
|
-
|
|
41891
|
-
|
|
41892
|
-
|
|
41893
|
-
|
|
41894
|
-
|
|
41895
|
-
|
|
41896
|
-
|
|
41897
|
-
|
|
41898
|
-
|
|
41899
|
-
|
|
41900
|
-
|
|
41901
|
-
|
|
41902
|
-
|
|
41903
|
-
),
|
|
41904
|
-
|
|
41905
|
-
|
|
41906
|
-
|
|
41907
|
-
|
|
41908
|
-
|
|
41909
|
-
|
|
41910
|
-
|
|
41911
|
-
|
|
41912
|
-
|
|
41913
|
-
|
|
41914
|
-
|
|
41915
|
-
|
|
41920
|
+
positionManager: (() => {
|
|
41921
|
+
try {
|
|
41922
|
+
return PositionManager__factory.connect(
|
|
41923
|
+
contractAddresses.positionManager,
|
|
41924
|
+
contractRunner
|
|
41925
|
+
);
|
|
41926
|
+
} catch (error) {
|
|
41927
|
+
throw new Error(`Failed to connect to PositionManager at ${contractAddresses.positionManager}: ${error}`);
|
|
41928
|
+
}
|
|
41929
|
+
})(),
|
|
41930
|
+
loanOperationsManager: (() => {
|
|
41931
|
+
try {
|
|
41932
|
+
return ILoanOperationsManager__factory.connect(
|
|
41933
|
+
contractAddresses.loanOperationsManager || ethers_exports.constants.AddressZero,
|
|
41934
|
+
contractRunner
|
|
41935
|
+
);
|
|
41936
|
+
} catch (error) {
|
|
41937
|
+
throw new Error(`Failed to connect to LoanOperationsManager at ${contractAddresses.loanOperationsManager}: ${error}`);
|
|
41938
|
+
}
|
|
41939
|
+
})(),
|
|
41940
|
+
ucdController: (() => {
|
|
41941
|
+
try {
|
|
41942
|
+
return IUCDController__factory.connect(
|
|
41943
|
+
contractAddresses.ucdToken,
|
|
41944
|
+
contractRunner
|
|
41945
|
+
);
|
|
41946
|
+
} catch (error) {
|
|
41947
|
+
throw new Error(`Failed to connect to UCDController at ${contractAddresses.ucdToken}: ${error}`);
|
|
41948
|
+
}
|
|
41949
|
+
})(),
|
|
41950
|
+
priceFeed: (() => {
|
|
41951
|
+
try {
|
|
41952
|
+
return IPriceFeedConsumer__factory.connect(
|
|
41953
|
+
contractAddresses.priceFeedConsumer,
|
|
41954
|
+
contractRunner
|
|
41955
|
+
);
|
|
41956
|
+
} catch (error) {
|
|
41957
|
+
throw new Error(`Failed to connect to PriceFeed at ${contractAddresses.priceFeedConsumer}: ${error}`);
|
|
41958
|
+
}
|
|
41959
|
+
})(),
|
|
41960
|
+
termManager: (() => {
|
|
41961
|
+
try {
|
|
41962
|
+
return ITermManager__factory.connect(
|
|
41963
|
+
contractAddresses.termManager || ethers_exports.constants.AddressZero,
|
|
41964
|
+
contractRunner
|
|
41965
|
+
);
|
|
41966
|
+
} catch (error) {
|
|
41967
|
+
throw new Error(`Failed to connect to TermManager at ${contractAddresses.termManager}: ${error}`);
|
|
41968
|
+
}
|
|
41969
|
+
})(),
|
|
41970
|
+
circuitBreaker: (() => {
|
|
41971
|
+
try {
|
|
41972
|
+
return CircuitBreakerModule__factory.connect(
|
|
41973
|
+
contractAddresses.circuitBreaker || ethers_exports.constants.AddressZero,
|
|
41974
|
+
contractRunner
|
|
41975
|
+
);
|
|
41976
|
+
} catch (error) {
|
|
41977
|
+
throw new Error(`Failed to connect to CircuitBreaker at ${contractAddresses.circuitBreaker}: ${error}`);
|
|
41978
|
+
}
|
|
41979
|
+
})(),
|
|
41980
|
+
communityManager: (() => {
|
|
41981
|
+
try {
|
|
41982
|
+
return ICommunityManager__factory.connect(
|
|
41983
|
+
contractAddresses.communityManager || ethers_exports.constants.AddressZero,
|
|
41984
|
+
contractRunner
|
|
41985
|
+
);
|
|
41986
|
+
} catch (error) {
|
|
41987
|
+
throw new Error(`Failed to connect to CommunityManager at ${contractAddresses.communityManager}: ${error}`);
|
|
41988
|
+
}
|
|
41989
|
+
})(),
|
|
41990
|
+
liquidationManager: (() => {
|
|
41991
|
+
try {
|
|
41992
|
+
return ILiquidationManager__factory.connect(
|
|
41993
|
+
contractAddresses.liquidationManager || ethers_exports.constants.AddressZero,
|
|
41994
|
+
contractRunner
|
|
41995
|
+
);
|
|
41996
|
+
} catch (error) {
|
|
41997
|
+
throw new Error(`Failed to connect to LiquidationManager at ${contractAddresses.liquidationManager}: ${error}`);
|
|
41998
|
+
}
|
|
41999
|
+
})()
|
|
41916
42000
|
};
|
|
41917
42001
|
this.contracts = contracts;
|
|
41918
42002
|
return success(contracts);
|
|
@@ -43592,6 +43676,55 @@ var LoanQuery = class {
|
|
|
43592
43676
|
})
|
|
43593
43677
|
);
|
|
43594
43678
|
}
|
|
43679
|
+
/**
|
|
43680
|
+
* Get loans with BTC balance data from Bitcoin network
|
|
43681
|
+
*
|
|
43682
|
+
* Same as getLoans but includes actual Bitcoin balance for each position's vault.
|
|
43683
|
+
* Queries BTC balances in parallel for performance.
|
|
43684
|
+
*
|
|
43685
|
+
* @param filters - Query filters
|
|
43686
|
+
* @param pagination - Pagination parameters
|
|
43687
|
+
* @returns Paginated loans response with BTC balance data
|
|
43688
|
+
*/
|
|
43689
|
+
async getLoansWithBtc(filters = {}, pagination) {
|
|
43690
|
+
const page = pagination?.page || 0;
|
|
43691
|
+
const pageSize = pagination?.pageSize || this.defaultPageSize;
|
|
43692
|
+
const skip = page * pageSize;
|
|
43693
|
+
if (!filters.borrower) {
|
|
43694
|
+
if (this.config.debug) {
|
|
43695
|
+
log.info("\u26A0\uFE0F getLoansWithBtc only supports borrower filter, falling back to getLoans");
|
|
43696
|
+
}
|
|
43697
|
+
return this.getLoans(filters, pagination);
|
|
43698
|
+
}
|
|
43699
|
+
if (this.config.debug) {
|
|
43700
|
+
log.info("\u{1F50D} Querying loans with BTC balance data", { filters, page, pageSize, skip });
|
|
43701
|
+
}
|
|
43702
|
+
return tryCatchAsync(
|
|
43703
|
+
async () => {
|
|
43704
|
+
const result = await this.config.graphClient.getUserPositionsWithBtc(
|
|
43705
|
+
filters.borrower,
|
|
43706
|
+
pageSize,
|
|
43707
|
+
skip,
|
|
43708
|
+
filters.orderBy || "createdAt",
|
|
43709
|
+
filters.orderDirection || "desc"
|
|
43710
|
+
);
|
|
43711
|
+
const enrichedLoans = await this.enrichLoansWithVaultAddresses(result.positions);
|
|
43712
|
+
return {
|
|
43713
|
+
loans: enrichedLoans,
|
|
43714
|
+
page,
|
|
43715
|
+
maxRows: pageSize,
|
|
43716
|
+
totalLoans: result.total
|
|
43717
|
+
};
|
|
43718
|
+
},
|
|
43719
|
+
(error) => new SDKError({
|
|
43720
|
+
message: "Failed to query loans with BTC balance",
|
|
43721
|
+
category: "SUBGRAPH" /* SUBGRAPH */,
|
|
43722
|
+
severity: "MEDIUM" /* MEDIUM */,
|
|
43723
|
+
originalError: error instanceof Error ? error : new Error(String(error)),
|
|
43724
|
+
context: { filters, page, pageSize }
|
|
43725
|
+
})
|
|
43726
|
+
);
|
|
43727
|
+
}
|
|
43595
43728
|
/**
|
|
43596
43729
|
* Enrich loans with vault addresses derived from PKP public keys
|
|
43597
43730
|
*
|
|
@@ -44177,7 +44310,10 @@ async function getBitcoinAddressesFromPkp(pkpPublicKey) {
|
|
|
44177
44310
|
var BitcoinUtils = class {
|
|
44178
44311
|
static validateAddress(address) {
|
|
44179
44312
|
const base58Pattern = /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/;
|
|
44180
|
-
|
|
44313
|
+
const isBase58 = base58Pattern.test(address) && address.length >= 26 && address.length <= 35;
|
|
44314
|
+
const bech32Pattern = /^(bc1|tb1|bcrt1)[a-z0-9]{39,87}$/;
|
|
44315
|
+
const isBech32 = bech32Pattern.test(address);
|
|
44316
|
+
return isBase58 || isBech32;
|
|
44181
44317
|
}
|
|
44182
44318
|
static formatTransaction(hash3, amount, recipient) {
|
|
44183
44319
|
return {
|
|
@@ -45559,7 +45695,8 @@ var MIN_BITCOIN_PROVIDERS_FOR_CONSENSUS = 2;
|
|
|
45559
45695
|
var DiamondHandsGraph = class {
|
|
45560
45696
|
client;
|
|
45561
45697
|
defaultPageSize;
|
|
45562
|
-
|
|
45698
|
+
bitcoinOps;
|
|
45699
|
+
constructor(config, bitcoinOps) {
|
|
45563
45700
|
this.client = new GraphClient({
|
|
45564
45701
|
endpoint: config.endpoint,
|
|
45565
45702
|
requestTimeoutMs: config.requestTimeoutMs,
|
|
@@ -45567,6 +45704,7 @@ var DiamondHandsGraph = class {
|
|
|
45567
45704
|
headers: config.headers
|
|
45568
45705
|
});
|
|
45569
45706
|
this.defaultPageSize = config.defaultPageSize ?? 100;
|
|
45707
|
+
this.bitcoinOps = bitcoinOps;
|
|
45570
45708
|
}
|
|
45571
45709
|
/**
|
|
45572
45710
|
* Transform graph position data to LoanData interface
|
|
@@ -45636,10 +45774,7 @@ var DiamondHandsGraph = class {
|
|
|
45636
45774
|
}
|
|
45637
45775
|
}
|
|
45638
45776
|
`;
|
|
45639
|
-
const result = await this.client.execute(
|
|
45640
|
-
query,
|
|
45641
|
-
{ ...variables, skip }
|
|
45642
|
-
);
|
|
45777
|
+
const result = await this.client.execute(query, { ...variables, skip });
|
|
45643
45778
|
const items = result && result["positions"] || [];
|
|
45644
45779
|
totalCount += items.length;
|
|
45645
45780
|
hasMore = items.length === batchSize;
|
|
@@ -45691,10 +45826,9 @@ var DiamondHandsGraph = class {
|
|
|
45691
45826
|
query,
|
|
45692
45827
|
variables
|
|
45693
45828
|
);
|
|
45694
|
-
const total = await this.getTotalCountPaginated(
|
|
45695
|
-
|
|
45696
|
-
|
|
45697
|
-
);
|
|
45829
|
+
const total = await this.getTotalCountPaginated("{ borrower: $borrower }", {
|
|
45830
|
+
borrower: userAddress.toLowerCase()
|
|
45831
|
+
});
|
|
45698
45832
|
let positions = [];
|
|
45699
45833
|
if (result && result.user && Array.isArray(result.user.positions)) {
|
|
45700
45834
|
positions = result.user.positions.filter((p) => p != null).map((p) => this.transformGraphPositionToLoanData(p));
|
|
@@ -45704,6 +45838,137 @@ var DiamondHandsGraph = class {
|
|
|
45704
45838
|
total
|
|
45705
45839
|
};
|
|
45706
45840
|
}
|
|
45841
|
+
/**
|
|
45842
|
+
* Get user positions with enriched Bitcoin balance data
|
|
45843
|
+
*
|
|
45844
|
+
* Same as getUserPositions but queries actual BTC balance from Bitcoin network
|
|
45845
|
+
* for each vault address in parallel.
|
|
45846
|
+
*
|
|
45847
|
+
* @param userAddress - User's Ethereum address
|
|
45848
|
+
* @param first - Optional: max number of positions to return (default: 10)
|
|
45849
|
+
* @param skip - Optional: number of positions to skip (default: 0)
|
|
45850
|
+
* @param orderBy - Optional: field to order by (default: "createdAt")
|
|
45851
|
+
* @param orderDirection - Optional: asc or desc (default: "desc" - most recent first)
|
|
45852
|
+
* @returns Positions with actual BTC balances from Bitcoin network
|
|
45853
|
+
*/
|
|
45854
|
+
async getUserPositionsWithBtc(userAddress, first = 10, skip = 0, orderBy = "createdAt", orderDirection = "desc") {
|
|
45855
|
+
const result = await this.getUserPositions(
|
|
45856
|
+
userAddress,
|
|
45857
|
+
first,
|
|
45858
|
+
skip,
|
|
45859
|
+
orderBy,
|
|
45860
|
+
orderDirection
|
|
45861
|
+
);
|
|
45862
|
+
if (!this.bitcoinOps) {
|
|
45863
|
+
console.warn(
|
|
45864
|
+
"[DiamondHandsGraph] BitcoinOperations not available - returning positions without BTC balance"
|
|
45865
|
+
);
|
|
45866
|
+
return result;
|
|
45867
|
+
}
|
|
45868
|
+
const positionsWithPkp = result.positions.filter(
|
|
45869
|
+
(p) => p.pkpId && p.pkpId !== ""
|
|
45870
|
+
);
|
|
45871
|
+
if (positionsWithPkp.length === 0) {
|
|
45872
|
+
console.log("[DiamondHandsGraph] No positions with PKP IDs to check");
|
|
45873
|
+
return result;
|
|
45874
|
+
}
|
|
45875
|
+
console.log(
|
|
45876
|
+
`[DiamondHandsGraph] Deriving Bitcoin addresses and querying balances for ${positionsWithPkp.length} positions in parallel...`
|
|
45877
|
+
);
|
|
45878
|
+
const balancePromises = positionsWithPkp.map(async (position) => {
|
|
45879
|
+
try {
|
|
45880
|
+
const pkpPublicKey = await getPKPPublicKeyFromTokenId(position.pkpId);
|
|
45881
|
+
const addressResult = await this.bitcoinOps.deriveAddresses(
|
|
45882
|
+
pkpPublicKey
|
|
45883
|
+
);
|
|
45884
|
+
if (!addressResult.success) {
|
|
45885
|
+
console.warn(
|
|
45886
|
+
`[DiamondHandsGraph] Failed to derive address for PKP public key ${pkpPublicKey}:`,
|
|
45887
|
+
addressResult.error
|
|
45888
|
+
);
|
|
45889
|
+
return {
|
|
45890
|
+
pkpId: position.pkpId,
|
|
45891
|
+
address: null,
|
|
45892
|
+
balance: null,
|
|
45893
|
+
addresses: null
|
|
45894
|
+
};
|
|
45895
|
+
}
|
|
45896
|
+
const addresses = addressResult.value;
|
|
45897
|
+
const btcAddress = addresses.regtest || addresses.testnet || addresses.mainnet;
|
|
45898
|
+
if (!btcAddress) {
|
|
45899
|
+
console.warn(
|
|
45900
|
+
`[DiamondHandsGraph] No Bitcoin address available for PKP ${position.pkpId}`
|
|
45901
|
+
);
|
|
45902
|
+
return {
|
|
45903
|
+
pkpId: position.pkpId,
|
|
45904
|
+
address: null,
|
|
45905
|
+
balance: null,
|
|
45906
|
+
addresses
|
|
45907
|
+
};
|
|
45908
|
+
}
|
|
45909
|
+
const balanceResult = await this.bitcoinOps.getBalance(btcAddress);
|
|
45910
|
+
if (balanceResult.success) {
|
|
45911
|
+
return {
|
|
45912
|
+
pkpId: position.pkpId,
|
|
45913
|
+
address: btcAddress,
|
|
45914
|
+
balance: balanceResult.value,
|
|
45915
|
+
addresses
|
|
45916
|
+
};
|
|
45917
|
+
} else {
|
|
45918
|
+
console.warn(
|
|
45919
|
+
`[DiamondHandsGraph] Failed to get balance for ${btcAddress}:`,
|
|
45920
|
+
balanceResult.error
|
|
45921
|
+
);
|
|
45922
|
+
return {
|
|
45923
|
+
pkpId: position.pkpId,
|
|
45924
|
+
address: btcAddress,
|
|
45925
|
+
balance: null,
|
|
45926
|
+
addresses
|
|
45927
|
+
};
|
|
45928
|
+
}
|
|
45929
|
+
} catch (error) {
|
|
45930
|
+
console.error(
|
|
45931
|
+
`[DiamondHandsGraph] Error processing PKP ${position.pkpId}:`,
|
|
45932
|
+
error
|
|
45933
|
+
);
|
|
45934
|
+
return {
|
|
45935
|
+
pkpId: position.pkpId,
|
|
45936
|
+
address: null,
|
|
45937
|
+
balance: null,
|
|
45938
|
+
addresses: null
|
|
45939
|
+
};
|
|
45940
|
+
}
|
|
45941
|
+
});
|
|
45942
|
+
const balanceResults = await Promise.all(balancePromises);
|
|
45943
|
+
const balanceMap = /* @__PURE__ */ new Map();
|
|
45944
|
+
balanceResults.forEach(({ pkpId, address, balance, addresses }) => {
|
|
45945
|
+
balanceMap.set(pkpId, { address, balance, addresses });
|
|
45946
|
+
});
|
|
45947
|
+
console.log(
|
|
45948
|
+
`[DiamondHandsGraph] Retrieved ${balanceResults.length} BTC balances`
|
|
45949
|
+
);
|
|
45950
|
+
const enrichedPositions = result.positions.map((position) => {
|
|
45951
|
+
if (!position.pkpId) {
|
|
45952
|
+
return position;
|
|
45953
|
+
}
|
|
45954
|
+
const data = balanceMap.get(position.pkpId);
|
|
45955
|
+
if (!data) {
|
|
45956
|
+
return position;
|
|
45957
|
+
}
|
|
45958
|
+
return {
|
|
45959
|
+
...position,
|
|
45960
|
+
collateral: {
|
|
45961
|
+
...position.collateral,
|
|
45962
|
+
vaultAddress: data.address || position.collateral?.vaultAddress || ""
|
|
45963
|
+
},
|
|
45964
|
+
btcBalance: data.balance || void 0
|
|
45965
|
+
};
|
|
45966
|
+
});
|
|
45967
|
+
return {
|
|
45968
|
+
positions: enrichedPositions,
|
|
45969
|
+
total: result.total
|
|
45970
|
+
};
|
|
45971
|
+
}
|
|
45707
45972
|
/**
|
|
45708
45973
|
* Get position by PKP ID from subgraph
|
|
45709
45974
|
*/
|
|
@@ -45806,10 +46071,7 @@ var DiamondHandsGraph = class {
|
|
|
45806
46071
|
const variables = {
|
|
45807
46072
|
pkpId: pkpId.toLowerCase()
|
|
45808
46073
|
};
|
|
45809
|
-
const result = await this.client.execute(
|
|
45810
|
-
query,
|
|
45811
|
-
variables
|
|
45812
|
-
);
|
|
46074
|
+
const result = await this.client.execute(query, variables);
|
|
45813
46075
|
if (!result || !result.positions) {
|
|
45814
46076
|
return null;
|
|
45815
46077
|
}
|
|
@@ -45886,10 +46148,7 @@ var DiamondHandsGraph = class {
|
|
|
45886
46148
|
const variables = {
|
|
45887
46149
|
positionId: positionId.toLowerCase()
|
|
45888
46150
|
};
|
|
45889
|
-
const result = await this.client.execute(
|
|
45890
|
-
query,
|
|
45891
|
-
variables
|
|
45892
|
-
);
|
|
46151
|
+
const result = await this.client.execute(query, variables);
|
|
45893
46152
|
if (!result || !result.positions) {
|
|
45894
46153
|
return null;
|
|
45895
46154
|
}
|
|
@@ -45962,10 +46221,12 @@ var DiamondHandsGraph = class {
|
|
|
45962
46221
|
}
|
|
45963
46222
|
}
|
|
45964
46223
|
`;
|
|
45965
|
-
const result = await this.client.execute(
|
|
45966
|
-
|
|
45967
|
-
|
|
45968
|
-
|
|
46224
|
+
const result = await this.client.execute(query, {
|
|
46225
|
+
first,
|
|
46226
|
+
skip,
|
|
46227
|
+
orderBy,
|
|
46228
|
+
orderDirection
|
|
46229
|
+
});
|
|
45969
46230
|
const total = await this.getTotalCountPaginated();
|
|
45970
46231
|
const positions = result && result.positions || [];
|
|
45971
46232
|
const transformedPositions = positions.map(
|
|
@@ -46007,10 +46268,13 @@ var DiamondHandsGraph = class {
|
|
|
46007
46268
|
}
|
|
46008
46269
|
}
|
|
46009
46270
|
`;
|
|
46010
|
-
const result = await this.client.execute(
|
|
46011
|
-
|
|
46012
|
-
|
|
46013
|
-
|
|
46271
|
+
const result = await this.client.execute(query, {
|
|
46272
|
+
first,
|
|
46273
|
+
skip,
|
|
46274
|
+
statuses,
|
|
46275
|
+
orderBy,
|
|
46276
|
+
orderDirection
|
|
46277
|
+
});
|
|
46014
46278
|
const total = await this.getTotalCountPaginated(
|
|
46015
46279
|
"{ status_in: $statuses }",
|
|
46016
46280
|
{ statuses }
|
|
@@ -46131,7 +46395,10 @@ var DiamondHandsGraph = class {
|
|
|
46131
46395
|
`;
|
|
46132
46396
|
const first = options?.first ?? this.defaultPageSize;
|
|
46133
46397
|
const skip = options?.skip ?? 0;
|
|
46134
|
-
const result = await this.client.execute(
|
|
46398
|
+
const result = await this.client.execute(
|
|
46399
|
+
query,
|
|
46400
|
+
{ first, skip }
|
|
46401
|
+
);
|
|
46135
46402
|
return result.loanTerms || [];
|
|
46136
46403
|
}
|
|
46137
46404
|
/**
|
|
@@ -46153,7 +46420,10 @@ var DiamondHandsGraph = class {
|
|
|
46153
46420
|
}
|
|
46154
46421
|
}
|
|
46155
46422
|
`;
|
|
46156
|
-
const result = await this.client.execute(
|
|
46423
|
+
const result = await this.client.execute(
|
|
46424
|
+
query,
|
|
46425
|
+
{ id: id3 }
|
|
46426
|
+
);
|
|
46157
46427
|
return result.loanTerm || null;
|
|
46158
46428
|
}
|
|
46159
46429
|
// ============================================================================
|
|
@@ -46270,7 +46540,13 @@ var DiamondHandsGraph = class {
|
|
|
46270
46540
|
* Get PSM transactions with filters
|
|
46271
46541
|
*/
|
|
46272
46542
|
async getPSMTransactions(filters) {
|
|
46273
|
-
const {
|
|
46543
|
+
const {
|
|
46544
|
+
user,
|
|
46545
|
+
stablecoin,
|
|
46546
|
+
type,
|
|
46547
|
+
first = this.defaultPageSize,
|
|
46548
|
+
skip = 0
|
|
46549
|
+
} = filters || {};
|
|
46274
46550
|
let whereConditions = [];
|
|
46275
46551
|
if (user)
|
|
46276
46552
|
whereConditions.push(`user: "${user.toLowerCase()}"`);
|
|
@@ -46330,7 +46606,10 @@ var DiamondHandsGraph = class {
|
|
|
46330
46606
|
}
|
|
46331
46607
|
`;
|
|
46332
46608
|
const variables = { first };
|
|
46333
|
-
const result = await this.client.execute(
|
|
46609
|
+
const result = await this.client.execute(
|
|
46610
|
+
query,
|
|
46611
|
+
variables
|
|
46612
|
+
);
|
|
46334
46613
|
return result.psmDailyMetrics || [];
|
|
46335
46614
|
}
|
|
46336
46615
|
// ============================================================================
|
|
@@ -46465,19 +46744,21 @@ var DiamondHandsGraph = class {
|
|
|
46465
46744
|
orderDirection
|
|
46466
46745
|
};
|
|
46467
46746
|
const result = await this.client.execute(query, variables);
|
|
46468
|
-
const payments = (result.position?.payments || []).map(
|
|
46469
|
-
|
|
46470
|
-
|
|
46471
|
-
|
|
46472
|
-
|
|
46473
|
-
|
|
46474
|
-
|
|
46475
|
-
|
|
46476
|
-
|
|
46477
|
-
|
|
46478
|
-
|
|
46479
|
-
|
|
46480
|
-
|
|
46747
|
+
const payments = (result.position?.payments || []).map(
|
|
46748
|
+
(p) => ({
|
|
46749
|
+
id: p.id,
|
|
46750
|
+
positionId,
|
|
46751
|
+
payer: p.payer.id,
|
|
46752
|
+
amount: p.amount,
|
|
46753
|
+
type: p.type,
|
|
46754
|
+
transactionHash: p.transactionHash,
|
|
46755
|
+
timestamp: p.timestamp,
|
|
46756
|
+
blockNumber: p.blockNumber,
|
|
46757
|
+
logIndex: p.logIndex,
|
|
46758
|
+
newDebt: p.newDebt,
|
|
46759
|
+
newCollateralRatio: p.newCollateralRatio
|
|
46760
|
+
})
|
|
46761
|
+
);
|
|
46481
46762
|
const statusUpdates = (result.position?.statusUpdates || []).map((s) => ({
|
|
46482
46763
|
id: s.id,
|
|
46483
46764
|
positionId,
|
|
@@ -46679,7 +46960,7 @@ function createMockTokenManager(config) {
|
|
|
46679
46960
|
import { LitOps } from "@gvnrdao/dh-lit-ops";
|
|
46680
46961
|
|
|
46681
46962
|
// src/utils/telegram-messaging.utils.ts
|
|
46682
|
-
|
|
46963
|
+
var TelegramBot = null;
|
|
46683
46964
|
async function sendTelegramMessage(chatId, chatToken, message, threadId) {
|
|
46684
46965
|
try {
|
|
46685
46966
|
const bot = new TelegramBot(chatToken, { polling: false });
|
|
@@ -46822,13 +47103,16 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
46822
47103
|
"Diamond Hands subgraph URL is required. Please provide config.subgraphs.diamondHandsUrl"
|
|
46823
47104
|
);
|
|
46824
47105
|
}
|
|
46825
|
-
this.graphClient = new DiamondHandsGraph(
|
|
46826
|
-
|
|
46827
|
-
|
|
46828
|
-
|
|
46829
|
-
|
|
46830
|
-
|
|
46831
|
-
|
|
47106
|
+
this.graphClient = new DiamondHandsGraph(
|
|
47107
|
+
{
|
|
47108
|
+
endpoint: graphEndpoint,
|
|
47109
|
+
requestTimeoutMs: config.graphOptions?.requestTimeoutMs,
|
|
47110
|
+
maxRetries: config.graphOptions?.maxRetries,
|
|
47111
|
+
defaultPageSize: config.graphOptions?.pageSize,
|
|
47112
|
+
headers: config.graphApiKey ? { Authorization: `Bearer ${config.graphApiKey}` } : void 0
|
|
47113
|
+
},
|
|
47114
|
+
this.bitcoinOperations
|
|
47115
|
+
);
|
|
46832
47116
|
const loanQueryResult = createLoanQuery({
|
|
46833
47117
|
graphClient: this.graphClient,
|
|
46834
47118
|
bitcoinOperations: this.bitcoinOperations,
|