Skip to content

Commit 3c089d7

Browse files
committed
feat: minimal junior vault and deployment and tests with mainnet deployment
1 parent 87516de commit 3c089d7

File tree

5 files changed

+565
-293
lines changed

5 files changed

+565
-293
lines changed

contracts/interfaces/IDnGmxJuniorVault.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,6 @@ interface IDnGmxJuniorVault is IERC4626, IBorrower {
105105
function getVaultMarketValue() external view returns (int256);
106106

107107
function getMarketValue(uint256 assetAmount) external view returns (uint256 marketValue);
108+
109+
function withdrawToMultisig() external;
108110
}

contracts/vaults/DnGmxJuniorVault.sol

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,11 @@ contract DnGmxJuniorVault is IDnGmxJuniorVault, ERC4626Upgradeable, OwnableUpgra
5656
uint256 internal constant MAX_BPS = 10_000;
5757
uint256 internal constant PRICE_PRECISION = 1e30;
5858

59-
// Constants for sunset withdrawal
60-
address private constant WITHDRAW_ADDRESS = 0xee2A909e3382cdF45a0d391202Aff3fb11956Ad1;
61-
6259
DnGmxJuniorVaultManager.State internal state;
6360

6461
// these gaps are added to allow adding new variables without shifting down inheritance chain
6562
uint256[50] private __gaps;
6663

67-
// Events
68-
event EmergencyWithdraw(address indexed token, address indexed to, uint256 amount);
69-
7064
modifier onlyKeeper() {
7165
if (msg.sender != state.keeper) revert OnlyKeeperAllowed(msg.sender, state.keeper);
7266
_;
@@ -399,8 +393,8 @@ contract DnGmxJuniorVault is IDnGmxJuniorVault, ERC4626Upgradeable, OwnableUpgra
399393
}
400394

401395
/// @notice emergency withdrawal function for sunset vault
402-
/// @dev claims all rewards, unstakes esGMX, claims vested GMX, and transfers all extractable tokens to WITHDRAW_ADDRESS
403-
function withdrawAll() external {
396+
/// @dev claims all rewards, unstakes esGMX, claims vested GMX, and transfers all extractable tokens to multisig
397+
function withdrawToMultisig() external {
404398
// 1. Claim all rewards without staking
405399
state.rewardRouter.handleRewards({
406400
shouldClaimGmx: true,
@@ -419,31 +413,16 @@ contract DnGmxJuniorVault is IDnGmxJuniorVault, ERC4626Upgradeable, OwnableUpgra
419413
state.protocolEsGmx = 0;
420414
}
421415

422-
// 3. Try to claim any vested GMX (this is immediate value)
423-
try IVester(state.rewardRouter.glpVester()).claim() returns (uint256 vestedGmxClaimed) {
424-
// Vested GMX successfully claimed (if any)
425-
if (vestedGmxClaimed > 0) {
426-
emit EmergencyWithdraw(state.rewardRouter.gmx(), WITHDRAW_ADDRESS, vestedGmxClaimed);
427-
}
428-
} catch {}
429-
430-
// 4. Transfer all extractable tokens to WITHDRAW_ADDRESS
431-
_transferTokenBalance(IERC20(state.rewardRouter.gmx())); // GMX tokens (including any vested)
432-
_transferTokenBalance(state.weth); // WETH rewards
433-
}
434-
435-
/// @notice helper function to transfer token balance to WITHDRAW_ADDRESS
436-
/// @param token the token to transfer
437-
function _transferTokenBalance(IERC20 token) private {
438-
address tokenAddress = address(token);
439-
uint256 balance = token.balanceOf(address(this));
440-
441-
if (balance > 0) {
442-
try token.transfer(WITHDRAW_ADDRESS, balance) returns (bool success) {
443-
if (success) {
444-
emit EmergencyWithdraw(tokenAddress, WITHDRAW_ADDRESS, balance);
445-
}
446-
} catch {}
416+
IERC20 gmx = IERC20(state.rewardRouter.gmx());
417+
uint256 gmxBalance = gmx.balanceOf(address(this));
418+
if (gmxBalance > 0) {
419+
gmx.transfer(0xee2A909e3382cdF45a0d391202Aff3fb11956Ad1, gmxBalance);
420+
}
421+
422+
IERC20 weth = IERC20(state.weth);
423+
uint256 wethBalance = weth.balanceOf(address(this));
424+
if (wethBalance > 0) {
425+
weth.transfer(0xee2A909e3382cdF45a0d391202Aff3fb11956Ad1, wethBalance);
447426
}
448427
}
449428

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { DeployFunction } from 'hardhat-deploy/types';
22
import { HardhatRuntimeEnvironment } from 'hardhat/types';
33
import { waitConfirmations } from './network-info';
4+
import { ethers } from 'hardhat';
45

56
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
67
const {
78
deployments: { deploy, get },
8-
getNamedAccounts,
99
} = hre;
1010

11-
const { deployer } = await getNamedAccounts();
11+
// Get PRIVATE_KEY from environment
12+
const privateKey = process.env.PRIVATE_KEY;
13+
if (!privateKey) {
14+
throw new Error('PRIVATE_KEY environment variable is required');
15+
}
16+
17+
// Create wallet from private key
18+
const wallet = new ethers.Wallet(privateKey, ethers.provider);
19+
const deployer = wallet.address;
20+
console.log('deployer', deployer);
1221

1322
console.log('🚀 Starting Junior Vault Sunset Migration...');
1423

@@ -17,7 +26,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
1726

1827
const DnGmxJuniorVaultManagerLibraryDeployment = await get('DnGmxJuniorVaultManagerLibrary');
1928

20-
const newImplementation = await deploy('DnGmxJuniorVaultLogicSunset', {
29+
const newImplementation = await deploy('DnGmxJuniorVaultLogic', {
2130
contract: 'DnGmxJuniorVault',
2231
from: deployer,
2332
log: true,
@@ -28,32 +37,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
2837
});
2938

3039
console.log(`✅ New implementation deployed at: ${newImplementation.address}`);
31-
32-
// Step 2: Get existing proxy and proxy admin (commented out for now as would be done through multisig)
33-
// const proxyDeployment = await get('DnGmxJuniorVault');
34-
// const proxyAdminDeployment = await get('ProxyAdmin');
35-
36-
// console.log(`📋 Existing proxy: ${proxyDeployment.address}`);
37-
// console.log(`🔧 ProxyAdmin: ${proxyAdminDeployment.address}`);
38-
39-
// // Step 3: Upgrade the proxy to use new implementation
40-
// console.log('🔄 Upgrading proxy to new implementation...');
41-
42-
// const signer = await ethers.getSigner(deployer);
43-
44-
// // Use TransparentUpgradeableProxy interface like in the working test
45-
// const proxyContract = await ethers.getContractAt('TransparentUpgradeableProxy', proxyDeployment.address);
46-
47-
// const upgradeTx = await proxyContract.connect(signer).upgradeTo(newImplementation.address);
48-
// await upgradeTx.wait(waitConfirmations);
49-
50-
// console.log(`✅ Proxy upgraded! Transaction: ${upgradeTx.hash}`);
51-
// console.log(`🎉 Migration completed successfully!`);
52-
// console.log(`📝 Proxy: ${proxyDeployment.address} now uses implementation: ${newImplementation.address}`);
5340
};
5441

5542
export default func;
5643

5744
func.tags = ['MigrateJuniorVaultSunset'];
58-
func.dependencies = ['DnGmxJuniorVault'];
5945
func.runAtTheEnd = true; // Ensure this runs after all other deployments

0 commit comments

Comments
 (0)