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
  1. USE CASES AND EXAMPLES
  2. More examples

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
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)
PreviousFee collectionNextArchitecture

Last updated 2 months ago