Block trade

The goal of this task is to sell tokens up-to a threshold per month.

Task

import { Environment, log } from '@mimicprotocol/lib-ts'

import { TaskInput } from './types'

export default function main(environment: Environment, input: TaskInput) {
  const intents = environment.getSwapIntents(
    'executed', 
    input.now.startOfMonth(),
    input.now.endOfMonth(),
    tokenIn: input.tokenIn, 
    tokenOut: input.tokenOut
  )
  
  const totalSwapped = intents.sum(intent => intent.amountIn)
  if (totalSwapped <= input.monthlyThreshold) {
    const amountOut = environment.convertTo(
      input.chainId, 
      input.tokenIn, 
      input.amount, 
      input.tokenOut
    )
    
    const minAmountOut = amountOut * (1 - input.slippage * 100)
	  
    environment.swap(
      sourceChain: input.chainId,
      tokenIn: input.tokenIn,
      amountIn: input.amount,
      tokenOut: input.tokenOut,
      minAmountOut: minAmountOut,
    )
    log.info('Created swap intent')
  } else {
    log.debug('Monthly threshold reached')
  }
}

Manifest

version: 1.0.0
name: Block Trade Task
description: Sell tokens up-to a monthly threshold.
trigger:
  - type: cron
inputs:
  - settler: address
  - chainId: number
  - tokenIn: address
  - amount: number
  - tokenOut: address
  - slippage: number

Last updated