@reyaxyz/api-sdk 0.168.25 → 0.169.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/dist/clients/api-client.js +0 -32
- package/dist/clients/api-client.js.map +1 -1
- package/dist/clients/modules/account/index.js +0 -22
- package/dist/clients/modules/account/index.js.map +1 -1
- package/dist/clients/modules/account/types.js.map +1 -1
- package/dist/clients/types.js +1 -3
- package/dist/clients/types.js.map +1 -1
- package/dist/types/clients/api-client.d.ts +0 -20
- package/dist/types/clients/api-client.d.ts.map +1 -1
- package/dist/types/clients/modules/account/index.d.ts +1 -3
- package/dist/types/clients/modules/account/index.d.ts.map +1 -1
- package/dist/types/clients/modules/account/types.d.ts +2 -14
- package/dist/types/clients/modules/account/types.d.ts.map +1 -1
- package/dist/types/clients/types.d.ts +1 -2
- package/dist/types/clients/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/clients/api-client.ts +0 -31
- package/src/clients/modules/account/index.ts +0 -22
- package/src/clients/modules/account/types.ts +0 -19
- package/src/clients/types.ts +0 -5
- package/dist/clients/modules/conditional-orders/index.js +0 -259
- package/dist/clients/modules/conditional-orders/index.js.map +0 -1
- package/dist/clients/modules/conditional-orders/types.js +0 -3
- package/dist/clients/modules/conditional-orders/types.js.map +0 -1
- package/dist/clients/modules/referral/index.js +0 -76
- package/dist/clients/modules/referral/index.js.map +0 -1
- package/dist/types/clients/modules/conditional-orders/index.d.ts +0 -15
- package/dist/types/clients/modules/conditional-orders/index.d.ts.map +0 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts +0 -53
- package/dist/types/clients/modules/conditional-orders/types.d.ts.map +0 -1
- package/dist/types/clients/modules/referral/index.d.ts +0 -5
- package/dist/types/clients/modules/referral/index.d.ts.map +0 -1
- package/src/clients/modules/conditional-orders/index.ts +0 -256
- package/src/clients/modules/conditional-orders/types.ts +0 -70
- package/src/clients/modules/referral/index.ts +0 -16
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
calculateMaxPriceLimit,
|
|
3
|
-
PositionEntity,
|
|
4
|
-
RestClient,
|
|
5
|
-
ReyaChainId,
|
|
6
|
-
signOrdersGatewayOrder,
|
|
7
|
-
signCancelConditionalOrder,
|
|
8
|
-
ConditionalOrder,
|
|
9
|
-
ConditionalOrderType,
|
|
10
|
-
scale,
|
|
11
|
-
CONDITIONAL_ORDER_SIG_DEADLINE,
|
|
12
|
-
} from '@reyaxyz/common';
|
|
13
|
-
import { AbiCoder } from 'ethers';
|
|
14
|
-
import { Signer, JsonRpcSigner } from 'ethers';
|
|
15
|
-
import {
|
|
16
|
-
AlreadyGaveTradePermissionParams,
|
|
17
|
-
AlreadyGaveTradePermissionResult,
|
|
18
|
-
CancelConditionalOrderParams,
|
|
19
|
-
CancelConditionalOrderResult,
|
|
20
|
-
GetConditionalOrdersHistoryForMarginAccountParams,
|
|
21
|
-
GetConditionalOrdersHistoryForMarginAccountResult,
|
|
22
|
-
GetConditionalOrdersHistoryForWalletAddressParams,
|
|
23
|
-
RegisterConditionalOrderParams,
|
|
24
|
-
RegisterConditionalOrderResult,
|
|
25
|
-
UpdateConditionalOrderParams,
|
|
26
|
-
UpdateConditionalOrderResult,
|
|
27
|
-
} from './types';
|
|
28
|
-
|
|
29
|
-
export default class ConditionalOrdersClient extends RestClient {
|
|
30
|
-
private reyaChainId: ReyaChainId;
|
|
31
|
-
|
|
32
|
-
constructor(reyaChainId: ReyaChainId, host: string) {
|
|
33
|
-
super(host);
|
|
34
|
-
this.reyaChainId = reyaChainId;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// ------ Conditional Orders History ---
|
|
38
|
-
async getConditionalOrdersHistoryForMarginAccount(
|
|
39
|
-
params: GetConditionalOrdersHistoryForMarginAccountParams,
|
|
40
|
-
): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {
|
|
41
|
-
const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}`;
|
|
42
|
-
return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {
|
|
43
|
-
limit: params.limit,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async getConditionalOrdersHistoryForWalletAddress(
|
|
48
|
-
params: GetConditionalOrdersHistoryForWalletAddressParams,
|
|
49
|
-
): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {
|
|
50
|
-
const uri = `/api/conditional-orders/get-orders-by-wallet/${params.walletAddress}`;
|
|
51
|
-
return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {
|
|
52
|
-
limit: params.limit,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async alreadyGaveTradePermissions(
|
|
57
|
-
params: AlreadyGaveTradePermissionParams,
|
|
58
|
-
): Promise<AlreadyGaveTradePermissionResult> {
|
|
59
|
-
const uri = `/api/conditional-orders/gave-trade-permission/${params.accountId}`;
|
|
60
|
-
const response = await this.get<boolean>(uri);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
permissionGiven: response,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async cancelConditionalOrder(
|
|
68
|
-
params: CancelConditionalOrderParams,
|
|
69
|
-
): Promise<CancelConditionalOrderResult> {
|
|
70
|
-
const signature = await signCancelConditionalOrder(
|
|
71
|
-
params.signer,
|
|
72
|
-
params.orderId,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const uri = `/api/conditional-orders/cancel-order`;
|
|
76
|
-
const res = await this.put<ConditionalOrder>(
|
|
77
|
-
uri,
|
|
78
|
-
{},
|
|
79
|
-
{
|
|
80
|
-
orderId: params.orderId,
|
|
81
|
-
userSignature: signature,
|
|
82
|
-
},
|
|
83
|
-
);
|
|
84
|
-
return res;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async registerConditionalOrder(
|
|
88
|
-
params: RegisterConditionalOrderParams,
|
|
89
|
-
): Promise<RegisterConditionalOrderResult> {
|
|
90
|
-
const inputs = await this.parseConditionalOrderInputs(
|
|
91
|
-
params.signer,
|
|
92
|
-
params.marginAccountId,
|
|
93
|
-
params.marketId,
|
|
94
|
-
params.orderType,
|
|
95
|
-
params.triggerPrice,
|
|
96
|
-
params.supportingParams.exchangeId,
|
|
97
|
-
params.supportingParams.counterpartyAccountIds,
|
|
98
|
-
params.amountInBase,
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
// create new entry
|
|
102
|
-
const uri = `/api/conditional-orders/create-or-update-order`;
|
|
103
|
-
|
|
104
|
-
const result = await this.post<ConditionalOrder>(
|
|
105
|
-
uri,
|
|
106
|
-
{},
|
|
107
|
-
{
|
|
108
|
-
accountId: params.marginAccountId,
|
|
109
|
-
poolId: params.supportingParams.counterpartyAccountIds[0],
|
|
110
|
-
deadline: inputs.deadline,
|
|
111
|
-
exchangeId: params.supportingParams.exchangeId,
|
|
112
|
-
isLong: inputs.actualAmountInBase > 0,
|
|
113
|
-
marketId: params.marketId,
|
|
114
|
-
nonce: inputs.nonce.toString(),
|
|
115
|
-
orderPriceLimit: inputs.orderPriceLimit.toString(),
|
|
116
|
-
orderType: params.orderType,
|
|
117
|
-
signature: inputs.signature,
|
|
118
|
-
signerWallet: await params.signer.getAddress(),
|
|
119
|
-
timestampMs: inputs.creationTimestampMs,
|
|
120
|
-
triggerPrice: params.triggerPrice,
|
|
121
|
-
orderBase: params.amountInBase,
|
|
122
|
-
},
|
|
123
|
-
);
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async updateConditionalOrder(
|
|
128
|
-
params: UpdateConditionalOrderParams,
|
|
129
|
-
): Promise<UpdateConditionalOrderResult> {
|
|
130
|
-
const inputs = await this.parseConditionalOrderInputs(
|
|
131
|
-
params.signer,
|
|
132
|
-
params.marginAccountId,
|
|
133
|
-
params.marketId,
|
|
134
|
-
params.orderType,
|
|
135
|
-
params.triggerPrice,
|
|
136
|
-
params.supportingParams.exchangeId,
|
|
137
|
-
params.supportingParams.counterpartyAccountIds,
|
|
138
|
-
params.amountInBase,
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
// create new entry
|
|
142
|
-
const uri = `/api/conditional-orders/create-or-update-order`;
|
|
143
|
-
|
|
144
|
-
const result = await this.post<ConditionalOrder>(
|
|
145
|
-
uri,
|
|
146
|
-
{},
|
|
147
|
-
{
|
|
148
|
-
accountId: params.marginAccountId,
|
|
149
|
-
poolId: params.supportingParams.counterpartyAccountIds[0],
|
|
150
|
-
deadline: inputs.deadline,
|
|
151
|
-
exchangeId: params.supportingParams.exchangeId,
|
|
152
|
-
isLong: inputs.actualAmountInBase > 0,
|
|
153
|
-
marketId: params.marketId,
|
|
154
|
-
nonce: inputs.nonce.toString(),
|
|
155
|
-
orderPriceLimit: inputs.orderPriceLimit.toString(),
|
|
156
|
-
orderType: params.orderType,
|
|
157
|
-
signature: inputs.signature,
|
|
158
|
-
signerWallet: await params.signer.getAddress(),
|
|
159
|
-
timestampMs: inputs.creationTimestampMs,
|
|
160
|
-
triggerPrice: params.triggerPrice,
|
|
161
|
-
cancelOrderId: params.cancelOrderId,
|
|
162
|
-
orderBase: params.amountInBase,
|
|
163
|
-
},
|
|
164
|
-
);
|
|
165
|
-
return result;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
private async getPosition(
|
|
169
|
-
accountId: number,
|
|
170
|
-
marketId: number,
|
|
171
|
-
): Promise<PositionEntity> {
|
|
172
|
-
const uri = `/api/accounts/marginAccount/position/${accountId}/${marketId}`;
|
|
173
|
-
return this.get<PositionEntity>(uri);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private async parseConditionalOrderInputs(
|
|
177
|
-
signer: Signer | JsonRpcSigner,
|
|
178
|
-
accountId: number,
|
|
179
|
-
marketId: number,
|
|
180
|
-
orderType: ConditionalOrderType,
|
|
181
|
-
triggerPrice: number,
|
|
182
|
-
exchangeId: number,
|
|
183
|
-
counterpartyAccountIds: number[],
|
|
184
|
-
amountInBase?: number,
|
|
185
|
-
): Promise<{
|
|
186
|
-
signature: string;
|
|
187
|
-
actualAmountInBase: number;
|
|
188
|
-
orderPriceLimit: bigint;
|
|
189
|
-
nonce: bigint;
|
|
190
|
-
deadline: number;
|
|
191
|
-
creationTimestampMs: number;
|
|
192
|
-
}> {
|
|
193
|
-
let inputs: string;
|
|
194
|
-
let actualAmountInBase: number;
|
|
195
|
-
let isLongOrder: boolean;
|
|
196
|
-
let orderPriceLimit: bigint;
|
|
197
|
-
|
|
198
|
-
if (orderType === ConditionalOrderType.LIMIT_ORDER) {
|
|
199
|
-
if (amountInBase === undefined) {
|
|
200
|
-
throw new Error('Order base is required for limit orders');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (amountInBase === 0) {
|
|
204
|
-
throw new Error('Cannot create an empty limit order');
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
actualAmountInBase = amountInBase;
|
|
208
|
-
isLongOrder = actualAmountInBase > 0;
|
|
209
|
-
orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
|
|
210
|
-
|
|
211
|
-
inputs = AbiCoder.defaultAbiCoder().encode(
|
|
212
|
-
['int256', 'uint256'],
|
|
213
|
-
[scale(18)(amountInBase), scale(18)(triggerPrice)],
|
|
214
|
-
);
|
|
215
|
-
} else {
|
|
216
|
-
const position = await this.getPosition(accountId, marketId);
|
|
217
|
-
const positionBase = position.base;
|
|
218
|
-
|
|
219
|
-
if (positionBase === 0) {
|
|
220
|
-
throw new Error('Cannot create SL or TP order for closed positions');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
actualAmountInBase = -positionBase;
|
|
224
|
-
isLongOrder = actualAmountInBase > 0;
|
|
225
|
-
orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
|
|
226
|
-
|
|
227
|
-
inputs = AbiCoder.defaultAbiCoder().encode(
|
|
228
|
-
['bool', 'uint256', 'uint256'],
|
|
229
|
-
[isLongOrder, scale(18)(triggerPrice), orderPriceLimit],
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const creationTimestampMs = Date.now();
|
|
234
|
-
const { serializedSignature, nonce } = await signOrdersGatewayOrder(
|
|
235
|
-
signer,
|
|
236
|
-
this.reyaChainId,
|
|
237
|
-
accountId,
|
|
238
|
-
marketId,
|
|
239
|
-
exchangeId,
|
|
240
|
-
counterpartyAccountIds,
|
|
241
|
-
orderType,
|
|
242
|
-
inputs,
|
|
243
|
-
CONDITIONAL_ORDER_SIG_DEADLINE,
|
|
244
|
-
creationTimestampMs,
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
signature: serializedSignature,
|
|
249
|
-
actualAmountInBase,
|
|
250
|
-
orderPriceLimit,
|
|
251
|
-
nonce,
|
|
252
|
-
deadline: CONDITIONAL_ORDER_SIG_DEADLINE,
|
|
253
|
-
creationTimestampMs,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConditionalOrder,
|
|
3
|
-
UnifiedConditionalOrderType,
|
|
4
|
-
ConditionalOrderType,
|
|
5
|
-
} from '@reyaxyz/common';
|
|
6
|
-
import { Signer, JsonRpcSigner } from 'ethers';
|
|
7
|
-
import { MarketEntity } from '@reyaxyz/common';
|
|
8
|
-
|
|
9
|
-
export type CancelConditionalOrderParams = {
|
|
10
|
-
signer: Signer | JsonRpcSigner;
|
|
11
|
-
orderId: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type CancelConditionalOrderResult = ConditionalOrder;
|
|
15
|
-
|
|
16
|
-
export type ConditionalOrderDetails = {
|
|
17
|
-
accountId: number;
|
|
18
|
-
marketId: number;
|
|
19
|
-
exchangeId: number;
|
|
20
|
-
counterpartyAccountIds: number[];
|
|
21
|
-
orderType: number;
|
|
22
|
-
inputs: string;
|
|
23
|
-
signer: string;
|
|
24
|
-
nonce: bigint;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type OrderSupportingParams = {
|
|
28
|
-
exchangeId: MarketEntity['orderInfo']['exchangeId'];
|
|
29
|
-
counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type RegisterConditionalOrderParams = {
|
|
33
|
-
signer: Signer | JsonRpcSigner;
|
|
34
|
-
marginAccountId: number;
|
|
35
|
-
triggerPrice: number;
|
|
36
|
-
orderType: ConditionalOrderType;
|
|
37
|
-
marketId: number;
|
|
38
|
-
supportingParams: OrderSupportingParams;
|
|
39
|
-
amountInBase?: number;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export type UpdateConditionalOrderParams = {
|
|
43
|
-
cancelOrderId: string;
|
|
44
|
-
} & RegisterConditionalOrderParams;
|
|
45
|
-
|
|
46
|
-
export type RegisterConditionalOrderResult = ConditionalOrder;
|
|
47
|
-
export type UpdateConditionalOrderResult = ConditionalOrder;
|
|
48
|
-
|
|
49
|
-
export type AlreadyGaveTradePermissionParams = {
|
|
50
|
-
accountId: number;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type AlreadyGaveTradePermissionResult = {
|
|
54
|
-
permissionGiven: boolean;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// ---- Conditional Orders History ---
|
|
58
|
-
export type GetConditionalOrdersHistoryForMarginAccountParams = {
|
|
59
|
-
address: string;
|
|
60
|
-
marginAccountId: number;
|
|
61
|
-
limit?: number;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type GetConditionalOrdersHistoryForWalletAddressParams = {
|
|
65
|
-
walletAddress: string;
|
|
66
|
-
limit?: number;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export type GetConditionalOrdersHistoryForMarginAccountResult =
|
|
70
|
-
UnifiedConditionalOrderType[];
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { RestClient } from '@reyaxyz/common';
|
|
2
|
-
|
|
3
|
-
export default class ReferralClient extends RestClient {
|
|
4
|
-
async propagateReferralOnChain(
|
|
5
|
-
walletAddress: string,
|
|
6
|
-
accountId?: number,
|
|
7
|
-
marketId?: number,
|
|
8
|
-
) {
|
|
9
|
-
const uri = `/api/referral/propagate-referral-on-chain`;
|
|
10
|
-
return this.post<void>(uri, {
|
|
11
|
-
walletAddress,
|
|
12
|
-
accountId,
|
|
13
|
-
marketId,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|