expand.network
  • Overview
  • Getting Started
  • 🔑How do I get my API Key?
  • 📑List of All Endpoints
  • ⚙️SDK
    • Overview
    • Getting Started
  • ⛓️INTEGRATIONS
    • ⚡Blockchains
      • EVM based blockchains
        • Ethereum
        • Binance Smart Chain
        • Avalanche - C
        • Avalanche - P
        • Avalanche - X
        • Polygon
        • Cronos
        • Arbitrum
        • Fantom
        • Optimism
        • Base
        • zkSync Era
        • Mantle
      • Non-EVM based chains
        • Tron
        • Solana
        • Near
        • Algorand
        • Aptos
        • Sui
        • Starknet
        • TON
        • Cosmos Hub
        • Osmosis
        • Stacks
        • Bitcoin
        • Stellar
          • Stellar RWA
        • XRP Ledger
          • XRP Ledger RWA
    • ⚡Bridges
      • Stargate
      • Stargate V2
      • Squid Router
      • Squid Router V2
      • Allbridge Classic
      • Allbridge Core
    • ⚡DEX & DEX Aggregators
      • Uniswap V2
      • Uniswap V3
      • Uniswap X
      • Sushiswap V2
      • PancakeSwap V2
      • PancakeSwap V3
      • Aerodrome
      • Camelot V3
      • Curve V2
      • Balancer V2
      • STON.fi
      • Trader Joe
      • Orca
      • Raydium
      • SDEX
      • Cetus
      • REF Finance
      • Liquidswap
      • Sologenic
      • Alex
      • 0x (Aggregator)
      • 1inch (Aggregator)
      • Kyberswap (Aggregator)
        • Kyberswap ( Limit Order Endpoints )
      • Jupiter (Aggregator)
    • ⚡Derivatives
      • dYdX V4
    • ⚡Fungible Tokens
      • ERC20
      • WETH
    • ⚡Lending Protocols
      • Aave V2
      • Aave V3
      • Compound V2
      • Compound V3
      • Morpho
    • ⚡Yield Aggregators
      • Yearn Finance V2
      • Harvest Finance
      • Pendle
    • ⚡Liquid Staking
      • Chorus One
      • Lido V2
      • Stader
      • Benqi
      • Jito
      • EigenLayer
    • ⚡Non Fungible Tokens
      • ERC721
      • ERC1155
      • Metaplex
    • ⚡Oracles
      • ChainLink
      • WinkLink
      • Pyth Network
      • RedStone
    • ⚡Stablecoins
      • EVM
    • ⚡Synthetics
      • Synthetix
    • ⚡Supported Wallets
      • MPC Wallets
        • DFNS
        • FORDEFI
        • FIREBLOCKS
        • CIRCLE
      • HD Wallets
        • PHANTOM
        • COINBASE
        • TON Wallet
      • Wallet Connect v2
  • How To
    • Execute a Local Swap
    • Execute a Cross Chain Swap
    • Use Limit Orders
    • Lend and Borrow
    • Provision Liquidity
      • Adding Liquidity
      • Removing liquidity
    • Yield Farm
    • Use Our Transaction Decoder
    • Submit an RFQ
    • Subscribe to Events
    • Stream Data (WebSocket)
      • Stream Transaction
      • Stream Trade
      • Stream Gas
      • Stream Ticker Price
    • Source Pricing
    • Track Memecoins
    • Manage Token Approvals
  • Use Cases
    • Trade Reconciliation
    • Portfolio Management
    • Trading Features
    • On-Chain Data: DEX Liquidity Pool Forensics
    • Transaction and Pool Analysis
  • Account Abstraction
    • Overview
      • User Endpoints
      • Paymaster Endpoint
      • Bundler Endpoint
    • ⚙️SDK - Overview
  • Additional Info
    • Error Messages
    • Client-Side Security Essentials
    • Compute Unit Costs
    • API Metadata
    • Audit Certificate
    • Brand Assets
    • FAQs
    • Quicknode Marketplace
      • DEX
      • Lending Protocols
  • ID's
    • Chain IDs
    • Bridge IDs
      • Internal Chain IDs for Bridges
    • DEX IDs
    • Lending Protocol IDs
    • Yield Aggregator ID
    • Liquid Staking IDs
    • Oracle IDs
    • Stablecoin IDs
    • Derivatives IDs
    • Synthetics IDs
  • Mapping
    • Blockchains
    • DEXs
      • Uniswap V2
      • Uniswap V3
      • Sushiswap
      • PancakeSwap
      • Curve
      • Balancer
    • Lending Protocols
      • Aave
      • Compound
  • Protocol Spender
    • Spender list
Powered by GitBook
On this page
  • Step 1: Check the allowance of the lending pool on the erc20 token the user wants to deposit.
  • Step 2: Approve the lending pool from the Token Contract
  • Step 3: Deposit
  • Step 4: Borrow
  • Step 5: Repay
  • Step 6: Withdraw
  1. How To

Lend and Borrow

PreviousUse Limit OrdersNextProvision Liquidity

Last updated 1 year ago

This section explains the integration and usage of lend and borrow protocols for deposit, withdraw and many more functionalities.

Step 1: Check the allowance of the lending pool on the erc20 token the user wants to deposit.

To initiate a swap, first determine if the lending pool has the necessary allowance to access the tokens. This can be done using the following API endpoint:


Sample Request:

https://api.expand.network/fungibletoken/getuserallowance?owner=0x6Fb447Ae94F5180254D436A693907a1f57696900&tokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&spender=0xBA12222222228d8Ba445958a75a0704d566BF2C8

Sample Response:

{
    "status": 200,
    "msg": "success",
    "data": {
        "allowance": "999000000000000000000"
    }
}

Step 2: Approve the lending pool from the Token Contract

If the allowance is less than the token amount to deposit, the user must approve the lending pool from the erc20 token contract. This can be done using the following API endpoint:


Sample Request:

{
    "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006", 
    "tokenAddress":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",  
    "amount": "1000000000000000000000",                  
    "to": "0x828b154032950c8ff7cf8085d841723db2696056", 
    "gas": "100000",
    "chainId": "1"
}

Sample Response:

{
    "status": 200,
    "msg": "success",
    "data": {
        "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
        "to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "value": "0",
        "gas": "100000",
        "data": "0x095ea7b3000000000000000000000000828b154032950c8ff7cf8085d841723db269605600000000000000000000000000000000000000000000003635c9adc5dea00000"
    }
}

Step 3: Deposit

In a particular lending pool, the user can deposit the token. The user will get the equivalent amount of "aToken" on a token deposit.

This can be done using the following API endpoint:


Sample Request:

{
    "lendborrowId": "1000",
    "asset": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    "amount": "10000000000000000",
    "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "onBehalfOf": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "gas": "408298"
}

Sample Response:

{
    "status": 200,
    "msg": "success",
    "data": {
        "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
        "to": "0x4bd5643ac6f66a5237E18bfA7d47cF22f1c9F210",
        "value": "0",
        "gas": "408298",
        "data": "0xe8eda9df000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d6000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000063056e00436da25bcf48a40dfbbdcc70893510060000000000000000000000000000000000000000000000000000000000000000"
    }
}

Users can only deposit the token and earn interest upon it. Borrowing is another option for the user.

Step 4: Borrow

The user can borrow the tokens based on the amount of collateral deposited.

This can be done using the following API endpoint:


Sample Request:

{
    "lendborrowId": "1000",
    "asset": "0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F",
    "amount": "100",
    "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "onBehalfOf": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "interestRateMode": "2",
    "gas": "408298"
}

Sample Response:

{
    "status": 200,
    "msg": "success",
    "data": {
        "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
        "to": "0x4bd5643ac6f66a5237E18bfA7d47cF22f1c9F210",
        "value": "0",
        "gas": "408298",
        "data": "0xa415bcad000000000000000000000000fc1ab0379db4b6ad8bf5bc1382e108a341e2eabb00000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000063056e00436da25bcf48a40dfbbdcc7089351006"
    }
}

Step 5: Repay

The user needs to repay the token amount borrowed with interest. To repay the token, the user need to follow step 1 and 2. The token to repay should approve the lending pool.

This can be done using the following API endpoint:


Sample Request:

{
    "lendborrowId": "1000",
    "asset": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
    "amount": "100000",
    "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "onBehalfOf": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "interestRateMode": "2",
    "gas": "408298"
}

Sample Response:

{
    "status": 200,
    "msg": "success",
    "data": {
        "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
        "to": "0x4bd5643ac6f66a5237E18bfA7d47cF22f1c9F210",
        "value": "0",
        "gas": "408298",
        "data": "0x573ade81000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000063056e00436da25bcf48a40dfbbdcc7089351006"
    }
}

Step 6: Withdraw

In this step, user withdraws the amount of the token deposited as collateral. To withdraw the token, the user needs to provide the aTokens that the user initially received.

This can be done using the following API endpoint:


Sample Request:

{
    "lendborrowId": "1000",
    "asset": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
    "amount": "1000000000000000000",
    "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "to": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
    "gas": "408298"
}

Sample Response:

{
    "status": 200,
    "msg": "success",
    "data": {
        "from": "0x63056E00436Da25BcF48A40dfBbDcc7089351006",
        "to": "0x4bd5643ac6f66a5237E18bfA7d47cF22f1c9F210",
        "value": "0",
        "gas": "408298",
        "data": "0x69328dec0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000063056e00436da25bcf48a40dfbbdcc7089351006"
    }
}

API URL:

API URL:

API URL:

API URL:

API URL:

API URL:

https://api.expand.network/fungibletoken/getuserallowance
https://api.expand.network/fungibletoken/approve
https://api.expand.network/lendborrow/deposit
https://api.expand.network/lendborrow/borrow
https://api.expand.network/lendborrow/repay
https://api.expand.network/lendborrow/withdraw