@polymarket/clob-client 5.1.0 → 5.1.2
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/dist/client.d.ts +141 -0
- package/dist/client.js +853 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +28 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/endpoints.d.ts +65 -0
- package/dist/endpoints.js +79 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +5 -0
- package/dist/errors.js.map +1 -0
- package/dist/headers/index.d.ts +7 -0
- package/dist/headers/index.js +41 -0
- package/dist/headers/index.js.map +1 -0
- package/dist/http-helpers/index.d.ts +21 -0
- package/dist/http-helpers/index.js +149 -0
- package/dist/http-helpers/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/order-builder/builder.d.ts +30 -0
- package/dist/order-builder/builder.js +52 -0
- package/dist/order-builder/builder.js.map +1 -0
- package/dist/order-builder/helpers.d.ts +51 -0
- package/dist/order-builder/helpers.js +279 -0
- package/dist/order-builder/helpers.js.map +1 -0
- package/dist/order-builder/index.d.ts +1 -0
- package/dist/order-builder/index.js +2 -0
- package/dist/order-builder/index.js.map +1 -0
- package/dist/rfq-client.d.ts +58 -0
- package/dist/rfq-client.js +358 -0
- package/dist/rfq-client.js.map +1 -0
- package/dist/rfq-deps.d.ts +44 -0
- package/dist/rfq-deps.js +2 -0
- package/dist/rfq-deps.js.map +1 -0
- package/dist/signing/constants.d.ts +14 -0
- package/dist/signing/constants.js +16 -0
- package/dist/signing/constants.js.map +1 -0
- package/dist/signing/eip712.d.ts +10 -0
- package/dist/signing/eip712.js +34 -0
- package/dist/signing/eip712.js.map +1 -0
- package/dist/signing/hmac.d.ts +9 -0
- package/dist/signing/hmac.js +58 -0
- package/dist/signing/hmac.js.map +1 -0
- package/dist/signing/index.d.ts +2 -0
- package/dist/signing/index.js +3 -0
- package/dist/signing/index.js.map +1 -0
- package/dist/types.d.ts +590 -0
- package/dist/types.js +37 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +16 -0
- package/dist/utilities.js +89 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { SignatureType } from "@polymarket/order-utils";
|
|
2
|
+
import { createMarketOrder, createOrder } from "./helpers.js";
|
|
3
|
+
export class OrderBuilder {
|
|
4
|
+
signer;
|
|
5
|
+
chainId;
|
|
6
|
+
// Signature type used sign orders, defaults to EOA type
|
|
7
|
+
signatureType;
|
|
8
|
+
// Address which holds funds to be used.
|
|
9
|
+
// Used for Polymarket proxy wallets and other smart contract wallets
|
|
10
|
+
// If not provided, funderAddress is the signer address
|
|
11
|
+
funderAddress;
|
|
12
|
+
/**
|
|
13
|
+
* Optional function to dynamically resolve the signer.
|
|
14
|
+
* If provided, this function will be called to obtain a fresh signer instance
|
|
15
|
+
* (e.g., for smart contract wallets or when the signer may change).
|
|
16
|
+
* Should return a Wallet or JsonRpcSigner, or a Promise resolving to one.
|
|
17
|
+
* If not provided, the static `signer` property is used.
|
|
18
|
+
*/
|
|
19
|
+
getSigner;
|
|
20
|
+
constructor(signer, chainId, signatureType, funderAddress, getSigner) {
|
|
21
|
+
this.signer = signer;
|
|
22
|
+
this.chainId = chainId;
|
|
23
|
+
this.signatureType = signatureType === undefined ? SignatureType.EOA : signatureType;
|
|
24
|
+
this.funderAddress = funderAddress;
|
|
25
|
+
this.getSigner = getSigner;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generate and sign a order
|
|
29
|
+
*/
|
|
30
|
+
async buildOrder(userOrder, options) {
|
|
31
|
+
const signer = await this.resolveSigner();
|
|
32
|
+
return createOrder(signer, this.chainId, this.signatureType, this.funderAddress, userOrder, options);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generate and sign a market order
|
|
36
|
+
*/
|
|
37
|
+
async buildMarketOrder(userMarketOrder, options) {
|
|
38
|
+
const signer = await this.resolveSigner();
|
|
39
|
+
return createMarketOrder(signer, this.chainId, this.signatureType, this.funderAddress, userMarketOrder, options);
|
|
40
|
+
}
|
|
41
|
+
/** Unified getter: use fresh signer if available */
|
|
42
|
+
async resolveSigner() {
|
|
43
|
+
if (this.getSigner) {
|
|
44
|
+
const s = await this.getSigner();
|
|
45
|
+
if (!s)
|
|
46
|
+
throw new Error("getSigner() function returned undefined or null");
|
|
47
|
+
return s;
|
|
48
|
+
}
|
|
49
|
+
return this.signer;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/order-builder/builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG9D,MAAM,OAAO,YAAY;IACZ,MAAM,CAAyB;IAE/B,OAAO,CAAQ;IAExB,wDAAwD;IAC/C,aAAa,CAAgB;IAEtC,wCAAwC;IACxC,qEAAqE;IACrE,uDAAuD;IAC9C,aAAa,CAAU;IAEhC;;;;;;OAMG;IACK,SAAS,CAAoE;IAErF,YACI,MAA8B,EAC9B,OAAc,EACd,aAA6B,EAC7B,aAAsB,EACtB,SAA4E;QAE5E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC;QACrF,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU,CACnB,SAAoB,EACpB,OAA2B;QAE3B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1C,OAAO,WAAW,CACd,MAAM,EACN,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,aAAa,EAClB,SAAS,EACT,OAAO,CACV,CAAC;IACN,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,gBAAgB,CACzB,eAAgC,EAChC,OAA2B;QAE3B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1C,OAAO,iBAAiB,CACpB,MAAM,EACN,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,aAAa,EAClB,eAAe,EACf,OAAO,CACV,CAAC;IACN,CAAC;IAED,oDAAoD;IAC5C,KAAK,CAAC,aAAa;QACvB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;YAC3E,OAAO,CAAC,CAAC;QACb,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CACJ"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { JsonRpcSigner } from "@ethersproject/providers";
|
|
2
|
+
import type { Wallet } from "@ethersproject/wallet";
|
|
3
|
+
import { SignatureType, Side as UtilsSide } from "@polymarket/order-utils";
|
|
4
|
+
import type { OrderData, SignedOrder } from "@polymarket/order-utils";
|
|
5
|
+
import { Side, OrderType } from "../types.ts";
|
|
6
|
+
import type { UserOrder, Chain, UserMarketOrder, TickSize, RoundConfig, CreateOrderOptions, OrderSummary } from "../types.ts";
|
|
7
|
+
export declare const ROUNDING_CONFIG: Record<TickSize, RoundConfig>;
|
|
8
|
+
/**
|
|
9
|
+
* Generate and sign a order
|
|
10
|
+
*
|
|
11
|
+
* @param signer
|
|
12
|
+
* @param exchangeAddress ctf exchange contract address
|
|
13
|
+
* @param chainId
|
|
14
|
+
* @param OrderData
|
|
15
|
+
* @returns SignedOrder
|
|
16
|
+
*/
|
|
17
|
+
export declare const buildOrder: (signer: Wallet | JsonRpcSigner, exchangeAddress: string, chainId: number, orderData: OrderData) => Promise<SignedOrder>;
|
|
18
|
+
export declare const getOrderRawAmounts: (side: Side, size: number, price: number, roundConfig: RoundConfig) => {
|
|
19
|
+
side: UtilsSide;
|
|
20
|
+
rawMakerAmt: number;
|
|
21
|
+
rawTakerAmt: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Translate simple user order to args used to generate Orders
|
|
25
|
+
*/
|
|
26
|
+
export declare const buildOrderCreationArgs: (signer: string, maker: string, signatureType: SignatureType, userOrder: UserOrder, roundConfig: RoundConfig) => Promise<OrderData>;
|
|
27
|
+
export declare const createOrder: (eoaSigner: Wallet | JsonRpcSigner, chainId: Chain, signatureType: SignatureType, funderAddress: string | undefined, userOrder: UserOrder, options: CreateOrderOptions) => Promise<SignedOrder>;
|
|
28
|
+
export declare const getMarketOrderRawAmounts: (side: Side, amount: number, price: number, roundConfig: RoundConfig) => {
|
|
29
|
+
side: UtilsSide;
|
|
30
|
+
rawMakerAmt: number;
|
|
31
|
+
rawTakerAmt: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Translate simple user market order to args used to generate Orders
|
|
35
|
+
*/
|
|
36
|
+
export declare const buildMarketOrderCreationArgs: (signer: string, maker: string, signatureType: SignatureType, userMarketOrder: UserMarketOrder, roundConfig: RoundConfig) => Promise<OrderData>;
|
|
37
|
+
export declare const createMarketOrder: (eoaSigner: Wallet | JsonRpcSigner, chainId: Chain, signatureType: SignatureType, funderAddress: string | undefined, userMarketOrder: UserMarketOrder, options: CreateOrderOptions) => Promise<SignedOrder>;
|
|
38
|
+
/**
|
|
39
|
+
* calculateBuyMarketPrice calculates the market price to buy a $$ amount
|
|
40
|
+
* @param positions
|
|
41
|
+
* @param amountToMatch worth to buy
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
export declare const calculateBuyMarketPrice: (positions: OrderSummary[], amountToMatch: number, orderType: OrderType) => number;
|
|
45
|
+
/**
|
|
46
|
+
* calculateSellMarketPrice calculates the market price to sell a shares
|
|
47
|
+
* @param positions
|
|
48
|
+
* @param amountToMatch sells to share
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
export declare const calculateSellMarketPrice: (positions: OrderSummary[], amountToMatch: number, orderType: OrderType) => number;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { parseUnits } from "@ethersproject/units";
|
|
2
|
+
import { ExchangeOrderBuilder, SignatureType, Side as UtilsSide, } from "@polymarket/order-utils";
|
|
3
|
+
import { Side, OrderType } from "../types.js";
|
|
4
|
+
import { decimalPlaces, roundDown, roundNormal, roundUp } from "../utilities.js";
|
|
5
|
+
import { COLLATERAL_TOKEN_DECIMALS, getContractConfig } from "../config.js";
|
|
6
|
+
export const ROUNDING_CONFIG = {
|
|
7
|
+
"0.1": {
|
|
8
|
+
price: 1,
|
|
9
|
+
size: 2,
|
|
10
|
+
amount: 3,
|
|
11
|
+
},
|
|
12
|
+
"0.01": {
|
|
13
|
+
price: 2,
|
|
14
|
+
size: 2,
|
|
15
|
+
amount: 4,
|
|
16
|
+
},
|
|
17
|
+
"0.001": {
|
|
18
|
+
price: 3,
|
|
19
|
+
size: 2,
|
|
20
|
+
amount: 5,
|
|
21
|
+
},
|
|
22
|
+
"0.0001": {
|
|
23
|
+
price: 4,
|
|
24
|
+
size: 2,
|
|
25
|
+
amount: 6,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Generate and sign a order
|
|
30
|
+
*
|
|
31
|
+
* @param signer
|
|
32
|
+
* @param exchangeAddress ctf exchange contract address
|
|
33
|
+
* @param chainId
|
|
34
|
+
* @param OrderData
|
|
35
|
+
* @returns SignedOrder
|
|
36
|
+
*/
|
|
37
|
+
export const buildOrder = async (signer, exchangeAddress, chainId, orderData) => {
|
|
38
|
+
const cTFExchangeOrderBuilder = new ExchangeOrderBuilder(exchangeAddress, chainId, signer);
|
|
39
|
+
return cTFExchangeOrderBuilder.buildSignedOrder(orderData);
|
|
40
|
+
};
|
|
41
|
+
export const getOrderRawAmounts = (side, size, price, roundConfig) => {
|
|
42
|
+
const rawPrice = roundNormal(price, roundConfig.price);
|
|
43
|
+
if (side === Side.BUY) {
|
|
44
|
+
// force 2 decimals places
|
|
45
|
+
const rawTakerAmt = roundDown(size, roundConfig.size);
|
|
46
|
+
let rawMakerAmt = rawTakerAmt * rawPrice;
|
|
47
|
+
if (decimalPlaces(rawMakerAmt) > roundConfig.amount) {
|
|
48
|
+
rawMakerAmt = roundUp(rawMakerAmt, roundConfig.amount + 4);
|
|
49
|
+
if (decimalPlaces(rawMakerAmt) > roundConfig.amount) {
|
|
50
|
+
rawMakerAmt = roundDown(rawMakerAmt, roundConfig.amount);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
side: UtilsSide.BUY,
|
|
55
|
+
rawMakerAmt,
|
|
56
|
+
rawTakerAmt,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const rawMakerAmt = roundDown(size, roundConfig.size);
|
|
61
|
+
let rawTakerAmt = rawMakerAmt * rawPrice;
|
|
62
|
+
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
|
63
|
+
rawTakerAmt = roundUp(rawTakerAmt, roundConfig.amount + 4);
|
|
64
|
+
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
|
65
|
+
rawTakerAmt = roundDown(rawTakerAmt, roundConfig.amount);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
side: UtilsSide.SELL,
|
|
70
|
+
rawMakerAmt,
|
|
71
|
+
rawTakerAmt,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Translate simple user order to args used to generate Orders
|
|
77
|
+
*/
|
|
78
|
+
export const buildOrderCreationArgs = async (signer, maker, signatureType, userOrder, roundConfig) => {
|
|
79
|
+
const { side, rawMakerAmt, rawTakerAmt } = getOrderRawAmounts(userOrder.side, userOrder.size, userOrder.price, roundConfig);
|
|
80
|
+
const makerAmount = parseUnits(rawMakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
|
|
81
|
+
const takerAmount = parseUnits(rawTakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
|
|
82
|
+
let taker;
|
|
83
|
+
if (typeof userOrder.taker !== "undefined" && userOrder.taker) {
|
|
84
|
+
taker = userOrder.taker;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
taker = "0x0000000000000000000000000000000000000000";
|
|
88
|
+
}
|
|
89
|
+
let feeRateBps;
|
|
90
|
+
if (typeof userOrder.feeRateBps !== "undefined" && userOrder.feeRateBps) {
|
|
91
|
+
feeRateBps = userOrder.feeRateBps.toString();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
feeRateBps = "0";
|
|
95
|
+
}
|
|
96
|
+
let nonce;
|
|
97
|
+
if (typeof userOrder.nonce !== "undefined" && userOrder.nonce) {
|
|
98
|
+
nonce = userOrder.nonce.toString();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
nonce = "0";
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
maker,
|
|
105
|
+
taker,
|
|
106
|
+
tokenId: userOrder.tokenID,
|
|
107
|
+
makerAmount,
|
|
108
|
+
takerAmount,
|
|
109
|
+
side,
|
|
110
|
+
feeRateBps,
|
|
111
|
+
nonce,
|
|
112
|
+
signer,
|
|
113
|
+
expiration: (userOrder.expiration || 0).toString(),
|
|
114
|
+
signatureType,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
export const createOrder = async (eoaSigner, chainId, signatureType, funderAddress, userOrder, options) => {
|
|
118
|
+
const eoaSignerAddress = await eoaSigner.getAddress();
|
|
119
|
+
// If funder address is not given, use the signer address
|
|
120
|
+
const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;
|
|
121
|
+
const contractConfig = getContractConfig(chainId);
|
|
122
|
+
const orderData = await buildOrderCreationArgs(eoaSignerAddress, maker, signatureType, userOrder, ROUNDING_CONFIG[options.tickSize]);
|
|
123
|
+
const exchangeContract = options.negRisk
|
|
124
|
+
? contractConfig.negRiskExchange
|
|
125
|
+
: contractConfig.exchange;
|
|
126
|
+
return buildOrder(eoaSigner, exchangeContract, chainId, orderData);
|
|
127
|
+
};
|
|
128
|
+
export const getMarketOrderRawAmounts = (side, amount, price, roundConfig) => {
|
|
129
|
+
// force 2 decimals places
|
|
130
|
+
const rawPrice = roundDown(price, roundConfig.price);
|
|
131
|
+
if (side === Side.BUY) {
|
|
132
|
+
const rawMakerAmt = roundDown(amount, roundConfig.size);
|
|
133
|
+
let rawTakerAmt = rawMakerAmt / rawPrice;
|
|
134
|
+
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
|
135
|
+
rawTakerAmt = roundUp(rawTakerAmt, roundConfig.amount + 4);
|
|
136
|
+
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
|
137
|
+
rawTakerAmt = roundDown(rawTakerAmt, roundConfig.amount);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
side: UtilsSide.BUY,
|
|
142
|
+
rawMakerAmt,
|
|
143
|
+
rawTakerAmt,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
const rawMakerAmt = roundDown(amount, roundConfig.size);
|
|
148
|
+
let rawTakerAmt = rawMakerAmt * rawPrice;
|
|
149
|
+
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
|
150
|
+
rawTakerAmt = roundUp(rawTakerAmt, roundConfig.amount + 4);
|
|
151
|
+
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
|
152
|
+
rawTakerAmt = roundDown(rawTakerAmt, roundConfig.amount);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
side: UtilsSide.SELL,
|
|
157
|
+
rawMakerAmt,
|
|
158
|
+
rawTakerAmt,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Translate simple user market order to args used to generate Orders
|
|
164
|
+
*/
|
|
165
|
+
export const buildMarketOrderCreationArgs = async (signer, maker, signatureType, userMarketOrder, roundConfig) => {
|
|
166
|
+
const { side, rawMakerAmt, rawTakerAmt } = getMarketOrderRawAmounts(userMarketOrder.side, userMarketOrder.amount, userMarketOrder.price || 1, roundConfig);
|
|
167
|
+
const makerAmount = parseUnits(rawMakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
|
|
168
|
+
const takerAmount = parseUnits(rawTakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
|
|
169
|
+
let taker;
|
|
170
|
+
if (typeof userMarketOrder.taker !== "undefined" && userMarketOrder.taker) {
|
|
171
|
+
taker = userMarketOrder.taker;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
taker = "0x0000000000000000000000000000000000000000";
|
|
175
|
+
}
|
|
176
|
+
let feeRateBps;
|
|
177
|
+
if (typeof userMarketOrder.feeRateBps !== "undefined" && userMarketOrder.feeRateBps) {
|
|
178
|
+
feeRateBps = userMarketOrder.feeRateBps.toString();
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
feeRateBps = "0";
|
|
182
|
+
}
|
|
183
|
+
let nonce;
|
|
184
|
+
if (typeof userMarketOrder.nonce !== "undefined" && userMarketOrder.nonce) {
|
|
185
|
+
nonce = userMarketOrder.nonce.toString();
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
nonce = "0";
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
maker,
|
|
192
|
+
taker,
|
|
193
|
+
tokenId: userMarketOrder.tokenID,
|
|
194
|
+
makerAmount,
|
|
195
|
+
takerAmount,
|
|
196
|
+
side,
|
|
197
|
+
feeRateBps,
|
|
198
|
+
nonce,
|
|
199
|
+
signer,
|
|
200
|
+
expiration: "0",
|
|
201
|
+
signatureType,
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
export const createMarketOrder = async (eoaSigner, chainId, signatureType, funderAddress, userMarketOrder, options) => {
|
|
205
|
+
const eoaSignerAddress = await eoaSigner.getAddress();
|
|
206
|
+
// If funder address is not given, use the signer address
|
|
207
|
+
const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;
|
|
208
|
+
const contractConfig = getContractConfig(chainId);
|
|
209
|
+
const orderData = await buildMarketOrderCreationArgs(eoaSignerAddress, maker, signatureType, userMarketOrder, ROUNDING_CONFIG[options.tickSize]);
|
|
210
|
+
const exchangeContract = options.negRisk
|
|
211
|
+
? contractConfig.negRiskExchange
|
|
212
|
+
: contractConfig.exchange;
|
|
213
|
+
return buildOrder(eoaSigner, exchangeContract, chainId, orderData);
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* calculateBuyMarketPrice calculates the market price to buy a $$ amount
|
|
217
|
+
* @param positions
|
|
218
|
+
* @param amountToMatch worth to buy
|
|
219
|
+
* @returns
|
|
220
|
+
*/
|
|
221
|
+
export const calculateBuyMarketPrice = (positions, amountToMatch, orderType) => {
|
|
222
|
+
if (!positions.length) {
|
|
223
|
+
throw new Error("no match");
|
|
224
|
+
}
|
|
225
|
+
let sum = 0;
|
|
226
|
+
/*
|
|
227
|
+
Asks:
|
|
228
|
+
[
|
|
229
|
+
{ price: '0.6', size: '100' },
|
|
230
|
+
{ price: '0.55', size: '100' },
|
|
231
|
+
{ price: '0.5', size: '100' }
|
|
232
|
+
]
|
|
233
|
+
So, if the amount to match is $150 that will be reached at first position so price will be 0.6
|
|
234
|
+
*/
|
|
235
|
+
for (let i = positions.length - 1; i >= 0; i--) {
|
|
236
|
+
const p = positions[i];
|
|
237
|
+
sum += parseFloat(p.size) * parseFloat(p.price);
|
|
238
|
+
if (sum >= amountToMatch) {
|
|
239
|
+
return parseFloat(p.price);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (orderType === OrderType.FOK) {
|
|
243
|
+
throw new Error("no match");
|
|
244
|
+
}
|
|
245
|
+
return parseFloat(positions[0].price);
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* calculateSellMarketPrice calculates the market price to sell a shares
|
|
249
|
+
* @param positions
|
|
250
|
+
* @param amountToMatch sells to share
|
|
251
|
+
* @returns
|
|
252
|
+
*/
|
|
253
|
+
export const calculateSellMarketPrice = (positions, amountToMatch, orderType) => {
|
|
254
|
+
if (!positions.length) {
|
|
255
|
+
throw new Error("no match");
|
|
256
|
+
}
|
|
257
|
+
let sum = 0;
|
|
258
|
+
/*
|
|
259
|
+
Bids:
|
|
260
|
+
[
|
|
261
|
+
{ price: '0.4', size: '100' },
|
|
262
|
+
{ price: '0.45', size: '100' },
|
|
263
|
+
{ price: '0.5', size: '100' }
|
|
264
|
+
]
|
|
265
|
+
So, if the amount to match is 300 that will be reached at the first position so price will be 0.4
|
|
266
|
+
*/
|
|
267
|
+
for (let i = positions.length - 1; i >= 0; i--) {
|
|
268
|
+
const p = positions[i];
|
|
269
|
+
sum += parseFloat(p.size);
|
|
270
|
+
if (sum >= amountToMatch) {
|
|
271
|
+
return parseFloat(p.price);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (orderType === OrderType.FOK) {
|
|
275
|
+
throw new Error("no match");
|
|
276
|
+
}
|
|
277
|
+
return parseFloat(positions[0].price);
|
|
278
|
+
};
|
|
279
|
+
//# sourceMappingURL=helpers.js.map
|
|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AC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./builder.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/order-builder/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CreateOrderOptions, RfqUserOrder, RfqUserQuote, CancelRfqQuoteParams, GetRfqQuotesParams, GetRfqBestQuoteParams, CancelRfqRequestParams, AcceptQuoteParams, ApproveOrderParams, GetRfqRequestsParams, RfqRequestsResponse, RfqQuotesResponse, RfqRequestResponse, RfqQuoteResponse, RfqQuote } from "./types.ts";
|
|
2
|
+
import type { IRfqClient, RfqDeps } from "./rfq-deps.ts";
|
|
3
|
+
/**
|
|
4
|
+
* RfqClient provides RFQ (Request for Quote) functionality on top of a CLOB client.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RfqClient implements IRfqClient {
|
|
7
|
+
private readonly deps;
|
|
8
|
+
constructor(deps: RfqDeps);
|
|
9
|
+
/**
|
|
10
|
+
* Creates and posts an RFQ request from user order parameters.
|
|
11
|
+
* Converts the order into the proper RFQ request format with asset amounts and submits it.
|
|
12
|
+
*/
|
|
13
|
+
createRfqRequest(userOrder: RfqUserOrder, options?: Partial<CreateOrderOptions>): Promise<RfqRequestResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Cancels an existing RFQ request
|
|
16
|
+
*/
|
|
17
|
+
cancelRfqRequest(request: CancelRfqRequestParams): Promise<"OK">;
|
|
18
|
+
/**
|
|
19
|
+
* Gets RFQ requests with optional filtering parameters
|
|
20
|
+
*/
|
|
21
|
+
getRfqRequests(params?: GetRfqRequestsParams): Promise<RfqRequestsResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a quote in response to an RFQ request.
|
|
24
|
+
* Converts user-friendly parameters into the proper RFQ quote format with asset amounts and submits it.
|
|
25
|
+
*/
|
|
26
|
+
createRfqQuote(userQuote: RfqUserQuote, options?: Partial<CreateOrderOptions>): Promise<RfqQuoteResponse>;
|
|
27
|
+
/**
|
|
28
|
+
* Gets RFQ quotes with optional filtering parameters
|
|
29
|
+
*/
|
|
30
|
+
getRfqQuotes(params?: GetRfqQuotesParams): Promise<RfqQuotesResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the best quote for a given request ID
|
|
33
|
+
*/
|
|
34
|
+
getRfqBestQuote(params?: GetRfqBestQuoteParams): Promise<RfqQuote>;
|
|
35
|
+
/**
|
|
36
|
+
* Cancels an existing quote
|
|
37
|
+
*/
|
|
38
|
+
cancelRfqQuote(quote: CancelRfqQuoteParams): Promise<"OK">;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the RFQ configuration from the server
|
|
41
|
+
*/
|
|
42
|
+
rfqConfig(): Promise<any>;
|
|
43
|
+
/**
|
|
44
|
+
* Accepts a quote and creates an order (taker side)
|
|
45
|
+
* This fetches the request details, creates an order, and submits the acceptance
|
|
46
|
+
*/
|
|
47
|
+
acceptRfqQuote(payload: AcceptQuoteParams): Promise<"OK">;
|
|
48
|
+
/**
|
|
49
|
+
* Approves a quote and creates an order (maker side)
|
|
50
|
+
* This fetches the quote details, creates an order, and submits the approval
|
|
51
|
+
*/
|
|
52
|
+
approveRfqOrder(payload: ApproveOrderParams): Promise<"OK">;
|
|
53
|
+
/**
|
|
54
|
+
* Ensures L2 authentication is available for RFQ endpoints.
|
|
55
|
+
*/
|
|
56
|
+
protected ensureL2Auth(): void;
|
|
57
|
+
private getRequestOrderCreationPayload;
|
|
58
|
+
}
|