Skip to content

Commit e9380e5

Browse files
committed
Merge branch 'main' of github.com:protofire/AAVEV3-Fork
2 parents f14b609 + 9e97d35 commit e9380e5

File tree

12 files changed

+816
-7
lines changed

12 files changed

+816
-7
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: agpl-3.0
2+
pragma solidity ^0.8.0;
3+
4+
import './interfaces/IChainlinkAggregator.sol';
5+
6+
contract USDOXChainlinkPriceAggregator is IChainlinkAggregator {
7+
int256 public USDOX_USD_PRICE = 100000000; // $1.00 USD with 8 decimals
8+
uint256 public currentRoundId = 1;
9+
10+
// Stores the price for each round ID
11+
mapping(uint256 => int256) private roundAnswers;
12+
13+
// Stores the timestamp for each round ID
14+
mapping(uint256 => uint256) private roundTimestamps;
15+
16+
event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
17+
event NewRound(uint256 indexed roundId, address indexed startedBy);
18+
19+
/**
20+
* @notice Returns the number of decimals for the price feed.
21+
* @dev Chainlink price feeds typically use 8 decimals.
22+
*/
23+
function decimals() external view override returns (uint8) {
24+
return 8;
25+
}
26+
27+
function aggregator() external view returns (address) {
28+
return address(this);
29+
}
30+
31+
function description() external view override returns (string memory) {
32+
return 'USDOX / USD';
33+
}
34+
35+
/**
36+
* @notice Returns the latest USDOX/USD price with 8 decimals.
37+
* The price is fixed at $1.00 USD per USDOX by default.
38+
*/
39+
function latestAnswer() external view override returns (int256) {
40+
return USDOX_USD_PRICE;
41+
}
42+
43+
/**
44+
* @notice Returns the latest timestamp when the price was updated.
45+
*/
46+
function latestTimestamp() external view override returns (uint256) {
47+
return roundTimestamps[currentRoundId];
48+
}
49+
50+
/**
51+
* @notice Returns the latest round ID.
52+
*/
53+
function latestRound() external view override returns (uint256) {
54+
return currentRoundId;
55+
}
56+
57+
/**
58+
* @notice Returns the price for a specific round.
59+
* @param roundId The round ID to query.
60+
*/
61+
function getAnswer(uint256 roundId) external view override returns (int256) {
62+
return roundAnswers[roundId];
63+
}
64+
65+
/**
66+
* @notice Returns the timestamp for a specific round.
67+
* @param roundId The round ID to query.
68+
*/
69+
function getTimestamp(uint256 roundId) external view override returns (uint256) {
70+
return roundTimestamps[roundId];
71+
}
72+
73+
/**
74+
* @notice Sets a new USDOX/USD price for testing purposes.
75+
* @dev This function should only be available in test environments.
76+
* @param newPrice The new price to set.
77+
*/
78+
function setPrice(int256 newPrice) external {
79+
USDOX_USD_PRICE = newPrice;
80+
emit AnswerUpdated(newPrice, currentRoundId, block.timestamp);
81+
_startNewRound(newPrice);
82+
}
83+
84+
/**
85+
* @notice Internal function to start a new round.
86+
* Emits the `NewRound` event.
87+
* @param newPrice The price to associate with the new round.
88+
*/
89+
function _startNewRound(int256 newPrice) internal {
90+
currentRoundId++;
91+
roundAnswers[currentRoundId] = newPrice;
92+
roundTimestamps[currentRoundId] = block.timestamp;
93+
94+
emit NewRound(currentRoundId, msg.sender);
95+
}
96+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: agpl-3.0
2+
pragma solidity ^0.8.0;
3+
4+
import './interfaces/IChainlinkAggregator.sol';
5+
6+
contract WSTZBUChainlinkPriceAggregator is IChainlinkAggregator {
7+
int256 public WSTZBU_USD_PRICE = 518000000; // $5.18 USD with 8 decimals
8+
uint256 public currentRoundId = 1;
9+
10+
// Stores the price for each round ID
11+
mapping(uint256 => int256) private roundAnswers;
12+
13+
// Stores the timestamp for each round ID
14+
mapping(uint256 => uint256) private roundTimestamps;
15+
16+
event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
17+
event NewRound(uint256 indexed roundId, address indexed startedBy);
18+
19+
/**
20+
* @notice Returns the number of decimals for the price feed.
21+
* @dev Chainlink price feeds typically use 8 decimals.
22+
*/
23+
function decimals() external view override returns (uint8) {
24+
return 8;
25+
}
26+
27+
function aggregator() external view returns (address) {
28+
return address(this);
29+
}
30+
31+
function description() external view override returns (string memory) {
32+
return 'WSTZBU / USD';
33+
}
34+
35+
/**
36+
* @notice Returns the latest WSTZBU/USD price with 8 decimals.
37+
* The price is fixed at $1.00 USD per WSTZBU by default.
38+
*/
39+
function latestAnswer() external view override returns (int256) {
40+
return WSTZBU_USD_PRICE;
41+
}
42+
43+
/**
44+
* @notice Returns the latest timestamp when the price was updated.
45+
*/
46+
function latestTimestamp() external view override returns (uint256) {
47+
return roundTimestamps[currentRoundId];
48+
}
49+
50+
/**
51+
* @notice Returns the latest round ID.
52+
*/
53+
function latestRound() external view override returns (uint256) {
54+
return currentRoundId;
55+
}
56+
57+
/**
58+
* @notice Returns the price for a specific round.
59+
* @param roundId The round ID to query.
60+
*/
61+
function getAnswer(uint256 roundId) external view override returns (int256) {
62+
return roundAnswers[roundId];
63+
}
64+
65+
/**
66+
* @notice Returns the timestamp for a specific round.
67+
* @param roundId The round ID to query.
68+
*/
69+
function getTimestamp(uint256 roundId) external view override returns (uint256) {
70+
return roundTimestamps[roundId];
71+
}
72+
73+
/**
74+
* @notice Sets a new WSTZBU/USD price for testing purposes.
75+
* @dev This function should only be available in test environments.
76+
* @param newPrice The new price to set.
77+
*/
78+
function setPrice(int256 newPrice) external {
79+
WSTZBU_USD_PRICE = newPrice;
80+
emit AnswerUpdated(newPrice, currentRoundId, block.timestamp);
81+
_startNewRound(newPrice);
82+
}
83+
84+
/**
85+
* @notice Internal function to start a new round.
86+
* Emits the `NewRound` event.
87+
* @param newPrice The price to associate with the new round.
88+
*/
89+
function _startNewRound(int256 newPrice) internal {
90+
currentRoundId++;
91+
roundAnswers[currentRoundId] = newPrice;
92+
roundTimestamps[currentRoundId] = block.timestamp;
93+
94+
emit NewRound(currentRoundId, msg.sender);
95+
}
96+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: agpl-3.0
2+
pragma solidity ^0.8.0;
3+
4+
import './interfaces/IChainlinkAggregator.sol';
5+
6+
contract ZBUChainlinkPriceAggregator is IChainlinkAggregator {
7+
int256 public ZBU_USD_PRICE = 518000000; // $5.18 USD with 8 decimals
8+
uint256 public currentRoundId = 1;
9+
10+
// Stores the price for each round ID
11+
mapping(uint256 => int256) private roundAnswers;
12+
13+
// Stores the timestamp for each round ID
14+
mapping(uint256 => uint256) private roundTimestamps;
15+
16+
event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
17+
event NewRound(uint256 indexed roundId, address indexed startedBy);
18+
19+
/**
20+
* @notice Returns the number of decimals for the price feed.
21+
* @dev Chainlink price feeds typically use 8 decimals.
22+
*/
23+
function decimals() external view override returns (uint8) {
24+
return 8;
25+
}
26+
27+
function aggregator() external view returns (address) {
28+
return address(this);
29+
}
30+
31+
function description() external view override returns (string memory) {
32+
return 'ZBU / USD';
33+
}
34+
35+
/**
36+
* @notice Returns the latest ZBU/USD price with 8 decimals.
37+
* The price is fixed at $2.00 USD per ZBU by default.
38+
*/
39+
function latestAnswer() external view override returns (int256) {
40+
return ZBU_USD_PRICE;
41+
}
42+
43+
/**
44+
* @notice Returns the latest timestamp when the price was updated.
45+
*/
46+
function latestTimestamp() external view override returns (uint256) {
47+
return roundTimestamps[currentRoundId];
48+
}
49+
50+
/**
51+
* @notice Returns the latest round ID.
52+
*/
53+
function latestRound() external view override returns (uint256) {
54+
return currentRoundId;
55+
}
56+
57+
/**
58+
* @notice Returns the price for a specific round.
59+
* @param roundId The round ID to query.
60+
*/
61+
function getAnswer(uint256 roundId) external view override returns (int256) {
62+
return roundAnswers[roundId];
63+
}
64+
65+
/**
66+
* @notice Returns the timestamp for a specific round.
67+
* @param roundId The round ID to query.
68+
*/
69+
function getTimestamp(uint256 roundId) external view override returns (uint256) {
70+
return roundTimestamps[roundId];
71+
}
72+
73+
/**
74+
* @notice Sets a new ZBU/USD price for testing purposes.
75+
* @dev This function should only be available in test environments.
76+
* @param newPrice The new price to set.
77+
*/
78+
function setPrice(int256 newPrice) external {
79+
ZBU_USD_PRICE = newPrice;
80+
emit AnswerUpdated(newPrice, currentRoundId, block.timestamp);
81+
_startNewRound(newPrice);
82+
}
83+
84+
/**
85+
* @notice Internal function to start a new round.
86+
* Emits the `NewRound` event.
87+
* @param newPrice The price to associate with the new round.
88+
*/
89+
function _startNewRound(int256 newPrice) internal {
90+
currentRoundId++;
91+
roundAnswers[currentRoundId] = newPrice;
92+
roundTimestamps[currentRoundId] = block.timestamp;
93+
94+
emit NewRound(currentRoundId, msg.sender);
95+
}
96+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: agpl-3.0
2+
pragma solidity ^0.8.0;
3+
4+
// Full interface for Chainlink Aggregator
5+
interface IChainlinkAggregator {
6+
function decimals() external view returns (uint8);
7+
8+
function latestAnswer() external view returns (int256);
9+
10+
function latestTimestamp() external view returns (uint256);
11+
12+
function latestRound() external view returns (uint256);
13+
14+
function getAnswer(uint256 roundId) external view returns (int256);
15+
16+
function getTimestamp(uint256 roundId) external view returns (uint256);
17+
18+
function description() external view returns (string memory);
19+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { POOL_ADMIN } from "./../../helpers/constants";
2+
import { eNetwork } from "./../../helpers/types";
3+
import { MARKET_NAME } from "./../../helpers/env";
4+
import {
5+
loadPoolConfig,
6+
isTestnetMarket,
7+
} from "./../../helpers/market-config-helpers";
8+
import { HardhatRuntimeEnvironment } from "hardhat/types";
9+
import { DeployFunction } from "hardhat-deploy/types";
10+
import { COMMON_DEPLOY_PARAMS } from "../../helpers/env";
11+
import {
12+
ZBUChainlinkPriceAggregator,
13+
ZBUChainlinkPriceAggregator__factory,
14+
} from "../../typechain";
15+
16+
const ZBU_PRICE_AGGREGATOR_ID = "ZBUPriceAggregator";
17+
18+
const func: DeployFunction = async function ({
19+
getNamedAccounts,
20+
deployments,
21+
...hre
22+
}: HardhatRuntimeEnvironment) {
23+
const { deploy, save } = deployments;
24+
const { deployer } = await getNamedAccounts();
25+
26+
const network = (process.env.FORK || hre.network.name) as eNetwork;
27+
let priceAggregatorOwner = POOL_ADMIN[network];
28+
29+
if (isTestnetMarket(await loadPoolConfig(MARKET_NAME))) {
30+
priceAggregatorOwner = deployer;
31+
} else {
32+
priceAggregatorOwner = deployer;
33+
}
34+
35+
const priceAggregatorArtifact = await deploy(ZBU_PRICE_AGGREGATOR_ID, {
36+
from: deployer,
37+
contract: "ZBUChainlinkPriceAggregator",
38+
args: [],
39+
...COMMON_DEPLOY_PARAMS,
40+
});
41+
42+
const priceAggregator = (await hre.ethers.getContractAt(priceAggregatorArtifact.abi, priceAggregatorArtifact.address)) as ZBUChainlinkPriceAggregator;
43+
44+
await save(ZBU_PRICE_AGGREGATOR_ID, {
45+
address: priceAggregatorArtifact.address,
46+
abi: ZBUChainlinkPriceAggregator__factory.abi,
47+
});
48+
49+
try {
50+
await hre.run("verify:verify", {
51+
address: priceAggregatorArtifact.address,
52+
constructorArguments: [],
53+
libraries: {},
54+
});
55+
} catch (error) {
56+
console.error(error);
57+
}
58+
59+
return true;
60+
};
61+
62+
func.tags = ["ZBUPriceAggregator"];
63+
func.dependencies = [];
64+
func.id = "ZBUPriceAggregator";
65+
66+
export default func;

0 commit comments

Comments
 (0)