Remove unused chainId
variables in signature_utils.ts
.
Obey the linter gods.
This commit is contained in:
committed by
Amir Bandeali
parent
35f568e346
commit
f77823ee24
@@ -10,8 +10,9 @@ import { signatureUtils } from './signature_utils';
|
||||
import { CreateOrderOpts } from './types';
|
||||
export const orderFactory = {
|
||||
createOrderFromPartial(partialOrder: Partial<Order>): Order {
|
||||
if (_.isNil(partialOrder.chainId))
|
||||
if (_.isNil(partialOrder.chainId)) {
|
||||
throw new Error('chainId must be valid');
|
||||
}
|
||||
const defaultOrder = generateEmptyOrder(partialOrder.chainId);
|
||||
return {
|
||||
...defaultOrder,
|
||||
@@ -19,8 +20,9 @@ export const orderFactory = {
|
||||
};
|
||||
},
|
||||
createSignedOrderFromPartial(partialSignedOrder: Partial<SignedOrder>): SignedOrder {
|
||||
if (_.isNil(partialSignedOrder.chainId))
|
||||
if (_.isNil(partialSignedOrder.chainId)) {
|
||||
throw new Error('chainId must be valid');
|
||||
}
|
||||
const defaultOrder = generateEmptySignedOrder(partialSignedOrder.chainId);
|
||||
return {
|
||||
...defaultOrder,
|
||||
@@ -53,7 +55,7 @@ export const orderFactory = {
|
||||
salt: createOrderOpts.salt || defaultCreateOrderOpts.salt,
|
||||
expirationTimeSeconds:
|
||||
createOrderOpts.expirationTimeSeconds || defaultCreateOrderOpts.expirationTimeSeconds,
|
||||
chainId: chainId,
|
||||
chainId,
|
||||
};
|
||||
return order;
|
||||
},
|
||||
@@ -103,7 +105,7 @@ function generateEmptyOrder(chainId: number): Order {
|
||||
takerAssetData: constants.NULL_BYTES,
|
||||
salt: generatePseudoRandomSalt(),
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: chainId,
|
||||
chainId,
|
||||
feeRecipientAddress: constants.NULL_ADDRESS,
|
||||
expirationTimeSeconds: constants.INFINITE_TIMESTAMP_SEC,
|
||||
};
|
||||
|
@@ -42,7 +42,6 @@ type OrderValidationResult = OrderValidResult | OrderInvalidResult;
|
||||
export class OrderStateUtils {
|
||||
private readonly _balanceAndProxyAllowanceFetcher: AbstractBalanceAndProxyAllowanceFetcher;
|
||||
private readonly _orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher;
|
||||
private readonly _chainId: number;
|
||||
private static _validateIfOrderIsValid(
|
||||
signedOrder: SignedOrder,
|
||||
sidedOrderRelevantState: SidedOrderRelevantState,
|
||||
@@ -103,17 +102,14 @@ export class OrderStateUtils {
|
||||
* and proxyAllowances for Ethereum addresses. It must implement AbstractBalanceAndProxyAllowanceFetcher
|
||||
* @param orderFilledCancelledFetcher A class that is capable of fetching whether an order
|
||||
* is cancelled and how much of it has been filled. It must implement AbstractOrderFilledCancelledFetcher
|
||||
* @param chainId The chain ID of the network being used.
|
||||
* @return Instance of OrderStateUtils
|
||||
*/
|
||||
constructor(
|
||||
balanceAndProxyAllowanceFetcher: AbstractBalanceAndProxyAllowanceFetcher,
|
||||
orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher,
|
||||
chainId: number,
|
||||
) {
|
||||
this._balanceAndProxyAllowanceFetcher = balanceAndProxyAllowanceFetcher;
|
||||
this._orderFilledCancelledFetcher = orderFilledCancelledFetcher;
|
||||
this._chainId = chainId;
|
||||
}
|
||||
/**
|
||||
* Get the orderState for an "open" order (i.e where takerAddress=NULL_ADDRESS)
|
||||
|
@@ -232,7 +232,6 @@ export const signatureUtils = {
|
||||
if (err.message.includes('User denied message signature')) {
|
||||
throw err;
|
||||
}
|
||||
const chainId = await providerUtils.getChainIdAsync(supportedProvider);
|
||||
const orderHash = orderHashUtils.getOrderHashHex(order);
|
||||
const signatureHex = await signatureUtils.ecSignHashAsync(supportedProvider, orderHash, signerAddress);
|
||||
const signedOrder = {
|
||||
@@ -256,7 +255,6 @@ export const signatureUtils = {
|
||||
signerAddress: string,
|
||||
): Promise<SignedOrder> {
|
||||
const provider = providerUtils.standardizeOrThrow(supportedProvider);
|
||||
const chainId = await providerUtils.getChainIdAsync(provider);
|
||||
assert.isETHAddressHex('signerAddress', signerAddress);
|
||||
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
|
||||
const web3Wrapper = new Web3Wrapper(provider);
|
||||
|
@@ -20,7 +20,7 @@ describe('EIP712 Utils', () => {
|
||||
primaryType,
|
||||
{ Test: [{ name: 'testValue', type: 'uint256' }] },
|
||||
{ testValue: '1' },
|
||||
{ chainId: CHAIN_ID, verifyingContractAddress: constants.NULL_ADDRESS, },
|
||||
{ chainId: CHAIN_ID, verifyingContractAddress: constants.NULL_ADDRESS },
|
||||
);
|
||||
expect(typedData.domain).to.not.be.undefined();
|
||||
expect(typedData.types.EIP712Domain).to.not.be.undefined();
|
||||
|
@@ -60,11 +60,7 @@ describe('OrderStateUtils', () => {
|
||||
1,
|
||||
);
|
||||
|
||||
const orderStateUtils = new OrderStateUtils(
|
||||
mockBalanceFetcher,
|
||||
mockOrderFilledFetcher,
|
||||
CHAIN_ID,
|
||||
);
|
||||
const orderStateUtils = new OrderStateUtils(mockBalanceFetcher, mockOrderFilledFetcher, CHAIN_ID);
|
||||
const orderState = await orderStateUtils.getOpenOrderStateAsync(signedOrder);
|
||||
expect(orderState.isValid).to.eq(true);
|
||||
});
|
||||
@@ -83,11 +79,7 @@ describe('OrderStateUtils', () => {
|
||||
1,
|
||||
);
|
||||
|
||||
const orderStateUtils = new OrderStateUtils(
|
||||
mockBalanceFetcher,
|
||||
mockOrderFilledFetcher,
|
||||
CHAIN_ID,
|
||||
);
|
||||
const orderStateUtils = new OrderStateUtils(mockBalanceFetcher, mockOrderFilledFetcher, CHAIN_ID);
|
||||
const orderState = await orderStateUtils.getOpenOrderStateAsync(signedOrder);
|
||||
expect(orderState.isValid).to.eq(false);
|
||||
});
|
||||
@@ -107,11 +99,7 @@ describe('OrderStateUtils', () => {
|
||||
1,
|
||||
);
|
||||
|
||||
const orderStateUtils = new OrderStateUtils(
|
||||
mockBalanceFetcher,
|
||||
mockOrderFilledFetcher,
|
||||
CHAIN_ID,
|
||||
);
|
||||
const orderStateUtils = new OrderStateUtils(mockBalanceFetcher, mockOrderFilledFetcher, CHAIN_ID);
|
||||
const orderState = await orderStateUtils.getOpenOrderStateAsync(signedOrder);
|
||||
expect(orderState.isValid).to.eq(false);
|
||||
});
|
||||
@@ -131,11 +119,7 @@ describe('OrderStateUtils', () => {
|
||||
1,
|
||||
);
|
||||
|
||||
const orderStateUtils = new OrderStateUtils(
|
||||
mockBalanceFetcher,
|
||||
mockOrderFilledFetcher,
|
||||
CHAIN_ID,
|
||||
);
|
||||
const orderStateUtils = new OrderStateUtils(mockBalanceFetcher, mockOrderFilledFetcher, CHAIN_ID);
|
||||
const orderState = await orderStateUtils.getOpenOrderStateAsync(signedOrder);
|
||||
expect(orderState.isValid).to.eq(false);
|
||||
});
|
||||
@@ -154,11 +138,7 @@ describe('OrderStateUtils', () => {
|
||||
1,
|
||||
);
|
||||
|
||||
const orderStateUtils = new OrderStateUtils(
|
||||
mockBalanceFetcher,
|
||||
mockOrderFilledFetcher,
|
||||
CHAIN_ID,
|
||||
);
|
||||
const orderStateUtils = new OrderStateUtils(mockBalanceFetcher, mockOrderFilledFetcher, CHAIN_ID);
|
||||
const transactionHash = '0xdeadbeef';
|
||||
const orderState = await orderStateUtils.getOpenOrderStateAsync(signedOrder, transactionHash);
|
||||
expect(orderState.transactionHash).to.eq(transactionHash);
|
||||
|
@@ -102,23 +102,28 @@ export const providerUtils = {
|
||||
* @return A promise thar resolves to the chain ID of the network the provider
|
||||
* is connected to.
|
||||
*/
|
||||
async getChainIdAsync(supportedProvider: SupportedProvider): Promise<number> {
|
||||
const provider = this.standardizeOrThrow(supportedProvider);
|
||||
return new Promise<number>((accept, reject) => {
|
||||
provider.sendAsync({
|
||||
jsonrpc: '2.0',
|
||||
id: _.random(0, 2**64),
|
||||
method: 'net_version',
|
||||
params: []
|
||||
},
|
||||
(err : Error | null, result?: JSONRPCResponsePayload) => {
|
||||
if (!_.isNil(err))
|
||||
async getChainIdAsync(supportedProvider: SupportedProvider): Promise<number> {
|
||||
const provider = providerUtils.standardizeOrThrow(supportedProvider);
|
||||
// tslint:disable-next-line:custom-no-magic-numbers
|
||||
const RPC_ID_MAX = 2 ** 64;
|
||||
return new Promise<number>((accept, reject) => {
|
||||
provider.sendAsync(
|
||||
{
|
||||
jsonrpc: '2.0',
|
||||
id: _.random(1, RPC_ID_MAX),
|
||||
method: 'net_version',
|
||||
params: [],
|
||||
},
|
||||
(err: Error | null, result?: JSONRPCResponsePayload) => {
|
||||
if (!_.isNil(err)) {
|
||||
reject(err);
|
||||
if (!result)
|
||||
throw new Error('Invalid \'net_version\' response');
|
||||
accept(_.toNumber(result.result));
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
throw new Error("Invalid 'net_version' response");
|
||||
}
|
||||
accept(_.toNumber(result.result));
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@@ -71,11 +71,12 @@ export const signTypedDataUtils = {
|
||||
return ethers.utils.defaultAbiCoder.encode(encodedTypes, encodedValues);
|
||||
},
|
||||
_normalizeValue(type: string, value: any): EIP712ObjectValue {
|
||||
if (type == 'uint256') {
|
||||
const STRING_BASE = 10;
|
||||
if (type === 'uint256') {
|
||||
if (BigNumber.isBigNumber(value)) {
|
||||
return value.toString(10);
|
||||
return value.toString(STRING_BASE);
|
||||
}
|
||||
return new BigNumber(value).toString(10);
|
||||
return new BigNumber(value).toString(STRING_BASE);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
Reference in New Issue
Block a user