@naviprotocol/lending 2.0.5 → 2.0.7
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 +2 -2
- package/dist/oracle.d.ts.map +1 -1
- package/dist/oracle.js +204 -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 +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 +6 -2
- package/dist/types.d.ts.map +1 -1
- 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 -2743
- package/dist/index.esm.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oracle.js","sources":["../src/oracle.ts"],"sourcesContent":["/**\n * Oracle Price Feed Management for Lending Protocol\n *\n * This module provides oracle price feed functionality for the lending protocol.\n * It integrates with Pyth Network for real-time price data and manages price updates\n * for various assets used in lending operations.\n */\n\nimport { getConfig, DEFAULT_CACHE_TIME } from './config'\nimport type {\n OraclePriceFeed,\n EnvOption,\n UserLendingInfo,\n Pool,\n SuiClientOption,\n MarketOption,\n LendingPosition,\n ServiceOption\n} from './types'\nimport { SuiPriceServiceConnection, SuiPythClient } from './pyth'\nimport { Transaction } from '@mysten/sui/transactions'\nimport { multiGetSuiObjects, suiClient } from './utils'\nimport { getLendingPositions } from './account'\n\ntype PythInfo = {\n priceFeedId: string\n priceInfoObject: string\n expiration?: number\n}\n\nexport type PythPriceInfo = {\n priceFeedId: string\n priceInfoObject: string\n price: string\n conf: string\n publishTime: number\n expiration?: number\n}\n\n/**\n * Pyth Network connection for price feed data\n * Connects to the Hermes endpoint for real-time price updates\n */\nconst pythConnections = new Map<string, SuiPriceServiceConnection>()\nconst getPythConnection = (endpoint?: string) => {\n const url = endpoint ?? 'https://hermes.pyth.network'\n let conn = pythConnections.get(url)\n if (!conn) {\n conn = new SuiPriceServiceConnection(url, { timeout: 10000 })\n pythConnections.set(url, conn)\n }\n return conn\n}\n\n/**\n * Get stale price feed IDs from Pyth Network\n *\n * Identifies price feeds that have not been updated recently (more than 30 seconds old).\n * This helps ensure that only fresh price data is used for lending operations.\n *\n * @param priceIds - Array of Pyth price feed IDs to check\n * @returns Array of stale price feed IDs that need updating\n * @throws Error if failed to fetch price feed data\n */\nexport async function getPythStalePriceFeedId(\n priceIds: string[],\n options?: Partial<EnvOption & MarketOption>\n): Promise<string[]> {\n try {\n const returnData: string[] = []\n const config = await getConfig({ ...options, cacheTime: DEFAULT_CACHE_TIME })\n const latestPriceFeeds = await getPythConnection(\n config.oracle.hermesEndpoint\n ).getLatestPriceFeeds(priceIds)\n if (!latestPriceFeeds) return returnData\n\n const currentTimestamp = Math.floor(new Date().valueOf() / 1000)\n for (const priceFeed of latestPriceFeeds) {\n const uncheckedPrice = priceFeed.getPriceUnchecked()\n if (uncheckedPrice.publishTime > currentTimestamp) {\n console.warn(\n `pyth price feed is invalid, id: ${priceFeed.id}, publish time: ${uncheckedPrice.publishTime}, current timestamp: ${currentTimestamp}`\n )\n continue\n }\n\n // From pyth state is 60, but setting it to 30 makes more sense.\n if (currentTimestamp - priceFeed.getPriceUnchecked().publishTime > 30) {\n console.info(\n `stale price feed, id: ${priceFeed.id}, publish time: ${uncheckedPrice.publishTime}, current timestamp: ${currentTimestamp}`\n )\n returnData.push(priceFeed.id)\n }\n }\n return returnData\n } catch (error) {\n throw new Error(`failed to get pyth stale price feed id, msg: ${(error as Error).message}`)\n }\n}\n\nasync function getOnChainPriceInfo(\n pythInfos: PythInfo[],\n options?: Partial<SuiClientOption>\n): Promise<PythPriceInfo[]> {\n // Whole-read failures (endpoint/RPC errors) propagate to the caller:\n // swallowing them here would silently skip the Pyth staleness update and let\n // transactions build against stale on-chain prices. Only per-feed anomalies\n // are skipped below.\n const priceInfos: PythPriceInfo[] = []\n const client = options?.client ?? suiClient\n\n const priceInfoObjectIds = pythInfos.map((k) => k.priceInfoObject)\n const priceInfoObjects = await multiGetSuiObjects(client, {\n ids: Array.from(new Set(priceInfoObjectIds)),\n options: { showContent: true }\n })\n for (const obj of priceInfoObjects) {\n const data = obj.data\n if (!data || !data.content || data.content.dataType !== 'moveObject') {\n console.warn(`fetched object ${data?.objectId} datatype should be moveObject`)\n continue\n }\n\n const pythInfo = pythInfos.find((v) => v.priceInfoObject == data.objectId)\n if (!pythInfo) {\n console.warn(`unable to find pyth info from array, priceInfoObject: ${data.objectId}`)\n continue\n }\n\n // The Sui v2 client returns nested Move structs directly, without the\n // per-level `.fields` wrapper the legacy JSON-RPC object shape carried.\n // Read the flattened shape and skip (not throw) on an unexpected object so\n // a single malformed feed can't abort the whole batch and silently leave\n // every on-chain price un-refreshed.\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n const priceStruct = data.content.fields?.price_info?.price_feed?.price\n const priceValue = priceStruct?.price\n if (!priceValue) {\n console.warn(`unexpected pyth price struct, priceInfoObject: ${data.objectId}`)\n continue\n }\n const { magnitude, negative } = priceValue\n const conf = priceStruct.conf\n const timestamp = priceStruct.timestamp\n\n priceInfos.push({\n priceFeedId: pythInfo.priceFeedId,\n priceInfoObject: pythInfo.priceInfoObject,\n price: negative ? '-' + magnitude : magnitude,\n conf,\n publishTime: Number(timestamp),\n expiration: pythInfo.expiration\n })\n }\n return priceInfos\n}\n\nexport async function getPythStalePriceFeedIdV2(\n pythInfos: PythInfo[],\n options?: Partial<SuiClientOption>\n): Promise<string[]> {\n try {\n const returnData: string[] = []\n const latestPriceFeeds = await getOnChainPriceInfo(pythInfos, options)\n if (!latestPriceFeeds) return returnData\n\n const currentTimestamp = Math.floor(new Date().valueOf() / 1000)\n\n for (const priceFeed of latestPriceFeeds) {\n if (priceFeed.publishTime > currentTimestamp) {\n console.warn(\n `pyth price feed is invalid, id: ${priceFeed.priceFeedId}, publish time: ${priceFeed.publishTime}, current timestamp: ${currentTimestamp}`\n )\n continue\n }\n\n const maxTime = priceFeed.expiration || 60\n // 3s is the margin of error for the price feed.\n if (currentTimestamp - priceFeed.publishTime > maxTime) {\n console.info(\n `stale price feed, id: ${priceFeed.priceFeedId}, publish time: ${priceFeed.publishTime}, current timestamp: ${currentTimestamp}`\n )\n returnData.push(priceFeed.priceFeedId)\n }\n }\n return returnData\n } catch (error) {\n throw new Error(`failed to get pyth stale price feed id, msg: ${(error as Error).message}`)\n }\n}\n\n/**\n * Update Pyth price feeds in a transaction\n *\n * Fetches the latest price update data from Pyth Network and adds the update\n * operations to the transaction block.\n *\n * @param tx - The transaction block to add price feed updates to\n * @param priceFeedIds - Array of Pyth price feed IDs to update\n * @param options - Optional client and environment configuration\n * @returns Promise that resolves when price feeds are updated\n * @throws Error if failed to update price feeds\n */\nexport async function updatePythPriceFeeds(\n tx: Transaction,\n priceFeedIds: string[],\n options?: Partial<SuiClientOption & EnvOption & MarketOption>\n) {\n const client = options?.client ?? suiClient\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n try {\n const priceUpdateData = await getPythConnection(\n config.oracle.hermesEndpoint\n ).getPriceFeedsUpdateData(priceFeedIds)\n const suiPythClient = new SuiPythClient(\n client as any,\n config.oracle.pythStateId,\n config.oracle.wormholeStateId\n )\n\n return await suiPythClient.updatePriceFeeds(tx as any, priceUpdateData, priceFeedIds)\n } catch (error) {\n throw new Error(`failed to update pyth price feeds, msg: ${(error as Error).message}`)\n }\n}\n\n/**\n * Update oracle prices in the PTB (Programmable Transaction Block)\n *\n * This function updates price feeds for the lending protocol. It can optionally\n * update Pyth price feeds first if they are stale, then updates individual\n * price feeds in the oracle contract.\n *\n * @param tx - The transaction block to add price update operations to\n * @param priceFeeds - Array of oracle price feeds to update\n * @param options - Optional configuration including whether to update Pyth feeds\n * @returns The updated transaction block\n */\nexport async function updateOraclePricesPTB(\n tx: Transaction,\n priceFeeds: OraclePriceFeed[],\n options?: Partial<\n EnvOption &\n SuiClientOption &\n ServiceOption &\n MarketOption & {\n updatePythPriceFeeds?: boolean\n }\n >\n): Promise<Transaction> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n\n // Optionally update Pyth price feeds if they are stale\n if (options?.updatePythPriceFeeds) {\n const pythInfos = priceFeeds\n .filter((feed) => !!feed.pythPriceFeedId && !!feed.pythPriceInfoObject)\n .map((feed) => ({\n priceFeedId: feed.pythPriceFeedId,\n priceInfoObject: feed.pythPriceInfoObject,\n expiration: 30\n }))\n\n // Do not silently swallow Pyth stale-price update failures: the previous\n // catch kept building the tx with possibly stale on-chain prices and masked\n // real endpoint/RPC errors. Throw so callers are aware (avoids\n // lending/liquidation based on stale prices).\n const stalePriceFeedIds = await getPythStalePriceFeedIdV2(pythInfos, options)\n if (stalePriceFeedIds.length > 0) {\n await updatePythPriceFeeds(tx, stalePriceFeedIds, options)\n }\n }\n\n // Update individual price feeds in the oracle contract\n for (const priceFeed of priceFeeds) {\n tx.moveCall({\n target: `${config.oracle.packageId}::oracle_pro::${config.oracle.updateFunction ?? 'update_single_price_v2'}`,\n arguments: [\n tx.object('0x6'), // Clock object\n tx.object(config.oracle.oracleConfig), // Oracle configuration\n tx.object(config.oracle.priceOracle), // Price oracle contract\n tx.object(config.oracle.supraOracleHolder), // Supra oracle holder\n tx.object(priceFeed.pythPriceInfoObject), // Pyth price info object\n tx.object(config.oracle.switchboardAggregator),\n tx.pure.address(priceFeed.feedId) // Price feed ID\n ]\n })\n }\n return tx\n}\n\n/**\n * Get all available price feeds from the configuration\n *\n * @param options - Optional environment configuration\n * @returns Array of oracle price feed configurations\n */\nexport async function getPriceFeeds(\n options?: Partial<EnvOption & ServiceOption>\n): Promise<OraclePriceFeed[]> {\n const config = await getConfig({\n ...options,\n cacheTime: DEFAULT_CACHE_TIME\n })\n return config.oracle.feeds\n}\n\n/**\n * Filter price feeds based on lending state and pools\n *\n * This function filters price feeds to only include those that are relevant\n * to the current lending state or available pools.\n *\n * @param feeds - Array of price feeds to filter\n * @param filters - Filter criteria including lending state and pools\n * @returns Filtered array of price feeds\n */\nexport function filterPriceFeeds(\n feeds: OraclePriceFeed[],\n filters: {\n lendingState?: UserLendingInfo[]\n pools?: Pool[]\n lendingPositions?: LendingPosition[]\n }\n): OraclePriceFeed[] {\n return feeds.filter((feed) => {\n // Filter by lending state (user's current positions)\n if (filters?.lendingState) {\n const inState = filters.lendingState.find((state) => {\n return feed.oracleId === state.pool.oracleId\n })\n if (inState) {\n return true\n }\n }\n\n if (filters?.lendingPositions) {\n const inPosition = filters.lendingPositions.find((position) => {\n const availableTypes = [\n 'navi-lending-supply',\n 'navi-lending-borrow',\n 'navi-lending-emode-supply',\n 'navi-lending-emode-borrow'\n ]\n if (!availableTypes.includes(position.type)) {\n return false\n }\n const pool = position[position.type]?.pool\n return feed.oracleId === pool?.oracleId\n })\n if (inPosition) {\n return true\n }\n }\n\n // Filter by available pools\n if (filters?.pools) {\n const inPool = filters.pools.find((pool) => {\n return feed.oracleId === pool.oracleId\n })\n if (inPool) {\n return true\n }\n }\n return false\n })\n}\n\nexport async function updateOraclePriceBeforeUserOperationPTB(\n tx: Transaction,\n address: string,\n pools: Pool[],\n options?: Partial<\n EnvOption &\n SuiClientOption &\n MarketOption & {\n throws?: boolean\n }\n >\n) {\n let relevantFeeds: OraclePriceFeed[] | undefined\n try {\n const allPriceFeeds = await getPriceFeeds({\n ...options\n })\n\n const markets = [] as string[]\n\n pools.forEach((pool) => {\n if (!markets.includes(pool.market)) {\n markets.push(pool.market)\n }\n })\n\n const lendingPositions = await getLendingPositions(address, {\n ...options,\n markets\n })\n\n relevantFeeds = filterPriceFeeds(allPriceFeeds, {\n lendingPositions,\n pools\n })\n\n const updatedTx = await updateOraclePricesPTB(tx, relevantFeeds, {\n updatePythPriceFeeds: true,\n ...options\n })\n return updatedTx\n } catch (e) {\n if (options?.throws) {\n throw e\n }\n console.error(e)\n // Degraded path: a Pyth refresh failure happens before any moveCall is\n // appended, so the tx is still clean. Retry the oracle update without the\n // Pyth feed refresh (matches the pre-v2 behavior where Pyth failures were\n // swallowed but update_single_price calls were still appended) instead of\n // dropping the oracle update entirely.\n if (relevantFeeds) {\n try {\n return await updateOraclePricesPTB(tx, relevantFeeds, {\n ...options,\n updatePythPriceFeeds: false\n })\n } catch (fallbackError) {\n console.error(fallbackError)\n }\n }\n return tx\n }\n}\n"],"names":["pythConnections","getPythConnection","endpoint","url","conn","SuiPriceServiceConnection","getPythStalePriceFeedId","priceIds","options","returnData","config","getConfig","DEFAULT_CACHE_TIME","latestPriceFeeds","currentTimestamp","priceFeed","uncheckedPrice","error","getOnChainPriceInfo","pythInfos","priceInfos","client","suiClient","priceInfoObjectIds","k","priceInfoObjects","multiGetSuiObjects","obj","data","pythInfo","v","priceStruct","priceValue","magnitude","negative","conf","timestamp","getPythStalePriceFeedIdV2","maxTime","updatePythPriceFeeds","tx","priceFeedIds","priceUpdateData","SuiPythClient","updateOraclePricesPTB","priceFeeds","feed","stalePriceFeedIds","getPriceFeeds","filterPriceFeeds","feeds","filters","state","position","pool","updateOraclePriceBeforeUserOperationPTB","address","pools","relevantFeeds","allPriceFeeds","markets","lendingPositions","getLendingPositions","e","fallbackError"],"mappings":";;;;AA2CA,MAAMA,wBAAsB,IAAA,GACtBC,IAAoB,CAACC,MAAsB;AAC/C,QAAMC,IAAMD,KAAY;AACxB,MAAIE,IAAOJ,EAAgB,IAAIG,CAAG;AAClC,SAAKC,MACHA,IAAO,IAAIC,EAA0BF,GAAK,EAAE,SAAS,KAAO,GAC5DH,EAAgB,IAAIG,GAAKC,CAAI,IAExBA;AACT;AAYA,eAAsBE,EACpBC,GACAC,GACmB;AACnB,MAAI;AACF,UAAMC,IAAuB,CAAA,GACvBC,IAAS,MAAMC,EAAU,EAAE,GAAGH,GAAS,WAAWI,GAAoB,GACtEC,IAAmB,MAAMZ;AAAA,MAC7BS,EAAO,OAAO;AAAA,IAAA,EACd,oBAAoBH,CAAQ;AAC9B,QAAI,CAACM,EAAkB,QAAOJ;AAE9B,UAAMK,IAAmB,KAAK,OAAM,oBAAI,QAAO,QAAA,IAAY,GAAI;AAC/D,eAAWC,KAAaF,GAAkB;AACxC,YAAMG,IAAiBD,EAAU,kBAAA;AACjC,UAAIC,EAAe,cAAcF,GAAkB;AACjD,gBAAQ;AAAA,UACN,mCAAmCC,EAAU,EAAE,mBAAmBC,EAAe,WAAW,wBAAwBF,CAAgB;AAAA,QAAA;AAEtI;AAAA,MACF;AAGA,MAAIA,IAAmBC,EAAU,kBAAA,EAAoB,cAAc,OACjE,QAAQ;AAAA,QACN,yBAAyBA,EAAU,EAAE,mBAA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AI;AACF,eAAO,MAAMd,EAAsBJ,GAAIkB,GAAe;AAAA,UACpD,GAAGlD;AAAA,UACH,sBAAsB;AAAA,QAAA,CACvB;AAAA,MACH,SAASwD,GAAe;AACtB,gBAAQ,MAAMA,CAAa;AAAA,MAC7B;AAEF,WAAOxB;AAAA,EACT;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
package/dist/pool.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvOption, CacheOption, Pool, AssetIdentifier, PoolStats, FeeDetail, CoinObject, TransactionResult, SingleCoinTransactionResult, AccountCapOption, BorrowFeeOption, SuiClientOption, MarketOption, MarketsOption, ServiceOption } from './types';
|
|
1
|
+
import { EnvOption, CacheOption, Pool, AssetIdentifier, PoolStats, FeeDetail, CoinObject, TransactionResult, SingleCoinTransactionResult, AccountCapOption, BorrowFeeOption, SuiClientOption, MarketOption, MarketsOption, ServiceOption } from './types.js';
|
|
2
2
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
3
|
|
|
4
4
|
/**
|
package/dist/pool.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
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 N, normalizeCoinType as m, parseTxValue as u, suiClient as I, devInspectTransaction as U, parseDevInspectResult as R, getSuiObject as F } from "./utils.js";
|
|
3
|
+
import { resolveNaviOpenApiEndpoint as f, buildNaviOpenApiUrl as h, mergeServiceHeaders as _ } from "./services.js";
|
|
4
|
+
import { Transaction as W } from "@mysten/sui/transactions";
|
|
5
|
+
import p from "bignumber.js";
|
|
6
|
+
import { bcs as M } from "@mysten/sui/bcs";
|
|
7
|
+
import T from "./package.json.js";
|
|
8
|
+
import { MARKETS as P, getMarketConfig as V, DEFAULT_MARKET_IDENTITY as B } from "./market.js";
|
|
9
|
+
var q = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(q || {});
|
|
10
|
+
const H = y(
|
|
11
|
+
w(
|
|
12
|
+
async (e) => {
|
|
13
|
+
const a = (e?.markets || [P.main]).map((t) => V(t)), r = f(e), n = h(
|
|
14
|
+
`/navi/pools?env=${e?.env || "prod"}&sdk=${T.version}&market=${a.map(
|
|
15
|
+
(t) => t.key
|
|
16
|
+
)}`,
|
|
17
|
+
e
|
|
18
|
+
), o = await fetch(n, { headers: _(C, r) }).then(
|
|
19
|
+
(t) => t.json()
|
|
20
|
+
);
|
|
21
|
+
return o.data.forEach((t) => {
|
|
22
|
+
const i = o.meta.emodes.filter((v) => {
|
|
23
|
+
const j = V(v.marketId);
|
|
24
|
+
return t.market === j.key && v.isActive;
|
|
25
|
+
}).filter((v) => !!v.assets.find((j) => j.assetId === t.id));
|
|
26
|
+
t.emodes = i;
|
|
27
|
+
const l = p(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), s = p(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), S = p(l).multipliedBy(t.oracle.price).toString(), $ = p(s).multipliedBy(t.oracle.price).toString(), A = p(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), k = p.max(
|
|
28
|
+
p(t.borrowedAmount),
|
|
29
|
+
p(t.validBorrowAmount)
|
|
30
|
+
).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), D = p(A).multipliedBy(t.oracle.price).toString(), E = p(k).multipliedBy(t.oracle.price).toString();
|
|
31
|
+
t.poolSupplyAmount = l, t.poolBorrowAmount = s, t.poolSupplyValue = S, t.poolBorrowValue = $, t.poolSupplyCapAmount = A, t.poolBorrowCapAmount = k, t.poolSupplyCapValue = D, t.poolBorrowCapValue = E;
|
|
32
|
+
}), o.data;
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
async function b(e, a) {
|
|
37
|
+
let r = a?.market;
|
|
38
|
+
if (typeof e == "string") {
|
|
39
|
+
const t = N(e);
|
|
40
|
+
t && (r = t.marketKey, e = t.poolId);
|
|
41
|
+
}
|
|
42
|
+
const n = await H({
|
|
43
|
+
...a,
|
|
44
|
+
markets: [r || B],
|
|
45
|
+
cacheTime: g
|
|
46
|
+
});
|
|
47
|
+
if (typeof e == "object")
|
|
48
|
+
return e;
|
|
49
|
+
const o = n.find((t) => typeof e == "string" ? m(t.suiCoinType) === m(e) : typeof e == "number" ? t.id === e : !1);
|
|
50
|
+
if (!o)
|
|
51
|
+
throw new Error("Pool not found");
|
|
52
|
+
return o.isDeprecated && console.log(`The lending pool for coinType ${o.suiCoinType} is going to be deprecated.`), o;
|
|
53
|
+
}
|
|
54
|
+
const X = y(
|
|
55
|
+
w(async (e) => {
|
|
56
|
+
const a = f(e), r = h(`/navi/stats?sdk=${T.version}`, e);
|
|
57
|
+
return (await fetch(r, {
|
|
58
|
+
headers: _(C, a)
|
|
59
|
+
}).then((o) => o.json())).data;
|
|
60
|
+
})
|
|
61
|
+
), Z = y(
|
|
62
|
+
w(
|
|
63
|
+
async (e) => {
|
|
64
|
+
const a = f(e), r = h(`/navi/fee?sdk=${T.version}`, e);
|
|
65
|
+
return await fetch(r, {
|
|
66
|
+
headers: _(C, a)
|
|
67
|
+
}).then((o) => o.json());
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
async function x(e, a, r, n) {
|
|
72
|
+
const o = await d({
|
|
73
|
+
...n,
|
|
74
|
+
cacheTime: g
|
|
75
|
+
}), t = await b(a, n), c = n?.market || B, i = n?.env || "prod";
|
|
76
|
+
if (t?.deprecatedAt && Date.now() > t.deprecatedAt)
|
|
77
|
+
throw new Error(`The lending pool for coinType ${t.suiCoinType} has been deprecated.`);
|
|
78
|
+
if (m(t.suiCoinType) === m("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
79
|
+
if (!n?.amount)
|
|
80
|
+
throw new Error("Amount is required for sui coin");
|
|
81
|
+
r = e.splitCoins(r, [n.amount]);
|
|
82
|
+
}
|
|
83
|
+
let l;
|
|
84
|
+
return typeof n?.amount < "u" ? l = u(n.amount, e.pure.u64) : l = e.moveCall({
|
|
85
|
+
target: "0x2::coin::value",
|
|
86
|
+
arguments: [u(r, e.object)],
|
|
87
|
+
typeArguments: [t.suiCoinType]
|
|
88
|
+
}), n?.accountCap ? e.moveCall({
|
|
89
|
+
target: `${o.package}::incentive_v3::deposit_with_account_cap`,
|
|
90
|
+
arguments: [
|
|
91
|
+
e.object("0x06"),
|
|
92
|
+
e.object(o.storage),
|
|
93
|
+
e.object(t.contract.pool),
|
|
94
|
+
e.pure.u8(t.id),
|
|
95
|
+
u(r, e.object),
|
|
96
|
+
e.object(o.incentiveV2),
|
|
97
|
+
e.object(o.incentiveV3),
|
|
98
|
+
u(n.accountCap, e.object)
|
|
99
|
+
],
|
|
100
|
+
typeArguments: [t.suiCoinType]
|
|
101
|
+
}) : e.moveCall({
|
|
102
|
+
target: `${o.package}::incentive_v3::entry_deposit`,
|
|
103
|
+
arguments: [
|
|
104
|
+
e.object("0x06"),
|
|
105
|
+
e.object(o.storage),
|
|
106
|
+
e.object(t.contract.pool),
|
|
107
|
+
e.pure.u8(t.id),
|
|
108
|
+
u(r, e.object),
|
|
109
|
+
l,
|
|
110
|
+
e.object(o.incentiveV2),
|
|
111
|
+
e.object(o.incentiveV3)
|
|
112
|
+
],
|
|
113
|
+
typeArguments: [t.suiCoinType]
|
|
114
|
+
}), o.version === 2 && t.token.symbol === "SUI" && i === "prod" && c === "main" && e.moveCall({
|
|
115
|
+
target: `${o.package}::pool::refresh_stake`,
|
|
116
|
+
arguments: [e.object(t.contract.pool), e.object("0x05")]
|
|
117
|
+
}), e;
|
|
118
|
+
}
|
|
119
|
+
async function ee(e, a, r, n) {
|
|
120
|
+
const o = await d({
|
|
121
|
+
...n,
|
|
122
|
+
cacheTime: g
|
|
123
|
+
}), t = await b(a, n), c = u(r, e.pure.u64);
|
|
124
|
+
let i;
|
|
125
|
+
if (o.version === 1)
|
|
126
|
+
if (n?.accountCap) {
|
|
127
|
+
const [s] = e.moveCall({
|
|
128
|
+
target: `${o.package}::incentive_v3::withdraw_with_account_cap`,
|
|
129
|
+
arguments: [
|
|
130
|
+
e.object("0x06"),
|
|
131
|
+
e.object(o.priceOracle),
|
|
132
|
+
e.object(o.storage),
|
|
133
|
+
e.object(t.contract.pool),
|
|
134
|
+
e.pure.u8(t.id),
|
|
135
|
+
c,
|
|
136
|
+
e.object(o.incentiveV2),
|
|
137
|
+
e.object(o.incentiveV3),
|
|
138
|
+
u(n.accountCap, e.object)
|
|
139
|
+
],
|
|
140
|
+
typeArguments: [t.suiCoinType]
|
|
141
|
+
});
|
|
142
|
+
i = s;
|
|
143
|
+
} else {
|
|
144
|
+
const [s] = e.moveCall({
|
|
145
|
+
target: `${o.package}::incentive_v3::withdraw`,
|
|
146
|
+
arguments: [
|
|
147
|
+
e.object("0x06"),
|
|
148
|
+
e.object(o.priceOracle),
|
|
149
|
+
e.object(o.storage),
|
|
150
|
+
e.object(t.contract.pool),
|
|
151
|
+
e.pure.u8(t.id),
|
|
152
|
+
c,
|
|
153
|
+
e.object(o.incentiveV2),
|
|
154
|
+
e.object(o.incentiveV3)
|
|
155
|
+
],
|
|
156
|
+
typeArguments: [t.suiCoinType]
|
|
157
|
+
});
|
|
158
|
+
i = s;
|
|
159
|
+
}
|
|
160
|
+
else if (n?.accountCap) {
|
|
161
|
+
const [s] = e.moveCall({
|
|
162
|
+
target: `${o.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
163
|
+
arguments: [
|
|
164
|
+
e.object("0x06"),
|
|
165
|
+
e.object(o.priceOracle),
|
|
166
|
+
e.object(o.storage),
|
|
167
|
+
e.object(t.contract.pool),
|
|
168
|
+
e.pure.u8(t.id),
|
|
169
|
+
c,
|
|
170
|
+
e.object(o.incentiveV2),
|
|
171
|
+
e.object(o.incentiveV3),
|
|
172
|
+
u(n.accountCap, e.object),
|
|
173
|
+
e.object("0x05")
|
|
174
|
+
],
|
|
175
|
+
typeArguments: [t.suiCoinType]
|
|
176
|
+
});
|
|
177
|
+
i = s;
|
|
178
|
+
} else {
|
|
179
|
+
const [s] = e.moveCall({
|
|
180
|
+
target: `${o.package}::incentive_v3::withdraw_v2`,
|
|
181
|
+
arguments: [
|
|
182
|
+
e.object("0x06"),
|
|
183
|
+
e.object(o.priceOracle),
|
|
184
|
+
e.object(o.storage),
|
|
185
|
+
e.object(t.contract.pool),
|
|
186
|
+
e.pure.u8(t.id),
|
|
187
|
+
c,
|
|
188
|
+
e.object(o.incentiveV2),
|
|
189
|
+
e.object(o.incentiveV3),
|
|
190
|
+
e.object("0x05")
|
|
191
|
+
],
|
|
192
|
+
typeArguments: [t.suiCoinType]
|
|
193
|
+
});
|
|
194
|
+
i = s;
|
|
195
|
+
}
|
|
196
|
+
return e.moveCall({
|
|
197
|
+
target: "0x2::coin::from_balance",
|
|
198
|
+
arguments: [i],
|
|
199
|
+
typeArguments: [t.suiCoinType]
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
async function te(e, a, r, n) {
|
|
203
|
+
const o = await d({
|
|
204
|
+
...n,
|
|
205
|
+
cacheTime: g
|
|
206
|
+
}), t = await b(a, n);
|
|
207
|
+
if (t?.deprecatedAt && Date.now() > t.deprecatedAt)
|
|
208
|
+
throw new Error(`The lending pool for coinType ${t.suiCoinType} has been deprecated.`);
|
|
209
|
+
const c = u(r, e.pure.u64);
|
|
210
|
+
let i;
|
|
211
|
+
if (o.version === 1)
|
|
212
|
+
if (n?.accountCap) {
|
|
213
|
+
const [s] = e.moveCall({
|
|
214
|
+
target: `${o.package}::incentive_v3::borrow_with_account_cap`,
|
|
215
|
+
arguments: [
|
|
216
|
+
e.object("0x06"),
|
|
217
|
+
e.object(o.priceOracle),
|
|
218
|
+
e.object(o.storage),
|
|
219
|
+
e.object(t.contract.pool),
|
|
220
|
+
e.pure.u8(t.id),
|
|
221
|
+
c,
|
|
222
|
+
e.object(o.incentiveV2),
|
|
223
|
+
e.object(o.incentiveV3),
|
|
224
|
+
u(n.accountCap, e.object)
|
|
225
|
+
],
|
|
226
|
+
typeArguments: [t.suiCoinType]
|
|
227
|
+
});
|
|
228
|
+
i = s;
|
|
229
|
+
} else {
|
|
230
|
+
const [s] = e.moveCall({
|
|
231
|
+
target: `${o.package}::incentive_v3::borrow`,
|
|
232
|
+
arguments: [
|
|
233
|
+
e.object("0x06"),
|
|
234
|
+
e.object(o.priceOracle),
|
|
235
|
+
e.object(o.storage),
|
|
236
|
+
e.object(t.contract.pool),
|
|
237
|
+
e.pure.u8(t.id),
|
|
238
|
+
c,
|
|
239
|
+
e.object(o.incentiveV2),
|
|
240
|
+
e.object(o.incentiveV3)
|
|
241
|
+
],
|
|
242
|
+
typeArguments: [t.suiCoinType]
|
|
243
|
+
});
|
|
244
|
+
i = s;
|
|
245
|
+
}
|
|
246
|
+
else if (n?.accountCap) {
|
|
247
|
+
const [s] = e.moveCall({
|
|
248
|
+
target: `${o.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
249
|
+
arguments: [
|
|
250
|
+
e.object("0x06"),
|
|
251
|
+
e.object(o.priceOracle),
|
|
252
|
+
e.object(o.storage),
|
|
253
|
+
e.object(t.contract.pool),
|
|
254
|
+
e.pure.u8(t.id),
|
|
255
|
+
c,
|
|
256
|
+
e.object(o.incentiveV2),
|
|
257
|
+
e.object(o.incentiveV3),
|
|
258
|
+
u(n.accountCap, e.object),
|
|
259
|
+
e.object("0x05")
|
|
260
|
+
],
|
|
261
|
+
typeArguments: [t.suiCoinType]
|
|
262
|
+
});
|
|
263
|
+
i = s;
|
|
264
|
+
} else {
|
|
265
|
+
const [s] = e.moveCall({
|
|
266
|
+
target: `${o.package}::incentive_v3::borrow_v2`,
|
|
267
|
+
arguments: [
|
|
268
|
+
e.object("0x06"),
|
|
269
|
+
e.object(o.priceOracle),
|
|
270
|
+
e.object(o.storage),
|
|
271
|
+
e.object(t.contract.pool),
|
|
272
|
+
e.pure.u8(t.id),
|
|
273
|
+
c,
|
|
274
|
+
e.object(o.incentiveV2),
|
|
275
|
+
e.object(o.incentiveV3),
|
|
276
|
+
e.object("0x05")
|
|
277
|
+
],
|
|
278
|
+
typeArguments: [t.suiCoinType]
|
|
279
|
+
});
|
|
280
|
+
i = s;
|
|
281
|
+
}
|
|
282
|
+
return e.moveCall({
|
|
283
|
+
target: "0x2::coin::from_balance",
|
|
284
|
+
arguments: [e.object(i)],
|
|
285
|
+
typeArguments: [t.suiCoinType]
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async function oe(e, a, r, n) {
|
|
289
|
+
const o = await d({
|
|
290
|
+
...n,
|
|
291
|
+
cacheTime: g
|
|
292
|
+
}), t = await b(a, n);
|
|
293
|
+
if (m(t.suiCoinType) === m("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
294
|
+
if (!n?.amount)
|
|
295
|
+
throw new Error("Amount is required for sui coin");
|
|
296
|
+
r = e.splitCoins(r, [n.amount]);
|
|
297
|
+
}
|
|
298
|
+
let c;
|
|
299
|
+
if (typeof n?.amount < "u" ? c = u(n.amount, e.pure.u64) : c = e.moveCall({
|
|
300
|
+
target: "0x2::coin::value",
|
|
301
|
+
arguments: [u(r, e.object)],
|
|
302
|
+
typeArguments: [t.suiCoinType]
|
|
303
|
+
}), n?.accountCap) {
|
|
304
|
+
const [i] = e.moveCall({
|
|
305
|
+
target: `${o.package}::incentive_v3::repay_with_account_cap`,
|
|
306
|
+
arguments: [
|
|
307
|
+
e.object("0x06"),
|
|
308
|
+
e.object(o.priceOracle),
|
|
309
|
+
e.object(o.storage),
|
|
310
|
+
e.object(t.contract.pool),
|
|
311
|
+
e.pure.u8(t.id),
|
|
312
|
+
u(r, e.object),
|
|
313
|
+
e.object(o.incentiveV2),
|
|
314
|
+
e.object(o.incentiveV3),
|
|
315
|
+
u(n.accountCap, e.object)
|
|
316
|
+
],
|
|
317
|
+
typeArguments: [t.suiCoinType]
|
|
318
|
+
});
|
|
319
|
+
return e.moveCall({
|
|
320
|
+
target: "0x2::coin::from_balance",
|
|
321
|
+
arguments: [i],
|
|
322
|
+
typeArguments: [t.suiCoinType]
|
|
323
|
+
});
|
|
324
|
+
} else
|
|
325
|
+
return e.moveCall({
|
|
326
|
+
target: `${o.package}::incentive_v3::entry_repay`,
|
|
327
|
+
arguments: [
|
|
328
|
+
e.object("0x06"),
|
|
329
|
+
e.object(o.priceOracle),
|
|
330
|
+
e.object(o.storage),
|
|
331
|
+
e.object(t.contract.pool),
|
|
332
|
+
e.pure.u8(t.id),
|
|
333
|
+
u(r, e.object),
|
|
334
|
+
c,
|
|
335
|
+
e.object(o.incentiveV2),
|
|
336
|
+
e.object(o.incentiveV3)
|
|
337
|
+
],
|
|
338
|
+
typeArguments: [t.suiCoinType]
|
|
339
|
+
}), e;
|
|
340
|
+
}
|
|
341
|
+
const ne = y(
|
|
342
|
+
w(
|
|
343
|
+
async (e) => {
|
|
344
|
+
const a = await d({
|
|
345
|
+
...e
|
|
346
|
+
}), r = e?.client ?? I;
|
|
347
|
+
if (e?.address && typeof e?.asset < "u")
|
|
348
|
+
try {
|
|
349
|
+
const t = await b(e.asset, e), c = new W();
|
|
350
|
+
c.moveCall({
|
|
351
|
+
target: `${a.package}::incentive_v3::get_borrow_fee_v2`,
|
|
352
|
+
arguments: [
|
|
353
|
+
c.object(a.incentiveV3),
|
|
354
|
+
c.pure.address(e.address),
|
|
355
|
+
c.pure.u8(t.id),
|
|
356
|
+
c.pure.u64(1e4)
|
|
357
|
+
],
|
|
358
|
+
typeArguments: []
|
|
359
|
+
});
|
|
360
|
+
const i = await U(r, {
|
|
361
|
+
transactionBlock: c,
|
|
362
|
+
sender: e.address
|
|
363
|
+
}), l = R(i, [M.u64()]);
|
|
364
|
+
return (Number(l[0]) || 0) / 100;
|
|
365
|
+
} catch (t) {
|
|
366
|
+
console.error(
|
|
367
|
+
"[lending] getBorrowFee per-user query failed, falling back to global rate:",
|
|
368
|
+
t
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
const o = (await F(r, {
|
|
372
|
+
id: a.incentiveV3,
|
|
373
|
+
options: { showType: !0, showOwner: !0, showContent: !0 }
|
|
374
|
+
})).data.content.fields.borrow_fee_rate;
|
|
375
|
+
return Number(o) / 100;
|
|
376
|
+
}
|
|
377
|
+
)
|
|
378
|
+
);
|
|
379
|
+
export {
|
|
380
|
+
q as PoolOperator,
|
|
381
|
+
te as borrowCoinPTB,
|
|
382
|
+
x as depositCoinPTB,
|
|
383
|
+
ne as getBorrowFee,
|
|
384
|
+
Z as getFees,
|
|
385
|
+
b as getPool,
|
|
386
|
+
H as getPools,
|
|
387
|
+
X as getStats,
|
|
388
|
+
oe as repayCoinPTB,
|
|
389
|
+
ee as withdrawCoinPTB
|
|
390
|
+
};
|
|
391
|
+
//# sourceMappingURL=pool.js.map
|
package/dist/pool.js.map
ADDED
|
@@ -0,0 +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,WAAWJ,EAAO,OAAOM,EAAM;AAAA,QAC7C,CAAC,EAC2B,OAAO,CAACA,MAC3B,CAAC,CAACA,EAAM,OAAO,KAAK,CAACC,MAAUA,EAAM,YAAYH,EAAK,EAAE,CAChE;AACD,QAAAA,EAAK,SAASC;AACd,cAAMG,IA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