@naviprotocol/wallet-client 2.0.6 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/client.d.ts +3 -3
  2. package/dist/client.js +160 -0
  3. package/dist/client.js.map +1 -0
  4. package/dist/index.d.ts +3 -3
  5. package/dist/index.js +8 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/modules/balanceModule/index.d.ts +4 -4
  8. package/dist/modules/balanceModule/index.js +214 -0
  9. package/dist/modules/balanceModule/index.js.map +1 -0
  10. package/dist/modules/balanceModule/portfolio.js +105 -0
  11. package/dist/modules/balanceModule/portfolio.js.map +1 -0
  12. package/dist/modules/haedalModule/index.d.ts +2 -2
  13. package/dist/modules/haedalModule/index.js +114 -0
  14. package/dist/modules/haedalModule/index.js.map +1 -0
  15. package/dist/modules/index.d.ts +5 -5
  16. package/dist/modules/index.js +21 -0
  17. package/dist/modules/index.js.map +1 -0
  18. package/dist/modules/lendingModule/index.d.ts +5 -5
  19. package/dist/modules/lendingModule/index.js +410 -0
  20. package/dist/modules/lendingModule/index.js.map +1 -0
  21. package/dist/modules/lendingModule/migrate.js +225 -0
  22. package/dist/modules/lendingModule/migrate.js.map +1 -0
  23. package/dist/modules/lendingModule/protocols/navi.d.ts +1 -1
  24. package/dist/modules/lendingModule/protocols/navi.js +37 -0
  25. package/dist/modules/lendingModule/protocols/navi.js.map +1 -0
  26. package/dist/modules/lendingModule/protocols/suilend.d.ts +1 -1
  27. package/dist/{suilend-CWugUjwd.js → modules/lendingModule/protocols/suilend.js} +1 -1
  28. package/dist/{suilend-CWugUjwd.js.map → modules/lendingModule/protocols/suilend.js.map} +1 -1
  29. package/dist/modules/module.d.ts +1 -1
  30. package/dist/modules/module.js +46 -0
  31. package/dist/modules/module.js.map +1 -0
  32. package/dist/modules/swapModule/index.d.ts +2 -2
  33. package/dist/modules/swapModule/index.js +159 -0
  34. package/dist/modules/swapModule/index.js.map +1 -0
  35. package/dist/modules/voloModule/index.d.ts +2 -2
  36. package/dist/modules/voloModule/index.js +128 -0
  37. package/dist/modules/voloModule/index.js.map +1 -0
  38. package/dist/signer.d.ts +1 -1
  39. package/dist/signer.js +102 -0
  40. package/dist/signer.js.map +1 -0
  41. package/dist/transaction-result.d.ts +1 -1
  42. package/dist/transaction-result.js +59 -0
  43. package/dist/transaction-result.js.map +1 -0
  44. package/package.json +7 -7
  45. package/dist/index.esm.js +0 -1686
  46. package/dist/index.esm.js.map +0 -1
@@ -0,0 +1,114 @@
1
+ import { isSuccessfulTransaction as o } from "../../transaction-result.js";
2
+ import { withCache as u, withSingleton as f, resolveNaviOpenApiEndpoint as h, buildNaviOpenApiUrl as g, mergeServiceHeaders as p, parseTxValue as r, mergeCoinsPTB as l } from "@naviprotocol/lending";
3
+ import { Transaction as d } from "@mysten/sui/transactions";
4
+ import { Module as w } from "../module.js";
5
+ class T extends w {
6
+ constructor() {
7
+ super(...arguments), this.name = "haedal", this.defaultConfig = {
8
+ packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
9
+ configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
10
+ coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
11
+ }, this.getApyCached = u(
12
+ f(async (e) => {
13
+ const a = { services: e?.services }, t = h(a);
14
+ return (await fetch(g("/haedal/stats", a), {
15
+ headers: p({}, t)
16
+ }).then((n) => n.json())).data.apy;
17
+ })
18
+ );
19
+ }
20
+ getApy(e) {
21
+ return this.getApyCached({
22
+ services: e?.services ?? this.config.services
23
+ });
24
+ }
25
+ /**
26
+ * Builds a transaction block for staking SUI to haSUI
27
+ *
28
+ * @param tx - Transaction to add staking operation to
29
+ * @param suiCoin - Sui coin object to stake
30
+ * @returns haSUI coin object
31
+ */
32
+ async stakePTB(e, a) {
33
+ const [t] = e.moveCall({
34
+ target: `${this.config.packageId}::staking::request_stake_coin`,
35
+ arguments: [
36
+ e.object("0x05"),
37
+ e.object(this.config.configId),
38
+ r(a, e.object),
39
+ e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
40
+ ],
41
+ typeArguments: []
42
+ });
43
+ return t;
44
+ }
45
+ /**
46
+ * Builds a transaction block for unstaking haSUI to SUI
47
+ *
48
+ * @param tx - Transaction to add unstaking operation to
49
+ * @param haSUICoin - haSUI coin object to unstake
50
+ * @returns SUI coin object
51
+ */
52
+ async unstakePTB(e, a) {
53
+ const [t] = e.moveCall({
54
+ target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
55
+ arguments: [
56
+ e.object("0x05"),
57
+ e.object(this.config.configId),
58
+ r(a, e.object)
59
+ ],
60
+ typeArguments: []
61
+ });
62
+ return t;
63
+ }
64
+ /**
65
+ * Stake SUI for haSUI
66
+ *
67
+ * @param suiAmount - Amount of SUI to stake
68
+ * @param options Optional dry run
69
+ */
70
+ async stake(e, a) {
71
+ if (!this.walletClient)
72
+ throw new Error("Wallet client not found");
73
+ const t = new d();
74
+ await this.walletClient.module("balance").waitForUpdate();
75
+ const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = l(t, s.coins, {
76
+ balance: e,
77
+ useGasCoin: !0,
78
+ addressBalance: s.addressBalance.toFixed(0),
79
+ coinType: "0x2::sui::SUI"
80
+ }), c = await this.stakePTB(t, n);
81
+ t.transferObjects([c], this.walletClient.address);
82
+ const i = await this.walletClient.signExecuteTransaction({
83
+ transaction: t,
84
+ dryRun: a?.dryRun ?? !1
85
+ });
86
+ return !a?.dryRun && o(i) && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
87
+ }
88
+ /**
89
+ * Unstake haSUI for SUI
90
+ *
91
+ * @param haSUIAmount - Amount of haSUI to unstake
92
+ * @param options Optional dry run
93
+ */
94
+ async unstake(e, a) {
95
+ if (!this.walletClient)
96
+ throw new Error("Wallet client not found");
97
+ await this.walletClient.module("balance").waitForUpdate();
98
+ const t = new d(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = l(t, s.coins, {
99
+ balance: e,
100
+ addressBalance: s.addressBalance.toFixed(0),
101
+ coinType: this.config.coinType
102
+ }), c = await this.unstakePTB(t, n);
103
+ t.transferObjects([c], this.walletClient.address);
104
+ const i = await this.walletClient.signExecuteTransaction({
105
+ transaction: t,
106
+ dryRun: a?.dryRun ?? !1
107
+ });
108
+ return !a?.dryRun && o(i) && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
109
+ }
110
+ }
111
+ export {
112
+ T as HaedalModule
113
+ };
114
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/modules/haedalModule/index.ts"],"sourcesContent":["/**\n * Haedal Staking Module\n *\n * This module provides staking and unstaking functionality for the Haedal protocol.\n * It allows users to stake SUI for haSUI and unstake haSUI back to SUI, and fetches APY stats.\n *\n * @module HaedalModule\n */\n\nimport { isSuccessfulTransaction } from '../../transaction-result'\nimport {\n CoinObject,\n buildNaviOpenApiUrl,\n mergeCoinsPTB,\n mergeServiceHeaders,\n parseTxValue,\n resolveNaviOpenApiEndpoint,\n withCache,\n withSingleton,\n type NaviSdkServiceOptions\n} from '@naviprotocol/lending'\nimport { Transaction } from '@mysten/sui/transactions'\nimport { Module } from '../module'\nimport type { NaviWalletTransactionResult } from '../../types'\n\n/**\n * Configuration for the Haedal module\n */\nexport interface HaedalModuleConfig {\n /** Haedal package ID on Sui */\n packageId: string\n /** Haedal config object ID */\n configId: string\n /** haSUI coin type */\n coinType: string\n /** Optional NAVI service endpoint overrides. */\n services?: NaviSdkServiceOptions\n}\n\nexport type HaedalApyOptions = {\n services?: NaviSdkServiceOptions\n}\n\n/**\n * Events emitted by the Haedal module\n */\nexport type Events = {\n /** Emitted when staking SUI is successful */\n 'haedal:stake-success': {\n suiAmount: number\n }\n /** Emitted when unstaking haSUI is successful */\n 'haedal:unstake-success': {\n haSUIAmount: number\n }\n}\n\n/**\n * Haedal staking/unstaking module for wallet client\n */\nexport class HaedalModule extends Module<HaedalModuleConfig, Events> {\n /** Module name identifier */\n readonly name = 'haedal'\n /** Default configuration values */\n readonly defaultConfig: HaedalModuleConfig = {\n packageId: '0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c',\n configId: '0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca',\n coinType: '0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI'\n }\n\n /**\n * Fetches the current APY for Haedal staking\n *\n * @returns Current APY of haSUI\n */\n private getApyCached = withCache(\n withSingleton(async (options?: HaedalApyOptions) => {\n const serviceOptions = { services: options?.services }\n const endpoint = resolveNaviOpenApiEndpoint(serviceOptions)\n const resp: {\n data: {\n apy: number\n }\n } = await fetch(buildNaviOpenApiUrl('/haedal/stats', serviceOptions), {\n headers: mergeServiceHeaders({}, endpoint)\n }).then((res) => res.json())\n\n return resp.data.apy\n })\n )\n\n getApy(options?: HaedalApyOptions) {\n return this.getApyCached({\n services: options?.services ?? this.config.services\n })\n }\n\n /**\n * Builds a transaction block for staking SUI to haSUI\n *\n * @param tx - Transaction to add staking operation to\n * @param suiCoin - Sui coin object to stake\n * @returns haSUI coin object\n */\n async stakePTB(tx: Transaction, suiCoin: CoinObject) {\n const [coin] = tx.moveCall({\n target: `${this.config.packageId}::staking::request_stake_coin`,\n arguments: [\n tx.object('0x05'),\n tx.object(this.config.configId),\n parseTxValue(suiCoin, tx.object),\n tx.pure.address('0x0000000000000000000000000000000000000000000000000000000000000000')\n ],\n typeArguments: []\n })\n return coin\n }\n\n /**\n * Builds a transaction block for unstaking haSUI to SUI\n *\n * @param tx - Transaction to add unstaking operation to\n * @param haSUICoin - haSUI coin object to unstake\n * @returns SUI coin object\n */\n async unstakePTB(tx: Transaction, haSUICoin: CoinObject) {\n const [coin] = tx.moveCall({\n target: `${this.config.packageId}::staking::request_unstake_instant_coin`,\n arguments: [\n tx.object('0x05'),\n tx.object(this.config.configId),\n parseTxValue(haSUICoin, tx.object)\n ],\n typeArguments: []\n })\n return coin\n }\n\n /**\n * Stake SUI for haSUI\n *\n * @param suiAmount - Amount of SUI to stake\n * @param options Optional dry run\n */\n async stake<T extends boolean = false>(\n suiAmount: number,\n options?: { dryRun: T }\n ): Promise<NaviWalletTransactionResult<T>> {\n if (!this.walletClient) {\n throw new Error('Wallet client not found')\n }\n\n const tx = new Transaction()\n await this.walletClient.module('balance').waitForUpdate()\n const suiBalance = this.walletClient.module('balance').portfolio.getBalance('0x2::sui::SUI')\n const mergedCoin = mergeCoinsPTB(tx, suiBalance.coins, {\n balance: suiAmount,\n useGasCoin: true,\n addressBalance: suiBalance.addressBalance.toFixed(0),\n coinType: '0x2::sui::SUI'\n })\n const haSUICoin = await this.stakePTB(tx, mergedCoin)\n tx.transferObjects([haSUICoin], this.walletClient.address)\n const result = await this.walletClient.signExecuteTransaction({\n transaction: tx,\n dryRun: options?.dryRun ?? false\n })\n if (!options?.dryRun && isSuccessfulTransaction(result)) {\n this.emit('haedal:stake-success', { suiAmount })\n this.walletClient.module('balance').updatePortfolio()\n }\n return result as any\n }\n\n /**\n * Unstake haSUI for SUI\n *\n * @param haSUIAmount - Amount of haSUI to unstake\n * @param options Optional dry run\n */\n async unstake<T extends boolean = false>(\n haSUIAmount: number,\n options?: { dryRun: T }\n ): Promise<NaviWalletTransactionResult<T>> {\n if (!this.walletClient) {\n throw new Error('Wallet client not found')\n }\n await this.walletClient.module('balance').waitForUpdate()\n const tx = new Transaction()\n const haSuiBalance = this.walletClient\n .module('balance')\n .portfolio.getBalance(this.config.coinType)\n const mergedCoin = mergeCoinsPTB(tx, haSuiBalance.coins, {\n balance: haSUIAmount,\n addressBalance: haSuiBalance.addressBalance.toFixed(0),\n coinType: this.config.coinType\n })\n const suiCoin = await this.unstakePTB(tx, mergedCoin)\n tx.transferObjects([suiCoin], this.walletClient.address)\n const result = await this.walletClient.signExecuteTransaction({\n transaction: tx,\n dryRun: options?.dryRun ?? false\n })\n if (!options?.dryRun && isSuccessfulTransaction(result)) {\n this.emit('haedal:unstake-success', { haSUIAmount })\n this.walletClient.module('balance').updatePortfolio()\n }\n return result as any\n }\n}\n"],"names":["HaedalModule","Module","withCache","withSingleton","options","serviceOptions","endpoint","resolveNaviOpenApiEndpoint","buildNaviOpenApiUrl","mergeServiceHeaders","res","tx","suiCoin","coin","parseTxValue","haSUICoin","suiAmount","Transaction","suiBalance","mergedCoin","mergeCoinsPTB","result","isSuccessfulTransaction","haSUIAmount","haSuiBalance"],"mappings":"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"}
@@ -1,8 +1,8 @@
1
- import { BalanceModule, Events as BalanceEvents } from './balanceModule';
2
- import { LendingModule, Events as LendingEvents } from './lendingModule';
3
- import { VoloModule, Events as VoloEvents } from './voloModule';
4
- import { SwapModule, Events as SwapEvents } from './swapModule';
5
- import { HaedalModule, Events as HaedalEvents } from './haedalModule';
1
+ import { BalanceModule, Events as BalanceEvents } from './balanceModule/index.js';
2
+ import { LendingModule, Events as LendingEvents } from './lendingModule/index.js';
3
+ import { VoloModule, Events as VoloEvents } from './voloModule/index.js';
4
+ import { SwapModule, Events as SwapEvents } from './swapModule/index.js';
5
+ import { HaedalModule, Events as HaedalEvents } from './haedalModule/index.js';
6
6
 
7
7
  /**
8
8
  * Registry of all available wallet client modules
@@ -0,0 +1,21 @@
1
+ import { BalanceModule as o } from "./balanceModule/index.js";
2
+ import { LendingModule as e } from "./lendingModule/index.js";
3
+ import { VoloModule as l } from "./voloModule/index.js";
4
+ import { SwapModule as n } from "./swapModule/index.js";
5
+ import { HaedalModule as m } from "./haedalModule/index.js";
6
+ const t = {
7
+ /** Balance management module */
8
+ balance: new o(),
9
+ /** Lending protocol module */
10
+ lending: new e(),
11
+ /** Volo protocol module */
12
+ volo: new l(),
13
+ /** DEX swapping module */
14
+ swap: new n(),
15
+ /** Haedal protocol module */
16
+ haedal: new m()
17
+ };
18
+ export {
19
+ t as modules
20
+ };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/modules/index.ts"],"sourcesContent":["/**\n * Wallet Client Modules - Main Index\n *\n * This module serves as the central registry for all wallet client modules.\n * It imports and exports all available modules (balance, lending, volo, swap, haedal)\n * and provides type definitions for module management.\n *\n * @module WalletClientModules\n */\n\nimport { BalanceModule, Events as BalanceEvents } from './balanceModule'\nimport { LendingModule, Events as LendingEvents } from './lendingModule'\nimport { VoloModule, Events as VoloEvents } from './voloModule'\nimport { SwapModule, Events as SwapEvents } from './swapModule'\nimport { HaedalModule, Events as HaedalEvents } from './haedalModule'\n\n/**\n * Registry of all available wallet client modules\n *\n * This object contains instances of all modules that provide different\n * functionalities for the wallet client (balance management, lending,\n * volo operations, swapping, and haedal integration).\n */\nexport const modules = {\n /** Balance management module */\n balance: new BalanceModule(),\n /** Lending protocol module */\n lending: new LendingModule(),\n /** Volo protocol module */\n volo: new VoloModule(),\n /** DEX swapping module */\n swap: new SwapModule(),\n /** Haedal protocol module */\n haedal: new HaedalModule()\n}\n\n/**\n * Union type of all module events\n *\n * This type combines all event types from different modules,\n * allowing the wallet client to handle events from any module.\n */\nexport type ModuleEvents = BalanceEvents & LendingEvents & VoloEvents & SwapEvents & HaedalEvents\n\n/**\n * Type for module names\n *\n * This type represents the keys of the modules object,\n * allowing type-safe access to specific modules.\n */\nexport type ModuleName = keyof typeof modules\n\n/**\n * Type for module instances\n *\n * This type represents any module instance from the modules registry.\n */\nexport type Module = (typeof modules)[ModuleName]\n\n/**\n * Type for module configurations\n *\n * This type represents the configuration type of any module,\n * extracted from the defaultConfig property.\n */\nexport type ModuleConfig = Module['defaultConfig']\n"],"names":["modules","BalanceModule","LendingModule","VoloModule","SwapModule","HaedalModule"],"mappings":";;;;;AAuBO,MAAMA,IAAU;AAAA;AAAA,EAErB,SAAS,IAAIC,EAAA;AAAA;AAAA,EAEb,SAAS,IAAIC,EAAA;AAAA;AAAA,EAEb,MAAM,IAAIC,EAAA;AAAA;AAAA,EAEV,MAAM,IAAIC,EAAA;AAAA;AAAA,EAEV,QAAQ,IAAIC,EAAA;AACd;"}
@@ -1,10 +1,10 @@
1
- import { NaviWalletTransactionResult } from '../../types';
2
- import { Module } from '../module';
1
+ import { NaviWalletTransactionResult } from '../../types.js';
2
+ import { Module } from '../module.js';
3
3
  import { AssetIdentifier, CacheOption, LendingReward, AccountCapOption, Pool, NaviSdkServiceOptions } from '@naviprotocol/lending';
4
4
  import { SuiGrpcClient } from '@mysten/sui/grpc';
5
- import { migrateBalanceToSupplyPTB, migrateBetweenBorrowPTB, migrateBetweenSupplyPTB } from './migrate';
6
- import { LendingProtocol } from './protocols';
7
- import { WalletClient } from '../../client';
5
+ import { migrateBalanceToSupplyPTB, migrateBetweenBorrowPTB, migrateBetweenSupplyPTB } from './migrate.js';
6
+ import { LendingProtocol } from './protocols/index.js';
7
+ import { WalletClient } from '../../client.js';
8
8
 
9
9
  /**
10
10
  * Configuration options for the lending module
@@ -0,0 +1,410 @@
1
+ import { isSuccessfulTransaction as h } from "../../transaction-result.js";
2
+ import { Module as P } from "../module.js";
3
+ import { getPools as S, getPool as c, mergeCoinsPTB as u, depositCoinPTB as b, withdrawCoinPTB as O, borrowCoinPTB as R, repayCoinPTB as x, getHealthFactor as E, liquidatePTB as F, getUserAvailableLendingRewards as p, getUserClaimedRewardHistory as W, claimLendingRewardsPTB as U, getPriceFeeds as _, filterPriceFeeds as L, updateOraclePricesPTB as A, getLendingState as G, createAccountCapPTB as j } from "@naviprotocol/lending";
4
+ import { Transaction as r } from "@mysten/sui/transactions";
5
+ import { migrateBetweenSupplyPTB as v, migrateBetweenBorrowPTB as f, migrateBalanceToSupplyPTB as g } from "./migrate.js";
6
+ import z from "./protocols/navi.js";
7
+ class K extends P {
8
+ constructor() {
9
+ super(), this.name = "lending", this.defaultConfig = {
10
+ env: "prod",
11
+ protocols: [],
12
+ enableSuilend: !0
13
+ }, this._protocols = [], this.migrateBetweenSupplyPTB = v, this.migrateBetweenBorrowPTB = f, this.migrateBalanceToSupplyPTB = g, this.migrateBetweenSupplyPTB = v.bind(this), this.migrateBetweenBorrowPTB = f.bind(this), this.migrateBalanceToSupplyPTB = g.bind(this);
14
+ }
15
+ /** Get protocols (either from internal storage or config) */
16
+ get protocols() {
17
+ return this._protocols.length > 0 ? this._protocols : this.config.protocols;
18
+ }
19
+ get naviServiceOptions() {
20
+ const t = this.config.services ?? this.walletClient?.clientBundle.services;
21
+ return {
22
+ ...t ? { services: t } : {}
23
+ };
24
+ }
25
+ install(t) {
26
+ super.install(t), this._protocols = [];
27
+ }
28
+ async getProtocol(t) {
29
+ return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((e) => e.name === t);
30
+ }
31
+ /**
32
+ * Gets all available lending pools
33
+ *
34
+ * @param options - Optional caching options
35
+ * @returns Array of pool information
36
+ */
37
+ async getPools(t) {
38
+ return await S({
39
+ ...this.naviServiceOptions,
40
+ env: this.config.env,
41
+ ...t
42
+ });
43
+ }
44
+ /**
45
+ * Gets information for a specific lending pool
46
+ *
47
+ * @param identifier - Asset identifier (string, Pool object, or number)
48
+ * @param options - Optional caching options
49
+ * @returns Pool information
50
+ */
51
+ async getPool(t, e) {
52
+ return await c(t, {
53
+ ...this.naviServiceOptions,
54
+ env: this.config.env,
55
+ ...e
56
+ });
57
+ }
58
+ /**
59
+ * Deposits coins into a lending pool
60
+ *
61
+ * @param identifier - Asset identifier for the pool
62
+ * @param amount - Amount to deposit
63
+ * @param options - Optional parameters including dry run mode and account capability
64
+ * @returns Transaction response or dry run response
65
+ */
66
+ async deposit(t, e, i) {
67
+ if (!this.walletClient)
68
+ throw new Error("Wallet client not found");
69
+ const n = await c(t, {
70
+ ...this.naviServiceOptions,
71
+ env: this.config.env
72
+ });
73
+ await this.walletClient.module("balance").waitForUpdate();
74
+ const a = new r(), l = this.walletClient.module("balance").portfolio.getBalance(n.suiCoinType), s = u(a, l.coins, {
75
+ balance: e,
76
+ useGasCoin: !0,
77
+ addressBalance: l.addressBalance.toFixed(0),
78
+ coinType: n.suiCoinType
79
+ });
80
+ await b(a, n, s, {
81
+ ...this.naviServiceOptions,
82
+ env: this.config.env,
83
+ amount: e,
84
+ accountCap: i?.accountCap
85
+ });
86
+ const o = await this.walletClient.signExecuteTransaction({
87
+ transaction: a,
88
+ dryRun: i?.dryRun ?? !1
89
+ });
90
+ return !i?.dryRun && h(o) && (this.emit("lending:deposit-success", {
91
+ identifier: t,
92
+ amount: e
93
+ }), this.walletClient.module("balance").updatePortfolio()), o;
94
+ }
95
+ /**
96
+ * Withdraws coins from a lending pool
97
+ *
98
+ * @param identifier - Asset identifier for the pool
99
+ * @param amount - Amount to withdraw
100
+ * @param options - Optional parameters including dry run mode and account capability
101
+ * @returns Transaction response or dry run response
102
+ */
103
+ async withdraw(t, e, i) {
104
+ if (!this.walletClient)
105
+ throw new Error("Wallet client not found");
106
+ const n = await c(t, {
107
+ ...this.naviServiceOptions,
108
+ env: this.config.env
109
+ }), a = new r();
110
+ i?.disableUpdateOracle || await this.updateOraclePTB(a, [n]);
111
+ const l = await O(a, n, e, {
112
+ ...this.naviServiceOptions,
113
+ env: this.config.env,
114
+ accountCap: i?.accountCap
115
+ });
116
+ a.transferObjects([l], this.walletClient.address);
117
+ const s = await this.walletClient.signExecuteTransaction({
118
+ transaction: a,
119
+ dryRun: i?.dryRun ?? !1
120
+ });
121
+ return !i?.dryRun && h(s) && (this.emit("lending:withdraw-success", {
122
+ identifier: t,
123
+ amount: e
124
+ }), this.walletClient.module("balance").updatePortfolio()), s;
125
+ }
126
+ /**
127
+ * Borrows coins from a lending pool
128
+ *
129
+ * @param identifier - Asset identifier for the pool
130
+ * @param amount - Amount to borrow
131
+ * @param options - Optional parameters including dry run mode and account capability
132
+ * @returns Transaction response or dry run response
133
+ */
134
+ async borrow(t, e, i) {
135
+ if (!this.walletClient)
136
+ throw new Error("Wallet client not found");
137
+ const n = await c(t, {
138
+ ...this.naviServiceOptions,
139
+ env: this.config.env
140
+ }), a = new r();
141
+ i?.disableUpdateOracle || await this.updateOraclePTB(a, [n]);
142
+ const l = await R(a, n, e, {
143
+ ...this.naviServiceOptions,
144
+ env: this.config.env,
145
+ accountCap: i?.accountCap
146
+ });
147
+ a.transferObjects([l], this.walletClient.address);
148
+ const s = await this.walletClient.signExecuteTransaction({
149
+ transaction: a,
150
+ dryRun: i?.dryRun ?? !1
151
+ });
152
+ return !i?.dryRun && h(s) && (this.emit("lending:borrow-success", {
153
+ identifier: t,
154
+ amount: e
155
+ }), this.walletClient.module("balance").updatePortfolio()), s;
156
+ }
157
+ /**
158
+ * Repays borrowed coins to a lending pool
159
+ *
160
+ * @param identifier - Asset identifier for the pool
161
+ * @param amount - Amount to repay
162
+ * @param options - Optional parameters including dry run mode and account capability
163
+ * @returns Transaction response or dry run response
164
+ */
165
+ async repay(t, e, i) {
166
+ if (!this.walletClient)
167
+ throw new Error("Wallet client not found");
168
+ await this.walletClient.module("balance").waitForUpdate();
169
+ const n = await c(t, {
170
+ ...this.naviServiceOptions,
171
+ env: this.config.env
172
+ }), a = new r(), l = this.walletClient.module("balance").portfolio.getBalance(n.suiCoinType), s = u(a, l.coins, {
173
+ balance: e,
174
+ useGasCoin: !0,
175
+ addressBalance: l.addressBalance.toFixed(0),
176
+ coinType: n.suiCoinType
177
+ });
178
+ await x(a, n, s, {
179
+ ...this.naviServiceOptions,
180
+ env: this.config.env,
181
+ amount: e,
182
+ accountCap: i?.accountCap
183
+ });
184
+ const o = await this.walletClient.signExecuteTransaction({
185
+ transaction: a,
186
+ dryRun: i?.dryRun ?? !1
187
+ });
188
+ return !i?.dryRun && h(o) && (this.emit("lending:repay-success", {
189
+ identifier: t,
190
+ amount: e
191
+ }), this.walletClient.module("balance").updatePortfolio()), o;
192
+ }
193
+ /**
194
+ * Gets the current health factor for the user
195
+ *
196
+ * @returns Current health factor value
197
+ */
198
+ async getHealthFactor() {
199
+ if (!this.walletClient)
200
+ throw new Error("Wallet client not found");
201
+ const t = this.walletClient.address;
202
+ return await E(t, {
203
+ ...this.naviServiceOptions,
204
+ env: this.config.env,
205
+ client: this.walletClient.client
206
+ });
207
+ }
208
+ /**
209
+ * Initiates a liquidation process
210
+ *
211
+ * @param payIdentifier - Asset identifier for the debt being paid
212
+ * @param payAmount - Amount of debt to pay
213
+ * @param collateralIdentifier - Asset identifier for the collateral being liquidated
214
+ * @param liquidationAddress - Address of the account being liquidated
215
+ * @param options - Optional parameters including dry run mode
216
+ * @returns Transaction response or dry run response
217
+ */
218
+ async liquidate(t, e, i, n, a) {
219
+ if (!this.walletClient)
220
+ throw new Error("Wallet client not found");
221
+ const l = await c(t, {
222
+ ...this.naviServiceOptions,
223
+ env: this.config.env
224
+ }), s = await c(i, {
225
+ ...this.naviServiceOptions,
226
+ env: this.config.env
227
+ }), o = new r(), d = this.walletClient.module("balance").portfolio.getBalance(l.suiCoinType), C = u(o, d.coins, {
228
+ balance: e,
229
+ useGasCoin: !0,
230
+ addressBalance: d.addressBalance.toFixed(0),
231
+ coinType: l.suiCoinType
232
+ }), [y, m] = await F(
233
+ o,
234
+ l,
235
+ C,
236
+ s,
237
+ n,
238
+ {
239
+ ...this.naviServiceOptions,
240
+ env: this.config.env
241
+ }
242
+ ), [B] = o.moveCall({
243
+ target: "0x2::coin::from_balance",
244
+ arguments: [y],
245
+ typeArguments: [s.suiCoinType]
246
+ }), [T] = o.moveCall({
247
+ target: "0x2::coin::from_balance",
248
+ arguments: [m],
249
+ typeArguments: [l.suiCoinType]
250
+ });
251
+ o.transferObjects([B, T], this.walletClient.address);
252
+ const w = await this.walletClient.signExecuteTransaction({
253
+ transaction: o,
254
+ dryRun: a?.dryRun ?? !1
255
+ });
256
+ return !a?.dryRun && h(w) && (this.emit("lending:liquidate-success", {
257
+ payIdentifier: t,
258
+ payAmount: e,
259
+ collateralIdentifier: i,
260
+ liquidationAddress: n
261
+ }), this.walletClient.module("balance").updatePortfolio()), w;
262
+ }
263
+ /**
264
+ * Gets the available lending rewards for the current user.
265
+ *
266
+ * @param options - Optional cache options.
267
+ * @returns The available lending rewards for the user.
268
+ * @throws If the wallet client is not found.
269
+ */
270
+ async getAvailableRewards(t) {
271
+ if (!this.walletClient)
272
+ throw new Error("Wallet client not found");
273
+ return p(this.walletClient.address, {
274
+ ...this.naviServiceOptions,
275
+ ...t,
276
+ env: this.config.env,
277
+ client: this.walletClient.client
278
+ });
279
+ }
280
+ /**
281
+ * Gets the claimed reward history for the current user.
282
+ *
283
+ * @param options - Optional cache options.
284
+ * @returns The claimed reward history for the user.
285
+ * @throws If the wallet client is not found.
286
+ */
287
+ async getClaimedRewardHistory(t) {
288
+ if (!this.walletClient)
289
+ throw new Error("Wallet client not found");
290
+ return W(this.walletClient.address, {
291
+ ...this.naviServiceOptions,
292
+ ...t
293
+ });
294
+ }
295
+ /**
296
+ * Claims all available lending rewards for the user
297
+ *
298
+ * @param options - Optional parameters including dry run mode and account capability
299
+ * @returns Transaction response or dry run response
300
+ */
301
+ async claimAllRewards(t) {
302
+ if (!this.walletClient)
303
+ throw new Error("Wallet client not found");
304
+ const e = new r(), i = await p(this.walletClient.address, {
305
+ ...this.naviServiceOptions,
306
+ env: this.config.env,
307
+ client: this.walletClient.client
308
+ });
309
+ await U(e, i, {
310
+ ...this.naviServiceOptions,
311
+ env: this.config.env,
312
+ accountCap: t?.accountCap
313
+ });
314
+ const n = await this.walletClient.signExecuteTransaction({
315
+ transaction: e,
316
+ dryRun: t?.dryRun ?? !1
317
+ });
318
+ return !t?.dryRun && h(n) && (this.emit("lending:claim-rewards-success", {
319
+ rewards: i
320
+ }), this.walletClient.module("balance").updatePortfolio()), n;
321
+ }
322
+ async updateOraclePTB(t, e) {
323
+ const i = await _({
324
+ ...this.naviServiceOptions,
325
+ env: this.config.env
326
+ }), n = await this.getLendingState({
327
+ cacheTime: 60 * 1e3
328
+ }), a = L(i, {
329
+ lendingState: n,
330
+ pools: e
331
+ });
332
+ await A(t, a, {
333
+ ...this.naviServiceOptions,
334
+ env: this.config.env,
335
+ updatePythPriceFeeds: !0,
336
+ client: this.walletClient?.client
337
+ });
338
+ }
339
+ /**
340
+ * Updates the oracle prices for the lending protocol
341
+ *
342
+ * @param options - Optional parameters including dry run mode and pools
343
+ * @param options.dryRun - Whether to perform a dry run
344
+ * @returns Transaction response or dry run response
345
+ */
346
+ async updateOracle(t) {
347
+ if (!this.walletClient)
348
+ throw new Error("Wallet client not found");
349
+ const e = new r();
350
+ return await this.updateOraclePTB(e, t?.pools), await this.walletClient.signExecuteTransaction({
351
+ transaction: e,
352
+ dryRun: t?.dryRun ?? !1
353
+ });
354
+ }
355
+ /**
356
+ * Gets all active lending positions for the user
357
+ *
358
+ * @param options - Optional caching options
359
+ * @returns User's lending state information
360
+ */
361
+ async getLendingState(t) {
362
+ if (!this.walletClient)
363
+ throw new Error("Wallet client not found");
364
+ return await G(this.walletClient.address, {
365
+ ...this.naviServiceOptions,
366
+ env: this.config.env,
367
+ ...t,
368
+ client: this.walletClient.client
369
+ });
370
+ }
371
+ /**
372
+ * Creates an account capability for the lending protocol
373
+ *
374
+ * @param options - Optional parameters including dry run mode
375
+ * @returns Transaction response or dry run response
376
+ */
377
+ async createAccountCap(t) {
378
+ if (!this.walletClient)
379
+ throw new Error("Wallet client not found");
380
+ const e = new r(), i = await j(e);
381
+ return e.transferObjects([i], this.walletClient.address), await this.walletClient.signExecuteTransaction({
382
+ transaction: e,
383
+ dryRun: t?.dryRun ?? !1
384
+ });
385
+ }
386
+ async initializeProtocols() {
387
+ if (!this.walletClient) {
388
+ console.warn("Wallet client not available during protocol initialization");
389
+ return;
390
+ }
391
+ const t = [];
392
+ if (t.push(new z(this.walletClient)), this.config.enableSuilend)
393
+ try {
394
+ const { default: e } = await import("./protocols/suilend.js");
395
+ t.push(
396
+ await e.create(this.walletClient, {
397
+ grpcClient: this.config.suilendGrpcClient,
398
+ grpcUrl: this.config.suilendGrpcUrl
399
+ })
400
+ );
401
+ } catch (e) {
402
+ console.warn("Failed to initialize SuilendProtocol:", e);
403
+ }
404
+ this._protocols = t;
405
+ }
406
+ }
407
+ export {
408
+ K as LendingModule
409
+ };
410
+ //# sourceMappingURL=index.js.map