Skip to content

Commit

Permalink
Aurora: fix unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Jul 12, 2024
1 parent 70665d2 commit 7edd390
Show file tree
Hide file tree
Showing 3 changed files with 4,548 additions and 4,633 deletions.
2 changes: 1 addition & 1 deletion aurora/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"borsh": "^0.7.0",
"chai": "^4.2.0",
"dotenv": "^16.3.1",
"eth-object": "https://github.com/aurora-is-near/eth-object#a84d1420fdde87a768b96c6a3b3d0ee435998f72",
"eth-object": "https://github.com/aurora-is-near/eth-object#378b8dbf44a71f7049666cea5a16ab88d45aed06",
"ethereumjs-util": "^7.1.5",
"ethers": "^6.6.0",
"ethers-utils": "^2.1.11",
Expand Down
22 changes: 3 additions & 19 deletions aurora/scripts/UnlockProof.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function getProofOfData(contractAddress, slotKey, blockNumber, web3) {
return await web3.eth.getProof(contractAddress, [slotKey], blockNumber);
}

async function getWithdrawalsRoot(blockNumber, ethRpcEndpointURL) {
async function getBlockData(blockNumber, ethRpcEndpointURL) {
const response = await fetch(ethRpcEndpointURL, {
method: 'POST',
headers: {
Expand All @@ -39,23 +39,7 @@ async function getWithdrawalsRoot(blockNumber, ethRpcEndpointURL) {
id: 0
})
});
return (await response.json())["result"]["withdrawalsRoot"];
}

async function getBlockData(blockNumber, web3, ethRpcEndpointURL) {
let block = await web3.eth.getBlock(blockNumber);
block.difficulty = web3.utils.toHex(block.difficulty);
block.number = web3.utils.toHex(parseInt(block.number));
block.nonce = "0x" + parseInt(block.nonce).toString(16).padStart(16, '0');
block.baseFeePerGas = web3.utils.toHex(parseInt(block.baseFeePerGas));
block.gasLimit = web3.utils.toHex(parseInt(block.gasLimit));
block.gasUsed = web3.utils.toHex(parseInt(block.gasUsed));
block.size = web3.utils.toHex(parseInt(block.size));
block.timestamp = web3.utils.toHex(parseInt(block.timestamp));
block.totalDifficulty = web3.utils.toHex(block.totalDifficulty);
block.withdrawalsRoot = await getWithdrawalsRoot(blockNumber, ethRpcEndpointURL);

return block;
return (await response.json())["result"];
}

async function generateUnlockProof(getProofResponse, block, web3){
Expand Down Expand Up @@ -94,7 +78,7 @@ async function getUnlockProof(contractAddress, data, blockNumber, ethRpcEndpoint
let processHash = processedHash(data.token, data.recipient, data.nonce, data.amount);
let slotKeyOfProcessedHash = getProcessedHashSlotKey(processHash);
let responseData = await getProofOfData(contractAddress, slotKeyOfProcessedHash, blockNumber, web3);
let block = await getBlockData(blockNumber, web3, ethRpcEndpointURL);
let block = await getBlockData(blockNumber, ethRpcEndpointURL);
let unlockProof = await generateUnlockProof(responseData, block, web3);

let borshSer = borsh.serialize(
Expand Down
Loading

0 comments on commit 7edd390

Please sign in to comment.