enums.js 796 B

12345678910111213141516171819202122
  1. function Enum(...options) {
  2. return Object.fromEntries(options.map((key, i) => [key, web3.utils.toBN(i)]));
  3. }
  4. function EnumBigInt(...options) {
  5. return Object.fromEntries(options.map((key, i) => [key, BigInt(i)]));
  6. }
  7. // TODO: remove web3, simplify code
  8. function createExport(Enum) {
  9. return {
  10. Enum,
  11. ProposalState: Enum('Pending', 'Active', 'Canceled', 'Defeated', 'Succeeded', 'Queued', 'Expired', 'Executed'),
  12. VoteType: Enum('Against', 'For', 'Abstain'),
  13. Rounding: Enum('Floor', 'Ceil', 'Trunc', 'Expand'),
  14. OperationState: Enum('Unset', 'Waiting', 'Ready', 'Done'),
  15. RevertType: Enum('None', 'RevertWithoutMessage', 'RevertWithMessage', 'RevertWithCustomError', 'Panic'),
  16. };
  17. }
  18. module.exports = createExport(Enum);
  19. module.exports.bigint = createExport(EnumBigInt);