Skip to content

Commit bdc492f

Browse files
authored
[eth] Some contract improvements (#356)
1 parent 398b187 commit bdc492f

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

ethereum/contracts/pyth/Pyth.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
5757
}
5858

5959
function updatePriceFeeds(bytes[] calldata updateData) public override payable {
60-
uint requiredFee = getUpdateFee(updateData.length);
60+
uint requiredFee = getUpdateFee(updateData);
6161
require(msg.value >= requiredFee, "insufficient paid fee amount");
62-
payable(msg.sender).transfer(msg.value - requiredFee);
6362

6463
for(uint i = 0; i < updateData.length; i++) {
6564
updatePriceBatchFromVm(updateData[i]);
@@ -68,10 +67,15 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
6867
emit UpdatePriceFeeds(msg.sender, updateData.length, requiredFee);
6968
}
7069

71-
function getUpdateFee(uint updateDataSize) public override view returns (uint feeAmount) {
70+
/// This method is deprecated, please use the `getUpdateFee(bytes[])` instead.
71+
function getUpdateFee(uint updateDataSize) public view returns (uint feeAmount) {
7272
return singleUpdateFeeInWei() * updateDataSize;
7373
}
7474

75+
function getUpdateFee(bytes[] calldata updateData) public override view returns (uint feeAmount) {
76+
return singleUpdateFeeInWei() * updateData.length;
77+
}
78+
7579
function createNewPriceInfo(PythInternalStructs.PriceAttestation memory pa) private view returns (PythInternalStructs.PriceInfo memory info) {
7680
info.attestationTime = pa.attestationTime;
7781
info.arrivalTime = block.timestamp;

ethereum/package-lock.json

Lines changed: 7 additions & 7 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@certusone/wormhole-sdk-wasm": "^0.0.1",
3131
"@openzeppelin/contracts": "^4.5.0",
3232
"@openzeppelin/contracts-upgradeable": "^4.5.2",
33-
"@pythnetwork/pyth-sdk-solidity": "^1.0.1",
33+
"@pythnetwork/pyth-sdk-solidity": "^2.0.0",
3434
"@pythnetwork/xc-governance-sdk": "file:../third_party/pyth/xc-governance-sdk-js",
3535
"dotenv": "^10.0.0",
3636
"elliptic": "^6.5.2",

ethereum/test/pyth.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ contract("Pyth", function () {
435435
let rawBatch2 = generateRawBatchAttestation(ts + 5, ts + 10, 1338);
436436

437437
// Getting the fee from the contract
438-
let feeInWei = await this.pythProxy.getUpdateFee(2);
438+
let feeInWei = await this.pythProxy.methods["getUpdateFee(bytes[])"]([rawBatch1, rawBatch2]);
439439
assert.equal(feeInWei, 20);
440440

441441
// When a smaller fee is payed it reverts
@@ -464,7 +464,7 @@ contract("Pyth", function () {
464464
let rawBatch2 = generateRawBatchAttestation(ts + 5, ts + 10, 1338);
465465

466466
// Getting the fee from the contract
467-
let feeInWei = await this.pythProxy.getUpdateFee(2);
467+
let feeInWei = await this.pythProxy.methods["getUpdateFee(bytes[])"]([rawBatch1, rawBatch2]);
468468
assert.equal(feeInWei, 20);
469469

470470
const receipt = await updatePriceFeeds(this.pythProxy, [rawBatch1, rawBatch2], feeInWei);
@@ -493,16 +493,16 @@ contract("Pyth", function () {
493493
let rawBatch1 = generateRawBatchAttestation(ts - 5, ts, 1337);
494494
let rawBatch2 = generateRawBatchAttestation(ts + 5, ts + 10, 1338);
495495

496-
// Getting the fee from the contract
497-
let feeInWei = await this.pythProxy.getUpdateFee(2);
496+
// Paying the fee works and extra fee is not paid back.
497+
let feeInWei = await this.pythProxy.methods["getUpdateFee(bytes[])"]([rawBatch1, rawBatch2]);
498498
assert.equal(feeInWei, 20);
499499

500500
const receipt = await updatePriceFeeds(this.pythProxy, [rawBatch1, rawBatch2], feeInWei + 10);
501501
expectEvent(receipt, 'UpdatePriceFeeds', {
502502
fee: feeInWei
503503
});
504504
const pythBalance = await web3.eth.getBalance(this.pythProxy.address);
505-
assert.equal(pythBalance, feeInWei);
505+
assert.equal(pythBalance, feeInWei + 10);
506506
});
507507

508508
it("should cache price updates", async function () {

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

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

48-
const updateFee = await this.p2wContract.getUpdateFee(1);
48+
const updateData = ["0x" + signedVAAs[i]];
49+
const updateFee = await this.p2wContract["getUpdateFee(bytes[])"](updateData);
4950

5051
let tx = this.p2wContract
51-
.updatePriceFeeds(["0x" + signedVAAs[i]], { gasLimit: 2000000, value: updateFee })
52+
.updatePriceFeeds(updateData, { gasLimit: 2000000, value: updateFee })
5253
.then(async (pending) => {
5354
let receipt = await pending.wait();
5455
logger.info(

0 commit comments

Comments
 (0)