The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hyperlane-monorepo/solidity/abacus-xapps/test/bridge/lib/permit.ts

47 lines
1.3 KiB

import { BigNumber, BigNumberish, ethers } from 'ethers';
import { BridgeToken } from '../../../typechain';
const PERMIT_TYPEHASH = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes(
'Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)',
),
);
export type Approval = {
owner: string;
spender: string;
value: BigNumberish;
deadline: BigNumberish;
};
export async function permitDigest(
token: BridgeToken,
approval: Approval,
): Promise<string> {
const separator = await token.domainSeparator();
const nonce = await token.nonces(approval.owner);
return ethers.utils.keccak256(
ethers.utils.solidityPack(
['bytes1', 'bytes1', 'bytes32', 'bytes32'],
[
'0x19', // prefix
'0x01', // version
separator,
ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(
['bytes32', 'address', 'address', 'uint256', 'uint256', 'uint256'],
[
PERMIT_TYPEHASH,
ethers.utils.getAddress(approval.owner),
ethers.utils.getAddress(approval.spender),
BigNumber.from(approval.value),
nonce,
BigNumber.from(approval.deadline),
],
),
),
],
),
);
}