Skip to content

Commit

Permalink
Merge pull request #86 from stakedotlink/feature/update-event-logic
Browse files Browse the repository at this point in the history
feat: Deployment scripts and contract changes
  • Loading branch information
AnonJon authored Feb 21, 2024
2 parents 2a71ca4 + 25e099d commit 2541c5f
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
run: yarn compile

- name: Run tests
env:
ETHEREUM_RPC_URL: ${{ secrets.ETHEREUM_RPC_URL }}
run: |
yarn test
forge test --no-match-test testFork -vvv
forge test --no-match-test testFork -vvv --ffi
14 changes: 8 additions & 6 deletions contracts/core/StakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down
12 changes: 7 additions & 5 deletions contracts/core/priorityPool/PriorityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion scripts/input/1/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"CommunityVCS": "0xAc12290b097f6893322F5430627e472131fBC1B5",
"MerkleDistributor": "0xe7Dd77d408920c000C40C35c4c111318Ba8B4767"
"MerkleDistributor": "0xe7Dd77d408920c000C40C35c4c111318Ba8B4767",
"PriorityPool": "0xDdC796a66E8b83d0BcCD97dF33A6CcFBA8fd60eA",
"StakingPool": "0xb8b295df2cd735b15BE5Eb419517Aa626fc43cD5",
"Multisig": "0xB351EC0FEaF4B99FdFD36b484d9EC90D0422493D"
}
63 changes: 63 additions & 0 deletions scripts/prod/deploy-imp-contracts-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 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)
})
73 changes: 73 additions & 0 deletions scripts/prod/upgrade-contracts-2.ts
Original file line number Diff line number Diff line change
@@ -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)
})
60 changes: 60 additions & 0 deletions test/foundry/fork/scripts/Deployment.2.24.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.15;
import {StakingPool} from "../../../../contracts/core/StakingPool.sol";
import {PriorityPool} from "../../../../contracts/core/priorityPool/PriorityPool.sol";
import {CommunityVCS} from "../../../../contracts/linkStaking/CommunityVCS.sol";
import {CommunityVaultAutomation} from "../../../../contracts/linkStaking/CommunityVaultAutomation.sol";
import {BaseTest} from "../../Base.t.sol";

contract Deployment is BaseTest {
bool internal _fork = true;
StakingPool internal stakingPool;
PriorityPool internal priorityPool;
CommunityVCS internal communityVCS;
CommunityVaultAutomation internal communityVaultAutomation;
uint256 internal minRewardsTotal = 650 ether;
uint256 internal minRewardsPerVault = 65 ether;
address internal multisig;

function setUp() public {
BaseTest.init(_fork);
communityVCS = CommunityVCS(getValue("CommunityVCS"));
stakingPool = StakingPool(getValue("StakingPool"));
priorityPool = PriorityPool(getValue("PriorityPool"));
multisig = getValue("Multisig");
vm.startPrank(multisig);
communityVaultAutomation = new CommunityVaultAutomation(address(communityVCS), minRewardsTotal, minRewardsPerVault);

// upgrade CommunityVCS
CommunityVCS impl = new CommunityVCS();
communityVCS.upgradeTo(address(impl));

// upgrade StakingPool
StakingPool stakingPoolImpl = new StakingPool();
stakingPool.upgradeTo(address(stakingPoolImpl));

// upgrade PriorityPool
PriorityPool priorityPoolImpl = new PriorityPool();
priorityPool.upgradeTo(address(priorityPoolImpl));
vm.stopPrank();
}

function testFork_upgrade_successful() public {
assertEq(address(communityVCS), address(getValue("CommunityVCS")));
assertEq(address(stakingPool), getValue("StakingPool"));
assertEq(address(priorityPool), getValue("PriorityPool"));
}

function testFork_CommunityVaultAutomation_success() public {
assertEq(communityVaultAutomation.minRewardsTotal(), minRewardsTotal);
assertEq(communityVaultAutomation.minRewardsPerVault(), minRewardsPerVault);
}

function testFork_StakingPool_owner() public {
assertEq(stakingPool.priorityPool(), address(priorityPool));
}

function testFork_PriorityPool_owner() public {
assertEq(address(priorityPool.stakingPool()), address(stakingPool));
}
}
8 changes: 8 additions & 0 deletions test/foundry/utils/proxy/UUPSProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.15;

import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract UUPSProxy is ERC1967Proxy {
constructor(address _implementation, bytes memory _data) ERC1967Proxy(_implementation, _data) {}
}

0 comments on commit 2541c5f

Please sign in to comment.