Fee collection

Collect

The goal of this task is to move tokens from an external source to the settler itself.

Task

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

import { ExternalSource, TaskInput } from './types'

export default function main(environment: Environment, input: TaskInput) {
  const tokens = environment.getRelevantERC20s(input.chainId, input.source)
	
  for (const token of tokens) {
    environment.call(
      settler: input.settler,
      chainId: input.chainId, 
      target: input.source, 
      data: ExternalSource.claim.encode(token.address, token.balance, input.settler),
      feeToken: input.feeToken,
      feeAmount: input.feeAmount,
    )
    log.info('Created call intent')
  }
}

Manifest

version: 1.0.0
name: Collect Task
description: Collects all tokens from an external source to the settler
trigger:
  - type: cron
inputs:
  - chainId: number
  - source: address
  - settler: address
  - target: address
  - feeToken: address
  - feeAmount: number
abis:
  - './abis/ExternalSource.json'

Swap

The goal of this task is to swap all tokens above a certain value in dollars to a specific token on a network.

Task

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

import { TaskInput } from './types'

export default function main(environment: Environment, input: TaskInput) {
  const tokens = environment.getRelevantERC20s(
    input.chainId,
    input.settler,
    input.thresholdUsd,
    input.ignoredTokens
  )
	
  for (const token of tokens) {
    const minAmountOut = token.amountInUsd * (1 - input.slippage * 100)
    environment.swap(
      settler: settler, 
      sourceChain: input.chainId,
      tokenIn: token.address,
      tokenOut: input.usdc,
      amountIn: token.balance,
      minAmountOut: minAmountOut,
    )
    log.info('Created swap intent')
  }
}

Manifest

version: 1.0.0
name: Swap Task
description: Swap all tokens above certain threshold in dollars to a token
trigger:
  - type: cron
inputs:
  - chainId: number
  - settler: address
  - thresholdUsd: number
  - slippage: number 
  - usdc: address
  - ignoredTokens: address[]

Bridge

The goal of this task is to bridge all tokens from all chains to a main one at the end of the month.

Task

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

import { TaskInput } from './types'

export default function main(environment: Environment, input: TaskInput) {
  const sourceUsdc = ERC20.load(input.sourceChain, input.sourceUsdc)
  const balance = sourceUsdc.balanceOf(environment.signer)
  if (balance >= input.thresholdUsd) {
    environment.swap(
      settler: settler,
      sourceChain: input.sourceChain,
      tokenIn: input.sourceUsdc,
      amountIn: balance,
      destinationChain: input.destinationChain,
      tokenOut: input.destinationUsdc,
      minAmountOut: balance - input.feeAmount
    )
  }
  log.info('Created bridge intent')
}

Manifest

version: 1.0.0
name: Bridge Task
description: Bridges all tokens above certain threshold in dollars to a token
trigger:
  - type: balance
  - schedule: gte
inputs:
  - settler: address
  - thresholdUsd: number
  - feeAmount: number 
  - sourceChain: number
  - sourceUsdc: address
  - destinationChain: number
  - destinationUsdc: address
abis:
  - './abis/ERC20.json'

Withdraw

The goal of this task is to withdraw the whole amount of USDC to a recipient address paying the service fees.

Implementation

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

import { TaskInput } from './types'

export default function main(environment: Environment, input: TaskInput) {
  const usdc = ERC20.load(input.chainId, input.usdc)
  const balance = usdc.balanceOf(environment.signer)
  const balanceAfterSolverFee = balance - input.solverFeeAmount
  const feeAmount = balanceAfterSolverFee.mul(input.serviceFeePct)
  const balanceAfterFees = balanceAfterSolverFee - feeAmount

  environment.transfer(
    settler: settler,
    chainId: input.chainId,
    token: input.usdc,
    amount: balanceAfterFees,
    to: input.recipient,
    feeAmount: input.solverFeeAmount / 2,
  )
	
  environment.transfer(
    settler: settler,
    chainId: input.chainId,
    token: input.usdc,
    amount: feeAmount,
    to: input.feeCollector,
    feeAmount: input.solverFeeAmount / 2,
  )

  log.info('Created withdraw intent')
}

Manifest

version: 1.0.0
name: Withdraw Task
description: Withdraws all USDC charging a service fee
trigger:
  - type: cron
inputs:
  - settler: address
  - chainId: number
  - usdc: address
  - recipient: address
  - solverFeeAmount: number 
  - serviceFeePct: number
  - feeCollector: address
abis:
  - './abis/ERC20.json'

Last updated