Skip to content

Commit

Permalink
🚀 v2.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders authored Mar 14, 2024
2 parents fe66fa5 + 444c241 commit 33f86ab
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 40 deletions.
2 changes: 1 addition & 1 deletion deploy-addresses/optimism.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Account": "0x8857CA2255f82E19c52f2E22529afb5f8d021492",
"Account": "0xf274803c43AC4888205E7eE482E9b7a379Cb8DB6",
"Events": "0xc3d16e00833355b48d2fD69D838c6ACF004cf4b6",
"Factory": "0x8234F990b149Ae59416dc260305E565e5DAfEb54",
"Settings": "0x865dA103d126b3Be3599D84caB57109A861F5631"
Expand Down
127 changes: 127 additions & 0 deletions script/upgrades/v2.1.3/Upgrade.s.sol
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));
}
}
10 changes: 5 additions & 5 deletions script/utils/parameters/OptimismParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity 0.8.18;
/// @dev for Synthetix addresses see:
/// https://github.com/Synthetixio/synthetix-docs/blob/master/content/addresses.md#mainnet-optimism-l2

// v2.1.1 deployer
address constant OPTIMISM_DEPLOYER = 0xb7CefE980D41F2f83d4272526b0A0F04617da96b;
// v2.1.3 deployer
address constant OPTIMISM_DEPLOYER = 0x12d970154Ac171293323f20757130d5731850deB;

address constant OPTIMISM_PDAO = 0xe826d43961a87fBE71C91d9B73F7ef9b16721C07;

Expand All @@ -16,14 +16,14 @@ address constant OPTIMISM_GELATO = 0x01051113D81D7d6DA508462F2ad6d7fD96cF42Ef;

address constant OPTIMISM_OPS = 0x340759c8346A1E6Ed92035FB8B6ec57cE1D82c2c;

// v2.1.2
// v2.1.3
address constant OPTIMISM_IMPLEMENTATION =
0x8857CA2255f82E19c52f2E22529afb5f8d021492;
0xf274803c43AC4888205E7eE482E9b7a379Cb8DB6;

// released with v2.1.2 implementation (used by v2.1.*)
address constant OPTIMISM_EVENTS = 0xc3d16e00833355b48d2fD69D838c6ACF004cf4b6;

// updated with v2.1.2 implementation
// updated with v2.1.3 implementation
address constant OPTIMISM_FACTORY = 0x8234F990b149Ae59416dc260305E565e5DAfEb54;

// released with v2.1.0 implementation (used by v2.1.*)
Expand Down
5 changes: 2 additions & 3 deletions src/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract Account is IAccount, Auth, OpsReady {
//////////////////////////////////////////////////////////////*/

/// @inheritdoc IAccount
bytes32 public constant VERSION = "2.1.2";
bytes32 public constant VERSION = "2.1.3";

/// @notice tracking code used when modifying positions
bytes32 internal constant TRACKING_CODE = "KWENTA";
Expand All @@ -51,9 +51,8 @@ contract Account is IAccount, Auth, OpsReady {
uint256 internal constant V3_SWAP_EXACT_IN = 0x00;

/// @notice Synthetix Dynamic Fees Module
/// @dev address will never change and only exists on Optimism Mainnet
IPerpsV2DynamicFeesModule internal constant PERPS_V2_DYNAMIC_FEES_MODULE =
IPerpsV2DynamicFeesModule(0xF4bc5588aAB8CBB412baDd3674094ECF808286f6);
IPerpsV2DynamicFeesModule(0x05F6f46e5EED6dec1D8Cc3c6e8169D447966844d);

/*//////////////////////////////////////////////////////////////
IMMUTABLES
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/*///////////////////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions test/integration/margin.behavior.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -728,19 +728,19 @@ contract MarginBehaviorTest is Test, ConsolidatedEvents {
}

function test_Commands_SetMinKeeperFee() public {
vm.mockCall(
PERPS_V2_DYNAMIC_FEES_MODULE,
abi.encodeWithSignature("setMinKeeperFee()"),
abi.encode(true)
);

IAccount.Command[] memory commands = new IAccount.Command[](1);
bytes[] memory inputs = new bytes[](1);

commands[0] = IAccount.Command.PERPS_V2_SET_MIN_KEEPER_FEE;
inputs[0] = abi.encode(0);

account.execute(commands, inputs);

(,,,,,, uint256 lastUpdatedAtTime) = IPerpsV2DynamicFeesModule(
PERPS_V2_DYNAMIC_FEES_MODULE
).getParameters();

assertEq(lastUpdatedAtTime, block.timestamp);
}

function test_Commands_SetMinKeeperFee_Fails() public {
Expand Down
24 changes: 1 addition & 23 deletions test/unit/Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ contract AccountTest is Test, ConsolidatedEvents {
//////////////////////////////////////////////////////////////*/

function test_GetVerison() public view {
assert(account.VERSION() == "2.1.2");
assert(account.VERSION() == "2.1.3");
}

function test_GetTrackingCode() public view {
Expand Down Expand Up @@ -732,28 +732,6 @@ contract AccountTest is Test, ConsolidatedEvents {
account.execute(commands, inputs);
}

function test_DelegatedTrader_Execute_PERPS_V2_SET_MIN_KEEPER_FEE()
public
{
account.addDelegate({_delegate: DELEGATE});

IAccount.Command[] memory commands = new IAccount.Command[](1);
bytes[] memory inputs = new bytes[](1);

commands[0] = IAccount.Command.PERPS_V2_SET_MIN_KEEPER_FEE;
inputs[0] = abi.encode(0);

vm.prank(DELEGATE);

account.execute(commands, inputs);

(,,,,,, uint256 lastUpdatedAtTime) = IPerpsV2DynamicFeesModule(
PERPS_V2_DYNAMIC_FEES_MODULE
).getParameters();

assertEq(lastUpdatedAtTime, block.timestamp);
}

/*//////////////////////////////////////////////////////////////
EXECUTION LOCK
//////////////////////////////////////////////////////////////*/
Expand Down
100 changes: 100 additions & 0 deletions test/upgrades/v2.1.3/Upgrade.t.sol
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"
);
}
}
Loading

0 comments on commit 33f86ab

Please sign in to comment.