mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 14:42:38 +03:00
feature: updated version to 0.20.14-rc0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.13",
|
||||
"version": "0.20.14-rc0",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.js",
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
export { default as signCancelOrder } from './signCancelOrder.js';
|
||||
export { default as signCancelOrderPersonal } from './signCancelOrderPersonal.js';
|
||||
export { default as signOrder } from './signOrder.js';
|
||||
export { default as signOrderPersonal } from './signOrderPersonal.js';
|
||||
|
||||
@@ -3,33 +3,27 @@ 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';
|
||||
import signCancelOrderPersonal from './signCancelOrderPersonal.js';
|
||||
|
||||
type SignerWithTypedDataSign = ethers.Signer & TypedDataSigner;
|
||||
|
||||
const signCancelOrder = async (
|
||||
senderAddress: string,
|
||||
id: string,
|
||||
usePersonalSign: boolean,
|
||||
signer: ethers.Signer,
|
||||
chainId: SupportedChainId,
|
||||
) => {
|
||||
const cancelOrderRequest: CancelOrderRequest = {
|
||||
id,
|
||||
senderAddress,
|
||||
isPersonalSign: usePersonalSign,
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const typedDataSigner = signer as SignerWithTypedDataSign;
|
||||
|
||||
const signature = usePersonalSign
|
||||
? await signCancelOrderPersonal(cancelOrderRequest, signer)
|
||||
// https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
||||
: await typedDataSigner.signTypedData(
|
||||
getDomainData(chainId),
|
||||
CANCEL_ORDER_TYPES,
|
||||
cancelOrderRequest,
|
||||
);
|
||||
const signature = await typedDataSigner.signTypedData(
|
||||
getDomainData(chainId),
|
||||
CANCEL_ORDER_TYPES,
|
||||
cancelOrderRequest,
|
||||
);
|
||||
|
||||
// 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"
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { ethers } from 'ethers';
|
||||
import type { CancelOrderRequest } from '../types.js';
|
||||
|
||||
const signCancelOrderPersonal = async (
|
||||
cancelOrderRequest: CancelOrderRequest,
|
||||
signer: ethers.Signer,
|
||||
) => {
|
||||
const types = ['string', 'string', 'address'];
|
||||
const message = ethers.solidityPackedKeccak256(
|
||||
types,
|
||||
['cancelOrder', cancelOrderRequest.id, cancelOrderRequest.senderAddress],
|
||||
);
|
||||
const signature = await signer.signMessage(ethers.getBytes(message));
|
||||
|
||||
// NOTE: metamask broke sig.v value and we fix it in next line
|
||||
return ethers.Signature.from(signature).serialized;
|
||||
};
|
||||
|
||||
export default signCancelOrderPersonal;
|
||||
@@ -7,7 +7,6 @@ import type { Order, SignedOrder, SupportedChainId } from '../types.js';
|
||||
import normalizeNumber from '../utils/normalizeNumber.js';
|
||||
import getDomainData from './getDomainData.js';
|
||||
import hashOrder from './hashOrder.js';
|
||||
import signOrderPersonal from './signOrderPersonal.js';
|
||||
|
||||
const DEFAULT_EXPIRATION = 29 * 24 * 60 * 60 * 1000; // 29 days
|
||||
|
||||
@@ -23,7 +22,6 @@ export const signOrder = async (
|
||||
senderAddress: string,
|
||||
matcherAddress: string,
|
||||
serviceFeeAssetAddr: string,
|
||||
usePersonalSign: boolean,
|
||||
signer: ethers.Signer,
|
||||
chainId: SupportedChainId,
|
||||
) => {
|
||||
@@ -54,19 +52,16 @@ export const signOrder = async (
|
||||
nonce,
|
||||
expiration,
|
||||
buySide: side === 'BUY' ? 1 : 0,
|
||||
isPersonalSign: usePersonalSign,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const typedDataSigner = signer as SignerWithTypedDataSign;
|
||||
|
||||
const signature = usePersonalSign
|
||||
? await signOrderPersonal(order, signer)
|
||||
: await typedDataSigner.signTypedData(
|
||||
getDomainData(chainId),
|
||||
ORDER_TYPES,
|
||||
order,
|
||||
);
|
||||
const signature = await typedDataSigner.signTypedData(
|
||||
getDomainData(chainId),
|
||||
ORDER_TYPES,
|
||||
order,
|
||||
);
|
||||
|
||||
// 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"
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { ethers } from 'ethers';
|
||||
import type { Order } from '../types.js';
|
||||
|
||||
const signOrderPersonal = async (order: Order, signer: ethers.Signer) => {
|
||||
const message = ethers.solidityPackedKeccak256(
|
||||
[
|
||||
'string', 'address', 'address', 'address', 'address',
|
||||
'address', 'uint64', 'uint64', 'uint64', 'uint64', 'uint64', 'uint8',
|
||||
],
|
||||
[
|
||||
'order',
|
||||
order.senderAddress,
|
||||
order.matcherAddress,
|
||||
order.baseAsset,
|
||||
order.quoteAsset,
|
||||
order.matcherFeeAsset,
|
||||
order.amount,
|
||||
order.price,
|
||||
order.matcherFee,
|
||||
order.nonce,
|
||||
order.expiration,
|
||||
order.buySide,
|
||||
],
|
||||
);
|
||||
const signature = await signer.signMessage(ethers.getBytes(message));
|
||||
|
||||
// NOTE: metamask broke sig.v value and we fix it in next line
|
||||
return ethers.Signature.from(signature).serialized;
|
||||
};
|
||||
|
||||
export default signOrderPersonal;
|
||||
@@ -48,7 +48,6 @@ export type Order = {
|
||||
nonce: number // uint64
|
||||
expiration: number // uint64
|
||||
buySide: 0 | 1 // uint8, 1=buy, 0=sell
|
||||
isPersonalSign: boolean // bool
|
||||
}
|
||||
|
||||
export type SignedOrder = {
|
||||
@@ -60,7 +59,6 @@ export type SignedOrder = {
|
||||
export type CancelOrderRequest = {
|
||||
id: number | string
|
||||
senderAddress: string
|
||||
isPersonalSign: boolean
|
||||
}
|
||||
|
||||
export type SignedCancelOrderRequest = {
|
||||
|
||||
Reference in New Issue
Block a user