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

Commit e0a4fe0

Browse files
authored
Merge pull request #43 from pyth-network:abehjati/update-interface
Update packages according to pyth-sdk-solidity v1 interface
2 parents ef14552 + 1ad1a7e commit e0a4fe0

File tree

10 files changed

+50
-64
lines changed

10 files changed

+50
-64
lines changed

pyth-evm-js/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ contract SomeContract {
7575
pyth = IPyth(pythContract);
7676
}
7777
78-
function doSomething(uint someArg, string memory otherArg, bytes[] memory priceUpdateData) public {
78+
function doSomething(uint someArg, string memory otherArg, bytes[] memory priceUpdateData) public payable {
7979
// Update the prices to be set to the latest values
80-
pyth.updatePriceFeeds(priceUpdateData);
80+
uint fee = pyth.getUpdateFee(priceUpdateData.length);
81+
pyth.updatePriceFeeds{value: fee}(priceUpdateData);
8182
8283
// Doing other things that uses prices
8384
bytes32 priceId = 0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b;
84-
PythStructs.Price currentPrice = pyth.getCurrentPrice(priceId);
85+
PythStructs.Price price = pyth.getPrice(priceId);
8586
}
8687
}
8788
```

pyth-evm-js/package-lock.json

Lines changed: 15 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-js",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "Pyth Network EVM Utils in JS",
55
"homepage": "https://pyth.network",
66
"author": {
@@ -30,6 +30,7 @@
3030
],
3131
"license": "Apache-2.0",
3232
"devDependencies": {
33+
"@pythnetwork/pyth-sdk-solidity": "^1.0.1",
3334
"@truffle/hdwallet-provider": "^2.0.8",
3435
"@types/ethereum-protocol": "^1.0.2",
3536
"@types/jest": "^27.4.1",

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { hideBin } from "yargs/helpers";
44

55
import { EvmPriceServiceConnection, CONTRACT_ADDR } from "../index";
66
import HDWalletProvider from "@truffle/hdwallet-provider";
7+
import PythInterfaceAbi from "@pythnetwork/pyth-sdk-solidity/abis/IPyth.json";
78

89
const argv = yargs(hideBin(process.argv))
910
.option("network", {
@@ -84,22 +85,6 @@ if (CONFIG[argv.network] !== undefined) {
8485
pythContractAddr = argv.pythContract;
8586
}
8687

87-
const pythRelayAbi = [
88-
{
89-
inputs: [
90-
{
91-
internalType: "bytes[]",
92-
name: "updateData",
93-
type: "bytes[]",
94-
},
95-
],
96-
name: "updatePriceFeeds",
97-
outputs: [],
98-
stateMutability: "nonpayable" as const,
99-
type: "function" as const,
100-
},
101-
];
102-
10388
const connection = new EvmPriceServiceConnection(argv.endpoint);
10489

10590
async function run() {
@@ -121,9 +106,13 @@ async function run() {
121106
);
122107
console.log(priceFeedUpdateData);
123108

124-
const pythContract = new web3.eth.Contract(pythRelayAbi, pythContractAddr, {
125-
from: provider.getAddress(0),
126-
});
109+
const pythContract = new web3.eth.Contract(
110+
PythInterfaceAbi as any,
111+
pythContractAddr,
112+
{
113+
from: provider.getAddress(0),
114+
}
115+
);
127116

128117
pythContract.methods
129118
.updatePriceFeeds(priceFeedUpdateData)

pyth-evm-js/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"declaration": true,
66
"outDir": "./lib",
77
"strict": true,
8-
"esModuleInterop": true
8+
"esModuleInterop": true,
9+
"resolveJsonModule": true
910
},
1011
"include": ["src"],
1112
"exclude": ["node_modules", "**/__tests__/*"]

pyth-evm-price-pusher/docker-compose.mainnet.sampleyaml renamed to pyth-evm-price-pusher/docker-compose.mainnet.sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
spy:
3-
image: ghcr.io/wormhole-foundation/guardiand:v2.8.10.1
3+
image: ghcr.io/wormhole-foundation/guardiand:v2.10.3
44
command:
55
- "spy"
66
- "--nodeKey"

pyth-evm-price-pusher/docker-compose.testnet.sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
spy:
3-
image: ghcr.io/wormhole-foundation/guardiand:v2.8.10.1
3+
image: ghcr.io/wormhole-foundation/guardiand:v2.10.3
44
command:
55
- "spy"
66
- "--nodeKey"

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": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Pyth EVM Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",
@@ -46,7 +46,7 @@
4646
},
4747
"dependencies": {
4848
"@pythnetwork/pyth-evm-js": "^0.5.0",
49-
"@pythnetwork/pyth-sdk-solidity": "^0.5.2",
49+
"@pythnetwork/pyth-sdk-solidity": "^1.0.1",
5050
"@truffle/hdwallet-provider": "^2.0.8",
5151
"joi": "^17.6.0",
5252
"web3": "^1.5.3",

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,40 +121,21 @@ export class EvmPriceListener implements PriceListener {
121121
async getOnChainPriceInfo(
122122
priceId: HexString
123123
): Promise<PriceInfo | undefined> {
124-
let priceFeedRaw;
124+
let priceRaw;
125125
try {
126-
priceFeedRaw = await this.pythContract.methods
127-
.queryPriceFeed(addLeading0x(priceId))
126+
priceRaw = await this.pythContract.methods
127+
.getPriceUnsafe(addLeading0x(priceId))
128128
.call();
129129
} catch (e) {
130130
console.error(`Getting on-chain price for ${priceId} failed. Error:`);
131131
console.error(e);
132132
return undefined;
133133
}
134134

135-
const priceFeed = new PriceFeed({
136-
id: removeLeading0x(priceFeedRaw.id),
137-
productId: removeLeading0x(priceFeedRaw.productId),
138-
price: priceFeedRaw.price,
139-
conf: priceFeedRaw.conf,
140-
expo: Number(priceFeedRaw.expo),
141-
status: statusNumberToEnum(Number(priceFeedRaw.status)),
142-
maxNumPublishers: Number(priceFeedRaw.maxNumPublishers),
143-
numPublishers: Number(priceFeedRaw.numPublishers),
144-
emaPrice: priceFeedRaw.emaPrice,
145-
emaConf: priceFeedRaw.emaConf,
146-
publishTime: Number(priceFeedRaw.publishTime),
147-
prevPrice: priceFeedRaw.prevPrice,
148-
prevConf: priceFeedRaw.prevConf,
149-
prevPublishTime: Number(priceFeedRaw.prevPublishTime),
150-
});
151-
152-
const latestAvailablePrice = priceFeed.getLatestAvailablePriceUnchecked();
153-
154135
return {
155-
conf: latestAvailablePrice[0].conf,
156-
price: latestAvailablePrice[0].price,
157-
publishTime: latestAvailablePrice[1],
136+
conf: priceRaw.conf,
137+
price: priceRaw.price,
138+
publishTime: priceRaw.publishTime,
158139
};
159140
}
160141
}

0 commit comments

Comments
 (0)