diff --git a/contracts/core/StakingPool.sol b/contracts/core/StakingPool.sol index acfd47f9..4e0a7b1b 100644 --- a/contracts/core/StakingPool.sol +++ b/contracts/core/StakingPool.sol @@ -77,12 +77,14 @@ contract StakingPool is StakingRewardsPool { **/ function deposit(address _account, uint256 _amount) external onlyPriorityPool { require(strategies.length > 0, "Must be > 0 strategies to stake"); - - token.safeTransferFrom(msg.sender, address(this), _amount); - depositLiquidity(); - - _mint(_account, _amount); - totalStaked += _amount; + if (_amount > 0) { + token.safeTransferFrom(msg.sender, address(this), _amount); + depositLiquidity(); + _mint(_account, _amount); + totalStaked += _amount; + } else { + depositLiquidity(); + } } /** diff --git a/contracts/core/priorityPool/PriorityPool.sol b/contracts/core/priorityPool/PriorityPool.sol index c9f70ca8..e92559b0 100644 --- a/contracts/core/priorityPool/PriorityPool.sol +++ b/contracts/core/priorityPool/PriorityPool.sol @@ -61,7 +61,7 @@ contract PriorityPool is UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeabl ); event SetPoolStatus(PoolStatus status); event SetQueueDepositParams(uint128 queueDepositMin, uint128 queueDepositMax); - event DepositQueuedTokens(uint256 amount); + event DepositTokens(uint256 unusedTokensAmount, uint256 queuedTokensAmount); error InvalidValue(); error UnauthorizedToken(); @@ -558,12 +558,14 @@ contract PriorityPool is UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeabl _depositMax - toDepositFromStakingPool ); - totalQueued = _totalQueued - toDepositFromQueue; - depositsSinceLastUpdate += toDepositFromQueue; - sharesSinceLastUpdate += stakingPool.getSharesByStake(toDepositFromQueue); stakingPool.deposit(address(this), toDepositFromQueue); - emit DepositQueuedTokens(toDepositFromQueue); + if (toDepositFromQueue != 0) { + totalQueued = _totalQueued - toDepositFromQueue; + depositsSinceLastUpdate += toDepositFromQueue; + sharesSinceLastUpdate += stakingPool.getSharesByStake(toDepositFromQueue); + } + emit DepositTokens(toDepositFromStakingPool, toDepositFromQueue); } /** diff --git a/lib/forge-std b/lib/forge-std new file mode 160000 index 00000000..155d547c --- /dev/null +++ b/lib/forge-std @@ -0,0 +1 @@ +Subproject commit 155d547c449afa8715f538d69454b83944117811 diff --git a/scripts/prod/deploy-imp-contracts-2.ts b/scripts/prod/deploy-imp-contracts-2.ts new file mode 100644 index 00000000..743ff70a --- /dev/null +++ b/scripts/prod/deploy-imp-contracts-2.ts @@ -0,0 +1,84 @@ +import { ethers, upgrades, run } from 'hardhat' +import { getContract } from '../utils/deployment' +import { StakingPool, PriorityPool, CommunityVCS } from '../../typechain-types' + +async function main() { + const stakingPool = (await getContract('LINK_StakingPool')) as StakingPool + const priorityPool = (await getContract('LINK_PriorityPool')) as PriorityPool + const communityVCS = (await getContract('LINK_CommunityVCS')) as CommunityVCS + const communityVaultAutomationFactory = await ethers.getContractFactory( + 'CommunityVaultAutomation' + ) + + const communityVCSAddress = '0xAc12290b097f6893322F5430627e472131fBC1B5' + const minRewardsTotal = ethers.utils.parseUnits('650', 18) + const minRewardsPerVault = ethers.utils.parseUnits('65', 18) + + const communityVaultAutomation = await communityVaultAutomationFactory.deploy( + communityVCSAddress, + minRewardsTotal, + minRewardsPerVault + ) + await communityVaultAutomation.deployed() + await communityVaultAutomation.deployTransaction.wait(5) + console.log('CommunityVaultAutomation deployed at:', communityVaultAutomation.address) + await verifyContract(communityVaultAutomation.address, [ + communityVCSAddress, + minRewardsTotal, + minRewardsPerVault, + ]) + + const stakingPoolImp = (await upgrades.prepareUpgrade( + stakingPool.address, + await ethers.getContractFactory('StakingPool'), + { + kind: 'uups', + unsafeAllowRenames: false, + } + )) as string + console.log('StakingPool implementation deployed at: ', stakingPoolImp) + + await verifyContract(stakingPoolImp, []) + + const priorityPoolImp = (await upgrades.prepareUpgrade( + priorityPool.address, + await ethers.getContractFactory('PriorityPool'), + { + kind: 'uups', + unsafeAllowRenames: false, + } + )) as string + console.log('PriorityPool implementation deployed at: ', priorityPoolImp) + + await verifyContract(priorityPoolImp, []) + + const communityVCSImp = (await upgrades.prepareUpgrade( + communityVCS.address, + await ethers.getContractFactory('CommunityVCS'), + { + kind: 'uups', + unsafeAllowRenames: false, + } + )) as string + console.log('CommunityVCS implementation deployed at: ', communityVCSImp) + await verifyContract(communityVCSImp, []) +} + +async function verifyContract(contractAddress: string, constructorArguments: any[]) { + try { + await run('verify:verify', { + address: contractAddress, + constructorArguments: constructorArguments, + }) + console.log(`Contract verified: ${contractAddress}`) + } catch (error: any) { + console.error(`Verification failed for ${contractAddress}: ${error.message}`) + } +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error) + process.exit(1) + }) diff --git a/scripts/prod/upgrade-contracts-2.ts b/scripts/prod/upgrade-contracts-2.ts new file mode 100644 index 00000000..4922c741 --- /dev/null +++ b/scripts/prod/upgrade-contracts-2.ts @@ -0,0 +1,73 @@ +import { ethers } from 'hardhat' +import Safe, { EthersAdapter } from '@safe-global/protocol-kit' +import SafeApiKit from '@safe-global/api-kit' +import { MetaTransactionData } from '@safe-global/safe-core-sdk-types' +import { PriorityPool, StakingPool, CommunityVCS } from '../../typechain-types' +import { getContract } from '../utils/deployment' +import { getAccounts } from '../utils/helpers' + +const multisigAddress = '0xB351EC0FEaF4B99FdFD36b484d9EC90D0422493D' + +// New implementation addresses for the contracts +const priorityPoolNewImplementation = '0xYourNewPriorityPoolAddress' +const stakingPoolNewImplementation = '0xYourNewStakingPoolAddress' +const communityVCSNewImplementation = '0xYourNewCommunityVCSAddress' + +async function main() { + const { signers } = await getAccounts() + const ethAdapter = new EthersAdapter({ + ethers, + signerOrProvider: signers[0], + }) + const safeSdk = await Safe.create({ ethAdapter, safeAddress: multisigAddress }) + const safeService = new SafeApiKit({ + txServiceUrl: 'https://safe-transaction-mainnet.safe.global', + ethAdapter, + }) + + const priorityPool = (await getContract('PriorityPool')) as PriorityPool + const stakingPool = (await getContract('StakingPool')) as StakingPool + const communityVCS = (await getContract('CommunityVCS')) as CommunityVCS + + const safeTransactionData: MetaTransactionData[] = [ + { + to: priorityPool.address, + data: + (await priorityPool.populateTransaction.upgradeTo(priorityPoolNewImplementation)).data || + '', + value: '0', + }, + { + to: stakingPool.address, + data: + (await stakingPool.populateTransaction.upgradeTo(stakingPoolNewImplementation)).data || '', + value: '0', + }, + { + to: communityVCS.address, + data: + (await communityVCS.populateTransaction.upgradeTo(communityVCSNewImplementation)).data || + '', + value: '0', + }, + ] + + const safeTransaction = await safeSdk.createTransaction({ safeTransactionData }) + const safeTxHash = await safeSdk.getTransactionHash(safeTransaction) + const senderSignature = await safeSdk.signTransactionHash(safeTxHash) + + await safeService.proposeTransaction({ + safeAddress: multisigAddress, + safeTransactionData: safeTransaction.data, + safeTxHash, + senderAddress: signers[0].address, + senderSignature: senderSignature.data, + }) +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error) + process.exit(1) + })