Skip to content

Commit

Permalink
make fields in signOrder optional
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJuze committed Jan 19, 2024
1 parent 330fc51 commit fcc3017
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.42-rc5",
"version": "0.20.42-rc6",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/crypt/signLockOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand Down
8 changes: 5 additions & 3 deletions src/crypt/signOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,7 +57,7 @@ export const signOrder = async (
)),
nonce,
expiration,
...(targetChainId !== undefined
...(isCrossChain
? {
secretHash,
targetChainId
Expand Down Expand Up @@ -83,7 +85,7 @@ export const signOrder = async (
...order,
id: hashOrder(order),
signature: fixedSignature,
secret
...(isCrossChain ? { secret } : {})
};
return signedOrder;
};
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"noUnusedLocals": true /* Enable error reporting when a local variables aren't read. */,
"noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
"noUncheckedIndexedAccess": true,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"exactOptionalPropertyTypes": false, /* allow ? in interfaces */
},
"ts-node": {
// Tell ts-node CLI to install the --loader automatically, explained below
Expand Down

0 comments on commit fcc3017

Please sign in to comment.