Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import Web3 from "web3"; // Web3
import axios from "axios"; // Axios requests
import { recoverTypedSignature } from "@metamask/eth-sig-util"; // EIP-712 sig verification
import { Defender } from "@openzeppelin/defender-sdk";

/**
* Instantiates server-side web3 connection
Expand All @@ -31,11 +30,11 @@ export const Web3Handler = () => {
const compToken = new web3.eth.Contract(COMP_ABI, COMP_ADDRESS);
const governorBravo = new web3.eth.Contract(
GOVERNOR_BRAVO_ABI,
GOVERNANCE_ADDRESS
GOVERNANCE_ADDRESS,
);
const governorCharlie = new web3.eth.Contract(
GOVERNOR_CHARLIE_ABI,
GOVERNOR_CHARLIE_ADDRESS
GOVERNOR_CHARLIE_ADDRESS,
);
const multicall = new web3.eth.Contract(MULTICALL_ABI, MULTICALL_ADDRESS);

Expand Down Expand Up @@ -442,32 +441,34 @@ const vote = async (address, proposalId, support, v, r, s) => {
};

const relayVote = async (voteSignature) => {
const { governorCharlie } = Web3Handler();

const client = new Defender({
relayerApiKey: process.env.DEFENDER_API_KEY,
relayerApiSecret: process.env.DEFENDER_API_SECRET,
});
const { web3, governorCharlie } = Web3Handler();

const web3jsTx = governorCharlie.methods.castVoteBySig(
voteSignature.proposalId,
voteSignature.support,
voteSignature.from,
`${voteSignature.r}${voteSignature.s.substring(
2
)}${voteSignature.v.substring(2)}`
2,
)}${voteSignature.v.substring(2)}`,
);

const account = web3.eth.accounts.privateKeyToAccount(
process.env.PRIVATE_KEY,
);

const tx = {
from: account.address,
to: GOVERNOR_CHARLIE_ADDRESS,
data: web3jsTx.encodeABI(),
gasLimit: Math.round((await web3jsTx.estimateGas()) * 1.2),
gas: Math.round((await web3jsTx.estimateGas({ from: account.address })) * 1.2),
value: 0,
maxPriorityFeePerGas: "500000000",
maxFeePerGas: "50000000000"
maxFeePerGas: "50000000000",
};

return (await client.relaySigner.sendTransaction(tx)).hash;
const signed = await account.signTransaction(tx);
const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
return receipt.transactionHash;
};

/**
Expand Down Expand Up @@ -554,7 +555,7 @@ const delegate = async (address, delegatee, nonce, expiry, v, r, s) => {
// Send notification to admin using telegram
if (typeof process.env.NOTIFICATION_HOOK != "undefined") {
await axios.get(
process.env.NOTIFICATION_HOOK + "New comp.vote delegation sig"
process.env.NOTIFICATION_HOOK + "New comp.vote delegation sig",
);
}
};
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@davatar/react": "^1.8.1",
"@ethersproject/providers": "^5.7.2",
"@metamask/eth-sig-util": "^4.0.0",
"@openzeppelin/defender-sdk": "^2.5.0",
"@rainbow-me/rainbowkit": "^2.0.0",
"@tanstack/react-query": "^5.17.0",
"@vercel/analytics": "^1.2.2",
Expand Down
Loading