Skip to content

Commit

Permalink
feat: Changes and script
Browse files Browse the repository at this point in the history
  • Loading branch information
1marcghannam committed Feb 6, 2024
1 parent acf0a26 commit 5b981fd
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 11 deletions.
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
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 155d54
84 changes: 84 additions & 0 deletions scripts/prod/deploy-imp-contracts-2.ts
Original file line number Diff line number Diff line change
@@ -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)
})
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)
})

0 comments on commit 5b981fd

Please sign in to comment.