Skip to content

Commit

Permalink
script to check if token is attested on target chain
Browse files Browse the repository at this point in the history
  • Loading branch information
martin0995 committed Sep 2, 2024
1 parent 1ae5cf4 commit ed4c15a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions script/check-attestation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ethers } from 'ethers';
import * as dotenv from 'dotenv';
import readlineSync from 'readline-sync';

dotenv.config();

async function main() {
// Prompt user for the target chain details
const rpcUrl = readlineSync.question('Enter the TARGET chain RPC URL: ');
const tokenBridgeAddress = readlineSync.question('Enter the Token Bridge contract address on the TARGET chain: ');

const provider = new ethers.JsonRpcProvider(rpcUrl);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);

// Load the Token Bridge ABI
const tokenBridgeAbi = [
'function wrappedAsset(uint16 tokenChainId, bytes32 tokenAddress) view returns (address)',
];

// Create the Token Bridge contract instance
const tokenBridge = new ethers.Contract(tokenBridgeAddress, tokenBridgeAbi, wallet);

// Ask for the token address and source chain ID to check
const tokenAddress = readlineSync.question('Enter the token contract address on the SOURCE chain: ');
const sourceChainId = readlineSync.questionInt('Enter the SOURCE chain ID: ');

// Convert the 20-byte token address to a 32-byte address padded with leading zeros
const paddedTokenAddress = ethers.zeroPadValue(ethers.getAddress(tokenAddress), 32);

// Check if the token is attested on the target chain
const wrappedTokenAddress = await tokenBridge.wrappedAsset(sourceChainId, paddedTokenAddress);

if (wrappedTokenAddress === ethers.ZeroAddress) {
console.log('The token has NOT been attested on the target chain.');
} else {
console.log(`The token is attested on the target chain. Wrapped token address: ${wrappedTokenAddress}`);
}
}

main().catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit ed4c15a

Please sign in to comment.