@naviprotocol/lending 1.4.1-beta.4 → 1.4.1-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts +7 -1
- package/dist/account.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +625 -614
- package/dist/index.esm.js.map +1 -1
- package/dist/market.d.ts +0 -9
- package/dist/market.d.ts.map +1 -1
- package/dist/oracle.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/account.d.ts
CHANGED
|
@@ -128,8 +128,10 @@ export declare function getCoins(address: string, options?: Partial<{
|
|
|
128
128
|
export declare const getLendingPositions: (address: string, options?: Partial<SuiClientOption & EnvOption & CacheOption & MarketsOption & {
|
|
129
129
|
includeZeroBalanceEmodePositions?: boolean;
|
|
130
130
|
}>) => Promise<LendingPosition[]>;
|
|
131
|
+
export type TokenPriceMap = Record<string, number>;
|
|
131
132
|
export declare class UserPositions {
|
|
132
133
|
private _positions;
|
|
134
|
+
private _priceMap;
|
|
133
135
|
private _overview;
|
|
134
136
|
get positions(): LendingPosition[];
|
|
135
137
|
get overview(): {
|
|
@@ -145,13 +147,17 @@ export declare class UserPositions {
|
|
|
145
147
|
supply: Record<string, string>;
|
|
146
148
|
borrow: Record<string, string>;
|
|
147
149
|
};
|
|
150
|
+
get priceMap(): TokenPriceMap;
|
|
148
151
|
set positions(positions: LendingPosition[]);
|
|
149
|
-
constructor(positions: LendingPosition[]);
|
|
152
|
+
constructor(positions: LendingPosition[], priceMap?: TokenPriceMap);
|
|
153
|
+
updatePriceMap(priceMap: TokenPriceMap): this;
|
|
154
|
+
private getPrice;
|
|
150
155
|
filterPositionsByPool(pool: Pool | EModePool): UserPositions;
|
|
151
156
|
deposit(pool: Pool | EModePool, amount: number): UserPositions;
|
|
152
157
|
withdraw(pool: Pool | EModePool, amount: number): UserPositions;
|
|
153
158
|
borrow(pool: Pool | EModePool, amount: number): UserPositions;
|
|
154
159
|
repay(pool: Pool | EModePool, amount: number): UserPositions;
|
|
160
|
+
private resolveValueUSD;
|
|
155
161
|
getPositionsOverview(positions: LendingPosition[]): {
|
|
156
162
|
hf: number;
|
|
157
163
|
netVaule: string;
|
package/dist/account.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"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
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"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"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("@mysten/sui/transactions"),m=require("@mysten/bcs"),Q=require("@mysten/sui/client"),Ce=require("lodash.camelcase"),je=require("@mysten/sui/utils"),K=require("@pythnetwork/pyth-sui-js"),p=require("bignumber.js"),C=require("@mysten/sui/bcs"),W=m.bcs.bytes(32).transform({input:e=>m.fromHex(e),output:e=>m.toHex(e)}),_e=m.bcs.struct("IncentiveAPYInfo",{asset_id:m.bcs.u8(),apy:m.bcs.u256(),coin_types:m.bcs.vector(m.bcs.string())}),te=m.bcs.struct("IncentivePoolInfo",{pool_id:W,funds:W,phase:m.bcs.u64(),start_at:m.bcs.u64(),end_at:m.bcs.u64(),closed_at:m.bcs.u64(),total_supply:m.bcs.u64(),asset_id:m.bcs.u8(),option:m.bcs.u8(),factor:m.bcs.u256(),distributed:m.bcs.u64(),available:m.bcs.u256(),total:m.bcs.u256()}),Te=m.bcs.struct("IncentivePoolInfoByPhase",{phase:m.bcs.u64(),pools:m.bcs.vector(te)}),Ie=m.bcs.struct("OracleInfo",{oracle_id:m.bcs.u8(),price:m.bcs.u256(),decimals:m.bcs.u8(),valid:m.bcs.bool()}),Be=m.bcs.struct("FlashLoanAssetConfig",{id:m.bcs.string(),asset_id:m.bcs.u8(),coin_type:m.bcs.string(),pool_id:m.bcs.string(),rate_to_supplier:m.bcs.u64(),rate_to_treasury:m.bcs.u64(),max:m.bcs.u64(),min:m.bcs.u64()}),Pe=m.bcs.struct("ReserveDataInfo",{id:m.bcs.u8(),oracle_id:m.bcs.u8(),coin_type:m.bcs.string(),supply_cap:m.bcs.u256(),borrow_cap:m.bcs.u256(),supply_rate:m.bcs.u256(),borrow_rate:m.bcs.u256(),supply_index:m.bcs.u256(),borrow_index:m.bcs.u256(),total_supply:m.bcs.u256(),total_borrow:m.bcs.u256(),last_update_at:m.bcs.u64(),ltv:m.bcs.u256(),treasury_factor:m.bcs.u256(),treasury_balance:m.bcs.u256(),base_rate:m.bcs.u256(),multiplier:m.bcs.u256(),jump_rate_multiplier:m.bcs.u256(),reserve_factor:m.bcs.u256(),optimal_utilization:m.bcs.u256(),liquidation_ratio:m.bcs.u256(),liquidation_bonus:m.bcs.u256(),liquidation_threshold:m.bcs.u256()}),oe=m.bcs.struct("UserStateInfo",{asset_id:m.bcs.u8(),borrow_balance:m.bcs.u256(),supply_balance:m.bcs.u256()}),Ae="1.4.1-beta.4",E={version:Ae},$e=E.version,Se=()=>{if(typeof process<"u"&&process.versions&&process.versions.node)try{const e=require("os"),n=process.version,o=e.type(),r=e.arch();return`Node.js ${n.startsWith("v")?n.substring(1):n}; ${o}/${r}`}catch{return`Node.js ${process.version}; OS/Unknown (Error)`}return"Node/Unknown"},Ee=()=>{let e="";return typeof process<"u"&&process.versions&&process.versions.node&&(e=`lending/${$e} (${Se()})`),e},X=Ee(),$=new Q.SuiClient({url:Q.getFullnodeUrl("mainnet")});function ne(e){const n=[];return e.forEach((o,r)=>{const t=r===e.length-1;if(typeof o=="object"&&o!==null&&t){const{client:a,disableCache:s,cacheTime:c,...i}=o;n.push(i)}else n.push(o)}),JSON.stringify(n)}function T(e){const n={};return(...o)=>{const r=ne(o);return n[r]||(n[r]=e(...o).finally(()=>{delete n[r]})),n[r]}}function A(e){let n={};return(...o)=>{const r=o[o.length-1],t=ne(o),a=n[t];return!r?.disableCache&&typeof a?.data<"u"&&(typeof r?.cacheTime>"u"||r.cacheTime>Date.now()-a.cacheAt)?a.data:e(...o).then(s=>(n[t]={data:s,cacheAt:Date.now()},s))}}function G(e){return Array.isArray(e)?e.map(n=>G(n)):e!=null&&typeof e=="object"?Object.keys(e).reduce((n,o)=>({...n,[Ce(o)]:G(e[o])}),{}):e}function f(e,n){return typeof e=="object"?e:n(e)}function Ve(e,n){return typeof n=="string"?e.object(n):typeof n=="object"&&n.$kind?n:e.object(n.contract.pool)}function q(e,n,o){if(e.results&&e.results.length>0){if(e.results[0].returnValues&&e.results[0].returnValues.length>0)return e.results[0].returnValues.map((r,t)=>(n[t]||n[0]).parse(Uint8Array.from(r[0])))}else if(e.error)return console.log(`Get an error, msg: ${e.error}`),[];return[]}function v(e){return je.normalizeStructTag(e)}function re(e){const n=(e||0)/Math.pow(10,27);return n>Math.pow(10,5)?1/0:n}new K.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:2e4});const Me=27,x=(e,n)=>{if(!Number(e)||!Number(n))return new p(0);const o=new p(1).shiftedBy(1*Me),r=o.multipliedBy(new p(.5));return new p(e).multipliedBy(new p(n)).plus(r).dividedBy(o).integerValue(p.ROUND_DOWN)},M=X?{"User-Agent":X}:{};function z(e,n="uniqueId"){return e.reduce((o,r)=>(o[r[n]]=r,o),{})}function ee(e,n="uniqueId"){return e.reduce((o,r)=>(o[r[n]]=r,o),{})}function L(e,n){const o=e.emodes.find(t=>t.emodeId===n.emodeId);if(!o)throw new Error("EMode not found in pool");const r=o.assets.find(t=>t.assetId===e.id);return{...e,emode:{...r,emodeId:o.emodeId},isEMode:!0}}function ae(e){const[n,o]=e.split("-");return!n||!o?null:{marketKey:n,poolId:parseInt(o)}}function B(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}var F=(e=>(e[e.Supply=1]="Supply",e[e.Withdraw=2]="Withdraw",e[e.Borrow=3]="Borrow",e[e.Repay=4]="Repay",e))(F||{});const R=A(T(async e=>{const n=(e?.markets||[V.main]).map(t=>_(t)),o=`https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env||"prod"}&sdk=${E.version}&market=${n.map(t=>t.key)}`,r=await fetch(o,{headers:M}).then(t=>t.json());return r.data.forEach(t=>{const s=r.meta.emodes.filter(b=>{const j=_(b.marketId);return t.market===j.key&&b.isActive}).filter(b=>!!b.assets.find(j=>j.assetId===t.id));t.emodes=s;const c=p(t.totalSupplyAmount).div(Math.pow(10,9)).decimalPlaces(t.token.decimals,p.ROUND_DOWN).toString(),i=p(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals,p.ROUND_DOWN).toString(),l=p(c).multipliedBy(t.oracle.price).toString(),d=p(i).multipliedBy(t.oracle.price).toString(),g=p(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals,p.ROUND_DOWN).toString(),h=p.max(p(t.borrowedAmount),p(t.validBorrowAmount)).shiftedBy(-9).decimalPlaces(t.token.decimals,p.ROUND_DOWN).toString(),y=p(g).multipliedBy(t.oracle.price).toString(),u=p(h).multipliedBy(t.oracle.price).toString();t.poolSupplyAmount=c,t.poolBorrowAmount=i,t.poolSupplyValue=l,t.poolBorrowValue=d,t.poolSupplyCapAmount=g,t.poolBorrowCapAmount=h,t.poolSupplyCapValue=y,t.poolBorrowCapValue=u}),r.data}));async function P(e,n){let o=n?.market;if(typeof e=="string"){const a=ae(e);a&&(o=a.marketKey,e=a.poolId)}const r=await R({...n,markets:[o||D],cacheTime:w});if(typeof e=="object")return e;const t=r.find(a=>typeof e=="string"?v(a.suiCoinType)===v(e):typeof e=="number"?a.id===e:!1);if(!t)throw new Error("Pool not found");return t.isDeprecated&&console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`),t}const Ue=A(T(async e=>{const n=`https://open-api.naviprotocol.io/api/navi/stats?sdk=${E.version}`;return(await fetch(n,{headers:M}).then(r=>r.json())).data})),De=A(T(async e=>{const n=`https://open-api.naviprotocol.io/api/navi/fee?sdk=${E.version}`;return await fetch(n,{headers:M}).then(r=>r.json())}));async function ce(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r);if(a?.deprecatedAt&&Date.now()>a.deprecatedAt)throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);const s=typeof o=="object"&&o.$kind==="GasCoin";if(v(a.suiCoinType)===v("0x2::sui::SUI")&&s){if(!r?.amount)throw new Error("Amount is required for sui coin");o=e.splitCoins(o,[r.amount])}let c;return typeof r?.amount<"u"?c=f(r.amount,e.pure.u64):c=e.moveCall({target:"0x2::coin::value",arguments:[f(o,e.object)],typeArguments:[a.suiCoinType]}),r?.accountCap?e.moveCall({target:`${t.package}::incentive_v3::deposit_with_account_cap`,arguments:[e.object("0x06"),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),f(o,e.object),e.object(t.incentiveV2),e.object(t.incentiveV3),f(r.accountCap,e.object)],typeArguments:[a.suiCoinType]}):e.moveCall({target:`${t.package}::incentive_v3::entry_deposit`,arguments:[e.object("0x06"),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),f(o,e.object),c,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]}),t.version===2&&a.id===0&&(!r?.env||r?.env==="prod")&&e.moveCall({target:`${t.package}::pool::refresh_stake`,arguments:[e.object(a.contract.pool),e.object("0x05")]}),e}async function Oe(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r),s=f(o,e.pure.u64);let c;if(t.version===1)if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw_with_account_cap`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3),f(r.accountCap,e.object)],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]});c=l}else if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw_with_account_cap_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3),f(r.accountCap,e.object),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}return e.moveCall({target:"0x2::coin::from_balance",arguments:[c],typeArguments:[a.suiCoinType]})}async function Fe(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r);if(a?.deprecatedAt&&Date.now()>a.deprecatedAt)throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);const s=f(o,e.pure.u64);let c;if(t.version===1)if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow_with_account_cap`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3),f(r.accountCap,e.object)],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]});c=l}else if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow_with_account_cap_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3),f(r.accountCap,e.object),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),s,e.object(t.incentiveV2),e.object(t.incentiveV3),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}return e.moveCall({target:"0x2::coin::from_balance",arguments:[e.object(c)],typeArguments:[a.suiCoinType]})}async function Ne(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r),s=typeof o=="object"&&o.$kind==="GasCoin";if(v(a.suiCoinType)===v("0x2::sui::SUI")&&s){if(!r?.amount)throw new Error("Amount is required for sui coin");o=e.splitCoins(o,[r.amount])}let c;if(typeof r?.amount<"u"?c=f(r.amount,e.pure.u64):c=e.moveCall({target:"0x2::coin::value",arguments:[f(o,e.object)],typeArguments:[a.suiCoinType]}),r?.accountCap){const[i]=e.moveCall({target:`${t.package}::incentive_v3::repay_with_account_cap`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),f(o,e.object),e.object(t.incentiveV2),e.object(t.incentiveV3),f(r.accountCap,e.object)],typeArguments:[a.suiCoinType]});return e.moveCall({target:"0x2::coin::from_balance",arguments:[i],typeArguments:[a.suiCoinType]})}else return e.moveCall({target:`${t.package}::incentive_v3::entry_repay`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),f(o,e.object),c,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]}),e}const Re=A(T(async e=>{const n=await k({...e});if(e?.address&&typeof e?.asset<"u")try{const t=await P(e.asset,e),a=e?.client??$,s=new N.Transaction;s.moveCall({target:`${n.package}::incentive_v3::get_borrow_fee_v2`,arguments:[s.object(n.incentiveV3),s.pure.address(e.address),s.pure.u8(t.id),s.pure.u64(1e4)],typeArguments:[]});const c=await a.devInspectTransactionBlock({transactionBlock:s,sender:e.address}),i=q(c,[C.bcs.u64()]);return(Number(i[0])||0)/100}catch(t){console.error(t)}const r=(await $.getObject({id:n.incentiveV3,options:{showType:!0,showOwner:!0,showContent:!0}})).data.content.fields.borrow_fee_rate;return Number(r)/100})),D="main",V={main:{id:0,key:"main",name:"Main Market"},ember:{id:1,key:"ember",name:"Ember Market"}};class se{constructor(n,o){this.poolMap={},this.emodeMap={},this.pools=[],this.emodes=[],this.emodePools=[],this.emodeBorrowablePools=[],this.emodeSupplyablePools=[],this._overview={marketTotalSupplyValue:"0",marketTotalBorrowValue:"0"},this.config=_(n),this.initPools(o)}get overview(){return this._overview}initPools(n){const o=z(this.pools),r=ee(this.emodes),t=new Set,a=new Set;let s=p(0),c=p(0);n.forEach(i=>{if(!this.checkMarket(i.market)){console.warn(`Pool is not in market ${this.config.name}`,i);return}o[i.uniqueId]||this.pools.push(i),i?.emodes?.forEach(d=>{r[d.uniqueId]||this.emodes.push(d),d.assets.forEach(g=>{g.isDebt&&d.assets.find(y=>y.isCollateral&&y.ltv>0&&y.assetId!==i.id)&&t.add(i.uniqueId),g.isCollateral&&d.assets.find(y=>y.isDebt&&y.assetId!==i.id)&&a.add(i.uniqueId)})}),c=c.plus(i.poolBorrowValue),s=s.plus(i.poolSupplyValue)}),this.poolMap=z(this.pools,"id"),this.emodeMap=ee(this.emodes,"emodeId"),this.emodes.forEach(i=>{const l=this.getEModePools(i.emodeId);this.emodePools.push(...l)}),this._overview={marketTotalSupplyValue:s.toString(),marketTotalBorrowValue:c.toString()},this.emodeBorrowablePools=this.pools.filter(i=>t.has(i.uniqueId)),this.emodeSupplyablePools=this.pools.filter(i=>a.has(i.uniqueId))}getEMode(n){return this.emodeMap[n]||null}getEModeRelatePools(n,o){const{collateral:r,debt:t,emodeId:a}=o||{},s=[];return n.emodes.forEach(c=>{typeof a=="number"&&a!==c.emodeId||c.assets.forEach(i=>{typeof r=="boolean"&&r&&i.isCollateral&&i.assetId===n.id&&s.push(this.poolMap[i.assetId]),typeof t=="boolean"&&t&&i.isDebt&&i.assetId===n.id&&s.push(this.poolMap[i.assetId])})}),s}getEModePools(n){const o=this.getEMode(n);return o?o.assets.map(t=>t.assetId).map(t=>this.poolMap[t]).filter(t=>!!t).map(t=>{const a=o.assets.find(s=>s.assetId===t.id);return{...t,emode:{...a,emodeId:o.emodeId},isEMode:!0}}):[]}checkMarket(n){let o=!1;return typeof n=="number"&&n===this.config.id&&(o=!0),typeof n=="string"&&n===this.config.key&&(o=!0),typeof n=="object"&&n.id===this.config.id&&(o=!0),o}}const _=e=>{const o=Object.values(V).find(r=>typeof e=="number"?r.id===e:typeof e=="string"?r.key===e:r.id===e.id);if(!o)throw new Error("Market not found");return o},ie=A(T(async(e,n)=>{const o=await R({cacheTime:6e4,...n,markets:e});return e.map(r=>{const t=_(r),a=o.filter(s=>s.market===t.key);return new se(r,a)})})),Le=A(T(async(e,n)=>(await ie([e],n))[0])),k=A(T(async e=>{const n=_(e?.market||D),o=`https://open-api.naviprotocol.io/api/navi/config?env=${e?.env||"prod"}&sdk=${E.version}&market=${n.key}`;return(await fetch(o,{headers:M}).then(t=>t.json())).data})),w=1e3*60*5;async function le(e,n){const o=await k({cacheTime:w,...n});return e.moveCall({target:`${o.package}::lending::create_account`,arguments:[]})}async function ue(e,n,o){const r=await k({cacheTime:w,...o});return e.moveCall({target:`${r.package}::account::account_owner`,arguments:[n]})}async function pe(e,n,o){const r=await k({...o,cacheTime:w});return o?.accountCap?e.moveCall({target:`${r.package}::lending::enter_emode_with_account_cap`,arguments:[e.object(r.storage),f(n,e.pure.u64),f(o.accountCap,e.object)]}):e.moveCall({target:`${r.package}::lending::enter_emode`,arguments:[e.object(r.storage),f(n,e.pure.u64)]}),e}async function qe(e,n){const o=await k({...n,cacheTime:w});return n?.accountCap?e.moveCall({target:`${o.package}::lending::exit_emode_with_account_cap`,arguments:[e.object(o.storage),f(n.accountCap,e.object)]}):e.moveCall({target:`${o.package}::lending::exit_emode`,arguments:[e.object(o.storage)]}),e}async function He(e,n,o){const r=await k({cacheTime:w,...o}),t=await le(e,o);await pe(e,n,{...o,accountCap:t});const a=await _(o?.market||D),s=await ue(e,t,o);return e.moveCall({target:`${r.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,arguments:[e.object(r.emode.contract.registryObject),s,f(a.id,e.pure.u64),f(n,e.pure.u64)]}),t}const Y=A(T(async(e,n)=>{const o=await k({cacheTime:w,...n}),r=new N.Transaction,t=n?.client??$;r.moveCall({target:`${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,arguments:[r.object(o.emode.contract.registryObject),r.pure.address(e)]});const s=(await t.devInspectTransactionBlock({transactionBlock:r,sender:e})).results[0].returnValues,c=C.bcs.vector(C.bcs.u64()).parse(Uint8Array.from(s[0][0])),i=C.bcs.vector(C.bcs.u64()).parse(Uint8Array.from(s[1][0])),l=C.bcs.vector(C.bcs.Address).parse(Uint8Array.from(s[2][0]));return c.map((d,g)=>({marketId:Number(d),emodeId:Number(i[g]),accountCap:l[g].toString()}))}));function We(e){return`${_(e.marketId).key}-${e.emodeId}`}function Ge(e,n,o){const r=typeof o?.balance=="number",t=r?o.balance:0;let a=0;const s=[];let c="";if(n.sort((i,l)=>Number(l.balance)-Number(i.balance)).forEach(i=>{if(!(r&&a>=t)&&Number(i.balance)!==0){if(c||(c=i.coinType),c!==i.coinType)throw new Error("All coins must be of the same type");a+=Number(i.balance),s.push(i.coinObjectId)}}),s.length===0)throw new Error("No coins to merge");if(r&&a<t)throw new Error(`Balance is less than the specified balance: ${a} < ${t}`);return v(c)===v("0x2::sui::SUI")&&o?.useGasCoin?r?e.splitCoins(e.gas,[e.pure.u64(t)]):e.gas:(s.length===1?e.object(s[0]):e.mergeCoins(s[0],s.slice(1)),r?e.splitCoins(s[0],[e.pure.u64(t)]):s[0])}async function J(e,n,o,r,t,a,s){const c=await k({...s,cacheTime:w}),i=await P(o,s);return e.moveCall({target:`${c.uiGetter}::calculator_unchecked::dynamic_health_factor`,arguments:[e.object("0x06"),e.object(c.storage),e.object(c.oracle.priceOracle),Ve(e,i),f(n,e.pure.address),f(i.id,e.pure.u8),f(r,e.pure.u64),f(t,e.pure.u64),f(a,e.pure.bool)],typeArguments:[i.suiCoinType]})}async function de(e,n,o){return J(e,n,0,0,0,!1,o)}async function me(e,n,o){const r=new N.Transaction,t=o?.client??$,a=await R({...o,markets:Object.values(V)}),s=z(a);for(let d of n){const g=await k({...o,cacheTime:w,market:d.market});r.moveCall({target:`${g.uiGetter}::getter_unchecked::get_user_state`,arguments:[r.object(g.storage),r.pure.address(d.address)]})}const i=((await t.devInspectTransactionBlock({transactionBlock:r,sender:e})).results||[]).map(d=>d.returnValues?.map(g=>C.bcs.vector(oe).parse(Uint8Array.from(g[0])))[0]||[]),l=[];return i.forEach((d,g)=>{const h=n[g],y=_(h.market);d.forEach(u=>{if(u.supply_balance==="0"&&u.borrow_balance==="0"&&(h.emodeId===void 0||!o?.includeZeroBalanceEmodePositions))return;const b=s[`${y.key}-${u.asset_id}`];if(!b)return;const j=x(u.supply_balance,b.currentSupplyIndex).toString(),I=x(u.borrow_balance,b.currentBorrowIndex).toString();l.push({supplyBalance:j,borrowBalance:I,assetId:u.asset_id,market:y.key,pool:b,emodeId:h.emodeId})})}),l}const ze=A(async(e,n)=>{const r=(n?.markets||Object.keys(V)).map(t=>_(t)).map(t=>({address:e,market:t.key}));return await me(e,r,n)});async function Ke(e,n){const o=n?.client??$,r=new N.Transaction;await de(r,e,n);const t=await o.devInspectTransactionBlock({transactionBlock:r,sender:e}),a=q(t,[C.bcs.u256()]);return re(Number(a[0])||0)}async function Ye(e,n,o,r){const t=r?.client??$,a=new N.Transaction;let s=0,c=0;const i=await P(n,r);if(o.forEach(h=>{h.type===F.Supply?s+=h.amount:h.type===F.Withdraw?s-=h.amount:h.type===F.Borrow?c+=h.amount:h.type===F.Repay&&(c-=h.amount)}),s*c<0)throw new Error("Invalid operations");const l=s>0||c>0;await J(a,e,i,Math.abs(s),Math.abs(c),l,r);const d=await t.devInspectTransactionBlock({transactionBlock:a,sender:e}),g=q(d,[C.bcs.u256()]);return re(Number(g[0])||0)}const Je=T(async(e,n)=>{const o=new URLSearchParams;n?.cursor&&o.set("cursor",n.cursor),o.set("userAddress",e);const r=`https://open-api.naviprotocol.io/api/navi/user/transactions?${o.toString()}&sdk=${E.version}`;return(await fetch(r,{headers:M}).then(a=>a.json())).data});async function Ze(e,n){let o=null;const r=[],t=n?.client??$;do{let a;if(n?.coinType?a=await t.getCoins({owner:e,coinType:n?.coinType,cursor:o,limit:100}):a=await t.getAllCoins({owner:e,cursor:o,limit:100}),!a.data||!a.data.length)break;r.push(...a.data),o=a.nextCursor}while(o);return r}const fe=A(async(e,n)=>{const o=[],r=(n?.markets||Object.keys(V)).map(c=>_(c));let t=[];try{t=await Y(e,n)}catch(c){console.error(c)}const a=r.map(c=>({address:e,market:c.key})).concat(t.filter(c=>!!r.find(i=>i.id===c.marketId)).map(c=>({address:c.accountCap,market:_(c.marketId).key,emodeId:c.emodeId})));return(await me(e,a,n)).forEach(c=>{const i=typeof c.emodeId=="number"?t.find(l=>{const d=_(c.market);return l.emodeId===c.emodeId&&l.marketId===d.id}):void 0;if(i){if(!c.pool.emodes.find(d=>d.emodeId===i.emodeId))return;if(p(c.supplyBalance).gte(0)){const d=p(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN),g=L(c.pool,i);if(d.gt(0)||g.emode.isCollateral)try{o.push({id:`${c.pool.uniqueId}_${i.emodeId}_navi-lending-emode-supply-${B()}`,wallet:e,protocol:"navi",market:c.market,type:"navi-lending-emode-supply","navi-lending-emode-supply":{amount:d.toString(),pool:L(c.pool,i),token:c.pool.token,valueUSD:d.multipliedBy(c.pool.oracle.price).toString(),emodeCap:i}})}catch(h){console.error(h)}}if(p(c.borrowBalance).gte(0)){const d=p(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN),g=L(c.pool,i);if(d.gt(0)||g.emode.isDebt)try{o.push({id:`${c.pool.uniqueId}_${i.emodeId}_navi-lending-emode-borrow-${B()}`,wallet:e,protocol:"navi",market:c.market,type:"navi-lending-emode-borrow","navi-lending-emode-borrow":{amount:d.toString(),pool:L(c.pool,i),token:c.pool.token,valueUSD:d.multipliedBy(c.pool.oracle.price).toString(),emodeCap:i}})}catch(h){console.error(h)}}}else{if(p(c.supplyBalance).gt(0)){const l=p(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN);o.push({id:`${c.pool.uniqueId}_navi-lending-supply-${B()}`,wallet:e,protocol:"navi",type:"navi-lending-supply",market:c.market,"navi-lending-supply":{amount:l.toString(),pool:c.pool,token:c.pool.token,valueUSD:l.multipliedBy(c.pool.oracle.price).toString()}})}if(p(c.borrowBalance).gt(0)){const l=p(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN);o.push({id:`${c.pool.uniqueId}_navi-lending-borrow-${B()}`,wallet:e,protocol:"navi",market:c.market,type:"navi-lending-borrow","navi-lending-borrow":{amount:l.toString(),pool:c.pool,token:c.pool.token,valueUSD:l.multipliedBy(c.pool.oracle.price).toString()}})}}}),o});class U{constructor(n){this._positions=[],this._overview={hf:1/0,netVaule:"0",netWorthApr:"0",totalSupplyValue:"0",totalBorrowValue:"0",totalsupplyApy:"0",totalBorrowApy:"0",maxLiquidationValue:"0",maxLoanToVaule:"0",supply:{},borrow:{}},this.positions=n}get positions(){return this._positions}get overview(){return this._overview}set positions(n){this._positions=n,this._overview=this.getPositionsOverview(n)}filterPositionsByPool(n){const r=!!n.isEMode?["navi-lending-emode-supply","navi-lending-emode-borrow"]:["navi-lending-supply","navi-lending-borrow"];return new U(this.positions.filter(t=>{const a=t[t.type];return r.includes(t.type)&&a.pool.uniqueId===n.uniqueId}))}deposit(n,o){const r=!!n.isEMode;let t;return r?t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-supply","navi-lending-emode-supply":{amount:o.toString(),valueUSD:p(o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n,emodeCap:{}}}:t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-supply","navi-lending-supply":{amount:o.toString(),valueUSD:p(o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n}},new U([...this.positions,t])}withdraw(n,o){const r=!!n.isEMode;let t;return r?t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-supply","navi-lending-emode-supply":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n,emodeCap:{}}}:t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-supply","navi-lending-supply":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n}},new U([...this.positions,t])}borrow(n,o){const r=!!n.isEMode;let t;return r?t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-borrow","navi-lending-emode-borrow":{amount:o.toString(),valueUSD:p(o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n,emodeCap:{}}}:t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-borrow","navi-lending-borrow":{amount:o.toString(),valueUSD:p(o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n}},new U([...this.positions,t])}repay(n,o){const r=!!n.isEMode;let t;return r?t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-borrow","navi-lending-emode-borrow":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n,emodeCap:{}}}:t={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-borrow","navi-lending-borrow":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(n.oracle.price).toString(),token:n.token,pool:n}},new U([...this.positions,t])}getPositionsOverview(n){const o={},r={};let t=new p(0),a=new p(0),s=new p(0),c=new p(0),i=new p(0),l=new p(0);n.forEach(y=>{if(y.type==="navi-lending-supply"){const u=y["navi-lending-supply"];t=t.plus(u.valueUSD),i=i.plus(new p(u.valueUSD).multipliedBy(u.pool.liquidationFactor.threshold)),l=l.plus(new p(u.valueUSD).multipliedBy(u.pool.ltvValue))}else if(y.type==="navi-lending-borrow")a=a.plus(y["navi-lending-borrow"].valueUSD);else if(y.type==="navi-lending-emode-supply"){const u=y["navi-lending-emode-supply"];t=t.plus(u.valueUSD);const b=u.pool.emode;i=i.plus(new p(u.valueUSD).multipliedBy(b.lt)),l=l.plus(new p(u.valueUSD).multipliedBy(b.ltv))}else y.type==="navi-lending-emode-borrow"&&(a=a.plus(y["navi-lending-emode-borrow"].valueUSD))}),a=p.max(a,0),t=p.max(t,0),i=p.max(i,0),l=p.max(l,0),n.forEach(y=>{if(y.type==="navi-lending-supply"){const u=y["navi-lending-supply"],b=u.pool.supplyIncentiveApyInfo.apy;t.gt(0)&&(s=s.plus(new p(u.valueUSD).dividedBy(t).multipliedBy(new p(b).dividedBy(100)))),o[u.pool.suiCoinType]=p(o[u.pool.suiCoinType]||0).plus(u.amount).toString()}else if(y.type==="navi-lending-borrow"){const u=y["navi-lending-borrow"],b=u.pool.borrowIncentiveApyInfo.apy;a.gt(0)&&(c=c.plus(new p(u.valueUSD).dividedBy(a).multipliedBy(new p(b).dividedBy(100)))),r[u.pool.suiCoinType]=p(r[u.pool.suiCoinType]||0).plus(u.amount).toString()}else if(y.type==="navi-lending-emode-supply"){const u=y["navi-lending-emode-supply"],b=u.pool.supplyIncentiveApyInfo.apy;t.gt(0)&&(s=s.plus(new p(u.valueUSD).dividedBy(t).multipliedBy(new p(b).dividedBy(100)))),o[u.pool.suiCoinType]=p(o[u.pool.suiCoinType]||0).plus(u.amount).toString()}else if(y.type==="navi-lending-emode-borrow"){const u=y["navi-lending-emode-borrow"],b=u.pool.borrowIncentiveApyInfo.apy;a.gt(0)&&(c=c.plus(new p(u.valueUSD).dividedBy(a).multipliedBy(new p(b).dividedBy(100)))),r[u.pool.suiCoinType]=p(r[u.pool.suiCoinType]||0).plus(u.amount).toString()}});const d=t.minus(a),g=t.minus(a).eq(0)?new p(0):t.multipliedBy(s).minus(a.multipliedBy(c)).div(t.minus(a));return{hf:a.toNumber()!==0?i.dividedBy(a).toNumber():1/0,netVaule:d.toString(),netWorthApr:g.toString(),totalSupplyValue:t.toString(),totalBorrowValue:a.toString(),totalsupplyApy:s.toString(),totalBorrowApy:c.toString(),maxLiquidationValue:i.toString(),maxLoanToVaule:l.toString(),supply:o,borrow:r}}}async function Qe(e,n,o,r){const t=await k({...r,cacheTime:w});t.limter&&e.moveCall({target:`${t.limter}::navi_adaptor::verify_navi_position_healthy`,arguments:[e.object("0x06"),e.object(t.storage),e.object(t.priceOracle),f(n,e.pure.address),e.pure.u256(new p(o).shiftedBy(27).toNumber())]})}const ge=new K.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:1e4});async function Xe(e){try{const n=[],o=await ge.getLatestPriceFeeds(e);if(!o)return n;const r=Math.floor(new Date().valueOf()/1e3);for(const t of o){const a=t.getPriceUnchecked();if(a.publishTime>r){console.warn(`pyth price feed is invalid, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`);continue}r-t.getPriceUnchecked().publishTime>30&&(console.info(`stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`),n.push(t.id))}return n}catch(n){throw new Error(`failed to get pyth stale price feed id, msg: ${n.message}`)}}async function xe(e,n){try{const o=[],r=n?.client??$,t=e.map(s=>s.priceInfoObject),a=await r.multiGetObjects({ids:Array.from(new Set(t)),options:{showContent:!0}});for(const s of a){const c=s.data;if(!c||!c.content||c.content.dataType!=="moveObject"){console.warn(`fetched object ${c?.objectId} datatype should be moveObject`);continue}const i=e.find(u=>u.priceInfoObject==c.objectId);if(!i){console.warn(`unable to find pyth info from array, priceInfoObject: ${c.objectId}`);continue}const l=c.content.fields.price_info.fields.price_feed.fields.price.fields,{magnitude:d,negative:g}=l.price.fields,h=l.conf,y=l.timestamp;o.push({priceFeedId:i.priceFeedId,priceInfoObject:i.priceInfoObject,price:g?"-"+d:d,conf:h,publishTime:Number(y),expiration:i.expiration})}return o}catch(o){console.error(o,`Polling Sui on-chain price for ${e} failed.`);return}}async function ye(e,n){try{const o=[],r=await xe(e,n);if(!r)return o;const t=Math.floor(new Date().valueOf()/1e3);for(const a of r){if(a.publishTime>t){console.warn(`pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`);continue}const s=a.expiration||60;t-a.publishTime>s&&(console.info(`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`),o.push(a.priceFeedId))}return o}catch(o){throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`)}}async function be(e,n,o){const r=o?.client??$,t=await k({...o,cacheTime:w});try{const a=await ge.getPriceFeedsUpdateData(n);return await new K.SuiPythClient(r,t.oracle.pythStateId,t.oracle.wormholeStateId).updatePriceFeeds(e,a,n)}catch(a){throw new Error(`failed to update pyth price feeds, msg: ${a.message}`)}}async function he(e,n,o){const r=await k({...o,cacheTime:w});if(o?.updatePythPriceFeeds){const t=n.filter(a=>!!a.pythPriceFeedId&&!!a.pythPriceInfoObject).map(a=>({priceFeedId:a.pythPriceFeedId,priceInfoObject:a.pythPriceInfoObject,expiration:30}));try{const a=await ye(t,o);a.length>0&&await be(e,a,o)}catch{console.error("Failed to update Pyth price feeds")}}for(const t of n)o?.env==="dev"?e.moveCall({target:`${r.oracle.packageId}::oracle_pro::update_single_price`,arguments:[e.object("0x6"),e.object(r.oracle.oracleConfig),e.object(r.oracle.priceOracle),e.object(r.oracle.supraOracleHolder),e.object(t.pythPriceInfoObject),e.pure.address(t.feedId)]}):e.moveCall({target:`${r.oracle.packageId}::oracle_pro::update_single_price_v2`,arguments:[e.object("0x6"),e.object(r.oracle.oracleConfig),e.object(r.oracle.priceOracle),e.object(r.oracle.supraOracleHolder),e.object(t.pythPriceInfoObject),e.object(r.oracle.switchboardAggregator),e.pure.address(t.feedId)]});return e}async function Z(e){return(await k({...e,cacheTime:w})).oracle.feeds}function we(e,n){return e.filter(o=>!!(n?.lendingState&&n.lendingState.find(t=>o.oracleId===t.pool.oracleId)||n?.lendingPositions&&n.lendingPositions.find(t=>{if(!["navi-lending-supply","navi-lending-borrow","navi-lending-emode-supply","navi-lending-emode-borrow"].includes(t.type))return!1;const s=t[t.type]?.pool;return o.oracleId===s?.oracleId})||n?.pools&&n.pools.find(t=>o.oracleId===t.oracleId)))}async function et(e,n,o,r){try{const t=await Z({...r}),a=[];o.forEach(l=>{a.includes(l.market)||a.push(l.market)});const s=await fe(n,{...r,markets:a}),c=we(t,{lendingPositions:s,pools:o});return await he(e,c,{updatePythPriceFeeds:!0,...r})}catch(t){if(r?.throws)throw t;return console.error(t),e}}const H=A(T(async e=>{const n=`https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env||"prod"}&sdk=${E.version}&market=${e?.market||D}`,o=await fetch(n,{headers:M}).then(r=>r.json());return Object.keys(o.data).map(r=>({...o.data[r],coinType:r}))}));async function tt(e,n){return(await H(n)).find(r=>typeof e=="string"?v(r.coinType)===v(e):typeof e=="number"?r.assetId===e:r.assetId===e.id)||null}async function ot(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r);if(!(await H({...r,cacheTime:w})).some(i=>v(i.coinType)===v(a.suiCoinType)))throw new Error("Pool does not support flashloan");if(t.version===1){const[i,l]=e.moveCall({target:`${t.package}::lending::flash_loan_with_ctx`,arguments:[e.object(t.flashloanConfig),e.object(a.contract.pool),f(o,e.pure.u64)],typeArguments:[a.suiCoinType]});return[i,l]}else{const[i,l]=e.moveCall({target:`${t.package}::lending::flash_loan_with_ctx_v2`,arguments:[e.object(t.flashloanConfig),e.object(a.contract.pool),f(o,e.pure.u64),e.object("0x05")],typeArguments:[a.suiCoinType]});return[i,l]}}async function nt(e,n,o,r,t){const a=await k({...t,cacheTime:w}),s=await P(n,t);if(!(await H({...t,cacheTime:w})).some(d=>v(d.coinType)===v(s.suiCoinType)))throw new Error("Pool does not support flashloan");const[l]=e.moveCall({target:`${a.package}::lending::flash_repay_with_ctx`,arguments:[e.object("0x06"),e.object(a.storage),e.object(s.contract.pool),f(o,e.object),f(r,e.object)],typeArguments:[s.suiCoinType]});return[l]}async function rt(e,n,o,r,t,a){const s={...a,cacheTime:w},c=await k(s),i=await P(n,s),l=await P(r,s);if(c.version===1){const[d,g]=e.moveCall({target:`${c.package}::incentive_v3::liquidation`,arguments:[e.object("0x06"),e.object(c.priceOracle),e.object(c.storage),e.pure.u8(i.id),e.object(i.contract.pool),f(o,e.object),e.pure.u8(l.id),e.object(l.contract.pool),f(t,e.pure.address),e.object(c.incentiveV2),e.object(c.incentiveV3)],typeArguments:[i.suiCoinType,l.suiCoinType]});return[d,g]}else{const[d,g]=e.moveCall({target:`${c.package}::incentive_v3::liquidation_v2`,arguments:[e.object("0x06"),e.object(c.priceOracle),e.object(c.storage),e.pure.u8(i.id),e.object(i.contract.pool),f(o,e.object),e.pure.u8(l.id),e.object(l.contract.pool),f(t,e.pure.address),e.object(c.incentiveV2),e.object(c.incentiveV3),e.object("0x05")],typeArguments:[i.suiCoinType,l.suiCoinType]});return[d,g]}}async function at(e,n,o){const r=o?.client??$,t=new N.Transaction,a=await R({...o,markets:Object.values(V),cacheTime:w}),s=await Z(o);for(let d of n){const g=await k({...o,cacheTime:w,market:d.market});t.moveCall({target:`${g.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,arguments:[t.object("0x06"),t.object(g.storage),t.object(g.incentiveV3),t.pure.address(d.address)]})}const c=await r.devInspectTransactionBlock({transactionBlock:t,sender:e}),i=[];c?.results?.forEach(d=>{i.push(q({results:[d]},[C.bcs.vector(C.bcs.string()),C.bcs.vector(C.bcs.string()),C.bcs.vector(C.bcs.u8()),C.bcs.vector(C.bcs.Address),C.bcs.vector(C.bcs.u256())]))});const l=[];return i.forEach((d,g)=>{const h=n[g];if(d.length===5&&Array.isArray(d[0])){const y=d[0].length;for(let u=0;u<y;u++){const b=s.find(I=>v(I.coinType)===v(d[1][u])),j=a.find(I=>v(I.coinType)===v(d[0][u])&&I.market===h.market);!b||!j||l.push({assetId:j.id,assetCoinType:v(d[0][u]),rewardCoinType:v(d[1][u]),option:Number(d[2][u]),userClaimableReward:Number(d[4][u])/Math.pow(10,b.priceDecimal),ruleIds:Array.isArray(d[3][u])?d[3][u]:[d[3][u]],market:h.market,owner:h.owner,address:h.address,emodeId:h.emodeId})}}}),l}async function ct(e,n){const o=(n?.markets||[V.main]).map(a=>_(a));let r=[];try{r=await Y(e,n)}catch(a){console.error(a)}const t=o.map(a=>({address:e,owner:e,market:a.key})).concat(r.filter(a=>!!o.find(s=>s.id===a.marketId)).map(a=>{const s=_(a.marketId);return{address:a.accountCap,owner:e,market:s.key,emodeId:a.emodeId}}));return await at(e,t,n)}function st(e){const n=new Map;e.forEach(r=>{const t=r.assetId,a=r.option,s=`${t}-${a}-${r.rewardCoinType}-${r.market}`;n.has(s)?n.get(s).total+=r.userClaimableReward:n.set(s,{assetId:t,rewardType:a,coinType:r.rewardCoinType,total:Number(r.userClaimableReward),market:r.market})});const o=new Map;for(const{assetId:r,rewardType:t,coinType:a,total:s,market:c}of n.values()){const i=`${r}-${t}-${c}`;o.has(i)||o.set(i,{assetId:r,rewardType:t,market:c,rewards:new Map});const l=o.get(i);l.rewards.set(a,(l.rewards.get(a)||0)+s)}return Array.from(o.values()).map(r=>({assetId:r.assetId,rewardType:r.rewardType,market:r.market,rewards:Array.from(r.rewards.entries()).map(([t,a])=>({coinType:t,available:a.toFixed(6)}))}))}const it=T(async(e,n)=>{const o=`https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${E.version}&market=${n?.market||D}`;return(await fetch(o,{headers:M}).then(t=>t.json())).data}),lt=T(async(e,n)=>{const o=`https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${n?.page||1}&pageSize=${n?.size||400}&sdk=${E.version}&market=${n?.market||D}`,r=await fetch(o,{headers:M}).then(t=>t.json());return G({data:r.data.rewards})});async function ut(e,n,o){const r=await R({...o,markets:Object.values(V),cacheTime:w}),t=new Map;for(const s of n){const{rewardCoinType:c,ruleIds:i,market:l,owner:d,address:g,emodeId:h}=s,y=`${c}___${g}`;for(const u of i){t.has(y)||t.set(y,{assetIds:[],ruleIds:[],amount:0,market:l,owner:d,address:g,isEMode:typeof h<"u"});const b=t.get(y);b.assetIds.push(s.assetCoinType.replace("0x","")),b.ruleIds.push(u),b.amount+=s.userClaimableReward}}const a=[];for(const[s,{assetIds:c,ruleIds:i,amount:l,market:d,owner:g,address:h,isEMode:y}]of t){const u=await k({...o,cacheTime:w,market:d}),b=s.split("___")[0],j=r.find(S=>v(S.suiCoinType)===v(b)&&S.market===d);if(!j||!j.contract.rewardFundId)throw new Error(`No matching rewardFund found for reward coin: ${b} ${d}`);const I=j.contract.rewardFundId;if(o?.accountCap&&!o.customCoinReceive)throw new Error("customCoinReceive is required when accountCap is provided");if(o?.customCoinReceive){let S;o.accountCap?S=e.moveCall({target:`${u.package}::incentive_v3::claim_reward_with_account_cap`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",i),f(o.accountCap,e.object)],typeArguments:[b]}):y?S=e.moveCall({target:`${u.package}::incentive_v3::claim_reward_with_account_cap`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",i),f(h,e.object)],typeArguments:[b]}):S=e.moveCall({target:`${u.package}::incentive_v3::claim_reward`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",i)],typeArguments:[b]});const[O]=e.moveCall({target:"0x2::coin::from_balance",arguments:[S],typeArguments:[b]});if(o?.customCoinReceive.type==="transfer"){if(!o.customCoinReceive.transfer)throw new Error("customCoinReceive.transfer is required");e.transferObjects([O],f(o.customCoinReceive.transfer,e.pure.address))}if(o?.customCoinReceive.type==="depositNAVI"){const ve=p(j.totalSupplyAmount).shiftedBy(-9),ke=p(j.supplyCapCeiling).shiftedBy(-27);ve.plus(l).isGreaterThan(ke)&&o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress?e.transferObjects([O],e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)):await ce(e,j,O,o)}else a.push({coin:O,identifier:j,owner:g,isEMode:y})}else if(o?.accountCap||y){const S=e.moveCall({target:`${u.package}::incentive_v3::claim_reward_with_account_cap`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",i),f(o?.accountCap||h,e.object)],typeArguments:[b]}),[O]=e.moveCall({target:"0x2::coin::from_balance",arguments:[S],typeArguments:[b]});e.transferObjects([O],f(o?.accountCap||g,e.pure.address))}else e.moveCall({target:`${u.package}::incentive_v3::claim_reward_entry`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",i)],typeArguments:[b]})}return a}exports.Address=W;exports.DEFAULT_CACHE_TIME=w;exports.DEFAULT_MARKET_IDENTITY=D;exports.FlashLoanAssetConfig=Be;exports.IncentiveAPYInfo=_e;exports.IncentivePoolInfo=te;exports.IncentivePoolInfoByPhase=Te;exports.MARKETS=V;exports.Market=se;exports.OracleInfo=Ie;exports.PoolOperator=F;exports.ReserveDataInfo=Pe;exports.UserPositions=U;exports.UserStateInfo=oe;exports.borrowCoinPTB=Fe;exports.claimLendingRewardsPTB=ut;exports.createAccountCapPTB=le;exports.createEModeCapPTB=He;exports.depositCoinPTB=ce;exports.emodeIdentityId=We;exports.enterEModePTB=pe;exports.exitEModePTB=qe;exports.filterPriceFeeds=we;exports.flashloanPTB=ot;exports.getAccountCapOwnerPTB=ue;exports.getAllFlashLoanAssets=H;exports.getBorrowFee=Re;exports.getCoins=Ze;exports.getConfig=k;exports.getFees=De;exports.getFlashLoanAsset=tt;exports.getHealthFactor=Ke;exports.getHealthFactorPTB=de;exports.getLendingPositions=fe;exports.getLendingState=ze;exports.getMarket=Le;exports.getMarketConfig=_;exports.getMarkets=ie;exports.getPool=P;exports.getPools=R;exports.getPriceFeeds=Z;exports.getPythStalePriceFeedId=Xe;exports.getPythStalePriceFeedIdV2=ye;exports.getSimulatedHealthFactor=Ye;exports.getSimulatedHealthFactorPTB=J;exports.getStats=Ue;exports.getTransactions=Je;exports.getUserAvailableLendingRewards=ct;exports.getUserClaimedRewardHistory=lt;exports.getUserEModeCaps=Y;exports.getUserTotalClaimedReward=it;exports.liquidatePTB=rt;exports.mergeCoinsPTB=Ge;exports.normalizeCoinType=v;exports.parsePoolUID=ae;exports.parseTxValue=f;exports.repayCoinPTB=Ne;exports.repayFlashLoanPTB=nt;exports.summaryLendingRewards=st;exports.updateOraclePriceBeforeUserOperationPTB=et;exports.updateOraclePricesPTB=he;exports.updatePythPriceFeeds=be;exports.verifyHealthFactorPTB=Qe;exports.withCache=A;exports.withSingleton=T;exports.withdrawCoinPTB=Oe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("@mysten/sui/transactions"),m=require("@mysten/bcs"),Q=require("@mysten/sui/client"),ke=require("lodash.camelcase"),_e=require("@mysten/sui/utils"),K=require("@pythnetwork/pyth-sui-js"),p=require("bignumber.js"),_=require("@mysten/sui/bcs"),W=m.bcs.bytes(32).transform({input:e=>m.fromHex(e),output:e=>m.toHex(e)}),Te=m.bcs.struct("IncentiveAPYInfo",{asset_id:m.bcs.u8(),apy:m.bcs.u256(),coin_types:m.bcs.vector(m.bcs.string())}),te=m.bcs.struct("IncentivePoolInfo",{pool_id:W,funds:W,phase:m.bcs.u64(),start_at:m.bcs.u64(),end_at:m.bcs.u64(),closed_at:m.bcs.u64(),total_supply:m.bcs.u64(),asset_id:m.bcs.u8(),option:m.bcs.u8(),factor:m.bcs.u256(),distributed:m.bcs.u64(),available:m.bcs.u256(),total:m.bcs.u256()}),je=m.bcs.struct("IncentivePoolInfoByPhase",{phase:m.bcs.u64(),pools:m.bcs.vector(te)}),Ie=m.bcs.struct("OracleInfo",{oracle_id:m.bcs.u8(),price:m.bcs.u256(),decimals:m.bcs.u8(),valid:m.bcs.bool()}),Be=m.bcs.struct("FlashLoanAssetConfig",{id:m.bcs.string(),asset_id:m.bcs.u8(),coin_type:m.bcs.string(),pool_id:m.bcs.string(),rate_to_supplier:m.bcs.u64(),rate_to_treasury:m.bcs.u64(),max:m.bcs.u64(),min:m.bcs.u64()}),Pe=m.bcs.struct("ReserveDataInfo",{id:m.bcs.u8(),oracle_id:m.bcs.u8(),coin_type:m.bcs.string(),supply_cap:m.bcs.u256(),borrow_cap:m.bcs.u256(),supply_rate:m.bcs.u256(),borrow_rate:m.bcs.u256(),supply_index:m.bcs.u256(),borrow_index:m.bcs.u256(),total_supply:m.bcs.u256(),total_borrow:m.bcs.u256(),last_update_at:m.bcs.u64(),ltv:m.bcs.u256(),treasury_factor:m.bcs.u256(),treasury_balance:m.bcs.u256(),base_rate:m.bcs.u256(),multiplier:m.bcs.u256(),jump_rate_multiplier:m.bcs.u256(),reserve_factor:m.bcs.u256(),optimal_utilization:m.bcs.u256(),liquidation_ratio:m.bcs.u256(),liquidation_bonus:m.bcs.u256(),liquidation_threshold:m.bcs.u256()}),oe=m.bcs.struct("UserStateInfo",{asset_id:m.bcs.u8(),borrow_balance:m.bcs.u256(),supply_balance:m.bcs.u256()}),Ae="1.4.1-dev.1",M={version:Ae},Se=M.version,$e=()=>{if(typeof process<"u"&&process.versions&&process.versions.node)try{const e=require("os"),n=process.version,o=e.type(),r=e.arch();return`Node.js ${n.startsWith("v")?n.substring(1):n}; ${o}/${r}`}catch{return`Node.js ${process.version}; OS/Unknown (Error)`}return"Node/Unknown"},Me=()=>{let e="";return typeof process<"u"&&process.versions&&process.versions.node&&(e=`lending/${Se} (${$e()})`),e},X=Me(),S=new Q.SuiClient({url:Q.getFullnodeUrl("mainnet")});function ne(e){const n=[];return e.forEach((o,r)=>{const t=r===e.length-1;if(typeof o=="object"&&o!==null&&t){const{client:a,disableCache:i,cacheTime:c,...s}=o;n.push(s)}else n.push(o)}),JSON.stringify(n)}function j(e){const n={};return(...o)=>{const r=ne(o);return n[r]||(n[r]=e(...o).finally(()=>{delete n[r]})),n[r]}}function A(e){let n={};return(...o)=>{const r=o[o.length-1],t=ne(o),a=n[t];return!r?.disableCache&&typeof a?.data<"u"&&(typeof r?.cacheTime>"u"||r.cacheTime>Date.now()-a.cacheAt)?a.data:e(...o).then(i=>(n[t]={data:i,cacheAt:Date.now()},i))}}function G(e){return Array.isArray(e)?e.map(n=>G(n)):e!=null&&typeof e=="object"?Object.keys(e).reduce((n,o)=>({...n,[ke(o)]:G(e[o])}),{}):e}function g(e,n){return typeof e=="object"?e:n(e)}function Ve(e,n){return typeof n=="string"?e.object(n):typeof n=="object"&&n.$kind?n:e.object(n.contract.pool)}function q(e,n,o){if(e.results&&e.results.length>0){if(e.results[0].returnValues&&e.results[0].returnValues.length>0)return e.results[0].returnValues.map((r,t)=>(n[t]||n[0]).parse(Uint8Array.from(r[0])))}else if(e.error)return console.log(`Get an error, msg: ${e.error}`),[];return[]}function C(e){return _e.normalizeStructTag(e)}function re(e){const n=(e||0)/Math.pow(10,27);return n>Math.pow(10,5)?1/0:n}new K.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:2e4});const Ee=27,x=(e,n)=>{if(!Number(e)||!Number(n))return new p(0);const o=new p(1).shiftedBy(1*Ee),r=o.multipliedBy(new p(.5));return new p(e).multipliedBy(new p(n)).plus(r).dividedBy(o).integerValue(p.ROUND_DOWN)},E=X?{"User-Agent":X}:{};function z(e,n="uniqueId"){return e.reduce((o,r)=>(o[r[n]]=r,o),{})}function ee(e,n="uniqueId"){return e.reduce((o,r)=>(o[r[n]]=r,o),{})}function L(e,n){const o=e.emodes.find(t=>t.emodeId===n.emodeId);if(!o)throw new Error("EMode not found in pool");const r=o.assets.find(t=>t.assetId===e.id);return{...e,emode:{...r,emodeId:o.emodeId},isEMode:!0}}function ae(e){const[n,o]=e.split("-");return!n||!o?null:{marketKey:n,poolId:parseInt(o)}}function B(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}var F=(e=>(e[e.Supply=1]="Supply",e[e.Withdraw=2]="Withdraw",e[e.Borrow=3]="Borrow",e[e.Repay=4]="Repay",e))(F||{});const R=A(j(async e=>{const n=(e?.markets||[V.main]).map(t=>T(t)),o=`https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env||"prod"}&sdk=${M.version}&market=${n.map(t=>t.key)}`,r=await fetch(o,{headers:E}).then(t=>t.json());return r.data.forEach(t=>{const i=r.meta.emodes.filter(f=>{const v=T(f.marketId);return t.market===v.key&&f.isActive}).filter(f=>!!f.assets.find(v=>v.assetId===t.id));t.emodes=i;const c=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(),l=p(c).multipliedBy(t.oracle.price).toString(),d=p(s).multipliedBy(t.oracle.price).toString(),y=p(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals,p.ROUND_DOWN).toString(),h=p.max(p(t.borrowedAmount),p(t.validBorrowAmount)).shiftedBy(-9).decimalPlaces(t.token.decimals,p.ROUND_DOWN).toString(),b=p(y).multipliedBy(t.oracle.price).toString(),u=p(h).multipliedBy(t.oracle.price).toString();t.poolSupplyAmount=c,t.poolBorrowAmount=s,t.poolSupplyValue=l,t.poolBorrowValue=d,t.poolSupplyCapAmount=y,t.poolBorrowCapAmount=h,t.poolSupplyCapValue=b,t.poolBorrowCapValue=u}),r.data}));async function P(e,n){let o=n?.market;if(typeof e=="string"){const a=ae(e);a&&(o=a.marketKey,e=a.poolId)}const r=await R({...n,markets:[o||D],cacheTime:w});if(typeof e=="object")return e;const t=r.find(a=>typeof e=="string"?C(a.suiCoinType)===C(e):typeof e=="number"?a.id===e:!1);if(!t)throw new Error("Pool not found");return t.isDeprecated&&console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`),t}const Ue=A(j(async e=>{const n=`https://open-api.naviprotocol.io/api/navi/stats?sdk=${M.version}`;return(await fetch(n,{headers:E}).then(r=>r.json())).data})),De=A(j(async e=>{const n=`https://open-api.naviprotocol.io/api/navi/fee?sdk=${M.version}`;return await fetch(n,{headers:E}).then(r=>r.json())}));async function ce(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r);if(a?.deprecatedAt&&Date.now()>a.deprecatedAt)throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);const i=typeof o=="object"&&o.$kind==="GasCoin";if(C(a.suiCoinType)===C("0x2::sui::SUI")&&i){if(!r?.amount)throw new Error("Amount is required for sui coin");o=e.splitCoins(o,[r.amount])}let c;return typeof r?.amount<"u"?c=g(r.amount,e.pure.u64):c=e.moveCall({target:"0x2::coin::value",arguments:[g(o,e.object)],typeArguments:[a.suiCoinType]}),r?.accountCap?e.moveCall({target:`${t.package}::incentive_v3::deposit_with_account_cap`,arguments:[e.object("0x06"),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),g(o,e.object),e.object(t.incentiveV2),e.object(t.incentiveV3),g(r.accountCap,e.object)],typeArguments:[a.suiCoinType]}):e.moveCall({target:`${t.package}::incentive_v3::entry_deposit`,arguments:[e.object("0x06"),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),g(o,e.object),c,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]}),t.version===2&&a.id===0&&(!r?.env||r?.env==="prod")&&e.moveCall({target:`${t.package}::pool::refresh_stake`,arguments:[e.object(a.contract.pool),e.object("0x05")]}),e}async function Oe(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r),i=g(o,e.pure.u64);let c;if(t.version===1)if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw_with_account_cap`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3),g(r.accountCap,e.object)],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]});c=l}else if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw_with_account_cap_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3),g(r.accountCap,e.object),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::withdraw_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}return e.moveCall({target:"0x2::coin::from_balance",arguments:[c],typeArguments:[a.suiCoinType]})}async function Fe(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r);if(a?.deprecatedAt&&Date.now()>a.deprecatedAt)throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);const i=g(o,e.pure.u64);let c;if(t.version===1)if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow_with_account_cap`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3),g(r.accountCap,e.object)],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]});c=l}else if(r?.accountCap){const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow_with_account_cap_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3),g(r.accountCap,e.object),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}else{const[l]=e.moveCall({target:`${t.package}::incentive_v3::borrow_v2`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),i,e.object(t.incentiveV2),e.object(t.incentiveV3),e.object("0x05")],typeArguments:[a.suiCoinType]});c=l}return e.moveCall({target:"0x2::coin::from_balance",arguments:[e.object(c)],typeArguments:[a.suiCoinType]})}async function Ne(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r),i=typeof o=="object"&&o.$kind==="GasCoin";if(C(a.suiCoinType)===C("0x2::sui::SUI")&&i){if(!r?.amount)throw new Error("Amount is required for sui coin");o=e.splitCoins(o,[r.amount])}let c;if(typeof r?.amount<"u"?c=g(r.amount,e.pure.u64):c=e.moveCall({target:"0x2::coin::value",arguments:[g(o,e.object)],typeArguments:[a.suiCoinType]}),r?.accountCap){const[s]=e.moveCall({target:`${t.package}::incentive_v3::repay_with_account_cap`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),g(o,e.object),e.object(t.incentiveV2),e.object(t.incentiveV3),g(r.accountCap,e.object)],typeArguments:[a.suiCoinType]});return e.moveCall({target:"0x2::coin::from_balance",arguments:[s],typeArguments:[a.suiCoinType]})}else return e.moveCall({target:`${t.package}::incentive_v3::entry_repay`,arguments:[e.object("0x06"),e.object(t.priceOracle),e.object(t.storage),e.object(a.contract.pool),e.pure.u8(a.id),g(o,e.object),c,e.object(t.incentiveV2),e.object(t.incentiveV3)],typeArguments:[a.suiCoinType]}),e}const Re=A(j(async e=>{const n=await k({...e});if(e?.address&&typeof e?.asset<"u")try{const t=await P(e.asset,e),a=e?.client??S,i=new N.Transaction;i.moveCall({target:`${n.package}::incentive_v3::get_borrow_fee_v2`,arguments:[i.object(n.incentiveV3),i.pure.address(e.address),i.pure.u8(t.id),i.pure.u64(1e4)],typeArguments:[]});const c=await a.devInspectTransactionBlock({transactionBlock:i,sender:e.address}),s=q(c,[_.bcs.u64()]);return(Number(s[0])||0)/100}catch(t){console.error(t)}const r=(await S.getObject({id:n.incentiveV3,options:{showType:!0,showOwner:!0,showContent:!0}})).data.content.fields.borrow_fee_rate;return Number(r)/100})),D="main",V={main:{id:0,key:"main",name:"Main Market"}};class se{constructor(n,o){this.poolMap={},this.emodeMap={},this.pools=[],this.emodes=[],this.emodePools=[],this.emodeBorrowablePools=[],this.emodeSupplyablePools=[],this._overview={marketTotalSupplyValue:"0",marketTotalBorrowValue:"0"},this.config=T(n),this.initPools(o)}get overview(){return this._overview}initPools(n){const o=z(this.pools),r=ee(this.emodes),t=new Set,a=new Set;let i=p(0),c=p(0);n.forEach(s=>{if(!this.checkMarket(s.market)){console.warn(`Pool is not in market ${this.config.name}`,s);return}o[s.uniqueId]||this.pools.push(s),s?.emodes?.forEach(d=>{r[d.uniqueId]||this.emodes.push(d),d.assets.forEach(y=>{y.isDebt&&d.assets.find(b=>b.isCollateral&&b.ltv>0&&b.assetId!==s.id)&&t.add(s.uniqueId),y.isCollateral&&d.assets.find(b=>b.isDebt&&b.assetId!==s.id)&&a.add(s.uniqueId)})}),c=c.plus(s.poolBorrowValue),i=i.plus(s.poolSupplyValue)}),this.poolMap=z(this.pools,"id"),this.emodeMap=ee(this.emodes,"emodeId"),this.emodes.forEach(s=>{const l=this.getEModePools(s.emodeId);this.emodePools.push(...l)}),this._overview={marketTotalSupplyValue:i.toString(),marketTotalBorrowValue:c.toString()},this.emodeBorrowablePools=this.pools.filter(s=>t.has(s.uniqueId)),this.emodeSupplyablePools=this.pools.filter(s=>a.has(s.uniqueId))}getEMode(n){return this.emodeMap[n]||null}getEModeRelatePools(n,o){const{collateral:r,debt:t,emodeId:a}=o||{},i=[];return n.emodes.forEach(c=>{typeof a=="number"&&a!==c.emodeId||c.assets.forEach(s=>{typeof r=="boolean"&&r&&s.isCollateral&&s.assetId===n.id&&i.push(this.poolMap[s.assetId]),typeof t=="boolean"&&t&&s.isDebt&&s.assetId===n.id&&i.push(this.poolMap[s.assetId])})}),i}getEModePools(n){const o=this.getEMode(n);return o?o.assets.map(t=>t.assetId).map(t=>this.poolMap[t]).filter(t=>!!t).map(t=>{const a=o.assets.find(i=>i.assetId===t.id);return{...t,emode:{...a,emodeId:o.emodeId},isEMode:!0}}):[]}checkMarket(n){let o=!1;return typeof n=="number"&&n===this.config.id&&(o=!0),typeof n=="string"&&n===this.config.key&&(o=!0),typeof n=="object"&&n.id===this.config.id&&(o=!0),o}}const T=e=>{const o=Object.values(V).find(r=>typeof e=="number"?r.id===e:typeof e=="string"?r.key===e:r.id===e.id);if(!o)throw new Error("Market not found");return o},ie=A(j(async(e,n)=>{const o=await R({cacheTime:6e4,...n,markets:e});return e.map(r=>{const t=T(r),a=o.filter(i=>i.market===t.key);return new se(r,a)})})),Le=A(j(async(e,n)=>(await ie([e],n))[0])),k=A(j(async e=>{const n=T(e?.market||D),o=`https://open-api.naviprotocol.io/api/navi/config?env=${e?.env||"prod"}&sdk=${M.version}&market=${n.key}`;return(await fetch(o,{headers:E}).then(t=>t.json())).data})),w=1e3*60*5;async function le(e,n){const o=await k({cacheTime:w,...n});return e.moveCall({target:`${o.package}::lending::create_account`,arguments:[]})}async function ue(e,n,o){const r=await k({cacheTime:w,...o});return e.moveCall({target:`${r.package}::account::account_owner`,arguments:[n]})}async function pe(e,n,o){const r=await k({...o,cacheTime:w});return o?.accountCap?e.moveCall({target:`${r.package}::lending::enter_emode_with_account_cap`,arguments:[e.object(r.storage),g(n,e.pure.u64),g(o.accountCap,e.object)]}):e.moveCall({target:`${r.package}::lending::enter_emode`,arguments:[e.object(r.storage),g(n,e.pure.u64)]}),e}async function qe(e,n){const o=await k({...n,cacheTime:w});return n?.accountCap?e.moveCall({target:`${o.package}::lending::exit_emode_with_account_cap`,arguments:[e.object(o.storage),g(n.accountCap,e.object)]}):e.moveCall({target:`${o.package}::lending::exit_emode`,arguments:[e.object(o.storage)]}),e}async function He(e,n,o){const r=await k({cacheTime:w,...o}),t=await le(e,o);await pe(e,n,{...o,accountCap:t});const a=await T(o?.market||D),i=await ue(e,t,o);return e.moveCall({target:`${r.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,arguments:[e.object(r.emode.contract.registryObject),i,g(a.id,e.pure.u64),g(n,e.pure.u64)]}),t}const Y=A(j(async(e,n)=>{const o=await k({cacheTime:w,...n}),r=new N.Transaction,t=n?.client??S;r.moveCall({target:`${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,arguments:[r.object(o.emode.contract.registryObject),r.pure.address(e)]});const i=(await t.devInspectTransactionBlock({transactionBlock:r,sender:e})).results[0].returnValues,c=_.bcs.vector(_.bcs.u64()).parse(Uint8Array.from(i[0][0])),s=_.bcs.vector(_.bcs.u64()).parse(Uint8Array.from(i[1][0])),l=_.bcs.vector(_.bcs.Address).parse(Uint8Array.from(i[2][0]));return c.map((d,y)=>({marketId:Number(d),emodeId:Number(s[y]),accountCap:l[y].toString()}))}));function We(e){return`${T(e.marketId).key}-${e.emodeId}`}function Ge(e,n,o){const r=typeof o?.balance=="number",t=r?o.balance:0;let a=0;const i=[];let c="";if(n.sort((s,l)=>Number(l.balance)-Number(s.balance)).forEach(s=>{if(!(r&&a>=t)&&Number(s.balance)!==0){if(c||(c=s.coinType),c!==s.coinType)throw new Error("All coins must be of the same type");a+=Number(s.balance),i.push(s.coinObjectId)}}),i.length===0)throw new Error("No coins to merge");if(r&&a<t)throw new Error(`Balance is less than the specified balance: ${a} < ${t}`);return C(c)===C("0x2::sui::SUI")&&o?.useGasCoin?r?e.splitCoins(e.gas,[e.pure.u64(t)]):e.gas:(i.length===1?e.object(i[0]):e.mergeCoins(i[0],i.slice(1)),r?e.splitCoins(i[0],[e.pure.u64(t)]):i[0])}async function J(e,n,o,r,t,a,i){const c=await k({...i,cacheTime:w}),s=await P(o,i);return e.moveCall({target:`${c.uiGetter}::calculator_unchecked::dynamic_health_factor`,arguments:[e.object("0x06"),e.object(c.storage),e.object(c.oracle.priceOracle),Ve(e,s),g(n,e.pure.address),g(s.id,e.pure.u8),g(r,e.pure.u64),g(t,e.pure.u64),g(a,e.pure.bool)],typeArguments:[s.suiCoinType]})}async function de(e,n,o){return J(e,n,0,0,0,!1,o)}async function me(e,n,o){const r=new N.Transaction,t=o?.client??S,a=await R({...o,markets:Object.values(V)}),i=z(a);for(let d of n){const y=await k({...o,cacheTime:w,market:d.market});r.moveCall({target:`${y.uiGetter}::getter_unchecked::get_user_state`,arguments:[r.object(y.storage),r.pure.address(d.address)]})}const s=((await t.devInspectTransactionBlock({transactionBlock:r,sender:e})).results||[]).map(d=>d.returnValues?.map(y=>_.bcs.vector(oe).parse(Uint8Array.from(y[0])))[0]||[]),l=[];return s.forEach((d,y)=>{const h=n[y],b=T(h.market);d.forEach(u=>{if(u.supply_balance==="0"&&u.borrow_balance==="0"&&(h.emodeId===void 0||!o?.includeZeroBalanceEmodePositions))return;const f=i[`${b.key}-${u.asset_id}`];if(!f)return;const v=x(u.supply_balance,f.currentSupplyIndex).toString(),I=x(u.borrow_balance,f.currentBorrowIndex).toString();l.push({supplyBalance:v,borrowBalance:I,assetId:u.asset_id,market:b.key,pool:f,emodeId:h.emodeId})})}),l}const ze=A(async(e,n)=>{const r=(n?.markets||Object.keys(V)).map(t=>T(t)).map(t=>({address:e,market:t.key}));return await me(e,r,n)});async function Ke(e,n){const o=n?.client??S,r=new N.Transaction;await de(r,e,n);const t=await o.devInspectTransactionBlock({transactionBlock:r,sender:e}),a=q(t,[_.bcs.u256()]);return re(Number(a[0])||0)}async function Ye(e,n,o,r){const t=r?.client??S,a=new N.Transaction;let i=0,c=0;const s=await P(n,r);if(o.forEach(h=>{h.type===F.Supply?i+=h.amount:h.type===F.Withdraw?i-=h.amount:h.type===F.Borrow?c+=h.amount:h.type===F.Repay&&(c-=h.amount)}),i*c<0)throw new Error("Invalid operations");const l=i>0||c>0;await J(a,e,s,Math.abs(i),Math.abs(c),l,r);const d=await t.devInspectTransactionBlock({transactionBlock:a,sender:e}),y=q(d,[_.bcs.u256()]);return re(Number(y[0])||0)}const Je=j(async(e,n)=>{const o=new URLSearchParams;n?.cursor&&o.set("cursor",n.cursor),o.set("userAddress",e);const r=`https://open-api.naviprotocol.io/api/navi/user/transactions?${o.toString()}&sdk=${M.version}`;return(await fetch(r,{headers:E}).then(a=>a.json())).data});async function Ze(e,n){let o=null;const r=[],t=n?.client??S;do{let a;if(n?.coinType?a=await t.getCoins({owner:e,coinType:n?.coinType,cursor:o,limit:100}):a=await t.getAllCoins({owner:e,cursor:o,limit:100}),!a.data||!a.data.length)break;r.push(...a.data),o=a.nextCursor}while(o);return r}const fe=A(async(e,n)=>{const o=[],r=(n?.markets||Object.keys(V)).map(c=>T(c));let t=[];try{t=await Y(e,n)}catch(c){console.error(c)}const a=r.map(c=>({address:e,market:c.key})).concat(t.filter(c=>!!r.find(s=>s.id===c.marketId)).map(c=>({address:c.accountCap,market:T(c.marketId).key,emodeId:c.emodeId})));return(await me(e,a,n)).forEach(c=>{const s=typeof c.emodeId=="number"?t.find(l=>{const d=T(c.market);return l.emodeId===c.emodeId&&l.marketId===d.id}):void 0;if(s){if(!c.pool.emodes.find(d=>d.emodeId===s.emodeId))return;if(p(c.supplyBalance).gte(0)){const d=p(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN),y=L(c.pool,s);if(d.gt(0)||y.emode.isCollateral)try{o.push({id:`${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${B()}`,wallet:e,protocol:"navi",market:c.market,type:"navi-lending-emode-supply","navi-lending-emode-supply":{amount:d.toString(),pool:L(c.pool,s),token:c.pool.token,valueUSD:d.multipliedBy(c.pool.oracle.price).toString(),emodeCap:s}})}catch(h){console.error(h)}}if(p(c.borrowBalance).gte(0)){const d=p(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN),y=L(c.pool,s);if(d.gt(0)||y.emode.isDebt)try{o.push({id:`${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${B()}`,wallet:e,protocol:"navi",market:c.market,type:"navi-lending-emode-borrow","navi-lending-emode-borrow":{amount:d.toString(),pool:L(c.pool,s),token:c.pool.token,valueUSD:d.multipliedBy(c.pool.oracle.price).toString(),emodeCap:s}})}catch(h){console.error(h)}}}else{if(p(c.supplyBalance).gt(0)){const l=p(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN);o.push({id:`${c.pool.uniqueId}_navi-lending-supply-${B()}`,wallet:e,protocol:"navi",type:"navi-lending-supply",market:c.market,"navi-lending-supply":{amount:l.toString(),pool:c.pool,token:c.pool.token,valueUSD:l.multipliedBy(c.pool.oracle.price).toString()}})}if(p(c.borrowBalance).gt(0)){const l=p(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals,p.ROUND_DOWN);o.push({id:`${c.pool.uniqueId}_navi-lending-borrow-${B()}`,wallet:e,protocol:"navi",market:c.market,type:"navi-lending-borrow","navi-lending-borrow":{amount:l.toString(),pool:c.pool,token:c.pool.token,valueUSD:l.multipliedBy(c.pool.oracle.price).toString()}})}}}),o});class U{constructor(n,o){this._positions=[],this._priceMap={},this._overview={hf:1/0,netVaule:"0",netWorthApr:"0",totalSupplyValue:"0",totalBorrowValue:"0",totalsupplyApy:"0",totalBorrowApy:"0",maxLiquidationValue:"0",maxLoanToVaule:"0",supply:{},borrow:{}},this._priceMap=o||{},this.positions=n}get positions(){return this._positions}get overview(){return this._overview}get priceMap(){return this._priceMap}set positions(n){this._positions=n,this._overview=this.getPositionsOverview(n)}updatePriceMap(n){return this._priceMap=n,this._overview=this.getPositionsOverview(this._positions),this}getPrice(n){const o=C(n.suiCoinType);if(this._priceMap[o]!==void 0)return this._priceMap[o].toString();const r=n.suiCoinType;return this._priceMap[r]!==void 0?this._priceMap[r].toString():n.oracle.price}filterPositionsByPool(n){const r=!!n.isEMode?["navi-lending-emode-supply","navi-lending-emode-borrow"]:["navi-lending-supply","navi-lending-borrow"];return new U(this.positions.filter(t=>{const a=t[t.type];return r.includes(t.type)&&a.pool.uniqueId===n.uniqueId}),this._priceMap)}deposit(n,o){const r=!!n.isEMode,t=this.getPrice(n);let a;return r?a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-supply","navi-lending-emode-supply":{amount:o.toString(),valueUSD:p(o).multipliedBy(t).toString(),token:n.token,pool:n,emodeCap:{}}}:a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-supply","navi-lending-supply":{amount:o.toString(),valueUSD:p(o).multipliedBy(t).toString(),token:n.token,pool:n}},new U([...this.positions,a],this._priceMap)}withdraw(n,o){const r=!!n.isEMode,t=this.getPrice(n);let a;return r?a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-supply","navi-lending-emode-supply":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(t).toString(),token:n.token,pool:n,emodeCap:{}}}:a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-supply","navi-lending-supply":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(t).toString(),token:n.token,pool:n}},new U([...this.positions,a],this._priceMap)}borrow(n,o){const r=!!n.isEMode,t=this.getPrice(n);let a;return r?a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-borrow","navi-lending-emode-borrow":{amount:o.toString(),valueUSD:p(o).multipliedBy(t).toString(),token:n.token,pool:n,emodeCap:{}}}:a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-borrow","navi-lending-borrow":{amount:o.toString(),valueUSD:p(o).multipliedBy(t).toString(),token:n.token,pool:n}},new U([...this.positions,a],this._priceMap)}repay(n,o){const r=!!n.isEMode,t=this.getPrice(n);let a;return r?a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-emode-borrow","navi-lending-emode-borrow":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(t).toString(),token:n.token,pool:n,emodeCap:{}}}:a={id:B(),wallet:"",protocol:"navi",market:"",type:"navi-lending-borrow","navi-lending-borrow":{amount:(-o).toString(),valueUSD:p(-o).multipliedBy(t).toString(),token:n.token,pool:n}},new U([...this.positions,a],this._priceMap)}resolveValueUSD(n){return Object.keys(this._priceMap).length>0?p(n.amount).multipliedBy(this.getPrice(n.pool)).toString():n.valueUSD}getPositionsOverview(n){const o={},r={};let t=new p(0),a=new p(0),i=new p(0),c=new p(0),s=new p(0),l=new p(0);n.forEach(b=>{if(b.type==="navi-lending-supply"){const u=b["navi-lending-supply"],f=this.resolveValueUSD(u);t=t.plus(f),s=s.plus(new p(f).multipliedBy(u.pool.liquidationFactor.threshold)),l=l.plus(new p(f).multipliedBy(u.pool.ltvValue))}else if(b.type==="navi-lending-borrow"){const u=b["navi-lending-borrow"];a=a.plus(this.resolveValueUSD(u))}else if(b.type==="navi-lending-emode-supply"){const u=b["navi-lending-emode-supply"],f=this.resolveValueUSD(u);t=t.plus(f);const v=u.pool.emode;s=s.plus(new p(f).multipliedBy(v.lt)),l=l.plus(new p(f).multipliedBy(v.ltv))}else if(b.type==="navi-lending-emode-borrow"){const u=b["navi-lending-emode-borrow"];a=a.plus(this.resolveValueUSD(u))}}),a=p.max(a,0),t=p.max(t,0),s=p.max(s,0),l=p.max(l,0),n.forEach(b=>{if(b.type==="navi-lending-supply"){const u=b["navi-lending-supply"],f=this.resolveValueUSD(u),v=u.pool.supplyIncentiveApyInfo.apy;t.gt(0)&&(i=i.plus(new p(f).dividedBy(t).multipliedBy(new p(v).dividedBy(100)))),o[u.pool.suiCoinType]=p(o[u.pool.suiCoinType]||0).plus(u.amount).toString()}else if(b.type==="navi-lending-borrow"){const u=b["navi-lending-borrow"],f=this.resolveValueUSD(u),v=u.pool.borrowIncentiveApyInfo.apy;a.gt(0)&&(c=c.plus(new p(f).dividedBy(a).multipliedBy(new p(v).dividedBy(100)))),r[u.pool.suiCoinType]=p(r[u.pool.suiCoinType]||0).plus(u.amount).toString()}else if(b.type==="navi-lending-emode-supply"){const u=b["navi-lending-emode-supply"],f=this.resolveValueUSD(u),v=u.pool.supplyIncentiveApyInfo.apy;t.gt(0)&&(i=i.plus(new p(f).dividedBy(t).multipliedBy(new p(v).dividedBy(100)))),o[u.pool.suiCoinType]=p(o[u.pool.suiCoinType]||0).plus(u.amount).toString()}else if(b.type==="navi-lending-emode-borrow"){const u=b["navi-lending-emode-borrow"],f=this.resolveValueUSD(u),v=u.pool.borrowIncentiveApyInfo.apy;a.gt(0)&&(c=c.plus(new p(f).dividedBy(a).multipliedBy(new p(v).dividedBy(100)))),r[u.pool.suiCoinType]=p(r[u.pool.suiCoinType]||0).plus(u.amount).toString()}});const d=t.minus(a),y=t.minus(a).eq(0)?new p(0):t.multipliedBy(i).minus(a.multipliedBy(c)).div(t.minus(a));return{hf:a.toNumber()!==0?s.dividedBy(a).toNumber():1/0,netVaule:d.toString(),netWorthApr:y.toString(),totalSupplyValue:t.toString(),totalBorrowValue:a.toString(),totalsupplyApy:i.toString(),totalBorrowApy:c.toString(),maxLiquidationValue:s.toString(),maxLoanToVaule:l.toString(),supply:o,borrow:r}}}async function Qe(e,n,o,r){const t=await k({...r,cacheTime:w});t.limter&&e.moveCall({target:`${t.limter}::navi_adaptor::verify_navi_position_healthy`,arguments:[e.object("0x06"),e.object(t.storage),e.object(t.priceOracle),g(n,e.pure.address),e.pure.u256(new p(o).shiftedBy(27).toNumber())]})}const ge=new K.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:1e4});async function Xe(e){try{const n=[],o=await ge.getLatestPriceFeeds(e);if(!o)return n;const r=Math.floor(new Date().valueOf()/1e3);for(const t of o){const a=t.getPriceUnchecked();if(a.publishTime>r){console.warn(`pyth price feed is invalid, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`);continue}r-t.getPriceUnchecked().publishTime>30&&(console.info(`stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`),n.push(t.id))}return n}catch(n){throw new Error(`failed to get pyth stale price feed id, msg: ${n.message}`)}}async function xe(e,n){try{const o=[],r=n?.client??S,t=e.map(i=>i.priceInfoObject),a=await r.multiGetObjects({ids:Array.from(new Set(t)),options:{showContent:!0}});for(const i of a){const c=i.data;if(!c||!c.content||c.content.dataType!=="moveObject"){console.warn(`fetched object ${c?.objectId} datatype should be moveObject`);continue}const s=e.find(u=>u.priceInfoObject==c.objectId);if(!s){console.warn(`unable to find pyth info from array, priceInfoObject: ${c.objectId}`);continue}const l=c.content.fields.price_info.fields.price_feed.fields.price.fields,{magnitude:d,negative:y}=l.price.fields,h=l.conf,b=l.timestamp;o.push({priceFeedId:s.priceFeedId,priceInfoObject:s.priceInfoObject,price:y?"-"+d:d,conf:h,publishTime:Number(b),expiration:s.expiration})}return o}catch(o){console.error(o,`Polling Sui on-chain price for ${e} failed.`);return}}async function ye(e,n){try{const o=[],r=await xe(e,n);if(!r)return o;const t=Math.floor(new Date().valueOf()/1e3);for(const a of r){if(a.publishTime>t){console.warn(`pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`);continue}const i=a.expiration||60;t-a.publishTime>i&&(console.info(`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`),o.push(a.priceFeedId))}return o}catch(o){throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`)}}async function be(e,n,o){const r=o?.client??S,t=await k({...o,cacheTime:w});try{const a=await ge.getPriceFeedsUpdateData(n);return await new K.SuiPythClient(r,t.oracle.pythStateId,t.oracle.wormholeStateId).updatePriceFeeds(e,a,n)}catch(a){throw new Error(`failed to update pyth price feeds, msg: ${a.message}`)}}async function he(e,n,o){const r=await k({...o,cacheTime:w});if(o?.updatePythPriceFeeds){const t=n.filter(a=>!!a.pythPriceFeedId&&!!a.pythPriceInfoObject).map(a=>({priceFeedId:a.pythPriceFeedId,priceInfoObject:a.pythPriceInfoObject,expiration:30}));try{const a=await ye(t,o);a.length>0&&await be(e,a,o)}catch{console.error("Failed to update Pyth price feeds")}}for(const t of n)o?.env==="dev"?e.moveCall({target:`${r.oracle.packageId}::oracle_pro::update_single_price`,arguments:[e.object("0x6"),e.object(r.oracle.oracleConfig),e.object(r.oracle.priceOracle),e.object(r.oracle.supraOracleHolder),e.object(t.pythPriceInfoObject),e.pure.address(t.feedId)]}):e.moveCall({target:`${r.oracle.packageId}::oracle_pro::update_single_price_v2`,arguments:[e.object("0x6"),e.object(r.oracle.oracleConfig),e.object(r.oracle.priceOracle),e.object(r.oracle.supraOracleHolder),e.object(t.pythPriceInfoObject),e.object(r.oracle.switchboardAggregator),e.pure.address(t.feedId)]});return e}async function Z(e){return(await k({...e,cacheTime:w})).oracle.feeds}function ve(e,n){return e.filter(o=>!!(n?.lendingState&&n.lendingState.find(t=>t.assetId===o.assetId)||n?.lendingPositions&&n.lendingPositions.find(t=>["navi-lending-supply","navi-lending-borrow","navi-lending-emode-supply","navi-lending-emode-borrow"].includes(t.type)?t[t.type]?.pool?.id===o.assetId:!1)||n?.pools&&n.pools.find(t=>t.id===o.assetId)))}async function et(e,n,o,r){try{const t=await Z({...r}),a=[];o.forEach(l=>{a.includes(l.market)||a.push(l.market)});const i=await fe(n,{...r,markets:a}),c=ve(t,{lendingPositions:i,pools:o});return await he(e,c,{updatePythPriceFeeds:!0,...r})}catch(t){if(r?.throws)throw t;return console.error(t),e}}const H=A(j(async e=>{const n=`https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env||"prod"}&sdk=${M.version}&market=${e?.market||D}`,o=await fetch(n,{headers:E}).then(r=>r.json());return Object.keys(o.data).map(r=>({...o.data[r],coinType:r}))}));async function tt(e,n){return(await H(n)).find(r=>typeof e=="string"?C(r.coinType)===C(e):typeof e=="number"?r.assetId===e:r.assetId===e.id)||null}async function ot(e,n,o,r){const t=await k({...r,cacheTime:w}),a=await P(n,r);if(!(await H({...r,cacheTime:w})).some(s=>C(s.coinType)===C(a.suiCoinType)))throw new Error("Pool does not support flashloan");if(t.version===1){const[s,l]=e.moveCall({target:`${t.package}::lending::flash_loan_with_ctx`,arguments:[e.object(t.flashloanConfig),e.object(a.contract.pool),g(o,e.pure.u64)],typeArguments:[a.suiCoinType]});return[s,l]}else{const[s,l]=e.moveCall({target:`${t.package}::lending::flash_loan_with_ctx_v2`,arguments:[e.object(t.flashloanConfig),e.object(a.contract.pool),g(o,e.pure.u64),e.object("0x05")],typeArguments:[a.suiCoinType]});return[s,l]}}async function nt(e,n,o,r,t){const a=await k({...t,cacheTime:w}),i=await P(n,t);if(!(await H({...t,cacheTime:w})).some(d=>C(d.coinType)===C(i.suiCoinType)))throw new Error("Pool does not support flashloan");const[l]=e.moveCall({target:`${a.package}::lending::flash_repay_with_ctx`,arguments:[e.object("0x06"),e.object(a.storage),e.object(i.contract.pool),g(o,e.object),g(r,e.object)],typeArguments:[i.suiCoinType]});return[l]}async function rt(e,n,o,r,t,a){const i={...a,cacheTime:w},c=await k(i),s=await P(n,i),l=await P(r,i);if(c.version===1){const[d,y]=e.moveCall({target:`${c.package}::incentive_v3::liquidation`,arguments:[e.object("0x06"),e.object(c.priceOracle),e.object(c.storage),e.pure.u8(s.id),e.object(s.contract.pool),g(o,e.object),e.pure.u8(l.id),e.object(l.contract.pool),g(t,e.pure.address),e.object(c.incentiveV2),e.object(c.incentiveV3)],typeArguments:[s.suiCoinType,l.suiCoinType]});return[d,y]}else{const[d,y]=e.moveCall({target:`${c.package}::incentive_v3::liquidation_v2`,arguments:[e.object("0x06"),e.object(c.priceOracle),e.object(c.storage),e.pure.u8(s.id),e.object(s.contract.pool),g(o,e.object),e.pure.u8(l.id),e.object(l.contract.pool),g(t,e.pure.address),e.object(c.incentiveV2),e.object(c.incentiveV3),e.object("0x05")],typeArguments:[s.suiCoinType,l.suiCoinType]});return[d,y]}}async function at(e,n,o){const r=o?.client??S,t=new N.Transaction,a=await R({...o,markets:Object.values(V),cacheTime:w}),i=await Z(o);for(let d of n){const y=await k({...o,cacheTime:w,market:d.market});t.moveCall({target:`${y.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,arguments:[t.object("0x06"),t.object(y.storage),t.object(y.incentiveV3),t.pure.address(d.address)]})}const c=await r.devInspectTransactionBlock({transactionBlock:t,sender:e}),s=[];c?.results?.forEach(d=>{s.push(q({results:[d]},[_.bcs.vector(_.bcs.string()),_.bcs.vector(_.bcs.string()),_.bcs.vector(_.bcs.u8()),_.bcs.vector(_.bcs.Address),_.bcs.vector(_.bcs.u256())]))});const l=[];return s.forEach((d,y)=>{const h=n[y];if(d.length===5&&Array.isArray(d[0])){const b=d[0].length;for(let u=0;u<b;u++){const f=i.find(I=>C(I.coinType)===C(d[1][u])),v=a.find(I=>C(I.coinType)===C(d[0][u])&&I.market===h.market);!f||!v||l.push({assetId:v.id,assetCoinType:C(d[0][u]),rewardCoinType:C(d[1][u]),option:Number(d[2][u]),userClaimableReward:Number(d[4][u])/Math.pow(10,f.priceDecimal),ruleIds:Array.isArray(d[3][u])?d[3][u]:[d[3][u]],market:h.market,owner:h.owner,address:h.address,emodeId:h.emodeId})}}}),l}async function ct(e,n){const o=(n?.markets||[V.main]).map(a=>T(a));let r=[];try{r=await Y(e,n)}catch(a){console.error(a)}const t=o.map(a=>({address:e,owner:e,market:a.key})).concat(r.filter(a=>!!o.find(i=>i.id===a.marketId)).map(a=>{const i=T(a.marketId);return{address:a.accountCap,owner:e,market:i.key,emodeId:a.emodeId}}));return await at(e,t,n)}function st(e){const n=new Map;e.forEach(r=>{const t=r.assetId,a=r.option,i=`${t}-${a}-${r.rewardCoinType}-${r.market}`;n.has(i)?n.get(i).total+=r.userClaimableReward:n.set(i,{assetId:t,rewardType:a,coinType:r.rewardCoinType,total:Number(r.userClaimableReward),market:r.market})});const o=new Map;for(const{assetId:r,rewardType:t,coinType:a,total:i,market:c}of n.values()){const s=`${r}-${t}-${c}`;o.has(s)||o.set(s,{assetId:r,rewardType:t,market:c,rewards:new Map});const l=o.get(s);l.rewards.set(a,(l.rewards.get(a)||0)+i)}return Array.from(o.values()).map(r=>({assetId:r.assetId,rewardType:r.rewardType,market:r.market,rewards:Array.from(r.rewards.entries()).map(([t,a])=>({coinType:t,available:a.toFixed(6)}))}))}const it=j(async(e,n)=>{const o=`https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${M.version}&market=${n?.market||D}`;return(await fetch(o,{headers:E}).then(t=>t.json())).data}),lt=j(async(e,n)=>{const o=`https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${n?.page||1}&pageSize=${n?.size||400}&sdk=${M.version}&market=${n?.market||D}`,r=await fetch(o,{headers:E}).then(t=>t.json());return G({data:r.data.rewards})});async function ut(e,n,o){const r=await R({...o,markets:Object.values(V),cacheTime:w}),t=new Map;for(const i of n){const{rewardCoinType:c,ruleIds:s,market:l,owner:d,address:y,emodeId:h}=i,b=`${c}___${y}`;for(const u of s){t.has(b)||t.set(b,{assetIds:[],ruleIds:[],amount:0,market:l,owner:d,address:y,isEMode:typeof h<"u"});const f=t.get(b);f.assetIds.push(i.assetCoinType.replace("0x","")),f.ruleIds.push(u),f.amount+=i.userClaimableReward}}const a=[];for(const[i,{assetIds:c,ruleIds:s,amount:l,market:d,owner:y,address:h,isEMode:b}]of t){const u=await k({...o,cacheTime:w,market:d}),f=i.split("___")[0],v=r.find($=>C($.suiCoinType)===C(f)&&$.market===d);if(!v||!v.contract.rewardFundId)throw new Error(`No matching rewardFund found for reward coin: ${f} ${d}`);const I=v.contract.rewardFundId;if(o?.accountCap&&!o.customCoinReceive)throw new Error("customCoinReceive is required when accountCap is provided");if(o?.customCoinReceive){let $;o.accountCap?$=e.moveCall({target:`${u.package}::incentive_v3::claim_reward_with_account_cap`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",s),g(o.accountCap,e.object)],typeArguments:[f]}):b?$=e.moveCall({target:`${u.package}::incentive_v3::claim_reward_with_account_cap`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",s),g(h,e.object)],typeArguments:[f]}):$=e.moveCall({target:`${u.package}::incentive_v3::claim_reward`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",s)],typeArguments:[f]});const[O]=e.moveCall({target:"0x2::coin::from_balance",arguments:[$],typeArguments:[f]});if(o?.customCoinReceive.type==="transfer"){if(!o.customCoinReceive.transfer)throw new Error("customCoinReceive.transfer is required");e.transferObjects([O],g(o.customCoinReceive.transfer,e.pure.address))}if(o?.customCoinReceive.type==="depositNAVI"){const we=p(v.totalSupplyAmount).shiftedBy(-9),Ce=p(v.supplyCapCeiling).shiftedBy(-27);we.plus(l).isGreaterThan(Ce)&&o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress?e.transferObjects([O],e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)):await ce(e,v,O,o)}else a.push({coin:O,identifier:v,owner:y,isEMode:b})}else if(o?.accountCap||b){const $=e.moveCall({target:`${u.package}::incentive_v3::claim_reward_with_account_cap`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",s),g(o?.accountCap||h,e.object)],typeArguments:[f]}),[O]=e.moveCall({target:"0x2::coin::from_balance",arguments:[$],typeArguments:[f]});e.transferObjects([O],g(o?.accountCap||y,e.pure.address))}else e.moveCall({target:`${u.package}::incentive_v3::claim_reward_entry`,arguments:[e.object("0x06"),e.object(u.incentiveV3),e.object(u.storage),e.object(I),e.pure.vector("string",c),e.pure.vector("address",s)],typeArguments:[f]})}return a}exports.Address=W;exports.DEFAULT_CACHE_TIME=w;exports.DEFAULT_MARKET_IDENTITY=D;exports.FlashLoanAssetConfig=Be;exports.IncentiveAPYInfo=Te;exports.IncentivePoolInfo=te;exports.IncentivePoolInfoByPhase=je;exports.MARKETS=V;exports.Market=se;exports.OracleInfo=Ie;exports.PoolOperator=F;exports.ReserveDataInfo=Pe;exports.UserPositions=U;exports.UserStateInfo=oe;exports.borrowCoinPTB=Fe;exports.claimLendingRewardsPTB=ut;exports.createAccountCapPTB=le;exports.createEModeCapPTB=He;exports.depositCoinPTB=ce;exports.emodeIdentityId=We;exports.enterEModePTB=pe;exports.exitEModePTB=qe;exports.filterPriceFeeds=ve;exports.flashloanPTB=ot;exports.getAccountCapOwnerPTB=ue;exports.getAllFlashLoanAssets=H;exports.getBorrowFee=Re;exports.getCoins=Ze;exports.getConfig=k;exports.getFees=De;exports.getFlashLoanAsset=tt;exports.getHealthFactor=Ke;exports.getHealthFactorPTB=de;exports.getLendingPositions=fe;exports.getLendingState=ze;exports.getMarket=Le;exports.getMarketConfig=T;exports.getMarkets=ie;exports.getPool=P;exports.getPools=R;exports.getPriceFeeds=Z;exports.getPythStalePriceFeedId=Xe;exports.getPythStalePriceFeedIdV2=ye;exports.getSimulatedHealthFactor=Ye;exports.getSimulatedHealthFactorPTB=J;exports.getStats=Ue;exports.getTransactions=Je;exports.getUserAvailableLendingRewards=ct;exports.getUserClaimedRewardHistory=lt;exports.getUserEModeCaps=Y;exports.getUserTotalClaimedReward=it;exports.liquidatePTB=rt;exports.mergeCoinsPTB=Ge;exports.normalizeCoinType=C;exports.parsePoolUID=ae;exports.parseTxValue=g;exports.repayCoinPTB=Ne;exports.repayFlashLoanPTB=nt;exports.summaryLendingRewards=st;exports.updateOraclePriceBeforeUserOperationPTB=et;exports.updateOraclePricesPTB=he;exports.updatePythPriceFeeds=be;exports.verifyHealthFactorPTB=Qe;exports.withCache=A;exports.withSingleton=j;exports.withdrawCoinPTB=Oe;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|