@naviprotocol/lending 2.0.9-beta.5 → 2.0.9
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/market.d.ts +6 -6
- package/dist/market.js +1 -1
- package/dist/market.js.map +1 -1
- package/dist/package.json.js +4 -4
- package/package.json +1 -1
package/dist/market.d.ts
CHANGED
|
@@ -22,32 +22,32 @@ export declare const MARKETS: {
|
|
|
22
22
|
key: string;
|
|
23
23
|
name: string;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
"sui-usdc": {
|
|
26
26
|
id: number;
|
|
27
27
|
key: string;
|
|
28
28
|
name: string;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
"wbtc-usdc": {
|
|
31
31
|
id: number;
|
|
32
32
|
key: string;
|
|
33
33
|
name: string;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
"xbtc-usdc": {
|
|
36
36
|
id: number;
|
|
37
37
|
key: string;
|
|
38
38
|
name: string;
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
"vsui-usdc": {
|
|
41
41
|
id: number;
|
|
42
42
|
key: string;
|
|
43
43
|
name: string;
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
"vsui-sui": {
|
|
46
46
|
id: number;
|
|
47
47
|
key: string;
|
|
48
48
|
name: string;
|
|
49
49
|
};
|
|
50
|
-
|
|
50
|
+
"hasui-sui": {
|
|
51
51
|
id: number;
|
|
52
52
|
key: string;
|
|
53
53
|
name: string;
|
package/dist/market.js
CHANGED
package/dist/market.js.map
CHANGED
|
@@ -1 +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 'sui-usdc': {\n id: 4,\n key: 'sui-usdc',\n name: 'SUI / USDC Market'\n },\n 'wbtc-usdc': {\n id: 5,\n key: 'wbtc-usdc',\n name: 'WBTC / USDC Market'\n },\n 'xbtc-usdc': {\n id: 6,\n key: 'xbtc-usdc',\n name: 'xBTC / USDC Market'\n },\n 'vsui-usdc': {\n id: 7,\n key: 'vsui-usdc',\n name: 'vSUI / USDC Market'\n },\n 'vsui-sui': {\n id: 8,\n key: 'vsui-sui',\n name: 'vSUI / SUI Market'\n },\n 'hasui-sui': {\n id: 9,\n key: 'hasui-sui',\n name: 'haSUI / SUI 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"],"mappings":";;;AAaO,MAAMA,IAA0B,QAE1BC,IAAU;AAAA,EACrB,MAAM;AAAA,IACJ,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,OAAO;AAAA,IACL,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,KAAK;AAAA,IACH,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,WAAW;AAAA,IACT,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,YAAY;AAAA,IACV,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,aAAa;AAAA,IACX,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,aAAa;AAAA,IACX,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,aAAa;AAAA,IACX,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,YAAY;AAAA,IACV,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,aAAa;AAAA,IACX,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAEV;AAEO,MAAMC,EAAO;AAAA,EAmBlB,YAAYC,GAAgCC,GAAe;AAlB3D,SAAQ,UAAU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AAA,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;"}
|
|
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 \"sui-usdc\": {\n id: 4,\n key: \"sui-usdc\",\n name: \"SUI / USDC Market\"\n },\n \"wbtc-usdc\": {\n id: 5,\n key: \"wbtc-usdc\",\n name: \"WBTC / USDC Market\"\n },\n \"xbtc-usdc\": {\n id: 6,\n key: \"xbtc-usdc\",\n name: \"xBTC / USDC Market\"\n },\n \"vsui-usdc\": {\n id: 7,\n key: \"vsui-usdc\",\n name: \"vSUI / USDC Market\"\n },\n \"vsui-sui\": {\n id: 8,\n key: \"vsui-sui\",\n name: \"vSUI / SUI Market\"\n },\n \"hasui-sui\": {\n id: 9,\n key: \"hasui-sui\",\n name: \"haSUI / SUI 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"],"mappings":";;;AAaO,MAAMA,IAA0B,QAE1BC,IAAU;AAAA,EACrB,MAAM;AAAA,IACJ,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,OAAO;AAAA,IACL,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;AAAA,EAER,KAAK;AAAA,IACH,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,MAAM;AAAA,EAAA;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