Skip to content

Commit

Permalink
Merge branch 'dev' into q-math
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk committed Jan 2, 2024
2 parents 3aff5d5 + 3e51e58 commit 449b845
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
name: test

on: workflow_dispatch
on: [push, workflow_dispatch]


concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

env:
FOUNDRY_PROFILE: ci
OP_MAINNET_RPC: ${{ secrets.OP_MAINNET_RPC }}
OP_GOERLI_RPC: ${{ secrets.OP_GOERLI_RPC }}
OP_MAINNET_DEPLOYER_PK: ${{ secrets.TEST_DEPLOYER_PK }}
OP_GOERLI_DEPLOYER_PK: ${{ secrets.TEST_DEPLOYER_PK }}
ARB_GOERLI_RPC: ${{ secrets.ARB_GOERLI_RPC }}
ARB_MAINNET_RPC: ${{ secrets.ARB_MAINNET_RPC }}

jobs:
check:
Expand Down
18 changes: 15 additions & 3 deletions src/contracts/oracles/CamelotRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract CamelotRelayer {
string public symbol;

uint128 public baseAmount;
uint256 public multiplier;
int256 public multiplier;
uint32 public quotePeriod;

constructor(address _algebraV3Factory, address _baseToken, address _quoteToken, uint32 _quotePeriod) {
Expand All @@ -36,7 +36,7 @@ contract CamelotRelayer {
}

baseAmount = uint128(10 ** IERC20Metadata(_baseToken).decimals());
multiplier = 18 - IERC20Metadata(_quoteToken).decimals();
multiplier = int256(18) - int256(uint256(IERC20Metadata(_quoteToken).decimals()));
quotePeriod = _quotePeriod;

symbol = string(abi.encodePacked(IERC20Metadata(_baseToken).symbol(), ' / ', IERC20Metadata(_quoteToken).symbol()));
Expand Down Expand Up @@ -72,6 +72,18 @@ contract CamelotRelayer {
}

function _parseResult(uint256 _quoteResult) internal view returns (uint256 _result) {
return _quoteResult * 10 ** multiplier;
if (multiplier > 0) {
return _quoteResult * (10 ** uint256(multiplier));
}
else if (multiplier < 0) {
return _quoteResult / (10 ** abs(multiplier));
}
else return _quoteResult;
}

// @notice Return the absolute value of a signed integer as an unsigned integer
function abs(int256 x) internal pure returns (uint256) {
x >= 0 ? x : -x;
return uint256(x);
}
}
2 changes: 1 addition & 1 deletion src/interfaces/oracles/IRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface IRelayer is IBaseOracle {
/**
* @dev The multiplier used to convert the quote into an 18 decimals format
*/
function multiplier() external view returns (uint256 _multiplier);
function multiplier() external view returns (int256 _multiplier);

/**
* @dev The length of the TWAP used to consult the pool
Expand Down

0 comments on commit 449b845

Please sign in to comment.