Skip to content

Commit 73a7b82

Browse files
authored
Fix: Update examples (#25)
1 parent 8c5873f commit 73a7b82

40 files changed

Lines changed: 603 additions & 504 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node-option": ["import=tsx/esm"]
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node-option": ["import=tsx/esm"]
3+
}

examples/02-simple-transfer-with-inputs/tests/task.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
2-
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
2+
import { Context, EvmCallQueryMock, runTask, Transfer } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44
import { Interface } from 'ethers'
55

@@ -24,7 +24,7 @@ describe('Task', () => {
2424
maxFee: '0.1', // 0.1 tokens
2525
}
2626

27-
const calls: ContractCallMock[] = [
27+
const calls: EvmCallQueryMock[] = [
2828
{
2929
request: {
3030
to: inputs.token,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node-option": ["import=tsx/esm"]
3+
}

examples/03-transfer-balance-threshold/src/task.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { inputs } from './types'
55

66
export default function main(): void {
77
const tokenContract = new ERC20(inputs.token, inputs.chainId)
8-
const balance = tokenContract.balanceOf(inputs.recipient)
8+
const balanceResult = tokenContract.balanceOf(inputs.recipient)
9+
if (balanceResult.isError) throw new Error(balanceResult.error)
10+
const balance = balanceResult.value
911

1012
const token = ERC20Token.fromAddress(inputs.token, inputs.chainId)
1113
const threshold = BigInt.fromStringDecimal(inputs.threshold, token.decimals)

examples/03-transfer-balance-threshold/tests/task.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
2-
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
2+
import { Context, EvmCallQueryMock, runTask, Transfer } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44
import { Interface } from 'ethers'
55

@@ -25,7 +25,7 @@ describe('Task', () => {
2525
threshold: '10.2', // 10.2 tokens
2626
}
2727

28-
const buildCalls = (balance: string): ContractCallMock[] => [
28+
const buildCalls = (balance: string): EvmCallQueryMock[] => [
2929
{
3030
request: {
3131
to: inputs.token,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node-option": ["import=tsx/esm"]
3+
}

examples/04-transfer-balance-threshold-with-oracles/src/task.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { inputs } from './types'
55

66
export default function main(): void {
77
const tokenContract = new ERC20(inputs.token, inputs.chainId)
8-
const balance = tokenContract.balanceOf(inputs.recipient)
8+
const balanceResult = tokenContract.balanceOf(inputs.recipient)
9+
if (balanceResult.isError) throw new Error(balanceResult.error)
10+
const balance = balanceResult.value
911

1012
const token = ERC20Token.fromAddress(inputs.token, inputs.chainId)
11-
const balanceInUsd = TokenAmount.fromBigInt(token, balance).toUsd()
13+
const balanceInUsdResult = TokenAmount.fromBigInt(token, balance).toUsd()
14+
if (balanceInUsdResult.isError) throw new Error(balanceInUsdResult.error)
15+
const balanceInUsd = balanceInUsdResult.value
1216
const thresholdUsd = USD.fromStringDecimal(inputs.thresholdUsd)
1317
log.info(`Balance in USD: ${balanceInUsd}`)
1418

examples/04-transfer-balance-threshold-with-oracles/tests/task.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
2-
import { Context, ContractCallMock, GetPriceMock, runTask, Transfer } from '@mimicprotocol/test-ts'
2+
import { Context, EvmCallQueryMock, runTask, TokenPriceQueryMock, Transfer } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44
import { Interface } from 'ethers'
55

@@ -25,14 +25,14 @@ describe('Task', () => {
2525
thresholdUsd: '10.5', // 10.5 USD
2626
}
2727

28-
const prices: GetPriceMock[] = [
28+
const prices: TokenPriceQueryMock[] = [
2929
{
3030
request: { token: inputs.token, chainId: inputs.chainId },
3131
response: ['1000000000000000000'], // 1 token = 1 USD
3232
},
3333
]
3434

35-
const buildCalls = (balance: string): ContractCallMock[] => [
35+
const buildCalls = (balance: string): EvmCallQueryMock[] => [
3636
{
3737
request: {
3838
to: inputs.token,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node-option": ["import=tsx/esm"]
3+
}

0 commit comments

Comments
 (0)