@upshiftfinance/sdk 0.2.0 → 0.4.0

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 (55) hide show
  1. package/README.md +1 -1
  2. package/lib/abis/KycRegistry.d.ts +109 -0
  3. package/lib/abis/KycRegistry.js +73 -0
  4. package/lib/abis/index.d.ts +1 -0
  5. package/lib/abis/index.js +1 -0
  6. package/lib/adapters/sui/actions.d.ts +174 -0
  7. package/lib/adapters/sui/actions.js +382 -0
  8. package/lib/adapters/sui/getters.d.ts +166 -0
  9. package/lib/adapters/sui/getters.js +391 -0
  10. package/lib/adapters/sui/index.d.ts +95 -2
  11. package/lib/adapters/sui/index.js +92 -2
  12. package/lib/adapters/sui/targets.d.ts +35 -0
  13. package/lib/adapters/sui/targets.js +35 -0
  14. package/lib/core/analytics/method-taxonomy.d.ts +1 -1
  15. package/lib/core/analytics/method-taxonomy.js +7 -0
  16. package/lib/core/analytics/version.d.ts +1 -1
  17. package/lib/core/analytics/version.js +1 -1
  18. package/lib/core/constants/core.d.ts +5 -0
  19. package/lib/core/constants/core.js +5 -0
  20. package/lib/core/constants/kyc.d.ts +9 -0
  21. package/lib/core/constants/kyc.js +12 -0
  22. package/lib/core/constants/swap-router.js +24 -0
  23. package/lib/core/constants/web3.d.ts +2 -2
  24. package/lib/core/constants/web3.js +9 -2
  25. package/lib/core/errors/index.d.ts +77 -1
  26. package/lib/core/errors/index.js +94 -1
  27. package/lib/core/fetcher.d.ts +5 -0
  28. package/lib/core/fetcher.js +1 -1
  29. package/lib/core/helpers/chain-support.d.ts +2 -2
  30. package/lib/core/helpers/chain-support.js +3 -3
  31. package/lib/core/helpers/kyc.d.ts +47 -0
  32. package/lib/core/helpers/kyc.js +111 -0
  33. package/lib/core/helpers/revert-decode.js +3 -2
  34. package/lib/core/index.d.ts +2 -0
  35. package/lib/core/index.js +2 -0
  36. package/lib/main.d.ts +31 -3
  37. package/lib/main.js +32 -0
  38. package/lib/modules/api/kyc.d.ts +4 -0
  39. package/lib/modules/api/kyc.js +148 -0
  40. package/lib/modules/api/main.d.ts +63 -1
  41. package/lib/modules/api/main.js +64 -0
  42. package/lib/modules/vaults/getters.d.ts +3 -1
  43. package/lib/modules/vaults/getters.js +53 -9
  44. package/lib/modules/vaults/main.d.ts +39 -3
  45. package/lib/modules/vaults/main.js +79 -5
  46. package/lib/modules/vaults/types.d.ts +7 -1
  47. package/lib/modules/vaults/utils.js +4 -1
  48. package/lib/sdk.d.ts +15131 -14393
  49. package/lib/types/index.d.ts +1 -0
  50. package/lib/types/index.js +1 -0
  51. package/lib/types/kyc.d.ts +61 -0
  52. package/lib/types/kyc.js +3 -0
  53. package/lib/types/vaults.d.ts +2 -0
  54. package/lib/types/webserver.d.ts +5 -0
  55. package/package.json +1 -1
@@ -0,0 +1,391 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.decodeSuiUint = decodeSuiUint;
37
+ exports.decodeSuiBool = decodeSuiBool;
38
+ exports.parseInstantRedemptionFeeBps = parseInstantRedemptionFeeBps;
39
+ exports.suiConfigForNetwork = suiConfigForNetwork;
40
+ exports.readSuiVaultState = readSuiVaultState;
41
+ exports.previewSuiDeposit = previewSuiDeposit;
42
+ exports.previewSuiRedemption = previewSuiRedemption;
43
+ exports.getSuiShareBalance = getSuiShareBalance;
44
+ exports.suiVaultRefFromRow = suiVaultRefFromRow;
45
+ exports.buildSuiVault = buildSuiVault;
46
+ exports.getSuiVault = getSuiVault;
47
+ const core_1 = require("../../core");
48
+ const chain_address_1 = require("../../core/helpers/chain-address");
49
+ const utils_1 = require("../../modules/vaults/utils");
50
+ const client_1 = require("./client");
51
+ const constants_1 = require("./constants");
52
+ const targets_1 = require("./targets");
53
+ /** Simulations need a sender; no signature or gas is involved. */
54
+ const SIMULATION_SENDER = `0x${'0'.repeat(64)}`;
55
+ /** The contract's "no limit" value for `u64` caps. */
56
+ const U64_MAX = 2n ** 64n - 1n;
57
+ /** Read-only targets {@link readSuiVaultState} calls, in command order. */
58
+ const STATE_READS = [
59
+ 'totalAssets',
60
+ 'totalSupply',
61
+ 'sharePrice',
62
+ 'decimals',
63
+ 'paused',
64
+ 'queueAttached',
65
+ 'minDeposit',
66
+ 'depositCap',
67
+ 'maxDepositAmount',
68
+ 'maxWithdrawalAmount',
69
+ ];
70
+ /** Targets that also take the Registry after the vault. */
71
+ const NEEDS_REGISTRY = new Set(['totalAssets', 'sharePrice']);
72
+ /**
73
+ * Decode a little-endian BCS unsigned integer of `size` bytes.
74
+ * @internal
75
+ */
76
+ function decodeSuiUint(bytes, size) {
77
+ if (bytes.length !== size) {
78
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `Sui read: expected a ${size}-byte integer, got ${bytes.length} bytes.`);
79
+ }
80
+ let value = 0n;
81
+ for (let i = size - 1; i >= 0; i -= 1) {
82
+ value = (value << 8n) | BigInt(bytes[i]);
83
+ }
84
+ return value;
85
+ }
86
+ /**
87
+ * Decode a BCS `bool`.
88
+ * @internal
89
+ */
90
+ function decodeSuiBool(bytes) {
91
+ if (bytes.length !== 1 || bytes[0] > 1) {
92
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', 'Sui read: expected a BCS bool.');
93
+ }
94
+ return bytes[0] === 1;
95
+ }
96
+ /**
97
+ * Read the instant-redemption fee from the vault object's JSON fields: the fee
98
+ * sits in a nested struct that a transaction cannot return.
99
+ * @internal
100
+ */
101
+ function parseInstantRedemptionFeeBps(json) {
102
+ const raw = json
103
+ ?.fee_state?.instant_redemption_fee_bps;
104
+ const text = typeof raw === 'number' ? String(raw) : raw;
105
+ if (typeof text !== 'string' || !/^\d+$/.test(text)) {
106
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', 'Sui read: vault object has no fee_state.instant_redemption_fee_bps.');
107
+ }
108
+ return Number(text);
109
+ }
110
+ /**
111
+ * The `sui` config to use for a vault on `network`: the consumer's config when
112
+ * it is for that network, else the network alone (built-in endpoint and
113
+ * contract IDs). A testnet override must never serve a mainnet vault.
114
+ * @internal
115
+ */
116
+ function suiConfigForNetwork(network, sui) {
117
+ return (sui?.network ?? 'mainnet') === network
118
+ ? { ...sui, network }
119
+ : { network };
120
+ }
121
+ function assertVaultRef(ref, method) {
122
+ if (!(0, chain_address_1.isSuiAddress)(ref.vaultId)) {
123
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `${method}: vaultId must be a Sui object ID (0x + 64 hex chars).`);
124
+ }
125
+ }
126
+ /**
127
+ * Simulate read-only vault calls in one transaction and return each call's
128
+ * return values (BCS bytes), in order.
129
+ */
130
+ async function simulateVaultReads(ref, sui, calls) {
131
+ const config = suiConfigForNetwork(ref.network, sui);
132
+ const contracts = (0, targets_1.resolveSuiVaultContracts)(config);
133
+ const { Transaction: SuiTransaction } = await Promise.resolve().then(() => __importStar(require('@mysten/sui/transactions')));
134
+ const typeArguments = (0, targets_1.suiVaultTypeArguments)(ref.assetCoinType, ref.shareCoinType);
135
+ return (0, client_1.withSuiClient)((0, client_1.resolveSuiNetworkConfig)(config), async (client) => {
136
+ // Built per attempt: building resolves object versions against this client.
137
+ const tx = new SuiTransaction();
138
+ tx.setSender(SIMULATION_SENDER);
139
+ for (const call of calls) {
140
+ tx.moveCall({
141
+ target: (0, targets_1.suiMoveCallTarget)(contracts, call.target),
142
+ typeArguments,
143
+ arguments: [
144
+ tx.object(ref.vaultId),
145
+ ...(call.registry ? [tx.object(contracts.registryId)] : []),
146
+ ...(call.pure?.(tx) ?? []),
147
+ ],
148
+ });
149
+ }
150
+ const result = await client.core.simulateTransaction({
151
+ transaction: tx,
152
+ include: { commandResults: true, effects: true },
153
+ });
154
+ if (result.$kind !== 'Transaction') {
155
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', 'Sui read: vault simulation failed — check the vault ID, its coin types and the contract IDs for this network.', {
156
+ context: {
157
+ network: ref.network,
158
+ status: JSON.stringify(result.FailedTransaction?.effects?.status),
159
+ },
160
+ });
161
+ }
162
+ return result.commandResults.map((c) => c.returnValues.map((v) => v.bcs));
163
+ });
164
+ }
165
+ /**
166
+ * Read a vault's on-chain state.
167
+ *
168
+ * RPC cost: two requests, run in parallel: one transaction simulation and one
169
+ * object read. `getVaults` makes these two per Sui vault.
170
+ *
171
+ * @param ref - The vault and its coin types and network.
172
+ * @param sui - The SDK's `sui` config; applied only when its network matches
173
+ * `ref.network`.
174
+ * @returns The vault's state; see {@link ISuiVaultState} for units.
175
+ * @throws {@link UpshiftValidationError} (`INVALID_ADDRESS`) for a malformed
176
+ * vault ID, (`INVALID_INPUT`) when the contract IDs for the network are not
177
+ * known or the simulation aborts (wrong vault, coin types or package).
178
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
179
+ * @example
180
+ * ```ts
181
+ * const state = await readSuiVaultState(
182
+ * { vaultId, assetCoinType, shareCoinType, network: 'testnet' },
183
+ * { network: 'testnet', packageId, originalPackageId, registryId },
184
+ * );
185
+ * ```
186
+ */
187
+ async function readSuiVaultState(ref, sui) {
188
+ assertVaultRef(ref, 'readSuiVaultState');
189
+ const config = suiConfigForNetwork(ref.network, sui);
190
+ const [values, fee] = await Promise.all([
191
+ simulateVaultReads(ref, sui, STATE_READS.map((target) => ({
192
+ target,
193
+ registry: NEEDS_REGISTRY.has(target),
194
+ }))),
195
+ (0, client_1.withSuiClient)((0, client_1.resolveSuiNetworkConfig)(config), (client) => client.core.getObject({ objectId: ref.vaultId, include: { json: true } })),
196
+ ]);
197
+ const at = (i) => {
198
+ const bytes = values[i]?.[0];
199
+ if (!bytes) {
200
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `Sui read: ${STATE_READS[i]} returned no value.`);
201
+ }
202
+ return bytes;
203
+ };
204
+ return {
205
+ totalAssets: decodeSuiUint(at(0), 16),
206
+ totalSupply: decodeSuiUint(at(1), 8),
207
+ sharePrice: decodeSuiUint(at(2), 16),
208
+ decimals: Number(decodeSuiUint(at(3), 1)),
209
+ paused: decodeSuiBool(at(4)),
210
+ queueAttached: decodeSuiBool(at(5)),
211
+ minDeposit: decodeSuiUint(at(6), 8),
212
+ depositCap: decodeSuiUint(at(7), 8),
213
+ maxDepositAmount: decodeSuiUint(at(8), 8),
214
+ maxWithdrawalAmount: decodeSuiUint(at(9), 8),
215
+ instantRedemptionFeeBps: parseInstantRedemptionFeeBps(fee.object.json),
216
+ };
217
+ }
218
+ /**
219
+ * Shares a deposit would mint at the current price. Limits are not checked.
220
+ *
221
+ * RPC cost: one transaction simulation.
222
+ *
223
+ * @param ref - The vault and its coin types and network.
224
+ * @param assets - Deposit amount in asset base units.
225
+ * @param sui - The SDK's `sui` config; applied only for `ref.network`.
226
+ * @returns Shares in share base units.
227
+ * @throws {@link UpshiftValidationError} for a malformed vault ID, a negative
228
+ * or out-of-range amount, unknown contract IDs or an aborted simulation.
229
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
230
+ */
231
+ async function previewSuiDeposit(ref, assets, sui) {
232
+ assertVaultRef(ref, 'previewSuiDeposit');
233
+ assertU64(assets, 'previewSuiDeposit', 'assets');
234
+ const [returned] = await simulateVaultReads(ref, sui, [
235
+ {
236
+ target: 'previewDeposit',
237
+ registry: true,
238
+ pure: (tx) => [tx.pure.u64(assets)],
239
+ },
240
+ ]);
241
+ return decodeSuiUint(returned[0], 8);
242
+ }
243
+ /**
244
+ * Assets a redemption of `shares` would pay at the current price.
245
+ *
246
+ * RPC cost: one transaction simulation.
247
+ *
248
+ * @param ref - The vault and its coin types and network.
249
+ * @param shares - Shares to redeem, in share base units.
250
+ * @param isInstant - `true` for instant `redeem` (charges the instant fee),
251
+ * `false` for a queued withdrawal (no fee).
252
+ * @param sui - The SDK's `sui` config; applied only for `ref.network`.
253
+ * @returns `gross` and `net` (after the instant fee) in asset base units.
254
+ * @throws {@link UpshiftValidationError} for a malformed vault ID, a negative
255
+ * or out-of-range amount, unknown contract IDs or an aborted simulation.
256
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
257
+ */
258
+ async function previewSuiRedemption(ref, shares, isInstant, sui) {
259
+ assertVaultRef(ref, 'previewSuiRedemption');
260
+ assertU64(shares, 'previewSuiRedemption', 'shares');
261
+ const [returned] = await simulateVaultReads(ref, sui, [
262
+ {
263
+ target: 'previewRedemption',
264
+ registry: true,
265
+ pure: (tx) => [tx.pure.u64(shares), tx.pure.bool(isInstant)],
266
+ },
267
+ ]);
268
+ return {
269
+ gross: decodeSuiUint(returned[0], 8),
270
+ net: decodeSuiUint(returned[1], 8),
271
+ };
272
+ }
273
+ function assertU64(value, method, name) {
274
+ if (typeof value !== 'bigint' || value < 0n || value > U64_MAX) {
275
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `${method}: ${name} must be a bigint between 0 and 2^64 - 1.`);
276
+ }
277
+ }
278
+ /**
279
+ * A wallet's balance of a share coin: coin objects plus the address balance.
280
+ *
281
+ * RPC cost: one balance read.
282
+ *
283
+ * @param owner - Wallet address (`0x` + 64 hex chars).
284
+ * @param shareCoinType - Move type of the vault's share coin.
285
+ * @param network - Network to read.
286
+ * @param sui - The SDK's `sui` config; applied only for `network`.
287
+ * @returns Shares in share base units.
288
+ * @throws {@link UpshiftValidationError} (`INVALID_ADDRESS`) for a malformed
289
+ * owner.
290
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
291
+ */
292
+ async function getSuiShareBalance(owner, shareCoinType, network, sui) {
293
+ if (!(0, chain_address_1.isSuiAddress)(owner)) {
294
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', 'getSuiShareBalance: owner must be a Sui address (0x + 64 hex chars).');
295
+ }
296
+ const config = suiConfigForNetwork(network, sui);
297
+ const { balance } = await (0, client_1.withSuiClient)((0, client_1.resolveSuiNetworkConfig)(config), (client) => client.core.getBalance({ owner, coinType: shareCoinType }));
298
+ return BigInt(balance.balance);
299
+ }
300
+ /**
301
+ * The vault reference for a backend row, or `null` when the row has no usable
302
+ * `sui_vault_metadata`.
303
+ * @internal
304
+ */
305
+ function suiVaultRefFromRow(row) {
306
+ const meta = row.sui_vault_metadata;
307
+ if (!meta?.share_coin_type || !meta.deposit_coin_type)
308
+ return null;
309
+ if (meta.network_name !== 'mainnet' && meta.network_name !== 'testnet') {
310
+ return null;
311
+ }
312
+ return {
313
+ vaultId: row.address,
314
+ assetCoinType: meta.deposit_coin_type,
315
+ shareCoinType: meta.share_coin_type,
316
+ network: meta.network_name,
317
+ };
318
+ }
319
+ /**
320
+ * Build the SDK's `IVault` for a Sui vault from its backend row and, when the
321
+ * read succeeded, its on-chain state. Without state, total assets fall back
322
+ * to the backend's `latest_reported_tvl`, supply to zero, and the vault is
323
+ * marked deposit-paused so no deposit is offered on unread state.
324
+ * @internal
325
+ */
326
+ function buildSuiVault(row, state) {
327
+ const meta = row.sui_vault_metadata;
328
+ const decimals = state?.decimals ?? meta?.deposit_token_decimals ?? 0;
329
+ const vault = (0, utils_1.buildBackendVault)(row, {
330
+ chainId: constants_1.SUI_CHAIN_ID,
331
+ version: 'sui-0',
332
+ name: row.vault_name || 'Sui Vault',
333
+ totalAssets: state
334
+ ? (0, core_1.toNormalizedBn)(state.totalAssets, decimals)
335
+ : (0, utils_1.backendTvlToNormalizedBn)(row.latest_reported_tvl, decimals),
336
+ totalSupply: (0, core_1.toNormalizedBn)(state?.totalSupply ?? 0n, decimals),
337
+ depositAssets: [
338
+ {
339
+ address: meta?.deposit_coin_type ?? '',
340
+ symbol: meta?.deposit_token_symbol ?? 'UNKNOWN',
341
+ decimals,
342
+ },
343
+ ],
344
+ receipt: {
345
+ address: meta?.share_coin_type ?? '',
346
+ symbol: row.receipt_token_symbol || 'UNKNOWN',
347
+ decimals,
348
+ },
349
+ isDepositPaused: !state || state.paused || !meta?.deposit_coin_type,
350
+ isWithdrawalPaused: state?.paused ?? false,
351
+ });
352
+ // u64::MAX is the contract's "no cap"; leave the field unset for it.
353
+ if (state && state.depositCap !== U64_MAX) {
354
+ vault.depositCap = (0, core_1.toNormalizedBn)(state.depositCap, decimals);
355
+ }
356
+ return vault;
357
+ }
358
+ /**
359
+ * Build a Sui vault's `IVault` from its backend row plus on-chain state.
360
+ *
361
+ * A failed read (unknown contract IDs, every endpoint down, an aborted
362
+ * simulation) does not fail the call: the vault is built from the backend row
363
+ * alone (see {@link buildSuiVault}) and a warning is logged.
364
+ *
365
+ * RPC cost: as {@link readSuiVaultState}.
366
+ *
367
+ * @param row - Backend `tokenized_vault` row with `sui_vault_metadata`.
368
+ * @param options - Vault options; `options.sui` carries the SDK's `sui` config.
369
+ * @returns The vault.
370
+ * @throws {@link UpshiftValidationError} (`INVALID_INPUT`) when the row has no
371
+ * usable `sui_vault_metadata` (e.g. a legacy Ember/Gamma Sui vault).
372
+ */
373
+ async function getSuiVault(row, options) {
374
+ const ref = suiVaultRefFromRow(row);
375
+ if (!ref) {
376
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', 'getSuiVault: not an Upshift Sui vault — the backend row has no usable sui_vault_metadata.', { context: { vault: row.address } });
377
+ }
378
+ let state = null;
379
+ try {
380
+ state = await readSuiVaultState(ref, options?.sui);
381
+ }
382
+ catch (err) {
383
+ core_1.Logger.log.warn('getSuiVault', 'On-chain read failed — using backend values', {
384
+ vault: row.address,
385
+ network: ref.network,
386
+ error: err instanceof Error ? err.message : String(err),
387
+ });
388
+ }
389
+ return buildSuiVault(row, state);
390
+ }
391
+ //# sourceMappingURL=getters.js.map
@@ -4,8 +4,10 @@
4
4
  * @module SuiAdapter
5
5
  */
6
6
  import type { ISuiConfig, ISuiNetwork } from '../../types';
7
+ import * as SuiActions from './actions';
7
8
  import * as SuiClient from './client';
8
9
  import * as SuiConstants from './constants';
10
+ import * as SuiGetters from './getters';
9
11
  import * as SuiTargets from './targets';
10
12
  import * as SuiUtils from './utils';
11
13
  export declare const Sui: {
@@ -13,12 +15,28 @@ export declare const Sui: {
13
15
  constants: typeof SuiConstants;
14
16
  client: typeof SuiClient;
15
17
  targets: typeof SuiTargets;
18
+ getters: typeof SuiGetters;
19
+ actions: typeof SuiActions;
16
20
  };
21
+ /**
22
+ * A Sui vault as the adapter methods take it; the network is the adapter's.
23
+ * From an `IVault`: `vaultId` is `address`, `assetCoinType` is
24
+ * `depositAssets[0].address`, `shareCoinType` is `receipt.address`.
25
+ */
26
+ export interface ISuiAdapterVault {
27
+ /** Vault object ID (`0x` + 64 hex chars). */
28
+ vaultId: string;
29
+ /** Move type of the deposit coin. */
30
+ assetCoinType: string;
31
+ /** Move type of the vault's share coin. */
32
+ shareCoinType: string;
33
+ }
17
34
  /**
18
35
  * Sui Adapter for Upshift SDK.
19
36
  *
20
- * Holds the Sui configuration passed to `new UpshiftSDK({ sui })` and the Sui
21
- * chain-identity helpers. It makes no network calls.
37
+ * Holds the Sui configuration passed to `new UpshiftSDK({ sui })`, the Sui
38
+ * chain-identity helpers, and the vault deposit / instant-redeem builders.
39
+ * Transactions run on the configured network.
22
40
  *
23
41
  * @example
24
42
  * ```ts
@@ -53,5 +71,80 @@ declare class SuiAdapter {
53
71
  * @returns `true` only for `-2`.
54
72
  */
55
73
  isSuiVault(chainId: number): boolean;
74
+ /**
75
+ * Build an unsigned deposit on the configured network: charge the
76
+ * management fee, deposit with a minimum share amount, send the shares to
77
+ * the sender. Dry-runs it first, so a vault that would reject it fails here.
78
+ *
79
+ * RPC cost: one dry run (plus the coin lookup it needs).
80
+ *
81
+ * @param params - The vault, `amount` in asset base units, the `sender`, and
82
+ * an optional `minSharesOut` (defaults to the dry run's exact preview).
83
+ * @returns The unsigned transaction for the sender's wallet, the shares the
84
+ * dry run minted, and the minimum it enforces.
85
+ * @throws {@link UpshiftValidationError} for malformed input, unknown
86
+ * contract IDs, or a transaction that cannot be built.
87
+ * @throws {@link UpshiftVaultAbortError} when the vault would reject it.
88
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
89
+ * @example
90
+ * ```ts
91
+ * const { transaction } = await sdk.sui.vaultDeposit({
92
+ * vaultId: vault.address,
93
+ * assetCoinType: vault.depositAssets[0].address,
94
+ * shareCoinType: vault.receipt.address,
95
+ * amount: 1_000_000n,
96
+ * sender: account.address,
97
+ * });
98
+ * await dAppKit.signAndExecuteTransaction({ transaction });
99
+ * ```
100
+ */
101
+ vaultDeposit(params: ISuiAdapterVault & {
102
+ amount: bigint;
103
+ sender: string;
104
+ minSharesOut?: bigint;
105
+ }): Promise<SuiActions.ISuiDepositTransaction>;
106
+ /**
107
+ * Build an unsigned instant redemption on the configured network: redeem
108
+ * shares with a minimum net asset amount, send the assets to the sender.
109
+ * Dry-runs it first; a vault with a withdrawal queue attached fails with
110
+ * `queue_attached`.
111
+ *
112
+ * Side effect on failure: a redemption the vault rejects is reported to that
113
+ * vault's curator (fire-and-forget; see `monitoring.curatorAlerts`).
114
+ *
115
+ * RPC cost: one dry run (plus the coin lookup it needs).
116
+ *
117
+ * @param params - The vault, `shares` in share base units, the `sender`, and
118
+ * an optional `minAssetsOut` net of the instant fee (defaults to the dry
119
+ * run's exact preview).
120
+ * @returns The unsigned transaction, the dry run's gross and net assets, and
121
+ * the minimum it enforces.
122
+ * @throws {@link UpshiftValidationError} for malformed input, unknown
123
+ * contract IDs, or a transaction that cannot be built.
124
+ * @throws {@link UpshiftVaultAbortError} when the vault would reject it.
125
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
126
+ */
127
+ vaultRedeem(params: ISuiAdapterVault & {
128
+ shares: bigint;
129
+ sender: string;
130
+ minAssetsOut?: bigint;
131
+ }): Promise<SuiActions.ISuiRedeemTransaction>;
132
+ /**
133
+ * Execute a wallet-signed transaction on the configured network and wait
134
+ * until it is indexed. Not needed when the wallet executes the transaction
135
+ * itself (e.g. dApp Kit's `signAndExecuteTransaction`).
136
+ *
137
+ * Side effect on failure: a failed instant redemption is reported to that
138
+ * vault's curator with its digest (fire-and-forget).
139
+ *
140
+ * @param signed - `{ bytes, signature }` from the wallet's `signTransaction`.
141
+ * @returns The transaction digest.
142
+ * @throws {@link UpshiftVaultAbortError} when the vault aborted it on chain.
143
+ * @throws {@link UpshiftSDKError} (`UNKNOWN`) when it failed otherwise.
144
+ * @throws {@link UpshiftTransactionError} when it executed but was not
145
+ * indexed in time.
146
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
147
+ */
148
+ executeTransaction(signed: SuiActions.ISuiSignedTransaction): Promise<string>;
56
149
  }
57
150
  export default SuiAdapter;
@@ -34,8 +34,10 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Sui = void 0;
37
+ const SuiActions = __importStar(require("./actions"));
37
38
  const SuiClient = __importStar(require("./client"));
38
39
  const SuiConstants = __importStar(require("./constants"));
40
+ const SuiGetters = __importStar(require("./getters"));
39
41
  const SuiTargets = __importStar(require("./targets"));
40
42
  const SuiUtils = __importStar(require("./utils"));
41
43
  exports.Sui = {
@@ -43,12 +45,15 @@ exports.Sui = {
43
45
  constants: SuiConstants,
44
46
  client: SuiClient,
45
47
  targets: SuiTargets,
48
+ getters: SuiGetters,
49
+ actions: SuiActions,
46
50
  };
47
51
  /**
48
52
  * Sui Adapter for Upshift SDK.
49
53
  *
50
- * Holds the Sui configuration passed to `new UpshiftSDK({ sui })` and the Sui
51
- * chain-identity helpers. It makes no network calls.
54
+ * Holds the Sui configuration passed to `new UpshiftSDK({ sui })`, the Sui
55
+ * chain-identity helpers, and the vault deposit / instant-redeem builders.
56
+ * Transactions run on the configured network.
52
57
  *
53
58
  * @example
54
59
  * ```ts
@@ -95,6 +100,91 @@ class SuiAdapter {
95
100
  isSuiVault(chainId) {
96
101
  return SuiUtils.isSuiVault(chainId);
97
102
  }
103
+ /**
104
+ * Build an unsigned deposit on the configured network: charge the
105
+ * management fee, deposit with a minimum share amount, send the shares to
106
+ * the sender. Dry-runs it first, so a vault that would reject it fails here.
107
+ *
108
+ * RPC cost: one dry run (plus the coin lookup it needs).
109
+ *
110
+ * @param params - The vault, `amount` in asset base units, the `sender`, and
111
+ * an optional `minSharesOut` (defaults to the dry run's exact preview).
112
+ * @returns The unsigned transaction for the sender's wallet, the shares the
113
+ * dry run minted, and the minimum it enforces.
114
+ * @throws {@link UpshiftValidationError} for malformed input, unknown
115
+ * contract IDs, or a transaction that cannot be built.
116
+ * @throws {@link UpshiftVaultAbortError} when the vault would reject it.
117
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
118
+ * @example
119
+ * ```ts
120
+ * const { transaction } = await sdk.sui.vaultDeposit({
121
+ * vaultId: vault.address,
122
+ * assetCoinType: vault.depositAssets[0].address,
123
+ * shareCoinType: vault.receipt.address,
124
+ * amount: 1_000_000n,
125
+ * sender: account.address,
126
+ * });
127
+ * await dAppKit.signAndExecuteTransaction({ transaction });
128
+ * ```
129
+ */
130
+ async vaultDeposit(params) {
131
+ const { amount, sender, minSharesOut, ...vault } = params;
132
+ return SuiActions.buildSuiDepositTransaction({
133
+ vault: { ...vault, network: this.network },
134
+ amount,
135
+ sender,
136
+ minSharesOut,
137
+ }, this._config);
138
+ }
139
+ /**
140
+ * Build an unsigned instant redemption on the configured network: redeem
141
+ * shares with a minimum net asset amount, send the assets to the sender.
142
+ * Dry-runs it first; a vault with a withdrawal queue attached fails with
143
+ * `queue_attached`.
144
+ *
145
+ * Side effect on failure: a redemption the vault rejects is reported to that
146
+ * vault's curator (fire-and-forget; see `monitoring.curatorAlerts`).
147
+ *
148
+ * RPC cost: one dry run (plus the coin lookup it needs).
149
+ *
150
+ * @param params - The vault, `shares` in share base units, the `sender`, and
151
+ * an optional `minAssetsOut` net of the instant fee (defaults to the dry
152
+ * run's exact preview).
153
+ * @returns The unsigned transaction, the dry run's gross and net assets, and
154
+ * the minimum it enforces.
155
+ * @throws {@link UpshiftValidationError} for malformed input, unknown
156
+ * contract IDs, or a transaction that cannot be built.
157
+ * @throws {@link UpshiftVaultAbortError} when the vault would reject it.
158
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
159
+ */
160
+ async vaultRedeem(params) {
161
+ const { shares, sender, minAssetsOut, ...vault } = params;
162
+ return SuiActions.buildSuiRedeemTransaction({
163
+ vault: { ...vault, network: this.network },
164
+ shares,
165
+ sender,
166
+ minAssetsOut,
167
+ }, this._config);
168
+ }
169
+ /**
170
+ * Execute a wallet-signed transaction on the configured network and wait
171
+ * until it is indexed. Not needed when the wallet executes the transaction
172
+ * itself (e.g. dApp Kit's `signAndExecuteTransaction`).
173
+ *
174
+ * Side effect on failure: a failed instant redemption is reported to that
175
+ * vault's curator with its digest (fire-and-forget).
176
+ *
177
+ * @param signed - `{ bytes, signature }` from the wallet's `signTransaction`.
178
+ * @returns The transaction digest.
179
+ * @throws {@link UpshiftVaultAbortError} when the vault aborted it on chain.
180
+ * @throws {@link UpshiftSDKError} (`UNKNOWN`) when it failed otherwise.
181
+ * @throws {@link UpshiftTransactionError} when it executed but was not
182
+ * indexed in time.
183
+ * @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
184
+ */
185
+ async executeTransaction(signed) {
186
+ return SuiActions.submitSuiTransaction(signed, this.network, this._config);
187
+ }
98
188
  }
99
189
  exports.default = SuiAdapter;
100
190
  //# sourceMappingURL=index.js.map
@@ -107,6 +107,41 @@ export declare const SUI_VAULT_TARGETS: {
107
107
  readonly function: "preview_redemption";
108
108
  readonly params: readonly ["&Vault<Asset, Share>", "&Registry", "u64", "bool"];
109
109
  };
110
+ readonly decimals: {
111
+ readonly module: "vault";
112
+ readonly function: "decimals";
113
+ readonly params: readonly ["&Vault<Asset, Share>"];
114
+ };
115
+ readonly paused: {
116
+ readonly module: "vault";
117
+ readonly function: "paused";
118
+ readonly params: readonly ["&Vault<Asset, Share>"];
119
+ };
120
+ readonly queueAttached: {
121
+ readonly module: "vault";
122
+ readonly function: "queue_attached";
123
+ readonly params: readonly ["&Vault<Asset, Share>"];
124
+ };
125
+ readonly minDeposit: {
126
+ readonly module: "vault";
127
+ readonly function: "min_deposit";
128
+ readonly params: readonly ["&Vault<Asset, Share>"];
129
+ };
130
+ readonly depositCap: {
131
+ readonly module: "vault";
132
+ readonly function: "deposit_cap";
133
+ readonly params: readonly ["&Vault<Asset, Share>"];
134
+ };
135
+ readonly maxDepositAmount: {
136
+ readonly module: "vault";
137
+ readonly function: "max_deposit_amount";
138
+ readonly params: readonly ["&Vault<Asset, Share>"];
139
+ };
140
+ readonly maxWithdrawalAmount: {
141
+ readonly module: "vault";
142
+ readonly function: "max_withdrawal_amount";
143
+ readonly params: readonly ["&Vault<Asset, Share>"];
144
+ };
110
145
  };
111
146
  /** Name of a package function the SDK calls; a key of {@link SUI_VAULT_TARGETS}. */
112
147
  export type ISuiVaultTarget = keyof typeof SUI_VAULT_TARGETS;