Skip to content

Commit

Permalink
πŸ‘·πŸ»β€β™‚οΈ Add $USDC to Engine constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Nov 15, 2023
1 parent 148c0a0 commit 88eb558
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 33 deletions.
24 changes: 16 additions & 8 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ contract Setup is Script {
address perpsMarketProxy,
address spotMarketProxy,
address sUSDProxy,
address oracle
address oracle,
address usdc
)
public
returns (
Expand All @@ -42,7 +43,8 @@ contract Setup is Script {
_spotMarketProxy: spotMarketProxy,
_sUSDProxy: sUSDProxy,
_oracle: oracle,
_trustedForwarder: address(trustedForwarderContract)
_trustedForwarder: address(trustedForwarderContract),
_usdc: usdc
});
}
}
Expand All @@ -59,7 +61,8 @@ contract DeployBase_Synthetix is Setup, BaseParameters {
perpsMarketProxy: PERPS_MARKET_PROXY,
spotMarketProxy: SPOT_MARKET_PROXY,
sUSDProxy: USD_PROXY,
oracle: PYTH
oracle: PYTH,
usdc: USDC
});

vm.stopBroadcast();
Expand All @@ -78,7 +81,8 @@ contract DeployBaseGoerli_Synthetix is Setup, BaseGoerliParameters {
perpsMarketProxy: PERPS_MARKET_PROXY,
spotMarketProxy: SPOT_MARKET_PROXY,
sUSDProxy: USD_PROXY,
oracle: PYTH
oracle: PYTH,
usdc: USDC
});

vm.stopBroadcast();
Expand All @@ -100,7 +104,8 @@ contract DeployBaseGoerli_KwentaFork is
perpsMarketProxy: PERPS_MARKET_PROXY,
spotMarketProxy: SPOT_MARKET_PROXY,
sUSDProxy: USD_PROXY,
oracle: PYTH
oracle: PYTH,
usdc: USDC
});

vm.stopBroadcast();
Expand All @@ -119,7 +124,8 @@ contract DeployBaseGoerli_Andromeda is Setup, BaseGoerliParameters {
perpsMarketProxy: PERPS_MARKET_PROXY_ANDROMEDA,
spotMarketProxy: SPOT_MARKET_PROXY_ANDROMEDA,
sUSDProxy: USD_PROXY_ANDROMEDA,
oracle: PYTH
oracle: PYTH,
usdc: USDC
});

vm.stopBroadcast();
Expand All @@ -138,7 +144,8 @@ contract DeployOptimism_Synthetix is Setup, OptimismParameters {
perpsMarketProxy: PERPS_MARKET_PROXY,
spotMarketProxy: SPOT_MARKET_PROXY,
sUSDProxy: USD_PROXY,
oracle: PYTH
oracle: PYTH,
usdc: USDC
});

vm.stopBroadcast();
Expand All @@ -157,7 +164,8 @@ contract DeployOptimismGoerli_Synthetix is Setup, OptimismGoerliParameters {
perpsMarketProxy: PERPS_MARKET_PROXY,
spotMarketProxy: SPOT_MARKET_PROXY,
sUSDProxy: USD_PROXY,
oracle: PYTH
oracle: PYTH,
usdc: USDC
});

vm.stopBroadcast();
Expand Down
2 changes: 2 additions & 0 deletions script/utils/parameters/BaseGoerliKwentaForkParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ contract BaseGoerliKwentaForkParameters {
0xD3bcDae94B0c2EF16d1c43d29c23b1735d864fC6;

address public constant PYTH = 0x5955C1478F0dAD753C7E2B4dD1b4bC530C64749f;

address public constant USDC = 0x2e9F75DF8839ff192Da27e977CD154FD1EAE03cf;
}
2 changes: 2 additions & 0 deletions script/utils/parameters/BaseGoerliParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contract BaseGoerliParameters {

address public constant PYTH = 0x5955C1478F0dAD753C7E2B4dD1b4bC530C64749f;

address public constant USDC = 0x2e9F75DF8839ff192Da27e977CD154FD1EAE03cf;

address public constant PERPS_MARKET_PROXY_ANDROMEDA =
0xEED61f0CB02f3B38923b1b6EAa939D5f04f431b6;

Expand Down
2 changes: 2 additions & 0 deletions script/utils/parameters/BaseParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ contract BaseParameters {
address public constant USD_PROXY = address(0);

address public constant PYTH = 0x8250f4aF4B972684F7b336503E2D6dFeDeB1487a;

address public constant USDC = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913;
}
2 changes: 2 additions & 0 deletions script/utils/parameters/OptimismGoerliParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ contract OptimismGoerliParameters {
0xe487Ad4291019b33e2230F8E2FB1fb6490325260;

address public constant PYTH = 0xff1a0f4744e8582DF1aE09D5611b887B6a12925C;

address public constant USDC = address(0xDEAD);
}
2 changes: 2 additions & 0 deletions script/utils/parameters/OptimismParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ contract OptimismParameters {
0xb2F30A7C980f052f02563fb518dcc39e6bf38175;

address public constant PYTH = 0xff1a0f4744e8582DF1aE09D5611b887B6a12925C;

address public constant USDC = 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85;
}
13 changes: 8 additions & 5 deletions src/Engine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ contract Engine is IEngine, EIP712, EIP7412, ERC2771Context {
/// @notice Synthetix v3 $sUSD contract
IERC20 internal immutable SUSD;

/// @notice $USDC contract
IERC20 internal immutable USDC;

/*//////////////////////////////////////////////////////////////
STATE
//////////////////////////////////////////////////////////////*/
Expand All @@ -103,23 +106,27 @@ contract Engine is IEngine, EIP712, EIP7412, ERC2771Context {
/// @param _sUSDProxy Synthetix v3 $sUSD contract
/// @param _oracle pyth oracle contract used to get asset prices
/// @param _trustedForwarder trusted forwarder contract used for meta transactions
/// @param _usdc $USDC contract address
constructor(
address _perpsMarketProxy,
address _spotMarketProxy,
address _sUSDProxy,
address _oracle,
address _trustedForwarder
address _trustedForwarder,
address _usdc
) ERC2771Context(_trustedForwarder) {
if (_perpsMarketProxy == address(0)) revert ZeroAddress();
if (_spotMarketProxy == address(0)) revert ZeroAddress();
if (_sUSDProxy == address(0)) revert ZeroAddress();
if (_oracle == address(0)) revert ZeroAddress();
if (_trustedForwarder == address(0)) revert ZeroAddress();
if (_usdc == address(0)) revert ZeroAddress();

PERPS_MARKET_PROXY = IPerpsMarketProxy(_perpsMarketProxy);
SPOT_MARKET_PROXY = ISpotMarketProxy(_spotMarketProxy);
SUSD = IERC20(_sUSDProxy);
ORACLE = IPyth(_oracle);
USDC = IERC20(_usdc);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -320,7 +327,6 @@ contract Engine is IEngine, EIP712, EIP7412, ERC2771Context {
/// @inheritdoc IEngine
function zap(
uint128 _accountId,
address _usdc,
uint128 _synthMarketId,
int256 _amount,
address _referrer
Expand All @@ -335,9 +341,6 @@ contract Engine is IEngine, EIP712, EIP7412, ERC2771Context {
revert ZapFailed();
}

// define $USDC contract
IERC20 USDC = IERC20(_usdc);

// define $sUSDC synth contract
IERC20 sUSDC = IERC20(_getSynthAddress(_synthMarketId));

Expand Down
2 changes: 0 additions & 2 deletions src/interfaces/IEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,11 @@ interface IEngine {
/// @notice "zap" $USDC for $sUSD and deposit the $sUSD into the perps market proxy
/// or withdraw the $sUSD from the perps market proxy and "zap" $sUSD for $USDC
/// @param _accountId the account id to modify collateral for
/// @param _usdc the address of the $USDC contract
/// @param _synthMarketId the id of the synth market (i.e. $sUSDC)
/// @param _amount the amount of $USDC to deposit/withdraw
/// @param _referrer the address of the referrer
function zap(
uint128 _accountId,
address _usdc,
uint128 _synthMarketId,
int256 _amount,
address _referrer
Expand Down
30 changes: 24 additions & 6 deletions test/Deployment.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ contract DeploymentTest is Test, Setup {
perpsMarketProxy: address(0x1),
spotMarketProxy: address(0x2),
sUSDProxy: address(0x3),
oracle: address(0x4)
oracle: address(0x4),
usdc: address(0x5)
});

assertTrue(address(engine) != address(0x0));
Expand All @@ -32,7 +33,8 @@ contract DeploymentTest is Test, Setup {
perpsMarketProxy: address(0),
spotMarketProxy: address(0x2),
sUSDProxy: address(0x3),
oracle: address(0x4)
oracle: address(0x4),
usdc: address(0x5)
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), IEngine.ZeroAddress.selector);
}
Expand All @@ -43,7 +45,8 @@ contract DeploymentTest is Test, Setup {
perpsMarketProxy: address(0x1),
spotMarketProxy: address(0),
sUSDProxy: address(0x3),
oracle: address(0x4)
oracle: address(0x4),
usdc: address(0x5)
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), IEngine.ZeroAddress.selector);
}
Expand All @@ -54,7 +57,8 @@ contract DeploymentTest is Test, Setup {
perpsMarketProxy: address(0x1),
spotMarketProxy: address(0x2),
sUSDProxy: address(0),
oracle: address(0x4)
oracle: address(0x4),
usdc: address(0x5)
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), IEngine.ZeroAddress.selector);
}
Expand All @@ -65,7 +69,8 @@ contract DeploymentTest is Test, Setup {
perpsMarketProxy: address(0x1),
spotMarketProxy: address(0x2),
sUSDProxy: address(0x3),
oracle: address(0)
oracle: address(0),
usdc: address(0x5)
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), IEngine.ZeroAddress.selector);
}
Expand All @@ -79,7 +84,20 @@ contract DeploymentTest is Test, Setup {
_spotMarketProxy: address(0x2),
_sUSDProxy: address(0x3),
_oracle: address(0x4),
_trustedForwarder: address(0)
_trustedForwarder: address(0),
_usdc: address(0x5)
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), IEngine.ZeroAddress.selector);
}
}

function test_deploy_usdc_zero_address() public {
try setup.deploySystem({
perpsMarketProxy: address(0x1),
spotMarketProxy: address(0x2),
sUSDProxy: address(0x3),
oracle: address(0x4),
usdc: address(0)
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), IEngine.ZeroAddress.selector);
}
Expand Down
Loading

0 comments on commit 88eb558

Please sign in to comment.