General description

The web3 defilama bridge allows a developer to incorporate defilama data into a smart contract. In order to use the bridge, first go to the defilama site to find the data which the user wishes to incorporate. Once one finds the defilama web2 request, one can convert this to a web3 request as follows. Start with the API doc for defilama located at https://defillama.com/docs/api The service name is the category of the api followed by the endpoint name, and can start with The request data should include the parameters associated with the service. Once you have the response, you can use keypath, api, and multiplier to convert the result to a format available in eth, and the values of these parameters is described in API tutorial.

Example 1 - Get the current circulating value on the harmony blockchain

The end point for this data is /stablecoinchains in category stablecoins. So the service and data are:
service; defilama/stablecoins/stablecoinchains
data: (blank)
We can use the swagger ui to get the result of the web2 call. Calling https://stablecoins.llama.fi/stablecoinchains we get the result
[
 {
    "gecko_id": "harmony",
    "totalCirculatingUSD": {
      "peggedUSD": 8854899.484894985
    },
    "tokenSymbol": "ONE",
    "name": "Harmony"
  }
]
We want to first select the object for which the gecko_id is harmony and then get the peggedUSD value to select the resulting value we set keypath to
  keypath: gecko_id=harmony.totalCirculatingUSD.peggedUSD
  
To make this available for a smart contract, we will need to multiply this value by a multiplier and set the result to uint256. This means that the following fields should be
abi: uint256
multiplier: 1000000000000000000

Example 2 - Get the total circulating value for USDT on Thu May 12 2022

Look at the defilama api web page we can find the ID for USDT by calling https://stablecoins.llama.fi/stablecoins?includePrices=true From this call we see that the id for USDT is 1. The call to get the prices of USDT is https://stablecoins.llama.fi/stablecoincharts/all?stablecoin=1
[
  {
    "date": "1609459200",
    "totalCirculating": {
      "peggedUSD": 20934027063.04073
    },
    "totalUnreleased": {
      "peggedUSD": 0
    },
    "totalCirculatingUSD": {
      "peggedUSD": 20935116985.493526
    },
    "totalMintedUSD": {
      "peggedUSD": 0
    },
    "totalBridgedToUSD": {
      "peggedUSD": 0
    }
}
]
we want to get prices for May 12 2022 which is unix date 1652313600 we can select the keypath using
  keypath: date=1652313600.totalCirculating.peggedUSD
Setting the multiplier and abi we get
abi: uint256
multiplier: 1000000000000000000

Example 3 - Get list of chains via IPFS

The previous examples take one number, but it may be useful to get a large amount of data. This can be done using the ipfs inference For example to get a list of all chains available on defilama, one uses the web2 interface under category TVL by calling https://api.llama.fi/chains To retrieve the list of chains for which tvl information is available, the calls are
service: defilama/tvl/chains
keypath: (blank)
abi: ipfs
data: (blank)
multiplier: (blank)