-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #862 from ionicprotocol/development
merge
- Loading branch information
Showing
28 changed files
with
10,257 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/contracts/chainDeploy/helpers/oracles/velodromeFraxtal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { prepareAndLogTransaction } from "../logging"; | ||
import { DeployResult } from "hardhat-deploy/types"; | ||
import { Address, Hex } from "viem"; | ||
|
||
import { addUnderlyingsToMpo } from "./utils"; | ||
import { underlying } from "../utils"; | ||
import { AerodromeDeployFnParams } from "../../types"; | ||
|
||
export const deployVelodromeOracleFraxtal = async ({ | ||
viem, | ||
getNamedAccounts, | ||
deployments, | ||
pricesContract, | ||
assets | ||
}: AerodromeDeployFnParams): Promise<{ apo: DeployResult }> => { | ||
const { deployer } = await getNamedAccounts(); | ||
const publicClient = await viem.getPublicClient(); | ||
let tx: Hex; | ||
|
||
//// Velodrome Oracle | ||
const apo = await deployments.deploy("VelodromePriceOracleFraxtal", { | ||
from: deployer, | ||
args: [pricesContract], | ||
log: true, | ||
waitConfirmations: 1 | ||
}); | ||
if (apo.transactionHash) await publicClient.waitForTransactionReceipt({ hash: apo.transactionHash as Address }); | ||
console.log("VelodromePriceOracleFraxtal: ", apo.address); | ||
|
||
const velodrome = await viem.getContractAt( | ||
"VelodromePriceOracleFraxtal", | ||
(await deployments.get("VelodromePriceOracleFraxtal")).address as Address | ||
); | ||
|
||
const underlyings = assets.map((c) => underlying(assets, c.symbol)); | ||
|
||
const mpo = await viem.getContractAt( | ||
"MasterPriceOracle", | ||
(await deployments.get("MasterPriceOracle")).address as Address | ||
); | ||
console.log("underlyings: ", underlyings); | ||
await addUnderlyingsToMpo(mpo as any, underlyings, velodrome.address, deployer, publicClient); | ||
|
||
const addressesProvider = await viem.getContractAt( | ||
"AddressesProvider", | ||
(await deployments.get("AddressesProvider")).address as Address | ||
); | ||
const velodromeAddress = await addressesProvider.read.getAddress(["VelodromePriceOracleFraxtal"]); | ||
if (velodromeAddress !== velodrome.address) { | ||
if (((await addressesProvider.read.owner()) as Address).toLowerCase() === deployer.toLowerCase()) { | ||
tx = await addressesProvider.write.setAddress(["VelodromePriceOracleFraxtal", velodrome.address]); | ||
await publicClient.waitForTransactionReceipt({ hash: tx }); | ||
console.log(`setAddress VelodromePriceOracleFraxtal at ${tx}`); | ||
} else { | ||
await prepareAndLogTransaction({ | ||
contractInstance: addressesProvider, | ||
functionName: "setAddress", | ||
args: ["VelodromePriceOracleFraxtal", velodrome.address], | ||
description: "Set VelodromePriceOracleFraxtal address on AddressProvider", | ||
inputs: [ | ||
{ internalType: "string", name: "id", type: "string" }, | ||
{ internalType: "address", name: "newAddress", type: "address" } | ||
] | ||
}); | ||
console.log("Logged Transaction to setAddress VelodromePriceOracleFraxtal on AddressProvider"); | ||
} | ||
} | ||
|
||
return { apo }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/contracts/contracts/oracles/default/VelodromePriceOracleFraxtal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.0; | ||
|
||
import "../BasePriceOracle.sol"; | ||
|
||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
interface Prices { | ||
function getRate(address srcToken, address dstToken, bool useSrcWrappers) external view returns (uint256 weightedRate); | ||
} | ||
|
||
contract VelodromePriceOracleFraxtal is BasePriceOracle { | ||
Prices immutable prices; | ||
|
||
constructor(address _prices) { | ||
prices = Prices(_prices); | ||
} | ||
/** | ||
* @notice Fetches the token/ETH price, with 18 decimals of precision. | ||
* @param underlying The underlying token address for which to get the price. | ||
* @return Price denominated in ETH (scaled by 1e18) | ||
*/ | ||
function price(address underlying) external view override returns (uint256) { | ||
return _price(underlying); | ||
} | ||
|
||
/** | ||
* @notice Returns the price in ETH of the token underlying `cToken`. | ||
* @dev Implements the `PriceOracle` interface for Ionic pools (and Compound v2). | ||
* @return Price in ETH of the token underlying `cToken`, scaled by `10 ** (36 - underlyingDecimals)`. | ||
*/ | ||
function getUnderlyingPrice(ICErc20 cToken) external view override returns (uint256) { | ||
address underlying = cToken.underlying(); | ||
// Comptroller needs prices to be scaled by 1e(36 - decimals) | ||
// Since `_price` returns prices scaled by 18 decimals, we must scale them by 1e(36 - 18 - decimals) | ||
return (_price(underlying)); | ||
} | ||
|
||
/** | ||
* @notice Fetches the token/ETH price, with 18 decimals of precision. | ||
*/ | ||
function _price(address token) internal view returns (uint256) { | ||
return prices.getRate(token, 0xFC00000000000000000000000000000000000006, false); | ||
} | ||
} |
Oops, something went wrong.