diff --git a/.eslintignore b/.eslintignore index b194bdc..2c5c3a5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -12,3 +12,4 @@ typechain/ # files .solcover.js coverage.json +.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 64709e6..09886cc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { plugins: ["@typescript-eslint", "unused-imports"], extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], parserOptions: { - project: "./tsconfig.json", + project: "./tsconfig.eslint.json", tsconfigRootDir: __dirname, sourceType: "module", }, diff --git a/examples/approveAllowances.ts b/examples/approveAllowances.ts index 2fce123..f990b56 100644 --- a/examples/approveAllowances.ts +++ b/examples/approveAllowances.ts @@ -2,16 +2,16 @@ import { BigNumber, constants, ethers } from "ethers"; import { config as dotenvConfig } from "dotenv"; import { resolve } from "path"; import { Chain } from "../src"; +import { getContractConfig } from "../src/config"; import { usdcAbi } from "./abi/usdcAbi"; import { ctfAbi } from "./abi/ctfAbi"; -import { getContracts } from "@polymarket/order-utils"; dotenvConfig({ path: resolve(__dirname, "../.env") }); export function getWallet(mainnetQ: boolean): ethers.Wallet { const pk = process.env.PK as string; const rpcToken: string = process.env.RPC_TOKEN as string; - let rpcUrl: string = ""; + let rpcUrl = ""; if (mainnetQ) { rpcUrl = `https://polygon-mainnet.g.alchemy.com/v2/${rpcToken}`; } else { @@ -24,21 +24,15 @@ export function getWallet(mainnetQ: boolean): ethers.Wallet { } export function getUsdcContract(mainnetQ: boolean, wallet: ethers.Wallet): ethers.Contract { - if (mainnetQ) { - const mainnetContracts = getContracts(137); - return new ethers.Contract(mainnetContracts.Collateral, usdcAbi, wallet); - } - const mumbaiContracts = getContracts(80001); - return new ethers.Contract(mumbaiContracts.Collateral, usdcAbi, wallet); + const chainId = mainnetQ ? 137 : 80001; + const contractConfig = getContractConfig(chainId); + return new ethers.Contract(contractConfig.collateral, usdcAbi, wallet); } export function getCtfContract(mainnetQ: boolean, wallet: ethers.Wallet): ethers.Contract { - if (mainnetQ) { - const mainnetContracts = getContracts(137); - return new ethers.Contract(mainnetContracts.Conditional, ctfAbi, wallet); - } - const mumbaiContracts = getContracts(80001); - return new ethers.Contract(mumbaiContracts.Conditional, ctfAbi, wallet); + const chainId = mainnetQ ? 137 : 80001; + const contractConfig = getContractConfig(chainId); + return new ethers.Contract(contractConfig.conditionalTokens, ctfAbi, wallet); } async function main() { @@ -50,7 +44,7 @@ async function main() { const chainId = parseInt(`${process.env.CHAIN_ID || Chain.MUMBAI}`) as Chain; console.log(`Address: ${await wallet.getAddress()}, chainId: ${chainId}`); - const contracts = getContracts(isMainnet ? 137 : 80001); + const contractConfig = getContractConfig(chainId); const usdc = getUsdcContract(isMainnet, wallet); const ctf = getCtfContract(isMainnet, wallet); @@ -61,31 +55,31 @@ async function main() { console.log(`usdcAllowanceCtf: ${usdcAllowanceCtf}`); const usdcAllowanceExchange = (await usdc.allowance( wallet.address, - contracts.Exchange, + contractConfig.exchange, )) as BigNumber; const conditionalTokensAllowanceExchange = (await ctf.isApprovedForAll( wallet.address, - contracts.Exchange, + contractConfig.exchange, )) as BigNumber; let txn; if (!usdcAllowanceCtf.gt(constants.Zero)) { - txn = await usdc.approve(contracts.Conditional, constants.MaxUint256, { + txn = await usdc.approve(contractConfig.conditionalTokens, constants.MaxUint256, { gasPrice: 100_000_000_000, gasLimit: 200_000, }); console.log(`Setting USDC allowance for CTF: ${txn.hash}`); } if (!usdcAllowanceExchange.gt(constants.Zero)) { - txn = await usdc.approve(contracts.Exchange, constants.MaxUint256, { + txn = await usdc.approve(contractConfig.exchange, constants.MaxUint256, { gasPrice: 100_000_000_000, gasLimit: 200_000, }); console.log(`Setting USDC allowance for Exchange: ${txn.hash}`); } if (!conditionalTokensAllowanceExchange) { - txn = await ctf.setApprovalForAll(contracts.Exchange, true, { + txn = await ctf.setApprovalForAll(contractConfig.exchange, true, { gasPrice: 100_000_000_000, gasLimit: 200_000, }); diff --git a/examples/approveNegRiskAllowances.ts b/examples/approveNegRiskAllowances.ts new file mode 100644 index 0000000..12d5cb6 --- /dev/null +++ b/examples/approveNegRiskAllowances.ts @@ -0,0 +1,111 @@ +import { BigNumber, constants, ethers } from "ethers"; +import { config as dotenvConfig } from "dotenv"; +import { resolve } from "path"; +import { Chain } from "../src"; +import { getContractConfig } from "../src/config"; +import { usdcAbi } from "./abi/usdcAbi"; +import { ctfAbi } from "./abi/ctfAbi"; + +dotenvConfig({ path: resolve(__dirname, "../.env") }); + +/** + * NegRisk markets require separate allowances + * for the NegRiskCtfExchange and the NegRiskAdapter. + */ + +export function getWallet(mainnetQ: boolean): ethers.Wallet { + const pk = process.env.PK as string; + const rpcToken: string = process.env.RPC_TOKEN as string; + let rpcUrl = ""; + if (mainnetQ) { + rpcUrl = `https://polygon-mainnet.g.alchemy.com/v2/${rpcToken}`; + } else { + rpcUrl = `https://polygon-mumbai.g.alchemy.com/v2/${rpcToken}`; + } + const provider = new ethers.providers.JsonRpcProvider(rpcUrl); + let wallet = new ethers.Wallet(pk); + wallet = wallet.connect(provider); + return wallet; +} + +export function getUsdcContract(mainnetQ: boolean, wallet: ethers.Wallet): ethers.Contract { + const chainId = mainnetQ ? 137 : 80001; + const contractConfig = getContractConfig(chainId); + return new ethers.Contract(contractConfig.collateral, usdcAbi, wallet); +} + +export function getCtfContract(mainnetQ: boolean, wallet: ethers.Wallet): ethers.Contract { + const chainId = mainnetQ ? 137 : 80001; + const contractConfig = getContractConfig(chainId); + return new ethers.Contract(contractConfig.conditionalTokens, ctfAbi, wallet); +} + +async function main() { + // -------------------------- + // SET MAINNET OR MUMBAI HERE + const isMainnet = false; + // -------------------------- + const wallet = getWallet(isMainnet); + const chainId = parseInt(`${process.env.CHAIN_ID || Chain.MUMBAI}`) as Chain; + console.log(`Address: ${await wallet.getAddress()}, chainId: ${chainId}`); + + const contractConfig = getContractConfig(chainId); + const usdc = getUsdcContract(isMainnet, wallet); + const ctf = getCtfContract(isMainnet, wallet); + + console.log(`usdc: ${usdc.address}`); + console.log(`ctf: ${ctf.address}`); + + const usdcAllowanceNegRiskAdapter = (await usdc.allowance( + wallet.address, + contractConfig.negRiskAdapter, + )) as BigNumber; + console.log(`usdcAllowanceNegRiskAdapter: ${usdcAllowanceNegRiskAdapter}`); + const usdcAllowanceNegRiskExchange = (await usdc.allowance( + wallet.address, + contractConfig.negRiskExchange, + )) as BigNumber; + const conditionalTokensAllowanceNegRiskExchange = (await ctf.isApprovedForAll( + wallet.address, + contractConfig.negRiskExchange, + )) as BigNumber; + const conditionalTokensAllowanceNegRiskAdapter = (await ctf.isApprovedForAll( + wallet.address, + contractConfig.negRiskAdapter, + )) as BigNumber; + + let txn; + + // for splitting through the NegRiskAdapter + if (!usdcAllowanceNegRiskAdapter.gt(constants.Zero)) { + txn = await usdc.approve(contractConfig.negRiskAdapter, constants.MaxUint256, { + gasPrice: 100_000_000_000, + gasLimit: 200_000, + }); + console.log(`Setting USDC allowance for NegRiskAdapter: ${txn.hash}`); + } + if (!usdcAllowanceNegRiskExchange.gt(constants.Zero)) { + txn = await usdc.approve(contractConfig.negRiskExchange, constants.MaxUint256, { + gasPrice: 100_000_000_000, + gasLimit: 200_000, + }); + console.log(`Setting USDC allowance for NegRiskExchange: ${txn.hash}`); + } + if (!conditionalTokensAllowanceNegRiskExchange) { + txn = await ctf.setApprovalForAll(contractConfig.negRiskExchange, true, { + gasPrice: 100_000_000_000, + gasLimit: 200_000, + }); + console.log(`Setting Conditional Tokens allowance for NegRiskExchange: ${txn.hash}`); + } + if (!conditionalTokensAllowanceNegRiskAdapter) { + txn = await ctf.setApprovalForAll(contractConfig.negRiskAdapter, true, { + gasPrice: 100_000_000_000, + gasLimit: 200_000, + }); + console.log(`Setting Conditional Tokens allowance for NegRiskAdapter: ${txn.hash}`); + } + console.log("Allowances set"); +} + +main(); diff --git a/examples/geoToken.ts b/examples/geoToken.ts index fb6c199..59f067f 100644 --- a/examples/geoToken.ts +++ b/examples/geoToken.ts @@ -1,7 +1,7 @@ import { ethers } from "ethers"; import { config as dotenvConfig } from "dotenv"; import { resolve } from "path"; -import { ApiKeyCreds, Chain, ClobClient, PriceHistoryInterval, Side } from "../src"; +import { ApiKeyCreds, Chain, ClobClient, Side } from "../src"; dotenvConfig({ path: resolve(__dirname, "../.env") }); @@ -37,7 +37,7 @@ async function main() { side: Side.BUY, size: 100, }, - "0.01", + { tickSize: "0.01" }, ); console.log("Created Order", order); diff --git a/examples/getOpenOrders.ts b/examples/getOpenOrders.ts index 1c65a82..747d0fb 100644 --- a/examples/getOpenOrders.ts +++ b/examples/getOpenOrders.ts @@ -21,6 +21,7 @@ async function main() { console.log( await clobClient.getOpenOrders({ asset_id: + // eslint-disable-next-line max-len "16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO owner: creds.key, }), @@ -28,6 +29,7 @@ async function main() { console.log( await clobClient.getOpenOrders({ asset_id: + // eslint-disable-next-line max-len "1343197538147866997676250008839231694243646439454152539053893078719042421992", // YES owner: creds.key, }), diff --git a/examples/getTrades.ts b/examples/getTrades.ts index 2a58077..658565e 100644 --- a/examples/getTrades.ts +++ b/examples/getTrades.ts @@ -21,6 +21,7 @@ async function main() { console.log( await clobClient.getTrades({ asset_id: + // eslint-disable-next-line max-len "16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO maker: await wallet.getAddress(), limit: 10, @@ -29,6 +30,7 @@ async function main() { console.log( await clobClient.getTrades({ asset_id: + // eslint-disable-next-line max-len "1343197538147866997676250008839231694243646439454152539053893078719042421992", // YES maker: await wallet.getAddress(), limit: 10, diff --git a/examples/order.ts b/examples/order.ts index 1e71b71..4be41ef 100644 --- a/examples/order.ts +++ b/examples/order.ts @@ -30,7 +30,7 @@ async function main() { nonce: 0, expiration: 0, }, - "0.01", + { tickSize: "0.01" }, ); console.log("Created Order", order); diff --git a/examples/signatureTypes.ts b/examples/signatureTypes.ts index ce0cd6e..488de09 100644 --- a/examples/signatureTypes.ts +++ b/examples/signatureTypes.ts @@ -1,7 +1,7 @@ import { ethers } from "ethers"; import { config as dotenvConfig } from "dotenv"; import { resolve } from "path"; -import { ApiKeyCreds, Chain, ClobClient, Side } from "../src"; +import { ApiKeyCreds, Chain, ClobClient } from "../src"; import { SignatureType } from "@polymarket/order-utils"; dotenvConfig({ path: resolve(__dirname, "../.env") }); @@ -22,12 +22,26 @@ async function main() { const clobClient = new ClobClient(host, chainId, wallet, creds); // Client used with a Polymarket Proxy Wallet: Signature type 1 - const proxyWalletAddress = "0x..."; - const polyProxyClient = new ClobClient(host, chainId, wallet, creds, SignatureType.POLY_PROXY, proxyWalletAddress); + const proxyWalletAddress = "0x..."; + const polyProxyClient = new ClobClient( + host, + chainId, + wallet, + creds, + SignatureType.POLY_PROXY, + proxyWalletAddress, + ); // Client used with a Polymarket Gnosis safe: Signature Type 2 const gnosisSafeAddress = "0x..."; - const polyGnosisSafeClient = new ClobClient(host, chainId, wallet, creds, SignatureType.POLY_GNOSIS_SAFE, gnosisSafeAddress) + const polyGnosisSafeClient = new ClobClient( + host, + chainId, + wallet, + creds, + SignatureType.POLY_GNOSIS_SAFE, + gnosisSafeAddress, + ); } main(); diff --git a/examples/socketConnection.ts b/examples/socketConnection.ts index a67fe07..ae4af4f 100644 --- a/examples/socketConnection.ts +++ b/examples/socketConnection.ts @@ -5,6 +5,7 @@ import { WebSocket } from "ws"; import { ApiKeyCreds } from "../src"; const YES_TOKEN_ID = "1343197538147866997676250008839231694243646439454152539053893078719042421992"; +// eslint-disable-next-line max-len // const NO_TOKEN_ID = "16678291189211314787145083999015737376658799626183230671758641503291735614088"; const CONDITION_ID = "0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af"; @@ -22,7 +23,7 @@ interface subscriptionMessage { async function main(type: "user" | "market" | "live-activity") { const host = process.env.WS_URL || "ws://localhost:8081"; console.log(`${host}/ws/${type}`); - let ws = new WebSocket(`${host}/ws/${type}`); // change to market for market, user for user + const ws = new WebSocket(`${host}/ws/${type}`); // change to market for market, user for user let subscriptionMessage: subscriptionMessage = {} as subscriptionMessage; diff --git a/examples/testPolyProxyMarketBuy.ts b/examples/testPolyProxyMarketBuy.ts index 23778a9..f84794c 100644 --- a/examples/testPolyProxyMarketBuy.ts +++ b/examples/testPolyProxyMarketBuy.ts @@ -17,6 +17,7 @@ async function populateBook(client: ClobClient) { await client.postOrder( await client.createOrder({ tokenID: + // eslint-disable-next-line max-len "16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO side: newOrder.side, price: newOrder.price, diff --git a/examples/testPolyProxyMarketSell.ts b/examples/testPolyProxyMarketSell.ts index 14f1a82..a37e2f8 100644 --- a/examples/testPolyProxyMarketSell.ts +++ b/examples/testPolyProxyMarketSell.ts @@ -17,6 +17,7 @@ async function populateBook(client: ClobClient) { await client.postOrder( await client.createOrder({ tokenID: + // eslint-disable-next-line max-len "16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO side: newOrder.side, price: newOrder.price, diff --git a/package.json b/package.json index 5deb9c1..89c0d3a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@polymarket/clob-client", "description": "Typescript client for Polymarket's CLOB", - "version": "3.2.0", + "version": "4.0.0", "contributors": [ { "name": "Jonathan Amenechi", @@ -18,6 +18,10 @@ { "name": "Liam Kovatch", "url": "https://github.com/l-kov" + }, + { + "name": "Mike Shrieve", + "url": "https://github.com/mshrieve" } ], "main": "dist/index.js", @@ -37,7 +41,7 @@ "test": "make test" }, "dependencies": { - "@polymarket/order-utils": "^1.3.1", + "@polymarket/order-utils": "^2.0.0", "axios": "^0.27.2", "browser-or-node": "^2.1.1", "ethers": "^5.7.1" diff --git a/src/client.ts b/src/client.ts index 873dd1f..47b5451 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5,6 +5,7 @@ import { ApiKeyCreds, ApiKeysResponse, Chain, + CreateOrderOptions, MarketPrice, OpenOrderParams, OpenOrdersResponse, @@ -416,30 +417,43 @@ export class ClobClient { return this.get(`${this.host}${endpoint}`, { headers, params }); } - public async createOrder(userOrder: UserOrder, tickSize?: TickSize): Promise { + public async createOrder( + userOrder: UserOrder, + options?: Partial, + ): Promise { this.canL1Auth(); const { tokenID } = userOrder; - tickSize = await this._resolveTickSize(tokenID, tickSize); - return this.orderBuilder.buildOrder(userOrder, tickSize); + const tickSize = await this._resolveTickSize(tokenID, options?.tickSize); + const negRisk = options?.negRisk ?? false; + + return this.orderBuilder.buildOrder(userOrder, { + tickSize, + negRisk, + }); } public async createMarketBuyOrder( userMarketOrder: UserMarketOrder, - tickSize?: TickSize, + options?: CreateOrderOptions, ): Promise { this.canL1Auth(); const { tokenID } = userMarketOrder; - tickSize = await this._resolveTickSize(tokenID, tickSize); + + const tickSize = await this._resolveTickSize(tokenID, options?.tickSize); + const negRisk = options?.negRisk ?? false; if (!userMarketOrder.price) { const marketPrice = await this.getPrice(tokenID, Side.BUY); userMarketOrder.price = parseFloat(marketPrice); } - return this.orderBuilder.buildMarketOrder(userMarketOrder, tickSize); + return this.orderBuilder.buildMarketOrder(userMarketOrder, { + tickSize, + negRisk, + }); } public async getOpenOrders(params?: OpenOrderParams): Promise { diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..0410a76 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,40 @@ +type ContractConfig = { + exchange: string; + negRiskAdapter: string; + negRiskExchange: string; + collateral: string; + conditionalTokens: string; +}; + +const MUMBAI_CONTRACTS: ContractConfig = { + exchange: "0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E", + negRiskAdapter: "0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296", + negRiskExchange: "0xC5d563A36AE78145C45a50134d48A1215220f80a", + collateral: "0x2E8DCfE708D44ae2e406a1c02DFE2Fa13012f961", + conditionalTokens: "0x7D8610E9567d2a6C9FBf66a5A13E9Ba8bb120d43", +}; + +const MATIC_CONTRACTS: ContractConfig = { + exchange: "0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E", + negRiskAdapter: "0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296", + negRiskExchange: "0xC5d563A36AE78145C45a50134d48A1215220f80a", + collateral: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", + conditionalTokens: "0x4D97DCd97eC945f40cF65F87097ACe5EA0476045", +}; + +const COLLATERAL_TOKEN_DECIMALS = 6; +const CONDITIONAL_TOKEN_DECIMALS = 6; + +const getContractConfig = (chainID: number): ContractConfig => { + switch (chainID) { + case 137: + return MATIC_CONTRACTS; + case 80001: + return MUMBAI_CONTRACTS; + default: + throw new Error("Invalid network"); + } +}; + +export type { ContractConfig }; +export { getContractConfig, COLLATERAL_TOKEN_DECIMALS, CONDITIONAL_TOKEN_DECIMALS }; diff --git a/src/order-builder/builder.ts b/src/order-builder/builder.ts index 54b1c48..7cf63ff 100644 --- a/src/order-builder/builder.ts +++ b/src/order-builder/builder.ts @@ -2,7 +2,7 @@ import { Wallet } from "@ethersproject/wallet"; import { JsonRpcSigner } from "@ethersproject/providers"; import { SignedOrder, SignatureType } from "@polymarket/order-utils"; import { createMarketBuyOrder, createOrder } from "./helpers"; -import { Chain, TickSize, UserMarketOrder, UserOrder } from "../types"; +import { Chain, CreateOrderOptions, UserMarketOrder, UserOrder } from "../types"; export class OrderBuilder { readonly signer: Wallet | JsonRpcSigner; @@ -32,14 +32,17 @@ export class OrderBuilder { /** * Generate and sign a order */ - public async buildOrder(userOrder: UserOrder, tickSize: TickSize): Promise { + public async buildOrder( + userOrder: UserOrder, + options: CreateOrderOptions, + ): Promise { return createOrder( this.signer, this.chainId, this.signatureType, this.funderAddress, userOrder, - tickSize, + options, ); } @@ -48,7 +51,7 @@ export class OrderBuilder { */ public async buildMarketOrder( userMarketOrder: UserMarketOrder, - tickSize: TickSize, + options: CreateOrderOptions, ): Promise { return createMarketBuyOrder( this.signer, @@ -56,7 +59,7 @@ export class OrderBuilder { this.signatureType, this.funderAddress, userMarketOrder, - tickSize, + options, ); } } diff --git a/src/order-builder/helpers.ts b/src/order-builder/helpers.ts index 10a4f92..7d01698 100644 --- a/src/order-builder/helpers.ts +++ b/src/order-builder/helpers.ts @@ -3,16 +3,26 @@ import { Wallet } from "@ethersproject/wallet"; import { parseUnits } from "@ethersproject/units"; import { ExchangeOrderBuilder, - getContracts, OrderData, SignatureType, SignedOrder, Side as UtilsSide, - COLLATERAL_TOKEN_DECIMALS, - CONDITIONAL_TOKEN_DECIMALS, } from "@polymarket/order-utils"; -import { UserOrder, Side, Chain, UserMarketOrder, TickSize, RoundConfig } from "../types"; +import { + UserOrder, + Side, + Chain, + UserMarketOrder, + TickSize, + RoundConfig, + CreateOrderOptions, +} from "../types"; import { decimalPlaces, roundDown, roundNormal, roundUp } from "../utilities"; +import { + COLLATERAL_TOKEN_DECIMALS, + CONDITIONAL_TOKEN_DECIMALS, + getContractConfig, +} from "../config"; export const ROUNDING_CONFIG: Record = { "0.1": { @@ -41,18 +51,18 @@ export const ROUNDING_CONFIG: Record = { * Generate and sign a order * * @param signer - * @param contractAddress ctf exchange contract address + * @param exchangeAddress ctf exchange contract address * @param chainId * @param OrderData * @returns SignedOrder */ export const buildOrder = async ( signer: Wallet | JsonRpcSigner, - contractAddress: string, + exchangeAddress: string, chainId: number, orderData: OrderData, ): Promise => { - const cTFExchangeOrderBuilder = new ExchangeOrderBuilder(contractAddress, chainId, signer); + const cTFExchangeOrderBuilder = new ExchangeOrderBuilder(exchangeAddress, chainId, signer); return cTFExchangeOrderBuilder.buildSignedOrder(orderData); }; @@ -162,22 +172,27 @@ export const createOrder = async ( signatureType: SignatureType, funderAddress: string | undefined, userOrder: UserOrder, - tickSize: TickSize, + options: CreateOrderOptions, ): Promise => { const eoaSignerAddress = await eoaSigner.getAddress(); // If funder address is not given, use the signer address const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress; - const clobContracts = getContracts(chainId); + const contractConfig = getContractConfig(chainId); const orderData = await buildOrderCreationArgs( eoaSignerAddress, maker, signatureType, userOrder, - ROUNDING_CONFIG[tickSize], + ROUNDING_CONFIG[options.tickSize], ); - return buildOrder(eoaSigner, clobContracts.Exchange, chainId, orderData); + + const exchangeContract = options.negRisk + ? contractConfig.negRiskExchange + : contractConfig.exchange; + + return buildOrder(eoaSigner, exchangeContract, chainId, orderData); }; export const getMarketBuyOrderRawAmounts = ( @@ -264,20 +279,25 @@ export const createMarketBuyOrder = async ( signatureType: SignatureType, funderAddress: string | undefined, userMarketOrder: UserMarketOrder, - tickSize: TickSize, + options: CreateOrderOptions, ): Promise => { const eoaSignerAddress = await eoaSigner.getAddress(); // If funder address is not given, use the signer address const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress; - const clobContracts = getContracts(chainId); + const contractConfig = getContractConfig(chainId); const orderData = await buildMarketBuyOrderCreationArgs( eoaSignerAddress, maker, signatureType, userMarketOrder, - ROUNDING_CONFIG[tickSize], + ROUNDING_CONFIG[options.tickSize], ); - return buildOrder(eoaSigner, clobContracts.Exchange, chainId, orderData); + + const exchangeContract = options.negRisk + ? contractConfig.negRiskExchange + : contractConfig.exchange; + + return buildOrder(eoaSigner, exchangeContract, chainId, orderData); }; diff --git a/src/types.ts b/src/types.ts index 17bc75b..8949749 100644 --- a/src/types.ts +++ b/src/types.ts @@ -334,6 +334,11 @@ export interface OrdersScoringParams { export type OrdersScoring = { [orderId in string]: boolean }; +export type CreateOrderOptions = { + tickSize: TickSize; + negRisk?: boolean; +}; + export type TickSize = "0.1" | "0.01" | "0.001" | "0.0001"; export interface RoundConfig { diff --git a/tests/headers/index.test.ts b/tests/headers/index.test.ts index 9474c17..aa2b5b6 100644 --- a/tests/headers/index.test.ts +++ b/tests/headers/index.test.ts @@ -5,7 +5,7 @@ import { Wallet } from "ethers"; import { ApiKeyCreds, Chain } from "../../src/types"; describe("headers", () => { - let chainId = Chain.MUMBAI; + const chainId = Chain.MUMBAI; let wallet: Wallet; let creds: ApiKeyCreds; beforeEach(() => { diff --git a/tests/order-builder/helpers.test.ts b/tests/order-builder/helpers.test.ts index 563b65d..6062229 100644 --- a/tests/order-builder/helpers.test.ts +++ b/tests/order-builder/helpers.test.ts @@ -11,25 +11,20 @@ import { getMarketBuyOrderRawAmounts, ROUNDING_CONFIG, } from "../../src/order-builder/helpers"; -import { - OrderData, - SignatureType, - Side as UtilsSide, - Contracts, - getContracts, -} from "@polymarket/order-utils"; +import { OrderData, SignatureType, Side as UtilsSide } from "@polymarket/order-utils"; import { Wallet } from "@ethersproject/wallet"; import { decimalPlaces, roundDown, roundNormal } from "../../src/utilities"; +import { ContractConfig, getContractConfig } from "../../src/config"; describe("helpers", () => { const chainId = Chain.MUMBAI; let wallet: Wallet; - let contracts: Contracts; + let contractConfig: ContractConfig; beforeEach(() => { // publicly known private key const privateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; wallet = new Wallet(privateKey); - contracts = getContracts(chainId); + contractConfig = getContractConfig(chainId); }); describe("buildOrder", () => { @@ -57,7 +52,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -102,7 +97,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -147,7 +142,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -192,7 +187,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -237,7 +232,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -283,7 +278,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -327,7 +322,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -371,7 +366,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -415,7 +410,7 @@ describe("helpers", () => { const signedOrder = await buildOrder( wallet, - contracts.Exchange, + contractConfig.exchange, chainId, orderData, ); @@ -1778,291 +1773,583 @@ describe("helpers", () => { }); describe("createOrder", () => { - describe("buy order", async () => { - it("0.1", async () => { - const order: UserOrder = { - tokenID: "123", - price: 0.5, - size: 21.04, - side: Side.BUY, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + describe("CTF Exchange", () => { + describe("buy order", async () => { + it("0.1", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.5, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("10520000"); - expect(signedOrder.takerAmount).equal("21040000"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; - }); + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("10520000"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); - it("0.01", async () => { - const order: UserOrder = { - tokenID: "123", - price: 0.56, - size: 21.04, - side: Side.BUY, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + it("0.01", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.56, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("11782400"); - expect(signedOrder.takerAmount).equal("21040000"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; - }); + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("11782400"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); - it("0.001", async () => { - const order: UserOrder = { - tokenID: "123", - price: 0.056, - size: 21.04, - side: Side.BUY, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + it("0.001", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.056, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("1178240"); - expect(signedOrder.takerAmount).equal("21040000"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; - }); + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("1178240"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); - it("0.0001", async () => { - const order: UserOrder = { - tokenID: "123", - price: 0.0056, - size: 21.04, - side: Side.BUY, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + it("0.0001", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.0056, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("117824"); - expect(signedOrder.takerAmount).equal("21040000"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("117824"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); }); - }); - - describe("sell order", async () => { - it("0.1", async () => { - const order: UserOrder = { - tokenID: "5", - price: 0.5, - size: 21.04, - side: Side.SELL, - feeRateBps: 0, - nonce: 0, - }; - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.POLY_GNOSIS_SAFE, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.1", - ); + describe("sell order", async () => { + it("0.1", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.5, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("5"); - expect(signedOrder.makerAmount).equal("21040000"); - expect(signedOrder.takerAmount).equal("10520000"); - expect(signedOrder.side).equal(UtilsSide.SELL); - expect(signedOrder.expiration).equal("0"); - expect(signedOrder.nonce).equal("0"); - expect(signedOrder.feeRateBps).equal("0"); - expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); - expect(signedOrder.signature).not.empty; - }); + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.1", negRisk: false }, + ); - it("0.01", async () => { - const order: UserOrder = { - tokenID: "5", - price: 0.56, - size: 21.04, - side: Side.SELL, - feeRateBps: 0, - nonce: 0, - }; + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("10520000"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.POLY_GNOSIS_SAFE, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.01", - ); + it("0.01", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.56, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("5"); - expect(signedOrder.makerAmount).equal("21040000"); - expect(signedOrder.takerAmount).equal("11782400"); - expect(signedOrder.side).equal(UtilsSide.SELL); - expect(signedOrder.expiration).equal("0"); - expect(signedOrder.nonce).equal("0"); - expect(signedOrder.feeRateBps).equal("0"); - expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); - expect(signedOrder.signature).not.empty; - }); + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.01", negRisk: false }, + ); - it("0.001", async () => { - const order: UserOrder = { - tokenID: "5", - price: 0.056, - size: 21.04, - side: Side.SELL, - feeRateBps: 0, - nonce: 0, - }; + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("11782400"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.POLY_GNOSIS_SAFE, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.001", - ); + it("0.001", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.056, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("5"); - expect(signedOrder.makerAmount).equal("21040000"); - expect(signedOrder.takerAmount).equal("1178240"); - expect(signedOrder.side).equal(UtilsSide.SELL); - expect(signedOrder.expiration).equal("0"); - expect(signedOrder.nonce).equal("0"); - expect(signedOrder.feeRateBps).equal("0"); - expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); - expect(signedOrder.signature).not.empty; + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.001", negRisk: false }, + ); + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("1178240"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); + + it("0.0001", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.0056, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.0001", negRisk: false }, + ); + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("117824"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); }); + }); - it("0.0001", async () => { - const order: UserOrder = { - tokenID: "5", - price: 0.0056, - size: 21.04, - side: Side.SELL, - feeRateBps: 0, - nonce: 0, - }; + describe("Neg RiskCTF Exchange", () => { + describe("buy order", async () => { + it("0.1", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.5, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createOrder( - wallet, - Chain.MUMBAI, - SignatureType.POLY_GNOSIS_SAFE, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.0001", - ); + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("5"); - expect(signedOrder.makerAmount).equal("21040000"); - expect(signedOrder.takerAmount).equal("117824"); - expect(signedOrder.side).equal(UtilsSide.SELL); - expect(signedOrder.expiration).equal("0"); - expect(signedOrder.nonce).equal("0"); - expect(signedOrder.feeRateBps).equal("0"); - expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); - expect(signedOrder.signature).not.empty; + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("10520000"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + + it("0.01", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.56, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("11782400"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + + it("0.001", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.056, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("1178240"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + + it("0.0001", async () => { + const order: UserOrder = { + tokenID: "123", + price: 0.0056, + size: 21.04, + side: Side.BUY, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("117824"); + expect(signedOrder.takerAmount).equal("21040000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + }); + + describe("sell order", async () => { + it("0.1", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.5, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.1", negRisk: true }, + ); + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("10520000"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); + + it("0.01", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.56, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.01", negRisk: true }, + ); + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("11782400"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); + + it("0.001", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.056, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.001", negRisk: true }, + ); + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("1178240"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); + + it("0.0001", async () => { + const order: UserOrder = { + tokenID: "5", + price: 0.0056, + size: 21.04, + side: Side.SELL, + feeRateBps: 0, + nonce: 0, + }; + + const signedOrder = await createOrder( + wallet, + Chain.MUMBAI, + SignatureType.POLY_GNOSIS_SAFE, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.0001", negRisk: true }, + ); + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("5"); + expect(signedOrder.makerAmount).equal("21040000"); + expect(signedOrder.takerAmount).equal("117824"); + expect(signedOrder.side).equal(UtilsSide.SELL); + expect(signedOrder.expiration).equal("0"); + expect(signedOrder.nonce).equal("0"); + expect(signedOrder.feeRateBps).equal("0"); + expect(signedOrder.signatureType).equal(SignatureType.POLY_GNOSIS_SAFE); + expect(signedOrder.signature).not.empty; + }); }); }); }); @@ -3054,149 +3341,299 @@ describe("helpers", () => { }); describe("createMarketBuyOrder", () => { - describe("buy order", async () => { - it("0.1", async () => { - const order: UserMarketOrder = { - tokenID: "123", - price: 0.5, - amount: 100, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + describe("CTF Exchange", () => { + describe("buy order", async () => { + it("0.1", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.5, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createMarketBuyOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("100000000"); - expect(signedOrder.takerAmount).equal("200000000"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; - }); + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("200000000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); - it("0.01", async () => { - const order: UserMarketOrder = { - tokenID: "123", - price: 0.56, - amount: 100, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + it("0.01", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.56, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createMarketBuyOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("100000000"); - expect(signedOrder.takerAmount).equal("178571400"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; - }); + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("178571400"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); - it("0.001", async () => { - const order: UserMarketOrder = { - tokenID: "123", - price: 0.056, - amount: 100, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + it("0.001", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.056, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createMarketBuyOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("100000000"); - expect(signedOrder.takerAmount).equal("1785714280"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("1785714280"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + + it("0.0001", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.0056, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; + + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("17857142857"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); }); + }); - it("0.0001", async () => { - const order: UserMarketOrder = { - tokenID: "123", - price: 0.0056, - amount: 100, - feeRateBps: 111, - nonce: 123, - expiration: 50000, - }; + describe("CTF Exchange", () => { + describe("buy order", async () => { + it("0.1", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.5, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; - const signedOrder = await createMarketBuyOrder( - wallet, - Chain.MUMBAI, - SignatureType.EOA, - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - order, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; - expect(signedOrder.salt).not.empty; - expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); - expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); - expect(signedOrder.tokenId).equal("123"); - expect(signedOrder.makerAmount).equal("100000000"); - expect(signedOrder.takerAmount).equal("17857142857"); - expect(signedOrder.side).equal(UtilsSide.BUY); - expect(signedOrder.expiration).equal("50000"); - expect(signedOrder.nonce).equal("123"); - expect(signedOrder.feeRateBps).equal("111"); - expect(signedOrder.signatureType).equal(SignatureType.EOA); - expect(signedOrder.signature).not.empty; + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("200000000"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + + it("0.01", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.56, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; + + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("178571400"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + + it("0.001", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.056, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; + + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("1785714280"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); + + it("0.0001", async () => { + const order: UserMarketOrder = { + tokenID: "123", + price: 0.0056, + amount: 100, + feeRateBps: 111, + nonce: 123, + expiration: 50000, + }; + + const signedOrder = await createMarketBuyOrder( + wallet, + Chain.MUMBAI, + SignatureType.EOA, + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + order, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + expect(signedOrder.salt).not.empty; + expect(signedOrder.maker).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.signer).equal("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); + expect(signedOrder.taker).equal("0x0000000000000000000000000000000000000000"); + expect(signedOrder.tokenId).equal("123"); + expect(signedOrder.makerAmount).equal("100000000"); + expect(signedOrder.takerAmount).equal("17857142857"); + expect(signedOrder.side).equal(UtilsSide.BUY); + expect(signedOrder.expiration).equal("50000"); + expect(signedOrder.nonce).equal("123"); + expect(signedOrder.feeRateBps).equal("111"); + expect(signedOrder.signatureType).equal(SignatureType.EOA); + expect(signedOrder.signature).not.empty; + }); }); }); }); diff --git a/tests/signing/eip712.test.ts b/tests/signing/eip712.test.ts index 1524b7f..92f9aac 100644 --- a/tests/signing/eip712.test.ts +++ b/tests/signing/eip712.test.ts @@ -18,6 +18,7 @@ describe("eip712", () => { expect(signature).not.undefined; expect(signature).not.empty; expect(signature).equal( + // eslint-disable-next-line max-len "0xd91760ebcb14e814e9e12600b9bc7cd6bf13ebc175f6a28538b4925763f94f90012da34dd71290d441c28bc4f9b2281d3eb9ecfd1c9a63db1ce9ca85c89c914c1b", ); }); diff --git a/tests/utilities.test.ts b/tests/utilities.test.ts index 230fe58..63accc3 100644 --- a/tests/utilities.test.ts +++ b/tests/utilities.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import "mocha"; import { expect } from "chai"; import { @@ -235,2642 +236,5286 @@ describe("utilities", () => { }); describe("All orders combinations", async () => { - describe("0.1", async () => { - // publicly known private key - const token = - "1343197538147866997676250008839231694243646439454152539053893078719042421992"; - const privateKey = - "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; - const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; - const wallet = new Wallet(privateKey); - const chainId = Chain.MUMBAI; - const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; - - it("GTD BUY EOA", async () => { - const userOrder: UserOrder = { - tokenID: token, - price: 0.5, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + describe("CTF Exchange", async () => { + describe("0.1", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTC BUY EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.5, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("FOK BUY EOA", async () => { - const userMarketOrder: UserMarketOrder = { - tokenID: token, - price: 0.5, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userMarketOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "200000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.5, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); - }); - it("FOK BUY POLY_PROXY", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.5, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userMarketOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "200000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.5, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); - }); - it("FOK BUY POLY_GNOSIS_SAFE", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.5, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userMarketOrder, - "0.1", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "200000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.5, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.1", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); - }); - describe("0.01", async () => { - // publicly known private key - const token = - "1343197538147866997676250008839231694243646439454152539053893078719042421992"; - const privateKey = - "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; - const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; - const wallet = new Wallet(privateKey); - const chainId = Chain.MUMBAI; - const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; - - it("GTD BUY EOA", async () => { - const userOrder: UserOrder = { - tokenID: token, - price: 0.05, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "5000000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + describe("0.01", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "5000000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "5000000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "5000000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "5000000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "5000000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTC BUY EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "5000000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "5000000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "5000000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "5000000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "5000000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.05, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "5000000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("FOK BUY EOA", async () => { - const userMarketOrder: UserMarketOrder = { - tokenID: token, - price: 0.05, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userMarketOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "2000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.05, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "2000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); - }); - it("FOK BUY POLY_PROXY", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.05, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userMarketOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "2000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.05, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "2000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); - }); - it("FOK BUY POLY_GNOSIS_SAFE", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.05, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userMarketOrder, - "0.01", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "2000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.05, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.01", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "2000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); - }); - describe("0.001", async () => { - // publicly known private key - const token = - "1343197538147866997676250008839231694243646439454152539053893078719042421992"; - const privateKey = - "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; - const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; - const wallet = new Wallet(privateKey); - const chainId = Chain.MUMBAI; - const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; - - it("GTD BUY EOA", async () => { - const userOrder: UserOrder = { - tokenID: token, - price: 0.005, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "500000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + describe("0.001", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "500000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "500000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "500000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "500000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "500000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTC BUY EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "500000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "500000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "500000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "500000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "500000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.005, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "500000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("FOK BUY EOA", async () => { - const userMarketOrder: UserMarketOrder = { - tokenID: token, - price: 0.005, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userMarketOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "20000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "20000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); - }); - it("FOK BUY POLY_PROXY", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.005, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userMarketOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "20000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "20000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "20000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); - it("FOK BUY POLY_GNOSIS_SAFE", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.005, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userMarketOrder, - "0.001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "20000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + describe("0.0001", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.0005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.0005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.0005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.0001", negRisk: false }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); }); - describe("0.0001", async () => { - // publicly known private key - const token = - "1343197538147866997676250008839231694243646439454152539053893078719042421992"; - const privateKey = - "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; - const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; - const wallet = new Wallet(privateKey); - const chainId = Chain.MUMBAI; - const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; - - it("GTD BUY EOA", async () => { - const userOrder: UserOrder = { - tokenID: token, - price: 0.0005, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + describe("Neg Risk CTF Exchange", async () => { + describe("0.1", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.BUY, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000", - takerAmount: "100000000", - side: "BUY", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTD SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.SELL, - size: 100, - expiration: 1709948026, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); - expect(jsonGTDOrder).not.null; - expect(jsonGTDOrder).not.undefined; - - expect(jsonGTDOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000", - side: "SELL", - expiration: "1709948026", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTD, + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); }); - }); - it("GTC BUY EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC BUY POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.BUY, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "50000", - takerAmount: "100000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL EOA", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); }); - }); - it("GTC SELL POLY_PROXY", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.5, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.5, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.5, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); - }); - it("GTC SELL POLY_GNOSIS_SAFE", async () => { - const userOrder = { - tokenID: token, - price: 0.0005, - side: Side.SELL, - size: 100, - }; - const signedOrder = await createOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); - expect(jsonGTCOrder).not.null; - expect(jsonGTCOrder).not.undefined; - - expect(jsonGTCOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "50000", - side: "SELL", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.GTC, + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.5, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.1", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); - it("FOK BUY EOA", async () => { - const userMarketOrder: UserMarketOrder = { - tokenID: token, - price: 0.0005, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.EOA, - address, - userMarketOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "200000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 0, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + describe("0.01", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "5000000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.05, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "5000000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.05, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "2000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.05, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "2000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.05, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.01", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "2000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); - it("FOK BUY POLY_PROXY", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.0005, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_PROXY, - address, - userMarketOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "200000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 1, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + describe("0.001", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "500000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "500000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "20000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "20000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "20000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); - it("FOK BUY POLY_GNOSIS_SAFE", async () => { - const userMarketOrder = { - tokenID: token, - price: 0.0005, - amount: 100, - }; - const signedOrder = await createMarketBuyOrder( - wallet, - chainId, - SignatureType.POLY_GNOSIS_SAFE, - address, - userMarketOrder, - "0.0001", - ); - expect(signedOrder).not.null; - expect(signedOrder).not.undefined; - - const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); - expect(jsonFOKOrder).not.null; - expect(jsonFOKOrder).not.undefined; - - expect(jsonFOKOrder).deep.equal({ - order: { - salt: parseInt(signedOrder.salt), - maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - taker: "0x0000000000000000000000000000000000000000", - tokenId: token, - makerAmount: "100000000", - takerAmount: "200000000000", - side: "BUY", - expiration: "0", - nonce: "0", - feeRateBps: "0", - signatureType: 2, - signature: signedOrder.signature, - }, - owner: owner, - orderType: OrderType.FOK, + describe("0.0001", async () => { + // publicly known private key + const token = + "1343197538147866997676250008839231694243646439454152539053893078719042421992"; + const privateKey = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const wallet = new Wallet(privateKey); + const chainId = Chain.MUMBAI; + const owner = "f4f247b7-4ac7-ff29-a152-04fda0a8755a"; + + it("GTD BUY EOA", async () => { + const userOrder: UserOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTD SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + expiration: 1709948026, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTDOrder = orderToJson(signedOrder, owner, OrderType.GTD); + expect(jsonGTDOrder).not.null; + expect(jsonGTDOrder).not.undefined; + + expect(jsonGTDOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "1709948026", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTD, + }); + }); + + it("GTC BUY EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC BUY POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.BUY, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "50000", + takerAmount: "100000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL EOA", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_PROXY", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("GTC SELL POLY_GNOSIS_SAFE", async () => { + const userOrder = { + tokenID: token, + price: 0.0005, + side: Side.SELL, + size: 100, + }; + const signedOrder = await createOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonGTCOrder = orderToJson(signedOrder, owner, OrderType.GTC); + expect(jsonGTCOrder).not.null; + expect(jsonGTCOrder).not.undefined; + + expect(jsonGTCOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "50000", + side: "SELL", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.GTC, + }); + }); + + it("FOK BUY EOA", async () => { + const userMarketOrder: UserMarketOrder = { + tokenID: token, + price: 0.0005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.EOA, + address, + userMarketOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 0, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_PROXY", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.0005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_PROXY, + address, + userMarketOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 1, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); + }); + + it("FOK BUY POLY_GNOSIS_SAFE", async () => { + const userMarketOrder = { + tokenID: token, + price: 0.0005, + amount: 100, + }; + const signedOrder = await createMarketBuyOrder( + wallet, + chainId, + SignatureType.POLY_GNOSIS_SAFE, + address, + userMarketOrder, + { tickSize: "0.0001", negRisk: true }, + ); + expect(signedOrder).not.null; + expect(signedOrder).not.undefined; + + const jsonFOKOrder = orderToJson(signedOrder, owner, OrderType.FOK); + expect(jsonFOKOrder).not.null; + expect(jsonFOKOrder).not.undefined; + + expect(jsonFOKOrder).deep.equal({ + order: { + salt: parseInt(signedOrder.salt), + maker: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + taker: "0x0000000000000000000000000000000000000000", + tokenId: token, + makerAmount: "100000000", + takerAmount: "200000000000", + side: "BUY", + expiration: "0", + nonce: "0", + feeRateBps: "0", + signatureType: 2, + signature: signedOrder.signature, + }, + owner: owner, + orderType: OrderType.FOK, + }); }); }); }); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..e9eea6e --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "./node_modules", "./node_modules/*"], + "include": ["src/**/*", "tests/**/*.ts", "examples/**/*.ts"] +} diff --git a/yarn.lock b/yarn.lock index b55f721..a34d086 100644 --- a/yarn.lock +++ b/yarn.lock @@ -697,10 +697,10 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@polymarket/order-utils@^1.3.1": - version "1.3.1" - resolved "https://registry.npmjs.org/@polymarket/order-utils/-/order-utils-1.3.1.tgz#786ac15b50dbff8289675615bce4dad9dfcfe6a6" - integrity sha512-+ml9tjIYvpEoWO98MAZwlq0V3fHDAW8oXOEJL0oj58CidFDTzgLGflhhzhDOs4DTEbjaUGD8mbFcuIN4OEzBBQ== +"@polymarket/order-utils@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@polymarket/order-utils/-/order-utils-2.0.0.tgz#26e2e8311248c19556f5e14d65a8f69f5bc1a98c" + integrity sha512-Ttb/m9bi1kR4ZUkdmtRxM7P7F+gfkseOiM2adAX/wXsebjn1owzZITg34pmRTwDsv89tgLEIkM6aSIDySsa/Gg== dependencies: "@metamask/eth-sig-util" "^5.0.0" ethers "^5.7.1"