Skip to content

Commit

Permalink
style(all): forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
AkemiHomura-maow committed Mar 23, 2024
1 parent c124e02 commit caa20ee
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
28 changes: 16 additions & 12 deletions contracts/PriceFetcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ contract PriceFetcher {
}
}

function add_tokens(bool is_connector, address[] calldata _tokens) public{
function add_tokens(bool is_connector, address[] calldata _tokens) public {
_only_owner();
IERC20Metadata[] storage arr = is_connector ? connectors : source_tokens;
for (uint256 i = 0; i < _tokens.length; i++) {
arr.push( IERC20Metadata(_tokens[i]) );
arr.push(IERC20Metadata(_tokens[i]));
}
}

function remove_tokens(bool is_connector, uint256[] calldata _indices) public{
function remove_tokens(bool is_connector, uint256[] calldata _indices) public {
_only_owner();
IERC20Metadata[] storage arr = is_connector ? connectors : source_tokens;
for (uint256 i = 0; i < _indices.length; i++) {
Expand All @@ -43,12 +43,16 @@ contract PriceFetcher {
}
}

function change_USDC(address _USDC) public{
function change_USDC(address _USDC) public {
_only_owner();
USDC = IERC20Metadata(_USDC);
}

function _construct_oracle_args(uint256 _src_len, uint256 _src_offset) internal view returns (IERC20Metadata[] memory oracle_args){
function _construct_oracle_args(uint256 _src_len, uint256 _src_offset)
internal
view
returns (IERC20Metadata[] memory oracle_args)
{
oracle_args = new IERC20Metadata[]( _src_len + connectors.length + 1);
for (uint256 i = _src_offset; i < _src_offset + _src_len; i++) {
oracle_args[i - _src_offset] = source_tokens[i];
Expand All @@ -72,7 +76,7 @@ contract PriceFetcher {
USDC = IERC20Metadata(_USDC);
}

function _only_owner() internal view{
function _only_owner() internal view {
require(msg.sender == owner);
}

Expand Down Expand Up @@ -111,15 +115,15 @@ contract PriceFetcher {
/// @notice Fetches prices for a list of tokens.
/// @dev Can only be called by the owner. Emits a PriceFetched event for each token.
/// @param _src_len The number of source tokens to fetch prices for.
/// @param _src_offset The number of source tokens to skip.
function fetchPrices(uint _src_len, uint _src_offset) public {
/// @param _src_offset The number of source tokens to skip.
function fetchPrices(uint256 _src_len, uint256 _src_offset) public {
require(msg.sender == owner || callers[msg.sender]);

uint256[] memory prices = oracle.getManyRatesWithConnectors(uint8(_src_len), _construct_oracle_args(_src_len, _src_offset));
uint256[] memory prices =
oracle.getManyRatesWithConnectors(uint8(_src_len), _construct_oracle_args(_src_len, _src_offset));

for (uint i = _src_offset; i < _src_offset + _src_len; i++) {
emit PriceFetched( address(source_tokens[i]), prices[i - _src_offset]);
for (uint256 i = _src_offset; i < _src_offset + _src_len; i++) {
emit PriceFetched(address(source_tokens[i]), prices[i - _src_offset]);
}
}

}
46 changes: 21 additions & 25 deletions contracts/VeloOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract VeloOracle is IVeloOracle {
}

/// @notice Struct to hold variables needed to identify CL pools
struct CLPairParams{
struct CLPairParams {
address tokenA;
address tokenB;
int24 tickSpacing;
Expand All @@ -90,14 +90,14 @@ contract VeloOracle is IVeloOracle {
}

/// @notice Permissioned function to enable routing through certain CL pools
function enableCLPairTickSpacing(CLPairParams[] calldata params) public{
function enableCLPairTickSpacing(CLPairParams[] calldata params) public {
require(msg.sender == owner);
for (uint256 i; i < params.length; i++){
for (uint256 i; i < params.length; i++) {
CLPairParams memory param = params[i];
address pair = CLFactory.getPool(param.tokenA, param.tokenB, param.tickSpacing);
require(pair != address(0x0));
enabledCLPools[param.tokenA][param.tokenB].push( ICLPool(pair) );
enabledCLPools[param.tokenB][param.tokenA].push( ICLPool(pair) );
enabledCLPools[param.tokenA][param.tokenB].push(ICLPool(pair));
enabledCLPools[param.tokenB][param.tokenA].push(ICLPool(pair));
}
}

Expand Down Expand Up @@ -143,7 +143,6 @@ contract VeloOracle is IVeloOracle {
out.mod = true;
(out.bal0, out.bal1, out.isStable) = (maxPair1, maxPair2, isMaxStable);
}

}

/**
Expand Down Expand Up @@ -281,7 +280,7 @@ contract VeloOracle is IVeloOracle {
uint256 newOut = 0;

// newOut in t1
try IVeloPair(currentPair).getAmountOut((10**t0_dec), address(t0)) returns (uint256 result) {
try IVeloPair(currentPair).getAmountOut((10 ** t0_dec), address(t0)) returns (uint256 result) {
newOut = result;
} catch {
return 0;
Expand Down Expand Up @@ -341,29 +340,27 @@ contract VeloOracle is IVeloOracle {
function _getVirtualBalances(IERC20Metadata srcToken, IERC20Metadata dstToken)
internal
view
returns (uint256 srcVirtualBalance, uint256 dstVirtualBalance){
returns (uint256 srcVirtualBalance, uint256 dstVirtualBalance)
{
uint256 maxLiquidity;
bool isSrcToken0 = srcToken < dstToken;
ICLPool[] memory pools = enabledCLPools[address(srcToken)][address(dstToken)];

uint256 maxLiquidity;
bool isSrcToken0 = srcToken < dstToken;
ICLPool[] memory pools = enabledCLPools[address(srcToken)][address(dstToken)];
for (uint256 i; i < pools.length; i++) {
ICLPool pool = pools[i];
uint256 liquidity = uint256(pool.liquidity());

for(uint256 i; i < pools.length; i++){
ICLPool pool = pools[i];
uint256 liquidity = uint256(pool.liquidity());
if (liquidity > maxLiquidity) {
(uint160 sqrtPriceX96,,,,,) = pool.slot0();

if (liquidity > maxLiquidity){
(uint160 sqrtPriceX96, , , , ,) = pool.slot0();
(srcVirtualBalance, dstVirtualBalance) = isSrcToken0
? ((liquidity << 96) / sqrtPriceX96, (liquidity * (sqrtPriceX96 >> 32)) >> 64)
: ((liquidity * (sqrtPriceX96 >> 32)) >> 64, (liquidity << 96) / sqrtPriceX96);

(srcVirtualBalance, dstVirtualBalance) =
isSrcToken0 ?
( (liquidity << 96) / sqrtPriceX96 , (liquidity * (sqrtPriceX96 >> 32 ) ) >> 64 )
: ( (liquidity * (sqrtPriceX96 >> 32 ) ) >> 64 , (liquidity << 96) / sqrtPriceX96 );

maxLiquidity = liquidity;
}
maxLiquidity = liquidity;
}

}
}

/// @notice Internal function to fetch the pair from tokens using correct order
/// @param tokenA First input token
Expand All @@ -387,4 +384,3 @@ contract VeloOracle is IVeloOracle {
return a < b ? a : b;
}
}

0 comments on commit caa20ee

Please sign in to comment.