@reyaxyz/common 0.274.4 → 0.276.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/transactions/abis/OrdersGateway.json +46 -61
- package/dist/transactions/consts.js +2 -1
- package/dist/transactions/consts.js.map +1 -1
- package/dist/transactions/contractAddresses.js +3 -0
- package/dist/transactions/contractAddresses.js.map +1 -1
- package/dist/transactions/sign.js +25 -6
- package/dist/transactions/sign.js.map +1 -1
- package/dist/types/transactions/consts.d.ts +1 -0
- package/dist/types/transactions/consts.d.ts.map +1 -1
- package/dist/types/transactions/contractAddresses.d.ts +1 -0
- package/dist/types/transactions/contractAddresses.d.ts.map +1 -1
- package/dist/types/transactions/sign.d.ts +9 -2
- package/dist/types/transactions/sign.d.ts.map +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/calculate.d.ts +0 -2
- package/dist/types/utils/calculate.d.ts.map +1 -1
- package/dist/types/utils/struct.d.ts +1 -1
- package/dist/types/utils/struct.d.ts.map +1 -1
- package/dist/types.js +9 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/calculate.js.map +1 -1
- package/dist/utils/struct.js +1 -7
- package/dist/utils/struct.js.map +1 -1
- package/package.json +2 -2
- package/src/transactions/abis/OrdersGateway.json +434 -449
- package/src/transactions/consts.ts +1 -0
- package/src/transactions/contractAddresses.ts +5 -0
- package/src/transactions/sign.ts +50 -7
- package/src/types.ts +8 -0
- package/src/utils/calculate.ts +0 -2
- package/src/utils/struct.ts +5 -5
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -5,24 +5,14 @@
|
|
|
5
5
|
"name": "execute",
|
|
6
6
|
"inputs": [
|
|
7
7
|
{
|
|
8
|
-
"name": "
|
|
9
|
-
"type": "
|
|
10
|
-
"internalType": "
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"name": "commands",
|
|
14
|
-
"type": "tuple[]",
|
|
15
|
-
"internalType": "struct Command[]",
|
|
8
|
+
"name": "order",
|
|
9
|
+
"type": "tuple",
|
|
10
|
+
"internalType": "struct ConditionalOrderDetails",
|
|
16
11
|
"components": [
|
|
17
12
|
{
|
|
18
|
-
"name": "
|
|
19
|
-
"type": "
|
|
20
|
-
"internalType": "
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"name": "inputs",
|
|
24
|
-
"type": "bytes",
|
|
25
|
-
"internalType": "bytes"
|
|
13
|
+
"name": "accountId",
|
|
14
|
+
"type": "uint128",
|
|
15
|
+
"internalType": "uint128"
|
|
26
16
|
},
|
|
27
17
|
{
|
|
28
18
|
"name": "marketId",
|
|
@@ -33,74 +23,69 @@
|
|
|
33
23
|
"name": "exchangeId",
|
|
34
24
|
"type": "uint128",
|
|
35
25
|
"internalType": "uint128"
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
"outputs": [
|
|
41
|
-
{
|
|
42
|
-
"name": "outputs",
|
|
43
|
-
"type": "bytes[]",
|
|
44
|
-
"internalType": "bytes[]"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"name": "usdNodeMarginInfo",
|
|
48
|
-
"type": "tuple",
|
|
49
|
-
"internalType": "struct MarginInfo",
|
|
50
|
-
"components": [
|
|
51
|
-
{
|
|
52
|
-
"name": "collateral",
|
|
53
|
-
"type": "address",
|
|
54
|
-
"internalType": "address"
|
|
55
26
|
},
|
|
56
27
|
{
|
|
57
|
-
"name": "
|
|
58
|
-
"type": "
|
|
59
|
-
"internalType": "
|
|
28
|
+
"name": "counterpartyAccountIds",
|
|
29
|
+
"type": "uint128[]",
|
|
30
|
+
"internalType": "uint128[]"
|
|
60
31
|
},
|
|
61
32
|
{
|
|
62
|
-
"name": "
|
|
63
|
-
"type": "
|
|
64
|
-
"internalType": "
|
|
33
|
+
"name": "orderType",
|
|
34
|
+
"type": "uint8",
|
|
35
|
+
"internalType": "enum OrderType"
|
|
65
36
|
},
|
|
66
37
|
{
|
|
67
|
-
"name": "
|
|
68
|
-
"type": "
|
|
69
|
-
"internalType": "
|
|
38
|
+
"name": "inputs",
|
|
39
|
+
"type": "bytes",
|
|
40
|
+
"internalType": "bytes"
|
|
70
41
|
},
|
|
71
42
|
{
|
|
72
|
-
"name": "
|
|
73
|
-
"type": "
|
|
74
|
-
"internalType": "
|
|
43
|
+
"name": "signer",
|
|
44
|
+
"type": "address",
|
|
45
|
+
"internalType": "address"
|
|
75
46
|
},
|
|
76
47
|
{
|
|
77
|
-
"name": "
|
|
78
|
-
"type": "
|
|
79
|
-
"internalType": "
|
|
80
|
-
}
|
|
48
|
+
"name": "nonce",
|
|
49
|
+
"type": "uint256",
|
|
50
|
+
"internalType": "uint256"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "signature",
|
|
56
|
+
"type": "tuple",
|
|
57
|
+
"internalType": "struct EIP712Signature",
|
|
58
|
+
"components": [
|
|
81
59
|
{
|
|
82
|
-
"name": "
|
|
83
|
-
"type": "
|
|
84
|
-
"internalType": "
|
|
60
|
+
"name": "v",
|
|
61
|
+
"type": "uint8",
|
|
62
|
+
"internalType": "uint8"
|
|
85
63
|
},
|
|
86
64
|
{
|
|
87
|
-
"name": "
|
|
88
|
-
"type": "
|
|
89
|
-
"internalType": "
|
|
65
|
+
"name": "r",
|
|
66
|
+
"type": "bytes32",
|
|
67
|
+
"internalType": "bytes32"
|
|
90
68
|
},
|
|
91
69
|
{
|
|
92
|
-
"name": "
|
|
93
|
-
"type": "
|
|
94
|
-
"internalType": "
|
|
70
|
+
"name": "s",
|
|
71
|
+
"type": "bytes32",
|
|
72
|
+
"internalType": "bytes32"
|
|
95
73
|
},
|
|
96
74
|
{
|
|
97
|
-
"name": "
|
|
75
|
+
"name": "deadline",
|
|
98
76
|
"type": "uint256",
|
|
99
77
|
"internalType": "uint256"
|
|
100
78
|
}
|
|
101
79
|
]
|
|
102
80
|
}
|
|
103
81
|
],
|
|
82
|
+
"outputs": [
|
|
83
|
+
{
|
|
84
|
+
"name": "output",
|
|
85
|
+
"type": "bytes",
|
|
86
|
+
"internalType": "bytes"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
104
89
|
"stateMutability": "nonpayable"
|
|
105
90
|
},
|
|
106
91
|
{
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONDITIONAL_ORDER_SIG_DEADLINE = exports.PUBLISHER_ACCOUNT = exports.RELAYER_ACCOUNT = exports.CORE_DEADLINE_IN_SECONDS = exports.BRIDGE_DEADLINE_IN_SECONDS = void 0;
|
|
3
|
+
exports.CONDITIONAL_ORDER_SIG_DEADLINE = exports.PUBLISHER_ACCOUNT = exports.RELAYER_ACCOUNT = exports.ORDERS_GATEWAY_DEADLINE_IN_SECONDS = exports.CORE_DEADLINE_IN_SECONDS = exports.BRIDGE_DEADLINE_IN_SECONDS = void 0;
|
|
4
4
|
exports.BRIDGE_DEADLINE_IN_SECONDS = 15 * 60; // 15 minutes
|
|
5
5
|
exports.CORE_DEADLINE_IN_SECONDS = 60; // 1 minute
|
|
6
|
+
exports.ORDERS_GATEWAY_DEADLINE_IN_SECONDS = 60; // 1 minute
|
|
6
7
|
exports.RELAYER_ACCOUNT = '0xb43c317c9c9215d268881d7d6b59c2d3d0247da1'; // @todo update value
|
|
7
8
|
exports.PUBLISHER_ACCOUNT = '0xE32519ca0e751C754c8E1378846B5cd95A1CB66a'; // @todo update value
|
|
8
9
|
exports.CONDITIONAL_ORDER_SIG_DEADLINE = Math.pow(10, 18); // very big number for timestamp
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"/","sources":["transactions/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,0BAA0B,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,aAAa;AACnD,QAAA,wBAAwB,GAAG,EAAE,CAAC,CAAC,WAAW;AAC1C,QAAA,eAAe,GAAG,4CAA4C,CAAC,CAAC,qBAAqB;AACrF,QAAA,iBAAiB,GAAG,4CAA4C,CAAC,CAAC,qBAAqB;AACvF,QAAA,8BAA8B,GAAG,SAAA,EAAE,EAAI,EAAE,CAAA,CAAC,CAAC,gCAAgC","sourcesContent":["export const BRIDGE_DEADLINE_IN_SECONDS = 15 * 60; // 15 minutes\nexport const CORE_DEADLINE_IN_SECONDS = 60; // 1 minute\nexport const RELAYER_ACCOUNT = '0xb43c317c9c9215d268881d7d6b59c2d3d0247da1'; // @todo update value\nexport const PUBLISHER_ACCOUNT = '0xE32519ca0e751C754c8E1378846B5cd95A1CB66a'; // @todo update value\nexport const CONDITIONAL_ORDER_SIG_DEADLINE = 10 ** 18; // very big number for timestamp\n"]}
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"/","sources":["transactions/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,0BAA0B,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,aAAa;AACnD,QAAA,wBAAwB,GAAG,EAAE,CAAC,CAAC,WAAW;AAC1C,QAAA,kCAAkC,GAAG,EAAE,CAAC,CAAC,WAAW;AACpD,QAAA,eAAe,GAAG,4CAA4C,CAAC,CAAC,qBAAqB;AACrF,QAAA,iBAAiB,GAAG,4CAA4C,CAAC,CAAC,qBAAqB;AACvF,QAAA,8BAA8B,GAAG,SAAA,EAAE,EAAI,EAAE,CAAA,CAAC,CAAC,gCAAgC","sourcesContent":["export const BRIDGE_DEADLINE_IN_SECONDS = 15 * 60; // 15 minutes\nexport const CORE_DEADLINE_IN_SECONDS = 60; // 1 minute\nexport const ORDERS_GATEWAY_DEADLINE_IN_SECONDS = 60; // 1 minute\nexport const RELAYER_ACCOUNT = '0xb43c317c9c9215d268881d7d6b59c2d3d0247da1'; // @todo update value\nexport const PUBLISHER_ACCOUNT = '0xE32519ca0e751C754c8E1378846B5cd95A1CB66a'; // @todo update value\nexport const CONDITIONAL_ORDER_SIG_DEADLINE = 10 ** 18; // very big number for timestamp\n"]}
|
|
@@ -9,6 +9,7 @@ var ContractType;
|
|
|
9
9
|
ContractType["PASSIVE_POOL_PROXY"] = "passive_pool_proxy";
|
|
10
10
|
ContractType["PERIPHERY_PROXY"] = "periphery_proxy";
|
|
11
11
|
ContractType["CONDITIONAL_ORDERS_PROXY"] = "conditional_orders_proxy";
|
|
12
|
+
ContractType["ORDERS_GATEWAY_PROXY"] = "orders_gateway_proxy";
|
|
12
13
|
ContractType["PASSIVE_PERP_PROXY"] = "passive_perp_proxy";
|
|
13
14
|
ContractType["ORACLE_ADAPTERS_PROXY"] = "oracle_adapters_proxy";
|
|
14
15
|
ContractType["MULTICALL"] = "multicall";
|
|
@@ -20,6 +21,7 @@ var addresses = (_a = {},
|
|
|
20
21
|
_b[ContractType.PASSIVE_POOL_PROXY] = '0x9a3a664987b88790a6fdc1632e3b607813fd94ff',
|
|
21
22
|
_b[ContractType.PERIPHERY_PROXY] = '0x94ccae812f1647696754412082dd6684c2366a7f',
|
|
22
23
|
_b[ContractType.CONDITIONAL_ORDERS_PROXY] = '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',
|
|
24
|
+
_b[ContractType.ORDERS_GATEWAY_PROXY] = '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',
|
|
23
25
|
_b[ContractType.PASSIVE_PERP_PROXY] = '0x9ec177fed042ef2307928be2f5cdbf663b20244b',
|
|
24
26
|
_b[ContractType.ORACLE_ADAPTERS_PROXY] = '0xc501a2356703cd351703d68963c6f4136120f7cf',
|
|
25
27
|
_b[ContractType.MULTICALL] = '0x5abde4f0af8eaf3c9967f7fa126e59a103357b5c',
|
|
@@ -30,6 +32,7 @@ var addresses = (_a = {},
|
|
|
30
32
|
_c[ContractType.PASSIVE_POOL_PROXY] = '0xb4b77d6180cc14472a9a7bdff01cc2459368d413',
|
|
31
33
|
_c[ContractType.PERIPHERY_PROXY] = '0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',
|
|
32
34
|
_c[ContractType.CONDITIONAL_ORDERS_PROXY] = '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',
|
|
35
|
+
_c[ContractType.ORDERS_GATEWAY_PROXY] = '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',
|
|
33
36
|
_c[ContractType.PASSIVE_PERP_PROXY] = '0x27e5cb712334e101b3c232eb0be198baaa595f5f',
|
|
34
37
|
_c[ContractType.ORACLE_ADAPTERS_PROXY] = '0x32edabc058c1207fe0ec5f8557643c28e4ff379e',
|
|
35
38
|
_c[ContractType.MULTICALL] = '0xed28d27dfca47ad2513c9f2e2d3c098c2ea5a47f',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractAddresses.js","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":";;;;AAAA,kCAAgD;AAEhD,IAAY,
|
|
1
|
+
{"version":3,"file":"contractAddresses.js","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":";;;;AAAA,kCAAgD;AAEhD,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,yDAAyC,CAAA;IACzC,mDAAmC,CAAA;IACnC,qEAAqD,CAAA;IACrD,6DAA6C,CAAA;IAC7C,yDAAyC,CAAA;IACzC,+DAA+C,CAAA;IAC/C,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;AACzB,CAAC,EAVW,YAAY,4BAAZ,YAAY,QAUvB;AAED,IAAM,SAAS;IACb,GAAC,mBAAW,CAAC,UAAU;QACrB,GAAC,YAAY,CAAC,UAAU,IAAG,4CAA4C;QACvE,GAAC,YAAY,CAAC,kBAAkB,IAC9B,4CAA4C;QAC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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 ORDERS_GATEWAY_PROXY = 'orders_gateway_proxy',\n PASSIVE_PERP_PROXY = 'passive_perp_proxy',\n ORACLE_ADAPTERS_PROXY = 'oracle_adapters_proxy',\n MULTICALL = 'multicall',\n REYA_SBTS = 'reya_sbts',\n}\n\nconst addresses: Record<ReyaChainId, Record<ContractType, Address>> = {\n [ReyaChainId.reyaCronos]: {\n [ContractType.CORE_PROXY]: '0xc6fb022962e1426f4e0ec9d2f8861c57926e9f72',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0x9a3a664987b88790a6fdc1632e3b607813fd94ff',\n [ContractType.PERIPHERY_PROXY]:\n '0x94ccae812f1647696754412082dd6684c2366a7f',\n [ContractType.CONDITIONAL_ORDERS_PROXY]:\n '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',\n [ContractType.ORDERS_GATEWAY_PROXY]:\n '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',\n [ContractType.PASSIVE_PERP_PROXY]:\n '0x9ec177fed042ef2307928be2f5cdbf663b20244b',\n [ContractType.ORACLE_ADAPTERS_PROXY]:\n '0xc501a2356703cd351703d68963c6f4136120f7cf',\n [ContractType.MULTICALL]: '0x5abde4f0af8eaf3c9967f7fa126e59a103357b5c',\n [ContractType.REYA_SBTS]: '0xc0092ea9179ace93b0cd8910958e335575562722',\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 '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',\n [ContractType.ORDERS_GATEWAY_PROXY]:\n '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',\n [ContractType.PASSIVE_PERP_PROXY]:\n '0x27e5cb712334e101b3c232eb0be198baaa595f5f',\n [ContractType.ORACLE_ADAPTERS_PROXY]:\n '0x32edabc058c1207fe0ec5f8557643c28e4ff379e',\n [ContractType.MULTICALL]: '0xed28d27dfca47ad2513c9f2e2d3c098c2ea5a47f',\n [ContractType.REYA_SBTS]: '0x14d7c1efc024e118df70b241afbd2447d37f1ed6',\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"]}
|
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.signRevokePermission = exports.signVoteByProxy = exports.signVote = exports.signGrantPermission = exports.signRegisterEmbeddedWallet = exports.signCancelConditionalOrder = exports.isConditionalOrderSignatureValid = exports.signInitiateOrUpdateSession = exports.
|
|
39
|
+
exports.signRevokePermission = exports.signVoteByProxy = exports.signVote = exports.signGrantPermission = exports.signRegisterEmbeddedWallet = exports.signCancelConditionalOrder = exports.isConditionalOrderSignatureValid = exports.signInitiateOrUpdateSession = exports.signOrdersGatewayOrder = exports.createOrdersGatewayOrderNonce = exports.signPoolRemoveLiquidity = exports.signCoreCommands = exports.convertEthersSignatureToEIP712Signature = void 0;
|
|
40
40
|
var ethers_1 = require("ethers");
|
|
41
41
|
var contractAddresses_1 = require("./contractAddresses");
|
|
42
42
|
var types_1 = require("../types");
|
|
@@ -189,16 +189,31 @@ var sessionUpdateTypes = {
|
|
|
189
189
|
{ name: 'nonce', type: 'uint256' },
|
|
190
190
|
],
|
|
191
191
|
};
|
|
192
|
-
function
|
|
192
|
+
function createOrdersGatewayOrderNonce(accountId, marketId, timestampMs) {
|
|
193
|
+
// Validate the input ranges
|
|
194
|
+
if (marketId < 0 || marketId >= Math.pow(2, 32))
|
|
195
|
+
throw new Error('marketId is out of range');
|
|
196
|
+
if (accountId < 0 || accountId >= Math.pow(2, 128))
|
|
197
|
+
throw new Error('accountId is out of range');
|
|
198
|
+
if (timestampMs < 0 || timestampMs >= Math.pow(2, 64))
|
|
199
|
+
throw new Error('timestamp is out of range');
|
|
200
|
+
var hashUint256 = (BigInt(accountId) << BigInt(98)) |
|
|
201
|
+
(BigInt(timestampMs) << BigInt(32)) |
|
|
202
|
+
BigInt(marketId);
|
|
203
|
+
return hashUint256;
|
|
204
|
+
}
|
|
205
|
+
exports.createOrdersGatewayOrderNonce = createOrdersGatewayOrderNonce;
|
|
206
|
+
function signOrdersGatewayOrder(signer, reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, deadline, creationTimestampMs) {
|
|
193
207
|
return __awaiter(this, void 0, void 0, function () {
|
|
194
|
-
var signature, _a, _b;
|
|
208
|
+
var nonce, signature, _a, _b;
|
|
195
209
|
var _c, _d;
|
|
196
210
|
return __generator(this, function (_e) {
|
|
197
211
|
switch (_e.label) {
|
|
198
212
|
case 0:
|
|
213
|
+
nonce = createOrdersGatewayOrderNonce(accountId, marketId, creationTimestampMs);
|
|
199
214
|
_a = signReyaTypedData;
|
|
200
215
|
_b = [signer,
|
|
201
|
-
(0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.
|
|
216
|
+
(0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY),
|
|
202
217
|
conditionalOrderTypes];
|
|
203
218
|
_c = {
|
|
204
219
|
verifyingChainId: reyaChainId,
|
|
@@ -219,12 +234,16 @@ function signConditionalOrder(signer, reyaChainId, accountId, marketId, exchange
|
|
|
219
234
|
_c)]))];
|
|
220
235
|
case 2:
|
|
221
236
|
signature = _e.sent();
|
|
222
|
-
return [2 /*return*/,
|
|
237
|
+
return [2 /*return*/, {
|
|
238
|
+
serializedSignature: signature.serialized,
|
|
239
|
+
nonce: nonce,
|
|
240
|
+
signature: convertEthersSignatureToEIP712Signature(signature, deadline),
|
|
241
|
+
}];
|
|
223
242
|
}
|
|
224
243
|
});
|
|
225
244
|
});
|
|
226
245
|
}
|
|
227
|
-
exports.
|
|
246
|
+
exports.signOrdersGatewayOrder = signOrdersGatewayOrder;
|
|
228
247
|
function signInitiateOrUpdateSession(signer, reyaChainId, accountId, target, until, nonce, deadline) {
|
|
229
248
|
return __awaiter(this, void 0, void 0, function () {
|
|
230
249
|
var signature, _a, _b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign.js","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAMgB;AAChB,yDAA+D;AAE/D,kCAAwE;AA0BxE,SAAgB,uCAAuC,CACrD,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,UAAA;KACT,CAAC;AACJ,CAAC;AAVD,0FAUC;AAED,SAAsB,gBAAgB,CACpC,MAA8B,EAC9B,WAAwB,EACx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jB,UAAkB,EAClB,IAAY,EACZ,KAAa,EACb,QAAgB;;;;;wBAEE,qBAAM,iBAAiB,CACvC,MAAM,EACN,IAAA,8BAAU,EAAC,WAAW,EAAE,gCAAY,CAAC,UAAU,CAAC,EAChD;wBACE,4BAA4B,EAAE;4BAC5B,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;4BAC7C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;4BACtC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;4BACvC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;4BACjC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;4BAClC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,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,oDAiCC","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 { Address, ConditionalOrderStatus, ReyaChainId } from '../types';\n\nexport type EIP712Signature = {\n v: number;\n r: string;\n s: string;\n deadline: number;\n};\n\nexport type CoreCommandsEIP712SignatureAndPayload = {\n signature: EIP712Signature;\n payload: {\n verifyingContract: string;\n types: Record<string, Array<TypedDataField>>;\n value: {\n verifyingChainId: number;\n caller: Address;\n accountId: number;\n commands: Command[];\n nonce: number;\n deadline: number;\n extraSignatureData: string;\n };\n };\n};\n\nexport function 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,\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<CoreCommandsEIP712SignatureAndPayload> {\n const types = {\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 const value = {\n verifyingChainId: reyaChainId,\n caller: caller,\n accountId: accountId,\n commands: commands,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n };\n\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n types,\n value,\n );\n\n const eip712Signature = convertEthersSignatureToEIP712Signature(\n signature,\n deadline,\n );\n\n return {\n signature: eip712Signature,\n payload: {\n verifyingContract: getAddress(reyaChainId, ContractType.CORE_PROXY),\n types: types,\n value: value,\n },\n };\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 extraSignatureData: 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: extraSignatureData,\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\nconst sessionUpdateTypes = {\n InitiateOrUpdateSession: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'session', type: 'InitiateOrUpdateSessionDetails' },\n ],\n InitiateOrUpdateSessionDetails: [\n { name: 'accountId', type: 'uint128' },\n { name: 'target', type: 'address' },\n { name: 'until', type: 'uint256' },\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 async function signInitiateOrUpdateSession(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n target: string,\n until: number,\n nonce: bigint,\n deadline: number,\n): Promise<string> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CONDITIONAL_ORDERS_PROXY),\n sessionUpdateTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n session: {\n accountId: accountId,\n target: target,\n until: until,\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\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: ConditionalOrderStatus.CANCELLED,\n actionType: 'changeStatus',\n };\n return await signer.signMessage(JSON.stringify(message));\n}\n\nexport async function signRegisterEmbeddedWallet(\n signer: Signer | JsonRpcSigner,\n embeddedWalletAddress: string,\n): Promise<string> {\n const message = {\n embeddedWalletAddress: embeddedWalletAddress,\n actionType: 'register',\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\nexport async function signVote(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n contractAddress: string,\n voter: string,\n isYesVote: boolean,\n deadline: number,\n): Promise<string> {\n const types = {\n CastVoteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'voter', type: 'address' },\n { name: 'yesVote', type: 'bool' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n };\n const values = {\n verifyingChainId: reyaChainId,\n voter: voter,\n yesVote: isYesVote,\n nonce: 1, // hardcoded because a user cannot vote more than once\n deadline: deadline,\n };\n\n const domain = getReyaDomain(contractAddress);\n\n const signatureString = await signer.signTypedData(domain, types, values);\n\n return signatureString;\n}\n\nexport async function signVoteByProxy(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n contractAddress: string,\n voter: string,\n votingPower: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n contractAddress,\n {\n RelayVoteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'voter', type: 'address' },\n { name: 'votingPower', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n voter: voter,\n votingPower: votingPower,\n deadline: deadline,\n },\n );\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signRevokePermission(\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 RevokeAccountPermissionBySig: [\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"]}
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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UAAkB,EAClB,IAAY,EACZ,KAAa,EACb,QAAgB;;;;;wBAEE,qBAAM,iBAAiB,CACvC,MAAM,EACN,IAAA,8BAAU,EAAC,WAAW,EAAE,gCAAY,CAAC,UAAU,CAAC,EAChD;wBACE,4BAA4B,EAAE;4BAC5B,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;4BAC7C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;4BACtC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;4BACvC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;4BACjC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;4BAClC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,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,oDAiCC","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 {\n Address,\n ConditionalOrderStatus,\n ConditionalOrderType,\n OrdersGatewayOrderType,\n ReyaChainId,\n} from '../types';\n\nexport type EIP712Signature = {\n v: number;\n r: string;\n s: string;\n deadline: number;\n};\n\nexport type CoreCommandsEIP712SignatureAndPayload = {\n signature: EIP712Signature;\n payload: {\n verifyingContract: string;\n types: Record<string, Array<TypedDataField>>;\n value: {\n verifyingChainId: number;\n caller: Address;\n accountId: number;\n commands: Command[];\n nonce: number;\n deadline: number;\n extraSignatureData: string;\n };\n };\n};\n\nexport function 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,\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<CoreCommandsEIP712SignatureAndPayload> {\n const types = {\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 const value = {\n verifyingChainId: reyaChainId,\n caller: caller,\n accountId: accountId,\n commands: commands,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n };\n\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n types,\n value,\n );\n\n const eip712Signature = convertEthersSignatureToEIP712Signature(\n signature,\n deadline,\n );\n\n return {\n signature: eip712Signature,\n payload: {\n verifyingContract: getAddress(reyaChainId, ContractType.CORE_PROXY),\n types: types,\n value: value,\n },\n };\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 extraSignatureData: 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: extraSignatureData,\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\nconst sessionUpdateTypes = {\n InitiateOrUpdateSession: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'session', type: 'InitiateOrUpdateSessionDetails' },\n ],\n InitiateOrUpdateSessionDetails: [\n { name: 'accountId', type: 'uint128' },\n { name: 'target', type: 'address' },\n { name: 'until', type: 'uint256' },\n { name: 'signer', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n};\n\nexport function createOrdersGatewayOrderNonce(\n accountId: number,\n marketId: number,\n timestampMs: number,\n): bigint {\n // Validate the input ranges\n if (marketId < 0 || marketId >= 2 ** 32)\n throw new Error('marketId is out of range');\n if (accountId < 0 || accountId >= 2 ** 128)\n throw new Error('accountId is out of range');\n if (timestampMs < 0 || timestampMs >= 2 ** 64)\n throw new Error('timestamp is out of range');\n\n const hashUint256 =\n (BigInt(accountId) << BigInt(98)) |\n (BigInt(timestampMs) << BigInt(32)) |\n BigInt(marketId);\n\n return hashUint256;\n}\n\ntype SignOrdersGatewayOrderOutput = {\n serializedSignature: string;\n nonce: bigint;\n signature: EIP712Signature;\n};\n\nexport async function signOrdersGatewayOrder(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: ConditionalOrderType | OrdersGatewayOrderType,\n inputs: string,\n deadline: number,\n creationTimestampMs: number,\n): Promise<SignOrdersGatewayOrderOutput> {\n const nonce = createOrdersGatewayOrderNonce(\n accountId,\n marketId,\n creationTimestampMs,\n );\n\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_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 {\n serializedSignature: signature.serialized,\n nonce,\n signature: convertEthersSignatureToEIP712Signature(signature, deadline),\n };\n}\n\nexport async function signInitiateOrUpdateSession(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n target: string,\n until: number,\n nonce: bigint,\n deadline: number,\n): Promise<string> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CONDITIONAL_ORDERS_PROXY),\n sessionUpdateTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n session: {\n accountId: accountId,\n target: target,\n until: until,\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\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: ConditionalOrderStatus.CANCELLED,\n actionType: 'changeStatus',\n };\n return await signer.signMessage(JSON.stringify(message));\n}\n\nexport async function signRegisterEmbeddedWallet(\n signer: Signer | JsonRpcSigner,\n embeddedWalletAddress: string,\n): Promise<string> {\n const message = {\n embeddedWalletAddress: embeddedWalletAddress,\n actionType: 'register',\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\nexport async function signVote(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n contractAddress: string,\n voter: string,\n isYesVote: boolean,\n deadline: number,\n): Promise<string> {\n const types = {\n CastVoteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'voter', type: 'address' },\n { name: 'yesVote', type: 'bool' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n };\n const values = {\n verifyingChainId: reyaChainId,\n voter: voter,\n yesVote: isYesVote,\n nonce: 1, // hardcoded because a user cannot vote more than once\n deadline: deadline,\n };\n\n const domain = getReyaDomain(contractAddress);\n\n const signatureString = await signer.signTypedData(domain, types, values);\n\n return signatureString;\n}\n\nexport async function signVoteByProxy(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n contractAddress: string,\n voter: string,\n votingPower: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n contractAddress,\n {\n RelayVoteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'voter', type: 'address' },\n { name: 'votingPower', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n voter: voter,\n votingPower: votingPower,\n deadline: deadline,\n },\n );\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signRevokePermission(\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 RevokeAccountPermissionBySig: [\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"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const BRIDGE_DEADLINE_IN_SECONDS: number;
|
|
2
2
|
export declare const CORE_DEADLINE_IN_SECONDS = 60;
|
|
3
|
+
export declare const ORDERS_GATEWAY_DEADLINE_IN_SECONDS = 60;
|
|
3
4
|
export declare const RELAYER_ACCOUNT = "0xb43c317c9c9215d268881d7d6b59c2d3d0247da1";
|
|
4
5
|
export declare const PUBLISHER_ACCOUNT = "0xE32519ca0e751C754c8E1378846B5cd95A1CB66a";
|
|
5
6
|
export declare const CONDITIONAL_ORDER_SIG_DEADLINE: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"/","sources":["transactions/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,QAAU,CAAC;AAClD,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,eAAO,MAAM,eAAe,+CAA+C,CAAC;AAC5E,eAAO,MAAM,iBAAiB,+CAA+C,CAAC;AAC9E,eAAO,MAAM,8BAA8B,QAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"/","sources":["transactions/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,QAAU,CAAC;AAClD,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,eAAO,MAAM,kCAAkC,KAAK,CAAC;AACrD,eAAO,MAAM,eAAe,+CAA+C,CAAC;AAC5E,eAAO,MAAM,iBAAiB,+CAA+C,CAAC;AAC9E,eAAO,MAAM,8BAA8B,QAAW,CAAC"}
|
|
@@ -4,6 +4,7 @@ export declare enum ContractType {
|
|
|
4
4
|
PASSIVE_POOL_PROXY = "passive_pool_proxy",
|
|
5
5
|
PERIPHERY_PROXY = "periphery_proxy",
|
|
6
6
|
CONDITIONAL_ORDERS_PROXY = "conditional_orders_proxy",
|
|
7
|
+
ORDERS_GATEWAY_PROXY = "orders_gateway_proxy",
|
|
7
8
|
PASSIVE_PERP_PROXY = "passive_perp_proxy",
|
|
8
9
|
ORACLE_ADAPTERS_PROXY = "oracle_adapters_proxy",
|
|
9
10
|
MULTICALL = "multicall",
|
|
@@ -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;IACrD,kBAAkB,uBAAuB;IACzC,qBAAqB,0BAA0B;IAC/C,SAAS,cAAc;IACvB,SAAS,cAAc;CACxB;
|
|
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;IACrD,oBAAoB,yBAAyB;IAC7C,kBAAkB,uBAAuB;IACzC,qBAAqB,0BAA0B;IAC/C,SAAS,cAAc;IACvB,SAAS,cAAc;CACxB;AAsCD,eAAO,MAAM,UAAU,YACZ,MAAM,gBACD,YAAY,KACzB,OAaF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signature, Signer, TypedDataField } from 'ethers';
|
|
2
2
|
import { Command } from './action';
|
|
3
|
-
import { Address, ReyaChainId } from '../types';
|
|
3
|
+
import { Address, ConditionalOrderType, OrdersGatewayOrderType, ReyaChainId } from '../types';
|
|
4
4
|
export type EIP712Signature = {
|
|
5
5
|
v: number;
|
|
6
6
|
r: string;
|
|
@@ -26,7 +26,13 @@ export type CoreCommandsEIP712SignatureAndPayload = {
|
|
|
26
26
|
export declare function convertEthersSignatureToEIP712Signature(signature: Signature, deadline: number): EIP712Signature;
|
|
27
27
|
export declare function signCoreCommands(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, caller: Address, accountId: number, commands: Command[], nonce: number, deadline: number, extraSignatureData: string): Promise<CoreCommandsEIP712SignatureAndPayload>;
|
|
28
28
|
export declare function signPoolRemoveLiquidity(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, caller: Address, owner: Address, poolId: number, sharesAmount: bigint, minOut: bigint, nonce: number, deadline: number, extraSignatureData: string): Promise<EIP712Signature>;
|
|
29
|
-
export declare function
|
|
29
|
+
export declare function createOrdersGatewayOrderNonce(accountId: number, marketId: number, timestampMs: number): bigint;
|
|
30
|
+
type SignOrdersGatewayOrderOutput = {
|
|
31
|
+
serializedSignature: string;
|
|
32
|
+
nonce: bigint;
|
|
33
|
+
signature: EIP712Signature;
|
|
34
|
+
};
|
|
35
|
+
export declare function signOrdersGatewayOrder(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, accountId: number, marketId: number, exchangeId: number, counterpartyAccountIds: number[], orderType: ConditionalOrderType | OrdersGatewayOrderType, inputs: string, deadline: number, creationTimestampMs: number): Promise<SignOrdersGatewayOrderOutput>;
|
|
30
36
|
export declare function signInitiateOrUpdateSession(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, accountId: number, target: string, until: number, nonce: bigint, deadline: number): Promise<string>;
|
|
31
37
|
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;
|
|
32
38
|
export declare function signCancelConditionalOrder(signer: Signer | JsonRpcSigner, orderId: string): Promise<string>;
|
|
@@ -35,4 +41,5 @@ export declare function signGrantPermission(signer: Signer | JsonRpcSigner, reya
|
|
|
35
41
|
export declare function signVote(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, contractAddress: string, voter: string, isYesVote: boolean, deadline: number): Promise<string>;
|
|
36
42
|
export declare function signVoteByProxy(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, contractAddress: string, voter: string, votingPower: number, deadline: number): Promise<EIP712Signature>;
|
|
37
43
|
export declare function signRevokePermission(signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, accountId: number, permission: string, user: string, nonce: number, deadline: number): Promise<EIP712Signature>;
|
|
44
|
+
export {};
|
|
38
45
|
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign.d.ts","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EACT,MAAM,EACN,cAAc,EAEf,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EACT,MAAM,EACN,cAAc,EAEf,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,OAAO,EAAE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,CAAC,eAAe,CAAC,CAyB1B"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -860,6 +860,13 @@ type ReadyWithdrawalStatus = {
|
|
|
860
860
|
export type PendingWithdrawal = {
|
|
861
861
|
tokenAmount: number;
|
|
862
862
|
} & (PendingWithdrawalStatus | ReadyWithdrawalStatus);
|
|
863
|
+
export declare enum OrdersGatewayOrderType {
|
|
864
|
+
STOP_LOSS = 0,
|
|
865
|
+
TAKE_PROFIT = 1,
|
|
866
|
+
LIMIT_ORDER = 2,
|
|
867
|
+
MARKET_ORDER = 3,
|
|
868
|
+
REDUCE_ONLY_MARKET_ORDER = 4
|
|
869
|
+
}
|
|
863
870
|
export declare enum ConditionalOrderType {
|
|
864
871
|
STOP_LOSS = 0,
|
|
865
872
|
TAKE_PROFIT = 1,
|