Automated refunds

The goal here is to integrate a backend to send refunds through Mimic Protocol.

Task

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

import { TaskInput } from './types'

export default function main(environment: Environment, input: TaskInput) {
  environment.transfer(
    chainId: Networks.mainnet,
    to: input.recipient,
    token: input.token,
    amount: token.amount,
    feeAmount: input.feeAmount,
  )
  log.info('Created transfer intent')
}

Manifest

version: 1.0.0
name: Client refunds
description: Refunds clients based on past orders
trigger: 
  - type: "immediate"
inputs:
  - token: address
  - amount: number
  - recipient: address
  - feeAmount: number

Backend

import { ethers } from 'ethers'
import { Task } from '@mimic-protocol/sdk'

// Fetch the refund info from an external service
const { token, amount, recipient } = await getRefundData()

// Prepare your task config data
const configData = {
  name: `refund-${Date.now()}`,
  data: { token, amount, recipient }
}

// Submit the signed task config to Mimic Protocol
const wallet = new ethers.Wallet(env.process.PRIVATE_KEY)
const task = new Task('YOUR_TASK_ID', wallet)
await task.execute(configData)

Last updated