Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit cbec863

Browse files
committed
Merge branch 'development' into fix/always-permission-per
2 parents 7c3f513 + 0ac137c commit cbec863

39 files changed

+12605
-4284
lines changed

chainDeploy/helpers/oracles/chainlink.ts

+52-100
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { addTransaction } from "../logging";
1+
import { prepareAndLogTransaction } from "../logging";
22

33
import { addUnderlyingsToMpo } from "./utils";
4-
import { Address, encodeFunctionData } from "viem";
4+
import { Address, Hex, zeroAddress } from "viem";
55
import { underlying } from "../utils";
66
import { ChainlinkFeedBaseCurrency } from "../../../../monorepo/packages/types";
77
import { ChainlinkDeployFnParams } from "../../types";
@@ -12,29 +12,31 @@ export const deployChainlinkOracle = async ({
1212
deployments,
1313
deployConfig,
1414
assets,
15-
chainlinkAssets
15+
chainlinkAssets,
16+
namePostfix
1617
}: ChainlinkDeployFnParams): Promise<{ cpo: any; chainLinkv2: any }> => {
1718
const { deployer } = await getNamedAccounts();
1819
const publicClient = await viem.getPublicClient();
19-
const walletClient = await viem.getWalletClient(deployer as Address);
20-
let tx;
20+
let tx: Hex;
2121

2222
//// Chainlink Oracle
2323

24+
const contractName = ["ChainlinkPriceOracleV2", namePostfix].join("_");
25+
2426
console.log("deployConfig.stableToken: ", deployConfig.stableToken);
2527
console.log("deployConfig.nativeTokenUsdChainlinkFeed: ", deployConfig.nativeTokenUsdChainlinkFeed);
26-
const cpo = await deployments.deploy("ChainlinkPriceOracleV2", {
28+
const cpo = await deployments.deploy(contractName, {
29+
contract: "ChainlinkPriceOracleV2",
2730
from: deployer,
2831
args: [],
2932
log: true,
3033
proxy: {
3134
execute: {
3235
init: {
3336
methodName: "initialize",
34-
args: [deployConfig.stableToken, deployConfig.nativeTokenUsdChainlinkFeed]
37+
args: [deployConfig.stableToken, zeroAddress]
3538
}
3639
},
37-
owner: deployer,
3840
proxyContract: "OpenZeppelinTransparentProxy"
3941
},
4042
waitConfirmations: 1
@@ -44,7 +46,7 @@ export const deployChainlinkOracle = async ({
4446

4547
const chainLinkv2 = await viem.getContractAt(
4648
"ChainlinkPriceOracleV2",
47-
(await deployments.get("ChainlinkPriceOracleV2")).address as Address
49+
(await deployments.get(contractName)).address as Address
4850
);
4951

5052
const chainlinkAssetsToChange = [];
@@ -75,37 +77,20 @@ export const deployChainlinkOracle = async ({
7577
await publicClient.waitForTransactionReceipt({ hash: tx });
7678
console.log(`Set ${usdBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2 at ${tx}`);
7779
} else {
78-
const tx = await walletClient.prepareTransactionRequest({
79-
account: (await chainLinkv2.read.owner()) as Address,
80-
to: chainLinkv2.address,
81-
data: encodeFunctionData({
82-
abi: chainLinkv2.abi,
83-
functionName: "setPriceFeeds",
84-
args: [
85-
usdBasedFeeds.map((c) => underlying(assets, c.symbol)),
86-
usdBasedFeeds.map((c) => c.aggregator),
87-
feedCurrency
88-
]
89-
})
90-
});
91-
addTransaction({
92-
to: tx.to,
93-
value: tx.value ? tx.value.toString() : "0",
94-
data: null,
95-
contractMethod: {
96-
inputs: [
97-
{ internalType: "address[]", name: "underlyings", type: "address[]" },
98-
{ internalType: "address[]", name: "feeds", type: "address[]" },
99-
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
100-
],
101-
name: "setPriceFeeds",
102-
payable: false
103-
},
104-
contractInputsValues: {
105-
underlyings: usdBasedFeeds.map((c) => underlying(assets, c.symbol)),
106-
feeds: usdBasedFeeds.map((c) => c.aggregator),
107-
baseCurrency: feedCurrency
108-
}
80+
await prepareAndLogTransaction({
81+
contractInstance: chainLinkv2,
82+
description: `Set ${usdBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2`,
83+
functionName: "setPriceFeeds",
84+
args: [
85+
usdBasedFeeds.map((c) => underlying(assets, c.symbol)),
86+
usdBasedFeeds.map((c) => c.aggregator),
87+
feedCurrency
88+
],
89+
inputs: [
90+
{ internalType: "address[]", name: "underlyings", type: "address[]" },
91+
{ internalType: "address[]", name: "feeds", type: "address[]" },
92+
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
93+
]
10994
});
11095
console.log(`Logged Transaction to set ${usdBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2`);
11196
}
@@ -121,37 +106,20 @@ export const deployChainlinkOracle = async ({
121106
await publicClient.waitForTransactionReceipt({ hash: tx });
122107
console.log(`Set ${ethBasedFeeds.length} native price feeds for ChainlinkPriceOracleV2`);
123108
} else {
124-
tx = await walletClient.prepareTransactionRequest({
125-
account: (await chainLinkv2.read.owner()) as Address,
126-
to: chainLinkv2.address,
127-
data: encodeFunctionData({
128-
abi: chainLinkv2.abi,
129-
functionName: "setPriceFeeds",
130-
args: [
131-
ethBasedFeeds.map((c) => underlying(assets, c.symbol)),
132-
ethBasedFeeds.map((c) => c.aggregator),
133-
feedCurrency
134-
]
135-
})
136-
});
137-
addTransaction({
138-
to: tx.to,
139-
value: tx.value ? tx.value.toString() : "0",
140-
data: null,
141-
contractMethod: {
142-
inputs: [
143-
{ internalType: "address[]", name: "underlyings", type: "address[]" },
144-
{ internalType: "address[]", name: "feeds", type: "address[]" },
145-
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
146-
],
147-
name: "setPriceFeeds",
148-
payable: false
149-
},
150-
contractInputsValues: {
151-
underlyings: ethBasedFeeds.map((c) => underlying(assets, c.symbol)),
152-
feeds: ethBasedFeeds.map((c) => c.aggregator),
153-
baseCurrency: feedCurrency
154-
}
109+
await prepareAndLogTransaction({
110+
contractInstance: chainLinkv2,
111+
description: `Set ${ethBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2`,
112+
functionName: "setPriceFeeds",
113+
args: [
114+
ethBasedFeeds.map((c) => underlying(assets, c.symbol)),
115+
ethBasedFeeds.map((c) => c.aggregator),
116+
feedCurrency
117+
],
118+
inputs: [
119+
{ internalType: "address[]", name: "underlyings", type: "address[]" },
120+
{ internalType: "address[]", name: "feeds", type: "address[]" },
121+
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
122+
]
155123
});
156124
console.log(`Logged Transaction to set ${ethBasedFeeds.length} ETH price feeds for ChainlinkPriceOracleV2`);
157125
}
@@ -163,44 +131,28 @@ export const deployChainlinkOracle = async ({
163131
"MasterPriceOracle",
164132
(await deployments.get("MasterPriceOracle")).address as Address
165133
);
166-
await addUnderlyingsToMpo(mpo as any, underlyings, chainLinkv2.address, deployer, publicClient, walletClient);
134+
await addUnderlyingsToMpo(mpo as any, underlyings, chainLinkv2.address, deployer, publicClient);
167135

168136
const addressesProvider = await viem.getContractAt(
169137
"AddressesProvider",
170138
(await deployments.get("AddressesProvider")).address as Address
171139
);
172-
const chainLinkv2Address = await addressesProvider.read.getAddress(["ChainlinkPriceOracleV2"]);
140+
const chainLinkv2Address = await addressesProvider.read.getAddress([contractName]);
173141
if (chainLinkv2Address !== chainLinkv2.address) {
174142
if (((await addressesProvider.read.owner()) as Address).toLowerCase() === deployer.toLowerCase()) {
175-
tx = await addressesProvider.write.setAddress(["ChainlinkPriceOracleV2", chainLinkv2.address]);
143+
tx = await addressesProvider.write.setAddress([contractName, chainLinkv2.address]);
176144
await publicClient.waitForTransactionReceipt({ hash: tx });
177-
console.log(`setAddress ChainlinkPriceOracleV2 at ${tx}`);
145+
console.log(`setAddress ${contractName} at ${tx}`);
178146
} else {
179-
tx = await walletClient.prepareTransactionRequest({
180-
account: (await addressesProvider.read.owner()) as Address,
181-
to: addressesProvider.address,
182-
data: encodeFunctionData({
183-
abi: addressesProvider.abi,
184-
functionName: "setAddress",
185-
args: ["ChainlinkPriceOracleV2", chainLinkv2.address]
186-
})
187-
});
188-
addTransaction({
189-
to: tx.to,
190-
value: tx.value ? tx.value.toString() : "0",
191-
data: null,
192-
contractMethod: {
193-
inputs: [
194-
{ internalType: "string", name: "id", type: "string" },
195-
{ internalType: "address", name: "newAddress", type: "address" }
196-
],
197-
name: "setAddress",
198-
payable: false
199-
},
200-
contractInputsValues: {
201-
id: "ChainlinkPriceOracleV2",
202-
newAddress: chainLinkv2.address
203-
}
147+
await prepareAndLogTransaction({
148+
contractInstance: addressesProvider,
149+
description: `setAddress ${contractName}`,
150+
functionName: "setAddress",
151+
args: [contractName, chainLinkv2.address],
152+
inputs: [
153+
{ internalType: "string", name: "id", type: "string" },
154+
{ internalType: "address", name: "newAddress", type: "address" }
155+
]
204156
});
205157
console.log("Logged Transaction to setAddress ChainlinkPriceOracleV2 on AddressProvider");
206158
}

chainDeploy/helpers/oracles/pyth.ts

+33-49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Address, encodeFunctionData, GetContractReturnType, WalletClient } from "viem";
22

3-
import { addTransaction } from "../logging";
3+
import { addTransaction, prepareAndLogTransaction } from "../logging";
44
import { pythPriceOracleAbi } from "../../../generated";
55

66
import { addUnderlyingsToMpo } from "./utils";
@@ -24,30 +24,30 @@ export const deployPythPriceOracle = async ({
2424
(await deployments.get("MasterPriceOracle")).address as Address
2525
);
2626

27-
//// Pyth Oracle
28-
const pyth = await deployments.deploy("PythPriceOracle", {
29-
from: deployer,
30-
args: [],
31-
log: true,
32-
proxy: {
33-
execute: {
34-
init: {
35-
methodName: "initialize",
36-
args: [pythAddress, nativeTokenUsdFeed, usdToken]
37-
},
38-
onUpgrade: {
39-
methodName: "reinitialize",
40-
args: [pythAddress, nativeTokenUsdFeed, usdToken]
41-
}
42-
},
43-
owner: deployer,
44-
proxyContract: "OpenZeppelinTransparentProxy"
45-
},
46-
waitConfirmations: 1
47-
});
27+
// //// Pyth Oracle
28+
// const pyth = await deployments.deploy("PythPriceOracle", {
29+
// from: deployer,
30+
// args: [],
31+
// log: true,
32+
// proxy: {
33+
// execute: {
34+
// init: {
35+
// methodName: "initialize",
36+
// args: [pythAddress, nativeTokenUsdFeed, usdToken]
37+
// },
38+
// onUpgrade: {
39+
// methodName: "reinitialize",
40+
// args: [pythAddress, nativeTokenUsdFeed, usdToken]
41+
// }
42+
// },
43+
// owner: deployer,
44+
// proxyContract: "OpenZeppelinTransparentProxy"
45+
// },
46+
// waitConfirmations: 1
47+
// });
4848

49-
if (pyth.transactionHash) publicClient.waitForTransactionReceipt({ hash: pyth.transactionHash as Address });
50-
console.log("PythPriceOracle: ", pyth.address);
49+
// if (pyth.transactionHash) publicClient.waitForTransactionReceipt({ hash: pyth.transactionHash as Address });
50+
// console.log("PythPriceOracle: ", pyth.address);
5151

5252
const pythOracle = await viem.getContractAt(
5353
"PythPriceOracle",
@@ -70,31 +70,15 @@ export const deployPythPriceOracle = async ({
7070
await publicClient.waitForTransactionReceipt({ hash: tx });
7171
console.log(`Set ${pythAssetsToChange.length} price feeds for PythPriceOracle at ${tx}`);
7272
} else {
73-
const tx = await walletClient.prepareTransactionRequest({
74-
account: (await pythOracle.read.owner()) as Address,
75-
to: pythOracle.address,
76-
data: encodeFunctionData({
77-
abi: pythOracle.abi,
78-
functionName: "setPriceFeeds",
79-
args: [pythAssetsToChange.map((f) => f.underlying), pythAssetsToChange.map((f) => f.feed)]
80-
})
81-
});
82-
addTransaction({
83-
to: tx.to,
84-
value: tx.value ? tx.value.toString() : "0",
85-
data: null,
86-
contractMethod: {
87-
inputs: [
88-
{ internalType: "address[]", name: "underlyings", type: "address[]" },
89-
{ internalType: "bytes32[]", name: "feeds", type: "bytes32[]" }
90-
],
91-
name: "setPriceFeeds",
92-
payable: false
93-
},
94-
contractInputsValues: {
95-
underlyings: pythAssetsToChange.map((f) => f.underlying),
96-
feeds: pythAssetsToChange.map((f) => f.feed)
97-
}
73+
await prepareAndLogTransaction({
74+
contractInstance: pythOracle,
75+
args: [pythAssetsToChange.map((f) => f.underlying), pythAssetsToChange.map((f) => f.feed)],
76+
description: `Set ${pythAssetsToChange.length} price feeds for PythPriceOracle`,
77+
functionName: "setPriceFeeds",
78+
inputs: [
79+
{ internalType: "address[]", name: "underlyings", type: "address[]" },
80+
{ internalType: "bytes32[]", name: "feeds", type: "bytes32[]" }
81+
]
9882
});
9983
console.log(`Logged Transaction to set ${pythAssetsToChange.length} price feeds for PythPriceOracle `);
10084
}

chainDeploy/helpers/oracles/utils.ts

+11-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Address, encodeFunctionData, PublicClient, WalletClient, zeroAddress } from "viem";
2-
import { addTransaction } from "../logging";
2+
import { addTransaction, prepareAndLogTransaction } from "../logging";
33
import { masterPriceOracleAbi } from "../../../generated";
44
import type { GetContractReturnType } from "@nomicfoundation/hardhat-viem/types.js";
55

@@ -8,8 +8,7 @@ export async function addUnderlyingsToMpo(
88
underlyingsToCheck: Address[],
99
oracleAddress: Address,
1010
deployer: string,
11-
publicClient: PublicClient,
12-
walletClient: WalletClient
11+
publicClient: PublicClient
1312
) {
1413
const oracles: Address[] = [];
1514
const underlyings: Address[] = [];
@@ -28,32 +27,15 @@ export async function addUnderlyingsToMpo(
2827
await publicClient.waitForTransactionReceipt({ hash: tx });
2928
console.log(`Master Price Oracle updated oracles for tokens ${underlyings.join(",")} at ${tx}`);
3029
} else {
31-
const tx = await walletClient.prepareTransactionRequest({
32-
chain: walletClient.chain,
33-
account: await mpo.read.admin(),
34-
to: mpo.address,
35-
data: encodeFunctionData({
36-
abi: mpo.abi,
37-
functionName: "add",
38-
args: [underlyings, oracles]
39-
})
40-
});
41-
addTransaction({
42-
to: tx.to,
43-
value: tx.value ? tx.value.toString() : "0",
44-
data: null,
45-
contractMethod: {
46-
inputs: [
47-
{ internalType: "address[]", name: "underlyings", type: "address[]" },
48-
{ internalType: "address[]", name: "_oracles", type: "address[]" }
49-
],
50-
name: "add",
51-
payable: false
52-
},
53-
contractInputsValues: {
54-
underlyings: underlyings,
55-
_oracles: oracles
56-
}
30+
await prepareAndLogTransaction({
31+
contractInstance: mpo,
32+
functionName: "add",
33+
args: [underlyings, oracles],
34+
description: `Add oracles for ${underlyings.join(",")}`,
35+
inputs: [
36+
{ internalType: "address[]", name: "underlyings", type: "address[]" },
37+
{ internalType: "address[]", name: "_oracles", type: "address[]" }
38+
]
5739
});
5840

5941
console.log(`Logged Transaction for Master Price Oracle update for tokens ${underlyings.join(",")}`);

0 commit comments

Comments
 (0)