change orderId calculation function

This commit is contained in:
Steam Deck User
2024-02-07 11:12:08 +04:00
parent e531ca3429
commit ed1a7fefe4
2 changed files with 14 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.55",
"version": "0.20.56",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -1,35 +1,16 @@
import { ethers } from 'ethers';
import { ethers, keccak256 } from 'ethers';
import type { Order } from '../types.js';
const hashOrder = (order: Order) => ethers.solidityPackedKeccak256(
[
'uint8',
'address',
'address',
'address',
'address',
'address',
'uint64',
'uint64',
'uint64',
'uint64',
'uint64',
'uint8',
],
[
'0x03',
order.senderAddress,
order.matcherAddress,
order.baseAsset,
order.quoteAsset,
order.matcherFeeAsset,
order.amount,
order.price,
order.matcherFee,
order.nonce,
order.expiration,
order.buySide === 1 ? '0x01' : '0x00',
],
);
const ORDER_TYPEHASH = "0xb5132db62dfceb466f2f8aee7a039db36a99772e5a9771d28388a5f9baad7c54"
export default hashOrder;
export default function getOrderHash(order: Order) {
const abiCoder = ethers.AbiCoder.defaultAbiCoder()
const { senderAddress, matcherAddress, baseAsset, quoteAsset, matcherFeeAsset, amount, price, matcherFee, nonce, expiration, buySide } = order
const orderBytes = abiCoder.encode(
["bytes32", "address", "address", "address", "address", "address", "uint64", "uint64", "uint64", "uint64", "uint64", "uint8"],
[ORDER_TYPEHASH, senderAddress, matcherAddress, baseAsset, quoteAsset, matcherFeeAsset, amount, price, matcherFee, nonce, expiration, buySide]
)
return keccak256(orderBytes)
}