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

Commit

Permalink
Merge pull request #214 from ConsenSys/fix/NFTSDK-000-polygontx
Browse files Browse the repository at this point in the history
NFT-000: hot fix for polygon
  • Loading branch information
sahar-fehri committed Jun 19, 2023
2 parents 1cae40a + ad51f17 commit 1e3ea36
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
3 changes: 2 additions & 1 deletion integration-test/sdk.nfts.transfers.test-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,14 @@ describe('E2E Test: Sdk (read)', () => {
});
});

describe('As an account I should get lowest trade price for a given collection with days', () => {
describe.skip('As an account I should get lowest trade price for a given collection with days', () => {
const contractAddress = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D';
it('should get the lowest trade price', async () => {
const result = await sdk.api.getLowestTradePrice({
tokenAddress: contractAddress,
days: 10,
});
console.log('🚀 ~ file: sdk.nfts.transfers.test-integration.ts:442 ~ it ~ result:', result);

expect(result).toMatchObject({
transactionHash: expect.any(String),
Expand Down
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 1e3ea36

Please sign in to comment.