Mimic Protocol
  • GENERAL
    • What's Mimic Protocol
    • How it works
    • Roadmap
  • USE CASES AND EXAMPLES
    • Build a simple task
    • More examples
      • Account refilling
      • Block trade
      • Fee collection
      • Automated refunds
  • DEVELOPERS
    • Architecture
    • CLI
    • API
  • RESOURCES
    • Whitepaper
    • Glossary
    • Security
    • Press kit
    • Contact
Powered by GitBook
On this page
  • Task
  • Manifest
  1. USE CASES AND EXAMPLES
  2. More examples

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: cron
inputs:
  - settler: address
  - chainId: number
  - tokenIn: address
  - amount: number
  - tokenOut: address
  - slippage: number
PreviousAccount refillingNextFee collection

Last updated 2 months ago