@naviprotocol/lending 2.1.0 → 2.2.0-preview.20261029.f4ae850
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts.map +1 -1
- package/dist/account.js +74 -63
- package/dist/account.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -5
- package/dist/config.js.map +1 -1
- package/dist/emode.d.ts.map +1 -1
- package/dist/emode.js +9 -7
- package/dist/emode.js.map +1 -1
- package/dist/index.js +45 -42
- package/dist/market.d.ts +55 -57
- package/dist/market.d.ts.map +1 -1
- package/dist/market.js +160 -62
- package/dist/market.js.map +1 -1
- package/dist/package.json.js +4 -4
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +2 -2
- package/dist/pool.js.map +1 -1
- package/dist/reward.d.ts.map +1 -1
- package/dist/reward.js +67 -61
- package/dist/reward.js.map +1 -1
- package/package.json +17 -16
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -1,96 +1,99 @@
|
|
|
1
|
-
import { UserPositions as r, getCoins as o, getHealthFactor as a, getHealthFactorPTB as i, getLendingPositions as n, getLendingState as s, getSimulatedHealthFactor as l, getSimulatedHealthFactorPTB as d, getTransactions as
|
|
2
|
-
import { Address as
|
|
1
|
+
import { UserPositions as r, getCoins as o, getHealthFactor as a, getHealthFactorPTB as i, getLendingPositions as n, getLendingState as s, getSimulatedHealthFactor as l, getSimulatedHealthFactorPTB as d, getTransactions as g, mergeCoinsPTB as c, verifyHealthFactorPTB as P } from "./account.js";
|
|
2
|
+
import { Address as f, FlashLoanAssetConfig as C, IncentiveAPYInfo as T, IncentivePoolInfo as B, IncentivePoolInfoByPhase as m, OracleInfo as h, ReserveDataInfo as A, UserStateInfo as I } from "./bcs.js";
|
|
3
3
|
import { DEFAULT_CACHE_TIME as v, getConfig as F } from "./config.js";
|
|
4
|
-
import { filterPriceFeeds as L, getPriceFeeds as
|
|
5
|
-
import { flashloanPTB as R, getAllFlashLoanAssets as O, getFlashLoanAsset as
|
|
4
|
+
import { filterPriceFeeds as L, getPriceFeeds as M, getPythStalePriceFeedId as S, getPythStalePriceFeedIdV2 as y, updateOraclePriceBeforeUserOperationPTB as E, updateOraclePricesPTB as U, updatePythPriceFeeds as w } from "./oracle.js";
|
|
5
|
+
import { flashloanPTB as R, getAllFlashLoanAssets as O, getFlashLoanAsset as k, repayFlashLoanPTB as H } from "./flashloan.js";
|
|
6
6
|
import { liquidatePTB as D } from "./liquidate.js";
|
|
7
7
|
import { PoolOperator as G, borrowCoinPTB as q, depositCoinPTB as z, getBorrowFee as K, getFees as Q, getPool as V, getPools as Y, getStats as j, repayCoinPTB as J, withdrawCoinPTB as W } from "./pool.js";
|
|
8
8
|
import { claimLendingRewardsPTB as Z, getUserAvailableLendingRewards as $, getUserClaimedRewardHistory as ee, getUserTotalClaimedReward as te, summaryLendingRewards as re } from "./reward.js";
|
|
9
9
|
import { devInspectTransaction as ae, normalizeCoinType as ie, parsePoolUID as ne, parseTxValue as se, withCache as le, withSingleton as de } from "./utils.js";
|
|
10
|
-
import { createAccountCapPTB as
|
|
11
|
-
import { createEModeCapPTB as
|
|
12
|
-
import { DEFAULT_MARKET_IDENTITY as Ae, MARKETS as Ie, Market as ue, getMarket as ve, getMarketConfig as Fe,
|
|
13
|
-
import { NaviMissingGraphQLClientError as
|
|
14
|
-
import { SuiPriceServiceConnection as
|
|
15
|
-
import { buildNaviOpenApiUrl as
|
|
10
|
+
import { createAccountCapPTB as ce, getAccountCapOwnerPTB as Pe } from "./account-cap.js";
|
|
11
|
+
import { createEModeCapPTB as fe, emodeIdentityId as Ce, enterEModePTB as Te, exitEModePTB as Be, getUserEModeCaps as me } from "./emode.js";
|
|
12
|
+
import { DEFAULT_MARKET_IDENTITY as Ae, MARKETS as Ie, Market as ue, getMarket as ve, getMarketConfig as Fe, getMarketConfigs as xe, getMarkets as Le, loadMarketConfigs as Me, registerMarketConfigs as Se } from "./market.js";
|
|
13
|
+
import { NaviMissingGraphQLClientError as Ee, PUBLIC_MAINNET_GRPC_URL as Ue, createNaviLegacyJsonRpcClient as we, createNaviSuiClient as Ne, createNaviSuiClientBundle as Re, getAddressBalance as Oe, getCoinObjectOnlyBalance as ke, listAddressBalances as He, normalizeAddressBalance as _e, requireNaviGraphQLClient as De } from "./sui.js";
|
|
14
|
+
import { SuiPriceServiceConnection as Ge, SuiPythClient as qe } from "./pyth.js";
|
|
15
|
+
import { buildNaviOpenApiUrl as Ke, configureNaviSdk as Qe, mergeServiceHeaders as Ve, resolveNaviOpenApiEndpoint as Ye } from "./services.js";
|
|
16
16
|
export {
|
|
17
|
-
|
|
17
|
+
f as Address,
|
|
18
18
|
v as DEFAULT_CACHE_TIME,
|
|
19
19
|
Ae as DEFAULT_MARKET_IDENTITY,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
C as FlashLoanAssetConfig,
|
|
21
|
+
T as IncentiveAPYInfo,
|
|
22
22
|
B as IncentivePoolInfo,
|
|
23
23
|
m as IncentivePoolInfoByPhase,
|
|
24
24
|
Ie as MARKETS,
|
|
25
25
|
ue as Market,
|
|
26
|
-
|
|
26
|
+
Ee as NaviMissingGraphQLClientError,
|
|
27
27
|
h as OracleInfo,
|
|
28
|
-
|
|
28
|
+
Ue as PUBLIC_MAINNET_GRPC_URL,
|
|
29
29
|
G as PoolOperator,
|
|
30
30
|
A as ReserveDataInfo,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
Ge as SuiPriceServiceConnection,
|
|
32
|
+
qe as SuiPythClient,
|
|
33
33
|
r as UserPositions,
|
|
34
34
|
I as UserStateInfo,
|
|
35
35
|
q as borrowCoinPTB,
|
|
36
|
-
|
|
36
|
+
Ke as buildNaviOpenApiUrl,
|
|
37
37
|
Z as claimLendingRewardsPTB,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
Qe as configureNaviSdk,
|
|
39
|
+
ce as createAccountCapPTB,
|
|
40
|
+
fe as createEModeCapPTB,
|
|
41
|
+
we as createNaviLegacyJsonRpcClient,
|
|
42
|
+
Ne as createNaviSuiClient,
|
|
43
|
+
Re as createNaviSuiClientBundle,
|
|
44
44
|
z as depositCoinPTB,
|
|
45
45
|
ae as devInspectTransaction,
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
Ce as emodeIdentityId,
|
|
47
|
+
Te as enterEModePTB,
|
|
48
48
|
Be as exitEModePTB,
|
|
49
49
|
L as filterPriceFeeds,
|
|
50
50
|
R as flashloanPTB,
|
|
51
51
|
Pe as getAccountCapOwnerPTB,
|
|
52
|
-
|
|
52
|
+
Oe as getAddressBalance,
|
|
53
53
|
O as getAllFlashLoanAssets,
|
|
54
54
|
K as getBorrowFee,
|
|
55
|
-
|
|
55
|
+
ke as getCoinObjectOnlyBalance,
|
|
56
56
|
o as getCoins,
|
|
57
57
|
F as getConfig,
|
|
58
58
|
Q as getFees,
|
|
59
|
-
|
|
59
|
+
k as getFlashLoanAsset,
|
|
60
60
|
a as getHealthFactor,
|
|
61
61
|
i as getHealthFactorPTB,
|
|
62
62
|
n as getLendingPositions,
|
|
63
63
|
s as getLendingState,
|
|
64
64
|
ve as getMarket,
|
|
65
65
|
Fe as getMarketConfig,
|
|
66
|
-
xe as
|
|
66
|
+
xe as getMarketConfigs,
|
|
67
|
+
Le as getMarkets,
|
|
67
68
|
V as getPool,
|
|
68
69
|
Y as getPools,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
M as getPriceFeeds,
|
|
71
|
+
S as getPythStalePriceFeedId,
|
|
72
|
+
y as getPythStalePriceFeedIdV2,
|
|
72
73
|
l as getSimulatedHealthFactor,
|
|
73
74
|
d as getSimulatedHealthFactorPTB,
|
|
74
75
|
j as getStats,
|
|
75
|
-
|
|
76
|
+
g as getTransactions,
|
|
76
77
|
$ as getUserAvailableLendingRewards,
|
|
77
78
|
ee as getUserClaimedRewardHistory,
|
|
78
79
|
me as getUserEModeCaps,
|
|
79
80
|
te as getUserTotalClaimedReward,
|
|
80
81
|
D as liquidatePTB,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
He as listAddressBalances,
|
|
83
|
+
Me as loadMarketConfigs,
|
|
84
|
+
c as mergeCoinsPTB,
|
|
85
|
+
Ve as mergeServiceHeaders,
|
|
86
|
+
_e as normalizeAddressBalance,
|
|
85
87
|
ie as normalizeCoinType,
|
|
86
88
|
ne as parsePoolUID,
|
|
87
89
|
se as parseTxValue,
|
|
90
|
+
Se as registerMarketConfigs,
|
|
88
91
|
J as repayCoinPTB,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
H as repayFlashLoanPTB,
|
|
93
|
+
De as requireNaviGraphQLClient,
|
|
94
|
+
Ye as resolveNaviOpenApiEndpoint,
|
|
92
95
|
re as summaryLendingRewards,
|
|
93
|
-
|
|
96
|
+
E as updateOraclePriceBeforeUserOperationPTB,
|
|
94
97
|
U as updateOraclePricesPTB,
|
|
95
98
|
w as updatePythPriceFeeds,
|
|
96
99
|
P as verifyHealthFactorPTB,
|
package/dist/market.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarketIdentity, EnvOption, CacheOption, EMode, MarketConfig, Pool, EModePool } from './types.js';
|
|
1
|
+
import { MarketIdentity, EnvOption, CacheOption, EMode, MarketConfig, Pool, EModePool, ServiceOption } from './types.js';
|
|
2
2
|
|
|
3
3
|
export declare const DEFAULT_MARKET_IDENTITY = "main";
|
|
4
4
|
export declare const MARKETS: {
|
|
@@ -22,42 +22,47 @@ export declare const MARKETS: {
|
|
|
22
22
|
key: string;
|
|
23
23
|
name: string;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
'sui-usdc': {
|
|
26
26
|
id: number;
|
|
27
27
|
key: string;
|
|
28
28
|
name: string;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
'wbtc-usdc': {
|
|
31
31
|
id: number;
|
|
32
32
|
key: string;
|
|
33
33
|
name: string;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
'xbtc-usdc': {
|
|
36
36
|
id: number;
|
|
37
37
|
key: string;
|
|
38
38
|
name: string;
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
'vsui-usdc': {
|
|
41
41
|
id: number;
|
|
42
42
|
key: string;
|
|
43
43
|
name: string;
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
'vsui-sui': {
|
|
46
46
|
id: number;
|
|
47
47
|
key: string;
|
|
48
48
|
name: string;
|
|
49
49
|
};
|
|
50
|
-
|
|
50
|
+
'hasui-sui': {
|
|
51
51
|
id: number;
|
|
52
52
|
key: string;
|
|
53
53
|
name: string;
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
'high-usdc': {
|
|
56
56
|
id: number;
|
|
57
57
|
key: string;
|
|
58
58
|
name: string;
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
'eearn-usdc': {
|
|
61
|
+
id: number;
|
|
62
|
+
key: string;
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
'hbtc-usdc': {
|
|
61
66
|
id: number;
|
|
62
67
|
key: string;
|
|
63
68
|
name: string;
|
|
@@ -88,55 +93,48 @@ export declare class Market {
|
|
|
88
93
|
getEModePools(emodeId: number): EModePool[];
|
|
89
94
|
private checkMarket;
|
|
90
95
|
}
|
|
91
|
-
export
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
key: string;
|
|
102
|
-
name: string;
|
|
103
|
-
} | {
|
|
104
|
-
id: number;
|
|
105
|
-
key: string;
|
|
106
|
-
name: string;
|
|
107
|
-
} | {
|
|
108
|
-
id: number;
|
|
109
|
-
key: string;
|
|
110
|
-
name: string;
|
|
111
|
-
} | {
|
|
112
|
-
id: number;
|
|
113
|
-
key: string;
|
|
114
|
-
name: string;
|
|
115
|
-
} | {
|
|
116
|
-
id: number;
|
|
117
|
-
key: string;
|
|
118
|
-
name: string;
|
|
119
|
-
} | {
|
|
120
|
-
id: number;
|
|
121
|
-
key: string;
|
|
122
|
-
name: string;
|
|
123
|
-
} | {
|
|
124
|
-
id: number;
|
|
125
|
-
key: string;
|
|
126
|
-
name: string;
|
|
127
|
-
} | {
|
|
128
|
-
id: number;
|
|
129
|
-
key: string;
|
|
130
|
-
name: string;
|
|
131
|
-
} | {
|
|
132
|
-
id: number;
|
|
133
|
-
key: string;
|
|
134
|
-
name: string;
|
|
135
|
-
} | {
|
|
136
|
-
id: number;
|
|
137
|
-
key: string;
|
|
138
|
-
name: string;
|
|
96
|
+
export type MarketEnv = EnvOption['env'];
|
|
97
|
+
export type MarketConfigsOptions = Partial<EnvOption & CacheOption & ServiceOption>;
|
|
98
|
+
export type RegisterMarketConfigsOptions = {
|
|
99
|
+
env?: MarketEnv;
|
|
100
|
+
/**
|
|
101
|
+
* The caller is itself the source of truth for this env's market list (e.g.
|
|
102
|
+
* open-api registering its own config). `loadMarketConfigs` then returns the
|
|
103
|
+
* registered list without an HTTP round trip.
|
|
104
|
+
*/
|
|
105
|
+
authoritative?: boolean;
|
|
139
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Replaces the market list of an env with the given configs.
|
|
109
|
+
*
|
|
110
|
+
* Registration only seeds the list: unless `authoritative` is set, a later
|
|
111
|
+
* `loadMarketConfigs` still fetches from open-api and replaces it.
|
|
112
|
+
*/
|
|
113
|
+
export declare const registerMarketConfigs: (configs: MarketConfig[], options?: RegisterMarketConfigsOptions) => MarketConfig[];
|
|
114
|
+
/**
|
|
115
|
+
* Returns the market list of an env: the loaded/registered list when present,
|
|
116
|
+
* otherwise the built-in MARKETS.
|
|
117
|
+
*/
|
|
118
|
+
export declare const getMarketConfigs: (options?: {
|
|
119
|
+
env?: MarketEnv;
|
|
120
|
+
}) => MarketConfig[];
|
|
121
|
+
/**
|
|
122
|
+
* Loads the market list of an env from open-api (`/navi/markets`) and stores
|
|
123
|
+
* it for `getMarketConfigs` / `getMarketConfig`.
|
|
124
|
+
*
|
|
125
|
+
* Never throws: on any failure it keeps whatever the env already has (the
|
|
126
|
+
* built-in MARKETS by default) and logs a warning.
|
|
127
|
+
*/
|
|
128
|
+
export declare const loadMarketConfigs: (options?: MarketConfigsOptions) => Promise<MarketConfig[]>;
|
|
129
|
+
/**
|
|
130
|
+
* Resolves a market by id, key or config. Searches the built-in MARKETS first
|
|
131
|
+
* (unchanged behavior for every existing market), then the loaded or
|
|
132
|
+
* registered list of `options.env`, so a market that only exists in open-api
|
|
133
|
+
* resolves too. Without an env it searches every env's list.
|
|
134
|
+
*/
|
|
135
|
+
export declare const getMarketConfig: (marketIdentity: MarketIdentity, options?: {
|
|
136
|
+
env?: MarketEnv;
|
|
137
|
+
}) => MarketConfig;
|
|
140
138
|
export declare const getMarkets: (markets: MarketIdentity[], options?: Partial<EnvOption & CacheOption>) => Promise<Market[]>;
|
|
141
139
|
export declare const getMarket: (market: MarketIdentity, options?: Partial<EnvOption & CacheOption>) => Promise<Market>;
|
|
142
140
|
//# sourceMappingURL=market.d.ts.map
|
package/dist/market.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../src/market.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,WAAW,EACX,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,SAAS,
|
|
1
|
+
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../src/market.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,WAAW,EACX,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,aAAa,EACd,MAAM,SAAS,CAAA;AAMhB,eAAO,MAAM,uBAAuB,SAAS,CAAA;AAE7C,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkEnB,CAAA;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,QAAQ,CAA8B;IAC9C,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,CAAK;IAC3B,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAK;IAC7B,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,CAAK;IACrC,oBAAoB,EAAE,IAAI,EAAE,CAAK;IACjC,oBAAoB,EAAE,IAAI,EAAE,CAAK;IAEjC,OAAO,CAAC,SAAS,CAGhB;IAED,IAAI,QAAQ;;;MAEX;gBAEW,cAAc,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE;IAKzD,OAAO,CAAC,SAAS;IA2DV,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAKvC,mBAAmB,CACxB,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,OAAO,CAAA;QACpB,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,GACA,IAAI,EAAE;IAwBF,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE;IAwBlD,OAAO,CAAC,WAAW;CAapB;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;AAExC,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,SAAS,GAAG,WAAW,GAAG,aAAa,CAAC,CAAA;AAEnF,MAAM,MAAM,4BAA4B,GAAG;IACzC,GAAG,CAAC,EAAE,SAAS,CAAA;IACf;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAoFD;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAS,YAAY,EAAE,EACvB,UAAU,4BAA4B,KACrC,YAAY,EAYd,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU;IAAE,GAAG,CAAC,EAAE,SAAS,CAAA;CAAE,KAAG,YAAY,EAG5E,CAAA;AA0CD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,oBAAoB,KAC7B,OAAO,CAAC,YAAY,EAAE,CA2BxB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,gBAAgB,cAAc,EAAE,UAAU;IAAE,GAAG,CAAC,EAAE,SAAS,CAAA;CAAE,iBAmB5F,CAAA;AAED,eAAO,MAAM,UAAU,YAGR,cAAc,EAAE,YACf,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC,KACzC,OAAO,CAAC,MAAM,EAAE,CAiBtB,CAAA;AAED,eAAO,MAAM,SAAS,WAEH,cAAc,YAAY,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC,KAAG,OAAO,CAAC,MAAM,CAK7F,CAAA"}
|
package/dist/market.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { withCache as
|
|
2
|
-
import { getPools as
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { withCache as y, getPoolsMap as w, getEmodesMap as b, withSingleton as g, requestHeaders as A } from "./utils.js";
|
|
2
|
+
import { getPools as U } from "./pool.js";
|
|
3
|
+
import E from "bignumber.js";
|
|
4
|
+
import $ from "./package.json.js";
|
|
5
|
+
import { resolveNaviOpenApiEndpoint as _, buildNaviOpenApiUrl as D, mergeServiceHeaders as B } from "./services.js";
|
|
6
|
+
const L = "main", N = {
|
|
5
7
|
main: {
|
|
6
8
|
id: 0,
|
|
7
9
|
key: "main",
|
|
@@ -61,101 +63,197 @@ const C = "main", w = {
|
|
|
61
63
|
id: 11,
|
|
62
64
|
key: "eearn-usdc",
|
|
63
65
|
name: "eEARN / USDC Market"
|
|
66
|
+
},
|
|
67
|
+
"hbtc-usdc": {
|
|
68
|
+
id: 12,
|
|
69
|
+
key: "hbtc-usdc",
|
|
70
|
+
name: "hBTC / USDC Market"
|
|
64
71
|
}
|
|
65
72
|
};
|
|
66
|
-
class
|
|
67
|
-
constructor(
|
|
73
|
+
class O {
|
|
74
|
+
constructor(e, s) {
|
|
68
75
|
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
69
76
|
marketTotalSupplyValue: "0",
|
|
70
77
|
marketTotalBorrowValue: "0"
|
|
71
|
-
}, this.config =
|
|
78
|
+
}, this.config = C(e), this.initPools(s);
|
|
72
79
|
}
|
|
73
80
|
get overview() {
|
|
74
81
|
return this._overview;
|
|
75
82
|
}
|
|
76
|
-
initPools(
|
|
77
|
-
const
|
|
78
|
-
let a =
|
|
79
|
-
|
|
80
|
-
if (!this.checkMarket(
|
|
81
|
-
console.warn(`Pool is not in market ${this.config.name}`,
|
|
83
|
+
initPools(e) {
|
|
84
|
+
const s = w(this.pools), n = b(this.emodes), t = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
|
|
85
|
+
let a = E(0), d = E(0);
|
|
86
|
+
e.forEach((r) => {
|
|
87
|
+
if (!this.checkMarket(r.market)) {
|
|
88
|
+
console.warn(`Pool is not in market ${this.config.name}`, r);
|
|
82
89
|
return;
|
|
83
90
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
(
|
|
88
|
-
) && t.add(
|
|
91
|
+
s[r.uniqueId] || this.pools.push(r), r?.emodes?.forEach((c) => {
|
|
92
|
+
n[c.uniqueId] || this.emodes.push(c), c.assets.forEach((m) => {
|
|
93
|
+
m.isDebt && c.assets.find(
|
|
94
|
+
(u) => u.isCollateral && u.ltv > 0 && u.assetId !== r.id
|
|
95
|
+
) && t.add(r.uniqueId), m.isCollateral && c.assets.find((u) => u.isDebt && u.assetId !== r.id) && i.add(r.uniqueId);
|
|
89
96
|
});
|
|
90
|
-
}),
|
|
91
|
-
}), this.poolMap =
|
|
92
|
-
const
|
|
93
|
-
this.emodePools.push(...
|
|
97
|
+
}), d = d.plus(r.poolBorrowValue), a = a.plus(r.poolSupplyValue);
|
|
98
|
+
}), this.poolMap = w(this.pools, "id"), this.emodeMap = b(this.emodes, "emodeId"), this.emodes.forEach((r) => {
|
|
99
|
+
const l = this.getEModePools(r.emodeId);
|
|
100
|
+
this.emodePools.push(...l);
|
|
94
101
|
}), this._overview = {
|
|
95
102
|
marketTotalSupplyValue: a.toString(),
|
|
96
|
-
marketTotalBorrowValue:
|
|
97
|
-
}, this.emodeBorrowablePools = this.pools.filter((
|
|
103
|
+
marketTotalBorrowValue: d.toString()
|
|
104
|
+
}, this.emodeBorrowablePools = this.pools.filter((r) => t.has(r.uniqueId)), this.emodeSupplyablePools = this.pools.filter((r) => i.has(r.uniqueId));
|
|
98
105
|
}
|
|
99
|
-
getEMode(
|
|
100
|
-
return this.emodeMap[
|
|
106
|
+
getEMode(e) {
|
|
107
|
+
return this.emodeMap[e] || null;
|
|
101
108
|
}
|
|
102
|
-
getEModeRelatePools(
|
|
103
|
-
const { collateral:
|
|
104
|
-
return
|
|
105
|
-
typeof
|
|
106
|
-
typeof
|
|
109
|
+
getEModeRelatePools(e, s) {
|
|
110
|
+
const { collateral: n, debt: t, emodeId: i } = s || {}, a = [];
|
|
111
|
+
return e.emodes.forEach((d) => {
|
|
112
|
+
typeof i == "number" && i !== d.emodeId || d.assets.forEach((r) => {
|
|
113
|
+
typeof n == "boolean" && n && r.isCollateral && r.assetId === e.id && a.push(this.poolMap[r.assetId]), typeof t == "boolean" && t && r.isDebt && r.assetId === e.id && a.push(this.poolMap[r.assetId]);
|
|
107
114
|
});
|
|
108
115
|
}), a;
|
|
109
116
|
}
|
|
110
|
-
getEModePools(
|
|
111
|
-
const
|
|
112
|
-
return
|
|
113
|
-
const
|
|
117
|
+
getEModePools(e) {
|
|
118
|
+
const s = this.getEMode(e);
|
|
119
|
+
return s ? s.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
|
|
120
|
+
const i = s.assets.find((a) => a.assetId === t.id);
|
|
114
121
|
return {
|
|
115
122
|
...t,
|
|
116
123
|
emode: {
|
|
117
|
-
...
|
|
118
|
-
emodeId:
|
|
124
|
+
...i,
|
|
125
|
+
emodeId: s.emodeId
|
|
119
126
|
},
|
|
120
127
|
isEMode: !0
|
|
121
128
|
};
|
|
122
129
|
}) : [];
|
|
123
130
|
}
|
|
124
|
-
checkMarket(
|
|
125
|
-
let
|
|
126
|
-
return typeof
|
|
131
|
+
checkMarket(e) {
|
|
132
|
+
let s = !1;
|
|
133
|
+
return typeof e == "number" && e === this.config.id && (s = !0), typeof e == "string" && e === this.config.key && (s = !0), typeof e == "object" && e.id === this.config.id && (s = !0), s;
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
|
|
136
|
+
const v = "prod", R = 1e3 * 60 * 5, S = 5e3, h = "[@naviprotocol/lending]", p = Object.values(N), f = {}, M = /* @__PURE__ */ new Set(), I = (o, e) => typeof e == "number" ? o.id === e : typeof e == "string" ? o.key === e : o.id === e.id && o.key === e.key, V = (o) => typeof o?.id == "number" && typeof o?.key == "string" && !!o.key && typeof o?.name == "string", T = (o) => {
|
|
137
|
+
const e = [], s = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
|
|
138
|
+
return o.forEach((t) => {
|
|
139
|
+
if (!V(t)) {
|
|
140
|
+
console.warn(`${h} Ignoring invalid market config`, t);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (s.has(t.key))
|
|
144
|
+
return;
|
|
145
|
+
const i = p.find((d) => d.key === t.key);
|
|
146
|
+
if (i) {
|
|
147
|
+
i.id !== t.id && console.warn(
|
|
148
|
+
`${h} Market "${t.key}" id ${t.id} conflicts with built-in id ${i.id}; using built-in`
|
|
149
|
+
), s.add(i.key), n.add(i.id), e.push({ id: i.id, key: i.key, name: i.name });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const a = p.find((d) => d.id === t.id) || (n.has(t.id) ? e.find((d) => d.id === t.id) : void 0);
|
|
153
|
+
if (a) {
|
|
154
|
+
console.warn(
|
|
155
|
+
`${h} Ignoring market "${t.key}": id ${t.id} already belongs to "${a.key}"`
|
|
156
|
+
);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
s.add(t.key), n.add(t.id), e.push({ id: t.id, key: t.key, name: t.name });
|
|
160
|
+
}), e;
|
|
161
|
+
}, z = (o, e) => {
|
|
162
|
+
const s = e?.env || v, n = T(o || []);
|
|
163
|
+
return n.length === 0 ? (console.warn(`${h} Ignoring empty market list for env "${s}"`), k({ env: s })) : (f[s] = n, e?.authoritative && M.add(s), n);
|
|
164
|
+
}, k = (o) => {
|
|
165
|
+
const e = o?.env || v;
|
|
166
|
+
return f[e] || p;
|
|
167
|
+
}, q = y(
|
|
168
|
+
g(async (o) => {
|
|
169
|
+
const e = _(o), s = D(
|
|
170
|
+
`/navi/markets?env=${o.env}&sdk=${$.version}`,
|
|
171
|
+
o
|
|
172
|
+
), n = typeof AbortController < "u" ? new AbortController() : void 0;
|
|
173
|
+
let t;
|
|
174
|
+
const i = new Promise((c, m) => {
|
|
175
|
+
t = setTimeout(() => {
|
|
176
|
+
n?.abort(), m(new Error(`Timed out after ${S}ms`));
|
|
177
|
+
}, S);
|
|
178
|
+
}), a = (async () => {
|
|
179
|
+
const c = await fetch(s, {
|
|
180
|
+
headers: B(A, e),
|
|
181
|
+
signal: n?.signal
|
|
182
|
+
});
|
|
183
|
+
if (!c.ok)
|
|
184
|
+
throw new Error(`HTTP ${c.status}`);
|
|
185
|
+
return c.json();
|
|
186
|
+
})();
|
|
187
|
+
a.catch(() => {
|
|
188
|
+
});
|
|
189
|
+
const r = (await Promise.race([a, i]).finally(() => clearTimeout(t)))?.data?.markets;
|
|
190
|
+
if (!Array.isArray(r))
|
|
191
|
+
throw new Error("Invalid /navi/markets response");
|
|
192
|
+
const l = T(r);
|
|
193
|
+
if (l.length === 0)
|
|
194
|
+
throw new Error("Empty /navi/markets response");
|
|
195
|
+
return l;
|
|
196
|
+
})
|
|
197
|
+
), J = async (o) => {
|
|
198
|
+
const e = o?.env || v;
|
|
199
|
+
if (M.has(e))
|
|
200
|
+
return k({ env: e });
|
|
201
|
+
try {
|
|
202
|
+
const s = await q({
|
|
203
|
+
cacheTime: R,
|
|
204
|
+
...o?.services ? { services: o.services } : {},
|
|
205
|
+
...o?.disableCache ? { disableCache: !0 } : {},
|
|
206
|
+
...o?.cacheTime !== void 0 ? { cacheTime: o.cacheTime } : {},
|
|
207
|
+
env: e
|
|
208
|
+
});
|
|
209
|
+
return M.has(e) ? k({ env: e }) : (f[e] = s, s);
|
|
210
|
+
} catch (s) {
|
|
211
|
+
return console.warn(
|
|
212
|
+
`${h} Failed to load markets for env "${e}", using the current list`,
|
|
213
|
+
s
|
|
214
|
+
), k({ env: e });
|
|
215
|
+
}
|
|
216
|
+
}, C = (o, e) => {
|
|
217
|
+
let s = p.find(
|
|
218
|
+
(n) => I(n, o)
|
|
219
|
+
);
|
|
220
|
+
if (!s) {
|
|
221
|
+
const n = e?.env ? [f[e.env]] : Object.values(f);
|
|
222
|
+
for (const t of n)
|
|
223
|
+
if (s = t?.find((i) => I(i, o)), s)
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (!s)
|
|
132
227
|
throw new Error("Market not found");
|
|
133
|
-
return
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
async (
|
|
137
|
-
const
|
|
228
|
+
return s;
|
|
229
|
+
}, F = y(
|
|
230
|
+
g(
|
|
231
|
+
async (o, e) => {
|
|
232
|
+
const s = await U({
|
|
138
233
|
cacheTime: 6e4,
|
|
139
|
-
...
|
|
140
|
-
markets:
|
|
234
|
+
...e,
|
|
235
|
+
markets: o
|
|
141
236
|
});
|
|
142
|
-
return
|
|
143
|
-
const t =
|
|
144
|
-
return new
|
|
237
|
+
return o.map((n) => {
|
|
238
|
+
const t = C(n, { env: e?.env || "prod" }), i = s.filter((a) => a.market === t.key);
|
|
239
|
+
return new O(t, i);
|
|
145
240
|
});
|
|
146
241
|
}
|
|
147
242
|
)
|
|
148
|
-
),
|
|
149
|
-
|
|
150
|
-
async (
|
|
243
|
+
), W = y(
|
|
244
|
+
g(
|
|
245
|
+
async (o, e) => (await F([o], e))[0]
|
|
151
246
|
)
|
|
152
247
|
);
|
|
153
248
|
export {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
249
|
+
L as DEFAULT_MARKET_IDENTITY,
|
|
250
|
+
N as MARKETS,
|
|
251
|
+
O as Market,
|
|
252
|
+
W as getMarket,
|
|
253
|
+
C as getMarketConfig,
|
|
254
|
+
k as getMarketConfigs,
|
|
255
|
+
F as getMarkets,
|
|
256
|
+
J as loadMarketConfigs,
|
|
257
|
+
z as registerMarketConfigs
|
|
160
258
|
};
|
|
161
259
|
//# sourceMappingURL=market.js.map
|