@naviprotocol/lending 2.0.6 → 2.0.8
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-cap.d.ts +1 -1
- package/dist/account-cap.js +26 -0
- package/dist/account-cap.js.map +1 -0
- package/dist/account.d.ts +2 -2
- package/dist/account.js +655 -0
- package/dist/account.js.map +1 -0
- package/dist/bcs.js +137 -0
- package/dist/bcs.js.map +1 -0
- package/dist/config.d.ts +1 -1
- package/dist/config.js +22 -0
- package/dist/config.js.map +1 -0
- package/dist/emode.d.ts +1 -1
- package/dist/emode.js +90 -0
- package/dist/emode.js.map +1 -0
- package/dist/flashloan.d.ts +1 -1
- package/dist/flashloan.js +94 -0
- package/dist/flashloan.js.map +1 -0
- package/dist/index.d.ts +17 -17
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/liquidate.d.ts +1 -1
- package/dist/liquidate.js +76 -0
- package/dist/liquidate.js.map +1 -0
- package/dist/market.d.ts +1 -1
- package/dist/market.js +121 -0
- package/dist/market.js.map +1 -0
- package/dist/oracle.d.ts +7 -2
- package/dist/oracle.d.ts.map +1 -1
- package/dist/oracle.js +206 -0
- package/dist/oracle.js.map +1 -0
- package/dist/package.json.js +8 -0
- package/dist/package.json.js.map +1 -0
- package/dist/pool.d.ts +1 -1
- package/dist/pool.js +391 -0
- package/dist/pool.js.map +1 -0
- package/dist/pyth.d.ts +5 -3
- package/dist/pyth.d.ts.map +1 -1
- package/dist/pyth.js +305 -0
- package/dist/pyth.js.map +1 -0
- package/dist/reward.d.ts +1 -1
- package/dist/reward.js +343 -0
- package/dist/reward.js.map +1 -0
- package/dist/services.js +52 -0
- package/dist/services.js.map +1 -0
- package/dist/sui.d.ts +1 -1
- package/dist/sui.js +121 -0
- package/dist/sui.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/ua.js +16 -0
- package/dist/ua.js.map +1 -0
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +227 -0
- package/dist/utils.js.map +1 -0
- package/package.json +5 -5
- package/dist/index.esm.js +0 -2749
- package/dist/index.esm.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,21 +6,21 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module Lending
|
|
8
8
|
*/
|
|
9
|
-
export * from './account';
|
|
10
|
-
export * from './bcs';
|
|
11
|
-
export * from './config';
|
|
12
|
-
export * from './oracle';
|
|
13
|
-
export * from './flashloan';
|
|
14
|
-
export * from './liquidate';
|
|
15
|
-
export * from './pool';
|
|
16
|
-
export * from './reward';
|
|
17
|
-
export * from './types';
|
|
18
|
-
export { withCache, withSingleton, normalizeCoinType, parseTxValue, parsePoolUID } from './utils';
|
|
19
|
-
export * from './account-cap';
|
|
20
|
-
export * from './emode';
|
|
21
|
-
export * from './market';
|
|
22
|
-
export * from './sui';
|
|
23
|
-
export * from './pyth';
|
|
24
|
-
export { buildNaviOpenApiUrl, configureNaviSdk, mergeServiceHeaders, resolveNaviOpenApiEndpoint } from './services';
|
|
25
|
-
export type { NaviSdkConfig, NaviSdkServiceOptions, NaviServiceEndpoint, ServiceEndpointOption } from './services';
|
|
9
|
+
export * from './account.js';
|
|
10
|
+
export * from './bcs.js';
|
|
11
|
+
export * from './config.js';
|
|
12
|
+
export * from './oracle.js';
|
|
13
|
+
export * from './flashloan.js';
|
|
14
|
+
export * from './liquidate.js';
|
|
15
|
+
export * from './pool.js';
|
|
16
|
+
export * from './reward.js';
|
|
17
|
+
export * from './types.js';
|
|
18
|
+
export { withCache, withSingleton, normalizeCoinType, parseTxValue, parsePoolUID } from './utils.js';
|
|
19
|
+
export * from './account-cap.js';
|
|
20
|
+
export * from './emode.js';
|
|
21
|
+
export * from './market.js';
|
|
22
|
+
export * from './sui.js';
|
|
23
|
+
export * from './pyth.js';
|
|
24
|
+
export { buildNaviOpenApiUrl, configureNaviSdk, mergeServiceHeaders, resolveNaviOpenApiEndpoint } from './services.js';
|
|
25
|
+
export type { NaviSdkConfig, NaviSdkServiceOptions, NaviServiceEndpoint, ServiceEndpointOption } from './services.js';
|
|
26
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
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 P, verifyHealthFactorPTB as c } from "./account.js";
|
|
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 F, getConfig as v } from "./config.js";
|
|
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
|
+
import { flashloanPTB as R, getAllFlashLoanAssets as O, getFlashLoanAsset as H, repayFlashLoanPTB as _ } from "./flashloan.js";
|
|
6
|
+
import { liquidatePTB as D } from "./liquidate.js";
|
|
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
|
+
import { claimLendingRewardsPTB as Z, getUserAvailableLendingRewards as $, getUserClaimedRewardHistory as ee, getUserTotalClaimedReward as te, summaryLendingRewards as re } from "./reward.js";
|
|
9
|
+
import { normalizeCoinType as ae, parsePoolUID as ie, parseTxValue as ne, withCache as se, withSingleton as le } from "./utils.js";
|
|
10
|
+
import { createAccountCapPTB as ge, getAccountCapOwnerPTB as Pe } from "./account-cap.js";
|
|
11
|
+
import { createEModeCapPTB as pe, emodeIdentityId as Te, enterEModePTB as fe, exitEModePTB as Ce, getUserEModeCaps as Be } from "./emode.js";
|
|
12
|
+
import { DEFAULT_MARKET_IDENTITY as he, MARKETS as Ae, Market as Ie, getMarket as ue, getMarketConfig as Fe, getMarkets as ve } from "./market.js";
|
|
13
|
+
import { NaviMissingGraphQLClientError as Le, PUBLIC_MAINNET_GRPC_URL as Se, createNaviLegacyJsonRpcClient as ye, createNaviSuiClient as Ee, createNaviSuiClientBundle as Me, getAddressBalance as Ue, getCoinObjectOnlyBalance as we, listAddressBalances as Ne, normalizeAddressBalance as Re, requireNaviGraphQLClient as Oe } from "./sui.js";
|
|
14
|
+
import { SuiPriceServiceConnection as _e, SuiPythClient as ke } from "./pyth.js";
|
|
15
|
+
import { buildNaviOpenApiUrl as be, configureNaviSdk as Ge, mergeServiceHeaders as qe, resolveNaviOpenApiEndpoint as ze } from "./services.js";
|
|
16
|
+
export {
|
|
17
|
+
T as Address,
|
|
18
|
+
F as DEFAULT_CACHE_TIME,
|
|
19
|
+
he as DEFAULT_MARKET_IDENTITY,
|
|
20
|
+
f as FlashLoanAssetConfig,
|
|
21
|
+
C as IncentiveAPYInfo,
|
|
22
|
+
B as IncentivePoolInfo,
|
|
23
|
+
m as IncentivePoolInfoByPhase,
|
|
24
|
+
Ae as MARKETS,
|
|
25
|
+
Ie as Market,
|
|
26
|
+
Le as NaviMissingGraphQLClientError,
|
|
27
|
+
h as OracleInfo,
|
|
28
|
+
Se as PUBLIC_MAINNET_GRPC_URL,
|
|
29
|
+
G as PoolOperator,
|
|
30
|
+
A as ReserveDataInfo,
|
|
31
|
+
_e as SuiPriceServiceConnection,
|
|
32
|
+
ke as SuiPythClient,
|
|
33
|
+
r as UserPositions,
|
|
34
|
+
I as UserStateInfo,
|
|
35
|
+
q as borrowCoinPTB,
|
|
36
|
+
be as buildNaviOpenApiUrl,
|
|
37
|
+
Z as claimLendingRewardsPTB,
|
|
38
|
+
Ge as configureNaviSdk,
|
|
39
|
+
ge as createAccountCapPTB,
|
|
40
|
+
pe as createEModeCapPTB,
|
|
41
|
+
ye as createNaviLegacyJsonRpcClient,
|
|
42
|
+
Ee as createNaviSuiClient,
|
|
43
|
+
Me as createNaviSuiClientBundle,
|
|
44
|
+
z as depositCoinPTB,
|
|
45
|
+
Te as emodeIdentityId,
|
|
46
|
+
fe as enterEModePTB,
|
|
47
|
+
Ce as exitEModePTB,
|
|
48
|
+
L as filterPriceFeeds,
|
|
49
|
+
R as flashloanPTB,
|
|
50
|
+
Pe as getAccountCapOwnerPTB,
|
|
51
|
+
Ue as getAddressBalance,
|
|
52
|
+
O as getAllFlashLoanAssets,
|
|
53
|
+
K as getBorrowFee,
|
|
54
|
+
we as getCoinObjectOnlyBalance,
|
|
55
|
+
o as getCoins,
|
|
56
|
+
v as getConfig,
|
|
57
|
+
Q as getFees,
|
|
58
|
+
H as getFlashLoanAsset,
|
|
59
|
+
a as getHealthFactor,
|
|
60
|
+
i as getHealthFactorPTB,
|
|
61
|
+
n as getLendingPositions,
|
|
62
|
+
s as getLendingState,
|
|
63
|
+
ue as getMarket,
|
|
64
|
+
Fe as getMarketConfig,
|
|
65
|
+
ve as getMarkets,
|
|
66
|
+
V as getPool,
|
|
67
|
+
Y as getPools,
|
|
68
|
+
S as getPriceFeeds,
|
|
69
|
+
y as getPythStalePriceFeedId,
|
|
70
|
+
E as getPythStalePriceFeedIdV2,
|
|
71
|
+
l as getSimulatedHealthFactor,
|
|
72
|
+
d as getSimulatedHealthFactorPTB,
|
|
73
|
+
j as getStats,
|
|
74
|
+
g as getTransactions,
|
|
75
|
+
$ as getUserAvailableLendingRewards,
|
|
76
|
+
ee as getUserClaimedRewardHistory,
|
|
77
|
+
Be as getUserEModeCaps,
|
|
78
|
+
te as getUserTotalClaimedReward,
|
|
79
|
+
D as liquidatePTB,
|
|
80
|
+
Ne as listAddressBalances,
|
|
81
|
+
P as mergeCoinsPTB,
|
|
82
|
+
qe as mergeServiceHeaders,
|
|
83
|
+
Re as normalizeAddressBalance,
|
|
84
|
+
ae as normalizeCoinType,
|
|
85
|
+
ie as parsePoolUID,
|
|
86
|
+
ne as parseTxValue,
|
|
87
|
+
J as repayCoinPTB,
|
|
88
|
+
_ as repayFlashLoanPTB,
|
|
89
|
+
Oe as requireNaviGraphQLClient,
|
|
90
|
+
ze as resolveNaviOpenApiEndpoint,
|
|
91
|
+
re as summaryLendingRewards,
|
|
92
|
+
M as updateOraclePriceBeforeUserOperationPTB,
|
|
93
|
+
U as updateOraclePricesPTB,
|
|
94
|
+
w as updatePythPriceFeeds,
|
|
95
|
+
c as verifyHealthFactorPTB,
|
|
96
|
+
se as withCache,
|
|
97
|
+
le as withSingleton,
|
|
98
|
+
W as withdrawCoinPTB
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
package/dist/liquidate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AssetIdentifier, CoinObject, EnvOption, TransactionResult, MarketOption, ServiceOption } from './types';
|
|
1
|
+
import { AssetIdentifier, CoinObject, EnvOption, TransactionResult, MarketOption, ServiceOption } from './types.js';
|
|
2
2
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { getConfig as j, DEFAULT_CACHE_TIME as g } from "./config.js";
|
|
2
|
+
import { getPool as u } from "./pool.js";
|
|
3
|
+
import { parseTxValue as n } from "./utils.js";
|
|
4
|
+
async function C(e, s, l, b, p, m) {
|
|
5
|
+
const i = {
|
|
6
|
+
...m,
|
|
7
|
+
cacheTime: g
|
|
8
|
+
}, o = await j(i), c = await u(s, i), a = await u(b, i);
|
|
9
|
+
if (o.version === 1) {
|
|
10
|
+
const [t, r] = e.moveCall({
|
|
11
|
+
target: `${o.package}::incentive_v3::liquidation`,
|
|
12
|
+
arguments: [
|
|
13
|
+
e.object("0x06"),
|
|
14
|
+
// Clock object
|
|
15
|
+
e.object(o.priceOracle),
|
|
16
|
+
// Price oracle for asset pricing
|
|
17
|
+
e.object(o.storage),
|
|
18
|
+
// Protocol storage
|
|
19
|
+
e.pure.u8(c.id),
|
|
20
|
+
// Pay asset ID
|
|
21
|
+
e.object(c.contract.pool),
|
|
22
|
+
// Pay asset pool contract
|
|
23
|
+
n(l, e.object),
|
|
24
|
+
// Debt repayment amount
|
|
25
|
+
e.pure.u8(a.id),
|
|
26
|
+
// Collateral asset ID
|
|
27
|
+
e.object(a.contract.pool),
|
|
28
|
+
// Collateral asset pool contract
|
|
29
|
+
n(p, e.pure.address),
|
|
30
|
+
// Borrower address
|
|
31
|
+
e.object(o.incentiveV2),
|
|
32
|
+
// Incentive V2 contract
|
|
33
|
+
e.object(o.incentiveV3)
|
|
34
|
+
// Incentive V3 contract
|
|
35
|
+
],
|
|
36
|
+
typeArguments: [c.suiCoinType, a.suiCoinType]
|
|
37
|
+
});
|
|
38
|
+
return [t, r];
|
|
39
|
+
} else {
|
|
40
|
+
const [t, r] = e.moveCall({
|
|
41
|
+
target: `${o.package}::incentive_v3::liquidation_v2`,
|
|
42
|
+
arguments: [
|
|
43
|
+
e.object("0x06"),
|
|
44
|
+
// Clock object
|
|
45
|
+
e.object(o.priceOracle),
|
|
46
|
+
// Price oracle for asset pricing
|
|
47
|
+
e.object(o.storage),
|
|
48
|
+
// Protocol storage
|
|
49
|
+
e.pure.u8(c.id),
|
|
50
|
+
// Pay asset ID
|
|
51
|
+
e.object(c.contract.pool),
|
|
52
|
+
// Pay asset pool contract
|
|
53
|
+
n(l, e.object),
|
|
54
|
+
// Debt repayment amount
|
|
55
|
+
e.pure.u8(a.id),
|
|
56
|
+
// Collateral asset ID
|
|
57
|
+
e.object(a.contract.pool),
|
|
58
|
+
// Collateral asset pool contract
|
|
59
|
+
n(p, e.pure.address),
|
|
60
|
+
// Borrower address
|
|
61
|
+
e.object(o.incentiveV2),
|
|
62
|
+
// Incentive V2 contract
|
|
63
|
+
e.object(o.incentiveV3),
|
|
64
|
+
// Incentive V3 contract
|
|
65
|
+
e.object("0x05")
|
|
66
|
+
// SuiSystemState object
|
|
67
|
+
],
|
|
68
|
+
typeArguments: [c.suiCoinType, a.suiCoinType]
|
|
69
|
+
});
|
|
70
|
+
return [t, r];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
C as liquidatePTB
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=liquidate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidate.js","sources":["../src/liquidate.ts"],"sourcesContent":["/**\n * Liquidation Functionality for Lending Protocol\n *\n * This module provides liquidation capabilities for the lending protocol.\n * Liquidation allows liquidators to repay a borrower's debt in exchange for their collateral\n * when the borrower's health factor falls below the liquidation threshold.\n */\n\nimport {\n AssetIdentifier,\n CoinObject,\n EnvOption,\n TransactionResult,\n MarketOption,\n ServiceOption\n} from './types'\nimport { Transaction } from '@mysten/sui/transactions'\nimport { DEFAULT_CACHE_TIME, getConfig } from './config'\nimport { getPool } from './pool'\nimport { getAllFlashLoanAssets } from './flashloan'\nimport { normalizeCoinType, parseTxValue } from './utils'\n\n/**\n * Create a liquidation transaction in the PTB (Programmable Transaction Block)\n *\n * This function allows liquidators to liquidate a borrower's position by repaying\n * their debt in exchange for their collateral. The liquidation process uses flash loans\n * to ensure atomic execution of the liquidation transaction.\n *\n * @param tx - The transaction block to add the liquidation operation to\n * @param payAsset - Asset identifier for the debt being repaid\n * @param payCoinObject - Coin object containing the debt repayment amount\n * @param collateralAsset - Asset identifier for the collateral being liquidated\n * @param liquidateAddress - Address of the borrower being liquidated\n * @param options - Optional environment configuration\n * @returns Tuple containing [collateralBalance, remainDebtBalance] where:\n * - collateralBalance: The collateral received from liquidation\n * - remainDebtBalance: Any remaining debt after liquidation\n * @throws Error if either pay asset or collateral asset does not support flash loans\n */\nexport async function liquidatePTB(\n tx: Transaction,\n payAsset: AssetIdentifier,\n payCoinObject: CoinObject,\n collateralAsset: AssetIdentifier,\n liquidateAddress: string | TransactionResult,\n options?: Partial<EnvOption & MarketOption & ServiceOption>\n) {\n const commonOptions = {\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n }\n const config = await getConfig(commonOptions)\n const payPool = await getPool(payAsset, commonOptions)\n const collateralPool = await getPool(collateralAsset, commonOptions)\n\n if (config.version === 1) {\n // Execute the liquidation transaction\n const [collateralBalance, remainDebtBalance] = tx.moveCall({\n target: `${config.package}::incentive_v3::liquidation`,\n arguments: [\n tx.object('0x06'), // Clock object\n tx.object(config.priceOracle), // Price oracle for asset pricing\n tx.object(config.storage), // Protocol storage\n tx.pure.u8(payPool.id), // Pay asset ID\n tx.object(payPool.contract.pool), // Pay asset pool contract\n parseTxValue(payCoinObject, tx.object), // Debt repayment amount\n tx.pure.u8(collateralPool.id), // Collateral asset ID\n tx.object(collateralPool.contract.pool), // Collateral asset pool contract\n parseTxValue(liquidateAddress, tx.pure.address), // Borrower address\n tx.object(config.incentiveV2), // Incentive V2 contract\n tx.object(config.incentiveV3) // Incentive V3 contract\n ],\n typeArguments: [payPool.suiCoinType, collateralPool.suiCoinType]\n })\n\n return [collateralBalance, remainDebtBalance]\n } else {\n // Execute the liquidation transaction\n const [collateralBalance, remainDebtBalance] = tx.moveCall({\n target: `${config.package}::incentive_v3::liquidation_v2`,\n arguments: [\n tx.object('0x06'), // Clock object\n tx.object(config.priceOracle), // Price oracle for asset pricing\n tx.object(config.storage), // Protocol storage\n tx.pure.u8(payPool.id), // Pay asset ID\n tx.object(payPool.contract.pool), // Pay asset pool contract\n parseTxValue(payCoinObject, tx.object), // Debt repayment amount\n tx.pure.u8(collateralPool.id), // Collateral asset ID\n tx.object(collateralPool.contract.pool), // Collateral asset pool contract\n parseTxValue(liquidateAddress, tx.pure.address), // Borrower address\n tx.object(config.incentiveV2), // Incentive V2 contract\n tx.object(config.incentiveV3), // Incentive V3 contract\n tx.object('0x05') // SuiSystemState object\n ],\n typeArguments: [payPool.suiCoinType, collateralPool.suiCoinType]\n })\n\n return [collateralBalance, remainDebtBalance]\n }\n}\n"],"names":["liquidatePTB","tx","payAsset","payCoinObject","collateralAsset","liquidateAddress","options","commonOptions","DEFAULT_CACHE_TIME","config","getConfig","payPool","getPool","collateralPool","collateralBalance","remainDebtBalance","parseTxValue"],"mappings":";;;AAwCA,eAAsBA,EACpBC,GACAC,GACAC,GACAC,GACAC,GACAC,GACA;AACA,QAAMC,IAAgB;AAAA,IACpB,GAAGD;AAAA,IACH,WAAWE;AAAA,EAAA,GAEPC,IAAS,MAAMC,EAAUH,CAAa,GACtCI,IAAU,MAAMC,EAAQV,GAAUK,CAAa,GAC/CM,IAAiB,MAAMD,EAAQR,GAAiBG,CAAa;AAEnE,MAAIE,EAAO,YAAY,GAAG;AAExB,UAAM,CAACK,GAAmBC,CAAiB,IAAId,EAAG,SAAS;AAAA,MACzD,QAAQ,GAAGQ,EAAO,OAAO;AAAA,MACzB,WAAW;AAAA,QACTR,EAAG,OAAO,MAAM;AAAA;AAAA,QAChBA,EAAG,OAAOQ,EAAO,WAAW;AAAA;AAAA,QAC5BR,EAAG,OAAOQ,EAAO,OAAO;AAAA;AAAA,QACxBR,EAAG,KAAK,GAAGU,EAAQ,EAAE;AAAA;AAAA,QACrBV,EAAG,OAAOU,EAAQ,SAAS,IAAI;AAAA;AAAA,QAC/BK,EAAab,GAAeF,EAAG,MAAM;AAAA;AAAA,QACrCA,EAAG,KAAK,GAAGY,EAAe,EAAE;AAAA;AAAA,QAC5BZ,EAAG,OAAOY,EAAe,SAAS,IAAI;AAAA;AAAA,QACtCG,EAAaX,GAAkBJ,EAAG,KAAK,OAAO;AAAA;AAAA,QAC9CA,EAAG,OAAOQ,EAAO,WAAW;AAAA;AAAA,QAC5BR,EAAG,OAAOQ,EAAO,WAAW;AAAA;AAAA,MAAA;AAAA,MAE9B,eAAe,CAACE,EAAQ,aAAaE,EAAe,WAAW;AAAA,IAAA,CAChE;AAED,WAAO,CAACC,GAAmBC,CAAiB;AAAA,EAC9C,OAAO;AAEL,UAAM,CAACD,GAAmBC,CAAiB,IAAId,EAAG,SAAS;AAAA,MACzD,QAAQ,GAAGQ,EAAO,OAAO;AAAA,MACzB,WAAW;AAAA,QACTR,EAAG,OAAO,MAAM;AAAA;AAAA,QAChBA,EAAG,OAAOQ,EAAO,WAAW;AAAA;AAAA,QAC5BR,EAAG,OAAOQ,EAAO,OAAO;AAAA;AAAA,QACxBR,EAAG,KAAK,GAAGU,EAAQ,EAAE;AAAA;AAAA,QACrBV,EAAG,OAAOU,EAAQ,SAAS,IAAI;AAAA;AAAA,QAC/BK,EAAab,GAAeF,EAAG,MAAM;AAAA;AAAA,QACrCA,EAAG,KAAK,GAAGY,EAAe,EAAE;AAAA;AAAA,QAC5BZ,EAAG,OAAOY,EAAe,SAAS,IAAI;AAAA;AAAA,QACtCG,EAAaX,GAAkBJ,EAAG,KAAK,OAAO;AAAA;AAAA,QAC9CA,EAAG,OAAOQ,EAAO,WAAW;AAAA;AAAA,QAC5BR,EAAG,OAAOQ,EAAO,WAAW;AAAA;AAAA,QAC5BR,EAAG,OAAO,MAAM;AAAA;AAAA,MAAA;AAAA,MAElB,eAAe,CAACU,EAAQ,aAAaE,EAAe,WAAW;AAAA,IAAA,CAChE;AAED,WAAO,CAACC,GAAmBC,CAAiB;AAAA,EAC9C;AACF;"}
|
package/dist/market.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarketIdentity, EnvOption, CacheOption, EMode, MarketConfig, Pool, EModePool } from './types';
|
|
1
|
+
import { MarketIdentity, EnvOption, CacheOption, EMode, MarketConfig, Pool, EModePool } from './types.js';
|
|
2
2
|
|
|
3
3
|
export declare const DEFAULT_MARKET_IDENTITY = "main";
|
|
4
4
|
export declare const MARKETS: {
|
package/dist/market.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { withCache as M, getPoolsMap as p, getEmodesMap as f, withSingleton as g } from "./utils.js";
|
|
2
|
+
import { getPools as k } from "./pool.js";
|
|
3
|
+
import m from "bignumber.js";
|
|
4
|
+
const v = "main", E = {
|
|
5
|
+
main: {
|
|
6
|
+
id: 0,
|
|
7
|
+
key: "main",
|
|
8
|
+
name: "Main Market"
|
|
9
|
+
},
|
|
10
|
+
ember: {
|
|
11
|
+
id: 1,
|
|
12
|
+
key: "ember",
|
|
13
|
+
name: "Ember Market"
|
|
14
|
+
},
|
|
15
|
+
rwa: {
|
|
16
|
+
id: 2,
|
|
17
|
+
key: "rwa",
|
|
18
|
+
name: "Matrixdock Market"
|
|
19
|
+
},
|
|
20
|
+
"sui-eco": {
|
|
21
|
+
id: 3,
|
|
22
|
+
key: "sui-eco",
|
|
23
|
+
name: "Sui Eco Market"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
class P {
|
|
27
|
+
constructor(o, s) {
|
|
28
|
+
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
29
|
+
marketTotalSupplyValue: "0",
|
|
30
|
+
marketTotalBorrowValue: "0"
|
|
31
|
+
}, this.config = b(o), this.initPools(s);
|
|
32
|
+
}
|
|
33
|
+
get overview() {
|
|
34
|
+
return this._overview;
|
|
35
|
+
}
|
|
36
|
+
initPools(o) {
|
|
37
|
+
const s = p(this.pools), i = f(this.emodes), t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
|
|
38
|
+
let a = m(0), l = m(0);
|
|
39
|
+
o.forEach((e) => {
|
|
40
|
+
if (!this.checkMarket(e.market)) {
|
|
41
|
+
console.warn(`Pool is not in market ${this.config.name}`, e);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
s[e.uniqueId] || this.pools.push(e), e?.emodes?.forEach((u) => {
|
|
45
|
+
i[u.uniqueId] || this.emodes.push(u), u.assets.forEach((h) => {
|
|
46
|
+
h.isDebt && u.assets.find(
|
|
47
|
+
(d) => d.isCollateral && d.ltv > 0 && d.assetId !== e.id
|
|
48
|
+
) && t.add(e.uniqueId), h.isCollateral && u.assets.find((d) => d.isDebt && d.assetId !== e.id) && n.add(e.uniqueId);
|
|
49
|
+
});
|
|
50
|
+
}), l = l.plus(e.poolBorrowValue), a = a.plus(e.poolSupplyValue);
|
|
51
|
+
}), this.poolMap = p(this.pools, "id"), this.emodeMap = f(this.emodes, "emodeId"), this.emodes.forEach((e) => {
|
|
52
|
+
const c = this.getEModePools(e.emodeId);
|
|
53
|
+
this.emodePools.push(...c);
|
|
54
|
+
}), this._overview = {
|
|
55
|
+
marketTotalSupplyValue: a.toString(),
|
|
56
|
+
marketTotalBorrowValue: l.toString()
|
|
57
|
+
}, this.emodeBorrowablePools = this.pools.filter((e) => t.has(e.uniqueId)), this.emodeSupplyablePools = this.pools.filter((e) => n.has(e.uniqueId));
|
|
58
|
+
}
|
|
59
|
+
getEMode(o) {
|
|
60
|
+
return this.emodeMap[o] || null;
|
|
61
|
+
}
|
|
62
|
+
getEModeRelatePools(o, s) {
|
|
63
|
+
const { collateral: i, debt: t, emodeId: n } = s || {}, a = [];
|
|
64
|
+
return o.emodes.forEach((l) => {
|
|
65
|
+
typeof n == "number" && n !== l.emodeId || l.assets.forEach((e) => {
|
|
66
|
+
typeof i == "boolean" && i && e.isCollateral && e.assetId === o.id && a.push(this.poolMap[e.assetId]), typeof t == "boolean" && t && e.isDebt && e.assetId === o.id && a.push(this.poolMap[e.assetId]);
|
|
67
|
+
});
|
|
68
|
+
}), a;
|
|
69
|
+
}
|
|
70
|
+
getEModePools(o) {
|
|
71
|
+
const s = this.getEMode(o);
|
|
72
|
+
return s ? s.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
|
|
73
|
+
const n = s.assets.find((a) => a.assetId === t.id);
|
|
74
|
+
return {
|
|
75
|
+
...t,
|
|
76
|
+
emode: {
|
|
77
|
+
...n,
|
|
78
|
+
emodeId: s.emodeId
|
|
79
|
+
},
|
|
80
|
+
isEMode: !0
|
|
81
|
+
};
|
|
82
|
+
}) : [];
|
|
83
|
+
}
|
|
84
|
+
checkMarket(o) {
|
|
85
|
+
let s = !1;
|
|
86
|
+
return typeof o == "number" && o === this.config.id && (s = !0), typeof o == "string" && o === this.config.key && (s = !0), typeof o == "object" && o.id === this.config.id && (s = !0), s;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const b = (r) => {
|
|
90
|
+
const s = Object.values(E).find((i) => typeof r == "number" ? i.id === r : typeof r == "string" ? i.key === r : i.id === r.id);
|
|
91
|
+
if (!s)
|
|
92
|
+
throw new Error("Market not found");
|
|
93
|
+
return s;
|
|
94
|
+
}, y = M(
|
|
95
|
+
g(
|
|
96
|
+
async (r, o) => {
|
|
97
|
+
const s = await k({
|
|
98
|
+
cacheTime: 6e4,
|
|
99
|
+
...o,
|
|
100
|
+
markets: r
|
|
101
|
+
});
|
|
102
|
+
return r.map((i) => {
|
|
103
|
+
const t = b(i), n = s.filter((a) => a.market === t.key);
|
|
104
|
+
return new P(i, n);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
), B = M(
|
|
109
|
+
g(
|
|
110
|
+
async (r, o) => (await y([r], o))[0]
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
export {
|
|
114
|
+
v as DEFAULT_MARKET_IDENTITY,
|
|
115
|
+
E as MARKETS,
|
|
116
|
+
P as Market,
|
|
117
|
+
B as getMarket,
|
|
118
|
+
b as getMarketConfig,
|
|
119
|
+
y as getMarkets
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=market.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"market.js","sources":["../src/market.ts"],"sourcesContent":["import { withCache, withSingleton, getPoolsMap, getEmodesMap } from './utils'\nimport type {\n MarketIdentity,\n EnvOption,\n CacheOption,\n EMode,\n MarketConfig,\n Pool,\n EModePool\n} from './types'\nimport { getPools } from './pool'\nimport BigNumber from 'bignumber.js'\n\nexport const DEFAULT_MARKET_IDENTITY = 'main'\n\nexport const MARKETS = {\n main: {\n id: 0,\n key: 'main',\n name: 'Main Market'\n },\n ember: {\n id: 1,\n key: 'ember',\n name: 'Ember Market'\n },\n rwa: {\n id: 2,\n key: 'rwa',\n name: 'Matrixdock Market'\n },\n 'sui-eco': {\n id: 3,\n key: 'sui-eco',\n name: 'Sui Eco Market'\n }\n}\n\nexport class Market {\n private poolMap = {} as Record<string, Pool>\n private emodeMap = {} as Record<string, EMode>\n readonly config: MarketConfig\n readonly pools: Pool[] = []\n readonly emodes: EMode[] = []\n readonly emodePools: EModePool[] = []\n emodeBorrowablePools: Pool[] = []\n emodeSupplyablePools: Pool[] = []\n\n private _overview = {\n marketTotalSupplyValue: '0',\n marketTotalBorrowValue: '0'\n }\n\n get overview() {\n return this._overview\n }\n\n constructor(marketIdentity: MarketIdentity, pools: Pool[]) {\n this.config = getMarketConfig(marketIdentity)\n this.initPools(pools)\n }\n\n private initPools(pools: Pool[]) {\n const poolsMap = getPoolsMap(this.pools)\n const emodesMap = getEmodesMap(this.emodes)\n const emodeBorrowablePoolIds = new Set<string>()\n const emodeSupplyablePoolIds = new Set<string>()\n let marketTotalSupplyValue = BigNumber(0)\n let marketTotalBorrowValue = BigNumber(0)\n\n pools.forEach((pool) => {\n const isMatch = this.checkMarket(pool.market)\n if (!isMatch) {\n console.warn(`Pool is not in market ${this.config.name}`, pool)\n return\n }\n if (!poolsMap[pool.uniqueId]) {\n this.pools.push(pool)\n }\n pool?.emodes?.forEach((emode) => {\n if (!emodesMap[emode.uniqueId]) {\n this.emodes.push(emode)\n }\n emode.assets.forEach((asset) => {\n if (asset.isDebt) {\n const debtAsset = emode.assets.find(\n (a) => a.isCollateral && a.ltv > 0 && a.assetId !== pool.id\n )\n if (debtAsset) {\n emodeBorrowablePoolIds.add(pool.uniqueId)\n }\n }\n if (asset.isCollateral) {\n const supplyAsset = emode.assets.find((a) => a.isDebt && a.assetId !== pool.id)\n if (supplyAsset) {\n emodeSupplyablePoolIds.add(pool.uniqueId)\n }\n }\n })\n })\n marketTotalBorrowValue = marketTotalBorrowValue.plus(pool.poolBorrowValue)\n marketTotalSupplyValue = marketTotalSupplyValue.plus(pool.poolSupplyValue)\n })\n this.poolMap = getPoolsMap(this.pools, 'id')\n this.emodeMap = getEmodesMap(this.emodes, 'emodeId')\n this.emodes.forEach((emode) => {\n const emodePools = this.getEModePools(emode.emodeId)\n this.emodePools.push(...emodePools)\n })\n this._overview = {\n marketTotalSupplyValue: marketTotalSupplyValue.toString(),\n marketTotalBorrowValue: marketTotalBorrowValue.toString()\n }\n this.emodeBorrowablePools = this.pools.filter((pool) => {\n return emodeBorrowablePoolIds.has(pool.uniqueId)\n })\n this.emodeSupplyablePools = this.pools.filter((pool) => {\n return emodeSupplyablePoolIds.has(pool.uniqueId)\n })\n }\n\n public getEMode(emodeId: number): EMode | null {\n const emode = this.emodeMap[emodeId]\n return emode || null\n }\n\n public getEModeRelatePools(\n pool: Pool,\n options?: {\n collateral?: boolean\n debt?: boolean\n emodeId?: number\n }\n ): Pool[] {\n const { collateral, debt, emodeId } = options || {}\n const relatePools = [] as Pool[]\n pool.emodes.forEach((emode) => {\n if (typeof emodeId === 'number' && emodeId !== emode.emodeId) {\n return\n }\n emode.assets.forEach((asset) => {\n if (\n typeof collateral === 'boolean' &&\n collateral &&\n asset.isCollateral &&\n asset.assetId === pool.id\n ) {\n relatePools.push(this.poolMap[asset.assetId])\n }\n if (typeof debt === 'boolean' && debt && asset.isDebt && asset.assetId === pool.id) {\n relatePools.push(this.poolMap[asset.assetId])\n }\n })\n })\n return relatePools\n }\n\n public getEModePools(emodeId: number): EModePool[] {\n const emode = this.getEMode(emodeId)\n if (!emode) {\n return []\n }\n const pools = emode.assets\n .map((asset) => asset.assetId)\n .map((id) => {\n return this.poolMap[id]\n })\n .filter((pool) => !!pool)\n return pools.map((pool) => {\n const asset = emode.assets.find((asset) => asset.assetId === pool.id)!\n return {\n ...pool,\n emode: {\n ...asset,\n emodeId: emode.emodeId\n },\n isEMode: true\n }\n })\n }\n\n private checkMarket(marketIdentity: MarketIdentity) {\n let isMatch = false\n if (typeof marketIdentity === 'number' && marketIdentity === this.config.id) {\n isMatch = true\n }\n if (typeof marketIdentity === 'string' && marketIdentity === this.config.key) {\n isMatch = true\n }\n if (typeof marketIdentity === 'object' && marketIdentity.id === this.config.id) {\n isMatch = true\n }\n return isMatch\n }\n}\n\nexport const getMarketConfig = (marketIdentity: MarketIdentity) => {\n const configs = Object.values(MARKETS)\n const config = configs.find((marketConfig) => {\n if (typeof marketIdentity === 'number') {\n return marketConfig.id === marketIdentity\n }\n if (typeof marketIdentity === 'string') {\n return marketConfig.key === marketIdentity\n }\n return marketConfig.id === marketIdentity.id\n })\n if (!config) {\n throw new Error(`Market not found`)\n }\n return config\n}\n\nexport const getMarkets = withCache(\n withSingleton(\n async (\n markets: MarketIdentity[],\n options?: Partial<EnvOption & CacheOption>\n ): Promise<Market[]> => {\n const pools = await getPools({\n cacheTime: 1000 * 60,\n ...options,\n markets\n })\n return markets.map((market) => {\n const marketConfig = getMarketConfig(market)\n const marketPools = pools.filter((pool) => {\n return pool.market === marketConfig.key\n })\n return new Market(market, marketPools)\n })\n }\n )\n)\n\nexport const getMarket = withCache(\n withSingleton(\n async (market: MarketIdentity, options?: Partial<EnvOption & CacheOption>): Promise<Market> => {\n const markets = await getMarkets([market], options)\n return markets[0]\n }\n )\n)\n"],"names":["DEFAULT_MARKET_IDENTITY","MARKETS","Market","marketIdentity","pools","getMarketConfig","poolsMap","getPoolsMap","emodesMap","getEmodesMap","emodeBorrowablePoolIds","emodeSupplyablePoolIds","marketTotalSupplyValue","BigNumber","marketTotalBorrowValue","pool","emode","asset","a","emodePools","emodeId","options","collateral","debt","relatePools","id","isMatch","config","marketConfig","getMarkets","withCache","withSingleton","markets","getPools","market","marketPools","getMarket"],"mapp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,IAAU,KAELA;AAAA,EACT;AACF;AAEO,MAAMrB,IAAkB,CAACF,MAAmC;AAEjE,QAAMwB,IADU,OAAO,OAAO1B,CAAO,EACd,KAAK,CAAC2B,MACvB,OAAOzB,KAAmB,WACrByB,EAAa,OAAOzB,IAEzB,OAAOA,KAAmB,WACrByB,EAAa,QAAQzB,IAEvByB,EAAa,OAAOzB,EAAe,EAC3C;AACD,MAAI,CAACwB;AACH,UAAM,IAAI,MAAM,kBAAkB;AAEpC,SAAOA;AACT,GAEaE,IAAaC;AAAA,EACxBC;AAAA,IACE,OACEC,GACAX,MACsB;AACtB,YAAMjB,IAAQ,MAAM6B,EAAS;AAAA,QAC3B,WAAW;AAAA,QACX,GAAGZ;AAAA,QACH,SAAAW;AAAA,MAAA,CACD;AACD,aAAOA,EAAQ,IAAI,CAACE,MAAW;AAC7B,cAAMN,IAAevB,EAAgB6B,CAAM,GACrCC,IAAc/B,EAAM,OAAO,CAACW,MACzBA,EAAK,WAAWa,EAAa,GACrC;AACD,eAAO,IAAI1B,EAAOgC,GAAQC,CAAW;AAAA,MACvC,CAAC;AAAA,IACH;AAAA,EAAA;AAEJ,GAEaC,IAAYN;AAAA,EACvBC;AAAA,IACE,OAAOG,GAAwBb,OACb,MAAMQ,EAAW,CAACK,CAAM,GAAGb,CAAO,GACnC,CAAC;AAAA,EAClB;AAEJ;"}
|
package/dist/oracle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OraclePriceFeed, EnvOption, UserLendingInfo, Pool, SuiClientOption, MarketOption, LendingPosition, ServiceOption } from './types';
|
|
1
|
+
import { OraclePriceFeed, EnvOption, UserLendingInfo, Pool, SuiClientOption, MarketOption, LendingPosition, ServiceOption, TransactionObjectArgument } from './types.js';
|
|
2
2
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
3
|
|
|
4
4
|
type PythInfo = {
|
|
@@ -38,7 +38,9 @@ export declare function getPythStalePriceFeedIdV2(pythInfos: PythInfo[], options
|
|
|
38
38
|
* @returns Promise that resolves when price feeds are updated
|
|
39
39
|
* @throws Error if failed to update price feeds
|
|
40
40
|
*/
|
|
41
|
-
export declare function updatePythPriceFeeds(tx: Transaction, priceFeedIds: string[], options?: Partial<SuiClientOption & EnvOption & MarketOption
|
|
41
|
+
export declare function updatePythPriceFeeds(tx: Transaction, priceFeedIds: string[], options?: Partial<SuiClientOption & EnvOption & MarketOption & {
|
|
42
|
+
pythFeeCoin?: TransactionObjectArgument;
|
|
43
|
+
}>): Promise<string[]>;
|
|
42
44
|
/**
|
|
43
45
|
* Update oracle prices in the PTB (Programmable Transaction Block)
|
|
44
46
|
*
|
|
@@ -53,6 +55,8 @@ export declare function updatePythPriceFeeds(tx: Transaction, priceFeedIds: stri
|
|
|
53
55
|
*/
|
|
54
56
|
export declare function updateOraclePricesPTB(tx: Transaction, priceFeeds: OraclePriceFeed[], options?: Partial<EnvOption & SuiClientOption & ServiceOption & MarketOption & {
|
|
55
57
|
updatePythPriceFeeds?: boolean;
|
|
58
|
+
/** Optional user-owned SUI coin used for Pyth update fees. Defaults to `tx.gas`. */
|
|
59
|
+
pythFeeCoin?: TransactionObjectArgument;
|
|
56
60
|
}>): Promise<Transaction>;
|
|
57
61
|
/**
|
|
58
62
|
* Get all available price feeds from the configuration
|
|
@@ -78,6 +82,7 @@ export declare function filterPriceFeeds(feeds: OraclePriceFeed[], filters: {
|
|
|
78
82
|
}): OraclePriceFeed[];
|
|
79
83
|
export declare function updateOraclePriceBeforeUserOperationPTB(tx: Transaction, address: string, pools: Pool[], options?: Partial<EnvOption & SuiClientOption & MarketOption & {
|
|
80
84
|
throws?: boolean;
|
|
85
|
+
pythFeeCoin?: TransactionObjectArgument;
|
|
81
86
|
}>): Promise<Transaction>;
|
|
82
87
|
export {};
|
|
83
88
|
//# sourceMappingURL=oracle.d.ts.map
|
package/dist/oracle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oracle.d.ts","sourceRoot":"","sources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AE,EACtB,OAAO,CAAC,EAAE,OAAO,CACf,eAAe,GACb,SAAS,GACT,YAAY,GAAG;IACb,WAAW,CAAC,EAAE,yBAAyB,CAAA;CACxC,CACJ,qBAuBF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,WAAW,EACf,UAAU,EAAE,eAAe,EAAE,EAC7B,OAAO,CAAC,EAAE,OAAO,CACf,SAAS,GACP,eAAe,GACf,aAAa,GACb,YAAY,GAAG;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,oFAAoF;IACpF,WAAW,CAAC,EAAE,yBAAyB,CAAA;CACxC,CACJ,GACA,OAAO,CAAC,WAAW,CAAC,CA0CtB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,GAAG,aAAa,CAAC,GAC3C,OAAO,CAAC,eAAe,EAAE,CAAC,CAM5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,eAAe,EAAE,EACxB,OAAO,EAAE;IACP,YAAY,CAAC,EAAE,eAAe,EAAE,CAAA;IAChC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAA;IACd,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAA;CACrC,GACA,eAAe,EAAE,CA0CnB;AAED,wBAAsB,uCAAuC,CAC3D,EAAE,EAAE,WAAW,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,IAAI,EAAE,EACb,OAAO,CAAC,EAAE,OAAO,CACf,SAAS,GACP,eAAe,GACf,YAAY,GAAG;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,WAAW,CAAC,EAAE,yBAAyB,CAAA;CACxC,CACJ,wBAqDF"}
|
package/dist/oracle.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { getConfig as p, DEFAULT_CACHE_TIME as l } from "./config.js";
|
|
2
|
+
import { SuiPythClient as F, SuiPriceServiceConnection as j } from "./pyth.js";
|
|
3
|
+
import { suiClient as b, multiGetSuiObjects as T } from "./utils.js";
|
|
4
|
+
import { getLendingPositions as O } from "./account.js";
|
|
5
|
+
const h = /* @__PURE__ */ new Map(), y = (i) => {
|
|
6
|
+
const c = i ?? "https://hermes.pyth.network";
|
|
7
|
+
let e = h.get(c);
|
|
8
|
+
return e || (e = new j(c, { timeout: 1e4 }), h.set(c, e)), e;
|
|
9
|
+
};
|
|
10
|
+
async function A(i, c) {
|
|
11
|
+
try {
|
|
12
|
+
const e = [], o = await p({ ...c, cacheTime: l }), t = await y(
|
|
13
|
+
o.oracle.hermesEndpoint
|
|
14
|
+
).getLatestPriceFeeds(i);
|
|
15
|
+
if (!t) return e;
|
|
16
|
+
const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
17
|
+
for (const r of t) {
|
|
18
|
+
const a = r.getPriceUnchecked();
|
|
19
|
+
if (a.publishTime > n) {
|
|
20
|
+
console.warn(
|
|
21
|
+
`pyth price feed is invalid, id: ${r.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
|
|
22
|
+
);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
n - r.getPriceUnchecked().publishTime > 30 && (console.info(
|
|
26
|
+
`stale price feed, id: ${r.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
|
|
27
|
+
), e.push(r.id));
|
|
28
|
+
}
|
|
29
|
+
return e;
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new Error(`failed to get pyth stale price feed id, msg: ${e.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function $(i, c) {
|
|
35
|
+
const e = [], o = c?.client ?? b, t = i.map((r) => r.priceInfoObject), n = await T(o, {
|
|
36
|
+
ids: Array.from(new Set(t)),
|
|
37
|
+
options: { showContent: !0 }
|
|
38
|
+
});
|
|
39
|
+
for (const r of n) {
|
|
40
|
+
const a = r.data;
|
|
41
|
+
if (!a || !a.content || a.content.dataType !== "moveObject") {
|
|
42
|
+
console.warn(`fetched object ${a?.objectId} datatype should be moveObject`);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const d = i.find((w) => w.priceInfoObject == a.objectId);
|
|
46
|
+
if (!d) {
|
|
47
|
+
console.warn(`unable to find pyth info from array, priceInfoObject: ${a.objectId}`);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const s = a.content.fields?.price_info?.price_feed?.price, u = s?.price;
|
|
51
|
+
if (!u) {
|
|
52
|
+
console.warn(`unexpected pyth price struct, priceInfoObject: ${a.objectId}`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const { magnitude: f, negative: g } = u, P = s.conf, I = s.timestamp;
|
|
56
|
+
e.push({
|
|
57
|
+
priceFeedId: d.priceFeedId,
|
|
58
|
+
priceInfoObject: d.priceInfoObject,
|
|
59
|
+
price: g ? "-" + f : f,
|
|
60
|
+
conf: P,
|
|
61
|
+
publishTime: Number(I),
|
|
62
|
+
expiration: d.expiration
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return e;
|
|
66
|
+
}
|
|
67
|
+
async function v(i, c) {
|
|
68
|
+
try {
|
|
69
|
+
const e = [], o = await $(i, c);
|
|
70
|
+
if (!o) return e;
|
|
71
|
+
const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
72
|
+
for (const n of o) {
|
|
73
|
+
if (n.publishTime > t) {
|
|
74
|
+
console.warn(
|
|
75
|
+
`pyth price feed is invalid, id: ${n.priceFeedId}, publish time: ${n.publishTime}, current timestamp: ${t}`
|
|
76
|
+
);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const r = n.expiration || 60;
|
|
80
|
+
t - n.publishTime > r && (console.info(
|
|
81
|
+
`stale price feed, id: ${n.priceFeedId}, publish time: ${n.publishTime}, current timestamp: ${t}`
|
|
82
|
+
), e.push(n.priceFeedId));
|
|
83
|
+
}
|
|
84
|
+
return e;
|
|
85
|
+
} catch (e) {
|
|
86
|
+
throw new Error(`failed to get pyth stale price feed id, msg: ${e.message}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function C(i, c, e) {
|
|
90
|
+
const o = e?.client ?? b, t = await p({
|
|
91
|
+
...e,
|
|
92
|
+
cacheTime: l
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
const n = await y(
|
|
96
|
+
t.oracle.hermesEndpoint
|
|
97
|
+
).getPriceFeedsUpdateData(c);
|
|
98
|
+
return await new F(
|
|
99
|
+
o,
|
|
100
|
+
t.oracle.pythStateId,
|
|
101
|
+
t.oracle.wormholeStateId
|
|
102
|
+
).updatePriceFeeds(i, n, c, {
|
|
103
|
+
feeCoin: e?.pythFeeCoin
|
|
104
|
+
});
|
|
105
|
+
} catch (n) {
|
|
106
|
+
throw new Error(`failed to update pyth price feeds, msg: ${n.message}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function m(i, c, e) {
|
|
110
|
+
const o = await p({
|
|
111
|
+
...e,
|
|
112
|
+
cacheTime: l
|
|
113
|
+
});
|
|
114
|
+
if (e?.updatePythPriceFeeds) {
|
|
115
|
+
const t = c.filter((r) => !!r.pythPriceFeedId && !!r.pythPriceInfoObject).map((r) => ({
|
|
116
|
+
priceFeedId: r.pythPriceFeedId,
|
|
117
|
+
priceInfoObject: r.pythPriceInfoObject,
|
|
118
|
+
expiration: 30
|
|
119
|
+
})), n = await v(t, e);
|
|
120
|
+
n.length > 0 && await C(i, n, e);
|
|
121
|
+
}
|
|
122
|
+
for (const t of c)
|
|
123
|
+
i.moveCall({
|
|
124
|
+
target: `${o.oracle.packageId}::oracle_pro::${o.oracle.updateFunction ?? "update_single_price_v2"}`,
|
|
125
|
+
arguments: [
|
|
126
|
+
i.object("0x6"),
|
|
127
|
+
// Clock object
|
|
128
|
+
i.object(o.oracle.oracleConfig),
|
|
129
|
+
// Oracle configuration
|
|
130
|
+
i.object(o.oracle.priceOracle),
|
|
131
|
+
// Price oracle contract
|
|
132
|
+
i.object(o.oracle.supraOracleHolder),
|
|
133
|
+
// Supra oracle holder
|
|
134
|
+
i.object(t.pythPriceInfoObject),
|
|
135
|
+
// Pyth price info object
|
|
136
|
+
i.object(o.oracle.switchboardAggregator),
|
|
137
|
+
i.pure.address(t.feedId)
|
|
138
|
+
// Price feed ID
|
|
139
|
+
]
|
|
140
|
+
});
|
|
141
|
+
return i;
|
|
142
|
+
}
|
|
143
|
+
async function S(i) {
|
|
144
|
+
return (await p({
|
|
145
|
+
...i,
|
|
146
|
+
cacheTime: l
|
|
147
|
+
})).oracle.feeds;
|
|
148
|
+
}
|
|
149
|
+
function E(i, c) {
|
|
150
|
+
return i.filter((e) => !!(c?.lendingState && c.lendingState.find((t) => e.oracleId === t.pool.oracleId) || c?.lendingPositions && c.lendingPositions.find((t) => {
|
|
151
|
+
if (![
|
|
152
|
+
"navi-lending-supply",
|
|
153
|
+
"navi-lending-borrow",
|
|
154
|
+
"navi-lending-emode-supply",
|
|
155
|
+
"navi-lending-emode-borrow"
|
|
156
|
+
].includes(t.type))
|
|
157
|
+
return !1;
|
|
158
|
+
const r = t[t.type]?.pool;
|
|
159
|
+
return e.oracleId === r?.oracleId;
|
|
160
|
+
}) || c?.pools && c.pools.find((t) => e.oracleId === t.oracleId)));
|
|
161
|
+
}
|
|
162
|
+
async function M(i, c, e, o) {
|
|
163
|
+
let t;
|
|
164
|
+
try {
|
|
165
|
+
const n = await S({
|
|
166
|
+
...o
|
|
167
|
+
}), r = [];
|
|
168
|
+
e.forEach((s) => {
|
|
169
|
+
r.includes(s.market) || r.push(s.market);
|
|
170
|
+
});
|
|
171
|
+
const a = await O(c, {
|
|
172
|
+
...o,
|
|
173
|
+
markets: r
|
|
174
|
+
});
|
|
175
|
+
return t = E(n, {
|
|
176
|
+
lendingPositions: a,
|
|
177
|
+
pools: e
|
|
178
|
+
}), await m(i, t, {
|
|
179
|
+
updatePythPriceFeeds: !0,
|
|
180
|
+
...o
|
|
181
|
+
});
|
|
182
|
+
} catch (n) {
|
|
183
|
+
if (o?.throws)
|
|
184
|
+
throw n;
|
|
185
|
+
if (console.error(n), t)
|
|
186
|
+
try {
|
|
187
|
+
return await m(i, t, {
|
|
188
|
+
...o,
|
|
189
|
+
updatePythPriceFeeds: !1
|
|
190
|
+
});
|
|
191
|
+
} catch (r) {
|
|
192
|
+
console.error(r);
|
|
193
|
+
}
|
|
194
|
+
return i;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
export {
|
|
198
|
+
E as filterPriceFeeds,
|
|
199
|
+
S as getPriceFeeds,
|
|
200
|
+
A as getPythStalePriceFeedId,
|
|
201
|
+
v as getPythStalePriceFeedIdV2,
|
|
202
|
+
M as updateOraclePriceBeforeUserOperationPTB,
|
|
203
|
+
m as updateOraclePricesPTB,
|
|
204
|
+
C as updatePythPriceFeeds
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=oracle.js.map
|