Skip to content

Commit 45ce077

Browse files
authored
Update contract initializer (#397)
* Update contract initializer * Reduce optimizer runs to 1000
1 parent 51514dc commit 45ce077

38 files changed

+509
-553
lines changed

ethereum/.env.cluster.mainnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ GOVERNANCE_CHAIN_ID=0x1
77
GOVERNANCE_EMITTER=0x5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e
88

99
MIGRATION_12_SET_FEE_VAA=0x01000000020d00c0749e12c5a921d38934aea2025e2748b589bc887b071649ad7e55c9356c942f11f0a731b57b4540136d3fdf0fa76a79b2c270cfb56457544ebcdc2bfa1de1bf00034855f23564ec5d9540c0a45d38ddbfdafe5ad7864e5e539f8233b9d1c35e78654fbb48bfde2ba995437bfb38b92be272224b34d8df2df54d8e478eba53f637e00106af3e7ba2f6891b79564270b549ac93f81d02cca85d80ea3bdf2fa0b5fc9831f04088cc644b65e37853d84150f5e7577946c1bf5b58fdce779c5890506a4a639800083b2fed7f4ae9ebe1be7d952be53ffeebc42f03ab2ebbb6d10fcbee34530857083537ec32154cf4c6c298401828145a095eca8d901c6bd34fd3dcbe51a95d9bf40109bd66527f6553a8fd3429305d4a18822d53104b299c9df15ec9437c75bdab9c3c7f55f7c8993283972e5c98a837f5c79e1ccd234330235829f745e97aa1ede88e010afa65862b5b74eab87b72d91cc026629bd82928424a7b85191fcc430cd5cd2ceb25438aa8a346c26585e2c74d00f460e9225e764969e218203fd9f9c41b3cdb2b010b95a4707053581ba586f4463bb6592420942beb1ef5060d7ff87f8980c0cc33526499643f25eb61939b6245a10cd1deb998ff3cf2a30586d336ab7b57424c5419000c12547c3b942944106d126151036f58d7382cdaea2c5bdd12fa5cb359ff0bf56c470ef714ff33313e3d76b36e12f76378d747417ad40cc73b1ad9050d40e50633010dbc7b13e8175715273342e7577018a5d2d22ee83c4916eac8996886568145244e2be027c0739593d10104f55661d4589ff1d45deb80918324e7888db7e0419f03000e12e244ada40eb8d3c1bdce80d4abd5efa9c57cd5bafc1b123f0539c2106aa8474cd250b1d7fffaeb922e6c54a3ce050fc221177d1c56cc784a4e8c76925a3804000f476f02d40ceaa24ee311f50f0486b047ec3ba4d985e771f08941ab81e184bb275e50a0cc2d738b178ef2c982db28e1eac5eaf87658716a5c3959689240ffd7670010f0a374448b3abc05f1cb765f7d8c790d1c34044a8145380557d42077f9bb027d6e29e013360809702e7a8a407b6abd63036d269d1a1abe66f69a7f73d0bb9209001210be861c7f88caa19c8afcdbd2c9fda6c35c68933e7d3a470b916fa4d47fa62868cf38c022764d542ed9a4ddba81ae093aa1e1ecad88f79c9d879e5484bb9b5b01634878210000000000015635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e000000000000000c015054474d0103000000000000000000010000000000000000
10+
SINGLE_UPDATE_FEE_IN_WEI=1

ethereum/.env.cluster.testnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ GOVERNANCE_CHAIN_ID=0x1
77
GOVERNANCE_EMITTER=0x63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385
88

99
MIGRATION_12_SET_FEE_VAA=0x010000000001006c844a6f378ddc46842e61552db124bf384d7fb2410584cdc8f3be8cc864b2d169cd9640f23c72e80ac119f10614bb22570731ce9cd8999501cb9178ad7b27e80063471aea00000000000163278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c3850000000000000006015054474d0103000000000000000000010000000000000000
10+
SINGLE_UPDATE_FEE_IN_WEI=1

ethereum/.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ PYTHNET_CHAIN_ID= # 0x1a
1919
PYTHNET_EMITTER= # 0xa27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6
2020
GOVERNANCE_CHAIN_ID= # 0x1
2121
GOVERNANCE_EMITTER= # 0x63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385
22+
SINGLE_UPDATE_FEE_IN_WEI=0

ethereum/.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ GOVERNANCE_CHAIN_ID=0x1
3030
GOVERNANCE_EMITTER=0x0000000000000000000000000000000000000000000000000000000000001234
3131

3232
WORMHOLE_CHAIN_NAME=ethereum
33+
SINGLE_UPDATE_FEE_IN_WEI=1

ethereum/contracts/pyth/Pyth.sol

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,37 @@ import "./PythInternalStructs.sol";
1414
abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
1515
function _initialize(
1616
address wormhole,
17-
uint16 pyth2WormholeChainId,
18-
bytes32 pyth2WormholeEmitter
17+
uint16[] calldata dataSourceEmitterChainIds,
18+
bytes32[] calldata dataSourceEmitterAddresses,
19+
uint validTimePeriodSeconds,
20+
uint singleUpdateFeeInWei
1921
) internal {
2022
setWormhole(wormhole);
21-
setPyth2WormholeChainId(pyth2WormholeChainId);
22-
setPyth2WormholeEmitter(pyth2WormholeEmitter);
23+
24+
require(
25+
dataSourceEmitterChainIds.length ==
26+
dataSourceEmitterAddresses.length,
27+
"data source arguments should have the same length"
28+
);
29+
30+
for (uint i = 0; i < dataSourceEmitterChainIds.length; i++) {
31+
PythInternalStructs.DataSource memory ds = PythInternalStructs
32+
.DataSource(
33+
dataSourceEmitterChainIds[i],
34+
dataSourceEmitterAddresses[i]
35+
);
36+
37+
require(
38+
!PythGetters.isValidDataSource(ds.chainId, ds.emitterAddress),
39+
"Data source already added"
40+
);
41+
42+
_state.isValidDataSource[hashDataSource(ds)] = true;
43+
_state.validDataSources.push(ds);
44+
}
45+
46+
PythSetters.setValidTimePeriodSeconds(validTimePeriodSeconds);
47+
PythSetters.setSingleUpdateFeeInWei(singleUpdateFeeInWei);
2348
}
2449

2550
function updatePriceBatchFromVm(bytes calldata encodedVm) private {

ethereum/contracts/pyth/PythGetters.sol

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ contract PythGetters is PythState {
1313
return IWormhole(_state.wormhole);
1414
}
1515

16-
/// Deprecated, use `validDataSources` instead
17-
function pyth2WormholeChainId() public view returns (uint16) {
18-
return _state._deprecatedPyth2WormholeChainId;
19-
}
20-
21-
/// Deprecated, use `validDataSources` instead
22-
function pyth2WormholeEmitter() public view returns (bytes32) {
23-
return _state._deprecatedPyth2WormholeEmitter;
24-
}
25-
2616
function latestPriceInfo(
2717
bytes32 priceId
2818
) internal view returns (PythInternalStructs.PriceInfo memory info) {

ethereum/contracts/pyth/PythSetters.sol

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ pragma solidity ^0.8.0;
66
import "./PythState.sol";
77

88
contract PythSetters is PythState {
9-
function setPyth2WormholeChainId(uint16 chainId) internal {
10-
_state._deprecatedPyth2WormholeChainId = chainId;
11-
}
12-
13-
function setPyth2WormholeEmitter(bytes32 emitterAddr) internal {
14-
_state._deprecatedPyth2WormholeEmitter = emitterAddr;
15-
}
16-
179
function setWormhole(address wh) internal {
1810
_state.wormhole = payable(wh);
1911
}

ethereum/contracts/pyth/PythUpgradable.sol

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ contract PythUpgradable is
2121
{
2222
function initialize(
2323
address wormhole,
24-
uint16 pyth2WormholeChainId,
25-
bytes32 pyth2WormholeEmitter
24+
uint16[] calldata dataSourceEmitterChainIds,
25+
bytes32[] calldata dataSourceEmitterAddresses,
26+
uint validTimePeriodSeconds,
27+
uint singleUpdateFeeInWei
2628
) public initializer {
2729
__Ownable_init();
2830
__UUPSUpgradeable_init();
2931

30-
Pyth._initialize(wormhole, pyth2WormholeChainId, pyth2WormholeEmitter);
32+
Pyth._initialize(
33+
wormhole,
34+
dataSourceEmitterChainIds,
35+
dataSourceEmitterAddresses,
36+
validTimePeriodSeconds,
37+
singleUpdateFeeInWei
38+
);
3139
}
3240

3341
/// Privileged function to specify additional data sources in the contract

ethereum/forge-test/utils/PythTestUtils.t.sol

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ abstract contract PythTestUtils is Test, WormholeTestUtils {
2828
new bytes(0)
2929
);
3030
PythUpgradable pyth = PythUpgradable(address(proxy));
31-
pyth.initialize(
32-
wormhole,
33-
SOURCE_EMITTER_CHAIN_ID,
34-
SOURCE_EMITTER_ADDRESS
35-
);
3631

37-
// TODO: All the logic below should be moved to the initializer
38-
pyth.addDataSource(SOURCE_EMITTER_CHAIN_ID, SOURCE_EMITTER_ADDRESS);
32+
uint16[] memory emitterChainIds = new uint16[](1);
33+
emitterChainIds[0] = SOURCE_EMITTER_CHAIN_ID;
3934

40-
pyth.updateSingleUpdateFeeInWei(1);
35+
bytes32[] memory emitterAddresses = new bytes32[](1);
36+
emitterAddresses[0] = SOURCE_EMITTER_ADDRESS;
4137

42-
pyth.updateValidTimePeriodSeconds(60);
38+
pyth.initialize(
39+
wormhole,
40+
emitterChainIds,
41+
emitterAddresses,
42+
60, // Valid time period in seconds
43+
1 // single update fee in wei
44+
);
4345

4446
pyth.updateGovernanceDataSource(
4547
GOVERNANCE_EMITTER_CHAIN_ID,

ethereum/foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[profile.default]
22
solc_version = '0.8.4'
33
optimizer = true
4-
optimizer_runs = 5000
4+
optimizer_runs = 1000
55
src = 'contracts'
66
# We put the tests into the forge-test directory (instead of test) so that
77
# truffle doesn't try to build them

0 commit comments

Comments
 (0)