import { Contract , providers as ethersProviders } from 'ethers' ; import { forwarderAbi } from './abis' ; export const FORWARD_SIG = '0xd948d468' ; param { string } calldata export function isValidForwardCall ( calldata ) { calldata = calldata . replace ( /^0x/ , '' ) ; const selector = calldata . substring ( 0 , 8 ) ; const evmscriptData = calldata . substring ( 8 ) ; return `0x${ selector }` === FORWARD_SIG && evmscriptData . length >= 128 ; } param { string } calldata returns { string } export function parseForwardCall ( calldata ) { calldata = calldata . replace ( /^0x/ , '' ) ; const evmscriptData = calldata . substring ( 8 ) ; const offset = parseInt ( `0x${ evmscriptData . substring ( 0 , 64 ) }` , 16 ) * 2 ; const startIndex = offset + 64 ; const dataLength = parseInt ( `0x${ evmscriptData . substring ( offset , startIndex ) }` , 16 ) * 2 ; return `0x${ evmscriptData . substring ( startIndex , startIndex + dataLength ) }` ; } /**
 * Whether the `sender` can use the `forwarder` to invoke `script`.
 */ export function canForward ( forwarderAddress , sender , script , provider ) { const forwarder = new Contract ( forwarderAddress , forwarderAbi , provider ) ; return forwarder . canForward ( sender , script ) . catch ( ( ) => false ) ; }