@evedex/exchange-crypto 1.0.25 → 1.1.0-beta.1
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/auth.d.ts +18 -0
- package/dist/cjs/auth.js +54 -0
- package/dist/cjs/index.d.ts +4 -88
- package/dist/cjs/index.js +15 -204
- package/dist/cjs/orders.d.ts +71 -0
- package/dist/cjs/orders.js +162 -0
- package/dist/mjs/auth.d.ts +18 -0
- package/dist/mjs/auth.js +36 -0
- package/dist/mjs/index.d.ts +4 -88
- package/dist/mjs/index.js +2 -215
- package/dist/mjs/orders.d.ts +71 -0
- package/dist/mjs/orders.js +179 -0
- package/package.json +10 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SignedPayload, WalletClient } from "./utils/crypto";
|
|
2
|
+
export interface AuthMessage {
|
|
3
|
+
nonce: string;
|
|
4
|
+
address: string;
|
|
5
|
+
chainId: string;
|
|
6
|
+
expirationTime?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AuthPayload {
|
|
9
|
+
message: string;
|
|
10
|
+
}
|
|
11
|
+
export interface NormalizeAuthPayload extends AuthPayload {
|
|
12
|
+
address: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SignedAuth extends NormalizeAuthPayload, SignedPayload {
|
|
15
|
+
}
|
|
16
|
+
export declare function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }: AuthMessage): AuthPayload;
|
|
17
|
+
export declare function signAuthMessage(signer: WalletClient, messagePayload: AuthMessage): Promise<SignedAuth>;
|
|
18
|
+
export declare function signAuth(signer: WalletClient, payload: AuthPayload): Promise<SignedAuth>;
|
package/dist/cjs/auth.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getAuthSiweMessagePayload = getAuthSiweMessagePayload;
|
|
13
|
+
exports.signAuthMessage = signAuthMessage;
|
|
14
|
+
exports.signAuth = signAuth;
|
|
15
|
+
const siwe_1 = require("siwe");
|
|
16
|
+
function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }) {
|
|
17
|
+
return {
|
|
18
|
+
message: new siwe_1.SiweMessage({
|
|
19
|
+
scheme: "https",
|
|
20
|
+
domain: "evedex.com",
|
|
21
|
+
uri: "https://evedex.com",
|
|
22
|
+
address,
|
|
23
|
+
statement: "Sign in to evedex.com",
|
|
24
|
+
nonce,
|
|
25
|
+
expirationTime,
|
|
26
|
+
chainId: Number(chainId),
|
|
27
|
+
version: "1",
|
|
28
|
+
}).prepareMessage(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function signAuthMessage(signer, messagePayload) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const address = yield signer.getAddress();
|
|
34
|
+
const { message } = getAuthSiweMessagePayload(messagePayload);
|
|
35
|
+
const signature = yield signer.signMessage(message);
|
|
36
|
+
return {
|
|
37
|
+
address,
|
|
38
|
+
message,
|
|
39
|
+
signature,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// @deprecated use signAuthMessage instead
|
|
44
|
+
function signAuth(signer, payload) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const address = yield signer.getAddress();
|
|
47
|
+
const signature = yield signer.signMessage(payload.message);
|
|
48
|
+
return {
|
|
49
|
+
address,
|
|
50
|
+
message: payload.message,
|
|
51
|
+
signature,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,89 +1,5 @@
|
|
|
1
|
-
import Big from "big.js";
|
|
2
|
-
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
|
-
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl, type OauthConsent, type TimeInForce } from "./utils/exchange";
|
|
4
1
|
export * as utils from "./utils";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expirationTime?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface AuthPayload {
|
|
12
|
-
message: string;
|
|
13
|
-
}
|
|
14
|
-
export interface NormalizeAuthPayload extends AuthPayload {
|
|
15
|
-
address: string;
|
|
16
|
-
}
|
|
17
|
-
export interface SignedAuth extends NormalizeAuthPayload, SignedPayload {
|
|
18
|
-
}
|
|
19
|
-
export declare function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }: AuthMessage): AuthPayload;
|
|
20
|
-
export declare function signAuthMessage(signer: WalletClient, messagePayload: AuthMessage): Promise<SignedAuth>;
|
|
21
|
-
export declare function signAuth(signer: WalletClient, payload: AuthPayload): Promise<SignedAuth>;
|
|
22
|
-
export interface NormalizeLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
23
|
-
quantity: string;
|
|
24
|
-
limitPrice: string;
|
|
25
|
-
postOnly?: "yes";
|
|
26
|
-
timeInForce?: TimeInForce;
|
|
27
|
-
}
|
|
28
|
-
export interface SignedLimitOrder extends NormalizeLimitOrder, SignedPayload {
|
|
29
|
-
quantity: string;
|
|
30
|
-
limitPrice: string;
|
|
31
|
-
}
|
|
32
|
-
export declare function signLimitOrder(signer: WalletClient, order: LimitOrder): Promise<SignedLimitOrder>;
|
|
33
|
-
export interface NormalizeMarketOrder extends CreateBaseOrder, Pick<MarketOrder, "timeInForce">, NetworkChain {
|
|
34
|
-
cashQuantity: string;
|
|
35
|
-
}
|
|
36
|
-
export interface SignedMarketOrder extends NormalizeMarketOrder, SignedPayload {
|
|
37
|
-
}
|
|
38
|
-
export declare function signMarketOrder(signer: WalletClient, order: MarketOrder): Promise<SignedMarketOrder>;
|
|
39
|
-
export interface NormalizeStopLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
40
|
-
quantity: string;
|
|
41
|
-
limitPrice: string;
|
|
42
|
-
stopPrice: string;
|
|
43
|
-
}
|
|
44
|
-
export interface SignedStopLimitOrder extends NormalizeStopLimitOrder, SignedPayload {
|
|
45
|
-
}
|
|
46
|
-
export declare function signStopLimitOrder(signer: WalletClient, order: StopLimitOrder): Promise<SignedStopLimitOrder>;
|
|
47
|
-
export interface NormalizePositionCloseOrder extends Pick<PositionCloseOrder, "instrument" | "leverage" | "id">, NetworkChain {
|
|
48
|
-
quantity: string;
|
|
49
|
-
}
|
|
50
|
-
export interface SignedPositionCloseOrder extends NormalizePositionCloseOrder, SignedPayload {
|
|
51
|
-
}
|
|
52
|
-
export declare function signPositionCloseOrder(signer: WalletClient, order: PositionCloseOrder): Promise<SignedPositionCloseOrder>;
|
|
53
|
-
export interface NormalizeReplaceLimitOrder extends ReplaceBaseOrder {
|
|
54
|
-
quantity: string;
|
|
55
|
-
limitPrice: string;
|
|
56
|
-
postOnly?: "yes";
|
|
57
|
-
}
|
|
58
|
-
export interface SignedReplaceLimitOrder extends NormalizeReplaceLimitOrder, SignedPayload {
|
|
59
|
-
}
|
|
60
|
-
export declare function signReplaceLimitOrder(signer: WalletClient, order: ReplaceLimitOrder): Promise<SignedReplaceLimitOrder>;
|
|
61
|
-
export interface NormalizeReplaceStopLimitOrder extends NormalizeReplaceLimitOrder {
|
|
62
|
-
stopPrice: string;
|
|
63
|
-
}
|
|
64
|
-
export interface SignedReplaceStopLimitOrder extends NormalizeReplaceStopLimitOrder, SignedPayload {
|
|
65
|
-
}
|
|
66
|
-
export declare function signReplaceStopLimitOrder(signer: WalletClient, order: ReplaceStopLimitOrder): Promise<SignedReplaceStopLimitOrder>;
|
|
67
|
-
export interface TradingBalanceWithdraw {
|
|
68
|
-
recipient: string;
|
|
69
|
-
amount: Big.BigSource;
|
|
70
|
-
}
|
|
71
|
-
export interface NormalizeTradingBalanceWithdraw extends Pick<TradingBalanceWithdraw, "recipient"> {
|
|
72
|
-
amount: string;
|
|
73
|
-
}
|
|
74
|
-
export interface SignedTradingBalanceWithdraw extends NormalizeTradingBalanceWithdraw {
|
|
75
|
-
signature: string;
|
|
76
|
-
}
|
|
77
|
-
export interface SignedOauthConsentRequest extends OauthConsent {
|
|
78
|
-
signature: string;
|
|
79
|
-
}
|
|
80
|
-
export declare function signTradingBalanceWithdraw(signer: WalletClient, withdraw: TradingBalanceWithdraw): Promise<SignedTradingBalanceWithdraw>;
|
|
81
|
-
export interface NormalizeTpSl extends Pick<TpSl, "instrument" | "side" | "type" | "order"> {
|
|
82
|
-
quantity: string;
|
|
83
|
-
price: string;
|
|
84
|
-
}
|
|
85
|
-
export interface SignedTpSl extends NormalizeTpSl {
|
|
86
|
-
signature: string;
|
|
87
|
-
}
|
|
88
|
-
export declare function signTpSl(signer: WalletClient, tpsl: TpSl): Promise<SignedTpSl>;
|
|
89
|
-
export declare function signOauthConsentTequest(signer: WalletClient, payload: OauthConsent): Promise<SignedOauthConsentRequest>;
|
|
2
|
+
export type { AuthMessage, AuthPayload, NormalizeAuthPayload, SignedAuth, } from "./auth";
|
|
3
|
+
export { getAuthSiweMessagePayload, signAuthMessage, signAuth } from "./auth";
|
|
4
|
+
export type { NormalizeLimitOrder, SignedLimitOrder, NormalizeMarketOrder, SignedMarketOrder, NormalizeStopLimitOrder, SignedStopLimitOrder, NormalizePositionCloseOrder, SignedPositionCloseOrder, NormalizeReplaceLimitOrder, SignedReplaceLimitOrder, NormalizeReplaceStopLimitOrder, SignedReplaceStopLimitOrder, TradingBalanceWithdraw, NormalizeTradingBalanceWithdraw, SignedTradingBalanceWithdraw, SignedOauthConsentRequest, NormalizeTpSl, SignedTpSl, } from "./orders";
|
|
5
|
+
export { signLimitOrder, signMarketOrder, signStopLimitOrder, signPositionCloseOrder, signReplaceLimitOrder, signReplaceStopLimitOrder, signTradingBalanceWithdraw, signTpSl, signOauthConsentTequest, } from "./orders";
|
package/dist/cjs/index.js
CHANGED
|
@@ -32,209 +32,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.utils = void 0;
|
|
49
|
-
exports.getAuthSiweMessagePayload = getAuthSiweMessagePayload;
|
|
50
|
-
exports.signAuthMessage = signAuthMessage;
|
|
51
|
-
exports.signAuth = signAuth;
|
|
52
|
-
exports.signLimitOrder = signLimitOrder;
|
|
53
|
-
exports.signMarketOrder = signMarketOrder;
|
|
54
|
-
exports.signStopLimitOrder = signStopLimitOrder;
|
|
55
|
-
exports.signPositionCloseOrder = signPositionCloseOrder;
|
|
56
|
-
exports.signReplaceLimitOrder = signReplaceLimitOrder;
|
|
57
|
-
exports.signReplaceStopLimitOrder = signReplaceStopLimitOrder;
|
|
58
|
-
exports.signTradingBalanceWithdraw = signTradingBalanceWithdraw;
|
|
59
|
-
exports.signTpSl = signTpSl;
|
|
60
|
-
exports.signOauthConsentTequest = signOauthConsentTequest;
|
|
61
|
-
const big_js_1 = __importDefault(require("big.js"));
|
|
62
|
-
const siwe_1 = require("siwe");
|
|
63
|
-
const crypto_1 = require("./utils/crypto");
|
|
64
|
-
const numeric_1 = require("./utils/numeric");
|
|
65
|
-
const validate_1 = require("./utils/validate");
|
|
66
|
-
const utils_1 = require("./utils");
|
|
36
|
+
exports.signOauthConsentTequest = exports.signTpSl = exports.signTradingBalanceWithdraw = exports.signReplaceStopLimitOrder = exports.signReplaceLimitOrder = exports.signPositionCloseOrder = exports.signStopLimitOrder = exports.signMarketOrder = exports.signLimitOrder = exports.signAuth = exports.signAuthMessage = exports.getAuthSiweMessagePayload = exports.utils = void 0;
|
|
67
37
|
exports.utils = __importStar(require("./utils"));
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
function signAuthMessage(signer, messagePayload) {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const address = yield signer.getAddress();
|
|
86
|
-
const { message } = getAuthSiweMessagePayload(messagePayload);
|
|
87
|
-
const signature = yield signer.signMessage(message);
|
|
88
|
-
return {
|
|
89
|
-
address,
|
|
90
|
-
message,
|
|
91
|
-
signature,
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
// @deprecated use signAuthMessage instead
|
|
96
|
-
function signAuth(signer, payload) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const address = yield signer.getAddress();
|
|
99
|
-
const signature = yield signer.signMessage(payload.message);
|
|
100
|
-
return {
|
|
101
|
-
address,
|
|
102
|
-
message: payload.message,
|
|
103
|
-
signature,
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
function signLimitOrder(signer, order) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
const chainId = yield signer.getChainId();
|
|
110
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createLimitOrder);
|
|
111
|
-
const normalize = {
|
|
112
|
-
id: order.id,
|
|
113
|
-
instrument: order.instrument,
|
|
114
|
-
side: order.side,
|
|
115
|
-
leverage: order.leverage,
|
|
116
|
-
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
117
|
-
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
118
|
-
tpsl: order.tpsl,
|
|
119
|
-
chainId,
|
|
120
|
-
};
|
|
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) }));
|
|
122
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, normalize), (order.postOnly && { postOnly: "yes" })), (order.timeInForce ? { timeInForce: order.timeInForce } : {})), { signature: signer.serializeSignature(signature) });
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
function signMarketOrder(signer, order) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const chainId = yield signer.getChainId();
|
|
128
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createMarketOrder);
|
|
129
|
-
const normalize = {
|
|
130
|
-
id: order.id,
|
|
131
|
-
instrument: order.instrument,
|
|
132
|
-
side: order.side,
|
|
133
|
-
timeInForce: order.timeInForce,
|
|
134
|
-
leverage: order.leverage,
|
|
135
|
-
cashQuantity: (0, numeric_1.toMatcherNumber)(order.cashQuantity),
|
|
136
|
-
tpsl: order.tpsl,
|
|
137
|
-
chainId,
|
|
138
|
-
};
|
|
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) }));
|
|
140
|
-
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
function signStopLimitOrder(signer, order) {
|
|
144
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const chainId = yield signer.getChainId();
|
|
146
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createStopLimitOrder);
|
|
147
|
-
const normalize = {
|
|
148
|
-
id: order.id,
|
|
149
|
-
instrument: order.instrument,
|
|
150
|
-
side: order.side,
|
|
151
|
-
leverage: order.leverage,
|
|
152
|
-
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
153
|
-
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
154
|
-
stopPrice: (0, numeric_1.toMatcherNumber)(order.stopPrice),
|
|
155
|
-
tpsl: order.tpsl,
|
|
156
|
-
chainId,
|
|
157
|
-
};
|
|
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) }));
|
|
159
|
-
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
function signPositionCloseOrder(signer, order) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const chainId = yield signer.getChainId();
|
|
165
|
-
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createPositionCloseOrder);
|
|
166
|
-
const normalize = {
|
|
167
|
-
id: order.id,
|
|
168
|
-
instrument: order.instrument,
|
|
169
|
-
leverage: order.leverage,
|
|
170
|
-
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
171
|
-
chainId,
|
|
172
|
-
};
|
|
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) }));
|
|
174
|
-
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
function signReplaceLimitOrder(signer, order) {
|
|
178
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
(0, validate_1.validatePayload)(order, crypto_1.EIP712Schemas.replaceLimitOrder);
|
|
180
|
-
const normalize = {
|
|
181
|
-
orderId: order.orderId,
|
|
182
|
-
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
183
|
-
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
184
|
-
};
|
|
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) }));
|
|
186
|
-
return Object.assign(Object.assign(Object.assign({}, normalize), (order.postOnly && { postOnly: "yes" })), { signature: signer.serializeSignature(signature) });
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
function signReplaceStopLimitOrder(signer, order) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
(0, validate_1.validatePayload)(order, crypto_1.EIP712Schemas.replaceStopLimitOrder);
|
|
192
|
-
const normalize = {
|
|
193
|
-
orderId: order.orderId,
|
|
194
|
-
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
195
|
-
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
196
|
-
stopPrice: (0, numeric_1.toMatcherNumber)(order.stopPrice),
|
|
197
|
-
};
|
|
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) }));
|
|
199
|
-
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function signTradingBalanceWithdraw(signer, withdraw) {
|
|
203
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
(0, validate_1.validatePayload)(withdraw, crypto_1.EIP712Schemas.withdraw);
|
|
205
|
-
const normalize = {
|
|
206
|
-
recipient: withdraw.recipient,
|
|
207
|
-
amount: (0, big_js_1.default)(withdraw.amount).round(utils_1.MATCHER_PRECISION, big_js_1.default.roundDown).toString(),
|
|
208
|
-
};
|
|
209
|
-
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.withdraw, {
|
|
210
|
-
recipient: withdraw.recipient,
|
|
211
|
-
amount: (0, crypto_1.toEthNumber)(normalize.amount),
|
|
212
|
-
});
|
|
213
|
-
return Object.assign(Object.assign({}, normalize), { signature });
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
function signTpSl(signer, tpsl) {
|
|
217
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
(0, validate_1.validatePayload)(tpsl, crypto_1.EIP712Schemas.createTpSl);
|
|
219
|
-
const normalize = {
|
|
220
|
-
instrument: tpsl.instrument,
|
|
221
|
-
type: tpsl.type,
|
|
222
|
-
side: tpsl.side,
|
|
223
|
-
quantity: (0, numeric_1.toMatcherNumber)(tpsl.quantity),
|
|
224
|
-
price: (0, numeric_1.toMatcherNumber)(tpsl.price),
|
|
225
|
-
order: tpsl.order,
|
|
226
|
-
};
|
|
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) }));
|
|
228
|
-
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
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
|
-
}
|
|
38
|
+
var auth_1 = require("./auth");
|
|
39
|
+
Object.defineProperty(exports, "getAuthSiweMessagePayload", { enumerable: true, get: function () { return auth_1.getAuthSiweMessagePayload; } });
|
|
40
|
+
Object.defineProperty(exports, "signAuthMessage", { enumerable: true, get: function () { return auth_1.signAuthMessage; } });
|
|
41
|
+
Object.defineProperty(exports, "signAuth", { enumerable: true, get: function () { return auth_1.signAuth; } });
|
|
42
|
+
var orders_1 = require("./orders");
|
|
43
|
+
Object.defineProperty(exports, "signLimitOrder", { enumerable: true, get: function () { return orders_1.signLimitOrder; } });
|
|
44
|
+
Object.defineProperty(exports, "signMarketOrder", { enumerable: true, get: function () { return orders_1.signMarketOrder; } });
|
|
45
|
+
Object.defineProperty(exports, "signStopLimitOrder", { enumerable: true, get: function () { return orders_1.signStopLimitOrder; } });
|
|
46
|
+
Object.defineProperty(exports, "signPositionCloseOrder", { enumerable: true, get: function () { return orders_1.signPositionCloseOrder; } });
|
|
47
|
+
Object.defineProperty(exports, "signReplaceLimitOrder", { enumerable: true, get: function () { return orders_1.signReplaceLimitOrder; } });
|
|
48
|
+
Object.defineProperty(exports, "signReplaceStopLimitOrder", { enumerable: true, get: function () { return orders_1.signReplaceStopLimitOrder; } });
|
|
49
|
+
Object.defineProperty(exports, "signTradingBalanceWithdraw", { enumerable: true, get: function () { return orders_1.signTradingBalanceWithdraw; } });
|
|
50
|
+
Object.defineProperty(exports, "signTpSl", { enumerable: true, get: function () { return orders_1.signTpSl; } });
|
|
51
|
+
Object.defineProperty(exports, "signOauthConsentTequest", { enumerable: true, get: function () { return orders_1.signOauthConsentTequest; } });
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Big from "big.js";
|
|
2
|
+
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
|
+
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl, type OauthConsent, type TimeInForce } from "./utils/exchange";
|
|
4
|
+
export interface NormalizeLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
5
|
+
quantity: string;
|
|
6
|
+
limitPrice: string;
|
|
7
|
+
postOnly?: "yes";
|
|
8
|
+
timeInForce?: TimeInForce;
|
|
9
|
+
}
|
|
10
|
+
export interface SignedLimitOrder extends NormalizeLimitOrder, SignedPayload {
|
|
11
|
+
quantity: string;
|
|
12
|
+
limitPrice: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function signLimitOrder(signer: WalletClient, order: LimitOrder): Promise<SignedLimitOrder>;
|
|
15
|
+
export interface NormalizeMarketOrder extends CreateBaseOrder, Pick<MarketOrder, "timeInForce">, NetworkChain {
|
|
16
|
+
cashQuantity: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SignedMarketOrder extends NormalizeMarketOrder, SignedPayload {
|
|
19
|
+
}
|
|
20
|
+
export declare function signMarketOrder(signer: WalletClient, order: MarketOrder): Promise<SignedMarketOrder>;
|
|
21
|
+
export interface NormalizeStopLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
22
|
+
quantity: string;
|
|
23
|
+
limitPrice: string;
|
|
24
|
+
stopPrice: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SignedStopLimitOrder extends NormalizeStopLimitOrder, SignedPayload {
|
|
27
|
+
}
|
|
28
|
+
export declare function signStopLimitOrder(signer: WalletClient, order: StopLimitOrder): Promise<SignedStopLimitOrder>;
|
|
29
|
+
export interface NormalizePositionCloseOrder extends Pick<PositionCloseOrder, "instrument" | "leverage" | "id">, NetworkChain {
|
|
30
|
+
quantity: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SignedPositionCloseOrder extends NormalizePositionCloseOrder, SignedPayload {
|
|
33
|
+
}
|
|
34
|
+
export declare function signPositionCloseOrder(signer: WalletClient, order: PositionCloseOrder): Promise<SignedPositionCloseOrder>;
|
|
35
|
+
export interface NormalizeReplaceLimitOrder extends ReplaceBaseOrder {
|
|
36
|
+
quantity: string;
|
|
37
|
+
limitPrice: string;
|
|
38
|
+
postOnly?: "yes";
|
|
39
|
+
}
|
|
40
|
+
export interface SignedReplaceLimitOrder extends NormalizeReplaceLimitOrder, SignedPayload {
|
|
41
|
+
}
|
|
42
|
+
export declare function signReplaceLimitOrder(signer: WalletClient, order: ReplaceLimitOrder): Promise<SignedReplaceLimitOrder>;
|
|
43
|
+
export interface NormalizeReplaceStopLimitOrder extends NormalizeReplaceLimitOrder {
|
|
44
|
+
stopPrice: string;
|
|
45
|
+
}
|
|
46
|
+
export interface SignedReplaceStopLimitOrder extends NormalizeReplaceStopLimitOrder, SignedPayload {
|
|
47
|
+
}
|
|
48
|
+
export declare function signReplaceStopLimitOrder(signer: WalletClient, order: ReplaceStopLimitOrder): Promise<SignedReplaceStopLimitOrder>;
|
|
49
|
+
export interface TradingBalanceWithdraw {
|
|
50
|
+
recipient: string;
|
|
51
|
+
amount: Big.BigSource;
|
|
52
|
+
}
|
|
53
|
+
export interface NormalizeTradingBalanceWithdraw extends Pick<TradingBalanceWithdraw, "recipient"> {
|
|
54
|
+
amount: string;
|
|
55
|
+
}
|
|
56
|
+
export interface SignedTradingBalanceWithdraw extends NormalizeTradingBalanceWithdraw {
|
|
57
|
+
signature: string;
|
|
58
|
+
}
|
|
59
|
+
export interface SignedOauthConsentRequest extends OauthConsent {
|
|
60
|
+
signature: string;
|
|
61
|
+
}
|
|
62
|
+
export declare function signTradingBalanceWithdraw(signer: WalletClient, withdraw: TradingBalanceWithdraw): Promise<SignedTradingBalanceWithdraw>;
|
|
63
|
+
export interface NormalizeTpSl extends Pick<TpSl, "instrument" | "side" | "type" | "order"> {
|
|
64
|
+
quantity: string;
|
|
65
|
+
price: string;
|
|
66
|
+
}
|
|
67
|
+
export interface SignedTpSl extends NormalizeTpSl {
|
|
68
|
+
signature: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function signTpSl(signer: WalletClient, tpsl: TpSl): Promise<SignedTpSl>;
|
|
71
|
+
export declare function signOauthConsentTequest(signer: WalletClient, payload: OauthConsent): Promise<SignedOauthConsentRequest>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.signLimitOrder = signLimitOrder;
|
|
16
|
+
exports.signMarketOrder = signMarketOrder;
|
|
17
|
+
exports.signStopLimitOrder = signStopLimitOrder;
|
|
18
|
+
exports.signPositionCloseOrder = signPositionCloseOrder;
|
|
19
|
+
exports.signReplaceLimitOrder = signReplaceLimitOrder;
|
|
20
|
+
exports.signReplaceStopLimitOrder = signReplaceStopLimitOrder;
|
|
21
|
+
exports.signTradingBalanceWithdraw = signTradingBalanceWithdraw;
|
|
22
|
+
exports.signTpSl = signTpSl;
|
|
23
|
+
exports.signOauthConsentTequest = signOauthConsentTequest;
|
|
24
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
25
|
+
const crypto_1 = require("./utils/crypto");
|
|
26
|
+
const numeric_1 = require("./utils/numeric");
|
|
27
|
+
const validate_1 = require("./utils/validate");
|
|
28
|
+
const utils_1 = require("./utils");
|
|
29
|
+
function signLimitOrder(signer, order) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const chainId = yield signer.getChainId();
|
|
32
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createLimitOrder);
|
|
33
|
+
const normalize = {
|
|
34
|
+
id: order.id,
|
|
35
|
+
instrument: order.instrument,
|
|
36
|
+
side: order.side,
|
|
37
|
+
leverage: order.leverage,
|
|
38
|
+
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
39
|
+
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
40
|
+
tpsl: order.tpsl,
|
|
41
|
+
chainId,
|
|
42
|
+
};
|
|
43
|
+
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) }));
|
|
44
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, normalize), (order.postOnly && { postOnly: "yes" })), (order.timeInForce ? { timeInForce: order.timeInForce } : {})), { signature: signer.serializeSignature(signature) });
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function signMarketOrder(signer, order) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const chainId = yield signer.getChainId();
|
|
50
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createMarketOrder);
|
|
51
|
+
const normalize = {
|
|
52
|
+
id: order.id,
|
|
53
|
+
instrument: order.instrument,
|
|
54
|
+
side: order.side,
|
|
55
|
+
timeInForce: order.timeInForce,
|
|
56
|
+
leverage: order.leverage,
|
|
57
|
+
cashQuantity: (0, numeric_1.toMatcherNumber)(order.cashQuantity),
|
|
58
|
+
tpsl: order.tpsl,
|
|
59
|
+
chainId,
|
|
60
|
+
};
|
|
61
|
+
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) }));
|
|
62
|
+
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function signStopLimitOrder(signer, order) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const chainId = yield signer.getChainId();
|
|
68
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createStopLimitOrder);
|
|
69
|
+
const normalize = {
|
|
70
|
+
id: order.id,
|
|
71
|
+
instrument: order.instrument,
|
|
72
|
+
side: order.side,
|
|
73
|
+
leverage: order.leverage,
|
|
74
|
+
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
75
|
+
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
76
|
+
stopPrice: (0, numeric_1.toMatcherNumber)(order.stopPrice),
|
|
77
|
+
tpsl: order.tpsl,
|
|
78
|
+
chainId,
|
|
79
|
+
};
|
|
80
|
+
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) }));
|
|
81
|
+
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function signPositionCloseOrder(signer, order) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const chainId = yield signer.getChainId();
|
|
87
|
+
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP712Schemas.createPositionCloseOrder);
|
|
88
|
+
const normalize = {
|
|
89
|
+
id: order.id,
|
|
90
|
+
instrument: order.instrument,
|
|
91
|
+
leverage: order.leverage,
|
|
92
|
+
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
93
|
+
chainId,
|
|
94
|
+
};
|
|
95
|
+
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) }));
|
|
96
|
+
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function signReplaceLimitOrder(signer, order) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
(0, validate_1.validatePayload)(order, crypto_1.EIP712Schemas.replaceLimitOrder);
|
|
102
|
+
const normalize = {
|
|
103
|
+
orderId: order.orderId,
|
|
104
|
+
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
105
|
+
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
106
|
+
};
|
|
107
|
+
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) }));
|
|
108
|
+
return Object.assign(Object.assign(Object.assign({}, normalize), (order.postOnly && { postOnly: "yes" })), { signature: signer.serializeSignature(signature) });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function signReplaceStopLimitOrder(signer, order) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
(0, validate_1.validatePayload)(order, crypto_1.EIP712Schemas.replaceStopLimitOrder);
|
|
114
|
+
const normalize = {
|
|
115
|
+
orderId: order.orderId,
|
|
116
|
+
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
117
|
+
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
118
|
+
stopPrice: (0, numeric_1.toMatcherNumber)(order.stopPrice),
|
|
119
|
+
};
|
|
120
|
+
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) }));
|
|
121
|
+
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function signTradingBalanceWithdraw(signer, withdraw) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
(0, validate_1.validatePayload)(withdraw, crypto_1.EIP712Schemas.withdraw);
|
|
127
|
+
const normalize = {
|
|
128
|
+
recipient: withdraw.recipient,
|
|
129
|
+
amount: (0, big_js_1.default)(withdraw.amount).round(utils_1.MATCHER_PRECISION, big_js_1.default.roundDown).toString(),
|
|
130
|
+
};
|
|
131
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.withdraw, {
|
|
132
|
+
recipient: withdraw.recipient,
|
|
133
|
+
amount: (0, crypto_1.toEthNumber)(normalize.amount),
|
|
134
|
+
});
|
|
135
|
+
return Object.assign(Object.assign({}, normalize), { signature });
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function signTpSl(signer, tpsl) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
(0, validate_1.validatePayload)(tpsl, crypto_1.EIP712Schemas.createTpSl);
|
|
141
|
+
const normalize = {
|
|
142
|
+
instrument: tpsl.instrument,
|
|
143
|
+
type: tpsl.type,
|
|
144
|
+
side: tpsl.side,
|
|
145
|
+
quantity: (0, numeric_1.toMatcherNumber)(tpsl.quantity),
|
|
146
|
+
price: (0, numeric_1.toMatcherNumber)(tpsl.price),
|
|
147
|
+
order: tpsl.order,
|
|
148
|
+
};
|
|
149
|
+
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) }));
|
|
150
|
+
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function signOauthConsentTequest(signer, payload) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const { oauthRequestId } = payload;
|
|
156
|
+
(0, validate_1.validatePayload)({ oauthRequestId }, crypto_1.EIP712Schemas.oauthConsent);
|
|
157
|
+
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP712Schemas.oauthConsent, {
|
|
158
|
+
oauthRequestId,
|
|
159
|
+
});
|
|
160
|
+
return Object.assign(Object.assign({}, payload), { signature });
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SignedPayload, WalletClient } from "./utils/crypto";
|
|
2
|
+
export interface AuthMessage {
|
|
3
|
+
nonce: string;
|
|
4
|
+
address: string;
|
|
5
|
+
chainId: string;
|
|
6
|
+
expirationTime?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AuthPayload {
|
|
9
|
+
message: string;
|
|
10
|
+
}
|
|
11
|
+
export interface NormalizeAuthPayload extends AuthPayload {
|
|
12
|
+
address: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SignedAuth extends NormalizeAuthPayload, SignedPayload {
|
|
15
|
+
}
|
|
16
|
+
export declare function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }: AuthMessage): AuthPayload;
|
|
17
|
+
export declare function signAuthMessage(signer: WalletClient, messagePayload: AuthMessage): Promise<SignedAuth>;
|
|
18
|
+
export declare function signAuth(signer: WalletClient, payload: AuthPayload): Promise<SignedAuth>;
|
package/dist/mjs/auth.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SiweMessage } from "siwe";
|
|
2
|
+
export function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }) {
|
|
3
|
+
return {
|
|
4
|
+
message: new SiweMessage({
|
|
5
|
+
scheme: "https",
|
|
6
|
+
domain: "evedex.com",
|
|
7
|
+
uri: "https://evedex.com",
|
|
8
|
+
address,
|
|
9
|
+
statement: "Sign in to evedex.com",
|
|
10
|
+
nonce,
|
|
11
|
+
expirationTime,
|
|
12
|
+
chainId: Number(chainId),
|
|
13
|
+
version: "1",
|
|
14
|
+
}).prepareMessage(),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export async function signAuthMessage(signer, messagePayload) {
|
|
18
|
+
const address = await signer.getAddress();
|
|
19
|
+
const { message } = getAuthSiweMessagePayload(messagePayload);
|
|
20
|
+
const signature = await signer.signMessage(message);
|
|
21
|
+
return {
|
|
22
|
+
address,
|
|
23
|
+
message,
|
|
24
|
+
signature,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// @deprecated use signAuthMessage instead
|
|
28
|
+
export async function signAuth(signer, payload) {
|
|
29
|
+
const address = await signer.getAddress();
|
|
30
|
+
const signature = await signer.signMessage(payload.message);
|
|
31
|
+
return {
|
|
32
|
+
address,
|
|
33
|
+
message: payload.message,
|
|
34
|
+
signature,
|
|
35
|
+
};
|
|
36
|
+
}
|
package/dist/mjs/index.d.ts
CHANGED
|
@@ -1,89 +1,5 @@
|
|
|
1
|
-
import Big from "big.js";
|
|
2
|
-
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
|
-
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl, type OauthConsent, type TimeInForce } from "./utils/exchange";
|
|
4
1
|
export * as utils from "./utils";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expirationTime?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface AuthPayload {
|
|
12
|
-
message: string;
|
|
13
|
-
}
|
|
14
|
-
export interface NormalizeAuthPayload extends AuthPayload {
|
|
15
|
-
address: string;
|
|
16
|
-
}
|
|
17
|
-
export interface SignedAuth extends NormalizeAuthPayload, SignedPayload {
|
|
18
|
-
}
|
|
19
|
-
export declare function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }: AuthMessage): AuthPayload;
|
|
20
|
-
export declare function signAuthMessage(signer: WalletClient, messagePayload: AuthMessage): Promise<SignedAuth>;
|
|
21
|
-
export declare function signAuth(signer: WalletClient, payload: AuthPayload): Promise<SignedAuth>;
|
|
22
|
-
export interface NormalizeLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
23
|
-
quantity: string;
|
|
24
|
-
limitPrice: string;
|
|
25
|
-
postOnly?: "yes";
|
|
26
|
-
timeInForce?: TimeInForce;
|
|
27
|
-
}
|
|
28
|
-
export interface SignedLimitOrder extends NormalizeLimitOrder, SignedPayload {
|
|
29
|
-
quantity: string;
|
|
30
|
-
limitPrice: string;
|
|
31
|
-
}
|
|
32
|
-
export declare function signLimitOrder(signer: WalletClient, order: LimitOrder): Promise<SignedLimitOrder>;
|
|
33
|
-
export interface NormalizeMarketOrder extends CreateBaseOrder, Pick<MarketOrder, "timeInForce">, NetworkChain {
|
|
34
|
-
cashQuantity: string;
|
|
35
|
-
}
|
|
36
|
-
export interface SignedMarketOrder extends NormalizeMarketOrder, SignedPayload {
|
|
37
|
-
}
|
|
38
|
-
export declare function signMarketOrder(signer: WalletClient, order: MarketOrder): Promise<SignedMarketOrder>;
|
|
39
|
-
export interface NormalizeStopLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
40
|
-
quantity: string;
|
|
41
|
-
limitPrice: string;
|
|
42
|
-
stopPrice: string;
|
|
43
|
-
}
|
|
44
|
-
export interface SignedStopLimitOrder extends NormalizeStopLimitOrder, SignedPayload {
|
|
45
|
-
}
|
|
46
|
-
export declare function signStopLimitOrder(signer: WalletClient, order: StopLimitOrder): Promise<SignedStopLimitOrder>;
|
|
47
|
-
export interface NormalizePositionCloseOrder extends Pick<PositionCloseOrder, "instrument" | "leverage" | "id">, NetworkChain {
|
|
48
|
-
quantity: string;
|
|
49
|
-
}
|
|
50
|
-
export interface SignedPositionCloseOrder extends NormalizePositionCloseOrder, SignedPayload {
|
|
51
|
-
}
|
|
52
|
-
export declare function signPositionCloseOrder(signer: WalletClient, order: PositionCloseOrder): Promise<SignedPositionCloseOrder>;
|
|
53
|
-
export interface NormalizeReplaceLimitOrder extends ReplaceBaseOrder {
|
|
54
|
-
quantity: string;
|
|
55
|
-
limitPrice: string;
|
|
56
|
-
postOnly?: "yes";
|
|
57
|
-
}
|
|
58
|
-
export interface SignedReplaceLimitOrder extends NormalizeReplaceLimitOrder, SignedPayload {
|
|
59
|
-
}
|
|
60
|
-
export declare function signReplaceLimitOrder(signer: WalletClient, order: ReplaceLimitOrder): Promise<SignedReplaceLimitOrder>;
|
|
61
|
-
export interface NormalizeReplaceStopLimitOrder extends NormalizeReplaceLimitOrder {
|
|
62
|
-
stopPrice: string;
|
|
63
|
-
}
|
|
64
|
-
export interface SignedReplaceStopLimitOrder extends NormalizeReplaceStopLimitOrder, SignedPayload {
|
|
65
|
-
}
|
|
66
|
-
export declare function signReplaceStopLimitOrder(signer: WalletClient, order: ReplaceStopLimitOrder): Promise<SignedReplaceStopLimitOrder>;
|
|
67
|
-
export interface TradingBalanceWithdraw {
|
|
68
|
-
recipient: string;
|
|
69
|
-
amount: Big.BigSource;
|
|
70
|
-
}
|
|
71
|
-
export interface NormalizeTradingBalanceWithdraw extends Pick<TradingBalanceWithdraw, "recipient"> {
|
|
72
|
-
amount: string;
|
|
73
|
-
}
|
|
74
|
-
export interface SignedTradingBalanceWithdraw extends NormalizeTradingBalanceWithdraw {
|
|
75
|
-
signature: string;
|
|
76
|
-
}
|
|
77
|
-
export interface SignedOauthConsentRequest extends OauthConsent {
|
|
78
|
-
signature: string;
|
|
79
|
-
}
|
|
80
|
-
export declare function signTradingBalanceWithdraw(signer: WalletClient, withdraw: TradingBalanceWithdraw): Promise<SignedTradingBalanceWithdraw>;
|
|
81
|
-
export interface NormalizeTpSl extends Pick<TpSl, "instrument" | "side" | "type" | "order"> {
|
|
82
|
-
quantity: string;
|
|
83
|
-
price: string;
|
|
84
|
-
}
|
|
85
|
-
export interface SignedTpSl extends NormalizeTpSl {
|
|
86
|
-
signature: string;
|
|
87
|
-
}
|
|
88
|
-
export declare function signTpSl(signer: WalletClient, tpsl: TpSl): Promise<SignedTpSl>;
|
|
89
|
-
export declare function signOauthConsentTequest(signer: WalletClient, payload: OauthConsent): Promise<SignedOauthConsentRequest>;
|
|
2
|
+
export type { AuthMessage, AuthPayload, NormalizeAuthPayload, SignedAuth, } from "./auth";
|
|
3
|
+
export { getAuthSiweMessagePayload, signAuthMessage, signAuth } from "./auth";
|
|
4
|
+
export type { NormalizeLimitOrder, SignedLimitOrder, NormalizeMarketOrder, SignedMarketOrder, NormalizeStopLimitOrder, SignedStopLimitOrder, NormalizePositionCloseOrder, SignedPositionCloseOrder, NormalizeReplaceLimitOrder, SignedReplaceLimitOrder, NormalizeReplaceStopLimitOrder, SignedReplaceStopLimitOrder, TradingBalanceWithdraw, NormalizeTradingBalanceWithdraw, SignedTradingBalanceWithdraw, SignedOauthConsentRequest, NormalizeTpSl, SignedTpSl, } from "./orders";
|
|
5
|
+
export { signLimitOrder, signMarketOrder, signStopLimitOrder, signPositionCloseOrder, signReplaceLimitOrder, signReplaceStopLimitOrder, signTradingBalanceWithdraw, signTpSl, signOauthConsentTequest, } from "./orders";
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,216 +1,3 @@
|
|
|
1
|
-
import Big from "big.js";
|
|
2
|
-
import { SiweMessage } from "siwe";
|
|
3
|
-
import { EIP712Schemas, getDomainData, toEthNumber, } from "./utils/crypto";
|
|
4
|
-
import { toMatcherNumber } from "./utils/numeric";
|
|
5
|
-
import { validatePayload } from "./utils/validate";
|
|
6
|
-
import { MATCHER_PRECISION } from "./utils";
|
|
7
1
|
export * as utils from "./utils";
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
message: new SiweMessage({
|
|
11
|
-
scheme: "https",
|
|
12
|
-
domain: "evedex.com",
|
|
13
|
-
uri: "https://evedex.com",
|
|
14
|
-
address,
|
|
15
|
-
statement: "Sign in to evedex.com",
|
|
16
|
-
nonce,
|
|
17
|
-
expirationTime,
|
|
18
|
-
chainId: Number(chainId),
|
|
19
|
-
version: "1",
|
|
20
|
-
}).prepareMessage(),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export async function signAuthMessage(signer, messagePayload) {
|
|
24
|
-
const address = await signer.getAddress();
|
|
25
|
-
const { message } = getAuthSiweMessagePayload(messagePayload);
|
|
26
|
-
const signature = await signer.signMessage(message);
|
|
27
|
-
return {
|
|
28
|
-
address,
|
|
29
|
-
message,
|
|
30
|
-
signature,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
// @deprecated use signAuthMessage instead
|
|
34
|
-
export async function signAuth(signer, payload) {
|
|
35
|
-
const address = await signer.getAddress();
|
|
36
|
-
const signature = await signer.signMessage(payload.message);
|
|
37
|
-
return {
|
|
38
|
-
address,
|
|
39
|
-
message: payload.message,
|
|
40
|
-
signature,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export async function signLimitOrder(signer, order) {
|
|
44
|
-
const chainId = await signer.getChainId();
|
|
45
|
-
validatePayload({ ...order, chainId }, EIP712Schemas.createLimitOrder);
|
|
46
|
-
const normalize = {
|
|
47
|
-
id: order.id,
|
|
48
|
-
instrument: order.instrument,
|
|
49
|
-
side: order.side,
|
|
50
|
-
leverage: order.leverage,
|
|
51
|
-
quantity: toMatcherNumber(order.quantity),
|
|
52
|
-
limitPrice: toMatcherNumber(order.limitPrice),
|
|
53
|
-
tpsl: order.tpsl,
|
|
54
|
-
chainId,
|
|
55
|
-
};
|
|
56
|
-
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createLimitOrder, {
|
|
57
|
-
...normalize,
|
|
58
|
-
quantity: toEthNumber(normalize.quantity),
|
|
59
|
-
limitPrice: toEthNumber(normalize.limitPrice),
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
...normalize,
|
|
63
|
-
...(order.postOnly && { postOnly: "yes" }),
|
|
64
|
-
...(order.timeInForce ? { timeInForce: order.timeInForce } : {}),
|
|
65
|
-
signature: signer.serializeSignature(signature),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
export async function signMarketOrder(signer, order) {
|
|
69
|
-
const chainId = await signer.getChainId();
|
|
70
|
-
validatePayload({ ...order, chainId }, EIP712Schemas.createMarketOrder);
|
|
71
|
-
const normalize = {
|
|
72
|
-
id: order.id,
|
|
73
|
-
instrument: order.instrument,
|
|
74
|
-
side: order.side,
|
|
75
|
-
timeInForce: order.timeInForce,
|
|
76
|
-
leverage: order.leverage,
|
|
77
|
-
cashQuantity: toMatcherNumber(order.cashQuantity),
|
|
78
|
-
tpsl: order.tpsl,
|
|
79
|
-
chainId,
|
|
80
|
-
};
|
|
81
|
-
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createMarketOrder, {
|
|
82
|
-
...normalize,
|
|
83
|
-
cashQuantity: toEthNumber(normalize.cashQuantity),
|
|
84
|
-
});
|
|
85
|
-
return {
|
|
86
|
-
...normalize,
|
|
87
|
-
signature: signer.serializeSignature(signature),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
export async function signStopLimitOrder(signer, order) {
|
|
91
|
-
const chainId = await signer.getChainId();
|
|
92
|
-
validatePayload({ ...order, chainId }, EIP712Schemas.createStopLimitOrder);
|
|
93
|
-
const normalize = {
|
|
94
|
-
id: order.id,
|
|
95
|
-
instrument: order.instrument,
|
|
96
|
-
side: order.side,
|
|
97
|
-
leverage: order.leverage,
|
|
98
|
-
quantity: toMatcherNumber(order.quantity),
|
|
99
|
-
limitPrice: toMatcherNumber(order.limitPrice),
|
|
100
|
-
stopPrice: toMatcherNumber(order.stopPrice),
|
|
101
|
-
tpsl: order.tpsl,
|
|
102
|
-
chainId,
|
|
103
|
-
};
|
|
104
|
-
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createStopLimitOrder, {
|
|
105
|
-
...normalize,
|
|
106
|
-
quantity: toEthNumber(normalize.quantity),
|
|
107
|
-
limitPrice: toEthNumber(normalize.limitPrice),
|
|
108
|
-
stopPrice: toEthNumber(normalize.stopPrice),
|
|
109
|
-
});
|
|
110
|
-
return {
|
|
111
|
-
...normalize,
|
|
112
|
-
signature: signer.serializeSignature(signature),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
export async function signPositionCloseOrder(signer, order) {
|
|
116
|
-
const chainId = await signer.getChainId();
|
|
117
|
-
validatePayload({ ...order, chainId }, EIP712Schemas.createPositionCloseOrder);
|
|
118
|
-
const normalize = {
|
|
119
|
-
id: order.id,
|
|
120
|
-
instrument: order.instrument,
|
|
121
|
-
leverage: order.leverage,
|
|
122
|
-
quantity: toMatcherNumber(order.quantity),
|
|
123
|
-
chainId,
|
|
124
|
-
};
|
|
125
|
-
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createPositionCloseOrder, {
|
|
126
|
-
...normalize,
|
|
127
|
-
quantity: toEthNumber(normalize.quantity),
|
|
128
|
-
});
|
|
129
|
-
return {
|
|
130
|
-
...normalize,
|
|
131
|
-
signature: signer.serializeSignature(signature),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
export async function signReplaceLimitOrder(signer, order) {
|
|
135
|
-
validatePayload(order, EIP712Schemas.replaceLimitOrder);
|
|
136
|
-
const normalize = {
|
|
137
|
-
orderId: order.orderId,
|
|
138
|
-
quantity: toMatcherNumber(order.quantity),
|
|
139
|
-
limitPrice: toMatcherNumber(order.limitPrice),
|
|
140
|
-
};
|
|
141
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.replaceLimitOrder, {
|
|
142
|
-
...normalize,
|
|
143
|
-
quantity: toEthNumber(normalize.quantity),
|
|
144
|
-
limitPrice: toEthNumber(normalize.limitPrice),
|
|
145
|
-
});
|
|
146
|
-
return {
|
|
147
|
-
...normalize,
|
|
148
|
-
...(order.postOnly && { postOnly: "yes" }),
|
|
149
|
-
signature: signer.serializeSignature(signature),
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
export async function signReplaceStopLimitOrder(signer, order) {
|
|
153
|
-
validatePayload(order, EIP712Schemas.replaceStopLimitOrder);
|
|
154
|
-
const normalize = {
|
|
155
|
-
orderId: order.orderId,
|
|
156
|
-
quantity: toMatcherNumber(order.quantity),
|
|
157
|
-
limitPrice: toMatcherNumber(order.limitPrice),
|
|
158
|
-
stopPrice: toMatcherNumber(order.stopPrice),
|
|
159
|
-
};
|
|
160
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.replaceStopLimitOrder, {
|
|
161
|
-
...normalize,
|
|
162
|
-
quantity: toEthNumber(normalize.quantity),
|
|
163
|
-
limitPrice: toEthNumber(normalize.limitPrice),
|
|
164
|
-
stopPrice: toEthNumber(normalize.stopPrice),
|
|
165
|
-
});
|
|
166
|
-
return {
|
|
167
|
-
...normalize,
|
|
168
|
-
signature: signer.serializeSignature(signature),
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
export async function signTradingBalanceWithdraw(signer, withdraw) {
|
|
172
|
-
validatePayload(withdraw, EIP712Schemas.withdraw);
|
|
173
|
-
const normalize = {
|
|
174
|
-
recipient: withdraw.recipient,
|
|
175
|
-
amount: Big(withdraw.amount).round(MATCHER_PRECISION, Big.roundDown).toString(),
|
|
176
|
-
};
|
|
177
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.withdraw, {
|
|
178
|
-
recipient: withdraw.recipient,
|
|
179
|
-
amount: toEthNumber(normalize.amount),
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
...normalize,
|
|
183
|
-
signature,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
export async function signTpSl(signer, tpsl) {
|
|
187
|
-
validatePayload(tpsl, EIP712Schemas.createTpSl);
|
|
188
|
-
const normalize = {
|
|
189
|
-
instrument: tpsl.instrument,
|
|
190
|
-
type: tpsl.type,
|
|
191
|
-
side: tpsl.side,
|
|
192
|
-
quantity: toMatcherNumber(tpsl.quantity),
|
|
193
|
-
price: toMatcherNumber(tpsl.price),
|
|
194
|
-
order: tpsl.order,
|
|
195
|
-
};
|
|
196
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.createTpSl, {
|
|
197
|
-
...normalize,
|
|
198
|
-
quantity: toEthNumber(normalize.quantity),
|
|
199
|
-
price: toEthNumber(normalize.price),
|
|
200
|
-
});
|
|
201
|
-
return {
|
|
202
|
-
...normalize,
|
|
203
|
-
signature: signer.serializeSignature(signature),
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
export async function signOauthConsentTequest(signer, payload) {
|
|
207
|
-
const { oauthRequestId } = payload;
|
|
208
|
-
validatePayload({ oauthRequestId }, EIP712Schemas.oauthConsent);
|
|
209
|
-
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.oauthConsent, {
|
|
210
|
-
oauthRequestId,
|
|
211
|
-
});
|
|
212
|
-
return {
|
|
213
|
-
...payload,
|
|
214
|
-
signature,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
2
|
+
export { getAuthSiweMessagePayload, signAuthMessage, signAuth } from "./auth";
|
|
3
|
+
export { signLimitOrder, signMarketOrder, signStopLimitOrder, signPositionCloseOrder, signReplaceLimitOrder, signReplaceStopLimitOrder, signTradingBalanceWithdraw, signTpSl, signOauthConsentTequest, } from "./orders";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Big from "big.js";
|
|
2
|
+
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
|
+
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl, type OauthConsent, type TimeInForce } from "./utils/exchange";
|
|
4
|
+
export interface NormalizeLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
5
|
+
quantity: string;
|
|
6
|
+
limitPrice: string;
|
|
7
|
+
postOnly?: "yes";
|
|
8
|
+
timeInForce?: TimeInForce;
|
|
9
|
+
}
|
|
10
|
+
export interface SignedLimitOrder extends NormalizeLimitOrder, SignedPayload {
|
|
11
|
+
quantity: string;
|
|
12
|
+
limitPrice: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function signLimitOrder(signer: WalletClient, order: LimitOrder): Promise<SignedLimitOrder>;
|
|
15
|
+
export interface NormalizeMarketOrder extends CreateBaseOrder, Pick<MarketOrder, "timeInForce">, NetworkChain {
|
|
16
|
+
cashQuantity: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SignedMarketOrder extends NormalizeMarketOrder, SignedPayload {
|
|
19
|
+
}
|
|
20
|
+
export declare function signMarketOrder(signer: WalletClient, order: MarketOrder): Promise<SignedMarketOrder>;
|
|
21
|
+
export interface NormalizeStopLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
22
|
+
quantity: string;
|
|
23
|
+
limitPrice: string;
|
|
24
|
+
stopPrice: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SignedStopLimitOrder extends NormalizeStopLimitOrder, SignedPayload {
|
|
27
|
+
}
|
|
28
|
+
export declare function signStopLimitOrder(signer: WalletClient, order: StopLimitOrder): Promise<SignedStopLimitOrder>;
|
|
29
|
+
export interface NormalizePositionCloseOrder extends Pick<PositionCloseOrder, "instrument" | "leverage" | "id">, NetworkChain {
|
|
30
|
+
quantity: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SignedPositionCloseOrder extends NormalizePositionCloseOrder, SignedPayload {
|
|
33
|
+
}
|
|
34
|
+
export declare function signPositionCloseOrder(signer: WalletClient, order: PositionCloseOrder): Promise<SignedPositionCloseOrder>;
|
|
35
|
+
export interface NormalizeReplaceLimitOrder extends ReplaceBaseOrder {
|
|
36
|
+
quantity: string;
|
|
37
|
+
limitPrice: string;
|
|
38
|
+
postOnly?: "yes";
|
|
39
|
+
}
|
|
40
|
+
export interface SignedReplaceLimitOrder extends NormalizeReplaceLimitOrder, SignedPayload {
|
|
41
|
+
}
|
|
42
|
+
export declare function signReplaceLimitOrder(signer: WalletClient, order: ReplaceLimitOrder): Promise<SignedReplaceLimitOrder>;
|
|
43
|
+
export interface NormalizeReplaceStopLimitOrder extends NormalizeReplaceLimitOrder {
|
|
44
|
+
stopPrice: string;
|
|
45
|
+
}
|
|
46
|
+
export interface SignedReplaceStopLimitOrder extends NormalizeReplaceStopLimitOrder, SignedPayload {
|
|
47
|
+
}
|
|
48
|
+
export declare function signReplaceStopLimitOrder(signer: WalletClient, order: ReplaceStopLimitOrder): Promise<SignedReplaceStopLimitOrder>;
|
|
49
|
+
export interface TradingBalanceWithdraw {
|
|
50
|
+
recipient: string;
|
|
51
|
+
amount: Big.BigSource;
|
|
52
|
+
}
|
|
53
|
+
export interface NormalizeTradingBalanceWithdraw extends Pick<TradingBalanceWithdraw, "recipient"> {
|
|
54
|
+
amount: string;
|
|
55
|
+
}
|
|
56
|
+
export interface SignedTradingBalanceWithdraw extends NormalizeTradingBalanceWithdraw {
|
|
57
|
+
signature: string;
|
|
58
|
+
}
|
|
59
|
+
export interface SignedOauthConsentRequest extends OauthConsent {
|
|
60
|
+
signature: string;
|
|
61
|
+
}
|
|
62
|
+
export declare function signTradingBalanceWithdraw(signer: WalletClient, withdraw: TradingBalanceWithdraw): Promise<SignedTradingBalanceWithdraw>;
|
|
63
|
+
export interface NormalizeTpSl extends Pick<TpSl, "instrument" | "side" | "type" | "order"> {
|
|
64
|
+
quantity: string;
|
|
65
|
+
price: string;
|
|
66
|
+
}
|
|
67
|
+
export interface SignedTpSl extends NormalizeTpSl {
|
|
68
|
+
signature: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function signTpSl(signer: WalletClient, tpsl: TpSl): Promise<SignedTpSl>;
|
|
71
|
+
export declare function signOauthConsentTequest(signer: WalletClient, payload: OauthConsent): Promise<SignedOauthConsentRequest>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import Big from "big.js";
|
|
2
|
+
import { EIP712Schemas, getDomainData, toEthNumber, } from "./utils/crypto";
|
|
3
|
+
import { toMatcherNumber } from "./utils/numeric";
|
|
4
|
+
import { validatePayload } from "./utils/validate";
|
|
5
|
+
import { MATCHER_PRECISION } from "./utils";
|
|
6
|
+
export async function signLimitOrder(signer, order) {
|
|
7
|
+
const chainId = await signer.getChainId();
|
|
8
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createLimitOrder);
|
|
9
|
+
const normalize = {
|
|
10
|
+
id: order.id,
|
|
11
|
+
instrument: order.instrument,
|
|
12
|
+
side: order.side,
|
|
13
|
+
leverage: order.leverage,
|
|
14
|
+
quantity: toMatcherNumber(order.quantity),
|
|
15
|
+
limitPrice: toMatcherNumber(order.limitPrice),
|
|
16
|
+
tpsl: order.tpsl,
|
|
17
|
+
chainId,
|
|
18
|
+
};
|
|
19
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createLimitOrder, {
|
|
20
|
+
...normalize,
|
|
21
|
+
quantity: toEthNumber(normalize.quantity),
|
|
22
|
+
limitPrice: toEthNumber(normalize.limitPrice),
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
...normalize,
|
|
26
|
+
...(order.postOnly && { postOnly: "yes" }),
|
|
27
|
+
...(order.timeInForce ? { timeInForce: order.timeInForce } : {}),
|
|
28
|
+
signature: signer.serializeSignature(signature),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export async function signMarketOrder(signer, order) {
|
|
32
|
+
const chainId = await signer.getChainId();
|
|
33
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createMarketOrder);
|
|
34
|
+
const normalize = {
|
|
35
|
+
id: order.id,
|
|
36
|
+
instrument: order.instrument,
|
|
37
|
+
side: order.side,
|
|
38
|
+
timeInForce: order.timeInForce,
|
|
39
|
+
leverage: order.leverage,
|
|
40
|
+
cashQuantity: toMatcherNumber(order.cashQuantity),
|
|
41
|
+
tpsl: order.tpsl,
|
|
42
|
+
chainId,
|
|
43
|
+
};
|
|
44
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createMarketOrder, {
|
|
45
|
+
...normalize,
|
|
46
|
+
cashQuantity: toEthNumber(normalize.cashQuantity),
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
...normalize,
|
|
50
|
+
signature: signer.serializeSignature(signature),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export async function signStopLimitOrder(signer, order) {
|
|
54
|
+
const chainId = await signer.getChainId();
|
|
55
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createStopLimitOrder);
|
|
56
|
+
const normalize = {
|
|
57
|
+
id: order.id,
|
|
58
|
+
instrument: order.instrument,
|
|
59
|
+
side: order.side,
|
|
60
|
+
leverage: order.leverage,
|
|
61
|
+
quantity: toMatcherNumber(order.quantity),
|
|
62
|
+
limitPrice: toMatcherNumber(order.limitPrice),
|
|
63
|
+
stopPrice: toMatcherNumber(order.stopPrice),
|
|
64
|
+
tpsl: order.tpsl,
|
|
65
|
+
chainId,
|
|
66
|
+
};
|
|
67
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createStopLimitOrder, {
|
|
68
|
+
...normalize,
|
|
69
|
+
quantity: toEthNumber(normalize.quantity),
|
|
70
|
+
limitPrice: toEthNumber(normalize.limitPrice),
|
|
71
|
+
stopPrice: toEthNumber(normalize.stopPrice),
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
...normalize,
|
|
75
|
+
signature: signer.serializeSignature(signature),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export async function signPositionCloseOrder(signer, order) {
|
|
79
|
+
const chainId = await signer.getChainId();
|
|
80
|
+
validatePayload({ ...order, chainId }, EIP712Schemas.createPositionCloseOrder);
|
|
81
|
+
const normalize = {
|
|
82
|
+
id: order.id,
|
|
83
|
+
instrument: order.instrument,
|
|
84
|
+
leverage: order.leverage,
|
|
85
|
+
quantity: toMatcherNumber(order.quantity),
|
|
86
|
+
chainId,
|
|
87
|
+
};
|
|
88
|
+
const signature = await signer.signTypedData(getDomainData(chainId), EIP712Schemas.createPositionCloseOrder, {
|
|
89
|
+
...normalize,
|
|
90
|
+
quantity: toEthNumber(normalize.quantity),
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
...normalize,
|
|
94
|
+
signature: signer.serializeSignature(signature),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export async function signReplaceLimitOrder(signer, order) {
|
|
98
|
+
validatePayload(order, EIP712Schemas.replaceLimitOrder);
|
|
99
|
+
const normalize = {
|
|
100
|
+
orderId: order.orderId,
|
|
101
|
+
quantity: toMatcherNumber(order.quantity),
|
|
102
|
+
limitPrice: toMatcherNumber(order.limitPrice),
|
|
103
|
+
};
|
|
104
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.replaceLimitOrder, {
|
|
105
|
+
...normalize,
|
|
106
|
+
quantity: toEthNumber(normalize.quantity),
|
|
107
|
+
limitPrice: toEthNumber(normalize.limitPrice),
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
...normalize,
|
|
111
|
+
...(order.postOnly && { postOnly: "yes" }),
|
|
112
|
+
signature: signer.serializeSignature(signature),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export async function signReplaceStopLimitOrder(signer, order) {
|
|
116
|
+
validatePayload(order, EIP712Schemas.replaceStopLimitOrder);
|
|
117
|
+
const normalize = {
|
|
118
|
+
orderId: order.orderId,
|
|
119
|
+
quantity: toMatcherNumber(order.quantity),
|
|
120
|
+
limitPrice: toMatcherNumber(order.limitPrice),
|
|
121
|
+
stopPrice: toMatcherNumber(order.stopPrice),
|
|
122
|
+
};
|
|
123
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.replaceStopLimitOrder, {
|
|
124
|
+
...normalize,
|
|
125
|
+
quantity: toEthNumber(normalize.quantity),
|
|
126
|
+
limitPrice: toEthNumber(normalize.limitPrice),
|
|
127
|
+
stopPrice: toEthNumber(normalize.stopPrice),
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
...normalize,
|
|
131
|
+
signature: signer.serializeSignature(signature),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export async function signTradingBalanceWithdraw(signer, withdraw) {
|
|
135
|
+
validatePayload(withdraw, EIP712Schemas.withdraw);
|
|
136
|
+
const normalize = {
|
|
137
|
+
recipient: withdraw.recipient,
|
|
138
|
+
amount: Big(withdraw.amount).round(MATCHER_PRECISION, Big.roundDown).toString(),
|
|
139
|
+
};
|
|
140
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.withdraw, {
|
|
141
|
+
recipient: withdraw.recipient,
|
|
142
|
+
amount: toEthNumber(normalize.amount),
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
...normalize,
|
|
146
|
+
signature,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export async function signTpSl(signer, tpsl) {
|
|
150
|
+
validatePayload(tpsl, EIP712Schemas.createTpSl);
|
|
151
|
+
const normalize = {
|
|
152
|
+
instrument: tpsl.instrument,
|
|
153
|
+
type: tpsl.type,
|
|
154
|
+
side: tpsl.side,
|
|
155
|
+
quantity: toMatcherNumber(tpsl.quantity),
|
|
156
|
+
price: toMatcherNumber(tpsl.price),
|
|
157
|
+
order: tpsl.order,
|
|
158
|
+
};
|
|
159
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.createTpSl, {
|
|
160
|
+
...normalize,
|
|
161
|
+
quantity: toEthNumber(normalize.quantity),
|
|
162
|
+
price: toEthNumber(normalize.price),
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
...normalize,
|
|
166
|
+
signature: signer.serializeSignature(signature),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export async function signOauthConsentTequest(signer, payload) {
|
|
170
|
+
const { oauthRequestId } = payload;
|
|
171
|
+
validatePayload({ oauthRequestId }, EIP712Schemas.oauthConsent);
|
|
172
|
+
const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP712Schemas.oauthConsent, {
|
|
173
|
+
oauthRequestId,
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
...payload,
|
|
177
|
+
signature,
|
|
178
|
+
};
|
|
179
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evedex/exchange-crypto",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.0-beta.1",
|
|
4
|
+
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
7
7
|
"types": "dist/mjs/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"import": "./dist/mjs/index.js",
|
|
11
|
-
"require": "./dist/cjs/index.js"
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"types": "./dist/mjs/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./auth": {
|
|
16
|
+
"import": "./dist/mjs/auth.js",
|
|
17
|
+
"require": "./dist/cjs/auth.js",
|
|
18
|
+
"types": "./dist/mjs/auth.d.ts"
|
|
12
19
|
}
|
|
13
20
|
},
|
|
14
21
|
"files": [
|