feat: update ethers@6

fix: bigint errors

fix: TS errors

fix: gasLimit fetch

fix: review comments

fix: contracts errors

chore: bump rc version

fix: revert wrong fix

fix: ts config

fix: ts config

fix: ts config

feat: update signer
This commit is contained in:
Oleg Nechiporenko
2023-09-07 00:12:07 +03:00
parent 27c426e815
commit c2a4084158
38 changed files with 409 additions and 608 deletions

View File

@@ -1,7 +1,7 @@
import { ethers } from 'ethers';
import type { Order } from '../types.js';
const hashOrder = (order: Order) => ethers.utils.solidityKeccak256(
const hashOrder = (order: Order) => ethers.solidityPackedKeccak256(
[
'uint8',
'address',

View File

@@ -1,6 +1,5 @@
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
import type { ethers } from 'ethers';
import { joinSignature, splitSignature } from 'ethers/lib/utils.js';
import { ethers } from 'ethers';
import CANCEL_ORDER_TYPES from '../constants/cancelOrderTypes.js';
import type { CancelOrderRequest, SignedCancelOrderRequest, SupportedChainId } from '../types.js';
import getDomainData from './getDomainData.js';
@@ -26,7 +25,7 @@ const signCancelOrder = async (
const signature = usePersonalSign
? await signCancelOrderPersonal(cancelOrderRequest, signer)
// https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
: await typedDataSigner._signTypedData(
: await typedDataSigner.signTypedData(
getDomainData(chainId),
CANCEL_ORDER_TYPES,
cancelOrderRequest,
@@ -34,7 +33,7 @@ const signCancelOrder = async (
// https://github.com/poap-xyz/poap-fun/pull/62#issue-928290265
// "Signature's v was always send as 27 or 28, but from Ledger was 0 or 1"
const fixedSignature = joinSignature(splitSignature(signature));
const fixedSignature = ethers.Signature.from(signature).serialized;
// if (!fixedSignature) throw new Error("Can't sign order cancel");

View File

@@ -1,5 +1,4 @@
import { ethers } from 'ethers';
import { arrayify, joinSignature, splitSignature } from 'ethers/lib/utils.js';
import type { CancelOrderRequest } from '../types.js';
const signCancelOrderPersonal = async (
@@ -7,14 +6,14 @@ const signCancelOrderPersonal = async (
signer: ethers.Signer,
) => {
const types = ['string', 'string', 'address'];
const message = ethers.utils.solidityKeccak256(
const message = ethers.solidityPackedKeccak256(
types,
['cancelOrder', cancelOrderRequest.id, cancelOrderRequest.senderAddress],
);
const signature = await signer.signMessage(arrayify(message));
const signature = await signer.signMessage(ethers.getBytes(message));
// NOTE: metamask broke sig.v value and we fix it in next line
return joinSignature(splitSignature(signature));
return ethers.Signature.from(signature).serialized;
};
export default signCancelOrderPersonal;

View File

@@ -1,7 +1,6 @@
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
import { BigNumber } from 'bignumber.js';
import type { ethers } from 'ethers';
import { joinSignature, splitSignature } from 'ethers/lib/utils.js';
import { ethers } from 'ethers';
import { INTERNAL_PROTOCOL_PRECISION } from '../constants/index.js';
import ORDER_TYPES from '../constants/orderTypes.js';
import type { Order, SignedOrder, SupportedChainId } from '../types.js';
@@ -37,21 +36,21 @@ export const signOrder = async (
baseAsset: baseAssetAddr,
quoteAsset: quoteAssetAddr,
matcherFeeAsset: serviceFeeAssetAddr,
amount: normalizeNumber(
amount: Number(normalizeNumber(
amount,
INTERNAL_PROTOCOL_PRECISION,
BigNumber.ROUND_FLOOR,
).toNumber(),
price: normalizeNumber(
)),
price: Number(normalizeNumber(
price,
INTERNAL_PROTOCOL_PRECISION,
BigNumber.ROUND_FLOOR,
).toNumber(),
matcherFee: normalizeNumber(
)),
matcherFee: Number(normalizeNumber(
matcherFee,
INTERNAL_PROTOCOL_PRECISION,
BigNumber.ROUND_CEIL, // ROUND_CEIL because we don't want get "not enough fee" error
).toNumber(),
)),
nonce,
expiration,
buySide: side === 'BUY' ? 1 : 0,
@@ -63,7 +62,7 @@ export const signOrder = async (
const signature = usePersonalSign
? await signOrderPersonal(order, signer)
: await typedDataSigner._signTypedData(
: await typedDataSigner.signTypedData(
getDomainData(chainId),
ORDER_TYPES,
order,
@@ -71,7 +70,7 @@ export const signOrder = async (
// https://github.com/poap-xyz/poap-fun/pull/62#issue-928290265
// "Signature's v was always send as 27 or 28, but from Ledger was 0 or 1"
const fixedSignature = joinSignature(splitSignature(signature));
const fixedSignature = ethers.Signature.from(signature).serialized;
// if (!fixedSignature) throw new Error("Can't sign order");

View File

@@ -1,10 +1,8 @@
import { ethers } from 'ethers';
import type { Order } from '../types.js';
const { arrayify, joinSignature, splitSignature } = ethers.utils;
const signOrderPersonal = async (order: Order, signer: ethers.Signer) => {
const message = ethers.utils.solidityKeccak256(
const message = ethers.solidityPackedKeccak256(
[
'string', 'address', 'address', 'address', 'address',
'address', 'uint64', 'uint64', 'uint64', 'uint64', 'uint64', 'uint8',
@@ -24,10 +22,10 @@ const signOrderPersonal = async (order: Order, signer: ethers.Signer) => {
order.buySide,
],
);
const signature = await signer.signMessage(arrayify(message));
const signature = await signer.signMessage(ethers.getBytes(message));
// NOTE: metamask broke sig.v value and we fix it in next line
return joinSignature(splitSignature(signature));
return ethers.Signature.from(signature).serialized;
};
export default signOrderPersonal;