🌲
Teller v2
Dev Guide
Dev Guide
  • Introduction
  • Borrow
    • Getting a loan offer
    • Executing a Loan
  • ROLLOVER
    • Getting Rollover Details
    • Executing a Rollover
  • REPAY
    • Getting Repay Details
    • Executing a Repayment
Powered by GitBook
On this page
  1. REPAY

Getting Repay Details

Getting user loans

The first step in repaying is to get the user loans. To do this, first query the subgraph using the user's wallet address

{
  user(id: "0x359e8a8ab1061ec972d9b8f807577563432b8994") { # replace this by the user id
    borrowers {
      marketplaceId
      tokenVolumes {
        aprAverage
        aprActiveAverage
        lendingTokenAddress
      }
      loans {
        all(where: { status_not: "Repaid" }) {
          totalRepaidPrincipal
          principal
          borrowerAddress
          lenderAddress
          apr
          marketplaceId
          lendingTokenAddress
          loanDuration
          paymentCycle
          paymentCycleAmount
          metadataURI
          bidId
          acceptedTimestamp
          lastRepaidTimestamp
          nextDueDate
          paymentDefaultDuration
          status
          expiresAt
          collateral {
            type
            collateralAddress
            token {
              name
              symbol
              decimals
            }
            amount
            tokenId
            status
          }
          marketplace {
            paymentType
          }
        }
      }
    }
  }
}

The important element to note here is querying the loans by status that has not been Repaid

This returns a list of all the loans for a specific user wallet, and with the most important information to display in the front end.

{
    "data": {
        "user": {
            "borrowers": [
                {
                    "loans": {
                        "all": [
                            {
                                "acceptedTimestamp": "1729976725",
                                "apr": "2500",
                                "bidId": "4295",
                                "borrowerAddress": "0x359e8a8ab1061ec972d9b8f807577563432b8994",
                                "collateral": [
                                    {
                                        "amount": "5000000000000000000",
                                        "collateralAddress": "0x692ac1e363ae34b6b489148152b12e2785a3d8d6",
                                        "status": "Deposited",
                                        "token": {
                                            "decimals": "18",
                                            "name": "Polytrade (PoS)",
                                            "symbol": "TRADE"
                                        },
                                        "tokenId": "0",
                                        "type": "ERC20"
                                    }
                                ],
                                "expiresAt": "1730581525",
                                "lastRepaidTimestamp": "0",
                                "lenderAddress": "0x0854d0c201fd3f9e0ae2341c92b28d289234549c",
                                "lendingTokenAddress": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
                                "loanDuration": "604800",
                                "marketplace": {
                                    "paymentType": "EMI"
                                },
                                "marketplaceId": "33",
                                "metadataURI": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
                                "nextDueDate": "1730581525",
                                "paymentCycle": "604800",
                                "paymentCycleAmount": "607360",
                                "paymentDefaultDuration": "0",
                                "principal": "604395",
                                "status": "Accepted",
                                "totalRepaidPrincipal": "0"
                            }
                        ]
                    },
                    "marketplaceId": "33",
                    "tokenVolumes": [
                        {
                            "aprActiveAverage": "2500",
                            "aprAverage": "2500",
                            "lendingTokenAddress": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174"
                        }
                    ]
                }
            ]
        }
    }
}

PreviousExecuting a RolloverNextExecuting a Repayment

Last updated 7 months ago