Skip to content

Commit d3d10f2

Browse files
authored
Add set fee to tests + add some sanity checks (#350)
* Add set fee to tests + add some sanity checks * Add fee to evm relayer
1 parent e4160b2 commit d3d10f2

File tree

6 files changed

+106
-27
lines changed

6 files changed

+106
-27
lines changed

ethereum/migrations/prod/12_pyth_set_fee_1_wei.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
const { assert } = require("chai");
2+
const governance = require("@pythnetwork/xc-governance-sdk");
3+
const assertVaaPayloadEquals = require("../../scripts/assertVaaPayloadEquals");
4+
const { assert } = require("chai");
5+
16
const loadEnv = require("../../scripts/loadEnv");
27
loadEnv("../../");
38

@@ -13,5 +18,18 @@ const PythUpgradable = artifacts.require("PythUpgradable");
1318
*/
1419
module.exports = async function (_deployer) {
1520
const proxy = await PythUpgradable.deployed();
21+
22+
const setFeeInstruction = new governance.SetFeeInstruction(
23+
governance.CHAINS.unset, // All the chains
24+
BigInt(1),
25+
BigInt(0),
26+
).serialize();
27+
28+
console.log("SetFeeInstruction: 0x", setFeeInstruction.toString('hex'));
29+
30+
assertVaaPayloadEquals(setFeeVaa, setFeeInstruction);
31+
1632
await proxy.executeGovernanceInstruction(setFeeVaa);
33+
34+
assert.equal((await proxy.singleUpdateFeeInWei()).toString(), "1");
1735
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const createLocalnetGovernanceVaa = require("../../scripts/createLocalnetGovernanceVaa");
2+
const assertVaaPayloadEquals = require("../../scripts/assertVaaPayloadEquals");
3+
const governance = require("@pythnetwork/xc-governance-sdk");
4+
const { assert } = require("chai");
5+
6+
const loadEnv = require("../../scripts/loadEnv");
7+
loadEnv("../../");
8+
9+
10+
const PythUpgradable = artifacts.require("PythUpgradable");
11+
12+
/**
13+
*
14+
* This change:
15+
* - Executes the VAA to set the fee to 1 wei
16+
*/
17+
module.exports = async function (_deployer) {
18+
const setFeeInstruction = new governance.SetFeeInstruction(
19+
governance.CHAINS.unset, // All the chains
20+
BigInt(1),
21+
BigInt(0),
22+
).serialize();
23+
24+
console.log("SetFeeInstruction: 0x", setFeeInstruction.toString('hex'));
25+
26+
const setFeeVaa = createLocalnetGovernanceVaa(
27+
setFeeInstruction,
28+
2
29+
);
30+
31+
assertVaaPayloadEquals(setFeeVaa, setFeeInstruction);
32+
33+
const proxy = await PythUpgradable.deployed();
34+
await proxy.executeGovernanceInstruction(setFeeVaa);
35+
36+
assert.equal((await proxy.singleUpdateFeeInWei()).toString(), "1");
37+
}

ethereum/package-lock.json

Lines changed: 31 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethereum/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"author": "",
2828
"license": "ISC",
2929
"dependencies": {
30+
"@certusone/wormhole-sdk-wasm": "^0.0.1",
3031
"@openzeppelin/contracts": "^4.5.0",
3132
"@openzeppelin/contracts-upgradeable": "^4.5.2",
3233
"@pythnetwork/pyth-sdk-solidity": "^1.0.1",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
const { importCoreWasm, setDefaultWasm } = require("@certusone/wormhole-sdk-wasm");
3+
setDefaultWasm("node");
4+
const { assert } = require("chai");
5+
6+
module.exports = async function assertVaaPayloadEquals(vaaHexString, expectedPayloadBuffer) {
7+
const { parse_vaa } = await importCoreWasm();
8+
9+
if (vaaHexString.startsWith("0x")) {
10+
vaaHexString = vaaHexString.substring(2);
11+
}
12+
13+
const vaaPayload = Buffer.from(parse_vaa(Buffer.from(vaaHexString, 'hex')).payload);
14+
15+
assert(expectedPayloadBuffer.equals(vaaPayload), "The VAA payload is not equal to the expected payload");
16+
}

third_party/pyth/p2w-relay/src/relay/evm.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ export class EvmRelay implements Relay {
4545
? await this.queryMany(priceIds)
4646
: null;
4747

48+
const updateFee = await this.p2wContract.getUpdateFee(1);
49+
4850
let tx = this.p2wContract
49-
.updatePriceFeeds(["0x" + signedVAAs[i]], { gasLimit: 2000000 })
51+
.updatePriceFeeds(["0x" + signedVAAs[i]], { gasLimit: 2000000, value: updateFee })
5052
.then(async (pending) => {
5153
let receipt = await pending.wait();
5254
logger.info(

0 commit comments

Comments
 (0)