@naviprotocol/lending 2.0.10 → 2.0.11
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -44
- package/dist/package.json.js +1 -1
- package/dist/pool.d.ts +3 -1
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +223 -223
- package/dist/pool.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export * from './liquidate.js';
|
|
|
15
15
|
export * from './pool.js';
|
|
16
16
|
export * from './reward.js';
|
|
17
17
|
export * from './types.js';
|
|
18
|
-
export { withCache, withSingleton, normalizeCoinType, parseTxValue, parsePoolUID } from './utils.js';
|
|
18
|
+
export { withCache, withSingleton, normalizeCoinType, parseTxValue, parsePoolUID, devInspectTransaction } from './utils.js';
|
|
19
19
|
export * from './account-cap.js';
|
|
20
20
|
export * from './emode.js';
|
|
21
21
|
export * from './market.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,WAAW,CAAA;AAGzB,cAAc,OAAO,CAAA;AAGrB,cAAc,UAAU,CAAA;AAGxB,cAAc,UAAU,CAAA;AAGxB,cAAc,aAAa,CAAA;AAG3B,cAAc,aAAa,CAAA;AAG3B,cAAc,QAAQ,CAAA;AAGtB,cAAc,UAAU,CAAA;AAGxB,cAAc,SAAS,CAAA;AAGvB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,WAAW,CAAA;AAGzB,cAAc,OAAO,CAAA;AAGrB,cAAc,UAAU,CAAA;AAGxB,cAAc,UAAU,CAAA;AAGxB,cAAc,aAAa,CAAA;AAG3B,cAAc,aAAa,CAAA;AAG3B,cAAc,QAAQ,CAAA;AAGtB,cAAc,UAAU,CAAA;AAGxB,cAAc,SAAS,CAAA;AAGvB,OAAO,EACL,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAGhB,cAAc,eAAe,CAAA;AAE7B,cAAc,SAAS,CAAA;AAEvB,cAAc,UAAU,CAAA;AAExB,cAAc,OAAO,CAAA;AAErB,cAAc,QAAQ,CAAA;AAEtB,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,YAAY,CAAA;AACnB,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,68 +1,69 @@
|
|
|
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
|
|
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 c, mergeCoinsPTB as g, verifyHealthFactorPTB as P } from "./account.js";
|
|
2
2
|
import { Address as T, FlashLoanAssetConfig as f, IncentiveAPYInfo as C, IncentivePoolInfo as B, IncentivePoolInfoByPhase as m, OracleInfo as h, ReserveDataInfo as A, UserStateInfo as I } from "./bcs.js";
|
|
3
|
-
import { DEFAULT_CACHE_TIME as
|
|
3
|
+
import { DEFAULT_CACHE_TIME as v, getConfig as F } from "./config.js";
|
|
4
4
|
import { filterPriceFeeds as L, getPriceFeeds as S, getPythStalePriceFeedId as y, getPythStalePriceFeedIdV2 as E, updateOraclePriceBeforeUserOperationPTB as M, updateOraclePricesPTB as U, updatePythPriceFeeds as w } from "./oracle.js";
|
|
5
5
|
import { flashloanPTB as R, getAllFlashLoanAssets as O, getFlashLoanAsset as H, repayFlashLoanPTB as _ } 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
|
-
import {
|
|
9
|
+
import { devInspectTransaction as ae, normalizeCoinType as ie, parsePoolUID as ne, parseTxValue as se, withCache as le, withSingleton as de } from "./utils.js";
|
|
10
10
|
import { createAccountCapPTB as ge, getAccountCapOwnerPTB as Pe } from "./account-cap.js";
|
|
11
|
-
import { createEModeCapPTB as
|
|
12
|
-
import { DEFAULT_MARKET_IDENTITY as
|
|
13
|
-
import { NaviMissingGraphQLClientError as
|
|
14
|
-
import { SuiPriceServiceConnection as
|
|
15
|
-
import { buildNaviOpenApiUrl as
|
|
11
|
+
import { createEModeCapPTB as Te, emodeIdentityId as fe, enterEModePTB as Ce, 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, getMarkets as xe } from "./market.js";
|
|
13
|
+
import { NaviMissingGraphQLClientError as Se, PUBLIC_MAINNET_GRPC_URL as ye, createNaviLegacyJsonRpcClient as Ee, createNaviSuiClient as Me, createNaviSuiClientBundle as Ue, getAddressBalance as we, getCoinObjectOnlyBalance as Ne, listAddressBalances as Re, normalizeAddressBalance as Oe, requireNaviGraphQLClient as He } from "./sui.js";
|
|
14
|
+
import { SuiPriceServiceConnection as ke, SuiPythClient as De } from "./pyth.js";
|
|
15
|
+
import { buildNaviOpenApiUrl as Ge, configureNaviSdk as qe, mergeServiceHeaders as ze, resolveNaviOpenApiEndpoint as Ke } from "./services.js";
|
|
16
16
|
export {
|
|
17
17
|
T as Address,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
v as DEFAULT_CACHE_TIME,
|
|
19
|
+
Ae as DEFAULT_MARKET_IDENTITY,
|
|
20
20
|
f as FlashLoanAssetConfig,
|
|
21
21
|
C as IncentiveAPYInfo,
|
|
22
22
|
B as IncentivePoolInfo,
|
|
23
23
|
m as IncentivePoolInfoByPhase,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
Ie as MARKETS,
|
|
25
|
+
ue as Market,
|
|
26
|
+
Se as NaviMissingGraphQLClientError,
|
|
27
27
|
h as OracleInfo,
|
|
28
|
-
|
|
28
|
+
ye as PUBLIC_MAINNET_GRPC_URL,
|
|
29
29
|
G as PoolOperator,
|
|
30
30
|
A as ReserveDataInfo,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
ke as SuiPriceServiceConnection,
|
|
32
|
+
De as SuiPythClient,
|
|
33
33
|
r as UserPositions,
|
|
34
34
|
I as UserStateInfo,
|
|
35
35
|
q as borrowCoinPTB,
|
|
36
|
-
|
|
36
|
+
Ge as buildNaviOpenApiUrl,
|
|
37
37
|
Z as claimLendingRewardsPTB,
|
|
38
|
-
|
|
38
|
+
qe as configureNaviSdk,
|
|
39
39
|
ge as createAccountCapPTB,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
Te as createEModeCapPTB,
|
|
41
|
+
Ee as createNaviLegacyJsonRpcClient,
|
|
42
|
+
Me as createNaviSuiClient,
|
|
43
|
+
Ue as createNaviSuiClientBundle,
|
|
44
44
|
z as depositCoinPTB,
|
|
45
|
-
|
|
46
|
-
fe as
|
|
47
|
-
Ce as
|
|
45
|
+
ae as devInspectTransaction,
|
|
46
|
+
fe as emodeIdentityId,
|
|
47
|
+
Ce as enterEModePTB,
|
|
48
|
+
Be as exitEModePTB,
|
|
48
49
|
L as filterPriceFeeds,
|
|
49
50
|
R as flashloanPTB,
|
|
50
51
|
Pe as getAccountCapOwnerPTB,
|
|
51
|
-
|
|
52
|
+
we as getAddressBalance,
|
|
52
53
|
O as getAllFlashLoanAssets,
|
|
53
54
|
K as getBorrowFee,
|
|
54
|
-
|
|
55
|
+
Ne as getCoinObjectOnlyBalance,
|
|
55
56
|
o as getCoins,
|
|
56
|
-
|
|
57
|
+
F as getConfig,
|
|
57
58
|
Q as getFees,
|
|
58
59
|
H as getFlashLoanAsset,
|
|
59
60
|
a as getHealthFactor,
|
|
60
61
|
i as getHealthFactorPTB,
|
|
61
62
|
n as getLendingPositions,
|
|
62
63
|
s as getLendingState,
|
|
63
|
-
|
|
64
|
+
ve as getMarket,
|
|
64
65
|
Fe as getMarketConfig,
|
|
65
|
-
|
|
66
|
+
xe as getMarkets,
|
|
66
67
|
V as getPool,
|
|
67
68
|
Y as getPools,
|
|
68
69
|
S as getPriceFeeds,
|
|
@@ -71,30 +72,30 @@ export {
|
|
|
71
72
|
l as getSimulatedHealthFactor,
|
|
72
73
|
d as getSimulatedHealthFactorPTB,
|
|
73
74
|
j as getStats,
|
|
74
|
-
|
|
75
|
+
c as getTransactions,
|
|
75
76
|
$ as getUserAvailableLendingRewards,
|
|
76
77
|
ee as getUserClaimedRewardHistory,
|
|
77
|
-
|
|
78
|
+
me as getUserEModeCaps,
|
|
78
79
|
te as getUserTotalClaimedReward,
|
|
79
80
|
D as liquidatePTB,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
Re as listAddressBalances,
|
|
82
|
+
g as mergeCoinsPTB,
|
|
83
|
+
ze as mergeServiceHeaders,
|
|
84
|
+
Oe as normalizeAddressBalance,
|
|
85
|
+
ie as normalizeCoinType,
|
|
86
|
+
ne as parsePoolUID,
|
|
87
|
+
se as parseTxValue,
|
|
87
88
|
J as repayCoinPTB,
|
|
88
89
|
_ as repayFlashLoanPTB,
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
He as requireNaviGraphQLClient,
|
|
91
|
+
Ke as resolveNaviOpenApiEndpoint,
|
|
91
92
|
re as summaryLendingRewards,
|
|
92
93
|
M as updateOraclePriceBeforeUserOperationPTB,
|
|
93
94
|
U as updateOraclePricesPTB,
|
|
94
95
|
w as updatePythPriceFeeds,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
P as verifyHealthFactorPTB,
|
|
97
|
+
le as withCache,
|
|
98
|
+
de as withSingleton,
|
|
98
99
|
W as withdrawCoinPTB
|
|
99
100
|
};
|
|
100
101
|
//# sourceMappingURL=index.js.map
|
package/dist/package.json.js
CHANGED
package/dist/pool.d.ts
CHANGED
|
@@ -26,7 +26,9 @@ export declare enum PoolOperator {
|
|
|
26
26
|
* @param options - Optional environment and caching options
|
|
27
27
|
* @returns Promise<Pool[]> - Array of all available lending pools
|
|
28
28
|
*/
|
|
29
|
-
export declare const getPools: (options?: Partial<EnvOption & CacheOption & MarketsOption & ServiceOption
|
|
29
|
+
export declare const getPools: (options?: Partial<EnvOption & CacheOption & MarketsOption & ServiceOption & {
|
|
30
|
+
pools: string[];
|
|
31
|
+
}>) => Promise<Pool[]>;
|
|
30
32
|
/**
|
|
31
33
|
* Gets information for a specific lending pool
|
|
32
34
|
*
|
package/dist/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,IAAI,EACJ,eAAe,EACf,SAAS,EACT,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,YAAY,EAEZ,aAAa,EACb,aA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O,CAAC,SAAS,GAAG,gBAAgB,GAAG,YAAY,GAAG,aAAa,CAAC,GAC7E,OAAO,CAAC,2BAA2B,CAAC,CAgGtC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,WAAW,EACf,UAAU,EAAE,eAAe,EAC3B,UAAU,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE,OAAO,CACf,SAAS,GACP,gBAAgB,GAChB,aAAa,GACb,YAAY,GAAG;IACb,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAA;CACnC,CACJ,GACA,OAAO,CAAC,WAAW,GAAG,iBAAiB,CAAC,CAqE1C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,aAGT,OAAO,CAAC,SAAS,GAAG,WAAW,GAAG,eAAe,GAAG,eAAe,GAAG,YAAY,CAAC,KAC5F,OAAO,CAAC,MAAM,CA0CpB,CAAA"}
|
package/dist/pool.js
CHANGED
|
@@ -1,391 +1,391 @@
|
|
|
1
1
|
import { DEFAULT_CACHE_TIME as g, getConfig as d } from "./config.js";
|
|
2
|
-
import { withCache as y, withSingleton as w, requestHeaders as C, parsePoolUID as
|
|
2
|
+
import { withCache as y, withSingleton as w, requestHeaders as C, parsePoolUID as I, normalizeCoinType as m, parseTxValue as u, suiClient as U, devInspectTransaction as R, parseDevInspectResult as F, getSuiObject as W } from "./utils.js";
|
|
3
3
|
import { resolveNaviOpenApiEndpoint as f, buildNaviOpenApiUrl as h, mergeServiceHeaders as _ } from "./services.js";
|
|
4
|
-
import { Transaction as
|
|
4
|
+
import { Transaction as M } from "@mysten/sui/transactions";
|
|
5
5
|
import p from "bignumber.js";
|
|
6
|
-
import { bcs as
|
|
6
|
+
import { bcs as P } from "@mysten/sui/bcs";
|
|
7
7
|
import T from "./package.json.js";
|
|
8
|
-
import { MARKETS as
|
|
9
|
-
var
|
|
10
|
-
const
|
|
8
|
+
import { MARKETS as q, getMarketConfig as B, DEFAULT_MARKET_IDENTITY as S } from "./market.js";
|
|
9
|
+
var H = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(H || {});
|
|
10
|
+
const K = y(
|
|
11
11
|
w(
|
|
12
12
|
async (e) => {
|
|
13
|
-
const a = (e?.markets || [
|
|
13
|
+
const a = (e?.markets || [q.main]).map((n) => B(n)), c = f(e), r = (e?.pools || []).join(","), t = h(
|
|
14
14
|
`/navi/pools?env=${e?.env || "prod"}&sdk=${T.version}&market=${a.map(
|
|
15
|
-
(
|
|
16
|
-
)}`,
|
|
15
|
+
(n) => n.key
|
|
16
|
+
)}${r ? "&pools=" + r : ""}`,
|
|
17
17
|
e
|
|
18
|
-
), o = await fetch(
|
|
19
|
-
(
|
|
18
|
+
), o = await fetch(t, { headers: _(C, c) }).then(
|
|
19
|
+
(n) => n.json()
|
|
20
20
|
);
|
|
21
|
-
return o.data.forEach((
|
|
22
|
-
const
|
|
23
|
-
const j =
|
|
24
|
-
return
|
|
25
|
-
}).filter((v) => !!v.assets.find((j) => j.assetId ===
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
p(
|
|
29
|
-
p(
|
|
30
|
-
).shiftedBy(-9).decimalPlaces(
|
|
31
|
-
|
|
21
|
+
return o.data.forEach((n) => {
|
|
22
|
+
const l = o.meta.emodes.filter((v) => {
|
|
23
|
+
const j = B(v.marketId);
|
|
24
|
+
return n.market === j.key && v.isActive;
|
|
25
|
+
}).filter((v) => !!v.assets.find((j) => j.assetId === n.id));
|
|
26
|
+
n.emodes = l;
|
|
27
|
+
const s = p(n.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(n.token.decimals, p.ROUND_DOWN).toString(), A = p(n.borrowedAmount).shiftedBy(-9).decimalPlaces(n.token.decimals, p.ROUND_DOWN).toString(), $ = p(s).multipliedBy(n.oracle.price).toString(), D = p(A).multipliedBy(n.oracle.price).toString(), k = p(n.supplyCapCeiling).shiftedBy(-27).decimalPlaces(n.token.decimals, p.ROUND_DOWN).toString(), V = p.max(
|
|
28
|
+
p(n.borrowedAmount),
|
|
29
|
+
p(n.validBorrowAmount)
|
|
30
|
+
).shiftedBy(-9).decimalPlaces(n.token.decimals, p.ROUND_DOWN).toString(), E = p(k).multipliedBy(n.oracle.price).toString(), N = p(V).multipliedBy(n.oracle.price).toString();
|
|
31
|
+
n.poolSupplyAmount = s, n.poolBorrowAmount = A, n.poolSupplyValue = $, n.poolBorrowValue = D, n.poolSupplyCapAmount = k, n.poolBorrowCapAmount = V, n.poolSupplyCapValue = E, n.poolBorrowCapValue = N;
|
|
32
32
|
}), o.data;
|
|
33
33
|
}
|
|
34
34
|
)
|
|
35
35
|
);
|
|
36
36
|
async function b(e, a) {
|
|
37
|
-
let
|
|
37
|
+
let c = a?.market;
|
|
38
38
|
if (typeof e == "string") {
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const o = I(e);
|
|
40
|
+
o && (c = o.marketKey, e = o.poolId);
|
|
41
41
|
}
|
|
42
|
-
const
|
|
42
|
+
const r = await K({
|
|
43
43
|
...a,
|
|
44
|
-
markets: [
|
|
44
|
+
markets: [c || S],
|
|
45
45
|
cacheTime: g
|
|
46
46
|
});
|
|
47
47
|
if (typeof e == "object")
|
|
48
48
|
return e;
|
|
49
|
-
const
|
|
50
|
-
if (!
|
|
49
|
+
const t = r.find((o) => typeof e == "string" ? m(o.suiCoinType) === m(e) : typeof e == "number" ? o.id === e : !1);
|
|
50
|
+
if (!t)
|
|
51
51
|
throw new Error("Pool not found");
|
|
52
|
-
return
|
|
52
|
+
return t.isDeprecated && console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`), t;
|
|
53
53
|
}
|
|
54
|
-
const
|
|
54
|
+
const Z = y(
|
|
55
55
|
w(async (e) => {
|
|
56
|
-
const a = f(e),
|
|
57
|
-
return (await fetch(
|
|
56
|
+
const a = f(e), c = h(`/navi/stats?sdk=${T.version}`, e);
|
|
57
|
+
return (await fetch(c, {
|
|
58
58
|
headers: _(C, a)
|
|
59
|
-
}).then((
|
|
59
|
+
}).then((t) => t.json())).data;
|
|
60
60
|
})
|
|
61
|
-
),
|
|
61
|
+
), x = y(
|
|
62
62
|
w(
|
|
63
63
|
async (e) => {
|
|
64
|
-
const a = f(e),
|
|
65
|
-
return await fetch(
|
|
64
|
+
const a = f(e), c = h(`/navi/fee?sdk=${T.version}`, e);
|
|
65
|
+
return await fetch(c, {
|
|
66
66
|
headers: _(C, a)
|
|
67
|
-
}).then((
|
|
67
|
+
}).then((t) => t.json());
|
|
68
68
|
}
|
|
69
69
|
)
|
|
70
70
|
);
|
|
71
|
-
async function
|
|
72
|
-
const
|
|
73
|
-
...
|
|
71
|
+
async function ee(e, a, c, r) {
|
|
72
|
+
const t = await d({
|
|
73
|
+
...r,
|
|
74
74
|
cacheTime: g
|
|
75
|
-
}),
|
|
76
|
-
if (
|
|
77
|
-
throw new Error(`The lending pool for coinType ${
|
|
78
|
-
if (m(
|
|
79
|
-
if (!
|
|
75
|
+
}), o = await b(a, r), n = r?.market || S, i = r?.env || "prod";
|
|
76
|
+
if (o?.deprecatedAt && Date.now() > o.deprecatedAt)
|
|
77
|
+
throw new Error(`The lending pool for coinType ${o.suiCoinType} has been deprecated.`);
|
|
78
|
+
if (m(o.suiCoinType) === m("0x2::sui::SUI") && typeof c == "object" && c?.$kind === "GasCoin") {
|
|
79
|
+
if (!r?.amount)
|
|
80
80
|
throw new Error("Amount is required for sui coin");
|
|
81
|
-
|
|
81
|
+
c = e.splitCoins(c, [r.amount]);
|
|
82
82
|
}
|
|
83
83
|
let l;
|
|
84
|
-
return typeof
|
|
84
|
+
return typeof r?.amount < "u" ? l = u(r.amount, e.pure.u64) : l = e.moveCall({
|
|
85
85
|
target: "0x2::coin::value",
|
|
86
|
-
arguments: [u(
|
|
87
|
-
typeArguments: [
|
|
88
|
-
}),
|
|
89
|
-
target: `${
|
|
86
|
+
arguments: [u(c, e.object)],
|
|
87
|
+
typeArguments: [o.suiCoinType]
|
|
88
|
+
}), r?.accountCap ? e.moveCall({
|
|
89
|
+
target: `${t.package}::incentive_v3::deposit_with_account_cap`,
|
|
90
90
|
arguments: [
|
|
91
91
|
e.object("0x06"),
|
|
92
|
-
e.object(
|
|
93
|
-
e.object(
|
|
94
|
-
e.pure.u8(
|
|
95
|
-
u(
|
|
96
|
-
e.object(
|
|
97
|
-
e.object(
|
|
98
|
-
u(
|
|
92
|
+
e.object(t.storage),
|
|
93
|
+
e.object(o.contract.pool),
|
|
94
|
+
e.pure.u8(o.id),
|
|
95
|
+
u(c, e.object),
|
|
96
|
+
e.object(t.incentiveV2),
|
|
97
|
+
e.object(t.incentiveV3),
|
|
98
|
+
u(r.accountCap, e.object)
|
|
99
99
|
],
|
|
100
|
-
typeArguments: [
|
|
100
|
+
typeArguments: [o.suiCoinType]
|
|
101
101
|
}) : e.moveCall({
|
|
102
|
-
target: `${
|
|
102
|
+
target: `${t.package}::incentive_v3::entry_deposit`,
|
|
103
103
|
arguments: [
|
|
104
104
|
e.object("0x06"),
|
|
105
|
-
e.object(
|
|
106
|
-
e.object(
|
|
107
|
-
e.pure.u8(
|
|
108
|
-
u(
|
|
105
|
+
e.object(t.storage),
|
|
106
|
+
e.object(o.contract.pool),
|
|
107
|
+
e.pure.u8(o.id),
|
|
108
|
+
u(c, e.object),
|
|
109
109
|
l,
|
|
110
|
-
e.object(
|
|
111
|
-
e.object(
|
|
110
|
+
e.object(t.incentiveV2),
|
|
111
|
+
e.object(t.incentiveV3)
|
|
112
112
|
],
|
|
113
|
-
typeArguments: [
|
|
114
|
-
}),
|
|
115
|
-
target: `${
|
|
116
|
-
arguments: [e.object(
|
|
113
|
+
typeArguments: [o.suiCoinType]
|
|
114
|
+
}), t.version === 2 && o.token.symbol === "SUI" && i === "prod" && n === "main" && e.moveCall({
|
|
115
|
+
target: `${t.package}::pool::refresh_stake`,
|
|
116
|
+
arguments: [e.object(o.contract.pool), e.object("0x05")]
|
|
117
117
|
}), e;
|
|
118
118
|
}
|
|
119
|
-
async function
|
|
120
|
-
const
|
|
121
|
-
...
|
|
119
|
+
async function te(e, a, c, r) {
|
|
120
|
+
const t = await d({
|
|
121
|
+
...r,
|
|
122
122
|
cacheTime: g
|
|
123
|
-
}),
|
|
123
|
+
}), o = await b(a, r), n = u(c, e.pure.u64);
|
|
124
124
|
let i;
|
|
125
|
-
if (
|
|
126
|
-
if (
|
|
125
|
+
if (t.version === 1)
|
|
126
|
+
if (r?.accountCap) {
|
|
127
127
|
const [s] = e.moveCall({
|
|
128
|
-
target: `${
|
|
128
|
+
target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
|
|
129
129
|
arguments: [
|
|
130
130
|
e.object("0x06"),
|
|
131
|
-
e.object(
|
|
132
|
-
e.object(
|
|
133
|
-
e.object(
|
|
134
|
-
e.pure.u8(
|
|
135
|
-
|
|
136
|
-
e.object(
|
|
137
|
-
e.object(
|
|
138
|
-
u(
|
|
131
|
+
e.object(t.priceOracle),
|
|
132
|
+
e.object(t.storage),
|
|
133
|
+
e.object(o.contract.pool),
|
|
134
|
+
e.pure.u8(o.id),
|
|
135
|
+
n,
|
|
136
|
+
e.object(t.incentiveV2),
|
|
137
|
+
e.object(t.incentiveV3),
|
|
138
|
+
u(r.accountCap, e.object)
|
|
139
139
|
],
|
|
140
|
-
typeArguments: [
|
|
140
|
+
typeArguments: [o.suiCoinType]
|
|
141
141
|
});
|
|
142
142
|
i = s;
|
|
143
143
|
} else {
|
|
144
144
|
const [s] = e.moveCall({
|
|
145
|
-
target: `${
|
|
145
|
+
target: `${t.package}::incentive_v3::withdraw`,
|
|
146
146
|
arguments: [
|
|
147
147
|
e.object("0x06"),
|
|
148
|
-
e.object(
|
|
149
|
-
e.object(
|
|
150
|
-
e.object(
|
|
151
|
-
e.pure.u8(
|
|
152
|
-
|
|
153
|
-
e.object(
|
|
154
|
-
e.object(
|
|
148
|
+
e.object(t.priceOracle),
|
|
149
|
+
e.object(t.storage),
|
|
150
|
+
e.object(o.contract.pool),
|
|
151
|
+
e.pure.u8(o.id),
|
|
152
|
+
n,
|
|
153
|
+
e.object(t.incentiveV2),
|
|
154
|
+
e.object(t.incentiveV3)
|
|
155
155
|
],
|
|
156
|
-
typeArguments: [
|
|
156
|
+
typeArguments: [o.suiCoinType]
|
|
157
157
|
});
|
|
158
158
|
i = s;
|
|
159
159
|
}
|
|
160
|
-
else if (
|
|
160
|
+
else if (r?.accountCap) {
|
|
161
161
|
const [s] = e.moveCall({
|
|
162
|
-
target: `${
|
|
162
|
+
target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
163
163
|
arguments: [
|
|
164
164
|
e.object("0x06"),
|
|
165
|
-
e.object(
|
|
166
|
-
e.object(
|
|
167
|
-
e.object(
|
|
168
|
-
e.pure.u8(
|
|
169
|
-
|
|
170
|
-
e.object(
|
|
171
|
-
e.object(
|
|
172
|
-
u(
|
|
165
|
+
e.object(t.priceOracle),
|
|
166
|
+
e.object(t.storage),
|
|
167
|
+
e.object(o.contract.pool),
|
|
168
|
+
e.pure.u8(o.id),
|
|
169
|
+
n,
|
|
170
|
+
e.object(t.incentiveV2),
|
|
171
|
+
e.object(t.incentiveV3),
|
|
172
|
+
u(r.accountCap, e.object),
|
|
173
173
|
e.object("0x05")
|
|
174
174
|
],
|
|
175
|
-
typeArguments: [
|
|
175
|
+
typeArguments: [o.suiCoinType]
|
|
176
176
|
});
|
|
177
177
|
i = s;
|
|
178
178
|
} else {
|
|
179
179
|
const [s] = e.moveCall({
|
|
180
|
-
target: `${
|
|
180
|
+
target: `${t.package}::incentive_v3::withdraw_v2`,
|
|
181
181
|
arguments: [
|
|
182
182
|
e.object("0x06"),
|
|
183
|
-
e.object(
|
|
184
|
-
e.object(
|
|
185
|
-
e.object(
|
|
186
|
-
e.pure.u8(
|
|
187
|
-
|
|
188
|
-
e.object(
|
|
189
|
-
e.object(
|
|
183
|
+
e.object(t.priceOracle),
|
|
184
|
+
e.object(t.storage),
|
|
185
|
+
e.object(o.contract.pool),
|
|
186
|
+
e.pure.u8(o.id),
|
|
187
|
+
n,
|
|
188
|
+
e.object(t.incentiveV2),
|
|
189
|
+
e.object(t.incentiveV3),
|
|
190
190
|
e.object("0x05")
|
|
191
191
|
],
|
|
192
|
-
typeArguments: [
|
|
192
|
+
typeArguments: [o.suiCoinType]
|
|
193
193
|
});
|
|
194
194
|
i = s;
|
|
195
195
|
}
|
|
196
196
|
return e.moveCall({
|
|
197
197
|
target: "0x2::coin::from_balance",
|
|
198
198
|
arguments: [i],
|
|
199
|
-
typeArguments: [
|
|
199
|
+
typeArguments: [o.suiCoinType]
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
|
-
async function
|
|
203
|
-
const
|
|
204
|
-
...
|
|
202
|
+
async function oe(e, a, c, r) {
|
|
203
|
+
const t = await d({
|
|
204
|
+
...r,
|
|
205
205
|
cacheTime: g
|
|
206
|
-
}),
|
|
207
|
-
if (
|
|
208
|
-
throw new Error(`The lending pool for coinType ${
|
|
209
|
-
const
|
|
206
|
+
}), o = await b(a, r);
|
|
207
|
+
if (o?.deprecatedAt && Date.now() > o.deprecatedAt)
|
|
208
|
+
throw new Error(`The lending pool for coinType ${o.suiCoinType} has been deprecated.`);
|
|
209
|
+
const n = u(c, e.pure.u64);
|
|
210
210
|
let i;
|
|
211
|
-
if (
|
|
212
|
-
if (
|
|
211
|
+
if (t.version === 1)
|
|
212
|
+
if (r?.accountCap) {
|
|
213
213
|
const [s] = e.moveCall({
|
|
214
|
-
target: `${
|
|
214
|
+
target: `${t.package}::incentive_v3::borrow_with_account_cap`,
|
|
215
215
|
arguments: [
|
|
216
216
|
e.object("0x06"),
|
|
217
|
-
e.object(
|
|
218
|
-
e.object(
|
|
219
|
-
e.object(
|
|
220
|
-
e.pure.u8(
|
|
221
|
-
|
|
222
|
-
e.object(
|
|
223
|
-
e.object(
|
|
224
|
-
u(
|
|
217
|
+
e.object(t.priceOracle),
|
|
218
|
+
e.object(t.storage),
|
|
219
|
+
e.object(o.contract.pool),
|
|
220
|
+
e.pure.u8(o.id),
|
|
221
|
+
n,
|
|
222
|
+
e.object(t.incentiveV2),
|
|
223
|
+
e.object(t.incentiveV3),
|
|
224
|
+
u(r.accountCap, e.object)
|
|
225
225
|
],
|
|
226
|
-
typeArguments: [
|
|
226
|
+
typeArguments: [o.suiCoinType]
|
|
227
227
|
});
|
|
228
228
|
i = s;
|
|
229
229
|
} else {
|
|
230
230
|
const [s] = e.moveCall({
|
|
231
|
-
target: `${
|
|
231
|
+
target: `${t.package}::incentive_v3::borrow`,
|
|
232
232
|
arguments: [
|
|
233
233
|
e.object("0x06"),
|
|
234
|
-
e.object(
|
|
235
|
-
e.object(
|
|
236
|
-
e.object(
|
|
237
|
-
e.pure.u8(
|
|
238
|
-
|
|
239
|
-
e.object(
|
|
240
|
-
e.object(
|
|
234
|
+
e.object(t.priceOracle),
|
|
235
|
+
e.object(t.storage),
|
|
236
|
+
e.object(o.contract.pool),
|
|
237
|
+
e.pure.u8(o.id),
|
|
238
|
+
n,
|
|
239
|
+
e.object(t.incentiveV2),
|
|
240
|
+
e.object(t.incentiveV3)
|
|
241
241
|
],
|
|
242
|
-
typeArguments: [
|
|
242
|
+
typeArguments: [o.suiCoinType]
|
|
243
243
|
});
|
|
244
244
|
i = s;
|
|
245
245
|
}
|
|
246
|
-
else if (
|
|
246
|
+
else if (r?.accountCap) {
|
|
247
247
|
const [s] = e.moveCall({
|
|
248
|
-
target: `${
|
|
248
|
+
target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
249
249
|
arguments: [
|
|
250
250
|
e.object("0x06"),
|
|
251
|
-
e.object(
|
|
252
|
-
e.object(
|
|
253
|
-
e.object(
|
|
254
|
-
e.pure.u8(
|
|
255
|
-
|
|
256
|
-
e.object(
|
|
257
|
-
e.object(
|
|
258
|
-
u(
|
|
251
|
+
e.object(t.priceOracle),
|
|
252
|
+
e.object(t.storage),
|
|
253
|
+
e.object(o.contract.pool),
|
|
254
|
+
e.pure.u8(o.id),
|
|
255
|
+
n,
|
|
256
|
+
e.object(t.incentiveV2),
|
|
257
|
+
e.object(t.incentiveV3),
|
|
258
|
+
u(r.accountCap, e.object),
|
|
259
259
|
e.object("0x05")
|
|
260
260
|
],
|
|
261
|
-
typeArguments: [
|
|
261
|
+
typeArguments: [o.suiCoinType]
|
|
262
262
|
});
|
|
263
263
|
i = s;
|
|
264
264
|
} else {
|
|
265
265
|
const [s] = e.moveCall({
|
|
266
|
-
target: `${
|
|
266
|
+
target: `${t.package}::incentive_v3::borrow_v2`,
|
|
267
267
|
arguments: [
|
|
268
268
|
e.object("0x06"),
|
|
269
|
-
e.object(
|
|
270
|
-
e.object(
|
|
271
|
-
e.object(
|
|
272
|
-
e.pure.u8(
|
|
273
|
-
|
|
274
|
-
e.object(
|
|
275
|
-
e.object(
|
|
269
|
+
e.object(t.priceOracle),
|
|
270
|
+
e.object(t.storage),
|
|
271
|
+
e.object(o.contract.pool),
|
|
272
|
+
e.pure.u8(o.id),
|
|
273
|
+
n,
|
|
274
|
+
e.object(t.incentiveV2),
|
|
275
|
+
e.object(t.incentiveV3),
|
|
276
276
|
e.object("0x05")
|
|
277
277
|
],
|
|
278
|
-
typeArguments: [
|
|
278
|
+
typeArguments: [o.suiCoinType]
|
|
279
279
|
});
|
|
280
280
|
i = s;
|
|
281
281
|
}
|
|
282
282
|
return e.moveCall({
|
|
283
283
|
target: "0x2::coin::from_balance",
|
|
284
284
|
arguments: [e.object(i)],
|
|
285
|
-
typeArguments: [
|
|
285
|
+
typeArguments: [o.suiCoinType]
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
|
-
async function
|
|
289
|
-
const
|
|
290
|
-
...
|
|
288
|
+
async function ne(e, a, c, r) {
|
|
289
|
+
const t = await d({
|
|
290
|
+
...r,
|
|
291
291
|
cacheTime: g
|
|
292
|
-
}),
|
|
293
|
-
if (m(
|
|
294
|
-
if (!
|
|
292
|
+
}), o = await b(a, r);
|
|
293
|
+
if (m(o.suiCoinType) === m("0x2::sui::SUI") && typeof c == "object" && c?.$kind === "GasCoin") {
|
|
294
|
+
if (!r?.amount)
|
|
295
295
|
throw new Error("Amount is required for sui coin");
|
|
296
|
-
|
|
296
|
+
c = e.splitCoins(c, [r.amount]);
|
|
297
297
|
}
|
|
298
|
-
let
|
|
299
|
-
if (typeof
|
|
298
|
+
let n;
|
|
299
|
+
if (typeof r?.amount < "u" ? n = u(r.amount, e.pure.u64) : n = e.moveCall({
|
|
300
300
|
target: "0x2::coin::value",
|
|
301
|
-
arguments: [u(
|
|
302
|
-
typeArguments: [
|
|
303
|
-
}),
|
|
301
|
+
arguments: [u(c, e.object)],
|
|
302
|
+
typeArguments: [o.suiCoinType]
|
|
303
|
+
}), r?.accountCap) {
|
|
304
304
|
const [i] = e.moveCall({
|
|
305
|
-
target: `${
|
|
305
|
+
target: `${t.package}::incentive_v3::repay_with_account_cap`,
|
|
306
306
|
arguments: [
|
|
307
307
|
e.object("0x06"),
|
|
308
|
-
e.object(
|
|
309
|
-
e.object(
|
|
310
|
-
e.object(
|
|
311
|
-
e.pure.u8(
|
|
312
|
-
u(
|
|
313
|
-
e.object(
|
|
314
|
-
e.object(
|
|
315
|
-
u(
|
|
308
|
+
e.object(t.priceOracle),
|
|
309
|
+
e.object(t.storage),
|
|
310
|
+
e.object(o.contract.pool),
|
|
311
|
+
e.pure.u8(o.id),
|
|
312
|
+
u(c, e.object),
|
|
313
|
+
e.object(t.incentiveV2),
|
|
314
|
+
e.object(t.incentiveV3),
|
|
315
|
+
u(r.accountCap, e.object)
|
|
316
316
|
],
|
|
317
|
-
typeArguments: [
|
|
317
|
+
typeArguments: [o.suiCoinType]
|
|
318
318
|
});
|
|
319
319
|
return e.moveCall({
|
|
320
320
|
target: "0x2::coin::from_balance",
|
|
321
321
|
arguments: [i],
|
|
322
|
-
typeArguments: [
|
|
322
|
+
typeArguments: [o.suiCoinType]
|
|
323
323
|
});
|
|
324
324
|
} else
|
|
325
325
|
return e.moveCall({
|
|
326
|
-
target: `${
|
|
326
|
+
target: `${t.package}::incentive_v3::entry_repay`,
|
|
327
327
|
arguments: [
|
|
328
328
|
e.object("0x06"),
|
|
329
|
-
e.object(
|
|
330
|
-
e.object(
|
|
331
|
-
e.object(
|
|
332
|
-
e.pure.u8(
|
|
333
|
-
u(
|
|
334
|
-
|
|
335
|
-
e.object(
|
|
336
|
-
e.object(
|
|
329
|
+
e.object(t.priceOracle),
|
|
330
|
+
e.object(t.storage),
|
|
331
|
+
e.object(o.contract.pool),
|
|
332
|
+
e.pure.u8(o.id),
|
|
333
|
+
u(c, e.object),
|
|
334
|
+
n,
|
|
335
|
+
e.object(t.incentiveV2),
|
|
336
|
+
e.object(t.incentiveV3)
|
|
337
337
|
],
|
|
338
|
-
typeArguments: [
|
|
338
|
+
typeArguments: [o.suiCoinType]
|
|
339
339
|
}), e;
|
|
340
340
|
}
|
|
341
|
-
const
|
|
341
|
+
const re = y(
|
|
342
342
|
w(
|
|
343
343
|
async (e) => {
|
|
344
344
|
const a = await d({
|
|
345
345
|
...e
|
|
346
|
-
}),
|
|
346
|
+
}), c = e?.client ?? U;
|
|
347
347
|
if (e?.address && typeof e?.asset < "u")
|
|
348
348
|
try {
|
|
349
|
-
const
|
|
350
|
-
|
|
349
|
+
const o = await b(e.asset, e), n = new M();
|
|
350
|
+
n.moveCall({
|
|
351
351
|
target: `${a.package}::incentive_v3::get_borrow_fee_v2`,
|
|
352
352
|
arguments: [
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
n.object(a.incentiveV3),
|
|
354
|
+
n.pure.address(e.address),
|
|
355
|
+
n.pure.u8(o.id),
|
|
356
|
+
n.pure.u64(1e4)
|
|
357
357
|
],
|
|
358
358
|
typeArguments: []
|
|
359
359
|
});
|
|
360
|
-
const i = await
|
|
361
|
-
transactionBlock:
|
|
360
|
+
const i = await R(c, {
|
|
361
|
+
transactionBlock: n,
|
|
362
362
|
sender: e.address
|
|
363
|
-
}), l =
|
|
363
|
+
}), l = F(i, [P.u64()]);
|
|
364
364
|
return (Number(l[0]) || 0) / 100;
|
|
365
|
-
} catch (
|
|
365
|
+
} catch (o) {
|
|
366
366
|
console.error(
|
|
367
367
|
"[lending] getBorrowFee per-user query failed, falling back to global rate:",
|
|
368
|
-
|
|
368
|
+
o
|
|
369
369
|
);
|
|
370
370
|
}
|
|
371
|
-
const
|
|
371
|
+
const t = (await W(c, {
|
|
372
372
|
id: a.incentiveV3,
|
|
373
373
|
options: { showType: !0, showOwner: !0, showContent: !0 }
|
|
374
374
|
})).data.content.fields.borrow_fee_rate;
|
|
375
|
-
return Number(
|
|
375
|
+
return Number(t) / 100;
|
|
376
376
|
}
|
|
377
377
|
)
|
|
378
378
|
);
|
|
379
379
|
export {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
380
|
+
H as PoolOperator,
|
|
381
|
+
oe as borrowCoinPTB,
|
|
382
|
+
ee as depositCoinPTB,
|
|
383
|
+
re as getBorrowFee,
|
|
384
|
+
x as getFees,
|
|
385
385
|
b as getPool,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
386
|
+
K as getPools,
|
|
387
|
+
Z as getStats,
|
|
388
|
+
ne as repayCoinPTB,
|
|
389
|
+
te as withdrawCoinPTB
|
|
390
390
|
};
|
|
391
391
|
//# sourceMappingURL=pool.js.map
|
package/dist/pool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sources":["../src/pool.ts"],"sourcesContent":["/**\n * Lending Pool Operations\n *\n * This module provides comprehensive pool management functionality for the lending protocol.\n * It handles pool information retrieval, deposit/withdraw operations, borrow/repay operations,\n * and various pool-related utilities and statistics.\n *\n * @module LendingPool\n */\n\nimport { DEFAULT_CACHE_TIME, getConfig } from './config'\nimport type {\n EnvOption,\n CacheOption,\n Pool,\n AssetIdentifier,\n PoolStats,\n FeeDetail,\n CoinObject,\n TransactionResult,\n SingleCoinTransactionResult,\n AccountCapOption,\n BorrowFeeOption,\n SuiClientOption,\n MarketOption,\n EMode,\n MarketsOption,\n ServiceOption\n} from './types'\nimport {\n normalizeCoinType,\n withCache,\n withSingleton,\n parseTxValue,\n requestHeaders,\n parsePoolUID,\n parseDevInspectResult,\n devInspectTransaction,\n getSuiObject,\n suiClient\n} from './utils'\nimport { buildNaviOpenApiUrl, mergeServiceHeaders, resolveNaviOpenApiEndpoint } from './services'\nimport { Transaction } from '@mysten/sui/transactions'\nimport BigNumber from 'bignumber.js'\nimport { bcs } from '@mysten/sui/bcs'\nimport packageJson from '../package.json'\nimport { DEFAULT_MARKET_IDENTITY, getMarketConfig, MARKETS } from './market'\n\n/**\n * Enumeration of pool operations\n *\n * This enum defines the different types of operations that can be performed\n * on lending pools, used for health factor calculations and operation tracking.\n */\nexport enum PoolOperator {\n /** Supply/deposit operation */\n Supply = 1,\n /** Withdraw operation */\n Withdraw = 2,\n /** Borrow operation */\n Borrow = 3,\n /** Repay operation */\n Repay = 4\n}\n\n/**\n * Fetches all available lending pools\n *\n * This function retrieves the complete list of lending pools from the Navi protocol API.\n * It's wrapped with caching and singleton behavior for efficient data access.\n *\n * @param options - Optional environment and caching options\n * @returns Promise<Pool[]> - Array of all available lending pools\n */\nexport const getPools = withCache(\n withSingleton(\n async (\n options?: Partial<EnvOption & CacheOption & MarketsOption & ServiceOption>\n ): Promise<Pool[]> => {\n const markets = (options?.markets || [MARKETS.main]).map((identity) => {\n return getMarketConfig(identity)\n })\n const endpoint = resolveNaviOpenApiEndpoint(options)\n const url = buildNaviOpenApiUrl(\n `/navi/pools?env=${options?.env || 'prod'}&sdk=${packageJson.version}&market=${markets.map(\n (market) => {\n return market.key\n }\n )}`,\n options\n )\n const res: {\n data: Pool[]\n meta: {\n emodes: EMode[]\n }\n } = await fetch(url, { headers: mergeServiceHeaders(requestHeaders, endpoint) }).then((res) =>\n res.json()\n )\n\n res.data.forEach((pool) => {\n const filterEmodes = res.meta.emodes.filter((emode) => {\n const market = getMarketConfig(emode.marketId)\n return pool.market === market.key && emode.isActive\n })\n const emodes = filterEmodes.filter((emode) => {\n return !!emode.assets.find((asset) => asset.assetId === pool.id)\n })\n pool.emodes = emodes\n const poolSupplyAmount = BigNumber(pool.totalSupplyAmount)\n .div(Math.pow(10, 9))\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolBorrowAmount = BigNumber(pool.borrowedAmount)\n .shiftedBy(-9)\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolSupplyValue = BigNumber(poolSupplyAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n const poolBorrowValue = BigNumber(poolBorrowAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n const poolSupplyCapAmount = BigNumber(pool.supplyCapCeiling)\n .shiftedBy(-27)\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolBorrowCapAmount = BigNumber.max(\n BigNumber(pool.borrowedAmount),\n BigNumber(pool.validBorrowAmount)\n )\n .shiftedBy(-9)\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolSupplyCapValue = BigNumber(poolSupplyCapAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n const poolBorrowCapValue = BigNumber(poolBorrowCapAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n pool.poolSupplyAmount = poolSupplyAmount\n pool.poolBorrowAmount = poolBorrowAmount\n pool.poolSupplyValue = poolSupplyValue\n pool.poolBorrowValue = poolBorrowValue\n pool.poolSupplyCapAmount = poolSupplyCapAmount\n pool.poolBorrowCapAmount = poolBorrowCapAmount\n pool.poolSupplyCapValue = poolSupplyCapValue\n pool.poolBorrowCapValue = poolBorrowCapValue\n })\n return res.data\n }\n )\n)\n\n/**\n * Gets information for a specific lending pool\n *\n * This function retrieves pool information based on various identifier types:\n * - Pool object (returns directly)\n * - String (coin type - normalized for comparison)\n * - Number (pool ID)\n *\n * @param identifier - Asset identifier (string, Pool object, or number)\n * @param options - Optional environment options\n * @returns Promise<Pool> - Pool information\n * @throws Error if pool is not found\n */\nexport async function getPool(\n identifier: AssetIdentifier,\n options?: Partial<EnvOption & MarketOption & ServiceOption>\n): Promise<Pool> {\n let market = options?.market\n if (typeof identifier === 'string') {\n const parsedUID = parsePoolUID(identifier)\n if (parsedUID) {\n market = parsedUID.marketKey\n identifier = parsedUID.poolId\n }\n }\n const pools = await getPools({\n ...options,\n markets: [market || DEFAULT_MARKET_IDENTITY],\n cacheTime: DEFAULT_CACHE_TIME\n })\n\n // If identifier is already a pool object, return it directly\n if (typeof identifier === 'object') {\n return identifier\n }\n\n // Find pool by identifier\n const pool = pools.find((p) => {\n if (typeof identifier === 'string') {\n return normalizeCoinType(p.suiCoinType) === normalizeCoinType(identifier)\n }\n if (typeof identifier === 'number') {\n return p.id === identifier\n }\n return false\n })\n\n if (!pool) {\n throw new Error(`Pool not found`)\n }\n\n if (pool.isDeprecated) {\n console.log(`The lending pool for coinType ${pool.suiCoinType} is going to be deprecated.`)\n }\n return pool\n}\n\n/**\n * Fetches protocol statistics\n *\n * This function retrieves overall protocol statistics including TVL,\n * total borrow amounts, and other key metrics.\n *\n * @param options - Optional caching options\n * @returns Promise<PoolStats> - Protocol statistics\n */\nexport const getStats = withCache(\n withSingleton(async (options?: Partial<CacheOption & ServiceOption>): Promise<PoolStats> => {\n const endpoint = resolveNaviOpenApiEndpoint(options)\n const url = buildNaviOpenApiUrl(`/navi/stats?sdk=${packageJson.version}`, options)\n const res = await fetch(url, {\n headers: mergeServiceHeaders(requestHeaders, endpoint)\n }).then((res) => res.json())\n return res.data\n })\n)\n\n/**\n * Fetches protocol fee information\n *\n * This function retrieves detailed fee information including:\n * - Total fee value\n * - V3 borrow fees\n * - Borrow interest fees\n * - Flash loan and liquidation fees\n *\n * @param options - Optional caching options\n * @returns Promise with detailed fee breakdown\n */\nexport const getFees = withCache(\n withSingleton(\n async (\n options?: Partial<CacheOption & ServiceOption>\n ): Promise<{\n totalValue: number\n v3BorrowFee: {\n totalValue: number\n details: FeeDetail[]\n }\n borrowInterestFee: {\n totalValue: number\n details: FeeDetail[]\n }\n flashloanAndLiquidationFee: {\n totalValue: number\n details: FeeDetail[]\n }\n }> => {\n const endpoint = resolveNaviOpenApiEndpoint(options)\n const url = buildNaviOpenApiUrl(`/navi/fee?sdk=${packageJson.version}`, options)\n const res = await fetch(url, {\n headers: mergeServiceHeaders(requestHeaders, endpoint)\n }).then((res) => res.json())\n return res\n }\n )\n)\n\n/**\n * Builds a deposit transaction for a lending pool\n *\n * This function creates a transaction block for depositing coins into a lending pool.\n * It handles both regular deposits and deposits with account capabilities,\n * and includes special handling for SUI gas coins.\n *\n * @param tx - Transaction object to build\n * @param identifier - Asset identifier for the pool\n * @param coinObject - Coin object to deposit\n * @param options - Optional parameters including environment, account capability, and amount\n * @returns Promise<Transaction> - Transaction with deposit operation\n */\nexport async function depositCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n coinObject: CoinObject,\n options?: Partial<\n EnvOption &\n AccountCapOption &\n ServiceOption &\n MarketOption & {\n amount: number | TransactionResult\n }\n >\n): Promise<Transaction> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n const market = options?.market || DEFAULT_MARKET_IDENTITY\n const env = options?.env || 'prod'\n\n if (pool?.deprecatedAt && Date.now() > pool.deprecatedAt) {\n throw new Error(`The lending pool for coinType ${pool.suiCoinType} has been deprecated.`)\n }\n\n // Handle SUI gas coin deposits\n if (\n normalizeCoinType(pool.suiCoinType) === normalizeCoinType('0x2::sui::SUI') &&\n typeof coinObject === 'object' &&\n coinObject?.$kind === 'GasCoin'\n ) {\n if (!options?.amount) {\n throw new Error('Amount is required for sui coin')\n }\n coinObject = tx.splitCoins(coinObject, [options.amount])\n }\n\n // Determine deposit amount\n let depositAmount: TransactionResult\n\n if (typeof options?.amount !== 'undefined') {\n depositAmount = parseTxValue(options.amount, tx.pure.u64)\n } else {\n depositAmount = tx.moveCall({\n target: '0x2::coin::value',\n arguments: [parseTxValue(coinObject as any, tx.object)],\n typeArguments: [pool.suiCoinType]\n })\n }\n\n // Build deposit transaction based on account capability\n if (options?.accountCap) {\n tx.moveCall({\n target: `${config.package}::incentive_v3::deposit_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n } else {\n tx.moveCall({\n target: `${config.package}::incentive_v3::entry_deposit`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n depositAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n }\n\n // refresh stake for sui pool to balance the stake after deposit\n if (config.version === 2 && pool.token.symbol === 'SUI' && env === 'prod' && market === 'main') {\n tx.moveCall({\n target: `${config.package}::pool::refresh_stake`,\n arguments: [tx.object(pool.contract.pool), tx.object('0x05')]\n })\n }\n\n return tx\n}\n\n/**\n * Builds a withdraw transaction for a lending pool\n *\n * Constructs and adds withdrawal operations to a transaction object.\n * This function supports standard withdrawal and withdrawal using account capability.\n *\n * @param tx - The transaction builder to append operations to\n * @param identifier - Asset identifier for the pool\n * @param amount - Amount to withdraw\n * @param options - Optional parameters including environment and account capability\n * @returns Transaction result representing the withdrawn coins\n */\nexport async function withdrawCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n amount: number | TransactionResult,\n options?: Partial<EnvOption & AccountCapOption & MarketOption & ServiceOption>\n): Promise<SingleCoinTransactionResult> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n\n const withdrawAmount = parseTxValue(amount, tx.pure.u64)\n\n let withdrawBalance\n\n if (config.version === 1) {\n // Build withdraw transaction based on account capability\n if (options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n }\n } else {\n // Build withdraw transaction based on account capability\n if (options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw_with_account_cap_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n }\n }\n\n const withdrawCoin = tx.moveCall({\n target: `0x2::coin::from_balance`,\n arguments: [withdrawBalance],\n typeArguments: [pool.suiCoinType]\n })\n\n return withdrawCoin as SingleCoinTransactionResult\n}\n\nexport async function borrowCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n amount: number | TransactionResult,\n options?: Partial<EnvOption & AccountCapOption & MarketOption & ServiceOption>\n): Promise<SingleCoinTransactionResult> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n\n if (pool?.deprecatedAt && Date.now() > pool.deprecatedAt) {\n throw new Error(`The lending pool for coinType ${pool.suiCoinType} has been deprecated.`)\n }\n\n const borrowAmount = parseTxValue(amount, tx.pure.u64)\n\n let borrowBalance\n\n if (config.version === 1) {\n if (!options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n }\n } else {\n if (!options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow_with_account_cap_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n }\n }\n\n const coin = tx.moveCall({\n target: `0x2::coin::from_balance`,\n arguments: [tx.object(borrowBalance)],\n typeArguments: [pool.suiCoinType]\n })\n\n return coin as SingleCoinTransactionResult\n}\n\n/**\n * Builds a repay transaction for a lending pool debt\n *\n * Constructs and adds repayment operations to an existing transaction object.\n * This function handles loan repayments, supporting both standard user\n * repayments and privileged operations via account capabilities.\n *\n *\n * @param tx - The transaction builder to append repayment operations to\n * @param identifier - Unique identifier for the lending pool asset (e.g., \"USDC\", \"SUI\")\n * @param coinObject - The coin object to use for repayment, or GasCoin for SUI payments\n * @param options - Configuration options for the repayment\n * - `amount` - Specific amount to repay (required for SUI gas coin, otherwise uses value of specified coinObject)\n * - `accountCap` - Optional account capability object for privileged repayments\n * - `env` - Environment configuration\n * - `cacheTime` - Cache duration for configuration data\n *\n * @returns Promise<Transaction | TransactionResult> - The modified transaction object with repayment operations added\n *\n * @throws {Error} When amount is not provided for SUI gas coin repayments\n * @throws Will throw if pool doesn't exist or repayment validation fails\n */\nexport async function repayCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n coinObject: CoinObject,\n options?: Partial<\n EnvOption &\n AccountCapOption &\n ServiceOption &\n MarketOption & {\n amount: number | TransactionResult\n }\n >\n): Promise<Transaction | TransactionResult> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n if (\n normalizeCoinType(pool.suiCoinType) === normalizeCoinType('0x2::sui::SUI') &&\n typeof coinObject === 'object' &&\n coinObject?.$kind === 'GasCoin'\n ) {\n if (!options?.amount) {\n throw new Error('Amount is required for sui coin')\n }\n coinObject = tx.splitCoins(coinObject, [options.amount])\n }\n\n let repayAmount: TransactionResult\n\n if (typeof options?.amount !== 'undefined') {\n repayAmount = parseTxValue(options.amount, tx.pure.u64)\n } else {\n repayAmount = tx.moveCall({\n target: '0x2::coin::value',\n arguments: [parseTxValue(coinObject as any, tx.object)],\n typeArguments: [pool.suiCoinType]\n })\n }\n\n if (options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::repay_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n const coin = tx.moveCall({\n target: `0x2::coin::from_balance`,\n arguments: [ret],\n typeArguments: [pool.suiCoinType]\n })\n return coin\n } else {\n tx.moveCall({\n target: `${config.package}::incentive_v3::entry_repay`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n repayAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n return tx\n }\n}\n\n/**\n * Fetches the current borrow fee rate\n *\n * This function can retrieve borrow fee rates in two ways:\n * - If `address` and `asset` are provided, it calculates the specific borrow fee rate\n * for a given address and asset by calling the on-chain `get_borrow_fee_v2` function\n * - Otherwise, it returns the global borrow fee rate from the incentive V3 contract\n *\n * @param options - Optional configuration options\n * - `address` - User address to calculate specific borrow fee (requires `asset` to be set)\n * - `asset` - Asset identifier to calculate specific borrow fee (requires `address` to be set)\n * - `env` - Environment setting ('dev' or 'prod')\n * - `client` - Sui client instance for on-chain queries\n * - `cacheTime` - Cache expiration time in milliseconds\n * - `disableCache` - Whether to disable caching for this operation\n * @returns Promise<number> - Borrow fee rate as a decimal number\n * - When `address` and `asset` are provided: returns the specific fee rate (divided by 10000)\n * - Otherwise: returns the global fee rate (divided by 100)\n */\nexport const getBorrowFee = withCache(\n withSingleton(\n async (\n options?: Partial<EnvOption & CacheOption & BorrowFeeOption & SuiClientOption & MarketOption>\n ): Promise<number> => {\n const config = await getConfig({\n ...options\n })\n const client = options?.client ?? suiClient\n if (options?.address && typeof options?.asset !== 'undefined') {\n try {\n const pool = await getPool(options.asset, options)\n const tx = new Transaction()\n tx.moveCall({\n target: `${config.package}::incentive_v3::get_borrow_fee_v2`,\n arguments: [\n tx.object(config.incentiveV3),\n tx.pure.address(options.address),\n tx.pure.u8(pool.id),\n tx.pure.u64(10000)\n ],\n typeArguments: []\n })\n const result = await devInspectTransaction(client, {\n transactionBlock: tx,\n sender: options.address\n })\n const res = parseDevInspectResult<number[]>(result, [bcs.u64()])\n return (Number(res[0]) || 0) / 100\n } catch (error) {\n // Per-user borrow-fee query failed -> fall back to the global rate below\n // (semantic change; marked explicitly for traceability, fallback behavior unchanged).\n console.error(\n '[lending] getBorrowFee per-user query failed, falling back to global rate:',\n error\n )\n }\n }\n const rawData: any = await getSuiObject(client, {\n id: config.incentiveV3,\n options: { showType: true, showOwner: true, showContent: true }\n })\n const borrowFee = rawData.data.content.fields.borrow_fee_rate\n return Number(borrowFee) / 100\n }\n )\n)\n"],"names":["PoolOperator","getPools","withCache","withSingleton","options","markets","MARKETS","identity","getMarketConfig","endpoint","resolveNaviOpenApiEndpoint","url","buildNaviOpenApiUrl","packageJson","market","res","mergeServiceHeaders","requestHeaders","pool","emodes","emode","asset","poolSupplyAmount","BigNumber","poolBorrowAmount","poolSupplyValue","poolBorrowValue","poolSupplyCapAmount","poolBorrowCapAmount","poolSupplyCapValue","poolBorrowCapValue","getPool","identifier","parsedUID","parsePoolUID","pools","DEFAULT_MARKET_IDENTITY","DEFAULT_CACHE_TIME","p","normalizeCoinType","getStats","getFees","depositCoinPTB","tx","coinObject","config","getConfig","env","depositAmount","parseTxValue","withdrawCoinPTB","amount","withdrawAmount","withdrawBalance","ret","borrowCoinPTB","borrowAmount","borrowBalance","repayCoinPTB","repayAmount","getBorrowFee","client","suiClient","Transaction","result","devInspectTransaction","parseDevInspectResult","bcs","error","borrowFee","getSuiObject"],"mappings":";;;;;;;;AAsDO,IAAKA,sBAAAA,OAEVA,EAAAA,EAAA,SAAS,CAAA,IAAT,UAEAA,EAAAA,EAAA,WAAW,CAAA,IAAX,YAEAA,EAAAA,EAAA,SAAS,CAAA,IAAT,UAEAA,EAAAA,EAAA,QAAQ,CAAA,IAAR,SARUA,IAAAA,KAAA,CAAA,CAAA;AAoBL,MAAMC,IAAWC;AAAA,EACtBC;AAAA,IACE,OACEC,MACoB;AACpB,YAAMC,KAAWD,GAAS,WAAW,CAACE,EAAQ,IAAI,GAAG,IAAI,CAACC,MACjDC,EAAgBD,CAAQ,CAChC,GACKE,IAAWC,EAA2BN,CAAO,GAC7CO,IAAMC;AAAA,QACV,mBAAmBR,GAAS,OAAO,MAAM,QAAQS,EAAY,OAAO,WAAWR,EAAQ;AAAA,UACrF,CAACS,MACQA,EAAO;AAAA,QAChB,CACD;AAAA,QACDV;AAAA,MAAA,GAEIW,IAKF,MAAM,MAAMJ,GAAK,EAAE,SAASK,EAAoBC,GAAgBR,CAAQ,EAAA,CAAG,EAAE;AAAA,QAAK,CAACM,MACrFA,EAAI,KAAA;AAAA,MAAK;AAGX,aAAAA,EAAI,KAAK,QAAQ,CAACG,MAAS;AAKzB,cAAMC,IAJeJ,EAAI,KAAK,OAAO,OAAO,CAACK,MAAU;AACrD,gBAAMN,IAASN,EAAgBY,EAAM,QAAQ;AAC7C,iBAAOF,EAAK,W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AAA,cAC/BuC,EAAG,KAAK,GAAGzB,EAAK,EAAE;AAAA,cAClByB,EAAG,KAAK,IAAI,GAAK;AAAA,YAAA;AAAA,YAEnB,eAAe,CAAA;AAAA,UAAC,CACjB;AACD,gBAAMqB,IAAS,MAAMC,EAAsBJ,GAAQ;AAAA,YACjD,kBAAkBlB;AAAA,YAClB,QAAQvC,EAAQ;AAAA,UAAA,CACjB,GACKW,IAAMmD,EAAgCF,GAAQ,CAACG,EAAI,IAAA,CAAK,CAAC;AAC/D,kBAAQ,OAAOpD,EAAI,CAAC,CAAC,KAAK,KAAK;AAAA,QACjC,SAASqD,GAAO;AAGd,kBAAQ;AAAA,YACN;AAAA,YACAA;AAAA,UAAA;AAAA,QAEJ;AAMF,YAAMC,KAJe,MAAMC,EAAaT,GAAQ;AAAA,QAC9C,IAAIhB,EAAO;AAAA,QACX,SAAS,EAAE,UAAU,IAAM,WAAW,IAAM,aAAa,GAAA;AAAA,MAAK,CAC/D,GACyB,KAAK,QAAQ,OAAO;AAC9C,aAAO,OAAOwB,CAAS,IAAI;AAAA,IAC7B;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"pool.js","sources":["../src/pool.ts"],"sourcesContent":["/**\n * Lending Pool Operations\n *\n * This module provides comprehensive pool management functionality for the lending protocol.\n * It handles pool information retrieval, deposit/withdraw operations, borrow/repay operations,\n * and various pool-related utilities and statistics.\n *\n * @module LendingPool\n */\n\nimport { DEFAULT_CACHE_TIME, getConfig } from './config'\nimport type {\n EnvOption,\n CacheOption,\n Pool,\n AssetIdentifier,\n PoolStats,\n FeeDetail,\n CoinObject,\n TransactionResult,\n SingleCoinTransactionResult,\n AccountCapOption,\n BorrowFeeOption,\n SuiClientOption,\n MarketOption,\n EMode,\n MarketsOption,\n ServiceOption\n} from './types'\nimport {\n normalizeCoinType,\n withCache,\n withSingleton,\n parseTxValue,\n requestHeaders,\n parsePoolUID,\n parseDevInspectResult,\n devInspectTransaction,\n getSuiObject,\n suiClient\n} from './utils'\nimport { buildNaviOpenApiUrl, mergeServiceHeaders, resolveNaviOpenApiEndpoint } from './services'\nimport { Transaction } from '@mysten/sui/transactions'\nimport BigNumber from 'bignumber.js'\nimport { bcs } from '@mysten/sui/bcs'\nimport packageJson from '../package.json'\nimport { DEFAULT_MARKET_IDENTITY, getMarketConfig, MARKETS } from './market'\n\n/**\n * Enumeration of pool operations\n *\n * This enum defines the different types of operations that can be performed\n * on lending pools, used for health factor calculations and operation tracking.\n */\nexport enum PoolOperator {\n /** Supply/deposit operation */\n Supply = 1,\n /** Withdraw operation */\n Withdraw = 2,\n /** Borrow operation */\n Borrow = 3,\n /** Repay operation */\n Repay = 4\n}\n\n/**\n * Fetches all available lending pools\n *\n * This function retrieves the complete list of lending pools from the Navi protocol API.\n * It's wrapped with caching and singleton behavior for efficient data access.\n *\n * @param options - Optional environment and caching options\n * @returns Promise<Pool[]> - Array of all available lending pools\n */\nexport const getPools = withCache(\n withSingleton(\n async (\n options?: Partial<\n EnvOption &\n CacheOption &\n MarketsOption &\n ServiceOption & {\n pools: string[]\n }\n >\n ): Promise<Pool[]> => {\n const markets = (options?.markets || [MARKETS.main]).map((identity) => {\n return getMarketConfig(identity)\n })\n const endpoint = resolveNaviOpenApiEndpoint(options)\n const poolsFilter = (options?.pools || []).join(',')\n const url = buildNaviOpenApiUrl(\n `/navi/pools?env=${options?.env || 'prod'}&sdk=${packageJson.version}&market=${markets.map(\n (market) => {\n return market.key\n }\n )}${!!poolsFilter ? '&pools=' + poolsFilter : ''}`,\n options\n )\n const res: {\n data: Pool[]\n meta: {\n emodes: EMode[]\n }\n } = await fetch(url, { headers: mergeServiceHeaders(requestHeaders, endpoint) }).then((res) =>\n res.json()\n )\n\n res.data.forEach((pool) => {\n const filterEmodes = res.meta.emodes.filter((emode) => {\n const market = getMarketConfig(emode.marketId)\n return pool.market === market.key && emode.isActive\n })\n const emodes = filterEmodes.filter((emode) => {\n return !!emode.assets.find((asset) => asset.assetId === pool.id)\n })\n pool.emodes = emodes\n const poolSupplyAmount = BigNumber(pool.totalSupplyAmount)\n .div(Math.pow(10, 9))\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolBorrowAmount = BigNumber(pool.borrowedAmount)\n .shiftedBy(-9)\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolSupplyValue = BigNumber(poolSupplyAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n const poolBorrowValue = BigNumber(poolBorrowAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n const poolSupplyCapAmount = BigNumber(pool.supplyCapCeiling)\n .shiftedBy(-27)\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolBorrowCapAmount = BigNumber.max(\n BigNumber(pool.borrowedAmount),\n BigNumber(pool.validBorrowAmount)\n )\n .shiftedBy(-9)\n .decimalPlaces(pool.token.decimals, BigNumber.ROUND_DOWN)\n .toString()\n const poolSupplyCapValue = BigNumber(poolSupplyCapAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n const poolBorrowCapValue = BigNumber(poolBorrowCapAmount)\n .multipliedBy(pool.oracle.price)\n .toString()\n pool.poolSupplyAmount = poolSupplyAmount\n pool.poolBorrowAmount = poolBorrowAmount\n pool.poolSupplyValue = poolSupplyValue\n pool.poolBorrowValue = poolBorrowValue\n pool.poolSupplyCapAmount = poolSupplyCapAmount\n pool.poolBorrowCapAmount = poolBorrowCapAmount\n pool.poolSupplyCapValue = poolSupplyCapValue\n pool.poolBorrowCapValue = poolBorrowCapValue\n })\n return res.data\n }\n )\n)\n\n/**\n * Gets information for a specific lending pool\n *\n * This function retrieves pool information based on various identifier types:\n * - Pool object (returns directly)\n * - String (coin type - normalized for comparison)\n * - Number (pool ID)\n *\n * @param identifier - Asset identifier (string, Pool object, or number)\n * @param options - Optional environment options\n * @returns Promise<Pool> - Pool information\n * @throws Error if pool is not found\n */\nexport async function getPool(\n identifier: AssetIdentifier,\n options?: Partial<EnvOption & MarketOption & ServiceOption>\n): Promise<Pool> {\n let market = options?.market\n if (typeof identifier === 'string') {\n const parsedUID = parsePoolUID(identifier)\n if (parsedUID) {\n market = parsedUID.marketKey\n identifier = parsedUID.poolId\n }\n }\n const pools = await getPools({\n ...options,\n markets: [market || DEFAULT_MARKET_IDENTITY],\n cacheTime: DEFAULT_CACHE_TIME\n })\n\n // If identifier is already a pool object, return it directly\n if (typeof identifier === 'object') {\n return identifier\n }\n\n // Find pool by identifier\n const pool = pools.find((p) => {\n if (typeof identifier === 'string') {\n return normalizeCoinType(p.suiCoinType) === normalizeCoinType(identifier)\n }\n if (typeof identifier === 'number') {\n return p.id === identifier\n }\n return false\n })\n\n if (!pool) {\n throw new Error(`Pool not found`)\n }\n\n if (pool.isDeprecated) {\n console.log(`The lending pool for coinType ${pool.suiCoinType} is going to be deprecated.`)\n }\n return pool\n}\n\n/**\n * Fetches protocol statistics\n *\n * This function retrieves overall protocol statistics including TVL,\n * total borrow amounts, and other key metrics.\n *\n * @param options - Optional caching options\n * @returns Promise<PoolStats> - Protocol statistics\n */\nexport const getStats = withCache(\n withSingleton(async (options?: Partial<CacheOption & ServiceOption>): Promise<PoolStats> => {\n const endpoint = resolveNaviOpenApiEndpoint(options)\n const url = buildNaviOpenApiUrl(`/navi/stats?sdk=${packageJson.version}`, options)\n const res = await fetch(url, {\n headers: mergeServiceHeaders(requestHeaders, endpoint)\n }).then((res) => res.json())\n return res.data\n })\n)\n\n/**\n * Fetches protocol fee information\n *\n * This function retrieves detailed fee information including:\n * - Total fee value\n * - V3 borrow fees\n * - Borrow interest fees\n * - Flash loan and liquidation fees\n *\n * @param options - Optional caching options\n * @returns Promise with detailed fee breakdown\n */\nexport const getFees = withCache(\n withSingleton(\n async (\n options?: Partial<CacheOption & ServiceOption>\n ): Promise<{\n totalValue: number\n v3BorrowFee: {\n totalValue: number\n details: FeeDetail[]\n }\n borrowInterestFee: {\n totalValue: number\n details: FeeDetail[]\n }\n flashloanAndLiquidationFee: {\n totalValue: number\n details: FeeDetail[]\n }\n }> => {\n const endpoint = resolveNaviOpenApiEndpoint(options)\n const url = buildNaviOpenApiUrl(`/navi/fee?sdk=${packageJson.version}`, options)\n const res = await fetch(url, {\n headers: mergeServiceHeaders(requestHeaders, endpoint)\n }).then((res) => res.json())\n return res\n }\n )\n)\n\n/**\n * Builds a deposit transaction for a lending pool\n *\n * This function creates a transaction block for depositing coins into a lending pool.\n * It handles both regular deposits and deposits with account capabilities,\n * and includes special handling for SUI gas coins.\n *\n * @param tx - Transaction object to build\n * @param identifier - Asset identifier for the pool\n * @param coinObject - Coin object to deposit\n * @param options - Optional parameters including environment, account capability, and amount\n * @returns Promise<Transaction> - Transaction with deposit operation\n */\nexport async function depositCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n coinObject: CoinObject,\n options?: Partial<\n EnvOption &\n AccountCapOption &\n ServiceOption &\n MarketOption & {\n amount: number | TransactionResult\n }\n >\n): Promise<Transaction> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n const market = options?.market || DEFAULT_MARKET_IDENTITY\n const env = options?.env || 'prod'\n\n if (pool?.deprecatedAt && Date.now() > pool.deprecatedAt) {\n throw new Error(`The lending pool for coinType ${pool.suiCoinType} has been deprecated.`)\n }\n\n // Handle SUI gas coin deposits\n if (\n normalizeCoinType(pool.suiCoinType) === normalizeCoinType('0x2::sui::SUI') &&\n typeof coinObject === 'object' &&\n coinObject?.$kind === 'GasCoin'\n ) {\n if (!options?.amount) {\n throw new Error('Amount is required for sui coin')\n }\n coinObject = tx.splitCoins(coinObject, [options.amount])\n }\n\n // Determine deposit amount\n let depositAmount: TransactionResult\n\n if (typeof options?.amount !== 'undefined') {\n depositAmount = parseTxValue(options.amount, tx.pure.u64)\n } else {\n depositAmount = tx.moveCall({\n target: '0x2::coin::value',\n arguments: [parseTxValue(coinObject as any, tx.object)],\n typeArguments: [pool.suiCoinType]\n })\n }\n\n // Build deposit transaction based on account capability\n if (options?.accountCap) {\n tx.moveCall({\n target: `${config.package}::incentive_v3::deposit_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n } else {\n tx.moveCall({\n target: `${config.package}::incentive_v3::entry_deposit`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n depositAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n }\n\n // refresh stake for sui pool to balance the stake after deposit\n if (config.version === 2 && pool.token.symbol === 'SUI' && env === 'prod' && market === 'main') {\n tx.moveCall({\n target: `${config.package}::pool::refresh_stake`,\n arguments: [tx.object(pool.contract.pool), tx.object('0x05')]\n })\n }\n\n return tx\n}\n\n/**\n * Builds a withdraw transaction for a lending pool\n *\n * Constructs and adds withdrawal operations to a transaction object.\n * This function supports standard withdrawal and withdrawal using account capability.\n *\n * @param tx - The transaction builder to append operations to\n * @param identifier - Asset identifier for the pool\n * @param amount - Amount to withdraw\n * @param options - Optional parameters including environment and account capability\n * @returns Transaction result representing the withdrawn coins\n */\nexport async function withdrawCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n amount: number | TransactionResult,\n options?: Partial<EnvOption & AccountCapOption & MarketOption & ServiceOption>\n): Promise<SingleCoinTransactionResult> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n\n const withdrawAmount = parseTxValue(amount, tx.pure.u64)\n\n let withdrawBalance\n\n if (config.version === 1) {\n // Build withdraw transaction based on account capability\n if (options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n }\n } else {\n // Build withdraw transaction based on account capability\n if (options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw_with_account_cap_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::withdraw_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n withdrawAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n withdrawBalance = ret\n }\n }\n\n const withdrawCoin = tx.moveCall({\n target: `0x2::coin::from_balance`,\n arguments: [withdrawBalance],\n typeArguments: [pool.suiCoinType]\n })\n\n return withdrawCoin as SingleCoinTransactionResult\n}\n\nexport async function borrowCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n amount: number | TransactionResult,\n options?: Partial<EnvOption & AccountCapOption & MarketOption & ServiceOption>\n): Promise<SingleCoinTransactionResult> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n\n if (pool?.deprecatedAt && Date.now() > pool.deprecatedAt) {\n throw new Error(`The lending pool for coinType ${pool.suiCoinType} has been deprecated.`)\n }\n\n const borrowAmount = parseTxValue(amount, tx.pure.u64)\n\n let borrowBalance\n\n if (config.version === 1) {\n if (!options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n }\n } else {\n if (!options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n } else {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::borrow_with_account_cap_v2`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n borrowAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object),\n tx.object('0x05')\n ],\n typeArguments: [pool.suiCoinType]\n })\n borrowBalance = ret\n }\n }\n\n const coin = tx.moveCall({\n target: `0x2::coin::from_balance`,\n arguments: [tx.object(borrowBalance)],\n typeArguments: [pool.suiCoinType]\n })\n\n return coin as SingleCoinTransactionResult\n}\n\n/**\n * Builds a repay transaction for a lending pool debt\n *\n * Constructs and adds repayment operations to an existing transaction object.\n * This function handles loan repayments, supporting both standard user\n * repayments and privileged operations via account capabilities.\n *\n *\n * @param tx - The transaction builder to append repayment operations to\n * @param identifier - Unique identifier for the lending pool asset (e.g., \"USDC\", \"SUI\")\n * @param coinObject - The coin object to use for repayment, or GasCoin for SUI payments\n * @param options - Configuration options for the repayment\n * - `amount` - Specific amount to repay (required for SUI gas coin, otherwise uses value of specified coinObject)\n * - `accountCap` - Optional account capability object for privileged repayments\n * - `env` - Environment configuration\n * - `cacheTime` - Cache duration for configuration data\n *\n * @returns Promise<Transaction | TransactionResult> - The modified transaction object with repayment operations added\n *\n * @throws {Error} When amount is not provided for SUI gas coin repayments\n * @throws Will throw if pool doesn't exist or repayment validation fails\n */\nexport async function repayCoinPTB(\n tx: Transaction,\n identifier: AssetIdentifier,\n coinObject: CoinObject,\n options?: Partial<\n EnvOption &\n AccountCapOption &\n ServiceOption &\n MarketOption & {\n amount: number | TransactionResult\n }\n >\n): Promise<Transaction | TransactionResult> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n const pool = await getPool(identifier, options)\n if (\n normalizeCoinType(pool.suiCoinType) === normalizeCoinType('0x2::sui::SUI') &&\n typeof coinObject === 'object' &&\n coinObject?.$kind === 'GasCoin'\n ) {\n if (!options?.amount) {\n throw new Error('Amount is required for sui coin')\n }\n coinObject = tx.splitCoins(coinObject, [options.amount])\n }\n\n let repayAmount: TransactionResult\n\n if (typeof options?.amount !== 'undefined') {\n repayAmount = parseTxValue(options.amount, tx.pure.u64)\n } else {\n repayAmount = tx.moveCall({\n target: '0x2::coin::value',\n arguments: [parseTxValue(coinObject as any, tx.object)],\n typeArguments: [pool.suiCoinType]\n })\n }\n\n if (options?.accountCap) {\n const [ret] = tx.moveCall({\n target: `${config.package}::incentive_v3::repay_with_account_cap`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3),\n parseTxValue(options.accountCap, tx.object)\n ],\n typeArguments: [pool.suiCoinType]\n })\n const coin = tx.moveCall({\n target: `0x2::coin::from_balance`,\n arguments: [ret],\n typeArguments: [pool.suiCoinType]\n })\n return coin\n } else {\n tx.moveCall({\n target: `${config.package}::incentive_v3::entry_repay`,\n arguments: [\n tx.object('0x06'),\n tx.object(config.priceOracle),\n tx.object(config.storage),\n tx.object(pool.contract.pool),\n tx.pure.u8(pool.id),\n parseTxValue(coinObject, tx.object),\n repayAmount,\n tx.object(config.incentiveV2),\n tx.object(config.incentiveV3)\n ],\n typeArguments: [pool.suiCoinType]\n })\n return tx\n }\n}\n\n/**\n * Fetches the current borrow fee rate\n *\n * This function can retrieve borrow fee rates in two ways:\n * - If `address` and `asset` are provided, it calculates the specific borrow fee rate\n * for a given address and asset by calling the on-chain `get_borrow_fee_v2` function\n * - Otherwise, it returns the global borrow fee rate from the incentive V3 contract\n *\n * @param options - Optional configuration options\n * - `address` - User address to calculate specific borrow fee (requires `asset` to be set)\n * - `asset` - Asset identifier to calculate specific borrow fee (requires `address` to be set)\n * - `env` - Environment setting ('dev' or 'prod')\n * - `client` - Sui client instance for on-chain queries\n * - `cacheTime` - Cache expiration time in milliseconds\n * - `disableCache` - Whether to disable caching for this operation\n * @returns Promise<number> - Borrow fee rate as a decimal number\n * - When `address` and `asset` are provided: returns the specific fee rate (divided by 10000)\n * - Otherwise: returns the global fee rate (divided by 100)\n */\nexport const getBorrowFee = withCache(\n withSingleton(\n async (\n options?: Partial<EnvOption & CacheOption & BorrowFeeOption & SuiClientOption & MarketOption>\n ): Promise<number> => {\n const config = await getConfig({\n ...options\n })\n const client = options?.client ?? suiClient\n if (options?.address && typeof options?.asset !== 'undefined') {\n try {\n const pool = await getPool(options.asset, options)\n const tx = new Transaction()\n tx.moveCall({\n target: `${config.package}::incentive_v3::get_borrow_fee_v2`,\n arguments: [\n tx.object(config.incentiveV3),\n tx.pure.address(options.address),\n tx.pure.u8(pool.id),\n tx.pure.u64(10000)\n ],\n typeArguments: []\n })\n const result = await devInspectTransaction(client, {\n transactionBlock: tx,\n sender: options.address\n })\n const res = parseDevInspectResult<number[]>(result, [bcs.u64()])\n return (Number(res[0]) || 0) / 100\n } catch (error) {\n // Per-user borrow-fee query failed -> fall back to the global rate below\n // (semantic change; marked explicitly for traceability, fallback behavior unchanged).\n console.error(\n '[lending] getBorrowFee per-user query failed, falling back to global rate:',\n error\n )\n }\n }\n const rawData: any = await getSuiObject(client, {\n id: config.incentiveV3,\n options: { showType: true, showOwner: true, showContent: true }\n })\n const borrowFee = rawData.data.content.fields.borrow_fee_rate\n return Number(borrowFee) / 100\n }\n )\n)\n"],"names":["PoolOperator","getPools","withCache","withSingleton","options","markets","MARKETS","identity","getMarketConfig","endpoint","resolveNaviOpenApiEndpoint","poolsFilter","url","buildNaviOpenApiUrl","packageJson","market","res","mergeServiceHeaders","requestHeaders","pool","emodes","emode","asset","poolSupplyAmount","BigNumber","poolBorrowAmount","poolSupplyValue","poolBorrowValue","poolSupplyCapAmount","poolBorrowCapAmount","poolSupplyCapValue","poolBorrowCapValue","getPool","identifier","parsedUID","parsePoolUID","pools","DEFAULT_MARKET_IDENTITY","DEFAULT_CACHE_TIME","p","normalizeCoinType","getStats","getFees","depositCoinPTB","tx","coinObject","config","getConfig","env","depositAmount","parseTxValue","withdrawCoinPTB","amount","withdrawAmount","withdrawBalance","ret","borrowCoinPTB","borrowAmount","borrowBalance","repayCoinPTB","repayAmount","getBorrowFee","client","suiClient","Transaction","result","devInspectTransaction","parseDevInspectResult","bcs","error","borrowFee","getSuiObject"],"mappings":";;;;;;;;AAsDO,IAAKA,sBAAAA,OAEVA,EAAAA,EAAA,SAAS,CAAA,IAAT,UAEAA,EAAAA,EAAA,WAAW,CAAA,IAAX,YAEAA,EAAAA,EAAA,SAAS,CAAA,IAAT,UAEAA,EAAAA,EAAA,QAAQ,CAAA,IAAR,SARUA,IAAAA,KAAA,CAAA,CAAA;AAoBL,MAAMC,IAAWC;AAAA,EACtBC;AAAA,IACE,OACEC,MAQoB;AACpB,YAAMC,KAAWD,GAAS,WAAW,CAACE,EAAQ,IAAI,GAAG,IAAI,CAACC,MACjDC,EAAgBD,CAAQ,CAChC,GACKE,IAAWC,EAA2BN,CAAO,GAC7CO,KAAeP,GAAS,SAAS,CAAA,GAAI,KAAK,GAAG,GAC7CQ,IAAMC;AAAA,QACV,mBAAmBT,GAAS,OAAO,MAAM,QAAQU,EAAY,OAAO,WAAWT,EAAQ;AAAA,UACrF,CAACU,MACQA,EAAO;AAAA,QAChB,CACD,GAAKJ,IAAc,YAAYA,IAAc,EAAE;AAAA,QAChDP;AAAA,MAAA,GAEIY,IAKF,MAAM,MAAMJ,GAAK,EAAE,SAASK,EAAoBC,GAAgBT,CAAQ,EAAA,CAAG,EAAE;AAAA,QAAK,CAACO,MACrFA,EAAI,KAAA;AAAA,MAAK;AAGX,aAAAA,EAAI,KAAK,QAAQ,CAACG,MAAS;AAKzB,cAAMC,IAJeJ,EAAI,KAAK,OAAO,OAAO,CAACK,MAAU;AACrD,gBAAMN,IAASP,EAAgBa,EAAM,QAAQ;AAC7C,iBAAOF,EAAK,WAAWJ,EAAO,OAAOM,EAAM;AAAA,QAC7C,CAAC,EAC2B,OAA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