@reyaxyz/api-sdk 0.157.0 → 0.159.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 -60
- package/dist/clients/api-client.js.map +1 -1
- package/dist/clients/modules/account/index.js +33 -94
- package/dist/clients/modules/account/index.js.map +1 -1
- package/dist/clients/modules/account/types.js.map +1 -1
- package/dist/clients/modules/auth/types.js.map +1 -1
- package/dist/clients/modules/conditional-orders/types.js.map +1 -1
- package/dist/clients/modules/deposit-existing-MA.simulation/types.js.map +1 -1
- package/dist/clients/modules/edit-collateral.simulation/types.js.map +1 -1
- package/dist/clients/modules/markets/index.js +0 -15
- package/dist/clients/modules/markets/index.js.map +1 -1
- package/dist/clients/modules/owner/index.js +0 -36
- package/dist/clients/modules/owner/index.js.map +1 -1
- package/dist/clients/modules/transfer-MA-Pool.simulation/types.js.map +1 -1
- package/dist/clients/modules/transfer-margin-between-MAs.simulation/types.js.map +1 -1
- package/dist/clients/modules/withdraw-MA.simulation/types.js.map +1 -1
- package/dist/clients/types.js +0 -3
- package/dist/clients/types.js.map +1 -1
- package/dist/types/clients/api-client.d.ts +0 -42
- package/dist/types/clients/api-client.d.ts.map +1 -1
- package/dist/types/clients/modules/account/index.d.ts +2 -10
- package/dist/types/clients/modules/account/index.d.ts.map +1 -1
- package/dist/types/clients/modules/account/types.d.ts +24 -24
- package/dist/types/clients/modules/account/types.d.ts.map +1 -1
- package/dist/types/clients/modules/auth/types.d.ts +1 -2
- package/dist/types/clients/modules/auth/types.d.ts.map +1 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts +3 -3
- package/dist/types/clients/modules/conditional-orders/types.d.ts.map +1 -1
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts +3 -3
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts +4 -4
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/markets/index.d.ts +1 -2
- package/dist/types/clients/modules/markets/index.d.ts.map +1 -1
- package/dist/types/clients/modules/owner/index.d.ts +1 -5
- package/dist/types/clients/modules/owner/index.d.ts.map +1 -1
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/types.d.ts +3 -3
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/types.d.ts +7 -7
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts +3 -3
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/socket-client.d.ts +1 -1
- package/dist/types/clients/types.d.ts +1 -4
- package/dist/types/clients/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/clients/api-client.ts +0 -58
- package/src/clients/modules/account/index.ts +34 -90
- package/src/clients/modules/account/types.ts +25 -24
- package/src/clients/modules/auth/types.ts +1 -2
- package/src/clients/modules/conditional-orders/types.ts +3 -3
- package/src/clients/modules/deposit-existing-MA.simulation/types.ts +3 -3
- package/src/clients/modules/edit-collateral.simulation/types.ts +4 -4
- package/src/clients/modules/markets/index.ts +1 -12
- package/src/clients/modules/owner/index.ts +0 -36
- package/src/clients/modules/transfer-MA-Pool.simulation/types.ts +3 -3
- package/src/clients/modules/transfer-margin-between-MAs.simulation/types.ts +7 -7
- package/src/clients/modules/withdraw-MA.simulation/types.ts +3 -3
- package/src/clients/types.ts +1 -4
- package/dist/clients/modules/isolated-order.simulation/index.js +0 -302
- package/dist/clients/modules/isolated-order.simulation/index.js.map +0 -1
- package/dist/clients/modules/isolated-order.simulation/types.js +0 -3
- package/dist/clients/modules/isolated-order.simulation/types.js.map +0 -1
- package/dist/clients/modules/rage-trade/index.js +0 -99
- package/dist/clients/modules/rage-trade/index.js.map +0 -1
- package/dist/clients/modules/rage-trade/types.js +0 -3
- package/dist/clients/modules/rage-trade/types.js.map +0 -1
- package/dist/clients/modules/trade.simulation/index.js +0 -331
- package/dist/clients/modules/trade.simulation/index.js.map +0 -1
- package/dist/clients/modules/trade.simulation/types.js +0 -3
- package/dist/clients/modules/trade.simulation/types.js.map +0 -1
- package/dist/clients/modules/trade.simulation/utils.js +0 -35
- package/dist/clients/modules/trade.simulation/utils.js.map +0 -1
- package/dist/types/clients/modules/isolated-order.simulation/index.d.ts +0 -24
- package/dist/types/clients/modules/isolated-order.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/isolated-order.simulation/types.d.ts +0 -44
- package/dist/types/clients/modules/isolated-order.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/rage-trade/index.d.ts +0 -9
- package/dist/types/clients/modules/rage-trade/index.d.ts.map +0 -1
- package/dist/types/clients/modules/rage-trade/types.d.ts +0 -80
- package/dist/types/clients/modules/rage-trade/types.d.ts.map +0 -1
- package/dist/types/clients/modules/trade.simulation/index.d.ts +0 -22
- package/dist/types/clients/modules/trade.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/trade.simulation/types.d.ts +0 -85
- package/dist/types/clients/modules/trade.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/trade.simulation/utils.d.ts +0 -8
- package/dist/types/clients/modules/trade.simulation/utils.d.ts.map +0 -1
- package/src/clients/modules/isolated-order.simulation/index.ts +0 -490
- package/src/clients/modules/isolated-order.simulation/types.ts +0 -55
- package/src/clients/modules/rage-trade/index.ts +0 -38
- package/src/clients/modules/rage-trade/types.ts +0 -91
- package/src/clients/modules/trade.simulation/index.ts +0 -534
- package/src/clients/modules/trade.simulation/types.ts +0 -98
- package/src/clients/modules/trade.simulation/utils.ts +0 -52
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AddFavoriteMarketParams,
|
|
3
|
-
AddFavoriteMarketResult,
|
|
4
|
-
GetAccountOwnerMetadataParams,
|
|
5
|
-
GetAccountOwnerMetadataResult,
|
|
6
|
-
GetOwnerConfigurationSettingsParams,
|
|
7
|
-
GetOwnerConfigurationSettingsResult,
|
|
8
2
|
GetOwnerLastSeenNotificationTimestampParams,
|
|
9
3
|
GetOwnerLastSeenNotificationTimestampResult,
|
|
10
4
|
GetOwnerMetadataParams,
|
|
11
5
|
GetOwnerMetadataResult,
|
|
12
|
-
RemoveFavoriteMarketParams,
|
|
13
|
-
RemoveFavoriteMarketResult,
|
|
14
6
|
SetOwnerLastSeenNotificationTimestampParams,
|
|
15
7
|
SetOwnerLastSeenNotificationTimestampResult,
|
|
16
8
|
} from './types';
|
|
@@ -24,34 +16,6 @@ export default class OwnerClient extends RestClient {
|
|
|
24
16
|
return this.get(uri);
|
|
25
17
|
}
|
|
26
18
|
|
|
27
|
-
async getAccountOwnerMetadata(
|
|
28
|
-
params: GetAccountOwnerMetadataParams,
|
|
29
|
-
): Promise<GetAccountOwnerMetadataResult> {
|
|
30
|
-
const uri = `/api/owner/${params.accountId}/account-owner-metadata`;
|
|
31
|
-
return this.get(uri);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async getOwnerConfigurationSettings(
|
|
35
|
-
params: GetOwnerConfigurationSettingsParams,
|
|
36
|
-
): Promise<GetOwnerConfigurationSettingsResult> {
|
|
37
|
-
const uri = `/api/owner/${params.ownerAddress}/configuration/settings`;
|
|
38
|
-
return this.get(uri);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async addFavoriteMarket(
|
|
42
|
-
params: AddFavoriteMarketParams,
|
|
43
|
-
): Promise<AddFavoriteMarketResult> {
|
|
44
|
-
const uri = `/api/owner/${params.ownerAddress}/configuration/favorite-market`;
|
|
45
|
-
return this.post(uri, undefined, params);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async removeFavoriteMarket(
|
|
49
|
-
params: RemoveFavoriteMarketParams,
|
|
50
|
-
): Promise<RemoveFavoriteMarketResult> {
|
|
51
|
-
const uri = `/api/owner/${params.ownerAddress}/configuration/favorite-market`;
|
|
52
|
-
return this.delete(uri, undefined, params);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
19
|
async getOwnerLastSeenNotificationTimestamp(
|
|
56
20
|
params: GetOwnerLastSeenNotificationTimestampParams,
|
|
57
21
|
): Promise<GetOwnerLastSeenNotificationTimestampResult> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MarginRatioHealth, TokenEntity } from '@reyaxyz/common';
|
|
2
2
|
import { EditCollateralSimulationLoadDataParams } from '../edit-collateral.simulation/types';
|
|
3
3
|
|
|
4
4
|
export type TransferMAPoolSimulationLoadDataParams =
|
|
@@ -10,6 +10,6 @@ export type TransferMAPoolSimulationSimulateParams = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export type SimulateTransferMAPoolEntity = {
|
|
13
|
-
marginRatio:
|
|
14
|
-
marginRatioHealth:
|
|
13
|
+
marginRatio: number;
|
|
14
|
+
marginRatioHealth: MarginRatioHealth;
|
|
15
15
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MarginRatioHealth, TokenEntity } from '@reyaxyz/common';
|
|
2
2
|
|
|
3
3
|
export type TransferMarginBetweenMAsSimulationLoadDataParams = {
|
|
4
|
-
fromMarginAccountId:
|
|
5
|
-
toMarginAccountId:
|
|
4
|
+
fromMarginAccountId: number;
|
|
5
|
+
toMarginAccountId: number;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export type TransferMarginBetweenMAsSimulationSimulateParams = {
|
|
@@ -11,8 +11,8 @@ export type TransferMarginBetweenMAsSimulationSimulateParams = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export type SimulateTransferMarginBetweenMAsEntity = {
|
|
14
|
-
fromMarginRatio:
|
|
15
|
-
fromMarginRatioHealth:
|
|
16
|
-
toMarginRatio:
|
|
17
|
-
toMarginRatioHealth:
|
|
14
|
+
fromMarginRatio: number;
|
|
15
|
+
fromMarginRatioHealth: MarginRatioHealth;
|
|
16
|
+
toMarginRatio: number;
|
|
17
|
+
toMarginRatioHealth: MarginRatioHealth;
|
|
18
18
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
MarginRatioHealth,
|
|
3
3
|
MoneyInOutChainId,
|
|
4
4
|
TokenEntity,
|
|
5
5
|
} from '@reyaxyz/common';
|
|
@@ -18,6 +18,6 @@ export type WithdrawMASimulationSimulateParams = {
|
|
|
18
18
|
export type SimulateWithdrawMAEntity = {
|
|
19
19
|
socketWithdrawFees: SocketWithdrawFees;
|
|
20
20
|
bridgeTimeInMS: number;
|
|
21
|
-
marginRatio:
|
|
22
|
-
marginRatioHealth:
|
|
21
|
+
marginRatio: number;
|
|
22
|
+
marginRatioHealth: MarginRatioHealth;
|
|
23
23
|
};
|
package/src/clients/types.ts
CHANGED
|
@@ -10,7 +10,7 @@ export {
|
|
|
10
10
|
TransactionHistoryType,
|
|
11
11
|
MarginAccountTransactionHistoryType,
|
|
12
12
|
MarginAccountTransactionHistoryEntity,
|
|
13
|
-
|
|
13
|
+
StrippedMarginAccountEntity,
|
|
14
14
|
LpPositionEntity,
|
|
15
15
|
LpPoolEntity,
|
|
16
16
|
ReyaChainId,
|
|
@@ -33,7 +33,6 @@ export * from './modules/conditional-orders/types';
|
|
|
33
33
|
export * from './modules/lp/types';
|
|
34
34
|
export * from './modules/markets/types';
|
|
35
35
|
export * from './modules/tokens/types';
|
|
36
|
-
export * from './modules/trade.simulation/types';
|
|
37
36
|
export * from './modules/owner/types';
|
|
38
37
|
export * from './modules/deposit-existing-MA.simulation/types';
|
|
39
38
|
export * from './modules/deposit-new-MA.simulation/types';
|
|
@@ -46,5 +45,3 @@ export * from './modules/transfer-MA-Pool.simulation/types';
|
|
|
46
45
|
export * from './modules/funding-rate/types';
|
|
47
46
|
export * from './modules/depth-chart.simulation/types';
|
|
48
47
|
export * from './modules/deposit-passive-pool.simulation/types';
|
|
49
|
-
export * from './modules/isolated-order.simulation/types';
|
|
50
|
-
export * from './modules/rage-trade/types';
|
|
@@ -1,302 +0,0 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var common_1 = require("@reyaxyz/common");
|
|
43
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
44
|
-
var common_2 = require("@reyaxyz/common");
|
|
45
|
-
var utils_1 = require("../trade.simulation/utils");
|
|
46
|
-
var IsolatedOrderSimulationClient = /** @class */ (function () {
|
|
47
|
-
function IsolatedOrderSimulationClient(accountClient) {
|
|
48
|
-
this.loadedData = null;
|
|
49
|
-
this.marketId = null;
|
|
50
|
-
// Constructor added
|
|
51
|
-
this.accountClient = accountClient;
|
|
52
|
-
}
|
|
53
|
-
// Method to asynchronously load data based on marketId and accountId
|
|
54
|
-
IsolatedOrderSimulationClient.prototype.arm = function (params) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var _a;
|
|
57
|
-
return __generator(this, function (_b) {
|
|
58
|
-
switch (_b.label) {
|
|
59
|
-
case 0:
|
|
60
|
-
this.marketId = params.marketId;
|
|
61
|
-
_a = this;
|
|
62
|
-
return [4 /*yield*/, this.fetchMarketData(params.marketId, params.marginAccountId)];
|
|
63
|
-
case 1:
|
|
64
|
-
_a.loadedData = _b.sent();
|
|
65
|
-
return [2 /*return*/];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
IsolatedOrderSimulationClient.genExposureCommandObject = function (exposureCommandState) {
|
|
71
|
-
return new common_1.ExposureCommand(exposureCommandState.accountId, exposureCommandState.rootCollateralPoolId, exposureCommandState.oraclePricePerMarket, exposureCommandState.accountBalancePerAsset, exposureCommandState.groupedByCollateral, exposureCommandState.riskMultipliers, exposureCommandState.riskMatrices, exposureCommandState.exchangeInfoPerAsset, exposureCommandState.positionInfoMarketConfiguration, exposureCommandState.uniqueTokenAddresses, exposureCommandState.uniqueQuoteCollaterals, exposureCommandState.tokenMarginInfoPerAsset, exposureCommandState.realizedPnLSum, exposureCommandState.unrealizedPnLSum, exposureCommandState.mtmRpnlSum, exposureCommandState.collateralAddressToExchangePrice);
|
|
72
|
-
};
|
|
73
|
-
IsolatedOrderSimulationClient.prototype.fetchMarketData = function (marketId, accountId) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
-
return __generator(this, function (_a) {
|
|
76
|
-
return [2 /*return*/, this.accountClient.getTransactionSimulationInitialData({
|
|
77
|
-
marginAccountId: accountId,
|
|
78
|
-
marketId: marketId,
|
|
79
|
-
})];
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
// Synchronous method to simulate operations
|
|
84
|
-
IsolatedOrderSimulationClient.prototype.simulate = function (params) {
|
|
85
|
-
if (!this.loadedData || !this.marketId) {
|
|
86
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
87
|
-
}
|
|
88
|
-
var oraclePrice = this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id];
|
|
89
|
-
var amount;
|
|
90
|
-
if (params.fromBase) {
|
|
91
|
-
amount = params.amount;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
amount = (0, bignumber_js_1.default)(params.amount).div(oraclePrice).toNumber();
|
|
95
|
-
}
|
|
96
|
-
var userAccountExposure = IsolatedOrderSimulationClient.genExposureCommandObject(this.loadedData.exposureDataAccount);
|
|
97
|
-
var passivePoolExposure = IsolatedOrderSimulationClient.genExposureCommandObject(this.loadedData.exposureDataPassivePool);
|
|
98
|
-
var slippage = passivePoolExposure.getSlippage((0, bignumber_js_1.default)(amount).negated().toNumber(), this.loadedData.marketConfiguration, this.loadedData.marketStorage);
|
|
99
|
-
var estimatedPrice = common_1.ExposureCommand.calculateEstimatedPrice(oraclePrice, slippage);
|
|
100
|
-
var amountSize = estimatedPrice * amount;
|
|
101
|
-
var feesV2 = (0, utils_1.computeFee)({
|
|
102
|
-
tradeSimulationState: this.loadedData,
|
|
103
|
-
marketId: this.marketId,
|
|
104
|
-
orderBase: amount,
|
|
105
|
-
});
|
|
106
|
-
/*
|
|
107
|
-
amount of margin in rUSD terms that needs to be transferred from the source account to the destination account,
|
|
108
|
-
this value is equal to absolute size in rUSD terms / leverage
|
|
109
|
-
*/
|
|
110
|
-
var requiredMargin = (0, bignumber_js_1.default)(amountSize)
|
|
111
|
-
.abs()
|
|
112
|
-
.div((0, bignumber_js_1.default)(params.isolatedPositionLeverage))
|
|
113
|
-
.toNumber();
|
|
114
|
-
var editCollateralActions = userAccountExposure.getEditCollateralActionsToCoverMargin(requiredMargin);
|
|
115
|
-
var newMarginInfoSource = userAccountExposure.getUsdNodeMarginInfoPostEditCollaterals(editCollateralActions);
|
|
116
|
-
/*
|
|
117
|
-
* Compute Isolated Account Liquidation Margin Requirement Post Transfer + Trade
|
|
118
|
-
* */
|
|
119
|
-
var isolatedLMR = this.calculateIsolatedLMR(amountSize);
|
|
120
|
-
/*
|
|
121
|
-
* margin balance of the destination account is the requiredMargin which is expected to be transferred
|
|
122
|
-
* to the destination account that performs the isolated trade
|
|
123
|
-
* the liquidation price in this case is trying to estimate what the liquidation price would be all else equal for
|
|
124
|
-
* the market where the trade is being made by the isolated account that is going to be created as part of isolated
|
|
125
|
-
* trade operation
|
|
126
|
-
* */
|
|
127
|
-
var liquidationPrice = common_1.ExposureCommand.calculateLiquidation(requiredMargin, isolatedLMR, oraclePrice, amount);
|
|
128
|
-
// todo: p1: margin ratio seems to be wrong on ui
|
|
129
|
-
var marginRatio = common_1.ExposureCommand.getMarginRatio(newMarginInfoSource);
|
|
130
|
-
var marginRatioHealth = common_1.ExposureCommand.evaluateHealthStatus(marginRatio * 100);
|
|
131
|
-
var baseSpacing = (0, common_1.amountNormalizer)(this.loadedData.marketConfiguration.base_spacing).toNumber();
|
|
132
|
-
var snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);
|
|
133
|
-
var snappedAmount = snappedAmountInBase * estimatedPrice;
|
|
134
|
-
var xpEarnRangeMin = Math.round(Math.abs(snappedAmount) / common_2.INSTANT_TRADING_RATE_XP);
|
|
135
|
-
var xpEarnRangeMax = Math.round((100 * Math.abs(snappedAmount)) / common_2.INSTANT_TRADING_RATE_XP);
|
|
136
|
-
return {
|
|
137
|
-
estimatedPrice: estimatedPrice,
|
|
138
|
-
estimatedSlippage: slippage * 100,
|
|
139
|
-
fees: feesV2.fee,
|
|
140
|
-
takerFeesPercentage: feesV2.feePercentage,
|
|
141
|
-
feesV2: feesV2,
|
|
142
|
-
liquidationPrice: liquidationPrice.toNumber(),
|
|
143
|
-
marginRatio: marginRatio * 100,
|
|
144
|
-
marginRatioHealth: marginRatioHealth,
|
|
145
|
-
snappedAmount: snappedAmount,
|
|
146
|
-
snappedAmountInBase: snappedAmountInBase,
|
|
147
|
-
requiredMargin: requiredMargin,
|
|
148
|
-
editCollateralActions: editCollateralActions,
|
|
149
|
-
xpEarnRange: {
|
|
150
|
-
min: xpEarnRangeMin,
|
|
151
|
-
max: xpEarnRangeMax,
|
|
152
|
-
},
|
|
153
|
-
maxSlippage: 1,
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
IsolatedOrderSimulationClient.prototype.convertValue = function (params) {
|
|
157
|
-
if (!this.loadedData) {
|
|
158
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
159
|
-
}
|
|
160
|
-
if (!params.fromBase)
|
|
161
|
-
return (0, bignumber_js_1.default)(params.amount)
|
|
162
|
-
.div(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id])
|
|
163
|
-
.toNumber();
|
|
164
|
-
else
|
|
165
|
-
return (0, bignumber_js_1.default)(params.amount)
|
|
166
|
-
.times(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id])
|
|
167
|
-
.toNumber();
|
|
168
|
-
};
|
|
169
|
-
IsolatedOrderSimulationClient.prototype.convertValueEstimatedPrice = function (params) {
|
|
170
|
-
if (!this.loadedData) {
|
|
171
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
172
|
-
}
|
|
173
|
-
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, this.loadedData.exposureDataPassivePool.rootCollateralPoolId, this.loadedData.exposureDataPassivePool.oraclePricePerMarket, this.loadedData.exposureDataPassivePool.accountBalancePerAsset, this.loadedData.exposureDataPassivePool.groupedByCollateral, this.loadedData.exposureDataPassivePool.riskMultipliers, this.loadedData.exposureDataPassivePool.riskMatrices, this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset, this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration, this.loadedData.exposureDataPassivePool.uniqueTokenAddresses, this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals, this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset, this.loadedData.exposureDataPassivePool.realizedPnLSum, this.loadedData.exposureDataPassivePool.unrealizedPnLSum, this.loadedData.exposureDataPassivePool.mtmRpnlSum, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
174
|
-
var amountForSlippage = params.fromBase
|
|
175
|
-
? params.amount
|
|
176
|
-
: (0, bignumber_js_1.default)(params.amount)
|
|
177
|
-
.div(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id])
|
|
178
|
-
.toNumber();
|
|
179
|
-
var slippage = passivePoolExposure.getSlippage((0, bignumber_js_1.default)(amountForSlippage).negated().toNumber(), this.loadedData.marketConfiguration, this.loadedData.marketStorage);
|
|
180
|
-
var estimatedPrice = common_1.ExposureCommand.calculateEstimatedPrice(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], slippage);
|
|
181
|
-
if (!params.fromBase)
|
|
182
|
-
return (0, bignumber_js_1.default)(params.amount).div(estimatedPrice).toNumber();
|
|
183
|
-
else
|
|
184
|
-
return (0, bignumber_js_1.default)(params.amount).times(estimatedPrice).toNumber();
|
|
185
|
-
};
|
|
186
|
-
IsolatedOrderSimulationClient.prototype.customLeverage = function () {
|
|
187
|
-
if (!this.loadedData) {
|
|
188
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
189
|
-
}
|
|
190
|
-
var customLeverage = this.loadedData.customLeverage;
|
|
191
|
-
return customLeverage;
|
|
192
|
-
};
|
|
193
|
-
IsolatedOrderSimulationClient.prototype.estimatedPrice = function (params) {
|
|
194
|
-
if (!this.loadedData) {
|
|
195
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
196
|
-
}
|
|
197
|
-
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, this.loadedData.exposureDataPassivePool.rootCollateralPoolId, this.loadedData.exposureDataPassivePool.oraclePricePerMarket, this.loadedData.exposureDataPassivePool.accountBalancePerAsset, this.loadedData.exposureDataPassivePool.groupedByCollateral, this.loadedData.exposureDataPassivePool.riskMultipliers, this.loadedData.exposureDataPassivePool.riskMatrices, this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset, this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration, this.loadedData.exposureDataPassivePool.uniqueTokenAddresses, this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals, this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset, this.loadedData.exposureDataPassivePool.realizedPnLSum, this.loadedData.exposureDataPassivePool.unrealizedPnLSum, this.loadedData.exposureDataPassivePool.mtmRpnlSum, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
198
|
-
var slippage = passivePoolExposure.getSlippage((0, bignumber_js_1.default)(params.amount).negated().toNumber(), this.loadedData.marketConfiguration, this.loadedData.marketStorage);
|
|
199
|
-
var price = this.loadedData.exposureDataAccount.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id];
|
|
200
|
-
var estimatedPrice = common_1.ExposureCommand.calculateEstimatedPrice(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], slippage);
|
|
201
|
-
return {
|
|
202
|
-
estimatedPrice: estimatedPrice,
|
|
203
|
-
markPrice: price,
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
IsolatedOrderSimulationClient.prototype.roundToBaseSpacing = function (amount, baseSpacing) {
|
|
207
|
-
var snappedAmount = (0, bignumber_js_1.default)(amount)
|
|
208
|
-
.abs()
|
|
209
|
-
.dividedBy(baseSpacing)
|
|
210
|
-
.integerValue(bignumber_js_1.default.ROUND_FLOOR)
|
|
211
|
-
.multipliedBy(baseSpacing)
|
|
212
|
-
.toNumber();
|
|
213
|
-
if (amount < 0) {
|
|
214
|
-
return -snappedAmount;
|
|
215
|
-
}
|
|
216
|
-
return snappedAmount;
|
|
217
|
-
};
|
|
218
|
-
IsolatedOrderSimulationClient.prototype.amountToSnappedAmount = function (amountInRusd, spotPrice, baseSpacing) {
|
|
219
|
-
var amountInBase = (0, bignumber_js_1.default)(amountInRusd)
|
|
220
|
-
.div((0, bignumber_js_1.default)(spotPrice))
|
|
221
|
-
.toNumber();
|
|
222
|
-
return this.roundToBaseSpacing(amountInBase, baseSpacing) * spotPrice;
|
|
223
|
-
};
|
|
224
|
-
IsolatedOrderSimulationClient.prototype.calculateIsolatedLMR = function (isolatedExposure) {
|
|
225
|
-
var _this = this;
|
|
226
|
-
// todo: p2: consider removing the need to load the entire data just to get a few vars to calc leverage bounds
|
|
227
|
-
if (!this.loadedData) {
|
|
228
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
229
|
-
}
|
|
230
|
-
if (!this.loadedData.marketStorage) {
|
|
231
|
-
throw new Error('Market storage not loaded');
|
|
232
|
-
}
|
|
233
|
-
// todo: p2: carefully test
|
|
234
|
-
var marketRiskMatrix = this.loadedData.exposureDataAccount.riskMatrices.find(function (riskMatrix) {
|
|
235
|
-
var _a;
|
|
236
|
-
return (riskMatrix.risk_block_id ===
|
|
237
|
-
(0, bignumber_js_1.default)(String((_a = _this.loadedData) === null || _a === void 0 ? void 0 : _a.marketStorage.risk_block_id)).toNumber());
|
|
238
|
-
});
|
|
239
|
-
if (!marketRiskMatrix) {
|
|
240
|
-
throw new Error('Failed to load risk matrix');
|
|
241
|
-
}
|
|
242
|
-
var marketDiagonalRiskParam = marketRiskMatrix.matrix[this.loadedData.marketConfiguration.risk_matrix_index][this.loadedData.marketConfiguration.risk_matrix_index];
|
|
243
|
-
var isolatedRiskMatrix = [[marketDiagonalRiskParam]];
|
|
244
|
-
var isolatedFilledExposures = [(0, bignumber_js_1.default)(isolatedExposure)];
|
|
245
|
-
return common_1.ExposureCommand.computeLiquidationMarginRequirement(isolatedRiskMatrix, isolatedFilledExposures);
|
|
246
|
-
};
|
|
247
|
-
IsolatedOrderSimulationClient.prototype.leverageBoundsAndAvailableMargin = function (_a) {
|
|
248
|
-
var amountTradedInRusd = _a.amountTradedInRusd;
|
|
249
|
-
if (!this.loadedData) {
|
|
250
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
251
|
-
}
|
|
252
|
-
var spotPrice = this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id];
|
|
253
|
-
var baseSpacing = (0, common_1.amountNormalizer)(this.loadedData.marketConfiguration.base_spacing).toNumber();
|
|
254
|
-
var snappedAmountInRusd = this.amountToSnappedAmount(amountTradedInRusd, spotPrice, baseSpacing);
|
|
255
|
-
/*
|
|
256
|
-
todo: p2: consider introducing buffer to the leverage (e.g. to account for the effect of trade on upnl
|
|
257
|
-
and actually depending on the size of the trade the estimated price would change -> different upnl
|
|
258
|
-
as upnl is calculated against oracle prioce + rpnl is also affected through the fees
|
|
259
|
-
* once the trader knows their trade size (in base & rusd terms), they should be able to toggle isolated trade flow
|
|
260
|
-
* which will prompt the user to choose a desired leverage value
|
|
261
|
-
* 0.1 can be hardcoded to be the min bound
|
|
262
|
-
* to get the maximum bound we need to calculate leverage that can be achieved when IMR is reached for position
|
|
263
|
-
* with 1 rUSD exposure in the market -> max leverage = 1/IMR
|
|
264
|
-
* */
|
|
265
|
-
// set max bound
|
|
266
|
-
var lmrUnitExposure = this.calculateIsolatedLMR(1);
|
|
267
|
-
var imrUnitExposure = (0, common_1.amountNormalizer)(String(this.loadedData.exposureDataAccount.riskMultipliers.im_multiplier)).multipliedBy(lmrUnitExposure);
|
|
268
|
-
var maxBound = (0, bignumber_js_1.default)(1).dividedBy(imrUnitExposure).toNumber();
|
|
269
|
-
// set min bound
|
|
270
|
-
var userAccountExposure = IsolatedOrderSimulationClient.genExposureCommandObject(this.loadedData.exposureDataAccount);
|
|
271
|
-
/*
|
|
272
|
-
max amount of margin in rUSD terms that can be transferred from the source account to the destination account
|
|
273
|
-
that performs the isolated position trade
|
|
274
|
-
*/
|
|
275
|
-
var availableMargin = userAccountExposure.getUsdNodeMarginInfo.initialDelta;
|
|
276
|
-
var minBound = (0, bignumber_js_1.default)(snappedAmountInRusd)
|
|
277
|
-
.abs()
|
|
278
|
-
.dividedBy(availableMargin)
|
|
279
|
-
.toNumber();
|
|
280
|
-
if (minBound > maxBound) {
|
|
281
|
-
throw Error('Min leverage bound higher than max');
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
minBound: minBound,
|
|
285
|
-
maxBound: maxBound,
|
|
286
|
-
availableMargin: availableMargin,
|
|
287
|
-
};
|
|
288
|
-
};
|
|
289
|
-
IsolatedOrderSimulationClient.prototype.updatePrice = function (price) {
|
|
290
|
-
if (!this.loadedData || !this.marketId) {
|
|
291
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
292
|
-
}
|
|
293
|
-
// update price
|
|
294
|
-
var marketId = this.marketId;
|
|
295
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[marketId] =
|
|
296
|
-
price;
|
|
297
|
-
this.loadedData.exposureDataAccount.oraclePricePerMarket[marketId] = price;
|
|
298
|
-
};
|
|
299
|
-
return IsolatedOrderSimulationClient;
|
|
300
|
-
}());
|
|
301
|
-
exports.default = IsolatedOrderSimulationClient;
|
|
302
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,0CAMyB;AACzB,8DAAqC;AAQrC,0CAA0D;AAC1D,mDAAuD;AAEvD;IAKE,uCAAY,aAA4B;QAJhC,eAAU,GAAgC,IAAI,CAAC;QAE/C,aAAQ,GAAkB,IAAI,CAAC;QAGrC,oBAAoB;QACpB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,qEAAqE;IAC/D,2CAAG,GAAT,UAAU,MAA6C;;;;;;wBACrD,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;wBAChC,KAAA,IAAI,CAAA;wBAAc,qBAAM,IAAI,CAAC,eAAe,CAC1C,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,eAAe,CACvB,EAAA;;wBAHD,GAAK,UAAU,GAAG,SAGjB,CAAC;;;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QAAQ,GAAG,IAAA,sBAAS,EAAC,mBAAmB,CAAC;aAC5C,GAAG,EAAE;aACL,SAAS,CAAC,eAAe,CAAC;aAC1B,QAAQ,EAAE,CAAC;QAEd,IAAI,QAAQ,GAAG,QAAQ,EAAE,CAAC;YACxB,MAAM,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACpD,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ;YAClB,eAAe,EAAE,eAAe;SACjC,CAAC;IACJ,CAAC;IAED,mDAAW,GAAX,UAAY,KAAa;QACvB,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QACD,eAAe;QACf,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,QAAQ,CAAC;YACpE,KAAK,CAAC;QACR,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC7E,CAAC;IACH,oCAAC;AAAD,CAAC,AA7cD,IA6cC","sourcesContent":["import {\n SimulateIsolatedOrderEntity,\n IsolatedOrderSimulationConvertValueParams,\n IsolatedOrderSimulationConvertValueResult,\n IsolatedOrderSimulationLoadDataParams,\n IsolatedOrderSimulationSimulateParams,\n LeverageBoundsAndAvailableMarginResult,\n LeverageBoundsAndAvailableMarginParams,\n} from './types';\nimport AccountClient from '../account';\nimport {\n amountNormalizer,\n ExposureCommand,\n ExposureCommandState,\n RiskMatrix,\n TradeSimulationState,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { EditCollateralAction } from '@reyaxyz/common';\nimport {\n EstimatedPriceParams,\n EstimatedPriceResult,\n TradeSimulationConvertValueEstimatedPriceParams,\n TradeSimulationConvertValueResult,\n} from '../trade.simulation/types';\nimport { INSTANT_TRADING_RATE_XP } from '@reyaxyz/common';\nimport { computeFee } from '../trade.simulation/utils';\n\nexport default class IsolatedOrderSimulationClient {\n private loadedData: TradeSimulationState | null = null;\n private accountClient: AccountClient;\n private marketId: number | null = null;\n\n constructor(accountClient: AccountClient) {\n // Constructor added\n this.accountClient = accountClient;\n }\n\n // Method to asynchronously load data based on marketId and accountId\n async arm(params: IsolatedOrderSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n this.loadedData = await this.fetchMarketData(\n params.marketId,\n params.marginAccountId,\n );\n }\n\n static genExposureCommandObject(\n exposureCommandState: ExposureCommandState,\n ): ExposureCommand {\n return new ExposureCommand(\n exposureCommandState.accountId,\n exposureCommandState.rootCollateralPoolId,\n exposureCommandState.oraclePricePerMarket,\n exposureCommandState.accountBalancePerAsset,\n exposureCommandState.groupedByCollateral,\n exposureCommandState.riskMultipliers,\n exposureCommandState.riskMatrices,\n exposureCommandState.exchangeInfoPerAsset,\n exposureCommandState.positionInfoMarketConfiguration,\n exposureCommandState.uniqueTokenAddresses,\n exposureCommandState.uniqueQuoteCollaterals,\n exposureCommandState.tokenMarginInfoPerAsset,\n exposureCommandState.realizedPnLSum,\n exposureCommandState.unrealizedPnLSum,\n exposureCommandState.mtmRpnlSum,\n exposureCommandState.collateralAddressToExchangePrice,\n );\n }\n\n private async fetchMarketData(\n marketId: number,\n accountId: number,\n ): Promise<TradeSimulationState> {\n return this.accountClient.getTransactionSimulationInitialData({\n marginAccountId: accountId,\n marketId: marketId,\n });\n }\n\n // Synchronous method to simulate operations\n simulate(\n params: IsolatedOrderSimulationSimulateParams,\n ): SimulateIsolatedOrderEntity {\n if (!this.loadedData || !this.marketId) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const oraclePrice =\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n\n let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n amount = BigNumber(params.amount).div(oraclePrice).toNumber();\n }\n\n const userAccountExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataAccount,\n );\n\n const passivePoolExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataPassivePool,\n );\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amount).negated().toNumber(),\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n oraclePrice,\n slippage,\n );\n\n const amountSize = estimatedPrice * amount;\n\n const feesV2 = computeFee({\n tradeSimulationState: this.loadedData,\n marketId: this.marketId,\n orderBase: amount,\n });\n\n /*\n amount of margin in rUSD terms that needs to be transferred from the source account to the destination account,\n this value is equal to absolute size in rUSD terms / leverage\n */\n\n const requiredMargin = BigNumber(amountSize)\n .abs()\n .div(BigNumber(params.isolatedPositionLeverage))\n .toNumber();\n\n const editCollateralActions: EditCollateralAction[] =\n userAccountExposure.getEditCollateralActionsToCoverMargin(requiredMargin);\n\n const newMarginInfoSource =\n userAccountExposure.getUsdNodeMarginInfoPostEditCollaterals(\n editCollateralActions,\n );\n\n /*\n * Compute Isolated Account Liquidation Margin Requirement Post Transfer + Trade\n * */\n\n const isolatedLMR = this.calculateIsolatedLMR(amountSize);\n\n /*\n * margin balance of the destination account is the requiredMargin which is expected to be transferred\n * to the destination account that performs the isolated trade\n * the liquidation price in this case is trying to estimate what the liquidation price would be all else equal for\n * the market where the trade is being made by the isolated account that is going to be created as part of isolated\n * trade operation\n * */\n const liquidationPrice = ExposureCommand.calculateLiquidation(\n requiredMargin,\n isolatedLMR,\n oraclePrice,\n amount,\n );\n\n // todo: p1: margin ratio seems to be wrong on ui\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfoSource);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n\n const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);\n const snappedAmount = snappedAmountInBase * estimatedPrice;\n const xpEarnRangeMin = Math.round(\n Math.abs(snappedAmount) / INSTANT_TRADING_RATE_XP,\n );\n const xpEarnRangeMax = Math.round(\n (100 * Math.abs(snappedAmount)) / INSTANT_TRADING_RATE_XP,\n );\n\n return {\n estimatedPrice: estimatedPrice,\n estimatedSlippage: slippage * 100,\n fees: feesV2.fee,\n takerFeesPercentage: feesV2.feePercentage,\n feesV2,\n liquidationPrice: liquidationPrice.toNumber(),\n marginRatio: marginRatio * 100,\n marginRatioHealth: marginRatioHealth,\n snappedAmount,\n snappedAmountInBase,\n requiredMargin: requiredMargin,\n editCollateralActions: editCollateralActions,\n xpEarnRange: {\n min: xpEarnRangeMin,\n max: xpEarnRangeMax,\n },\n maxSlippage: 1,\n };\n }\n\n convertValue(\n params: IsolatedOrderSimulationConvertValueParams,\n ): IsolatedOrderSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!params.fromBase)\n return BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n else\n return BigNumber(params.amount)\n .times(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n }\n\n convertValueEstimatedPrice(\n params: TradeSimulationConvertValueEstimatedPriceParams,\n ): TradeSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\n this.loadedData.exposureDataPassivePool.rootCollateralPoolId,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket,\n this.loadedData.exposureDataPassivePool.accountBalancePerAsset,\n this.loadedData.exposureDataPassivePool.groupedByCollateral,\n this.loadedData.exposureDataPassivePool.riskMultipliers,\n this.loadedData.exposureDataPassivePool.riskMatrices,\n this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset,\n this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration,\n this.loadedData.exposureDataPassivePool.uniqueTokenAddresses,\n this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals,\n this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,\n this.loadedData.exposureDataPassivePool.realizedPnLSum,\n this.loadedData.exposureDataPassivePool.unrealizedPnLSum,\n this.loadedData.exposureDataPassivePool.mtmRpnlSum,\n this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n const amountForSlippage = params.fromBase\n ? params.amount\n : BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amountForSlippage).negated().toNumber(),\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n slippage,\n );\n\n if (!params.fromBase)\n return BigNumber(params.amount).div(estimatedPrice).toNumber();\n else return BigNumber(params.amount).times(estimatedPrice).toNumber();\n }\n\n customLeverage(): number | null {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n const { customLeverage } = this.loadedData;\n\n return customLeverage;\n }\n\n estimatedPrice(params: EstimatedPriceParams): EstimatedPriceResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\n this.loadedData.exposureDataPassivePool.rootCollateralPoolId,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket,\n this.loadedData.exposureDataPassivePool.accountBalancePerAsset,\n this.loadedData.exposureDataPassivePool.groupedByCollateral,\n this.loadedData.exposureDataPassivePool.riskMultipliers,\n this.loadedData.exposureDataPassivePool.riskMatrices,\n this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset,\n this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration,\n this.loadedData.exposureDataPassivePool.uniqueTokenAddresses,\n this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals,\n this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,\n this.loadedData.exposureDataPassivePool.realizedPnLSum,\n this.loadedData.exposureDataPassivePool.unrealizedPnLSum,\n this.loadedData.exposureDataPassivePool.mtmRpnlSum,\n this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(params.amount).negated().toNumber(),\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n\n const price =\n this.loadedData.exposureDataAccount.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n slippage,\n );\n\n return {\n estimatedPrice,\n markPrice: price,\n };\n }\n\n roundToBaseSpacing(amount: number, baseSpacing: number): number {\n const snappedAmount = BigNumber(amount)\n .abs()\n .dividedBy(baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(baseSpacing)\n .toNumber();\n\n if (amount < 0) {\n return -snappedAmount;\n }\n return snappedAmount;\n }\n\n amountToSnappedAmount(\n amountInRusd: number,\n spotPrice: number,\n baseSpacing: number,\n ): number {\n const amountInBase = BigNumber(amountInRusd)\n .div(BigNumber(spotPrice))\n .toNumber();\n\n return this.roundToBaseSpacing(amountInBase, baseSpacing) * spotPrice;\n }\n\n calculateIsolatedLMR(isolatedExposure: number): number {\n // todo: p2: consider removing the need to load the entire data just to get a few vars to calc leverage bounds\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!this.loadedData.marketStorage) {\n throw new Error('Market storage not loaded');\n }\n\n // todo: p2: carefully test\n const marketRiskMatrix =\n this.loadedData.exposureDataAccount.riskMatrices.find(\n (riskMatrix: RiskMatrix) => {\n return (\n riskMatrix.risk_block_id ===\n BigNumber(\n String(this.loadedData?.marketStorage.risk_block_id),\n ).toNumber()\n );\n },\n );\n\n if (!marketRiskMatrix) {\n throw new Error('Failed to load risk matrix');\n }\n\n const marketDiagonalRiskParam =\n marketRiskMatrix.matrix[\n this.loadedData.marketConfiguration.risk_matrix_index\n ][this.loadedData.marketConfiguration.risk_matrix_index];\n const isolatedRiskMatrix: BigNumber[][] = [[marketDiagonalRiskParam]];\n const isolatedFilledExposures: BigNumber[] = [BigNumber(isolatedExposure)];\n\n return ExposureCommand.computeLiquidationMarginRequirement(\n isolatedRiskMatrix,\n isolatedFilledExposures,\n );\n }\n\n leverageBoundsAndAvailableMargin({\n amountTradedInRusd,\n }: LeverageBoundsAndAvailableMarginParams): LeverageBoundsAndAvailableMarginResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const spotPrice =\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n const snappedAmountInRusd = this.amountToSnappedAmount(\n amountTradedInRusd,\n spotPrice,\n baseSpacing,\n );\n\n /*\n todo: p2: consider introducing buffer to the leverage (e.g. to account for the effect of trade on upnl\n and actually depending on the size of the trade the estimated price would change -> different upnl\n as upnl is calculated against oracle prioce + rpnl is also affected through the fees\n * once the trader knows their trade size (in base & rusd terms), they should be able to toggle isolated trade flow\n * which will prompt the user to choose a desired leverage value\n * 0.1 can be hardcoded to be the min bound\n * to get the maximum bound we need to calculate leverage that can be achieved when IMR is reached for position\n * with 1 rUSD exposure in the market -> max leverage = 1/IMR\n * */\n\n // set max bound\n\n const lmrUnitExposure = this.calculateIsolatedLMR(1);\n\n const imrUnitExposure: BigNumber = amountNormalizer(\n String(this.loadedData.exposureDataAccount.riskMultipliers.im_multiplier),\n ).multipliedBy(lmrUnitExposure);\n\n const maxBound = BigNumber(1).dividedBy(imrUnitExposure).toNumber();\n\n // set min bound\n\n const userAccountExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataAccount,\n );\n\n /*\n max amount of margin in rUSD terms that can be transferred from the source account to the destination account\n that performs the isolated position trade\n */\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const minBound = BigNumber(snappedAmountInRusd)\n .abs()\n .dividedBy(availableMargin)\n .toNumber();\n\n if (minBound > maxBound) {\n throw Error('Min leverage bound higher than max');\n }\n\n return {\n minBound: minBound,\n maxBound: maxBound,\n availableMargin: availableMargin,\n };\n }\n\n updatePrice(price: number): void {\n if (!this.loadedData || !this.marketId) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n // update price\n const marketId = this.marketId;\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[marketId] =\n price;\n this.loadedData.exposureDataAccount.oraclePricePerMarket[marketId] = price;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n MarginAccountEntity,\n MarketEntity,\n EditCollateralAction,\n} from '@reyaxyz/common';\nimport { SimulateTradeFeeEntity } from '../trade.simulation/types';\n\nexport type IsolatedOrderSimulationLoadDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type IsolatedOrderSimulationSimulateParams = {\n amount: number; // position size in rUSD / base terms, + for long | - for short\n isolatedPositionLeverage: number; // leverage chosen for isolated position trade\n fromBase?: boolean;\n};\n\nexport type IsolatedOrderSimulationConvertValueParams = {\n amount: number;\n fromBase: boolean;\n};\n\nexport type SimulateIsolatedOrderEntity = {\n liquidationPrice: number;\n fees: number;\n takerFeesPercentage: number;\n feesV2: SimulateTradeFeeEntity;\n estimatedPrice: number;\n estimatedSlippage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n snappedAmount: number;\n snappedAmountInBase: number;\n requiredMargin: number;\n editCollateralActions: EditCollateralAction[];\n maxSlippage: number;\n xpEarnRange?: {\n min: number;\n max: number;\n };\n};\n\nexport type IsolatedOrderSimulationConvertValueResult = number;\n\nexport type LeverageBoundsAndAvailableMarginResult = {\n minBound: number;\n maxBound: number;\n availableMargin: number;\n};\n\nexport type LeverageBoundsAndAvailableMarginParams = {\n // Note, this amount is not expected to be snapped\n amountTradedInRusd: number;\n};\n"]}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
var common_1 = require("@reyaxyz/common");
|
|
55
|
-
var RageTradeClient = /** @class */ (function (_super) {
|
|
56
|
-
__extends(RageTradeClient, _super);
|
|
57
|
-
function RageTradeClient() {
|
|
58
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
59
|
-
}
|
|
60
|
-
RageTradeClient.prototype.getRewardsPerEpochAndTier = function () {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
-
var uri;
|
|
63
|
-
return __generator(this, function (_a) {
|
|
64
|
-
uri = "/api/rage-trade/rewards-per-epoch-and-tier";
|
|
65
|
-
return [2 /*return*/, this.get(uri)];
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
RageTradeClient.prototype.getLeaderboardForEpochAndTier = function (params) {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var uri;
|
|
72
|
-
return __generator(this, function (_a) {
|
|
73
|
-
uri = "/api/rage-trade/leaderboard-for-epoch-and-tier/".concat(params.walletAddress, "?epochId=").concat(params.epochId, "&tierId=").concat(params.tierId, "&skip=").concat(params.skip, "&limit=").concat(params.limit);
|
|
74
|
-
return [2 /*return*/, this.get(uri)];
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
RageTradeClient.prototype.getLeaderboardDetailsForWalletAddress = function (params) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
-
var uri;
|
|
81
|
-
return __generator(this, function (_a) {
|
|
82
|
-
uri = "/api/rage-trade/leaderboard/".concat(params.walletAddress);
|
|
83
|
-
return [2 /*return*/, this.get(uri)];
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
RageTradeClient.prototype.getDailyVolumeForPeriod = function (params) {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
-
var uri;
|
|
90
|
-
return __generator(this, function (_a) {
|
|
91
|
-
uri = "/api/rage-trade/daily-volume-for-period?timestampFrom=".concat(params.timestampFrom, "×tampTo=").concat(params.timestampTo);
|
|
92
|
-
return [2 /*return*/, this.get(uri)];
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
return RageTradeClient;
|
|
97
|
-
}(common_1.RestClient));
|
|
98
|
-
exports.default = RageTradeClient;
|
|
99
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/rage-trade/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,0CAA6C;AAE7C;IAA6C,mCAAU;IAAvD;;IA0BA,CAAC;IAzBO,mDAAyB,GAA/B;;;;gBACQ,GAAG,GAAG,4CAA4C,CAAC;gBACzD,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,uDAA6B,GAAnC,UACE,MAAgD;;;;gBAE1C,GAAG,GAAG,yDAAkD,MAAM,CAAC,aAAa,sBAAY,MAAM,CAAC,OAAO,qBAAW,MAAM,CAAC,MAAM,mBAAS,MAAM,CAAC,IAAI,oBAAU,MAAM,CAAC,KAAK,CAAE,CAAC;gBACjL,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,+DAAqC,GAA3C,UACE,MAAqD;;;;gBAE/C,GAAG,GAAG,sCAA+B,MAAM,CAAC,aAAa,CAAE,CAAC;gBAClE,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,iDAAuB,GAA7B,UACE,MAA8C;;;;gBAExC,GAAG,GAAG,gEAAyD,MAAM,CAAC,aAAa,0BAAgB,MAAM,CAAC,WAAW,CAAE,CAAC;gBAC9H,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IACH,sBAAC;AAAD,CAAC,AA1BD,CAA6C,mBAAU,GA0BtD","sourcesContent":["import {\n GetRageTradeDailyVolumeForPeriodParams,\n GetRageTradeDailyVolumeForPeriodResult,\n GetRageTradeLeaderboardForEpochAndTierResult,\n GetRageTradeLeaderboardForWalletAddressParams,\n GetRageTradeLeaderboardForWalletAddressResult,\n GetRageTradeRewardsPerEpochAndTierParams,\n GetRageTradeRewardsPerEpochAndTierResult,\n} from './types';\nimport { RestClient } from '@reyaxyz/common';\n\nexport default class RageTradeClient extends RestClient {\n async getRewardsPerEpochAndTier(): Promise<GetRageTradeRewardsPerEpochAndTierResult> {\n const uri = `/api/rage-trade/rewards-per-epoch-and-tier`;\n return this.get(uri);\n }\n\n async getLeaderboardForEpochAndTier(\n params: GetRageTradeRewardsPerEpochAndTierParams,\n ): Promise<GetRageTradeLeaderboardForEpochAndTierResult> {\n const uri = `/api/rage-trade/leaderboard-for-epoch-and-tier/${params.walletAddress}?epochId=${params.epochId}&tierId=${params.tierId}&skip=${params.skip}&limit=${params.limit}`;\n return this.get(uri);\n }\n\n async getLeaderboardDetailsForWalletAddress(\n params: GetRageTradeLeaderboardForWalletAddressParams,\n ): Promise<GetRageTradeLeaderboardForWalletAddressResult> {\n const uri = `/api/rage-trade/leaderboard/${params.walletAddress}`;\n return this.get(uri);\n }\n\n async getDailyVolumeForPeriod(\n params: GetRageTradeDailyVolumeForPeriodParams,\n ): Promise<GetRageTradeDailyVolumeForPeriodResult> {\n const uri = `/api/rage-trade/daily-volume-for-period?timestampFrom=${params.timestampFrom}×tampTo=${params.timestampTo}`;\n return this.get(uri);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/rage-trade/types.ts"],"names":[],"mappings":"","sourcesContent":["export type GetRageTradeRewardsPerEpochAndTierResult = {\n rewards: RageTradeRewards[];\n collateralTierLimits: RageTradeCollateralTierLimits;\n};\n\nexport type RageTradeCollateralTierLimits = {\n '1': number;\n '2': number;\n '3': number;\n '4': number;\n};\n\nexport type RageTradeRewards = {\n epochId: number;\n startTimeStamp: number;\n endTimeStamp: number;\n competitionName: string;\n rewards: RageTradeReward[];\n};\n\nexport type RageTradeReward = {\n tierId: number;\n rewardsPerRank: RageTradeRewardsPerRank;\n};\n\nexport type RageTradeRewardsPerRank = {\n '1': number;\n '2': number;\n '3': number;\n '4': number;\n '5': number;\n '6': number;\n '7': number;\n '8': number;\n '9': number;\n '10': number;\n};\n\nexport type GetRageTradeLeaderboardForEpochAndTierResult = {\n totalCount: number;\n leaderboard: RageTradeLeaderboard[];\n maxCollateralAverage: number;\n};\n\nexport type RageTradeLeaderboard = {\n epochId: number;\n tierId: number;\n rank: number;\n address: string;\n maxCollateral: number;\n pnl: number;\n roi: number;\n};\n\nexport type GetRageTradeRewardsPerEpochAndTierParams = {\n epochId: string;\n tierId: string;\n skip: number;\n limit: number;\n walletAddress: string;\n};\n\nexport type GetRageTradeLeaderboardForWalletAddressParams = {\n walletAddress: string;\n};\n\nexport type GetRageTradeLeaderboardForWalletAddressResult = {\n tierId: number;\n address: string;\n rank: number;\n points: number;\n pnl: number;\n roi: number;\n maxCollateral: number;\n};\n\nexport type GetRageTradeDailyVolumeForPeriodParams = {\n timestampFrom: number;\n timestampTo: number;\n};\n\nexport type GetRageTradeDailyVolumeForPeriodResult = {\n total: number;\n data: RageTradeDailyVolumeForPeriodData[];\n};\n\nexport type RageTradeDailyVolumeForPeriodData = {\n dateStartTimestamp: number;\n dateEndTimestamp: number;\n total_volume: number;\n};\n"]}
|