This guide explains how to deposit assets into a Glider portfolio.

Overview

Depositing assets into your portfolio is necessary before you can start using Glider’s automated rebalancing features. Depositing funds involves:

  1. Getting deposit instructions from the Glider API
  2. Creating a transaction with these instructions
  3. Having the user sign and send the transaction

Deposit Process

1. Get Deposit Instructions

First, request deposit instructions from the API:

const depositResponse = await fetch(`https://api.glider.fi/v1/portfolio/${portfolioId}/deposit`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': 'your_api_key_here',
  },
  body: JSON.stringify({
    token: {
      chainId: 8453, // Base chain
      address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH on Base
      amount: '0.1' // 0.1 ETH
    }
  }),
});

const depositData = await depositResponse.json();

For ERC-20 tokens, replace the token address with the token’s contract address:

body: JSON.stringify({
  token: {
    chainId: 8453, // Base chain
    address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
    amount: '10000000' // 10 USDC (6 decimals)
  }
})

2. Create and Send the Transaction

The response will include transaction data that you can use to create a transaction for the user to sign:

// Example response
{
  "success": true,
  "data": {
    "to": "0xPortfolioVaultAddress",
    "value": "100000000000000000", // 0.1 ETH in wei
    "data": "0x...", // Transaction calldata
    "chainId": 8453
  }
}

Use this data to create and send a transaction:

// Using ethers.js
const tx = await signer.sendTransaction({
  to: depositData.data.to,
  value: depositData.data.value,
  data: depositData.data.data,
  chainId: depositData.data.chainId
});

// Wait for confirmation
const receipt = await tx.wait();
console.log("Deposit confirmed:", receipt.transactionHash);

3. Verify the Deposit

After the transaction is confirmed, you can verify the deposit by retrieving the portfolio details:

const portfolioResponse = await fetch(`https://api.glider.fi/v1/portfolio/${portfolioId}`, {
  method: 'GET',
  headers: {
    'X-API-KEY': 'your_api_key_here',
  },
});

const portfolio = await portfolioResponse.json();
console.log("Portfolio assets:", portfolio.data.vaults[0].assets);

Handling ERC-20 Token Approvals

For ERC-20 tokens, users need to approve the portfolio vault to spend their tokens first. The deposit endpoint handles this for you:

  1. If the user hasn’t approved the tokens yet, the deposit endpoint will return approval transaction data
  2. After the approval transaction is confirmed, you need to call the deposit endpoint again to get the deposit transaction data
// Check if we need to approve first
if (depositData.data.requiresApproval) {
  const approveTx = await signer.sendTransaction({
    to: depositData.data.approvalData.to,
    data: depositData.data.approvalData.data,
    chainId: depositData.data.chainId
  });
  
  await approveTx.wait();
  
  // Now call deposit endpoint again
  const depositResponse2 = await fetch(`https://api.glider.fi/v1/portfolio/${portfolioId}/deposit`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key_here',
    },
    body: JSON.stringify({
      token: {
        chainId: 8453,
        address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
        amount: '10000000' // 10 USDC
      }
    }),
  });
  
  const depositData2 = await depositResponse2.json();
  // Proceed with deposit transaction
}

Best Practices

  1. Validate inputs: Ensure the token address and amount are valid before sending the request
  2. Handle network errors: Implement retry logic for network failures
  3. Verify gas costs: For large deposits, consider using the simulate: true parameter to estimate gas costs
  4. Inform users: Display a loading state during transaction confirmation
  5. Verify balances: Check that the user has sufficient balance before attempting the deposit

Next Steps

After depositing assets, you can:

  1. Start portfolio automation to enable automatic rebalancing
  2. Update the portfolio if you want to change its configuration
  3. Monitor the portfolio’s performance to track its growth