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

Commit 58d07e7

Browse files
authored
Update packages to handle fee (#60)
* Update testnet spy * Add fee to code + readme * Bump package versions * Remove ropsten contract address
1 parent 3239ea6 commit 58d07e7

File tree

9 files changed

+33
-11
lines changed

9 files changed

+33
-11
lines changed

pyth-evm-js/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ setTimeout(() => {
5959
// call the Pyth Contract with this data.
6060
const priceUpdateData = await connection.getPriceUpdateData(priceIds);
6161

62-
await someContract.doSomething(someArg, otherArg, priceUpdateData);
62+
// If the user is paying the price update fee, you need to fetch it from the Pyth contract.
63+
// Please refer to https://docs.pyth.network/consume-data/on-demand#fees for more information.
64+
//
65+
// `pythContract` below is a web3.js contract; if you wish to use ethers, you need to change it accordingly.
66+
// You can find the Pyth interface ABI in @pythnetwork/pyth-sdk-solidity npm package.
67+
const updateFee = await pythContract.methods
68+
.getUpdateFee(priceFeedUpdateData.length)
69+
.call();
70+
71+
// Calling someContract method
72+
// `someContract` below is a web3.js contract; if you wish to use ethers, you need to change it accordingly.
73+
await someContract.methods
74+
.doSomething(someArg, otherArg, priceUpdateData)
75+
.send({ value: updateFee });
6376
```
6477

6578
`SomeContract` looks like so:

pyth-evm-js/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyth-evm-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-js",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Pyth Network EVM Utils in JS",
55
"homepage": "https://pyth.network",
66
"author": {

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ async function run() {
114114
}
115115
);
116116

117+
const updateFee = await pythContract.methods
118+
.getUpdateFee(priceFeedUpdateData.length)
119+
.call();
120+
console.log(`Update fee: ${updateFee}`);
121+
117122
pythContract.methods
118123
.updatePriceFeeds(priceFeedUpdateData)
119-
.send()
124+
.send({ value: updateFee })
120125
.on("transactionHash", (hash: string) => {
121126
console.log(`Tx hash: ${hash}`);
122127
});

pyth-evm-js/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const CONTRACT_ADDR: Record<string, string> = {
1313
bnb_testnet: "0xd7308b14BF4008e7C7196eC35610B1427C5702EA",
1414
fuji: "0xff1a0f4744e8582DF1aE09D5611b887B6a12925C",
1515
fantom_testnet: "0xff1a0f4744e8582DF1aE09D5611b887B6a12925C",
16-
ropsten: "0xff1a0f4744e8582DF1aE09D5611b887B6a12925C",
1716
goerli: "0xff1a0f4744e8582DF1aE09D5611b887B6a12925C",
1817
mumbai: "0xff1a0f4744e8582DF1aE09D5611b887B6a12925C",
1918
aurora_testnet: "0x4305FB66699C3B2702D4d05CF36551390A4c69C6",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- "--spyRPC"
99
- "[::]:7072"
1010
- "--bootstrap"
11-
- "/dns4/wormhole-testnet-v2-bootstrap.certus.one/udp/8999/quic/p2p/12D3KooWBY9ty9CXLBXGQzMuqkziLntsVcyz4pk1zWaJRvJn6Mmt"
11+
- "/dns4/wormhole-testnet-v2-bootstrap.certus.one/udp/8999/quic/p2p/12D3KooWAkB9ynDur1Jtoa97LBUp8RXdhzS5uHgAfdTquJbrbN7i"
1212
- "--network"
1313
- "/wormhole/testnet/2/1"
1414
- "--logLevel"

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

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyth-evm-price-pusher/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-price-pusher",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Pyth EVM Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,18 @@ export class Pusher {
108108
)
109109
);
110110

111+
const updateFee = await this.pythContract.methods
112+
.getUpdateFee(priceFeedUpdateData.length)
113+
.call();
114+
console.log(`Update fee: ${updateFee}`);
115+
111116
this.pythContract.methods
112117
.updatePriceFeedsIfNecessary(
113118
priceFeedUpdateData,
114119
priceIds,
115120
pubTimesToPush
116121
)
117-
.send()
122+
.send({ value: updateFee })
118123
.on("transactionHash", (hash: string) => {
119124
console.log(`Successful. Tx hash: ${hash}`);
120125
})

0 commit comments

Comments
 (0)