@@ -3,7 +3,16 @@ import { EIP1193Provider } from 'mipd'
33import { AbiFunction , Bytes , Hex , TransactionReceipt } from 'ox'
44import { FeeOption , FeeQuote , OperationStatus , Relayer } from '../relayer.js'
55import { IntentPrecondition } from './rpc/relayer.gen.js'
6- import { decodePrecondition } from '../../preconditions/index.js'
6+ import {
7+ decodePrecondition ,
8+ Erc1155ApprovalPrecondition ,
9+ Erc1155BalancePrecondition ,
10+ Erc20ApprovalPrecondition ,
11+ Erc20BalancePrecondition ,
12+ Erc721ApprovalPrecondition ,
13+ Erc721OwnershipPrecondition ,
14+ NativeBalancePrecondition ,
15+ } from '../../preconditions/index.js'
716import {
817 erc20BalanceOf ,
918 erc20Allowance ,
@@ -171,8 +180,8 @@ export class LocalRelayer implements Relayer {
171180
172181 switch ( decoded . type ( ) ) {
173182 case 'native-balance' : {
174- const native = decoded as any
175- const balance = await this . provider . getBalance ( native . address . toString ( ) )
183+ const native = decoded as NativeBalancePrecondition
184+ const balance = await this . provider . getBalance ( native . address )
176185 if ( native . min !== undefined && balance < native . min ) {
177186 return false
178187 }
@@ -183,10 +192,10 @@ export class LocalRelayer implements Relayer {
183192 }
184193
185194 case 'erc20-balance' : {
186- const erc20 = decoded as any
187- const data = AbiFunction . encodeData ( erc20BalanceOf , [ erc20 . address . toString ( ) ] )
195+ const erc20 = decoded as Erc20BalancePrecondition
196+ const data = AbiFunction . encodeData ( erc20BalanceOf , [ erc20 . address ] )
188197 const result = await this . provider . call ( {
189- to : erc20 . token . toString ( ) ,
198+ to : erc20 . token ,
190199 data,
191200 } )
192201 const balance = BigInt ( result )
@@ -200,21 +209,21 @@ export class LocalRelayer implements Relayer {
200209 }
201210
202211 case 'erc20-approval' : {
203- const erc20 = decoded as any
204- const data = AbiFunction . encodeData ( erc20Allowance , [ erc20 . address . toString ( ) , erc20 . operator . toString ( ) ] )
212+ const erc20 = decoded as Erc20ApprovalPrecondition
213+ const data = AbiFunction . encodeData ( erc20Allowance , [ erc20 . address , erc20 . operator ] )
205214 const result = await this . provider . call ( {
206- to : erc20 . token . toString ( ) ,
215+ to : erc20 . token ,
207216 data,
208217 } )
209218 const allowance = BigInt ( result )
210219 return allowance >= erc20 . min
211220 }
212221
213222 case 'erc721-ownership' : {
214- const erc721 = decoded as any
223+ const erc721 = decoded as Erc721OwnershipPrecondition
215224 const data = AbiFunction . encodeData ( erc721OwnerOf , [ erc721 . tokenId ] )
216225 const result = await this . provider . call ( {
217- to : erc721 . token . toString ( ) ,
226+ to : erc721 . token ,
218227 data,
219228 } )
220229 const owner = Address . checksum ( `0x${ result . slice ( 26 ) } ` )
@@ -223,21 +232,21 @@ export class LocalRelayer implements Relayer {
223232 }
224233
225234 case 'erc721-approval' : {
226- const erc721 = decoded as any
235+ const erc721 = decoded as Erc721ApprovalPrecondition
227236 const data = AbiFunction . encodeData ( erc721GetApproved , [ erc721 . tokenId ] )
228237 const result = await this . provider . call ( {
229- to : erc721 . token . toString ( ) ,
238+ to : erc721 . token ,
230239 data,
231240 } )
232241 const approved = Address . checksum ( `0x${ result . slice ( 26 ) } ` )
233242 return Address . isEqual ( approved , erc721 . operator )
234243 }
235244
236245 case 'erc1155-balance' : {
237- const erc1155 = decoded as any
238- const data = AbiFunction . encodeData ( erc1155BalanceOf , [ erc1155 . address . toString ( ) , erc1155 . tokenId ] )
246+ const erc1155 = decoded as Erc1155BalancePrecondition
247+ const data = AbiFunction . encodeData ( erc1155BalanceOf , [ erc1155 . address , erc1155 . tokenId ] )
239248 const result = await this . provider . call ( {
240- to : erc1155 . token . toString ( ) ,
249+ to : erc1155 . token ,
241250 data,
242251 } )
243252 const balance = BigInt ( result )
@@ -251,13 +260,10 @@ export class LocalRelayer implements Relayer {
251260 }
252261
253262 case 'erc1155-approval' : {
254- const erc1155 = decoded as any
255- const data = AbiFunction . encodeData ( erc1155IsApprovedForAll , [
256- erc1155 . address . toString ( ) ,
257- erc1155 . operator . toString ( ) ,
258- ] )
263+ const erc1155 = decoded as Erc1155ApprovalPrecondition
264+ const data = AbiFunction . encodeData ( erc1155IsApprovedForAll , [ erc1155 . address , erc1155 . operator ] )
259265 const result = await this . provider . call ( {
260- to : erc1155 . token . toString ( ) ,
266+ to : erc1155 . token ,
261267 data,
262268 } )
263269 return BigInt ( result ) === 1n
0 commit comments