@gvnrdao/dh-sdk 0.0.1
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/README.md +77 -0
- package/dist/browser.d.ts +14 -0
- package/dist/browser.js +36 -0
- package/dist/constants/chunks/contract-abis.d.ts +6 -0
- package/dist/constants/chunks/contract-abis.js +39 -0
- package/dist/constants/chunks/environment.browser.d.ts +40 -0
- package/dist/constants/chunks/environment.browser.js +111 -0
- package/dist/constants/chunks/environment.d.ts +40 -0
- package/dist/constants/chunks/environment.js +146 -0
- package/dist/constants/chunks/sdk-config.d.ts +27 -0
- package/dist/constants/chunks/sdk-config.js +34 -0
- package/dist/constants/index.d.ts +9 -0
- package/dist/constants/index.js +28 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +50 -0
- package/dist/interfaces/chunks/IBTCProof.d.ts +32 -0
- package/dist/interfaces/chunks/IBTCProof.js +2 -0
- package/dist/interfaces/chunks/SDKTypes.d.ts +2 -0
- package/dist/interfaces/chunks/SDKTypes.js +19 -0
- package/dist/interfaces/chunks/btc.i.d.ts +36 -0
- package/dist/interfaces/chunks/btc.i.js +5 -0
- package/dist/interfaces/chunks/config.i.d.ts +45 -0
- package/dist/interfaces/chunks/config.i.js +5 -0
- package/dist/interfaces/chunks/contract-interactions.i.d.ts +66 -0
- package/dist/interfaces/chunks/contract-interactions.i.js +5 -0
- package/dist/interfaces/chunks/lit-actions.d.ts +27 -0
- package/dist/interfaces/chunks/lit-actions.i.d.ts +44 -0
- package/dist/interfaces/chunks/lit-actions.i.js +5 -0
- package/dist/interfaces/chunks/lit-actions.js +2 -0
- package/dist/interfaces/chunks/loan-operations.d.ts +56 -0
- package/dist/interfaces/chunks/loan-operations.i.d.ts +85 -0
- package/dist/interfaces/chunks/loan-operations.i.js +5 -0
- package/dist/interfaces/chunks/loan-operations.js +2 -0
- package/dist/interfaces/chunks/pkp-integration.i.d.ts +88 -0
- package/dist/interfaces/chunks/pkp-integration.i.js +5 -0
- package/dist/interfaces/chunks/requests.i.d.ts +28 -0
- package/dist/interfaces/chunks/requests.i.js +5 -0
- package/dist/interfaces/chunks/ucd-minting.i.d.ts +34 -0
- package/dist/interfaces/chunks/ucd-minting.i.js +5 -0
- package/dist/interfaces/chunks/utility.i.d.ts +64 -0
- package/dist/interfaces/chunks/utility.i.js +5 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/index.js +40 -0
- package/dist/modules/contract-interaction-manager.module.d.ts +86 -0
- package/dist/modules/contract-interaction-manager.module.js +136 -0
- package/dist/modules/diamond-hands-sdk.module.d.ts +109 -0
- package/dist/modules/diamond-hands-sdk.module.js +773 -0
- package/dist/modules/loan-operations-manager.module.d.ts +92 -0
- package/dist/modules/loan-operations-manager.module.js +171 -0
- package/dist/modules/pkp-integration-manager.module.d.ts +86 -0
- package/dist/modules/pkp-integration-manager.module.js +62 -0
- package/dist/types/loanStatus.d.ts +10 -0
- package/dist/types/loanStatus.js +16 -0
- package/dist/utils/chunks/bitcoin-utils.d.ts +51 -0
- package/dist/utils/chunks/bitcoin-utils.js +135 -0
- package/dist/utils/chunks/environment-utils.d.ts +11 -0
- package/dist/utils/chunks/environment-utils.js +21 -0
- package/dist/utils/chunks/pkp-utils.d.ts +19 -0
- package/dist/utils/chunks/pkp-utils.js +44 -0
- package/dist/utils/chunks/validation-utils.d.ts +30 -0
- package/dist/utils/chunks/validation-utils.js +58 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +39 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @gvnrdao/dh-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
The official TypeScript SDK for the Diamond Hands Protocol, enabling developers to interact with Bitcoin-backed lending smart contracts using LIT Protocol's Programmable Key Pairs (PKPs) for secure asset management.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @gvnrdao/dh-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic Setup
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { DiamondHandsSDK } from "@gvnrdao/dh-sdk";
|
|
21
|
+
|
|
22
|
+
// Initialize SDK
|
|
23
|
+
const sdk = new DiamondHandsSDK({
|
|
24
|
+
mode: "service", // or 'standalone'
|
|
25
|
+
serviceEndpoint: "http://localhost:3001",
|
|
26
|
+
contractAddresses: {
|
|
27
|
+
positionManager: "0x...",
|
|
28
|
+
ucdToken: "0x...",
|
|
29
|
+
// ... other contract addresses
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await sdk.initialize();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Creating a Loan
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
const loanRequest = {
|
|
40
|
+
collateralAmount: 25000, // UCD equivalent
|
|
41
|
+
collateralRatio: 150, // 150%
|
|
42
|
+
selectedTerm: 3, // 3 months
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const result = await sdk.createLoan(loanRequest);
|
|
46
|
+
if (result.success) {
|
|
47
|
+
console.log("Loan created:", result.transactionHash);
|
|
48
|
+
console.log("Position ID:", result.positionId);
|
|
49
|
+
console.log("PKP Address:", result.pkpData.ethAddress);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
- ✅ **Service & Standalone Modes**: Flexible deployment options
|
|
56
|
+
- ✅ **Browser & Node.js Support**: Works in both environments
|
|
57
|
+
- ✅ **TypeScript Support**: Full type definitions included
|
|
58
|
+
- ✅ **PKP Integration**: Secure key management with LIT Protocol
|
|
59
|
+
- ✅ **Smart Contract Integration**: Direct interaction with Diamond Hands contracts
|
|
60
|
+
- ✅ **Bitcoin Operations**: Support for Bitcoin deposit verification
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
|
|
64
|
+
### Core Methods
|
|
65
|
+
|
|
66
|
+
- `initialize()` - Initialize the SDK
|
|
67
|
+
- `createLoan(request)` - Create a new loan position
|
|
68
|
+
- `repayLoan(positionId, amount)` - Repay an existing loan
|
|
69
|
+
- `liquidatePosition(positionId)` - Liquidate an undercollateralized position
|
|
70
|
+
|
|
71
|
+
### Configuration Options
|
|
72
|
+
|
|
73
|
+
See the full API documentation for detailed configuration options and method signatures.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible entry point for Diamond Hands SDK
|
|
3
|
+
* This exports only the core SDK functionality for browser use
|
|
4
|
+
*/
|
|
5
|
+
import { DiamondHandsSDK as SDK } from "./modules/diamond-hands-sdk.module";
|
|
6
|
+
export * from "./interfaces";
|
|
7
|
+
export * from "./constants";
|
|
8
|
+
export { SDK as DiamondHandsSDK };
|
|
9
|
+
declare const defaultExport: {
|
|
10
|
+
DiamondHandsSDK: typeof SDK;
|
|
11
|
+
};
|
|
12
|
+
export default defaultExport;
|
|
13
|
+
export * from "./interfaces";
|
|
14
|
+
export * from "./constants";
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser-compatible entry point for Diamond Hands SDK
|
|
4
|
+
* This exports only the core SDK functionality for browser use
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.DiamondHandsSDK = void 0;
|
|
22
|
+
const diamond_hands_sdk_module_1 = require("./modules/diamond-hands-sdk.module");
|
|
23
|
+
Object.defineProperty(exports, "DiamondHandsSDK", { enumerable: true, get: function () { return diamond_hands_sdk_module_1.DiamondHandsSDK; } });
|
|
24
|
+
// Export interfaces and types
|
|
25
|
+
__exportStar(require("./interfaces"), exports);
|
|
26
|
+
__exportStar(require("./constants"), exports);
|
|
27
|
+
// Default export for UMD compatibility
|
|
28
|
+
const defaultExport = {
|
|
29
|
+
DiamondHandsSDK: diamond_hands_sdk_module_1.DiamondHandsSDK,
|
|
30
|
+
};
|
|
31
|
+
exports.default = defaultExport;
|
|
32
|
+
// Also export everything from constants and interfaces on the default export
|
|
33
|
+
__exportStar(require("./interfaces"), exports);
|
|
34
|
+
__exportStar(require("./constants"), exports);
|
|
35
|
+
// Note: Contract utilities and advanced features are excluded from browser build
|
|
36
|
+
// for compatibility. Use only the core SDK functionality in browsers.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart Contract ABIs
|
|
3
|
+
*/
|
|
4
|
+
export declare const POSITION_MANAGER_ABI: readonly ["function createPosition(bytes32 pkpId, uint256 amount, bytes calldata validatorSignature) external returns (bool)", "function mintUCD(bytes32 pkpId, bytes memory proof, uint256 amount) external returns (bool)", "function liquidatePosition(bytes32 positionId) external returns (bool)", "function calculateCollateralRatio(bytes32 positionId) external view returns (uint256)", "function getPositionDetails(bytes32 positionId) external view returns (tuple(bytes32 positionId, bytes32 pkpId, address borrower, uint256 btcAmount, uint256 ucdDebt, uint256 createdAt, uint256 lastUpdated, bool isActive, uint256 collateralRatio))", "function getUserPositions(address user) external view returns (bytes32[] memory)", "event PositionCreated(bytes32 indexed positionId, bytes32 indexed pkpId, address indexed borrower, uint256 amount)", "event UCDMinted(bytes32 indexed positionId, uint256 amount, bytes proof)", "event PositionLiquidated(bytes32 indexed positionId, address indexed liquidator, uint256 collateralRatio, uint256 liquidationBonus)", "event CollateralRatioUpdated(bytes32 indexed positionId, uint256 oldRatio, uint256 newRatio)", "event PositionUpdated(bytes32 indexed positionId, uint256 oldDebt, uint256 newDebt)"];
|
|
5
|
+
export declare const UCD_TOKEN_ABI: readonly ["function balanceOf(address account) external view returns (uint256)", "function transfer(address to, uint256 amount) external returns (bool)", "function approve(address spender, uint256 amount) external returns (bool)", "function allowance(address owner, address spender) external view returns (uint256)", "function mint(address to, uint256 amount) external", "function burn(uint256 amount) external", "function burnFrom(address account, uint256 amount) external", "event Transfer(address indexed from, address indexed to, uint256 value)", "event Approval(address indexed owner, address indexed spender, uint256 value)"];
|
|
6
|
+
export declare const PRICE_FEED_CONSUMER_ABI: readonly ["function getCurrentPrice() external view returns (uint256)", "function isPriceStale() external view returns (bool)", "function updatePrice() external", "event PriceUpdated(uint256 indexed price, uint256 timestamp)"];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Smart Contract ABIs
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PRICE_FEED_CONSUMER_ABI = exports.UCD_TOKEN_ABI = exports.POSITION_MANAGER_ABI = void 0;
|
|
7
|
+
// Position Manager Contract ABI
|
|
8
|
+
exports.POSITION_MANAGER_ABI = [
|
|
9
|
+
"function createPosition(bytes32 pkpId, uint256 amount, bytes calldata validatorSignature) external returns (bool)",
|
|
10
|
+
"function mintUCD(bytes32 pkpId, bytes memory proof, uint256 amount) external returns (bool)",
|
|
11
|
+
"function liquidatePosition(bytes32 positionId) external returns (bool)",
|
|
12
|
+
"function calculateCollateralRatio(bytes32 positionId) external view returns (uint256)",
|
|
13
|
+
"function getPositionDetails(bytes32 positionId) external view returns (tuple(bytes32 positionId, bytes32 pkpId, address borrower, uint256 btcAmount, uint256 ucdDebt, uint256 createdAt, uint256 lastUpdated, bool isActive, uint256 collateralRatio))",
|
|
14
|
+
"function getUserPositions(address user) external view returns (bytes32[] memory)",
|
|
15
|
+
"event PositionCreated(bytes32 indexed positionId, bytes32 indexed pkpId, address indexed borrower, uint256 amount)",
|
|
16
|
+
"event UCDMinted(bytes32 indexed positionId, uint256 amount, bytes proof)",
|
|
17
|
+
"event PositionLiquidated(bytes32 indexed positionId, address indexed liquidator, uint256 collateralRatio, uint256 liquidationBonus)",
|
|
18
|
+
"event CollateralRatioUpdated(bytes32 indexed positionId, uint256 oldRatio, uint256 newRatio)",
|
|
19
|
+
"event PositionUpdated(bytes32 indexed positionId, uint256 oldDebt, uint256 newDebt)",
|
|
20
|
+
];
|
|
21
|
+
// UCD Token Contract ABI
|
|
22
|
+
exports.UCD_TOKEN_ABI = [
|
|
23
|
+
"function balanceOf(address account) external view returns (uint256)",
|
|
24
|
+
"function transfer(address to, uint256 amount) external returns (bool)",
|
|
25
|
+
"function approve(address spender, uint256 amount) external returns (bool)",
|
|
26
|
+
"function allowance(address owner, address spender) external view returns (uint256)",
|
|
27
|
+
"function mint(address to, uint256 amount) external",
|
|
28
|
+
"function burn(uint256 amount) external",
|
|
29
|
+
"function burnFrom(address account, uint256 amount) external",
|
|
30
|
+
"event Transfer(address indexed from, address indexed to, uint256 value)",
|
|
31
|
+
"event Approval(address indexed owner, address indexed spender, uint256 value)",
|
|
32
|
+
];
|
|
33
|
+
// Price Feed Consumer ABI
|
|
34
|
+
exports.PRICE_FEED_CONSUMER_ABI = [
|
|
35
|
+
"function getCurrentPrice() external view returns (uint256)",
|
|
36
|
+
"function isPriceStale() external view returns (bool)",
|
|
37
|
+
"function updatePrice() external",
|
|
38
|
+
"event PriceUpdated(uint256 indexed price, uint256 timestamp)",
|
|
39
|
+
];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment Configuration for Diamond Hands SDK - Browser Version
|
|
3
|
+
* Browser-compatible environment handling without Node.js dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { LitNetwork } from "@gvnrdao/dh-lit-ops";
|
|
6
|
+
export type EnvironmentName = "datil-test" | "datil";
|
|
7
|
+
export interface SDKConfig {
|
|
8
|
+
environment: EnvironmentName;
|
|
9
|
+
litNetwork: LitNetwork;
|
|
10
|
+
realLitTesting: boolean;
|
|
11
|
+
debugMode: boolean;
|
|
12
|
+
runRealIntegrationTests: boolean;
|
|
13
|
+
litRelayUrl?: string;
|
|
14
|
+
ethRpcUrl: string;
|
|
15
|
+
polygonRpcUrl: string;
|
|
16
|
+
pkpMintPrivateKey?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the current environment from environment variables
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCurrentEnvironment(): EnvironmentName;
|
|
22
|
+
/**
|
|
23
|
+
* Load and validate SDK configuration from environment
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadSDKConfig(): SDKConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Get LIT Network configuration
|
|
28
|
+
*/
|
|
29
|
+
export declare function getLitNetworkConfig(networkName: LitNetwork): LitNetwork;
|
|
30
|
+
/**
|
|
31
|
+
* Environment-aware console logging
|
|
32
|
+
*/
|
|
33
|
+
export declare function envLog(message: string, ...args: any[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Validate SDK environment requirements
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateSDKEnvironment(requirements: {
|
|
38
|
+
requiresRealLitTesting?: boolean;
|
|
39
|
+
requiresPrivateKey?: boolean;
|
|
40
|
+
}): SDKConfig;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Environment Configuration for Diamond Hands SDK - Browser Version
|
|
4
|
+
* Browser-compatible environment handling without Node.js dependencies
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getCurrentEnvironment = getCurrentEnvironment;
|
|
8
|
+
exports.loadSDKConfig = loadSDKConfig;
|
|
9
|
+
exports.getLitNetworkConfig = getLitNetworkConfig;
|
|
10
|
+
exports.envLog = envLog;
|
|
11
|
+
exports.validateSDKEnvironment = validateSDKEnvironment;
|
|
12
|
+
// Browser environment variable access
|
|
13
|
+
function getEnv(key, defaultValue) {
|
|
14
|
+
// Try window environment (if set by app)
|
|
15
|
+
if (typeof window !== "undefined") {
|
|
16
|
+
// Check for Vite environment variables on window
|
|
17
|
+
const viteEnv = window.VITE_ENV || {};
|
|
18
|
+
if (viteEnv[`VITE_${key}`])
|
|
19
|
+
return viteEnv[`VITE_${key}`];
|
|
20
|
+
if (viteEnv[key])
|
|
21
|
+
return viteEnv[key];
|
|
22
|
+
// Check for general environment variables on window
|
|
23
|
+
const env = window.__ENV__ || {};
|
|
24
|
+
if (env[key])
|
|
25
|
+
return env[key];
|
|
26
|
+
}
|
|
27
|
+
return defaultValue;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the current environment from environment variables
|
|
31
|
+
*/
|
|
32
|
+
function getCurrentEnvironment() {
|
|
33
|
+
const network = (getEnv("LIT_NETWORK") || "datil-test");
|
|
34
|
+
// Map LIT_NETWORK to environment names - both are valid networks now
|
|
35
|
+
if (network === "datil-test") {
|
|
36
|
+
return "datil-test";
|
|
37
|
+
}
|
|
38
|
+
else if (network === "datil") {
|
|
39
|
+
return "datil-test"; // Map datil to datil-test environment for consistency
|
|
40
|
+
}
|
|
41
|
+
return "datil-test"; // Default fallback
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Load and validate SDK configuration from environment
|
|
45
|
+
*/
|
|
46
|
+
function loadSDKConfig() {
|
|
47
|
+
// Get environment
|
|
48
|
+
const environment = getCurrentEnvironment();
|
|
49
|
+
// Load environment variables with environment-aware defaults
|
|
50
|
+
const litNetwork = (getEnv("LIT_NETWORK") || "datil-test");
|
|
51
|
+
const realLitTesting = getEnv("REAL_LIT_TESTING") === "true";
|
|
52
|
+
const debugMode = getEnv("DEBUG_SDK") === "true" || environment === "datil-test";
|
|
53
|
+
const runRealIntegrationTests = getEnv("RUN_REAL_INTEGRATION_TESTS") === "true";
|
|
54
|
+
const litRelayUrl = getEnv("LIT_RELAY_URL");
|
|
55
|
+
// Environment-specific defaults
|
|
56
|
+
const ethRpcUrl = environment === "datil-test"
|
|
57
|
+
? getEnv("ETH_RPC_URL") || "https://rpc.ankr.com/eth"
|
|
58
|
+
: getEnv("ETH_RPC_URL") || "https://rpc.ankr.com/eth";
|
|
59
|
+
const polygonRpcUrl = environment === "datil-test"
|
|
60
|
+
? getEnv("POLYGON_RPC_URL") || "https://rpc.ankr.com/polygon"
|
|
61
|
+
: getEnv("POLYGON_RPC_URL") || "https://rpc.ankr.com/polygon";
|
|
62
|
+
const pkpMintPrivateKey = getEnv("PKP_MINT_PRIVATE_KEY");
|
|
63
|
+
// Validate LIT network
|
|
64
|
+
const validNetworks = ["datil-test", "datil"];
|
|
65
|
+
if (!validNetworks.includes(litNetwork)) {
|
|
66
|
+
throw new Error(`Invalid LIT_NETWORK: ${litNetwork}. Must be one of: ${validNetworks.join(", ")}`);
|
|
67
|
+
}
|
|
68
|
+
const config = {
|
|
69
|
+
environment,
|
|
70
|
+
litNetwork,
|
|
71
|
+
realLitTesting,
|
|
72
|
+
debugMode,
|
|
73
|
+
runRealIntegrationTests,
|
|
74
|
+
ethRpcUrl,
|
|
75
|
+
polygonRpcUrl,
|
|
76
|
+
};
|
|
77
|
+
if (litRelayUrl)
|
|
78
|
+
config.litRelayUrl = litRelayUrl;
|
|
79
|
+
if (pkpMintPrivateKey)
|
|
80
|
+
config.pkpMintPrivateKey = pkpMintPrivateKey;
|
|
81
|
+
return config;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get LIT Network configuration
|
|
85
|
+
*/
|
|
86
|
+
function getLitNetworkConfig(networkName) {
|
|
87
|
+
// With dh-lit-ops, we can return the network name directly
|
|
88
|
+
return networkName;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Environment-aware console logging
|
|
92
|
+
*/
|
|
93
|
+
function envLog(message, ...args) {
|
|
94
|
+
const config = loadSDKConfig();
|
|
95
|
+
if (config.debugMode) {
|
|
96
|
+
console.log(`[SDK:${config.environment.toUpperCase()}] ${message}`, ...args);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Validate SDK environment requirements
|
|
101
|
+
*/
|
|
102
|
+
function validateSDKEnvironment(requirements) {
|
|
103
|
+
const config = loadSDKConfig();
|
|
104
|
+
if (requirements.requiresRealLitTesting && !config.realLitTesting) {
|
|
105
|
+
throw new Error("REAL_LIT_TESTING=true is required for this operation");
|
|
106
|
+
}
|
|
107
|
+
if (requirements.requiresPrivateKey && !config.pkpMintPrivateKey) {
|
|
108
|
+
throw new Error("PKP_MINT_PRIVATE_KEY environment variable is required for this operation");
|
|
109
|
+
}
|
|
110
|
+
return config;
|
|
111
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment Configuration for Diamond Hands SDK
|
|
3
|
+
* Loads and validates environment variables with multi-path support
|
|
4
|
+
*/
|
|
5
|
+
import { LitNetwork } from "@gvnrdao/dh-lit-ops";
|
|
6
|
+
export type EnvironmentName = "datil-test" | "datil";
|
|
7
|
+
export interface SDKConfig {
|
|
8
|
+
environment: EnvironmentName;
|
|
9
|
+
litNetwork: LitNetwork;
|
|
10
|
+
realLitTesting: boolean;
|
|
11
|
+
debugMode: boolean;
|
|
12
|
+
runRealIntegrationTests: boolean;
|
|
13
|
+
litRelayUrl?: string;
|
|
14
|
+
ethRpcUrl: string;
|
|
15
|
+
polygonRpcUrl: string;
|
|
16
|
+
pkpMintPrivateKey?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the current environment from environment variables
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCurrentEnvironment(): EnvironmentName;
|
|
22
|
+
/**
|
|
23
|
+
* Load and validate SDK configuration from environment
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadSDKConfig(): SDKConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Get LIT Network configuration
|
|
28
|
+
*/
|
|
29
|
+
export declare function getLitNetworkConfig(networkName: LitNetwork): LitNetwork;
|
|
30
|
+
/**
|
|
31
|
+
* Environment-aware console logging
|
|
32
|
+
*/
|
|
33
|
+
export declare function envLog(message: string, ...args: any[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Validate SDK environment requirements
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateSDKEnvironment(requirements: {
|
|
38
|
+
requiresRealLitTesting?: boolean;
|
|
39
|
+
requiresPrivateKey?: boolean;
|
|
40
|
+
}): SDKConfig;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Environment Configuration for Diamond Hands SDK
|
|
4
|
+
* Loads and validates environment variables with multi-path support
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.getCurrentEnvironment = getCurrentEnvironment;
|
|
41
|
+
exports.loadSDKConfig = loadSDKConfig;
|
|
42
|
+
exports.getLitNetworkConfig = getLitNetworkConfig;
|
|
43
|
+
exports.envLog = envLog;
|
|
44
|
+
exports.validateSDKEnvironment = validateSDKEnvironment;
|
|
45
|
+
const dotenv_1 = require("dotenv");
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
// Load environment from multiple possible locations
|
|
48
|
+
const possibleEnvPaths = [
|
|
49
|
+
".env",
|
|
50
|
+
path.join(__dirname, "../../.env"),
|
|
51
|
+
path.join(__dirname, "../../../.env"),
|
|
52
|
+
".datil", // Support for .datil files
|
|
53
|
+
path.join(__dirname, "../../.datil"),
|
|
54
|
+
path.join(__dirname, "../../../.datil"),
|
|
55
|
+
];
|
|
56
|
+
for (const envPath of possibleEnvPaths) {
|
|
57
|
+
try {
|
|
58
|
+
(0, dotenv_1.config)({ path: envPath });
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
// Silently continue if file doesn't exist
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the current environment from environment variables
|
|
66
|
+
*/
|
|
67
|
+
function getCurrentEnvironment() {
|
|
68
|
+
const network = (process.env.LIT_NETWORK || "datil-test");
|
|
69
|
+
// Map LIT_NETWORK to environment names - both are valid networks now
|
|
70
|
+
if (network === "datil-test") {
|
|
71
|
+
return "datil-test";
|
|
72
|
+
}
|
|
73
|
+
else if (network === "datil") {
|
|
74
|
+
return "datil-test"; // Map datil to datil-test environment for consistency
|
|
75
|
+
}
|
|
76
|
+
return "datil-test"; // Default fallback
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Load and validate SDK configuration from environment
|
|
80
|
+
*/
|
|
81
|
+
function loadSDKConfig() {
|
|
82
|
+
// Get environment
|
|
83
|
+
const environment = getCurrentEnvironment();
|
|
84
|
+
// Load environment variables with environment-aware defaults
|
|
85
|
+
const litNetwork = (process.env.LIT_NETWORK || "datil-test");
|
|
86
|
+
const realLitTesting = process.env.REAL_LIT_TESTING === "true";
|
|
87
|
+
const debugMode = process.env.DEBUG_SDK === "true" || environment === "datil-test";
|
|
88
|
+
const runRealIntegrationTests = process.env.RUN_REAL_INTEGRATION_TESTS === "true";
|
|
89
|
+
const litRelayUrl = process.env.LIT_RELAY_URL;
|
|
90
|
+
// Environment-specific defaults
|
|
91
|
+
const ethRpcUrl = environment === "datil-test"
|
|
92
|
+
? process.env.ETH_RPC_URL || "https://rpc.ankr.com/eth"
|
|
93
|
+
: process.env.ETH_RPC_URL || "https://rpc.ankr.com/eth";
|
|
94
|
+
const polygonRpcUrl = environment === "datil-test"
|
|
95
|
+
? process.env.POLYGON_RPC_URL || "https://rpc.ankr.com/polygon"
|
|
96
|
+
: process.env.POLYGON_RPC_URL || "https://rpc.ankr.com/polygon";
|
|
97
|
+
const pkpMintPrivateKey = process.env.PKP_MINT_PRIVATE_KEY;
|
|
98
|
+
// Validate LIT network
|
|
99
|
+
const validNetworks = ["datil-test", "datil"];
|
|
100
|
+
if (!validNetworks.includes(litNetwork)) {
|
|
101
|
+
throw new Error(`Invalid LIT_NETWORK: ${litNetwork}. Must be one of: ${validNetworks.join(", ")}`);
|
|
102
|
+
}
|
|
103
|
+
const config = {
|
|
104
|
+
environment,
|
|
105
|
+
litNetwork,
|
|
106
|
+
realLitTesting,
|
|
107
|
+
debugMode,
|
|
108
|
+
runRealIntegrationTests,
|
|
109
|
+
ethRpcUrl,
|
|
110
|
+
polygonRpcUrl,
|
|
111
|
+
};
|
|
112
|
+
if (litRelayUrl)
|
|
113
|
+
config.litRelayUrl = litRelayUrl;
|
|
114
|
+
if (pkpMintPrivateKey)
|
|
115
|
+
config.pkpMintPrivateKey = pkpMintPrivateKey;
|
|
116
|
+
return config;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get LIT Network configuration
|
|
120
|
+
*/
|
|
121
|
+
function getLitNetworkConfig(networkName) {
|
|
122
|
+
// With dh-lit-ops, we can return the network name directly
|
|
123
|
+
return networkName;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Environment-aware console logging
|
|
127
|
+
*/
|
|
128
|
+
function envLog(message, ...args) {
|
|
129
|
+
const config = loadSDKConfig();
|
|
130
|
+
if (config.debugMode) {
|
|
131
|
+
console.log(`[SDK:${config.environment.toUpperCase()}] ${message}`, ...args);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Validate SDK environment requirements
|
|
136
|
+
*/
|
|
137
|
+
function validateSDKEnvironment(requirements) {
|
|
138
|
+
const config = loadSDKConfig();
|
|
139
|
+
if (requirements.requiresRealLitTesting && !config.realLitTesting) {
|
|
140
|
+
throw new Error("REAL_LIT_TESTING=true is required for this operation");
|
|
141
|
+
}
|
|
142
|
+
if (requirements.requiresPrivateKey && !config.pkpMintPrivateKey) {
|
|
143
|
+
throw new Error("PKP_MINT_PRIVATE_KEY environment variable is required for this operation");
|
|
144
|
+
}
|
|
145
|
+
return config;
|
|
146
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Configuration Constants
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_NETWORKS: {
|
|
5
|
+
readonly ETHEREUM_MAINNET: "https://eth-mainnet.g.alchemy.com/v2/";
|
|
6
|
+
readonly ETHEREUM_SEPOLIA: "https://eth-sepolia.g.alchemy.com/v2/";
|
|
7
|
+
readonly POLYGON_MAINNET: "https://polygon-mainnet.g.alchemy.com/v2/";
|
|
8
|
+
readonly LOCAL_HARDHAT: "http://localhost:8545";
|
|
9
|
+
};
|
|
10
|
+
export declare const DEFAULT_LIT_NETWORKS: {
|
|
11
|
+
readonly DATIL_TEST: "datil-test";
|
|
12
|
+
readonly DATIL: "datil";
|
|
13
|
+
};
|
|
14
|
+
export declare const SDK_DEFAULTS: {
|
|
15
|
+
readonly SESSION_EXPIRATION_MINUTES: 60;
|
|
16
|
+
readonly TRANSACTION_TIMEOUT_MS: 30000;
|
|
17
|
+
readonly RETRY_ATTEMPTS: 3;
|
|
18
|
+
readonly DEBUG: false;
|
|
19
|
+
};
|
|
20
|
+
export declare const SDK_ERROR_MESSAGES: {
|
|
21
|
+
readonly NOT_INITIALIZED: "SDK not initialized. Call initialize() first.";
|
|
22
|
+
readonly INVALID_CONFIG: "Invalid SDK configuration provided.";
|
|
23
|
+
readonly NETWORK_ERROR: "Network connection error occurred.";
|
|
24
|
+
readonly TRANSACTION_FAILED: "Transaction failed to execute.";
|
|
25
|
+
readonly PKP_CREATION_FAILED: "PKP creation failed.";
|
|
26
|
+
readonly SIGNATURE_INVALID: "Invalid signature provided.";
|
|
27
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK Configuration Constants
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SDK_ERROR_MESSAGES = exports.SDK_DEFAULTS = exports.DEFAULT_LIT_NETWORKS = exports.DEFAULT_NETWORKS = void 0;
|
|
7
|
+
// Default network configurations
|
|
8
|
+
exports.DEFAULT_NETWORKS = {
|
|
9
|
+
ETHEREUM_MAINNET: "https://eth-mainnet.g.alchemy.com/v2/",
|
|
10
|
+
ETHEREUM_SEPOLIA: "https://eth-sepolia.g.alchemy.com/v2/",
|
|
11
|
+
POLYGON_MAINNET: "https://polygon-mainnet.g.alchemy.com/v2/",
|
|
12
|
+
LOCAL_HARDHAT: "http://localhost:8545",
|
|
13
|
+
};
|
|
14
|
+
// Default LIT networks
|
|
15
|
+
exports.DEFAULT_LIT_NETWORKS = {
|
|
16
|
+
DATIL_TEST: "datil-test",
|
|
17
|
+
DATIL: "datil",
|
|
18
|
+
};
|
|
19
|
+
// SDK Configuration Defaults
|
|
20
|
+
exports.SDK_DEFAULTS = {
|
|
21
|
+
SESSION_EXPIRATION_MINUTES: 60,
|
|
22
|
+
TRANSACTION_TIMEOUT_MS: 30000,
|
|
23
|
+
RETRY_ATTEMPTS: 3,
|
|
24
|
+
DEBUG: false,
|
|
25
|
+
};
|
|
26
|
+
// Error Messages
|
|
27
|
+
exports.SDK_ERROR_MESSAGES = {
|
|
28
|
+
NOT_INITIALIZED: "SDK not initialized. Call initialize() first.",
|
|
29
|
+
INVALID_CONFIG: "Invalid SDK configuration provided.",
|
|
30
|
+
NETWORK_ERROR: "Network connection error occurred.",
|
|
31
|
+
TRANSACTION_FAILED: "Transaction failed to execute.",
|
|
32
|
+
PKP_CREATION_FAILED: "PKP creation failed.",
|
|
33
|
+
SIGNATURE_INVALID: "Invalid signature provided.",
|
|
34
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diamond Hands SDK Constants
|
|
3
|
+
* All constants used in the SDK package
|
|
4
|
+
*
|
|
5
|
+
* Following the golden source pattern with organized chunks
|
|
6
|
+
*/
|
|
7
|
+
export * from "./chunks/sdk-config";
|
|
8
|
+
export * from "./chunks/environment.browser";
|
|
9
|
+
export * from "./chunks/contract-abis";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Diamond Hands SDK Constants
|
|
4
|
+
* All constants used in the SDK package
|
|
5
|
+
*
|
|
6
|
+
* Following the golden source pattern with organized chunks
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
// SDK Configuration Constants
|
|
24
|
+
__exportStar(require("./chunks/sdk-config"), exports);
|
|
25
|
+
// Environment Configuration
|
|
26
|
+
__exportStar(require("./chunks/environment.browser"), exports);
|
|
27
|
+
// Contract Interface Constants
|
|
28
|
+
__exportStar(require("./chunks/contract-abis"), exports);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diamond Hands SDK Package
|
|
3
|
+
* Diamond Hands Protocol - SDK Operations
|
|
4
|
+
*
|
|
5
|
+
* Provides high-level interface for Diamond Hands Protocol operations supporting:
|
|
6
|
+
* - Loan creation with PKP integration
|
|
7
|
+
* - Smart contract interactions
|
|
8
|
+
* - LIT Protocol operations
|
|
9
|
+
*
|
|
10
|
+
* Following the golden source pattern from lit-ops
|
|
11
|
+
*/
|
|
12
|
+
export * from "./interfaces";
|
|
13
|
+
export * from "./constants";
|
|
14
|
+
export * from "./utils";
|
|
15
|
+
export { DiamondHandsSDK } from "./modules/diamond-hands-sdk.module";
|
|
16
|
+
export { ContractInteractionManager } from "./modules/contract-interaction-manager.module";
|
|
17
|
+
export { LoanOperationsManager } from "./modules/loan-operations-manager.module";
|
|
18
|
+
export { PKPIntegrationManager } from "./modules/pkp-integration-manager.module";
|
|
19
|
+
export type { CreateLoanRequest, CreateLoanResult, LoanData, LoansQuery, } from "./interfaces";
|
|
20
|
+
export type { ContractTransactionResult, PositionDetails, ContractCallOptions, } from "./modules/contract-interaction-manager.module";
|
|
21
|
+
export { DiamondHandsSDK as default } from "./modules/diamond-hands-sdk.module";
|