@@ -10,7 +10,16 @@ import {
1010import { Address , Hex , AbiFunction } from 'ox'
1111import { Constants , Payload , Network } from '@0xsequence/wallet-primitives'
1212import { FeeOption , FeeQuote , OperationStatus , Relayer } from '../index.js'
13- import { decodePrecondition } from '../../preconditions/index.js'
13+ import {
14+ decodePrecondition ,
15+ Erc1155ApprovalPrecondition ,
16+ Erc1155BalancePrecondition ,
17+ Erc20ApprovalPrecondition ,
18+ Erc20BalancePrecondition ,
19+ Erc721ApprovalPrecondition ,
20+ Erc721OwnershipPrecondition ,
21+ NativeBalancePrecondition ,
22+ } from '../../preconditions/index.js'
1423import {
1524 erc20BalanceOf ,
1625 erc20Allowance ,
@@ -69,7 +78,9 @@ export const getChain = (chainId: number): Chain => {
6978 }
7079
7180 // Fall back to viem's built-in chains
72- const viemChain = Object . values ( chains ) . find ( ( c : any ) => typeof c === 'object' && 'id' in c && c . id === chainId )
81+ const viemChain = Object . values ( chains ) . find (
82+ ( c : unknown ) => typeof c === 'object' && c !== null && 'id' in c && c . id === chainId ,
83+ )
7384 if ( viemChain ) {
7485 return viemChain as Chain
7586 }
@@ -78,7 +89,7 @@ export const getChain = (chainId: number): Chain => {
7889}
7990
8091export class RpcRelayer implements Relayer {
81- public readonly kind : 'relayer' = 'relayer'
92+ public readonly kind = 'relayer'
8293 public readonly type = 'rpc'
8394 public readonly id : string
8495 public readonly chainId : number
@@ -239,7 +250,7 @@ export class RpcRelayer implements Relayer {
239250 return { opHash : `0x${ result . txnHash } ` }
240251 }
241252
242- async status ( opHash : Hex . Hex , chainId : number ) : Promise < OperationStatus > {
253+ async status ( opHash : Hex . Hex , _chainId : number ) : Promise < OperationStatus > {
243254 try {
244255 const cleanedOpHash = opHash . startsWith ( '0x' ) ? opHash . substring ( 2 ) : opHash
245256 const result = await this . client . getMetaTxnReceipt ( { metaTxID : cleanedOpHash } )
@@ -291,9 +302,9 @@ export class RpcRelayer implements Relayer {
291302
292303 switch ( decoded . type ( ) ) {
293304 case 'native-balance' : {
294- const native = decoded as any
305+ const native = decoded as NativeBalancePrecondition
295306 try {
296- const balance = await this . provider . getBalance ( { address : native . address . toString ( ) as `0x${ string } ` } )
307+ const balance = await this . provider . getBalance ( { address : native . address } )
297308 const minWei = native . min !== undefined ? BigInt ( native . min ) : undefined
298309 const maxWei = native . max !== undefined ? BigInt ( native . max ) : undefined
299310
@@ -316,9 +327,9 @@ export class RpcRelayer implements Relayer {
316327 }
317328
318329 case 'erc20-balance' : {
319- const erc20 = decoded as any
330+ const erc20 = decoded as Erc20BalancePrecondition
320331 try {
321- const data = AbiFunction . encodeData ( erc20BalanceOf , [ erc20 . address . toString ( ) ] )
332+ const data = AbiFunction . encodeData ( erc20BalanceOf , [ erc20 . address ] )
322333 const result = await this . provider . call ( {
323334 to : erc20 . token . toString ( ) as `0x${string } `,
324335 data : data as `0x${string } `,
@@ -345,9 +356,9 @@ export class RpcRelayer implements Relayer {
345356 }
346357
347358 case 'erc20-approval' : {
348- const erc20 = decoded as any
359+ const erc20 = decoded as Erc20ApprovalPrecondition
349360 try {
350- const data = AbiFunction . encodeData ( erc20Allowance , [ erc20 . address . toString ( ) , erc20 . operator . toString ( ) ] )
361+ const data = AbiFunction . encodeData ( erc20Allowance , [ erc20 . address , erc20 . operator ] )
351362 const result = await this . provider . call ( {
352363 to : erc20 . token . toString ( ) as `0x${string } `,
353364 data : data as `0x${string } `,
@@ -362,12 +373,12 @@ export class RpcRelayer implements Relayer {
362373 }
363374
364375 case 'erc721-ownership' : {
365- const erc721 = decoded as any
376+ const erc721 = decoded as Erc721OwnershipPrecondition
366377 try {
367378 const data = AbiFunction . encodeData ( erc721OwnerOf , [ erc721 . tokenId ] )
368379 const result = await this . provider . call ( {
369- to : erc721 . token . toString ( ) as `0x${ string } ` ,
370- data : data as `0x${ string } ` ,
380+ to : erc721 . token ,
381+ data : data ,
371382 } )
372383 const resultHex = result . toString ( ) as `0x${string } `
373384 const owner = resultHex . slice ( - 40 )
@@ -381,7 +392,7 @@ export class RpcRelayer implements Relayer {
381392 }
382393
383394 case 'erc721-approval' : {
384- const erc721 = decoded as any
395+ const erc721 = decoded as Erc721ApprovalPrecondition
385396 try {
386397 const data = AbiFunction . encodeData ( erc721GetApproved , [ erc721 . tokenId ] )
387398 const result = await this . provider . call ( {
@@ -398,9 +409,9 @@ export class RpcRelayer implements Relayer {
398409 }
399410
400411 case 'erc1155-balance' : {
401- const erc1155 = decoded as any
412+ const erc1155 = decoded as Erc1155BalancePrecondition
402413 try {
403- const data = AbiFunction . encodeData ( erc1155BalanceOf , [ erc1155 . address . toString ( ) , erc1155 . tokenId ] )
414+ const data = AbiFunction . encodeData ( erc1155BalanceOf , [ erc1155 . address , erc1155 . tokenId ] )
404415 const result = await this . provider . call ( {
405416 to : erc1155 . token . toString ( ) as `0x${string } `,
406417 data : data as `0x${string } `,
@@ -427,15 +438,12 @@ export class RpcRelayer implements Relayer {
427438 }
428439
429440 case 'erc1155-approval' : {
430- const erc1155 = decoded as any
441+ const erc1155 = decoded as Erc1155ApprovalPrecondition
431442 try {
432- const data = AbiFunction . encodeData ( erc1155IsApprovedForAll , [
433- erc1155 . address . toString ( ) ,
434- erc1155 . operator . toString ( ) ,
435- ] )
443+ const data = AbiFunction . encodeData ( erc1155IsApprovedForAll , [ erc1155 . address , erc1155 . operator ] )
436444 const result = await this . provider . call ( {
437- to : erc1155 . token . toString ( ) as `0x${ string } ` ,
438- data : data as `0x${ string } ` ,
445+ to : erc1155 . token ,
446+ data : data ,
439447 } )
440448 return BigInt ( result . toString ( ) ) === 1n
441449 } catch ( error ) {
0 commit comments