@naviprotocol/wallet-client 2.0.6 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,159 @@
1
+ import { generateRefId as C, getQuote as y, buildSwapPTBFromQuote as B } from "@naviprotocol/astros-aggregator-sdk";
2
+ import { Transaction as v } from "@mysten/sui/transactions";
3
+ import { fromBase64 as T } from "@mysten/sui/utils";
4
+ import { Module as O } from "../module.js";
5
+ import { defaultTransactionResponseOptions as w, normalizeTransactionResult as R, isSuccessfulTransaction as E, mergeTransactionResponseOptions as F } from "../../transaction-result.js";
6
+ import S from "bignumber.js";
7
+ import { mergeCoinsPTB as Q } from "@naviprotocol/lending";
8
+ import { executeAuction as K } from "shio-sdk";
9
+ function P() {
10
+ const n = F(w);
11
+ return {
12
+ effects: n.showEffects,
13
+ events: n.showEvents,
14
+ balanceChanges: n.showBalanceChanges,
15
+ objectTypes: n.showObjectChanges
16
+ };
17
+ }
18
+ function J(n) {
19
+ return n.core;
20
+ }
21
+ class M extends O {
22
+ constructor() {
23
+ super(...arguments), this.name = "swap", this.defaultConfig = {
24
+ apiKey: "",
25
+ baseUrl: "https://open-aggregator-api.naviprotocol.io/find_routes",
26
+ dexList: [],
27
+ depth: 3,
28
+ serviceFee: void 0,
29
+ env: "prod"
30
+ };
31
+ }
32
+ /**
33
+ * Gets the referral ID for this swap module
34
+ *
35
+ * @returns Referral ID if API key is configured, otherwise 0
36
+ */
37
+ get referral() {
38
+ return this.config.apiKey ? C(this.config.apiKey) : 0;
39
+ }
40
+ /**
41
+ * Get the swap options
42
+ * @returns The swap options
43
+ */
44
+ get swapOptions() {
45
+ return {
46
+ baseUrl: this.config.baseUrl,
47
+ dexList: this.config.dexList,
48
+ depth: this.config.depth,
49
+ serviceFee: this.config.serviceFee,
50
+ services: this.config.services ?? this.walletClient?.clientBundle.services
51
+ };
52
+ }
53
+ /**
54
+ * Get a quote for a swap
55
+ * @param fromCoinType - The type of the coin being swapped from
56
+ * @param toCoinType - The type of the coin being swapped to
57
+ * @param fromAmount - The amount of the coin being swapped from
58
+ * @returns A promise that resolves with the quote
59
+ */
60
+ async getQuote(e, s, i) {
61
+ return y(e, s, i, this.config.apiKey, this.swapOptions);
62
+ }
63
+ /**
64
+ * Builds a swap transaction from a quote
65
+ * @param tx - The transaction to build the swap from
66
+ * @param quote - The quote to build the swap from
67
+ * @param fromCoin - The coin to swap from
68
+ * @param slippage - The slippage tolerance
69
+ * @returns The swap transaction
70
+ */
71
+ async buildSwapPTBFromQuote(e, s, i, o) {
72
+ if (!this.walletClient)
73
+ throw new Error("Wallet client not found");
74
+ const c = new S(s.amount_out).multipliedBy(1 - o).toFixed(0);
75
+ return await B(
76
+ this.walletClient.address,
77
+ e,
78
+ Number(c),
79
+ i,
80
+ s,
81
+ this.referral,
82
+ !1,
83
+ this.config.apiKey,
84
+ this.swapOptions
85
+ );
86
+ }
87
+ /**
88
+ * Executes a swap between two coin types
89
+ *
90
+ * This method performs a complete swap operation including:
91
+ * - Balance validation
92
+ * - Quote retrieval from aggregator
93
+ * - Transaction building with slippage protection
94
+ * - Transaction execution
95
+ * - Event emission on success
96
+ *
97
+ * @param fromCoinType - Source coin type
98
+ * @param toCoinType - Target coin type
99
+ * @param fromAmount - Amount to swap
100
+ * @param slippage - Slippage tolerance (0-1)
101
+ * @param options - Optional parameters including dry run mode
102
+ * @returns Transaction response or dry run response
103
+ */
104
+ async swap(e, s, i, o, c) {
105
+ if (!this.walletClient)
106
+ throw new Error("Wallet client not found");
107
+ await this.walletClient.module("balance").waitForUpdate();
108
+ const p = this.walletClient.module("balance").portfolio.getBalance(e), a = new v(), h = Q(a, p.coins, {
109
+ balance: i,
110
+ useGasCoin: !0,
111
+ addressBalance: p.addressBalance.toFixed(0),
112
+ coinType: e
113
+ }), f = await this.getQuote(e, s, i), g = await this.buildSwapPTBFromQuote(a, f, h, o);
114
+ if (a.transferObjects([g], this.walletClient.address), a.setSender(this.walletClient.address), c?.dryRun)
115
+ return await this.walletClient.signExecuteTransaction({
116
+ transaction: a,
117
+ dryRun: !0
118
+ });
119
+ const m = await a.build({
120
+ client: this.walletClient.client
121
+ }), r = await this.walletClient.signer.signTransaction(m), l = [r.signature];
122
+ try {
123
+ await K(r.bytes, l);
124
+ } catch (t) {
125
+ console.error(t);
126
+ }
127
+ const d = J(this.walletClient.client), b = typeof d?.executeTransaction == "function" ? await d.executeTransaction({
128
+ transaction: T(r.bytes),
129
+ signatures: l,
130
+ include: P()
131
+ }) : await (() => {
132
+ const t = this.walletClient.clientBundle.legacyJsonRpc;
133
+ if (!t)
134
+ throw new Error(
135
+ "Swap execution requires core.executeTransaction or an explicit legacyJsonRpc client"
136
+ );
137
+ return t.executeTransactionBlock({
138
+ transactionBlock: r.bytes,
139
+ signature: l,
140
+ options: w
141
+ });
142
+ })(), u = R("execute", b);
143
+ if (E(u)) {
144
+ const t = u.events?.find((x) => x.type?.includes("::slippage::SwapEvent"));
145
+ t && this.emit("swap:swap-success", {
146
+ fromCoinType: e,
147
+ toCoinType: s,
148
+ fromAmount: i,
149
+ slippage: o,
150
+ toAmount: Number(t.parsedJson.amount_out)
151
+ }), this.walletClient.module("balance").updatePortfolio();
152
+ }
153
+ return u;
154
+ }
155
+ }
156
+ export {
157
+ M as SwapModule
158
+ };
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/modules/swapModule/index.ts"],"sourcesContent":["/**\n * Swap Module Implementation\n *\n * This module provides DEX swapping functionality for the wallet client.\n * It integrates with the Astros aggregator to find the best swap routes\n * and execute trades across multiple decentralized exchanges.\n *\n * @module SwapModule\n */\n\nimport {\n buildSwapPTBFromQuote,\n getQuote,\n Dex,\n FeeOption,\n generateRefId,\n Quote\n} from '@naviprotocol/astros-aggregator-sdk'\nimport { Transaction } from '@mysten/sui/transactions'\nimport { fromBase64 } from '@mysten/sui/utils'\nimport { Module } from '../module'\nimport { isSuccessfulTransaction } from '../../transaction-result'\nimport type { NaviWalletTransactionResult } from '../../types'\nimport BigNumber from 'bignumber.js'\nimport { mergeCoinsPTB, type NaviSdkServiceOptions } from '@naviprotocol/lending'\nimport { executeAuction } from 'shio-sdk'\nimport {\n defaultTransactionResponseOptions,\n mergeTransactionResponseOptions,\n normalizeTransactionResult\n} from '../../transaction-result'\n\n/**\n * Configuration options for the swap module\n */\nexport interface SwapModuleConfig {\n /** API key for aggregator access */\n apiKey: string\n /** Base URL for the aggregator API */\n baseUrl: string\n /** List of DEXes to use for routing */\n dexList: Dex[]\n /** Maximum routing depth for finding optimal paths */\n depth: number\n /** Service fee configuration */\n serviceFee: FeeOption | undefined\n /** Environment setting */\n env: 'dev' | 'prod'\n /** Optional NAVI service endpoint overrides. */\n services?: NaviSdkServiceOptions\n}\n\n/**\n * Events emitted by the swap module\n */\nexport type Events = {\n /** Emitted when a swap is successfully completed */\n 'swap:swap-success': {\n /** Source coin type */\n fromCoinType: string\n /** Target coin type */\n toCoinType: string\n /** Input amount */\n fromAmount: number\n /** Applied slippage tolerance */\n slippage: number\n /** Output amount received */\n toAmount: number\n }\n}\n\nfunction transactionIncludeOptions() {\n const merged = mergeTransactionResponseOptions(defaultTransactionResponseOptions)\n return {\n effects: merged.showEffects,\n events: merged.showEvents,\n balanceChanges: merged.showBalanceChanges,\n objectTypes: merged.showObjectChanges\n }\n}\n\nfunction getCoreExecutor(client: unknown) {\n return (client as { core?: unknown }).core as\n | {\n executeTransaction?(options: any): Promise<any>\n }\n | undefined\n}\n\n/**\n * DEX swapping module for wallet operations\n *\n * This module provides functionality for:\n * - Getting swap quotes from multiple DEXes\n * - Executing swaps with slippage protection\n * - Managing swap transactions and events\n * - Integrating with the balance module for coin management\n */\nexport class SwapModule extends Module<SwapModuleConfig, Events> {\n /** Module name identifier */\n readonly name = 'swap'\n\n /** Default configuration values */\n readonly defaultConfig: SwapModuleConfig = {\n apiKey: '',\n baseUrl: 'https://open-aggregator-api.naviprotocol.io/find_routes',\n dexList: [],\n depth: 3,\n serviceFee: undefined,\n env: 'prod'\n }\n\n /**\n * Gets the referral ID for this swap module\n *\n * @returns Referral ID if API key is configured, otherwise 0\n */\n get referral() {\n return this.config.apiKey ? generateRefId(this.config.apiKey) : 0\n }\n\n /**\n * Get the swap options\n * @returns The swap options\n */\n get swapOptions() {\n return {\n baseUrl: this.config.baseUrl,\n dexList: this.config.dexList,\n depth: this.config.depth,\n serviceFee: this.config.serviceFee,\n services: this.config.services ?? this.walletClient?.clientBundle.services\n }\n }\n\n /**\n * Get a quote for a swap\n * @param fromCoinType - The type of the coin being swapped from\n * @param toCoinType - The type of the coin being swapped to\n * @param fromAmount - The amount of the coin being swapped from\n * @returns A promise that resolves with the quote\n */\n async getQuote(fromCoinType: string, toCoinType: string, fromAmount: number) {\n return getQuote(fromCoinType, toCoinType, fromAmount, this.config.apiKey, this.swapOptions)\n }\n\n /**\n * Builds a swap transaction from a quote\n * @param tx - The transaction to build the swap from\n * @param quote - The quote to build the swap from\n * @param fromCoin - The coin to swap from\n * @param slippage - The slippage tolerance\n * @returns The swap transaction\n */\n async buildSwapPTBFromQuote(tx: Transaction, quote: Quote, fromCoin: any, slippage: number) {\n if (!this.walletClient) {\n throw new Error('Wallet client not found')\n }\n const minAmountOut = new BigNumber(quote.amount_out).multipliedBy(1 - slippage).toFixed(0)\n return await buildSwapPTBFromQuote(\n this.walletClient.address,\n tx,\n Number(minAmountOut),\n fromCoin as any,\n quote,\n this.referral,\n false,\n this.config.apiKey,\n this.swapOptions\n )\n }\n\n /**\n * Executes a swap between two coin types\n *\n * This method performs a complete swap operation including:\n * - Balance validation\n * - Quote retrieval from aggregator\n * - Transaction building with slippage protection\n * - Transaction execution\n * - Event emission on success\n *\n * @param fromCoinType - Source coin type\n * @param toCoinType - Target coin type\n * @param fromAmount - Amount to swap\n * @param slippage - Slippage tolerance (0-1)\n * @param options - Optional parameters including dry run mode\n * @returns Transaction response or dry run response\n */\n async swap<T extends boolean = false>(\n fromCoinType: string,\n toCoinType: string,\n fromAmount: number,\n slippage: number,\n options?: { dryRun: T }\n ): Promise<NaviWalletTransactionResult<T>> {\n if (!this.walletClient) {\n throw new Error('Wallet client not found')\n }\n\n // Wait for latest balance update\n await this.walletClient.module('balance').waitForUpdate()\n\n // Get current balance for the source coin\n const fromCoinBalance = this.walletClient.module('balance').portfolio.getBalance(fromCoinType)\n\n // Build transaction\n const tx = new Transaction()\n\n // Merge coins for the swap input (coin objects + address balance)\n const fromCoin = mergeCoinsPTB(tx, fromCoinBalance.coins, {\n balance: fromAmount,\n useGasCoin: true,\n addressBalance: fromCoinBalance.addressBalance.toFixed(0),\n coinType: fromCoinType\n })\n\n // Get quote from aggregator\n const quote = await this.getQuote(fromCoinType, toCoinType, fromAmount)\n\n // Build swap transaction from quote\n const coinOut = await this.buildSwapPTBFromQuote(tx, quote, fromCoin, slippage)\n\n // Transfer output coins to wallet\n tx.transferObjects([coinOut], this.walletClient.address)\n\n // Set sender address\n tx.setSender(this.walletClient.address)\n\n if (options?.dryRun) {\n const result = await this.walletClient.signExecuteTransaction({\n transaction: tx,\n dryRun: true\n })\n return result as any\n }\n\n const builtTx = await tx.build({\n client: this.walletClient.client as any\n })\n\n const signed = await this.walletClient.signer.signTransaction(builtTx)\n const signatures = [signed.signature]\n\n try {\n await executeAuction(signed.bytes, signatures)\n } catch (e) {\n console.error(e)\n }\n\n const core = getCoreExecutor(this.walletClient.client)\n const result =\n typeof core?.executeTransaction === 'function'\n ? await core.executeTransaction({\n transaction: fromBase64(signed.bytes),\n signatures,\n include: transactionIncludeOptions()\n })\n : await (() => {\n const legacyJsonRpc = this.walletClient.clientBundle.legacyJsonRpc\n if (!legacyJsonRpc) {\n throw new Error(\n 'Swap execution requires core.executeTransaction or an explicit legacyJsonRpc client'\n )\n }\n return legacyJsonRpc.executeTransactionBlock({\n transactionBlock: signed!.bytes,\n signature: signatures,\n options: defaultTransactionResponseOptions\n })\n })()\n\n const normalizedResult = normalizeTransactionResult('execute', result)\n\n if (isSuccessfulTransaction(normalizedResult)) {\n // Find slippage event to get actual output amount\n const slippageEvent = normalizedResult.events?.find((event) => {\n return event.type?.includes('::slippage::SwapEvent')\n })\n\n if (slippageEvent) {\n // Emit swap success event with actual amounts\n this.emit('swap:swap-success', {\n fromCoinType,\n toCoinType,\n fromAmount,\n slippage,\n toAmount: Number((slippageEvent.parsedJson as any).amount_out)\n })\n }\n\n // Update balance portfolio after successful swap\n this.walletClient.module('balance').updatePortfolio()\n }\n\n return normalizedResult as any\n }\n}\n"],"names":["transactionIncludeOptions","merged","mergeTransactionResponseOptions","defaultTransactionResponseOptions","getCoreExecutor","client","SwapModule","Module","generateRefId","fromCoinType","toCoinType","fromAmount","getQuote","tx","quote","fromCoin","slippage","minAmountOut","BigNumber","buildSwapPTBFromQuote","options","fromCoinBalance","Transaction","mergeCoinsPTB","coinOut","builtTx","signed","signatures","executeAuction","e","core","result","fromBase64","legacyJsonRpc","normalizedResult","normalizeTransactionResult","isSuccessfulTransaction","slippageEvent","event"],"mappings":";;;;;;;;AAuEA,SAASA,IAA4B;AACnC,QAAMC,IAASC,EAAgCC,CAAiC;AAChF,SAAO;AAAA,IACL,SAASF,EAAO;AAAA,IAChB,QAAQA,EAAO;AAAA,IACf,gBAAgBA,EAAO;AAAA,IACvB,aAAaA,EAAO;AAAA,EAAA;AAExB;AAEA,SAASG,EAAgBC,GAAiB;AACxC,SAAQA,EAA8B;AAKxC;AAWO,MAAMC,UAAmBC,EAAiC;AAAA,EAA1D,cAAA;AAAA,UAAA,GAAA,SAAA,GAEL,KAAS,OAAO,QAGhB,KAAS,gBAAkC;AAAA,MACzC,QAAQ;AAAA,MACR,SA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B,CACpC,IACD,OAAO,MAAM;AACX,YAAMiC,IAAgB,KAAK,aAAa,aAAa;AACrD,UAAI,CAACA;AACH,cAAM,IAAI;AAAA,UACR;AAAA,QAAA;AAGJ,aAAOA,EAAc,wBAAwB;AAAA,QAC3C,kBAAkBP,EAAQ;AAAA,QAC1B,WAAWC;AAAA,QACX,SAASxB;AAAA,MAAA,CACV;AAAA,IACH,GAAA,GAEA+B,IAAmBC,EAA2B,WAAWJ,CAAM;AAErE,QAAIK,EAAwBF,CAAgB,GAAG;AAE7C,YAAMG,IAAgBH,EAAiB,QAAQ,KAAK,CAACI,MAC5CA,EAAM,MAAM,SAAS,uBAAuB,CACpD;AAED,MAAID,KAEF,KAAK,KAAK,qBAAqB;AAAA,QAC7B,cAAA5B;AAAA,QACA,YAAAC;AAAA,QACA,YAAAC;AAAA,QACA,UAAAK;AAAA,QACA,UAAU,OAAQqB,EAAc,WAAmB,UAAU;AAAA,MAAA,CAC9D,GAIH,KAAK,aAAa,OAAO,SAAS,EAAE,gBAAA;AAAA,IACtC;AAEA,WAAOH;AAAA,EACT;AACF;"}
@@ -1,7 +1,7 @@
1
1
  import { CoinObject, NaviSdkServiceOptions } from '@naviprotocol/lending';
2
2
  import { Transaction } from '@mysten/sui/transactions';
3
- import { Module } from '../module';
4
- import { NaviWalletTransactionResult } from '../../types';
3
+ import { Module } from '../module.js';
4
+ import { NaviWalletTransactionResult } from '../../types.js';
5
5
 
6
6
  /**
7
7
  * Configuration interface for the Volo staking module
@@ -0,0 +1,128 @@
1
+ import { isSuccessfulTransaction as c } from "../../transaction-result.js";
2
+ import { withCache as u, withSingleton as f, resolveNaviOpenApiEndpoint as h, buildNaviOpenApiUrl as b, 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 g } from "../module.js";
5
+ class v extends g {
6
+ constructor() {
7
+ super(...arguments), this.name = "volo", this.defaultConfig = {
8
+ packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
9
+ poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
10
+ metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
11
+ coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
12
+ }, this.getStatsCached = u(
13
+ f(async (e) => {
14
+ const a = { services: e?.services }, t = h(a);
15
+ return (await fetch(b("/volo/stats", a), {
16
+ headers: p({}, t)
17
+ }).then((n) => n.json())).data;
18
+ })
19
+ );
20
+ }
21
+ getStats(e) {
22
+ return this.getStatsCached({
23
+ services: e?.services ?? this.config.services
24
+ });
25
+ }
26
+ /**
27
+ * Adds staking operation to a transaction black
28
+ *
29
+ * @param tx - The transaction block to add the staking operation to
30
+ * @param suiCoin - The SUI coin object to stake
31
+ * @returns The vSUI coin object received from staking
32
+ */
33
+ async stakePTB(e, a) {
34
+ const [t] = e.moveCall({
35
+ target: `${this.config.packageId}::stake_pool::stake`,
36
+ arguments: [
37
+ e.object(this.config.poolId),
38
+ e.object(this.config.metadataId),
39
+ e.object("0x05"),
40
+ r(a, e.object)
41
+ ],
42
+ typeArguments: []
43
+ });
44
+ return t;
45
+ }
46
+ /**
47
+ * Adds unstaking operation to a transaction black
48
+ *
49
+ * @param tx - The transaction block to add the unstaking operation to
50
+ * @param vSuiCoin - The vSUI coin object to unstake
51
+ * @returns The SUI coin object received from unstaking
52
+ */
53
+ async unstakePTB(e, a) {
54
+ const [t] = e.moveCall({
55
+ target: `${this.config.packageId}::stake_pool::unstake`,
56
+ arguments: [
57
+ e.object(this.config.poolId),
58
+ e.object(this.config.metadataId),
59
+ e.object("0x05"),
60
+ r(a, e.object)
61
+ ],
62
+ typeArguments: []
63
+ });
64
+ return t;
65
+ }
66
+ /**
67
+ * Stake SUI tokens to receive vSUI tokens
68
+ *
69
+ * @param suiAmount - Amount of SUI to stake (in MIST units)
70
+ * @param options - Optional parameters including dryRun flag
71
+ * @returns Transaction response or dry run response
72
+ * @throws Error if wallet client not found or stake amount is too low
73
+ */
74
+ async stake(e, a) {
75
+ if (!this.walletClient)
76
+ throw new Error("Wallet client not found");
77
+ if (e < 1e9)
78
+ throw new Error("Stake amount should be greater than 1Sui");
79
+ const t = new d();
80
+ await this.walletClient.module("balance").waitForUpdate();
81
+ const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = l(t, s.coins, {
82
+ balance: e,
83
+ useGasCoin: !0,
84
+ addressBalance: s.addressBalance.toFixed(0),
85
+ coinType: "0x2::sui::SUI"
86
+ }), i = await this.stakePTB(t, n);
87
+ t.transferObjects([i], this.walletClient.address);
88
+ const o = await this.walletClient.signExecuteTransaction({
89
+ transaction: t,
90
+ dryRun: a?.dryRun ?? !1
91
+ });
92
+ return !a?.dryRun && c(o) && (this.emit("volo:stake-success", {
93
+ suiAmount: e
94
+ }), this.walletClient.module("balance").updatePortfolio()), o;
95
+ }
96
+ /**
97
+ * Unstake vSUI tokens to receive SUI tokens
98
+ *
99
+ * @param vSuiAmount - Amount of vSUI to unstake (in MIST units)
100
+ * @param options - Optional parameters including dryRun flag
101
+ * @returns Transaction response or dry run response
102
+ * @throws Error if wallet client not found or unstake amount is too low
103
+ */
104
+ async unstake(e, a) {
105
+ if (!this.walletClient)
106
+ throw new Error("Wallet client not found");
107
+ if (e < 1e9)
108
+ throw new Error("Unstake amount should >= 1vSui");
109
+ await this.walletClient.module("balance").waitForUpdate();
110
+ const t = new d(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = l(t, s.coins, {
111
+ balance: e,
112
+ addressBalance: s.addressBalance.toFixed(0),
113
+ coinType: this.config.coinType
114
+ }), i = await this.unstakePTB(t, n);
115
+ t.transferObjects([i], this.walletClient.address);
116
+ const o = await this.walletClient.signExecuteTransaction({
117
+ transaction: t,
118
+ dryRun: a?.dryRun ?? !1
119
+ });
120
+ return !a?.dryRun && c(o) && (this.emit("volo:unstake-success", {
121
+ vSuiAmount: e
122
+ }), this.walletClient.module("balance").updatePortfolio()), o;
123
+ }
124
+ }
125
+ export {
126
+ v as VoloModule
127
+ };
128
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/modules/voloModule/index.ts"],"sourcesContent":["/**\n * Volo Module for Sui Staking Protocol Integration\n *\n * This module provides functionality to interact with the Volo staking protocol on Sui.\n * Volo allows users to stake SUI tokens and receive vSUI (volo SUI) tokens in return,\n * enabling liquid staking with potential rewards and instant unstaking capabilities.\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 interface for the Volo staking module\n */\nexport interface VoloModuleConfig {\n /** The package ID of the Volo staking contract */\n packageId: string\n /** The pool ID for the staking pool */\n poolId: string\n /** The coin type for vSUI tokens */\n coinType: string\n /** The metadata ID for the staking pool */\n metadataId: string\n /** Optional NAVI service endpoint overrides. */\n services?: NaviSdkServiceOptions\n}\n\nexport type VoloStatsOptions = {\n services?: NaviSdkServiceOptions\n}\n\n/**\n * Event types emitted by the Volo module\n */\nexport type Events = {\n /** Emitted when staking is successful */\n 'volo:stake-success': {\n /** Amount of SUI staked */\n suiAmount: number\n }\n /** Emitted when unstaking is successful */\n 'volo:unstake-success': {\n /** Amount of vSUI unstaked */\n vSuiAmount: number\n }\n}\n\n/**\n * Statistics and information about the Volo staking pool\n */\nexport type VoloStats = {\n /** Current operator balance */\n operatorBalance: string\n /** Collectable fees in the pool */\n collectableFee: string\n /** Pending stakes waiting to be processed */\n pendingStakes: string\n /** Total amount staked in the pool */\n totalStaked: string\n /** Total rewards distributed to stakers */\n totalRewardsInStakes: string\n /** Currently active stake amount */\n activeStake: string\n /** Current epoch number */\n currentEpoch: string\n /** List of validators in the pool */\n validators: {\n /** Validator address */\n address: string\n /** Total amount staked with this validator */\n totalStaked: string\n /** Assigned weight for this validator */\n assigned_weight: string\n /** Annual percentage yield for this validator */\n apy: string\n /** Validator name */\n name: string\n }[]\n /** Current exchange rate between SUI and vSUI */\n exchangeRate: number\n /** Total supply of vSUI tokens */\n totalSupply: string\n /** Overall APY for the staking pool */\n apy: number\n /** Maximum amount that can be instantly unstaked */\n maxInstantUnstake: string\n /** Maximum amount that can be unstaked without fees */\n maxNoFeeUnstake: string\n /** Total number of stakers in the pool */\n totalStakers: number\n /** Timestamp of last update */\n lastUpdated: number\n}\n\n/**\n * Volo Module for Sui Staking Protocol\n *\n * Provides functionality to stake SUI tokens and receive vSUI tokens,\n * enabling liquid staking with potential rewards and instant unstaking.\n */\nexport class VoloModule extends Module<VoloModuleConfig, Events> {\n /** Module name identifier */\n readonly name = 'volo'\n\n /** Default configuration for the Volo staking protocol */\n readonly defaultConfig: VoloModuleConfig = {\n packageId: '0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20',\n poolId: '0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5',\n metadataId: '0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60',\n coinType: '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT'\n }\n\n /**\n * Get current statistics and information about the Volo staking pool\n * Uses caching to avoid repeated API calls\n *\n * @returns Volo staking pool information\n */\n private getStatsCached = withCache(\n withSingleton(async (options?: VoloStatsOptions) => {\n const serviceOptions = { services: options?.services }\n const endpoint = resolveNaviOpenApiEndpoint(serviceOptions)\n const resp: {\n data: VoloStats\n } = await fetch(buildNaviOpenApiUrl('/volo/stats', serviceOptions), {\n headers: mergeServiceHeaders({}, endpoint)\n }).then((res) => res.json())\n\n return resp.data\n })\n )\n\n getStats(options?: VoloStatsOptions) {\n return this.getStatsCached({\n services: options?.services ?? this.config.services\n })\n }\n\n /**\n * Adds staking operation to a transaction black\n *\n * @param tx - The transaction block to add the staking operation to\n * @param suiCoin - The SUI coin object to stake\n * @returns The vSUI coin object received from staking\n */\n async stakePTB(tx: Transaction, suiCoin: CoinObject) {\n const [coin] = tx.moveCall({\n target: `${this.config.packageId}::stake_pool::stake`,\n arguments: [\n tx.object(this.config.poolId),\n tx.object(this.config.metadataId),\n tx.object('0x05'),\n parseTxValue(suiCoin, tx.object)\n ],\n typeArguments: []\n })\n return coin\n }\n\n /**\n * Adds unstaking operation to a transaction black\n *\n * @param tx - The transaction block to add the unstaking operation to\n * @param vSuiCoin - The vSUI coin object to unstake\n * @returns The SUI coin object received from unstaking\n */\n async unstakePTB(tx: Transaction, vSuiCoin: CoinObject) {\n const [coin] = tx.moveCall({\n target: `${this.config.packageId}::stake_pool::unstake`,\n arguments: [\n tx.object(this.config.poolId),\n tx.object(this.config.metadataId),\n tx.object('0x05'),\n parseTxValue(vSuiCoin, tx.object)\n ],\n typeArguments: []\n })\n return coin\n }\n\n /**\n * Stake SUI tokens to receive vSUI tokens\n *\n * @param suiAmount - Amount of SUI to stake (in MIST units)\n * @param options - Optional parameters including dryRun flag\n * @returns Transaction response or dry run response\n * @throws Error if wallet client not found or stake amount is too low\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 if (suiAmount < 1e9) {\n throw new Error('Stake amount should be greater than 1Sui')\n }\n\n const tx = new Transaction()\n\n await this.walletClient.module('balance').waitForUpdate()\n\n const suiBalance = this.walletClient.module('balance').portfolio.getBalance('0x2::sui::SUI')\n\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\n const vSuiCoin = await this.stakePTB(tx, mergedCoin)\n\n tx.transferObjects([vSuiCoin], this.walletClient.address)\n\n const result = await this.walletClient.signExecuteTransaction({\n transaction: tx,\n dryRun: options?.dryRun ?? false\n })\n\n if (!options?.dryRun && isSuccessfulTransaction(result)) {\n this.emit('volo:stake-success', {\n suiAmount\n })\n\n this.walletClient.module('balance').updatePortfolio()\n }\n\n return result as any\n }\n\n /**\n * Unstake vSUI tokens to receive SUI tokens\n *\n * @param vSuiAmount - Amount of vSUI to unstake (in MIST units)\n * @param options - Optional parameters including dryRun flag\n * @returns Transaction response or dry run response\n * @throws Error if wallet client not found or unstake amount is too low\n */\n async unstake<T extends boolean = false>(\n vSuiAmount: number,\n options?: { dryRun: T }\n ): Promise<NaviWalletTransactionResult<T>> {\n if (!this.walletClient) {\n throw new Error('Wallet client not found')\n }\n\n if (vSuiAmount < 1e9) {\n throw new Error('Unstake amount should >= 1vSui')\n }\n\n await this.walletClient.module('balance').waitForUpdate()\n\n const tx = new Transaction()\n\n const vSuiBalance = this.walletClient\n .module('balance')\n .portfolio.getBalance(this.config.coinType)\n\n const mergedCoin = mergeCoinsPTB(tx, vSuiBalance.coins, {\n balance: vSuiAmount,\n addressBalance: vSuiBalance.addressBalance.toFixed(0),\n coinType: this.config.coinType\n })\n\n const suiCoin = await this.unstakePTB(tx, mergedCoin)\n\n tx.transferObjects([suiCoin], this.walletClient.address)\n\n const result = await this.walletClient.signExecuteTransaction({\n transaction: tx,\n dryRun: options?.dryRun ?? false\n })\n\n if (!options?.dryRun && isSuccessfulTransaction(result)) {\n this.emit('volo:unstake-success', {\n vSuiAmount\n })\n\n this.walletClient.module('balance').updatePortfolio()\n }\n\n return result as any\n }\n}\n"],"names":["VoloModule","Module","withCache","withSingleton","options","serviceOptions","endpoint","resolveNaviOpenApiEndpoint","buildNaviOpenApiUrl","mergeServiceHeaders","res","tx","suiCoin","coin","parseTxValue","vSuiCoin","suiAmount","Transaction","suiBalance","mergedCoin","mergeCoinsPTB","result","isSuccessfulTransaction","vSuiAmount","vSuiBalance"],"mappings":";;;;AAiHO,MAAMA,UAAmBC,EAAiC;AAAA,EAA1D,cAAA;AAAA,UAAA,GAAA,SAAA,GAEL,KAAS,OAAO,QAGhB,KAAS,gBAAkC;AAAA,MACzC,WAAW;AAAA,MACX,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,UAAU;AAAA,IAAA,GASZ,KAAQ,iBAAiBC;AAAA,MACvBC,EAAc,OAAOC,MAA+B;AAClD,cAAMC,IAAiB,EAAE,UAAUD,GAAS,SAAA,GACtCE,IAAWC,EAA2BF,CAAc;AAO1D,gBAJI,MAAM,MAAMG,EAAoB,eAAeH,CAAc,GAAG;AAAA,UAClE,SAASI,EAAoB,CAAA,GAAIH,CAAQ;AAAA,QAAA,CAC1C,EAAE,KAAK,CAACI,MAAQA,EAAI,MAAM,GAEf;AAAA,MACd,CAAC;AAAA,IAAA;AAAA,EACH;AAAA,EAEA,SAASN,GAA4B;AACnC,WAAO,KAAK,eAAe;AAAA,MACzB,UAAUA,GAAS,YAAY,KAAK,OAAO;AAAA,IAAA,CAC5C;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,SAASO,GAAiBC,GAAqB;AACnD,UAAM,CAACC,CAAI,IAAIF,EAAG,SAAS;AAAA,MACzB,QAAQ,GAAG,KAAK,OAAO,SAAS;AAAA,MAChC,WAAW;AAAA,QACTA,EAAG,OAAO,KAAK,OAAO,MAAM;AAAA,QAC5BA,EAAG,OAAO,KAAK,OAAO,UAAU;AAAA,QAChCA,EAAG,OAAO,MAAM;AAAA,QAChBG,EAAaF,GAASD,EAAG,MAAM;AAAA,MAAA;AAAA,MAEjC,eAAe,CAAA;AAAA,IAAC,CACjB;AACD,WAAOE;AAAA,EACT;AAAA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AAAL;AAAA,IAAA,CACD,GAED,KAAK,aAAa,OAAO,SAAS,EAAE,gBAAA,IAG/BK;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,QACJE,GACAnB,GACyC;AACzC,QAAI,CAAC,KAAK;AACR,YAAM,IAAI,MAAM,yBAAyB;AAG3C,QAAImB,IAAa;AACf,YAAM,IAAI,MAAM,gCAAgC;AAGlD,UAAM,KAAK,aAAa,OAAO,SAAS,EAAE,cAAA;AAE1C,UAAMZ,IAAK,IAAIM,EAAA,GAETO,IAAc,KAAK,aACtB,OAAO,SAAS,EAChB,UAAU,WAAW,KAAK,OAAO,QAAQ,GAEtCL,IAAaC,EAAcT,GAAIa,EAAY,OAAO;AAAA,MACtD,SAASD;AAAA,MACT,gBAAgBC,EAAY,eAAe,QAAQ,CAAC;AAAA,MACpD,UAAU,KAAK,OAAO;AAAA,IAAA,CACvB,GAEKZ,IAAU,MAAM,KAAK,WAAWD,GAAIQ,CAAU;AAEpD,IAAAR,EAAG,gBAAgB,CAACC,CAAO,GAAG,KAAK,aAAa,OAAO;AAEvD,UAAMS,IAAS,MAAM,KAAK,aAAa,uBAAuB;AAAA,MAC5D,aAAaV;AAAA,MACb,QAAQP,GAAS,UAAU;AAAA,IAAA,CAC5B;AAED,WAAI,CAACA,GAAS,UAAUkB,EAAwBD,CAAM,MACpD,KAAK,KAAK,wBAAwB;AAAA,MAChC,YAAAE;AAAA,IAAA,CACD,GAED,KAAK,aAAa,OAAO,SAAS,EAAE,gBAAA,IAG/BF;AAAA,EACT;AACF;"}
package/dist/signer.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Signer, PublicKey, SignatureScheme, SignatureWithBytes } from '@mysten/sui/cryptography';
2
2
  import { Transaction } from '@mysten/sui/transactions';
3
- import { NaviWalletExecutionClient } from './types';
3
+ import { NaviWalletExecutionClient } from './types.js';
4
4
 
5
5
  /**
6
6
  * Options for signing and executing transactions
package/dist/signer.js ADDED
@@ -0,0 +1,102 @@
1
+ import { Signer as s } from "@mysten/sui/cryptography";
2
+ function t(r) {
3
+ return {
4
+ toSuiAddress: () => r,
5
+ toBytes: () => new Uint8Array(32),
6
+ toRawBytes: () => new Uint8Array(32),
7
+ flag: () => 0,
8
+ verify: async () => !1
9
+ };
10
+ }
11
+ class i extends s {
12
+ /**
13
+ * Creates a new watch-only signer
14
+ *
15
+ * @param address - The wallet address to watch
16
+ */
17
+ constructor(e) {
18
+ super(), this.address = e;
19
+ }
20
+ /**
21
+ * Signs transaction bytes (not implemented for watch-only mode)
22
+ *
23
+ * This method is required by the Signer interface but cannot
24
+ * actually sign transactions in watch-only mode.
25
+ *
26
+ * @param bytes - Transaction bytes to sign
27
+ * @returns Promise<Uint8Array> - Empty signature (not valid)
28
+ */
29
+ async sign(e) {
30
+ return Promise.resolve(new Uint8Array(0));
31
+ }
32
+ /**
33
+ * Gets the public key information for this signer
34
+ *
35
+ * Returns a mock public key object that provides the wallet address
36
+ * but cannot be used for actual cryptographic operations.
37
+ */
38
+ getPublicKey() {
39
+ return t(this.address);
40
+ }
41
+ /**
42
+ * Gets the key scheme for this signer
43
+ *
44
+ * @returns Key scheme (ed25519 for compatibility)
45
+ */
46
+ getKeyScheme() {
47
+ return "ED25519";
48
+ }
49
+ /**
50
+ * Signs and executes a transaction (not implemented for watch-only mode)
51
+ *
52
+ * This method is required by the Signer interface but cannot
53
+ * actually sign and execute transactions in watch-only mode.
54
+ */
55
+ async signAndExecuteTransaction(e) {
56
+ return {};
57
+ }
58
+ }
59
+ class a extends s {
60
+ /**
61
+ * Creates a new watch-only signer
62
+ *
63
+ * @param address - The wallet address to watch
64
+ */
65
+ constructor(e) {
66
+ super(), this.address = e;
67
+ }
68
+ /**
69
+ * Signs transaction bytes (not implemented for watch-only mode)
70
+ *
71
+ * This method is required by the Signer interface but cannot
72
+ * actually sign transactions in watch-only mode.
73
+ *
74
+ * @param bytes - Transaction bytes to sign
75
+ * @returns Promise<Uint8Array> - Empty signature (not valid)
76
+ */
77
+ async sign(e) {
78
+ return Promise.resolve(new Uint8Array(0));
79
+ }
80
+ /**
81
+ * Gets the public key information for this signer
82
+ *
83
+ * Returns a mock public key object that provides the wallet address
84
+ * but cannot be used for actual cryptographic operations.
85
+ */
86
+ getPublicKey() {
87
+ return t(this.address);
88
+ }
89
+ /**
90
+ * Gets the key scheme for this signer
91
+ *
92
+ * @returns Key scheme (ed25519 for compatibility)
93
+ */
94
+ getKeyScheme() {
95
+ return "ED25519";
96
+ }
97
+ }
98
+ export {
99
+ i as WatchSigner,
100
+ a as WebSigner
101
+ };
102
+ //# sourceMappingURL=signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.js","sources":["../src/signer.ts"],"sourcesContent":["/**\n * Watch Signer Implementation\n *\n * This module provides a watch-only signer implementation for the wallet client.\n * It allows users to view wallet information and transaction details without\n * the ability to sign transactions, useful for read-only operations.\n *\n * @module WatchSigner\n */\n\nimport { Signer } from '@mysten/sui/cryptography'\nimport { Transaction } from '@mysten/sui/transactions'\nimport type { PublicKey, SignatureScheme, SignatureWithBytes } from '@mysten/sui/cryptography'\nimport type { NaviWalletExecutionClient } from './types'\n\n/**\n * Minimal mock public key used by watch-only / web signers. It exposes the\n * address but cannot perform real cryptography; typed as `PublicKey` for the\n * `Signer` contract via a cast since it is intentionally incomplete.\n */\nfunction createMockPublicKey(address: string): PublicKey {\n return {\n toSuiAddress: () => address,\n toBytes: () => new Uint8Array(32),\n toRawBytes: () => new Uint8Array(32),\n flag: () => 0,\n verify: async () => false\n } as unknown as PublicKey\n}\n\n/**\n * Options for signing and executing transactions\n */\ninterface SignAndExecuteOptions {\n /** Transaction to sign and execute */\n transaction: Transaction\n /** Sui client instance */\n client: NaviWalletExecutionClient\n}\n\n/**\n * Watch-only signer implementation\n *\n * This signer provides read-only access to wallet information without\n * the ability to sign transactions. It's useful for viewing wallet\n * balances, transaction history, and other non-signing operations.\n *\n * Note: This signer cannot actually sign transactions and will return\n * empty signatures or throw errors when signing is attempted.\n */\nexport class WatchSigner extends Signer {\n /** The wallet address this signer represents */\n private address: string\n\n /**\n * Creates a new watch-only signer\n *\n * @param address - The wallet address to watch\n */\n constructor(address: string) {\n super()\n this.address = address\n }\n\n /**\n * Signs transaction bytes (not implemented for watch-only mode)\n *\n * This method is required by the Signer interface but cannot\n * actually sign transactions in watch-only mode.\n *\n * @param bytes - Transaction bytes to sign\n * @returns Promise<Uint8Array> - Empty signature (not valid)\n */\n override async sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {\n return Promise.resolve(new Uint8Array(0))\n }\n\n /**\n * Gets the public key information for this signer\n *\n * Returns a mock public key object that provides the wallet address\n * but cannot be used for actual cryptographic operations.\n */\n getPublicKey(): PublicKey {\n return createMockPublicKey(this.address)\n }\n\n /**\n * Gets the key scheme for this signer\n *\n * @returns Key scheme (ed25519 for compatibility)\n */\n getKeyScheme(): SignatureScheme {\n return 'ED25519'\n }\n\n /**\n * Signs and executes a transaction (not implemented for watch-only mode)\n *\n * This method is required by the Signer interface but cannot\n * actually sign and execute transactions in watch-only mode.\n */\n override async signAndExecuteTransaction(\n options: SignAndExecuteOptions\n ): ReturnType<Signer['signAndExecuteTransaction']> {\n return {} as Awaited<ReturnType<Signer['signAndExecuteTransaction']>>\n }\n}\n\n/**\n * Web signer implementation\n *\n * For use in browser environments\n */\nexport abstract class WebSigner extends Signer {\n private address: string\n\n /**\n * Creates a new watch-only signer\n *\n * @param address - The wallet address to watch\n */\n constructor(address: string) {\n super()\n this.address = address\n }\n\n /**\n * Signs transaction bytes (not implemented for watch-only mode)\n *\n * This method is required by the Signer interface but cannot\n * actually sign transactions in watch-only mode.\n *\n * @param bytes - Transaction bytes to sign\n * @returns Promise<Uint8Array> - Empty signature (not valid)\n */\n override async sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {\n return Promise.resolve(new Uint8Array(0))\n }\n\n /**\n * Gets the public key information for this signer\n *\n * Returns a mock public key object that provides the wallet address\n * but cannot be used for actual cryptographic operations.\n */\n getPublicKey(): PublicKey {\n return createMockPublicKey(this.address)\n }\n\n /**\n * Gets the key scheme for this signer\n *\n * @returns Key scheme (ed25519 for compatibility)\n */\n getKeyScheme(): SignatureScheme {\n return 'ED25519'\n }\n\n abstract signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes>\n\n abstract signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes>\n}\n"],"names":["createMockPublicKey","address","WatchSigner","Signer","bytes","options","WebSigner"],"mappings":";AAoBA,SAASA,EAAoBC,GAA4B;AACvD,SAAO;AAAA,IACL,cAAc,MAAMA;AAAA,IACpB,SAAS,MAAM,IAAI,WAAW,EAAE;AAAA,IAChC,YAAY,MAAM,IAAI,WAAW,EAAE;AAAA,IACnC,MAAM,MAAM;AAAA,IACZ,QAAQ,YAAY;AAAA,EAAA;AAExB;AAsBO,MAAMC,UAAoBC,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAStC,YAAYF,GAAiB;AAC3B,UAAA,GACA,KAAK,UAAUA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAe,KAAKG,GAAqD;AACvE,WAAO,QAAQ,QAAQ,IAAI,WAAW,CAAC,CAAC;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,eAA0B;AACxB,WAAOJ,EAAoB,KAAK,OAAO;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,eAAgC;AAC9B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAe,0BACbK,GACiD;AACjD,WAAO,CAAA;AAAA,EACT;AACF;AAOO,MAAeC,UAAkBH,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7C,YAAYF,GAAiB;AAC3B,UAAA,GACA,KAAK,UAAUA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAe,KAAKG,GAAqD;AACvE,WAAO,QAAQ,QAAQ,IAAI,WAAW,CAAC,CAAC;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,eAA0B;AACxB,WAAOJ,EAAoB,KAAK,OAAO;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,eAAgC;AAC9B,WAAO;AAAA,EACT;AAKF;"}
@@ -1,4 +1,4 @@
1
- import { NaviDryRunTransactionResult, NaviExecuteTransactionResult, NaviTransactionResponseOptions } from './types';
1
+ import { NaviDryRunTransactionResult, NaviExecuteTransactionResult, NaviTransactionResponseOptions } from './types.js';
2
2
 
3
3
  export declare const defaultTransactionResponseOptions: NaviTransactionResponseOptions;
4
4
  export declare function mergeTransactionResponseOptions(options?: NaviTransactionResponseOptions): NaviTransactionResponseOptions;
@@ -0,0 +1,59 @@
1
+ const c = {
2
+ showEffects: !0,
3
+ showEvents: !0,
4
+ showBalanceChanges: !0,
5
+ showObjectChanges: !0
6
+ };
7
+ function f(n) {
8
+ return {
9
+ ...c,
10
+ ...n
11
+ };
12
+ }
13
+ function p(n) {
14
+ const s = n?.effects?.status;
15
+ return s?.status === "success" || s?.success === !0;
16
+ }
17
+ function h(n, s) {
18
+ const t = o(s ?? {}), a = u(t);
19
+ return {
20
+ ...t,
21
+ kind: n,
22
+ effects: a,
23
+ events: i(t.events),
24
+ balanceChanges: Array.isArray(t.balanceChanges) ? t.balanceChanges : [],
25
+ objectChanges: Array.isArray(t.objectChanges) ? t.objectChanges : []
26
+ };
27
+ }
28
+ function o(n) {
29
+ const s = n.Transaction;
30
+ if (e(s))
31
+ return s;
32
+ const r = n.FailedTransaction;
33
+ return e(r) ? r : n;
34
+ }
35
+ function u(n) {
36
+ if (e(n.effects))
37
+ return n.effects;
38
+ if (e(n.status))
39
+ return {
40
+ status: n.status
41
+ };
42
+ }
43
+ function i(n) {
44
+ return Array.isArray(n) ? n.map((s) => e(s) ? {
45
+ ...s,
46
+ type: s.type ?? s.eventType,
47
+ parsedJson: s.parsedJson ?? s.json
48
+ } : s) : [];
49
+ }
50
+ function e(n) {
51
+ return typeof n == "object" && n !== null;
52
+ }
53
+ export {
54
+ c as defaultTransactionResponseOptions,
55
+ p as isSuccessfulTransaction,
56
+ f as mergeTransactionResponseOptions,
57
+ h as normalizeTransactionResult
58
+ };
59
+ //# sourceMappingURL=transaction-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-result.js","sources":["../src/transaction-result.ts"],"sourcesContent":["import type {\n NaviDryRunTransactionResult,\n NaviExecuteTransactionResult,\n NaviTransactionEffects,\n NaviTransactionEvent,\n NaviTransactionResponseOptions\n} from './types'\n\nexport const defaultTransactionResponseOptions: NaviTransactionResponseOptions = {\n showEffects: true,\n showEvents: true,\n showBalanceChanges: true,\n showObjectChanges: true\n}\n\nexport function mergeTransactionResponseOptions(\n options?: NaviTransactionResponseOptions\n): NaviTransactionResponseOptions {\n return {\n ...defaultTransactionResponseOptions,\n ...options\n }\n}\n\n/**\n * Whether a (normalized) transaction result succeeded.\n *\n * Handles both shapes: v1 JSON-RPC effects `status.status === 'success'` (string)\n * and Sui v2 Core `status.success === true` (boolean). Using only the v1 string\n * check makes success events silently never fire on the gRPC/Core path.\n */\nexport function isSuccessfulTransaction(result: {\n effects?: { status?: unknown } | null\n}): boolean {\n const status = result?.effects?.status as Record<string, unknown> | undefined\n return status?.status === 'success' || status?.success === true\n}\n\nexport function normalizeTransactionResult(\n kind: 'dryRun',\n result: unknown\n): NaviDryRunTransactionResult\nexport function normalizeTransactionResult(\n kind: 'execute',\n result: unknown\n): NaviExecuteTransactionResult\nexport function normalizeTransactionResult(\n kind: 'dryRun' | 'execute',\n result: unknown\n): NaviDryRunTransactionResult | NaviExecuteTransactionResult {\n const source = (result ?? {}) as Record<string, unknown>\n const raw = unwrapTransactionResult(source)\n const effects = normalizeEffects(raw)\n\n return {\n ...raw,\n kind,\n effects,\n events: normalizeEvents(raw.events),\n balanceChanges: Array.isArray(raw.balanceChanges) ? raw.balanceChanges : [],\n objectChanges: Array.isArray(raw.objectChanges) ? raw.objectChanges : []\n }\n}\n\nfunction unwrapTransactionResult(result: Record<string, unknown>) {\n const transaction = result.Transaction\n if (isRecord(transaction)) {\n return transaction\n }\n\n const failedTransaction = result.FailedTransaction\n if (isRecord(failedTransaction)) {\n return failedTransaction\n }\n\n return result\n}\n\nfunction normalizeEffects(raw: Record<string, unknown>): NaviTransactionEffects | undefined {\n if (isRecord(raw.effects)) {\n return raw.effects as NaviTransactionEffects\n }\n\n if (isRecord(raw.status)) {\n return {\n status: raw.status as NaviTransactionEffects['status']\n }\n }\n\n return undefined\n}\n\nfunction normalizeEvents(events: unknown): NaviTransactionEvent[] {\n if (!Array.isArray(events)) {\n return []\n }\n\n return events.map((event) => {\n if (!isRecord(event)) {\n return event\n }\n\n return {\n ...event,\n type: event.type ?? event.eventType,\n parsedJson: event.parsedJson ?? event.json\n }\n }) as NaviTransactionEvent[]\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\n}\n"],"names":["defaultTransactionResponseOptions","mergeTransactionResponseOptions","options","isSuccessfulTransaction","result","status","normalizeTransactionResult","kind","raw","unwrapTransactionResult","effects","normalizeEffects","normalizeEvents","transaction","isRecord","failedTransaction","events","event","value"],"mappings":"AAQO,MAAMA,IAAoE;AAAA,EAC/E,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,oBAAoB;AAAA,EACpB,mBAAmB;AACrB;AAEO,SAASC,EACdC,GACgC;AAChC,SAAO;AAAA,IACL,GAAGF;AAAA,IACH,GAAGE;AAAA,EAAA;AAEP;AASO,SAASC,EAAwBC,GAE5B;AACV,QAAMC,IAASD,GAAQ,SAAS;AAChC,SAAOC,GAAQ,WAAW,aAAaA,GAAQ,YAAY;AAC7D;AAUO,SAASC,EACdC,GACAH,GAC4D;AAE5D,QAAMI,IAAMC,EADIL,KAAU,CAAA,CACgB,GACpCM,IAAUC,EAAiBH,CAAG;AAEpC,SAAO;AAAA,IACL,GAAGA;AAAA,IACH,MAAAD;AAAA,IACA,SAAAG;AAAA,IACA,QAAQE,EAAgBJ,EAAI,MAAM;AAAA,IAClC,gBAAgB,MAAM,QAAQA,EAAI,cAAc,IAAIA,EAAI,iBAAiB,CAAA;AAAA,IACzE,eAAe,MAAM,QAAQA,EAAI,aAAa,IAAIA,EAAI,gBAAgB,CAAA;AAAA,EAAC;AAE3E;AAEA,SAASC,EAAwBL,GAAiC;AAChE,QAAMS,IAAcT,EAAO;AAC3B,MAAIU,EAASD,CAAW;AACtB,WAAOA;AAGT,QAAME,IAAoBX,EAAO;AACjC,SAAIU,EAASC,CAAiB,IACrBA,IAGFX;AACT;AAEA,SAASO,EAAiBH,GAAkE;AAC1F,MAAIM,EAASN,EAAI,OAAO;AACtB,WAAOA,EAAI;AAGb,MAAIM,EAASN,EAAI,MAAM;AACrB,WAAO;AAAA,MACL,QAAQA,EAAI;AAAA,IAAA;AAKlB;AAEA,SAASI,EAAgBI,GAAyC;AAChE,SAAK,MAAM,QAAQA,CAAM,IAIlBA,EAAO,IAAI,CAACC,MACZH,EAASG,CAAK,IAIZ;AAAA,IACL,GAAGA;AAAA,IACH,MAAMA,EAAM,QAAQA,EAAM;AAAA,IAC1B,YAAYA,EAAM,cAAcA,EAAM;AAAA,EAAA,IAN/BA,CAQV,IAbQ,CAAA;AAcX;AAEA,SAASH,EAASI,GAAkD;AAClE,SAAO,OAAOA,KAAU,YAAYA,MAAU;AAChD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naviprotocol/wallet-client",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "NAVI Wallet Client",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,8 +15,8 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/naviprotocol/naviprotocol-monorepo.git"
17
17
  },
18
- "main": "dist/index.esm.js",
19
- "module": "dist/index.esm.js",
18
+ "main": "dist/index.js",
19
+ "module": "dist/index.js",
20
20
  "types": "dist/index.d.ts",
21
21
  "source": "src/index.ts",
22
22
  "files": [
@@ -27,8 +27,8 @@
27
27
  "./package.json": "./package.json",
28
28
  ".": {
29
29
  "types": "./dist/index.d.ts",
30
- "import": "./dist/index.esm.js",
31
- "default": "./dist/index.esm.js"
30
+ "import": "./dist/index.js",
31
+ "default": "./dist/index.js"
32
32
  }
33
33
  },
34
34
  "publishConfig": {
@@ -43,8 +43,8 @@
43
43
  "date-fns": "4.1.0",
44
44
  "mitt": "3.0.1",
45
45
  "shio-sdk": "1.0.9",
46
- "@naviprotocol/astros-aggregator-sdk": "2.0.4",
47
- "@naviprotocol/lending": "2.0.6"
46
+ "@naviprotocol/astros-aggregator-sdk": "2.0.5",
47
+ "@naviprotocol/lending": "2.0.7"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@mysten/bcs": "2.0.1",