Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
node_modules
.env
dist

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

gas_report

contracts/vendor
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
extends: ['plugin:@api3/eslint-plugin-commons/universal', 'plugin:@api3/eslint-plugin-commons/jest'],
parserOptions: {
project: ['./tsconfig.json'],
},
rules: {
camelcase: 'off',
'no-nested-ternary': 'off',

'functional/no-try-statements': 'off',

'jest/no-conditional-in-test': 'off',

'lodash/prefer-constant': 'off',
'lodash/prefer-lodash-typecheck': 'off',
'lodash/prefer-noop': 'off',

'unicorn/filename-case': 'off',
'unicorn/no-anonymous-default-export': 'off',
'unicorn/prefer-export-from': 'off',
'unicorn/prefer-object-from-entries': 'off',
'unicorn/prefer-ternary': 'off',

'@typescript-eslint/max-params': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/require-await': 'off',
},
};
7 changes: 7 additions & 0 deletions .github/config/linkspector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
aliveStatusCodes:
- 200
- 406
dirs:
- .
- .github
useGitIgnore: true
16 changes: 16 additions & 0 deletions .github/workflows/check-md-links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Check Markdown links

on: push

jobs:
check-md-links:
runs-on: ubuntu-latest
steps:
- name: Clone @api3/data-feed-proxy-combinators
uses: actions/checkout@v4
- name: Check Markdown links
uses: umbrelladocs/action-linkspector@v1
with:
reporter: github-pr-review
config_file: .github/config/linkspector.yml
fail_on_error: true
40 changes: 40 additions & 0 deletions .github/workflows/continuous-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Continuous build

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint-build-test:
runs-on: ubuntu-latest
steps:
- name: Clone @api3/data-feed-proxy-combinators
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v3

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20.17.0'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm lint

- name: Build
run: pnpm build

- name: Verify vendor contracts
run: pnpm verify-vendor-contracts

- name: Test
run: pnpm test
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
.env
dist

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

gas_report
19 changes: 19 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
node_modules
.env
dist

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

gas_report

contracts/vendor
27 changes: 27 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bracketSpacing": true,
"printWidth": 120,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.md",
"options": {
"parser": "markdown"
}
},
{
"files": "*.sol",
"options": {
"parser": "antlr",
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}
]
}
3 changes: 3 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['mock', 'test', 'vendor'],
};
13 changes: 13 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }],
"not-rely-on-time": "off",
"no-empty-blocks": "off",
"no-global-import": "off",
"func-name-mixedcase": "off",
"immutable-vars-naming": "off",
"gas-custom-errors": "off"
}
}
19 changes: 19 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
node_modules
.env
dist

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

gas_report

contracts/vendor
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 API3 Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# data-feed-proxy-combinators
# data-feed-proxy-combinators
131 changes: 131 additions & 0 deletions contracts/InverseApi3ReaderProxyV1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import "@api3/contracts/interfaces/IApi3ReaderProxy.sol";
import "./interfaces/IInverseApi3ReaderProxyV1.sol";

/// @title An immutable proxy contract that inverts the value returned by an
/// IApi3ReaderProxy data feed
/// @dev This contract implements the AggregatorV2V3Interface to be compatible
/// with Chainlink aggregators. This allows the contract to be used as a drop-in
/// replacement for Chainlink aggregators in existing dApps.
/// Refer to https://github.com/api3dao/migrate-from-chainlink-to-api3 for more
/// information about the Chainlink interface implementation.
contract InverseApi3ReaderProxyV1 is IInverseApi3ReaderProxyV1 {
/// @notice IApi3ReaderProxy contract address
address public immutable override proxy;

/// @param proxy_ IApi3ReaderProxy contract address
constructor(address proxy_) {
if (proxy_ == address(0)) {
revert ZeroProxyAddress();
}
proxy = proxy_;
}

/// @notice Returns the inverted value of the underlying IApi3ReaderProxy
/// @dev This inverts the 18-decimal fixed-point value using 1e36 / value.
/// The operation will revert if `baseValue` is zero (division by zero) or if
/// `baseValue` is so small (yet non-zero) that the resulting inverted value
/// would overflow the `int224` type.
/// @return value Inverted value of the underlying proxy
/// @return timestamp Timestamp from the underlying proxy
function read()
public
view
override
returns (int224 value, uint32 timestamp)
{
(int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxy(proxy)
.read();

value = int224((1e36) / int256(baseValue));
timestamp = baseTimestamp;
}

/// @dev AggregatorV2V3Interface users are already responsible with
/// validating the values that they receive (e.g., revert if the spot price
/// of an asset is negative). Therefore, this contract omits validation.
function latestAnswer() external view override returns (int256 value) {
(value, ) = read();
}

/// @dev A Chainlink feed contract returns the block timestamp at which the
/// feed was last updated. On the other hand, an Api3 feed timestamp
/// denotes the point in time at which the first-party oracles signed the
/// data used to do the last update. We find this to be a reasonable
/// approximation, considering that usually the timestamp is only used to
/// check if the last update is stale.
function latestTimestamp()
external
view
override
returns (uint256 timestamp)
{
(, timestamp) = read();
}

/// @dev Api3 feeds are updated asynchronously and not in rounds
function latestRound() external pure override returns (uint256) {
revert FunctionIsNotSupported();
}

/// @dev Functions that use the round ID as an argument are not supported
function getAnswer(uint256) external pure override returns (int256) {
revert FunctionIsNotSupported();
}

/// @dev Functions that use the round ID as an argument are not supported
function getTimestamp(uint256) external pure override returns (uint256) {
revert FunctionIsNotSupported();
}

/// @dev Api3 feeds always use 18 decimals
function decimals() external pure override returns (uint8) {
return 18;
}

/// @dev Underlying proxy dApp ID and dAPI name act as the description, and
/// this is left empty to save gas on contract deployment
function description() external pure override returns (string memory) {
return "";
}

/// @dev A unique version is chosen to easily check if an unverified
/// contract that acts as a Chainlink feed is a InverseApi3ReaderProxyV1
function version() external pure override returns (uint256) {
return 4915;
}

/// @dev Functions that use the round ID as an argument are not supported
function getRoundData(
uint80
)
external
pure
override
returns (uint80, int256, uint256, uint256, uint80)
{
revert FunctionIsNotSupported();
}

/// @dev Rounds IDs are returned as `0` as invalid values.
/// Similar to `latestAnswer()`, we leave the validation of the returned
/// value to the caller.
function latestRoundData()
external
view
override
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
roundId = answeredInRound = 0;
(answer, startedAt) = read();
updatedAt = startedAt;
}
}
Loading