2021-09-09 05:42:42 +00:00
|
|
|
use ethers::{
|
2021-10-29 12:29:35 +00:00
|
|
|
contract::{Eip712, EthAbiType},
|
2021-10-08 16:31:42 +00:00
|
|
|
core::types::transaction::eip712::Eip712,
|
|
|
|
types::{Address, U256},
|
2021-09-09 05:42:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Generate the EIP712 permit hash to sign for a Uniswap V2 pair.
|
2022-03-19 17:05:39 +00:00
|
|
|
// <https://eips.ethereum.org/EIPS/eip-712>
|
|
|
|
// <https://eips.ethereum.org/EIPS/eip-2612>
|
2021-10-08 16:31:42 +00:00
|
|
|
#[derive(Eip712, EthAbiType, Clone)]
|
|
|
|
#[eip712(
|
|
|
|
name = "Uniswap V2",
|
|
|
|
version = "1",
|
|
|
|
chain_id = 1,
|
|
|
|
verifying_contract = "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc"
|
|
|
|
)]
|
|
|
|
struct Permit {
|
|
|
|
owner: Address,
|
|
|
|
spender: Address,
|
|
|
|
value: U256,
|
|
|
|
nonce: U256,
|
|
|
|
deadline: U256,
|
|
|
|
}
|
2021-09-09 05:42:42 +00:00
|
|
|
|
2021-10-08 16:31:42 +00:00
|
|
|
fn main() {
|
|
|
|
let permit = Permit {
|
|
|
|
owner: Address::random(),
|
|
|
|
spender: Address::random(),
|
|
|
|
value: 100.into(),
|
|
|
|
nonce: 0.into(),
|
|
|
|
deadline: U256::MAX,
|
|
|
|
};
|
|
|
|
let permit_hash = permit.encode_eip712().unwrap();
|
|
|
|
println!("Permit hash: 0x{}", hex::encode(permit_hash));
|
2021-09-09 05:42:42 +00:00
|
|
|
}
|