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

NFT-000: hot fix for polygon #214

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
NFT-000: hot fix for polygon
  • Loading branch information
sahar-fehri committed Jun 19, 2023
commit eedc12e83cc8fcec6c30783dd9e314c9508f3889
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,
);
sahar-fehri marked this conversation as resolved.
Show resolved Hide resolved
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
Loading