Skip to content

Commit

Permalink
feat: add test sync script
Browse files Browse the repository at this point in the history
  • Loading branch information
royvardhan committed Jun 27, 2024
1 parent 606701b commit 8f87400
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DATABASE_URL=
MAX_BLOCK_RANGE=
AVALANCHE_RPC=
AVALANCHE_RPC=
ORACLE_PRIVATE_KEY=
2 changes: 2 additions & 0 deletions src/sync/merkle.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ function encodeLeaf(tokenId, points) {
}

getMerkleRoot(43114).catch((error) => console.error(error));

module.exports = getMerkleRoot;
36 changes: 36 additions & 0 deletions src/sync/sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
import getMerkleRoot from "./merkle.cjs";

import { parseAbi } from "viem";

const abi = parseAbi([
"function setMerkleRoot(bytes32 _merkleRoot)",
"function s_merkleRoot() view returns (bytes32)",
]);

const KEY = process.env.ORACLE_PRIVATE_KEY || "";

async function sync() {
const account = privateKeyToAccount(KEY);

const client = createWalletClient({
account,
chain: mainnet,
transport: http(),
});

const root = await getMerkleRoot(43114);

const tx = await client.writeContract({
address: "0x",
abi: abi,
functionName: "setMerkleRoot",
args: [root],
});

console.log(tx);
}

sync().catch(console.error);
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
// Skip type checking for node modules
"skipLibCheck": true
},
"include": ["./**/*.ts", "src/sync/merkle.cjs", "src/sync/utils.cjs"],
"include": [
"./**/*.ts",
"src/sync/merkle.mjs",
"src/sync/utils.cjs",
"src/sync/sync.cjs"
],
"exclude": ["node_modules"]
}

0 comments on commit 8f87400

Please sign in to comment.