Instant Deposit
depositInstant(sender, tokenIn, amount, minReceiveAmount, referrerId)
: Prepares an instant deposit transaction that will deposit tokens with auto mint if account fits daily limit and token allowance. The prepared transaction will transfer token from the user, fee in tokenIn to feeReceiver, and mint collateral to user.
Parameters
sender
(string): The address of the transaction sendertokenIn
(string): The token address to deposit (must be supported by issuance vault)amount
(BigNumberish): The amount to depositminReceiveAmount
(BigNumberish): The minimum amount to receive (slippage protection)referrerId
(string): The referrer ID as bytes32 (useZeroReferrer
for no referrer)
Code Example
ts
import { HYSP, ZeroReferrer } from "@everstake/wallet-sdk-hysp";
import { ethers } from "ethers";
// Initialize SDK
const hysp = new HYSP();
await hysp.init("eth_mainnet", "mmev");
const walletAddress = "0x...";
const usdcAddress = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
const depositAmount = 100.0;
// Create deposit transaction
const depositTx = await hysp.depositInstant(
walletAddress,
usdcAddress,
depositAmount,
0, // minReceiveAmount
ZeroReferrer
);
// Sign and send transaction
const signer = await ethers.getSigner();
const txResponse = await signer.sendTransaction(depositTx);
await txResponse.wait();
Calculating minReceiveAmount
The minReceiveAmount
can be calculated using the oracle price to provide slippage protection:
ts
// Calculate minimum receive amount with slippage protection
const price = await hysp.getPrice();
const depositFee = await hysp.getInstantDepositFee();
const slippageTolerance = 0.01; // 1% slippage tolerance
// Calculate expected output after fees
const grossOutput = new BigNumber(depositAmount).multipliedBy(price);
const feeAmount = grossOutput.multipliedBy(depositFee / 100);
const expectedOutput = grossOutput.minus(feeAmount);
// Apply slippage tolerance
const minReceiveAmount = expectedOutput.multipliedBy(1 - slippageTolerance);
// Create deposit transaction with slippage protection
const depositTx = await hysp.depositInstant(
walletAddress,
usdcAddress,
depositAmount,
minReceiveAmount,
ZeroReferrer
);
Prerequisites
- Token must be approved for issuance vault before depositing (use
approveToIssuanceVault()
) - Token must be in
hysp.supportedIssuanceTokensAddresses
- Sufficient token balance required