@polymarket/clob-client-v2 1.1.0 → 1.2.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/client.cjs +17 -14
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +17 -14
- package/dist/client.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.cjs +3 -2
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.cjs.map +1 -1
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.js +3 -2
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.js.map +1 -1
- package/dist/order-builder/helpers/buildOrderCreationArgs.cjs +3 -2
- package/dist/order-builder/helpers/buildOrderCreationArgs.cjs.map +1 -1
- package/dist/order-builder/helpers/buildOrderCreationArgs.js +3 -2
- package/dist/order-builder/helpers/buildOrderCreationArgs.js.map +1 -1
- package/dist/order-builder/helpers/createMarketOrder.cjs +6 -4
- package/dist/order-builder/helpers/createMarketOrder.cjs.map +1 -1
- package/dist/order-builder/helpers/createMarketOrder.js +6 -4
- package/dist/order-builder/helpers/createMarketOrder.js.map +1 -1
- package/dist/order-builder/helpers/createOrder.cjs +6 -4
- package/dist/order-builder/helpers/createOrder.cjs.map +1 -1
- package/dist/order-builder/helpers/createOrder.js +6 -4
- package/dist/order-builder/helpers/createOrder.js.map +1 -1
- package/dist/order-builder/helpers/orderAsset.cjs +16 -0
- package/dist/order-builder/helpers/orderAsset.cjs.map +1 -0
- package/dist/order-builder/helpers/orderAsset.js +14 -0
- package/dist/order-builder/helpers/orderAsset.js.map +1 -0
- package/dist/order-builder/orderBuilder.cjs +2 -2
- package/dist/order-builder/orderBuilder.cjs.map +1 -1
- package/dist/order-builder/orderBuilder.d.cts +2 -2
- package/dist/order-builder/orderBuilder.d.ts +2 -2
- package/dist/order-builder/orderBuilder.js +2 -2
- package/dist/order-builder/orderBuilder.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/ordersV1.cjs.map +1 -1
- package/dist/types/ordersV1.d.cts +2 -0
- package/dist/types/ordersV1.d.ts +2 -0
- package/dist/types/ordersV1.js.map +1 -1
- package/dist/types/ordersV2.cjs.map +1 -1
- package/dist/types/ordersV2.d.cts +17 -13
- package/dist/types/ordersV2.d.ts +17 -13
- package/dist/types/ordersV2.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildOrderCreationArgs.js","names":[],"sources":["../../../src/order-builder/helpers/buildOrderCreationArgs.ts"],"sourcesContent":["import { parseUnits, zeroAddress } from \"viem\";\n\nimport { COLLATERAL_TOKEN_DECIMALS } from \"../../config.js\";\nimport { bytes32Zero } from \"../../constants.js\";\nimport type {\n\tOrderDataV1,\n\tOrderDataV2,\n\tSignatureTypeV1,\n\tSignatureTypeV2,\n} from \"../../order-utils/index.js\";\nimport type { RoundConfig, UserOrderV1, UserOrderV2 } from \"../../types/index.js\";\n\nimport { getOrderRawAmounts } from \"./getOrderRawAmounts.js\";\n\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: 1,\n): Promise<OrderDataV1>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion?: 2,\n): Promise<OrderDataV2>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: 3,\n): Promise<OrderDataV2>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: number,\n): Promise<OrderDataV1 | OrderDataV2>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: number = 2,\n): Promise<OrderDataV1 | OrderDataV2> {\n\tconst { side, rawMakerAmt, rawTakerAmt } = getOrderRawAmounts(\n\t\tuserOrder.side,\n\t\tuserOrder.size,\n\t\tuserOrder.price,\n\t\troundConfig,\n\t);\n\n\tconst makerAmount = parseUnits(rawMakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();\n\tconst takerAmount = parseUnits(rawTakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();\n\n\tif (version === 1) {\n\t\tconst v1Order = userOrder as UserOrderV1;\n\t\treturn {\n\t\t\tmaker,\n\t\t\ttaker: v1Order.taker ?? zeroAddress,\n\t\t\ttokenId: userOrder
|
|
1
|
+
{"version":3,"file":"buildOrderCreationArgs.js","names":[],"sources":["../../../src/order-builder/helpers/buildOrderCreationArgs.ts"],"sourcesContent":["import { parseUnits, zeroAddress } from \"viem\";\n\nimport { COLLATERAL_TOKEN_DECIMALS } from \"../../config.js\";\nimport { bytes32Zero } from \"../../constants.js\";\nimport type {\n\tOrderDataV1,\n\tOrderDataV2,\n\tSignatureTypeV1,\n\tSignatureTypeV2,\n} from \"../../order-utils/index.js\";\nimport type { RoundConfig, UserOrderV1, UserOrderV2 } from \"../../types/index.js\";\n\nimport { getOrderRawAmounts } from \"./getOrderRawAmounts.js\";\nimport { resolveOrderAssetID } from \"./orderAsset.js\";\n\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: 1,\n): Promise<OrderDataV1>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion?: 2,\n): Promise<OrderDataV2>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: 3,\n): Promise<OrderDataV2>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: number,\n): Promise<OrderDataV1 | OrderDataV2>;\nexport async function buildOrderCreationArgs(\n\tsigner: string,\n\tmaker: string,\n\tsignatureType: SignatureTypeV2,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\troundConfig: RoundConfig,\n\tversion: number = 2,\n): Promise<OrderDataV1 | OrderDataV2> {\n\tconst { side, rawMakerAmt, rawTakerAmt } = getOrderRawAmounts(\n\t\tuserOrder.side,\n\t\tuserOrder.size,\n\t\tuserOrder.price,\n\t\troundConfig,\n\t);\n\n\tconst makerAmount = parseUnits(rawMakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();\n\tconst takerAmount = parseUnits(rawTakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();\n\n\tif (version === 1) {\n\t\tconst v1Order = userOrder as UserOrderV1;\n\t\treturn {\n\t\t\tmaker,\n\t\t\ttaker: v1Order.taker ?? zeroAddress,\n\t\t\ttokenId: resolveOrderAssetID(userOrder),\n\t\t\tmakerAmount,\n\t\t\ttakerAmount,\n\t\t\tside,\n\t\t\tsigner,\n\t\t\tsignatureType: signatureType as unknown as SignatureTypeV1,\n\t\t\tfeeRateBps: v1Order.feeRateBps?.toString() ?? \"0\",\n\t\t\tnonce: v1Order.nonce?.toString() ?? \"0\",\n\t\t\texpiration: userOrder.expiration !== undefined ? userOrder.expiration.toString() : \"0\",\n\t\t};\n\t}\n\n\treturn {\n\t\tmaker,\n\t\ttokenId: resolveOrderAssetID(userOrder),\n\t\tmakerAmount,\n\t\ttakerAmount,\n\t\tside,\n\t\tsigner,\n\t\tsignatureType,\n\t\ttimestamp: Date.now().toString(),\n\t\tmetadata: \"metadata\" in userOrder ? (userOrder.metadata ?? bytes32Zero) : bytes32Zero,\n\t\tbuilder: userOrder.builderCode ?? bytes32Zero,\n\t\texpiration: userOrder.expiration !== undefined ? userOrder.expiration.toString() : \"0\",\n\t};\n}\n"],"mappings":";;;;;;;AA+CA,eAAsB,uBACrB,QACA,OACA,eACA,WACA,aACA,UAAkB,GACmB;CACrC,MAAM,EAAE,MAAM,aAAa,gBAAgB,mBAC1C,UAAU,MACV,UAAU,MACV,UAAU,OACV,YACA;CAED,MAAM,cAAc,WAAW,YAAY,UAAU,EAAE,0BAA0B,CAAC,UAAU;CAC5F,MAAM,cAAc,WAAW,YAAY,UAAU,EAAE,0BAA0B,CAAC,UAAU;AAE5F,KAAI,YAAY,GAAG;EAClB,MAAM,UAAU;AAChB,SAAO;GACN;GACA,OAAO,QAAQ,SAAS;GACxB,SAAS,oBAAoB,UAAU;GACvC;GACA;GACA;GACA;GACe;GACf,YAAY,QAAQ,YAAY,UAAU,IAAI;GAC9C,OAAO,QAAQ,OAAO,UAAU,IAAI;GACpC,YAAY,UAAU,eAAe,SAAY,UAAU,WAAW,UAAU,GAAG;GACnF;;AAGF,QAAO;EACN;EACA,SAAS,oBAAoB,UAAU;EACvC;EACA;EACA;EACA;EACA;EACA,WAAW,KAAK,KAAK,CAAC,UAAU;EAChC,UAAU,cAAc,YAAa,UAAU,YAAY,cAAe;EAC1E,SAAS,UAAU,eAAe;EAClC,YAAY,UAAU,eAAe,SAAY,UAAU,WAAW,UAAU,GAAG;EACnF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_signer = require('../../signing/signer.cjs');
|
|
2
2
|
const require_config = require('../../config.cjs');
|
|
3
|
+
const require_orderAsset = require('./orderAsset.cjs');
|
|
3
4
|
const require_buildMarketOrderCreationArgs = require('./buildMarketOrderCreationArgs.cjs');
|
|
4
5
|
const require_signatureTypeV2 = require('../../order-utils/model/signatureTypeV2.cjs');
|
|
5
6
|
const require_buildOrder = require('./buildOrder.cjs');
|
|
@@ -11,9 +12,10 @@ const createMarketOrder = async (eoaSigner, chainId, signatureType, funderAddres
|
|
|
11
12
|
const maker = funderAddress === void 0 ? eoaSignerAddress : funderAddress;
|
|
12
13
|
const signerForOrder = signatureType === require_signatureTypeV2.SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;
|
|
13
14
|
const contractConfig = require_config.getContractConfig(chainId);
|
|
14
|
-
const
|
|
15
|
+
const orderVersion = require_orderAsset.resolveOrderRouting(userMarketOrder, version).exchangeVersion ?? version;
|
|
16
|
+
const orderData = await require_buildMarketOrderCreationArgs.buildMarketOrderCreationArgs(signerForOrder, maker, signatureType, userMarketOrder, require_roundingConfig.ROUNDING_CONFIG[options.tickSize], orderVersion);
|
|
15
17
|
let exchangeContract;
|
|
16
|
-
switch (
|
|
18
|
+
switch (orderVersion) {
|
|
17
19
|
case 1:
|
|
18
20
|
if (signatureType === require_signatureTypeV2.SignatureTypeV2.POLY_1271) throw new Error(`signature type POLY_1271 is not supported for v1 orders`);
|
|
19
21
|
exchangeContract = options.negRisk ? contractConfig.negRiskExchange : contractConfig.exchange;
|
|
@@ -24,9 +26,9 @@ const createMarketOrder = async (eoaSigner, chainId, signatureType, funderAddres
|
|
|
24
26
|
case 3:
|
|
25
27
|
exchangeContract = contractConfig.exchangeV3;
|
|
26
28
|
break;
|
|
27
|
-
default: throw new Error(`unsupported order version ${
|
|
29
|
+
default: throw new Error(`unsupported order version ${orderVersion}`);
|
|
28
30
|
}
|
|
29
|
-
return require_buildOrder.buildOrder(eoaSigner, exchangeContract, chainId, orderData,
|
|
31
|
+
return require_buildOrder.buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMarketOrder.cjs","names":["getSignerAddress","SignatureTypeV2","getContractConfig","buildMarketOrderCreationArgs","ROUNDING_CONFIG","exchangeContract: string","buildOrder"],"sources":["../../../src/order-builder/helpers/createMarketOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n} from \"../../types/index.js\";\nimport { buildMarketOrderCreationArgs } from \"./buildMarketOrderCreationArgs.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createMarketOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\n\tconst orderData = await buildMarketOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserMarketOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\
|
|
1
|
+
{"version":3,"file":"createMarketOrder.cjs","names":["getSignerAddress","SignatureTypeV2","getContractConfig","resolveOrderRouting","buildMarketOrderCreationArgs","ROUNDING_CONFIG","exchangeContract: string","buildOrder"],"sources":["../../../src/order-builder/helpers/createMarketOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n} from \"../../types/index.js\";\nimport { buildMarketOrderCreationArgs } from \"./buildMarketOrderCreationArgs.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { resolveOrderRouting } from \"./orderAsset.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createMarketOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\tconst orderVersion = resolveOrderRouting(userMarketOrder, version).exchangeVersion ?? version;\n\n\tconst orderData = await buildMarketOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserMarketOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\torderVersion,\n\t);\n\n\tlet exchangeContract: string;\n\tswitch (orderVersion) {\n\t\tcase 1:\n\t\t\tif (signatureType === SignatureTypeV2.POLY_1271) {\n\t\t\t\tthrow new Error(`signature type POLY_1271 is not supported for v1 orders`);\n\t\t\t}\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchange\n\t\t\t\t: contractConfig.exchange;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchangeV2\n\t\t\t\t: contractConfig.exchangeV2;\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\texchangeContract = contractConfig.exchangeV3;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`unsupported order version ${orderVersion}`);\n\t}\n\n\treturn buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,oBAAoB,OAChC,WACA,SACA,eACA,eACA,iBACA,SACA,YAC4C;CAC5C,MAAM,mBAAmB,MAAMA,gCAAiB,UAAU;CAG1D,MAAM,QAAQ,kBAAkB,SAAY,mBAAmB;CAG/D,MAAM,iBAAiB,kBAAkBC,wCAAgB,YAAY,QAAQ;CAC7E,MAAM,iBAAiBC,iCAAkB,QAAQ;CACjD,MAAM,eAAeC,uCAAoB,iBAAiB,QAAQ,CAAC,mBAAmB;CAEtF,MAAM,YAAY,MAAMC,kEACvB,gBACA,OACA,eACA,iBACAC,uCAAgB,QAAQ,WACxB,aACA;CAED,IAAIC;AACJ,SAAQ,cAAR;EACC,KAAK;AACJ,OAAI,kBAAkBL,wCAAgB,UACrC,OAAM,IAAI,MAAM,0DAA0D;AAE3E,sBAAmB,QAAQ,UACxB,eAAe,kBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,QAAQ,UACxB,eAAe,oBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,eAAe;AAClC;EACD,QACC,OAAM,IAAI,MAAM,6BAA6B,eAAe;;AAG9D,QAAOM,8BAAW,WAAW,kBAAkB,SAAS,WAAW,aAAa"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getSignerAddress } from "../../signing/signer.js";
|
|
2
2
|
import { getContractConfig } from "../../config.js";
|
|
3
|
+
import { resolveOrderRouting } from "./orderAsset.js";
|
|
3
4
|
import { buildMarketOrderCreationArgs } from "./buildMarketOrderCreationArgs.js";
|
|
4
5
|
import { SignatureTypeV2 } from "../../order-utils/model/signatureTypeV2.js";
|
|
5
6
|
import { buildOrder } from "./buildOrder.js";
|
|
@@ -11,9 +12,10 @@ const createMarketOrder = async (eoaSigner, chainId, signatureType, funderAddres
|
|
|
11
12
|
const maker = funderAddress === void 0 ? eoaSignerAddress : funderAddress;
|
|
12
13
|
const signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;
|
|
13
14
|
const contractConfig = getContractConfig(chainId);
|
|
14
|
-
const
|
|
15
|
+
const orderVersion = resolveOrderRouting(userMarketOrder, version).exchangeVersion ?? version;
|
|
16
|
+
const orderData = await buildMarketOrderCreationArgs(signerForOrder, maker, signatureType, userMarketOrder, ROUNDING_CONFIG[options.tickSize], orderVersion);
|
|
15
17
|
let exchangeContract;
|
|
16
|
-
switch (
|
|
18
|
+
switch (orderVersion) {
|
|
17
19
|
case 1:
|
|
18
20
|
if (signatureType === SignatureTypeV2.POLY_1271) throw new Error(`signature type POLY_1271 is not supported for v1 orders`);
|
|
19
21
|
exchangeContract = options.negRisk ? contractConfig.negRiskExchange : contractConfig.exchange;
|
|
@@ -24,9 +26,9 @@ const createMarketOrder = async (eoaSigner, chainId, signatureType, funderAddres
|
|
|
24
26
|
case 3:
|
|
25
27
|
exchangeContract = contractConfig.exchangeV3;
|
|
26
28
|
break;
|
|
27
|
-
default: throw new Error(`unsupported order version ${
|
|
29
|
+
default: throw new Error(`unsupported order version ${orderVersion}`);
|
|
28
30
|
}
|
|
29
|
-
return buildOrder(eoaSigner, exchangeContract, chainId, orderData,
|
|
31
|
+
return buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMarketOrder.js","names":["exchangeContract: string"],"sources":["../../../src/order-builder/helpers/createMarketOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n} from \"../../types/index.js\";\nimport { buildMarketOrderCreationArgs } from \"./buildMarketOrderCreationArgs.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createMarketOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\n\tconst orderData = await buildMarketOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserMarketOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\
|
|
1
|
+
{"version":3,"file":"createMarketOrder.js","names":["exchangeContract: string"],"sources":["../../../src/order-builder/helpers/createMarketOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n} from \"../../types/index.js\";\nimport { buildMarketOrderCreationArgs } from \"./buildMarketOrderCreationArgs.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { resolveOrderRouting } from \"./orderAsset.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createMarketOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\tconst orderVersion = resolveOrderRouting(userMarketOrder, version).exchangeVersion ?? version;\n\n\tconst orderData = await buildMarketOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserMarketOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\torderVersion,\n\t);\n\n\tlet exchangeContract: string;\n\tswitch (orderVersion) {\n\t\tcase 1:\n\t\t\tif (signatureType === SignatureTypeV2.POLY_1271) {\n\t\t\t\tthrow new Error(`signature type POLY_1271 is not supported for v1 orders`);\n\t\t\t}\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchange\n\t\t\t\t: contractConfig.exchange;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchangeV2\n\t\t\t\t: contractConfig.exchangeV2;\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\texchangeContract = contractConfig.exchangeV3;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`unsupported order version ${orderVersion}`);\n\t}\n\n\treturn buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,oBAAoB,OAChC,WACA,SACA,eACA,eACA,iBACA,SACA,YAC4C;CAC5C,MAAM,mBAAmB,MAAM,iBAAiB,UAAU;CAG1D,MAAM,QAAQ,kBAAkB,SAAY,mBAAmB;CAG/D,MAAM,iBAAiB,kBAAkB,gBAAgB,YAAY,QAAQ;CAC7E,MAAM,iBAAiB,kBAAkB,QAAQ;CACjD,MAAM,eAAe,oBAAoB,iBAAiB,QAAQ,CAAC,mBAAmB;CAEtF,MAAM,YAAY,MAAM,6BACvB,gBACA,OACA,eACA,iBACA,gBAAgB,QAAQ,WACxB,aACA;CAED,IAAIA;AACJ,SAAQ,cAAR;EACC,KAAK;AACJ,OAAI,kBAAkB,gBAAgB,UACrC,OAAM,IAAI,MAAM,0DAA0D;AAE3E,sBAAmB,QAAQ,UACxB,eAAe,kBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,QAAQ,UACxB,eAAe,oBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,eAAe;AAClC;EACD,QACC,OAAM,IAAI,MAAM,6BAA6B,eAAe;;AAG9D,QAAO,WAAW,WAAW,kBAAkB,SAAS,WAAW,aAAa"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_signer = require('../../signing/signer.cjs');
|
|
2
2
|
const require_config = require('../../config.cjs');
|
|
3
|
+
const require_orderAsset = require('./orderAsset.cjs');
|
|
3
4
|
const require_signatureTypeV2 = require('../../order-utils/model/signatureTypeV2.cjs');
|
|
4
5
|
const require_buildOrder = require('./buildOrder.cjs');
|
|
5
6
|
const require_buildOrderCreationArgs = require('./buildOrderCreationArgs.cjs');
|
|
@@ -11,9 +12,10 @@ const createOrder = async (eoaSigner, chainId, signatureType, funderAddress, use
|
|
|
11
12
|
const maker = funderAddress === void 0 ? eoaSignerAddress : funderAddress;
|
|
12
13
|
const signerForOrder = signatureType === require_signatureTypeV2.SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;
|
|
13
14
|
const contractConfig = require_config.getContractConfig(chainId);
|
|
14
|
-
const
|
|
15
|
+
const orderVersion = require_orderAsset.resolveOrderRouting(userOrder, version).exchangeVersion ?? version;
|
|
16
|
+
const orderData = await require_buildOrderCreationArgs.buildOrderCreationArgs(signerForOrder, maker, signatureType, userOrder, require_roundingConfig.ROUNDING_CONFIG[options.tickSize], orderVersion);
|
|
15
17
|
let exchangeContract;
|
|
16
|
-
switch (
|
|
18
|
+
switch (orderVersion) {
|
|
17
19
|
case 1:
|
|
18
20
|
if (signatureType === require_signatureTypeV2.SignatureTypeV2.POLY_1271) throw new Error(`signature type POLY_1271 is not supported for v1 orders`);
|
|
19
21
|
exchangeContract = options.negRisk ? contractConfig.negRiskExchange : contractConfig.exchange;
|
|
@@ -24,9 +26,9 @@ const createOrder = async (eoaSigner, chainId, signatureType, funderAddress, use
|
|
|
24
26
|
case 3:
|
|
25
27
|
exchangeContract = contractConfig.exchangeV3;
|
|
26
28
|
break;
|
|
27
|
-
default: throw new Error(`unsupported order version ${
|
|
29
|
+
default: throw new Error(`unsupported order version ${orderVersion}`);
|
|
28
30
|
}
|
|
29
|
-
return require_buildOrder.buildOrder(eoaSigner, exchangeContract, chainId, orderData,
|
|
31
|
+
return require_buildOrder.buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOrder.cjs","names":["getSignerAddress","SignatureTypeV2","getContractConfig","buildOrderCreationArgs","ROUNDING_CONFIG","exchangeContract: string","buildOrder"],"sources":["../../../src/order-builder/helpers/createOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type { Chain, CreateOrderOptions, UserOrderV1, UserOrderV2 } from \"../../types/index.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { buildOrderCreationArgs } from \"./buildOrderCreationArgs.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\n\tconst orderData = await buildOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\
|
|
1
|
+
{"version":3,"file":"createOrder.cjs","names":["getSignerAddress","SignatureTypeV2","getContractConfig","resolveOrderRouting","buildOrderCreationArgs","ROUNDING_CONFIG","exchangeContract: string","buildOrder"],"sources":["../../../src/order-builder/helpers/createOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type { Chain, CreateOrderOptions, UserOrderV1, UserOrderV2 } from \"../../types/index.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { buildOrderCreationArgs } from \"./buildOrderCreationArgs.js\";\nimport { resolveOrderRouting } from \"./orderAsset.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\tconst orderVersion = resolveOrderRouting(userOrder, version).exchangeVersion ?? version;\n\n\tconst orderData = await buildOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\torderVersion,\n\t);\n\tlet exchangeContract: string;\n\tswitch (orderVersion) {\n\t\tcase 1:\n\t\t\tif (signatureType === SignatureTypeV2.POLY_1271) {\n\t\t\t\tthrow new Error(`signature type POLY_1271 is not supported for v1 orders`);\n\t\t\t}\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchange\n\t\t\t\t: contractConfig.exchange;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchangeV2\n\t\t\t\t: contractConfig.exchangeV2;\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\texchangeContract = contractConfig.exchangeV3;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`unsupported order version ${orderVersion}`);\n\t}\n\treturn buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);\n};\n"],"mappings":";;;;;;;;;AAUA,MAAa,cAAc,OAC1B,WACA,SACA,eACA,eACA,WACA,SACA,YAC4C;CAC5C,MAAM,mBAAmB,MAAMA,gCAAiB,UAAU;CAG1D,MAAM,QAAQ,kBAAkB,SAAY,mBAAmB;CAG/D,MAAM,iBAAiB,kBAAkBC,wCAAgB,YAAY,QAAQ;CAC7E,MAAM,iBAAiBC,iCAAkB,QAAQ;CACjD,MAAM,eAAeC,uCAAoB,WAAW,QAAQ,CAAC,mBAAmB;CAEhF,MAAM,YAAY,MAAMC,sDACvB,gBACA,OACA,eACA,WACAC,uCAAgB,QAAQ,WACxB,aACA;CACD,IAAIC;AACJ,SAAQ,cAAR;EACC,KAAK;AACJ,OAAI,kBAAkBL,wCAAgB,UACrC,OAAM,IAAI,MAAM,0DAA0D;AAE3E,sBAAmB,QAAQ,UACxB,eAAe,kBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,QAAQ,UACxB,eAAe,oBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,eAAe;AAClC;EACD,QACC,OAAM,IAAI,MAAM,6BAA6B,eAAe;;AAE9D,QAAOM,8BAAW,WAAW,kBAAkB,SAAS,WAAW,aAAa"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getSignerAddress } from "../../signing/signer.js";
|
|
2
2
|
import { getContractConfig } from "../../config.js";
|
|
3
|
+
import { resolveOrderRouting } from "./orderAsset.js";
|
|
3
4
|
import { SignatureTypeV2 } from "../../order-utils/model/signatureTypeV2.js";
|
|
4
5
|
import { buildOrder } from "./buildOrder.js";
|
|
5
6
|
import { buildOrderCreationArgs } from "./buildOrderCreationArgs.js";
|
|
@@ -11,9 +12,10 @@ const createOrder = async (eoaSigner, chainId, signatureType, funderAddress, use
|
|
|
11
12
|
const maker = funderAddress === void 0 ? eoaSignerAddress : funderAddress;
|
|
12
13
|
const signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;
|
|
13
14
|
const contractConfig = getContractConfig(chainId);
|
|
14
|
-
const
|
|
15
|
+
const orderVersion = resolveOrderRouting(userOrder, version).exchangeVersion ?? version;
|
|
16
|
+
const orderData = await buildOrderCreationArgs(signerForOrder, maker, signatureType, userOrder, ROUNDING_CONFIG[options.tickSize], orderVersion);
|
|
15
17
|
let exchangeContract;
|
|
16
|
-
switch (
|
|
18
|
+
switch (orderVersion) {
|
|
17
19
|
case 1:
|
|
18
20
|
if (signatureType === SignatureTypeV2.POLY_1271) throw new Error(`signature type POLY_1271 is not supported for v1 orders`);
|
|
19
21
|
exchangeContract = options.negRisk ? contractConfig.negRiskExchange : contractConfig.exchange;
|
|
@@ -24,9 +26,9 @@ const createOrder = async (eoaSigner, chainId, signatureType, funderAddress, use
|
|
|
24
26
|
case 3:
|
|
25
27
|
exchangeContract = contractConfig.exchangeV3;
|
|
26
28
|
break;
|
|
27
|
-
default: throw new Error(`unsupported order version ${
|
|
29
|
+
default: throw new Error(`unsupported order version ${orderVersion}`);
|
|
28
30
|
}
|
|
29
|
-
return buildOrder(eoaSigner, exchangeContract, chainId, orderData,
|
|
31
|
+
return buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOrder.js","names":["exchangeContract: string"],"sources":["../../../src/order-builder/helpers/createOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type { Chain, CreateOrderOptions, UserOrderV1, UserOrderV2 } from \"../../types/index.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { buildOrderCreationArgs } from \"./buildOrderCreationArgs.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\n\tconst orderData = await buildOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\
|
|
1
|
+
{"version":3,"file":"createOrder.js","names":["exchangeContract: string"],"sources":["../../../src/order-builder/helpers/createOrder.ts"],"sourcesContent":["import { getContractConfig } from \"../../config.js\";\nimport type { SignedOrderV1, SignedOrderV2 } from \"../../order-utils/index.js\";\nimport { SignatureTypeV2 } from \"../../order-utils/index.js\";\nimport { type ClobSigner, getSignerAddress } from \"../../signing/signer.js\";\nimport type { Chain, CreateOrderOptions, UserOrderV1, UserOrderV2 } from \"../../types/index.js\";\nimport { buildOrder } from \"./buildOrder.js\";\nimport { buildOrderCreationArgs } from \"./buildOrderCreationArgs.js\";\nimport { resolveOrderRouting } from \"./orderAsset.js\";\nimport { ROUNDING_CONFIG } from \"./roundingConfig.js\";\n\nexport const createOrder = async (\n\teoaSigner: ClobSigner,\n\tchainId: Chain,\n\tsignatureType: SignatureTypeV2,\n\tfunderAddress: string | undefined,\n\tuserOrder: UserOrderV1 | UserOrderV2,\n\toptions: CreateOrderOptions,\n\tversion: number,\n): Promise<SignedOrderV1 | SignedOrderV2> => {\n\tconst eoaSignerAddress = await getSignerAddress(eoaSigner);\n\n\t// If funder address is not given, use the signer address\n\tconst maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;\n\n\t// For POLY_1271, both maker and signer in the order are the wallet address\n\tconst signerForOrder = signatureType === SignatureTypeV2.POLY_1271 ? maker : eoaSignerAddress;\n\tconst contractConfig = getContractConfig(chainId);\n\tconst orderVersion = resolveOrderRouting(userOrder, version).exchangeVersion ?? version;\n\n\tconst orderData = await buildOrderCreationArgs(\n\t\tsignerForOrder,\n\t\tmaker,\n\t\tsignatureType,\n\t\tuserOrder,\n\t\tROUNDING_CONFIG[options.tickSize],\n\t\torderVersion,\n\t);\n\tlet exchangeContract: string;\n\tswitch (orderVersion) {\n\t\tcase 1:\n\t\t\tif (signatureType === SignatureTypeV2.POLY_1271) {\n\t\t\t\tthrow new Error(`signature type POLY_1271 is not supported for v1 orders`);\n\t\t\t}\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchange\n\t\t\t\t: contractConfig.exchange;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\texchangeContract = options.negRisk\n\t\t\t\t? contractConfig.negRiskExchangeV2\n\t\t\t\t: contractConfig.exchangeV2;\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\texchangeContract = contractConfig.exchangeV3;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`unsupported order version ${orderVersion}`);\n\t}\n\treturn buildOrder(eoaSigner, exchangeContract, chainId, orderData, orderVersion);\n};\n"],"mappings":";;;;;;;;;AAUA,MAAa,cAAc,OAC1B,WACA,SACA,eACA,eACA,WACA,SACA,YAC4C;CAC5C,MAAM,mBAAmB,MAAM,iBAAiB,UAAU;CAG1D,MAAM,QAAQ,kBAAkB,SAAY,mBAAmB;CAG/D,MAAM,iBAAiB,kBAAkB,gBAAgB,YAAY,QAAQ;CAC7E,MAAM,iBAAiB,kBAAkB,QAAQ;CACjD,MAAM,eAAe,oBAAoB,WAAW,QAAQ,CAAC,mBAAmB;CAEhF,MAAM,YAAY,MAAM,uBACvB,gBACA,OACA,eACA,WACA,gBAAgB,QAAQ,WACxB,aACA;CACD,IAAIA;AACJ,SAAQ,cAAR;EACC,KAAK;AACJ,OAAI,kBAAkB,gBAAgB,UACrC,OAAM,IAAI,MAAM,0DAA0D;AAE3E,sBAAmB,QAAQ,UACxB,eAAe,kBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,QAAQ,UACxB,eAAe,oBACf,eAAe;AAClB;EACD,KAAK;AACJ,sBAAmB,eAAe;AAClC;EACD,QACC,OAAM,IAAI,MAAM,6BAA6B,eAAe;;AAE9D,QAAO,WAAW,WAAW,kBAAkB,SAAS,WAAW,aAAa"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/order-builder/helpers/orderAsset.ts
|
|
3
|
+
function resolveOrderAssetID(asset) {
|
|
4
|
+
return asset.positionID ?? asset.tokenID;
|
|
5
|
+
}
|
|
6
|
+
function resolveOrderRouting(asset, requestedVersion) {
|
|
7
|
+
return {
|
|
8
|
+
assetID: resolveOrderAssetID(asset),
|
|
9
|
+
exchangeVersion: asset.positionID === void 0 ? requestedVersion : 3
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.resolveOrderAssetID = resolveOrderAssetID;
|
|
15
|
+
exports.resolveOrderRouting = resolveOrderRouting;
|
|
16
|
+
//# sourceMappingURL=orderAsset.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderAsset.cjs","names":[],"sources":["../../../src/order-builder/helpers/orderAsset.ts"],"sourcesContent":["import type { OrderAsset } from \"../../types/index.js\";\n\nexport type OrderRouting = {\n\tassetID: string;\n\texchangeVersion: number | undefined;\n};\n\nexport function resolveOrderAssetID(asset: OrderAsset): string {\n\treturn asset.positionID ?? asset.tokenID;\n}\n\nexport function resolveOrderRouting(asset: OrderAsset, requestedVersion?: number): OrderRouting {\n\treturn {\n\t\tassetID: resolveOrderAssetID(asset),\n\t\texchangeVersion: asset.positionID === undefined ? requestedVersion : 3,\n\t};\n}\n"],"mappings":";;AAOA,SAAgB,oBAAoB,OAA2B;AAC9D,QAAO,MAAM,cAAc,MAAM;;AAGlC,SAAgB,oBAAoB,OAAmB,kBAAyC;AAC/F,QAAO;EACN,SAAS,oBAAoB,MAAM;EACnC,iBAAiB,MAAM,eAAe,SAAY,mBAAmB;EACrE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/order-builder/helpers/orderAsset.ts
|
|
2
|
+
function resolveOrderAssetID(asset) {
|
|
3
|
+
return asset.positionID ?? asset.tokenID;
|
|
4
|
+
}
|
|
5
|
+
function resolveOrderRouting(asset, requestedVersion) {
|
|
6
|
+
return {
|
|
7
|
+
assetID: resolveOrderAssetID(asset),
|
|
8
|
+
exchangeVersion: asset.positionID === void 0 ? requestedVersion : 3
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { resolveOrderAssetID, resolveOrderRouting };
|
|
14
|
+
//# sourceMappingURL=orderAsset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderAsset.js","names":[],"sources":["../../../src/order-builder/helpers/orderAsset.ts"],"sourcesContent":["import type { OrderAsset } from \"../../types/index.js\";\n\nexport type OrderRouting = {\n\tassetID: string;\n\texchangeVersion: number | undefined;\n};\n\nexport function resolveOrderAssetID(asset: OrderAsset): string {\n\treturn asset.positionID ?? asset.tokenID;\n}\n\nexport function resolveOrderRouting(asset: OrderAsset, requestedVersion?: number): OrderRouting {\n\treturn {\n\t\tassetID: resolveOrderAssetID(asset),\n\t\texchangeVersion: asset.positionID === undefined ? requestedVersion : 3,\n\t};\n}\n"],"mappings":";AAOA,SAAgB,oBAAoB,OAA2B;AAC9D,QAAO,MAAM,cAAc,MAAM;;AAGlC,SAAgB,oBAAoB,OAAmB,kBAAyC;AAC/F,QAAO;EACN,SAAS,oBAAoB,MAAM;EACnC,iBAAiB,MAAM,eAAe,SAAY,mBAAmB;EACrE"}
|
|
@@ -27,13 +27,13 @@ var OrderBuilder = class {
|
|
|
27
27
|
/**
|
|
28
28
|
* Generate and sign a order
|
|
29
29
|
*/
|
|
30
|
-
async buildOrder(userOrder, options, version) {
|
|
30
|
+
async buildOrder(userOrder, options, version = 2) {
|
|
31
31
|
return require_createOrder.createOrder(await this.resolveSigner(), this.chainId, this.signatureType, this.funderAddress, userOrder, options, version);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Generate and sign a market order
|
|
35
35
|
*/
|
|
36
|
-
async buildMarketOrder(userMarketOrder, options, version) {
|
|
36
|
+
async buildMarketOrder(userMarketOrder, options, version = 2) {
|
|
37
37
|
return require_createMarketOrder.createMarketOrder(await this.resolveSigner(), this.chainId, this.signatureType, this.funderAddress, userMarketOrder, options, version);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orderBuilder.cjs","names":["SignatureTypeV2","createOrder","createMarketOrder","createExchangeV3OrderFromAmounts"],"sources":["../../src/order-builder/orderBuilder.ts"],"sourcesContent":["import { SignatureTypeV2, type SignedOrderV1, type SignedOrderV2 } from \"../order-utils/index.js\";\nimport type { ClobSigner } from \"../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tExchangeV3OrderAmounts,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n\tUserOrderV1,\n\tUserOrderV2,\n} from \"../types/index.js\";\n\nimport { createExchangeV3OrderFromAmounts } from \"./helpers/createExchangeV3OrderFromAmounts.js\";\nimport { createMarketOrder, createOrder } from \"./helpers/index.js\";\n\nexport class OrderBuilder {\n\treadonly signer: ClobSigner;\n\n\treadonly chainId: Chain;\n\n\t// Signature type used sign orders, defaults to EOA type\n\treadonly signatureType: SignatureTypeV2;\n\n\t// Address which holds funds to be used.\n\t// Used for Polymarket proxy wallets and other smart contract wallets\n\t// If not provided, funderAddress is the signer address\n\treadonly funderAddress?: string;\n\n\t/**\n\t * Optional function to dynamically resolve the signer.\n\t * If provided, this function will be called to obtain a fresh signer instance\n\t * (e.g., for smart contract wallets or when the signer may change).\n\t * Should return a Wallet or JsonRpcSigner, or a Promise resolving to one.\n\t * If not provided, the static `signer` property is used.\n\t */\n\tprivate getSigner?: () => Promise<ClobSigner> | ClobSigner;\n\n\tconstructor(\n\t\tsigner: ClobSigner,\n\t\tchainId: Chain,\n\t\tsignatureType?: SignatureTypeV2,\n\t\tfunderAddress?: string,\n\t\tgetSigner?: () => Promise<ClobSigner> | ClobSigner,\n\t) {\n\t\tthis.signer = signer;\n\t\tthis.chainId = chainId;\n\t\tthis.signatureType = signatureType === undefined ? SignatureTypeV2.EOA : signatureType;\n\t\tthis.funderAddress = funderAddress;\n\t\tthis.getSigner = getSigner;\n\t}\n\n\t/**\n\t * Generate and sign a order\n\t */\n\tpublic async buildOrder(\n\t\tuserOrder: UserOrderV1 | UserOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign a market order\n\t */\n\tpublic async buildMarketOrder(\n\t\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createMarketOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserMarketOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign an ExchangeV3 order using exact base-unit amounts.\n\t */\n\tpublic async buildExchangeV3OrderFromAmounts(\n\t\tuserOrder: ExchangeV3OrderAmounts,\n\t): Promise<SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createExchangeV3OrderFromAmounts(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t);\n\t}\n\n\t/** Unified getter: use fresh signer if available */\n\tprivate async resolveSigner(): Promise<ClobSigner> {\n\t\tif (this.getSigner) {\n\t\t\tconst s = await this.getSigner();\n\t\t\tif (!s) throw new Error(\"getSigner() function returned undefined or null\");\n\t\t\treturn s;\n\t\t}\n\t\treturn this.signer;\n\t}\n}\n"],"mappings":";;;;;;AAeA,IAAa,eAAb,MAA0B;CACzB,AAAS;CAET,AAAS;CAGT,AAAS;CAKT,AAAS;;;;;;;;CAST,AAAQ;CAER,YACC,QACA,SACA,eACA,eACA,WACC;AACD,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,gBAAgB,kBAAkB,SAAYA,wCAAgB,MAAM;AACzE,OAAK,gBAAgB;AACrB,OAAK,YAAY;;;;;CAMlB,MAAa,WACZ,WACA,SACA,
|
|
1
|
+
{"version":3,"file":"orderBuilder.cjs","names":["SignatureTypeV2","createOrder","createMarketOrder","createExchangeV3OrderFromAmounts"],"sources":["../../src/order-builder/orderBuilder.ts"],"sourcesContent":["import { SignatureTypeV2, type SignedOrderV1, type SignedOrderV2 } from \"../order-utils/index.js\";\nimport type { ClobSigner } from \"../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tExchangeV3OrderAmounts,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n\tUserOrderV1,\n\tUserOrderV2,\n} from \"../types/index.js\";\n\nimport { createExchangeV3OrderFromAmounts } from \"./helpers/createExchangeV3OrderFromAmounts.js\";\nimport { createMarketOrder, createOrder } from \"./helpers/index.js\";\n\nexport class OrderBuilder {\n\treadonly signer: ClobSigner;\n\n\treadonly chainId: Chain;\n\n\t// Signature type used sign orders, defaults to EOA type\n\treadonly signatureType: SignatureTypeV2;\n\n\t// Address which holds funds to be used.\n\t// Used for Polymarket proxy wallets and other smart contract wallets\n\t// If not provided, funderAddress is the signer address\n\treadonly funderAddress?: string;\n\n\t/**\n\t * Optional function to dynamically resolve the signer.\n\t * If provided, this function will be called to obtain a fresh signer instance\n\t * (e.g., for smart contract wallets or when the signer may change).\n\t * Should return a Wallet or JsonRpcSigner, or a Promise resolving to one.\n\t * If not provided, the static `signer` property is used.\n\t */\n\tprivate getSigner?: () => Promise<ClobSigner> | ClobSigner;\n\n\tconstructor(\n\t\tsigner: ClobSigner,\n\t\tchainId: Chain,\n\t\tsignatureType?: SignatureTypeV2,\n\t\tfunderAddress?: string,\n\t\tgetSigner?: () => Promise<ClobSigner> | ClobSigner,\n\t) {\n\t\tthis.signer = signer;\n\t\tthis.chainId = chainId;\n\t\tthis.signatureType = signatureType === undefined ? SignatureTypeV2.EOA : signatureType;\n\t\tthis.funderAddress = funderAddress;\n\t\tthis.getSigner = getSigner;\n\t}\n\n\t/**\n\t * Generate and sign a order\n\t */\n\tpublic async buildOrder(\n\t\tuserOrder: UserOrderV1 | UserOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number = 2,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign a market order\n\t */\n\tpublic async buildMarketOrder(\n\t\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number = 2,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createMarketOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserMarketOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign an ExchangeV3 order using exact base-unit amounts.\n\t */\n\tpublic async buildExchangeV3OrderFromAmounts(\n\t\tuserOrder: ExchangeV3OrderAmounts,\n\t): Promise<SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createExchangeV3OrderFromAmounts(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t);\n\t}\n\n\t/** Unified getter: use fresh signer if available */\n\tprivate async resolveSigner(): Promise<ClobSigner> {\n\t\tif (this.getSigner) {\n\t\t\tconst s = await this.getSigner();\n\t\t\tif (!s) throw new Error(\"getSigner() function returned undefined or null\");\n\t\t\treturn s;\n\t\t}\n\t\treturn this.signer;\n\t}\n}\n"],"mappings":";;;;;;AAeA,IAAa,eAAb,MAA0B;CACzB,AAAS;CAET,AAAS;CAGT,AAAS;CAKT,AAAS;;;;;;;;CAST,AAAQ;CAER,YACC,QACA,SACA,eACA,eACA,WACC;AACD,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,gBAAgB,kBAAkB,SAAYA,wCAAgB,MAAM;AACzE,OAAK,gBAAgB;AACrB,OAAK,YAAY;;;;;CAMlB,MAAa,WACZ,WACA,SACA,UAAkB,GACuB;AAEzC,SAAOC,gCADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,WACA,SACA,QACA;;;;;CAMF,MAAa,iBACZ,iBACA,SACA,UAAkB,GACuB;AAEzC,SAAOC,4CADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,iBACA,SACA,QACA;;;;;CAMF,MAAa,gCACZ,WACyB;AAEzB,SAAOC,0EADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,UACA;;;CAIF,MAAc,gBAAqC;AAClD,MAAI,KAAK,WAAW;GACnB,MAAM,IAAI,MAAM,KAAK,WAAW;AAChC,OAAI,CAAC,EAAG,OAAM,IAAI,MAAM,kDAAkD;AAC1E,UAAO;;AAER,SAAO,KAAK"}
|
|
@@ -25,11 +25,11 @@ declare class OrderBuilder {
|
|
|
25
25
|
/**
|
|
26
26
|
* Generate and sign a order
|
|
27
27
|
*/
|
|
28
|
-
buildOrder(userOrder: UserOrderV1 | UserOrderV2, options: CreateOrderOptions, version
|
|
28
|
+
buildOrder(userOrder: UserOrderV1 | UserOrderV2, options: CreateOrderOptions, version?: number): Promise<SignedOrderV1 | SignedOrderV2>;
|
|
29
29
|
/**
|
|
30
30
|
* Generate and sign a market order
|
|
31
31
|
*/
|
|
32
|
-
buildMarketOrder(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options: CreateOrderOptions, version
|
|
32
|
+
buildMarketOrder(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options: CreateOrderOptions, version?: number): Promise<SignedOrderV1 | SignedOrderV2>;
|
|
33
33
|
/**
|
|
34
34
|
* Generate and sign an ExchangeV3 order using exact base-unit amounts.
|
|
35
35
|
*/
|
|
@@ -27,11 +27,11 @@ declare class OrderBuilder {
|
|
|
27
27
|
/**
|
|
28
28
|
* Generate and sign a order
|
|
29
29
|
*/
|
|
30
|
-
buildOrder(userOrder: UserOrderV1 | UserOrderV2, options: CreateOrderOptions, version
|
|
30
|
+
buildOrder(userOrder: UserOrderV1 | UserOrderV2, options: CreateOrderOptions, version?: number): Promise<SignedOrderV1 | SignedOrderV2>;
|
|
31
31
|
/**
|
|
32
32
|
* Generate and sign a market order
|
|
33
33
|
*/
|
|
34
|
-
buildMarketOrder(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options: CreateOrderOptions, version
|
|
34
|
+
buildMarketOrder(userMarketOrder: UserMarketOrderV1 | UserMarketOrderV2, options: CreateOrderOptions, version?: number): Promise<SignedOrderV1 | SignedOrderV2>;
|
|
35
35
|
/**
|
|
36
36
|
* Generate and sign an ExchangeV3 order using exact base-unit amounts.
|
|
37
37
|
*/
|
|
@@ -27,13 +27,13 @@ var OrderBuilder = class {
|
|
|
27
27
|
/**
|
|
28
28
|
* Generate and sign a order
|
|
29
29
|
*/
|
|
30
|
-
async buildOrder(userOrder, options, version) {
|
|
30
|
+
async buildOrder(userOrder, options, version = 2) {
|
|
31
31
|
return createOrder(await this.resolveSigner(), this.chainId, this.signatureType, this.funderAddress, userOrder, options, version);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Generate and sign a market order
|
|
35
35
|
*/
|
|
36
|
-
async buildMarketOrder(userMarketOrder, options, version) {
|
|
36
|
+
async buildMarketOrder(userMarketOrder, options, version = 2) {
|
|
37
37
|
return createMarketOrder(await this.resolveSigner(), this.chainId, this.signatureType, this.funderAddress, userMarketOrder, options, version);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orderBuilder.js","names":[],"sources":["../../src/order-builder/orderBuilder.ts"],"sourcesContent":["import { SignatureTypeV2, type SignedOrderV1, type SignedOrderV2 } from \"../order-utils/index.js\";\nimport type { ClobSigner } from \"../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tExchangeV3OrderAmounts,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n\tUserOrderV1,\n\tUserOrderV2,\n} from \"../types/index.js\";\n\nimport { createExchangeV3OrderFromAmounts } from \"./helpers/createExchangeV3OrderFromAmounts.js\";\nimport { createMarketOrder, createOrder } from \"./helpers/index.js\";\n\nexport class OrderBuilder {\n\treadonly signer: ClobSigner;\n\n\treadonly chainId: Chain;\n\n\t// Signature type used sign orders, defaults to EOA type\n\treadonly signatureType: SignatureTypeV2;\n\n\t// Address which holds funds to be used.\n\t// Used for Polymarket proxy wallets and other smart contract wallets\n\t// If not provided, funderAddress is the signer address\n\treadonly funderAddress?: string;\n\n\t/**\n\t * Optional function to dynamically resolve the signer.\n\t * If provided, this function will be called to obtain a fresh signer instance\n\t * (e.g., for smart contract wallets or when the signer may change).\n\t * Should return a Wallet or JsonRpcSigner, or a Promise resolving to one.\n\t * If not provided, the static `signer` property is used.\n\t */\n\tprivate getSigner?: () => Promise<ClobSigner> | ClobSigner;\n\n\tconstructor(\n\t\tsigner: ClobSigner,\n\t\tchainId: Chain,\n\t\tsignatureType?: SignatureTypeV2,\n\t\tfunderAddress?: string,\n\t\tgetSigner?: () => Promise<ClobSigner> | ClobSigner,\n\t) {\n\t\tthis.signer = signer;\n\t\tthis.chainId = chainId;\n\t\tthis.signatureType = signatureType === undefined ? SignatureTypeV2.EOA : signatureType;\n\t\tthis.funderAddress = funderAddress;\n\t\tthis.getSigner = getSigner;\n\t}\n\n\t/**\n\t * Generate and sign a order\n\t */\n\tpublic async buildOrder(\n\t\tuserOrder: UserOrderV1 | UserOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign a market order\n\t */\n\tpublic async buildMarketOrder(\n\t\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createMarketOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserMarketOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign an ExchangeV3 order using exact base-unit amounts.\n\t */\n\tpublic async buildExchangeV3OrderFromAmounts(\n\t\tuserOrder: ExchangeV3OrderAmounts,\n\t): Promise<SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createExchangeV3OrderFromAmounts(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t);\n\t}\n\n\t/** Unified getter: use fresh signer if available */\n\tprivate async resolveSigner(): Promise<ClobSigner> {\n\t\tif (this.getSigner) {\n\t\t\tconst s = await this.getSigner();\n\t\t\tif (!s) throw new Error(\"getSigner() function returned undefined or null\");\n\t\t\treturn s;\n\t\t}\n\t\treturn this.signer;\n\t}\n}\n"],"mappings":";;;;;;AAeA,IAAa,eAAb,MAA0B;CACzB,AAAS;CAET,AAAS;CAGT,AAAS;CAKT,AAAS;;;;;;;;CAST,AAAQ;CAER,YACC,QACA,SACA,eACA,eACA,WACC;AACD,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,gBAAgB,kBAAkB,SAAY,gBAAgB,MAAM;AACzE,OAAK,gBAAgB;AACrB,OAAK,YAAY;;;;;CAMlB,MAAa,WACZ,WACA,SACA,
|
|
1
|
+
{"version":3,"file":"orderBuilder.js","names":[],"sources":["../../src/order-builder/orderBuilder.ts"],"sourcesContent":["import { SignatureTypeV2, type SignedOrderV1, type SignedOrderV2 } from \"../order-utils/index.js\";\nimport type { ClobSigner } from \"../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tExchangeV3OrderAmounts,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n\tUserOrderV1,\n\tUserOrderV2,\n} from \"../types/index.js\";\n\nimport { createExchangeV3OrderFromAmounts } from \"./helpers/createExchangeV3OrderFromAmounts.js\";\nimport { createMarketOrder, createOrder } from \"./helpers/index.js\";\n\nexport class OrderBuilder {\n\treadonly signer: ClobSigner;\n\n\treadonly chainId: Chain;\n\n\t// Signature type used sign orders, defaults to EOA type\n\treadonly signatureType: SignatureTypeV2;\n\n\t// Address which holds funds to be used.\n\t// Used for Polymarket proxy wallets and other smart contract wallets\n\t// If not provided, funderAddress is the signer address\n\treadonly funderAddress?: string;\n\n\t/**\n\t * Optional function to dynamically resolve the signer.\n\t * If provided, this function will be called to obtain a fresh signer instance\n\t * (e.g., for smart contract wallets or when the signer may change).\n\t * Should return a Wallet or JsonRpcSigner, or a Promise resolving to one.\n\t * If not provided, the static `signer` property is used.\n\t */\n\tprivate getSigner?: () => Promise<ClobSigner> | ClobSigner;\n\n\tconstructor(\n\t\tsigner: ClobSigner,\n\t\tchainId: Chain,\n\t\tsignatureType?: SignatureTypeV2,\n\t\tfunderAddress?: string,\n\t\tgetSigner?: () => Promise<ClobSigner> | ClobSigner,\n\t) {\n\t\tthis.signer = signer;\n\t\tthis.chainId = chainId;\n\t\tthis.signatureType = signatureType === undefined ? SignatureTypeV2.EOA : signatureType;\n\t\tthis.funderAddress = funderAddress;\n\t\tthis.getSigner = getSigner;\n\t}\n\n\t/**\n\t * Generate and sign a order\n\t */\n\tpublic async buildOrder(\n\t\tuserOrder: UserOrderV1 | UserOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number = 2,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign a market order\n\t */\n\tpublic async buildMarketOrder(\n\t\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number = 2,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createMarketOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserMarketOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign an ExchangeV3 order using exact base-unit amounts.\n\t */\n\tpublic async buildExchangeV3OrderFromAmounts(\n\t\tuserOrder: ExchangeV3OrderAmounts,\n\t): Promise<SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createExchangeV3OrderFromAmounts(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t);\n\t}\n\n\t/** Unified getter: use fresh signer if available */\n\tprivate async resolveSigner(): Promise<ClobSigner> {\n\t\tif (this.getSigner) {\n\t\t\tconst s = await this.getSigner();\n\t\t\tif (!s) throw new Error(\"getSigner() function returned undefined or null\");\n\t\t\treturn s;\n\t\t}\n\t\treturn this.signer;\n\t}\n}\n"],"mappings":";;;;;;AAeA,IAAa,eAAb,MAA0B;CACzB,AAAS;CAET,AAAS;CAGT,AAAS;CAKT,AAAS;;;;;;;;CAST,AAAQ;CAER,YACC,QACA,SACA,eACA,eACA,WACC;AACD,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,gBAAgB,kBAAkB,SAAY,gBAAgB,MAAM;AACzE,OAAK,gBAAgB;AACrB,OAAK,YAAY;;;;;CAMlB,MAAa,WACZ,WACA,SACA,UAAkB,GACuB;AAEzC,SAAO,YADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,WACA,SACA,QACA;;;;;CAMF,MAAa,iBACZ,iBACA,SACA,UAAkB,GACuB;AAEzC,SAAO,kBADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,iBACA,SACA,QACA;;;;;CAMF,MAAa,gCACZ,WACyB;AAEzB,SAAO,iCADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,UACA;;;CAIF,MAAc,gBAAqC;AAClD,MAAI,KAAK,WAAW;GACnB,MAAM,IAAI,MAAM,KAAK,WAAW;AAChC,OAAI,CAAC,EAAG,OAAM,IAAI,MAAM,kDAAkD;AAC1E,UAAO;;AAER,SAAO,KAAK"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Side } from "../order-utils/model/side.js";
|
|
2
2
|
import { ApiKeyCreds, ApiKeyRaw, ApiKeysResponse, AssetType, BalanceAllowanceParams, BalanceAllowanceResponse, BanStatus, BookParams, BuilderApiKey, BuilderApiKeyResponse, BuilderConfig, BuilderFeeRates, BuilderTrade, BuilderTradeParams, BuilderTradesResponse, Chain, ClobErrorResponseBody, ClobRewards, ClobToken, CreateOrderOptions, DropNotificationParams, Earning, FeeDetails, FeeInfo, FeeInfos, FeeRates, L1PolyHeader, L2HeaderArgs, L2PolyHeader, MakerOrder, MarketDetails, MarketPrice, MarketReward, MarketTradeEvent, NegRisk, Notification, OpenOrder, OpenOrderParams, OpenOrdersResponse, OrderBookSummary, OrderMarketCancelParams, OrderPayload, OrderResponse, OrderScoring, OrderScoringParams, OrderSummary, OrderType, OrderVersion, OrdersScoring, OrdersScoringParams, PaginationPayload, PreMigrationOrder, PreMigrationOrdersResponse, PriceHistoryFilterParams, PriceHistoryInterval, ReadonlyApiKeyResponse, RewardsConfig, RewardsPercentages, RoundConfig, SimpleHeaders, TickSize, TickSizes, Token, TokenConditionMap, TotalUserEarning, Trade, TradeParams, TradesPaginatedResponse, UserEarning, UserRewardsEarning } from "./clob.js";
|
|
3
3
|
import { NewOrderV1, PostOrdersV1Args, UserMarketOrderV1, UserOrderV1, orderToJsonV1 } from "./ordersV1.js";
|
|
4
|
-
import { NewOrderV2, PostOrdersV2Args, UserMarketOrderV2, UserOrderV2, orderToJsonV2 } from "./ordersV2.js";
|
|
4
|
+
import { NewOrderV2, OrderAsset, PostOrdersV2Args, UserMarketOrderV2, UserOrderV2, orderToJsonV2 } from "./ordersV2.js";
|
|
5
5
|
import { ExchangeV3OrderAmounts } from "./ordersV3.js";
|
|
6
6
|
import { PostOrdersArgs, SignedOrder, VersionedPostOrdersArgs, VersionedSignedOrder, VersionedUserMarketOrder, VersionedUserOrder, isV2Order } from "./unifiedOrder.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordersV1.cjs","names":[],"sources":["../../src/types/ordersV1.ts"],"sourcesContent":["import type { SignatureTypeV1, SignedOrderV1 } from \"../order-utils/index.js\";\n\nimport type { OrderType, Side } from \"./clob.js\";\n\nexport function orderToJsonV1<T extends OrderType>(\n\torder: SignedOrderV1,\n\towner: string,\n\torderType: T,\n\tpostOnly = false,\n\tdeferExec = false,\n): NewOrderV1<T> {\n\treturn {\n\t\tdeferExec,\n\t\tpostOnly,\n\t\torder: {\n\t\t\tsalt: parseInt(order.salt, 10),\n\t\t\tmaker: order.maker,\n\t\t\tsigner: order.signer,\n\t\t\ttaker: order.taker,\n\t\t\ttokenId: order.tokenId,\n\t\t\tmakerAmount: order.makerAmount,\n\t\t\ttakerAmount: order.takerAmount,\n\t\t\tside: order.side,\n\t\t\texpiration: order.expiration,\n\t\t\tnonce: order.nonce,\n\t\t\tfeeRateBps: order.feeRateBps,\n\t\t\tsignatureType: order.signatureType,\n\t\t\tsignature: order.signature,\n\t\t},\n\t\towner,\n\t\torderType,\n\t} as NewOrderV1<T>;\n}\n\nexport interface PostOrdersV1Args {\n\torder: SignedOrderV1;\n\torderType: OrderType;\n}\n\nexport interface NewOrderV1<T extends OrderType> {\n\treadonly order: {\n\t\treadonly salt: number;\n\t\treadonly maker: string;\n\t\treadonly signer: string;\n\t\treadonly taker: string;\n\t\treadonly tokenId: string;\n\t\treadonly makerAmount: string;\n\t\treadonly takerAmount: string;\n\t\treadonly expiration: string;\n\t\treadonly nonce: string;\n\t\treadonly feeRateBps: string;\n\t\treadonly side: string;\n\t\treadonly signatureType: SignatureTypeV1;\n\t\treadonly signature: string;\n\t};\n\treadonly owner: string;\n\treadonly orderType: T;\n\treadonly deferExec: boolean;\n\treadonly postOnly: boolean;\n}\n\n// Simplified order for users\nexport interface UserOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\n\t/**\n\t * Price used to create the order\n\t */\n\tprice: number;\n\n\t/**\n\t * Size in terms of the ConditionalToken\n\t */\n\tsize: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Timestamp after which the order is expired.\n\t */\n\texpiration?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n\n// Simplified market order for users\nexport interface UserMarketOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\n\t/**\n\t * Price used to create the order\n\t * If it is not present the market price will be used.\n\t */\n\tprice?: number;\n\n\t/**\n\t * BUY orders: $$$ Amount to buy\n\t * SELL orders: Shares to sell\n\t */\n\tamount: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Specifies the type of order execution:\n\t * - FOK (Fill or Kill): The order must be filled entirely or not at all.\n\t * - FAK (Fill and Kill): The order can be partially filled, and any unfilled portion is canceled.\n\t */\n\torderType?: OrderType.FOK | OrderType.FAK;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n"],"mappings":";;AAIA,SAAgB,cACf,OACA,OACA,WACA,WAAW,OACX,YAAY,OACI;AAChB,QAAO;EACN;EACA;EACA,OAAO;GACN,MAAM,SAAS,MAAM,MAAM,GAAG;GAC9B,OAAO,MAAM;GACb,QAAQ,MAAM;GACd,OAAO,MAAM;GACb,SAAS,MAAM;GACf,aAAa,MAAM;GACnB,aAAa,MAAM;GACnB,MAAM,MAAM;GACZ,YAAY,MAAM;GAClB,OAAO,MAAM;GACb,YAAY,MAAM;GAClB,eAAe,MAAM;GACrB,WAAW,MAAM;GACjB;EACD;EACA;EACA"}
|
|
1
|
+
{"version":3,"file":"ordersV1.cjs","names":[],"sources":["../../src/types/ordersV1.ts"],"sourcesContent":["import type { SignatureTypeV1, SignedOrderV1 } from \"../order-utils/index.js\";\n\nimport type { OrderType, Side } from \"./clob.js\";\n\nexport function orderToJsonV1<T extends OrderType>(\n\torder: SignedOrderV1,\n\towner: string,\n\torderType: T,\n\tpostOnly = false,\n\tdeferExec = false,\n): NewOrderV1<T> {\n\treturn {\n\t\tdeferExec,\n\t\tpostOnly,\n\t\torder: {\n\t\t\tsalt: parseInt(order.salt, 10),\n\t\t\tmaker: order.maker,\n\t\t\tsigner: order.signer,\n\t\t\ttaker: order.taker,\n\t\t\ttokenId: order.tokenId,\n\t\t\tmakerAmount: order.makerAmount,\n\t\t\ttakerAmount: order.takerAmount,\n\t\t\tside: order.side,\n\t\t\texpiration: order.expiration,\n\t\t\tnonce: order.nonce,\n\t\t\tfeeRateBps: order.feeRateBps,\n\t\t\tsignatureType: order.signatureType,\n\t\t\tsignature: order.signature,\n\t\t},\n\t\towner,\n\t\torderType,\n\t} as NewOrderV1<T>;\n}\n\nexport interface PostOrdersV1Args {\n\torder: SignedOrderV1;\n\torderType: OrderType;\n}\n\nexport interface NewOrderV1<T extends OrderType> {\n\treadonly order: {\n\t\treadonly salt: number;\n\t\treadonly maker: string;\n\t\treadonly signer: string;\n\t\treadonly taker: string;\n\t\treadonly tokenId: string;\n\t\treadonly makerAmount: string;\n\t\treadonly takerAmount: string;\n\t\treadonly expiration: string;\n\t\treadonly nonce: string;\n\t\treadonly feeRateBps: string;\n\t\treadonly side: string;\n\t\treadonly signatureType: SignatureTypeV1;\n\t\treadonly signature: string;\n\t};\n\treadonly owner: string;\n\treadonly orderType: T;\n\treadonly deferExec: boolean;\n\treadonly postOnly: boolean;\n}\n\n// Simplified order for users\nexport interface UserOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\tpositionID?: never;\n\n\t/**\n\t * Price used to create the order\n\t */\n\tprice: number;\n\n\t/**\n\t * Size in terms of the ConditionalToken\n\t */\n\tsize: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Timestamp after which the order is expired.\n\t */\n\texpiration?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n\n// Simplified market order for users\nexport interface UserMarketOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\tpositionID?: never;\n\n\t/**\n\t * Price used to create the order\n\t * If it is not present the market price will be used.\n\t */\n\tprice?: number;\n\n\t/**\n\t * BUY orders: $$$ Amount to buy\n\t * SELL orders: Shares to sell\n\t */\n\tamount: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Specifies the type of order execution:\n\t * - FOK (Fill or Kill): The order must be filled entirely or not at all.\n\t * - FAK (Fill and Kill): The order can be partially filled, and any unfilled portion is canceled.\n\t */\n\torderType?: OrderType.FOK | OrderType.FAK;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n"],"mappings":";;AAIA,SAAgB,cACf,OACA,OACA,WACA,WAAW,OACX,YAAY,OACI;AAChB,QAAO;EACN;EACA;EACA,OAAO;GACN,MAAM,SAAS,MAAM,MAAM,GAAG;GAC9B,OAAO,MAAM;GACb,QAAQ,MAAM;GACd,OAAO,MAAM;GACb,SAAS,MAAM;GACf,aAAa,MAAM;GACnB,aAAa,MAAM;GACnB,MAAM,MAAM;GACZ,YAAY,MAAM;GAClB,OAAO,MAAM;GACb,YAAY,MAAM;GAClB,eAAe,MAAM;GACrB,WAAW,MAAM;GACjB;EACD;EACA;EACA"}
|
|
@@ -35,6 +35,7 @@ interface UserOrderV1 {
|
|
|
35
35
|
* TokenID of the Conditional token asset being traded
|
|
36
36
|
*/
|
|
37
37
|
tokenID: string;
|
|
38
|
+
positionID?: never;
|
|
38
39
|
/**
|
|
39
40
|
* Price used to create the order
|
|
40
41
|
*/
|
|
@@ -73,6 +74,7 @@ interface UserMarketOrderV1 {
|
|
|
73
74
|
* TokenID of the Conditional token asset being traded
|
|
74
75
|
*/
|
|
75
76
|
tokenID: string;
|
|
77
|
+
positionID?: never;
|
|
76
78
|
/**
|
|
77
79
|
* Price used to create the order
|
|
78
80
|
* If it is not present the market price will be used.
|
package/dist/types/ordersV1.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ interface UserOrderV1 {
|
|
|
36
36
|
* TokenID of the Conditional token asset being traded
|
|
37
37
|
*/
|
|
38
38
|
tokenID: string;
|
|
39
|
+
positionID?: never;
|
|
39
40
|
/**
|
|
40
41
|
* Price used to create the order
|
|
41
42
|
*/
|
|
@@ -74,6 +75,7 @@ interface UserMarketOrderV1 {
|
|
|
74
75
|
* TokenID of the Conditional token asset being traded
|
|
75
76
|
*/
|
|
76
77
|
tokenID: string;
|
|
78
|
+
positionID?: never;
|
|
77
79
|
/**
|
|
78
80
|
* Price used to create the order
|
|
79
81
|
* If it is not present the market price will be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordersV1.js","names":[],"sources":["../../src/types/ordersV1.ts"],"sourcesContent":["import type { SignatureTypeV1, SignedOrderV1 } from \"../order-utils/index.js\";\n\nimport type { OrderType, Side } from \"./clob.js\";\n\nexport function orderToJsonV1<T extends OrderType>(\n\torder: SignedOrderV1,\n\towner: string,\n\torderType: T,\n\tpostOnly = false,\n\tdeferExec = false,\n): NewOrderV1<T> {\n\treturn {\n\t\tdeferExec,\n\t\tpostOnly,\n\t\torder: {\n\t\t\tsalt: parseInt(order.salt, 10),\n\t\t\tmaker: order.maker,\n\t\t\tsigner: order.signer,\n\t\t\ttaker: order.taker,\n\t\t\ttokenId: order.tokenId,\n\t\t\tmakerAmount: order.makerAmount,\n\t\t\ttakerAmount: order.takerAmount,\n\t\t\tside: order.side,\n\t\t\texpiration: order.expiration,\n\t\t\tnonce: order.nonce,\n\t\t\tfeeRateBps: order.feeRateBps,\n\t\t\tsignatureType: order.signatureType,\n\t\t\tsignature: order.signature,\n\t\t},\n\t\towner,\n\t\torderType,\n\t} as NewOrderV1<T>;\n}\n\nexport interface PostOrdersV1Args {\n\torder: SignedOrderV1;\n\torderType: OrderType;\n}\n\nexport interface NewOrderV1<T extends OrderType> {\n\treadonly order: {\n\t\treadonly salt: number;\n\t\treadonly maker: string;\n\t\treadonly signer: string;\n\t\treadonly taker: string;\n\t\treadonly tokenId: string;\n\t\treadonly makerAmount: string;\n\t\treadonly takerAmount: string;\n\t\treadonly expiration: string;\n\t\treadonly nonce: string;\n\t\treadonly feeRateBps: string;\n\t\treadonly side: string;\n\t\treadonly signatureType: SignatureTypeV1;\n\t\treadonly signature: string;\n\t};\n\treadonly owner: string;\n\treadonly orderType: T;\n\treadonly deferExec: boolean;\n\treadonly postOnly: boolean;\n}\n\n// Simplified order for users\nexport interface UserOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\n\t/**\n\t * Price used to create the order\n\t */\n\tprice: number;\n\n\t/**\n\t * Size in terms of the ConditionalToken\n\t */\n\tsize: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Timestamp after which the order is expired.\n\t */\n\texpiration?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n\n// Simplified market order for users\nexport interface UserMarketOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\n\t/**\n\t * Price used to create the order\n\t * If it is not present the market price will be used.\n\t */\n\tprice?: number;\n\n\t/**\n\t * BUY orders: $$$ Amount to buy\n\t * SELL orders: Shares to sell\n\t */\n\tamount: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Specifies the type of order execution:\n\t * - FOK (Fill or Kill): The order must be filled entirely or not at all.\n\t * - FAK (Fill and Kill): The order can be partially filled, and any unfilled portion is canceled.\n\t */\n\torderType?: OrderType.FOK | OrderType.FAK;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n"],"mappings":";AAIA,SAAgB,cACf,OACA,OACA,WACA,WAAW,OACX,YAAY,OACI;AAChB,QAAO;EACN;EACA;EACA,OAAO;GACN,MAAM,SAAS,MAAM,MAAM,GAAG;GAC9B,OAAO,MAAM;GACb,QAAQ,MAAM;GACd,OAAO,MAAM;GACb,SAAS,MAAM;GACf,aAAa,MAAM;GACnB,aAAa,MAAM;GACnB,MAAM,MAAM;GACZ,YAAY,MAAM;GAClB,OAAO,MAAM;GACb,YAAY,MAAM;GAClB,eAAe,MAAM;GACrB,WAAW,MAAM;GACjB;EACD;EACA;EACA"}
|
|
1
|
+
{"version":3,"file":"ordersV1.js","names":[],"sources":["../../src/types/ordersV1.ts"],"sourcesContent":["import type { SignatureTypeV1, SignedOrderV1 } from \"../order-utils/index.js\";\n\nimport type { OrderType, Side } from \"./clob.js\";\n\nexport function orderToJsonV1<T extends OrderType>(\n\torder: SignedOrderV1,\n\towner: string,\n\torderType: T,\n\tpostOnly = false,\n\tdeferExec = false,\n): NewOrderV1<T> {\n\treturn {\n\t\tdeferExec,\n\t\tpostOnly,\n\t\torder: {\n\t\t\tsalt: parseInt(order.salt, 10),\n\t\t\tmaker: order.maker,\n\t\t\tsigner: order.signer,\n\t\t\ttaker: order.taker,\n\t\t\ttokenId: order.tokenId,\n\t\t\tmakerAmount: order.makerAmount,\n\t\t\ttakerAmount: order.takerAmount,\n\t\t\tside: order.side,\n\t\t\texpiration: order.expiration,\n\t\t\tnonce: order.nonce,\n\t\t\tfeeRateBps: order.feeRateBps,\n\t\t\tsignatureType: order.signatureType,\n\t\t\tsignature: order.signature,\n\t\t},\n\t\towner,\n\t\torderType,\n\t} as NewOrderV1<T>;\n}\n\nexport interface PostOrdersV1Args {\n\torder: SignedOrderV1;\n\torderType: OrderType;\n}\n\nexport interface NewOrderV1<T extends OrderType> {\n\treadonly order: {\n\t\treadonly salt: number;\n\t\treadonly maker: string;\n\t\treadonly signer: string;\n\t\treadonly taker: string;\n\t\treadonly tokenId: string;\n\t\treadonly makerAmount: string;\n\t\treadonly takerAmount: string;\n\t\treadonly expiration: string;\n\t\treadonly nonce: string;\n\t\treadonly feeRateBps: string;\n\t\treadonly side: string;\n\t\treadonly signatureType: SignatureTypeV1;\n\t\treadonly signature: string;\n\t};\n\treadonly owner: string;\n\treadonly orderType: T;\n\treadonly deferExec: boolean;\n\treadonly postOnly: boolean;\n}\n\n// Simplified order for users\nexport interface UserOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\tpositionID?: never;\n\n\t/**\n\t * Price used to create the order\n\t */\n\tprice: number;\n\n\t/**\n\t * Size in terms of the ConditionalToken\n\t */\n\tsize: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Timestamp after which the order is expired.\n\t */\n\texpiration?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n\n// Simplified market order for users\nexport interface UserMarketOrderV1 {\n\t/**\n\t * TokenID of the Conditional token asset being traded\n\t */\n\ttokenID: string;\n\tpositionID?: never;\n\n\t/**\n\t * Price used to create the order\n\t * If it is not present the market price will be used.\n\t */\n\tprice?: number;\n\n\t/**\n\t * BUY orders: $$$ Amount to buy\n\t * SELL orders: Shares to sell\n\t */\n\tamount: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Fee rate, in basis points, charged to the order maker, charged on proceeds\n\t */\n\tfeeRateBps?: number;\n\n\t/**\n\t * Nonce used for onchain cancellations\n\t */\n\tnonce?: number;\n\n\t/**\n\t * Address of the order taker. The zero address is used to indicate a public order\n\t */\n\ttaker?: string;\n\n\t/**\n\t * Specifies the type of order execution:\n\t * - FOK (Fill or Kill): The order must be filled entirely or not at all.\n\t * - FAK (Fill and Kill): The order can be partially filled, and any unfilled portion is canceled.\n\t */\n\torderType?: OrderType.FOK | OrderType.FAK;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n}\n"],"mappings":";AAIA,SAAgB,cACf,OACA,OACA,WACA,WAAW,OACX,YAAY,OACI;AAChB,QAAO;EACN;EACA;EACA,OAAO;GACN,MAAM,SAAS,MAAM,MAAM,GAAG;GAC9B,OAAO,MAAM;GACb,QAAQ,MAAM;GACd,OAAO,MAAM;GACb,SAAS,MAAM;GACf,aAAa,MAAM;GACnB,aAAa,MAAM;GACnB,MAAM,MAAM;GACZ,YAAY,MAAM;GAClB,OAAO,MAAM;GACb,YAAY,MAAM;GAClB,eAAe,MAAM;GACrB,WAAW,MAAM;GACjB;EACD;EACA;EACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordersV2.cjs","names":[],"sources":["../../src/types/ordersV2.ts"],"sourcesContent":["import type { SignatureTypeV2, SignedOrderV2 } from \"../order-utils/index.js\";\n\nimport type { OrderType, Side } from \"./clob.js\";\n\nexport function orderToJsonV2<T extends OrderType>(\n\torder: SignedOrderV2,\n\towner: string,\n\torderType: T,\n\tpostOnly = false,\n\tdeferExec = false,\n): NewOrderV2<T> {\n\treturn {\n\t\tdeferExec,\n\t\tpostOnly,\n\t\torder: {\n\t\t\tsalt: parseInt(order.salt, 10),\n\t\t\tmaker: order.maker,\n\t\t\tsigner: order.signer,\n\t\t\ttaker: order.taker,\n\t\t\ttokenId: order.tokenId,\n\t\t\tmakerAmount: order.makerAmount,\n\t\t\ttakerAmount: order.takerAmount,\n\t\t\tside: order.side,\n\t\t\tsignatureType: order.signatureType,\n\t\t\ttimestamp: order.timestamp,\n\t\t\texpiration: order.expiration,\n\t\t\tmetadata: order.metadata,\n\t\t\tbuilder: order.builder,\n\t\t\tsignature: order.signature,\n\t\t},\n\t\towner,\n\t\torderType,\n\t} as NewOrderV2<T>;\n}\n\nexport interface PostOrdersV2Args {\n\torder: SignedOrderV2;\n\torderType: OrderType;\n}\n\nexport interface NewOrderV2<T extends OrderType> {\n\treadonly order: {\n\t\treadonly salt: number;\n\t\treadonly maker: string;\n\t\treadonly signer: string;\n\t\treadonly taker: string;\n\t\treadonly tokenId: string;\n\t\treadonly makerAmount: string;\n\t\treadonly takerAmount: string;\n\t\treadonly side: string;\n\t\treadonly signatureType: SignatureTypeV2;\n\t\treadonly timestamp: string;\n\t\treadonly expiration: string;\n\t\treadonly metadata: string;\n\t\treadonly builder: string;\n\t\treadonly signature: string;\n\t};\n\treadonly owner: string;\n\treadonly orderType: T;\n\treadonly deferExec: boolean;\n\treadonly postOnly: boolean;\n}\n\n
|
|
1
|
+
{"version":3,"file":"ordersV2.cjs","names":[],"sources":["../../src/types/ordersV2.ts"],"sourcesContent":["import type { SignatureTypeV2, SignedOrderV2 } from \"../order-utils/index.js\";\n\nimport type { OrderType, Side } from \"./clob.js\";\n\nexport function orderToJsonV2<T extends OrderType>(\n\torder: SignedOrderV2,\n\towner: string,\n\torderType: T,\n\tpostOnly = false,\n\tdeferExec = false,\n): NewOrderV2<T> {\n\treturn {\n\t\tdeferExec,\n\t\tpostOnly,\n\t\torder: {\n\t\t\tsalt: parseInt(order.salt, 10),\n\t\t\tmaker: order.maker,\n\t\t\tsigner: order.signer,\n\t\t\ttaker: order.taker,\n\t\t\ttokenId: order.tokenId,\n\t\t\tmakerAmount: order.makerAmount,\n\t\t\ttakerAmount: order.takerAmount,\n\t\t\tside: order.side,\n\t\t\tsignatureType: order.signatureType,\n\t\t\ttimestamp: order.timestamp,\n\t\t\texpiration: order.expiration,\n\t\t\tmetadata: order.metadata,\n\t\t\tbuilder: order.builder,\n\t\t\tsignature: order.signature,\n\t\t},\n\t\towner,\n\t\torderType,\n\t} as NewOrderV2<T>;\n}\n\nexport interface PostOrdersV2Args {\n\torder: SignedOrderV2;\n\torderType: OrderType;\n}\n\nexport interface NewOrderV2<T extends OrderType> {\n\treadonly order: {\n\t\treadonly salt: number;\n\t\treadonly maker: string;\n\t\treadonly signer: string;\n\t\treadonly taker: string;\n\t\treadonly tokenId: string;\n\t\treadonly makerAmount: string;\n\t\treadonly takerAmount: string;\n\t\treadonly side: string;\n\t\treadonly signatureType: SignatureTypeV2;\n\t\treadonly timestamp: string;\n\t\treadonly expiration: string;\n\t\treadonly metadata: string;\n\t\treadonly builder: string;\n\t\treadonly signature: string;\n\t};\n\treadonly owner: string;\n\treadonly orderType: T;\n\treadonly deferExec: boolean;\n\treadonly postOnly: boolean;\n}\n\n/** Identifies the outcome to trade. Provide exactly one identifier. */\nexport type OrderAsset =\n\t| {\n\t\t\t/** Token identifier for a CTF outcome. */\n\t\t\ttokenID: string;\n\t\t\tpositionID?: never;\n\t }\n\t| {\n\t\t\t/** Position identifier for a Polymarket V2 outcome. */\n\t\t\tpositionID: string;\n\t\t\ttokenID?: never;\n\t };\n\n// Simplified order for users\ntype BaseUserOrderV2 = {\n\t/**\n\t * Price used to create the order\n\t */\n\tprice: number;\n\n\t/**\n\t * Size in outcome shares.\n\t */\n\tsize: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Metadata (bytes32)\n\t */\n\tmetadata?: string;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n\n\t/**\n\t * Expiration timestamp (unix seconds). Defaults to 0 (no expiration).\n\t */\n\texpiration?: number;\n\n\t/**\n\t * User's USDC balance. If provided and sufficient to cover amount + fees, the order\n\t * size is used as-is. Otherwise fees are deducted from the order notional and size is reduced.\n\t * If this field is left empty, the default flow is to use the order size as-is.\n\t * This is used for marketable limit orders\n\t */\n\tuserUSDCBalance?: number;\n};\n\nexport type UserOrderV2 = OrderAsset & BaseUserOrderV2;\n\n// Simplified market order for users\ntype BaseUserMarketOrderV2 = {\n\t/**\n\t * Price used to create the order\n\t * If it is not present the market price will be used.\n\t */\n\tprice?: number;\n\n\t/**\n\t * BUY orders: $$$ Amount to buy\n\t * SELL orders: Shares to sell\n\t */\n\tamount: number;\n\n\t/**\n\t * Side of the order\n\t */\n\tside: Side;\n\n\t/**\n\t * Specifies the type of order execution:\n\t * - FOK (Fill or Kill): The order must be filled entirely or not at all.\n\t * - FAK (Fill and Kill): The order can be partially filled, and any unfilled portion is canceled.\n\t */\n\torderType?: OrderType.FOK | OrderType.FAK;\n\n\t/**\n\t * User's USDC balance. If provided and sufficient to cover amount + fees, the order\n\t * amount is used as-is. Otherwise fees are deducted from the amount.\n\t * If this field is left empty, the default flow is to use the order amount as-is\n\t */\n\tuserUSDCBalance?: number;\n\n\t/**\n\t * Metadata (bytes32)\n\t */\n\tmetadata?: string;\n\n\t/**\n\t * Builder code (bytes32)\n\t */\n\tbuilderCode?: string;\n};\n\nexport type UserMarketOrderV2 = OrderAsset & BaseUserMarketOrderV2;\n"],"mappings":";;AAIA,SAAgB,cACf,OACA,OACA,WACA,WAAW,OACX,YAAY,OACI;AAChB,QAAO;EACN;EACA;EACA,OAAO;GACN,MAAM,SAAS,MAAM,MAAM,GAAG;GAC9B,OAAO,MAAM;GACb,QAAQ,MAAM;GACd,OAAO,MAAM;GACb,SAAS,MAAM;GACf,aAAa,MAAM;GACnB,aAAa,MAAM;GACnB,MAAM,MAAM;GACZ,eAAe,MAAM;GACrB,WAAW,MAAM;GACjB,YAAY,MAAM;GAClB,UAAU,MAAM;GAChB,SAAS,MAAM;GACf,WAAW,MAAM;GACjB;EACD;EACA;EACA"}
|
|
@@ -31,17 +31,23 @@ interface NewOrderV2<T extends OrderType> {
|
|
|
31
31
|
readonly deferExec: boolean;
|
|
32
32
|
readonly postOnly: boolean;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/
|
|
34
|
+
/** Identifies the outcome to trade. Provide exactly one identifier. */
|
|
35
|
+
type OrderAsset = {
|
|
36
|
+
/** Token identifier for a CTF outcome. */
|
|
38
37
|
tokenID: string;
|
|
38
|
+
positionID?: never;
|
|
39
|
+
} | {
|
|
40
|
+
/** Position identifier for a Polymarket V2 outcome. */
|
|
41
|
+
positionID: string;
|
|
42
|
+
tokenID?: never;
|
|
43
|
+
};
|
|
44
|
+
type BaseUserOrderV2 = {
|
|
39
45
|
/**
|
|
40
46
|
* Price used to create the order
|
|
41
47
|
*/
|
|
42
48
|
price: number;
|
|
43
49
|
/**
|
|
44
|
-
* Size in
|
|
50
|
+
* Size in outcome shares.
|
|
45
51
|
*/
|
|
46
52
|
size: number;
|
|
47
53
|
/**
|
|
@@ -67,12 +73,9 @@ interface UserOrderV2 {
|
|
|
67
73
|
* This is used for marketable limit orders
|
|
68
74
|
*/
|
|
69
75
|
userUSDCBalance?: number;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* TokenID of the Conditional token asset being traded
|
|
74
|
-
*/
|
|
75
|
-
tokenID: string;
|
|
76
|
+
};
|
|
77
|
+
type UserOrderV2 = OrderAsset & BaseUserOrderV2;
|
|
78
|
+
type BaseUserMarketOrderV2 = {
|
|
76
79
|
/**
|
|
77
80
|
* Price used to create the order
|
|
78
81
|
* If it is not present the market price will be used.
|
|
@@ -107,7 +110,8 @@ interface UserMarketOrderV2 {
|
|
|
107
110
|
* Builder code (bytes32)
|
|
108
111
|
*/
|
|
109
112
|
builderCode?: string;
|
|
110
|
-
}
|
|
113
|
+
};
|
|
114
|
+
type UserMarketOrderV2 = OrderAsset & BaseUserMarketOrderV2;
|
|
111
115
|
//#endregion
|
|
112
|
-
export { NewOrderV2, PostOrdersV2Args, UserMarketOrderV2, UserOrderV2, orderToJsonV2 };
|
|
116
|
+
export { NewOrderV2, OrderAsset, PostOrdersV2Args, UserMarketOrderV2, UserOrderV2, orderToJsonV2 };
|
|
113
117
|
//# sourceMappingURL=ordersV2.d.cts.map
|