@moonwell-fi/moonwell-sdk
Version:
TypeScript Interface for Moonwell
71 lines • 2.78 kB
JavaScript
import { Amount, getEnvironmentFromArgs } from "../../common/index.js";
import { publicEnvironments, } from "../../environments/index.js";
export async function getUserVoteReceipt(client, args) {
const { proposalId, userAddress } = args;
const environment = getEnvironmentFromArgs(client, args);
if (!environment) {
return [];
}
let isMultichain = false;
let getReceiptProposalId = proposalId;
if (environment.contracts.multichainGovernor) {
if (environment.custom?.governance?.proposalIdOffset) {
if (proposalId > environment.custom?.governance?.proposalIdOffset) {
isMultichain = true;
getReceiptProposalId =
proposalId - environment.custom?.governance?.proposalIdOffset;
}
}
}
const result = [];
if (isMultichain) {
const governanceChainIds = environment.custom?.governance?.chainIds || [];
const receipt = await environment.contracts.multichainGovernor?.read.getReceipt([
BigInt(getReceiptProposalId),
userAddress,
]);
const [hasVoted, voteValue, votes] = receipt || [false, 0, 0];
result.push({
chainId: environment.chainId,
proposalId,
account: userAddress,
option: voteValue,
voted: hasVoted,
votes: new Amount(votes || 0, 18),
});
for (const chainId of governanceChainIds) {
const multichainEnvironment = Object.values(publicEnvironments).find((r) => r.chainId === chainId);
if (multichainEnvironment) {
const receipt = await multichainEnvironment.contracts.voteCollector?.read.getReceipt([
BigInt(getReceiptProposalId),
userAddress,
]);
const [hasVoted, voteValue, votes] = receipt || [false, 0, 0];
result.push({
chainId: multichainEnvironment.chainId,
proposalId,
account: userAddress,
option: voteValue,
voted: hasVoted,
votes: new Amount(votes || 0, 18),
});
}
}
}
else {
const receipt = await environment.contracts.governor?.read.getReceipt([
BigInt(getReceiptProposalId),
userAddress,
]);
result.push({
chainId: environment.chainId,
proposalId,
account: userAddress,
option: receipt?.voteValue || 0,
voted: receipt?.hasVoted || false,
votes: new Amount(receipt?.votes || 0, 18),
});
}
return result;
}
//# sourceMappingURL=getUserVoteReceipt.js.map