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
11 changes: 5 additions & 6 deletions examples/1-simple-transfer/src/task.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Address, BigInt, Transfer } from '@mimicprotocol/lib-ts'
import { Address, BigInt, ERC20Token, Transfer } from '@mimicprotocol/lib-ts'

export default function main(): void {
const chainId = 10
const recipient = Address.fromString('0xbcE3248eDE29116e4bD18416dcC2DFca668Eeb84')
const USDC = Address.fromString('0x7F5c764cBc14f9669B88837ca1490cCa17c31607')
const USDC = ERC20Token.fromString('0x7F5c764cBc14f9669B88837ca1490cCa17c31607', 10)
const amount = BigInt.fromStringDecimal('1', 6)
const fee = BigInt.fromStringDecimal('0.1', 6)
const recipient = Address.fromString('0xbcE3248eDE29116e4bD18416dcC2DFca668Eeb84')
const maxFee = BigInt.fromStringDecimal('0.1', 6)

Transfer.create(chainId, USDC, amount, recipient, fee).send()
Transfer.create(USDC, amount, recipient, maxFee).send()
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { runTask, Transfer } from '@mimicprotocol/test-ts'
import { Context, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

describe('Task', () => {
const taskDir = './'

it('produces the expected intents', async () => {
const context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
timestamp: Date.now(),
}
const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
timestamp: Date.now(),
}

it('produces the expected intents', async () => {
const intents = (await runTask(taskDir, context)) as Transfer[]

expect(intents).to.be.an('array').that.is.not.empty
expect(intents).to.have.lengthOf(1)

expect(intents[0].type).to.be.equal('transfer')
expect(intents[0].settler).to.be.equal(context.settlers[0].address)
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
expect(intents[0].user).to.be.equal(context.user)
expect(intents[0].chainId).to.be.equal(10)
expect(intents[0].maxFees).to.have.lengthOf(1)
Expand Down
2 changes: 1 addition & 1 deletion examples/2-simple-transfer-with-inputs/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ inputs:
- token: address
- amount: uint256
- recipient: address
- fee: uint256
- maxFee: uint256
5 changes: 3 additions & 2 deletions examples/2-simple-transfer-with-inputs/src/task.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Transfer } from '@mimicprotocol/lib-ts'
import { ERC20Token, Transfer } from '@mimicprotocol/lib-ts'

import { inputs } from './types'

export default function main(): void {
Transfer.create(inputs.chainId, inputs.token, inputs.amount, inputs.recipient, inputs.fee).send()
const token = ERC20Token.fromAddress(inputs.token, inputs.chainId)
Transfer.create(token, inputs.amount, inputs.recipient, inputs.maxFee).send()
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import { runTask, Transfer } from '@mimicprotocol/test-ts'
import { Context, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

describe('Task', () => {
const taskDir = './'

it('produces the expected intents', async () => {
const context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
timestamp: Date.now(),
}
const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
timestamp: Date.now(),
}

const inputs = {
chainId: 10, // Optimism
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
amount: '1000000', // 1 USDC
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
fee: '100000', // 0.1 USDC
}
const inputs = {
chainId: 10, // Optimism
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
amount: '1000000', // 1 USDC
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
maxFee: '100000', // 0.1 USDC
}

it('produces the expected intents', async () => {
const intents = (await runTask(taskDir, context, { inputs })) as Transfer[]

expect(intents).to.be.an('array').that.is.not.empty
expect(intents).to.have.lengthOf(1)

expect(intents[0].type).to.be.equal('transfer')
expect(intents[0].settler).to.be.equal(context.settlers[0].address)
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
expect(intents[0].user).to.be.equal(context.user)
expect(intents[0].chainId).to.be.equal(inputs.chainId)
expect(intents[0].maxFees).to.have.lengthOf(1)
expect(intents[0].maxFees[0].token).to.be.equal(inputs.token)
expect(intents[0].maxFees[0].amount).to.be.equal(inputs.fee)
expect(intents[0].maxFees[0].amount).to.be.equal(inputs.maxFee)

expect(intents[0].transfers).to.have.lengthOf(1)
expect(intents[0].transfers[0].token).to.be.equal(inputs.token)
Expand Down
2 changes: 1 addition & 1 deletion examples/3-transfer-balance-threshold/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inputs:
- token: address
- amount: uint256
- recipient: address
- fee: uint256
- maxFee: uint256
- threshold: uint256
abis:
- ERC20: ./abis/ERC20.json
5 changes: 3 additions & 2 deletions examples/3-transfer-balance-threshold/src/task.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transfer } from '@mimicprotocol/lib-ts'
import { ERC20Token, Transfer } from '@mimicprotocol/lib-ts'

import { ERC20 } from './types/ERC20'
import { inputs } from './types'
Expand All @@ -8,6 +8,7 @@ export default function main(): void {
const balance = tokenContract.balanceOf(inputs.recipient)

if (balance.lt(inputs.threshold)) {
Transfer.create(inputs.chainId, inputs.token, inputs.amount, inputs.recipient, inputs.fee).send()
const token = ERC20Token.fromAddress(inputs.token, inputs.chainId)
Transfer.create(token, inputs.amount, inputs.recipient, inputs.maxFee).send()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ContractCall, runTask, Transfer } from '@mimicprotocol/test-ts'
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

describe('Task', () => {
const taskDir = './'

const context = {
const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
timestamp: Date.now(),
Expand All @@ -15,17 +15,21 @@ describe('Task', () => {
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
amount: '1000000', // 1 USDC
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
fee: '100000', // 0.1 USDC
maxFee: '100000', // 0.1 USDC
threshold: '10000000', // 10 USDC
}

const buildCalls = (balance: string): ContractCall[] => [
const buildCalls = (balance: string): ContractCallMock[] => [
{
to: inputs.token,
chainId: inputs.chainId,
data: '0x70a08231', // `balanceOf` fn selector
output: balance,
outputType: 'uint256',
request: {
to: inputs.token,
chainId: inputs.chainId,
data: '0x70a08231', // `balanceOf` fn selector
},
response: {
value: balance,
abiType: 'uint256',
},
},
]

Expand All @@ -35,17 +39,15 @@ describe('Task', () => {

it('produces the expected intents', async () => {
const intents = (await runTask(taskDir, context, { inputs, calls })) as Transfer[]

expect(intents).to.be.an('array').that.is.not.empty
expect(intents).to.have.lengthOf(1)

expect(intents[0].type).to.be.equal('transfer')
expect(intents[0].settler).to.be.equal(context.settlers[0].address)
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
expect(intents[0].user).to.be.equal(context.user)
expect(intents[0].chainId).to.be.equal(inputs.chainId)
expect(intents[0].maxFees).to.have.lengthOf(1)
expect(intents[0].maxFees[0].token).to.be.equal(inputs.token)
expect(intents[0].maxFees[0].amount).to.be.equal(inputs.fee)
expect(intents[0].maxFees[0].amount).to.be.equal(inputs.maxFee)

expect(intents[0].transfers).to.have.lengthOf(1)
expect(intents[0].transfers[0].token).to.be.equal(inputs.token)
Expand All @@ -60,8 +62,7 @@ describe('Task', () => {

it('does not produce any intent', async () => {
const intents = await runTask(taskDir, context, { inputs, calls })

expect(intents).to.be.an('array').that.is.empty
expect(intents).to.be.empty
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inputs:
- token: address
- amount: uint256
- recipient: address
- fee: uint256
- maxFee: uint256
- thresholdUSD: uint32
abis:
- ERC20: ./abis/ERC20.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export default function main(): void {
log.info('Balance in USD: ' + balanceInUsd.toString())

if (balanceInUsd.lt(thresholdUsd)) {
Transfer.create(inputs.chainId, inputs.token, inputs.amount, inputs.recipient, inputs.fee).send()
Transfer.create(token, inputs.amount, inputs.recipient, inputs.maxFee).send()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ContractCall, runTask, Transfer } from '@mimicprotocol/test-ts'
import { Context, ContractCallMock, GetPriceMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

describe('Task', () => {
const taskDir = './'

const context = {
const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
timestamp: Date.now(),
Expand All @@ -15,32 +15,42 @@ describe('Task', () => {
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
amount: '1000000', // 1 USDC
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
fee: '100000', // 0.1 USDC
maxFee: '100000', // 0.1 USDC
thresholdUSD: 10, // 10 USD
}

const prices = [
const prices: GetPriceMock[] = [
{
token: inputs.token,
chainId: inputs.chainId,
usdPrice: '1000000000000000000', // 1 USD = 1 USDC
request: {
token: inputs.token,
chainId: inputs.chainId,
},
response: ['1000000000000000000'], // 1 USD = 1 USDC
},
]

const buildCalls = (balance: string): ContractCall[] => [
const buildCalls = (balance: string): ContractCallMock[] => [
{
to: inputs.token,
chainId: inputs.chainId,
data: '0x70a08231', // `balanceOf` fn selector
output: balance,
outputType: 'uint256',
request: {
to: inputs.token,
chainId: inputs.chainId,
data: '0x70a08231', // `balanceOf` fn selector
},
response: {
value: balance,
abiType: 'uint256',
},
},
{
to: inputs.token,
chainId: inputs.chainId,
data: '0x313ce567', // `decimals` fn selector
output: '6',
outputType: 'uint8',
request: {
to: inputs.token,
chainId: inputs.chainId,
data: '0x313ce567', // `decimals` fn selector
},
response: {
value: '6',
abiType: 'uint8',
},
},
]

Expand All @@ -50,17 +60,15 @@ describe('Task', () => {

it('produces the expected intents', async () => {
const intents = (await runTask(taskDir, context, { inputs, calls, prices })) as Transfer[]

expect(intents).to.be.an('array').that.is.not.empty
expect(intents).to.have.lengthOf(1)

expect(intents[0].type).to.be.equal('transfer')
expect(intents[0].settler).to.be.equal(context.settlers[0].address)
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
expect(intents[0].user).to.be.equal(context.user)
expect(intents[0].chainId).to.be.equal(inputs.chainId)
expect(intents[0].maxFees.length).to.be.equal(1)
expect(intents[0].maxFees[0].token).to.be.equal(inputs.token)
expect(intents[0].maxFees[0].amount).to.be.equal(inputs.fee)
expect(intents[0].maxFees[0].amount).to.be.equal(inputs.maxFee)

expect(intents[0].transfers).to.have.lengthOf(1)
expect(intents[0].transfers[0].token).to.be.equal(inputs.token)
Expand All @@ -75,8 +83,7 @@ describe('Task', () => {

it('does not produce any intent', async () => {
const intents = await runTask(taskDir, context, { inputs, calls, prices })

expect(intents).to.be.an('array').that.is.empty
expect(intents).to.be.empty
})
})
})
8 changes: 1 addition & 7 deletions examples/5-invest-aave-idle-balance/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export default function main(): void {
const minAmountOut = underlyingTokenBalance.toTokenAmount(aToken).times(slippagePct).div(BigInt.fromI32(100))
log.info('Min amount out: ' + minAmountOut.toString())

Swap.create(
inputs.chainId,
underlyingTokenAddress,
underlyingTokenBalanceAmount,
inputs.aToken,
minAmountOut.amount
).send()
Swap.create(inputs.chainId, underlyingToken, underlyingTokenBalanceAmount, aToken, minAmountOut.amount).send()
}
}
Loading