Skip to content

Commit b36d88a

Browse files
committed
Merge branch 'release/v4.7.3'
2 parents fa5dafd + 573b441 commit b36d88a

File tree

6 files changed

+221
-9
lines changed

6 files changed

+221
-9
lines changed

contracts/oracles/ManagedCurrentAggregatorOracle.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ contract ManagedCurrentAggregatorOracle is CurrentAggregatorOracle, ManagedCurre
9191
if (address(tokenConfig) != address(0)) {
9292
return tokenConfig.minimumResponses();
9393
}
94+
tokenConfig = tokenConfigs[address(0)]; // Default config
95+
if (address(tokenConfig) != address(0)) {
96+
return tokenConfig.minimumResponses();
97+
}
9498

9599
return super._minimumResponses(token);
96100
}
@@ -100,6 +104,10 @@ contract ManagedCurrentAggregatorOracle is CurrentAggregatorOracle, ManagedCurre
100104
if (address(tokenConfig) != address(0)) {
101105
return tokenConfig.aggregationStrategy();
102106
}
107+
tokenConfig = tokenConfigs[address(0)]; // Default config
108+
if (address(tokenConfig) != address(0)) {
109+
return tokenConfig.aggregationStrategy();
110+
}
103111

104112
return super._aggregationStrategy(token);
105113
}
@@ -109,6 +117,10 @@ contract ManagedCurrentAggregatorOracle is CurrentAggregatorOracle, ManagedCurre
109117
if (address(tokenConfig) != address(0)) {
110118
return tokenConfig.validationStrategy();
111119
}
120+
tokenConfig = tokenConfigs[address(0)]; // Default config
121+
if (address(tokenConfig) != address(0)) {
122+
return tokenConfig.validationStrategy();
123+
}
112124

113125
return super._validationStrategy(token);
114126
}
@@ -118,6 +130,10 @@ contract ManagedCurrentAggregatorOracle is CurrentAggregatorOracle, ManagedCurre
118130
if (address(tokenConfig) != address(0)) {
119131
return tokenConfig.oracles();
120132
}
133+
tokenConfig = tokenConfigs[address(0)]; // Default config
134+
if (address(tokenConfig) != address(0)) {
135+
return tokenConfig.oracles();
136+
}
121137

122138
return super._getOracles(token);
123139
}

contracts/oracles/ManagedPeriodicAggregatorOracle.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ contract ManagedPeriodicAggregatorOracle is PeriodicAggregatorOracle, ManagedAgg
7575
if (address(tokenConfig) != address(0)) {
7676
return tokenConfig.minimumResponses();
7777
}
78+
tokenConfig = tokenConfigs[address(0)]; // Default config
79+
if (address(tokenConfig) != address(0)) {
80+
return tokenConfig.minimumResponses();
81+
}
7882

7983
return super._minimumResponses(token);
8084
}
@@ -84,6 +88,10 @@ contract ManagedPeriodicAggregatorOracle is PeriodicAggregatorOracle, ManagedAgg
8488
if (address(tokenConfig) != address(0)) {
8589
return tokenConfig.aggregationStrategy();
8690
}
91+
tokenConfig = tokenConfigs[address(0)]; // Default config
92+
if (address(tokenConfig) != address(0)) {
93+
return tokenConfig.aggregationStrategy();
94+
}
8795

8896
return super._aggregationStrategy(token);
8997
}
@@ -93,6 +101,10 @@ contract ManagedPeriodicAggregatorOracle is PeriodicAggregatorOracle, ManagedAgg
93101
if (address(tokenConfig) != address(0)) {
94102
return tokenConfig.validationStrategy();
95103
}
104+
tokenConfig = tokenConfigs[address(0)]; // Default config
105+
if (address(tokenConfig) != address(0)) {
106+
return tokenConfig.validationStrategy();
107+
}
96108

97109
return super._validationStrategy(token);
98110
}
@@ -102,6 +114,10 @@ contract ManagedPeriodicAggregatorOracle is PeriodicAggregatorOracle, ManagedAgg
102114
if (address(tokenConfig) != address(0)) {
103115
return tokenConfig.oracles();
104116
}
117+
tokenConfig = tokenConfigs[address(0)]; // Default config
118+
if (address(tokenConfig) != address(0)) {
119+
return tokenConfig.oracles();
120+
}
105121

106122
return super._getOracles(token);
107123
}

contracts/oracles/bases/ManagedAggregatorOracleBase.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ abstract contract ManagedAggregatorOracleBase is ManagedOracleBase {
4242
constructor() ManagedOracleBase() {}
4343

4444
/**
45-
* @notice Sets a new configuration for a specific token.
45+
* @notice Sets a new configuration for a token.
4646
* @dev This configuration is for the strategies, minimum responses, and underlying oracles.
47-
* @param token The token to set the configuration for.
48-
* @param newConfig The new token configuration.
47+
* @param token The token to set the configuration for. Use address(0) to set the default configuration.
48+
* @param newConfig The new token configuration. Use address(0) to remove the configuration so that the default
49+
* configuration is used.
4950
*/
5051
function setTokenConfig(
5152
address token,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adrastia-oracle/adrastia-periphery",
3-
"version": "4.7.2",
3+
"version": "4.7.3",
44
"main": "index.js",
55
"author": "TRILEZ SOFTWARE INC.",
66
"license": "BUSL-1.1",

scripts/oracles/deploy-oracle-aggregator-config.js

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,80 @@ const hre = require("hardhat");
22

33
const ethers = hre.ethers;
44

5+
const aggregationStrategies = {
6+
arbitrum: {
7+
median: "0xC7E8e1daB09e7E29cda87C32DBDf34b8E2859003",
8+
minimum: "0xC2273620B48BBbC38D193B7aaa05A9594668c0D6",
9+
maximum: "0xc5DFF7Ce4A8D6B98c6eb70ACa1C5527d8147e539",
10+
},
11+
optimism: {
12+
median: "0x2a0755Ca1EbcB9c37C883c09DE5202b3cc7b7470",
13+
minimum: "0x248Ab376F7dB8B06e7c9EA1dE3E746d47Ee489c3",
14+
maximum: "0x10E514cEF50424306eDD391b2d4cB016930E1cc2",
15+
},
16+
polygon: {
17+
median: "0x021e3bd203144ae330a766d4076040a48fea6122",
18+
minimum: "0x90C8E14d36bfc6ea6c871F5874eE095631d4eDC6",
19+
maximum: "0x92Eb6895550Fd2EFc1519De69f8b85A819A1fDC1",
20+
},
21+
};
22+
23+
const oracles = {
24+
arbitrum: {
25+
"chainlink-eth-usd": "0x8aC5f2E2960fb3d022cD45f5410201c5bFc95891",
26+
"pyth-eth-usd": "0x4e22Ea0CB77B5aE0085551EF0fC5026C82c07e1D",
27+
"median-dao-usd": "0x41F14ed7e7E8034a5EB4EC72BdE3C94F91ECfa10",
28+
"liquidation-oracle-usd": "0x9EdaB5295260AC27c13564E4827b73408C132270",
29+
},
30+
optimism: {
31+
"chainlink-eth-usd": "0x00922ad039612B8b2DD9a8b10e6a834cec74B9DC",
32+
"pyth-eth-usd": "0xc68a2bBfE00786B2710FfDe68e03Fa80654280Ce",
33+
"median-dao-usd": "0x4Ace7Ed2941774FE9Ec58e0CeD53F91fCFe7e4cc",
34+
"liquidation-oracle-usd": "0x8950365aAAe83aa8CFAD779457423ac2D8FF8Ce0",
35+
},
36+
polygon: {
37+
"chainlink-eth-usd": "0xeb0FF74b91F46b1d5BB4402736D6DFEfc1B0f532",
38+
"pyth-eth-usd": "0x9b5b125dae8e21eb0207430c229f11198bd116fc",
39+
"median-dao-usd": "0xe6D09cD4a7f59B1be72513E7F3BA425b81e00948",
40+
"liquidation-oracle-usd": "0x0D32b0B3D75Ad5209BAA2DC8E0E7a2cF698a5551",
41+
},
42+
};
43+
544
async function main() {
45+
const chain = "optimism";
46+
647
// The address of the aggregation strategy.
7-
const aggregationStrategy = "";
48+
const aggregationStrategy = aggregationStrategies[chain].maximum;
849

950
// The address of the validation strategy. Can be the zero address to skip validation.
10-
const validationStrategy = "";
51+
const validationStrategy = ethers.constants.AddressZero;
1152

1253
// The minimum number of underlying oracle responses required to perform an update.
13-
const minimumResponses = 1;
54+
const minimumResponses = 2;
1455

1556
// An array of the underlying oracle addresses.
16-
const oracles = [];
57+
const oracles_ = [oracles[chain]["median-dao-usd"], oracles[chain]["liquidation-oracle-usd"]];
1758

1859
const factory = await ethers.getContractFactory("OracleAggregatorTokenConfig");
19-
const config = await factory.deploy(aggregationStrategy, validationStrategy, minimumResponses, oracles);
60+
const config = await factory.deploy(aggregationStrategy, validationStrategy, minimumResponses, oracles_);
2061
await config.deployed();
2162

2263
console.log("OracleAggregatorTokenConfig deployed to:", config.address);
2364

65+
console.log("Waiting for 30 seconds...");
66+
67+
await new Promise((resolve) => setTimeout(resolve, 30000));
68+
69+
console.log("Verifying contract...");
70+
71+
const contractAddress = config.address;
72+
73+
await hre.run("verify:verify", {
74+
contract: "contracts/oracles/configs/OracleAggregatorTokenConfig.sol:OracleAggregatorTokenConfig",
75+
address: contractAddress,
76+
constructorArguments: [aggregationStrategy, validationStrategy, minimumResponses, oracles_],
77+
});
78+
2479
console.log("Done");
2580
}
2681

test/oracles/managed-aggregator-oracle.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
507507
var tokenConfigFactory;
508508

509509
var alternativeTokenConfig;
510+
var alternativeTokenConfig2;
510511

511512
var oracleStub1;
512513
var oracleStub2;
@@ -519,6 +520,8 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
519520

520521
var newAggregationStrategy;
521522
var newValidationStrategy;
523+
var newAggregationStrategy2;
524+
var newValidationStrategy2;
522525

523526
beforeEach(async function () {
524527
const aggregatorDeployment = await deployFunction();
@@ -549,7 +552,9 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
549552
DEFAULT_AGGREGATION_STRATEGY_BYTECODE
550553
);
551554
newAggregationStrategy = await aggregationStrategyFactory.deploy(newAveragingStrategy.address);
555+
newAggregationStrategy2 = await aggregationStrategyFactory.deploy(newAveragingStrategy.address);
552556
await newAggregationStrategy.deployed();
557+
await newAggregationStrategy2.deployed();
553558

554559
const validationStrategyFactory = await ethers.getContractFactory(
555560
DEFAULT_VALIDATION_STRATEGY_ABI,
@@ -562,7 +567,15 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
562567
1,
563568
100000
564569
);
570+
newValidationStrategy2 = await validationStrategyFactory.deploy(
571+
DEFAULT_QUOTE_TOKEN_DECIMALS,
572+
0,
573+
0,
574+
1,
575+
100000
576+
);
565577
await newValidationStrategy.deployed();
578+
await newValidationStrategy2.deployed();
566579

567580
const oracleStubFactory = await ethers.getContractFactory("MockOracle");
568581
oracleStub1 = await oracleStubFactory.deploy(DEFAULT_QUOTE_TOKEN_ADDRESS, DEFAULT_LIQUIDITY_DECIMALS);
@@ -589,6 +602,12 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
589602
2,
590603
[oracleStub1.address, oracleStub2.address]
591604
);
605+
alternativeTokenConfig2 = await tokenConfigFactory.deploy(
606+
newAggregationStrategy2.address,
607+
newValidationStrategy2.address,
608+
3,
609+
[oracleStub1.address, oracleStub2.address, oracleStub3.address]
610+
);
592611
});
593612

594613
it("Overrides the default config", async function () {
@@ -612,6 +631,111 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
612631
expect(await oracle.getOracles(GRT)).to.not.have.lengthOf(1);
613632
});
614633

634+
it("Changes the default config", async function () {
635+
const tx = await oracle.setTokenConfig(ethers.constants.AddressZero, alternativeTokenConfig.address);
636+
const receipt = await tx.wait();
637+
638+
expect(receipt)
639+
.to.emit(oracle, "TokenConfigUpdated")
640+
.withArgs(ethers.constants.AddressZero, ethers.constants.AddressZero, alternativeTokenConfig.address);
641+
642+
// Check that the functions return the new values
643+
expect(await oracle.aggregationStrategy(WETH)).to.equal(await alternativeTokenConfig.aggregationStrategy());
644+
expect(await oracle.validationStrategy(WETH)).to.equal(await alternativeTokenConfig.validationStrategy());
645+
expect(await oracle.minimumResponses(WETH)).to.equal(await alternativeTokenConfig.minimumResponses());
646+
expect(await oracle.getOracles(WETH)).to.eql(await alternativeTokenConfig.oracles()); // eql = deep equality
647+
648+
// Sanity check that the functions return values other than the default
649+
expect(await oracle.aggregationStrategy(WETH)).to.not.equal(aggregationStrategy);
650+
expect(await oracle.validationStrategy(WETH)).to.not.equal(validationStrategy);
651+
expect(await oracle.minimumResponses(WETH)).to.not.equal(1);
652+
expect(await oracle.getOracles(WETH)).to.not.have.lengthOf(1);
653+
});
654+
655+
it("Changing the default config does not affect the token-specific config", async function () {
656+
// Set a token-specific config
657+
const tx = await oracle.setTokenConfig(WETH, alternativeTokenConfig2.address);
658+
const receipt = await tx.wait();
659+
660+
expect(receipt)
661+
.to.emit(oracle, "TokenConfigUpdated")
662+
.withArgs(WETH, ethers.constants.AddressZero, alternativeTokenConfig2.address);
663+
664+
// Check that the functions return the new values
665+
expect(await oracle.aggregationStrategy(WETH)).to.equal(
666+
await alternativeTokenConfig2.aggregationStrategy()
667+
);
668+
expect(await oracle.validationStrategy(WETH)).to.equal(await alternativeTokenConfig2.validationStrategy());
669+
expect(await oracle.minimumResponses(WETH)).to.equal(await alternativeTokenConfig2.minimumResponses());
670+
expect(await oracle.getOracles(WETH)).to.eql(await alternativeTokenConfig2.oracles()); // eql = deep equality
671+
672+
// Change the default config
673+
const tx2 = await oracle.setTokenConfig(ethers.constants.AddressZero, alternativeTokenConfig.address);
674+
const receipt2 = await tx2.wait();
675+
676+
expect(receipt2)
677+
.to.emit(oracle, "TokenConfigUpdated")
678+
.withArgs(ethers.constants.AddressZero, ethers.constants.AddressZero, alternativeTokenConfig.address);
679+
680+
// Check that the token-specific config is still the same
681+
expect(await oracle.aggregationStrategy(WETH)).to.equal(
682+
await alternativeTokenConfig2.aggregationStrategy()
683+
);
684+
expect(await oracle.validationStrategy(WETH)).to.equal(await alternativeTokenConfig2.validationStrategy());
685+
expect(await oracle.minimumResponses(WETH)).to.equal(await alternativeTokenConfig2.minimumResponses());
686+
expect(await oracle.getOracles(WETH)).to.eql(await alternativeTokenConfig2.oracles()); // eql = deep equality
687+
});
688+
689+
it("The config reverts to the default if the new config is the zero address", async function () {
690+
// First set the config to something other than the default
691+
const tx = await oracle.setTokenConfig(GRT, alternativeTokenConfig.address);
692+
const receipt = await tx.wait();
693+
expect(receipt)
694+
.to.emit(oracle, "TokenConfigUpdated")
695+
.withArgs(GRT, ethers.constants.AddressZero, alternativeTokenConfig.address);
696+
697+
// Then set the config to the zero address
698+
const tx2 = await oracle.setTokenConfig(GRT, ethers.constants.AddressZero);
699+
const receipt2 = await tx2.wait();
700+
expect(receipt2)
701+
.to.emit(oracle, "TokenConfigUpdated")
702+
.withArgs(GRT, alternativeTokenConfig.address, ethers.constants.AddressZero);
703+
704+
expect(await oracle.aggregationStrategy(GRT)).to.equal(aggregationStrategy);
705+
expect(await oracle.validationStrategy(GRT)).to.equal(validationStrategy);
706+
expect(await oracle.minimumResponses(GRT)).to.equal(1);
707+
expect(await oracle.getOracles(GRT)).to.have.lengthOf(1);
708+
});
709+
710+
it("The config reverts to a new default if the new config is the zero address", async function () {
711+
// Change the default config
712+
const tx1 = await oracle.setTokenConfig(ethers.constants.AddressZero, alternativeTokenConfig2.address);
713+
const receipt1 = await tx1.wait();
714+
715+
expect(receipt1)
716+
.to.emit(oracle, "TokenConfigUpdated")
717+
.withArgs(ethers.constants.AddressZero, ethers.constants.AddressZero, alternativeTokenConfig2.address);
718+
719+
// Set the config to something other than the default
720+
const tx = await oracle.setTokenConfig(GRT, alternativeTokenConfig.address);
721+
const receipt = await tx.wait();
722+
expect(receipt)
723+
.to.emit(oracle, "TokenConfigUpdated")
724+
.withArgs(GRT, ethers.constants.AddressZero, alternativeTokenConfig.address);
725+
726+
// Then set the config to the zero address
727+
const tx2 = await oracle.setTokenConfig(GRT, ethers.constants.AddressZero);
728+
const receipt2 = await tx2.wait();
729+
expect(receipt2)
730+
.to.emit(oracle, "TokenConfigUpdated")
731+
.withArgs(GRT, alternativeTokenConfig.address, ethers.constants.AddressZero);
732+
733+
expect(await oracle.aggregationStrategy(GRT)).to.equal(await alternativeTokenConfig2.aggregationStrategy());
734+
expect(await oracle.validationStrategy(GRT)).to.equal(await alternativeTokenConfig2.validationStrategy());
735+
expect(await oracle.minimumResponses(GRT)).to.equal(await alternativeTokenConfig2.minimumResponses());
736+
expect(await oracle.getOracles(GRT)).to.eql(await alternativeTokenConfig2.oracles()); // eql = deep equality
737+
});
738+
615739
it("Works with 8 oracles", async function () {
616740
const alternativeTokenConfigWith8Oracles = await tokenConfigFactory.deploy(
617741
newAggregationStrategy.address,

0 commit comments

Comments
 (0)