@reyaxyz/api-sdk 0.44.0 → 0.45.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 +67 -0
- package/dist/clients/api-client.js.map +1 -1
- package/dist/clients/modules/account/index.js +9 -0
- package/dist/clients/modules/account/index.js.map +1 -1
- package/dist/clients/modules/account/types.js.map +1 -1
- package/dist/clients/modules/deposit-existing-MA.simulation/index.js +84 -0
- package/dist/clients/modules/deposit-existing-MA.simulation/index.js.map +1 -0
- package/dist/clients/modules/deposit-existing-MA.simulation/types.js +3 -0
- package/dist/clients/modules/deposit-existing-MA.simulation/types.js.map +1 -0
- package/dist/clients/modules/deposit-new-MA.simulation/index.js +67 -0
- package/dist/clients/modules/deposit-new-MA.simulation/index.js.map +1 -0
- package/dist/clients/modules/deposit-new-MA.simulation/types.js +3 -0
- package/dist/clients/modules/deposit-new-MA.simulation/types.js.map +1 -0
- package/dist/clients/modules/edit-collateral.simulation/index.js +84 -0
- package/dist/clients/modules/edit-collateral.simulation/index.js.map +1 -0
- package/dist/clients/modules/edit-collateral.simulation/types.js +3 -0
- package/dist/clients/modules/edit-collateral.simulation/types.js.map +1 -0
- package/dist/clients/modules/trade.simulation/index.js +2 -2
- package/dist/clients/modules/trade.simulation/index.js.map +1 -1
- package/dist/clients/modules/withdraw-MA.simulation/index.js +83 -0
- package/dist/clients/modules/withdraw-MA.simulation/index.js.map +1 -0
- package/dist/clients/modules/withdraw-MA.simulation/types.js +3 -0
- package/dist/clients/modules/withdraw-MA.simulation/types.js.map +1 -0
- package/dist/types/clients/api-client.d.ts +48 -0
- package/dist/types/clients/api-client.d.ts.map +1 -1
- package/dist/types/clients/modules/account/index.d.ts +3 -2
- package/dist/types/clients/modules/account/index.d.ts.map +1 -1
- package/dist/types/clients/modules/account/types.d.ts +3 -0
- package/dist/types/clients/modules/account/types.d.ts.map +1 -1
- package/dist/types/clients/modules/deposit-existing-MA.simulation/index.d.ts +9 -0
- package/dist/types/clients/modules/deposit-existing-MA.simulation/index.d.ts.map +1 -0
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts +16 -0
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts.map +1 -0
- package/dist/types/clients/modules/deposit-new-MA.simulation/index.d.ts +9 -0
- package/dist/types/clients/modules/deposit-new-MA.simulation/index.d.ts.map +1 -0
- package/dist/types/clients/modules/deposit-new-MA.simulation/types.d.ts +4 -0
- package/dist/types/clients/modules/deposit-new-MA.simulation/types.d.ts.map +1 -0
- package/dist/types/clients/modules/edit-collateral.simulation/index.d.ts +11 -0
- package/dist/types/clients/modules/edit-collateral.simulation/index.d.ts.map +1 -0
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts +13 -0
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts.map +1 -0
- package/dist/types/clients/modules/trade.simulation/index.d.ts.map +1 -1
- package/dist/types/clients/modules/withdraw-MA.simulation/index.d.ts +9 -0
- package/dist/types/clients/modules/withdraw-MA.simulation/index.d.ts.map +1 -0
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts +16 -0
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/clients/api-client.ts +68 -0
- package/src/clients/modules/account/index.ts +12 -1
- package/src/clients/modules/account/types.ts +6 -0
- package/src/clients/modules/deposit-existing-MA.simulation/index.ts +50 -0
- package/src/clients/modules/deposit-existing-MA.simulation/types.ts +23 -0
- package/src/clients/modules/deposit-new-MA.simulation/index.ts +30 -0
- package/src/clients/modules/deposit-new-MA.simulation/types.ts +9 -0
- package/src/clients/modules/edit-collateral.simulation/index.ts +75 -0
- package/src/clients/modules/edit-collateral.simulation/types.ts +15 -0
- package/src/clients/modules/trade.simulation/index.ts +2 -0
- package/src/clients/modules/withdraw-MA.simulation/index.ts +48 -0
- package/src/clients/modules/withdraw-MA.simulation/types.ts +24 -0
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EditCollateralSimulationLoadDataParams,
|
|
3
|
+
EditCollateralSimulationSimulateParams,
|
|
4
|
+
SimulateEditCollateralEntity,
|
|
5
|
+
} from './types';
|
|
6
|
+
import AccountClient from '../account';
|
|
7
|
+
import {
|
|
8
|
+
EditCollateralSimulationState,
|
|
9
|
+
ExposureCommand,
|
|
10
|
+
} from '@reyaxyz/common';
|
|
11
|
+
|
|
12
|
+
export default class EditCollateralSimulationClient {
|
|
13
|
+
private accountId: number | null = null;
|
|
14
|
+
private loadedData: EditCollateralSimulationState | null = null;
|
|
15
|
+
private accountClient: AccountClient;
|
|
16
|
+
constructor(accountClient: AccountClient) {
|
|
17
|
+
// Constructor added
|
|
18
|
+
this.accountClient = accountClient;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Method to asynchronously load data based on accountId
|
|
22
|
+
async arm(params: EditCollateralSimulationLoadDataParams): Promise<void> {
|
|
23
|
+
this.accountId = params.marginAccountId;
|
|
24
|
+
|
|
25
|
+
this.loadedData =
|
|
26
|
+
await this.accountClient.getEditCollateralSimulationInitialData({
|
|
27
|
+
marginAccountId: this.accountId,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Synchronous method to simulate operations based on an amount
|
|
32
|
+
simulate(
|
|
33
|
+
params: EditCollateralSimulationSimulateParams,
|
|
34
|
+
): SimulateEditCollateralEntity {
|
|
35
|
+
if (!this.loadedData) {
|
|
36
|
+
throw new Error('Data not loaded. Call arm() first.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const userAccountExposure = new ExposureCommand(
|
|
40
|
+
this.loadedData.exposureDataAccount.accountId,
|
|
41
|
+
this.loadedData.exposureDataAccount.rootCollateralPoolId,
|
|
42
|
+
this.loadedData.exposureDataAccount.oraclePricePerMarket,
|
|
43
|
+
this.loadedData.exposureDataAccount.accountBalancePerAsset,
|
|
44
|
+
this.loadedData.exposureDataAccount.groupedByCollateral,
|
|
45
|
+
this.loadedData.exposureDataAccount.riskMultipliers,
|
|
46
|
+
this.loadedData.exposureDataAccount.riskMatrices,
|
|
47
|
+
this.loadedData.exposureDataAccount.exchangeInfoPerAsset,
|
|
48
|
+
this.loadedData.exposureDataAccount.positionInfoMarketConfiguration,
|
|
49
|
+
this.loadedData.exposureDataAccount.uniqueTokenAddresses,
|
|
50
|
+
this.loadedData.exposureDataAccount.uniqueQuoteCollaterals,
|
|
51
|
+
this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset,
|
|
52
|
+
this.loadedData.exposureDataAccount.realizedPnLSum,
|
|
53
|
+
this.loadedData.exposureDataAccount.unrealizedPnLSum,
|
|
54
|
+
this.loadedData.exposureDataAccount.collateralAddressToExchangePrice,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const newMarginInfo =
|
|
58
|
+
userAccountExposure.getUsdNodeMarginInfoPostEditCollateral(
|
|
59
|
+
params.collateralDelta,
|
|
60
|
+
params.collateralAddress,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo);
|
|
64
|
+
|
|
65
|
+
const marginRatioHealth = ExposureCommand.evaluateHealthStatus(
|
|
66
|
+
marginRatio,
|
|
67
|
+
newMarginInfo,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
marginRatio: marginRatio * 100,
|
|
72
|
+
marginRatioHealth: marginRatioHealth,
|
|
73
|
+
} as SimulateEditCollateralEntity;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MarginAccountEntity, TokenEntity } from '@reyaxyz/common';
|
|
2
|
+
|
|
3
|
+
export type EditCollateralSimulationLoadDataParams = {
|
|
4
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type EditCollateralSimulationSimulateParams = {
|
|
8
|
+
collateralDelta: number; // + for deposit, - for withdraw
|
|
9
|
+
collateralAddress: TokenEntity['address'];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type SimulateEditCollateralEntity = {
|
|
13
|
+
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
14
|
+
marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
|
|
15
|
+
};
|
|
@@ -50,6 +50,7 @@ export default class TradeSimulationClient {
|
|
|
50
50
|
.toNumber();
|
|
51
51
|
|
|
52
52
|
const userAccountExposure = new ExposureCommand(
|
|
53
|
+
this.loadedData.exposureDataAccount.accountId,
|
|
53
54
|
this.loadedData.exposureDataAccount.rootCollateralPoolId,
|
|
54
55
|
this.loadedData.exposureDataAccount.oraclePricePerMarket,
|
|
55
56
|
this.loadedData.exposureDataAccount.accountBalancePerAsset,
|
|
@@ -67,6 +68,7 @@ export default class TradeSimulationClient {
|
|
|
67
68
|
);
|
|
68
69
|
|
|
69
70
|
const passivePoolExposure = new ExposureCommand(
|
|
71
|
+
this.loadedData.exposureDataPassivePool.accountId,
|
|
70
72
|
this.loadedData.exposureDataPassivePool.rootCollateralPoolId,
|
|
71
73
|
this.loadedData.exposureDataPassivePool.oraclePricePerMarket,
|
|
72
74
|
this.loadedData.exposureDataPassivePool.accountBalancePerAsset,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getSocketBridgeTime, getSocketWithdrawFees } from '@reyaxyz/common';
|
|
2
|
+
import EditCollateralClient from '../edit-collateral.simulation';
|
|
3
|
+
import {
|
|
4
|
+
SimulateWithdrawMAEntity,
|
|
5
|
+
WithdrawMASimulationLoadDataParams,
|
|
6
|
+
WithdrawMASimulationSimulateParams,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
export default class WithdrawMASimulationClient {
|
|
10
|
+
private editCollateralClient: EditCollateralClient;
|
|
11
|
+
constructor(editCollateralClient: EditCollateralClient) {
|
|
12
|
+
// Constructor added
|
|
13
|
+
this.editCollateralClient = editCollateralClient;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Method to asynchronously load data based on accountId
|
|
17
|
+
async arm(params: WithdrawMASimulationLoadDataParams): Promise<void> {
|
|
18
|
+
await this.editCollateralClient.arm({
|
|
19
|
+
marginAccountId: params.marginAccountId,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Synchronous method to simulate operations based on an amount
|
|
24
|
+
simulate(
|
|
25
|
+
params: WithdrawMASimulationSimulateParams,
|
|
26
|
+
): SimulateWithdrawMAEntity {
|
|
27
|
+
const simulateEditCollateralEntity = this.editCollateralClient.simulate({
|
|
28
|
+
collateralDelta: params.collateralDelta,
|
|
29
|
+
collateralAddress: params.collateralAddress,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const bridgeTimeInMS = getSocketBridgeTime({
|
|
33
|
+
moneyInOutChainId: params.moneyInOutChainId,
|
|
34
|
+
}).bridgeTimeInMS;
|
|
35
|
+
|
|
36
|
+
const fees = getSocketWithdrawFees({
|
|
37
|
+
reyaChainId: params.reyaChainId,
|
|
38
|
+
tokenAddress: params.collateralAddress,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
fees: fees.fees,
|
|
43
|
+
bridgeTimeInMS: bridgeTimeInMS,
|
|
44
|
+
marginRatio: simulateEditCollateralEntity.marginRatio,
|
|
45
|
+
marginRatioHealth: simulateEditCollateralEntity.marginRatioHealth,
|
|
46
|
+
} as SimulateWithdrawMAEntity;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MarginAccountEntity,
|
|
3
|
+
MoneyInOutChainId,
|
|
4
|
+
ReyaChainId,
|
|
5
|
+
TokenEntity,
|
|
6
|
+
} from '@reyaxyz/common';
|
|
7
|
+
import { EditCollateralSimulationLoadDataParams } from '../edit-collateral.simulation/types';
|
|
8
|
+
|
|
9
|
+
export type WithdrawMASimulationLoadDataParams =
|
|
10
|
+
EditCollateralSimulationLoadDataParams;
|
|
11
|
+
|
|
12
|
+
export type WithdrawMASimulationSimulateParams = {
|
|
13
|
+
reyaChainId: ReyaChainId;
|
|
14
|
+
moneyInOutChainId: MoneyInOutChainId;
|
|
15
|
+
collateralDelta: number; // + for deposit, - for withdraw
|
|
16
|
+
collateralAddress: TokenEntity['address'];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type SimulateWithdrawMAEntity = {
|
|
20
|
+
fees: number;
|
|
21
|
+
bridgeTimeInMS: number;
|
|
22
|
+
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
23
|
+
marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
|
|
24
|
+
};
|