@reyaxyz/sdk 0.136.16 → 0.138.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/services/lp/types.js.map +1 -1
- package/dist/services/margin-accounts/types.js.map +1 -1
- package/dist/services/orders/order.js +4 -6
- package/dist/services/orders/order.js.map +1 -1
- package/dist/services/orders/types.js.map +1 -1
- package/dist/types/services/lp/types.d.ts +4 -4
- package/dist/types/services/lp/types.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/types.d.ts +18 -18
- package/dist/types/services/margin-accounts/types.d.ts.map +1 -1
- package/dist/types/services/orders/order.d.ts.map +1 -1
- package/dist/types/services/orders/types.d.ts +6 -7
- package/dist/types/services/orders/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/lp/types.ts +3 -4
- package/src/services/margin-accounts/types.ts +18 -18
- package/src/services/orders/order.ts +3 -13
- package/src/services/orders/types.ts +5 -7
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/lp/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport {\n LpPoolEntity,\n LpWithdrawBalanceEntity,\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/lp/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport {\n LpPoolEntity,\n LpWithdrawBalanceEntity,\n MoneyInOutChainId,\n OwnerMetadataEntity,\n ReyaChainId,\n SocketDepositFees,\n TokenEntity,\n TokenName,\n} from '@reyaxyz/common';\n\nexport type TransferStakeToMarginAccountParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'address' | 'poolSigNonce'>;\n marginAccountId: number;\n pool: Pick<LpPoolEntity, 'id'>;\n srusdAmount: number;\n};\n\nexport type TransferStakeToMarginAccountResult = {\n transactionHash: string | null;\n poolSigNonce: OwnerMetadataEntity['poolSigNonce'] | null;\n};\n\nexport type UnstakeFromMarginAccountParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: number;\n pool: Pick<LpPoolEntity, 'id'>;\n srusdAmount: number;\n};\n\nexport type UnstakeFromMarginAccountResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n};\n\nexport type StakeFromMarginAccountParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: number;\n pool: Pick<LpPoolEntity, 'id' | 'tokenAddress'>;\n amount: number;\n};\n\nexport type StakeFromMarginAccountResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n};\n\nexport type WithdrawPassivePoolAndBridgeParams = {\n signer: Signer | JsonRpcSigner;\n moneyInOutChainId: MoneyInOutChainId;\n owner: Pick<OwnerMetadataEntity, 'address' | 'poolSigNonce'>;\n pool: Pick<LpPoolEntity, 'id' | 'tokenAddress'>;\n amount: number;\n sharePrice: LpWithdrawBalanceEntity['poolSharePrice'];\n sharesAmount: number;\n withdrawMax: boolean;\n};\n\nexport type WithdrawPassivePoolAndBridgeParamsV2 = {\n signer: Signer | JsonRpcSigner;\n moneyInOutChainId: MoneyInOutChainId;\n owner: Pick<OwnerMetadataEntity, 'address' | 'poolSigNonce'>;\n pool: Pick<LpPoolEntity, 'id'>;\n amount: number;\n sharePrice: LpWithdrawBalanceEntity['poolSharePrice'];\n priceTokenToRusd: LpWithdrawBalanceEntity['balanceBreakdown'][string]['priceTokenToRusd'];\n sharesAmount: number;\n withdrawMax: boolean;\n tokenAddress: TokenEntity['address']; // address from reya chain\n};\n\nexport type WithdrawPassivePoolAndBridgeResult = {\n transactionHash: string | null;\n poolSigNonce: OwnerMetadataEntity['poolSigNonce'] | null;\n};\n\nexport type BridgeAndDepositPassivePoolParams = {\n signer: Signer | JsonRpcSigner;\n ownerAddress: OwnerMetadataEntity['address'];\n pool: Pick<LpPoolEntity, 'id' | 'tokenAddress'>;\n amount: number;\n socketDepositFees: SocketDepositFees['fees'];\n};\n\nexport type BridgeAndDepositPassivePoolParamsV2 = {\n signer: Signer | JsonRpcSigner;\n ownerAddress: OwnerMetadataEntity['address'];\n pool: Pick<LpPoolEntity, 'id'>;\n amount: number;\n socketDepositFees: SocketDepositFees['fees'];\n tokenAddress: TokenEntity['address'];\n};\n\nexport type BridgeAndDepositPassivePoolResult = {\n transactionHash: string | null;\n};\n\nexport type SimulateBridgeAndDepositPassivePoolResult = {\n fees: number;\n feesUnderlyingToken: TokenName;\n bridgeTimeInMS: number;\n};\n\nexport type SimulateBridgeAndDepositPassivePoolParams = {\n moneyInOutChainId: MoneyInOutChainId;\n};\n\nexport type SimulateWithdrawPassivePoolAndBridgeResult = {\n fees: number;\n feesUnderlyingToken: TokenName;\n bridgeTimeInMS: number;\n};\n\nexport type SimulateWithdrawPassivePoolAndBridgeParams = {\n reyaChainId: ReyaChainId;\n moneyInOutChainId: MoneyInOutChainId;\n tokenAddress: TokenEntity['address'];\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/margin-accounts/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport {\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/margin-accounts/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport {\n MarginRatioHealth,\n MoneyInOutChainId,\n OwnerMetadataEntity,\n SocketDepositFees,\n TokenEntity,\n} from '@reyaxyz/common';\n\nexport type CreateAccountParams = {\n ownerAddress: string;\n name: string;\n source?: string;\n};\n\nexport type CreateAccountResult = {\n transactionHash: string | null;\n accountId: number | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n};\n\nexport type DepositParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n};\n\nexport type DepositResult = {\n transactionHash: string | null;\n};\n\nexport type WithdrawParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n};\n\nexport type WithdrawResult = {\n transactionHash: string | null;\n};\n\nexport type SimulateDepositResult = {\n bridgeGasFees: number;\n marginRatioHealth: MarginRatioHealth;\n marginRatio: number;\n};\n\n// TODO: Milan reevaluate these params\nexport type SimulateDepositParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n};\n\nexport type SimulateWithdrawResult = {\n bridgeGasFees: number;\n\n marginRatioHealth: MarginRatioHealth;\n marginRatio: number;\n};\n\n// TODO: Milan reevaluate these params\nexport type SimulateWithdrawParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n};\n\nexport type TransferMarginBetweenAccountsParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n fromMarginAccountId: number;\n toMarginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n};\n\nexport type TransferMarginBetweenAccountsResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n};\n\nexport type WithdrawMAAndBridgeParams = {\n signer: Signer | JsonRpcSigner;\n moneyInOutChainId: MoneyInOutChainId;\n owner: Pick<OwnerMetadataEntity, 'address' | 'coreSigNonce'>;\n marginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n // if not provided it has same value as owner.address\n receiverAddress?: Lowercase<string>;\n};\n\nexport type WithdrawMAAndBridgeParamsResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n};\n\nexport type BridgeAndDepositNewMAParams = {\n signer: Signer | JsonRpcSigner;\n ownerAddress: OwnerMetadataEntity['address'];\n tokenAddress: TokenEntity['address'];\n amount: number;\n socketDepositFees: SocketDepositFees['fees'];\n};\n\nexport type BridgeAndDepositNewMAResult = {\n transactionHash: string | null;\n};\n\nexport type BridgeAndDepositExistingMAParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n socketDepositFees: SocketDepositFees['fees'];\n moneyInOutChainId?: MoneyInOutChainId;\n};\n\nexport type BridgeAndDepositExistingMAResult = {\n transactionHash: string | null;\n};\n\nexport type SimulateTransferMarginBetweenAccountsResult = {\n bridgeGasFees: number;\n marginRatioHealth: MarginRatioHealth;\n marginRatio: number;\n};\n\n// TODO: Milan reevaluate these params\nexport type SimulateTransferMarginBetweenAccountsParams = {\n signer: Signer | JsonRpcSigner;\n fromMarginAccountId: number;\n toMarginAccountId: number;\n tokenAddress: TokenEntity['address'];\n amount: number;\n};\n"]}
|
|
@@ -91,7 +91,7 @@ var executeMarketOrderViaOrdersGateway = function (params) { return __awaiter(vo
|
|
|
91
91
|
});
|
|
92
92
|
}); };
|
|
93
93
|
var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
94
|
-
var snappedAmount, orderBaseE18,
|
|
94
|
+
var snappedAmount, orderBaseE18, orderPriceLimitE18, result;
|
|
95
95
|
var _a, _b, _c, _d, _e, _f;
|
|
96
96
|
return __generator(this, function (_g) {
|
|
97
97
|
switch (_g.label) {
|
|
@@ -113,8 +113,7 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
113
113
|
throw new Error("Minimum trade amount ".concat(params.market.minOrderSizeBase));
|
|
114
114
|
}
|
|
115
115
|
orderBaseE18 = (0, common_3.scale)(18)(snappedAmount);
|
|
116
|
-
|
|
117
|
-
orderPriceLimitE18 = (0, common_1.calculatePriceLimitForTrade)(params.market.currentPrice, snappedAmount, slippageFactor);
|
|
116
|
+
orderPriceLimitE18 = (0, common_1.calculateMaxPriceLimit)(snappedAmount > 0);
|
|
118
117
|
return [4 /*yield*/, executeMarketOrderViaOrdersGateway({
|
|
119
118
|
signer: params.signer,
|
|
120
119
|
marginAccountId: params.marginAccountId,
|
|
@@ -149,7 +148,7 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
149
148
|
}); };
|
|
150
149
|
exports.matchOrder = matchOrder;
|
|
151
150
|
var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
152
|
-
var closingBase,
|
|
151
|
+
var closingBase, orderPriceLimit, result;
|
|
153
152
|
var _a, _b, _c, _d, _e, _f;
|
|
154
153
|
return __generator(this, function (_g) {
|
|
155
154
|
switch (_g.label) {
|
|
@@ -173,8 +172,7 @@ var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
173
172
|
throw new Error('Specified base to close is larger than the actual order.');
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
|
-
|
|
177
|
-
orderPriceLimit = (0, common_1.calculatePriceLimitForTrade)(params.market.currentPrice, -closingBase, slippageFactor);
|
|
175
|
+
orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(closingBase < 0);
|
|
178
176
|
return [4 /*yield*/, executeMarketOrderViaOrdersGateway({
|
|
179
177
|
signer: params.signer,
|
|
180
178
|
marginAccountId: params.marginAccountId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,8EAA6E;AAC7E,0CAOyB;AACzB,8DAAqC;AACrC,0CAA+C;AAC/C,0CAAwC;AACxC,+C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D,IAAI,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,IAAI,KAAI,CAAC;qBACrC,EAAC;;;KACH,CAAC;AA7DW,QAAA,UAAU,cA6DrB","sourcesContent":["import {\n CloseOrderParams,\n CloseOrderResult,\n MatchOrderParams,\n MatchOrderResult,\n OrdersGatewayMarketOrderParams,\n} from './types';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport {\n calculatePriceLimitForTrade,\n ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n OrdersGatewayAbi,\n OrdersGatewayOrderType,\n signOrdersGatewayOrder,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { ContractType } from '@reyaxyz/common';\nimport { scale } from '@reyaxyz/common';\nimport { getReyaNetwork } from '../../utils/network';\nimport { AbiCoder, Interface } from 'ethers';\n\nconst executeMarketOrderViaOrdersGateway = async (\n params: OrdersGatewayMarketOrderParams,\n): Promise<TransactionExecutionOutput> => {\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [params.order.baseE18, params.order.priceLimitE18],\n );\n\n const reyaChainId = getReyaNetwork();\n const creationTimestampMs = Date.now();\n const creationTimestampSeconds = Math.floor(creationTimestampMs / 1000);\n\n const { signature, nonce } = await signOrdersGatewayOrder(\n params.signer,\n reyaChainId,\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n creationTimestampSeconds + ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n creationTimestampMs,\n );\n\n const fnSig = 'execute';\n const fnArgs = [\n [\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n await params.signer.getAddress(),\n nonce,\n ],\n [signature.v, signature.r, signature.s, signature.deadline],\n ];\n\n const ogInterface = new Interface(OrdersGatewayAbi);\n const data = ogInterface.encodeFunctionData(fnSig, fnArgs);\n\n const isFastExecutionEnabled =\n process.env.FAST_ORDER_EXECUTION === 'true' || false;\n\n const result = await signAndBroadcastTransaction(\n data,\n reyaChainId,\n ContractType.ORDERS_GATEWAY_PROXY,\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n tradeSource: params.tradeSource,\n action: isFastExecutionEnabled ? 'ioc-order-ui' : undefined,\n },\n );\n\n return result;\n};\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n if (params.amountInBase === 0) {\n throw new Error('Order cannot be of size zero.');\n }\n\n let snappedAmount = BigNumber(params.amountInBase)\n .abs()\n .dividedBy(params.market.baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(params.market.baseSpacing)\n .toNumber();\n\n if (params.amountInBase < 0) {\n snappedAmount = -snappedAmount;\n }\n\n if (Math.abs(snappedAmount) < params.market.minOrderSizeBase) {\n console.error(\n `Minimum trade amount ${params.market.minOrderSizeBase}. Entered amount ${snappedAmount}, ${params.amountInBase}`,\n );\n throw new Error(`Minimum trade amount ${params.market.minOrderSizeBase}`);\n }\n\n const orderBaseE18 = scale(18)(snappedAmount);\n const slippageFactor = 40; // 2.5%\n const orderPriceLimitE18 = calculatePriceLimitForTrade(\n params.market.currentPrice,\n snappedAmount,\n slippageFactor,\n );\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n tradeSource: params.tradeSource,\n order: {\n baseE18: orderBaseE18,\n priceLimitE18: orderPriceLimitE18,\n type: OrdersGatewayOrderType.MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n positions: result.positions,\n orders: result.orders,\n accounts: result.accounts,\n };\n};\n\nexport const closeOrder = async (\n params: CloseOrderParams,\n): Promise<CloseOrderResult> => {\n if (params.orderBase === 0) {\n throw new Error('Position is already closed.');\n }\n\n let closingBase: number = 0;\n if (params.type === 'full') {\n closingBase = params.orderBase;\n } else {\n closingBase = params.closingOrderBase;\n\n if (closingBase === 0) {\n throw new Error('Specified base to close is zero.');\n }\n\n if (closingBase * params.orderBase < 0) {\n throw new Error(\n 'Specified base to close is in different direction that the actual order.',\n );\n }\n\n if (Math.abs(closingBase) > Math.abs(params.orderBase)) {\n throw new Error(\n 'Specified base to close is larger than the actual order.',\n );\n }\n }\n\n const slippageFactor = 40; // 2.5%\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n -closingBase,\n slippageFactor,\n );\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n order: {\n baseE18: -scale(18)(closingBase),\n priceLimitE18: orderPriceLimit,\n type: OrdersGatewayOrderType.REDUCE_ONLY_MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;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,MAAM,CAAC,YAAY,0CAAE,IAAI,KAAI,CAAC;qBACrC,EAAC;;;KACH,CAAC;AAxDW,QAAA,UAAU,cAwDrB","sourcesContent":["import {\n CloseOrderParams,\n CloseOrderResult,\n MatchOrderParams,\n MatchOrderResult,\n OrdersGatewayMarketOrderParams,\n} from './types';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport {\n calculateMaxPriceLimit,\n ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n OrdersGatewayAbi,\n OrdersGatewayOrderType,\n signOrdersGatewayOrder,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { ContractType } from '@reyaxyz/common';\nimport { scale } from '@reyaxyz/common';\nimport { getReyaNetwork } from '../../utils/network';\nimport { AbiCoder, Interface } from 'ethers';\n\nconst executeMarketOrderViaOrdersGateway = async (\n params: OrdersGatewayMarketOrderParams,\n): Promise<TransactionExecutionOutput> => {\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [params.order.baseE18, params.order.priceLimitE18],\n );\n\n const reyaChainId = getReyaNetwork();\n const creationTimestampMs = Date.now();\n const creationTimestampSeconds = Math.floor(creationTimestampMs / 1000);\n\n const { signature, nonce } = await signOrdersGatewayOrder(\n params.signer,\n reyaChainId,\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n creationTimestampSeconds + ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n creationTimestampMs,\n );\n\n const fnSig = 'execute';\n const fnArgs = [\n [\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n await params.signer.getAddress(),\n nonce,\n ],\n [signature.v, signature.r, signature.s, signature.deadline],\n ];\n\n const ogInterface = new Interface(OrdersGatewayAbi);\n const data = ogInterface.encodeFunctionData(fnSig, fnArgs);\n\n const isFastExecutionEnabled =\n process.env.FAST_ORDER_EXECUTION === 'true' || false;\n\n const result = await signAndBroadcastTransaction(\n data,\n reyaChainId,\n ContractType.ORDERS_GATEWAY_PROXY,\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n tradeSource: params.tradeSource,\n action: isFastExecutionEnabled ? 'ioc-order-ui' : undefined,\n },\n );\n\n return result;\n};\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n if (params.amountInBase === 0) {\n throw new Error('Order cannot be of size zero.');\n }\n\n let snappedAmount = BigNumber(params.amountInBase)\n .abs()\n .dividedBy(params.market.baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(params.market.baseSpacing)\n .toNumber();\n\n if (params.amountInBase < 0) {\n snappedAmount = -snappedAmount;\n }\n\n if (Math.abs(snappedAmount) < params.market.minOrderSizeBase) {\n console.error(\n `Minimum trade amount ${params.market.minOrderSizeBase}. Entered amount ${snappedAmount}, ${params.amountInBase}`,\n );\n throw new Error(`Minimum trade amount ${params.market.minOrderSizeBase}`);\n }\n\n const orderBaseE18 = scale(18)(snappedAmount);\n const orderPriceLimitE18 = calculateMaxPriceLimit(snappedAmount > 0);\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n tradeSource: params.tradeSource,\n order: {\n baseE18: orderBaseE18,\n priceLimitE18: orderPriceLimitE18,\n type: OrdersGatewayOrderType.MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n positions: result.positions,\n orders: result.orders,\n accounts: result.accounts,\n };\n};\n\nexport const closeOrder = async (\n params: CloseOrderParams,\n): Promise<CloseOrderResult> => {\n if (params.orderBase === 0) {\n throw new Error('Position is already closed.');\n }\n\n let closingBase: number = 0;\n if (params.type === 'full') {\n closingBase = params.orderBase;\n } else {\n closingBase = params.closingOrderBase;\n\n if (closingBase === 0) {\n throw new Error('Specified base to close is zero.');\n }\n\n if (closingBase * params.orderBase < 0) {\n throw new Error(\n 'Specified base to close is in different direction that the actual order.',\n );\n }\n\n if (Math.abs(closingBase) > Math.abs(params.orderBase)) {\n throw new Error(\n 'Specified base to close is larger than the actual order.',\n );\n }\n }\n\n const orderPriceLimit = calculateMaxPriceLimit(closingBase < 0);\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n order: {\n baseE18: -scale(18)(closingBase),\n priceLimitE18: orderPriceLimit,\n type: OrdersGatewayOrderType.REDUCE_ONLY_MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer, JsonRpcSigner } from 'ethers';\nimport {\n CoreCommandsEIP712SignatureAndPayload,\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer, JsonRpcSigner } from 'ethers';\nimport {\n CoreCommandsEIP712SignatureAndPayload,\n MarketEntity,\n MethodParameters,\n OrdersGatewayOrderType,\n OwnerMetadataEntity,\n PositionEntity,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\n\nexport type MarketParams = {\n id: MarketEntity['id'];\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n minOrderSizeBase: MarketEntity['minOrderSizeBase'];\n baseSpacing: MarketEntity['baseSpacing'];\n};\n\nexport type MatchOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n amountInBase: number; // amount in base\n market: MarketParams;\n tradeSource?: 'reya' | 'rage' | 'other';\n};\n\nexport type CloseOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n orderBase: PositionEntity['base'];\n market: MarketParams;\n} & (\n | {\n type: 'full';\n }\n | {\n type: 'partial';\n closingOrderBase: number;\n }\n);\n\nexport type MatchOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n lotteryXpBoost: number;\n isNftWon: boolean;\n marginAccountId: number;\n xpEarned: number;\n executionPrice: number;\n base: number;\n positions?: TransactionExecutionOutput['positions'];\n orders?: TransactionExecutionOutput['orders'];\n accounts?: TransactionExecutionOutput['accounts'];\n};\n\nexport type CloseOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n lotteryXpBoost: number;\n isNftWon: boolean;\n marginAccountId: number;\n xpEarned: number;\n executionPrice: number;\n base: number;\n};\n\nexport type MethodParametersAndEIP712Payload = MethodParameters &\n CoreCommandsEIP712SignatureAndPayload;\n\nexport type OrdersGatewayMarketOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n marketId: MarketEntity['id'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n order: {\n baseE18: bigint;\n priceLimitE18: bigint;\n type:\n | OrdersGatewayOrderType.MARKET_ORDER\n | OrdersGatewayOrderType.REDUCE_ONLY_MARKET_ORDER;\n };\n tradeSource?: 'reya' | 'rage' | 'other';\n};\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
import { LpPoolEntity, LpWithdrawBalanceEntity,
|
|
2
|
+
import { LpPoolEntity, LpWithdrawBalanceEntity, MoneyInOutChainId, OwnerMetadataEntity, ReyaChainId, SocketDepositFees, TokenEntity, TokenName } from '@reyaxyz/common';
|
|
3
3
|
export type TransferStakeToMarginAccountParams = {
|
|
4
4
|
signer: Signer | JsonRpcSigner;
|
|
5
5
|
owner: Pick<OwnerMetadataEntity, 'address' | 'poolSigNonce'>;
|
|
6
|
-
marginAccountId:
|
|
6
|
+
marginAccountId: number;
|
|
7
7
|
pool: Pick<LpPoolEntity, 'id'>;
|
|
8
8
|
srusdAmount: number;
|
|
9
9
|
};
|
|
@@ -14,7 +14,7 @@ export type TransferStakeToMarginAccountResult = {
|
|
|
14
14
|
export type UnstakeFromMarginAccountParams = {
|
|
15
15
|
signer: Signer | JsonRpcSigner;
|
|
16
16
|
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
17
|
-
marginAccountId:
|
|
17
|
+
marginAccountId: number;
|
|
18
18
|
pool: Pick<LpPoolEntity, 'id'>;
|
|
19
19
|
srusdAmount: number;
|
|
20
20
|
};
|
|
@@ -25,7 +25,7 @@ export type UnstakeFromMarginAccountResult = {
|
|
|
25
25
|
export type StakeFromMarginAccountParams = {
|
|
26
26
|
signer: Signer | JsonRpcSigner;
|
|
27
27
|
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
28
|
-
marginAccountId:
|
|
28
|
+
marginAccountId: number;
|
|
29
29
|
pool: Pick<LpPoolEntity, 'id' | 'tokenAddress'>;
|
|
30
30
|
amount: number;
|
|
31
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/lp/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/lp/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,kCAAkC,GAAG;IAC/C,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,cAAc,CAAC,CAAC;IAC7D,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,YAAY,EAAE,mBAAmB,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACjD,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAC/B,WAA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,yCAAyC,GAAG;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB,EAAE,SAAS,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yCAAyC,GAAG;IACtD,iBAAiB,EAAE,iBAAiB,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB,EAAE,SAAS,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,YAAY,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CACtC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
import {
|
|
2
|
+
import { MarginRatioHealth, MoneyInOutChainId, OwnerMetadataEntity, SocketDepositFees, TokenEntity } from '@reyaxyz/common';
|
|
3
3
|
export type CreateAccountParams = {
|
|
4
4
|
ownerAddress: string;
|
|
5
5
|
name: string;
|
|
@@ -7,12 +7,12 @@ export type CreateAccountParams = {
|
|
|
7
7
|
};
|
|
8
8
|
export type CreateAccountResult = {
|
|
9
9
|
transactionHash: string | null;
|
|
10
|
-
accountId:
|
|
10
|
+
accountId: number | null;
|
|
11
11
|
coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;
|
|
12
12
|
};
|
|
13
13
|
export type DepositParams = {
|
|
14
14
|
signer: Signer | JsonRpcSigner;
|
|
15
|
-
marginAccountId:
|
|
15
|
+
marginAccountId: number;
|
|
16
16
|
tokenAddress: TokenEntity['address'];
|
|
17
17
|
amount: number;
|
|
18
18
|
};
|
|
@@ -21,7 +21,7 @@ export type DepositResult = {
|
|
|
21
21
|
};
|
|
22
22
|
export type WithdrawParams = {
|
|
23
23
|
signer: Signer | JsonRpcSigner;
|
|
24
|
-
marginAccountId:
|
|
24
|
+
marginAccountId: number;
|
|
25
25
|
tokenAddress: TokenEntity['address'];
|
|
26
26
|
amount: number;
|
|
27
27
|
};
|
|
@@ -30,31 +30,31 @@ export type WithdrawResult = {
|
|
|
30
30
|
};
|
|
31
31
|
export type SimulateDepositResult = {
|
|
32
32
|
bridgeGasFees: number;
|
|
33
|
-
marginRatioHealth:
|
|
34
|
-
marginRatio:
|
|
33
|
+
marginRatioHealth: MarginRatioHealth;
|
|
34
|
+
marginRatio: number;
|
|
35
35
|
};
|
|
36
36
|
export type SimulateDepositParams = {
|
|
37
37
|
signer: Signer | JsonRpcSigner;
|
|
38
|
-
marginAccountId:
|
|
38
|
+
marginAccountId: number;
|
|
39
39
|
tokenAddress: TokenEntity['address'];
|
|
40
40
|
amount: number;
|
|
41
41
|
};
|
|
42
42
|
export type SimulateWithdrawResult = {
|
|
43
43
|
bridgeGasFees: number;
|
|
44
|
-
marginRatioHealth:
|
|
45
|
-
marginRatio:
|
|
44
|
+
marginRatioHealth: MarginRatioHealth;
|
|
45
|
+
marginRatio: number;
|
|
46
46
|
};
|
|
47
47
|
export type SimulateWithdrawParams = {
|
|
48
48
|
signer: Signer | JsonRpcSigner;
|
|
49
|
-
marginAccountId:
|
|
49
|
+
marginAccountId: number;
|
|
50
50
|
tokenAddress: TokenEntity['address'];
|
|
51
51
|
amount: number;
|
|
52
52
|
};
|
|
53
53
|
export type TransferMarginBetweenAccountsParams = {
|
|
54
54
|
signer: Signer | JsonRpcSigner;
|
|
55
55
|
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
56
|
-
fromMarginAccountId:
|
|
57
|
-
toMarginAccountId:
|
|
56
|
+
fromMarginAccountId: number;
|
|
57
|
+
toMarginAccountId: number;
|
|
58
58
|
tokenAddress: TokenEntity['address'];
|
|
59
59
|
amount: number;
|
|
60
60
|
};
|
|
@@ -66,7 +66,7 @@ export type WithdrawMAAndBridgeParams = {
|
|
|
66
66
|
signer: Signer | JsonRpcSigner;
|
|
67
67
|
moneyInOutChainId: MoneyInOutChainId;
|
|
68
68
|
owner: Pick<OwnerMetadataEntity, 'address' | 'coreSigNonce'>;
|
|
69
|
-
marginAccountId:
|
|
69
|
+
marginAccountId: number;
|
|
70
70
|
tokenAddress: TokenEntity['address'];
|
|
71
71
|
amount: number;
|
|
72
72
|
receiverAddress?: Lowercase<string>;
|
|
@@ -87,7 +87,7 @@ export type BridgeAndDepositNewMAResult = {
|
|
|
87
87
|
};
|
|
88
88
|
export type BridgeAndDepositExistingMAParams = {
|
|
89
89
|
signer: Signer | JsonRpcSigner;
|
|
90
|
-
marginAccountId:
|
|
90
|
+
marginAccountId: number;
|
|
91
91
|
tokenAddress: TokenEntity['address'];
|
|
92
92
|
amount: number;
|
|
93
93
|
socketDepositFees: SocketDepositFees['fees'];
|
|
@@ -98,13 +98,13 @@ export type BridgeAndDepositExistingMAResult = {
|
|
|
98
98
|
};
|
|
99
99
|
export type SimulateTransferMarginBetweenAccountsResult = {
|
|
100
100
|
bridgeGasFees: number;
|
|
101
|
-
marginRatioHealth:
|
|
102
|
-
marginRatio:
|
|
101
|
+
marginRatioHealth: MarginRatioHealth;
|
|
102
|
+
marginRatio: number;
|
|
103
103
|
};
|
|
104
104
|
export type SimulateTransferMarginBetweenAccountsParams = {
|
|
105
105
|
signer: Signer | JsonRpcSigner;
|
|
106
|
-
fromMarginAccountId:
|
|
107
|
-
toMarginAccountId:
|
|
106
|
+
fromMarginAccountId: number;
|
|
107
|
+
toMarginAccountId: number;
|
|
108
108
|
tokenAddress: TokenEntity['address'];
|
|
109
109
|
amount: number;
|
|
110
110
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/margin-accounts/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"types.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,CAAC;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AA6EjB,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AA6EjB,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAsD1B,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAsD1B,CAAC"}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { Signer, JsonRpcSigner } from 'ethers';
|
|
2
|
-
import { CoreCommandsEIP712SignatureAndPayload,
|
|
2
|
+
import { CoreCommandsEIP712SignatureAndPayload, MarketEntity, MethodParameters, OrdersGatewayOrderType, OwnerMetadataEntity, PositionEntity, TransactionExecutionOutput } from '@reyaxyz/common';
|
|
3
3
|
export type MarketParams = {
|
|
4
4
|
id: MarketEntity['id'];
|
|
5
5
|
exchangeId: MarketEntity['orderInfo']['exchangeId'];
|
|
6
6
|
counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
|
|
7
|
-
currentPrice: number;
|
|
8
7
|
minOrderSizeBase: MarketEntity['minOrderSizeBase'];
|
|
9
8
|
baseSpacing: MarketEntity['baseSpacing'];
|
|
10
9
|
};
|
|
11
10
|
export type MatchOrderParams = {
|
|
12
11
|
signer: Signer | JsonRpcSigner;
|
|
13
|
-
marginAccountId:
|
|
12
|
+
marginAccountId: number;
|
|
14
13
|
amountInBase: number;
|
|
15
14
|
market: MarketParams;
|
|
16
15
|
tradeSource?: 'reya' | 'rage' | 'other';
|
|
17
16
|
};
|
|
18
17
|
export type CloseOrderParams = {
|
|
19
18
|
signer: Signer | JsonRpcSigner;
|
|
20
|
-
marginAccountId:
|
|
19
|
+
marginAccountId: number;
|
|
21
20
|
orderBase: PositionEntity['base'];
|
|
22
21
|
market: MarketParams;
|
|
23
22
|
} & ({
|
|
@@ -32,7 +31,7 @@ export type MatchOrderResult = {
|
|
|
32
31
|
xpBoost: number;
|
|
33
32
|
lotteryXpBoost: number;
|
|
34
33
|
isNftWon: boolean;
|
|
35
|
-
marginAccountId:
|
|
34
|
+
marginAccountId: number;
|
|
36
35
|
xpEarned: number;
|
|
37
36
|
executionPrice: number;
|
|
38
37
|
base: number;
|
|
@@ -46,7 +45,7 @@ export type CloseOrderResult = {
|
|
|
46
45
|
xpBoost: number;
|
|
47
46
|
lotteryXpBoost: number;
|
|
48
47
|
isNftWon: boolean;
|
|
49
|
-
marginAccountId:
|
|
48
|
+
marginAccountId: number;
|
|
50
49
|
xpEarned: number;
|
|
51
50
|
executionPrice: number;
|
|
52
51
|
base: number;
|
|
@@ -54,7 +53,7 @@ export type CloseOrderResult = {
|
|
|
54
53
|
export type MethodParametersAndEIP712Payload = MethodParameters & CoreCommandsEIP712SignatureAndPayload;
|
|
55
54
|
export type OrdersGatewayMarketOrderParams = {
|
|
56
55
|
signer: Signer | JsonRpcSigner;
|
|
57
|
-
marginAccountId:
|
|
56
|
+
marginAccountId: number;
|
|
58
57
|
marketId: MarketEntity['id'];
|
|
59
58
|
counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
|
|
60
59
|
exchangeId: MarketEntity['orderInfo']['exchangeId'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,qCAAqC,EACrC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,qCAAqC,EACrC,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC;IACpD,sBAAsB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAC5E,gBAAgB,EAAE,YAAY,CAAC,kBAAkB,CAAC,CAAC;IACnD,WAAW,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,EAAE,YAAY,CAAC;CACtB,GAAG,CACA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,CAAC;IAC7B,sBAAsB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAC5E,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC;IACpD,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,EACA,sBAAsB,CAAC,YAAY,GACnC,sBAAsB,CAAC,wBAAwB,CAAC;KACrD,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.138.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@reyaxyz/common": "0.
|
|
32
|
+
"@reyaxyz/common": "0.312.0",
|
|
33
33
|
"axios": "1.6.2",
|
|
34
34
|
"bignumber.js": "9.1.2",
|
|
35
35
|
"ethers": "6.9.0"
|
|
36
36
|
},
|
|
37
37
|
"packageManager": "pnpm@8.3.1",
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "9466fb19baa2841b90d1d99f5eb4ca44bf457e73"
|
|
39
39
|
}
|
package/src/services/lp/types.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { JsonRpcSigner, Signer } from 'ethers';
|
|
|
2
2
|
import {
|
|
3
3
|
LpPoolEntity,
|
|
4
4
|
LpWithdrawBalanceEntity,
|
|
5
|
-
MarginAccountEntity,
|
|
6
5
|
MoneyInOutChainId,
|
|
7
6
|
OwnerMetadataEntity,
|
|
8
7
|
ReyaChainId,
|
|
@@ -14,7 +13,7 @@ import {
|
|
|
14
13
|
export type TransferStakeToMarginAccountParams = {
|
|
15
14
|
signer: Signer | JsonRpcSigner;
|
|
16
15
|
owner: Pick<OwnerMetadataEntity, 'address' | 'poolSigNonce'>;
|
|
17
|
-
marginAccountId:
|
|
16
|
+
marginAccountId: number;
|
|
18
17
|
pool: Pick<LpPoolEntity, 'id'>;
|
|
19
18
|
srusdAmount: number;
|
|
20
19
|
};
|
|
@@ -27,7 +26,7 @@ export type TransferStakeToMarginAccountResult = {
|
|
|
27
26
|
export type UnstakeFromMarginAccountParams = {
|
|
28
27
|
signer: Signer | JsonRpcSigner;
|
|
29
28
|
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
30
|
-
marginAccountId:
|
|
29
|
+
marginAccountId: number;
|
|
31
30
|
pool: Pick<LpPoolEntity, 'id'>;
|
|
32
31
|
srusdAmount: number;
|
|
33
32
|
};
|
|
@@ -40,7 +39,7 @@ export type UnstakeFromMarginAccountResult = {
|
|
|
40
39
|
export type StakeFromMarginAccountParams = {
|
|
41
40
|
signer: Signer | JsonRpcSigner;
|
|
42
41
|
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
43
|
-
marginAccountId:
|
|
42
|
+
marginAccountId: number;
|
|
44
43
|
pool: Pick<LpPoolEntity, 'id' | 'tokenAddress'>;
|
|
45
44
|
amount: number;
|
|
46
45
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
MarginRatioHealth,
|
|
4
4
|
MoneyInOutChainId,
|
|
5
5
|
OwnerMetadataEntity,
|
|
6
6
|
SocketDepositFees,
|
|
@@ -15,13 +15,13 @@ export type CreateAccountParams = {
|
|
|
15
15
|
|
|
16
16
|
export type CreateAccountResult = {
|
|
17
17
|
transactionHash: string | null;
|
|
18
|
-
accountId:
|
|
18
|
+
accountId: number | null;
|
|
19
19
|
coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export type DepositParams = {
|
|
23
23
|
signer: Signer | JsonRpcSigner;
|
|
24
|
-
marginAccountId:
|
|
24
|
+
marginAccountId: number;
|
|
25
25
|
tokenAddress: TokenEntity['address'];
|
|
26
26
|
amount: number;
|
|
27
27
|
};
|
|
@@ -32,7 +32,7 @@ export type DepositResult = {
|
|
|
32
32
|
|
|
33
33
|
export type WithdrawParams = {
|
|
34
34
|
signer: Signer | JsonRpcSigner;
|
|
35
|
-
marginAccountId:
|
|
35
|
+
marginAccountId: number;
|
|
36
36
|
tokenAddress: TokenEntity['address'];
|
|
37
37
|
amount: number;
|
|
38
38
|
};
|
|
@@ -43,14 +43,14 @@ export type WithdrawResult = {
|
|
|
43
43
|
|
|
44
44
|
export type SimulateDepositResult = {
|
|
45
45
|
bridgeGasFees: number;
|
|
46
|
-
marginRatioHealth:
|
|
47
|
-
marginRatio:
|
|
46
|
+
marginRatioHealth: MarginRatioHealth;
|
|
47
|
+
marginRatio: number;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// TODO: Milan reevaluate these params
|
|
51
51
|
export type SimulateDepositParams = {
|
|
52
52
|
signer: Signer | JsonRpcSigner;
|
|
53
|
-
marginAccountId:
|
|
53
|
+
marginAccountId: number;
|
|
54
54
|
tokenAddress: TokenEntity['address'];
|
|
55
55
|
amount: number;
|
|
56
56
|
};
|
|
@@ -58,14 +58,14 @@ export type SimulateDepositParams = {
|
|
|
58
58
|
export type SimulateWithdrawResult = {
|
|
59
59
|
bridgeGasFees: number;
|
|
60
60
|
|
|
61
|
-
marginRatioHealth:
|
|
62
|
-
marginRatio:
|
|
61
|
+
marginRatioHealth: MarginRatioHealth;
|
|
62
|
+
marginRatio: number;
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
// TODO: Milan reevaluate these params
|
|
66
66
|
export type SimulateWithdrawParams = {
|
|
67
67
|
signer: Signer | JsonRpcSigner;
|
|
68
|
-
marginAccountId:
|
|
68
|
+
marginAccountId: number;
|
|
69
69
|
tokenAddress: TokenEntity['address'];
|
|
70
70
|
amount: number;
|
|
71
71
|
};
|
|
@@ -73,8 +73,8 @@ export type SimulateWithdrawParams = {
|
|
|
73
73
|
export type TransferMarginBetweenAccountsParams = {
|
|
74
74
|
signer: Signer | JsonRpcSigner;
|
|
75
75
|
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
76
|
-
fromMarginAccountId:
|
|
77
|
-
toMarginAccountId:
|
|
76
|
+
fromMarginAccountId: number;
|
|
77
|
+
toMarginAccountId: number;
|
|
78
78
|
tokenAddress: TokenEntity['address'];
|
|
79
79
|
amount: number;
|
|
80
80
|
};
|
|
@@ -88,7 +88,7 @@ export type WithdrawMAAndBridgeParams = {
|
|
|
88
88
|
signer: Signer | JsonRpcSigner;
|
|
89
89
|
moneyInOutChainId: MoneyInOutChainId;
|
|
90
90
|
owner: Pick<OwnerMetadataEntity, 'address' | 'coreSigNonce'>;
|
|
91
|
-
marginAccountId:
|
|
91
|
+
marginAccountId: number;
|
|
92
92
|
tokenAddress: TokenEntity['address'];
|
|
93
93
|
amount: number;
|
|
94
94
|
// if not provided it has same value as owner.address
|
|
@@ -114,7 +114,7 @@ export type BridgeAndDepositNewMAResult = {
|
|
|
114
114
|
|
|
115
115
|
export type BridgeAndDepositExistingMAParams = {
|
|
116
116
|
signer: Signer | JsonRpcSigner;
|
|
117
|
-
marginAccountId:
|
|
117
|
+
marginAccountId: number;
|
|
118
118
|
tokenAddress: TokenEntity['address'];
|
|
119
119
|
amount: number;
|
|
120
120
|
socketDepositFees: SocketDepositFees['fees'];
|
|
@@ -127,15 +127,15 @@ export type BridgeAndDepositExistingMAResult = {
|
|
|
127
127
|
|
|
128
128
|
export type SimulateTransferMarginBetweenAccountsResult = {
|
|
129
129
|
bridgeGasFees: number;
|
|
130
|
-
marginRatioHealth:
|
|
131
|
-
marginRatio:
|
|
130
|
+
marginRatioHealth: MarginRatioHealth;
|
|
131
|
+
marginRatio: number;
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
// TODO: Milan reevaluate these params
|
|
135
135
|
export type SimulateTransferMarginBetweenAccountsParams = {
|
|
136
136
|
signer: Signer | JsonRpcSigner;
|
|
137
|
-
fromMarginAccountId:
|
|
138
|
-
toMarginAccountId:
|
|
137
|
+
fromMarginAccountId: number;
|
|
138
|
+
toMarginAccountId: number;
|
|
139
139
|
tokenAddress: TokenEntity['address'];
|
|
140
140
|
amount: number;
|
|
141
141
|
};
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from './types';
|
|
8
8
|
import { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
calculateMaxPriceLimit,
|
|
11
11
|
ORDERS_GATEWAY_DEADLINE_IN_SECONDS,
|
|
12
12
|
OrdersGatewayAbi,
|
|
13
13
|
OrdersGatewayOrderType,
|
|
@@ -107,12 +107,7 @@ export const matchOrder = async (
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const orderBaseE18 = scale(18)(snappedAmount);
|
|
110
|
-
const
|
|
111
|
-
const orderPriceLimitE18 = calculatePriceLimitForTrade(
|
|
112
|
-
params.market.currentPrice,
|
|
113
|
-
snappedAmount,
|
|
114
|
-
slippageFactor,
|
|
115
|
-
);
|
|
110
|
+
const orderPriceLimitE18 = calculateMaxPriceLimit(snappedAmount > 0);
|
|
116
111
|
|
|
117
112
|
const result = await executeMarketOrderViaOrdersGateway({
|
|
118
113
|
signer: params.signer,
|
|
@@ -174,12 +169,7 @@ export const closeOrder = async (
|
|
|
174
169
|
}
|
|
175
170
|
}
|
|
176
171
|
|
|
177
|
-
const
|
|
178
|
-
const orderPriceLimit = calculatePriceLimitForTrade(
|
|
179
|
-
params.market.currentPrice,
|
|
180
|
-
-closingBase,
|
|
181
|
-
slippageFactor,
|
|
182
|
-
);
|
|
172
|
+
const orderPriceLimit = calculateMaxPriceLimit(closingBase < 0);
|
|
183
173
|
|
|
184
174
|
const result = await executeMarketOrderViaOrdersGateway({
|
|
185
175
|
signer: params.signer,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Signer, JsonRpcSigner } from 'ethers';
|
|
2
2
|
import {
|
|
3
3
|
CoreCommandsEIP712SignatureAndPayload,
|
|
4
|
-
MarginAccountEntity,
|
|
5
4
|
MarketEntity,
|
|
6
5
|
MethodParameters,
|
|
7
6
|
OrdersGatewayOrderType,
|
|
@@ -14,14 +13,13 @@ export type MarketParams = {
|
|
|
14
13
|
id: MarketEntity['id'];
|
|
15
14
|
exchangeId: MarketEntity['orderInfo']['exchangeId'];
|
|
16
15
|
counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
|
|
17
|
-
currentPrice: number;
|
|
18
16
|
minOrderSizeBase: MarketEntity['minOrderSizeBase'];
|
|
19
17
|
baseSpacing: MarketEntity['baseSpacing'];
|
|
20
18
|
};
|
|
21
19
|
|
|
22
20
|
export type MatchOrderParams = {
|
|
23
21
|
signer: Signer | JsonRpcSigner;
|
|
24
|
-
marginAccountId:
|
|
22
|
+
marginAccountId: number;
|
|
25
23
|
amountInBase: number; // amount in base
|
|
26
24
|
market: MarketParams;
|
|
27
25
|
tradeSource?: 'reya' | 'rage' | 'other';
|
|
@@ -29,7 +27,7 @@ export type MatchOrderParams = {
|
|
|
29
27
|
|
|
30
28
|
export type CloseOrderParams = {
|
|
31
29
|
signer: Signer | JsonRpcSigner;
|
|
32
|
-
marginAccountId:
|
|
30
|
+
marginAccountId: number;
|
|
33
31
|
orderBase: PositionEntity['base'];
|
|
34
32
|
market: MarketParams;
|
|
35
33
|
} & (
|
|
@@ -48,7 +46,7 @@ export type MatchOrderResult = {
|
|
|
48
46
|
xpBoost: number;
|
|
49
47
|
lotteryXpBoost: number;
|
|
50
48
|
isNftWon: boolean;
|
|
51
|
-
marginAccountId:
|
|
49
|
+
marginAccountId: number;
|
|
52
50
|
xpEarned: number;
|
|
53
51
|
executionPrice: number;
|
|
54
52
|
base: number;
|
|
@@ -63,7 +61,7 @@ export type CloseOrderResult = {
|
|
|
63
61
|
xpBoost: number;
|
|
64
62
|
lotteryXpBoost: number;
|
|
65
63
|
isNftWon: boolean;
|
|
66
|
-
marginAccountId:
|
|
64
|
+
marginAccountId: number;
|
|
67
65
|
xpEarned: number;
|
|
68
66
|
executionPrice: number;
|
|
69
67
|
base: number;
|
|
@@ -74,7 +72,7 @@ export type MethodParametersAndEIP712Payload = MethodParameters &
|
|
|
74
72
|
|
|
75
73
|
export type OrdersGatewayMarketOrderParams = {
|
|
76
74
|
signer: Signer | JsonRpcSigner;
|
|
77
|
-
marginAccountId:
|
|
75
|
+
marginAccountId: number;
|
|
78
76
|
marketId: MarketEntity['id'];
|
|
79
77
|
counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
|
|
80
78
|
exchangeId: MarketEntity['orderInfo']['exchangeId'];
|