// SPDX-License-Identifier: Apache-2.0 // https://docs.soliditylang.org/en/v0.8.10/style-guide.html pragma solidity 0.8.11; import "src/staking/SpiralsStakingV2.sol"; import "src/staking/migration/IMigrationToImpactVault.sol"; import "src/vaults/ImpactVault.sol"; import "src/vaults/SpiralsCeloImpactVault.sol"; /// @title SpiralsStakingMigration /// @author @douglasqian /// contract SpiralsStakingMigration is IMigrationToImpactVault, SpiralsStakingV2 { /// @notice Helper function for withdrawing the full amount staked /// for an individual staker to prepare for migration. function withdrawAllForMigration() external onlyOwner whenPaused { // Revoke as much as you can. uint256 totalRevoked; uint256 activeVotes = getActiveVotes(); if (activeVotes > 0) { revokeActive(activeVotes); totalRevoked += activeVotes; } (uint256 pendingVotes, ) = getPendingVotes(); if (pendingVotes > 0) { revokePending(pendingVotes); totalRevoked += pendingVotes; } unlock(totalRevoked); // 3 days later Celo will land in this contract. } /// @notice Pt 2 when we transfer to SpiralsCeloImpactVault. /// @param _yields values will come from subgraph function transferAssetsToImpactVault( address[] memory _addrs, ImpactVault _vault, uint256[] memory _yields ) external onlyOwner whenPaused { for (uint256 i = 0; i < _addrs.length; i++) { transferAssetsToImpactVaultForAddress( _addrs[i], _vault, _yields[i] ); } } function transferAssetsToImpactVaultForAddress( address _address, ImpactVault _vault, uint256 _yield ) public onlyOwner whenPaused { StakerInfo memory s = stakers[_address]; uint256 celoStaked = s.stakedValue + s.withdrawalValue; // withdraw everything! uint256 totalCelo = celoStaked + _yield; if (totalCelo == 0) { return; } stakers[_address].stakedValue = 0; stakers[_address].withdrawalValue = 0; stakers[_address].withdrawalTimestamp = 0; SpiralsCeloImpactVault celoVault = SpiralsCeloImpactVault( payable(address(_vault)) ); IERC20Upgradeable(getGoldToken()).approve(address(_vault), totalCelo); celoVault.depositWithYield(celoStaked, _address, _yield); emit AssetsTransferredToImpactVault( _address, celoStaked, _yield, address(_vault) ); // This event will decrease celo staked count on Spirals subgraph // Should be fine as long as value increases proportionally on // Celo impact vault. emit UserCeloUnstaked(_address, validatorGroup, celoStaked); } /// @dev Returns an Election.sol interface for interacting with the smart contract. function getGoldToken() internal view returns (IERC20Upgradeable) { address electionAddr = c_celoRegistry.getAddressForStringOrDie( "GoldToken" ); return IERC20Upgradeable(electionAddr); } }