Automated refunds

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

Task

import { Transfer, ERC20Token, Address, BigInt, Ethereum } from '@mimicprotocol/lib-ts'

import { inputs } from './types'

export default function main() {
  // Create token instance from address
  const token = ERC20Token.fromString(inputs.token, Ethereum.CHAIN_ID)
  
  // Create transfer intent
  Transfer
    .create(
      token,
      BigInt.fromString(inputs.amount),
      Address.fromString(inputs.recipient),
      BigInt.fromString(inputs.fee)
    )
    .send()
  
  console.log('Created transfer intent')
}

Manifest

version: 1.0.0
name: Client refunds
description: Refunds clients based on past orders
inputs:
  - token: string    # Token contract address
  - amount: string   # Amount in wei (as string)
  - recipient: string # Recipient address
  - fee: string      # Max fee in wei (as string)

Backend

import { Client, EthersSigner } from '@mimicprotocol/sdk'

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

// Create client with signer
const signer = EthersSigner.fromPrivateKey(process.env.PRIVATE_KEY)
const client = new Client({ signer })

// Get task manifest from deployed task
const taskCid = 'Qm...' // Task must be deployed first
const manifest = await client.tasks.getManifest(taskCid)

// Submit the signed task config to Mimic Protocol for one-time execution
await client.configs.signAndCreate({
  description: `Refund execution - ${Date.now()}`,
  taskCid,
  version: '1.0.0',
  manifest,
  trigger: {
    type: 'cron',
    schedule: '0 0 * * *', // Will execute immediately on next cron cycle
    delta: '1h',
    endDate: 0
  },
  input: { token, amount, recipient, fee },
})

Last updated