diff --git a/contracts/margin-dex/Vault.vy b/contracts/margin-dex/Vault.vy index 56b5615..b0b3ed3 100644 --- a/contracts/margin-dex/Vault.vy +++ b/contracts/margin-dex/Vault.vy @@ -52,7 +52,6 @@ PERCENTAGE_BASE: constant(uint256) = 100_00 # == 100% PERCENTAGE_BASE_HIGH_PRECISION: constant(uint256) = 100_00_000 # == 100% ARBITRUM_SEQUENCER_UPTIME_FEED: constant(address) = 0xFdB631F5EE196F0ed6FAa767959853A9F217697D -ORACLE_FRESHNESS_THRESHOLD: constant(uint256) = 24*60*60 # 24h WETH: constant(address) = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 @@ -77,6 +76,7 @@ is_enabled_market: HashMap[address, HashMap[address, bool]] max_leverage: public(HashMap[address, HashMap[address, uint256]]) # token -> Chainlink oracle to_usd_oracle: public(HashMap[address, address]) +oracle_freshness_threshold: public(HashMap[address, uint256]) # token_in -> # token_out -> slippage liquidate_slippage: public(HashMap[address, HashMap[address, uint256]]) @@ -587,7 +587,7 @@ def _to_usd_oracle_price(_token: address) -> uint256: self.to_usd_oracle[_token] ).latestRoundData() - assert (block.timestamp - updated_at) < ORACLE_FRESHNESS_THRESHOLD, "oracle not fresh" + assert (block.timestamp - updated_at) < self.oracle_freshness_threshold[self.to_usd_oracle[_token]], "oracle not fresh" usd_price: uint256 = convert(answer, uint256) # 8 dec return usd_price @@ -1486,12 +1486,17 @@ def set_is_accepting_new_orders(_is_accepting_new_orders: bool): # allowed tokens & markets # @external -def whitelist_token(_token: address, _token_to_usd_oracle: address) -> uint256: +def whitelist_token( + _token: address, + _token_to_usd_oracle: address, + _oracle_freshness_threshold: uint256) -> uint256: assert msg.sender == self.admin, "unauthorized" assert self.is_whitelisted_token[_token] == False, "already whitelisted" + assert _oracle_freshness_threshold > 0, "invalid oracle freshness threshold" self.is_whitelisted_token[_token] = True self.to_usd_oracle[_token] = _token_to_usd_oracle + self.oracle_freshness_threshold[_token_to_usd_oracle] = _oracle_freshness_threshold return self._to_usd_oracle_price(_token) diff --git a/tests/conftest.py b/tests/conftest.py index fa220d7..dca3f9d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,9 +66,9 @@ def dex(): @pytest.fixture(scope="session", autouse=True) def vault(eth_usd_oracle, usdc_usd_oracle, wbtc_usd_oracle): vault = boa.load("contracts/margin-dex/Vault.vy") - vault.whitelist_token(pytest.WETH, pytest.ETH_USD_ORACLE) - vault.whitelist_token(pytest.USDC, pytest.USDC_USD_ORACLE) - vault.whitelist_token(pytest.WBTC, pytest.WBTC_USD_ORACLE) + vault.whitelist_token(pytest.WETH, pytest.ETH_USD_ORACLE, 60*60*24) + vault.whitelist_token(pytest.USDC, pytest.USDC_USD_ORACLE, 60*60*24) + vault.whitelist_token(pytest.WBTC, pytest.WBTC_USD_ORACLE, 60*60*24) vault.enable_market(pytest.WETH, pytest.USDC, 50) vault.enable_market(pytest.USDC, pytest.WETH, 50) vault.set_variable_interest_parameters(pytest.WETH, 0, 0, 0, 80_00_000) diff --git a/tintinweb.vscode-vyper-0.0.15.vsix b/tintinweb.vscode-vyper-0.0.15.vsix new file mode 100644 index 0000000..47f9275 Binary files /dev/null and b/tintinweb.vscode-vyper-0.0.15.vsix differ