diff --git a/package.json b/package.json index 08cabb2..1d76cfd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/crypt/hashOrder.ts b/src/crypt/hashOrder.ts index 23bc474..c62f97d 100644 --- a/src/crypt/hashOrder.ts +++ b/src/crypt/hashOrder.ts @@ -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) +} \ No newline at end of file