@reyaxyz/common 0.274.3 → 0.275.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/commands/exposure/command.js +1 -1
- package/dist/commands/exposure/command.js.map +1 -1
- package/dist/transactions/abis/OrdersGateway.json +46 -61
- package/dist/transactions/consts.js +2 -1
- package/dist/transactions/consts.js.map +1 -1
- package/dist/transactions/contractAddresses.js +3 -0
- package/dist/transactions/contractAddresses.js.map +1 -1
- package/dist/transactions/sign.js +25 -6
- package/dist/transactions/sign.js.map +1 -1
- package/dist/types/transactions/consts.d.ts +1 -0
- package/dist/types/transactions/consts.d.ts.map +1 -1
- package/dist/types/transactions/contractAddresses.d.ts +1 -0
- package/dist/types/transactions/contractAddresses.d.ts.map +1 -1
- package/dist/types/transactions/sign.d.ts +9 -2
- package/dist/types/transactions/sign.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/calculate.d.ts +1 -0
- package/dist/types/utils/calculate.d.ts.map +1 -1
- package/dist/types.js +9 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/calculate.js +3 -3
- package/dist/utils/calculate.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/exposure/command.ts +2 -2
- package/src/transactions/abis/OrdersGateway.json +434 -449
- package/src/transactions/consts.ts +1 -0
- package/src/transactions/contractAddresses.ts +5 -0
- package/src/transactions/sign.ts +50 -7
- package/src/types.ts +9 -0
- package/src/utils/calculate.ts +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const BRIDGE_DEADLINE_IN_SECONDS = 15 * 60; // 15 minutes
|
|
2
2
|
export const CORE_DEADLINE_IN_SECONDS = 60; // 1 minute
|
|
3
|
+
export const ORDERS_GATEWAY_DEADLINE_IN_SECONDS = 60; // 1 minute
|
|
3
4
|
export const RELAYER_ACCOUNT = '0xb43c317c9c9215d268881d7d6b59c2d3d0247da1'; // @todo update value
|
|
4
5
|
export const PUBLISHER_ACCOUNT = '0xE32519ca0e751C754c8E1378846B5cd95A1CB66a'; // @todo update value
|
|
5
6
|
export const CONDITIONAL_ORDER_SIG_DEADLINE = 10 ** 18; // very big number for timestamp
|
|
@@ -5,6 +5,7 @@ export enum ContractType {
|
|
|
5
5
|
PASSIVE_POOL_PROXY = 'passive_pool_proxy',
|
|
6
6
|
PERIPHERY_PROXY = 'periphery_proxy',
|
|
7
7
|
CONDITIONAL_ORDERS_PROXY = 'conditional_orders_proxy',
|
|
8
|
+
ORDERS_GATEWAY_PROXY = 'orders_gateway_proxy',
|
|
8
9
|
PASSIVE_PERP_PROXY = 'passive_perp_proxy',
|
|
9
10
|
ORACLE_ADAPTERS_PROXY = 'oracle_adapters_proxy',
|
|
10
11
|
MULTICALL = 'multicall',
|
|
@@ -20,6 +21,8 @@ const addresses: Record<ReyaChainId, Record<ContractType, Address>> = {
|
|
|
20
21
|
'0x94ccae812f1647696754412082dd6684c2366a7f',
|
|
21
22
|
[ContractType.CONDITIONAL_ORDERS_PROXY]:
|
|
22
23
|
'0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',
|
|
24
|
+
[ContractType.ORDERS_GATEWAY_PROXY]:
|
|
25
|
+
'0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',
|
|
23
26
|
[ContractType.PASSIVE_PERP_PROXY]:
|
|
24
27
|
'0x9ec177fed042ef2307928be2f5cdbf663b20244b',
|
|
25
28
|
[ContractType.ORACLE_ADAPTERS_PROXY]:
|
|
@@ -35,6 +38,8 @@ const addresses: Record<ReyaChainId, Record<ContractType, Address>> = {
|
|
|
35
38
|
'0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',
|
|
36
39
|
[ContractType.CONDITIONAL_ORDERS_PROXY]:
|
|
37
40
|
'0xfc8c96be87da63cecddbf54abfa7b13ee8044739',
|
|
41
|
+
[ContractType.ORDERS_GATEWAY_PROXY]:
|
|
42
|
+
'0xfc8c96be87da63cecddbf54abfa7b13ee8044739',
|
|
38
43
|
[ContractType.PASSIVE_PERP_PROXY]:
|
|
39
44
|
'0x27e5cb712334e101b3c232eb0be198baaa595f5f',
|
|
40
45
|
[ContractType.ORACLE_ADAPTERS_PROXY]:
|
package/src/transactions/sign.ts
CHANGED
|
@@ -7,7 +7,13 @@ import {
|
|
|
7
7
|
} from 'ethers';
|
|
8
8
|
import { ContractType, getAddress } from './contractAddresses';
|
|
9
9
|
import { Command } from './action';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
Address,
|
|
12
|
+
ConditionalOrderStatus,
|
|
13
|
+
ConditionalOrderType,
|
|
14
|
+
OrdersGatewayOrderType,
|
|
15
|
+
ReyaChainId,
|
|
16
|
+
} from '../types';
|
|
11
17
|
|
|
12
18
|
export type EIP712Signature = {
|
|
13
19
|
v: number;
|
|
@@ -204,21 +210,54 @@ const sessionUpdateTypes = {
|
|
|
204
210
|
],
|
|
205
211
|
};
|
|
206
212
|
|
|
207
|
-
export
|
|
213
|
+
export function createOrdersGatewayOrderNonce(
|
|
214
|
+
accountId: number,
|
|
215
|
+
marketId: number,
|
|
216
|
+
timestampMs: number,
|
|
217
|
+
): bigint {
|
|
218
|
+
// Validate the input ranges
|
|
219
|
+
if (marketId < 0 || marketId >= 2 ** 32)
|
|
220
|
+
throw new Error('marketId is out of range');
|
|
221
|
+
if (accountId < 0 || accountId >= 2 ** 128)
|
|
222
|
+
throw new Error('accountId is out of range');
|
|
223
|
+
if (timestampMs < 0 || timestampMs >= 2 ** 64)
|
|
224
|
+
throw new Error('timestamp is out of range');
|
|
225
|
+
|
|
226
|
+
const hashUint256 =
|
|
227
|
+
(BigInt(accountId) << BigInt(98)) |
|
|
228
|
+
(BigInt(timestampMs) << BigInt(32)) |
|
|
229
|
+
BigInt(marketId);
|
|
230
|
+
|
|
231
|
+
return hashUint256;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
type SignOrdersGatewayOrderOutput = {
|
|
235
|
+
serializedSignature: string;
|
|
236
|
+
nonce: bigint;
|
|
237
|
+
signature: EIP712Signature;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export async function signOrdersGatewayOrder(
|
|
208
241
|
signer: Signer | JsonRpcSigner,
|
|
209
242
|
reyaChainId: ReyaChainId,
|
|
210
243
|
accountId: number,
|
|
211
244
|
marketId: number,
|
|
212
245
|
exchangeId: number,
|
|
213
246
|
counterpartyAccountIds: number[],
|
|
214
|
-
orderType:
|
|
247
|
+
orderType: ConditionalOrderType | OrdersGatewayOrderType,
|
|
215
248
|
inputs: string,
|
|
216
|
-
nonce: bigint,
|
|
217
249
|
deadline: number,
|
|
218
|
-
|
|
250
|
+
creationTimestampMs: number,
|
|
251
|
+
): Promise<SignOrdersGatewayOrderOutput> {
|
|
252
|
+
const nonce = createOrdersGatewayOrderNonce(
|
|
253
|
+
accountId,
|
|
254
|
+
marketId,
|
|
255
|
+
creationTimestampMs,
|
|
256
|
+
);
|
|
257
|
+
|
|
219
258
|
const signature = await signReyaTypedData(
|
|
220
259
|
signer,
|
|
221
|
-
getAddress(reyaChainId, ContractType.
|
|
260
|
+
getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),
|
|
222
261
|
conditionalOrderTypes,
|
|
223
262
|
{
|
|
224
263
|
verifyingChainId: reyaChainId,
|
|
@@ -236,7 +275,11 @@ export async function signConditionalOrder(
|
|
|
236
275
|
},
|
|
237
276
|
);
|
|
238
277
|
|
|
239
|
-
return
|
|
278
|
+
return {
|
|
279
|
+
serializedSignature: signature.serialized,
|
|
280
|
+
nonce,
|
|
281
|
+
signature: convertEthersSignatureToEIP712Signature(signature, deadline),
|
|
282
|
+
};
|
|
240
283
|
}
|
|
241
284
|
|
|
242
285
|
export async function signInitiateOrUpdateSession(
|
package/src/types.ts
CHANGED
|
@@ -493,6 +493,7 @@ export type GetBalancesForBridgeArgs = {
|
|
|
493
493
|
|
|
494
494
|
export type DepthSimulationState = {
|
|
495
495
|
spotPrice: number;
|
|
496
|
+
depthFactor: number;
|
|
496
497
|
maxOrderSizeLong: number;
|
|
497
498
|
maxOrderSizeShort: number;
|
|
498
499
|
netExposure: number;
|
|
@@ -1042,6 +1043,14 @@ export type PendingWithdrawal = {
|
|
|
1042
1043
|
tokenAmount: number;
|
|
1043
1044
|
} & (PendingWithdrawalStatus | ReadyWithdrawalStatus);
|
|
1044
1045
|
|
|
1046
|
+
export enum OrdersGatewayOrderType {
|
|
1047
|
+
STOP_LOSS = 0,
|
|
1048
|
+
TAKE_PROFIT = 1,
|
|
1049
|
+
LIMIT_ORDER = 2,
|
|
1050
|
+
MARKET_ORDER = 3,
|
|
1051
|
+
REDUCE_ONLY_MARKET_ORDER = 4,
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1045
1054
|
export enum ConditionalOrderType {
|
|
1046
1055
|
STOP_LOSS = 0,
|
|
1047
1056
|
TAKE_PROFIT = 1,
|