Curve 3pool Proportion Monitoring

The previous sample showed the most simplified example of the Script feature. It can be also utilized in more complicated scenarios. For example, monitoring the proportion of tokens in a liquidity pool.

Here we take Curve 3pool as an example to monitor the proportion of USDT:

Check the script here:

The script code is as following:

Here we use [Cache] to store last result, and define a delta variant to monitor the change of the ratio.

export const name = '3pool USDT';
export const description = 'curve 3pool monitor';
export const tag = 'curve 3pool';

const { Contract, utils, BigNumber } = ethers;
const ERC20 = ['function balanceOf(address) view returns (uint)'];

const formatNumber = (num: number, decimals:number = 4 ) => Number(num.toFixed(decimals));

const formatBN = (wei: BigNumber, unit:number = 18) => Number(utils.formatUnits(wei, unit));

export const run = async () => {
  const provider: Web3Provider = evm.getProvider('ethereum');

  const USDT = new Contract('0xdAC17F958D2ee523a2206206994597C13D831ec7', ERC20, provider);
  const USDC = new Contract('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', ERC20, provider);
  const DAI = new Contract('0x6B175474E89094C44Da98b954EedeAC495271d0F', ERC20, provider);

  const USDTAmount = formatBN(await USDT.balanceOf(CURVE_LIQUIDITY_FARMING_POOL), 6);
  const USDCAmount = formatBN(await USDC.balanceOf(CURVE_LIQUIDITY_FARMING_POOL), 6)
  const DAIAmount = formatBN(await DAI.balanceOf(CURVE_LIQUIDITY_FARMING_POOL), 18)

  const totalAmount = USDTAmount + USDCAmount + DAIAmount;
  const usdtRatio = formatNumber(USDTAmount / totalAmount * 100, 2);

  const key = '3pool-usdt';
  let lastUSDTRatio = await cache[key] || 0;
  const ratioDeltaAbs=Math.abs(usdtRatio-lastUSDTRatio);
    cache[key] = usdtRatio;

  return {

Once the Script is created, it can be saved and run, the result is as below:

  "USDTAmount": 247110557.436453,
  "USDCAmount": 357517694.26593,
  "DAIAmount": 349215555.09886163,
  "usdtRatio": 25.91,
  "ratioDeltaAbs": 7.7499999999999964

Now you can schedule a task for the script:

Then set the alert to notify my Twitter bot:

So the alert will notify me when the change is above 2%, and some variants from the result are filled in the notify message. The condition will be checked every 1 minute.

⚠️ Warning: $USDT ratio of @CurveFinance 3pool is now {usdtRatio}%, $USDC balance is {USDCAmount}, $DAI balance is {DAIAmount}, for more info, see: Powered by @compassDAO

Now you get your perfect Twitter bot:

A similar case you can use to monitor the Curve stETH pool (just simply change the token addresses in script):

Last updated