Deposit
Create a deposit request in a Volo vault and handle the SDK's pre-checks.
A Volo deposit is a request. The coin moves into the vault when the user signs, and shares are issued at the share price when the operator settles the request.
import { Transaction } from '@mysten/sui/transactions';
import { depositPTB, getVault, isVaultSdkError, type Vault } from '@naviprotocol/vault';
export async function buildDeposit(vaultId: string, owner: string, amount: string) {
const vault: Vault = await getVault(vaultId);
if (vault.source !== 'volo') throw new Error('Not a Volo vault');
const tx = new Transaction();
tx.setSender(owner);
try {
// amount is a decimal string in the deposit coin, for example '25.5'
const { requestId } = await depositPTB(tx, vault, owner, amount);
return { tx, requestId };
} catch (error) {
if (isVaultSdkError(error) && error.code === 'DEPOSIT_BELOW_MINIMUM') {
throw new Error(`Deposit at least ${vault.minInvestment} ${vault.assets.baseCoin.symbol}`);
}
throw error;
}
}What depositPTB does
- Checks the vault is open (
VAULT_NOT_OPEN), the amount is at leastminInvestment(DEPOSIT_BELOW_MINIMUM) and within the remaining capacity (DEPOSIT_CAP_EXCEEDED). No transaction is built if a check fails. - Selects and merges the owner’s coins of the deposit type.
- Adds the deposit request and transfers the receipt, and any change coin, back to the owner.
- Returns
{ receipt, requestId, charge }as transaction handles.
Compose a deposit
| Need | Option |
|---|---|
| Deposit a coin produced earlier in the PTB | Pass the coin as amount together with { coin }; the amount is then raw base units. |
| Route the receipt yourself | Pass { disableAutoTransfer: true } and transfer or use receipt and the change coin charge. |
| Pay from the gas coin | Pass { useGasCoin: true } for SUI deposits. |