Skip to content

Update contract initializer #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ethereum/.env.cluster.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ GOVERNANCE_CHAIN_ID=0x1
GOVERNANCE_EMITTER=0x5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e

MIGRATION_12_SET_FEE_VAA=0x01000000020d00c0749e12c5a921d38934aea2025e2748b589bc887b071649ad7e55c9356c942f11f0a731b57b4540136d3fdf0fa76a79b2c270cfb56457544ebcdc2bfa1de1bf00034855f23564ec5d9540c0a45d38ddbfdafe5ad7864e5e539f8233b9d1c35e78654fbb48bfde2ba995437bfb38b92be272224b34d8df2df54d8e478eba53f637e00106af3e7ba2f6891b79564270b549ac93f81d02cca85d80ea3bdf2fa0b5fc9831f04088cc644b65e37853d84150f5e7577946c1bf5b58fdce779c5890506a4a639800083b2fed7f4ae9ebe1be7d952be53ffeebc42f03ab2ebbb6d10fcbee34530857083537ec32154cf4c6c298401828145a095eca8d901c6bd34fd3dcbe51a95d9bf40109bd66527f6553a8fd3429305d4a18822d53104b299c9df15ec9437c75bdab9c3c7f55f7c8993283972e5c98a837f5c79e1ccd234330235829f745e97aa1ede88e010afa65862b5b74eab87b72d91cc026629bd82928424a7b85191fcc430cd5cd2ceb25438aa8a346c26585e2c74d00f460e9225e764969e218203fd9f9c41b3cdb2b010b95a4707053581ba586f4463bb6592420942beb1ef5060d7ff87f8980c0cc33526499643f25eb61939b6245a10cd1deb998ff3cf2a30586d336ab7b57424c5419000c12547c3b942944106d126151036f58d7382cdaea2c5bdd12fa5cb359ff0bf56c470ef714ff33313e3d76b36e12f76378d747417ad40cc73b1ad9050d40e50633010dbc7b13e8175715273342e7577018a5d2d22ee83c4916eac8996886568145244e2be027c0739593d10104f55661d4589ff1d45deb80918324e7888db7e0419f03000e12e244ada40eb8d3c1bdce80d4abd5efa9c57cd5bafc1b123f0539c2106aa8474cd250b1d7fffaeb922e6c54a3ce050fc221177d1c56cc784a4e8c76925a3804000f476f02d40ceaa24ee311f50f0486b047ec3ba4d985e771f08941ab81e184bb275e50a0cc2d738b178ef2c982db28e1eac5eaf87658716a5c3959689240ffd7670010f0a374448b3abc05f1cb765f7d8c790d1c34044a8145380557d42077f9bb027d6e29e013360809702e7a8a407b6abd63036d269d1a1abe66f69a7f73d0bb9209001210be861c7f88caa19c8afcdbd2c9fda6c35c68933e7d3a470b916fa4d47fa62868cf38c022764d542ed9a4ddba81ae093aa1e1ecad88f79c9d879e5484bb9b5b01634878210000000000015635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e000000000000000c015054474d0103000000000000000000010000000000000000
SINGLE_UPDATE_FEE_IN_WEI=1
1 change: 1 addition & 0 deletions ethereum/.env.cluster.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ GOVERNANCE_CHAIN_ID=0x1
GOVERNANCE_EMITTER=0x63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385

MIGRATION_12_SET_FEE_VAA=0x010000000001006c844a6f378ddc46842e61552db124bf384d7fb2410584cdc8f3be8cc864b2d169cd9640f23c72e80ac119f10614bb22570731ce9cd8999501cb9178ad7b27e80063471aea00000000000163278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c3850000000000000006015054474d0103000000000000000000010000000000000000
SINGLE_UPDATE_FEE_IN_WEI=1
1 change: 1 addition & 0 deletions ethereum/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ PYTHNET_CHAIN_ID= # 0x1a
PYTHNET_EMITTER= # 0xa27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6
GOVERNANCE_CHAIN_ID= # 0x1
GOVERNANCE_EMITTER= # 0x63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385
SINGLE_UPDATE_FEE_IN_WEI=0
1 change: 1 addition & 0 deletions ethereum/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ GOVERNANCE_CHAIN_ID=0x1
GOVERNANCE_EMITTER=0x0000000000000000000000000000000000000000000000000000000000001234

WORMHOLE_CHAIN_NAME=ethereum
SINGLE_UPDATE_FEE_IN_WEI=1
33 changes: 29 additions & 4 deletions ethereum/contracts/pyth/Pyth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,37 @@ import "./PythInternalStructs.sol";
abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
function _initialize(
address wormhole,
uint16 pyth2WormholeChainId,
bytes32 pyth2WormholeEmitter
uint16[] calldata dataSourceEmitterChainIds,
bytes32[] calldata dataSourceEmitterAddresses,
uint validTimePeriodSeconds,
uint singleUpdateFeeInWei
) internal {
setWormhole(wormhole);
setPyth2WormholeChainId(pyth2WormholeChainId);
setPyth2WormholeEmitter(pyth2WormholeEmitter);

require(
dataSourceEmitterChainIds.length ==
dataSourceEmitterAddresses.length,
"data source arguments should have the same length"
);

for (uint i = 0; i < dataSourceEmitterChainIds.length; i++) {
PythInternalStructs.DataSource memory ds = PythInternalStructs
.DataSource(
dataSourceEmitterChainIds[i],
dataSourceEmitterAddresses[i]
);

require(
!PythGetters.isValidDataSource(ds.chainId, ds.emitterAddress),
"Data source already added"
);

_state.isValidDataSource[hashDataSource(ds)] = true;
_state.validDataSources.push(ds);
}

PythSetters.setValidTimePeriodSeconds(validTimePeriodSeconds);
PythSetters.setSingleUpdateFeeInWei(singleUpdateFeeInWei);
}

function updatePriceBatchFromVm(bytes calldata encodedVm) private {
Expand Down
10 changes: 0 additions & 10 deletions ethereum/contracts/pyth/PythGetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ contract PythGetters is PythState {
return IWormhole(_state.wormhole);
}

/// Deprecated, use `validDataSources` instead
function pyth2WormholeChainId() public view returns (uint16) {
return _state._deprecatedPyth2WormholeChainId;
}

/// Deprecated, use `validDataSources` instead
function pyth2WormholeEmitter() public view returns (bytes32) {
return _state._deprecatedPyth2WormholeEmitter;
}

function latestPriceInfo(
bytes32 priceId
) internal view returns (PythInternalStructs.PriceInfo memory info) {
Expand Down
8 changes: 0 additions & 8 deletions ethereum/contracts/pyth/PythSetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ pragma solidity ^0.8.0;
import "./PythState.sol";

contract PythSetters is PythState {
function setPyth2WormholeChainId(uint16 chainId) internal {
_state._deprecatedPyth2WormholeChainId = chainId;
}

function setPyth2WormholeEmitter(bytes32 emitterAddr) internal {
_state._deprecatedPyth2WormholeEmitter = emitterAddr;
}

function setWormhole(address wh) internal {
_state.wormhole = payable(wh);
}
Expand Down
14 changes: 11 additions & 3 deletions ethereum/contracts/pyth/PythUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ contract PythUpgradable is
{
function initialize(
address wormhole,
uint16 pyth2WormholeChainId,
bytes32 pyth2WormholeEmitter
uint16[] calldata dataSourceEmitterChainIds,
bytes32[] calldata dataSourceEmitterAddresses,
uint validTimePeriodSeconds,
uint singleUpdateFeeInWei
) public initializer {
__Ownable_init();
__UUPSUpgradeable_init();

Pyth._initialize(wormhole, pyth2WormholeChainId, pyth2WormholeEmitter);
Pyth._initialize(
wormhole,
dataSourceEmitterChainIds,
dataSourceEmitterAddresses,
validTimePeriodSeconds,
singleUpdateFeeInWei
);
}

/// Privileged function to specify additional data sources in the contract
Expand Down
20 changes: 11 additions & 9 deletions ethereum/forge-test/utils/PythTestUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ abstract contract PythTestUtils is Test, WormholeTestUtils {
new bytes(0)
);
PythUpgradable pyth = PythUpgradable(address(proxy));
pyth.initialize(
wormhole,
SOURCE_EMITTER_CHAIN_ID,
SOURCE_EMITTER_ADDRESS
);

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

pyth.updateSingleUpdateFeeInWei(1);
bytes32[] memory emitterAddresses = new bytes32[](1);
emitterAddresses[0] = SOURCE_EMITTER_ADDRESS;

pyth.updateValidTimePeriodSeconds(60);
pyth.initialize(
wormhole,
emitterChainIds,
emitterAddresses,
60, // Valid time period in seconds
1 // single update fee in wei
);

pyth.updateGovernanceDataSource(
GOVERNANCE_EMITTER_CHAIN_ID,
Expand Down
2 changes: 1 addition & 1 deletion ethereum/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[profile.default]
solc_version = '0.8.4'
optimizer = true
optimizer_runs = 5000
optimizer_runs = 1000
src = 'contracts'
# We put the tests into the forge-test directory (instead of test) so that
# truffle doesn't try to build them
Expand Down
43 changes: 33 additions & 10 deletions ethereum/migrations/prod-receiver/3_deploy_pyth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,49 @@ const loadEnv = require("../../scripts/loadEnv");
loadEnv("../../");

const PythUpgradable = artifacts.require("PythUpgradable");
const WormholeReceiver = artifacts.require("WormholeReceiver");

const pyth2WormholeChainId = process.env.SOLANA_CHAIN_ID;
const pyth2WormholeEmitter = process.env.SOLANA_EMITTER;

const { deployProxy } = require("@openzeppelin/truffle-upgrades");
const tdr = require("truffle-deploy-registry");
const { CONTRACTS } = require("@certusone/wormhole-sdk");
const { assert } = require("chai");

console.log("pyth2WormholeEmitter: " + pyth2WormholeEmitter);
console.log("pyth2WormholeChainId: " + pyth2WormholeChainId);
const emitterChainIds = [
process.env.SOLANA_CHAIN_ID,
process.env.PYTHNET_CHAIN_ID,
];
const emitterAddresses = [
process.env.SOLANA_EMITTER,
process.env.PYTHNET_EMITTER,
];
const validTimePeriodSeconds = Number(process.env.VALID_TIME_PERIOD_SECONDS);
const singleUpdateFeeInWei = Number(process.env.SINGLE_UPDATE_FEE_IN_WEI);

console.log("emitterChainIds: " + emitterChainIds);
console.log("emitterAddresses: " + emitterAddresses);
console.log("validTimePeriodSeconds: " + validTimePeriodSeconds);
console.log("singleUpdateFeeInWei: " + singleUpdateFeeInWei);

module.exports = async function (deployer, network) {
const cluster = process.env.CLUSTER;
const chainName = process.env.WORMHOLE_CHAIN_NAME;

assert(cluster !== undefined && chainName !== undefined);

const wormholeBridgeAddress =
CONTRACTS[cluster.toUpperCase()][chainName].core;
assert(wormholeBridgeAddress !== undefined);

console.log("Wormhole bridge address: " + wormholeBridgeAddress);

// Deploy the proxy. This will return an instance of PythUpgradable,
// with the address field corresponding to the fronting ERC1967Proxy.
let proxyInstance = await deployProxy(
PythUpgradable,
[
(await WormholeReceiver.deployed()).address,
pyth2WormholeChainId,
pyth2WormholeEmitter,
wormholeBridgeAddress,
emitterChainIds,
emitterAddresses,
validTimePeriodSeconds,
singleUpdateFeeInWei,
],
{ deployer }
);
Expand Down
21 changes: 0 additions & 21 deletions ethereum/migrations/prod-receiver/4_pyth_multiple_emitters.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions ethereum/migrations/prod-receiver/9_pyth_add_pythnet_datasource.js

This file was deleted.

Loading