@evedex/exchange-crypto 1.0.18 → 1.0.20
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/cjs/index.d.ts +5 -1
- package/dist/cjs/index.js +27 -16
- package/dist/cjs/utils/crypto.d.ts +7 -1
- package/dist/cjs/utils/crypto.js +6 -3
- package/dist/cjs/utils/exchange.d.ts +5 -0
- package/dist/mjs/index.d.ts +5 -1
- package/dist/mjs/index.js +28 -17
- package/dist/mjs/utils/crypto.d.ts +7 -1
- package/dist/mjs/utils/crypto.js +5 -2
- package/dist/mjs/utils/exchange.d.ts +5 -0
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
|
-
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl } from "./utils/exchange";
|
|
3
|
+
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl, type OauthConsent } from "./utils/exchange";
|
|
4
4
|
export * as utils from "./utils";
|
|
5
5
|
export interface AuthMessage {
|
|
6
6
|
nonce: string;
|
|
@@ -73,6 +73,9 @@ export interface NormalizeTradingBalanceWithdraw extends Pick<TradingBalanceWith
|
|
|
73
73
|
export interface SignedTradingBalanceWithdraw extends NormalizeTradingBalanceWithdraw {
|
|
74
74
|
signature: string;
|
|
75
75
|
}
|
|
76
|
+
export interface SignedOauthConsentRequest extends OauthConsent {
|
|
77
|
+
signature: string;
|
|
78
|
+
}
|
|
76
79
|
export declare function signTradingBalanceWithdraw(signer: WalletClient, withdraw: TradingBalanceWithdraw): Promise<SignedTradingBalanceWithdraw>;
|
|
77
80
|
export interface NormalizeTpSl extends Pick<TpSl, "instrument" | "side" | "type" | "order"> {
|
|
78
81
|
quantity: string;
|
|
@@ -82,3 +85,4 @@ export interface SignedTpSl extends NormalizeTpSl {
|
|
|
82
85
|
signature: string;
|
|
83
86
|
}
|
|
84
87
|
export declare function signTpSl(signer: WalletClient, tpsl: TpSl): Promise<SignedTpSl>;
|
|
88
|
+
export declare function signOauthConsentTequest(signer: WalletClient, payload: OauthConsent): Promise<SignedOauthConsentRequest>;
|
package/dist/cjs/index.js
CHANGED
|
@@ -57,6 +57,7 @@ exports.signReplaceLimitOrder = signReplaceLimitOrder;
|
|
|
57
57
|
exports.signReplaceStopLimitOrder = signReplaceStopLimitOrder;
|
|
58
58
|
exports.signTradingBalanceWithdraw = signTradingBalanceWithdraw;
|
|
59
59
|
exports.signTpSl = signTpSl;
|
|
60
|
+
exports.signOauthConsentTequest = signOauthConsentTequest;
|
|
60
61
|
const big_js_1 = __importDefault(require("big.js"));
|
|
61
62
|
const siwe_1 = require("siwe");
|
|
62
63
|
const crypto_1 = require("./utils/crypto");
|
|
@@ -106,7 +107,7 @@ function signAuth(signer, payload) {
|
|
|
106
107
|
function signLimitOrder(signer, order) {
|
|
107
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
109
|
const chainId = yield signer.getChainId();
|
|
109
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.
|
|
110
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createLimitOrder);
|
|
110
111
|
const normalize = {
|
|
111
112
|
id: order.id,
|
|
112
113
|
instrument: order.instrument,
|
|
@@ -117,14 +118,14 @@ function signLimitOrder(signer, order) {
|
|
|
117
118
|
tpsl: order.tpsl,
|
|
118
119
|
chainId,
|
|
119
120
|
};
|
|
120
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.
|
|
121
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.EIP712Schemas.createLimitOrder, Object.assign(Object.assign({}, normalize), { quantity: (0, crypto_1.toEthNumber)(normalize.quantity), limitPrice: (0, crypto_1.toEthNumber)(normalize.limitPrice) }));
|
|
121
122
|
return Object.assign(Object.assign(Object.assign({}, normalize), (order.postOnly && { postOnly: "yes" })), { signature: signer.serializeSignature(signature) });
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
125
|
function signMarketOrder(signer, order) {
|
|
125
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
127
|
const chainId = yield signer.getChainId();
|
|
127
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.
|
|
128
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createMarketOrder);
|
|
128
129
|
const normalize = {
|
|
129
130
|
id: order.id,
|
|
130
131
|
instrument: order.instrument,
|
|
@@ -135,14 +136,14 @@ function signMarketOrder(signer, order) {
|
|
|
135
136
|
tpsl: order.tpsl,
|
|
136
137
|
chainId,
|
|
137
138
|
};
|
|
138
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.
|
|
139
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.EIP712Schemas.createMarketOrder, Object.assign(Object.assign({}, normalize), { cashQuantity: (0, crypto_1.toEthNumber)(normalize.cashQuantity) }));
|
|
139
140
|
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
140
141
|
});
|
|
141
142
|
}
|
|
142
143
|
function signStopLimitOrder(signer, order) {
|
|
143
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
145
|
const chainId = yield signer.getChainId();
|
|
145
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.
|
|
146
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createStopLimitOrder);
|
|
146
147
|
const normalize = {
|
|
147
148
|
id: order.id,
|
|
148
149
|
instrument: order.instrument,
|
|
@@ -154,14 +155,14 @@ function signStopLimitOrder(signer, order) {
|
|
|
154
155
|
tpsl: order.tpsl,
|
|
155
156
|
chainId,
|
|
156
157
|
};
|
|
157
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.
|
|
158
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.EIP712Schemas.createStopLimitOrder, Object.assign(Object.assign({}, normalize), { quantity: (0, crypto_1.toEthNumber)(normalize.quantity), limitPrice: (0, crypto_1.toEthNumber)(normalize.limitPrice), stopPrice: (0, crypto_1.toEthNumber)(normalize.stopPrice) }));
|
|
158
159
|
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
159
160
|
});
|
|
160
161
|
}
|
|
161
162
|
function signPositionCloseOrder(signer, order) {
|
|
162
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
163
164
|
const chainId = yield signer.getChainId();
|
|
164
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.
|
|
165
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createPositionCloseOrder);
|
|
165
166
|
const normalize = {
|
|
166
167
|
id: order.id,
|
|
167
168
|
instrument: order.instrument,
|
|
@@ -169,43 +170,43 @@ function signPositionCloseOrder(signer, order) {
|
|
|
169
170
|
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
170
171
|
chainId,
|
|
171
172
|
};
|
|
172
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.
|
|
173
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.EIP712Schemas.createPositionCloseOrder, Object.assign(Object.assign({}, normalize), { quantity: (0, crypto_1.toEthNumber)(normalize.quantity) }));
|
|
173
174
|
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
174
175
|
});
|
|
175
176
|
}
|
|
176
177
|
function signReplaceLimitOrder(signer, order) {
|
|
177
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
(0, validate_1.validatePayload)(order, crypto_1.
|
|
179
|
+
(0, validate_1.validatePayload)(order, crypto_1.EIP712Schemas.replaceLimitOrder);
|
|
179
180
|
const normalize = {
|
|
180
181
|
orderId: order.orderId,
|
|
181
182
|
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
182
183
|
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
183
184
|
};
|
|
184
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.
|
|
185
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.replaceLimitOrder, Object.assign(Object.assign({}, normalize), { quantity: (0, crypto_1.toEthNumber)(normalize.quantity), limitPrice: (0, crypto_1.toEthNumber)(normalize.limitPrice) }));
|
|
185
186
|
return Object.assign(Object.assign(Object.assign({}, normalize), (order.postOnly && { postOnly: "yes" })), { signature: signer.serializeSignature(signature) });
|
|
186
187
|
});
|
|
187
188
|
}
|
|
188
189
|
function signReplaceStopLimitOrder(signer, order) {
|
|
189
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
(0, validate_1.validatePayload)(order, crypto_1.
|
|
191
|
+
(0, validate_1.validatePayload)(order, crypto_1.EIP712Schemas.replaceStopLimitOrder);
|
|
191
192
|
const normalize = {
|
|
192
193
|
orderId: order.orderId,
|
|
193
194
|
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
194
195
|
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
195
196
|
stopPrice: (0, numeric_1.toMatcherNumber)(order.stopPrice),
|
|
196
197
|
};
|
|
197
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.
|
|
198
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.replaceStopLimitOrder, Object.assign(Object.assign({}, normalize), { quantity: (0, crypto_1.toEthNumber)(normalize.quantity), limitPrice: (0, crypto_1.toEthNumber)(normalize.limitPrice), stopPrice: (0, crypto_1.toEthNumber)(normalize.stopPrice) }));
|
|
198
199
|
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
199
200
|
});
|
|
200
201
|
}
|
|
201
202
|
function signTradingBalanceWithdraw(signer, withdraw) {
|
|
202
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
(0, validate_1.validatePayload)(withdraw, crypto_1.
|
|
204
|
+
(0, validate_1.validatePayload)(withdraw, crypto_1.EIP712Schemas.withdraw);
|
|
204
205
|
const normalize = {
|
|
205
206
|
recipient: withdraw.recipient,
|
|
206
207
|
amount: (0, big_js_1.default)(withdraw.amount).round(utils_1.MATCHER_PRECISION, big_js_1.default.roundDown).toString(),
|
|
207
208
|
};
|
|
208
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.
|
|
209
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.withdraw, {
|
|
209
210
|
recipient: withdraw.recipient,
|
|
210
211
|
amount: (0, crypto_1.toEthNumber)(normalize.amount),
|
|
211
212
|
});
|
|
@@ -214,7 +215,7 @@ function signTradingBalanceWithdraw(signer, withdraw) {
|
|
|
214
215
|
}
|
|
215
216
|
function signTpSl(signer, tpsl) {
|
|
216
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
(0, validate_1.validatePayload)(tpsl, crypto_1.
|
|
218
|
+
(0, validate_1.validatePayload)(tpsl, crypto_1.EIP712Schemas.createTpSl);
|
|
218
219
|
const normalize = {
|
|
219
220
|
instrument: tpsl.instrument,
|
|
220
221
|
type: tpsl.type,
|
|
@@ -223,7 +224,17 @@ function signTpSl(signer, tpsl) {
|
|
|
223
224
|
price: (0, numeric_1.toMatcherNumber)(tpsl.price),
|
|
224
225
|
order: tpsl.order,
|
|
225
226
|
};
|
|
226
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.
|
|
227
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.createTpSl, Object.assign(Object.assign({}, normalize), { quantity: (0, crypto_1.toEthNumber)(normalize.quantity), price: (0, crypto_1.toEthNumber)(normalize.price) }));
|
|
227
228
|
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
228
229
|
});
|
|
229
230
|
}
|
|
231
|
+
function signOauthConsentTequest(signer, payload) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
const { oauthRequestId } = payload;
|
|
234
|
+
(0, validate_1.validatePayload)({ oauthRequestId }, crypto_1.EIP712Schemas.oauthConsent);
|
|
235
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.oauthConsent, {
|
|
236
|
+
oauthRequestId,
|
|
237
|
+
});
|
|
238
|
+
return Object.assign(Object.assign({}, payload), { signature });
|
|
239
|
+
});
|
|
240
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const EIP712Schemas: {
|
|
3
3
|
domain: {
|
|
4
4
|
name: string;
|
|
5
5
|
version: string;
|
|
@@ -53,6 +53,12 @@ export declare const EIP721Schemas: {
|
|
|
53
53
|
type: string;
|
|
54
54
|
}[];
|
|
55
55
|
};
|
|
56
|
+
oauthConsent: {
|
|
57
|
+
"Oauth consent": {
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
56
62
|
};
|
|
57
63
|
export declare function getDomainData(chainId: string): {
|
|
58
64
|
chainId: string;
|
package/dist/cjs/utils/crypto.js
CHANGED
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.EIP712Schemas = void 0;
|
|
7
7
|
exports.getDomainData = getDomainData;
|
|
8
8
|
exports.toEthNumber = toEthNumber;
|
|
9
9
|
const big_js_1 = __importDefault(require("big.js"));
|
|
10
10
|
const constants_1 = require("./constants");
|
|
11
|
-
exports.
|
|
11
|
+
exports.EIP712Schemas = {
|
|
12
12
|
domain: {
|
|
13
13
|
name: "EVEDEX",
|
|
14
14
|
version: "2",
|
|
@@ -87,9 +87,12 @@ exports.EIP721Schemas = {
|
|
|
87
87
|
{ name: "stopPrice", type: "uint80" },
|
|
88
88
|
],
|
|
89
89
|
},
|
|
90
|
+
oauthConsent: {
|
|
91
|
+
"Oauth consent": [{ name: "oauthRequestId", type: "string" }],
|
|
92
|
+
},
|
|
90
93
|
};
|
|
91
94
|
function getDomainData(chainId) {
|
|
92
|
-
return Object.assign(Object.assign({}, exports.
|
|
95
|
+
return Object.assign(Object.assign({}, exports.EIP712Schemas.domain), { chainId });
|
|
93
96
|
}
|
|
94
97
|
function toEthNumber(value) {
|
|
95
98
|
return (0, big_js_1.default)(value).mul(`1e${constants_1.MATCHER_PRECISION}`).toFixed(0);
|
|
@@ -58,3 +58,8 @@ export interface ReplaceLimitOrder extends ReplaceBaseOrder {
|
|
|
58
58
|
export interface ReplaceStopLimitOrder extends ReplaceLimitOrder {
|
|
59
59
|
stopPrice: Big.BigSource;
|
|
60
60
|
}
|
|
61
|
+
export interface OauthConsent {
|
|
62
|
+
oauthRequestId: string;
|
|
63
|
+
apiKeyEnabled: boolean;
|
|
64
|
+
octWalletPrivateKey?: string;
|
|
65
|
+
}
|
package/dist/mjs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
|
-
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl } from "./utils/exchange";
|
|
3
|
+
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl, type OauthConsent } from "./utils/exchange";
|
|
4
4
|
export * as utils from "./utils";
|
|
5
5
|
export interface AuthMessage {
|
|
6
6
|
nonce: string;
|
|
@@ -73,6 +73,9 @@ export interface NormalizeTradingBalanceWithdraw extends Pick<TradingBalanceWith
|
|
|
73
73
|
export interface SignedTradingBalanceWithdraw extends NormalizeTradingBalanceWithdraw {
|
|
74
74
|
signature: string;
|
|
75
75
|
}
|
|
76
|
+
export interface SignedOauthConsentRequest extends OauthConsent {
|
|
77
|
+
signature: string;
|
|
78
|
+
}
|
|
76
79
|
export declare function signTradingBalanceWithdraw(signer: WalletClient, withdraw: TradingBalanceWithdraw): Promise<SignedTradingBalanceWithdraw>;
|
|
77
80
|
export interface NormalizeTpSl extends Pick<TpSl, "instrument" | "side" | "type" | "order"> {
|
|
78
81
|
quantity: string;
|
|
@@ -82,3 +85,4 @@ export interface SignedTpSl extends NormalizeTpSl {
|
|
|
82
85
|
signature: string;
|
|
83
86
|
}
|
|
84
87
|
export declare function signTpSl(signer: WalletClient, tpsl: TpSl): Promise<SignedTpSl>;
|
|
88
|
+
export declare function signOauthConsentTequest(signer: WalletClient, payload: OauthConsent): Promise<SignedOauthConsentRequest>;
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { SiweMessage } from "siwe";
|
|
3
|
-
import {
|
|
3
|
+
import { EIP712Schemas, getDomainData, toEthNumber, } from "./utils/crypto";
|
|
4
4
|
import { toMatcherNumber } from "./utils/numeric";
|
|
5
5
|
import { validatePayload } from "./utils/validate";
|
|
6
6
|
import { MATCHER_PRECISION } from "./utils";
|
|
@@ -42,7 +42,7 @@ export async function signAuth(signer, payload) {
|
|
|
42
42
|
}
|
|
43
43
|
export async function signLimitOrder(signer, order) {
|
|
44
44
|
const chainId = await signer.getChainId();
|
|
45
|
-
validatePayload({ ...order, chainId },
|
|
45
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createLimitOrder);
|
|
46
46
|
const normalize = {
|
|
47
47
|
id: order.id,
|
|
48
48
|
instrument: order.instrument,
|
|
@@ -53,7 +53,7 @@ export async function signLimitOrder(signer, order) {
|
|
|
53
53
|
tpsl: order.tpsl,
|
|
54
54
|
chainId,
|
|
55
55
|
};
|
|
56
|
-
const signature = await signer.signTypedData(getDomainData(chainId),
|
|
56
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createLimitOrder, {
|
|
57
57
|
...normalize,
|
|
58
58
|
quantity: toEthNumber(normalize.quantity),
|
|
59
59
|
limitPrice: toEthNumber(normalize.limitPrice),
|
|
@@ -66,7 +66,7 @@ export async function signLimitOrder(signer, order) {
|
|
|
66
66
|
}
|
|
67
67
|
export async function signMarketOrder(signer, order) {
|
|
68
68
|
const chainId = await signer.getChainId();
|
|
69
|
-
validatePayload({ ...order, chainId },
|
|
69
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createMarketOrder);
|
|
70
70
|
const normalize = {
|
|
71
71
|
id: order.id,
|
|
72
72
|
instrument: order.instrument,
|
|
@@ -77,7 +77,7 @@ export async function signMarketOrder(signer, order) {
|
|
|
77
77
|
tpsl: order.tpsl,
|
|
78
78
|
chainId,
|
|
79
79
|
};
|
|
80
|
-
const signature = await signer.signTypedData(getDomainData(chainId),
|
|
80
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createMarketOrder, {
|
|
81
81
|
...normalize,
|
|
82
82
|
cashQuantity: toEthNumber(normalize.cashQuantity),
|
|
83
83
|
});
|
|
@@ -88,7 +88,7 @@ export async function signMarketOrder(signer, order) {
|
|
|
88
88
|
}
|
|
89
89
|
export async function signStopLimitOrder(signer, order) {
|
|
90
90
|
const chainId = await signer.getChainId();
|
|
91
|
-
validatePayload({ ...order, chainId },
|
|
91
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createStopLimitOrder);
|
|
92
92
|
const normalize = {
|
|
93
93
|
id: order.id,
|
|
94
94
|
instrument: order.instrument,
|
|
@@ -100,7 +100,7 @@ export async function signStopLimitOrder(signer, order) {
|
|
|
100
100
|
tpsl: order.tpsl,
|
|
101
101
|
chainId,
|
|
102
102
|
};
|
|
103
|
-
const signature = await signer.signTypedData(getDomainData(chainId),
|
|
103
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createStopLimitOrder, {
|
|
104
104
|
...normalize,
|
|
105
105
|
quantity: toEthNumber(normalize.quantity),
|
|
106
106
|
limitPrice: toEthNumber(normalize.limitPrice),
|
|
@@ -113,7 +113,7 @@ export async function signStopLimitOrder(signer, order) {
|
|
|
113
113
|
}
|
|
114
114
|
export async function signPositionCloseOrder(signer, order) {
|
|
115
115
|
const chainId = await signer.getChainId();
|
|
116
|
-
validatePayload({ ...order, chainId },
|
|
116
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createPositionCloseOrder);
|
|
117
117
|
const normalize = {
|
|
118
118
|
id: order.id,
|
|
119
119
|
instrument: order.instrument,
|
|
@@ -121,7 +121,7 @@ export async function signPositionCloseOrder(signer, order) {
|
|
|
121
121
|
quantity: toMatcherNumber(order.quantity),
|
|
122
122
|
chainId,
|
|
123
123
|
};
|
|
124
|
-
const signature = await signer.signTypedData(getDomainData(chainId),
|
|
124
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createPositionCloseOrder, {
|
|
125
125
|
...normalize,
|
|
126
126
|
quantity: toEthNumber(normalize.quantity),
|
|
127
127
|
});
|
|
@@ -131,13 +131,13 @@ export async function signPositionCloseOrder(signer, order) {
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
export async function signReplaceLimitOrder(signer, order) {
|
|
134
|
-
validatePayload(order,
|
|
134
|
+
validatePayload(order, EIP712Schemas.replaceLimitOrder);
|
|
135
135
|
const normalize = {
|
|
136
136
|
orderId: order.orderId,
|
|
137
137
|
quantity: toMatcherNumber(order.quantity),
|
|
138
138
|
limitPrice: toMatcherNumber(order.limitPrice),
|
|
139
139
|
};
|
|
140
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()),
|
|
140
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.replaceLimitOrder, {
|
|
141
141
|
...normalize,
|
|
142
142
|
quantity: toEthNumber(normalize.quantity),
|
|
143
143
|
limitPrice: toEthNumber(normalize.limitPrice),
|
|
@@ -149,14 +149,14 @@ export async function signReplaceLimitOrder(signer, order) {
|
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
export async function signReplaceStopLimitOrder(signer, order) {
|
|
152
|
-
validatePayload(order,
|
|
152
|
+
validatePayload(order, EIP712Schemas.replaceStopLimitOrder);
|
|
153
153
|
const normalize = {
|
|
154
154
|
orderId: order.orderId,
|
|
155
155
|
quantity: toMatcherNumber(order.quantity),
|
|
156
156
|
limitPrice: toMatcherNumber(order.limitPrice),
|
|
157
157
|
stopPrice: toMatcherNumber(order.stopPrice),
|
|
158
158
|
};
|
|
159
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()),
|
|
159
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.replaceStopLimitOrder, {
|
|
160
160
|
...normalize,
|
|
161
161
|
quantity: toEthNumber(normalize.quantity),
|
|
162
162
|
limitPrice: toEthNumber(normalize.limitPrice),
|
|
@@ -168,12 +168,12 @@ export async function signReplaceStopLimitOrder(signer, order) {
|
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
export async function signTradingBalanceWithdraw(signer, withdraw) {
|
|
171
|
-
validatePayload(withdraw,
|
|
171
|
+
validatePayload(withdraw, EIP712Schemas.withdraw);
|
|
172
172
|
const normalize = {
|
|
173
173
|
recipient: withdraw.recipient,
|
|
174
174
|
amount: Big(withdraw.amount).round(MATCHER_PRECISION, Big.roundDown).toString(),
|
|
175
175
|
};
|
|
176
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()),
|
|
176
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.withdraw, {
|
|
177
177
|
recipient: withdraw.recipient,
|
|
178
178
|
amount: toEthNumber(normalize.amount),
|
|
179
179
|
});
|
|
@@ -183,7 +183,7 @@ export async function signTradingBalanceWithdraw(signer, withdraw) {
|
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
185
|
export async function signTpSl(signer, tpsl) {
|
|
186
|
-
validatePayload(tpsl,
|
|
186
|
+
validatePayload(tpsl, EIP712Schemas.createTpSl);
|
|
187
187
|
const normalize = {
|
|
188
188
|
instrument: tpsl.instrument,
|
|
189
189
|
type: tpsl.type,
|
|
@@ -192,7 +192,7 @@ export async function signTpSl(signer, tpsl) {
|
|
|
192
192
|
price: toMatcherNumber(tpsl.price),
|
|
193
193
|
order: tpsl.order,
|
|
194
194
|
};
|
|
195
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()),
|
|
195
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.createTpSl, {
|
|
196
196
|
...normalize,
|
|
197
197
|
quantity: toEthNumber(normalize.quantity),
|
|
198
198
|
price: toEthNumber(normalize.price),
|
|
@@ -202,3 +202,14 @@ export async function signTpSl(signer, tpsl) {
|
|
|
202
202
|
signature: signer.serializeSignature(signature),
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
+
export async function signOauthConsentTequest(signer, payload) {
|
|
206
|
+
const { oauthRequestId } = payload;
|
|
207
|
+
validatePayload({ oauthRequestId }, EIP712Schemas.oauthConsent);
|
|
208
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.oauthConsent, {
|
|
209
|
+
oauthRequestId,
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
...payload,
|
|
213
|
+
signature,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const EIP712Schemas: {
|
|
3
3
|
domain: {
|
|
4
4
|
name: string;
|
|
5
5
|
version: string;
|
|
@@ -53,6 +53,12 @@ export declare const EIP721Schemas: {
|
|
|
53
53
|
type: string;
|
|
54
54
|
}[];
|
|
55
55
|
};
|
|
56
|
+
oauthConsent: {
|
|
57
|
+
"Oauth consent": {
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
56
62
|
};
|
|
57
63
|
export declare function getDomainData(chainId: string): {
|
|
58
64
|
chainId: string;
|
package/dist/mjs/utils/crypto.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { MATCHER_PRECISION } from "./constants";
|
|
3
|
-
export const
|
|
3
|
+
export const EIP712Schemas = {
|
|
4
4
|
domain: {
|
|
5
5
|
name: "EVEDEX",
|
|
6
6
|
version: "2",
|
|
@@ -79,10 +79,13 @@ export const EIP721Schemas = {
|
|
|
79
79
|
{ name: "stopPrice", type: "uint80" },
|
|
80
80
|
],
|
|
81
81
|
},
|
|
82
|
+
oauthConsent: {
|
|
83
|
+
"Oauth consent": [{ name: "oauthRequestId", type: "string" }],
|
|
84
|
+
},
|
|
82
85
|
};
|
|
83
86
|
export function getDomainData(chainId) {
|
|
84
87
|
return {
|
|
85
|
-
...
|
|
88
|
+
...EIP712Schemas.domain,
|
|
86
89
|
chainId,
|
|
87
90
|
};
|
|
88
91
|
}
|
|
@@ -58,3 +58,8 @@ export interface ReplaceLimitOrder extends ReplaceBaseOrder {
|
|
|
58
58
|
export interface ReplaceStopLimitOrder extends ReplaceLimitOrder {
|
|
59
59
|
stopPrice: Big.BigSource;
|
|
60
60
|
}
|
|
61
|
+
export interface OauthConsent {
|
|
62
|
+
oauthRequestId: string;
|
|
63
|
+
apiKeyEnabled: boolean;
|
|
64
|
+
octWalletPrivateKey?: string;
|
|
65
|
+
}
|