41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { parseUnits, formatUnits } from 'viem'
|
|
|
|
const CONTRACT_ADDRESS = process.env.NEXT_PUBLIC_POLL_CONTRACT_ADDRESS as `0x${string}`
|
|
|
|
const ABI = [
|
|
{
|
|
"inputs": [{"internalType": "string","name": "pollId","type": "string"},{"internalType": "uint256","name": "option","type": "uint256"},{"internalType": "uint256","name": "amount","type": "uint256"}],
|
|
"name": "vote",
|
|
"outputs": [],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
},
|
|
{
|
|
"inputs": [{"internalType": "string","name": "pollId","type": "string"}],
|
|
"name": "claimReward",
|
|
"outputs": [],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
},
|
|
{
|
|
"inputs": [{"internalType": "string","name": "pollId","type": "string"},{"internalType": "address","name": "user","type": "address"}],
|
|
"name": "getUserVote",
|
|
"outputs": [{"internalType": "uint256","name": "option","type": "uint256"},{"internalType": "uint256","name": "amount","type": "uint256"},{"internalType": "bool","name": "claimed","type": "bool"}],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}
|
|
] as const
|
|
|
|
export const POLL_CONTRACT = {
|
|
address: CONTRACT_ADDRESS,
|
|
abi: ABI,
|
|
}
|
|
|
|
export function parseVoteAmount(amount: string) {
|
|
return parseUnits(amount, 18)
|
|
}
|
|
|
|
export function formatVoteAmount(amount: bigint) {
|
|
return formatUnits(amount, 18)
|
|
}
|