Fulcrum liquidity check

Monitor the liquidity and check when you can claim back your tokens

Fulcrum is a Defi platform for tokenized margin lending and trading.

Using Fulcrum, you can lend your tokens and earn interests in crypto. Although in principle your tokens can be redeemed any time you want, in practice you need to wait until there is available (non-borrowed) liquidity to claim your loan back. One of the ways you can use HAL is to monitor the liquidity and check when you can claim back your tokens

How does landing work on Fulcrum?

Lending on Fulcrum is powered by iTokens, which are global lending pools. Each asset has a single iToken equivalent (ETH as iETH, DAI has iDAI, etc.), and has an independent interest rate paid to lenders who have deposited funds into the contract. The interest earned is proportional to the amount of iToken held by each lender. iTokens are minted by transferring the underlying asset to the contract, calling mint, and receiving back an equivalent amount of the iToken (ERC20) at the current iToken price. iTokens have an on-chain API to query current "redemption value".

Using Fulcrum you can lend the following tokens, receiving the equivalent iToken:

You can retrieve your original tokens when the balanceOf() shows there is enough liquidity for that token.

Take a look at this example:

const Web3 = require('web3');

const infuraEndPoint = 'https://mainnet.infura.io/v3/FOOBAR'; // Your InfuraEndPoint
const web3 = new Web3(new Web3.providers.HttpProvider(infuraEndPoint));

const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'; // WETH address
const iETH = '0x77f973FCaF871459aa58cd81881Ce453759281bC'; // iETH address

const tokenAbi = [{
  constant: true,
  inputs: [{
    name: '_owner',
    type: 'address',
  }],
  name: 'balanceOf',
  outputs: [{
    name: 'balance',
    type: 'uint256',
  }],
  payable: false,
  type: 'function',
}];

const getData = async (token, iToken) => {
  const tokenInst = await new web3.eth.Contract(tokenAbi, token);
  const balance = await tokenInst.methods.balanceOf(iToken).call();
  return console.log('😎 Balance: ', balance);
};

getData(WETH, iETH);

Use HAL to check available liquidity

Using HAL you can create a trigger to check if there is available liquidity to claim your loan back, no coding needed 🤘.

What do you need?

  1. A HAL account 😈

  2. The token address

  3. the iToken address

Let's go!

1. Go to "Contracts triggers" page and create a new trigger

2. in the contract address field, insert the token address (ie. 0xdd974d5c2e2928dea5f71b9825b8b646686bd200)

3. Select the function balanceOf, insert the iToken address (ie. 0x1cc9567ea2eb740824a45f8026ccf8e46973234d), then insert a value

4. Select an action (ie. send an email)

5. Name your trigger, save. Have a beer 🍺and wait 😴

ERC20 tokens usually have 18 decimal digits. So, if you want to check if the total available liquidity is bigger than 1 KNC, you have to insert 1 000 000 000 000 000 000.

Using the GraphQL layer

You can create a trigger programmatically using HAL's GraphQL layer. Simply use this mutation:

mutation {
  createContractsTrigger(input: {
        name: "Check liquidity",
    type: ContractsTrigger,
    statement: {
      contract: {
        address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // ETH address
        abi: [...]
      },
        inputs: [
        {
          type: "address",
          name: "_owner",
          value: "0x77f973FCaF871459aa58cd81881Ce453759281bC" // iETH address
        }
      ],
      outputFilters: [
        {
          parameter: {
            name: "balance",
            type: "uint256"
          },
          returnIndex: 0,
          condition: {
            attribute: "1000000000000000000", // 1 ETH
            predicate: "BiggerThan"
          }
        }
      ],
      "method": {
        "name": "balanceOf"
      }
    },
    actions: [
      {
        type: Email,
        attributes: {
          body: "Hey!",
          subject: "You can reedem your loan!",
          to: [
            "foo@bar.it"
          ]
        }
      }
    ]
  }) {
    UUID
  }
}

Last updated