Skip to content

chore(contract-manager) Add custom fees for evm deployment #2499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion contract_manager/scripts/deploy_evm_pricefeed_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getOrDeployWormholeContract,
BaseDeployConfig,
} from "./common";
import { HermesClient } from "@pythnetwork/hermes-client";

interface DeploymentConfig extends BaseDeployConfig {
type: DeploymentType;
Expand Down Expand Up @@ -45,6 +46,21 @@ const parser = yargs(hideBin(process.argv))
default: 1,
desc: "Single update fee in wei for the price feed",
},
"single-update-fee-in-usd": {
type: "number",
demandOption: false,
desc: "Single update fee in USD for the price feed. (This overrides the single-update-fee-in-wei option) ",
},
"native-token-price-feed-id": {
type: "string",
demandOption: false,
desc: "Pyth Price Feed ID to fetch the current price of the native token (This will be used to calculate the single-update-fee-in-usd)",
},
"native-token-decimals": {
type: "number",
demandOption: false,
desc: "Number of decimals of the native token",
},
});

async function deployPriceFeedContracts(
Expand Down Expand Up @@ -92,11 +108,46 @@ async function deployPriceFeedContracts(

async function main() {
const argv = await parser.argv;
let singleUpdateFeeInWei = argv.singleUpdateFeeInWei;

const singleUpdateFeeInUsd = argv["single-update-fee-in-usd"];
const nativeTokenPriceFeedId = argv["native-token-price-feed-id"];
const nativeTokenDecimals = argv["native-token-decimals"];
if (
singleUpdateFeeInUsd &&
(nativeTokenPriceFeedId == null || nativeTokenDecimals == null)
) {
throw new Error(
"native-token-price-feed-id and native-token-decimals are required when single-update-fee-in-usd is provided",
);
}

if (nativeTokenPriceFeedId && singleUpdateFeeInUsd && nativeTokenDecimals) {
const hermesClient = new HermesClient("https://hermes.pyth.network");
const priceObject = await hermesClient.getLatestPriceUpdates(
[nativeTokenPriceFeedId],
{
parsed: true,
},
);

const price = priceObject.parsed?.[0].price;
if (price == null) {
throw new Error("Failed to get price of the native token");
}
const priceInUsd = Number(price.price);
const exponent = price.expo;
singleUpdateFeeInWei = Math.round(
Math.pow(10, nativeTokenDecimals) *
(singleUpdateFeeInUsd / (priceInUsd * Math.pow(10, exponent))),
);
console.log(`Single update fee in wei: ${singleUpdateFeeInWei}`);
}

const deploymentConfig: DeploymentConfig = {
type: toDeploymentType(argv.deploymentType),
validTimePeriodSeconds: argv.validTimePeriodSeconds,
singleUpdateFeeInWei: argv.singleUpdateFeeInWei,
singleUpdateFeeInWei: singleUpdateFeeInWei,
gasMultiplier: argv.gasMultiplier,
gasPriceMultiplier: argv.gasPriceMultiplier,
privateKey: toPrivateKey(argv.privateKey),
Expand Down