@reyaxyz/sdk 0.106.1 → 0.106.3

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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/config/index.js +35 -1
  3. package/dist/config/index.js.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/services/conditional-orders/grant-trade-permission/encode.js +69 -0
  7. package/dist/services/conditional-orders/grant-trade-permission/encode.js.map +1 -0
  8. package/dist/services/conditional-orders/grant-trade-permission/grantTradePermission.js +67 -0
  9. package/dist/services/conditional-orders/grant-trade-permission/grantTradePermission.js.map +1 -0
  10. package/dist/services/conditional-orders/grant-trade-permission/index.js +19 -0
  11. package/dist/services/conditional-orders/grant-trade-permission/index.js.map +1 -0
  12. package/dist/services/conditional-orders/grant-trade-permission/types.js +3 -0
  13. package/dist/services/conditional-orders/grant-trade-permission/types.js.map +1 -0
  14. package/dist/services/conditional-orders/index.js +18 -0
  15. package/dist/services/conditional-orders/index.js.map +1 -0
  16. package/dist/services/isolated-order/isolatedOrder.js +2 -0
  17. package/dist/services/isolated-order/isolatedOrder.js.map +1 -1
  18. package/dist/services/isolated-order/types.js.map +1 -1
  19. package/dist/services/orders/order.js +14 -10
  20. package/dist/services/orders/order.js.map +1 -1
  21. package/dist/services/orders/types.js.map +1 -1
  22. package/dist/types/config/index.d.ts +5 -1
  23. package/dist/types/config/index.d.ts.map +1 -1
  24. package/dist/types/index.d.ts +1 -0
  25. package/dist/types/index.d.ts.map +1 -1
  26. package/dist/types/services/conditional-orders/grant-trade-permission/encode.d.ts +4 -0
  27. package/dist/types/services/conditional-orders/grant-trade-permission/encode.d.ts.map +1 -0
  28. package/dist/types/services/conditional-orders/grant-trade-permission/grantTradePermission.d.ts +3 -0
  29. package/dist/types/services/conditional-orders/grant-trade-permission/grantTradePermission.d.ts.map +1 -0
  30. package/dist/types/services/conditional-orders/grant-trade-permission/index.d.ts +3 -0
  31. package/dist/types/services/conditional-orders/grant-trade-permission/index.d.ts.map +1 -0
  32. package/dist/types/services/conditional-orders/grant-trade-permission/types.d.ts +11 -0
  33. package/dist/types/services/conditional-orders/grant-trade-permission/types.d.ts.map +1 -0
  34. package/dist/types/services/conditional-orders/index.d.ts +2 -0
  35. package/dist/types/services/conditional-orders/index.d.ts.map +1 -0
  36. package/dist/types/services/isolated-order/isolatedOrder.d.ts.map +1 -1
  37. package/dist/types/services/isolated-order/types.d.ts +2 -0
  38. package/dist/types/services/isolated-order/types.d.ts.map +1 -1
  39. package/dist/types/services/orders/order.d.ts.map +1 -1
  40. package/dist/types/services/orders/types.d.ts +4 -0
  41. package/dist/types/services/orders/types.d.ts.map +1 -1
  42. package/package.json +3 -3
  43. package/src/config/index.ts +40 -0
  44. package/src/index.ts +1 -0
  45. package/src/services/conditional-orders/grant-trade-permission/encode.ts +45 -0
  46. package/src/services/conditional-orders/grant-trade-permission/grantTradePermission.ts +38 -0
  47. package/src/services/conditional-orders/grant-trade-permission/index.ts +2 -0
  48. package/src/services/conditional-orders/grant-trade-permission/types.ts +12 -0
  49. package/src/services/conditional-orders/index.ts +1 -0
  50. package/src/services/isolated-order/isolatedOrder.ts +2 -0
  51. package/src/services/isolated-order/types.ts +2 -0
  52. package/src/services/orders/order.ts +4 -0
  53. package/src/services/orders/types.ts +4 -0
package/README.md CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-11.33%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-6.19%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-6.66%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-10.72%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-11.13%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-5.55%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-6.25%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-10.57%25-red.svg?style=flat) |
10
10
 
@@ -51,7 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
51
51
  }
52
52
  };
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.getAlphaTermsModuleClient = exports.getTransactionModuleClient = exports.configureSDK = exports.getSdkEnvironment = exports.AlphaTermsModule = exports.TransactionModule = void 0;
54
+ exports.getApiInteractionsModule = exports.getAlphaTermsModuleClient = exports.getTransactionModuleClient = exports.configureSDK = exports.getSdkEnvironment = exports.ApiInteractionsModule = exports.AlphaTermsModule = exports.TransactionModule = void 0;
55
55
  var common_1 = require("@reyaxyz/common");
56
56
  var TransactionModule = /** @class */ (function (_super) {
57
57
  __extends(TransactionModule, _super);
@@ -110,9 +110,36 @@ var AlphaTermsModule = /** @class */ (function (_super) {
110
110
  return AlphaTermsModule;
111
111
  }(common_1.RestClient));
112
112
  exports.AlphaTermsModule = AlphaTermsModule;
113
+ var ApiInteractionsModule = /** @class */ (function (_super) {
114
+ __extends(ApiInteractionsModule, _super);
115
+ function ApiInteractionsModule() {
116
+ return _super !== null && _super.apply(this, arguments) || this;
117
+ }
118
+ ApiInteractionsModule.prototype.createSLOrder = function (accountId, marketId, isLong, stopPrice, signerWallet, nonce, signature) {
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ var uri;
121
+ return __generator(this, function (_a) {
122
+ uri = "/api/conditional-orders/sl/create-order";
123
+ return [2 /*return*/, this.post(uri, {}, {
124
+ accountId: accountId,
125
+ marketId: marketId,
126
+ isLong: isLong,
127
+ stopPrice: stopPrice,
128
+ signerWallet: signerWallet,
129
+ nonce: nonce,
130
+ signature: signature,
131
+ status: common_1.StopLossOrderStatus.NEW,
132
+ })];
133
+ });
134
+ });
135
+ };
136
+ return ApiInteractionsModule;
137
+ }(common_1.RestClient));
138
+ exports.ApiInteractionsModule = ApiInteractionsModule;
113
139
  // Internal state
114
140
  var transactionModule = new TransactionModule(common_1.API_CLIENT_CONFIGS['test'].apiEndpoint);
115
141
  var alphaTermsModule = new AlphaTermsModule(common_1.API_CLIENT_CONFIGS['test'].apiEndpoint);
142
+ var apiInteractionsModule = new ApiInteractionsModule(common_1.API_CLIENT_CONFIGS['test'].apiEndpoint);
116
143
  var sdkEnv = 'test';
117
144
  var getSdkEnvironment = function () {
118
145
  return sdkEnv;
@@ -124,6 +151,7 @@ var configureSDK = function (environment) {
124
151
  sdkEnv = environment;
125
152
  transactionModule = new TransactionModule(config.apiEndpoint);
126
153
  alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);
154
+ apiInteractionsModule = new ApiInteractionsModule(config.apiEndpoint);
127
155
  };
128
156
  exports.configureSDK = configureSDK;
129
157
  var getTransactionModuleClient = function () {
@@ -138,4 +166,10 @@ var getAlphaTermsModuleClient = function () {
138
166
  return alphaTermsModule;
139
167
  };
140
168
  exports.getAlphaTermsModuleClient = getAlphaTermsModuleClient;
169
+ var getApiInteractionsModule = function () {
170
+ if (!apiInteractionsModule)
171
+ throw new Error('SDK is not configured! Call configureSDK()');
172
+ return apiInteractionsModule;
173
+ };
174
+ exports.getApiInteractionsModule = getApiInteractionsModule;
141
175
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAOyB;AAYzB;IAAuC,qCAAU;IAAjD;;IAwCA,CAAC;IAvCO,8CAAkB,GAAxB,UACE,MAAc,EACd,eAAuB,EACvB,QAAsC;;;;gBAEhC,GAAG,GAAG,uCAAuC,CAAC;gBACpD,uFAAuF;gBACvF,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF;wBACE,MAAM,EAAE,MAAM;wBACd,eAAe,iBAAA;wBACf,QAAQ,UAAA;qBACT,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CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AACF,gCAAgC;AACzB,IAAM,YAAY,GAAG,UAC1B,WAAyC;IAEzC,IAAM,MAAM,GAAG,2BAAkB,CAAC,WAAW,CAAC,IAAI,2BAAkB,CAAC,MAAM,CAAC,CAAC;IAC7E,MAAM,GAAG,WAAW,CAAC;IACrB,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9D,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC9D,CAAC,CAAC;AAPW,QAAA,YAAY,gBAOvB;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,yBAAyB,GAAG;IACvC,IAAI,CAAC,gBAAgB;QACnB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAJW,QAAA,yBAAyB,6BAIpC","sourcesContent":["import {\n Address,\n API_CLIENT_CONFIGS,\n RestClient,\n ServiceConfig,\n TransactionExecutionMetadata,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\ntype AlphaTermsData = {\n walletAddress: Address;\n link: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: TransactionExecutionMetadata,\n ) {\n const uri = `/api/transaction-gelato/executeGelato`;\n // const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer\n return this.post<TransactionExecutionOutput>(\n uri,\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\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 AlphaTermsModule extends RestClient {\n async registerAlphaSignature(params: AlphaTermsData): Promise<void> {\n // Build formData object.\n const formData = new FormData();\n formData.append('walletAddress', params.walletAddress);\n formData.append('signedLink', params.link);\n\n const uri = '/api/tos/alpha-signatures';\n return this.post(uri, undefined, formData, undefined);\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\nlet alphaTermsModule: AlphaTermsModule = new AlphaTermsModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\n\nlet sdkEnv: ServiceConfig['environment'] = 'test';\n\nexport const getSdkEnvironment = (): ServiceConfig['environment'] => {\n return sdkEnv;\n};\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n const config = API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n sdkEnv = environment;\n transactionModule = new TransactionModule(config.apiEndpoint);\n alphaTermsModule = new AlphaTermsModule(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 getAlphaTermsModuleClient = (): AlphaTermsModule => {\n if (!alphaTermsModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return alphaTermsModule;\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CASyB;AAYzB;IAAuC,qCAAU;IAAjD;;IAwCA,CAAC;IAvCO,8CAAkB,GAAxB,UACE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qBAAqB,GAAG,IAAI,qBAAqB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACxE,CAAC,CAAC;AARW,QAAA,YAAY,gBAQvB;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,yBAAyB,GAAG;IACvC,IAAI,CAAC,gBAAgB;QACnB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAJW,QAAA,yBAAyB,6BAIpC;AAEK,IAAM,wBAAwB,GAAG;IACtC,IAAI,CAAC,qBAAqB;QACxB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,qBAAqB,CAAC;AAC/B,CAAC,CAAC;AAJW,QAAA,wBAAwB,4BAInC","sourcesContent":["import {\n Address,\n API_CLIENT_CONFIGS,\n RestClient,\n ServiceConfig,\n TransactionExecutionMetadata,\n TransactionExecutionOutput,\n StopLossOrderStatus,\n StopLossOrder,\n} from '@reyaxyz/common';\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\ntype AlphaTermsData = {\n walletAddress: Address;\n link: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: TransactionExecutionMetadata,\n ) {\n const uri = `/api/transaction-gelato/executeGelato`;\n // const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer\n return this.post<TransactionExecutionOutput>(\n uri,\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\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 AlphaTermsModule extends RestClient {\n async registerAlphaSignature(params: AlphaTermsData): Promise<void> {\n // Build formData object.\n const formData = new FormData();\n formData.append('walletAddress', params.walletAddress);\n formData.append('signedLink', params.link);\n\n const uri = '/api/tos/alpha-signatures';\n return this.post(uri, undefined, formData, undefined);\n }\n}\n\nexport class ApiInteractionsModule extends RestClient {\n async createSLOrder(\n accountId: number,\n marketId: number,\n isLong: boolean,\n stopPrice: number,\n signerWallet: string,\n nonce: number,\n signature: string,\n ) {\n const uri = `/api/conditional-orders/sl/create-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: accountId,\n marketId: marketId,\n isLong: isLong,\n stopPrice: stopPrice,\n signerWallet: signerWallet,\n nonce: nonce,\n signature: signature,\n status: StopLossOrderStatus.NEW,\n },\n );\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\nlet alphaTermsModule: AlphaTermsModule = new AlphaTermsModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\nlet apiInteractionsModule: ApiInteractionsModule = new ApiInteractionsModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\n\nlet sdkEnv: ServiceConfig['environment'] = 'test';\n\nexport const getSdkEnvironment = (): ServiceConfig['environment'] => {\n return sdkEnv;\n};\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n const config = API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n sdkEnv = environment;\n transactionModule = new TransactionModule(config.apiEndpoint);\n alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);\n apiInteractionsModule = new ApiInteractionsModule(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 getAlphaTermsModuleClient = (): AlphaTermsModule => {\n if (!alphaTermsModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return alphaTermsModule;\n};\n\nexport const getApiInteractionsModule = (): ApiInteractionsModule => {\n if (!apiInteractionsModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return apiInteractionsModule;\n};\n"]}
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./services/lp"), exports);
19
19
  __exportStar(require("./services/margin-accounts"), exports);
20
20
  __exportStar(require("./services/money-flows"), exports);
21
21
  __exportStar(require("./services/orders"), exports);
22
+ __exportStar(require("./services/conditional-orders"), exports);
22
23
  __exportStar(require("./services/isolated-order"), exports);
23
24
  __exportStar(require("./services/token"), exports);
24
25
  var config_1 = require("./config");
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,4DAA0C;AAC1C,mDAAiC;AACjC,mCAAwC;AAA/B,sGAAA,YAAY,OAAA","sourcesContent":["export * from './services/lp';\nexport * from './services/margin-accounts';\nexport * from './services/money-flows';\nexport * from './services/orders';\nexport * from './services/isolated-order';\nexport * from './services/token';\nexport { configureSDK } from './config';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA2C;AAC3C,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAC9C,4DAA0C;AAC1C,mDAAiC;AACjC,mCAAwC;AAA/B,sGAAA,YAAY,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/isolated-order';\nexport * from './services/token';\nexport { configureSDK } from './config';\n"]}
@@ -0,0 +1,69 @@
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.encodeGrantTradePermission = void 0;
40
+ var common_1 = require("@reyaxyz/common");
41
+ var common_2 = require("@reyaxyz/common");
42
+ var common_3 = require("@reyaxyz/common");
43
+ var ethers_1 = require("ethers");
44
+ var encodeGrantTradePermission = function (signer, chainId, coreSigNonce, accountId) { return __awaiter(void 0, void 0, void 0, function () {
45
+ var permission, user, eip712Signature, value, functionSignature, parameters, INTERFACE, calldata;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ permission = (0, common_2.getPermission)(common_2.CoreAccountPermissionTypes.MATCH_ORDER);
50
+ user = (0, common_2.getAddress)(chainId, common_2.ContractType.CONDITIONAL_ORDERS_PROXY);
51
+ return [4 /*yield*/, (0, common_2.signGrantPermission)(signer, chainId, accountId, permission, user, coreSigNonce + 1, (0, common_2.getCurrentTimestampInSeconds)() + common_3.CORE_DEADLINE_IN_SECONDS)];
52
+ case 1:
53
+ eip712Signature = _a.sent();
54
+ value = BigInt(0);
55
+ functionSignature = 'grantAccountPermissionBySig';
56
+ parameters = [
57
+ { accountId: accountId, permission: permission, user: user, sig: eip712Signature },
58
+ ];
59
+ INTERFACE = new ethers_1.Interface(common_1.CoreAbi);
60
+ calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
61
+ return [2 /*return*/, {
62
+ calldata: calldata,
63
+ value: BigInt(value).toString(10),
64
+ }];
65
+ }
66
+ });
67
+ }); };
68
+ exports.encodeGrantTradePermission = encodeGrantTradePermission;
69
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/encode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAmE;AACnE,0CAOyB;AACzB,0CAA2D;AAC3D,iCAA2C;AAEpC,IAAM,0BAA0B,GAAG,UACxC,MAAc,EACd,OAAe,EACf,YAAoB,EACpB,SAAiB;;;;;gBAEX,UAAU,GAAG,IAAA,sBAAa,EAAC,mCAA0B,CAAC,WAAW,CAAC,CAAC;gBACnE,IAAI,GAAG,IAAA,mBAAU,EAAC,OAAO,EAAE,qBAAY,CAAC,wBAAwB,CAAC,CAAC;gBAEhD,qBAAM,IAAA,4BAAmB,EAC/C,MAAM,EACN,OAAO,EACP,SAAS,EACT,UAAU,EACV,IAAI,EACJ,YAAY,GAAG,CAAC,EAChB,IAAA,qCAA4B,GAAE,GAAG,iCAAwB,CAC1D,EAAA;;gBARK,eAAe,GAAG,SAQvB;gBAEK,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAElB,iBAAiB,GAAG,6BAA6B,CAAC;gBAClD,UAAU,GAAG;oBACjB,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,YAAA,EAAE,IAAI,MAAA,EAAE,GAAG,EAAE,eAAe,EAAE;iBACjE,CAAC;gBAEI,SAAS,GAAG,IAAI,kBAAS,CAAC,gBAAG,CAAC,CAAC;gBAC/B,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;gBAC7E,sBAAO;wBACL,QAAQ,EAAE,QAAQ;wBAClB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;qBAClC,EAAC;;;KACH,CAAC;AAhCW,QAAA,0BAA0B,8BAgCrC","sourcesContent":["import { MethodParameters, CoreAbi as abi } from '@reyaxyz/common';\nimport {\n getCurrentTimestampInSeconds,\n ContractType,\n getAddress,\n CoreAccountPermissionTypes,\n getPermission,\n signGrantPermission,\n} from '@reyaxyz/common';\nimport { CORE_DEADLINE_IN_SECONDS } from '@reyaxyz/common';\nimport { Interface, Signer } from 'ethers';\n\nexport const encodeGrantTradePermission = async (\n signer: Signer,\n chainId: number,\n coreSigNonce: number,\n accountId: number,\n): Promise<MethodParameters> => {\n const permission = getPermission(CoreAccountPermissionTypes.MATCH_ORDER);\n const user = getAddress(chainId, ContractType.CONDITIONAL_ORDERS_PROXY);\n\n const eip712Signature = await signGrantPermission(\n signer,\n chainId,\n accountId,\n permission,\n user,\n coreSigNonce + 1,\n getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,\n );\n\n const value = BigInt(0);\n\n const functionSignature = 'grantAccountPermissionBySig';\n const parameters = [\n { accountId: accountId, permission, user, sig: eip712Signature },\n ];\n\n const INTERFACE = new Interface(abi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return {\n calldata: calldata,\n value: BigInt(value).toString(10),\n };\n};\n"]}
@@ -0,0 +1,67 @@
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.grantTradePermission = void 0;
40
+ var encode_1 = require("./encode");
41
+ var signAndBroadcastTransaction_1 = require("../../signAndBroadcastTransaction");
42
+ var common_1 = require("@reyaxyz/common");
43
+ var common_2 = require("@reyaxyz/common");
44
+ var config_1 = require("../../../config");
45
+ var grantTradePermission = function (params) { return __awaiter(void 0, void 0, void 0, function () {
46
+ var env, chainId, _a, data, value, result;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ env = (0, config_1.getSdkEnvironment)();
51
+ chainId = (0, common_1.getReyaNetwork)(env === 'production' ? 'production' : 'test');
52
+ return [4 /*yield*/, (0, encode_1.encodeGrantTradePermission)(params.signer, chainId, params.owner.coreSigNonce, params.accountId)];
53
+ case 1:
54
+ _a = _b.sent(), data = _a.calldata, value = _a.value;
55
+ return [4 /*yield*/, (0, signAndBroadcastTransaction_1.signAndBroadcastTransaction)(params.signer, data, value, chainId, common_2.ContractType.CORE_PROXY, {
56
+ accountId: params.accountId,
57
+ })];
58
+ case 2:
59
+ result = _b.sent();
60
+ return [2 /*return*/, {
61
+ transactionHash: (result === null || result === void 0 ? void 0 : result.txHash) || null,
62
+ }];
63
+ }
64
+ });
65
+ }); };
66
+ exports.grantTradePermission = grantTradePermission;
67
+ //# sourceMappingURL=grantTradePermission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grantTradePermission.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/grantTradePermission.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mCAAsD;AACtD,iFAAgF;AAChF,0CAAiD;AACjD,0CAA+C;AAC/C,0CAAoD;AAE7C,IAAM,oBAAoB,GAAG,UAClC,MAAkC;;;;;gBAE5B,GAAG,GAAG,IAAA,0BAAiB,GAAE,CAAC;gBAC1B,OAAO,GAAG,IAAA,uBAAc,EAAC,GAAG,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;gBAE3C,qBAAM,IAAA,mCAA0B,EAChE,MAAM,CAAC,MAAM,EACb,OAAO,EACP,MAAM,CAAC,KAAK,CAAC,YAAY,EACzB,MAAM,CAAC,SAAS,CACjB,EAAA;;gBALK,KAA4B,SAKjC,EALiB,IAAI,cAAA,EAAE,KAAK,WAAA;gBAOd,qBAAM,IAAA,yDAA2B,EAC9C,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,qBAAY,CAAC,UAAU,EACvB;wBACE,SAAS,EAAE,MAAM,CAAC,SAAS;qBAC5B,CACF,EAAA;;gBATK,MAAM,GAAG,SASd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;qBACxC,EAAC;;;KACH,CAAC;AA3BW,QAAA,oBAAoB,wBA2B/B","sourcesContent":["import {\n GrantTradePermissionParams,\n GrantTradePermissionResult,\n} from './types';\nimport { encodeGrantTradePermission } from './encode';\nimport { signAndBroadcastTransaction } from '../../signAndBroadcastTransaction';\nimport { getReyaNetwork } from '@reyaxyz/common';\nimport { ContractType } from '@reyaxyz/common';\nimport { getSdkEnvironment } from '../../../config';\n\nexport const grantTradePermission = async (\n params: GrantTradePermissionParams,\n): Promise<GrantTradePermissionResult> => {\n const env = getSdkEnvironment();\n const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');\n\n const { calldata: data, value } = await encodeGrantTradePermission(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.accountId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.CORE_PROXY,\n {\n accountId: params.accountId,\n },\n );\n\n return {\n transactionHash: result?.txHash || null,\n };\n};\n"]}
@@ -0,0 +1,19 @@
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("./grantTradePermission"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,yDAAuC","sourcesContent":["export * from './types';\nexport * from './grantTradePermission';\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/types.ts"],"names":[],"mappings":"","sourcesContent":["import { OwnerMetadataEntity } from '@reyaxyz/common';\nimport { JsonRpcSigner, Signer } from 'ethers';\n\nexport type GrantTradePermissionParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n accountId: number;\n};\n\nexport type GrantTradePermissionResult = {\n transactionHash: string | null;\n};\n"]}
@@ -0,0 +1,18 @@
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("./grant-trade-permission"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["services/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC","sourcesContent":["export * from './grant-trade-permission';\n"]}
@@ -94,6 +94,8 @@ var isolatedOrder = function (params) { return __awaiter(void 0, void 0, void 0,
94
94
  isNftWon: matchOrderResult.isNftWon,
95
95
  marginAccountId: createAccountResult.accountId,
96
96
  xpEarned: matchOrderResult.xpEarned,
97
+ executionPrice: matchOrderResult.executionPrice,
98
+ base: matchOrderResult.base,
97
99
  }];
98
100
  }
99
101
  });
@@ -1 +1 @@
1
- {"version":3,"file":"isolatedOrder.js","sourceRoot":"/","sources":["services/isolated-order/isolatedOrder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAG4B;AAC5B,oCAAuC;AAGhC,IAAM,aAAa,GAAG,UAC3B,MAA2B;;;;oBAQC,qBAAM,IAAA,+BAAa,EAAC;oBAC9C,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;oBAClC,IAAI,EAAE,wBAAwB;iBAC/B,CAAC,EAAA;;gBAHI,mBAAmB,GAAG,SAG1B;gBAEF,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;gBAC5E,CAAC;sBAIgD,EAA5B,KAAA,MAAM,CAAC,qBAAqB;;;qBAA5B,CAAA,cAA4B,CAAA;gBAAtC,MAAM;gBACf,6FAA6F;gBAC7F,qBAAM,IAAA,+CAA6B,EAAC;wBAClC,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;wBAC/C,iBAAiB,EAAE,mBAAmB,CAAC,SAAS;wBAChD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC;wBACxC,YAAY,EAAE,MAAM,CAAC,iBAAiB;qBACvC,CAAC,EAAA;;gBARF,6FAA6F;gBAC7F,SAOE,CAAC;;;gBATgB,IAA4B,CAAA;;;gBAkB3C,oBAAoB,GAGtB;oBACF,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC;oBAC3C,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;iBAC9B,CAAC;gBAGuB,qBAAM,IAAA,mBAAU,EAAC;wBACxC,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,KAAK,EAAE,oBAAoB;wBAC3B,eAAe,EAAE,mBAAmB,CAAC,SAAS;wBAC9C,YAAY,EAAE,MAAM,CAAC,YAAY;wBACjC,MAAM,EAAE,MAAM,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,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;wBACnC,eAAe,EAAE,mBAAmB,CAAC,SAAS;wBAC9C,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;qBACpC,EAAC;;;KACH,CAAC;AA/DW,QAAA,aAAa,iBA+DxB","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 isNftWon: matchOrderResult.isNftWon,\n marginAccountId: createAccountResult.accountId,\n xpEarned: matchOrderResult.xpEarned,\n };\n};\n"]}
1
+ {"version":3,"file":"isolatedOrder.js","sourceRoot":"/","sources":["services/isolated-order/isolatedOrder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAG4B;AAC5B,oCAAuC;AAGhC,IAAM,aAAa,GAAG,UAC3B,MAA2B;;;;oBAQC,qBAAM,IAAA,+BAAa,EAAC;oBAC9C,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;oBAClC,IAAI,EAAE,wBAAwB;iBAC/B,CAAC,EAAA;;gBAHI,mBAAmB,GAAG,SAG1B;gBAEF,IAAI,CAAC,mBAAmB,CAAC,SAA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mB,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;AAjEW,QAAA,aAAa,iBAiExB","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 isNftWon: matchOrderResult.isNftWon,\n marginAccountId: createAccountResult.accountId,\n xpEarned: matchOrderResult.xpEarned,\n executionPrice: matchOrderResult.executionPrice,\n base: matchOrderResult.base,\n };\n};\n"]}
@@ -1 +1 @@
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 isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n};\n"]}
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 isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n executionPrice: number;\n base: number;\n};\n"]}
@@ -49,9 +49,9 @@ var common_3 = require("@reyaxyz/common");
49
49
  var config_1 = require("../../config");
50
50
  var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
51
51
  var snappedAmount, orderPriceLimit, orderBase, env, chainId, _a, data, value, result;
52
- var _b, _c, _d;
53
- return __generator(this, function (_e) {
54
- switch (_e.label) {
52
+ var _b, _c, _d, _e, _f;
53
+ return __generator(this, function (_g) {
54
+ switch (_g.label) {
55
55
  case 0:
56
56
  if (params.amountInBase === 0) {
57
57
  throw new Error('Position base can not be 0');
@@ -75,14 +75,14 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
75
75
  chainId = (0, common_1.getReyaNetwork)(env === 'production' ? 'production' : 'test');
76
76
  return [4 /*yield*/, (0, encode_1.encodeMatchOrder)(params.signer, chainId, params.owner.coreSigNonce, params.marginAccountId, orderBase, orderPriceLimit, params.market.counterpartyAccountIds, params.market.id, params.market.exchangeId)];
77
77
  case 1:
78
- _a = _e.sent(), data = _a.calldata, value = _a.value;
78
+ _a = _g.sent(), data = _a.calldata, value = _a.value;
79
79
  return [4 /*yield*/, (0, signAndBroadcastTransaction_1.signAndBroadcastTransaction)(params.signer, data, value, chainId, common_2.ContractType.PERIPHERY_PROXY, {
80
80
  action: 'matchOrder',
81
81
  accountId: params.marginAccountId,
82
82
  marketId: params.market.id,
83
83
  })];
84
84
  case 2:
85
- result = _e.sent();
85
+ result = _g.sent();
86
86
  return [2 /*return*/, {
87
87
  transactionHash: (result === null || result === void 0 ? void 0 : result.txHash) || null,
88
88
  coreSigNonce: Number(result === null || result === void 0 ? void 0 : result.coreSigNonce) || null,
@@ -90,6 +90,8 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
90
90
  isNftWon: ((_c = result.miscellaneous) === null || _c === void 0 ? void 0 : _c.xpNftAwarded) || false,
91
91
  marginAccountId: params.marginAccountId,
92
92
  xpEarned: ((_d = result.miscellaneous) === null || _d === void 0 ? void 0 : _d.xpEarned) || 0,
93
+ executionPrice: ((_e = result.tradeDetails) === null || _e === void 0 ? void 0 : _e.executionPrice) || 0,
94
+ base: ((_f = result.tradeDetails) === null || _f === void 0 ? void 0 : _f.base) || 0,
93
95
  }];
94
96
  }
95
97
  });
@@ -97,9 +99,9 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
97
99
  exports.matchOrder = matchOrder;
98
100
  var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
99
101
  var base, orderPriceLimit, env, chainId, _a, data, value, result;
100
- var _b, _c, _d;
101
- return __generator(this, function (_e) {
102
- switch (_e.label) {
102
+ var _b, _c, _d, _e, _f;
103
+ return __generator(this, function (_g) {
104
+ switch (_g.label) {
103
105
  case 0:
104
106
  if (params.orderBase === 0) {
105
107
  throw new Error('Position base can not be 0');
@@ -110,14 +112,14 @@ var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
110
112
  chainId = (0, common_1.getReyaNetwork)(env === 'production' ? 'production' : 'test');
111
113
  return [4 /*yield*/, (0, encode_1.encodeMatchOrder)(params.signer, chainId, params.owner.coreSigNonce, params.marginAccountId, -base, orderPriceLimit, params.market.counterpartyAccountIds, params.market.id, params.market.exchangeId)];
112
114
  case 1:
113
- _a = _e.sent(), data = _a.calldata, value = _a.value;
115
+ _a = _g.sent(), data = _a.calldata, value = _a.value;
114
116
  return [4 /*yield*/, (0, signAndBroadcastTransaction_1.signAndBroadcastTransaction)(params.signer, data, value, chainId, common_2.ContractType.PERIPHERY_PROXY, {
115
117
  action: 'closeOrder',
116
118
  accountId: params.marginAccountId,
117
119
  marketId: params.market.id,
118
120
  })];
119
121
  case 2:
120
- result = _e.sent();
122
+ result = _g.sent();
121
123
  return [2 /*return*/, {
122
124
  transactionHash: (result === null || result === void 0 ? void 0 : result.txHash) || null,
123
125
  coreSigNonce: Number(result === null || result === void 0 ? void 0 : result.coreSigNonce) || null,
@@ -125,6 +127,8 @@ var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
125
127
  isNftWon: ((_c = result.miscellaneous) === null || _c === void 0 ? void 0 : _c.xpNftAwarded) || false,
126
128
  marginAccountId: params.marginAccountId,
127
129
  xpEarned: ((_d = result.miscellaneous) === null || _d === void 0 ? void 0 : _d.xpEarned) || 0,
130
+ executionPrice: ((_e = result.tradeDetails) === null || _e === void 0 ? void 0 : _e.executionPrice) || 0,
131
+ base: ((_f = result.tradeDetails) === null || _f === void 0 ? void 0 : _f.base) || 0,
128
132
  }];
129
133
  }
130
134
  });
@@ -1 +1 @@
1
- {"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,mCAA4C;AAC5C,8EAA6E;AAC7E,0CAA8E;AAC9E,8DAAqC;AACrC,0CAA+C;AAC/C,0CAAwC;AACxC,uCAAiD;AAE1C,IAAM,UAAU,GAAG,UACxB,MAAwB;;;;;;gBAExB,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAChD,CAAC;gBAEG,aAAa,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,YAAY,CAAC;qBAC/C,GAAG,EAAE;qBACL,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;qBACpC,YAAY,CAAC,sBAAS,CAAC,WAAW,CAAC;qBACnC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;qBACvC,QAAQ,EAAE,CAAC;gBAEd,IAAI,MAAM,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;oBAC5B,aAAa,GAAG,CAAC,aAAa,CAAC;gBACjC,CAAC;gBAED,IAAI,IAAI,CAAC,GAAG,CAAC,aAA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,EACf,MAAM,CAAC,MAAM,CAAC,sBAAsB,EACpC,MAAM,CAAC,MAAM,CAAC,EAAE,EAChB,MAAM,CAAC,MAAM,CAAC,UAAU,CACzB,EAAA;;gBAVK,KAA4B,SAUjC,EAViB,IAAI,cAAA,EAAE,KAAK,WAAA;gBAYd,qBAAM,IAAA,yDAA2B,EAC9C,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,qBAAY,CAAC,eAAe,EAC5B;wBACE,MAAM,EAAE,YAAY;wBACpB,SAAS,EAAE,MAAM,CAAC,eAAe;wBACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE;qBAC3B,CACF,EAAA;;gBAXK,MAAM,GAAG,SAWd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;wBACvC,YAAY,EAAE,MAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,CAAC,IAAI,IAAI;wBAClD,OAAO,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,YAAY,KAAI,CAAC;wBAChD,QAAQ,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,YAAY,KAAI,KAAK;wBACrD,eAAe,EAAE,MAAM,CAAC,eAAe;wBACvC,QAAQ,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,QAAQ,KAAI,CAAC;qBAC9C,EAAC;;;KACH,CAAC;AAhDW,QAAA,UAAU,cAgDrB","sourcesContent":["import {\n CloseOrderParams,\n CloseOrderResult,\n MatchOrderParams,\n MatchOrderResult,\n} from './types';\nimport { encodeMatchOrder } from './encode';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport { calculatePriceLimitForTrade, getReyaNetwork } from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { ContractType } from '@reyaxyz/common';\nimport { scale } from '@reyaxyz/common';\nimport { getSdkEnvironment } from '../../config';\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n if (params.amountInBase === 0) {\n throw new Error('Position base can not be 0');\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 // add rounding here\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n snappedAmount,\n );\n\n const orderBase = scale(18)(snappedAmount);\n const env = getSdkEnvironment();\n const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');\n\n const { calldata: data, value } = await encodeMatchOrder(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.marginAccountId,\n orderBase,\n orderPriceLimit,\n params.market.counterpartyAccountIds,\n params.market.id,\n params.market.exchangeId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.PERIPHERY_PROXY,\n {\n action: 'matchOrder',\n accountId: params.marginAccountId,\n marketId: params.market.id,\n },\n );\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n };\n};\n\nexport const closeOrder = async (\n params: CloseOrderParams,\n): Promise<CloseOrderResult> => {\n if (params.orderBase === 0) {\n throw new Error('Position base can not be 0');\n }\n\n const base = scale(18)(params.orderBase);\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n BigNumber(params.orderBase).negated().toNumber(), // used just because of sign\n );\n\n const env = getSdkEnvironment();\n const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');\n const { calldata: data, value } = await encodeMatchOrder(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.marginAccountId,\n -base,\n orderPriceLimit,\n params.market.counterpartyAccountIds,\n params.market.id,\n params.market.exchangeId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.PERIPHERY_PROXY,\n {\n action: 'closeOrder',\n accountId: params.marginAccountId,\n marketId: params.market.id,\n },\n );\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n };\n};\n"]}
1
+ {"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,mCAA4C;AAC5C,8EAA6E;AAC7E,0CAA8E;AAC9E,8DAAqC;AACrC,0CAA+C;AAC/C,0CAAwC;AACxC,uCAAiD;AAE1C,IAAM,UAAU,GAAG,UACxB,MAAwB;;;;;;gBAExB,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAChD,CAAC;gBAEG,aAAa,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,YAAY,CAAC;qBAC/C,GAAG,EAAE;qBACL,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;qBACpC,YAAY,CAAC,sBAAS,CAAC,WAAW,CAAC;qBACnC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;qBACvC,QAAQ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,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,cAAc,KAAI,CAAC;wBACxD,IAAI,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,IAAI,KAAI,CAAC;qBACrC,EAAC;;;KACH,CAAC;AAlDW,QAAA,UAAU,cAkDrB","sourcesContent":["import {\n CloseOrderParams,\n CloseOrderResult,\n MatchOrderParams,\n MatchOrderResult,\n} from './types';\nimport { encodeMatchOrder } from './encode';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport { calculatePriceLimitForTrade, getReyaNetwork } from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { ContractType } from '@reyaxyz/common';\nimport { scale } from '@reyaxyz/common';\nimport { getSdkEnvironment } from '../../config';\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n if (params.amountInBase === 0) {\n throw new Error('Position base can not be 0');\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 // add rounding here\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n snappedAmount,\n );\n\n const orderBase = scale(18)(snappedAmount);\n const env = getSdkEnvironment();\n const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');\n\n const { calldata: data, value } = await encodeMatchOrder(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.marginAccountId,\n orderBase,\n orderPriceLimit,\n params.market.counterpartyAccountIds,\n params.market.id,\n params.market.exchangeId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.PERIPHERY_PROXY,\n {\n action: 'matchOrder',\n accountId: params.marginAccountId,\n marketId: params.market.id,\n },\n );\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 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\nexport const closeOrder = async (\n params: CloseOrderParams,\n): Promise<CloseOrderResult> => {\n if (params.orderBase === 0) {\n throw new Error('Position base can not be 0');\n }\n\n const base = scale(18)(params.orderBase);\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n BigNumber(params.orderBase).negated().toNumber(), // used just because of sign\n );\n\n const env = getSdkEnvironment();\n const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');\n const { calldata: data, value } = await encodeMatchOrder(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.marginAccountId,\n -base,\n orderPriceLimit,\n params.market.counterpartyAccountIds,\n params.market.id,\n params.market.exchangeId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.PERIPHERY_PROXY,\n {\n action: 'closeOrder',\n accountId: params.marginAccountId,\n marketId: params.market.id,\n },\n );\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 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 MarginAccountEntity,\n MarketEntity,\n OwnerMetadataEntity,\n PositionEntity,\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 owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: MarginAccountEntity['id'];\n amountInBase: number; // amount in base\n market: MarketParams;\n};\n\nexport type CloseOrderParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: MarginAccountEntity['id'];\n orderBase: PositionEntity['base'];\n market: MarketParams;\n};\n\nexport type MatchOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n};\n\nexport type CloseOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer, JsonRpcSigner } from 'ethers';\nimport {\n MarginAccountEntity,\n MarketEntity,\n OwnerMetadataEntity,\n PositionEntity,\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 owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: MarginAccountEntity['id'];\n amountInBase: number; // amount in base\n market: MarketParams;\n};\n\nexport type CloseOrderParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: MarginAccountEntity['id'];\n orderBase: PositionEntity['base'];\n market: MarketParams;\n};\n\nexport type MatchOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n executionPrice: number;\n base: number;\n};\n\nexport type CloseOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n executionPrice: number;\n base: number;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { Address, RestClient, ServiceConfig, TransactionExecutionMetadata, TransactionExecutionOutput } from '@reyaxyz/common';
1
+ import { Address, RestClient, ServiceConfig, TransactionExecutionMetadata, TransactionExecutionOutput, StopLossOrder } from '@reyaxyz/common';
2
2
  export type TxData = {
3
3
  to: string;
4
4
  data: string;
@@ -16,9 +16,13 @@ export declare class TransactionModule extends RestClient {
16
16
  export declare class AlphaTermsModule extends RestClient {
17
17
  registerAlphaSignature(params: AlphaTermsData): Promise<void>;
18
18
  }
19
+ export declare class ApiInteractionsModule extends RestClient {
20
+ createSLOrder(accountId: number, marketId: number, isLong: boolean, stopPrice: number, signerWallet: string, nonce: number, signature: string): Promise<StopLossOrder>;
21
+ }
19
22
  export declare const getSdkEnvironment: () => ServiceConfig['environment'];
20
23
  export declare const configureSDK: (environment: ServiceConfig['environment']) => void;
21
24
  export declare const getTransactionModuleClient: () => TransactionModule;
22
25
  export declare const getAlphaTermsModuleClient: () => AlphaTermsModule;
26
+ export declare const getApiInteractionsModule: () => ApiInteractionsModule;
23
27
  export {};
24
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACV,aAAa,EACb,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,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;IAelC,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,gBAAiB,SAAQ,UAAU;IACxC,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASpE;AAYD,eAAO,MAAM,iBAAiB,QAAO,aAAa,CAAC,aAAa,CAE/D,CAAC;AAEF,eAAO,MAAM,YAAY,gBACV,aAAa,CAAC,aAAa,CAAC,KACxC,IAKF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAO,gBAI5C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"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 +2,7 @@ export * from './services/lp';
2
2
  export * from './services/margin-accounts';
3
3
  export * from './services/money-flows';
4
4
  export * from './services/orders';
5
+ export * from './services/conditional-orders';
5
6
  export * from './services/isolated-order';
6
7
  export * from './services/token';
7
8
  export { configureSDK } from './config';
@@ -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,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,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,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { MethodParameters } from '@reyaxyz/common';
2
+ import { Signer } from 'ethers';
3
+ export declare const encodeGrantTradePermission: (signer: Signer, chainId: number, coreSigNonce: number, accountId: number) => Promise<MethodParameters>;
4
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,iBAAiB,CAAC;AAUnE,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,0BAA0B,WAC7B,MAAM,WACL,MAAM,gBACD,MAAM,aACT,MAAM,KAChB,QAAQ,gBAAgB,CA2B1B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { GrantTradePermissionParams, GrantTradePermissionResult } from './types';
2
+ export declare const grantTradePermission: (params: GrantTradePermissionParams) => Promise<GrantTradePermissionResult>;
3
+ //# sourceMappingURL=grantTradePermission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grantTradePermission.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/grantTradePermission.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAOjB,eAAO,MAAM,oBAAoB,WACvB,0BAA0B,KACjC,QAAQ,0BAA0B,CAyBpC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './grantTradePermission';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { OwnerMetadataEntity } from '@reyaxyz/common';
2
+ import { JsonRpcSigner, Signer } from 'ethers';
3
+ export type GrantTradePermissionParams = {
4
+ signer: Signer | JsonRpcSigner;
5
+ owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
6
+ accountId: number;
7
+ };
8
+ export type GrantTradePermissionResult = {
9
+ transactionHash: string | null;
10
+ };
11
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './grant-trade-permission';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -1 +1 @@
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,CA6D7B,CAAC"}
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,CA+D7B,CAAC"}
@@ -16,5 +16,7 @@ export type IsolatedOrderResult = {
16
16
  isNftWon: boolean;
17
17
  marginAccountId: MarginAccountEntity['id'];
18
18
  xpEarned: number;
19
+ executionPrice: number;
20
+ base: number;
19
21
  };
20
22
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
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,mBAA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AY,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,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 +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,EACjB,MAAM,SAAS,CAAC;AASjB,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAkE1B,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CA8C1B,CAAC"}
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,EACjB,MAAM,SAAS,CAAC;AASjB,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAoE1B,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAgD1B,CAAC"}
@@ -29,6 +29,8 @@ export type MatchOrderResult = {
29
29
  isNftWon: boolean;
30
30
  marginAccountId: MarginAccountEntity['id'];
31
31
  xpEarned: number;
32
+ executionPrice: number;
33
+ base: number;
32
34
  };
33
35
  export type CloseOrderResult = {
34
36
  transactionHash: string | null;
@@ -37,5 +39,7 @@ export type CloseOrderResult = {
37
39
  isNftWon: boolean;
38
40
  marginAccountId: MarginAccountEntity['id'];
39
41
  xpEarned: number;
42
+ executionPrice: number;
43
+ base: number;
40
44
  };
41
45
  //# sourceMappingURL=types.d.ts.map
@@ -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,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACf,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,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACjD,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACjD,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,SAAS,EA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C;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/sdk",
3
- "version": "0.106.1",
3
+ "version": "0.106.3",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -29,10 +29,10 @@
29
29
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
30
30
  },
31
31
  "dependencies": {
32
- "@reyaxyz/common": "0.155.0",
32
+ "@reyaxyz/common": "0.155.2",
33
33
  "bignumber.js": "^9.1.2",
34
34
  "ethers": "6.9.0"
35
35
  },
36
36
  "packageManager": "pnpm@8.3.1",
37
- "gitHead": "c59febaa4e5d033b519cab4b28474a780ce26e24"
37
+ "gitHead": "240612564e67810b06016413f108a43c6b234e25"
38
38
  }
@@ -5,6 +5,8 @@ import {
5
5
  ServiceConfig,
6
6
  TransactionExecutionMetadata,
7
7
  TransactionExecutionOutput,
8
+ StopLossOrderStatus,
9
+ StopLossOrder,
8
10
  } from '@reyaxyz/common';
9
11
 
10
12
  export type TxData = {
@@ -71,6 +73,34 @@ export class AlphaTermsModule extends RestClient {
71
73
  }
72
74
  }
73
75
 
76
+ export class ApiInteractionsModule extends RestClient {
77
+ async createSLOrder(
78
+ accountId: number,
79
+ marketId: number,
80
+ isLong: boolean,
81
+ stopPrice: number,
82
+ signerWallet: string,
83
+ nonce: number,
84
+ signature: string,
85
+ ) {
86
+ const uri = `/api/conditional-orders/sl/create-order`;
87
+ return this.post<StopLossOrder>(
88
+ uri,
89
+ {},
90
+ {
91
+ accountId: accountId,
92
+ marketId: marketId,
93
+ isLong: isLong,
94
+ stopPrice: stopPrice,
95
+ signerWallet: signerWallet,
96
+ nonce: nonce,
97
+ signature: signature,
98
+ status: StopLossOrderStatus.NEW,
99
+ },
100
+ );
101
+ }
102
+ }
103
+
74
104
  // Internal state
75
105
  let transactionModule: TransactionModule = new TransactionModule(
76
106
  API_CLIENT_CONFIGS['test'].apiEndpoint,
@@ -78,6 +108,9 @@ let transactionModule: TransactionModule = new TransactionModule(
78
108
  let alphaTermsModule: AlphaTermsModule = new AlphaTermsModule(
79
109
  API_CLIENT_CONFIGS['test'].apiEndpoint,
80
110
  );
111
+ let apiInteractionsModule: ApiInteractionsModule = new ApiInteractionsModule(
112
+ API_CLIENT_CONFIGS['test'].apiEndpoint,
113
+ );
81
114
 
82
115
  let sdkEnv: ServiceConfig['environment'] = 'test';
83
116
 
@@ -92,6 +125,7 @@ export const configureSDK = (
92
125
  sdkEnv = environment;
93
126
  transactionModule = new TransactionModule(config.apiEndpoint);
94
127
  alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);
128
+ apiInteractionsModule = new ApiInteractionsModule(config.apiEndpoint);
95
129
  };
96
130
 
97
131
  export const getTransactionModuleClient = (): TransactionModule => {
@@ -105,3 +139,9 @@ export const getAlphaTermsModuleClient = (): AlphaTermsModule => {
105
139
  throw new Error('SDK is not configured! Call configureSDK()');
106
140
  return alphaTermsModule;
107
141
  };
142
+
143
+ export const getApiInteractionsModule = (): ApiInteractionsModule => {
144
+ if (!apiInteractionsModule)
145
+ throw new Error('SDK is not configured! Call configureSDK()');
146
+ return apiInteractionsModule;
147
+ };
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './services/lp';
2
2
  export * from './services/margin-accounts';
3
3
  export * from './services/money-flows';
4
4
  export * from './services/orders';
5
+ export * from './services/conditional-orders';
5
6
  export * from './services/isolated-order';
6
7
  export * from './services/token';
7
8
  export { configureSDK } from './config';
@@ -0,0 +1,45 @@
1
+ import { MethodParameters, CoreAbi as abi } from '@reyaxyz/common';
2
+ import {
3
+ getCurrentTimestampInSeconds,
4
+ ContractType,
5
+ getAddress,
6
+ CoreAccountPermissionTypes,
7
+ getPermission,
8
+ signGrantPermission,
9
+ } from '@reyaxyz/common';
10
+ import { CORE_DEADLINE_IN_SECONDS } from '@reyaxyz/common';
11
+ import { Interface, Signer } from 'ethers';
12
+
13
+ export const encodeGrantTradePermission = async (
14
+ signer: Signer,
15
+ chainId: number,
16
+ coreSigNonce: number,
17
+ accountId: number,
18
+ ): Promise<MethodParameters> => {
19
+ const permission = getPermission(CoreAccountPermissionTypes.MATCH_ORDER);
20
+ const user = getAddress(chainId, ContractType.CONDITIONAL_ORDERS_PROXY);
21
+
22
+ const eip712Signature = await signGrantPermission(
23
+ signer,
24
+ chainId,
25
+ accountId,
26
+ permission,
27
+ user,
28
+ coreSigNonce + 1,
29
+ getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,
30
+ );
31
+
32
+ const value = BigInt(0);
33
+
34
+ const functionSignature = 'grantAccountPermissionBySig';
35
+ const parameters = [
36
+ { accountId: accountId, permission, user, sig: eip712Signature },
37
+ ];
38
+
39
+ const INTERFACE = new Interface(abi);
40
+ const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
41
+ return {
42
+ calldata: calldata,
43
+ value: BigInt(value).toString(10),
44
+ };
45
+ };
@@ -0,0 +1,38 @@
1
+ import {
2
+ GrantTradePermissionParams,
3
+ GrantTradePermissionResult,
4
+ } from './types';
5
+ import { encodeGrantTradePermission } from './encode';
6
+ import { signAndBroadcastTransaction } from '../../signAndBroadcastTransaction';
7
+ import { getReyaNetwork } from '@reyaxyz/common';
8
+ import { ContractType } from '@reyaxyz/common';
9
+ import { getSdkEnvironment } from '../../../config';
10
+
11
+ export const grantTradePermission = async (
12
+ params: GrantTradePermissionParams,
13
+ ): Promise<GrantTradePermissionResult> => {
14
+ const env = getSdkEnvironment();
15
+ const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');
16
+
17
+ const { calldata: data, value } = await encodeGrantTradePermission(
18
+ params.signer,
19
+ chainId,
20
+ params.owner.coreSigNonce,
21
+ params.accountId,
22
+ );
23
+
24
+ const result = await signAndBroadcastTransaction(
25
+ params.signer,
26
+ data,
27
+ value,
28
+ chainId,
29
+ ContractType.CORE_PROXY,
30
+ {
31
+ accountId: params.accountId,
32
+ },
33
+ );
34
+
35
+ return {
36
+ transactionHash: result?.txHash || null,
37
+ };
38
+ };
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './grantTradePermission';
@@ -0,0 +1,12 @@
1
+ import { OwnerMetadataEntity } from '@reyaxyz/common';
2
+ import { JsonRpcSigner, Signer } from 'ethers';
3
+
4
+ export type GrantTradePermissionParams = {
5
+ signer: Signer | JsonRpcSigner;
6
+ owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
7
+ accountId: number;
8
+ };
9
+
10
+ export type GrantTradePermissionResult = {
11
+ transactionHash: string | null;
12
+ };
@@ -0,0 +1 @@
1
+ export * from './grant-trade-permission';
@@ -68,5 +68,7 @@ export const isolatedOrder = async (
68
68
  isNftWon: matchOrderResult.isNftWon,
69
69
  marginAccountId: createAccountResult.accountId,
70
70
  xpEarned: matchOrderResult.xpEarned,
71
+ executionPrice: matchOrderResult.executionPrice,
72
+ base: matchOrderResult.base,
71
73
  };
72
74
  };
@@ -22,4 +22,6 @@ export type IsolatedOrderResult = {
22
22
  isNftWon: boolean;
23
23
  marginAccountId: MarginAccountEntity['id'];
24
24
  xpEarned: number;
25
+ executionPrice: number;
26
+ base: number;
25
27
  };
@@ -79,6 +79,8 @@ export const matchOrder = async (
79
79
  isNftWon: result.miscellaneous?.xpNftAwarded || false,
80
80
  marginAccountId: params.marginAccountId,
81
81
  xpEarned: result.miscellaneous?.xpEarned || 0,
82
+ executionPrice: result.tradeDetails?.executionPrice || 0,
83
+ base: result.tradeDetails?.base || 0,
82
84
  };
83
85
  };
84
86
 
@@ -129,5 +131,7 @@ export const closeOrder = async (
129
131
  isNftWon: result.miscellaneous?.xpNftAwarded || false,
130
132
  marginAccountId: params.marginAccountId,
131
133
  xpEarned: result.miscellaneous?.xpEarned || 0,
134
+ executionPrice: result.tradeDetails?.executionPrice || 0,
135
+ base: result.tradeDetails?.base || 0,
132
136
  };
133
137
  };
@@ -38,6 +38,8 @@ export type MatchOrderResult = {
38
38
  isNftWon: boolean;
39
39
  marginAccountId: MarginAccountEntity['id'];
40
40
  xpEarned: number;
41
+ executionPrice: number;
42
+ base: number;
41
43
  };
42
44
 
43
45
  export type CloseOrderResult = {
@@ -47,4 +49,6 @@ export type CloseOrderResult = {
47
49
  isNftWon: boolean;
48
50
  marginAccountId: MarginAccountEntity['id'];
49
51
  xpEarned: number;
52
+ executionPrice: number;
53
+ base: number;
50
54
  };