Skip to content

Commit

Permalink
update precompiled staking V2
Browse files Browse the repository at this point in the history
  • Loading branch information
CheeKeat10 committed Aug 13, 2024
1 parent 4ffcd67 commit 6fb404c
Show file tree
Hide file tree
Showing 38 changed files with 4,344 additions and 648 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified contracts/.DS_Store
Binary file not shown.
65 changes: 65 additions & 0 deletions contracts/EsBAVA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract EsBAVA is Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, ERC20PausableUpgradeable, AccessControlUpgradeable, ERC20PermitUpgradeable, UUPSUpgradeable {
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(address defaultAdmin, address pauser, address minter, address upgrader)
initializer public
{
__ERC20_init("Escrowed BAVA", "esBAVA");
__ERC20Burnable_init();
__ERC20Pausable_init();
__AccessControl_init();
__ERC20Permit_init("Escrowed BAVA");
__UUPSUpgradeable_init();

_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_grantRole(PAUSER_ROLE, pauser);
_grantRole(MINTER_ROLE, minter);
_grantRole(UPGRADER_ROLE, upgrader);
}

function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}

function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}

function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
_mint(to, amount);
}

function _authorizeUpgrade(address newImplementation)
internal
onlyRole(UPGRADER_ROLE)
override
{}

// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 amount)
internal
whenNotPaused
override(ERC20Upgradeable, ERC20PausableUpgradeable)
{
super._beforeTokenTransfer(from, to, amount);
}
}
27 changes: 27 additions & 0 deletions contracts/MultiCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ contract MultiCall is
uint256 delegationReward;
}

struct ValidatorUserDelegationInfo {
string validator;
uint256 delegationAmount;
uint256 allowanceShares;
}

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
Expand Down Expand Up @@ -56,6 +62,27 @@ contract MultiCall is
}
}

/**
* @dev Get All Validator User Delegation
*/
function getAllValidatorUserDelegation(address user) external view returns (ValidatorUserDelegationInfo[] memory validatorUserDelegations) {
uint256 validatorsLength = IStakeFXVault(stFX).getValLength();

validatorUserDelegations = new ValidatorUserDelegationInfo[](validatorsLength);
for (uint256 i = 0; i < validatorsLength; i++) {
(, string memory validatorAddress) = IStakeFXVault(stFX).getValInfo(i);

(, uint256 delegationAmount) = _delegation(validatorAddress, user);
uint256 allowanceShares = _allowanceShares(validatorAddress, user, stFX);

validatorUserDelegations[i] = ValidatorUserDelegationInfo({
validator: validatorAddress,
delegationAmount: delegationAmount,
allowanceShares: allowanceShares
});
}
}

/**************************************** Only Owner Functions ****************************************/

function updateStFX(
Expand Down
9 changes: 9 additions & 0 deletions contracts/RewardDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,17 @@ contract RewardDistributor is Initializable, UUPSUpgradeable, IRewardDistributor
emit TokensPerIntervalChange(_amount);
}



/**************************************** Only Owner Functions ****************************************/

/**
* @dev Need to make sure all rewardTracker contracts fully migrate rewardToken to new rewardToken after update this contract rewardToken address
*/
function updateRewardToken(address _rewardToken) external onlyRole(OWNER_ROLE) {
rewardToken = _rewardToken;
}

function recoverToken(
address token,
uint256 amount,
Expand Down
2 changes: 1 addition & 1 deletion contracts/StakeFXVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract StakeFXVault is

VaultInfo public vaultInfo; // Vault Info
mapping(uint256 => ValInfo) public valInfo; // Validator info
mapping (address => UserInfo) public userInfo; // User info
mapping(address => UserInfo) public userInfo; // User info
mapping(string => bool) public addedValidator; // True if validator is added

struct VaultInfo {
Expand Down
Loading

0 comments on commit 6fb404c

Please sign in to comment.