@reyaxyz/sdk 0.134.36 → 0.135.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/config/index.js +5 -23
- package/dist/config/index.js.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/services/orders/types.js.map +1 -1
- package/dist/types/config/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/orders/types.d.ts +0 -2
- package/dist/types/services/orders/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/config/index.ts +4 -25
- package/src/index.ts +0 -1
- package/src/services/orders/types.ts +0 -2
- package/dist/services/isolated-order/index.js +0 -19
- package/dist/services/isolated-order/index.js.map +0 -1
- package/dist/services/isolated-order/isolatedOrder.js +0 -105
- package/dist/services/isolated-order/isolatedOrder.js.map +0 -1
- package/dist/services/isolated-order/types.js +0 -3
- package/dist/services/isolated-order/types.js.map +0 -1
- package/dist/types/services/isolated-order/index.d.ts +0 -3
- package/dist/types/services/isolated-order/index.d.ts.map +0 -1
- package/dist/types/services/isolated-order/isolatedOrder.d.ts +0 -3
- package/dist/types/services/isolated-order/isolatedOrder.d.ts.map +0 -1
- package/dist/types/services/isolated-order/types.d.ts +0 -23
- package/dist/types/services/isolated-order/types.d.ts.map +0 -1
- package/src/services/isolated-order/index.ts +0 -2
- package/src/services/isolated-order/isolatedOrder.ts +0 -75
- package/src/services/isolated-order/types.ts +0 -28
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
package/dist/config/index.js
CHANGED
|
@@ -60,35 +60,17 @@ var TransactionModule = /** @class */ (function (_super) {
|
|
|
60
60
|
}
|
|
61
61
|
TransactionModule.prototype.executeTransaction = function (txData, contractAddress, metadata) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
var
|
|
63
|
+
var result;
|
|
64
64
|
return __generator(this, function (_a) {
|
|
65
65
|
switch (_a.label) {
|
|
66
|
-
case 0:
|
|
67
|
-
isReyaExecutorEnabled = process.env.IS_REYA_EXECUTOR_ENABLED === 'true' || false;
|
|
68
|
-
if (!isReyaExecutorEnabled) return [3 /*break*/, 4];
|
|
69
|
-
_a.label = 1;
|
|
70
|
-
case 1:
|
|
71
|
-
_a.trys.push([1, 3, , 4]);
|
|
72
|
-
return [4 /*yield*/, this.post('/api/transaction-gelato/executeReya', {}, {
|
|
73
|
-
txData: txData,
|
|
74
|
-
contractAddress: contractAddress,
|
|
75
|
-
metadata: metadata,
|
|
76
|
-
})];
|
|
77
|
-
case 2:
|
|
78
|
-
result = _a.sent();
|
|
79
|
-
if (result.txHash) {
|
|
80
|
-
return [2 /*return*/, result];
|
|
81
|
-
}
|
|
82
|
-
return [3 /*break*/, 4];
|
|
83
|
-
case 3:
|
|
84
|
-
error_1 = _a.sent();
|
|
85
|
-
console.warn('Reya executor failed', error_1);
|
|
86
|
-
return [3 /*break*/, 4];
|
|
87
|
-
case 4: return [2 /*return*/, this.post('/api/transaction-gelato/executeGelato', {}, {
|
|
66
|
+
case 0: return [4 /*yield*/, this.post('/api/transaction-gelato/executeReya', {}, {
|
|
88
67
|
txData: txData,
|
|
89
68
|
contractAddress: contractAddress,
|
|
90
69
|
metadata: metadata,
|
|
91
70
|
})];
|
|
71
|
+
case 1:
|
|
72
|
+
result = _a.sent();
|
|
73
|
+
return [2 /*return*/, result];
|
|
92
74
|
}
|
|
93
75
|
});
|
|
94
76
|
});
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AM,CAAC,CAAC,WAAW,CACvC,CAAC;AAEF,IAAI,iBAAiB,GAAsB,IAAI,iBAAiB,CAC9D,IAAA,2BAAkB,EAAC,MAAM,CAAC,CAAC,WAAW,CACvC,CAAC;AAEF,IAAI,MAAqB,CAAC;AAEnB,IAAM,YAAY,GAAG;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAEF,gCAAgC;AACzB,IAAM,YAAY,GAAG,UAC1B,WAAyC;IAEzC,MAAM,GAAG,IAAA,2BAAkB,EAAC,WAAW,CAAC,CAAC;IACzC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9D,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAChE,CAAC,CAAC;AANW,QAAA,YAAY,gBAMvB;AAEK,IAAM,0BAA0B,GAAG;IACxC,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC;AAEK,IAAM,0BAA0B,GAAG;IACxC,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC","sourcesContent":["import {\n RestClient,\n ServiceConfig,\n TransactionExecutionMetadata,\n TransactionExecutionOutput,\n CollateralWithHaircut,\n getApiClientConfig,\n} from '@reyaxyz/common';\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: TransactionExecutionMetadata,\n ): Promise<TransactionExecutionOutput> {\n const result = await this.post<TransactionExecutionOutput>(\n '/api/transaction-gelato/executeReya',\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n\n return result;\n }\n\n async pushPendingTransaction(\n marginAccountId: number,\n transactionHash: string,\n sourceChainId: number,\n amount: number,\n assetId: string,\n type: string,\n ) {\n const uri = `/api/accounts/${marginAccountId}/push-pending-transaction`;\n return this.post<{ successful: boolean }>(\n uri,\n {},\n {\n tx_hash: transactionHash,\n source_chain_id: sourceChainId,\n amount,\n asset_id: assetId,\n type: type,\n },\n );\n }\n}\n\nexport class GeneralRestModule extends RestClient {\n async getCollateralInfo(): Promise<CollateralWithHaircut[]> {\n return this.get<CollateralWithHaircut[]>(\n `/api/tokens/available-collaterals/excluding-rusd/${false}`,\n );\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n getApiClientConfig('test').apiEndpoint,\n);\n\nlet generalRestModule: GeneralRestModule = new GeneralRestModule(\n getApiClientConfig('test').apiEndpoint,\n);\n\nlet config: ServiceConfig;\n\nexport const getSdkConfig = (): ServiceConfig => {\n return config;\n};\n\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n config = getApiClientConfig(environment);\n transactionModule = new TransactionModule(config.apiEndpoint);\n generalRestModule = new GeneralRestModule(config.apiEndpoint);\n};\n\nexport const getTransactionModuleClient = (): TransactionModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return transactionModule;\n};\n\nexport const getGeneralRestModuleClient = (): GeneralRestModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return generalRestModule;\n};\n"]}
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,6 @@ __exportStar(require("./services/margin-accounts"), exports);
|
|
|
20
20
|
__exportStar(require("./services/money-flows"), exports);
|
|
21
21
|
__exportStar(require("./services/orders"), exports);
|
|
22
22
|
__exportStar(require("./services/conditional-orders"), exports);
|
|
23
|
-
__exportStar(require("./services/isolated-order"), exports);
|
|
24
23
|
__exportStar(require("./services/token"), exports);
|
|
25
24
|
var config_1 = require("./config");
|
|
26
25
|
Object.defineProperty(exports, "configureSDK", { enumerable: true, get: function () { return config_1.configureSDK; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA2C;AAC3C,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA2C;AAC3C,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAC9C,mDAAiC;AACjC,mCAAoE;AAA3D,sGAAA,YAAY,OAAA;AAAE,oHAAA,0BAA0B,OAAA","sourcesContent":["export * from './services/lp';\nexport * from './services/margin-accounts';\nexport * from './services/money-flows';\nexport * from './services/orders';\nexport * from './services/conditional-orders';\nexport * from './services/token';\nexport { configureSDK, getTransactionModuleClient } from './config';\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 MarginAccountEntity,\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 currentPrice: number;\n minOrderSizeBase: MarketEntity['minOrderSizeBase'];\n baseSpacing: MarketEntity['baseSpacing'];\n};\n\nexport type MatchOrderParams = {\n signer: Signer | JsonRpcSigner;\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 MarginAccountEntity,\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 currentPrice: number;\n minOrderSizeBase: MarketEntity['minOrderSizeBase'];\n baseSpacing: MarketEntity['baseSpacing'];\n};\n\nexport type MatchOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\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: MarginAccountEntity['id'];\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: MarginAccountEntity['id'];\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: MarginAccountEntity['id'];\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: MarginAccountEntity['id'];\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,4BAA4B,EAC5B,0BAA0B,EAC1B,qBAAqB,EAEtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,4BAA4B,GACrC,OAAO,CAAC,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,4BAA4B,EAC5B,0BAA0B,EAC1B,qBAAqB,EAEtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,4BAA4B,GACrC,OAAO,CAAC,0BAA0B,CAAC;IAchC,sBAAsB,CAC1B,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM;oBAGmB,OAAO;;CAYzC;AAED,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,iBAAiB,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;CAK5D;AAaD,eAAO,MAAM,YAAY,QAAO,aAE/B,CAAC;AAGF,eAAO,MAAM,YAAY,gBACV,aAAa,CAAC,aAAa,CAAC,KACxC,IAIF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export * from './services/margin-accounts';
|
|
|
3
3
|
export * from './services/money-flows';
|
|
4
4
|
export * from './services/orders';
|
|
5
5
|
export * from './services/conditional-orders';
|
|
6
|
-
export * from './services/isolated-order';
|
|
7
6
|
export * from './services/token';
|
|
8
7
|
export { configureSDK, getTransactionModuleClient } from './config';
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -10,7 +10,6 @@ export type MarketParams = {
|
|
|
10
10
|
};
|
|
11
11
|
export type MatchOrderParams = {
|
|
12
12
|
signer: Signer | JsonRpcSigner;
|
|
13
|
-
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
14
13
|
marginAccountId: MarginAccountEntity['id'];
|
|
15
14
|
amountInBase: number;
|
|
16
15
|
market: MarketParams;
|
|
@@ -18,7 +17,6 @@ export type MatchOrderParams = {
|
|
|
18
17
|
};
|
|
19
18
|
export type CloseOrderParams = {
|
|
20
19
|
signer: Signer | JsonRpcSigner;
|
|
21
|
-
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
22
20
|
marginAccountId: MarginAccountEntity['id'];
|
|
23
21
|
orderBase: PositionEntity['base'];
|
|
24
22
|
market: MarketParams;
|
|
@@ -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,mBAAmB,EACnB,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,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,YAAY,CAAC,kBAAkB,CAAC,CAAC;IACnD,WAAW,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC;CAC1C,C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AAC,CAAC;IAC3C,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,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.135.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"ethers": "6.9.0"
|
|
36
36
|
},
|
|
37
37
|
"packageManager": "pnpm@8.3.1",
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "d8950346218a79fb9f02edebadf1ef7581f899e6"
|
|
39
39
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -18,31 +18,8 @@ export class TransactionModule extends RestClient {
|
|
|
18
18
|
contractAddress: string,
|
|
19
19
|
metadata: TransactionExecutionMetadata,
|
|
20
20
|
): Promise<TransactionExecutionOutput> {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (isReyaExecutorEnabled) {
|
|
25
|
-
try {
|
|
26
|
-
const result = await this.post<TransactionExecutionOutput>(
|
|
27
|
-
'/api/transaction-gelato/executeReya',
|
|
28
|
-
{},
|
|
29
|
-
{
|
|
30
|
-
txData: txData,
|
|
31
|
-
contractAddress,
|
|
32
|
-
metadata,
|
|
33
|
-
},
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
if (result.txHash) {
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.warn('Reya executor failed', error);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return this.post<TransactionExecutionOutput>(
|
|
45
|
-
'/api/transaction-gelato/executeGelato',
|
|
21
|
+
const result = await this.post<TransactionExecutionOutput>(
|
|
22
|
+
'/api/transaction-gelato/executeReya',
|
|
46
23
|
{},
|
|
47
24
|
{
|
|
48
25
|
txData: txData,
|
|
@@ -50,6 +27,8 @@ export class TransactionModule extends RestClient {
|
|
|
50
27
|
metadata,
|
|
51
28
|
},
|
|
52
29
|
);
|
|
30
|
+
|
|
31
|
+
return result;
|
|
53
32
|
}
|
|
54
33
|
|
|
55
34
|
async pushPendingTransaction(
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,5 @@ export * from './services/margin-accounts';
|
|
|
3
3
|
export * from './services/money-flows';
|
|
4
4
|
export * from './services/orders';
|
|
5
5
|
export * from './services/conditional-orders';
|
|
6
|
-
export * from './services/isolated-order';
|
|
7
6
|
export * from './services/token';
|
|
8
7
|
export { configureSDK, getTransactionModuleClient } from './config';
|
|
@@ -21,7 +21,6 @@ export type MarketParams = {
|
|
|
21
21
|
|
|
22
22
|
export type MatchOrderParams = {
|
|
23
23
|
signer: Signer | JsonRpcSigner;
|
|
24
|
-
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
25
24
|
marginAccountId: MarginAccountEntity['id'];
|
|
26
25
|
amountInBase: number; // amount in base
|
|
27
26
|
market: MarketParams;
|
|
@@ -30,7 +29,6 @@ export type MatchOrderParams = {
|
|
|
30
29
|
|
|
31
30
|
export type CloseOrderParams = {
|
|
32
31
|
signer: Signer | JsonRpcSigner;
|
|
33
|
-
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
34
32
|
marginAccountId: MarginAccountEntity['id'];
|
|
35
33
|
orderBase: PositionEntity['base'];
|
|
36
34
|
market: MarketParams;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
18
|
-
__exportStar(require("./isolatedOrder"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/isolated-order/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,kDAAgC","sourcesContent":["export * from './types';\nexport * from './isolatedOrder';\n"]}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.isolatedOrder = void 0;
|
|
40
|
-
var margin_accounts_1 = require("../margin-accounts");
|
|
41
|
-
var orders_1 = require("../orders");
|
|
42
|
-
var isolatedOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
-
var createAccountResult, _i, _a, action, ownerWithBumpedNonce, matchOrderResult;
|
|
44
|
-
return __generator(this, function (_b) {
|
|
45
|
-
switch (_b.label) {
|
|
46
|
-
case 0: return [4 /*yield*/, (0, margin_accounts_1.createAccount)({
|
|
47
|
-
ownerAddress: params.owner.address,
|
|
48
|
-
name: 'Isolated Trade Account',
|
|
49
|
-
})];
|
|
50
|
-
case 1:
|
|
51
|
-
createAccountResult = _b.sent();
|
|
52
|
-
if (!createAccountResult.accountId) {
|
|
53
|
-
throw new Error('New Account Id not available to execute isolated trade');
|
|
54
|
-
}
|
|
55
|
-
_i = 0, _a = params.editCollateralActions;
|
|
56
|
-
_b.label = 2;
|
|
57
|
-
case 2:
|
|
58
|
-
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
59
|
-
action = _a[_i];
|
|
60
|
-
// todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)
|
|
61
|
-
return [4 /*yield*/, (0, margin_accounts_1.transferMarginBetweenAccounts)({
|
|
62
|
-
signer: params.signer,
|
|
63
|
-
owner: params.owner,
|
|
64
|
-
fromMarginAccountId: params.fromMarginAccountId,
|
|
65
|
-
toMarginAccountId: createAccountResult.accountId,
|
|
66
|
-
amount: Math.abs(action.collateralDelta),
|
|
67
|
-
tokenAddress: action.collateralAddress,
|
|
68
|
-
})];
|
|
69
|
-
case 3:
|
|
70
|
-
// todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)
|
|
71
|
-
_b.sent();
|
|
72
|
-
_b.label = 4;
|
|
73
|
-
case 4:
|
|
74
|
-
_i++;
|
|
75
|
-
return [3 /*break*/, 2];
|
|
76
|
-
case 5:
|
|
77
|
-
ownerWithBumpedNonce = {
|
|
78
|
-
coreSigNonce: params.owner.coreSigNonce + 1,
|
|
79
|
-
address: params.owner.address,
|
|
80
|
-
};
|
|
81
|
-
return [4 /*yield*/, (0, orders_1.matchOrder)({
|
|
82
|
-
signer: params.signer,
|
|
83
|
-
owner: ownerWithBumpedNonce,
|
|
84
|
-
marginAccountId: createAccountResult.accountId,
|
|
85
|
-
amountInBase: params.amountInBase,
|
|
86
|
-
market: params.market,
|
|
87
|
-
})];
|
|
88
|
-
case 6:
|
|
89
|
-
matchOrderResult = _b.sent();
|
|
90
|
-
return [2 /*return*/, {
|
|
91
|
-
transactionHash: (matchOrderResult === null || matchOrderResult === void 0 ? void 0 : matchOrderResult.transactionHash) || null,
|
|
92
|
-
coreSigNonce: matchOrderResult.coreSigNonce,
|
|
93
|
-
xpBoost: matchOrderResult.xpBoost,
|
|
94
|
-
lotteryXpBoost: matchOrderResult.lotteryXpBoost,
|
|
95
|
-
isNftWon: matchOrderResult.isNftWon,
|
|
96
|
-
marginAccountId: createAccountResult.accountId,
|
|
97
|
-
xpEarned: matchOrderResult.xpEarned,
|
|
98
|
-
executionPrice: matchOrderResult.executionPrice,
|
|
99
|
-
base: matchOrderResult.base,
|
|
100
|
-
}];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}); };
|
|
104
|
-
exports.isolatedOrder = isolatedOrder;
|
|
105
|
-
//# sourceMappingURL=isolatedOrder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isolatedOrder.js","sourceRoot":"/","sources":["services/isolated-order/isolatedOrder.ts"],"names":[],"mappings":";;;;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M,CAAC,MAAM;qBACtB,CAAC,EAAA;;gBANI,gBAAgB,GAAG,SAMvB;gBAEF,sBAAO;wBACL,eAAe,EAAE,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,eAAe,KAAI,IAAI;wBAC1D,YAAY,EAAE,gBAAgB,CAAC,YAAY;wBAC3C,OAAO,EAAE,gBAAgB,CAAC,OAAO;wBACjC,cAAc,EAAE,gBAAgB,CAAC,cAAc;wBAC/C,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;wBACnC,eAAe,EAAE,mBAAmB,CAAC,SAAS;wBAC9C,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;wBACnC,cAAc,EAAE,gBAAgB,CAAC,cAAc;wBAC/C,IAAI,EAAE,gBAAgB,CAAC,IAAI;qBAC5B,EAAC;;;KACH,CAAC;AAlEW,QAAA,aAAa,iBAkExB","sourcesContent":["import { IsolatedOrderParams, IsolatedOrderResult } from './types';\nimport {\n createAccount,\n transferMarginBetweenAccounts,\n} from '../margin-accounts';\nimport { matchOrder } from '../orders';\nimport { OwnerMetadataEntity } from '@reyaxyz/common';\n\nexport const isolatedOrder = async (\n params: IsolatedOrderParams,\n): Promise<IsolatedOrderResult> => {\n // todo: p2 consider performing all steps in api and only call one api function from here?\n\n // step 1: create new account\n\n // todo: p2: consider having a function that creates an account and auto-generates a name in one go, use it t&cs also\n // todo: p2: error handling & logging\n const createAccountResult = await createAccount({\n ownerAddress: params.owner.address,\n name: 'Isolated Trade Account',\n });\n\n if (!createAccountResult.accountId) {\n throw new Error('New Account Id not available to execute isolated trade');\n }\n\n // step 2: transfer margin from source to destination account\n\n for (const action of params.editCollateralActions) {\n // todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)\n await transferMarginBetweenAccounts({\n signer: params.signer,\n owner: params.owner,\n fromMarginAccountId: params.fromMarginAccountId,\n toMarginAccountId: createAccountResult.accountId,\n amount: Math.abs(action.collateralDelta),\n tokenAddress: action.collateralAddress,\n });\n }\n\n // step 3: execute trade\n\n /*\n * We need to bump the nonce since we've just executed a transfer transaction\n * */\n\n const ownerWithBumpedNonce: Pick<\n OwnerMetadataEntity,\n 'coreSigNonce' | 'address'\n > = {\n coreSigNonce: params.owner.coreSigNonce + 1,\n address: params.owner.address,\n };\n\n // todo: p1: need to increase the nonce for this tx as well\n const matchOrderResult = await matchOrder({\n signer: params.signer,\n owner: ownerWithBumpedNonce,\n marginAccountId: createAccountResult.accountId,\n amountInBase: params.amountInBase,\n market: params.market,\n });\n\n return {\n transactionHash: matchOrderResult?.transactionHash || null,\n coreSigNonce: matchOrderResult.coreSigNonce,\n xpBoost: matchOrderResult.xpBoost,\n lotteryXpBoost: matchOrderResult.lotteryXpBoost,\n isNftWon: matchOrderResult.isNftWon,\n marginAccountId: createAccountResult.accountId,\n xpEarned: matchOrderResult.xpEarned,\n executionPrice: matchOrderResult.executionPrice,\n base: matchOrderResult.base,\n };\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/isolated-order/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer, JsonRpcSigner } from 'ethers';\nimport {\n EditCollateralAction,\n MarginAccountEntity,\n OwnerMetadataEntity,\n} from '@reyaxyz/common';\nimport { MarketParams } from '../orders';\n\nexport type IsolatedOrderParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce' | 'address'>;\n fromMarginAccountId: MarginAccountEntity['id'];\n editCollateralActions: EditCollateralAction[]; // todo: p2: consider abstracting this such that UI doesn't pass this\n amountInBase: number;\n market: MarketParams;\n};\n\nexport type IsolatedOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n lotteryXpBoost: number;\n isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n executionPrice: number;\n base: number;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/isolated-order/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isolatedOrder.d.ts","sourceRoot":"/","sources":["services/isolated-order/isolatedOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAQnE,eAAO,MAAM,aAAa,WAChB,mBAAmB,KAC1B,QAAQ,mBAAmB,CAgE7B,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Signer, JsonRpcSigner } from 'ethers';
|
|
2
|
-
import { EditCollateralAction, MarginAccountEntity, OwnerMetadataEntity } from '@reyaxyz/common';
|
|
3
|
-
import { MarketParams } from '../orders';
|
|
4
|
-
export type IsolatedOrderParams = {
|
|
5
|
-
signer: Signer | JsonRpcSigner;
|
|
6
|
-
owner: Pick<OwnerMetadataEntity, 'coreSigNonce' | 'address'>;
|
|
7
|
-
fromMarginAccountId: MarginAccountEntity['id'];
|
|
8
|
-
editCollateralActions: EditCollateralAction[];
|
|
9
|
-
amountInBase: number;
|
|
10
|
-
market: MarketParams;
|
|
11
|
-
};
|
|
12
|
-
export type IsolatedOrderResult = {
|
|
13
|
-
transactionHash: string | null;
|
|
14
|
-
coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;
|
|
15
|
-
xpBoost: number;
|
|
16
|
-
lotteryXpBoost: number;
|
|
17
|
-
isNftWon: boolean;
|
|
18
|
-
marginAccountId: MarginAccountEntity['id'];
|
|
19
|
-
xpEarned: number;
|
|
20
|
-
executionPrice: number;
|
|
21
|
-
base: number;
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/isolated-order/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;IAC7D,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC/C,qBAAqB,EAAE,oBAAoB,EAAE,CAAC;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,YAAY,EAAE,mBAAmB,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { IsolatedOrderParams, IsolatedOrderResult } from './types';
|
|
2
|
-
import {
|
|
3
|
-
createAccount,
|
|
4
|
-
transferMarginBetweenAccounts,
|
|
5
|
-
} from '../margin-accounts';
|
|
6
|
-
import { matchOrder } from '../orders';
|
|
7
|
-
import { OwnerMetadataEntity } from '@reyaxyz/common';
|
|
8
|
-
|
|
9
|
-
export const isolatedOrder = async (
|
|
10
|
-
params: IsolatedOrderParams,
|
|
11
|
-
): Promise<IsolatedOrderResult> => {
|
|
12
|
-
// todo: p2 consider performing all steps in api and only call one api function from here?
|
|
13
|
-
|
|
14
|
-
// step 1: create new account
|
|
15
|
-
|
|
16
|
-
// todo: p2: consider having a function that creates an account and auto-generates a name in one go, use it t&cs also
|
|
17
|
-
// todo: p2: error handling & logging
|
|
18
|
-
const createAccountResult = await createAccount({
|
|
19
|
-
ownerAddress: params.owner.address,
|
|
20
|
-
name: 'Isolated Trade Account',
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (!createAccountResult.accountId) {
|
|
24
|
-
throw new Error('New Account Id not available to execute isolated trade');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// step 2: transfer margin from source to destination account
|
|
28
|
-
|
|
29
|
-
for (const action of params.editCollateralActions) {
|
|
30
|
-
// todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)
|
|
31
|
-
await transferMarginBetweenAccounts({
|
|
32
|
-
signer: params.signer,
|
|
33
|
-
owner: params.owner,
|
|
34
|
-
fromMarginAccountId: params.fromMarginAccountId,
|
|
35
|
-
toMarginAccountId: createAccountResult.accountId,
|
|
36
|
-
amount: Math.abs(action.collateralDelta),
|
|
37
|
-
tokenAddress: action.collateralAddress,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// step 3: execute trade
|
|
42
|
-
|
|
43
|
-
/*
|
|
44
|
-
* We need to bump the nonce since we've just executed a transfer transaction
|
|
45
|
-
* */
|
|
46
|
-
|
|
47
|
-
const ownerWithBumpedNonce: Pick<
|
|
48
|
-
OwnerMetadataEntity,
|
|
49
|
-
'coreSigNonce' | 'address'
|
|
50
|
-
> = {
|
|
51
|
-
coreSigNonce: params.owner.coreSigNonce + 1,
|
|
52
|
-
address: params.owner.address,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// todo: p1: need to increase the nonce for this tx as well
|
|
56
|
-
const matchOrderResult = await matchOrder({
|
|
57
|
-
signer: params.signer,
|
|
58
|
-
owner: ownerWithBumpedNonce,
|
|
59
|
-
marginAccountId: createAccountResult.accountId,
|
|
60
|
-
amountInBase: params.amountInBase,
|
|
61
|
-
market: params.market,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
transactionHash: matchOrderResult?.transactionHash || null,
|
|
66
|
-
coreSigNonce: matchOrderResult.coreSigNonce,
|
|
67
|
-
xpBoost: matchOrderResult.xpBoost,
|
|
68
|
-
lotteryXpBoost: matchOrderResult.lotteryXpBoost,
|
|
69
|
-
isNftWon: matchOrderResult.isNftWon,
|
|
70
|
-
marginAccountId: createAccountResult.accountId,
|
|
71
|
-
xpEarned: matchOrderResult.xpEarned,
|
|
72
|
-
executionPrice: matchOrderResult.executionPrice,
|
|
73
|
-
base: matchOrderResult.base,
|
|
74
|
-
};
|
|
75
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Signer, JsonRpcSigner } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
EditCollateralAction,
|
|
4
|
-
MarginAccountEntity,
|
|
5
|
-
OwnerMetadataEntity,
|
|
6
|
-
} from '@reyaxyz/common';
|
|
7
|
-
import { MarketParams } from '../orders';
|
|
8
|
-
|
|
9
|
-
export type IsolatedOrderParams = {
|
|
10
|
-
signer: Signer | JsonRpcSigner;
|
|
11
|
-
owner: Pick<OwnerMetadataEntity, 'coreSigNonce' | 'address'>;
|
|
12
|
-
fromMarginAccountId: MarginAccountEntity['id'];
|
|
13
|
-
editCollateralActions: EditCollateralAction[]; // todo: p2: consider abstracting this such that UI doesn't pass this
|
|
14
|
-
amountInBase: number;
|
|
15
|
-
market: MarketParams;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type IsolatedOrderResult = {
|
|
19
|
-
transactionHash: string | null;
|
|
20
|
-
coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;
|
|
21
|
-
xpBoost: number;
|
|
22
|
-
lotteryXpBoost: number;
|
|
23
|
-
isNftWon: boolean;
|
|
24
|
-
marginAccountId: MarginAccountEntity['id'];
|
|
25
|
-
xpEarned: number;
|
|
26
|
-
executionPrice: number;
|
|
27
|
-
base: number;
|
|
28
|
-
};
|