-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
522 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.8.18; | ||
|
||
import {Script} from "lib/forge-std/src/Script.sol"; | ||
|
||
import {IAddressResolver} from "script/utils/interfaces/IAddressResolver.sol"; | ||
|
||
import {Account} from "src/Account.sol"; | ||
import {Events} from "src/Events.sol"; | ||
import {Settings} from "src/Settings.sol"; | ||
import {IAccount} from "src/interfaces/IAccount.sol"; | ||
|
||
import { | ||
OPTIMISM_GELATO, | ||
OPTIMISM_OPS, | ||
FUTURES_MARKET_MANAGER, | ||
OPTIMISM_FACTORY, | ||
OPTIMISM_EVENTS, | ||
OPTIMISM_SETTINGS, | ||
OPTIMISM_SYNTHETIX_ADDRESS_RESOLVER, | ||
OPTIMISM_UNISWAP_PERMIT2, | ||
OPTIMISM_UNISWAP_UNIVERSAL_ROUTER, | ||
PERPS_V2_EXCHANGE_RATE, | ||
PROXY_SUSD, | ||
SYSTEM_STATUS | ||
} from "script/utils/parameters/OptimismParameters.sol"; | ||
import { | ||
OPTIMISM_GOERLI_EVENTS, | ||
OPTIMISM_GOERLI_SETTINGS, | ||
OPTIMISM_GOERLI_FACTORY, | ||
OPTIMISM_GOERLI_GELATO, | ||
OPTIMISM_GOERLI_OPS, | ||
OPTIMISM_GOERLI_SYNTHETIX_ADDRESS_RESOLVER, | ||
OPTIMISM_GOERLI_UNISWAP_PERMIT2, | ||
OPTIMISM_GOERLI_UNISWAP_UNIVERSAL_ROUTER | ||
} from "script/utils/parameters/OptimismGoerliParameters.sol"; | ||
|
||
/// @title Script to upgrade the Account implementation v2.1.2 -> v2.1.3 | ||
/// @author JaredBorders ([email protected]) | ||
|
||
/// @dev steps to deploy and verify on Optimism: | ||
/// (1) load the variables in the .env file via `source .env` | ||
/// (2) run `forge script script/upgrades/v2.1.3/Upgrade.s.sol:UpgradeAccountOptimism --rpc-url $ARCHIVE_NODE_URL_L2 --broadcast --verify -vvvv` | ||
/// (3) Smart Margin Account Factory owner (i.e. Kwenta pDAO) will need to call `upgradeAccountImplementation` on the Factory with the address of the new Account implementation | ||
contract UpgradeAccountOptimism is Script { | ||
function run() public { | ||
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
upgrade(); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
|
||
function upgrade() public returns (address implementation) { | ||
IAddressResolver addressResolver = | ||
IAddressResolver(OPTIMISM_SYNTHETIX_ADDRESS_RESOLVER); | ||
|
||
address marginAsset = addressResolver.getAddress({name: PROXY_SUSD}); | ||
address perpsV2ExchangeRate = | ||
addressResolver.getAddress({name: PERPS_V2_EXCHANGE_RATE}); | ||
address futuresMarketManager = | ||
addressResolver.getAddress({name: FUTURES_MARKET_MANAGER}); | ||
address systemStatus = addressResolver.getAddress({name: SYSTEM_STATUS}); | ||
|
||
IAccount.AccountConstructorParams memory params = IAccount | ||
.AccountConstructorParams({ | ||
factory: OPTIMISM_FACTORY, | ||
events: OPTIMISM_EVENTS, | ||
marginAsset: marginAsset, | ||
perpsV2ExchangeRate: perpsV2ExchangeRate, | ||
futuresMarketManager: futuresMarketManager, | ||
systemStatus: systemStatus, | ||
gelato: OPTIMISM_GELATO, | ||
ops: OPTIMISM_OPS, | ||
settings: OPTIMISM_SETTINGS, | ||
universalRouter: OPTIMISM_UNISWAP_UNIVERSAL_ROUTER, | ||
permit2: OPTIMISM_UNISWAP_PERMIT2 | ||
}); | ||
|
||
implementation = address(new Account(params)); | ||
} | ||
} | ||
|
||
/// @dev steps to deploy and verify on Optimism Goerli: | ||
/// (1) load the variables in the .env file via `source .env` | ||
/// (2) run `forge script script/upgrades/v2.1.3/Upgrade.s.sol:UpgradeAccountOptimismGoerli --rpc-url $ARCHIVE_NODE_URL_GOERLI_L2 --broadcast --verify -vvvv` | ||
/// (3) Smart Margin Account Factory owner (i.e. Kwenta pDAO) will need to call `upgradeAccountImplementation` on the Factory with the address of the new Account implementation | ||
contract UpgradeAccountOptimismGoerli is Script { | ||
function run() public { | ||
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
upgrade(); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
|
||
function upgrade() public returns (address implementation) { | ||
IAddressResolver addressResolver = | ||
IAddressResolver(OPTIMISM_GOERLI_SYNTHETIX_ADDRESS_RESOLVER); | ||
|
||
address marginAsset = addressResolver.getAddress({name: PROXY_SUSD}); | ||
address perpsV2ExchangeRate = | ||
addressResolver.getAddress({name: PERPS_V2_EXCHANGE_RATE}); | ||
address futuresMarketManager = | ||
addressResolver.getAddress({name: FUTURES_MARKET_MANAGER}); | ||
address systemStatus = addressResolver.getAddress({name: SYSTEM_STATUS}); | ||
|
||
IAccount.AccountConstructorParams memory params = IAccount | ||
.AccountConstructorParams({ | ||
factory: OPTIMISM_GOERLI_FACTORY, | ||
events: OPTIMISM_GOERLI_EVENTS, | ||
marginAsset: marginAsset, | ||
perpsV2ExchangeRate: perpsV2ExchangeRate, | ||
futuresMarketManager: futuresMarketManager, | ||
systemStatus: systemStatus, | ||
gelato: OPTIMISM_GOERLI_GELATO, | ||
ops: OPTIMISM_GOERLI_OPS, | ||
settings: OPTIMISM_GOERLI_SETTINGS, | ||
universalRouter: OPTIMISM_GOERLI_UNISWAP_UNIVERSAL_ROUTER, | ||
permit2: OPTIMISM_GOERLI_UNISWAP_PERMIT2 | ||
}); | ||
|
||
implementation = address(new Account(params)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ pragma solidity 0.8.18; | |
import {IPerpsV2MarketConsolidated} from | ||
"src/interfaces/synthetix/IPerpsV2MarketConsolidated.sol"; | ||
|
||
/// @title Kwenta Smart Margin Account v2.1.2 Implementation Interface | ||
/// @title Kwenta Smart Margin Account v2.1.3 Implementation Interface | ||
/// @author JaredBorders ([email protected]), JChiaramonte7 ([email protected]) | ||
interface IAccount { | ||
/*/////////////////////////////////////////////////////////////// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.8.18; | ||
|
||
import {Test} from "lib/forge-std/src/Test.sol"; | ||
import {IAccount} from "src/interfaces/IAccount.sol"; | ||
import {AccountExposed} from "test/utils/AccountExposed.sol"; | ||
|
||
/// @notice Test mutable storage slots are not changed in | ||
/// Account contract to ensure upgrade safety | ||
contract UpgradeTest is Test { | ||
AccountExposed private accountExposed; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
SLOTS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
uint256 internal constant OWNER_SLOT = 0; | ||
uint256 internal constant DELEGATES_SLOT = 1; | ||
uint256 internal constant COMMITTED_MARGIN_SLOT = 21; | ||
uint256 internal constant CONDITIONAL_ORDER_ID_SLOT = 22; | ||
uint256 internal constant CONDITIONAL_ORDERS_SLOT = 23; | ||
uint256 internal constant LOCKED_SLOT = 24; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
SETUP | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
function setUp() public { | ||
IAccount.AccountConstructorParams memory params = IAccount | ||
.AccountConstructorParams( | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0), | ||
address(0) | ||
); | ||
|
||
accountExposed = new AccountExposed(params); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
TESTS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
function test_owner_slot() public { | ||
/// @dev slot should NEVER change | ||
assertEq( | ||
accountExposed.expose_owner_slot(), OWNER_SLOT, "slot missmatch" | ||
); | ||
} | ||
|
||
function test_delegates_slot() public { | ||
/// @dev slot should NEVER change | ||
assertEq( | ||
accountExposed.expose_delegates_slot(), | ||
DELEGATES_SLOT, | ||
"slot missmatch" | ||
); | ||
} | ||
|
||
function test_committedMargin_slot() public { | ||
/// @dev slot should NEVER change | ||
assertEq( | ||
accountExposed.expose_committedMargin_slot(), | ||
COMMITTED_MARGIN_SLOT, | ||
"slot missmatch" | ||
); | ||
} | ||
|
||
function test_conditionalOrderId_slot() public { | ||
/// @dev slot should NEVER change | ||
assertEq( | ||
accountExposed.expose_conditionalOrderId_slot(), | ||
CONDITIONAL_ORDER_ID_SLOT, | ||
"slot missmatch" | ||
); | ||
} | ||
|
||
function test_conditionalOrders_slot() public { | ||
/// @dev slot should NEVER change | ||
assertEq( | ||
accountExposed.expose_conditionalOrders_slot(), | ||
CONDITIONAL_ORDERS_SLOT, | ||
"slot missmatch" | ||
); | ||
} | ||
|
||
function test_locked_slot() public { | ||
/// @dev slot should NEVER change | ||
assertEq( | ||
accountExposed.expose_locked_slot(), LOCKED_SLOT, "slot missmatch" | ||
); | ||
} | ||
} |
Oops, something went wrong.