defi-dash-sdk 0.1.0 → 0.1.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 +172 -138
- package/dist/index.d.ts +25 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/index.js +1 -0
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/logger.d.ts +30 -0
- package/dist/lib/utils/logger.d.ts.map +1 -0
- package/dist/lib/utils/logger.js +142 -0
- package/dist/lib/utils/logger.js.map +1 -0
- package/dist/protocols/index.d.ts +7 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js +11 -0
- package/dist/protocols/index.js.map +1 -0
- package/dist/protocols/interface.d.ts +102 -0
- package/dist/protocols/interface.d.ts.map +1 -0
- package/dist/protocols/interface.js +8 -0
- package/dist/protocols/interface.js.map +1 -0
- package/dist/protocols/navi.d.ts +36 -0
- package/dist/protocols/navi.d.ts.map +1 -0
- package/dist/protocols/navi.js +187 -0
- package/dist/protocols/navi.js.map +1 -0
- package/dist/protocols/suilend.d.ts +38 -0
- package/dist/protocols/suilend.d.ts.map +1 -0
- package/dist/protocols/suilend.js +188 -0
- package/dist/protocols/suilend.js.map +1 -0
- package/dist/sdk.d.ts +101 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +297 -0
- package/dist/sdk.js.map +1 -0
- package/dist/strategies/deleverage.d.ts +46 -0
- package/dist/strategies/deleverage.d.ts.map +1 -0
- package/dist/strategies/deleverage.js +115 -0
- package/dist/strategies/deleverage.js.map +1 -0
- package/dist/strategies/index.d.ts +6 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +13 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/leverage.d.ts +43 -0
- package/dist/strategies/leverage.d.ts.map +1 -0
- package/dist/strategies/leverage.js +133 -0
- package/dist/strategies/leverage.js.map +1 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -24
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DeFi Dash SDK - Logging Utilities
|
|
4
|
+
*
|
|
5
|
+
* Common logging functions for test scripts
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.formatAmount = formatAmount;
|
|
9
|
+
exports.formatUsd = formatUsd;
|
|
10
|
+
exports.formatGas = formatGas;
|
|
11
|
+
exports.logHeader = logHeader;
|
|
12
|
+
exports.logSection = logSection;
|
|
13
|
+
exports.logDivider = logDivider;
|
|
14
|
+
exports.logFooter = logFooter;
|
|
15
|
+
exports.logPosition = logPosition;
|
|
16
|
+
exports.logLeverageParams = logLeverageParams;
|
|
17
|
+
exports.logLeveragePreview = logLeveragePreview;
|
|
18
|
+
exports.logStrategyResult = logStrategyResult;
|
|
19
|
+
exports.logWallet = logWallet;
|
|
20
|
+
exports.logBalances = logBalances;
|
|
21
|
+
exports.logSDKInit = logSDKInit;
|
|
22
|
+
const DIVIDER = "─".repeat(55);
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Basic Formatters
|
|
25
|
+
// ============================================================================
|
|
26
|
+
function formatAmount(amount, decimals) {
|
|
27
|
+
const num = Number(amount) / Math.pow(10, decimals);
|
|
28
|
+
return num.toFixed(Math.min(decimals, 6));
|
|
29
|
+
}
|
|
30
|
+
function formatUsd(value) {
|
|
31
|
+
return `$${value.toFixed(2)}`;
|
|
32
|
+
}
|
|
33
|
+
function formatGas(gasUsed) {
|
|
34
|
+
return `${(Number(gasUsed) / 1e9).toFixed(6)} SUI`;
|
|
35
|
+
}
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Section Loggers
|
|
38
|
+
// ============================================================================
|
|
39
|
+
function logHeader(title) {
|
|
40
|
+
console.log(DIVIDER);
|
|
41
|
+
console.log(` ${title}`);
|
|
42
|
+
console.log(DIVIDER);
|
|
43
|
+
}
|
|
44
|
+
function logSection(title) {
|
|
45
|
+
console.log(`\n${title}`);
|
|
46
|
+
console.log(DIVIDER);
|
|
47
|
+
}
|
|
48
|
+
function logDivider() {
|
|
49
|
+
console.log(DIVIDER);
|
|
50
|
+
}
|
|
51
|
+
function logFooter(message = "✨ Done!") {
|
|
52
|
+
console.log("\n" + DIVIDER);
|
|
53
|
+
console.log(` ${message}`);
|
|
54
|
+
console.log(DIVIDER);
|
|
55
|
+
}
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// Position Logging
|
|
58
|
+
// ============================================================================
|
|
59
|
+
function logPosition(position, protocol) {
|
|
60
|
+
console.log(`\n📊 Checking current position on ${protocol}...`);
|
|
61
|
+
if (!position) {
|
|
62
|
+
console.log(" ⚠️ No position found");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const { collateral, debt, netValueUsd } = position;
|
|
66
|
+
console.log(`\n📋 Current Position:`);
|
|
67
|
+
console.log(DIVIDER);
|
|
68
|
+
console.log(` Collateral: ${formatAmount(collateral.amount, collateral.decimals)} ${collateral.symbol}`);
|
|
69
|
+
console.log(` Value: ${formatUsd(collateral.valueUsd)}`);
|
|
70
|
+
console.log(` Debt: ${formatAmount(debt.amount, debt.decimals)} ${debt.symbol}`);
|
|
71
|
+
console.log(` Value: ${formatUsd(debt.valueUsd)}`);
|
|
72
|
+
console.log(` Net Value: ${formatUsd(netValueUsd)}`);
|
|
73
|
+
console.log(DIVIDER);
|
|
74
|
+
}
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Leverage Preview Logging
|
|
77
|
+
// ============================================================================
|
|
78
|
+
function logLeverageParams(params) {
|
|
79
|
+
console.log("\n📈 Leverage Preview:");
|
|
80
|
+
console.log(DIVIDER);
|
|
81
|
+
console.log(` Protocol: ${params.protocol}`);
|
|
82
|
+
console.log(` Deposit Asset: ${params.depositAsset}`);
|
|
83
|
+
console.log(` Deposit Amount: ${params.depositAmount}`);
|
|
84
|
+
console.log(` Multiplier: ${params.multiplier}x`);
|
|
85
|
+
}
|
|
86
|
+
function logLeveragePreview(preview) {
|
|
87
|
+
console.log(DIVIDER);
|
|
88
|
+
console.log(` Initial Equity: ${formatUsd(preview.initialEquityUsd)}`);
|
|
89
|
+
console.log(` Flash Loan: ${(Number(preview.flashLoanUsdc) / 1e6).toFixed(2)} USDC`);
|
|
90
|
+
console.log(` Total Position: ${formatUsd(preview.totalPositionUsd)}`);
|
|
91
|
+
console.log(` Total Debt: ${formatUsd(preview.debtUsd)}`);
|
|
92
|
+
console.log(` Position LTV: ${preview.ltvPercent.toFixed(1)}%`);
|
|
93
|
+
console.log(` Liquidation Price: $${preview.liquidationPrice.toLocaleString()}`);
|
|
94
|
+
console.log(` Price Drop Buffer: ${preview.priceDropBuffer.toFixed(1)}%`);
|
|
95
|
+
console.log(DIVIDER);
|
|
96
|
+
}
|
|
97
|
+
// ============================================================================
|
|
98
|
+
// Strategy Result Logging
|
|
99
|
+
// ============================================================================
|
|
100
|
+
function logStrategyResult(result, strategyName, isDryRun = true) {
|
|
101
|
+
const mode = isDryRun ? "DRY RUN" : "EXECUTION";
|
|
102
|
+
console.log(`\n🔧 Executing ${strategyName} strategy (${mode})...`);
|
|
103
|
+
if (result.success) {
|
|
104
|
+
console.log(" ✅ " + (isDryRun ? "Dry run successful!" : "Execution successful!"));
|
|
105
|
+
if (result.txDigest) {
|
|
106
|
+
console.log(` 📝 TX: ${result.txDigest}`);
|
|
107
|
+
}
|
|
108
|
+
if (result.gasUsed) {
|
|
109
|
+
console.log(` ⛽ Gas: ${formatGas(result.gasUsed)}`);
|
|
110
|
+
}
|
|
111
|
+
if (isDryRun) {
|
|
112
|
+
console.log("\n 💡 To execute for real, set dryRun: false");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.error(` ❌ ${mode} failed: ${result.error}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// ============================================================================
|
|
120
|
+
// Wallet Logging
|
|
121
|
+
// ============================================================================
|
|
122
|
+
function logWallet(address) {
|
|
123
|
+
console.log(`\n👤 Wallet: ${address}`);
|
|
124
|
+
}
|
|
125
|
+
function logBalances(balances) {
|
|
126
|
+
console.log("\n💰 Wallet Balances:");
|
|
127
|
+
for (const b of balances) {
|
|
128
|
+
const decimals = b.decimals || 9;
|
|
129
|
+
const formatted = formatAmount(BigInt(b.balance), decimals);
|
|
130
|
+
console.log(` ${b.symbol}: ${formatted}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// ============================================================================
|
|
134
|
+
// SDK Status
|
|
135
|
+
// ============================================================================
|
|
136
|
+
function logSDKInit(success = true) {
|
|
137
|
+
console.log("\n📦 Initializing DefiDash SDK...");
|
|
138
|
+
if (success) {
|
|
139
|
+
console.log(" ✅ SDK initialized");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/lib/utils/logger.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAUH,oCAMC;AAED,8BAEC;AAED,8BAEC;AAMD,8BAIC;AAED,gCAGC;AAED,gCAEC;AAED,8BAIC;AAMD,kCAyBC;AAMD,8CAYC;AAED,gDAcC;AAMD,8CA2BC;AAMD,8BAEC;AAED,kCASC;AAMD,gCAKC;AA7KD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAE/B,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,SAAgB,YAAY,CAC1B,MAAuB,EACvB,QAAgB;IAEhB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CA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MAAM,CAAC,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,SAAgB,UAAU,CAAC,UAAmB,IAAI;IAChD,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocols/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DeFi Dash SDK - Protocol Exports
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NaviAdapter = exports.SuilendAdapter = void 0;
|
|
7
|
+
var suilend_1 = require("./suilend");
|
|
8
|
+
Object.defineProperty(exports, "SuilendAdapter", { enumerable: true, get: function () { return suilend_1.SuilendAdapter; } });
|
|
9
|
+
var navi_1 = require("./navi");
|
|
10
|
+
Object.defineProperty(exports, "NaviAdapter", { enumerable: true, get: function () { return navi_1.NaviAdapter; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocols/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,qCAA2C;AAAlC,yGAAA,cAAc,OAAA;AACvB,+BAAqC;AAA5B,mGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeFi Dash SDK - Lending Protocol Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstract interface for lending protocols (Suilend, Navi, etc.)
|
|
5
|
+
*/
|
|
6
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
8
|
+
import { PositionInfo } from "../types";
|
|
9
|
+
/**
|
|
10
|
+
* Common interface for all lending protocol adapters
|
|
11
|
+
*/
|
|
12
|
+
export interface ILendingProtocol {
|
|
13
|
+
/** Protocol name identifier */
|
|
14
|
+
readonly name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the protocol client
|
|
17
|
+
* Must be called before using other methods
|
|
18
|
+
*/
|
|
19
|
+
initialize(suiClient: SuiClient): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get current lending position for a user
|
|
22
|
+
* @param userAddress - Sui address of the user
|
|
23
|
+
* @returns Position info or null if no position exists
|
|
24
|
+
*/
|
|
25
|
+
getPosition(userAddress: string): Promise<PositionInfo | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Check if user has an existing obligation/position
|
|
28
|
+
* @param userAddress - Sui address of the user
|
|
29
|
+
*/
|
|
30
|
+
hasPosition(userAddress: string): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Deposit collateral into the lending protocol
|
|
33
|
+
* @param tx - Transaction to add deposit command to
|
|
34
|
+
* @param coin - Coin object to deposit
|
|
35
|
+
* @param coinType - Full coin type string
|
|
36
|
+
* @param userAddress - User's address (for obligation lookup)
|
|
37
|
+
*/
|
|
38
|
+
deposit(tx: Transaction, coin: any, coinType: string, userAddress: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Withdraw collateral from the lending protocol
|
|
41
|
+
* @param tx - Transaction to add withdraw command to
|
|
42
|
+
* @param coinType - Full coin type string
|
|
43
|
+
* @param amount - Amount to withdraw (raw units as string)
|
|
44
|
+
* @param userAddress - User's address
|
|
45
|
+
* @returns Withdrawn coin object
|
|
46
|
+
*/
|
|
47
|
+
withdraw(tx: Transaction, coinType: string, amount: string, userAddress: string): Promise<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Borrow from the lending protocol
|
|
50
|
+
* @param tx - Transaction to add borrow command to
|
|
51
|
+
* @param coinType - Full coin type string (e.g., USDC)
|
|
52
|
+
* @param amount - Amount to borrow (raw units as string)
|
|
53
|
+
* @param userAddress - User's address
|
|
54
|
+
* @param skipOracle - Skip oracle refresh (if already done)
|
|
55
|
+
* @returns Borrowed coin object
|
|
56
|
+
*/
|
|
57
|
+
borrow(tx: Transaction, coinType: string, amount: string, userAddress: string, skipOracle?: boolean): Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Repay debt to the lending protocol
|
|
60
|
+
* @param tx - Transaction to add repay command to
|
|
61
|
+
* @param coinType - Full coin type string
|
|
62
|
+
* @param coin - Coin object to use for repayment
|
|
63
|
+
* @param userAddress - User's address
|
|
64
|
+
*/
|
|
65
|
+
repay(tx: Transaction, coinType: string, coin: any, userAddress: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Refresh oracle prices (protocol-specific)
|
|
68
|
+
* Must be called before deposit/borrow operations
|
|
69
|
+
* @param tx - Transaction to add refresh commands to
|
|
70
|
+
* @param coinTypes - Coin types to refresh oracles for
|
|
71
|
+
* @param userAddress - User's address (for obligation lookup)
|
|
72
|
+
*/
|
|
73
|
+
refreshOracles(tx: Transaction, coinTypes: string[], userAddress: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Get reserve/pool info for a coin type
|
|
76
|
+
* @param coinType - Full coin type string
|
|
77
|
+
* @returns Reserve info or undefined
|
|
78
|
+
*/
|
|
79
|
+
getReserveInfo(coinType: string): Promise<ReserveInfo | undefined>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reserve/Pool information
|
|
83
|
+
*/
|
|
84
|
+
export interface ReserveInfo {
|
|
85
|
+
/** Coin type */
|
|
86
|
+
coinType: string;
|
|
87
|
+
/** Token symbol */
|
|
88
|
+
symbol: string;
|
|
89
|
+
/** Token decimals */
|
|
90
|
+
decimals: number;
|
|
91
|
+
/** Reserve/Pool ID */
|
|
92
|
+
id?: string;
|
|
93
|
+
/** Open LTV (loan-to-value) percentage */
|
|
94
|
+
openLtvPct?: number;
|
|
95
|
+
/** Close LTV (liquidation threshold) percentage */
|
|
96
|
+
closeLtvPct?: number;
|
|
97
|
+
/** Current deposit APY */
|
|
98
|
+
depositApy?: number;
|
|
99
|
+
/** Current borrow APY */
|
|
100
|
+
borrowApy?: number;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/protocols/interface.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+BAA+B;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD;;;;OAIG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAE/D;;;OAGG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnD;;;;;;OAMG;IACH,OAAO,CACL,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,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@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/protocols/interface.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeFi Dash SDK - Navi Protocol Adapter
|
|
3
|
+
*
|
|
4
|
+
* Implements ILendingProtocol for Navi
|
|
5
|
+
*/
|
|
6
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
8
|
+
import { ILendingProtocol, ReserveInfo } from "./interface";
|
|
9
|
+
import { PositionInfo } from "../types";
|
|
10
|
+
/**
|
|
11
|
+
* Navi lending protocol adapter
|
|
12
|
+
*/
|
|
13
|
+
export declare class NaviAdapter implements ILendingProtocol {
|
|
14
|
+
readonly name = "navi";
|
|
15
|
+
private suiClient;
|
|
16
|
+
private pools;
|
|
17
|
+
private priceFeeds;
|
|
18
|
+
private initialized;
|
|
19
|
+
initialize(suiClient: SuiClient): Promise<void>;
|
|
20
|
+
private ensureInitialized;
|
|
21
|
+
private getPool;
|
|
22
|
+
private getPriceFeed;
|
|
23
|
+
getPosition(userAddress: string): Promise<PositionInfo | null>;
|
|
24
|
+
hasPosition(userAddress: string): Promise<boolean>;
|
|
25
|
+
deposit(tx: Transaction, coin: any, coinType: string, userAddress: string): Promise<void>;
|
|
26
|
+
withdraw(tx: Transaction, coinType: string, amount: string, userAddress: string): Promise<any>;
|
|
27
|
+
borrow(tx: Transaction, coinType: string, amount: string, userAddress: string, skipOracle?: boolean): Promise<any>;
|
|
28
|
+
repay(tx: Transaction, coinType: string, coin: any, userAddress: string): Promise<void>;
|
|
29
|
+
refreshOracles(tx: Transaction, coinTypes: string[], userAddress: string): Promise<void>;
|
|
30
|
+
getReserveInfo(coinType: string): Promise<ReserveInfo | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Get all available pools
|
|
33
|
+
*/
|
|
34
|
+
getPools(): any[];
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,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,UAAQ,GACjB,OAAO,CAAC,GAAG,CAAC;IAeT,KAAK,CACT,EAAE,EAAE,WAAW,EACf,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC;IAaV,cAAc,CAClB,EAAE,EAAE,WAAW,EACf,SAAS,EAAE,MAAM,EAAE,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC;IAeV,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAexE;;OAEG;IACH,QAAQ;CAIT"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DeFi Dash SDK - Navi Protocol Adapter
|
|
4
|
+
*
|
|
5
|
+
* Implements ILendingProtocol for Navi
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.NaviAdapter = void 0;
|
|
9
|
+
const lending_1 = require("@naviprotocol/lending");
|
|
10
|
+
const types_1 = require("../types");
|
|
11
|
+
const utils_1 = require("../lib/utils");
|
|
12
|
+
const const_1 = require("../lib/suilend/const");
|
|
13
|
+
const sdk_ts_1 = require("@7kprotocol/sdk-ts");
|
|
14
|
+
// Navi SDK returns balances with 9 decimal precision internally
|
|
15
|
+
const NAVI_BALANCE_DECIMALS = 9;
|
|
16
|
+
/**
|
|
17
|
+
* Navi lending protocol adapter
|
|
18
|
+
*/
|
|
19
|
+
class NaviAdapter {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.name = "navi";
|
|
22
|
+
this.pools = [];
|
|
23
|
+
this.priceFeeds = [];
|
|
24
|
+
this.initialized = false;
|
|
25
|
+
}
|
|
26
|
+
async initialize(suiClient) {
|
|
27
|
+
this.suiClient = suiClient;
|
|
28
|
+
// Fetch pools
|
|
29
|
+
const poolsResult = await (0, lending_1.getPools)({ env: "prod" });
|
|
30
|
+
this.pools = Array.isArray(poolsResult)
|
|
31
|
+
? poolsResult
|
|
32
|
+
: Object.values(poolsResult);
|
|
33
|
+
// Fetch price feeds
|
|
34
|
+
this.priceFeeds = await (0, lending_1.getPriceFeeds)({ env: "prod" });
|
|
35
|
+
this.initialized = true;
|
|
36
|
+
}
|
|
37
|
+
ensureInitialized() {
|
|
38
|
+
if (!this.initialized) {
|
|
39
|
+
throw new Error("NaviAdapter not initialized. Call initialize() first.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getPool(coinType) {
|
|
43
|
+
const normalized = (0, utils_1.normalizeCoinType)(coinType);
|
|
44
|
+
return this.pools.find((p) => {
|
|
45
|
+
const poolCoinType = (0, utils_1.normalizeCoinType)(p.coinType ?? p.suiCoinType ?? "");
|
|
46
|
+
return poolCoinType === normalized;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getPriceFeed(coinType) {
|
|
50
|
+
const normalized = (0, utils_1.normalizeCoinType)(coinType);
|
|
51
|
+
return this.priceFeeds.find((f) => (0, utils_1.normalizeCoinType)(f.coinType) === normalized);
|
|
52
|
+
}
|
|
53
|
+
async getPosition(userAddress) {
|
|
54
|
+
this.ensureInitialized();
|
|
55
|
+
const lendingState = await (0, lending_1.getLendingState)(userAddress, { env: "prod" });
|
|
56
|
+
if (lendingState.length === 0)
|
|
57
|
+
return null;
|
|
58
|
+
const activePositions = lendingState.filter((p) => BigInt(p.supplyBalance) > 0 || BigInt(p.borrowBalance) > 0);
|
|
59
|
+
if (activePositions.length === 0)
|
|
60
|
+
return null;
|
|
61
|
+
// Find supply position
|
|
62
|
+
let collateral = null;
|
|
63
|
+
let debt = null;
|
|
64
|
+
for (const pos of activePositions) {
|
|
65
|
+
const poolCoinType = (0, utils_1.normalizeCoinType)(pos.pool.coinType);
|
|
66
|
+
const reserve = (0, const_1.getReserveByCoinType)(poolCoinType);
|
|
67
|
+
const decimals = reserve?.decimals || 9;
|
|
68
|
+
const symbol = reserve?.symbol || poolCoinType.split("::").pop() || "???";
|
|
69
|
+
if (BigInt(pos.supplyBalance) > 0) {
|
|
70
|
+
const amount = BigInt(pos.supplyBalance);
|
|
71
|
+
const price = await (0, sdk_ts_1.getTokenPrice)(poolCoinType);
|
|
72
|
+
collateral = {
|
|
73
|
+
amount,
|
|
74
|
+
symbol,
|
|
75
|
+
coinType: poolCoinType,
|
|
76
|
+
decimals: NAVI_BALANCE_DECIMALS, // Navi uses 9 decimals internally
|
|
77
|
+
valueUsd: (Number(amount) / Math.pow(10, NAVI_BALANCE_DECIMALS)) * price,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (BigInt(pos.borrowBalance) > 0) {
|
|
81
|
+
const rawAmount = BigInt(pos.borrowBalance);
|
|
82
|
+
// Convert from Navi's 9 decimal precision to native decimals
|
|
83
|
+
const amount = rawAmount / BigInt(10 ** (NAVI_BALANCE_DECIMALS - decimals));
|
|
84
|
+
const price = await (0, sdk_ts_1.getTokenPrice)(poolCoinType);
|
|
85
|
+
debt = {
|
|
86
|
+
amount,
|
|
87
|
+
symbol,
|
|
88
|
+
coinType: poolCoinType,
|
|
89
|
+
decimals,
|
|
90
|
+
valueUsd: (Number(amount) / Math.pow(10, decimals)) * price,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!collateral)
|
|
95
|
+
return null;
|
|
96
|
+
const netValueUsd = collateral.valueUsd - (debt?.valueUsd || 0);
|
|
97
|
+
return {
|
|
98
|
+
collateral,
|
|
99
|
+
debt: debt || {
|
|
100
|
+
amount: 0n,
|
|
101
|
+
symbol: "USDC",
|
|
102
|
+
coinType: (0, utils_1.normalizeCoinType)(types_1.USDC_COIN_TYPE),
|
|
103
|
+
decimals: 6,
|
|
104
|
+
valueUsd: 0,
|
|
105
|
+
},
|
|
106
|
+
netValueUsd,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async hasPosition(userAddress) {
|
|
110
|
+
const position = await this.getPosition(userAddress);
|
|
111
|
+
return position !== null;
|
|
112
|
+
}
|
|
113
|
+
async deposit(tx, coin, coinType, userAddress) {
|
|
114
|
+
this.ensureInitialized();
|
|
115
|
+
const pool = this.getPool(coinType);
|
|
116
|
+
if (!pool) {
|
|
117
|
+
throw new Error(`Pool not found for ${coinType}`);
|
|
118
|
+
}
|
|
119
|
+
// Navi's depositCoinPTB expects the coin directly
|
|
120
|
+
await (0, lending_1.depositCoinPTB)(tx, pool, coin, {
|
|
121
|
+
env: "prod",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async withdraw(tx, coinType, amount, userAddress) {
|
|
125
|
+
this.ensureInitialized();
|
|
126
|
+
const pool = this.getPool(coinType);
|
|
127
|
+
if (!pool) {
|
|
128
|
+
throw new Error(`Pool not found for ${coinType}`);
|
|
129
|
+
}
|
|
130
|
+
const withdrawnCoin = await (0, lending_1.withdrawCoinPTB)(tx, pool, Number(amount), { env: "prod" });
|
|
131
|
+
return withdrawnCoin;
|
|
132
|
+
}
|
|
133
|
+
async borrow(tx, coinType, amount, userAddress, skipOracle = false) {
|
|
134
|
+
this.ensureInitialized();
|
|
135
|
+
const pool = this.getPool(coinType);
|
|
136
|
+
if (!pool) {
|
|
137
|
+
throw new Error(`Pool not found for ${coinType}`);
|
|
138
|
+
}
|
|
139
|
+
const borrowedCoin = await (0, lending_1.borrowCoinPTB)(tx, pool, Number(amount), {
|
|
140
|
+
env: "prod",
|
|
141
|
+
});
|
|
142
|
+
return borrowedCoin;
|
|
143
|
+
}
|
|
144
|
+
async repay(tx, coinType, coin, userAddress) {
|
|
145
|
+
this.ensureInitialized();
|
|
146
|
+
const pool = this.getPool(coinType);
|
|
147
|
+
if (!pool) {
|
|
148
|
+
throw new Error(`Pool not found for ${coinType}`);
|
|
149
|
+
}
|
|
150
|
+
await (0, lending_1.repayCoinPTB)(tx, pool, coin, {
|
|
151
|
+
env: "prod",
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async refreshOracles(tx, coinTypes, userAddress) {
|
|
155
|
+
this.ensureInitialized();
|
|
156
|
+
const feedsToUpdate = coinTypes
|
|
157
|
+
.map((ct) => this.getPriceFeed(ct))
|
|
158
|
+
.filter(Boolean);
|
|
159
|
+
if (feedsToUpdate.length > 0) {
|
|
160
|
+
await (0, lending_1.updateOraclePricesPTB)(tx, feedsToUpdate, {
|
|
161
|
+
env: "prod",
|
|
162
|
+
updatePythPriceFeeds: true,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async getReserveInfo(coinType) {
|
|
167
|
+
this.ensureInitialized();
|
|
168
|
+
const pool = this.getPool(coinType);
|
|
169
|
+
if (!pool)
|
|
170
|
+
return undefined;
|
|
171
|
+
const reserve = (0, const_1.getReserveByCoinType)((0, utils_1.normalizeCoinType)(coinType));
|
|
172
|
+
return {
|
|
173
|
+
coinType: pool.coinType,
|
|
174
|
+
symbol: reserve?.symbol || pool.coinType.split("::").pop() || "???",
|
|
175
|
+
decimals: reserve?.decimals || 9,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get all available pools
|
|
180
|
+
*/
|
|
181
|
+
getPools() {
|
|
182
|
+
this.ensureInitialized();
|
|
183
|
+
return this.pools;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.NaviAdapter = NaviAdapter;
|
|
187
|
+
//# sourceMappingURL=navi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navi.js","sourceRoot":"","sources":["../../src/protocols/navi.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH,mDAU+B;AAE/B,oCAAuE;AACvE,wCAAiD;AACjD,gDAA4D;AAC5D,+CAAmD;AAEnD,gEAAgE;AAChE,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC;;GAEG;AACH,MAAa,WAAW;IAAxB;QACW,SAAI,GAAG,MAAM,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AC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,QAAgB;QACnC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAE5B,MAAM,OAAO,GAAG,IAAA,4BAAoB,EAAC,IAAA,yBAAiB,EAAC,QAAQ,CAAC,CAAC,CAAC;QAElE,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK;YACnE,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAC;SACjC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AA9OD,kCA8OC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeFi Dash SDK - Suilend Protocol Adapter
|
|
3
|
+
*
|
|
4
|
+
* Implements ILendingProtocol for Suilend
|
|
5
|
+
*/
|
|
6
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
8
|
+
import { SuilendClient } from "@suilend/sdk";
|
|
9
|
+
import { ILendingProtocol, ReserveInfo } from "./interface";
|
|
10
|
+
import { PositionInfo } from "../types";
|
|
11
|
+
/**
|
|
12
|
+
* Suilend lending protocol adapter
|
|
13
|
+
*/
|
|
14
|
+
export declare class SuilendAdapter implements ILendingProtocol {
|
|
15
|
+
readonly name = "suilend";
|
|
16
|
+
private client;
|
|
17
|
+
private suiClient;
|
|
18
|
+
private initialized;
|
|
19
|
+
initialize(suiClient: SuiClient): Promise<void>;
|
|
20
|
+
private ensureInitialized;
|
|
21
|
+
getPosition(userAddress: string): Promise<PositionInfo | null>;
|
|
22
|
+
hasPosition(userAddress: string): Promise<boolean>;
|
|
23
|
+
deposit(tx: Transaction, coin: any, coinType: string, userAddress: string): Promise<void>;
|
|
24
|
+
withdraw(tx: Transaction, coinType: string, amount: string, userAddress: string): Promise<any>;
|
|
25
|
+
borrow(tx: Transaction, coinType: string, amount: string, userAddress: string, skipOracle?: boolean): Promise<any>;
|
|
26
|
+
repay(tx: Transaction, coinType: string, coin: any, userAddress: string): Promise<void>;
|
|
27
|
+
refreshOracles(tx: Transaction, coinTypes: string[], userAddress: string): Promise<void>;
|
|
28
|
+
getReserveInfo(coinType: string): Promise<ReserveInfo | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Get obligation owner cap info
|
|
31
|
+
*/
|
|
32
|
+
getObligationCap(userAddress: string): Promise<import("@suilend/sdk/_generated/suilend/lending-market/structs").ObligationOwnerCap<string> | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Get the underlying Suilend client for advanced operations
|
|
35
|
+
*/
|
|
36
|
+
getSuilendClient(): SuilendClient;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=suilend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suilend.d.ts","sourceRoot":"","sources":["../../src/protocols/suilend.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,aAAa,EAGd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAiC,MAAM,UAAU,CAAC;AAQvE;;GAEG;AACH,qBAAa,cAAe,YAAW,gBAAgB;IACrD,QAAQ,CAAC,IAAI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