Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit d4f8185

Browse files
authored
Update solidity-sdk version and its usages (#72)
* Update pyth-sdk-solidity version * Update getUpdateFee in pyth-evm-js * Update getUpdateFee call on price pusher * Remove insufficient err handling for closed conn * Update updatePriceFeedsIfNec... rejection handler * Refactor a little * Bump versions
1 parent 019a97f commit d4f8185

File tree

8 files changed

+34
-50
lines changed

8 files changed

+34
-50
lines changed

pyth-evm-js/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ const priceUpdateData = await connection.getPriceUpdateData(priceIds);
4646
// `pythContract` below is a web3.js contract; if you wish to use ethers, you need to change it accordingly.
4747
// You can find the Pyth interface ABI in @pythnetwork/pyth-sdk-solidity npm package.
4848
const updateFee = await pythContract.methods
49-
.getUpdateFee(priceFeedUpdateData.length)
49+
.getUpdateFee(priceFeedUpdateData)
5050
.call();
51-
5251
// Calling someContract method
5352
// `someContract` below is a web3.js contract; if you wish to use ethers, you need to change it accordingly.
5453
await someContract.methods
@@ -73,7 +72,7 @@ contract SomeContract {
7372
7473
function doSomething(uint someArg, string memory otherArg, bytes[] memory priceUpdateData) public payable {
7574
// Update the prices to be set to the latest values
76-
uint fee = pyth.getUpdateFee(priceUpdateData.length);
75+
uint fee = pyth.getUpdateFee(priceUpdateData);
7776
pyth.updatePriceFeeds{value: fee}(priceUpdateData);
7877
7978
// Doing other things that uses prices

pyth-evm-js/package-lock.json

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

pyth-evm-js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-js",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Pyth Network EVM Utils in JS",
55
"homepage": "https://pyth.network",
66
"author": {
@@ -30,7 +30,7 @@
3030
],
3131
"license": "Apache-2.0",
3232
"devDependencies": {
33-
"@pythnetwork/pyth-sdk-solidity": "^1.0.1",
33+
"@pythnetwork/pyth-sdk-solidity": "^2.2.0",
3434
"@truffle/hdwallet-provider": "^2.0.8",
3535
"@types/ethereum-protocol": "^1.0.2",
3636
"@types/jest": "^27.4.1",

pyth-evm-js/src/examples/EvmRelay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async function run() {
115115
);
116116

117117
const updateFee = await pythContract.methods
118-
.getUpdateFee(priceFeedUpdateData.length)
118+
.getUpdateFee(priceFeedUpdateData)
119119
.call();
120120
console.log(`Update fee: ${updateFee}`);
121121

pyth-evm-price-pusher/package-lock.json

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

pyth-evm-price-pusher/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-price-pusher",
3-
"version": "1.0.3",
3+
"version": "2.0.0",
44
"description": "Pyth EVM Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",
@@ -44,7 +44,7 @@
4444
},
4545
"dependencies": {
4646
"@pythnetwork/pyth-evm-js": "^1.0.0",
47-
"@pythnetwork/pyth-sdk-solidity": "^1.0.1",
47+
"@pythnetwork/pyth-sdk-solidity": "^2.2.0",
4848
"@truffle/hdwallet-provider": "^2.1.3",
4949
"joi": "^17.6.0",
5050
"web3": "^1.8.1",

pyth-evm-price-pusher/src/evm-price-listener.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import { HexString } from "@pythnetwork/pyth-evm-js";
2-
3-
import AbstractPythAbi from "@pythnetwork/pyth-sdk-solidity/abis/AbstractPyth.json";
4-
import Web3 from "web3";
52
import { Contract, EventData } from "web3-eth-contract";
63
import { PriceConfig } from "./price-config";
74
import { PriceInfo, PriceListener } from "./price-listener";
85
import { PythContractFactory } from "./pyth-contract-factory";
9-
import {
10-
addLeading0x,
11-
DurationInSeconds,
12-
isWsEndpoint,
13-
removeLeading0x,
14-
} from "./utils";
6+
import { addLeading0x, DurationInSeconds, removeLeading0x } from "./utils";
157

168
export class EvmPriceListener implements PriceListener {
179
private pythContractFactory: PythContractFactory;

pyth-evm-price-pusher/src/pusher.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import {
55
import { addLeading0x, DurationInSeconds, sleep } from "./utils";
66
import { PriceInfo, PriceListener } from "./price-listener";
77
import { Contract } from "web3-eth-contract";
8-
import AbstractPythAbi from "@pythnetwork/pyth-sdk-solidity/abis/AbstractPyth.json";
9-
import Web3 from "web3";
10-
import HDWalletProvider from "@truffle/hdwallet-provider";
118
import { PriceConfig } from "./price-config";
129
import { TransactionReceipt } from "ethereum-protocol";
13-
import { Provider } from "web3/providers";
1410
import { PythContractFactory } from "./pyth-contract-factory";
1511

1612
export class Pusher {
@@ -96,7 +92,7 @@ export class Pusher {
9692
);
9793

9894
const updateFee = await this.pythContract.methods
99-
.getUpdateFee(priceFeedUpdateData.length)
95+
.getUpdateFee(priceFeedUpdateData)
10096
.call();
10197
console.log(`Update fee: ${updateFee}`);
10298

@@ -113,11 +109,16 @@ export class Pusher {
113109
.on("error", (err: Error, receipt: TransactionReceipt) => {
114110
if (
115111
err.message.includes(
116-
"no prices in the submitted batch have fresh prices, so this update will have no effect"
112+
"VM Exception while processing transaction: revert"
117113
)
118114
) {
115+
// Since we are using custom error structs on solidity the rejection
116+
// doesn't return any information why the call has reverted. Assuming that
117+
// the update data is valid there is no possible rejection cause other than
118+
// the target chain price being already updated.
119119
console.log(
120-
"The target chain price has already updated, Skipping this push."
120+
"Execution reverted. With high probablity, the target chain price " +
121+
"has already updated, Skipping this push."
121122
);
122123
return;
123124
}
@@ -136,14 +137,6 @@ export class Pusher {
136137
throw err;
137138
}
138139

139-
if (err.message.includes("connection not open on send")) {
140-
console.error(
141-
"Web3 connection is closed. Recreating the connection and skipping this push."
142-
);
143-
this.pythContract =
144-
this.pythContractFactory.createPythContractWithPayer();
145-
}
146-
147140
console.error("An unidentified error has occured:");
148141
console.error(receipt);
149142
throw err;

0 commit comments

Comments
 (0)