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

Commit

Permalink
NFT-000: hot fix for polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri committed Jun 19, 2023
1 parent 1cae40a commit eedc12e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 22 deletions.
53 changes: 46 additions & 7 deletions src/lib/ContractComponents/hasAccessControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import { DEFAULT_ADMIN_ROLE, DEFAULT_MINTER_ROLE } from '../constants';
type SingleAddressOptions = {
publicAddress: string;
gas?: string;
maxFeePerGas?: string;
maxPriorityFeePerGas?: string;
};

type RenounceOptions = {
gas?: string;
maxFeePerGas?: string;
maxPriorityFeePerGas?: string;
};

export default class HasAccessControl {
Expand Down Expand Up @@ -48,7 +52,12 @@ export default class HasAccessControl {
}

try {
const options = addGasPriceToOptions({}, params.gas);
const options = addGasPriceToOptions(
{},
params.gas,
params.maxFeePerGas,
params.maxPriorityFeePerGas,
);
return this.contractDeployed.grantRole(DEFAULT_MINTER_ROLE, params.publicAddress, options);
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
Expand Down Expand Up @@ -86,7 +95,12 @@ export default class HasAccessControl {
}

try {
const options = addGasPriceToOptions({}, params.gas);
const options = addGasPriceToOptions(
{},
params.gas,
params.maxFeePerGas,
params.maxPriorityFeePerGas,
);
return this.contractDeployed.renounceRole(DEFAULT_MINTER_ROLE, params.publicAddress, options);
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
Expand Down Expand Up @@ -122,7 +136,12 @@ export default class HasAccessControl {
}

try {
const options = addGasPriceToOptions({}, params.gas);
const options = addGasPriceToOptions(
{},
params.gas,
params.maxFeePerGas,
params.maxPriorityFeePerGas,
);
return this.contractDeployed.revokeRole(DEFAULT_MINTER_ROLE, params.publicAddress, options);
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
Expand Down Expand Up @@ -193,7 +212,12 @@ export default class HasAccessControl {
}

try {
const options = addGasPriceToOptions({}, params.gas);
const options = addGasPriceToOptions(
{},
params.gas,
params.maxFeePerGas,
params.maxPriorityFeePerGas,
);
return this.contractDeployed.grantRole(DEFAULT_ADMIN_ROLE, params.publicAddress, options);
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
Expand Down Expand Up @@ -230,7 +254,12 @@ export default class HasAccessControl {
}

try {
const options = addGasPriceToOptions({}, params.gas);
const options = addGasPriceToOptions(
{},
params.gas,
params.maxFeePerGas,
params.maxPriorityFeePerGas,
);
return this.contractDeployed.revokeRole(DEFAULT_ADMIN_ROLE, params.publicAddress, options);
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
Expand Down Expand Up @@ -267,7 +296,12 @@ export default class HasAccessControl {
}

try {
const options = addGasPriceToOptions({}, params.gas);
const options = addGasPriceToOptions(
{},
params.gas,
params.maxFeePerGas,
params.maxPriorityFeePerGas,
);
return this.contractDeployed.renounceRole(DEFAULT_ADMIN_ROLE, params.publicAddress, options);
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
Expand Down Expand Up @@ -329,7 +363,12 @@ export default class HasAccessControl {
}

try {
const options = addGasPriceToOptions({}, params.gas);
const options = addGasPriceToOptions(
{},
params.gas,
params.maxFeePerGas,
params.maxPriorityFeePerGas,
);
return this.contractDeployed.renounceOwnership(options);
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
Expand Down
40 changes: 25 additions & 15 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,35 @@ export const isJson = (param: string) => {
// eslint-disable-next-line no-promise-executor-return
export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

export const addGasPriceToOptions = (options: any, gas: string | undefined) => {
export const addGasPriceToOptions = (
options: any,
gas: string | undefined,
maxFeePerGas?: string | undefined,
maxPriorityFeePerGas?: string | undefined,
) => {
const newOptions = options;
if (gas) {
if (typeof parseFloat(gas) !== 'number') {
log.throwArgumentError(Logger.message.invalid_gas_price_supplied, 'gas', gas, {
// TODO: update location
location: Logger.location.ERC721MINTABLE_ADDGASPRICETOOPTIONS,
});
}
try {

try {
if (gas) {
if (typeof parseFloat(gas) !== 'number') {
log.throwArgumentError(Logger.message.invalid_gas_price_supplied, 'gas', gas, {
// TODO: update location
location: Logger.location.ERC721MINTABLE_ADDGASPRICETOOPTIONS,
});
}
newOptions.gasPrice = ethers.utils.parseUnits(gas, 'gwei');
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
// TODO: update location
location: Logger.location.ERC721MINTABLE_ADDGASPRICETOOPTIONS,
error,
});
} else if (maxFeePerGas || maxPriorityFeePerGas) {
newOptions.maxFeePerGas = maxFeePerGas;
newOptions.maxPriorityFeePerGas = maxPriorityFeePerGas;
}
} catch (error) {
return log.throwError(Logger.message.ethers_error, Logger.code.NETWORK, {
// TODO: update location
location: Logger.location.ERC721MINTABLE_ADDGASPRICETOOPTIONS,
error,
});
}

return newOptions;
};

Expand Down

0 comments on commit eedc12e

Please sign in to comment.