Skip to content

Commit 7511b44

Browse files
Chore: Update with operations (#29)
Co-authored-by: Agustincito <agus@poap.io>
1 parent 8f3ff3f commit 7511b44

30 files changed

Lines changed: 951 additions & 935 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Address, BigInt, ERC20Token, Transfer } from '@mimicprotocol/lib-ts'
1+
import { Address, ChainId, Optimism, TokenAmount, TransferBuilder } from '@mimicprotocol/lib-ts'
22

33
export default function main(): void {
4-
const USDC = ERC20Token.fromString('0x7F5c764cBc14f9669B88837ca1490cCa17c31607', 10)
5-
const amount = BigInt.fromStringDecimal('1', 6)
64
const recipient = Address.fromString('0xbcE3248eDE29116e4bD18416dcC2DFca668Eeb84')
7-
const maxFee = BigInt.fromStringDecimal('0.1', 6)
8-
9-
Transfer.create(USDC, amount, recipient, maxFee).send()
5+
const maxFee = TokenAmount.fromStringDecimal(Optimism.USDC, '1')
6+
TransferBuilder.forChain(ChainId.OPTIMISM)
7+
.addTransferFromStringDecimal(Optimism.USDC, '1', recipient)
8+
.build()
9+
.send(maxFee)
1010
}
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OpType } from '@mimicprotocol/sdk'
2-
import { Context, runFunction, Transfer } from '@mimicprotocol/test-ts'
2+
import { Context, runFunction, TransferOperation } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44

55
describe('Function', () => {
@@ -16,20 +16,21 @@ describe('Function', () => {
1616
expect(result.success).to.be.true
1717
expect(result.timestamp).to.be.equal(context.timestamp)
1818

19-
const intents = result.intents as Transfer[]
20-
expect(intents).to.have.lengthOf(1)
19+
expect(result.intents).to.have.lengthOf(1)
20+
const intent = result.intents[0]
21+
const op = intent.operations[0] as TransferOperation
2122

22-
expect(intents[0].op).to.be.equal(OpType.Transfer)
23-
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
24-
expect(intents[0].user).to.be.equal(context.user)
25-
expect(intents[0].chainId).to.be.equal(10)
26-
expect(intents[0].maxFees).to.have.lengthOf(1)
27-
expect(intents[0].maxFees[0].token).to.be.equal('0x7f5c764cbc14f9669b88837ca1490cca17c31607')
28-
expect(intents[0].maxFees[0].amount).to.be.equal('100000')
23+
expect(op.opType).to.be.equal(OpType.Transfer)
24+
expect(intent.settler).to.be.equal(context.settlers?.[0].address)
25+
expect(op.user).to.be.equal(context.user)
26+
expect(op.chainId).to.be.equal(10)
27+
expect(intent.maxFees).to.have.lengthOf(1)
28+
expect(intent.maxFees[0].token).to.be.equal('0x0b2c639c533813f4aa9d7837caf62653d097ff85')
29+
expect(intent.maxFees[0].amount).to.be.equal('1000000')
2930

30-
expect(intents[0].transfers).to.have.lengthOf(1)
31-
expect(intents[0].transfers[0].token).to.be.equal('0x7f5c764cbc14f9669b88837ca1490cca17c31607')
32-
expect(intents[0].transfers[0].amount).to.be.equal('1000000')
33-
expect(intents[0].transfers[0].recipient).to.be.equal('0xbce3248ede29116e4bd18416dcc2dfca668eeb84')
31+
expect(op.transfers).to.have.lengthOf(1)
32+
expect(op.transfers[0].token).to.be.equal('0x0b2c639c533813f4aa9d7837caf62653d097ff85')
33+
expect(op.transfers[0].amount).to.be.equal('1000000')
34+
expect(op.transfers[0].recipient).to.be.equal('0xbce3248ede29116e4bd18416dcc2dfca668eeb84')
3435
})
3536
})
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { BigInt, ERC20Token, Transfer } from '@mimicprotocol/lib-ts'
1+
import { ERC20Token, TokenAmount, TransferBuilder } from '@mimicprotocol/lib-ts'
22

33
import { inputs } from './types'
44

55
export default function main(): void {
66
const token = ERC20Token.fromAddress(inputs.token, inputs.chainId)
7-
const amount = BigInt.fromStringDecimal(inputs.amount, token.decimals)
8-
const maxFee = BigInt.fromStringDecimal(inputs.maxFee, token.decimals)
9-
Transfer.create(token, amount, inputs.recipient, maxFee).send()
7+
const amount = TokenAmount.fromStringDecimal(token, inputs.amount)
8+
const maxFee = TokenAmount.fromStringDecimal(token, inputs.maxFee)
9+
TransferBuilder.forChain(inputs.chainId).addTransferFromTokenAmount(amount, inputs.recipient).build().send(maxFee)
1010
}

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

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

@@ -40,20 +40,21 @@ describe('Function', () => {
4040
expect(result.success).to.be.true
4141
expect(result.timestamp).to.be.equal(context.timestamp)
4242

43-
const intents = result.intents as Transfer[]
44-
expect(intents).to.have.lengthOf(1)
45-
46-
expect(intents[0].op).to.be.equal(OpType.Transfer)
47-
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
48-
expect(intents[0].user).to.be.equal(context.user)
49-
expect(intents[0].chainId).to.be.equal(inputs.chainId)
50-
expect(intents[0].maxFees).to.have.lengthOf(1)
51-
expect(intents[0].maxFees[0].token).to.be.equal(inputs.token)
52-
expect(intents[0].maxFees[0].amount).to.be.equal(fp(inputs.maxFee, 6).toString())
53-
54-
expect(intents[0].transfers).to.have.lengthOf(1)
55-
expect(intents[0].transfers[0].token).to.be.equal(inputs.token)
56-
expect(intents[0].transfers[0].amount).to.be.equal(fp(inputs.amount, 6).toString())
57-
expect(intents[0].transfers[0].recipient).to.be.equal(inputs.recipient)
43+
expect(result.intents).to.have.lengthOf(1)
44+
const intent = result.intents[0]
45+
const op = intent.operations[0] as TransferOperation
46+
47+
expect(op.opType).to.be.equal(OpType.Transfer)
48+
expect(intent.settler).to.be.equal(context.settlers?.[0].address)
49+
expect(op.user).to.be.equal(context.user)
50+
expect(op.chainId).to.be.equal(inputs.chainId)
51+
expect(intent.maxFees).to.have.lengthOf(1)
52+
expect(intent.maxFees[0].token).to.be.equal(inputs.token)
53+
expect(intent.maxFees[0].amount).to.be.equal(fp(inputs.maxFee, 6).toString())
54+
55+
expect(op.transfers).to.have.lengthOf(1)
56+
expect(op.transfers[0].token).to.be.equal(inputs.token)
57+
expect(op.transfers[0].amount).to.be.equal(fp(inputs.amount, 6).toString())
58+
expect(op.transfers[0].recipient).to.be.equal(inputs.recipient)
5859
})
5960
})
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigInt, ERC20Token, Transfer } from '@mimicprotocol/lib-ts'
1+
import { BigInt, ERC20Token, TokenAmount, TransferBuilder } from '@mimicprotocol/lib-ts'
22

33
import { ERC20 } from './types/ERC20'
44
import { inputs } from './types'
@@ -10,8 +10,8 @@ export default function main(): void {
1010
const threshold = BigInt.fromStringDecimal(inputs.threshold, token.decimals)
1111

1212
if (balance.lt(threshold)) {
13-
const amount = BigInt.fromStringDecimal(inputs.amount, token.decimals)
14-
const maxFee = BigInt.fromStringDecimal(inputs.maxFee, token.decimals)
15-
Transfer.create(token, amount, inputs.recipient, maxFee).send()
13+
const amount = TokenAmount.fromStringDecimal(token, inputs.amount)
14+
const maxFee = TokenAmount.fromStringDecimal(token, inputs.maxFee)
15+
TransferBuilder.forChain(inputs.chainId).addTransferFromTokenAmount(amount, inputs.recipient).build().send(maxFee)
1616
}
1717
}

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

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

@@ -54,21 +54,22 @@ describe('Function', () => {
5454
expect(result.success).to.be.true
5555
expect(result.timestamp).to.be.equal(context.timestamp)
5656

57-
const intents = result.intents as Transfer[]
58-
expect(intents).to.have.lengthOf(1)
57+
expect(result.intents).to.have.lengthOf(1)
58+
const intent = result.intents[0]
59+
const op = intent.operations[0] as TransferOperation
5960

60-
expect(intents[0].op).to.be.equal(OpType.Transfer)
61-
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
62-
expect(intents[0].user).to.be.equal(context.user)
63-
expect(intents[0].chainId).to.be.equal(inputs.chainId)
64-
expect(intents[0].maxFees).to.have.lengthOf(1)
65-
expect(intents[0].maxFees[0].token).to.be.equal(inputs.token)
66-
expect(intents[0].maxFees[0].amount).to.be.equal(fp(inputs.maxFee, 6).toString())
61+
expect(op.opType).to.be.equal(OpType.Transfer)
62+
expect(intent.settler).to.be.equal(context.settlers?.[0].address)
63+
expect(op.user).to.be.equal(context.user)
64+
expect(op.chainId).to.be.equal(inputs.chainId)
65+
expect(intent.maxFees).to.have.lengthOf(1)
66+
expect(intent.maxFees[0].token).to.be.equal(inputs.token)
67+
expect(intent.maxFees[0].amount).to.be.equal(fp(inputs.maxFee, 6).toString())
6768

68-
expect(intents[0].transfers).to.have.lengthOf(1)
69-
expect(intents[0].transfers[0].token).to.be.equal(inputs.token)
70-
expect(intents[0].transfers[0].amount).to.be.equal(fp(inputs.amount, 6).toString())
71-
expect(intents[0].transfers[0].recipient).to.be.equal(inputs.recipient)
69+
expect(op.transfers).to.have.lengthOf(1)
70+
expect(op.transfers[0].token).to.be.equal(inputs.token)
71+
expect(op.transfers[0].amount).to.be.equal(fp(inputs.amount, 6).toString())
72+
expect(op.transfers[0].recipient).to.be.equal(inputs.recipient)
7273
})
7374
})
7475

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigInt, ERC20Token, log, TokenAmount, Transfer, USD } from '@mimicprotocol/lib-ts'
1+
import { ERC20Token, log, TokenAmount, TransferBuilder, USD } from '@mimicprotocol/lib-ts'
22

33
import { ERC20 } from './types/ERC20'
44
import { inputs } from './types'
@@ -13,8 +13,8 @@ export default function main(): void {
1313
log.info(`Balance in USD: ${balanceInUsd}`)
1414

1515
if (balanceInUsd.lt(thresholdUsd)) {
16-
const amount = BigInt.fromStringDecimal(inputs.amount, token.decimals)
17-
const maxFee = BigInt.fromStringDecimal(inputs.maxFee, token.decimals)
18-
Transfer.create(token, amount, inputs.recipient, maxFee).send()
16+
const amount = TokenAmount.fromStringDecimal(token, inputs.amount)
17+
const maxFee = TokenAmount.fromStringDecimal(token, inputs.maxFee)
18+
TransferBuilder.forChain(inputs.chainId).addTransferFromTokenAmount(amount, inputs.recipient).build().send(maxFee)
1919
}
2020
}

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

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

@@ -61,21 +61,22 @@ describe('Function', () => {
6161
expect(result.success).to.be.true
6262
expect(result.timestamp).to.be.equal(context.timestamp)
6363

64-
const intents = result.intents as Transfer[]
65-
expect(intents).to.have.lengthOf(1)
66-
67-
expect(intents[0].op).to.be.equal(OpType.Transfer)
68-
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
69-
expect(intents[0].user).to.be.equal(context.user)
70-
expect(intents[0].chainId).to.be.equal(inputs.chainId)
71-
expect(intents[0].maxFees.length).to.be.equal(1)
72-
expect(intents[0].maxFees[0].token).to.be.equal(inputs.token)
73-
expect(intents[0].maxFees[0].amount).to.be.equal(fp(inputs.maxFee, 6).toString())
74-
75-
expect(intents[0].transfers).to.have.lengthOf(1)
76-
expect(intents[0].transfers[0].token).to.be.equal(inputs.token)
77-
expect(intents[0].transfers[0].amount).to.be.equal(fp(inputs.amount, 6).toString())
78-
expect(intents[0].transfers[0].recipient).to.be.equal(inputs.recipient)
64+
expect(result.intents).to.have.lengthOf(1)
65+
const intent = result.intents[0]
66+
const op = intent.operations[0] as TransferOperation
67+
68+
expect(op.opType).to.be.equal(OpType.Transfer)
69+
expect(intent.settler).to.be.equal(context.settlers?.[0].address)
70+
expect(op.user).to.be.equal(context.user)
71+
expect(op.chainId).to.be.equal(inputs.chainId)
72+
expect(intent.maxFees.length).to.be.equal(1)
73+
expect(intent.maxFees[0].token).to.be.equal(inputs.token)
74+
expect(intent.maxFees[0].amount).to.be.equal(fp(inputs.maxFee, 6).toString())
75+
76+
expect(op.transfers).to.have.lengthOf(1)
77+
expect(op.transfers[0].token).to.be.equal(inputs.token)
78+
expect(op.transfers[0].amount).to.be.equal(fp(inputs.amount, 6).toString())
79+
expect(op.transfers[0].recipient).to.be.equal(inputs.recipient)
7980

8081
expect(result.logs).to.have.lengthOf(1)
8182
expect(result.logs[0]).to.be.equal('[Info] Balance in USD: 9')

examples/05-invest-aave-idle-balance/src/function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ export default function main(): void {
3636

3737
// Use mimic credits to pay for the transaction fee
3838
const feeWithCredits = TokenAmount.fromStringDecimal(DenominationToken.USD(), inputs.maxFeeUsd)
39-
calls.addUser(inputs.smartAccount).addMaxFee(feeWithCredits).build().send()
39+
calls.addUser(inputs.smartAccount).build().send(feeWithCredits)
4040
}

examples/05-invest-aave-idle-balance/tests/function.spec.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { EvmCallIntent, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
2-
import { Context, EvmCallQueryMock, runFunction, TokenPriceQueryMock } from '@mimicprotocol/test-ts'
1+
import { OpType, randomEvmAddress } from '@mimicprotocol/sdk'
2+
import { CallOperation, Context, EvmCallQueryMock, runFunction, TokenPriceQueryMock } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44
import { Interface } from 'ethers'
55

@@ -128,28 +128,29 @@ describe('Function', () => {
128128
expect(result.success).to.be.true
129129
expect(result.timestamp).to.be.equal(context.timestamp)
130130

131-
const intents = result.intents as EvmCallIntent[]
132-
expect(intents).to.have.lengthOf(1)
131+
expect(result.intents).to.have.lengthOf(1)
132+
const intent = result.intents[0]
133+
const op = intent.operations[0] as CallOperation
133134

134-
expect(intents[0].op).to.be.equal(OpType.EvmCall)
135-
expect(intents[0].settler).to.be.equal(context.settlers?.[0].address)
136-
expect(intents[0].user).to.be.equal(inputs.smartAccount)
137-
expect(intents[0].chainId).to.be.equal(inputs.chainId)
135+
expect(op.opType).to.be.equal(OpType.EvmCall)
136+
expect(intent.settler).to.be.equal(context.settlers?.[0].address)
137+
expect(op.user).to.be.equal(inputs.smartAccount)
138+
expect(op.chainId).to.be.equal(inputs.chainId)
138139

139140
const expectedApproveData = ERC20Interface.encodeFunctionData('approve', [aavePool, balance])
140-
expect(intents[0].calls[0].target).to.be.equal(underlyingToken)
141-
expect(intents[0].calls[0].value).to.be.equal('0')
142-
expect(intents[0].calls[0].data).to.be.equal(expectedApproveData)
141+
expect(op.calls[0].target).to.be.equal(underlyingToken)
142+
expect(op.calls[0].value).to.be.equal('0')
143+
expect(op.calls[0].data).to.be.equal(expectedApproveData)
143144

144145
const expectedSupplyData = AavePoolInterface.encodeFunctionData('supply(address,uint256,address,uint16)', [
145146
underlyingToken,
146147
balance,
147148
inputs.smartAccount,
148149
0,
149150
])
150-
expect(intents[0].calls[1].target).to.be.equal(aavePool)
151-
expect(intents[0].calls[1].value).to.be.equal('0')
152-
expect(intents[0].calls[1].data).to.be.equal(expectedSupplyData)
151+
expect(op.calls[1].target).to.be.equal(aavePool)
152+
expect(op.calls[1].value).to.be.equal('0')
153+
expect(op.calls[1].data).to.be.equal(expectedSupplyData)
153154

154155
expect(result.logs).to.have.lengthOf(1)
155156
expect(result.logs[0]).to.be.equal('[Info] Underlying balance in USD: 11')

0 commit comments

Comments
 (0)