From 6c9c5da80dfdc392c05fe7cf8ad5a064917ee557 Mon Sep 17 00:00:00 2001 From: Vadym Mozharivsky Date: Thu, 12 Dec 2024 11:04:19 +0200 Subject: [PATCH 1/2] berrachain --- src/berrachain/bgt.js | 2021 ++++++++++++++++++++++++++++ src/berrachain/bgt.ts | 1766 ++++++++++++++++++++++++ src/berrachain/constants/errors.js | 8 + src/berrachain/constants/errors.ts | 16 + src/berrachain/constants/index.js | 6 + src/berrachain/constants/index.ts | 6 + src/berrachain/index.js | 115 ++ src/berrachain/index.ts | 281 ++++ src/berrachain/types/index.js | 2 + src/berrachain/types/index.ts | 9 + src/ethereum/__tests__/index.ts | 56 +- src/index.ts | 3 + src/utils/constants/errors.js | 7 + src/utils/index.js | 139 ++ 14 files changed, 4406 insertions(+), 29 deletions(-) create mode 100644 src/berrachain/bgt.js create mode 100755 src/berrachain/bgt.ts create mode 100644 src/berrachain/constants/errors.js create mode 100644 src/berrachain/constants/errors.ts create mode 100644 src/berrachain/constants/index.js create mode 100644 src/berrachain/constants/index.ts create mode 100644 src/berrachain/index.js create mode 100644 src/berrachain/index.ts create mode 100644 src/berrachain/types/index.js create mode 100644 src/berrachain/types/index.ts create mode 100644 src/utils/constants/errors.js create mode 100644 src/utils/index.js diff --git a/src/berrachain/bgt.js b/src/berrachain/bgt.js new file mode 100644 index 0000000..5297648 --- /dev/null +++ b/src/berrachain/bgt.js @@ -0,0 +1,2021 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BGT_ABI = void 0; +exports.BGT_ABI = [ + { + inputs: [], + name: 'AlreadyInitialized', + type: 'error', + }, + { + inputs: [], + name: 'AmountLessThanMinIncentiveRate', + type: 'error', + }, + { + inputs: [], + name: 'CannotRecoverIncentiveToken', + type: 'error', + }, + { + inputs: [], + name: 'CannotRecoverRewardToken', + type: 'error', + }, + { + inputs: [], + name: 'CannotRecoverStakingToken', + type: 'error', + }, + { + inputs: [], + name: 'CheckpointUnorderedInsertion', + type: 'error', + }, + { + inputs: [], + name: 'DepositNotMultipleOfGwei', + type: 'error', + }, + { + inputs: [], + name: 'DepositValueTooHigh', + type: 'error', + }, + { + inputs: [], + name: 'DonateAmountLessThanPayoutAmount', + type: 'error', + }, + { + inputs: [], + name: 'ECDSAInvalidSignature', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'length', + type: 'uint256', + }, + ], + name: 'ECDSAInvalidSignatureLength', + type: 'error', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + name: 'ECDSAInvalidSignatureS', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'increasedSupply', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'cap', + type: 'uint256', + }, + ], + name: 'ERC20ExceededSafeSupply', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'allowance', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'needed', + type: 'uint256', + }, + ], + name: 'ERC20InsufficientAllowance', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'balance', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'needed', + type: 'uint256', + }, + ], + name: 'ERC20InsufficientBalance', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'approver', + type: 'address', + }, + ], + name: 'ERC20InvalidApprover', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + ], + name: 'ERC20InvalidReceiver', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + ], + name: 'ERC20InvalidSender', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'ERC20InvalidSpender', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'timepoint', + type: 'uint256', + }, + { + internalType: 'uint48', + name: 'clock', + type: 'uint48', + }, + ], + name: 'ERC5805FutureLookup', + type: 'error', + }, + { + inputs: [], + name: 'ERC6372InconsistentClock', + type: 'error', + }, + { + inputs: [], + name: 'IncentiveRateTooHigh', + type: 'error', + }, + { + inputs: [], + name: 'IndexOutOfRange', + type: 'error', + }, + { + inputs: [], + name: 'InsolventReward', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientDelegateStake', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientDeposit', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientSelfStake', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientStake', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint256', + name: 'currentNonce', + type: 'uint256', + }, + ], + name: 'InvalidAccountNonce', + type: 'error', + }, + { + inputs: [], + name: 'InvalidActivateBoostDelay', + type: 'error', + }, + { + inputs: [], + name: 'InvalidBaseRate', + type: 'error', + }, + { + inputs: [], + name: 'InvalidBoostMultiplier', + type: 'error', + }, + { + inputs: [], + name: 'InvalidCredentialsLength', + type: 'error', + }, + { + inputs: [], + name: 'InvalidDropBoostDelay', + type: 'error', + }, + { + inputs: [], + name: 'InvalidInitialization', + type: 'error', + }, + { + inputs: [], + name: 'InvalidMaxIncentiveTokensCount', + type: 'error', + }, + { + inputs: [], + name: 'InvalidMinBoostedRewardRate', + type: 'error', + }, + { + inputs: [], + name: 'InvalidProof', + type: 'error', + }, + { + inputs: [], + name: 'InvalidPubKeyLength', + type: 'error', + }, + { + inputs: [], + name: 'InvalidRewardAllocationWeights', + type: 'error', + }, + { + inputs: [], + name: 'InvalidRewardConvexity', + type: 'error', + }, + { + inputs: [], + name: 'InvalidRewardRate', + type: 'error', + }, + { + inputs: [], + name: 'InvalidRewardVaultAddress', + type: 'error', + }, + { + inputs: [], + name: 'InvalidSignatureLength', + type: 'error', + }, + { + inputs: [], + name: 'InvalidStartBlock', + type: 'error', + }, + { + inputs: [], + name: 'InvalidateDefaultRewardAllocation', + type: 'error', + }, + { + inputs: [], + name: 'InvariantCheckFailed', + type: 'error', + }, + { + inputs: [], + name: 'MaxNumWeightsPerRewardAllocationIsZero', + type: 'error', + }, + { + inputs: [], + name: 'MinIncentiveRateIsZero', + type: 'error', + }, + { + inputs: [], + name: 'NotAContract', + type: 'error', + }, + { + inputs: [], + name: 'NotApprovedSender', + type: 'error', + }, + { + inputs: [], + name: 'NotBGT', + type: 'error', + }, + { + inputs: [], + name: 'NotBlockRewardController', + type: 'error', + }, + { + inputs: [], + name: 'NotDelegate', + type: 'error', + }, + { + inputs: [], + name: 'NotDistributor', + type: 'error', + }, + { + inputs: [], + name: 'NotEnoughBalance', + type: 'error', + }, + { + inputs: [], + name: 'NotEnoughBoostedBalance', + type: 'error', + }, + { + inputs: [], + name: 'NotEnoughTime', + type: 'error', + }, + { + inputs: [], + name: 'NotFactoryVault', + type: 'error', + }, + { + inputs: [], + name: 'NotFeeCollector', + type: 'error', + }, + { + inputs: [], + name: 'NotGovernance', + type: 'error', + }, + { + inputs: [], + name: 'NotIncentiveManager', + type: 'error', + }, + { + inputs: [], + name: 'NotInitializing', + type: 'error', + }, + { + inputs: [], + name: 'NotNewOperator', + type: 'error', + }, + { + inputs: [], + name: 'NotOperator', + type: 'error', + }, + { + inputs: [], + name: 'NotRootFollower', + type: 'error', + }, + { + inputs: [], + name: 'NotWhitelistedVault', + type: 'error', + }, + { + inputs: [], + name: 'OperatorAlreadySet', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'OwnableInvalidOwner', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'OwnableUnauthorizedAccount', + type: 'error', + }, + { + inputs: [], + name: 'PayoutAmountIsZero', + type: 'error', + }, + { + inputs: [], + name: 'RewardAllocationAlreadyQueued', + type: 'error', + }, + { + inputs: [], + name: 'RewardAllocationBlockDelayTooLarge', + type: 'error', + }, + { + inputs: [], + name: 'RewardCycleNotEnded', + type: 'error', + }, + { + inputs: [], + name: 'RewardsDurationIsZero', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint8', + name: 'bits', + type: 'uint8', + }, + { + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'SafeCastOverflowedUintDowncast', + type: 'error', + }, + { + inputs: [], + name: 'StakeAmountIsZero', + type: 'error', + }, + { + inputs: [], + name: 'TimestampAlreadyProcessed', + type: 'error', + }, + { + inputs: [], + name: 'TokenAlreadyWhitelistedOrLimitReached', + type: 'error', + }, + { + inputs: [], + name: 'TokenNotWhitelisted', + type: 'error', + }, + { + inputs: [], + name: 'TooManyWeights', + type: 'error', + }, + { + inputs: [], + name: 'TotalSupplyOverflow', + type: 'error', + }, + { + inputs: [], + name: 'VaultAlreadyExists', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'expiry', + type: 'uint256', + }, + ], + name: 'VotesExpiredSignature', + type: 'error', + }, + { + inputs: [], + name: 'WithdrawAmountIsZero', + type: 'error', + }, + { + inputs: [], + name: 'ZeroAddress', + type: 'error', + }, + { + inputs: [], + name: 'ZeroOperatorOnFirstDeposit', + type: 'error', + }, + { + inputs: [], + name: 'ZeroPercentageWeight', + type: 'error', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'user', + type: 'address', + }, + { + indexed: true, + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'ActivateBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint32', + name: 'newDelay', + type: 'uint32', + }, + ], + name: 'ActivateBoostDelayChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previous', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'current', + type: 'address', + }, + ], + name: 'BeaconDepositContractChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'CancelBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'user', + type: 'address', + }, + { + indexed: true, + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'CancelDropBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'delegator', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'fromDelegate', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'toDelegate', + type: 'address', + }, + ], + name: 'DelegateChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'delegate', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'previousVotes', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'newVotes', + type: 'uint256', + }, + ], + name: 'DelegateVotesChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'DropBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint32', + name: 'newDelay', + type: 'uint32', + }, + ], + name: 'DropBoostDelayChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [], + name: 'EIP712DomainChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint64', + name: 'version', + type: 'uint64', + }, + ], + name: 'Initialized', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previous', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'current', + type: 'address', + }, + ], + name: 'MinterChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'QueueBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'user', + type: 'address', + }, + { + indexed: true, + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'QueueDropBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'Redeem', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'SenderWhitelisted', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previous', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'current', + type: 'address', + }, + ], + name: 'StakerChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + inputs: [], + name: 'CLOCK_MODE', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'user', + type: 'address', + }, + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + ], + name: 'activateBoost', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'activateBoostDelay', + outputs: [ + { + internalType: 'uint32', + name: '', + type: 'uint32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'allowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'beaconDepositContract', + outputs: [ + { + internalType: 'contract IBeaconDeposit', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + ], + name: 'boosted', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + ], + name: 'boostedQueue', + outputs: [ + { + internalType: 'uint32', + name: 'blockNumberLast', + type: 'uint32', + }, + { + internalType: 'uint128', + name: 'balance', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + ], + name: 'boostees', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'boosts', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'cancelBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'cancelDropBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint32', + name: 'pos', + type: 'uint32', + }, + ], + name: 'checkpoints', + outputs: [ + { + components: [ + { + internalType: 'uint48', + name: '_key', + type: 'uint48', + }, + { + internalType: 'uint208', + name: '_value', + type: 'uint208', + }, + ], + internalType: 'struct Checkpoints.Checkpoint208', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'clock', + outputs: [ + { + internalType: 'uint48', + name: '', + type: 'uint48', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'decimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'delegatee', + type: 'address', + }, + ], + name: 'delegate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'delegatee', + type: 'address', + }, + { + internalType: 'uint256', + name: 'nonce', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'expiry', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + name: 'delegateBySig', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'delegates', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'user', + type: 'address', + }, + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + ], + name: 'dropBoost', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'dropBoostDelay', + outputs: [ + { + internalType: 'uint32', + name: '', + type: 'uint32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + ], + name: 'dropBoostQueue', + outputs: [ + { + internalType: 'uint32', + name: 'blockNumberLast', + type: 'uint32', + }, + { + internalType: 'uint128', + name: 'balance', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'eip712Domain', + outputs: [ + { + internalType: 'bytes1', + name: 'fields', + type: 'bytes1', + }, + { + internalType: 'string', + name: 'name', + type: 'string', + }, + { + internalType: 'string', + name: 'version', + type: 'string', + }, + { + internalType: 'uint256', + name: 'chainId', + type: 'uint256', + }, + { + internalType: 'address', + name: 'verifyingContract', + type: 'address', + }, + { + internalType: 'bytes32', + name: 'salt', + type: 'bytes32', + }, + { + internalType: 'uint256[]', + name: 'extensions', + type: 'uint256[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'timepoint', + type: 'uint256', + }, + ], + name: 'getPastTotalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint256', + name: 'timepoint', + type: 'uint256', + }, + ], + name: 'getPastVotes', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'getVotes', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_owner', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + ], + name: 'isWhitelistedSender', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'distributor', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'mint', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'minter', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes[]', + name: 'data', + type: 'bytes[]', + }, + ], + name: 'multicall', + outputs: [ + { + internalType: 'bytes[]', + name: '', + type: 'bytes[]', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'nonces', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + ], + name: 'normalizedBoost', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'numCheckpoints', + outputs: [ + { + internalType: 'uint32', + name: '', + type: 'uint32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'queueBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'pubkey', + type: 'bytes', + }, + { + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'queueDropBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'queuedBoost', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'redeem', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint32', + name: '_activateBoostDelay', + type: 'uint32', + }, + ], + name: 'setActivateBoostDelay', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_beaconDepositContract', + type: 'address', + }, + ], + name: 'setBeaconDepositContract', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint32', + name: '_dropBoostDelay', + type: 'uint32', + }, + ], + name: 'setDropBoostDelay', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_minter', + type: 'address', + }, + ], + name: 'setMinter', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_staker', + type: 'address', + }, + ], + name: 'setStaker', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'staker', + outputs: [ + { + internalType: 'contract BGTStaker', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'totalBoosts', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'unboostedBalanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'whitelistSender', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +]; diff --git a/src/berrachain/bgt.ts b/src/berrachain/bgt.ts new file mode 100755 index 0000000..e7c80d4 --- /dev/null +++ b/src/berrachain/bgt.ts @@ -0,0 +1,1766 @@ +export const BGT_ABI = [ + { + inputs: [], + name: 'AlreadyInitialized', + type: 'error', + }, + { + inputs: [], + name: 'AmountLessThanMinIncentiveRate', + type: 'error', + }, + { + inputs: [], + name: 'BlockDoesNotExist', + type: 'error', + }, + { + inputs: [], + name: 'BlockNotInBuffer', + type: 'error', + }, + { + inputs: [], + name: 'CannotRecoverRewardToken', + type: 'error', + }, + { + inputs: [], + name: 'CannotRecoverStakingToken', + type: 'error', + }, + { + inputs: [], + name: 'CheckpointUnorderedInsertion', + type: 'error', + }, + { + inputs: [], + name: 'DelegateStakedOverflow', + type: 'error', + }, + { + inputs: [], + name: 'ECDSAInvalidSignature', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'length', + type: 'uint256', + }, + ], + name: 'ECDSAInvalidSignatureLength', + type: 'error', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + name: 'ECDSAInvalidSignatureS', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'increasedSupply', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'cap', + type: 'uint256', + }, + ], + name: 'ERC20ExceededSafeSupply', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'allowance', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'needed', + type: 'uint256', + }, + ], + name: 'ERC20InsufficientAllowance', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'balance', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'needed', + type: 'uint256', + }, + ], + name: 'ERC20InsufficientBalance', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'approver', + type: 'address', + }, + ], + name: 'ERC20InvalidApprover', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + ], + name: 'ERC20InvalidReceiver', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + ], + name: 'ERC20InvalidSender', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'ERC20InvalidSpender', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'timepoint', + type: 'uint256', + }, + { + internalType: 'uint48', + name: 'clock', + type: 'uint48', + }, + ], + name: 'ERC5805FutureLookup', + type: 'error', + }, + { + inputs: [], + name: 'ERC6372InconsistentClock', + type: 'error', + }, + { + inputs: [], + name: 'InsolventReward', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientDelegateStake', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientSelfStake', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientStake', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint256', + name: 'currentNonce', + type: 'uint256', + }, + ], + name: 'InvalidAccountNonce', + type: 'error', + }, + { + inputs: [], + name: 'InvalidCommission', + type: 'error', + }, + { + inputs: [], + name: 'InvalidCuttingBoardWeights', + type: 'error', + }, + { + inputs: [], + name: 'InvalidInitialization', + type: 'error', + }, + { + inputs: [], + name: 'InvalidMaxIncentiveTokensCount', + type: 'error', + }, + { + inputs: [], + name: 'InvalidMinter', + type: 'error', + }, + { + inputs: [], + name: 'InvalidStartBlock', + type: 'error', + }, + { + inputs: [], + name: 'InvariantCheckFailed', + type: 'error', + }, + { + inputs: [], + name: 'MaxNumWeightsPerCuttingBoardIsZero', + type: 'error', + }, + { + inputs: [], + name: 'NoWhitelistedTokens', + type: 'error', + }, + { + inputs: [], + name: 'NotActionableBlock', + type: 'error', + }, + { + inputs: [], + name: 'NotApprovedSender', + type: 'error', + }, + { + inputs: [], + name: 'NotBGT', + type: 'error', + }, + { + inputs: [], + name: 'NotBlockRewardController', + type: 'error', + }, + { + inputs: [], + name: 'NotDelegate', + type: 'error', + }, + { + inputs: [], + name: 'NotDistributor', + type: 'error', + }, + { + inputs: [], + name: 'NotEnoughBalance', + type: 'error', + }, + { + inputs: [], + name: 'NotEnoughTime', + type: 'error', + }, + { + inputs: [], + name: 'NotFeeCollector', + type: 'error', + }, + { + inputs: [], + name: 'NotFriendOfTheChef', + type: 'error', + }, + { + inputs: [], + name: 'NotGovernance', + type: 'error', + }, + { + inputs: [], + name: 'NotInitializing', + type: 'error', + }, + { + inputs: [], + name: 'NotOperator', + type: 'error', + }, + { + inputs: [], + name: 'NotProver', + type: 'error', + }, + { + inputs: [], + name: 'NotRootFollower', + type: 'error', + }, + { + inputs: [], + name: 'NotValidatorOrOperator', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'OwnableInvalidOwner', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'OwnableUnauthorizedAccount', + type: 'error', + }, + { + inputs: [], + name: 'PayoutAmountIsZero', + type: 'error', + }, + { + inputs: [], + name: 'PayoutTokenIsZero', + type: 'error', + }, + { + inputs: [], + name: 'QueuedCuttingBoardNotFound', + type: 'error', + }, + { + inputs: [], + name: 'QueuedCuttingBoardNotReady', + type: 'error', + }, + { + inputs: [], + name: 'RewardCycleNotEnded', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint8', + name: 'bits', + type: 'uint8', + }, + { + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'SafeCastOverflowedUintDowncast', + type: 'error', + }, + { + inputs: [], + name: 'StakeAmountIsZero', + type: 'error', + }, + { + inputs: [], + name: 'TokenAlreadyWhitelistedOrLimitReached', + type: 'error', + }, + { + inputs: [], + name: 'TokenNotWhitelisted', + type: 'error', + }, + { + inputs: [], + name: 'TooManyWeights', + type: 'error', + }, + { + inputs: [], + name: 'TotalSupplyOverflow', + type: 'error', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'Unauthorized', + type: 'error', + }, + { + inputs: [], + name: 'VaultAlreadyExists', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'expiry', + type: 'uint256', + }, + ], + name: 'VotesExpiredSignature', + type: 'error', + }, + { + inputs: [], + name: 'WithdrawAmountIsZero', + type: 'error', + }, + { + inputs: [], + name: 'ZeroAddress', + type: 'error', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'ActivateBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previous', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'current', + type: 'address', + }, + ], + name: 'BeraChefChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'CancelBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'delegator', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'fromDelegate', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'toDelegate', + type: 'address', + }, + ], + name: 'DelegateChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'delegate', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'previousVotes', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'newVotes', + type: 'uint256', + }, + ], + name: 'DelegateVotesChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'DropBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [], + name: 'EIP712DomainChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint64', + name: 'version', + type: 'uint64', + }, + ], + name: 'Initialized', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previous', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'current', + type: 'address', + }, + ], + name: 'MinterChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + indexed: false, + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'QueueBoost', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'Redeem', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'SenderWhitelisted', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'oldRate', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'newRate', + type: 'uint256', + }, + ], + name: 'UpdateCommission', + type: 'event', + }, + { + inputs: [], + name: 'CLOCK_MODE', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + ], + name: 'activateBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'allowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'beraChef', + outputs: [ + { + internalType: 'contract IBeraChef', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + ], + name: 'boosted', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + ], + name: 'boostedQueue', + outputs: [ + { + internalType: 'uint32', + name: 'blockNumberLast', + type: 'uint32', + }, + { + internalType: 'uint128', + name: 'balance', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + internalType: 'uint256', + name: 'rewardRate', + type: 'uint256', + }, + ], + name: 'boostedRewardRate', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + ], + name: 'boostees', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'boosts', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'cancelBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint32', + name: 'pos', + type: 'uint32', + }, + ], + name: 'checkpoints', + outputs: [ + { + components: [ + { + internalType: 'uint48', + name: '_key', + type: 'uint48', + }, + { + internalType: 'uint208', + name: '_value', + type: 'uint208', + }, + ], + internalType: 'struct Checkpoints.Checkpoint208', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'clock', + outputs: [ + { + internalType: 'uint48', + name: '', + type: 'uint48', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + internalType: 'uint256', + name: 'rewardRate', + type: 'uint256', + }, + ], + name: 'commissionRewardRate', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + ], + name: 'commissions', + outputs: [ + { + internalType: 'uint32', + name: 'blockNumberLast', + type: 'uint32', + }, + { + internalType: 'uint224', + name: 'rate', + type: 'uint224', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'decimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'delegatee', + type: 'address', + }, + ], + name: 'delegate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'delegatee', + type: 'address', + }, + { + internalType: 'uint256', + name: 'nonce', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'expiry', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + name: 'delegateBySig', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'delegates', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'dropBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'eip712Domain', + outputs: [ + { + internalType: 'bytes1', + name: 'fields', + type: 'bytes1', + }, + { + internalType: 'string', + name: 'name', + type: 'string', + }, + { + internalType: 'string', + name: 'version', + type: 'string', + }, + { + internalType: 'uint256', + name: 'chainId', + type: 'uint256', + }, + { + internalType: 'address', + name: 'verifyingContract', + type: 'address', + }, + { + internalType: 'bytes32', + name: 'salt', + type: 'bytes32', + }, + { + internalType: 'uint256[]', + name: 'extensions', + type: 'uint256[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'timepoint', + type: 'uint256', + }, + ], + name: 'getPastTotalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint256', + name: 'timepoint', + type: 'uint256', + }, + ], + name: 'getPastVotes', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'getVotes', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + ], + name: 'isWhitelistedSender', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'distributor', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'mint', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'minter', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'nonces', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'numCheckpoints', + outputs: [ + { + internalType: 'uint32', + name: '', + type: 'uint32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + internalType: 'uint128', + name: 'amount', + type: 'uint128', + }, + ], + name: 'queueBoost', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'queuedBoost', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'redeem', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_beraChef', + type: 'address', + }, + ], + name: 'setBeraChef', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'validator', + type: 'address', + }, + { + internalType: 'uint256', + name: 'rate', + type: 'uint256', + }, + ], + name: 'setCommission', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_minter', + type: 'address', + }, + ], + name: 'setMinter', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_staker', + type: 'address', + }, + ], + name: 'setStaker', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'staker', + outputs: [ + { + internalType: 'contract BGTStaker', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'totalBoosts', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'unboostedBalanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'whitelistSender', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as const; diff --git a/src/berrachain/constants/errors.js b/src/berrachain/constants/errors.js new file mode 100644 index 0000000..59c187a --- /dev/null +++ b/src/berrachain/constants/errors.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ORIGINAL_ERROR_MESSAGES = exports.ERROR_MESSAGES = void 0; +exports.ERROR_MESSAGES = { + NETWORK_ERR: 'Invalid network', + ADDRESS_FORMAT_ERROR: 'Invalid Ethereum address format', +}; +exports.ORIGINAL_ERROR_MESSAGES = {}; diff --git a/src/berrachain/constants/errors.ts b/src/berrachain/constants/errors.ts new file mode 100644 index 0000000..5540bd5 --- /dev/null +++ b/src/berrachain/constants/errors.ts @@ -0,0 +1,16 @@ +export const ERROR_MESSAGES = { + NETWORK_ERR: 'Invalid network', + + ADDRESS_FORMAT_ERROR: 'Invalid Berrachain address format', + BALANCE_ERROR: 'An error occurred while getting the balance', + BOOSTED_ERROR: 'An error occurred while getting the boosted balance', + BOOSTS_ERROR: 'An error occurred while getting all boosts', + BOOST_QUEUE_ERROR: 'An error occurred while getting boost queue', + + ACTIVATE_BOOST_ERROR: 'An error occurred while making boost tx data', + CANCEL_BOOST_ERROR: 'An error occurred while making cancel boost tx data', + DROP_BOOST_ERROR: 'An error occurred while making drop boost tx data', + BOOST_ERROR: 'An error occurred while making boost tx data', +}; + +export const ORIGINAL_ERROR_MESSAGES = {}; diff --git a/src/berrachain/constants/index.js b/src/berrachain/constants/index.js new file mode 100644 index 0000000..6ae51db --- /dev/null +++ b/src/berrachain/constants/index.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ETH_GAS_RESERVE = exports.TESTNET_BGT_CONTRACT_ADDRESS = exports.TESTNET_VALIDATOR = void 0; +exports.TESTNET_VALIDATOR = '0x6f06dD615817886E8e1c3Cb837BF69F94e903472'; +exports.TESTNET_BGT_CONTRACT_ADDRESS = '0x8288Ab28D6196cA4E89269B8644A146E493E23B3'; +exports.ETH_GAS_RESERVE = 220000; diff --git a/src/berrachain/constants/index.ts b/src/berrachain/constants/index.ts new file mode 100644 index 0000000..ecc6d92 --- /dev/null +++ b/src/berrachain/constants/index.ts @@ -0,0 +1,6 @@ +export const BERA_TESTNET_VALIDATOR = + '0x6f06dD615817886E8e1c3Cb837BF69F94e903472'; +export const BERA_TESTNET_BGT_CONTRACT_ADDRESS = + '0xbda130737bdd9618301681329bf2e46a016ff9ad'; + +export const BERA_GAS_RESERVE = 220000; diff --git a/src/berrachain/index.js b/src/berrachain/index.js new file mode 100644 index 0000000..33c11bb --- /dev/null +++ b/src/berrachain/index.js @@ -0,0 +1,115 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); + return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Berrachain = void 0; +var utils_1 = require("../utils"); +var web3_1 = require("web3"); +var web3_2 = require("web3"); +var bgt_1 = require("./bgt"); +var constants_1 = require("./constants"); +var errors_1 = require("./constants/errors"); +var Berrachain = /** @class */ (function (_super) { + __extends(Berrachain, _super); + function Berrachain(network, rpc) { + var _this = _super.call(this) || this; + _this.ERROR_MESSAGES = errors_1.ERROR_MESSAGES; + _this.ORIGINAL_ERROR_MESSAGES = errors_1.ORIGINAL_ERROR_MESSAGES; + switch (network) { + case 'testnet': + _this.validator = constants_1.TESTNET_VALIDATOR; + _this.btgAddress = constants_1.TESTNET_BGT_CONTRACT_ADDRESS; + break; + default: + throw _this.throwError('NETWORK_ERROR'); + } + var httpProvider = new web3_2.HttpProvider(rpc); + _this.web3 = new web3_1.default(httpProvider); + console.log(_this.web3); + _this.btg = new _this.web3.eth.Contract(bgt_1.BGT_ABI, _this.btgAddress); + return _this; + } + Berrachain.prototype.boost = function (address, amount) { + return __awaiter(this, void 0, void 0, function () { + var amountWei, gasConsumption; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this.isAddress(address)) { + this.throwError('ADDRESS_FORMAT_ERROR'); + } + amountWei = this.web3.utils.toWei(amount, 'ether'); + return [4 /*yield*/, this.btg.methods + .queueBoost(this.validator, amount) + .estimateGas({ from: address })]; + case 1: + gasConsumption = _a.sent(); + return [2 /*return*/, { + from: address, + to: this.btgAddress, + value: Number(amountWei), + gasLimit: this.calculateGasLimit(gasConsumption), + data: this.btg.methods.queueBoost(address, amount).encodeABI(), + }]; + } + }); + }); + }; + Berrachain.prototype.calculateGasLimit = function (gasConsumption) { + return Number(gasConsumption) + constants_1.ETH_GAS_RESERVE; + }; + Berrachain.prototype.isAddress = function (address) { + return /^(0x)?([0-9a-f]{40})$/.test(address.toLowerCase()); + }; + return Berrachain; +}(utils_1.Blockchain)); +exports.Berrachain = Berrachain; diff --git a/src/berrachain/index.ts b/src/berrachain/index.ts new file mode 100644 index 0000000..2a901c9 --- /dev/null +++ b/src/berrachain/index.ts @@ -0,0 +1,281 @@ +import { Blockchain } from '../utils'; +import { Network, Transaction } from './types'; +import Web3 from 'web3'; +import { HttpProvider } from 'web3'; +import type { Contract } from 'web3'; +import { BGT_ABI } from './bgt'; +import { + BERA_GAS_RESERVE, + BERA_TESTNET_BGT_CONTRACT_ADDRESS, + BERA_TESTNET_VALIDATOR, +} from './constants'; + +import { ERROR_MESSAGES, ORIGINAL_ERROR_MESSAGES } from './constants/errors'; + +/** + * The `Berrachain` class extends the `Blockchain` class and provides methods for interacting with the Berrachain network. + * + * It allows you to select a network, initialize it, and retrieve the balance of the contract. + * + * @property {string} validator - The address of the validator. + * @property {Web3} web3 - The Web3 instance used for interacting with the Ethereum network. + * @property {string} btgAddress - The address of the BTG contract. + * @property {Contract} btg - The BTG contract instance. + * @property ERROR_MESSAGES - The error messages for the Berrachain class. + * @property ORIGINAL_ERROR_MESSAGES - The original error messages for the Berrachain class. + * + */ +export class Berrachain extends Blockchain { + private validator: string; + private web3!: Web3; + private readonly btgAddress: string; + private btg!: Contract; + + protected ERROR_MESSAGES = ERROR_MESSAGES; + protected ORIGINAL_ERROR_MESSAGES = ORIGINAL_ERROR_MESSAGES; + + constructor(network: Network, rpc: string) { + super(); + switch (network) { + case 'testnet': + this.validator = BERA_TESTNET_VALIDATOR; + this.btgAddress = BERA_TESTNET_BGT_CONTRACT_ADDRESS; + break; + default: + throw this.throwError('NETWORK_ERROR'); + } + const httpProvider = new HttpProvider(rpc); + this.web3 = new Web3(httpProvider); + this.btg = new this.web3.eth.Contract(BGT_ABI, this.btgAddress); + } + + /** + * Retrieves the balance of the user by address + * + * @param address - The staker address + * @returns A Promise that resolves to the balance. + * + * @throws Will throw an error if the contract call fails. + */ + public async balanceOf(address: string): Promise { + try { + return await this.btg.methods.balanceOf(address).call(); + } catch (error) { + throw this.handleError('BALANCE_ERROR', error); + } + } + + /** + * Retrieves the boosted stake of the user by address + * + * @param address - The staker address + * @returns A Promise that resolves to the boosted stake. + * + * @throws Will throw an error if the contract call fails. + */ + public async boosted(address: string): Promise { + try { + return await this.btg.methods.boosted(this.validator, address).call(); + } catch (error) { + throw this.handleError('BOOSTED_ERROR', error); + } + } + + /** + * Retrieves all uses boosts by address + * + * @param address - The staker address + * @returns A Promise that resolves to the ball user's boosts. + * + * @throws Will throw an error if the contract call fails. + */ + public async boosts(address: string): Promise { + try { + return await this.btg.methods.boosts(address).call(); + } catch (error) { + throw this.handleError('BOOSTS_ERROR', error); + } + } + + /** + * Retrieves info about user's boost queue by address + * + * @param address - The staker address + * @returns A Promise that resolves to the balance in queue. + * + * @throws Will throw an error if the contract call fails. + */ + public async boostedQueue( + address: string, + ): Promise<{ lastBlock: number; balance: string }> { + try { + const result = await this.btg.methods + .boostedQueue(address, this.validator) + .call(); + + return { + lastBlock: Number(result[0]), + balance: result[1].toString(), + }; + } catch (error) { + throw this.handleError('BOOST_QUEUE_ERROR', error); + } + } + + /** + * Creates a transaction data for boost activation + * + * @param address - The staker address + * @returns A Promise that resolves to the transaction data + * + * @throws Will throw an error if the contract call fails. + */ + public async activateBoost(address: string): Promise { + try { + const gasConsumption = await this.btg.methods + .activateBoost(this.validator) + .estimateGas({ from: address }); + + return { + from: address, + to: this.btgAddress, + value: 0, + gasLimit: this.calculateGasLimit(gasConsumption), + data: this.btg.methods.activateBoost(this.validator).encodeABI(), + }; + } catch (error) { + throw this.handleError('ACTIVATE_BOOST_ERROR', error); + } + } + + /** + * Creates a transaction data for canceling boost queue + * + * @param address - The staker address + * @param amount - The amount of boost + * @returns A Promise that resolves to the transaction data + * + * @throws Will throw an error if the contract call fails. + */ + public async cancelBoost( + address: string, + amount: string, + ): Promise { + try { + if (!this.isAddress(address)) { + this.throwError('ADDRESS_FORMAT_ERROR'); + } + + const amountWei = this.web3.utils.toWei(amount, 'ether'); + + const gasConsumption = await this.btg.methods + .cancelBoost(this.validator, amountWei) + .estimateGas({ from: address }); + + return { + from: address, + to: this.btgAddress, + value: 0, + gasLimit: this.calculateGasLimit(gasConsumption), + data: this.btg.methods + .cancelBoost(this.validator, amountWei) + .encodeABI(), + }; + } catch (error) { + throw this.handleError('CANCEL_BOOST_ERROR', error); + } + } + + /** + * Creates a transaction data for drop boost (unstake) + * + * @param address - The staker address + * @param amount - The amount of boost + * @returns A Promise that resolves to the transaction data + * + * @throws Will throw an error if the contract call fails. + */ + public async dropBoost( + address: string, + amount: string, + ): Promise { + try { + if (!this.isAddress(address)) { + this.throwError('ADDRESS_FORMAT_ERROR'); + } + + const amountWei = this.web3.utils.toWei(amount, 'ether'); + + const gasConsumption = await this.btg.methods + .dropBoost(this.validator, amountWei) + .estimateGas({ from: address }); + + return { + from: address, + to: this.btgAddress, + value: 0, + gasLimit: this.calculateGasLimit(gasConsumption), + data: this.btg.methods.dropBoost(this.validator, amountWei).encodeABI(), + }; + } catch (error) { + throw this.handleError('DROP_BOOST_ERROR', error); + } + } + + /** + * Creates a transaction data for boost (staking) + * + * @param address - The staker address + * @param amount - The amount of boost + * @returns A Promise that resolves to the transaction data + * + * @throws Will throw an error if the contract call fails. + */ + public async boost(address: string, amount: string): Promise { + try { + if (!this.isAddress(address)) { + this.throwError('ADDRESS_FORMAT_ERROR'); + } + + const amountWei = this.web3.utils.toWei(amount, 'ether'); + + const gasConsumption = await this.btg.methods + .queueBoost(this.validator, amountWei) + .estimateGas({ from: address }); + + return { + from: address, + to: this.btgAddress, + value: 0, + gasLimit: this.calculateGasLimit(gasConsumption), + data: this.btg.methods + .queueBoost(this.validator, amountWei) + .encodeABI(), + }; + } catch (error) { + throw this.handleError('BOOST_ERROR', error); + } + } + + /** + * Calculates the gas limit by adding a predefined BERA_GAS_RESERVE to the given gas consumption. + * + * @param gasConsumption - The amount of gas consumed. + * + * @returns The calculated gas limit as a number. + */ + private calculateGasLimit(gasConsumption: bigint): number { + return Number(gasConsumption) + BERA_GAS_RESERVE; + } + + /** + * Checks if a given address has the basic requirements of an Berrachain address format. + * + * @param address - The Berrachain address to validate. + * + * @returns `true` if the address meets basic requirements, otherwise `false`. + */ + private isAddress(address: string): boolean { + return /^(0x)?([0-9a-f]{40})$/.test(address.toLowerCase()); + } +} diff --git a/src/berrachain/types/index.js b/src/berrachain/types/index.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/src/berrachain/types/index.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/src/berrachain/types/index.ts b/src/berrachain/types/index.ts new file mode 100644 index 0000000..b8c6dc3 --- /dev/null +++ b/src/berrachain/types/index.ts @@ -0,0 +1,9 @@ +export type Network = 'testnet'; + +export type Transaction = { + from: string; + to: string; + value: number; + gasLimit: number; + data: string; +}; diff --git a/src/ethereum/__tests__/index.ts b/src/ethereum/__tests__/index.ts index c238d87..4d95856 100644 --- a/src/ethereum/__tests__/index.ts +++ b/src/ethereum/__tests__/index.ts @@ -5,8 +5,6 @@ import { // claimWithdrawRequestSuccessFixture, selectNetworErrorkFixture, selectNetworkSuccessFixture, - stakeErrorFixture, - stakeSuccessFixture, unstakeErrorFixture, unstakePendingErrorFixture, unstakePendingSuccessFixture, @@ -137,33 +135,33 @@ describe('claimWithdrawRequest', () => { ); }); -describe('stake', () => { - stakeSuccessFixture.forEach(({ description, args, result }) => { - it(description, async () => { - const ethereum = new Ethereum(args.network as EthNetworkType); - - ethereum.contractPool.methods.stake(args.source).estimateGas = jest - .fn() - .mockResolvedValue(result.mockGasConsumption); - - const tx = await ethereum.stake(args.address, args.amount, args.source); - const { gasLimit, ...rest } = tx; - - expect(gasLimit).toBeGreaterThan(0); - expect(rest).toEqual(result.expectedTx); - }); - }); - - stakeErrorFixture.forEach(({ description, args, error }) => { - it(description, async () => { - const ethereum = new Ethereum(args.network as EthNetworkType); - - await expect( - ethereum.stake(args.address, args.amount as string, args.source), - ).rejects.toThrow(error); - }); - }); -}); +// describe('stake', () => { +// stakeSuccessFixture.forEach(({ description, args, result }) => { +// it(description, async () => { +// const ethereum = new Ethereum(args.network as EthNetworkType); +// +// ethereum.contractPool.methods.stake(args.source).estimateGas = jest +// .fn() +// .mockResolvedValue(result.mockGasConsumption); +// +// const tx = await ethereum.stake(args.address, args.amount, args.source); +// const { gasLimit, ...rest } = tx; +// +// expect(gasLimit).toBeGreaterThan(0); +// expect(rest).toEqual(result.expectedTx); +// }); +// }); +// +// stakeErrorFixture.forEach(({ description, args, error }) => { +// it(description, async () => { +// const ethereum = new Ethereum(args.network as EthNetworkType); +// +// await expect( +// ethereum.stake(args.address, args.amount as string, args.source), +// ).rejects.toThrow(error); +// }); +// }); +// }); describe('unstake', () => { unstakeSuccessFixture.forEach( diff --git a/src/index.ts b/src/index.ts index 79ce0a0..7337da8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from './ethereum'; export * from './solana'; +export * from './berrachain'; export * from './solana/stakeAccount'; export * from './utils'; @@ -7,6 +8,8 @@ export * from './utils/api'; export * from './ethereum/constants'; export * from './solana/constants'; +export * from './berrachain/constants'; export * from './ethereum/types'; export * from './solana/types'; +export * from './berrachain/types'; diff --git a/src/utils/constants/errors.js b/src/utils/constants/errors.js new file mode 100644 index 0000000..4fcd36d --- /dev/null +++ b/src/utils/constants/errors.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.COMMON_ERROR_MESSAGES = void 0; +exports.COMMON_ERROR_MESSAGES = { + UNKNOWN_ERROR: 'An unknown error occurred', + TOKEN_ERROR: 'Please create or use correct token', +}; diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..b505dc4 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,139 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Blockchain = exports.WalletSDKError = void 0; +var errors_1 = require("./constants/errors"); +/** + * `WalletSDKError` is a custom error class that extends the built-in `Error` class. + * It provides additional properties for error handling within the Wallet SDK. + * + * @remarks + * This class is needed to provide additional context for errors, such as a code + * and the original error, if any. + * + * @public + * + * @param message - The error message. + * @param code - A string representing the error code. + * @param originalError - The original error that caused this error, if any. + */ +var WalletSDKError = /** @class */ (function (_super) { + __extends(WalletSDKError, _super); + function WalletSDKError(message, code, originalError) { + var _newTarget = this.constructor; + var _this = _super.call(this, message) || this; + _this.code = code; + _this.originalError = originalError; + // This line is needed to restore the correct prototype chain. + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return WalletSDKError; +}(Error)); +exports.WalletSDKError = WalletSDKError; +/** + * `Blockchain` is an abstract class that provides a structure for blockchain-specific classes. + * It includes methods for error handling and throwing errors. + * + * @remarks + * This class should be extended by classes that implement blockchain-specific functionality. + * The extending classes should provide their own `ERROR_MESSAGES` and `ORIGINAL_ERROR_MESSAGES`. + * + * @property ERROR_MESSAGES - An object that maps error codes to error messages. + * @property ORIGINAL_ERROR_MESSAGES - An object that maps original error messages to user-friendly error messages. + * + * + * **/ +var Blockchain = /** @class */ (function () { + function Blockchain() { + } + /** + * Handles errors that occur within the Ethereum class. + * + * @param {keyof typeof ERROR_MESSAGES} code - The error code associated with the error. + * @param {Error | WalletSDKError | unknown} originalError - The original error that was thrown. + * + * If the original error is an instance of WalletSDKError, it is thrown as is. + * If the original error is an instance of the built-in Error class, a new WalletSDKError is thrown with the original error as the cause. + * If the original error is not an instance of WalletSDKError or Error, a new WalletSDKError is thrown with a generic message and code. + */ + Blockchain.prototype.handleError = function (code, originalError) { + var _a; + var message = this.ERROR_MESSAGES[code]; + // If originalError is an instance of WalletSDKError, or if message or code is not defined, + // throw the originalError + if (originalError instanceof WalletSDKError || !message || !code) { + throw originalError; + } + // If originalError is an instance of Error + if (originalError instanceof Error) { + // Find the first entry in ORIGINAL_ERROR_MESSAGES where the key is included in originalError.message + // If such an entry is found, newMessage will be the value of that entry + var newMessage = (_a = Object.entries(this.ORIGINAL_ERROR_MESSAGES).find(function (_a) { + var originalMessage = _a[0]; + return originalError.message.includes(originalMessage); + })) === null || _a === void 0 ? void 0 : _a[1]; + var errorMessage = newMessage || + this.ERROR_MESSAGES[code] || + errors_1.COMMON_ERROR_MESSAGES['UNKNOWN_ERROR']; + throw new WalletSDKError(errorMessage, String(code), originalError); + } + throw new WalletSDKError(errors_1.COMMON_ERROR_MESSAGES['UNKNOWN_ERROR'], 'UNKNOWN_ERROR'); + }; + /** + * Throws a WalletSDKError with a specified error code and message. + * + * @param {keyof typeof ERROR_MESSAGES} code - The error code associated with the error. + * @param {...string[]} values - The values to be inserted into the error message. + * + * The method retrieves the error message template associated with the provided code from the ERROR_MESSAGES object. + * It then replaces placeholders in the message template with provided values and throws a WalletSDKError with the final message and the provided code. + */ + Blockchain.prototype.throwError = function (code) { + var values = []; + for (var _i = 1; _i < arguments.length; _i++) { + values[_i - 1] = arguments[_i]; + } + var message = this.ERROR_MESSAGES[code]; + values.forEach(function (value, index) { + message = message === null || message === void 0 ? void 0 : message.replace("{".concat(index, "}"), value); + }); + if (!message) { + throw new WalletSDKError(errors_1.COMMON_ERROR_MESSAGES['UNKNOWN_ERROR'], 'UNKNOWN_ERROR'); + } + throw new WalletSDKError(message, String(code)); + }; + /** + * Check if the URL is valid + * + * @param {string} url - URL + * @returns a bool type result. + * + */ + Blockchain.prototype.isValidURL = function (url) { + var urlClass; + try { + urlClass = new URL(url); + } + catch (_) { + return false; + } + return urlClass.protocol === 'http:' || urlClass.protocol === 'https:'; + }; + return Blockchain; +}()); +exports.Blockchain = Blockchain; From c170e38a9f0e6c9927a0d3a869733a11164de0e4 Mon Sep 17 00:00:00 2001 From: Vadym Mozharivsky Date: Thu, 12 Dec 2024 11:15:38 +0200 Subject: [PATCH 2/2] remove tmp files --- src/berrachain/bgt.js | 2021 ---------------------------- src/berrachain/constants/errors.js | 8 - src/berrachain/constants/index.js | 6 - src/berrachain/index.js | 115 -- src/berrachain/types/index.js | 2 - src/ethereum/__tests__/index.ts | 56 +- src/utils/constants/errors.js | 7 - src/utils/index.js | 139 -- 8 files changed, 29 insertions(+), 2325 deletions(-) delete mode 100644 src/berrachain/bgt.js delete mode 100644 src/berrachain/constants/errors.js delete mode 100644 src/berrachain/constants/index.js delete mode 100644 src/berrachain/index.js delete mode 100644 src/berrachain/types/index.js delete mode 100644 src/utils/constants/errors.js delete mode 100644 src/utils/index.js diff --git a/src/berrachain/bgt.js b/src/berrachain/bgt.js deleted file mode 100644 index 5297648..0000000 --- a/src/berrachain/bgt.js +++ /dev/null @@ -1,2021 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.BGT_ABI = void 0; -exports.BGT_ABI = [ - { - inputs: [], - name: 'AlreadyInitialized', - type: 'error', - }, - { - inputs: [], - name: 'AmountLessThanMinIncentiveRate', - type: 'error', - }, - { - inputs: [], - name: 'CannotRecoverIncentiveToken', - type: 'error', - }, - { - inputs: [], - name: 'CannotRecoverRewardToken', - type: 'error', - }, - { - inputs: [], - name: 'CannotRecoverStakingToken', - type: 'error', - }, - { - inputs: [], - name: 'CheckpointUnorderedInsertion', - type: 'error', - }, - { - inputs: [], - name: 'DepositNotMultipleOfGwei', - type: 'error', - }, - { - inputs: [], - name: 'DepositValueTooHigh', - type: 'error', - }, - { - inputs: [], - name: 'DonateAmountLessThanPayoutAmount', - type: 'error', - }, - { - inputs: [], - name: 'ECDSAInvalidSignature', - type: 'error', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'length', - type: 'uint256', - }, - ], - name: 'ECDSAInvalidSignatureLength', - type: 'error', - }, - { - inputs: [ - { - internalType: 'bytes32', - name: 's', - type: 'bytes32', - }, - ], - name: 'ECDSAInvalidSignatureS', - type: 'error', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'increasedSupply', - type: 'uint256', - }, - { - internalType: 'uint256', - name: 'cap', - type: 'uint256', - }, - ], - name: 'ERC20ExceededSafeSupply', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'spender', - type: 'address', - }, - { - internalType: 'uint256', - name: 'allowance', - type: 'uint256', - }, - { - internalType: 'uint256', - name: 'needed', - type: 'uint256', - }, - ], - name: 'ERC20InsufficientAllowance', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'sender', - type: 'address', - }, - { - internalType: 'uint256', - name: 'balance', - type: 'uint256', - }, - { - internalType: 'uint256', - name: 'needed', - type: 'uint256', - }, - ], - name: 'ERC20InsufficientBalance', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'approver', - type: 'address', - }, - ], - name: 'ERC20InvalidApprover', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'receiver', - type: 'address', - }, - ], - name: 'ERC20InvalidReceiver', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'sender', - type: 'address', - }, - ], - name: 'ERC20InvalidSender', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'spender', - type: 'address', - }, - ], - name: 'ERC20InvalidSpender', - type: 'error', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'timepoint', - type: 'uint256', - }, - { - internalType: 'uint48', - name: 'clock', - type: 'uint48', - }, - ], - name: 'ERC5805FutureLookup', - type: 'error', - }, - { - inputs: [], - name: 'ERC6372InconsistentClock', - type: 'error', - }, - { - inputs: [], - name: 'IncentiveRateTooHigh', - type: 'error', - }, - { - inputs: [], - name: 'IndexOutOfRange', - type: 'error', - }, - { - inputs: [], - name: 'InsolventReward', - type: 'error', - }, - { - inputs: [], - name: 'InsufficientDelegateStake', - type: 'error', - }, - { - inputs: [], - name: 'InsufficientDeposit', - type: 'error', - }, - { - inputs: [], - name: 'InsufficientSelfStake', - type: 'error', - }, - { - inputs: [], - name: 'InsufficientStake', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - { - internalType: 'uint256', - name: 'currentNonce', - type: 'uint256', - }, - ], - name: 'InvalidAccountNonce', - type: 'error', - }, - { - inputs: [], - name: 'InvalidActivateBoostDelay', - type: 'error', - }, - { - inputs: [], - name: 'InvalidBaseRate', - type: 'error', - }, - { - inputs: [], - name: 'InvalidBoostMultiplier', - type: 'error', - }, - { - inputs: [], - name: 'InvalidCredentialsLength', - type: 'error', - }, - { - inputs: [], - name: 'InvalidDropBoostDelay', - type: 'error', - }, - { - inputs: [], - name: 'InvalidInitialization', - type: 'error', - }, - { - inputs: [], - name: 'InvalidMaxIncentiveTokensCount', - type: 'error', - }, - { - inputs: [], - name: 'InvalidMinBoostedRewardRate', - type: 'error', - }, - { - inputs: [], - name: 'InvalidProof', - type: 'error', - }, - { - inputs: [], - name: 'InvalidPubKeyLength', - type: 'error', - }, - { - inputs: [], - name: 'InvalidRewardAllocationWeights', - type: 'error', - }, - { - inputs: [], - name: 'InvalidRewardConvexity', - type: 'error', - }, - { - inputs: [], - name: 'InvalidRewardRate', - type: 'error', - }, - { - inputs: [], - name: 'InvalidRewardVaultAddress', - type: 'error', - }, - { - inputs: [], - name: 'InvalidSignatureLength', - type: 'error', - }, - { - inputs: [], - name: 'InvalidStartBlock', - type: 'error', - }, - { - inputs: [], - name: 'InvalidateDefaultRewardAllocation', - type: 'error', - }, - { - inputs: [], - name: 'InvariantCheckFailed', - type: 'error', - }, - { - inputs: [], - name: 'MaxNumWeightsPerRewardAllocationIsZero', - type: 'error', - }, - { - inputs: [], - name: 'MinIncentiveRateIsZero', - type: 'error', - }, - { - inputs: [], - name: 'NotAContract', - type: 'error', - }, - { - inputs: [], - name: 'NotApprovedSender', - type: 'error', - }, - { - inputs: [], - name: 'NotBGT', - type: 'error', - }, - { - inputs: [], - name: 'NotBlockRewardController', - type: 'error', - }, - { - inputs: [], - name: 'NotDelegate', - type: 'error', - }, - { - inputs: [], - name: 'NotDistributor', - type: 'error', - }, - { - inputs: [], - name: 'NotEnoughBalance', - type: 'error', - }, - { - inputs: [], - name: 'NotEnoughBoostedBalance', - type: 'error', - }, - { - inputs: [], - name: 'NotEnoughTime', - type: 'error', - }, - { - inputs: [], - name: 'NotFactoryVault', - type: 'error', - }, - { - inputs: [], - name: 'NotFeeCollector', - type: 'error', - }, - { - inputs: [], - name: 'NotGovernance', - type: 'error', - }, - { - inputs: [], - name: 'NotIncentiveManager', - type: 'error', - }, - { - inputs: [], - name: 'NotInitializing', - type: 'error', - }, - { - inputs: [], - name: 'NotNewOperator', - type: 'error', - }, - { - inputs: [], - name: 'NotOperator', - type: 'error', - }, - { - inputs: [], - name: 'NotRootFollower', - type: 'error', - }, - { - inputs: [], - name: 'NotWhitelistedVault', - type: 'error', - }, - { - inputs: [], - name: 'OperatorAlreadySet', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - ], - name: 'OwnableInvalidOwner', - type: 'error', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'OwnableUnauthorizedAccount', - type: 'error', - }, - { - inputs: [], - name: 'PayoutAmountIsZero', - type: 'error', - }, - { - inputs: [], - name: 'RewardAllocationAlreadyQueued', - type: 'error', - }, - { - inputs: [], - name: 'RewardAllocationBlockDelayTooLarge', - type: 'error', - }, - { - inputs: [], - name: 'RewardCycleNotEnded', - type: 'error', - }, - { - inputs: [], - name: 'RewardsDurationIsZero', - type: 'error', - }, - { - inputs: [ - { - internalType: 'uint8', - name: 'bits', - type: 'uint8', - }, - { - internalType: 'uint256', - name: 'value', - type: 'uint256', - }, - ], - name: 'SafeCastOverflowedUintDowncast', - type: 'error', - }, - { - inputs: [], - name: 'StakeAmountIsZero', - type: 'error', - }, - { - inputs: [], - name: 'TimestampAlreadyProcessed', - type: 'error', - }, - { - inputs: [], - name: 'TokenAlreadyWhitelistedOrLimitReached', - type: 'error', - }, - { - inputs: [], - name: 'TokenNotWhitelisted', - type: 'error', - }, - { - inputs: [], - name: 'TooManyWeights', - type: 'error', - }, - { - inputs: [], - name: 'TotalSupplyOverflow', - type: 'error', - }, - { - inputs: [], - name: 'VaultAlreadyExists', - type: 'error', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'expiry', - type: 'uint256', - }, - ], - name: 'VotesExpiredSignature', - type: 'error', - }, - { - inputs: [], - name: 'WithdrawAmountIsZero', - type: 'error', - }, - { - inputs: [], - name: 'ZeroAddress', - type: 'error', - }, - { - inputs: [], - name: 'ZeroOperatorOnFirstDeposit', - type: 'error', - }, - { - inputs: [], - name: 'ZeroPercentageWeight', - type: 'error', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'sender', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'user', - type: 'address', - }, - { - indexed: true, - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - indexed: false, - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'ActivateBoost', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: 'uint32', - name: 'newDelay', - type: 'uint32', - }, - ], - name: 'ActivateBoostDelayChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'owner', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'spender', - type: 'address', - }, - { - indexed: false, - internalType: 'uint256', - name: 'value', - type: 'uint256', - }, - ], - name: 'Approval', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'previous', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'current', - type: 'address', - }, - ], - name: 'BeaconDepositContractChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'sender', - type: 'address', - }, - { - indexed: true, - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - indexed: false, - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'CancelBoost', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'user', - type: 'address', - }, - { - indexed: true, - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - indexed: false, - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'CancelDropBoost', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'delegator', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'fromDelegate', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'toDelegate', - type: 'address', - }, - ], - name: 'DelegateChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'delegate', - type: 'address', - }, - { - indexed: false, - internalType: 'uint256', - name: 'previousVotes', - type: 'uint256', - }, - { - indexed: false, - internalType: 'uint256', - name: 'newVotes', - type: 'uint256', - }, - ], - name: 'DelegateVotesChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'sender', - type: 'address', - }, - { - indexed: true, - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - indexed: false, - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'DropBoost', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: 'uint32', - name: 'newDelay', - type: 'uint32', - }, - ], - name: 'DropBoostDelayChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [], - name: 'EIP712DomainChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: 'uint64', - name: 'version', - type: 'uint64', - }, - ], - name: 'Initialized', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'previous', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'current', - type: 'address', - }, - ], - name: 'MinterChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'previousOwner', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'newOwner', - type: 'address', - }, - ], - name: 'OwnershipTransferred', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'sender', - type: 'address', - }, - { - indexed: true, - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - indexed: false, - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'QueueBoost', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'user', - type: 'address', - }, - { - indexed: true, - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - indexed: false, - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'QueueDropBoost', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'from', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'receiver', - type: 'address', - }, - { - indexed: false, - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'Redeem', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'sender', - type: 'address', - }, - { - indexed: false, - internalType: 'bool', - name: 'approved', - type: 'bool', - }, - ], - name: 'SenderWhitelisted', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'previous', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'current', - type: 'address', - }, - ], - name: 'StakerChanged', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'from', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'to', - type: 'address', - }, - { - indexed: false, - internalType: 'uint256', - name: 'value', - type: 'uint256', - }, - ], - name: 'Transfer', - type: 'event', - }, - { - inputs: [], - name: 'CLOCK_MODE', - outputs: [ - { - internalType: 'string', - name: '', - type: 'string', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'user', - type: 'address', - }, - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - ], - name: 'activateBoost', - outputs: [ - { - internalType: 'bool', - name: '', - type: 'bool', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [], - name: 'activateBoostDelay', - outputs: [ - { - internalType: 'uint32', - name: '', - type: 'uint32', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - { - internalType: 'address', - name: 'spender', - type: 'address', - }, - ], - name: 'allowance', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'spender', - type: 'address', - }, - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'approve', - outputs: [ - { - internalType: 'bool', - name: '', - type: 'bool', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'balanceOf', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'beaconDepositContract', - outputs: [ - { - internalType: 'contract IBeaconDeposit', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - ], - name: 'boosted', - outputs: [ - { - internalType: 'uint128', - name: '', - type: 'uint128', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - ], - name: 'boostedQueue', - outputs: [ - { - internalType: 'uint32', - name: 'blockNumberLast', - type: 'uint32', - }, - { - internalType: 'uint128', - name: 'balance', - type: 'uint128', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - ], - name: 'boostees', - outputs: [ - { - internalType: 'uint128', - name: '', - type: 'uint128', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'boosts', - outputs: [ - { - internalType: 'uint128', - name: '', - type: 'uint128', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'cancelBoost', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'cancelDropBoost', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - { - internalType: 'uint32', - name: 'pos', - type: 'uint32', - }, - ], - name: 'checkpoints', - outputs: [ - { - components: [ - { - internalType: 'uint48', - name: '_key', - type: 'uint48', - }, - { - internalType: 'uint208', - name: '_value', - type: 'uint208', - }, - ], - internalType: 'struct Checkpoints.Checkpoint208', - name: '', - type: 'tuple', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'clock', - outputs: [ - { - internalType: 'uint48', - name: '', - type: 'uint48', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'decimals', - outputs: [ - { - internalType: 'uint8', - name: '', - type: 'uint8', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'delegatee', - type: 'address', - }, - ], - name: 'delegate', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'delegatee', - type: 'address', - }, - { - internalType: 'uint256', - name: 'nonce', - type: 'uint256', - }, - { - internalType: 'uint256', - name: 'expiry', - type: 'uint256', - }, - { - internalType: 'uint8', - name: 'v', - type: 'uint8', - }, - { - internalType: 'bytes32', - name: 'r', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: 's', - type: 'bytes32', - }, - ], - name: 'delegateBySig', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'delegates', - outputs: [ - { - internalType: 'address', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'user', - type: 'address', - }, - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - ], - name: 'dropBoost', - outputs: [ - { - internalType: 'bool', - name: '', - type: 'bool', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [], - name: 'dropBoostDelay', - outputs: [ - { - internalType: 'uint32', - name: '', - type: 'uint32', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - ], - name: 'dropBoostQueue', - outputs: [ - { - internalType: 'uint32', - name: 'blockNumberLast', - type: 'uint32', - }, - { - internalType: 'uint128', - name: 'balance', - type: 'uint128', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'eip712Domain', - outputs: [ - { - internalType: 'bytes1', - name: 'fields', - type: 'bytes1', - }, - { - internalType: 'string', - name: 'name', - type: 'string', - }, - { - internalType: 'string', - name: 'version', - type: 'string', - }, - { - internalType: 'uint256', - name: 'chainId', - type: 'uint256', - }, - { - internalType: 'address', - name: 'verifyingContract', - type: 'address', - }, - { - internalType: 'bytes32', - name: 'salt', - type: 'bytes32', - }, - { - internalType: 'uint256[]', - name: 'extensions', - type: 'uint256[]', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'timepoint', - type: 'uint256', - }, - ], - name: 'getPastTotalSupply', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - { - internalType: 'uint256', - name: 'timepoint', - type: 'uint256', - }, - ], - name: 'getPastVotes', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'getVotes', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: '_owner', - type: 'address', - }, - ], - name: 'initialize', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'sender', - type: 'address', - }, - ], - name: 'isWhitelistedSender', - outputs: [ - { - internalType: 'bool', - name: '', - type: 'bool', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'distributor', - type: 'address', - }, - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'mint', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [], - name: 'minter', - outputs: [ - { - internalType: 'address', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes[]', - name: 'data', - type: 'bytes[]', - }, - ], - name: 'multicall', - outputs: [ - { - internalType: 'bytes[]', - name: '', - type: 'bytes[]', - }, - ], - stateMutability: 'payable', - type: 'function', - }, - { - inputs: [], - name: 'name', - outputs: [ - { - internalType: 'string', - name: '', - type: 'string', - }, - ], - stateMutability: 'pure', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - ], - name: 'nonces', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - ], - name: 'normalizedBoost', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'numCheckpoints', - outputs: [ - { - internalType: 'uint32', - name: '', - type: 'uint32', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'owner', - outputs: [ - { - internalType: 'address', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'queueBoost', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'bytes', - name: 'pubkey', - type: 'bytes', - }, - { - internalType: 'uint128', - name: 'amount', - type: 'uint128', - }, - ], - name: 'queueDropBoost', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'queuedBoost', - outputs: [ - { - internalType: 'uint128', - name: '', - type: 'uint128', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'receiver', - type: 'address', - }, - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'redeem', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [], - name: 'renounceOwnership', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint32', - name: '_activateBoostDelay', - type: 'uint32', - }, - ], - name: 'setActivateBoostDelay', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: '_beaconDepositContract', - type: 'address', - }, - ], - name: 'setBeaconDepositContract', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint32', - name: '_dropBoostDelay', - type: 'uint32', - }, - ], - name: 'setDropBoostDelay', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: '_minter', - type: 'address', - }, - ], - name: 'setMinter', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: '_staker', - type: 'address', - }, - ], - name: 'setStaker', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [], - name: 'staker', - outputs: [ - { - internalType: 'contract BGTStaker', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'symbol', - outputs: [ - { - internalType: 'string', - name: '', - type: 'string', - }, - ], - stateMutability: 'pure', - type: 'function', - }, - { - inputs: [], - name: 'totalBoosts', - outputs: [ - { - internalType: 'uint128', - name: '', - type: 'uint128', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'totalSupply', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'to', - type: 'address', - }, - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'transfer', - outputs: [ - { - internalType: 'bool', - name: '', - type: 'bool', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'from', - type: 'address', - }, - { - internalType: 'address', - name: 'to', - type: 'address', - }, - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'transferFrom', - outputs: [ - { - internalType: 'bool', - name: '', - type: 'bool', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'newOwner', - type: 'address', - }, - ], - name: 'transferOwnership', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'account', - type: 'address', - }, - ], - name: 'unboostedBalanceOf', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'sender', - type: 'address', - }, - { - internalType: 'bool', - name: 'approved', - type: 'bool', - }, - ], - name: 'whitelistSender', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, -]; diff --git a/src/berrachain/constants/errors.js b/src/berrachain/constants/errors.js deleted file mode 100644 index 59c187a..0000000 --- a/src/berrachain/constants/errors.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ORIGINAL_ERROR_MESSAGES = exports.ERROR_MESSAGES = void 0; -exports.ERROR_MESSAGES = { - NETWORK_ERR: 'Invalid network', - ADDRESS_FORMAT_ERROR: 'Invalid Ethereum address format', -}; -exports.ORIGINAL_ERROR_MESSAGES = {}; diff --git a/src/berrachain/constants/index.js b/src/berrachain/constants/index.js deleted file mode 100644 index 6ae51db..0000000 --- a/src/berrachain/constants/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ETH_GAS_RESERVE = exports.TESTNET_BGT_CONTRACT_ADDRESS = exports.TESTNET_VALIDATOR = void 0; -exports.TESTNET_VALIDATOR = '0x6f06dD615817886E8e1c3Cb837BF69F94e903472'; -exports.TESTNET_BGT_CONTRACT_ADDRESS = '0x8288Ab28D6196cA4E89269B8644A146E493E23B3'; -exports.ETH_GAS_RESERVE = 220000; diff --git a/src/berrachain/index.js b/src/berrachain/index.js deleted file mode 100644 index 33c11bb..0000000 --- a/src/berrachain/index.js +++ /dev/null @@ -1,115 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); - return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Berrachain = void 0; -var utils_1 = require("../utils"); -var web3_1 = require("web3"); -var web3_2 = require("web3"); -var bgt_1 = require("./bgt"); -var constants_1 = require("./constants"); -var errors_1 = require("./constants/errors"); -var Berrachain = /** @class */ (function (_super) { - __extends(Berrachain, _super); - function Berrachain(network, rpc) { - var _this = _super.call(this) || this; - _this.ERROR_MESSAGES = errors_1.ERROR_MESSAGES; - _this.ORIGINAL_ERROR_MESSAGES = errors_1.ORIGINAL_ERROR_MESSAGES; - switch (network) { - case 'testnet': - _this.validator = constants_1.TESTNET_VALIDATOR; - _this.btgAddress = constants_1.TESTNET_BGT_CONTRACT_ADDRESS; - break; - default: - throw _this.throwError('NETWORK_ERROR'); - } - var httpProvider = new web3_2.HttpProvider(rpc); - _this.web3 = new web3_1.default(httpProvider); - console.log(_this.web3); - _this.btg = new _this.web3.eth.Contract(bgt_1.BGT_ABI, _this.btgAddress); - return _this; - } - Berrachain.prototype.boost = function (address, amount) { - return __awaiter(this, void 0, void 0, function () { - var amountWei, gasConsumption; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.isAddress(address)) { - this.throwError('ADDRESS_FORMAT_ERROR'); - } - amountWei = this.web3.utils.toWei(amount, 'ether'); - return [4 /*yield*/, this.btg.methods - .queueBoost(this.validator, amount) - .estimateGas({ from: address })]; - case 1: - gasConsumption = _a.sent(); - return [2 /*return*/, { - from: address, - to: this.btgAddress, - value: Number(amountWei), - gasLimit: this.calculateGasLimit(gasConsumption), - data: this.btg.methods.queueBoost(address, amount).encodeABI(), - }]; - } - }); - }); - }; - Berrachain.prototype.calculateGasLimit = function (gasConsumption) { - return Number(gasConsumption) + constants_1.ETH_GAS_RESERVE; - }; - Berrachain.prototype.isAddress = function (address) { - return /^(0x)?([0-9a-f]{40})$/.test(address.toLowerCase()); - }; - return Berrachain; -}(utils_1.Blockchain)); -exports.Berrachain = Berrachain; diff --git a/src/berrachain/types/index.js b/src/berrachain/types/index.js deleted file mode 100644 index c8ad2e5..0000000 --- a/src/berrachain/types/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/src/ethereum/__tests__/index.ts b/src/ethereum/__tests__/index.ts index 4d95856..c238d87 100644 --- a/src/ethereum/__tests__/index.ts +++ b/src/ethereum/__tests__/index.ts @@ -5,6 +5,8 @@ import { // claimWithdrawRequestSuccessFixture, selectNetworErrorkFixture, selectNetworkSuccessFixture, + stakeErrorFixture, + stakeSuccessFixture, unstakeErrorFixture, unstakePendingErrorFixture, unstakePendingSuccessFixture, @@ -135,33 +137,33 @@ describe('claimWithdrawRequest', () => { ); }); -// describe('stake', () => { -// stakeSuccessFixture.forEach(({ description, args, result }) => { -// it(description, async () => { -// const ethereum = new Ethereum(args.network as EthNetworkType); -// -// ethereum.contractPool.methods.stake(args.source).estimateGas = jest -// .fn() -// .mockResolvedValue(result.mockGasConsumption); -// -// const tx = await ethereum.stake(args.address, args.amount, args.source); -// const { gasLimit, ...rest } = tx; -// -// expect(gasLimit).toBeGreaterThan(0); -// expect(rest).toEqual(result.expectedTx); -// }); -// }); -// -// stakeErrorFixture.forEach(({ description, args, error }) => { -// it(description, async () => { -// const ethereum = new Ethereum(args.network as EthNetworkType); -// -// await expect( -// ethereum.stake(args.address, args.amount as string, args.source), -// ).rejects.toThrow(error); -// }); -// }); -// }); +describe('stake', () => { + stakeSuccessFixture.forEach(({ description, args, result }) => { + it(description, async () => { + const ethereum = new Ethereum(args.network as EthNetworkType); + + ethereum.contractPool.methods.stake(args.source).estimateGas = jest + .fn() + .mockResolvedValue(result.mockGasConsumption); + + const tx = await ethereum.stake(args.address, args.amount, args.source); + const { gasLimit, ...rest } = tx; + + expect(gasLimit).toBeGreaterThan(0); + expect(rest).toEqual(result.expectedTx); + }); + }); + + stakeErrorFixture.forEach(({ description, args, error }) => { + it(description, async () => { + const ethereum = new Ethereum(args.network as EthNetworkType); + + await expect( + ethereum.stake(args.address, args.amount as string, args.source), + ).rejects.toThrow(error); + }); + }); +}); describe('unstake', () => { unstakeSuccessFixture.forEach( diff --git a/src/utils/constants/errors.js b/src/utils/constants/errors.js deleted file mode 100644 index 4fcd36d..0000000 --- a/src/utils/constants/errors.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.COMMON_ERROR_MESSAGES = void 0; -exports.COMMON_ERROR_MESSAGES = { - UNKNOWN_ERROR: 'An unknown error occurred', - TOKEN_ERROR: 'Please create or use correct token', -}; diff --git a/src/utils/index.js b/src/utils/index.js deleted file mode 100644 index b505dc4..0000000 --- a/src/utils/index.js +++ /dev/null @@ -1,139 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Blockchain = exports.WalletSDKError = void 0; -var errors_1 = require("./constants/errors"); -/** - * `WalletSDKError` is a custom error class that extends the built-in `Error` class. - * It provides additional properties for error handling within the Wallet SDK. - * - * @remarks - * This class is needed to provide additional context for errors, such as a code - * and the original error, if any. - * - * @public - * - * @param message - The error message. - * @param code - A string representing the error code. - * @param originalError - The original error that caused this error, if any. - */ -var WalletSDKError = /** @class */ (function (_super) { - __extends(WalletSDKError, _super); - function WalletSDKError(message, code, originalError) { - var _newTarget = this.constructor; - var _this = _super.call(this, message) || this; - _this.code = code; - _this.originalError = originalError; - // This line is needed to restore the correct prototype chain. - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return WalletSDKError; -}(Error)); -exports.WalletSDKError = WalletSDKError; -/** - * `Blockchain` is an abstract class that provides a structure for blockchain-specific classes. - * It includes methods for error handling and throwing errors. - * - * @remarks - * This class should be extended by classes that implement blockchain-specific functionality. - * The extending classes should provide their own `ERROR_MESSAGES` and `ORIGINAL_ERROR_MESSAGES`. - * - * @property ERROR_MESSAGES - An object that maps error codes to error messages. - * @property ORIGINAL_ERROR_MESSAGES - An object that maps original error messages to user-friendly error messages. - * - * - * **/ -var Blockchain = /** @class */ (function () { - function Blockchain() { - } - /** - * Handles errors that occur within the Ethereum class. - * - * @param {keyof typeof ERROR_MESSAGES} code - The error code associated with the error. - * @param {Error | WalletSDKError | unknown} originalError - The original error that was thrown. - * - * If the original error is an instance of WalletSDKError, it is thrown as is. - * If the original error is an instance of the built-in Error class, a new WalletSDKError is thrown with the original error as the cause. - * If the original error is not an instance of WalletSDKError or Error, a new WalletSDKError is thrown with a generic message and code. - */ - Blockchain.prototype.handleError = function (code, originalError) { - var _a; - var message = this.ERROR_MESSAGES[code]; - // If originalError is an instance of WalletSDKError, or if message or code is not defined, - // throw the originalError - if (originalError instanceof WalletSDKError || !message || !code) { - throw originalError; - } - // If originalError is an instance of Error - if (originalError instanceof Error) { - // Find the first entry in ORIGINAL_ERROR_MESSAGES where the key is included in originalError.message - // If such an entry is found, newMessage will be the value of that entry - var newMessage = (_a = Object.entries(this.ORIGINAL_ERROR_MESSAGES).find(function (_a) { - var originalMessage = _a[0]; - return originalError.message.includes(originalMessage); - })) === null || _a === void 0 ? void 0 : _a[1]; - var errorMessage = newMessage || - this.ERROR_MESSAGES[code] || - errors_1.COMMON_ERROR_MESSAGES['UNKNOWN_ERROR']; - throw new WalletSDKError(errorMessage, String(code), originalError); - } - throw new WalletSDKError(errors_1.COMMON_ERROR_MESSAGES['UNKNOWN_ERROR'], 'UNKNOWN_ERROR'); - }; - /** - * Throws a WalletSDKError with a specified error code and message. - * - * @param {keyof typeof ERROR_MESSAGES} code - The error code associated with the error. - * @param {...string[]} values - The values to be inserted into the error message. - * - * The method retrieves the error message template associated with the provided code from the ERROR_MESSAGES object. - * It then replaces placeholders in the message template with provided values and throws a WalletSDKError with the final message and the provided code. - */ - Blockchain.prototype.throwError = function (code) { - var values = []; - for (var _i = 1; _i < arguments.length; _i++) { - values[_i - 1] = arguments[_i]; - } - var message = this.ERROR_MESSAGES[code]; - values.forEach(function (value, index) { - message = message === null || message === void 0 ? void 0 : message.replace("{".concat(index, "}"), value); - }); - if (!message) { - throw new WalletSDKError(errors_1.COMMON_ERROR_MESSAGES['UNKNOWN_ERROR'], 'UNKNOWN_ERROR'); - } - throw new WalletSDKError(message, String(code)); - }; - /** - * Check if the URL is valid - * - * @param {string} url - URL - * @returns a bool type result. - * - */ - Blockchain.prototype.isValidURL = function (url) { - var urlClass; - try { - urlClass = new URL(url); - } - catch (_) { - return false; - } - return urlClass.protocol === 'http:' || urlClass.protocol === 'https:'; - }; - return Blockchain; -}()); -exports.Blockchain = Blockchain;