UpshiftDocs

SuiAdapter

Sui adapter for the Upshift SDK — Move vault deposits, instant redemptions, and signed-transaction execution, plus Sui chain-identity helpers.

Generated from @upshiftfinance/sdk 1.0.1

This page is produced from the SDK's TSDoc on every release. To correct it, edit the TSDoc in the SDK repository — an edit here is overwritten by the next release.

Sui Adapter for Upshift SDK

Sui Adapter for Upshift SDK.

Holds the Sui configuration passed to new UpshiftSDK({ sui }), the Sui chain-identity helpers, and the vault deposit / instant-redeem builders. Transactions run on the configured network.

Example

const sdk = new UpshiftSDK({ appName: 'my-app', sui: { network: 'testnet' } });
sdk.sui.network; // 'testnet'
sdk.sui.isSuiAddress(vault.address);

Constructors

Constructor

new SuiAdapter(config?): SuiAdapter

Parameters

ParameterTypeDescription
configISuiConfigOptional Sui settings; omit to target Sui mainnet.

Returns

SuiAdapter

Accessors

chainId

Get Signature

get chainId(): number

The SDK's Sui chain ID, -2 (same as the backend's chain for Sui vaults).

Returns

number

network

Get Signature

get network(): ISuiNetwork

Configured Sui network; 'mainnet' unless the SDK was built with another.

Returns

ISuiNetwork

rpcUrl

Get Signature

get rpcUrl(): string

Configured RPC endpoint override, or undefined when none was given.

Returns

string

Methods

claimWithdrawal()

claimWithdrawal(params): Promise<ISuiClaimWithdrawalTransaction>

Build an unsigned claim of a withdrawal request on the configured network: burns the escrowed shares and pays their current value, with no instant fee, to the request's payout.

The payout lands in the payout address's address balance, not as a coin object. A request can be claimed from eligibleAtMs until expiresAtMs by its owner or finalizer (anyone when it names none), and by anyone from one day after it became eligible.

RPC cost: one dry run. Plus the vault's package lookup (see ISuiVaultRef.originalPackageId).

Parameters

ParameterTypeDescription
paramsISuiAdapterVault & objectThe vault, the request object ID, the sender, and optionally minAssetsOut or slippageBps (the minimum defaults to the dry run's payout less 0.1%).

Returns

Promise<ISuiClaimWithdrawalTransaction>

The unsigned transaction, the shares it burns, the dry run's payout, and the minimum it enforces.

Throws

UpshiftValidationError for malformed input, unknown contract IDs, or a request that no longer exists.

Throws

UpshiftVaultAbortError when the vault would reject it, e.g. not_eligible_yet, request_expired or insufficient_liquidity.

Throws

UpshiftNetworkError when every Sui endpoint fails.

Example

const [pending] = await sdk.sui.getWithdrawalRequests({ ...vault, owner: account.address });
const { transaction } = await sdk.sui.claimWithdrawal({
  ...vault, request: pending.request, sender: account.address,
});

executeTransaction()

executeTransaction(signed): Promise<string>

Execute a wallet-signed transaction on the configured network and wait until it is indexed. Not needed when the wallet executes the transaction itself (e.g. dApp Kit's signAndExecuteTransaction).

Side effect on failure: a failed instant redemption is reported to that vault's curator with its digest (fire-and-forget).

Parameters

ParameterTypeDescription
signedISuiSignedTransaction{ bytes, signature } from the wallet's signTransaction.

Returns

Promise<string>

The transaction digest.

Throws

UpshiftVaultAbortError when the vault aborted it on chain.

Throws

UpshiftSDKError (UNKNOWN) when it failed otherwise.

Throws

UpshiftTransactionError when it executed but was not indexed in time.

Throws

UpshiftNetworkError when every Sui endpoint fails.

getWithdrawalRequests()

getWithdrawalRequests(params): Promise<ISuiWithdrawalRequest[]>

A wallet's pending withdrawal requests on a vault, on the configured network, oldest first. Finds every request made through the SDK however old; claimed and cancelled requests are left out.

RPC cost: one object read for a wallet that has made up to 23 requests on the vault (most wallets), one more per further 25. Plus the vault's package lookup (see ISuiVaultRef.originalPackageId).

Parameters

ParameterTypeDescription
paramsISuiAdapterVault & objectThe vault and the owner wallet.

Returns

Promise<ISuiWithdrawalRequest[]>

The pending requests, with shares, payout, and the times they become claimable and expire; empty when there are none.

Throws

UpshiftValidationError for malformed input, or a vault ID that is not an Upshift vault of a known or configured deployment.

Throws

UpshiftNetworkError when every Sui endpoint fails.

Example

const pending = await sdk.sui.getWithdrawalRequests({
  vaultId, assetCoinType, shareCoinType, owner: account.address,
});
const now = Date.now();
const claimable = pending.filter(
  (r) => r.eligibleAtMs <= now && (r.expiresAtMs === null || now < r.expiresAtMs),
);

isSuiAddress()

isSuiAddress(address): boolean

Check whether a string is a Sui address or object ID (0x + 64 hex chars).

Parameters

ParameterTypeDescription
addressstringCandidate address.

Returns

boolean

true for the long, 64-hex-digit form only.

isSuiVault()

isSuiVault(chainId): boolean

Check whether a chain ID is Sui's (-2).

Parameters

ParameterTypeDescription
chainIdnumberNumeric chain ID, e.g. a backend vault row's chain.

Returns

boolean

true only for -2.

vaultCancelRedeemRequest()

vaultCancelRedeemRequest(params): Promise<ISuiCancelRedeemRequestTransaction>

Build an unsigned cancellation of a pending withdrawal request on the configured network; the escrowed shares go back to the sender. Allowed at any time while the request exists, also while the vault is paused. Only the wallet that made the request may cancel it.

RPC cost: one dry run. Plus the vault's package lookup (see ISuiVaultRef.originalPackageId).

Parameters

ParameterTypeDescription
paramsISuiAdapterVault & objectThe vault, the request object ID and the sender.

Returns

Promise<ISuiCancelRedeemRequestTransaction>

The unsigned transaction and the shares it returns.

Throws

UpshiftValidationError for malformed input, unknown contract IDs, or a request that no longer exists.

Throws

UpshiftVaultAbortError when the vault would reject it, e.g. not_request_owner.

Throws

UpshiftNetworkError when every Sui endpoint fails.

Example

const { transaction } = await sdk.sui.vaultCancelRedeemRequest({
  vaultId, assetCoinType, shareCoinType, request, sender: account.address,
});

vaultDeposit()

vaultDeposit(params): Promise<ISuiDepositTransaction>

Build an unsigned deposit on the configured network: charge the management fee, deposit with a minimum share amount, send the shares to the sender. Dry-runs it first, so a vault that would reject it fails here.

RPC cost: one dry run (plus the coin lookup it needs). Plus the vault's package lookup (see ISuiVaultRef.originalPackageId).

Parameters

ParameterTypeDescription
paramsISuiAdapterVault & objectThe vault, amount in asset base units, the sender, and optionally minSharesOut or slippageBps (the minimum defaults to the dry run's preview less 0.1%).

Returns

Promise<ISuiDepositTransaction>

The unsigned transaction for the sender's wallet, the shares the dry run minted, and the minimum it enforces.

Throws

UpshiftValidationError for malformed input, unknown contract IDs, or a transaction that cannot be built.

Throws

UpshiftVaultAbortError when the vault would reject it.

Throws

UpshiftNetworkError when every Sui endpoint fails.

Example

const { transaction } = await sdk.sui.vaultDeposit({
  vaultId: vault.address,
  assetCoinType: vault.depositAssets[0].address,
  shareCoinType: vault.receipt.address,
  amount: 1_000_000n,
  sender: account.address,
});
const digest = await sdk.sui.executeTransaction(
  await dAppKit.signTransaction({ transaction }),
);

vaultRedeem()

vaultRedeem(params): Promise<ISuiRedeemTransaction>

Build an unsigned instant redemption on the configured network: charge the management fee, redeem shares with a minimum net asset amount, send the assets to the sender. Dry-runs it first; a vault with a withdrawal queue attached fails with queue_attached.

Side effect on failure: a redemption the vault rejects is reported to that vault's curator (fire-and-forget; see monitoring.curatorAlerts).

RPC cost: one dry run (plus the coin lookup it needs). Plus the vault's package lookup (see ISuiVaultRef.originalPackageId).

Parameters

ParameterTypeDescription
paramsISuiAdapterVault & objectThe vault, shares in share base units, the sender, and optionally minAssetsOut (net of the instant fee) or slippageBps (the minimum defaults to the dry run's preview less 0.1%).

Returns

Promise<ISuiRedeemTransaction>

The unsigned transaction, the dry run's gross and net assets, and the minimum it enforces.

Throws

UpshiftValidationError for malformed input, unknown contract IDs, or a transaction that cannot be built.

Throws

UpshiftVaultAbortError when the vault would reject it.

Throws

UpshiftNetworkError when every Sui endpoint fails.

vaultRequestRedeem()

vaultRequestRedeem(params): Promise<ISuiRequestRedeemTransaction>

Build an unsigned withdrawal request on the configured network, for a vault with a withdrawal queue attached (where instant redemption is off). Escrows the shares in a new request; dry-runs it first, so a vault that would reject it fails here.

The request is priced when it is claimed. Once the vault's cooldown has run, claim it with SuiAdapter.claimWithdrawal; cancel it at any time with SuiAdapter.vaultCancelRedeemRequest. List a wallet's requests with SuiAdapter.getWithdrawalRequests.

RPC cost: one object read for a wallet with up to 23 earlier requests on the vault (one more per further 25), then one dry run. Plus the vault's package lookup (see ISuiVaultRef.originalPackageId).

Parameters

ParameterTypeDescription
paramsISuiAdapterVault & objectThe vault, shares in share base units, the sender, and optionally payout (defaults to the sender) and finalizer: who besides the owner may claim during the first day the request is claimable (anyone may after). Defaults to the owner alone; pass a keeper address, or null to let anyone claim as soon as the cooldown ends.

Returns

Promise<ISuiRequestRedeemTransaction>

The unsigned transaction, the request ID, the request's object ID (request) for claiming or cancelling, and expectedAssets at today's price.

Throws

UpshiftValidationError for malformed input, unknown contract IDs, or a transaction that cannot be built.

Throws

UpshiftVaultAbortError when the vault would reject it, e.g. queue_not_attached (redeem instantly instead) or paused.

Throws

UpshiftNetworkError when every Sui endpoint fails.

Example

const { transaction, request } = await sdk.sui.vaultRequestRedeem({
  vaultId: vault.address,
  assetCoinType: vault.depositAssets[0].address,
  shareCoinType: vault.receipt.address,
  shares: 1_000_000n,
  sender: account.address,
});
await sdk.sui.executeTransaction(await dAppKit.signTransaction({ transaction }));

Interfaces

ISuiAdapterVault

A Sui vault as the adapter methods take it; the network is the adapter's. From an IVault: vaultId is address, assetCoinType is depositAssets[0].address, shareCoinType is receipt.address.

Properties

PropertyTypeDescription
assetCoinTypestringMove type of the deposit coin.
shareCoinTypestringMove type of the vault's share coin.
vaultIdstringVault object ID (0x + 64 hex chars).

Variables

Sui

const Sui: object

Sui helpers by area: chain identity (utils), constants, the gRPC client with failover (client), move-call targets (targets), vault reads (getters) and deposit / instant-redeem builders (actions).

Type Declaration

NameTypeDefault value
actions__moduleSuiActions
client__moduleSuiClient
constants__moduleSuiConstants
getters__moduleSuiGetters
targets__moduleSuiTargets
utils__moduleSuiUtils

References

default

Renames and re-exports SuiAdapter