Skip to content

Commit f8f75a0

Browse files
authored
updated cdr pricer (#229)
1 parent afa12b2 commit f8f75a0

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Security contact: [[email protected]](mailto:[email protected]
1212
### Package organization
1313

1414
* [spot-contracts](./spot-contracts): SPOT protocol smart contracts.
15+
* [spot-vaults](./spot-vaults): Vault strategies leveraging the SPOT system.
1516
* [spot-subgraph](./spot-subgraph): Subgraph to index SPOT protocol on-chain data.
1617

1718
## Licensing
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity ^0.8.24;
33

4-
import { IAmpleforthOracle } from "./IAmpleforthOracle.sol";
5-
64
interface IAmpleforth {
7-
function cpiOracle() external view returns (IAmpleforthOracle);
5+
function getTargetRate() external returns (uint256, bool);
86
}

spot-vaults/contracts/_strategies/SpotCDRPricer.sol

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
66
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77
import { IPerpetualTranche } from "@ampleforthorg/spot-contracts/contracts/_interfaces/IPerpetualTranche.sol";
88
import { IChainlinkOracle } from "../_interfaces/external/IChainlinkOracle.sol";
9-
import { IAmpleforthOracle } from "../_interfaces/external/IAmpleforthOracle.sol";
9+
import { IAMPL } from "../_interfaces/external/IAMPL.sol";
10+
import { IAmpleforth } from "../_interfaces/external/IAmpleforth.sol";
1011
import { ISpotPricingStrategy } from "../_interfaces/ISpotPricingStrategy.sol";
1112

1213
/**
@@ -51,32 +52,23 @@ contract SpotCDRPricer is ISpotPricingStrategy {
5152
/// @notice Number of decimals representing the prices returned by the chainlink oracle.
5253
uint256 public immutable USD_ORACLE_DECIMALS;
5354

54-
/// @notice Address of the Ampleforth CPI oracle. (provides the inflation-adjusted target price for AMPL).
55-
IAmpleforthOracle public immutable AMPL_CPI_ORACLE;
56-
57-
/// @notice Number of decimals representing the prices returned by the ampleforth oracle.
58-
uint256 public immutable AMPL_CPI_ORACLE_DECIMALS;
55+
/// @notice Address of the Ampleforth monetary policy. (provides the inflation-adjusted target price for AMPL)
56+
IAmpleforth public immutable AMPLEFORTH_POLICY;
5957

6058
//-----------------------------------------------------------------------------
6159
// Constructor
6260

6361
/// @notice Contract constructor.
6462
/// @param spot Address of the SPOT token.
6563
/// @param usdOracle Address of the USD token market price oracle token.
66-
/// @param cpiOracle Address of the Ampleforth CPI oracle.
67-
constructor(
68-
IPerpetualTranche spot,
69-
IChainlinkOracle usdOracle,
70-
IAmpleforthOracle cpiOracle
71-
) {
64+
constructor(IPerpetualTranche spot, IChainlinkOracle usdOracle) {
7265
SPOT = spot;
7366
AMPL = IERC20(address(spot.underlying()));
7467

7568
USD_ORACLE = usdOracle;
7669
USD_ORACLE_DECIMALS = usdOracle.decimals();
7770

78-
AMPL_CPI_ORACLE = cpiOracle;
79-
AMPL_CPI_ORACLE_DECIMALS = cpiOracle.DECIMALS();
71+
AMPLEFORTH_POLICY = IAmpleforth(IAMPL(address(AMPL)).monetaryPolicy());
8072
}
8173

8274
//--------------------------------------------------------------------------
@@ -95,9 +87,9 @@ contract SpotCDRPricer is ISpotPricingStrategy {
9587
/// @return p The price of the spot token in dollar coins.
9688
/// @return v True if the price is valid and can be used by downstream consumers.
9789
function perpPrice() external override returns (uint256, bool) {
98-
// NOTE: Since {DECIMALS} == {AMPL_CPI_ORACLE_DECIMALS} == 18
90+
// NOTE: Since {DECIMALS} == {AMPLEFORTH_POLICY_DECIMALS} == 18
9991
// we don't adjust the returned values.
100-
(uint256 targetPrice, bool targetPriceValid) = AMPL_CPI_ORACLE.getData();
92+
(uint256 targetPrice, bool targetPriceValid) = AMPLEFORTH_POLICY.getTargetRate();
10193
uint256 p = targetPrice.mulDiv(SPOT.getTVL(), SPOT.totalSupply());
10294
return (p, targetPriceValid);
10395
}

spot-vaults/test/SpotCDRPricer.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ describe("SpotCDRPricer", function () {
1010
const accounts = await ethers.getSigners();
1111
const deployer = accounts[0];
1212

13-
const amplTargetOracle = new DMock("MedianOracle");
14-
await amplTargetOracle.deploy();
15-
await amplTargetOracle.mockMethod("getData()", [priceFP("1.15"), true]);
16-
await amplTargetOracle.mockMethod("DECIMALS()", [18]);
17-
18-
const policy = new DMock("UFragmentsPolicy");
13+
const policy = new DMock("IAmpleforth");
1914
await policy.deploy();
20-
await policy.mockMethod("cpiOracle()", [amplTargetOracle.target]);
15+
await policy.mockMethod("getTargetRate()", [priceFP("1.15"), true]);
2116

2217
const ampl = new DMock("UFragments");
2318
await ampl.deploy();
@@ -42,30 +37,26 @@ describe("SpotCDRPricer", function () {
4237
]);
4338

4439
const SpotCDRPricer = await ethers.getContractFactory("SpotCDRPricer");
45-
const strategy = await SpotCDRPricer.deploy(
46-
spot.target,
47-
usdPriceOrcle.target,
48-
amplTargetOracle.target,
49-
);
40+
const strategy = await SpotCDRPricer.deploy(spot.target, usdPriceOrcle.target);
5041
return {
5142
deployer,
5243
ampl,
5344
spot,
5445
usdPriceOrcle,
55-
amplTargetOracle,
46+
policy,
5647
strategy,
5748
};
5849
}
5950

6051
describe("init", function () {
6152
it("should initial params", async function () {
62-
const { strategy, ampl, spot, usdPriceOrcle, amplTargetOracle } = await loadFixture(
53+
const { strategy, ampl, spot, usdPriceOrcle, policy } = await loadFixture(
6354
setupContracts,
6455
);
6556
expect(await strategy.AMPL()).to.eq(ampl.target);
6657
expect(await strategy.SPOT()).to.eq(spot.target);
6758
expect(await strategy.USD_ORACLE()).to.eq(usdPriceOrcle.target);
68-
expect(await strategy.AMPL_CPI_ORACLE()).to.eq(amplTargetOracle.target);
59+
expect(await strategy.AMPLEFORTH_POLICY()).to.eq(policy.target);
6960
expect(await strategy.decimals()).to.eq(18);
7061
});
7162
});
@@ -130,8 +121,8 @@ describe("SpotCDRPricer", function () {
130121
describe("#perpPrice", function () {
131122
describe("when AMPL target data is invalid", function () {
132123
it("should return invalid", async function () {
133-
const { strategy, amplTargetOracle } = await loadFixture(setupContracts);
134-
await amplTargetOracle.mockMethod("getData()", [priceFP("1.2"), false]);
124+
const { strategy, policy } = await loadFixture(setupContracts);
125+
await policy.mockMethod("getTargetRate()", [priceFP("1.2"), false]);
135126
const p = await strategy.perpPrice.staticCall();
136127
expect(p[0]).to.eq(priceFP("1.2"));
137128
expect(p[1]).to.eq(false);

0 commit comments

Comments
 (0)