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
14 changes: 7 additions & 7 deletions examples/02-simple-transfer-with-inputs/tests/task.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { fp, OpType } from '@mimicprotocol/sdk'
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

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

const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
user: randomEvmAddress(),
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
timestamp: Date.now(),
}

const inputs = {
chainId: 10, // Optimism
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
amount: '1.5', // 1.5 USDC
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
maxFee: '0.1', // 0.1 USDC
token: randomEvmAddress(),
amount: '1.5', // 1.5 tokens
recipient: randomEvmAddress(),
maxFee: '0.1', // 0.1 tokens
}

const calls: ContractCallMock[] = [
Expand Down
20 changes: 10 additions & 10 deletions examples/03-transfer-balance-threshold/tests/task.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { fp, OpType } from '@mimicprotocol/sdk'
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

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

const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
user: randomEvmAddress(),
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
timestamp: Date.now(),
}

const inputs = {
chainId: 10, // Optimism
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
amount: '1', // 1 USDC
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
maxFee: '0.1', // 0.1 USDC
threshold: '10.2', // 10.2 USDC
token: randomEvmAddress(),
amount: '1', // 1 token
recipient: randomEvmAddress(),
maxFee: '0.1', // 0.1 tokens
threshold: '10.2', // 10.2 tokens
}

const buildCalls = (balance: string): ContractCallMock[] => [
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('Task', () => {
]

describe('when the balance is below the threshold', () => {
const balance = '9000000' // 9 USDC
const balance = '9000000' // 9 tokens
const calls = buildCalls(balance)

it('produces the expected intents', async () => {
Expand All @@ -79,7 +79,7 @@ describe('Task', () => {
})

describe('when the balance is above the threshold', () => {
const balance = '11000000' // 11 USDC
const balance = '11000000' // 11 tokens
const calls = buildCalls(balance)

it('does not produce any intent', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { fp, OpType } from '@mimicprotocol/sdk'
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, GetPriceMock, runTask, Transfer } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

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

const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
user: randomEvmAddress(),
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
timestamp: Date.now(),
}

const inputs = {
chainId: 10, // Optimism
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
amount: '1', // 1 USDC
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
maxFee: '0.1', // 0.1 USDC
token: randomEvmAddress(),
amount: '1', // 1 token
recipient: randomEvmAddress(),
maxFee: '0.1', // 0.1 tokens
thresholdUsd: '10.5', // 10.5 USD
}

Expand All @@ -26,7 +26,7 @@ describe('Task', () => {
token: inputs.token,
chainId: inputs.chainId,
},
response: ['1000000000000000000'], // 1 USD = 1 USDC
response: ['1000000000000000000'], // 1 token = 1 USD
},
]

Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Task', () => {
]

describe('when the balance is below the threshold', () => {
const balance = '9000000' // 9 USDC
const balance = '9000000' // 9 tokens
const calls = buildCalls(balance)

it('produces the expected intents', async () => {
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Task', () => {
})

describe('when the balance is above the threshold', () => {
const balance = '11000000' // 11 USDC
const balance = '11000000' // 11 tokens
const calls = buildCalls(balance)

it('does not produce any intent', async () => {
Expand Down
24 changes: 12 additions & 12 deletions examples/05-invest-aave-idle-balance/tests/task.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EvmCallIntent, OpType } from '@mimicprotocol/sdk'
import { EvmCallIntent, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, GetPriceMock, runTask } from '@mimicprotocol/test-ts'
import { expect } from 'chai'
import { Interface } from 'ethers'
Expand All @@ -13,36 +13,36 @@ describe('Task', () => {
const taskDir = './build'

const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
user: randomEvmAddress(),
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
timestamp: Date.now(),
}

const inputs = {
chainId: 10, // Optimism
aToken: '0x625e7708f30ca75bfd92586e17077590c60eb4cd', // Aave Optimism USDC
smartAccount: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a1',
aToken: randomEvmAddress(), // Aave Optimism USDC
smartAccount: randomEvmAddress(),
thresholdUsd: '10.5', // 10.5 USD
maxFeeUsd: '0.1', // 0.1 USD
}

const underlyingToken = '0x7f5c764cbc14f9669b88837ca1490cca17c31607' // USDC
const pool = '0x794a61358d6845594f94dc1db02a252b5b4814ad' // Aave Pool
const underlyingToken = randomEvmAddress() // USDC
const aavePool = randomEvmAddress()

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

Expand All @@ -66,7 +66,7 @@ describe('Task', () => {
fnSelector: '0x7535d246', // `POOL`
},
response: {
value: pool,
value: aavePool,
abiType: 'address',
},
},
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('Task', () => {
expect(intents[0].user).to.be.equal(inputs.smartAccount)
expect(intents[0].chainId).to.be.equal(inputs.chainId)

const expectedApproveData = ERC20Interface.encodeFunctionData('approve', [pool, balance])
const expectedApproveData = ERC20Interface.encodeFunctionData('approve', [aavePool, balance])
expect(intents[0].calls[0].target).to.be.equal(underlyingToken)
expect(intents[0].calls[0].value).to.be.equal('0')
expect(intents[0].calls[0].data).to.be.equal(expectedApproveData)
Expand All @@ -177,7 +177,7 @@ describe('Task', () => {
inputs.smartAccount,
0,
])
expect(intents[0].calls[1].target).to.be.equal(pool)
expect(intents[0].calls[1].target).to.be.equal(aavePool)
expect(intents[0].calls[1].value).to.be.equal('0')
expect(intents[0].calls[1].data).to.be.equal(expectedSupplyData)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { OpType } from '@mimicprotocol/sdk'
import { OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, GetPriceMock, runTask, Swap } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

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

const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
user: randomEvmAddress(),
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
timestamp: Date.now(),
}

const inputs = {
chainId: 10, // Optimism
aToken: '0x625e7708f30ca75bfd92586e17077590c60eb4cd', // Aave Optimism USDC
aToken: randomEvmAddress(), // Aave Optimism USDC
slippageBps: 200, // 2%
thresholdUsd: '10', // 10 USD
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
recipient: randomEvmAddress(),
}

const underlyingToken = '0x7f5c764cbc14f9669b88837ca1490cca17c31607' // USDC
const underlyingToken = randomEvmAddress() // USDC

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 1.0.0
name: Claim-Swap-Transfer Loop Task
description: This task is for demo purposes. It withdraws from AAVE, swaps for an AAVE token and transfer to deposit in loop
inputs:
- usdFeeAmount: string
- maxFeeUsdt: string # e.g., '0.5' = 0.5 USDT
- smartAccount: address
abis:
- AavePool: ./abis/AavePool.json
6 changes: 3 additions & 3 deletions examples/07-withdraw-from-aave-swap-and-transfer/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export default function main(): void {
const usdcUser = findTokenAmount(userTokens, USDC)
const aUsdcUser = findTokenAmount(userTokens, aUSDC)

const feeUsdt = TokenAmount.fromStringDecimal(USDT, inputs.usdFeeAmount)
const maxFeeUsdt = TokenAmount.fromStringDecimal(USDT, inputs.maxFeeUsdt)

if (aUsdcSmartAccount && aUsdcSmartAccount.amount > BigInt.zero()) {
// Claim aUSDC to user EOA using USDC in smart account
aaveV3Pool
.withdraw(USDC.address, aUsdcSmartAccount.amount, context.user)
.addMaxFee(feeUsdt)
.addMaxFee(maxFeeUsdt)
.addUser(inputs.smartAccount)
.build()
.send()
Expand All @@ -73,7 +73,7 @@ export default function main(): void {
// Transfer aUSDC from user EOA to smart account
TransferBuilder.forChain(chainId)
.addTransfer(new TransferData(aUSDC.address, aUsdcUser.amount, inputs.smartAccount))
.addMaxFee(feeUsdt)
.addMaxFee(maxFeeUsdt)
.build()
.send()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chains, OpType } from '@mimicprotocol/sdk'
import { Chains, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import {
Call,
Context,
Expand All @@ -23,15 +23,15 @@ describe('Task', () => {
}

const context: Context = {
user: '0xae7168deb525862f4fee37d987a971b385b96952',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
user: randomEvmAddress(),
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
timestamp: Date.now(),
}

const inputs = {
chainId,
smartAccount: '0x863df6bfa4469f3ead0be8f9f2aae51c91a907b4',
usdFeeAmount: '1', // 1 USD in USDT
smartAccount: randomEvmAddress(),
maxFeeUsdt: '1', // 1 USDT
}

const calls: ContractCallMock[] = [
Expand Down
2 changes: 1 addition & 1 deletion examples/08-relevant-tokens-query/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: Relevant tokens query example
description: Example of how to use the relevant tokens query
inputs:
- chainId: int32
- feeAmountUsd: string # e.g., '1.5' = 1.5 USD
- maxFeeUsd: string # e.g., '1.5' = 1.5 USD
- recipient: address
2 changes: 1 addition & 1 deletion examples/08-relevant-tokens-query/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default function main(): void {
return
}

builder.addMaxFee(TokenAmount.fromStringDecimal(DenominationToken.USD(), inputs.feeAmountUsd)).build().send()
builder.addMaxFee(TokenAmount.fromStringDecimal(DenominationToken.USD(), inputs.maxFeeUsd)).build().send()
}
2 changes: 1 addition & 1 deletion examples/08-relevant-tokens-query/tests/task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Task', () => {

const inputs = {
chainId,
feeAmountUsd: '0.1',
maxFeeUsd: '0.1',
recipient: randomEvmAddress(),
}

Expand Down
12 changes: 6 additions & 6 deletions examples/09-subgraph-query/tests/task.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { OpType } from '@mimicprotocol/sdk'
import { OpType, randomEvmAddress } from '@mimicprotocol/sdk'
import { Context, ContractCallMock, runTask, SubgraphQueryMock, Swap } from '@mimicprotocol/test-ts'
import { expect } from 'chai'

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

const context: Context = {
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 1 }],
user: randomEvmAddress(),
settlers: [{ address: randomEvmAddress(), chainId: 1 }],
timestamp: Date.now(),
}

const inputs = {
subgraphId: 'subgraph-id',
chainId: 1,
tokenIn: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
tokenOut: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH
tokenIn: '0xa' + randomEvmAddress().slice(3),
tokenOut: '0xb' + randomEvmAddress().slice(3),
slippageBps: 100, // 1%
}

Expand Down Expand Up @@ -72,7 +72,7 @@ describe('Task', () => {
]

describe('when the balance is not zero', () => {
const balance = '9000000000' // 9000 USDC
const balance = '9000000000' // 9000 tokenIn
const calls = buildCalls(balance)

it('produces the expected intents', async () => {
Expand Down
Loading