make fields in signOrder optional

This commit is contained in:
TheJuze
2024-01-19 12:27:19 +03:00
parent 330fc513e5
commit fcc30178ab
6 changed files with 14 additions and 11 deletions

View File

@@ -14,10 +14,10 @@ export type LockOrderProps = {
senderAddress: string // broker
asset: string
amount: ethers.BigNumberish
targetChainId: ethers.BigNumberish
sign: string // подпись юзера
signer: ethers.Signer
chainId: SupportedChainId
targetChainId: SupportedChainId
}
export const signLockOrder = async ({

View File

@@ -25,13 +25,15 @@ export const signOrder = async (
serviceFeeAssetAddr: string,
signer: ethers.Signer,
chainId: SupportedChainId,
targetChainId?: ethers.BigNumberish,
targetChainId?: SupportedChainId,
) => {
const nonce = Date.now();
const expiration = nonce + DEFAULT_EXPIRATION;
const secret = generateSecret();
const secretHash = ethers.keccak256(secret);
const isCrossChain = targetChainId === undefined || targetChainId === chainId;
const order: Order = {
senderAddress,
matcherAddress,
@@ -55,7 +57,7 @@ export const signOrder = async (
)),
nonce,
expiration,
...(targetChainId !== undefined
...(isCrossChain
? {
secretHash,
targetChainId
@@ -83,7 +85,7 @@ export const signOrder = async (
...order,
id: hashOrder(order),
signature: fixedSignature,
secret
...(isCrossChain ? { secret } : {})
};
return signedOrder;
};

View File

@@ -51,7 +51,7 @@ export type Order = {
expiration: number // uint64
buySide: 0 | 1 // uint8, 1=buy, 0=sell
secretHash?: string // uint64
targetChainId?: ethers.BigNumberish // uint64
targetChainId?: SupportedChainId // uint64
}
export type LockOrder = {
@@ -60,14 +60,14 @@ export type LockOrder = {
expiration: ethers.BigNumberish // uint64
asset: string // address(?)
amount: ethers.BigNumberish // uint64
targetChainId: ethers.BigNumberish // uint64
targetChainId: SupportedChainId // uint64
secretHash: string // uint64
sign: string // uint64 // подпись юзера
}
type SignedOrderAdditionalProps = {
signature: string // bytes
secret: string
secret?: string
needWithdraw?: boolean // bool (not supported yet by smart-contract)
}