@reyaxyz/api-sdk 0.169.5 → 0.169.6
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 -149
- package/dist/clients/api-client.js.map +1 -1
- package/dist/clients/modules/account/index.js +0 -20
- package/dist/clients/modules/account/index.js.map +1 -1
- package/dist/clients/modules/account/types.js.map +1 -1
- package/dist/clients/modules/lp/index.js +0 -9
- package/dist/clients/modules/lp/index.js.map +1 -1
- package/dist/clients/modules/lp/types.js.map +1 -1
- package/dist/clients/types.js +0 -7
- package/dist/clients/types.js.map +1 -1
- package/dist/types/clients/api-client.d.ts +0 -106
- package/dist/types/clients/api-client.d.ts.map +1 -1
- package/dist/types/clients/modules/account/index.d.ts +2 -4
- package/dist/types/clients/modules/account/index.d.ts.map +1 -1
- package/dist/types/clients/modules/account/types.d.ts +0 -8
- package/dist/types/clients/modules/account/types.d.ts.map +1 -1
- package/dist/types/clients/modules/lp/index.d.ts +2 -3
- package/dist/types/clients/modules/lp/index.d.ts.map +1 -1
- package/dist/types/clients/modules/lp/types.d.ts +1 -4
- package/dist/types/clients/modules/lp/types.d.ts.map +1 -1
- package/dist/types/clients/types.d.ts +0 -7
- package/dist/types/clients/types.d.ts.map +1 -1
- package/package.json +4 -5
- package/src/clients/api-client.ts +0 -159
- package/src/clients/modules/account/index.ts +1 -24
- package/src/clients/modules/account/types.ts +0 -14
- package/src/clients/modules/lp/index.ts +1 -13
- package/src/clients/modules/lp/types.ts +0 -5
- package/src/clients/types.ts +0 -7
- package/dist/clients/modules/binance/index.js +0 -104
- package/dist/clients/modules/binance/index.js.map +0 -1
- package/dist/clients/modules/binance/types.js +0 -3
- package/dist/clients/modules/binance/types.js.map +0 -1
- package/dist/clients/modules/deposit-existing-MA.simulation/index.js +0 -117
- package/dist/clients/modules/deposit-existing-MA.simulation/index.js.map +0 -1
- package/dist/clients/modules/deposit-existing-MA.simulation/types.js +0 -3
- package/dist/clients/modules/deposit-existing-MA.simulation/types.js.map +0 -1
- package/dist/clients/modules/deposit-new-MA.simulation/index.js +0 -67
- package/dist/clients/modules/deposit-new-MA.simulation/index.js.map +0 -1
- package/dist/clients/modules/deposit-new-MA.simulation/types.js +0 -3
- package/dist/clients/modules/deposit-new-MA.simulation/types.js.map +0 -1
- package/dist/clients/modules/depth-chart.simulation/index.js +0 -142
- package/dist/clients/modules/depth-chart.simulation/index.js.map +0 -1
- package/dist/clients/modules/depth-chart.simulation/types.js +0 -3
- package/dist/clients/modules/depth-chart.simulation/types.js.map +0 -1
- package/dist/clients/modules/edit-collateral.simulation/index.js +0 -92
- package/dist/clients/modules/edit-collateral.simulation/index.js.map +0 -1
- package/dist/clients/modules/edit-collateral.simulation/types.js +0 -3
- package/dist/clients/modules/edit-collateral.simulation/types.js.map +0 -1
- package/dist/clients/modules/transfer-MA-Pool.simulation/index.js +0 -74
- package/dist/clients/modules/transfer-MA-Pool.simulation/index.js.map +0 -1
- package/dist/clients/modules/transfer-MA-Pool.simulation/types.js +0 -3
- package/dist/clients/modules/transfer-MA-Pool.simulation/types.js.map +0 -1
- package/dist/clients/modules/transfer-margin-between-MAs.simulation/index.js +0 -90
- package/dist/clients/modules/transfer-margin-between-MAs.simulation/index.js.map +0 -1
- package/dist/clients/modules/transfer-margin-between-MAs.simulation/types.js +0 -3
- package/dist/clients/modules/transfer-margin-between-MAs.simulation/types.js.map +0 -1
- package/dist/clients/modules/withdraw-MA.simulation/index.js +0 -120
- package/dist/clients/modules/withdraw-MA.simulation/index.js.map +0 -1
- package/dist/clients/modules/withdraw-MA.simulation/types.js +0 -3
- package/dist/clients/modules/withdraw-MA.simulation/types.js.map +0 -1
- package/dist/types/clients/modules/binance/index.d.ts +0 -7
- package/dist/types/clients/modules/binance/index.d.ts.map +0 -1
- package/dist/types/clients/modules/binance/types.d.ts +0 -10
- package/dist/types/clients/modules/binance/types.d.ts.map +0 -1
- package/dist/types/clients/modules/deposit-existing-MA.simulation/index.d.ts +0 -11
- package/dist/types/clients/modules/deposit-existing-MA.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts +0 -15
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/deposit-new-MA.simulation/index.d.ts +0 -9
- package/dist/types/clients/modules/deposit-new-MA.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/deposit-new-MA.simulation/types.d.ts +0 -4
- package/dist/types/clients/modules/deposit-new-MA.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/depth-chart.simulation/index.d.ts +0 -14
- package/dist/types/clients/modules/depth-chart.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/depth-chart.simulation/types.d.ts +0 -22
- package/dist/types/clients/modules/depth-chart.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/edit-collateral.simulation/index.d.ts +0 -13
- package/dist/types/clients/modules/edit-collateral.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts +0 -13
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/index.d.ts +0 -9
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/types.d.ts +0 -12
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/index.d.ts +0 -11
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/types.d.ts +0 -16
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/withdraw-MA.simulation/index.d.ts +0 -12
- package/dist/types/clients/modules/withdraw-MA.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts +0 -16
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts.map +0 -1
- package/src/clients/modules/binance/index.ts +0 -50
- package/src/clients/modules/binance/types.ts +0 -25
- package/src/clients/modules/deposit-existing-MA.simulation/index.ts +0 -82
- package/src/clients/modules/deposit-existing-MA.simulation/types.ts +0 -23
- package/src/clients/modules/deposit-new-MA.simulation/index.ts +0 -30
- package/src/clients/modules/deposit-new-MA.simulation/types.ts +0 -9
- package/src/clients/modules/depth-chart.simulation/index.ts +0 -131
- package/src/clients/modules/depth-chart.simulation/types.ts +0 -25
- package/src/clients/modules/edit-collateral.simulation/index.ts +0 -86
- package/src/clients/modules/edit-collateral.simulation/types.ts +0 -15
- package/src/clients/modules/transfer-MA-Pool.simulation/index.ts +0 -38
- package/src/clients/modules/transfer-MA-Pool.simulation/types.ts +0 -15
- package/src/clients/modules/transfer-margin-between-MAs.simulation/index.ts +0 -65
- package/src/clients/modules/transfer-margin-between-MAs.simulation/types.ts +0 -18
- package/src/clients/modules/withdraw-MA.simulation/index.ts +0 -94
- package/src/clients/modules/withdraw-MA.simulation/types.ts +0 -23
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
descale,
|
|
3
|
-
getSocketBridgeTime,
|
|
4
|
-
getTokenInfoByAddress,
|
|
5
|
-
RestClient,
|
|
6
|
-
SocketDepositFees,
|
|
7
|
-
SocketDepositFeesEntry,
|
|
8
|
-
} from '@reyaxyz/common';
|
|
9
|
-
import EditCollateralClient from '../edit-collateral.simulation';
|
|
10
|
-
import {
|
|
11
|
-
DepositExistingMASimulationLoadDataParams,
|
|
12
|
-
DepositExistingMASimulationSimulateParams,
|
|
13
|
-
SimulateDepositExistingMAEntity,
|
|
14
|
-
} from './types';
|
|
15
|
-
import { getNativeToken } from '@reyaxyz/common';
|
|
16
|
-
|
|
17
|
-
export default class DepositExistingMASimulationClient extends RestClient {
|
|
18
|
-
private editCollateralClient: EditCollateralClient;
|
|
19
|
-
private socketDepositFeesList: SocketDepositFeesEntry[] = [];
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
editCollateralClient: EditCollateralClient,
|
|
23
|
-
host: string,
|
|
24
|
-
apiTimeout?: number | null,
|
|
25
|
-
) {
|
|
26
|
-
super(host, apiTimeout);
|
|
27
|
-
this.editCollateralClient = editCollateralClient;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Method to asynchronously load data based on accountId
|
|
31
|
-
async arm(params: DepositExistingMASimulationLoadDataParams): Promise<void> {
|
|
32
|
-
await this.editCollateralClient.arm({
|
|
33
|
-
marginAccountId: params.marginAccountId,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
this.socketDepositFeesList = await this.get<SocketDepositFeesEntry[]>(
|
|
37
|
-
`/api/socket/deposit-fees`,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Synchronous method to simulate operations based on an amount
|
|
42
|
-
simulate(
|
|
43
|
-
params: DepositExistingMASimulationSimulateParams,
|
|
44
|
-
): SimulateDepositExistingMAEntity {
|
|
45
|
-
const moneyInOutChainId = params.moneyInOutChainId;
|
|
46
|
-
const tokenInfo = getTokenInfoByAddress(
|
|
47
|
-
params.tokenAddress,
|
|
48
|
-
moneyInOutChainId,
|
|
49
|
-
);
|
|
50
|
-
const socketDepositFeesEntry = this.socketDepositFeesList.find(
|
|
51
|
-
(socketDepositFeesEntry) =>
|
|
52
|
-
socketDepositFeesEntry.moneyInOutChainId === moneyInOutChainId &&
|
|
53
|
-
socketDepositFeesEntry.tokenName === tokenInfo.name,
|
|
54
|
-
);
|
|
55
|
-
if (!socketDepositFeesEntry) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`Socket deposit fees for chain ${moneyInOutChainId} and token ${tokenInfo.name} not loaded. Call arm() first (or make sure arm will fetch info for this chain id and token)`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
const socketDepositFees: SocketDepositFees = {
|
|
61
|
-
fees: socketDepositFeesEntry.fees,
|
|
62
|
-
feesInUnderlyingToken: descale(18)(socketDepositFeesEntry.fees),
|
|
63
|
-
underlyingTokenName: getNativeToken(moneyInOutChainId),
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const simulateEditCollateralEntity = this.editCollateralClient.simulate({
|
|
67
|
-
signedAmount: params.amount,
|
|
68
|
-
tokenAddress: params.tokenAddress,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const bridgeTimeInMS = getSocketBridgeTime({
|
|
72
|
-
moneyInOutChainId: moneyInOutChainId,
|
|
73
|
-
}).bridgeTimeInMS;
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
socketDepositFees: socketDepositFees,
|
|
77
|
-
bridgeTimeInMS: bridgeTimeInMS,
|
|
78
|
-
marginRatio: simulateEditCollateralEntity.marginRatio,
|
|
79
|
-
marginRatioHealth: simulateEditCollateralEntity.marginRatioHealth,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MarginRatioHealth,
|
|
3
|
-
MoneyInOutChainId,
|
|
4
|
-
SocketDepositFees,
|
|
5
|
-
TokenEntity,
|
|
6
|
-
} from '@reyaxyz/common';
|
|
7
|
-
import { EditCollateralSimulationLoadDataParams } from '../edit-collateral.simulation/types';
|
|
8
|
-
|
|
9
|
-
export type DepositExistingMASimulationLoadDataParams =
|
|
10
|
-
EditCollateralSimulationLoadDataParams;
|
|
11
|
-
|
|
12
|
-
export type DepositExistingMASimulationSimulateParams = {
|
|
13
|
-
moneyInOutChainId: MoneyInOutChainId;
|
|
14
|
-
amount: number;
|
|
15
|
-
tokenAddress: TokenEntity['address'];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type SimulateDepositExistingMAEntity = {
|
|
19
|
-
socketDepositFees: SocketDepositFees;
|
|
20
|
-
bridgeTimeInMS: number;
|
|
21
|
-
marginRatio: number;
|
|
22
|
-
marginRatioHealth: MarginRatioHealth;
|
|
23
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { MAX_UINT128 } from '@reyaxyz/common';
|
|
2
|
-
import DepositExistingMASimulationClient from '../deposit-existing-MA.simulation';
|
|
3
|
-
import {
|
|
4
|
-
DepositNewMASimulationSimulateParams,
|
|
5
|
-
SimulateDepositNewMAEntity,
|
|
6
|
-
} from './types';
|
|
7
|
-
|
|
8
|
-
export default class DepositNewMASimulationClient {
|
|
9
|
-
private depositExistingMASimulationClient: DepositExistingMASimulationClient;
|
|
10
|
-
constructor(
|
|
11
|
-
depositExistingMASimulationClient: DepositExistingMASimulationClient,
|
|
12
|
-
) {
|
|
13
|
-
// Constructor added
|
|
14
|
-
this.depositExistingMASimulationClient = depositExistingMASimulationClient;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Method to asynchronously load data based on accountId
|
|
18
|
-
async arm(): Promise<void> {
|
|
19
|
-
await this.depositExistingMASimulationClient.arm({
|
|
20
|
-
marginAccountId: MAX_UINT128, // account ids are increasing one by one in Core
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Synchronous method to simulate operations based on an amount
|
|
25
|
-
simulate(
|
|
26
|
-
params: DepositNewMASimulationSimulateParams,
|
|
27
|
-
): SimulateDepositNewMAEntity {
|
|
28
|
-
return this.depositExistingMASimulationClient.simulate(params);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DepositExistingMASimulationSimulateParams,
|
|
3
|
-
SimulateDepositExistingMAEntity,
|
|
4
|
-
} from '../deposit-existing-MA.simulation/types';
|
|
5
|
-
|
|
6
|
-
export type DepositNewMASimulationSimulateParams =
|
|
7
|
-
DepositExistingMASimulationSimulateParams;
|
|
8
|
-
|
|
9
|
-
export type SimulateDepositNewMAEntity = SimulateDepositExistingMAEntity;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GetDepthChartParams,
|
|
3
|
-
GetDepthChartResult,
|
|
4
|
-
DepthSimulationLoadDataParams,
|
|
5
|
-
SimulateDepthEntity,
|
|
6
|
-
} from './types';
|
|
7
|
-
|
|
8
|
-
import LpClient from '../lp';
|
|
9
|
-
import { DepthSimulationState, amountNormalizer } from '@reyaxyz/common';
|
|
10
|
-
import BigNumber from 'bignumber.js';
|
|
11
|
-
|
|
12
|
-
export default class DepthChartSimulationClient {
|
|
13
|
-
private marketId: number | null = null;
|
|
14
|
-
private loadedData: DepthSimulationState | null = null;
|
|
15
|
-
private lpClient: LpClient;
|
|
16
|
-
constructor(lpClient: LpClient) {
|
|
17
|
-
// Constructor added
|
|
18
|
-
this.lpClient = lpClient;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Method to asynchronously load data based on marketId
|
|
22
|
-
async arm(params: DepthSimulationLoadDataParams): Promise<void> {
|
|
23
|
-
this.marketId = params.marketId;
|
|
24
|
-
|
|
25
|
-
this.loadedData = await this.fetchPoolData(this.marketId);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private async fetchPoolData(marketId: number): Promise<DepthSimulationState> {
|
|
29
|
-
return this.lpClient.getLpPoolDepthChartSimulationData({
|
|
30
|
-
marketId: marketId,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getDepthChart(params?: GetDepthChartParams): GetDepthChartResult {
|
|
35
|
-
if (!this.loadedData) {
|
|
36
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Adjust initial step size based on max exposures
|
|
40
|
-
const maxExposure = Math.max(
|
|
41
|
-
this.loadedData.maxOrderSizeLong,
|
|
42
|
-
Math.abs(this.loadedData.maxOrderSizeShort),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const maxPriceImpact = 0.035; // 3.5%
|
|
46
|
-
const maxSize = BigNumber(this.loadedData.netExposure)
|
|
47
|
-
.plus(
|
|
48
|
-
BigNumber(maxExposure)
|
|
49
|
-
.times(amountNormalizer(this.loadedData.depthFactor))
|
|
50
|
-
.times(maxPriceImpact)
|
|
51
|
-
.div(1 + maxPriceImpact),
|
|
52
|
-
)
|
|
53
|
-
.toNumber();
|
|
54
|
-
|
|
55
|
-
const maxDisplayedSize = maxExposure < maxSize ? maxExposure : maxSize;
|
|
56
|
-
|
|
57
|
-
const initialStepSize = maxDisplayedSize / (params?.initialSteps || 100);
|
|
58
|
-
|
|
59
|
-
const step = params?.step || initialStepSize;
|
|
60
|
-
|
|
61
|
-
const leftResults: SimulateDepthEntity[] = [];
|
|
62
|
-
const rightResults: SimulateDepthEntity[] = [];
|
|
63
|
-
|
|
64
|
-
// Simplified loop conditions to focus on reaching maxExposure limits efficiently
|
|
65
|
-
let delta = 0;
|
|
66
|
-
while (Math.abs(delta) < maxDisplayedSize) {
|
|
67
|
-
delta -= step;
|
|
68
|
-
const result = this.calculate(delta);
|
|
69
|
-
leftResults.push(result);
|
|
70
|
-
// Adjust currentStep based on your liquidity model or other factors
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
delta = 0; // Reset for the right side
|
|
74
|
-
while (Math.abs(delta) < maxDisplayedSize) {
|
|
75
|
-
delta += step;
|
|
76
|
-
const result = this.calculate(delta);
|
|
77
|
-
rightResults.push(result);
|
|
78
|
-
// Adjust currentStep similarly
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
leftChart: leftResults.reverse(),
|
|
83
|
-
rightChart: rightResults,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private calculate(delta: number): SimulateDepthEntity {
|
|
88
|
-
if (!this.loadedData) {
|
|
89
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const n0Delta = BigNumber(this.loadedData.netExposure).plus(delta);
|
|
93
|
-
const maxOrderSize = n0Delta.gt(0)
|
|
94
|
-
? BigNumber(this.loadedData.maxOrderSizeLong)
|
|
95
|
-
: BigNumber(this.loadedData.maxOrderSizeShort);
|
|
96
|
-
|
|
97
|
-
const currentPrice = BigNumber(this.loadedData.spotPrice).times(
|
|
98
|
-
BigNumber(1).minus(
|
|
99
|
-
n0Delta.div(
|
|
100
|
-
BigNumber(n0Delta).plus(
|
|
101
|
-
maxOrderSize.times(amountNormalizer(this.loadedData.depthFactor)),
|
|
102
|
-
),
|
|
103
|
-
),
|
|
104
|
-
),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
const size = BigNumber(delta).div(this.loadedData.spotPrice).abs();
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
price: currentPrice.toNumber(),
|
|
111
|
-
totalSize: size.toNumber(),
|
|
112
|
-
totalCost: size.times(currentPrice).toNumber(),
|
|
113
|
-
priceImpact: DepthChartSimulationClient.calculatePriceChangePercentage(
|
|
114
|
-
this.loadedData.spotPrice,
|
|
115
|
-
currentPrice.toNumber(),
|
|
116
|
-
),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
static calculatePriceChangePercentage(
|
|
121
|
-
price: number,
|
|
122
|
-
estimatedPrice: number,
|
|
123
|
-
): number {
|
|
124
|
-
// Calculate the price difference
|
|
125
|
-
const priceDifference = estimatedPrice - price;
|
|
126
|
-
|
|
127
|
-
const absPriceDifference = Math.abs(priceDifference);
|
|
128
|
-
// Calculate the percentage change
|
|
129
|
-
return (absPriceDifference / Math.abs(price)) * 100;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { MarketEntity } from '@reyaxyz/common';
|
|
2
|
-
|
|
3
|
-
export type DepthSimulationLoadDataParams = {
|
|
4
|
-
marketId: MarketEntity['id'];
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type SimulateDepthEntity = {
|
|
8
|
-
price: number;
|
|
9
|
-
totalSize: number;
|
|
10
|
-
totalCost: number;
|
|
11
|
-
priceImpact: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type GetDepthChartResult = {
|
|
15
|
-
leftChart: SimulateDepthEntity[];
|
|
16
|
-
rightChart: SimulateDepthEntity[];
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type GetDepthChartParams = {
|
|
20
|
-
step?: number;
|
|
21
|
-
percentageChange?: number;
|
|
22
|
-
maxPoints?: number;
|
|
23
|
-
dynamicStepIncreaseFactor?: number;
|
|
24
|
-
initialSteps?: number;
|
|
25
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EditCollateralSimulationLoadDataParams,
|
|
3
|
-
EditCollateralSimulationSimulateParams,
|
|
4
|
-
SimulateEditCollateralEntity,
|
|
5
|
-
} from './types';
|
|
6
|
-
import AccountClient from '../account';
|
|
7
|
-
import {
|
|
8
|
-
EditCollateralSimulationState,
|
|
9
|
-
ExposureCommand,
|
|
10
|
-
ReyaChainId,
|
|
11
|
-
getTokenInfoByAddress,
|
|
12
|
-
getTokenInfoByName,
|
|
13
|
-
} from '@reyaxyz/common';
|
|
14
|
-
export default class EditCollateralSimulationClient {
|
|
15
|
-
private reyaChainId: ReyaChainId;
|
|
16
|
-
private accountId: number | null = null;
|
|
17
|
-
private loadedData: EditCollateralSimulationState | null = null;
|
|
18
|
-
private accountClient: AccountClient;
|
|
19
|
-
constructor(reyaChainId: ReyaChainId, accountClient: AccountClient) {
|
|
20
|
-
// Constructor added
|
|
21
|
-
this.reyaChainId = reyaChainId;
|
|
22
|
-
this.accountClient = accountClient;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Method to asynchronously load data based on accountId
|
|
26
|
-
async arm(params: EditCollateralSimulationLoadDataParams): Promise<void> {
|
|
27
|
-
this.accountId = params.marginAccountId;
|
|
28
|
-
|
|
29
|
-
this.loadedData =
|
|
30
|
-
await this.accountClient.getEditCollateralSimulationInitialData({
|
|
31
|
-
marginAccountId: this.accountId,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Synchronous method to simulate operations based on an amount
|
|
36
|
-
simulate(
|
|
37
|
-
params: EditCollateralSimulationSimulateParams,
|
|
38
|
-
): SimulateEditCollateralEntity {
|
|
39
|
-
if (!this.loadedData) {
|
|
40
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const userAccountExposure = new ExposureCommand(
|
|
44
|
-
this.loadedData.exposureDataAccount.accountId,
|
|
45
|
-
this.loadedData.exposureDataAccount.rootCollateralPoolId,
|
|
46
|
-
this.loadedData.exposureDataAccount.oraclePricePerMarket,
|
|
47
|
-
this.loadedData.exposureDataAccount.accountBalancePerAsset,
|
|
48
|
-
this.loadedData.exposureDataAccount.groupedByCollateral,
|
|
49
|
-
this.loadedData.exposureDataAccount.riskMultipliers,
|
|
50
|
-
this.loadedData.exposureDataAccount.riskMatrices,
|
|
51
|
-
this.loadedData.exposureDataAccount.exchangeInfoPerAsset,
|
|
52
|
-
this.loadedData.exposureDataAccount.positionInfoMarketConfiguration,
|
|
53
|
-
this.loadedData.exposureDataAccount.uniqueTokenAddresses,
|
|
54
|
-
this.loadedData.exposureDataAccount.uniqueQuoteCollaterals,
|
|
55
|
-
this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset,
|
|
56
|
-
this.loadedData.exposureDataAccount.realizedPnLSum,
|
|
57
|
-
this.loadedData.exposureDataAccount.unrealizedPnLSum,
|
|
58
|
-
this.loadedData.exposureDataAccount.mtmRpnlSum,
|
|
59
|
-
this.loadedData.exposureDataAccount.collateralAddressToExchangePrice,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
let tokenInfo = getTokenInfoByAddress(params.tokenAddress);
|
|
63
|
-
if (tokenInfo.isRUSDUnderlying) {
|
|
64
|
-
tokenInfo = getTokenInfoByName('RUSD', this.reyaChainId);
|
|
65
|
-
} else {
|
|
66
|
-
tokenInfo = getTokenInfoByName(tokenInfo.name, this.reyaChainId);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const newMarginInfo =
|
|
70
|
-
userAccountExposure.getUsdNodeMarginInfoPostEditCollateral(
|
|
71
|
-
params.signedAmount,
|
|
72
|
-
tokenInfo.address,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo);
|
|
76
|
-
|
|
77
|
-
const marginRatioHealth = ExposureCommand.evaluateHealthStatus(
|
|
78
|
-
marginRatio * 100,
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
marginRatio: marginRatio * 100,
|
|
83
|
-
marginRatioHealth: marginRatioHealth,
|
|
84
|
-
} as SimulateEditCollateralEntity;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MarginRatioHealth, TokenEntity } from '@reyaxyz/common';
|
|
2
|
-
|
|
3
|
-
export type EditCollateralSimulationLoadDataParams = {
|
|
4
|
-
marginAccountId: number;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type EditCollateralSimulationSimulateParams = {
|
|
8
|
-
signedAmount: number; // + for deposit, - for withdraw
|
|
9
|
-
tokenAddress: TokenEntity['address'];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type SimulateEditCollateralEntity = {
|
|
13
|
-
marginRatio: number;
|
|
14
|
-
marginRatioHealth: MarginRatioHealth;
|
|
15
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import EditCollateralClient from '../edit-collateral.simulation';
|
|
2
|
-
import {
|
|
3
|
-
TransferMAPoolSimulationLoadDataParams,
|
|
4
|
-
TransferMAPoolSimulationSimulateParams,
|
|
5
|
-
SimulateTransferMAPoolEntity,
|
|
6
|
-
} from './types';
|
|
7
|
-
|
|
8
|
-
export default class TransferMAPoolSimulationClient {
|
|
9
|
-
private editCollateralClient: EditCollateralClient;
|
|
10
|
-
constructor(editCollateralClient: EditCollateralClient) {
|
|
11
|
-
// Constructor added
|
|
12
|
-
this.editCollateralClient = editCollateralClient;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Method to asynchronously load data based on accountId
|
|
16
|
-
async arm(params: TransferMAPoolSimulationLoadDataParams): Promise<void> {
|
|
17
|
-
await this.editCollateralClient.arm({
|
|
18
|
-
marginAccountId: params.marginAccountId,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Synchronous method to simulate operations based on an amount
|
|
23
|
-
simulate(
|
|
24
|
-
params: TransferMAPoolSimulationSimulateParams,
|
|
25
|
-
): SimulateTransferMAPoolEntity {
|
|
26
|
-
const simulateEditCollateralEntity = this.editCollateralClient.simulate({
|
|
27
|
-
signedAmount: -params.amount,
|
|
28
|
-
tokenAddress: params.tokenAddress,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const result: SimulateTransferMAPoolEntity = {
|
|
32
|
-
marginRatio: simulateEditCollateralEntity.marginRatio,
|
|
33
|
-
marginRatioHealth: simulateEditCollateralEntity.marginRatioHealth,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MarginRatioHealth, TokenEntity } from '@reyaxyz/common';
|
|
2
|
-
import { EditCollateralSimulationLoadDataParams } from '../edit-collateral.simulation/types';
|
|
3
|
-
|
|
4
|
-
export type TransferMAPoolSimulationLoadDataParams =
|
|
5
|
-
EditCollateralSimulationLoadDataParams;
|
|
6
|
-
|
|
7
|
-
export type TransferMAPoolSimulationSimulateParams = {
|
|
8
|
-
amount: number;
|
|
9
|
-
tokenAddress: TokenEntity['address'];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type SimulateTransferMAPoolEntity = {
|
|
13
|
-
marginRatio: number;
|
|
14
|
-
marginRatioHealth: MarginRatioHealth;
|
|
15
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import EditCollateralClient from '../edit-collateral.simulation';
|
|
2
|
-
import {
|
|
3
|
-
TransferMarginBetweenMAsSimulationLoadDataParams,
|
|
4
|
-
TransferMarginBetweenMAsSimulationSimulateParams,
|
|
5
|
-
SimulateTransferMarginBetweenMAsEntity,
|
|
6
|
-
} from './types';
|
|
7
|
-
import AccountClient from '../account';
|
|
8
|
-
import EditCollateralSimulationClient from '../edit-collateral.simulation';
|
|
9
|
-
import { ReyaChainId } from '@reyaxyz/common';
|
|
10
|
-
|
|
11
|
-
export default class TransferMarginBetweenMAsSimulationClient {
|
|
12
|
-
private fromEditCollateralClient: EditCollateralClient;
|
|
13
|
-
private toEditCollateralClient: EditCollateralClient;
|
|
14
|
-
constructor(reyaChainId: ReyaChainId, accountClient: AccountClient) {
|
|
15
|
-
// Constructor added
|
|
16
|
-
this.fromEditCollateralClient = new EditCollateralSimulationClient(
|
|
17
|
-
reyaChainId,
|
|
18
|
-
accountClient,
|
|
19
|
-
);
|
|
20
|
-
this.toEditCollateralClient = new EditCollateralSimulationClient(
|
|
21
|
-
reyaChainId,
|
|
22
|
-
accountClient,
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Method to asynchronously load data based on accountId
|
|
27
|
-
async arm(
|
|
28
|
-
params: TransferMarginBetweenMAsSimulationLoadDataParams,
|
|
29
|
-
): Promise<void> {
|
|
30
|
-
await this.fromEditCollateralClient.arm({
|
|
31
|
-
marginAccountId: params.fromMarginAccountId,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
await this.toEditCollateralClient.arm({
|
|
35
|
-
marginAccountId: params.toMarginAccountId,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Synchronous method to simulate operations based on an amount
|
|
40
|
-
simulate(
|
|
41
|
-
params: TransferMarginBetweenMAsSimulationSimulateParams,
|
|
42
|
-
): SimulateTransferMarginBetweenMAsEntity {
|
|
43
|
-
const simulateFromEditCollateralEntity =
|
|
44
|
-
this.fromEditCollateralClient.simulate({
|
|
45
|
-
signedAmount: -params.amount,
|
|
46
|
-
tokenAddress: params.tokenAddress,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const simulateToEditCollateralEntity = this.toEditCollateralClient.simulate(
|
|
50
|
-
{
|
|
51
|
-
signedAmount: params.amount,
|
|
52
|
-
tokenAddress: params.tokenAddress,
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const result: SimulateTransferMarginBetweenMAsEntity = {
|
|
57
|
-
fromMarginRatio: simulateFromEditCollateralEntity.marginRatio,
|
|
58
|
-
fromMarginRatioHealth: simulateFromEditCollateralEntity.marginRatioHealth,
|
|
59
|
-
toMarginRatio: simulateToEditCollateralEntity.marginRatio,
|
|
60
|
-
toMarginRatioHealth: simulateToEditCollateralEntity.marginRatioHealth,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { MarginRatioHealth, TokenEntity } from '@reyaxyz/common';
|
|
2
|
-
|
|
3
|
-
export type TransferMarginBetweenMAsSimulationLoadDataParams = {
|
|
4
|
-
fromMarginAccountId: number;
|
|
5
|
-
toMarginAccountId: number;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type TransferMarginBetweenMAsSimulationSimulateParams = {
|
|
9
|
-
amount: number;
|
|
10
|
-
tokenAddress: TokenEntity['address'];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type SimulateTransferMarginBetweenMAsEntity = {
|
|
14
|
-
fromMarginRatio: number;
|
|
15
|
-
fromMarginRatioHealth: MarginRatioHealth;
|
|
16
|
-
toMarginRatio: number;
|
|
17
|
-
toMarginRatioHealth: MarginRatioHealth;
|
|
18
|
-
};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getSocketBridgeTime,
|
|
3
|
-
getTokenInfoByAddress,
|
|
4
|
-
ReyaChainId,
|
|
5
|
-
SocketWithdrawFeesEntry,
|
|
6
|
-
RestClient,
|
|
7
|
-
SocketWithdrawFees,
|
|
8
|
-
descale,
|
|
9
|
-
getRUSDUnderlyingTokenInfo,
|
|
10
|
-
} from '@reyaxyz/common';
|
|
11
|
-
import EditCollateralClient from '../edit-collateral.simulation';
|
|
12
|
-
import {
|
|
13
|
-
SimulateWithdrawMAEntity,
|
|
14
|
-
WithdrawMASimulationLoadDataParams,
|
|
15
|
-
WithdrawMASimulationSimulateParams,
|
|
16
|
-
} from './types';
|
|
17
|
-
|
|
18
|
-
export default class WithdrawMASimulationClient extends RestClient {
|
|
19
|
-
private editCollateralClient: EditCollateralClient;
|
|
20
|
-
private reyaChainId: ReyaChainId;
|
|
21
|
-
private socketWithdrawFeesList: SocketWithdrawFeesEntry[] = [];
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
editCollateralClient: EditCollateralClient,
|
|
25
|
-
reyaChainId: ReyaChainId,
|
|
26
|
-
host: string,
|
|
27
|
-
apiTimeout?: number | null,
|
|
28
|
-
) {
|
|
29
|
-
super(host, apiTimeout);
|
|
30
|
-
this.editCollateralClient = editCollateralClient;
|
|
31
|
-
this.reyaChainId = reyaChainId;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Method to asynchronously load data based on accountId
|
|
35
|
-
async arm(params: WithdrawMASimulationLoadDataParams): Promise<void> {
|
|
36
|
-
await this.editCollateralClient.arm({
|
|
37
|
-
marginAccountId: params.marginAccountId,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
this.socketWithdrawFeesList = await this.get<SocketWithdrawFeesEntry[]>(
|
|
41
|
-
`/api/socket/withdraw-fees`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Synchronous method to simulate operations based on an amount
|
|
46
|
-
simulate(
|
|
47
|
-
params: WithdrawMASimulationSimulateParams,
|
|
48
|
-
): SimulateWithdrawMAEntity {
|
|
49
|
-
const tokenInfo = getTokenInfoByAddress(
|
|
50
|
-
params.tokenAddress,
|
|
51
|
-
this.reyaChainId,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const moneyInOutTokenInfo =
|
|
55
|
-
tokenInfo.name === 'RUSD'
|
|
56
|
-
? getRUSDUnderlyingTokenInfo(params.moneyInOutChainId)
|
|
57
|
-
: tokenInfo;
|
|
58
|
-
const socketWithdrawFeesEntry = this.socketWithdrawFeesList.find(
|
|
59
|
-
(socketWithdrawFeesEntry) =>
|
|
60
|
-
socketWithdrawFeesEntry.moneyInOutChainId ===
|
|
61
|
-
params.moneyInOutChainId &&
|
|
62
|
-
socketWithdrawFeesEntry.tokenName === moneyInOutTokenInfo.name,
|
|
63
|
-
);
|
|
64
|
-
if (!socketWithdrawFeesEntry) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Socket withdraw fees for chain ${params.moneyInOutChainId} and token ${moneyInOutTokenInfo.name} not loaded. Call arm() first (or make sure arm will fetch info for this chain id and token)`,
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const socketWithdrawFees: SocketWithdrawFees = {
|
|
71
|
-
fees: socketWithdrawFeesEntry.fees,
|
|
72
|
-
feesInUnderlyingToken: descale(moneyInOutTokenInfo.decimals)(
|
|
73
|
-
socketWithdrawFeesEntry.fees,
|
|
74
|
-
),
|
|
75
|
-
underlyingTokenName: moneyInOutTokenInfo.name,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const simulateEditCollateralEntity = this.editCollateralClient.simulate({
|
|
79
|
-
signedAmount: -params.amount,
|
|
80
|
-
tokenAddress: params.tokenAddress,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const bridgeTimeInMS = getSocketBridgeTime({
|
|
84
|
-
moneyInOutChainId: params.moneyInOutChainId,
|
|
85
|
-
}).bridgeTimeInMS;
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
socketWithdrawFees,
|
|
89
|
-
bridgeTimeInMS: bridgeTimeInMS,
|
|
90
|
-
marginRatio: simulateEditCollateralEntity.marginRatio,
|
|
91
|
-
marginRatioHealth: simulateEditCollateralEntity.marginRatioHealth,
|
|
92
|
-
} as SimulateWithdrawMAEntity;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MarginRatioHealth,
|
|
3
|
-
MoneyInOutChainId,
|
|
4
|
-
TokenEntity,
|
|
5
|
-
} from '@reyaxyz/common';
|
|
6
|
-
import { EditCollateralSimulationLoadDataParams } from '../edit-collateral.simulation/types';
|
|
7
|
-
import { SocketWithdrawFees } from '@reyaxyz/common';
|
|
8
|
-
|
|
9
|
-
export type WithdrawMASimulationLoadDataParams =
|
|
10
|
-
EditCollateralSimulationLoadDataParams;
|
|
11
|
-
|
|
12
|
-
export type WithdrawMASimulationSimulateParams = {
|
|
13
|
-
moneyInOutChainId: MoneyInOutChainId;
|
|
14
|
-
amount: number;
|
|
15
|
-
tokenAddress: TokenEntity['address'];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type SimulateWithdrawMAEntity = {
|
|
19
|
-
socketWithdrawFees: SocketWithdrawFees;
|
|
20
|
-
bridgeTimeInMS: number;
|
|
21
|
-
marginRatio: number;
|
|
22
|
-
marginRatioHealth: MarginRatioHealth;
|
|
23
|
-
};
|