mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-18 03:45:02 +03:00
fix signLockOrder
This commit is contained in:
43
package-lock.json
generated
43
package-lock.json
generated
@@ -1,17 +1,16 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.42-rc12",
|
||||
"version": "0.20.42-rc13",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.42-rc12",
|
||||
"version": "0.20.42-rc13",
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.21.0",
|
||||
"@ethersproject/abstract-signer": "^5.7.0",
|
||||
"@ethersproject/providers": "^5.7.2",
|
||||
"@orionprotocol/contracts": "1.22.6",
|
||||
"@types/lodash.clonedeep": "^4.5.9",
|
||||
@@ -1084,28 +1083,6 @@
|
||||
"@ethersproject/web": "^5.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@ethersproject/abstract-signer": {
|
||||
"version": "5.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abstract-signer/-/abstract-signer-5.7.0.tgz",
|
||||
"integrity": "sha512-a16V8bq1/Cz+TGCkE2OPMTOUDLS3grCpdjoJCYNnVBbdYEMSgKrU0+B90s8b6H+ByYTBZN7a3g76jdIJi7UfKQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2"
|
||||
},
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://www.buymeacoffee.com/ricmoo"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"@ethersproject/abstract-provider": "^5.7.0",
|
||||
"@ethersproject/bignumber": "^5.7.0",
|
||||
"@ethersproject/bytes": "^5.7.0",
|
||||
"@ethersproject/logger": "^5.7.0",
|
||||
"@ethersproject/properties": "^5.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@ethersproject/address": {
|
||||
"version": "5.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/address/-/address-5.7.0.tgz",
|
||||
@@ -1236,7 +1213,6 @@
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"@ethersproject/abstract-signer": "^5.7.0",
|
||||
"@ethersproject/address": "^5.7.0",
|
||||
"@ethersproject/base64": "^5.7.0",
|
||||
"@ethersproject/bignumber": "^5.7.0",
|
||||
@@ -1333,7 +1309,6 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@ethersproject/abstract-provider": "^5.7.0",
|
||||
"@ethersproject/abstract-signer": "^5.7.0",
|
||||
"@ethersproject/address": "^5.7.0",
|
||||
"@ethersproject/base64": "^5.7.0",
|
||||
"@ethersproject/basex": "^5.7.0",
|
||||
@@ -12573,18 +12548,6 @@
|
||||
"@ethersproject/web": "^5.7.0"
|
||||
}
|
||||
},
|
||||
"@ethersproject/abstract-signer": {
|
||||
"version": "5.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abstract-signer/-/abstract-signer-5.7.0.tgz",
|
||||
"integrity": "sha512-a16V8bq1/Cz+TGCkE2OPMTOUDLS3grCpdjoJCYNnVBbdYEMSgKrU0+B90s8b6H+ByYTBZN7a3g76jdIJi7UfKQ==",
|
||||
"requires": {
|
||||
"@ethersproject/abstract-provider": "^5.7.0",
|
||||
"@ethersproject/bignumber": "^5.7.0",
|
||||
"@ethersproject/bytes": "^5.7.0",
|
||||
"@ethersproject/logger": "^5.7.0",
|
||||
"@ethersproject/properties": "^5.7.0"
|
||||
}
|
||||
},
|
||||
"@ethersproject/address": {
|
||||
"version": "5.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/address/-/address-5.7.0.tgz",
|
||||
@@ -12645,7 +12608,6 @@
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/hash/-/hash-5.7.0.tgz",
|
||||
"integrity": "sha512-qX5WrQfnah1EFnO5zJv1v46a8HW0+E5xuBBDTwMFZLuVTx0tbU2kkx15NqdjxecrLGatQN9FGQKpb1FKdHCt+g==",
|
||||
"requires": {
|
||||
"@ethersproject/abstract-signer": "^5.7.0",
|
||||
"@ethersproject/address": "^5.7.0",
|
||||
"@ethersproject/base64": "^5.7.0",
|
||||
"@ethersproject/bignumber": "^5.7.0",
|
||||
@@ -12692,7 +12654,6 @@
|
||||
"integrity": "sha512-g34EWZ1WWAVgr4aptGlVBF8mhl3VWjv+8hoAnzStu8Ah22VHBsuGzP17eb6xDVRzw895G4W7vvx60lFFur/1Rg==",
|
||||
"requires": {
|
||||
"@ethersproject/abstract-provider": "^5.7.0",
|
||||
"@ethersproject/abstract-signer": "^5.7.0",
|
||||
"@ethersproject/address": "^5.7.0",
|
||||
"@ethersproject/base64": "^5.7.0",
|
||||
"@ethersproject/basex": "^5.7.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.42-rc12",
|
||||
"version": "0.20.42-rc13",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.js",
|
||||
@@ -86,7 +86,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.21.0",
|
||||
"@ethersproject/abstract-signer": "^5.7.0",
|
||||
"@ethersproject/providers": "^5.7.2",
|
||||
"@orionprotocol/contracts": "1.22.6",
|
||||
"@types/lodash.clonedeep": "^4.5.9",
|
||||
|
||||
11
src/constants/lockOrderTypes.ts
Normal file
11
src/constants/lockOrderTypes.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const LOCK_ORDER_TYPES = {
|
||||
Order: [
|
||||
{ name: 'user', type: 'address' },
|
||||
{ name: 'sender', type: 'address' },
|
||||
{ name: 'expiration', type: 'uint64' },
|
||||
{ name: 'asset', type: 'string' },
|
||||
{ name: 'amount', type: 'uint64' },
|
||||
{ name: 'targetChainId', type: 'uint64' },
|
||||
{ name: 'secretHash', type: 'string' },
|
||||
],
|
||||
};
|
||||
25
src/crypt/hashLockOrder.ts
Normal file
25
src/crypt/hashLockOrder.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ethers } from 'ethers';
|
||||
import type { LockOrder } from '../types.js';
|
||||
|
||||
export const hashLockOrder = (order: LockOrder) => ethers.solidityPackedKeccak256(
|
||||
[
|
||||
'uint8',
|
||||
'address',
|
||||
'uint64',
|
||||
'string',
|
||||
'uint64',
|
||||
'uint64',
|
||||
'uint64',
|
||||
'string'
|
||||
],
|
||||
[
|
||||
'0x03',
|
||||
order.user,
|
||||
order.sender,
|
||||
order.expiration,
|
||||
order.asset,
|
||||
order.amount,
|
||||
order.targetChainId,
|
||||
order.secretHash
|
||||
],
|
||||
);
|
||||
@@ -14,8 +14,6 @@ const hashOrder = (order: Order) => ethers.solidityPackedKeccak256(
|
||||
'uint64',
|
||||
'uint64',
|
||||
'uint64',
|
||||
'uint64',
|
||||
'uint64',
|
||||
'uint8',
|
||||
],
|
||||
[
|
||||
@@ -26,12 +24,10 @@ const hashOrder = (order: Order) => ethers.solidityPackedKeccak256(
|
||||
order.quoteAsset,
|
||||
order.matcherFeeAsset,
|
||||
order.amount,
|
||||
order.targetChainId,
|
||||
order.price,
|
||||
order.matcherFee,
|
||||
order.nonce,
|
||||
order.expiration,
|
||||
order.secretHash,
|
||||
order.buySide === 1 ? '0x01' : '0x00',
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
|
||||
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';
|
||||
|
||||
type SignerWithTypedDataSign = ethers.Signer & TypedDataSigner;
|
||||
|
||||
const signCancelOrder = async (
|
||||
senderAddress: string,
|
||||
id: string,
|
||||
@@ -16,10 +13,8 @@ const signCancelOrder = async (
|
||||
id,
|
||||
senderAddress,
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const typedDataSigner = signer as SignerWithTypedDataSign;
|
||||
|
||||
const signature = await typedDataSigner.signTypedData(
|
||||
const signature = await signer.signTypedData(
|
||||
getDomainData(chainId),
|
||||
CANCEL_ORDER_TYPES,
|
||||
cancelOrderRequest,
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
|
||||
import { ethers } from 'ethers';
|
||||
import ORDER_TYPES from '../constants/orderTypes.js';
|
||||
import type { LockOrder, SignedLockOrder, SupportedChainId } from '../types.js';
|
||||
import getDomainData from './getDomainData.js';
|
||||
import generateSecret from '../utils/generateSecret';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import normalizeNumber from '../utils/normalizeNumber';
|
||||
import { INTERNAL_PROTOCOL_PRECISION } from '../constants';
|
||||
import { LOCK_ORDER_TYPES } from '../constants/lockOrderTypes';
|
||||
|
||||
const DEFAULT_EXPIRATION = 29 * 24 * 60 * 60 * 1000; // 29 days
|
||||
|
||||
type SignerWithTypedDataSign = ethers.Signer & TypedDataSigner;
|
||||
|
||||
export type LockOrderProps = {
|
||||
userAddress: string // адрес юзера который хочет сделать лок
|
||||
senderAddress: string // broker
|
||||
@@ -20,7 +17,6 @@ export type LockOrderProps = {
|
||||
signer: ethers.Signer
|
||||
chainId: SupportedChainId
|
||||
targetChainId: SupportedChainId
|
||||
logger?: (message: string) => void
|
||||
}
|
||||
|
||||
export const signLockOrder = async ({
|
||||
@@ -31,7 +27,6 @@ export const signLockOrder = async ({
|
||||
targetChainId,
|
||||
asset,
|
||||
signer,
|
||||
logger
|
||||
}: LockOrderProps) => {
|
||||
const nonce = Date.now();
|
||||
const expiration = nonce + DEFAULT_EXPIRATION;
|
||||
@@ -51,23 +46,16 @@ export const signLockOrder = async ({
|
||||
targetChainId,
|
||||
secretHash,
|
||||
};
|
||||
logger?.('❌ test1');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const typedDataSigner = signer as SignerWithTypedDataSign;
|
||||
logger?.('❌ test2');
|
||||
|
||||
const signature = await typedDataSigner.signTypedData(
|
||||
const signature = await signer.signTypedData(
|
||||
getDomainData(chainId),
|
||||
ORDER_TYPES,
|
||||
LOCK_ORDER_TYPES,
|
||||
order,
|
||||
);
|
||||
logger?.('❌ test3');
|
||||
|
||||
// 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 = ethers.Signature.from(signature).serialized;
|
||||
logger?.('❌ test4');
|
||||
|
||||
// if (!fixedSignature) throw new Error("Can't sign order");
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { INTERNAL_PROTOCOL_PRECISION } from '../constants';
|
||||
@@ -11,8 +10,6 @@ import generateSecret from '../utils/generateSecret';
|
||||
|
||||
const DEFAULT_EXPIRATION = 29 * 24 * 60 * 60 * 1000; // 29 days
|
||||
|
||||
type SignerWithTypedDataSign = ethers.Signer & TypedDataSigner;
|
||||
|
||||
export const signOrder = async (
|
||||
baseAssetAddr: string,
|
||||
quoteAssetAddr: string,
|
||||
@@ -66,10 +63,7 @@ export const signOrder = async (
|
||||
buySide: side === 'BUY' ? 1 : 0,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const typedDataSigner = signer as SignerWithTypedDataSign;
|
||||
|
||||
const signature = await typedDataSigner.signTypedData(
|
||||
const signature = await signer.signTypedData(
|
||||
getDomainData(chainId),
|
||||
ORDER_TYPES,
|
||||
order,
|
||||
|
||||
Reference in New Issue
Block a user