@upshiftfinance/sdk 0.3.0 → 0.5.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.
- package/README.md +6 -2
- package/esm/index.d.mts +15 -0
- package/esm/index.mjs +18 -0
- package/lib/abis/KycRegistry.d.ts +109 -0
- package/lib/abis/KycRegistry.js +73 -0
- package/lib/abis/index.d.ts +1 -0
- package/lib/abis/index.js +1 -0
- package/lib/adapters/sui/actions.d.ts +420 -0
- package/lib/adapters/sui/actions.js +701 -0
- package/lib/adapters/sui/client.d.ts +3 -3
- package/lib/adapters/sui/client.js +27 -9
- package/lib/adapters/sui/getters.d.ts +268 -0
- package/lib/adapters/sui/getters.js +669 -0
- package/lib/adapters/sui/index.d.ts +243 -3
- package/lib/adapters/sui/index.js +250 -3
- package/lib/adapters/sui/targets.d.ts +42 -1
- package/lib/adapters/sui/targets.js +42 -1
- package/lib/core/analytics/method-taxonomy.d.ts +1 -1
- package/lib/core/analytics/method-taxonomy.js +9 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/constants/core.d.ts +5 -0
- package/lib/core/constants/core.js +5 -0
- package/lib/core/constants/kyc.d.ts +9 -0
- package/lib/core/constants/kyc.js +12 -0
- package/lib/core/constants/web3.d.ts +2 -2
- package/lib/core/constants/web3.js +9 -2
- package/lib/core/errors/index.d.ts +90 -1
- package/lib/core/errors/index.js +94 -1
- package/lib/core/fetcher.d.ts +5 -0
- package/lib/core/fetcher.js +1 -1
- package/lib/core/helpers/chain-support.d.ts +2 -2
- package/lib/core/helpers/chain-support.js +3 -3
- package/lib/core/helpers/kyc.d.ts +47 -0
- package/lib/core/helpers/kyc.js +111 -0
- package/lib/core/helpers/revert-decode.js +3 -2
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +2 -0
- package/lib/evm/methods/crossChainVault.js +25 -43
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/main.d.ts +33 -3
- package/lib/main.js +32 -0
- package/lib/modules/api/kyc.d.ts +4 -0
- package/lib/modules/api/kyc.js +148 -0
- package/lib/modules/api/main.d.ts +63 -1
- package/lib/modules/api/main.js +64 -0
- package/lib/modules/vaults/getters.d.ts +3 -1
- package/lib/modules/vaults/getters.js +82 -10
- package/lib/modules/vaults/main.d.ts +41 -3
- package/lib/modules/vaults/main.js +82 -6
- package/lib/modules/vaults/types.d.ts +7 -1
- package/lib/modules/vaults/utils.js +4 -1
- package/lib/sdk.d.ts +16363 -14615
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/kyc.d.ts +61 -0
- package/lib/types/kyc.js +3 -0
- package/lib/types/vaults.d.ts +2 -0
- package/lib/types/webserver.d.ts +5 -0
- package/package.json +21 -2
|
@@ -4,21 +4,44 @@
|
|
|
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';
|
|
13
|
+
/**
|
|
14
|
+
* Sui helpers by area: chain identity (`utils`), constants, the gRPC client
|
|
15
|
+
* with failover (`client`), move-call targets (`targets`), vault reads
|
|
16
|
+
* (`getters`) and deposit / instant-redeem builders (`actions`).
|
|
17
|
+
*/
|
|
11
18
|
export declare const Sui: {
|
|
12
19
|
utils: typeof SuiUtils;
|
|
13
20
|
constants: typeof SuiConstants;
|
|
14
21
|
client: typeof SuiClient;
|
|
15
22
|
targets: typeof SuiTargets;
|
|
23
|
+
getters: typeof SuiGetters;
|
|
24
|
+
actions: typeof SuiActions;
|
|
16
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* A Sui vault as the adapter methods take it; the network is the adapter's.
|
|
28
|
+
* From an `IVault`: `vaultId` is `address`, `assetCoinType` is
|
|
29
|
+
* `depositAssets[0].address`, `shareCoinType` is `receipt.address`.
|
|
30
|
+
*/
|
|
31
|
+
export interface ISuiAdapterVault {
|
|
32
|
+
/** Vault object ID (`0x` + 64 hex chars). */
|
|
33
|
+
vaultId: string;
|
|
34
|
+
/** Move type of the deposit coin. */
|
|
35
|
+
assetCoinType: string;
|
|
36
|
+
/** Move type of the vault's share coin. */
|
|
37
|
+
shareCoinType: string;
|
|
38
|
+
}
|
|
17
39
|
/**
|
|
18
40
|
* Sui Adapter for Upshift SDK.
|
|
19
41
|
*
|
|
20
|
-
* Holds the Sui configuration passed to `new UpshiftSDK({ sui })
|
|
21
|
-
* chain-identity helpers
|
|
42
|
+
* Holds the Sui configuration passed to `new UpshiftSDK({ sui })`, the Sui
|
|
43
|
+
* chain-identity helpers, and the vault deposit / instant-redeem builders.
|
|
44
|
+
* Transactions run on the configured network.
|
|
22
45
|
*
|
|
23
46
|
* @example
|
|
24
47
|
* ```ts
|
|
@@ -27,7 +50,7 @@ export declare const Sui: {
|
|
|
27
50
|
* sdk.sui.isSuiAddress(vault.address);
|
|
28
51
|
* ```
|
|
29
52
|
*/
|
|
30
|
-
declare class SuiAdapter {
|
|
53
|
+
export declare class SuiAdapter {
|
|
31
54
|
private readonly _config;
|
|
32
55
|
/**
|
|
33
56
|
* @param config - Optional Sui settings; omit to target Sui mainnet.
|
|
@@ -53,5 +76,222 @@ declare class SuiAdapter {
|
|
|
53
76
|
* @returns `true` only for `-2`.
|
|
54
77
|
*/
|
|
55
78
|
isSuiVault(chainId: number): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Build an unsigned deposit on the configured network: charge the
|
|
81
|
+
* management fee, deposit with a minimum share amount, send the shares to
|
|
82
|
+
* the sender. Dry-runs it first, so a vault that would reject it fails here.
|
|
83
|
+
*
|
|
84
|
+
* RPC cost: one dry run (plus the coin lookup it needs).
|
|
85
|
+
*
|
|
86
|
+
* @param params - The vault, `amount` in asset base units, the `sender`, and
|
|
87
|
+
* optionally `minSharesOut` or `slippageBps` (the minimum defaults to the
|
|
88
|
+
* dry run's preview less 0.1%).
|
|
89
|
+
* @returns The unsigned transaction for the sender's wallet, the shares the
|
|
90
|
+
* dry run minted, and the minimum it enforces.
|
|
91
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
92
|
+
* contract IDs, or a transaction that cannot be built.
|
|
93
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it.
|
|
94
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const { transaction } = await sdk.sui.vaultDeposit({
|
|
98
|
+
* vaultId: vault.address,
|
|
99
|
+
* assetCoinType: vault.depositAssets[0].address,
|
|
100
|
+
* shareCoinType: vault.receipt.address,
|
|
101
|
+
* amount: 1_000_000n,
|
|
102
|
+
* sender: account.address,
|
|
103
|
+
* });
|
|
104
|
+
* const digest = await sdk.sui.executeTransaction(
|
|
105
|
+
* await dAppKit.signTransaction({ transaction }),
|
|
106
|
+
* );
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
vaultDeposit(params: ISuiAdapterVault & {
|
|
110
|
+
amount: bigint;
|
|
111
|
+
sender: string;
|
|
112
|
+
minSharesOut?: bigint;
|
|
113
|
+
slippageBps?: number;
|
|
114
|
+
}): Promise<SuiActions.ISuiDepositTransaction>;
|
|
115
|
+
/**
|
|
116
|
+
* Build an unsigned instant redemption on the configured network: charge
|
|
117
|
+
* the management fee, redeem shares with a minimum net asset amount, send
|
|
118
|
+
* the assets to the sender.
|
|
119
|
+
* Dry-runs it first; a vault with a withdrawal queue attached fails with
|
|
120
|
+
* `queue_attached`.
|
|
121
|
+
*
|
|
122
|
+
* Side effect on failure: a redemption the vault rejects is reported to that
|
|
123
|
+
* vault's curator (fire-and-forget; see `monitoring.curatorAlerts`).
|
|
124
|
+
*
|
|
125
|
+
* RPC cost: one dry run (plus the coin lookup it needs).
|
|
126
|
+
*
|
|
127
|
+
* @param params - The vault, `shares` in share base units, the `sender`, and
|
|
128
|
+
* optionally `minAssetsOut` (net of the instant fee) or `slippageBps` (the
|
|
129
|
+
* minimum defaults to the dry run's preview less 0.1%).
|
|
130
|
+
* @returns The unsigned transaction, the dry run's gross and net assets, and
|
|
131
|
+
* the minimum it enforces.
|
|
132
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
133
|
+
* contract IDs, or a transaction that cannot be built.
|
|
134
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it.
|
|
135
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
136
|
+
*/
|
|
137
|
+
vaultRedeem(params: ISuiAdapterVault & {
|
|
138
|
+
shares: bigint;
|
|
139
|
+
sender: string;
|
|
140
|
+
minAssetsOut?: bigint;
|
|
141
|
+
slippageBps?: number;
|
|
142
|
+
}): Promise<SuiActions.ISuiRedeemTransaction>;
|
|
143
|
+
/**
|
|
144
|
+
* Build an unsigned withdrawal request on the configured network, for a
|
|
145
|
+
* vault with a withdrawal queue attached (where instant redemption is off).
|
|
146
|
+
* Escrows the shares in a new request; dry-runs it first, so a vault that
|
|
147
|
+
* would reject it fails here.
|
|
148
|
+
*
|
|
149
|
+
* The request is priced when it is claimed. Once the vault's cooldown has
|
|
150
|
+
* run, claim it with {@link SuiAdapter.claimWithdrawal}; cancel it at any
|
|
151
|
+
* time with {@link SuiAdapter.vaultCancelRedeemRequest}. List a wallet's
|
|
152
|
+
* requests with {@link SuiAdapter.getWithdrawalRequests}.
|
|
153
|
+
*
|
|
154
|
+
* RPC cost: one object read for a wallet with up to 23 earlier requests on
|
|
155
|
+
* the vault (one more per further 25), then one dry run.
|
|
156
|
+
*
|
|
157
|
+
* @param params - The vault, `shares` in share base units, the `sender`, and
|
|
158
|
+
* optionally `payout` (defaults to the sender) and `finalizer`: who besides
|
|
159
|
+
* the owner may claim during the first day the request is claimable
|
|
160
|
+
* (anyone may after). Defaults to the owner alone; pass a keeper address,
|
|
161
|
+
* or `null` to let anyone claim as soon as the cooldown ends.
|
|
162
|
+
* @returns The unsigned transaction, the request ID, the request's object ID
|
|
163
|
+
* (`request`) for claiming or cancelling, and `expectedAssets` at today's
|
|
164
|
+
* price.
|
|
165
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
166
|
+
* contract IDs, or a transaction that cannot be built.
|
|
167
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it,
|
|
168
|
+
* e.g. `queue_not_attached` (redeem instantly instead) or `paused`.
|
|
169
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const { transaction, request } = await sdk.sui.vaultRequestRedeem({
|
|
173
|
+
* vaultId: vault.address,
|
|
174
|
+
* assetCoinType: vault.depositAssets[0].address,
|
|
175
|
+
* shareCoinType: vault.receipt.address,
|
|
176
|
+
* shares: 1_000_000n,
|
|
177
|
+
* sender: account.address,
|
|
178
|
+
* });
|
|
179
|
+
* await sdk.sui.executeTransaction(await dAppKit.signTransaction({ transaction }));
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
vaultRequestRedeem(params: ISuiAdapterVault & {
|
|
183
|
+
shares: bigint;
|
|
184
|
+
sender: string;
|
|
185
|
+
payout?: string;
|
|
186
|
+
finalizer?: string | null;
|
|
187
|
+
}): Promise<SuiActions.ISuiRequestRedeemTransaction>;
|
|
188
|
+
/**
|
|
189
|
+
* Build an unsigned cancellation of a pending withdrawal request on the
|
|
190
|
+
* configured network; the escrowed shares go back to the sender. Allowed at
|
|
191
|
+
* any time while the request exists, also while the vault is paused. Only
|
|
192
|
+
* the wallet that made the request may cancel it.
|
|
193
|
+
*
|
|
194
|
+
* RPC cost: one dry run.
|
|
195
|
+
*
|
|
196
|
+
* @param params - The vault, the `request` object ID and the `sender`.
|
|
197
|
+
* @returns The unsigned transaction and the shares it returns.
|
|
198
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
199
|
+
* contract IDs, or a request that no longer exists.
|
|
200
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it,
|
|
201
|
+
* e.g. `not_request_owner`.
|
|
202
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const { transaction } = await sdk.sui.vaultCancelRedeemRequest({
|
|
206
|
+
* vaultId, assetCoinType, shareCoinType, request, sender: account.address,
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
vaultCancelRedeemRequest(params: ISuiAdapterVault & {
|
|
211
|
+
request: string;
|
|
212
|
+
sender: string;
|
|
213
|
+
}): Promise<SuiActions.ISuiCancelRedeemRequestTransaction>;
|
|
214
|
+
/**
|
|
215
|
+
* Build an unsigned claim of a withdrawal request on the configured
|
|
216
|
+
* network: burns the escrowed shares and pays their current value, with no
|
|
217
|
+
* instant fee, to the request's payout.
|
|
218
|
+
*
|
|
219
|
+
* The payout lands in the payout address's address balance, not as a coin
|
|
220
|
+
* object. A request can be claimed from `eligibleAtMs` until `expiresAtMs`
|
|
221
|
+
* by its owner or finalizer (anyone when it names none), and by anyone from
|
|
222
|
+
* one day after it became eligible.
|
|
223
|
+
*
|
|
224
|
+
* RPC cost: one dry run.
|
|
225
|
+
*
|
|
226
|
+
* @param params - The vault, the `request` object ID, the `sender`, and
|
|
227
|
+
* optionally `minAssetsOut` or `slippageBps` (the minimum defaults to the
|
|
228
|
+
* dry run's payout less 0.1%).
|
|
229
|
+
* @returns The unsigned transaction, the shares it burns, the dry run's
|
|
230
|
+
* payout, and the minimum it enforces.
|
|
231
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
232
|
+
* contract IDs, or a request that no longer exists.
|
|
233
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it,
|
|
234
|
+
* e.g. `not_eligible_yet`, `request_expired` or `insufficient_liquidity`.
|
|
235
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* const [pending] = await sdk.sui.getWithdrawalRequests({ ...vault, owner: account.address });
|
|
239
|
+
* const { transaction } = await sdk.sui.claimWithdrawal({
|
|
240
|
+
* ...vault, request: pending.request, sender: account.address,
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
claimWithdrawal(params: ISuiAdapterVault & {
|
|
245
|
+
request: string;
|
|
246
|
+
sender: string;
|
|
247
|
+
minAssetsOut?: bigint;
|
|
248
|
+
slippageBps?: number;
|
|
249
|
+
}): Promise<SuiActions.ISuiClaimWithdrawalTransaction>;
|
|
250
|
+
/**
|
|
251
|
+
* A wallet's pending withdrawal requests on a vault, on the configured
|
|
252
|
+
* network, oldest first. Finds every request made through the SDK however
|
|
253
|
+
* old; claimed and cancelled requests are left out.
|
|
254
|
+
*
|
|
255
|
+
* RPC cost: one object read for a wallet that has made up to 23 requests on
|
|
256
|
+
* the vault (most wallets), one more per further 25.
|
|
257
|
+
*
|
|
258
|
+
* @param params - The vault and the `owner` wallet.
|
|
259
|
+
* @returns The pending requests, with shares, payout, and the times they
|
|
260
|
+
* become claimable and expire; empty when there are none.
|
|
261
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
262
|
+
* contract IDs, or a vault ID that is not a vault of the configured
|
|
263
|
+
* `sui.originalPackageId`.
|
|
264
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* const pending = await sdk.sui.getWithdrawalRequests({
|
|
268
|
+
* vaultId, assetCoinType, shareCoinType, owner: account.address,
|
|
269
|
+
* });
|
|
270
|
+
* const now = Date.now();
|
|
271
|
+
* const claimable = pending.filter(
|
|
272
|
+
* (r) => r.eligibleAtMs <= now && (r.expiresAtMs === null || now < r.expiresAtMs),
|
|
273
|
+
* );
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
getWithdrawalRequests(params: ISuiAdapterVault & {
|
|
277
|
+
owner: string;
|
|
278
|
+
}): Promise<SuiGetters.ISuiWithdrawalRequest[]>;
|
|
279
|
+
/**
|
|
280
|
+
* Execute a wallet-signed transaction on the configured network and wait
|
|
281
|
+
* until it is indexed. Not needed when the wallet executes the transaction
|
|
282
|
+
* itself (e.g. dApp Kit's `signAndExecuteTransaction`).
|
|
283
|
+
*
|
|
284
|
+
* Side effect on failure: a failed instant redemption is reported to that
|
|
285
|
+
* vault's curator with its digest (fire-and-forget).
|
|
286
|
+
*
|
|
287
|
+
* @param signed - `{ bytes, signature }` from the wallet's `signTransaction`.
|
|
288
|
+
* @returns The transaction digest.
|
|
289
|
+
* @throws {@link UpshiftVaultAbortError} when the vault aborted it on chain.
|
|
290
|
+
* @throws {@link UpshiftSDKError} (`UNKNOWN`) when it failed otherwise.
|
|
291
|
+
* @throws {@link UpshiftTransactionError} when it executed but was not
|
|
292
|
+
* indexed in time.
|
|
293
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
294
|
+
*/
|
|
295
|
+
executeTransaction(signed: SuiActions.ISuiSignedTransaction): Promise<string>;
|
|
56
296
|
}
|
|
57
297
|
export default SuiAdapter;
|
|
@@ -33,22 +33,32 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Sui = void 0;
|
|
36
|
+
exports.SuiAdapter = 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"));
|
|
43
|
+
/**
|
|
44
|
+
* Sui helpers by area: chain identity (`utils`), constants, the gRPC client
|
|
45
|
+
* with failover (`client`), move-call targets (`targets`), vault reads
|
|
46
|
+
* (`getters`) and deposit / instant-redeem builders (`actions`).
|
|
47
|
+
*/
|
|
41
48
|
exports.Sui = {
|
|
42
49
|
utils: SuiUtils,
|
|
43
50
|
constants: SuiConstants,
|
|
44
51
|
client: SuiClient,
|
|
45
52
|
targets: SuiTargets,
|
|
53
|
+
getters: SuiGetters,
|
|
54
|
+
actions: SuiActions,
|
|
46
55
|
};
|
|
47
56
|
/**
|
|
48
57
|
* Sui Adapter for Upshift SDK.
|
|
49
58
|
*
|
|
50
|
-
* Holds the Sui configuration passed to `new UpshiftSDK({ sui })
|
|
51
|
-
* chain-identity helpers
|
|
59
|
+
* Holds the Sui configuration passed to `new UpshiftSDK({ sui })`, the Sui
|
|
60
|
+
* chain-identity helpers, and the vault deposit / instant-redeem builders.
|
|
61
|
+
* Transactions run on the configured network.
|
|
52
62
|
*
|
|
53
63
|
* @example
|
|
54
64
|
* ```ts
|
|
@@ -95,6 +105,243 @@ class SuiAdapter {
|
|
|
95
105
|
isSuiVault(chainId) {
|
|
96
106
|
return SuiUtils.isSuiVault(chainId);
|
|
97
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Build an unsigned deposit on the configured network: charge the
|
|
110
|
+
* management fee, deposit with a minimum share amount, send the shares to
|
|
111
|
+
* the sender. Dry-runs it first, so a vault that would reject it fails here.
|
|
112
|
+
*
|
|
113
|
+
* RPC cost: one dry run (plus the coin lookup it needs).
|
|
114
|
+
*
|
|
115
|
+
* @param params - The vault, `amount` in asset base units, the `sender`, and
|
|
116
|
+
* optionally `minSharesOut` or `slippageBps` (the minimum defaults to the
|
|
117
|
+
* dry run's preview less 0.1%).
|
|
118
|
+
* @returns The unsigned transaction for the sender's wallet, the shares the
|
|
119
|
+
* dry run minted, and the minimum it enforces.
|
|
120
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
121
|
+
* contract IDs, or a transaction that cannot be built.
|
|
122
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it.
|
|
123
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const { transaction } = await sdk.sui.vaultDeposit({
|
|
127
|
+
* vaultId: vault.address,
|
|
128
|
+
* assetCoinType: vault.depositAssets[0].address,
|
|
129
|
+
* shareCoinType: vault.receipt.address,
|
|
130
|
+
* amount: 1_000_000n,
|
|
131
|
+
* sender: account.address,
|
|
132
|
+
* });
|
|
133
|
+
* const digest = await sdk.sui.executeTransaction(
|
|
134
|
+
* await dAppKit.signTransaction({ transaction }),
|
|
135
|
+
* );
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async vaultDeposit(params) {
|
|
139
|
+
const { amount, sender, minSharesOut, slippageBps, ...vault } = params;
|
|
140
|
+
return SuiActions.buildSuiDepositTransaction({
|
|
141
|
+
vault: { ...vault, network: this.network },
|
|
142
|
+
amount,
|
|
143
|
+
sender,
|
|
144
|
+
minSharesOut,
|
|
145
|
+
slippageBps,
|
|
146
|
+
}, this._config);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Build an unsigned instant redemption on the configured network: charge
|
|
150
|
+
* the management fee, redeem shares with a minimum net asset amount, send
|
|
151
|
+
* the assets to the sender.
|
|
152
|
+
* Dry-runs it first; a vault with a withdrawal queue attached fails with
|
|
153
|
+
* `queue_attached`.
|
|
154
|
+
*
|
|
155
|
+
* Side effect on failure: a redemption the vault rejects is reported to that
|
|
156
|
+
* vault's curator (fire-and-forget; see `monitoring.curatorAlerts`).
|
|
157
|
+
*
|
|
158
|
+
* RPC cost: one dry run (plus the coin lookup it needs).
|
|
159
|
+
*
|
|
160
|
+
* @param params - The vault, `shares` in share base units, the `sender`, and
|
|
161
|
+
* optionally `minAssetsOut` (net of the instant fee) or `slippageBps` (the
|
|
162
|
+
* minimum defaults to the dry run's preview less 0.1%).
|
|
163
|
+
* @returns The unsigned transaction, the dry run's gross and net assets, and
|
|
164
|
+
* the minimum it enforces.
|
|
165
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
166
|
+
* contract IDs, or a transaction that cannot be built.
|
|
167
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it.
|
|
168
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
169
|
+
*/
|
|
170
|
+
async vaultRedeem(params) {
|
|
171
|
+
const { shares, sender, minAssetsOut, slippageBps, ...vault } = params;
|
|
172
|
+
return SuiActions.buildSuiRedeemTransaction({
|
|
173
|
+
vault: { ...vault, network: this.network },
|
|
174
|
+
shares,
|
|
175
|
+
sender,
|
|
176
|
+
minAssetsOut,
|
|
177
|
+
slippageBps,
|
|
178
|
+
}, this._config);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Build an unsigned withdrawal request on the configured network, for a
|
|
182
|
+
* vault with a withdrawal queue attached (where instant redemption is off).
|
|
183
|
+
* Escrows the shares in a new request; dry-runs it first, so a vault that
|
|
184
|
+
* would reject it fails here.
|
|
185
|
+
*
|
|
186
|
+
* The request is priced when it is claimed. Once the vault's cooldown has
|
|
187
|
+
* run, claim it with {@link SuiAdapter.claimWithdrawal}; cancel it at any
|
|
188
|
+
* time with {@link SuiAdapter.vaultCancelRedeemRequest}. List a wallet's
|
|
189
|
+
* requests with {@link SuiAdapter.getWithdrawalRequests}.
|
|
190
|
+
*
|
|
191
|
+
* RPC cost: one object read for a wallet with up to 23 earlier requests on
|
|
192
|
+
* the vault (one more per further 25), then one dry run.
|
|
193
|
+
*
|
|
194
|
+
* @param params - The vault, `shares` in share base units, the `sender`, and
|
|
195
|
+
* optionally `payout` (defaults to the sender) and `finalizer`: who besides
|
|
196
|
+
* the owner may claim during the first day the request is claimable
|
|
197
|
+
* (anyone may after). Defaults to the owner alone; pass a keeper address,
|
|
198
|
+
* or `null` to let anyone claim as soon as the cooldown ends.
|
|
199
|
+
* @returns The unsigned transaction, the request ID, the request's object ID
|
|
200
|
+
* (`request`) for claiming or cancelling, and `expectedAssets` at today's
|
|
201
|
+
* price.
|
|
202
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
203
|
+
* contract IDs, or a transaction that cannot be built.
|
|
204
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it,
|
|
205
|
+
* e.g. `queue_not_attached` (redeem instantly instead) or `paused`.
|
|
206
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* const { transaction, request } = await sdk.sui.vaultRequestRedeem({
|
|
210
|
+
* vaultId: vault.address,
|
|
211
|
+
* assetCoinType: vault.depositAssets[0].address,
|
|
212
|
+
* shareCoinType: vault.receipt.address,
|
|
213
|
+
* shares: 1_000_000n,
|
|
214
|
+
* sender: account.address,
|
|
215
|
+
* });
|
|
216
|
+
* await sdk.sui.executeTransaction(await dAppKit.signTransaction({ transaction }));
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
async vaultRequestRedeem(params) {
|
|
220
|
+
const { shares, sender, payout, finalizer, ...vault } = params;
|
|
221
|
+
return SuiActions.buildSuiRequestRedeemTransaction({
|
|
222
|
+
vault: { ...vault, network: this.network },
|
|
223
|
+
shares,
|
|
224
|
+
sender,
|
|
225
|
+
payout,
|
|
226
|
+
finalizer,
|
|
227
|
+
}, this._config);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Build an unsigned cancellation of a pending withdrawal request on the
|
|
231
|
+
* configured network; the escrowed shares go back to the sender. Allowed at
|
|
232
|
+
* any time while the request exists, also while the vault is paused. Only
|
|
233
|
+
* the wallet that made the request may cancel it.
|
|
234
|
+
*
|
|
235
|
+
* RPC cost: one dry run.
|
|
236
|
+
*
|
|
237
|
+
* @param params - The vault, the `request` object ID and the `sender`.
|
|
238
|
+
* @returns The unsigned transaction and the shares it returns.
|
|
239
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
240
|
+
* contract IDs, or a request that no longer exists.
|
|
241
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it,
|
|
242
|
+
* e.g. `not_request_owner`.
|
|
243
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* const { transaction } = await sdk.sui.vaultCancelRedeemRequest({
|
|
247
|
+
* vaultId, assetCoinType, shareCoinType, request, sender: account.address,
|
|
248
|
+
* });
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
async vaultCancelRedeemRequest(params) {
|
|
252
|
+
const { request, sender, ...vault } = params;
|
|
253
|
+
return SuiActions.buildSuiCancelRedeemRequestTransaction({ vault: { ...vault, network: this.network }, request, sender }, this._config);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Build an unsigned claim of a withdrawal request on the configured
|
|
257
|
+
* network: burns the escrowed shares and pays their current value, with no
|
|
258
|
+
* instant fee, to the request's payout.
|
|
259
|
+
*
|
|
260
|
+
* The payout lands in the payout address's address balance, not as a coin
|
|
261
|
+
* object. A request can be claimed from `eligibleAtMs` until `expiresAtMs`
|
|
262
|
+
* by its owner or finalizer (anyone when it names none), and by anyone from
|
|
263
|
+
* one day after it became eligible.
|
|
264
|
+
*
|
|
265
|
+
* RPC cost: one dry run.
|
|
266
|
+
*
|
|
267
|
+
* @param params - The vault, the `request` object ID, the `sender`, and
|
|
268
|
+
* optionally `minAssetsOut` or `slippageBps` (the minimum defaults to the
|
|
269
|
+
* dry run's payout less 0.1%).
|
|
270
|
+
* @returns The unsigned transaction, the shares it burns, the dry run's
|
|
271
|
+
* payout, and the minimum it enforces.
|
|
272
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
273
|
+
* contract IDs, or a request that no longer exists.
|
|
274
|
+
* @throws {@link UpshiftVaultAbortError} when the vault would reject it,
|
|
275
|
+
* e.g. `not_eligible_yet`, `request_expired` or `insufficient_liquidity`.
|
|
276
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* const [pending] = await sdk.sui.getWithdrawalRequests({ ...vault, owner: account.address });
|
|
280
|
+
* const { transaction } = await sdk.sui.claimWithdrawal({
|
|
281
|
+
* ...vault, request: pending.request, sender: account.address,
|
|
282
|
+
* });
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
async claimWithdrawal(params) {
|
|
286
|
+
const { request, sender, minAssetsOut, slippageBps, ...vault } = params;
|
|
287
|
+
return SuiActions.buildSuiClaimWithdrawalTransaction({
|
|
288
|
+
vault: { ...vault, network: this.network },
|
|
289
|
+
request,
|
|
290
|
+
sender,
|
|
291
|
+
minAssetsOut,
|
|
292
|
+
slippageBps,
|
|
293
|
+
}, this._config);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* A wallet's pending withdrawal requests on a vault, on the configured
|
|
297
|
+
* network, oldest first. Finds every request made through the SDK however
|
|
298
|
+
* old; claimed and cancelled requests are left out.
|
|
299
|
+
*
|
|
300
|
+
* RPC cost: one object read for a wallet that has made up to 23 requests on
|
|
301
|
+
* the vault (most wallets), one more per further 25.
|
|
302
|
+
*
|
|
303
|
+
* @param params - The vault and the `owner` wallet.
|
|
304
|
+
* @returns The pending requests, with shares, payout, and the times they
|
|
305
|
+
* become claimable and expire; empty when there are none.
|
|
306
|
+
* @throws {@link UpshiftValidationError} for malformed input, unknown
|
|
307
|
+
* contract IDs, or a vault ID that is not a vault of the configured
|
|
308
|
+
* `sui.originalPackageId`.
|
|
309
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const pending = await sdk.sui.getWithdrawalRequests({
|
|
313
|
+
* vaultId, assetCoinType, shareCoinType, owner: account.address,
|
|
314
|
+
* });
|
|
315
|
+
* const now = Date.now();
|
|
316
|
+
* const claimable = pending.filter(
|
|
317
|
+
* (r) => r.eligibleAtMs <= now && (r.expiresAtMs === null || now < r.expiresAtMs),
|
|
318
|
+
* );
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
async getWithdrawalRequests(params) {
|
|
322
|
+
const { owner, ...vault } = params;
|
|
323
|
+
return SuiGetters.getSuiWithdrawalRequests({ ...vault, network: this.network }, owner, this._config);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Execute a wallet-signed transaction on the configured network and wait
|
|
327
|
+
* until it is indexed. Not needed when the wallet executes the transaction
|
|
328
|
+
* itself (e.g. dApp Kit's `signAndExecuteTransaction`).
|
|
329
|
+
*
|
|
330
|
+
* Side effect on failure: a failed instant redemption is reported to that
|
|
331
|
+
* vault's curator with its digest (fire-and-forget).
|
|
332
|
+
*
|
|
333
|
+
* @param signed - `{ bytes, signature }` from the wallet's `signTransaction`.
|
|
334
|
+
* @returns The transaction digest.
|
|
335
|
+
* @throws {@link UpshiftVaultAbortError} when the vault aborted it on chain.
|
|
336
|
+
* @throws {@link UpshiftSDKError} (`UNKNOWN`) when it failed otherwise.
|
|
337
|
+
* @throws {@link UpshiftTransactionError} when it executed but was not
|
|
338
|
+
* indexed in time.
|
|
339
|
+
* @throws {@link UpshiftNetworkError} when every Sui endpoint fails.
|
|
340
|
+
*/
|
|
341
|
+
async executeTransaction(signed) {
|
|
342
|
+
return SuiActions.submitSuiTransaction(signed, this.network, this._config);
|
|
343
|
+
}
|
|
98
344
|
}
|
|
345
|
+
exports.SuiAdapter = SuiAdapter;
|
|
99
346
|
exports.default = SuiAdapter;
|
|
100
347
|
//# sourceMappingURL=index.js.map
|
|
@@ -29,7 +29,8 @@ export interface ISuiVaultTargetSpec {
|
|
|
29
29
|
* Every `upshift_vault` function the SDK calls, keyed by a stable name.
|
|
30
30
|
*
|
|
31
31
|
* Vault functions take the `<Asset, Share>` type arguments built by
|
|
32
|
-
* {@link suiVaultTypeArguments}; `withdrawal::share`
|
|
32
|
+
* {@link suiVaultTypeArguments}; `withdrawal::share` and `withdrawal::shares`
|
|
33
|
+
* take `<Share>` only.
|
|
33
34
|
*/
|
|
34
35
|
export declare const SUI_VAULT_TARGETS: {
|
|
35
36
|
readonly deposit: {
|
|
@@ -67,6 +68,11 @@ export declare const SUI_VAULT_TARGETS: {
|
|
|
67
68
|
readonly function: "share";
|
|
68
69
|
readonly params: readonly ["WithdrawalRequest<Share>"];
|
|
69
70
|
};
|
|
71
|
+
readonly withdrawalRequestShares: {
|
|
72
|
+
readonly module: "withdrawal";
|
|
73
|
+
readonly function: "shares";
|
|
74
|
+
readonly params: readonly ["&WithdrawalRequest<Share>"];
|
|
75
|
+
};
|
|
70
76
|
readonly finalizeWithdrawal: {
|
|
71
77
|
readonly module: "vault";
|
|
72
78
|
readonly function: "finalize_withdrawal";
|
|
@@ -107,6 +113,41 @@ export declare const SUI_VAULT_TARGETS: {
|
|
|
107
113
|
readonly function: "preview_redemption";
|
|
108
114
|
readonly params: readonly ["&Vault<Asset, Share>", "&Registry", "u64", "bool"];
|
|
109
115
|
};
|
|
116
|
+
readonly decimals: {
|
|
117
|
+
readonly module: "vault";
|
|
118
|
+
readonly function: "decimals";
|
|
119
|
+
readonly params: readonly ["&Vault<Asset, Share>"];
|
|
120
|
+
};
|
|
121
|
+
readonly paused: {
|
|
122
|
+
readonly module: "vault";
|
|
123
|
+
readonly function: "paused";
|
|
124
|
+
readonly params: readonly ["&Vault<Asset, Share>"];
|
|
125
|
+
};
|
|
126
|
+
readonly queueAttached: {
|
|
127
|
+
readonly module: "vault";
|
|
128
|
+
readonly function: "queue_attached";
|
|
129
|
+
readonly params: readonly ["&Vault<Asset, Share>"];
|
|
130
|
+
};
|
|
131
|
+
readonly minDeposit: {
|
|
132
|
+
readonly module: "vault";
|
|
133
|
+
readonly function: "min_deposit";
|
|
134
|
+
readonly params: readonly ["&Vault<Asset, Share>"];
|
|
135
|
+
};
|
|
136
|
+
readonly depositCap: {
|
|
137
|
+
readonly module: "vault";
|
|
138
|
+
readonly function: "deposit_cap";
|
|
139
|
+
readonly params: readonly ["&Vault<Asset, Share>"];
|
|
140
|
+
};
|
|
141
|
+
readonly maxDepositAmount: {
|
|
142
|
+
readonly module: "vault";
|
|
143
|
+
readonly function: "max_deposit_amount";
|
|
144
|
+
readonly params: readonly ["&Vault<Asset, Share>"];
|
|
145
|
+
};
|
|
146
|
+
readonly maxWithdrawalAmount: {
|
|
147
|
+
readonly module: "vault";
|
|
148
|
+
readonly function: "max_withdrawal_amount";
|
|
149
|
+
readonly params: readonly ["&Vault<Asset, Share>"];
|
|
150
|
+
};
|
|
110
151
|
};
|
|
111
152
|
/** Name of a package function the SDK calls; a key of {@link SUI_VAULT_TARGETS}. */
|
|
112
153
|
export type ISuiVaultTarget = keyof typeof SUI_VAULT_TARGETS;
|
|
@@ -12,7 +12,8 @@ const constants_1 = require("./constants");
|
|
|
12
12
|
* Every `upshift_vault` function the SDK calls, keyed by a stable name.
|
|
13
13
|
*
|
|
14
14
|
* Vault functions take the `<Asset, Share>` type arguments built by
|
|
15
|
-
* {@link suiVaultTypeArguments}; `withdrawal::share`
|
|
15
|
+
* {@link suiVaultTypeArguments}; `withdrawal::share` and `withdrawal::shares`
|
|
16
|
+
* take `<Share>` only.
|
|
16
17
|
*/
|
|
17
18
|
exports.SUI_VAULT_TARGETS = {
|
|
18
19
|
deposit: {
|
|
@@ -86,6 +87,11 @@ exports.SUI_VAULT_TARGETS = {
|
|
|
86
87
|
function: 'share',
|
|
87
88
|
params: ['WithdrawalRequest<Share>'],
|
|
88
89
|
},
|
|
90
|
+
withdrawalRequestShares: {
|
|
91
|
+
module: 'withdrawal',
|
|
92
|
+
function: 'shares',
|
|
93
|
+
params: ['&WithdrawalRequest<Share>'],
|
|
94
|
+
},
|
|
89
95
|
finalizeWithdrawal: {
|
|
90
96
|
module: 'vault',
|
|
91
97
|
function: 'finalize_withdrawal',
|
|
@@ -139,6 +145,41 @@ exports.SUI_VAULT_TARGETS = {
|
|
|
139
145
|
function: 'preview_redemption',
|
|
140
146
|
params: ['&Vault<Asset, Share>', '&Registry', 'u64', 'bool'],
|
|
141
147
|
},
|
|
148
|
+
decimals: {
|
|
149
|
+
module: 'vault',
|
|
150
|
+
function: 'decimals',
|
|
151
|
+
params: ['&Vault<Asset, Share>'],
|
|
152
|
+
},
|
|
153
|
+
paused: {
|
|
154
|
+
module: 'vault',
|
|
155
|
+
function: 'paused',
|
|
156
|
+
params: ['&Vault<Asset, Share>'],
|
|
157
|
+
},
|
|
158
|
+
queueAttached: {
|
|
159
|
+
module: 'vault',
|
|
160
|
+
function: 'queue_attached',
|
|
161
|
+
params: ['&Vault<Asset, Share>'],
|
|
162
|
+
},
|
|
163
|
+
minDeposit: {
|
|
164
|
+
module: 'vault',
|
|
165
|
+
function: 'min_deposit',
|
|
166
|
+
params: ['&Vault<Asset, Share>'],
|
|
167
|
+
},
|
|
168
|
+
depositCap: {
|
|
169
|
+
module: 'vault',
|
|
170
|
+
function: 'deposit_cap',
|
|
171
|
+
params: ['&Vault<Asset, Share>'],
|
|
172
|
+
},
|
|
173
|
+
maxDepositAmount: {
|
|
174
|
+
module: 'vault',
|
|
175
|
+
function: 'max_deposit_amount',
|
|
176
|
+
params: ['&Vault<Asset, Share>'],
|
|
177
|
+
},
|
|
178
|
+
maxWithdrawalAmount: {
|
|
179
|
+
module: 'vault',
|
|
180
|
+
function: 'max_withdrawal_amount',
|
|
181
|
+
params: ['&Vault<Asset, Share>'],
|
|
182
|
+
},
|
|
142
183
|
};
|
|
143
184
|
/**
|
|
144
185
|
* Resolve the Upshift vault contract IDs for a Sui config: each `sui` override
|