Skip to content

Commit

Permalink
fix: unable to deploy contracts on stability mainnet
Browse files Browse the repository at this point in the history
make sure stability uses gas station to estimate gas price and add
dotenv package to read stability api key
  • Loading branch information
MinHtet-O committed Mar 25, 2024
1 parent 739981a commit b7b0cd5
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 222 deletions.
287 changes: 99 additions & 188 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@tradetrust-tt/token-registry": "^4.9.0",
"@tradetrust-tt/tradetrust": "^6.9.1",
"@tradetrust-tt/tradetrust-config": "^1.14.1",
"@tradetrust-tt/tt-verify": "^8.8.5",
"@tradetrust-tt/tt-verify": "^8.9.1",
"ajv": "^8.4.0",
"ajv-formats": "^2.1.0",
"chalk": "^4.1.2",
Expand Down
6 changes: 1 addition & 5 deletions src/common/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ const jsonRpcProvider =
() =>
new providers.JsonRpcProvider(url);

const getStabilityApiKey = (): string => {
return process.env.STABILITY_API_KEY ?? "";
};

export const supportedNetwork: {
[key in NetworkCmdName]: SupportedNetwork;
} = {
Expand Down Expand Up @@ -119,7 +115,7 @@ export const supportedNetwork: {
},
[NetworkCmdName.Stability]: {
explorer: "https://stability.blockscout.com",
provider: jsonRpcProvider(`https://gtn.stabilityprotocol.com/zgt/${getStabilityApiKey()}`),
provider: jsonRpcProvider(`https://gtn.stabilityprotocol.com/zgt/tradeTrust`),
networkId: 101010,
networkName: NetworkCmdName.Stability,
currency: "FREE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const deployDocumentStore = async ({

let transaction: DocumentStore;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
signale.await(`Sending transaction to pool`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const deployTokenRegistry = async ({
let gasFees;

if (canEstimateGasPrice(network)) {
gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/document-store/grant-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const grantDocumentStoreRole = async ({
});
process.exit(0);
}
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await documentStore.callStatic.grantRole(roleString, account);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/document-store/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const issueToDocumentStore = async ({
});
process.exit(0);
}
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await documentStore.callStatic.issue(hash);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/document-store/revoke-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const revokeDocumentStoreRole = async ({
});
process.exit(0);
}
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await documentStore.callStatic.revokeRole(roleString, account);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/document-store/revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const revokeToDocumentStore = async ({
});
process.exit(0);
}
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await documentStore.callStatic.revoke(hash);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/document-store/transfer-ownership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const transferDocumentStoreOwnership = async ({
});
process.exit(0);
}
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
signale.await(`Sending transaction to pool`);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/title-escrow/acceptSurrendered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const acceptSurrendered = async ({
}
let transaction;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ network, provider: wallet.provider, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await tokenRegistryInstance.callStatic.burn(tokenId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const endorseNominatedBeneficiary = async ({
}
let transaction;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await titleEscrow.callStatic.transferBeneficiary(nominatedBeneficiary);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/title-escrow/nominateBeneficiary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const nominateBeneficiary = async ({
}
let transaction;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await titleEscrow.callStatic.nominate(newBeneficiary);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/title-escrow/rejectSurrendered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const rejectSurrendered = async ({
}
let transaction;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await tokenRegistryInstance.callStatic.restore(tokenId);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/title-escrow/surrenderDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const surrenderDocument = async ({
let transaction;

if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await titleEscrow.callStatic.surrender();
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/title-escrow/transferHolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const transferHolder = async ({
}
let transaction;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await titleEscrow.callStatic.transferHolder(to);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/title-escrow/transferOwners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const transferOwners = async ({
}
let transaction;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await titleEscrow.callStatic.transferOwners(newOwner, newHolder);
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/token-registry/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const issueToTokenRegistry = async ({

let transaction;
if (canEstimateGasPrice(network)) {
const gasFees = await getGasFees({ provider: wallet.provider, network, ...rest });
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
trace(`Gas maxFeePerGas: ${gasFees.maxFeePerGas}`);
trace(`Gas maxPriorityFeePerGas: ${gasFees.maxPriorityFeePerGas}`);
await tokenRegistry.callStatic.mint(beneficiary, holder, tokenId);
Expand Down
16 changes: 3 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,11 @@ export const scaleBigNumber = (wei: BigNumber | null | undefined, multiplier: nu

interface GetGasFeesArgs extends GasPriceScale {
provider: Provider;
network: string;
}

export const getGasFees = async ({
provider,
maxPriorityFeePerGasScale,
network,
}: GetGasFeesArgs): Promise<Overrides> => {
export const getGasFees = async ({ provider, maxPriorityFeePerGasScale }: GetGasFeesArgs): Promise<Overrides> => {
const feeData = await getFeeData(provider);
const { maxFeePerGas, maxPriorityFeePerGas } = feeData;
if (network === NetworkCmdName.StabilityTestnet) {
return {
maxFeePerGas: 0,
maxPriorityFeePerGas: 0,
};
}
return {
maxPriorityFeePerGas: scaleBigNumber(maxPriorityFeePerGas, maxPriorityFeePerGasScale),
maxFeePerGas: calculateMaxFee(maxFeePerGas, maxPriorityFeePerGas, maxPriorityFeePerGasScale),
Expand Down Expand Up @@ -122,7 +111,8 @@ export const displayTransactionPrice = async (
if (
network === NetworkCmdName.XDC ||
network === NetworkCmdName.XDCApothem ||
network === NetworkCmdName.StabilityTestnet
network === NetworkCmdName.StabilityTestnet ||
network === NetworkCmdName.Stability
) {
return;
}
Expand Down

0 comments on commit b7b0cd5

Please sign in to comment.