From ae0f286879006915deb4b127c01d7c2d2a75c7db Mon Sep 17 00:00:00 2001 From: Facu Spagnuolo Date: Fri, 19 Sep 2025 16:25:15 -0300 Subject: [PATCH 1/3] chore: update lib to v0.0.1-rc.17 --- examples/1-simple-transfer/src/task.ts | 11 +- .../tests/{Task.spec.ts => task.spec.ts} | 14 +- .../manifest.yaml | 2 +- .../2-simple-transfer-with-inputs/src/task.ts | 5 +- .../tests/{Task.spec.ts => task.spec.ts} | 30 ++-- .../manifest.yaml | 2 +- .../3-transfer-balance-threshold/src/task.ts | 5 +- .../tests/{Task.spec.ts => task.spec.ts} | 9 +- .../manifest.yaml | 2 +- .../src/task.ts | 2 +- .../tests/{Task.spec.ts => task.spec.ts} | 9 +- .../5-invest-aave-idle-balance/src/task.ts | 8 +- .../tests/{Task.spec.ts => task.spec.ts} | 12 +- .../tests/{Task.spec.ts => task.spec.ts} | 8 +- .../tests/Task.spec.ts | 143 ---------------- .../tests/task.spec.ts | 159 ++++++++++++++++++ yarn.lock | 18 +- 17 files changed, 220 insertions(+), 219 deletions(-) rename examples/1-simple-transfer/tests/{Task.spec.ts => task.spec.ts} (80%) rename examples/2-simple-transfer-with-inputs/tests/{Task.spec.ts => task.spec.ts} (61%) rename examples/3-transfer-balance-threshold/tests/{Task.spec.ts => task.spec.ts} (90%) rename examples/4-transfer-balance-threshold-with-oracles/tests/{Task.spec.ts => task.spec.ts} (91%) rename examples/5-invest-aave-idle-balance/tests/{Task.spec.ts => task.spec.ts} (94%) rename examples/6-withdraw-from-aave-balance-threshold/tests/{Task.spec.ts => task.spec.ts} (96%) delete mode 100644 examples/7-withdraw-from-aave-swap-and-transfer/tests/Task.spec.ts create mode 100644 examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts diff --git a/examples/1-simple-transfer/src/task.ts b/examples/1-simple-transfer/src/task.ts index 4f74471..e6dc690 100644 --- a/examples/1-simple-transfer/src/task.ts +++ b/examples/1-simple-transfer/src/task.ts @@ -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() } diff --git a/examples/1-simple-transfer/tests/Task.spec.ts b/examples/1-simple-transfer/tests/task.spec.ts similarity index 80% rename from examples/1-simple-transfer/tests/Task.spec.ts rename to examples/1-simple-transfer/tests/task.spec.ts index fb66594..16c064b 100644 --- a/examples/1-simple-transfer/tests/Task.spec.ts +++ b/examples/1-simple-transfer/tests/task.spec.ts @@ -4,16 +4,14 @@ 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 = { + 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') diff --git a/examples/2-simple-transfer-with-inputs/manifest.yaml b/examples/2-simple-transfer-with-inputs/manifest.yaml index 8ece36b..99242ac 100644 --- a/examples/2-simple-transfer-with-inputs/manifest.yaml +++ b/examples/2-simple-transfer-with-inputs/manifest.yaml @@ -6,4 +6,4 @@ inputs: - token: address - amount: uint256 - recipient: address - - fee: uint256 + - maxFee: uint256 diff --git a/examples/2-simple-transfer-with-inputs/src/task.ts b/examples/2-simple-transfer-with-inputs/src/task.ts index e93bf2b..f9150aa 100644 --- a/examples/2-simple-transfer-with-inputs/src/task.ts +++ b/examples/2-simple-transfer-with-inputs/src/task.ts @@ -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() } diff --git a/examples/2-simple-transfer-with-inputs/tests/Task.spec.ts b/examples/2-simple-transfer-with-inputs/tests/task.spec.ts similarity index 61% rename from examples/2-simple-transfer-with-inputs/tests/Task.spec.ts rename to examples/2-simple-transfer-with-inputs/tests/task.spec.ts index fe090ef..95a9a67 100644 --- a/examples/2-simple-transfer-with-inputs/tests/Task.spec.ts +++ b/examples/2-simple-transfer-with-inputs/tests/task.spec.ts @@ -4,24 +4,22 @@ 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 = { + 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') @@ -30,7 +28,7 @@ describe('Task', () => { 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) diff --git a/examples/3-transfer-balance-threshold/manifest.yaml b/examples/3-transfer-balance-threshold/manifest.yaml index b1d850f..b3e9cd5 100644 --- a/examples/3-transfer-balance-threshold/manifest.yaml +++ b/examples/3-transfer-balance-threshold/manifest.yaml @@ -6,7 +6,7 @@ inputs: - token: address - amount: uint256 - recipient: address - - fee: uint256 + - maxFee: uint256 - threshold: uint256 abis: - ERC20: ./abis/ERC20.json diff --git a/examples/3-transfer-balance-threshold/src/task.ts b/examples/3-transfer-balance-threshold/src/task.ts index 4837eab..6b7f922 100644 --- a/examples/3-transfer-balance-threshold/src/task.ts +++ b/examples/3-transfer-balance-threshold/src/task.ts @@ -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' @@ -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() } } diff --git a/examples/3-transfer-balance-threshold/tests/Task.spec.ts b/examples/3-transfer-balance-threshold/tests/task.spec.ts similarity index 90% rename from examples/3-transfer-balance-threshold/tests/Task.spec.ts rename to examples/3-transfer-balance-threshold/tests/task.spec.ts index 6b22e04..d21d90e 100644 --- a/examples/3-transfer-balance-threshold/tests/Task.spec.ts +++ b/examples/3-transfer-balance-threshold/tests/task.spec.ts @@ -15,7 +15,7 @@ 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 } @@ -35,8 +35,6 @@ 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') @@ -45,7 +43,7 @@ describe('Task', () => { 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) @@ -60,8 +58,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 }) }) }) diff --git a/examples/4-transfer-balance-threshold-with-oracles/manifest.yaml b/examples/4-transfer-balance-threshold-with-oracles/manifest.yaml index 7e0ac5e..e5bcfde 100644 --- a/examples/4-transfer-balance-threshold-with-oracles/manifest.yaml +++ b/examples/4-transfer-balance-threshold-with-oracles/manifest.yaml @@ -6,7 +6,7 @@ inputs: - token: address - amount: uint256 - recipient: address - - fee: uint256 + - maxFee: uint256 - thresholdUSD: uint32 abis: - ERC20: ./abis/ERC20.json diff --git a/examples/4-transfer-balance-threshold-with-oracles/src/task.ts b/examples/4-transfer-balance-threshold-with-oracles/src/task.ts index 067a770..e9c835f 100644 --- a/examples/4-transfer-balance-threshold-with-oracles/src/task.ts +++ b/examples/4-transfer-balance-threshold-with-oracles/src/task.ts @@ -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() } } diff --git a/examples/4-transfer-balance-threshold-with-oracles/tests/Task.spec.ts b/examples/4-transfer-balance-threshold-with-oracles/tests/task.spec.ts similarity index 91% rename from examples/4-transfer-balance-threshold-with-oracles/tests/Task.spec.ts rename to examples/4-transfer-balance-threshold-with-oracles/tests/task.spec.ts index e308086..6d52dc7 100644 --- a/examples/4-transfer-balance-threshold-with-oracles/tests/Task.spec.ts +++ b/examples/4-transfer-balance-threshold-with-oracles/tests/task.spec.ts @@ -15,7 +15,7 @@ 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 } @@ -50,8 +50,6 @@ 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') @@ -60,7 +58,7 @@ describe('Task', () => { 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) @@ -75,8 +73,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 }) }) }) diff --git a/examples/5-invest-aave-idle-balance/src/task.ts b/examples/5-invest-aave-idle-balance/src/task.ts index 1a12c15..9929638 100644 --- a/examples/5-invest-aave-idle-balance/src/task.ts +++ b/examples/5-invest-aave-idle-balance/src/task.ts @@ -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() } } diff --git a/examples/5-invest-aave-idle-balance/tests/Task.spec.ts b/examples/5-invest-aave-idle-balance/tests/task.spec.ts similarity index 94% rename from examples/5-invest-aave-idle-balance/tests/Task.spec.ts rename to examples/5-invest-aave-idle-balance/tests/task.spec.ts index ed282c2..2f5abbf 100644 --- a/examples/5-invest-aave-idle-balance/tests/Task.spec.ts +++ b/examples/5-invest-aave-idle-balance/tests/task.spec.ts @@ -70,6 +70,13 @@ describe('Task', () => { output: '6', outputType: 'uint8', }, + { + to: underlyingToken, + chainId: inputs.chainId, + data: '0x95d89b41', // `symbol` fn selector + output: 'USDC', + outputType: 'string', + }, ] describe('when the balance is below the threshold', () => { @@ -78,8 +85,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 }) }) @@ -89,8 +95,6 @@ describe('Task', () => { it('produces the expected intents', async () => { const intents = (await runTask(taskDir, context, { inputs, calls, prices })) as Swap[] - - expect(intents).to.be.an('array').that.is.not.empty expect(intents).to.have.lengthOf(1) expect(intents[0].type).to.be.equal('swap') diff --git a/examples/6-withdraw-from-aave-balance-threshold/tests/Task.spec.ts b/examples/6-withdraw-from-aave-balance-threshold/tests/task.spec.ts similarity index 96% rename from examples/6-withdraw-from-aave-balance-threshold/tests/Task.spec.ts rename to examples/6-withdraw-from-aave-balance-threshold/tests/task.spec.ts index e2aaa57..4baf837 100644 --- a/examples/6-withdraw-from-aave-balance-threshold/tests/Task.spec.ts +++ b/examples/6-withdraw-from-aave-balance-threshold/tests/task.spec.ts @@ -97,8 +97,6 @@ describe('Task', () => { it('produces the expected intents', async () => { const intents = (await runTask(taskDir, context, { inputs, calls, prices })) as Swap[] - - expect(intents).to.be.an('array').that.is.not.empty expect(intents).to.have.lengthOf(1) expect(intents[0].type).to.be.equal('swap') @@ -124,8 +122,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 }) }) }) @@ -136,8 +133,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 }) }) }) diff --git a/examples/7-withdraw-from-aave-swap-and-transfer/tests/Task.spec.ts b/examples/7-withdraw-from-aave-swap-and-transfer/tests/Task.spec.ts deleted file mode 100644 index e0017ef..0000000 --- a/examples/7-withdraw-from-aave-swap-and-transfer/tests/Task.spec.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { Call, RelevantTokens, runTask, Swap, Transfer } from '@mimicprotocol/test-ts' -import { expect } from 'chai' - -describe('Task', () => { - const taskDir = './' - - const chainId = 10 // Optimism - - const tokens = { - aUSDC: '0x625e7708f30ca75bfd92586e17077590c60eb4cd', - USDC: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', - USDT: '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', - } - - const context = { - user: '0xae7168deb525862f4fee37d987a971b385b96952', - settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }], - timestamp: Date.now(), - } - - const inputs = { - chainId, - smartAccount: '0x863df6bfa4469f3ead0be8f9f2aae51c91a907b4', - usdFeeAmount: '1', // 1 USD in USDT - } - - const prices = [ - { token: tokens.aUSDC, chainId, usdPrice: '1000000' }, - { token: tokens.USDC, chainId, usdPrice: '1000000' }, - { token: tokens.USDT, chainId, usdPrice: '1000000' }, - ] - - const buildTokenBalances = ({ - aUsdcSmartAccountBalance, - usdcUserBalance, - aUsdcUserBalance, - }: { - aUsdcSmartAccountBalance: string - usdcUserBalance: string - aUsdcUserBalance: string - }): RelevantTokens[] => [ - { - owner: inputs.smartAccount, - chainIds: [10], - usdMinAmount: '0', - tokenFilter: 0, - tokens: [{ address: tokens.aUSDC, chainId }], - // aUSDC balance in smart account - output: [{ token: { address: tokens.aUSDC, chainId }, amount: aUsdcSmartAccountBalance }], - }, - - { - owner: context.user, - chainIds: [10], - usdMinAmount: '0', - tokenFilter: 0, - tokens: [ - { address: tokens.USDC, chainId }, - { address: tokens.aUSDC, chainId }, - ], - output: [ - // USDC balance in user - { token: { address: tokens.USDC, chainId }, amount: usdcUserBalance }, - // aUSDC balance in user - { token: { address: tokens.aUSDC, chainId }, amount: aUsdcUserBalance }, - ], - }, - ] - - it('produces claim, swap, and transfer when all balances are present', async () => { - const balances = buildTokenBalances({ - aUsdcSmartAccountBalance: '1000000', - usdcUserBalance: '1000000', - aUsdcUserBalance: '1000000', - }) - - const intents = await runTask(taskDir, context, { inputs, balances, prices }) - - const claimIntent = intents.find((i) => i.type === 'transfer') - const swapIntent = intents.find((i) => i.type === 'swap') - const transferIntent = intents.find((i) => i.type === 'call') - - expect(claimIntent).to.exist - expect(swapIntent).to.exist - expect(transferIntent).to.exist - }) - - it('only produces claim when only aUSDC exists in smart account', async () => { - const balances = buildTokenBalances({ - aUsdcSmartAccountBalance: '1000000', - usdcUserBalance: '0', - aUsdcUserBalance: '0', - }) - - const intents = (await runTask(taskDir, context, { inputs, balances, prices })) as Call[] - expect(intents).to.have.lengthOf(1) - expect(intents[0].type).to.equal('call') - expect(intents[0].user).to.equal(inputs.smartAccount) - }) - - it('only produces swap when only USDC exists in user', async () => { - const amount = '1000000' - const balances = buildTokenBalances({ - aUsdcSmartAccountBalance: '0', - usdcUserBalance: amount, - aUsdcUserBalance: '0', - }) - - const intents = (await runTask(taskDir, context, { inputs, balances, prices })) as Swap[] - expect(intents).to.have.lengthOf(1) - expect(intents[0].type).to.equal('swap') - expect(intents[0].user).to.equal(context.user) - expect(intents[0].tokensIn[0].token).to.equal(tokens.USDC) - expect(intents[0].tokensIn[0].amount).to.equal(amount) - expect(intents[0].tokensOut[0].token).to.equal(tokens.aUSDC) - }) - - it('only produces transfer when only aUSDC exists in user', async () => { - const amount = '1000000' - const balances = buildTokenBalances({ - aUsdcSmartAccountBalance: '0', - usdcUserBalance: '0', - aUsdcUserBalance: amount, - }) - const intents = (await runTask(taskDir, context, { inputs, prices, balances })) as Transfer[] - expect(intents).to.have.lengthOf(1) - expect(intents[0].type).to.equal('transfer') - expect(intents[0].transfers[0].recipient).to.equal(inputs.smartAccount) - expect(intents[0].transfers[0].amount).to.equal(amount) - expect(intents[0].user).to.equal(context.user) - }) - - it('produces no intents when all balances are zero', async () => { - const balances = buildTokenBalances({ - aUsdcSmartAccountBalance: '0', - usdcUserBalance: '0', - aUsdcUserBalance: '0', - }) - - const intents = await runTask(taskDir, context, { inputs, balances, prices }) - expect(intents).to.be.an('array').that.is.empty - }) -}) diff --git a/examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts b/examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts new file mode 100644 index 0000000..60bf552 --- /dev/null +++ b/examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts @@ -0,0 +1,159 @@ +import { Call, RelevantTokens, runTask, Swap, Transfer } from '@mimicprotocol/test-ts' +import { expect } from 'chai' + +describe('Task', () => { + const taskDir = './' + + const chainId = 10 // Optimism + + const tokens = { + aUSDC: '0x625e7708f30ca75bfd92586e17077590c60eb4cd', + USDC: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', + USDT: '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', + } + + const context = { + user: '0xae7168deb525862f4fee37d987a971b385b96952', + settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }], + timestamp: Date.now(), + } + + const inputs = { + chainId, + smartAccount: '0x863df6bfa4469f3ead0be8f9f2aae51c91a907b4', + usdFeeAmount: '1', // 1 USD in USDT + } + + const prices = [ + { token: tokens.aUSDC, chainId, usdPrice: '1000000' }, + { token: tokens.USDC, chainId, usdPrice: '1000000' }, + { token: tokens.USDT, chainId, usdPrice: '1000000' }, + ] + + const buildTokenBalances = ({ + aUsdcSmartAccountBalance, + usdcUserBalance, + aUsdcUserBalance, + }: { + aUsdcSmartAccountBalance: string + usdcUserBalance: string + aUsdcUserBalance: string + }): RelevantTokens[] => [ + { + owner: inputs.smartAccount, + chainIds: [10], + usdMinAmount: '0', + tokenFilter: 0, + tokens: [{ address: tokens.aUSDC, chainId }], + // aUSDC balance in smart account + output: [{ token: { address: tokens.aUSDC, chainId }, amount: aUsdcSmartAccountBalance }], + }, + + { + owner: context.user, + chainIds: [10], + usdMinAmount: '0', + tokenFilter: 0, + tokens: [ + { address: tokens.USDC, chainId }, + { address: tokens.aUSDC, chainId }, + ], + output: [ + // USDC balance in user + { token: { address: tokens.USDC, chainId }, amount: usdcUserBalance }, + // aUSDC balance in user + { token: { address: tokens.aUSDC, chainId }, amount: aUsdcUserBalance }, + ], + }, + ] + + describe('when all balances are present', () => { + const balances = buildTokenBalances({ + aUsdcSmartAccountBalance: '1000000', + usdcUserBalance: '1000000', + aUsdcUserBalance: '1000000', + }) + + it('produces claim, swap, and transfer', async () => { + const intents = await runTask(taskDir, context, { inputs, balances, prices }) + + const claimIntent = intents.find((i) => i.type === 'transfer') + const swapIntent = intents.find((i) => i.type === 'swap') + const transferIntent = intents.find((i) => i.type === 'call') + + expect(claimIntent).to.exist + expect(swapIntent).to.exist + expect(transferIntent).to.exist + }) + }) + + describe('when all balances are not present', () => { + describe('when there is only aUSDC in the smart account', () => { + const balances = buildTokenBalances({ + aUsdcSmartAccountBalance: '1000000', + usdcUserBalance: '0', + aUsdcUserBalance: '0', + }) + + it('only produces a claim intent', async () => { + const intents = (await runTask(taskDir, context, { inputs, balances, prices })) as Call[] + expect(intents).to.have.lengthOf(1) + + expect(intents[0].type).to.equal('call') + expect(intents[0].user).to.equal(inputs.smartAccount) + }) + }) + + describe('when there is only USDC in the user account', () => { + const amount = '1000000' + const balances = buildTokenBalances({ + aUsdcSmartAccountBalance: '0', + usdcUserBalance: amount, + aUsdcUserBalance: '0', + }) + + it('only produces a swap intent', async () => { + const intents = (await runTask(taskDir, context, { inputs, balances, prices })) as Swap[] + expect(intents).to.have.lengthOf(1) + + expect(intents[0].type).to.equal('swap') + expect(intents[0].user).to.equal(context.user) + expect(intents[0].tokensIn[0].token).to.equal(tokens.USDC) + expect(intents[0].tokensIn[0].amount).to.equal(amount) + expect(intents[0].tokensOut[0].token).to.equal(tokens.aUSDC) + }) + }) + + describe('when there is only aUSDC in the user account', () => { + const amount = '1000000' + const balances = buildTokenBalances({ + aUsdcSmartAccountBalance: '0', + usdcUserBalance: '0', + aUsdcUserBalance: amount, + }) + + it('only produces a transfer intent', async () => { + const intents = (await runTask(taskDir, context, { inputs, prices, balances })) as Transfer[] + expect(intents).to.have.lengthOf(1) + + expect(intents[0].type).to.equal('transfer') + expect(intents[0].transfers[0].recipient).to.equal(inputs.smartAccount) + expect(intents[0].transfers[0].amount).to.equal(amount) + expect(intents[0].user).to.equal(context.user) + }) + }) + + describe('when all balances are zero', () => { + const balances = buildTokenBalances({ + aUsdcSmartAccountBalance: '0', + usdcUserBalance: '0', + aUsdcUserBalance: '0', + }) + + it('does not produce any intents', async () => { + const intents = await runTask(taskDir, context, { inputs, balances, prices }) + expect(intents).to.be.empty + }) + }) + }) +}) diff --git a/yarn.lock b/yarn.lock index a71df7c..cb24500 100644 --- a/yarn.lock +++ b/yarn.lock @@ -364,9 +364,9 @@ integrity sha512-lg9Whz8onIHRthWaN1Q9EGLa/0LFJjyM8mEUbL1eTi6yMGvBf8gvyDLtxSXztQsxMvhxxNpJYrwa1YHdq+w4Jw== "@mimicprotocol/cli@latest": - version "0.0.1-rc.14" - resolved "https://registry.yarnpkg.com/@mimicprotocol/cli/-/cli-0.0.1-rc.14.tgz#f03069a7482f9818360f3ae222fd5e046e04ad64" - integrity sha512-V+xmRH2ARpd33z9RNPzpmDxJwMLiJHMqPLG72D8lgwf/n7Dj7zUffh+xMZ+tmQZtv0sLX86vtb33F4QnT+VC7w== + version "0.0.1-rc.17" + resolved "https://registry.yarnpkg.com/@mimicprotocol/cli/-/cli-0.0.1-rc.17.tgz#9583c8b00bdb5f3d87339a51a44335128ab08a10" + integrity sha512-PlEWD+PoX7Z/7rdxQKtQnIzEmUZ526Z87XClKo51f8mGugaxeL+ZMueQOApehNcQ/kWHn9Ay9/QIqI55PPU1VA== dependencies: "@inquirer/prompts" "^7.2.4" "@oclif/core" "^4.2.2" @@ -379,9 +379,9 @@ zod "^3.24.1" "@mimicprotocol/lib-ts@latest": - version "0.0.1-rc.14" - resolved "https://registry.yarnpkg.com/@mimicprotocol/lib-ts/-/lib-ts-0.0.1-rc.14.tgz#cb85d5071e65ed117789a18f62c48d57a97f14bb" - integrity sha512-V9ndlS69qlIaz2tNCJH+BrC2NKKMHQLLjW9hoiR815Z7OQcesZmnOcDchxt76YFAxeyqQERrrfRmuk/O7OP5vQ== + version "0.0.1-rc.17" + resolved "https://registry.yarnpkg.com/@mimicprotocol/lib-ts/-/lib-ts-0.0.1-rc.17.tgz#0eb111e3cde983609e20018cb8427043212c6c56" + integrity sha512-4/MSOLhtNp+sM0fG5RLopEDUnnquxrYb3PvzjXrhc33P4dzV0S/wTZ1gd9NKdx5pijGpWVlOEGn8LO0RT9iPmQ== dependencies: as-base58 "^0.1.1" eslint-config-mimic "^0.0.3" @@ -389,9 +389,9 @@ visitor-as "0.11.4" "@mimicprotocol/test-ts@latest": - version "0.0.1-rc.14" - resolved "https://registry.yarnpkg.com/@mimicprotocol/test-ts/-/test-ts-0.0.1-rc.14.tgz#71232a4c2985c788849ffdc868e67b049820d794" - integrity sha512-HEI8baPhf5zlVMqtqB2WJwbmnsog7dF4DpTA1nTDHg5eLmSMcUl5SM6pdNjULnb6cXNYBbnt44RTpWDQ5qmcZg== + version "0.0.1-rc.17" + resolved "https://registry.yarnpkg.com/@mimicprotocol/test-ts/-/test-ts-0.0.1-rc.17.tgz#9962a479f292034b1061a8681540486a16534324" + integrity sha512-fWmvI5plmY3QQxFkU5lkO+7ytBde68GRx2cM907GXNCHxQbc4b7UWG7q22WUjU0IeTgkY8/d3b7V8kronF+tNg== dependencies: zod "^3.24.1" From a1b01aabddaa5b00bb7dc2df6dcee9cf60737ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Comerci?= <45410089+ncomerci@users.noreply.github.com> Date: Thu, 25 Sep 2025 21:56:03 -0300 Subject: [PATCH 2/3] Fix: Update test mocks (#8) --- examples/1-simple-transfer/tests/task.spec.ts | 6 +- .../tests/task.spec.ts | 6 +- .../tests/task.spec.ts | 22 ++-- .../tests/task.spec.ts | 46 ++++--- .../tests/task.spec.ts | 110 ++++++++++------ .../tests/task.spec.ts | 124 +++++++++++------- .../tests/task.spec.ts | 109 ++++++++++----- 7 files changed, 270 insertions(+), 153 deletions(-) diff --git a/examples/1-simple-transfer/tests/task.spec.ts b/examples/1-simple-transfer/tests/task.spec.ts index 16c064b..9b00076 100644 --- a/examples/1-simple-transfer/tests/task.spec.ts +++ b/examples/1-simple-transfer/tests/task.spec.ts @@ -1,10 +1,10 @@ -import { runTask, Transfer } from '@mimicprotocol/test-ts' +import { Context, 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(), @@ -15,7 +15,7 @@ describe('Task', () => { 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) diff --git a/examples/2-simple-transfer-with-inputs/tests/task.spec.ts b/examples/2-simple-transfer-with-inputs/tests/task.spec.ts index 95a9a67..15fdeaf 100644 --- a/examples/2-simple-transfer-with-inputs/tests/task.spec.ts +++ b/examples/2-simple-transfer-with-inputs/tests/task.spec.ts @@ -1,10 +1,10 @@ -import { runTask, Transfer } from '@mimicprotocol/test-ts' +import { Context, 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(), @@ -23,7 +23,7 @@ describe('Task', () => { 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) diff --git a/examples/3-transfer-balance-threshold/tests/task.spec.ts b/examples/3-transfer-balance-threshold/tests/task.spec.ts index d21d90e..97e8c91 100644 --- a/examples/3-transfer-balance-threshold/tests/task.spec.ts +++ b/examples/3-transfer-balance-threshold/tests/task.spec.ts @@ -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(), @@ -19,13 +19,17 @@ describe('Task', () => { 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', + }, }, ] @@ -38,7 +42,7 @@ describe('Task', () => { 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) diff --git a/examples/4-transfer-balance-threshold-with-oracles/tests/task.spec.ts b/examples/4-transfer-balance-threshold-with-oracles/tests/task.spec.ts index 6d52dc7..93456d5 100644 --- a/examples/4-transfer-balance-threshold-with-oracles/tests/task.spec.ts +++ b/examples/4-transfer-balance-threshold-with-oracles/tests/task.spec.ts @@ -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(), @@ -19,28 +19,38 @@ describe('Task', () => { 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', + }, }, ] @@ -53,7 +63,7 @@ describe('Task', () => { 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) diff --git a/examples/5-invest-aave-idle-balance/tests/task.spec.ts b/examples/5-invest-aave-idle-balance/tests/task.spec.ts index 2f5abbf..b39ba6e 100644 --- a/examples/5-invest-aave-idle-balance/tests/task.spec.ts +++ b/examples/5-invest-aave-idle-balance/tests/task.spec.ts @@ -1,10 +1,10 @@ -import { ContractCall, runTask, Swap } from '@mimicprotocol/test-ts' +import { Context, ContractCallMock, GetPriceMock, runTask, Swap } 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(), @@ -19,63 +19,91 @@ describe('Task', () => { const underlyingToken = '0x7f5c764cbc14f9669b88837ca1490cca17c31607' // USDC - const prices = [ + const prices: GetPriceMock[] = [ { - token: inputs.aToken, - chainId: inputs.chainId, - usdPrice: '1000000000000000000', // 1 USD = 1 aOptUSDC + request: { + token: inputs.aToken, + chainId: inputs.chainId, + }, + response: ['1000000000000000000'], // 1 USD = 1 aOptUSDC }, { - token: underlyingToken, - chainId: inputs.chainId, - usdPrice: '1000000000000000000', // 1 USD = 1 USDC + request: { + token: underlyingToken, + chainId: inputs.chainId, + }, + response: ['1000000000000000000'], // 1 USD = 1 USDC }, ] - const buildCalls = (balance: string): ContractCall[] => [ + const buildCalls = (balance: string): ContractCallMock[] => [ // aOptUSDC { - to: inputs.aToken, - chainId: inputs.chainId, - data: '0xb16a19de', // `UNDERLYING_ASSET_ADDRESS` fn selector - output: underlyingToken, - outputType: 'address', + request: { + to: inputs.aToken, + chainId: inputs.chainId, + data: '0xb16a19de', // `UNDERLYING_ASSET_ADDRESS` fn selector + }, + response: { + value: underlyingToken, + abiType: 'address', + }, }, { - to: inputs.aToken, - chainId: inputs.chainId, - data: '0x313ce567', // `decimals` fn selector - output: '6', - outputType: 'uint8', + request: { + to: inputs.aToken, + chainId: inputs.chainId, + data: '0x313ce567', // `decimals` fn selector + }, + response: { + value: '6', + abiType: 'uint8', + }, }, { - to: inputs.aToken, - chainId: inputs.chainId, - data: '0x95d89b41', // `symbol` fn selector - output: 'aOptUSDC', - outputType: 'string', + request: { + to: inputs.aToken, + chainId: inputs.chainId, + data: '0x95d89b41', // `symbol` fn selector + }, + response: { + value: 'aOptUSDC', + abiType: 'string', + }, }, // USDC { - to: underlyingToken, - chainId: inputs.chainId, - data: '0x70a08231', // `balanceOf` fn selector - output: balance, - outputType: 'uint256', + request: { + to: underlyingToken, + chainId: inputs.chainId, + data: '0x70a08231', // `balanceOf` fn selector + }, + response: { + value: balance, + abiType: 'uint256', + }, }, { - to: underlyingToken, - chainId: inputs.chainId, - data: '0x313ce567', // `decimals` fn selector - output: '6', - outputType: 'uint8', + request: { + to: underlyingToken, + chainId: inputs.chainId, + data: '0x313ce567', // `decimals` fn selector + }, + response: { + value: '6', + abiType: 'uint8', + }, }, { - to: underlyingToken, - chainId: inputs.chainId, - data: '0x95d89b41', // `symbol` fn selector - output: 'USDC', - outputType: 'string', + request: { + to: underlyingToken, + chainId: inputs.chainId, + data: '0x95d89b41', // `symbol` fn selector + }, + response: { + value: 'USDC', + abiType: 'string', + }, }, ] @@ -98,7 +126,7 @@ describe('Task', () => { expect(intents).to.have.lengthOf(1) expect(intents[0].type).to.be.equal('swap') - 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].sourceChain).to.be.equal(inputs.chainId) expect(intents[0].destinationChain).to.be.equal(inputs.chainId) diff --git a/examples/6-withdraw-from-aave-balance-threshold/tests/task.spec.ts b/examples/6-withdraw-from-aave-balance-threshold/tests/task.spec.ts index 4baf837..3a2002b 100644 --- a/examples/6-withdraw-from-aave-balance-threshold/tests/task.spec.ts +++ b/examples/6-withdraw-from-aave-balance-threshold/tests/task.spec.ts @@ -1,10 +1,10 @@ -import { ContractCall, runTask, Swap } from '@mimicprotocol/test-ts' +import { Context, ContractCallMock, GetPriceMock, runTask, Swap } 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(), @@ -20,70 +20,102 @@ describe('Task', () => { const underlyingToken = '0x7f5c764cbc14f9669b88837ca1490cca17c31607' // USDC - const prices = [ + const prices: GetPriceMock[] = [ { - token: inputs.aToken, - chainId: inputs.chainId, - usdPrice: '1000000000000000000', // 1 USD = 1 aOptUSDC + request: { + token: inputs.aToken, + chainId: inputs.chainId, + }, + response: ['1000000000000000000'], // 1 USD = 1 aOptUSDC }, { - token: underlyingToken, - chainId: inputs.chainId, - usdPrice: '1000000000000000000', // 1 USD = 1 USDC + request: { + token: underlyingToken, + chainId: inputs.chainId, + }, + response: ['1000000000000000000'], // 1 USD = 1 USDC }, ] - const buildCalls = (recipientBalance: string, userBalance: string): ContractCall[] => [ + const buildCalls = (recipientBalance: string, userBalance: string): ContractCallMock[] => [ // aOptUSDC { - to: inputs.aToken, - chainId: inputs.chainId, - data: '0xb16a19de', // `UNDERLYING_ASSET_ADDRESS` fn selector - output: underlyingToken, - outputType: 'address', + request: { + to: inputs.aToken, + chainId: inputs.chainId, + data: '0xb16a19de', // `UNDERLYING_ASSET_ADDRESS` fn selector + }, + response: { + value: underlyingToken, + abiType: 'address', + }, }, { - to: inputs.aToken, - chainId: inputs.chainId, - data: '0x70a08231', // `balanceOf` fn selector - output: userBalance, - outputType: 'uint256', + request: { + to: inputs.aToken, + chainId: inputs.chainId, + data: '0x70a08231', // `balanceOf` fn selector + }, + response: { + value: userBalance, + abiType: 'uint256', + }, }, { - to: inputs.aToken, - chainId: inputs.chainId, - data: '0x313ce567', // `decimals` fn selector - output: '6', - outputType: 'uint8', + request: { + to: inputs.aToken, + chainId: inputs.chainId, + data: '0x313ce567', // `decimals` fn selector + }, + response: { + value: '6', + abiType: 'uint8', + }, }, { - to: inputs.aToken, - chainId: inputs.chainId, - data: '0x95d89b41', // `symbol` fn selector - output: 'aOptUSDC', - outputType: 'string', + request: { + to: inputs.aToken, + chainId: inputs.chainId, + data: '0x95d89b41', // `symbol` fn selector + }, + response: { + value: 'aOptUSDC', + abiType: 'string', + }, }, // USDC { - to: underlyingToken, - chainId: inputs.chainId, - data: '0x70a08231', // `balanceOf` fn selector - output: recipientBalance, - outputType: 'uint256', + request: { + to: underlyingToken, + chainId: inputs.chainId, + data: '0x70a08231', // `balanceOf` fn selector + }, + response: { + value: recipientBalance, + abiType: 'uint256', + }, }, { - to: underlyingToken, - chainId: inputs.chainId, - data: '0x313ce567', // `decimals` fn selector - output: '6', - outputType: 'uint8', + request: { + to: underlyingToken, + chainId: inputs.chainId, + data: '0x313ce567', // `decimals` fn selector + }, + response: { + value: '6', + abiType: 'uint8', + }, }, { - to: underlyingToken, - chainId: inputs.chainId, - data: '0x95d89b41', // `symbol` fn selector - output: 'USDC', - outputType: 'string', + request: { + to: underlyingToken, + chainId: inputs.chainId, + data: '0x95d89b41', // `symbol` fn selector + }, + response: { + value: 'USDC', + abiType: 'string', + }, }, ] @@ -100,7 +132,7 @@ describe('Task', () => { expect(intents).to.have.lengthOf(1) expect(intents[0].type).to.be.equal('swap') - 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].sourceChain).to.be.equal(inputs.chainId) expect(intents[0].destinationChain).to.be.equal(inputs.chainId) diff --git a/examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts b/examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts index 60bf552..9de520c 100644 --- a/examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts +++ b/examples/7-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts @@ -1,4 +1,13 @@ -import { Call, RelevantTokens, runTask, Swap, Transfer } from '@mimicprotocol/test-ts' +import { + Call, + Context, + ContractCallMock, + GetPriceMock, + GetRelevantTokensMock, + runTask, + Swap, + Transfer, +} from '@mimicprotocol/test-ts' import { expect } from 'chai' describe('Task', () => { @@ -12,7 +21,7 @@ describe('Task', () => { USDT: '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', } - const context = { + const context: Context = { user: '0xae7168deb525862f4fee37d987a971b385b96952', settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }], timestamp: Date.now(), @@ -24,10 +33,42 @@ describe('Task', () => { usdFeeAmount: '1', // 1 USD in USDT } - const prices = [ - { token: tokens.aUSDC, chainId, usdPrice: '1000000' }, - { token: tokens.USDC, chainId, usdPrice: '1000000' }, - { token: tokens.USDT, chainId, usdPrice: '1000000' }, + const calls: ContractCallMock[] = [ + { + request: { + to: tokens.USDT, + chainId, + data: '0x313ce567', // `decimals` fn selector + }, + response: { + value: '6', + abiType: 'uint8', + }, + }, + ] + + const prices: GetPriceMock[] = [ + { + request: { + token: tokens.aUSDC, + chainId, + }, + response: ['1000000'], + }, + { + request: { + token: tokens.USDC, + chainId, + }, + response: ['1000000'], + }, + { + request: { + token: tokens.USDT, + chainId, + }, + response: ['1000000'], + }, ] const buildTokenBalances = ({ @@ -38,31 +79,33 @@ describe('Task', () => { aUsdcSmartAccountBalance: string usdcUserBalance: string aUsdcUserBalance: string - }): RelevantTokens[] => [ + }): GetRelevantTokensMock[] => [ { - owner: inputs.smartAccount, - chainIds: [10], - usdMinAmount: '0', - tokenFilter: 0, - tokens: [{ address: tokens.aUSDC, chainId }], - // aUSDC balance in smart account - output: [{ token: { address: tokens.aUSDC, chainId }, amount: aUsdcSmartAccountBalance }], + request: { + owner: inputs.smartAccount, + chainIds: [10], + usdMinAmount: '0', + tokenFilter: 0, + tokens: [{ address: tokens.aUSDC, chainId }], + }, + response: [[{ token: { address: tokens.aUSDC, chainId }, amount: aUsdcSmartAccountBalance }]], }, - { - owner: context.user, - chainIds: [10], - usdMinAmount: '0', - tokenFilter: 0, - tokens: [ - { address: tokens.USDC, chainId }, - { address: tokens.aUSDC, chainId }, - ], - output: [ - // USDC balance in user - { token: { address: tokens.USDC, chainId }, amount: usdcUserBalance }, - // aUSDC balance in user - { token: { address: tokens.aUSDC, chainId }, amount: aUsdcUserBalance }, + request: { + owner: context.user!, + chainIds: [10], + usdMinAmount: '0', + tokenFilter: 0, + tokens: [ + { address: tokens.USDC, chainId }, + { address: tokens.aUSDC, chainId }, + ], + }, + response: [ + [ + { token: { address: tokens.USDC, chainId }, amount: usdcUserBalance }, + { token: { address: tokens.aUSDC, chainId }, amount: aUsdcUserBalance }, + ], ], }, ] @@ -75,7 +118,7 @@ describe('Task', () => { }) it('produces claim, swap, and transfer', async () => { - const intents = await runTask(taskDir, context, { inputs, balances, prices }) + const intents = await runTask(taskDir, context, { inputs, balances, prices, calls }) const claimIntent = intents.find((i) => i.type === 'transfer') const swapIntent = intents.find((i) => i.type === 'swap') @@ -96,7 +139,7 @@ describe('Task', () => { }) it('only produces a claim intent', async () => { - const intents = (await runTask(taskDir, context, { inputs, balances, prices })) as Call[] + const intents = (await runTask(taskDir, context, { inputs, balances, prices, calls })) as Call[] expect(intents).to.have.lengthOf(1) expect(intents[0].type).to.equal('call') @@ -113,7 +156,7 @@ describe('Task', () => { }) it('only produces a swap intent', async () => { - const intents = (await runTask(taskDir, context, { inputs, balances, prices })) as Swap[] + const intents = (await runTask(taskDir, context, { inputs, balances, prices, calls })) as Swap[] expect(intents).to.have.lengthOf(1) expect(intents[0].type).to.equal('swap') @@ -133,7 +176,7 @@ describe('Task', () => { }) it('only produces a transfer intent', async () => { - const intents = (await runTask(taskDir, context, { inputs, prices, balances })) as Transfer[] + const intents = (await runTask(taskDir, context, { inputs, prices, balances, calls })) as Transfer[] expect(intents).to.have.lengthOf(1) expect(intents[0].type).to.equal('transfer') @@ -151,7 +194,7 @@ describe('Task', () => { }) it('does not produce any intents', async () => { - const intents = await runTask(taskDir, context, { inputs, balances, prices }) + const intents = await runTask(taskDir, context, { inputs, balances, prices, calls }) expect(intents).to.be.empty }) }) From f0ef1dcb882af70eda545739acc082dc565b1929 Mon Sep 17 00:00:00 2001 From: Facu Spagnuolo Date: Thu, 25 Sep 2025 22:01:04 -0300 Subject: [PATCH 3/3] chore: update lib to v0.0.1-rc.18 --- yarn.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/yarn.lock b/yarn.lock index cb24500..0e7fb01 100644 --- a/yarn.lock +++ b/yarn.lock @@ -364,9 +364,9 @@ integrity sha512-lg9Whz8onIHRthWaN1Q9EGLa/0LFJjyM8mEUbL1eTi6yMGvBf8gvyDLtxSXztQsxMvhxxNpJYrwa1YHdq+w4Jw== "@mimicprotocol/cli@latest": - version "0.0.1-rc.17" - resolved "https://registry.yarnpkg.com/@mimicprotocol/cli/-/cli-0.0.1-rc.17.tgz#9583c8b00bdb5f3d87339a51a44335128ab08a10" - integrity sha512-PlEWD+PoX7Z/7rdxQKtQnIzEmUZ526Z87XClKo51f8mGugaxeL+ZMueQOApehNcQ/kWHn9Ay9/QIqI55PPU1VA== + version "0.0.1-rc.18" + resolved "https://registry.yarnpkg.com/@mimicprotocol/cli/-/cli-0.0.1-rc.18.tgz#3f12bec611e916403a5f7c2bac639f466bf68c27" + integrity sha512-lZB3gfv2p3/y/I3cMBFbO7EUf6xIllM/zxerUx5aWe4xV6EgK8Aqmzcg6xN3oOT0QS8ZZjd7WNLQ5e0TM0YsLQ== dependencies: "@inquirer/prompts" "^7.2.4" "@oclif/core" "^4.2.2" @@ -379,9 +379,9 @@ zod "^3.24.1" "@mimicprotocol/lib-ts@latest": - version "0.0.1-rc.17" - resolved "https://registry.yarnpkg.com/@mimicprotocol/lib-ts/-/lib-ts-0.0.1-rc.17.tgz#0eb111e3cde983609e20018cb8427043212c6c56" - integrity sha512-4/MSOLhtNp+sM0fG5RLopEDUnnquxrYb3PvzjXrhc33P4dzV0S/wTZ1gd9NKdx5pijGpWVlOEGn8LO0RT9iPmQ== + version "0.0.1-rc.18" + resolved "https://registry.yarnpkg.com/@mimicprotocol/lib-ts/-/lib-ts-0.0.1-rc.18.tgz#c5cba0ea2682a0e45ceeb46e8bc2a7a236c53dde" + integrity sha512-88GrO4sUm9O33CGi2KwHq3ycUUGp1JDdTvLynhfuuktVDJFYAW8J2BfguNsPWiAInFoP9iDA6Zd3NSSp05VtWw== dependencies: as-base58 "^0.1.1" eslint-config-mimic "^0.0.3" @@ -389,9 +389,9 @@ visitor-as "0.11.4" "@mimicprotocol/test-ts@latest": - version "0.0.1-rc.17" - resolved "https://registry.yarnpkg.com/@mimicprotocol/test-ts/-/test-ts-0.0.1-rc.17.tgz#9962a479f292034b1061a8681540486a16534324" - integrity sha512-fWmvI5plmY3QQxFkU5lkO+7ytBde68GRx2cM907GXNCHxQbc4b7UWG7q22WUjU0IeTgkY8/d3b7V8kronF+tNg== + version "0.0.1-rc.18" + resolved "https://registry.yarnpkg.com/@mimicprotocol/test-ts/-/test-ts-0.0.1-rc.18.tgz#c055dfedb17a1080ec672d8f8fb880b2e43f1acd" + integrity sha512-gson4ETtK/ba7M4sAxcYoqGl6n53aAFwoQzuBGdNdDj042gfaxSJNB/vF5bIXi45KdVKfaXTbd+hkap1gb0raA== dependencies: zod "^3.24.1"