Skip to content

Commit

Permalink
update sync voting power in esXai on any transfer
Browse files Browse the repository at this point in the history
fix initializer on voting
  • Loading branch information
CryptITAustria committed Jan 23, 2025
1 parent 431d571 commit e11cf78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
31 changes: 15 additions & 16 deletions infrastructure/smart-contracts/contracts/upgrades/esXai/esXai4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@ contract esXai4 is ERC20Upgradeable, ERC20BurnableUpgradeable, AccessControlUpgr
*/
function transfer(address to, uint256 amount) public override returns (bool) {
require(_whitelist.contains(msg.sender) || _whitelist.contains(to), "Transfer not allowed: address not in whitelist");

try IXaiVoting(xaiVotingAddress).onUpdateBalance(msg.sender, to, amount) {
} catch Error(string memory reason) {
emit OnTransferUpdateError(msg.sender, to, amount, reason);
} catch {
emit OnTransferUpdateError(msg.sender, to, amount, "Unknown error in onUpdateBalance");
}

return super.transfer(to, amount);
}

Expand All @@ -169,14 +161,6 @@ contract esXai4 is ERC20Upgradeable, ERC20BurnableUpgradeable, AccessControlUpgr
*/
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
require(_whitelist.contains(from) || _whitelist.contains(to), "Transfer not allowed: address not in whitelist");

try IXaiVoting(xaiVotingAddress).onUpdateBalance(from, to, amount) {
} catch Error(string memory reason) {
emit OnTransferUpdateError(from, to, amount, reason);
} catch {
emit OnTransferUpdateError(from, to, amount, "Unknown error in onUpdateBalance");
}

return super.transferFrom(from, to, amount);
}

Expand Down Expand Up @@ -400,4 +384,19 @@ contract esXai4 is ERC20Upgradeable, ERC20BurnableUpgradeable, AccessControlUpgr

return (redemptions, totalRedemptions);
}

function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
try IXaiVoting(xaiVotingAddress).onUpdateBalance(from, to, amount) {
} catch Error(string memory reason) {
emit OnTransferUpdateError(from, to, amount, reason);
} catch {
emit OnTransferUpdateError(from, to, amount, "Unknown error in onUpdateBalance");
}

super._afterTokenTransfer(from, to, amount);
}
}
11 changes: 10 additions & 1 deletion infrastructure/xai-governance-contracts/contracts/XaiVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ contract XaiVoting is Initializable, VotesUpgradeable {
_;
}

function initialize() external {
function initialize(
address _xaiAddress,
address _esXaiAddress,
address _poolFactoryAddress
) external initializer {
__EIP712_init("XaiVoting", "1");
xaiAddress = _xaiAddress;
esXaiAddress = _esXaiAddress;
poolFactoryAddress = _poolFactoryAddress;

weights[xaiAddress] = 100;
weights[esXaiAddress] = 100;
weights[poolFactoryAddress] = 100;
Expand Down

0 comments on commit e11cf78

Please sign in to comment.