Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 222 additions & 0 deletions examples/02-simple-transfer-with-inputs/abis/ERC20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
},
{
"name": "_spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"payable": true,
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
},
{
"indexed": true,
"name": "spender",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]
11 changes: 10 additions & 1 deletion examples/02-simple-transfer-with-inputs/tests/task.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'
import { Interface } from 'ethers'

import ERC20Abi from '../abis/ERC20.json'

const ERC20Interface = new Interface(ERC20Abi)

describe('Task', () => {
const taskDir = './build'
Expand All @@ -21,7 +26,11 @@ describe('Task', () => {

const calls: ContractCallMock[] = [
{
request: { to: inputs.token, chainId: inputs.chainId, fnSelector: '0x313ce567' }, // decimals
request: {
to: inputs.token,
chainId: inputs.chainId,
fnSelector: ERC20Interface.getFunction('decimals')!.selector,
},
response: { value: '6', abiType: 'uint8' },
},
]
Expand Down
26 changes: 10 additions & 16 deletions examples/03-transfer-balance-threshold/tests/task.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'
import { Interface } from 'ethers'

import ERC20Abi from '../abis/ERC20.json'

const ERC20Interface = new Interface(ERC20Abi)

describe('Task', () => {
const taskDir = './build'
Expand All @@ -25,29 +30,18 @@ describe('Task', () => {
request: {
to: inputs.token,
chainId: inputs.chainId,
fnSelector: '0x70a08231', // `balanceOf`
params: [
{
value: inputs.recipient,
abiType: 'address',
},
],
},
response: {
value: balance,
abiType: 'uint256',
fnSelector: ERC20Interface.getFunction('balanceOf')!.selector,
params: [{ value: inputs.recipient, abiType: 'address' }],
},
response: { value: balance, abiType: 'uint256' },
},
{
request: {
to: inputs.token,
chainId: inputs.chainId,
fnSelector: '0x313ce567', // `decimals`
},
response: {
value: '6',
abiType: 'uint8',
fnSelector: ERC20Interface.getFunction('decimals')!.selector,
},
response: { value: '6', abiType: 'uint8' },
},
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, GetPriceMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'
import { Interface } from 'ethers'

import ERC20Abi from '../abis/ERC20.json'

const ERC20Interface = new Interface(ERC20Abi)

describe('Task', () => {
const taskDir = './build'
Expand All @@ -22,10 +27,7 @@ describe('Task', () => {

const prices: GetPriceMock[] = [
{
request: {
token: inputs.token,
chainId: inputs.chainId,
},
request: { token: inputs.token, chainId: inputs.chainId },
response: ['1000000000000000000'], // 1 token = 1 USD
},
]
Expand All @@ -35,29 +37,18 @@ describe('Task', () => {
request: {
to: inputs.token,
chainId: inputs.chainId,
fnSelector: '0x70a08231', // `balanceOf`,
params: [
{
value: inputs.recipient,
abiType: 'address',
},
],
},
response: {
value: balance,
abiType: 'uint256',
fnSelector: ERC20Interface.getFunction('balanceOf')!.selector,
params: [{ value: inputs.recipient, abiType: 'address' }],
},
response: { value: balance, abiType: 'uint256' },
},
{
request: {
to: inputs.token,
chainId: inputs.chainId,
fnSelector: '0x313ce567', // `decimals`
},
response: {
value: '6',
abiType: 'uint8',
fnSelector: ERC20Interface.getFunction('decimals')!.selector,
},
response: { value: '6', abiType: 'uint8' },
},
]

Expand Down
Loading