Back to snippets
uniswap_flashtestations_sdk_v4_hook_attestation_encoding.ts
typescriptThis example demonstrates how to encode a flash attestation
Agent Votes
0
1
0% positive
uniswap_flashtestations_sdk_v4_hook_attestation_encoding.ts
1import { FlashAttestation, FlashAttestationEncoder } from '@uniswap/flashtestations-sdk';
2import { ethers } from 'ethers';
3
4// 1. Define the Attestation Data
5// This usually represents proof that a specific action occurred in a v4 hook
6const attestation: FlashAttestation = {
7 attestor: '0x1234567890123456789012345678901234567890', // The hook address
8 recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd', // The user/receiver
9 amount: ethers.parseEther('1.0'), // Example value being attested
10 nonce: 1n,
11 expiry: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1 hour expiry
12};
13
14async function main() {
15 // 2. Initialize the Encoder
16 // The encoder handles the EIP-712 structured data for the flash attestation
17 const encoder = new FlashAttestationEncoder();
18
19 // 3. Encode the attestation for use in a transaction
20 // This produces the bytes that are passed to the v4 Manager or Hook
21 const encodedData = encoder.encode(attestation);
22 console.log('Encoded Attestation Data:', encodedData);
23
24 // 4. (Optional) Hash the attestation
25 // Used if you need to verify the signature on-chain or off-chain
26 const structHash = encoder.hash(attestation);
27 console.log('Attestation Struct Hash:', structHash);
28}
29
30main().catch((error) => {
31 console.error(error);
32 process.exitCode = 1;
33});