@reyaxyz/common 0.155.2 → 0.155.4

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 CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-15.24%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-14.03%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-9.09%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-15.84%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-15.11%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-14.85%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-9.45%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-15.69%25-red.svg?style=flat) |
10
10
 
@@ -5595,6 +5595,56 @@
5595
5595
  "type": "error",
5596
5596
  "name": "NoCounterpartiesInMatchOrder",
5597
5597
  "inputs": []
5598
+ },
5599
+ {
5600
+ "type": "function",
5601
+ "name": "grantAccountPermissionBySig",
5602
+ "inputs": [
5603
+ {
5604
+ "name": "accountId",
5605
+ "type": "uint128",
5606
+ "internalType": "uint128"
5607
+ },
5608
+ {
5609
+ "name": "permission",
5610
+ "type": "bytes32",
5611
+ "internalType": "bytes32"
5612
+ },
5613
+ {
5614
+ "name": "user",
5615
+ "type": "address",
5616
+ "internalType": "address"
5617
+ },
5618
+ {
5619
+ "name": "sig",
5620
+ "type": "tuple",
5621
+ "internalType": "struct EIP712Signature",
5622
+ "components": [
5623
+ {
5624
+ "name": "v",
5625
+ "type": "uint8",
5626
+ "internalType": "uint8"
5627
+ },
5628
+ {
5629
+ "name": "r",
5630
+ "type": "bytes32",
5631
+ "internalType": "bytes32"
5632
+ },
5633
+ {
5634
+ "name": "s",
5635
+ "type": "bytes32",
5636
+ "internalType": "bytes32"
5637
+ },
5638
+ {
5639
+ "name": "deadline",
5640
+ "type": "uint256",
5641
+ "internalType": "uint256"
5642
+ }
5643
+ ]
5644
+ }
5645
+ ],
5646
+ "outputs": [],
5647
+ "stateMutability": "nonpayable"
5598
5648
  }
5599
5649
  ]
5600
5650
  }
@@ -15,13 +15,13 @@ var addresses = (_a = {},
15
15
  _b[ContractType.CORE_PROXY] = '0x20da8f7aa44f858a3a3e3f03ba6ffad039d1eb28',
16
16
  _b[ContractType.PASSIVE_POOL_PROXY] = '0x9afc30bed29d636e566fd9d7dd89d51773724be6',
17
17
  _b[ContractType.PERIPHERY_PROXY] = '0xa45d0566144956b6012d461ad509dad2bacacaaf',
18
- _b[ContractType.CONDITIONAL_ORDERS_PROXY] = '',
18
+ _b[ContractType.CONDITIONAL_ORDERS_PROXY] = '0x0000000000000000000000000000000000000000',
19
19
  _b),
20
20
  _a[types_1.ReyaChainId.reyaNetwork] = (_c = {},
21
21
  _c[ContractType.CORE_PROXY] = '0xa763b6a5e09378434406c003dae6487fbbdc1a80',
22
22
  _c[ContractType.PASSIVE_POOL_PROXY] = '0xb4b77d6180cc14472a9a7bdff01cc2459368d413',
23
23
  _c[ContractType.PERIPHERY_PROXY] = '0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',
24
- _c[ContractType.CONDITIONAL_ORDERS_PROXY] = '',
24
+ _c[ContractType.CONDITIONAL_ORDERS_PROXY] = '0x0000000000000000000000000000000000000000',
25
25
  _c),
26
26
  _a);
27
27
  var getAddress = function (chainId, contractName) {
@@ -1 +1 @@
1
- {"version":3,"file":"contractAddresses.js","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":";;;;AAAA,kCAAgD;AAEhD,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,yDAAyC,CAAA;IACzC,mDAAmC,CAAA;IACnC,qEAAqD,CAAA;AACvD,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAED,IAAM,SAAS;IACb,GAAC,mBAAW,CAAC,UAAU;QACrB,GAAC,YAAY,CAAC,UAAU,IAAG,4CAA4C;QACvE,GAAC,YAAY,CAAC,kBAAkB,IAC9B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,eAAe,IAC3B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,wBAAwB,IAAG,EAAE;WAC5C;IACD,GAAC,mBAAW,CAAC,WAAW;QACtB,GAAC,YAAY,CAAC,UAAU,IAAG,4CAA4C;QACvE,GAAC,YAAY,CAAC,kBAAkB,IAC9B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,eAAe,IAC3B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,wBAAwB,IAAG,EAAE;WAC5C;OACF,CAAC;AACK,IAAM,UAAU,GAAG,UACxB,OAAe,EACf,YAA0B;IAE1B,IAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAEtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,6CAAsC,UAAU,CAAE,CAAC,CAAC;IACtE,CAAC;IAED,IAAM,gBAAgB,GAAG,SAAS,CAAC,OAAsB,CAAC,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,kCAA2B,YAAY,cAAW,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACxC,CAAC,CAAC;AAhBW,QAAA,UAAU,cAgBrB","sourcesContent":["import { Address, ReyaChainId } from '../types';\n\nexport enum ContractType {\n CORE_PROXY = 'core_proxy',\n PASSIVE_POOL_PROXY = 'passive_pool_proxy',\n PERIPHERY_PROXY = 'periphery_proxy',\n CONDITIONAL_ORDERS_PROXY = 'conditional_orders_proxy',\n}\n\nconst addresses: Record<ReyaChainId, Record<ContractType, Address>> = {\n [ReyaChainId.reyaCronos]: {\n [ContractType.CORE_PROXY]: '0x20da8f7aa44f858a3a3e3f03ba6ffad039d1eb28',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0x9afc30bed29d636e566fd9d7dd89d51773724be6',\n [ContractType.PERIPHERY_PROXY]:\n '0xa45d0566144956b6012d461ad509dad2bacacaaf',\n [ContractType.CONDITIONAL_ORDERS_PROXY]: '',\n },\n [ReyaChainId.reyaNetwork]: {\n [ContractType.CORE_PROXY]: '0xa763b6a5e09378434406c003dae6487fbbdc1a80',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0xb4b77d6180cc14472a9a7bdff01cc2459368d413',\n [ContractType.PERIPHERY_PROXY]:\n '0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',\n [ContractType.CONDITIONAL_ORDERS_PROXY]: '',\n },\n};\nexport const getAddress = (\n chainId: number,\n contractName: ContractType,\n): Address => {\n const keyChainId = chainId.toString();\n\n if (!Object.keys(addresses).includes(keyChainId)) {\n throw new Error(`Unspecified addresses for chain id ${keyChainId}`);\n }\n\n const networkAddresses = addresses[chainId as ReyaChainId];\n if (!Object.keys(networkAddresses).includes(contractName)) {\n throw new Error(`Unspecified address for ${contractName} contract`);\n }\n\n return networkAddresses[contractName];\n};\n"]}
1
+ {"version":3,"file":"contractAddresses.js","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":";;;;AAAA,kCAAgD;AAEhD,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,yDAAyC,CAAA;IACzC,mDAAmC,CAAA;IACnC,qEAAqD,CAAA;AACvD,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAED,IAAM,SAAS;IACb,GAAC,mBAAW,CAAC,UAAU;QACrB,GAAC,YAAY,CAAC,UAAU,IAAG,4CAA4C;QACvE,GAAC,YAAY,CAAC,kBAAkB,IAC9B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,eAAe,IAC3B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,wBAAwB,IACpC,4CAA4C;WAC/C;IACD,GAAC,mBAAW,CAAC,WAAW;QACtB,GAAC,YAAY,CAAC,UAAU,IAAG,4CAA4C;QACvE,GAAC,YAAY,CAAC,kBAAkB,IAC9B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,eAAe,IAC3B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,wBAAwB,IACpC,4CAA4C;WAC/C;OACF,CAAC;AACK,IAAM,UAAU,GAAG,UACxB,OAAe,EACf,YAA0B;IAE1B,IAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAEtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,6CAAsC,UAAU,CAAE,CAAC,CAAC;IACtE,CAAC;IAED,IAAM,gBAAgB,GAAG,SAAS,CAAC,OAAsB,CAAC,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,kCAA2B,YAAY,cAAW,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACxC,CAAC,CAAC;AAhBW,QAAA,UAAU,cAgBrB","sourcesContent":["import { Address, ReyaChainId } from '../types';\n\nexport enum ContractType {\n CORE_PROXY = 'core_proxy',\n PASSIVE_POOL_PROXY = 'passive_pool_proxy',\n PERIPHERY_PROXY = 'periphery_proxy',\n CONDITIONAL_ORDERS_PROXY = 'conditional_orders_proxy',\n}\n\nconst addresses: Record<ReyaChainId, Record<ContractType, Address>> = {\n [ReyaChainId.reyaCronos]: {\n [ContractType.CORE_PROXY]: '0x20da8f7aa44f858a3a3e3f03ba6ffad039d1eb28',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0x9afc30bed29d636e566fd9d7dd89d51773724be6',\n [ContractType.PERIPHERY_PROXY]:\n '0xa45d0566144956b6012d461ad509dad2bacacaaf',\n [ContractType.CONDITIONAL_ORDERS_PROXY]:\n '0x0000000000000000000000000000000000000000',\n },\n [ReyaChainId.reyaNetwork]: {\n [ContractType.CORE_PROXY]: '0xa763b6a5e09378434406c003dae6487fbbdc1a80',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0xb4b77d6180cc14472a9a7bdff01cc2459368d413',\n [ContractType.PERIPHERY_PROXY]:\n '0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',\n [ContractType.CONDITIONAL_ORDERS_PROXY]:\n '0x0000000000000000000000000000000000000000',\n },\n};\nexport const getAddress = (\n chainId: number,\n contractName: ContractType,\n): Address => {\n const keyChainId = chainId.toString();\n\n if (!Object.keys(addresses).includes(keyChainId)) {\n throw new Error(`Unspecified addresses for chain id ${keyChainId}`);\n }\n\n const networkAddresses = addresses[chainId as ReyaChainId];\n if (!Object.keys(networkAddresses).includes(contractName)) {\n throw new Error(`Unspecified address for ${contractName} contract`);\n }\n\n return networkAddresses[contractName];\n};\n"]}
@@ -14,14 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Socket_VaultWithPayloadAbi = exports.ConditionalOrdersAbi = exports.PeripheryAbi = exports.CoreAbi = void 0;
17
+ exports.Socket_VaultWithPayloadAbi = exports.PeripheryAbi = exports.CoreAbi = void 0;
18
18
  __exportStar(require("./action"), exports);
19
19
  var CoreProxy_json_1 = require("./abis/CoreProxy.json");
20
20
  Object.defineProperty(exports, "CoreAbi", { enumerable: true, get: function () { return CoreProxy_json_1.abi; } });
21
21
  var Periphery_json_1 = require("./abis/Periphery.json");
22
22
  Object.defineProperty(exports, "PeripheryAbi", { enumerable: true, get: function () { return Periphery_json_1.abi; } });
23
- var ConditionalOrdersGateway_json_1 = require("./abis/ConditionalOrdersGateway.json");
24
- Object.defineProperty(exports, "ConditionalOrdersAbi", { enumerable: true, get: function () { return ConditionalOrdersGateway_json_1.abi; } });
25
23
  var VaultWithPayload_json_1 = require("./abis/socket/VaultWithPayload.json");
26
24
  Object.defineProperty(exports, "Socket_VaultWithPayloadAbi", { enumerable: true, get: function () { return VaultWithPayload_json_1.abi; } });
27
25
  __exportStar(require("./contractAddresses"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["transactions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,wDAAuD;AAA9C,yGAAA,GAAG,OAAW;AACvB,wDAA4D;AAAnD,8GAAA,GAAG,OAAgB;AAC5B,sFAAmF;AAA1E,qIAAA,GAAG,OAAwB;AACpC,6EAAwF;AAA/E,mIAAA,GAAG,OAA8B;AAC1C,sDAAoC;AACpC,mDAAiC;AACjC,yCAAuB;AACvB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,uDAAqC;AACrC,gDAA8B","sourcesContent":["export * from './action';\nexport { abi as CoreAbi } from './abis/CoreProxy.json';\nexport { abi as PeripheryAbi } from './abis/Periphery.json';\nexport { abi as ConditionalOrdersAbi } from './abis/ConditionalOrdersGateway.json';\nexport { abi as Socket_VaultWithPayloadAbi } from './abis/socket/VaultWithPayload.json';\nexport * from './contractAddresses';\nexport * from './routerCommands';\nexport * from './sign';\nexport * from './trade';\nexport * from './txHelpers';\nexport * from './consts';\nexport * from './executeTransaction';\nexport * from './permissions';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["transactions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,wDAAuD;AAA9C,yGAAA,GAAG,OAAW;AACvB,wDAA4D;AAAnD,8GAAA,GAAG,OAAgB;AAC5B,6EAAwF;AAA/E,mIAAA,GAAG,OAA8B;AAC1C,sDAAoC;AACpC,mDAAiC;AACjC,yCAAuB;AACvB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,uDAAqC;AACrC,gDAA8B","sourcesContent":["export * from './action';\nexport { abi as CoreAbi } from './abis/CoreProxy.json';\nexport { abi as PeripheryAbi } from './abis/Periphery.json';\nexport { abi as Socket_VaultWithPayloadAbi } from './abis/socket/VaultWithPayload.json';\nexport * from './contractAddresses';\nexport * from './routerCommands';\nexport * from './sign';\nexport * from './trade';\nexport * from './txHelpers';\nexport * from './consts';\nexport * from './executeTransaction';\nexport * from './permissions';\n"]}
@@ -36,10 +36,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.signGrantPermission = exports.signConditionalOrder = exports.signPoolRemoveLiquidity = exports.signCoreCommands = void 0;
39
+ exports.signGrantPermission = exports.signCancelConditionalOrder = exports.isConditionalOrderSignatureValid = exports.signConditionalOrder = exports.signPoolRemoveLiquidity = exports.signCoreCommands = void 0;
40
40
  var ethers_1 = require("ethers");
41
41
  var contractAddresses_1 = require("./contractAddresses");
42
42
  var ethers_2 = require("ethers");
43
+ var types_1 = require("../types");
43
44
  function convertEthersSignatureToEIP712Signature(signature, deadline) {
44
45
  return {
45
46
  v: signature.v,
@@ -130,11 +131,7 @@ value) {
130
131
  return __generator(this, function (_a) {
131
132
  switch (_a.label) {
132
133
  case 0:
133
- domain = {
134
- name: 'Reya',
135
- version: '1',
136
- verifyingContract: verifyingContract,
137
- };
134
+ domain = getReyaDomain(verifyingContract);
138
135
  return [4 /*yield*/, signer.signTypedData(domain, types, value)];
139
136
  case 1:
140
137
  signatureString = _a.sent();
@@ -143,29 +140,46 @@ value) {
143
140
  });
144
141
  });
145
142
  }
143
+ function getReyaDomain(verifyingContract) {
144
+ return {
145
+ name: 'Reya',
146
+ version: '1',
147
+ verifyingContract: verifyingContract,
148
+ };
149
+ }
150
+ var conditionalOrderTypes = {
151
+ ConditionalOrder: [
152
+ { name: 'verifyingChainId', type: 'uint256' },
153
+ { name: 'deadline', type: 'uint256' },
154
+ { name: 'order', type: 'ConditionalOrderDetails' },
155
+ ],
156
+ ConditionalOrderDetails: [
157
+ { name: 'accountId', type: 'uint128' },
158
+ { name: 'marketId', type: 'uint128' },
159
+ { name: 'exchangeId', type: 'uint128' },
160
+ { name: 'counterpartyAccountIds', type: 'uint128[]' },
161
+ { name: 'orderType', type: 'uint8' },
162
+ { name: 'inputs', type: 'bytes' },
163
+ { name: 'signer', type: 'address' },
164
+ { name: 'nonce', type: 'uint256' },
165
+ ],
166
+ };
146
167
  function signConditionalOrder(signer, reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, nonce, deadline) {
147
168
  return __awaiter(this, void 0, void 0, function () {
148
169
  var signature, _a, _b;
149
- var _c;
150
- return __generator(this, function (_d) {
151
- switch (_d.label) {
170
+ var _c, _d;
171
+ return __generator(this, function (_e) {
172
+ switch (_e.label) {
152
173
  case 0:
153
174
  _a = signReyaTypedData;
154
175
  _b = [signer,
155
176
  (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.CONDITIONAL_ORDERS_PROXY),
156
- {
157
- ConditionalOrderDetails: [
158
- { name: 'accountId', type: 'uint128' },
159
- { name: 'marketId', type: 'uint128' },
160
- { name: 'exchangeId', type: 'uint128' },
161
- { name: 'counterpartyAccountIds', type: 'uint128[]' },
162
- { name: 'orderType', type: 'uint8' },
163
- { name: 'inputs', type: 'bytes' },
164
- { name: 'signer', type: 'address' },
165
- { name: 'nonce', type: 'uint256' },
166
- ],
167
- }];
177
+ conditionalOrderTypes];
168
178
  _c = {
179
+ verifyingChainId: reyaChainId,
180
+ deadline: BigInt(deadline)
181
+ };
182
+ _d = {
169
183
  accountId: accountId,
170
184
  marketId: marketId,
171
185
  exchangeId: exchangeId,
@@ -174,51 +188,82 @@ function signConditionalOrder(signer, reyaChainId, accountId, marketId, exchange
174
188
  inputs: inputs
175
189
  };
176
190
  return [4 /*yield*/, signer.getAddress()];
177
- case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([(_c.signer = _d.sent(),
178
- _c.nonce = nonce,
191
+ case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([(_c.order = (_d.signer = _e.sent(),
192
+ _d.nonce = nonce,
193
+ _d),
179
194
  _c)]))];
180
195
  case 2:
181
- signature = _d.sent();
182
- return [2 /*return*/, convertEthersSignatureToEIP712Signature(signature, deadline)];
196
+ signature = _e.sent();
197
+ return [2 /*return*/, signature.serialized];
183
198
  }
184
199
  });
185
200
  });
186
201
  }
187
202
  exports.signConditionalOrder = signConditionalOrder;
188
- function signGrantPermission(signer, reyaChainId, accountId, permission, user, nonce, deadline) {
203
+ function isConditionalOrderSignatureValid(signerAddress, signature, reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, nonce, deadline) {
204
+ // Encode the data for recovering the address
205
+ var domain = getReyaDomain((0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.CONDITIONAL_ORDERS_PROXY));
206
+ var value = {
207
+ verifyingChainId: reyaChainId,
208
+ deadline: BigInt(deadline),
209
+ order: {
210
+ accountId: accountId,
211
+ marketId: marketId,
212
+ exchangeId: exchangeId,
213
+ counterpartyAccountIds: counterpartyAccountIds,
214
+ orderType: orderType,
215
+ inputs: inputs,
216
+ signer: signerAddress,
217
+ nonce: nonce,
218
+ },
219
+ };
220
+ // Recover the address
221
+ var recoveredAddress = (0, ethers_1.verifyTypedData)(domain, conditionalOrderTypes, value, signature);
222
+ return recoveredAddress === signerAddress;
223
+ }
224
+ exports.isConditionalOrderSignatureValid = isConditionalOrderSignatureValid;
225
+ function signCancelConditionalOrder(signer, orderId) {
189
226
  return __awaiter(this, void 0, void 0, function () {
190
- var signature, _a, _b;
191
- var _c;
192
- return __generator(this, function (_d) {
193
- switch (_d.label) {
227
+ var message;
228
+ return __generator(this, function (_a) {
229
+ switch (_a.label) {
194
230
  case 0:
195
- _a = signReyaTypedData;
196
- _b = [signer,
197
- (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.CORE_PROXY),
198
- {
199
- GrantAccountPermissionBySig: [
200
- { name: 'verifyingChainId', type: 'uint256' },
201
- { name: 'caller', type: 'address' },
202
- { name: 'accountId', type: 'uint128' },
203
- { name: 'permission', type: 'bytes32' },
204
- { name: 'user', type: 'address' },
205
- { name: 'nonce', type: 'uint256' },
206
- { name: 'deadline', type: 'uint256' },
207
- ],
208
- }];
209
- _c = {
210
- verifyingChainId: reyaChainId
231
+ message = {
232
+ orderId: orderId,
233
+ status: types_1.StopLossOrderStatus.CANCELLED,
234
+ actionType: 'changeStatus',
211
235
  };
212
- return [4 /*yield*/, signer.getAddress()];
213
- case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([(_c.caller = _d.sent(),
214
- _c.accountId = accountId,
215
- _c.permission = permission,
216
- _c.user = user,
217
- _c.nonce = nonce,
218
- _c.deadline = deadline,
219
- _c)]))];
220
- case 2:
221
- signature = _d.sent();
236
+ return [4 /*yield*/, signer.signMessage(JSON.stringify(message))];
237
+ case 1: return [2 /*return*/, _a.sent()];
238
+ }
239
+ });
240
+ });
241
+ }
242
+ exports.signCancelConditionalOrder = signCancelConditionalOrder;
243
+ function signGrantPermission(signer, reyaChainId, accountId, permission, user, nonce, deadline) {
244
+ return __awaiter(this, void 0, void 0, function () {
245
+ var signature;
246
+ return __generator(this, function (_a) {
247
+ switch (_a.label) {
248
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.CORE_PROXY), {
249
+ GrantAccountPermissionBySig: [
250
+ { name: 'verifyingChainId', type: 'uint256' },
251
+ { name: 'accountId', type: 'uint128' },
252
+ { name: 'permission', type: 'bytes32' },
253
+ { name: 'user', type: 'address' },
254
+ { name: 'nonce', type: 'uint256' },
255
+ { name: 'deadline', type: 'uint256' },
256
+ ],
257
+ }, {
258
+ verifyingChainId: reyaChainId,
259
+ accountId: accountId,
260
+ permission: permission,
261
+ user: user,
262
+ nonce: nonce,
263
+ deadline: deadline,
264
+ })];
265
+ case 1:
266
+ signature = _a.sent();
222
267
  return [2 /*return*/, convertEthersSignatureToEIP712Signature(signature, deadline)];
223
268
  }
224
269
  });
@@ -1 +1 @@
1
- {"version":3,"file":"sign.js","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA0E;AAC1E,yDAA+D;AAE/D,iCAAgC;AAUhC,SAAS,uCAAuC,CAC9C,SAAoB,EACpB,QAAgB;IAEhB,OAAO;QACL,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,QAAQ,EAAE,QAAQ;KACnB,CAAC;AACJ,CAAC;AAED,SAAsB,gBAAgB,CACpC,MAA8B,EAC9B,WAAwB,EACxB,MAAe,EACf,SAAiB,EACjB,QAAmB,EACnB,KAAa,EACb,QAAgB,EAChB,kBAA0B;;;;;wBAER,qBAAM,iBAAiB,CACvC,MAAM,EACN,IAAA,8BAAU,EAAC,WAAW,EAAE,gCAAY,CAAC,UAAU,CAAC,EAChD;wBACE,YAAY,EAAE;4BACZ,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;4BAC7C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;4BACnC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;4BACtC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE;4BACvC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAA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EAAC;;;;CACrE;AAzCD,oDAyCC;AAED,SAAsB,mBAAmB,CACvC,MAA8B,EAC9B,WAAwB,EACxB,SAAiB,EACjB,UAAkB,EAClB,IAAY,EACZ,KAAa,EACb,QAAgB;;;;;;;oBAEQ,KAAA,iBAAiB,CAAA;0BACvC,MAAM;wBACN,IAAA,8BAAU,EAAC,WAAW,EAAE,gCAAY,CAAC,UAAU,CAAC;wBAChD;4BACE,2BAA2B,EAAE;gCAC3B,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;gCAC7C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;gCACnC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;gCACtC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;gCACvC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;gCACjC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;gCAClC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;6BACtC;yBACF;;wBAEC,gBAAgB,EAAE,WAAW;;oBACrB,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;wBAhBnB,qBAAM,6BAgBpB,SAAM,GAAE,SAAyB;4BACjC,YAAS,GAAE,SAAS;4BACpB,aAAU,GAAE,UAAU;4BACtB,OAAI,GAAE,IAAI;4BACV,QAAK,GAAE,KAAK;4BACZ,WAAQ,GAAE,QAAQ;kCAErB,EAAA;;oBAvBK,SAAS,GAAG,SAuBjB;oBAED,sBAAO,uCAAuC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAC;;;;CACrE;AAnCD,kDAmCC","sourcesContent":["import { JsonRpcSigner, Signature, Signer, TypedDataField } from 'ethers';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { Command } from './action';\nimport { ethers } from 'ethers';\nimport { Address, ReyaChainId } from '../types';\n\nexport type EIP712Signature = {\n v: number;\n r: string;\n s: string;\n deadline: number;\n};\n\nfunction convertEthersSignatureToEIP712Signature(\n signature: Signature,\n deadline: number,\n): EIP712Signature {\n return {\n v: signature.v,\n r: signature.r,\n s: signature.s,\n deadline: deadline,\n };\n}\n\nexport async function signCoreCommands(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n accountId: number,\n commands: Command[],\n nonce: number,\n deadline: number,\n extraSignatureData: string,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n ExecuteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'accountId', type: 'uint128' },\n { name: 'commands', type: 'Command[]' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n Command: [\n { name: 'commandType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n caller: caller,\n accountId: accountId,\n commands: commands,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signPoolRemoveLiquidity(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n owner: Address,\n poolId: number,\n sharesAmount: bigint,\n minOut: bigint,\n nonce: number,\n deadline: number,\n socketMsgGasLimit: bigint,\n chainId: number,\n receiver: string,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.PASSIVE_POOL_PROXY),\n {\n RemoveLiquidityBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'owner', type: 'address' },\n { name: 'poolId', type: 'uint128' },\n { name: 'sharesAmount', type: 'uint256' },\n { name: 'minOut', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n caller: caller,\n owner: owner,\n poolId: poolId,\n sharesAmount: sharesAmount,\n minOut: minOut,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: ethers.AbiCoder.defaultAbiCoder().encode(\n ['address', 'uint256', 'uint256'],\n [receiver, chainId, socketMsgGasLimit],\n ),\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nasync function signReyaTypedData(\n signer: Signer | JsonRpcSigner,\n verifyingContract: string,\n types: Record<string, Array<TypedDataField>>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: Record<string, any>,\n): Promise<Signature> {\n const domain = {\n name: 'Reya',\n version: '1',\n verifyingContract: verifyingContract,\n };\n\n const signatureString = await signer.signTypedData(domain, types, value);\n\n return Signature.from(signatureString);\n}\n\nexport async function signConditionalOrder(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: number,\n inputs: string,\n nonce: number,\n deadline: number,\n): Promise<EIP712Signature> {\n // todo: add deadline to encoded sig\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CONDITIONAL_ORDERS_PROXY),\n {\n ConditionalOrderDetails: [\n { name: 'accountId', type: 'uint128' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n { name: 'counterpartyAccountIds', type: 'uint128[]' },\n { name: 'orderType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'signer', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n },\n {\n accountId: accountId,\n marketId: marketId,\n exchangeId: exchangeId,\n counterpartyAccountIds: counterpartyAccountIds,\n orderType: orderType,\n inputs: inputs,\n signer: await signer.getAddress(),\n nonce: nonce,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signGrantPermission(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n permission: string,\n user: string,\n nonce: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n GrantAccountPermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'accountId', type: 'uint128' },\n { name: 'permission', type: 'bytes32' },\n { name: 'user', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n caller: await signer.getAddress(),\n accountId: accountId,\n permission: permission,\n user: user,\n nonce: nonce,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n"]}
1
+ {"version":3,"file":"sign.js","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAMgB;AAChB,yDAA+D;AAE/D,iCAAgC;AAChC,kCAAqE;AASrE,SAAS,uCAAuC,CAC9C,SAAoB,EACpB,QAAgB;IAEhB,OAAO;QACL,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,QAAQ,EAAE,QAAQ;KACnB,CAAC;AACJ,CAAC;AAED,SAAsB,gBAAgB,CACpC,MAA8B,EAC9B,WAAwB,EACxB,MAAe,EACf,SAAiB,EACjB,QAAmB,EACnB,KAAa,EACb,QAAgB,EAChB,kBAA0B;;;;;wBAER,qBAAM,iBAAiB,CACvC,MAAM,EACN,IAAA,8BAAU,EAAC,WAAW,EAAE,gCAAY,CAAC,UAAU,CAAC,EACh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I,EAAE,SAAS,EAAE;yBACtC;qBACF,EACD;wBACE,gBAAgB,EAAE,WAAW;wBAC7B,SAAS,EAAE,SAAS;wBACpB,UAAU,EAAE,UAAU;wBACtB,IAAI,EAAE,IAAI;wBACV,KAAK,EAAE,KAAK;wBACZ,QAAQ,EAAE,QAAQ;qBACnB,CACF,EAAA;;oBArBK,SAAS,GAAG,SAqBjB;oBAED,sBAAO,uCAAuC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAC;;;;CACrE;AAjCD,kDAiCC","sourcesContent":["import {\n JsonRpcSigner,\n Signature,\n Signer,\n TypedDataField,\n verifyTypedData,\n} from 'ethers';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { Command } from './action';\nimport { ethers } from 'ethers';\nimport { Address, ReyaChainId, StopLossOrderStatus } from '../types';\n\nexport type EIP712Signature = {\n v: number;\n r: string;\n s: string;\n deadline: number;\n};\n\nfunction convertEthersSignatureToEIP712Signature(\n signature: Signature,\n deadline: number,\n): EIP712Signature {\n return {\n v: signature.v,\n r: signature.r,\n s: signature.s,\n deadline: deadline,\n };\n}\n\nexport async function signCoreCommands(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n accountId: number,\n commands: Command[],\n nonce: number,\n deadline: number,\n extraSignatureData: string,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n ExecuteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'accountId', type: 'uint128' },\n { name: 'commands', type: 'Command[]' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n Command: [\n { name: 'commandType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n caller: caller,\n accountId: accountId,\n commands: commands,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signPoolRemoveLiquidity(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n owner: Address,\n poolId: number,\n sharesAmount: bigint,\n minOut: bigint,\n nonce: number,\n deadline: number,\n socketMsgGasLimit: bigint,\n chainId: number,\n receiver: string,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.PASSIVE_POOL_PROXY),\n {\n RemoveLiquidityBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'owner', type: 'address' },\n { name: 'poolId', type: 'uint128' },\n { name: 'sharesAmount', type: 'uint256' },\n { name: 'minOut', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n caller: caller,\n owner: owner,\n poolId: poolId,\n sharesAmount: sharesAmount,\n minOut: minOut,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: ethers.AbiCoder.defaultAbiCoder().encode(\n ['address', 'uint256', 'uint256'],\n [receiver, chainId, socketMsgGasLimit],\n ),\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nasync function signReyaTypedData(\n signer: Signer | JsonRpcSigner,\n verifyingContract: string,\n types: Record<string, Array<TypedDataField>>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: Record<string, any>,\n): Promise<Signature> {\n const domain = getReyaDomain(verifyingContract);\n\n const signatureString = await signer.signTypedData(domain, types, value);\n\n return Signature.from(signatureString);\n}\n\nfunction getReyaDomain(verifyingContract: string) {\n return {\n name: 'Reya',\n version: '1',\n verifyingContract: verifyingContract,\n };\n}\n\nconst conditionalOrderTypes = {\n ConditionalOrder: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'order', type: 'ConditionalOrderDetails' },\n ],\n ConditionalOrderDetails: [\n { name: 'accountId', type: 'uint128' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n { name: 'counterpartyAccountIds', type: 'uint128[]' },\n { name: 'orderType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'signer', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n};\n\nexport async function signConditionalOrder(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: number,\n inputs: string,\n nonce: bigint,\n deadline: number,\n): Promise<string> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CONDITIONAL_ORDERS_PROXY),\n conditionalOrderTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n order: {\n accountId: accountId,\n marketId: marketId,\n exchangeId: exchangeId,\n counterpartyAccountIds: counterpartyAccountIds,\n orderType: orderType,\n inputs: inputs,\n signer: await signer.getAddress(),\n nonce: nonce,\n },\n },\n );\n\n return signature.serialized;\n}\n\nexport function isConditionalOrderSignatureValid(\n signerAddress: string,\n signature: string,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: number,\n inputs: string,\n nonce: bigint,\n deadline: number,\n): boolean {\n // Encode the data for recovering the address\n const domain = getReyaDomain(\n getAddress(reyaChainId, ContractType.CONDITIONAL_ORDERS_PROXY),\n );\n const value = {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n order: {\n accountId: accountId,\n marketId: marketId,\n exchangeId: exchangeId,\n counterpartyAccountIds: counterpartyAccountIds,\n orderType: orderType,\n inputs: inputs,\n signer: signerAddress,\n nonce: nonce,\n },\n };\n\n // Recover the address\n const recoveredAddress = verifyTypedData(\n domain,\n conditionalOrderTypes,\n value,\n signature,\n );\n\n return recoveredAddress === signerAddress;\n}\n\nexport async function signCancelConditionalOrder(\n signer: Signer | JsonRpcSigner,\n orderId: string,\n): Promise<string> {\n const message = {\n orderId: orderId,\n status: StopLossOrderStatus.CANCELLED,\n actionType: 'changeStatus',\n };\n return await signer.signMessage(JSON.stringify(message));\n}\n\nexport async function signGrantPermission(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n permission: string,\n user: string,\n nonce: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n GrantAccountPermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'accountId', type: 'uint128' },\n { name: 'permission', type: 'bytes32' },\n { name: 'user', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n accountId: accountId,\n permission: permission,\n user: user,\n nonce: nonce,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n"]}
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.calculatePriceLimitForTrade = void 0;
6
+ exports.calculateMaxPriceLimit = exports.calculatePriceLimitForTrade = void 0;
7
7
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ var ethers_1 = require("ethers");
8
9
  // todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance
9
10
  function calculatePriceLimitForTrade(orderPrice, amount) {
10
11
  // Ensure orderPrice is BigInt
@@ -21,4 +22,14 @@ function calculatePriceLimitForTrade(orderPrice, amount) {
21
22
  }
22
23
  }
23
24
  exports.calculatePriceLimitForTrade = calculatePriceLimitForTrade;
25
+ function calculateMaxPriceLimit(isLong) {
26
+ // Determine if the amount is positive or negative and adjust the price accordingly
27
+ if (isLong) {
28
+ return ethers_1.MaxUint256;
29
+ }
30
+ else {
31
+ return BigInt(0);
32
+ }
33
+ }
34
+ exports.calculateMaxPriceLimit = calculateMaxPriceLimit;
24
35
  //# sourceMappingURL=trade.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"trade.js","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAErC,iHAAiH;AACjH,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,MAAc;IAEd,8BAA8B;IAC9B,IAAM,gBAAgB,GAAG,IAAA,sBAAS,EAAC,UAAU,CAAC,CAAC;IAE/C,kCAAkC;IAClC,IAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEzC,mFAAmF;IACnF,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,wBAAwB;QACxB,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAChE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AArBD,kEAqBC","sourcesContent":["import BigNumber from 'bignumber.js';\n\n// todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance\nexport function calculatePriceLimitForTrade(\n orderPrice: number,\n amount: number,\n): bigint {\n // Ensure orderPrice is BigInt\n const orderPriceBigInt = BigNumber(orderPrice);\n\n // Calculate 1% of the order price\n const offset = orderPriceBigInt.div(100);\n\n // Determine if the amount is positive or negative and adjust the price accordingly\n if (amount > 0) {\n // Trade is long, so add\n return BigInt(\n BigNumber(orderPriceBigInt).plus(offset).times(1e18).toFixed(0),\n );\n } else {\n return BigInt(\n BigNumber(orderPriceBigInt).minus(offset).times(1e18).toFixed(0),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"trade.js","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AACrC,iCAAoC;AAEpC,iHAAiH;AACjH,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,MAAc;IAEd,8BAA8B;IAC9B,IAAM,gBAAgB,GAAG,IAAA,sBAAS,EAAC,UAAU,CAAC,CAAC;IAE/C,kCAAkC;IAClC,IAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEzC,mFAAmF;IACnF,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,wBAAwB;QACxB,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAChE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AArBD,kEAqBC;AAED,SAAgB,sBAAsB,CAAC,MAAe;IACpD,mFAAmF;IACnF,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,mBAAU,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;AACH,CAAC;AAPD,wDAOC","sourcesContent":["import BigNumber from 'bignumber.js';\nimport { MaxUint256 } from 'ethers';\n\n// todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance\nexport function calculatePriceLimitForTrade(\n orderPrice: number,\n amount: number,\n): bigint {\n // Ensure orderPrice is BigInt\n const orderPriceBigInt = BigNumber(orderPrice);\n\n // Calculate 1% of the order price\n const offset = orderPriceBigInt.div(100);\n\n // Determine if the amount is positive or negative and adjust the price accordingly\n if (amount > 0) {\n // Trade is long, so add\n return BigInt(\n BigNumber(orderPriceBigInt).plus(offset).times(1e18).toFixed(0),\n );\n } else {\n return BigInt(\n BigNumber(orderPriceBigInt).minus(offset).times(1e18).toFixed(0),\n );\n }\n}\n\nexport function calculateMaxPriceLimit(isLong: boolean): bigint {\n // Determine if the amount is positive or negative and adjust the price accordingly\n if (isLong) {\n return MaxUint256;\n } else {\n return BigInt(0);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"contractAddresses.d.ts","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,UAAU,CAAC;AAEhD,oBAAY,YAAY;IACtB,UAAU,eAAe;IACzB,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;IACnC,wBAAwB,6BAA6B;CACtD;AAoBD,eAAO,MAAM,UAAU,YACZ,MAAM,gBACD,YAAY,KACzB,OAaF,CAAC"}
1
+ {"version":3,"file":"contractAddresses.d.ts","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,UAAU,CAAC;AAEhD,oBAAY,YAAY;IACtB,UAAU,eAAe;IACzB,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;IACnC,wBAAwB,6BAA6B;CACtD;AAsBD,eAAO,MAAM,UAAU,YACZ,MAAM,gBACD,YAAY,KACzB,OAaF,CAAC"}
@@ -1,7 +1,6 @@
1
1
  export * from './action';
2
2
  export { abi as CoreAbi } from './abis/CoreProxy.json';
3
3
  export { abi as PeripheryAbi } from './abis/Periphery.json';
4
- export { abi as ConditionalOrdersAbi } from './abis/ConditionalOrdersGateway.json';
5
4
  export { abi as Socket_VaultWithPayloadAbi } from './abis/socket/VaultWithPayload.json';
6
5
  export * from './contractAddresses';
7
6
  export * from './routerCommands';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["transactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,GAAG,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,GAAG,IAAI,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,GAAG,IAAI,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACxF,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["transactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,GAAG,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,GAAG,IAAI,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACxF,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC"}
@@ -9,6 +9,8 @@ export type EIP712Signature = {
9
9
  };
10
10
  export declare function signCoreCommands(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, caller: Address, accountId: number, commands: Command[], nonce: number, deadline: number, extraSignatureData: string): Promise<EIP712Signature>;
11
11
  export declare function signPoolRemoveLiquidity(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, caller: Address, owner: Address, poolId: number, sharesAmount: bigint, minOut: bigint, nonce: number, deadline: number, socketMsgGasLimit: bigint, chainId: number, receiver: string): Promise<EIP712Signature>;
12
- export declare function signConditionalOrder(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, accountId: number, marketId: number, exchangeId: number, counterpartyAccountIds: number[], orderType: number, inputs: string, nonce: number, deadline: number): Promise<EIP712Signature>;
12
+ export declare function signConditionalOrder(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, accountId: number, marketId: number, exchangeId: number, counterpartyAccountIds: number[], orderType: number, inputs: string, nonce: bigint, deadline: number): Promise<string>;
13
+ export declare function isConditionalOrderSignatureValid(signerAddress: string, signature: string, reyaChainId: ReyaChainId, accountId: number, marketId: number, exchangeId: number, counterpartyAccountIds: number[], orderType: number, inputs: string, nonce: bigint, deadline: number): boolean;
14
+ export declare function signCancelConditionalOrder(signer: Signer | JsonRpcSigner, orderId: string): Promise<string>;
13
15
  export declare function signGrantPermission(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, accountId: number, permission: string, user: string, nonce: number, deadline: number): Promise<EIP712Signature>;
14
16
  //# sourceMappingURL=sign.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sign.d.ts","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAa,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CA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AM,EAChB,UAAU,EAAE,MAAM,EAClB,sBAAsB,EAAE,MAAM,EAAE,EAChC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAsBjB;AAED,wBAAgB,gCAAgC,CAC9C,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,sBAAsB,EAAE,MAAM,EAAE,EAChC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CA6BT;AAED,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,CAAC,CAyB1B"}
@@ -1,2 +1,3 @@
1
1
  export declare function calculatePriceLimitForTrade(orderPrice: number, amount: number): bigint;
2
+ export declare function calculateMaxPriceLimit(isLong: boolean): bigint;
2
3
  //# sourceMappingURL=trade.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trade.d.ts","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":"AAGA,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAkBR"}
1
+ {"version":3,"file":"trade.d.ts","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":"AAIA,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAkBR;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAO9D"}
@@ -94,13 +94,19 @@ export type MarginAccountEntity = {
94
94
  collaterals: CollateralEntity[];
95
95
  positions: PositionEntity[];
96
96
  };
97
+ export type ConditionalOrdersInfo = {
98
+ stopLoss?: {
99
+ stopLossPrice: number;
100
+ orderId: string;
101
+ };
102
+ };
97
103
  export type PositionEntity = {
98
104
  id: number;
99
105
  side: Side;
100
106
  size: number;
101
107
  base: number;
102
108
  price: number;
103
- stopLossPrice?: number;
109
+ conditionalOrdersInfo?: ConditionalOrdersInfo;
104
110
  markPrice: number;
105
111
  orderStatus: Status;
106
112
  realisedPnl: number;
@@ -711,23 +717,27 @@ type ReadyWithdrawalStatus = {
711
717
  export type PendingWithdrawal = {
712
718
  tokenAmount: number;
713
719
  } & (PendingWithdrawalStatus | ReadyWithdrawalStatus);
720
+ export declare enum ConditionalOrderType {
721
+ STOP_LOSS = 0
722
+ }
714
723
  export declare enum StopLossOrderStatus {
715
- NEW = "new",
724
+ PENDING = "pending",
716
725
  FILLED = "filled",
717
726
  CANCELLED = "cancelled",
718
727
  REJECTED = "rejected"
719
728
  }
720
729
  export type StopLossOrder = {
721
- orderId: number;
730
+ orderId: string;
722
731
  accountId: number;
723
732
  marketId: number;
724
733
  isLong: boolean;
725
734
  stopPrice: number;
726
735
  signerWallet: string;
727
- nonce: number;
736
+ nonce: string;
728
737
  signature: string;
729
738
  status: StopLossOrderStatus;
730
- timestampMs: number;
739
+ creationTimestampMs: number;
740
+ lastUpdateTimestampMs: number;
731
741
  };
732
742
  export {};
733
743
  //# sourceMappingURL=types.d.ts.map