@reyaxyz/sdk 0.52.0 → 0.53.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/dist/services/margin-accounts/encode.js +5 -2
- package/dist/services/margin-accounts/encode.js.map +1 -1
- package/dist/services/orders/encode.js +8 -5
- package/dist/services/orders/encode.js.map +1 -1
- package/dist/services/orders/order.js +1 -1
- package/dist/services/orders/order.js.map +1 -1
- package/dist/services/sign.js +3 -0
- package/dist/services/sign.js.map +1 -1
- package/dist/types/services/margin-accounts/encode.d.ts.map +1 -1
- package/dist/types/services/orders/encode.d.ts.map +1 -1
- package/dist/types/services/sign.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/margin-accounts/encode.ts +6 -3
- package/src/services/orders/encode.ts +8 -5
- package/src/services/orders/order.ts +1 -1
- package/src/services/sign.ts +3 -0
|
@@ -58,6 +58,8 @@ var VaultWithPayload_json_1 = require("../../abis/socket/VaultWithPayload.json")
|
|
|
58
58
|
var sign_1 = require("../sign");
|
|
59
59
|
var consts_1 = require("../../utils/consts");
|
|
60
60
|
var common_1 = require("@reyaxyz/common");
|
|
61
|
+
var ethers_2 = require("ethers");
|
|
62
|
+
var contractAddresses_1 = require("../../utils/contractAddresses");
|
|
61
63
|
var encodeCreateAccountCall = function (accountOwner) {
|
|
62
64
|
var functionSignature = 'createAccount';
|
|
63
65
|
var parameters = [accountOwner];
|
|
@@ -90,7 +92,7 @@ var encodeTransferMargin = function (signer, chainId, coreSigNonce, fromMarginAc
|
|
|
90
92
|
multiAction = new action_1.MultiAction();
|
|
91
93
|
// todo: note can we make this more stateless?
|
|
92
94
|
(0, encode_1.encodeSingleTransferMargin)(toMarginAccountId, token, amount, multiAction);
|
|
93
|
-
return [4 /*yield*/, (0, sign_1.signCoreCommands)(signer, chainId,
|
|
95
|
+
return [4 /*yield*/, (0, sign_1.signCoreCommands)(signer, chainId, (0, contractAddresses_1.getAddress)(chainId, contractAddresses_1.ContractType.PERIPHERY_PROXY), fromMarginAccountId, multiAction.commands, coreSigNonce + 1, (0, common_1.getCurrentTimestampInSeconds)() + consts_1.CORE_DEADLINE_IN_SECONDS)];
|
|
94
96
|
case 1:
|
|
95
97
|
eip712Signature = _a.sent();
|
|
96
98
|
value = BigInt(0);
|
|
@@ -99,6 +101,7 @@ var encodeTransferMargin = function (signer, chainId, coreSigNonce, fromMarginAc
|
|
|
99
101
|
fromMarginAccountId,
|
|
100
102
|
multiAction.commands,
|
|
101
103
|
eip712Signature,
|
|
104
|
+
ethers_2.ethers.AbiCoder.defaultAbiCoder().encode([], []),
|
|
102
105
|
];
|
|
103
106
|
INTERFACE = new ethers_1.Interface(CoreProxy_json_2.abi);
|
|
104
107
|
calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
|
|
@@ -139,7 +142,7 @@ var encodeBridgeAndDepositNewMA = function (receiver, socketMsgGasLimit, socketC
|
|
|
139
142
|
var fallbackData = {
|
|
140
143
|
socketMsgGasLimit: fallbackSocketMsgGasLimit,
|
|
141
144
|
socketConnector: fallbackSocketConnector,
|
|
142
|
-
socketPayloadSize: fallbackSocketPayloadSize,
|
|
145
|
+
socketPayloadSize: fallbackSocketPayloadSize, // @todo update it
|
|
143
146
|
};
|
|
144
147
|
var peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData('depositNewMA((address,address,uint256),(uint256,uint256,address))', [inputs, fallbackData]);
|
|
145
148
|
var functionSignature = 'bridge';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/margin-accounts/encode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAmE;AACnE,iCAAmC;AACnC,oCAKmB;AAEnB,4DAAgD;AAChD,4DAA2D;AAC3D,4DAAgE;AAChE,iFAA4F;AAC5F,gCAA4D;AAC5D,6CAA+E;AAC/E,0CAA+D;AAGxD,IAAM,uBAAuB,GAA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C,EAAE,CAAC,EAAE,CAAC;AAChE,CAAC,CAAC;AA1CW,QAAA,gCAAgC,oCA0C3C","sourcesContent":["import { MethodParameters, MultiAction } from '../../utils/action';\nimport { Interface } from 'ethers';\nimport {\n encodeRouterCall,\n encodeSingleDeposit,\n encodeSingleTransferMargin,\n encodeSingleWithdraw,\n} from '../encode';\n\nimport { abi } from '../../abis/CoreProxy.json';\nimport { abi as coreAbi } from '../../abis/CoreProxy.json';\nimport { abi as peripheryAbi } from '../../abis/Periphery.json';\nimport { abi as Socket_VaultWithPayloadAbi } from '../../abis/socket/VaultWithPayload.json';\nimport { EIP712Signature, signCoreCommands } from '../sign';\nimport { CORE_DEADLINE_IN_SECONDS, RELAYER_ACCOUNT } from '../../utils/consts';\nimport { getCurrentTimestampInSeconds } from '@reyaxyz/common';\nimport { Signer } from 'ethers';\n\nexport const encodeCreateAccountCall = (\n accountOwner: string,\n): MethodParameters => {\n const functionSignature = 'createAccount';\n const parameters = [accountOwner];\n const INTERFACE = new Interface(abi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: BigInt(0).toString(10) };\n};\n\nexport const encodeDeposit = (\n accountId: number,\n token: string,\n amount: bigint,\n): MethodParameters => {\n const multiAction = new MultiAction();\n\n encodeSingleDeposit(token, amount, multiAction);\n\n const value = BigInt(0);\n const call = encodeRouterCall(multiAction, accountId, value);\n\n return {\n ...call,\n };\n};\n\nexport const encodeWithdraw = (\n accountId: number,\n token: string,\n amount: bigint,\n): MethodParameters => {\n const multiAction = new MultiAction();\n\n encodeSingleWithdraw(token, amount, multiAction);\n\n const value = BigInt(0);\n const call = encodeRouterCall(multiAction, accountId, value);\n\n return {\n ...call,\n };\n};\n\nexport const encodeTransferMargin = async (\n signer: Signer,\n chainId: number,\n coreSigNonce: number,\n fromMarginAccountId: number,\n toMarginAccountId: number,\n token: string,\n amount: bigint,\n): Promise<MethodParameters> => {\n const multiAction = new MultiAction();\n // todo: note can we make this more stateless?\n encodeSingleTransferMargin(toMarginAccountId, token, amount, multiAction);\n\n const eip712Signature = await signCoreCommands(\n signer,\n chainId,\n RELAYER_ACCOUNT,\n fromMarginAccountId,\n multiAction.commands,\n coreSigNonce + 1,\n getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,\n );\n\n const value = BigInt(0);\n const functionSignature = 'executeBySig';\n const parameters = [\n fromMarginAccountId,\n multiAction.commands,\n eip712Signature,\n ];\n\n const INTERFACE = new Interface(coreAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return {\n calldata: calldata,\n value: BigInt(value).toString(10),\n };\n};\n\nexport const encodeWithdrawMAAndBridge = (\n accountId: number,\n corePeripheryTokenAddress: string,\n corePeripheryTokenAmount: bigint,\n sig: EIP712Signature,\n socketMsgGasLimit: bigint,\n socketPayloadSize: bigint,\n socketConnector: string,\n receiver: string,\n): MethodParameters => {\n const functionSignature = 'withdrawMA';\n const parameters = [\n {\n accountId,\n token: corePeripheryTokenAddress,\n tokenAmount: corePeripheryTokenAmount,\n sig,\n socketMsgGasLimit,\n socketPayloadSize,\n socketConnector,\n receiver,\n },\n ];\n const INTERFACE = new Interface(peripheryAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: BigInt(0).toString(10) };\n};\n\nexport const encodeBridgeAndDepositNewMA = (\n receiver: string,\n socketMsgGasLimit: bigint,\n socketConnector: string,\n socketBridgeOptions: string,\n socketFees: bigint,\n accountOwner: string,\n peripheryTokenAddress: string,\n peripheryTokenAmount: bigint,\n moneyInOutTokenAmount: bigint,\n fallbackSocketMsgGasLimit: bigint,\n fallbackSocketConnector: string,\n fallbackSocketPayloadSize: bigint,\n): MethodParameters => {\n const PERIPHERY_INTERFACE = new Interface(peripheryAbi);\n const inputs = {\n accountOwner,\n token: peripheryTokenAddress,\n tokenAmount: peripheryTokenAmount,\n };\n const fallbackData = {\n socketMsgGasLimit: fallbackSocketMsgGasLimit,\n socketConnector: fallbackSocketConnector,\n socketPayloadSize: fallbackSocketPayloadSize,\n };\n const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(\n 'depositNewMA((address,address,uint256),(uint256,uint256,address))',\n [inputs, fallbackData],\n );\n\n const functionSignature = 'bridge';\n const parameters = [\n receiver,\n moneyInOutTokenAmount,\n socketMsgGasLimit,\n socketConnector,\n peripheryCalldata,\n socketBridgeOptions,\n ];\n const INTERFACE = new Interface(Socket_VaultWithPayloadAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: socketFees.toString(10) };\n};\n\nexport const encodeBridgeAndDepositExistingMA = (\n receiver: string,\n socketMsgGasLimit: bigint,\n socketConnector: string,\n socketBridgeOptions: string,\n socketFees: bigint,\n accountId: number,\n peripheryTokenAddress: string,\n peripheryTokenAmount: bigint,\n moneyInOutTokenAmount: bigint,\n fallbackSocketMsgGasLimit: bigint,\n fallbackSocketConnector: string,\n fallbackSocketPayloadSize: bigint,\n): MethodParameters => {\n const PERIPHERY_INTERFACE = new Interface(peripheryAbi);\n const inputs = {\n accountId,\n token: peripheryTokenAddress,\n tokenAmount: peripheryTokenAmount,\n };\n const fallbackData = {\n socketMsgGasLimit: fallbackSocketMsgGasLimit,\n socketConnector: fallbackSocketConnector,\n socketPayloadSize: fallbackSocketPayloadSize,\n };\n const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(\n 'depositExistingMA((uint128,address,uint256),(uint256,uint256,address))',\n [inputs, fallbackData],\n );\n\n const functionSignature = 'bridge';\n const parameters = [\n receiver,\n moneyInOutTokenAmount,\n socketMsgGasLimit,\n socketConnector,\n peripheryCalldata,\n socketBridgeOptions,\n ];\n const INTERFACE = new Interface(Socket_VaultWithPayloadAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: socketFees.toString(10) };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/margin-accounts/encode.ts"],"names":[],"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AAM,EAAE,YAAY,CAAC,CACvB,CAAC;IAEF,IAAM,iBAAiB,GAAG,QAAQ,CAAC;IACnC,IAAM,UAAU,GAAG;QACjB,QAAQ;QACR,qBAAqB;QACrB,iBAAiB;QACjB,eAAe;QACf,iBAAiB;QACjB,mBAAmB;KACpB,CAAC;IACF,IAAM,SAAS,GAAG,IAAI,kBAAS,CAAC,2BAA0B,CAAC,CAAC;IAC5D,IAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC7E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAChE,CAAC,CAAC;AA1CW,QAAA,gCAAgC,oCA0C3C","sourcesContent":["import { MethodParameters, MultiAction } from '../../utils/action';\nimport { Interface } from 'ethers';\nimport {\n encodeRouterCall,\n encodeSingleDeposit,\n encodeSingleTransferMargin,\n encodeSingleWithdraw,\n} from '../encode';\n\nimport { abi } from '../../abis/CoreProxy.json';\nimport { abi as coreAbi } from '../../abis/CoreProxy.json';\nimport { abi as peripheryAbi } from '../../abis/Periphery.json';\nimport { abi as Socket_VaultWithPayloadAbi } from '../../abis/socket/VaultWithPayload.json';\nimport { EIP712Signature, signCoreCommands } from '../sign';\nimport { CORE_DEADLINE_IN_SECONDS } from '../../utils/consts';\nimport { getCurrentTimestampInSeconds } from '@reyaxyz/common';\nimport { Signer } from 'ethers';\nimport { ethers } from 'ethers';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\n\nexport const encodeCreateAccountCall = (\n accountOwner: string,\n): MethodParameters => {\n const functionSignature = 'createAccount';\n const parameters = [accountOwner];\n const INTERFACE = new Interface(abi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: BigInt(0).toString(10) };\n};\n\nexport const encodeDeposit = (\n accountId: number,\n token: string,\n amount: bigint,\n): MethodParameters => {\n const multiAction = new MultiAction();\n\n encodeSingleDeposit(token, amount, multiAction);\n\n const value = BigInt(0);\n const call = encodeRouterCall(multiAction, accountId, value);\n\n return {\n ...call,\n };\n};\n\nexport const encodeWithdraw = (\n accountId: number,\n token: string,\n amount: bigint,\n): MethodParameters => {\n const multiAction = new MultiAction();\n\n encodeSingleWithdraw(token, amount, multiAction);\n\n const value = BigInt(0);\n const call = encodeRouterCall(multiAction, accountId, value);\n\n return {\n ...call,\n };\n};\n\nexport const encodeTransferMargin = async (\n signer: Signer,\n chainId: number,\n coreSigNonce: number,\n fromMarginAccountId: number,\n toMarginAccountId: number,\n token: string,\n amount: bigint,\n): Promise<MethodParameters> => {\n const multiAction = new MultiAction();\n // todo: note can we make this more stateless?\n encodeSingleTransferMargin(toMarginAccountId, token, amount, multiAction);\n\n const eip712Signature = await signCoreCommands(\n signer,\n chainId,\n getAddress(chainId, ContractType.PERIPHERY_PROXY),\n fromMarginAccountId,\n multiAction.commands,\n coreSigNonce + 1,\n getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,\n );\n\n const value = BigInt(0);\n const functionSignature = 'executeBySig';\n const parameters = [\n fromMarginAccountId,\n multiAction.commands,\n eip712Signature,\n ethers.AbiCoder.defaultAbiCoder().encode([], []),\n ];\n\n const INTERFACE = new Interface(coreAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return {\n calldata: calldata,\n value: BigInt(value).toString(10),\n };\n};\n\nexport const encodeWithdrawMAAndBridge = (\n accountId: number,\n corePeripheryTokenAddress: string,\n corePeripheryTokenAmount: bigint,\n sig: EIP712Signature,\n socketMsgGasLimit: bigint,\n socketPayloadSize: bigint,\n socketConnector: string,\n receiver: string,\n): MethodParameters => {\n const functionSignature = 'withdrawMA';\n const parameters = [\n {\n accountId,\n token: corePeripheryTokenAddress,\n tokenAmount: corePeripheryTokenAmount,\n sig,\n socketMsgGasLimit,\n socketPayloadSize,\n socketConnector,\n receiver,\n },\n ];\n const INTERFACE = new Interface(peripheryAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: BigInt(0).toString(10) };\n};\n\nexport const encodeBridgeAndDepositNewMA = (\n receiver: string,\n socketMsgGasLimit: bigint,\n socketConnector: string,\n socketBridgeOptions: string,\n socketFees: bigint,\n accountOwner: string,\n peripheryTokenAddress: string,\n peripheryTokenAmount: bigint,\n moneyInOutTokenAmount: bigint,\n fallbackSocketMsgGasLimit: bigint,\n fallbackSocketConnector: string,\n fallbackSocketPayloadSize: bigint,\n): MethodParameters => {\n const PERIPHERY_INTERFACE = new Interface(peripheryAbi);\n const inputs = {\n accountOwner,\n token: peripheryTokenAddress,\n tokenAmount: peripheryTokenAmount,\n };\n const fallbackData = {\n socketMsgGasLimit: fallbackSocketMsgGasLimit,\n socketConnector: fallbackSocketConnector,\n socketPayloadSize: fallbackSocketPayloadSize, // @todo update it\n };\n const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(\n 'depositNewMA((address,address,uint256),(uint256,uint256,address))',\n [inputs, fallbackData],\n );\n\n const functionSignature = 'bridge';\n const parameters = [\n receiver,\n moneyInOutTokenAmount,\n socketMsgGasLimit,\n socketConnector,\n peripheryCalldata,\n socketBridgeOptions,\n ];\n const INTERFACE = new Interface(Socket_VaultWithPayloadAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: socketFees.toString(10) };\n};\n\nexport const encodeBridgeAndDepositExistingMA = (\n receiver: string,\n socketMsgGasLimit: bigint,\n socketConnector: string,\n socketBridgeOptions: string,\n socketFees: bigint,\n accountId: number,\n peripheryTokenAddress: string,\n peripheryTokenAmount: bigint,\n moneyInOutTokenAmount: bigint,\n fallbackSocketMsgGasLimit: bigint,\n fallbackSocketConnector: string,\n fallbackSocketPayloadSize: bigint,\n): MethodParameters => {\n const PERIPHERY_INTERFACE = new Interface(peripheryAbi);\n const inputs = {\n accountId,\n token: peripheryTokenAddress,\n tokenAmount: peripheryTokenAmount,\n };\n const fallbackData = {\n socketMsgGasLimit: fallbackSocketMsgGasLimit,\n socketConnector: fallbackSocketConnector,\n socketPayloadSize: fallbackSocketPayloadSize,\n };\n const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(\n 'depositExistingMA((uint128,address,uint256),(uint256,uint256,address))',\n [inputs, fallbackData],\n );\n\n const functionSignature = 'bridge';\n const parameters = [\n receiver,\n moneyInOutTokenAmount,\n socketMsgGasLimit,\n socketConnector,\n peripheryCalldata,\n socketBridgeOptions,\n ];\n const INTERFACE = new Interface(Socket_VaultWithPayloadAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: socketFees.toString(10) };\n};\n"]}
|
|
@@ -43,7 +43,8 @@ var sign_1 = require("../sign");
|
|
|
43
43
|
var common_1 = require("@reyaxyz/common");
|
|
44
44
|
var consts_1 = require("../../utils/consts");
|
|
45
45
|
var ethers_1 = require("ethers");
|
|
46
|
-
var
|
|
46
|
+
var Periphery_json_1 = require("../../abis/Periphery.json");
|
|
47
|
+
var contractAddresses_1 = require("../../utils/contractAddresses");
|
|
47
48
|
var encodeMatchOrder = function (signer, chainId, coreSigNonce, accountId, orderBase, orderPriceLimit, counterpartyAccountIds, marketId, exchangeId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
49
|
var multiAction, eip712Signature, value, functionSignature, parameters, INTERFACE, calldata;
|
|
49
50
|
return __generator(this, function (_a) {
|
|
@@ -51,13 +52,15 @@ var encodeMatchOrder = function (signer, chainId, coreSigNonce, accountId, order
|
|
|
51
52
|
case 0:
|
|
52
53
|
multiAction = new action_1.MultiAction();
|
|
53
54
|
(0, encode_1.encodeSingleTrade)(counterpartyAccountIds, orderBase, orderPriceLimit, marketId, exchangeId, multiAction);
|
|
54
|
-
return [4 /*yield*/, (0, sign_1.signCoreCommands)(signer, chainId,
|
|
55
|
+
return [4 /*yield*/, (0, sign_1.signCoreCommands)(signer, chainId, (0, contractAddresses_1.getAddress)(chainId, contractAddresses_1.ContractType.PERIPHERY_PROXY), accountId, multiAction.commands, coreSigNonce + 1, (0, common_1.getCurrentTimestampInSeconds)() + consts_1.CORE_DEADLINE_IN_SECONDS)];
|
|
55
56
|
case 1:
|
|
56
57
|
eip712Signature = _a.sent();
|
|
57
58
|
value = BigInt(0);
|
|
58
|
-
functionSignature = '
|
|
59
|
-
parameters = [
|
|
60
|
-
|
|
59
|
+
functionSignature = 'executeMatchOrders';
|
|
60
|
+
parameters = [
|
|
61
|
+
{ accountId: accountId, commands: multiAction.commands, sig: eip712Signature },
|
|
62
|
+
];
|
|
63
|
+
INTERFACE = new ethers_1.Interface(Periphery_json_1.abi);
|
|
61
64
|
calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
|
|
62
65
|
return [2 /*return*/, {
|
|
63
66
|
calldata: calldata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/orders/encode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAmE;AACnE,oCAA8C;AAC9C,gCAA2C;AAC3C,0CAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/orders/encode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAmE;AACnE,oCAA8C;AAC9C,gCAA2C;AAC3C,0CAA+D;AAC/D,6CAA8D;AAC9D,iCAA2C;AAC3C,4DAAgD;AAChD,mEAAyE;AAClE,IAAM,gBAAgB,GAAG,UAC9B,MAAc,EACd,OAAe,EACf,YAAoB,EACpB,SAAiB,EACjB,SAAiB,EACjB,eAAuB,EACvB,sBAAgC,EAChC,QAAgB,EAChB,UAAkB;;;;;gBAEZ,WAAW,GAAG,IAAI,oBAAW,EAAE,CAAC;gBAEtC,IAAA,0BAAiB,EACf,sBAAsB,EACtB,SAAS,EACT,eAAe,EACf,QAAQ,EACR,UAAU,EACV,WAAW,CACZ,CAAC;gBACsB,qBAAM,IAAA,uBAAgB,EAC5C,MAAM,EACN,OAAO,EACP,IAAA,8BAAU,EAAC,OAAO,EAAE,gCAAY,CAAC,eAAe,CAAC,EACjD,SAAS,EACT,WAAW,CAAC,QAAQ,EACpB,YAAY,GAAG,CAAC,EAChB,IAAA,qCAA4B,GAAE,GAAG,iCAAwB,CAC1D,EAAA;;gBARK,eAAe,GAAG,SAQvB;gBAEK,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAClB,iBAAiB,GAAG,oBAAoB,CAAC;gBACzC,UAAU,GAAG;oBACjB,EAAE,SAAS,WAAA,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE;iBACpE,CAAC;gBAEI,SAAS,GAAG,IAAI,kBAAS,CAAC,oBAAG,CAAC,CAAC;gBAC/B,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;gBAC7E,sBAAO;wBACL,QAAQ,EAAE,QAAQ;wBAClB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;qBAClC,EAAC;;;KACH,CAAC;AA3CW,QAAA,gBAAgB,oBA2C3B","sourcesContent":["import { MethodParameters, MultiAction } from '../../utils/action';\nimport { encodeSingleTrade } from '../encode';\nimport { signCoreCommands } from '../sign';\nimport { getCurrentTimestampInSeconds } from '@reyaxyz/common';\nimport { CORE_DEADLINE_IN_SECONDS } from '../../utils/consts';\nimport { Interface, Signer } from 'ethers';\nimport { abi } from '../../abis/Periphery.json';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\nexport const encodeMatchOrder = async (\n signer: Signer,\n chainId: number,\n coreSigNonce: number,\n accountId: number,\n orderBase: bigint,\n orderPriceLimit: bigint,\n counterpartyAccountIds: number[],\n marketId: number,\n exchangeId: number,\n): Promise<MethodParameters> => {\n const multiAction = new MultiAction();\n\n encodeSingleTrade(\n counterpartyAccountIds,\n orderBase,\n orderPriceLimit,\n marketId,\n exchangeId,\n multiAction,\n );\n const eip712Signature = await signCoreCommands(\n signer,\n chainId,\n getAddress(chainId, ContractType.PERIPHERY_PROXY),\n accountId,\n multiAction.commands,\n coreSigNonce + 1,\n getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,\n );\n\n const value = BigInt(0);\n const functionSignature = 'executeMatchOrders';\n const parameters = [\n { accountId, commands: multiAction.commands, sig: eip712Signature },\n ];\n\n const INTERFACE = new Interface(abi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return {\n calldata: calldata,\n value: BigInt(value).toString(10),\n };\n};\n"]}
|
|
@@ -64,7 +64,7 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
64
64
|
return [4 /*yield*/, (0, encode_1.encodeMatchOrder)(params.signer, chainId, params.owner.coreSigNonce, params.marginAccountId, orderBase, orderPriceLimit, params.market.counterpartyAccountIds, params.market.id, params.market.exchangeId)];
|
|
65
65
|
case 2:
|
|
66
66
|
_a = _c.sent(), data = _a.calldata, value = _a.value;
|
|
67
|
-
return [4 /*yield*/, (0, executeTransaction_1.signAndBroadcastTransaction)(params.signer, data, value, chainId, contractAddresses_1.ContractType.
|
|
67
|
+
return [4 /*yield*/, (0, executeTransaction_1.signAndBroadcastTransaction)(params.signer, data, value, chainId, contractAddresses_1.ContractType.PERIPHERY_PROXY, {})];
|
|
68
68
|
case 3:
|
|
69
69
|
result = _c.sent();
|
|
70
70
|
return [2 /*return*/, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,mCAA4C;AAC5C,4DAAoE;AACpE,2CAAgE;AAChE,8DAAqC;AACrC,mEAA6D;AAC7D,0CAAwC;AAEjC,IAAM,UAA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ult,\n MatchOrderParams,\n MatchOrderResult,\n} from './types';\nimport { encodeMatchOrder } from './encode';\nimport { signAndBroadcastTransaction } from '../executeTransaction';\nimport { calculatePriceLimitForTrade } from '../../utils/trade';\nimport BigNumber from 'bignumber.js';\nimport { ContractType } from '../../utils/contractAddresses';\nimport { scale } from '@reyaxyz/common';\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n if (params.snappedAmountInBase === 0) {\n throw new Error('Position base can not be 0');\n }\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n params.snappedAmountInBase,\n );\n\n const orderBase = scale(18)(params.snappedAmountInBase);\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n const { calldata: data, value } = await encodeMatchOrder(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.marginAccountId,\n orderBase,\n orderPriceLimit,\n params.market.counterpartyAccountIds,\n params.market.id,\n params.market.exchangeId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.PERIPHERY_PROXY,\n {},\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n\nexport const closeOrder = async (\n params: CloseOrderParams,\n): Promise<CloseOrderResult> => {\n if (params.orderBase === 0) {\n throw new Error('Position base can not be 0');\n }\n\n const base = scale(18)(params.orderBase);\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n BigNumber(params.orderBase).negated().toNumber(), // used just because of sign\n );\n\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n const { calldata: data, value } = await encodeMatchOrder(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.marginAccountId,\n -base,\n orderPriceLimit,\n params.market.counterpartyAccountIds,\n params.market.id,\n params.market.exchangeId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.CORE_PROXY,\n {},\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
package/dist/services/sign.js
CHANGED
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.signPoolRemoveLiquidity = exports.signCoreCommands = void 0;
|
|
40
40
|
var ethers_1 = require("ethers");
|
|
41
41
|
var contractAddresses_1 = require("../utils/contractAddresses");
|
|
42
|
+
var ethers_2 = require("ethers");
|
|
42
43
|
function convertEthersSignatureToEIP712Signature(signature, deadline) {
|
|
43
44
|
return {
|
|
44
45
|
v: signature.v,
|
|
@@ -60,6 +61,7 @@ function signCoreCommands(signer, reyaChainId, caller, accountId, commands, nonc
|
|
|
60
61
|
{ name: 'commands', type: 'Command[]' },
|
|
61
62
|
{ name: 'nonce', type: 'uint256' },
|
|
62
63
|
{ name: 'deadline', type: 'uint256' },
|
|
64
|
+
{ name: 'extraSignatureData', type: 'bytes' },
|
|
63
65
|
],
|
|
64
66
|
Command: [
|
|
65
67
|
{ name: 'commandType', type: 'uint8' },
|
|
@@ -74,6 +76,7 @@ function signCoreCommands(signer, reyaChainId, caller, accountId, commands, nonc
|
|
|
74
76
|
commands: commands,
|
|
75
77
|
nonce: nonce,
|
|
76
78
|
deadline: deadline,
|
|
79
|
+
extraSignatureData: ethers_2.ethers.AbiCoder.defaultAbiCoder().encode([], []),
|
|
77
80
|
})];
|
|
78
81
|
case 1:
|
|
79
82
|
signature = _a.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign.js","sourceRoot":"/","sources":["services/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA0E;AAC1E,gEAAsE;
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"/","sources":["services/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA0E;AAC1E,gEAAsE;AAGtE,iCAAgC;AAShC,SAAS,uCAAuC,CAC9C,SAAoB,EACpB,QA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,EAAE,KAAK;wBACZ,QAAQ,EAAE,QAAQ;qBACnB,CACF,EAAA;;oBAzBK,SAAS,GAAG,SAyBjB;oBAED,sBAAO,uCAAuC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAC;;;;CACrE;AAvCD,0DAuCC;AAED,SAAe,iBAAiB,CAC9B,MAA8B,EAC9B,iBAAyB,EACzB,KAA4C;AAC5C,8DAA8D;AAC9D,KAA0B;;;;;;oBAEpB,MAAM,GAAG;wBACb,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,GAAG;wBACZ,iBAAiB,EAAE,iBAAiB;qBACrC,CAAC;oBAEsB,qBAAM,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,EAAA;;oBAAlE,eAAe,GAAG,SAAgD;oBAExE,sBAAO,kBAAS,CAAC,IAAI,CAAC,eAAe,CAAC,EAAC;;;;CACxC","sourcesContent":["import { JsonRpcSigner, Signature, Signer, TypedDataField } from 'ethers';\nimport { ContractType, getAddress } from '../utils/contractAddresses';\nimport { Address, ReyaChainId } from '@reyaxyz/common';\nimport { Command } from '../utils/action';\nimport { ethers } from 'ethers';\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): 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: ethers.AbiCoder.defaultAbiCoder().encode([], []),\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): 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 ],\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 },\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"/","sources":["services/margin-accounts/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAanE,OAAO,EAAE,eAAe,EAAoB,MAAM,SAAS,CAAC;AAG5D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"/","sources":["services/margin-accounts/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAanE,OAAO,EAAE,eAAe,EAAoB,MAAM,SAAS,CAAC;AAG5D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,uBAAuB,iBACpB,MAAM,KACnB,gBAMF,CAAC;AAEF,eAAO,MAAM,aAAa,cACb,MAAM,SACV,MAAM,UACL,MAAM,KACb,gBAWF,CAAC;AAEF,eAAO,MAAM,cAAc,cACd,MAAM,SACV,MAAM,UACL,MAAM,KACb,gBAWF,CAAC;AAEF,eAAO,MAAM,oBAAoB,WACvB,MAAM,WACL,MAAM,gBACD,MAAM,uBACC,MAAM,qBACR,MAAM,SAClB,MAAM,UACL,MAAM,KACb,QAAQ,gBAAgB,CA8B1B,CAAC;AAEF,eAAO,MAAM,yBAAyB,cACzB,MAAM,6BACU,MAAM,4BACP,MAAM,OAC3B,eAAe,qBACD,MAAM,qBACN,MAAM,mBACR,MAAM,YACb,MAAM,KACf,gBAiBF,CAAC;AAEF,eAAO,MAAM,2BAA2B,aAC5B,MAAM,qBACG,MAAM,mBACR,MAAM,uBACF,MAAM,cACf,MAAM,gBACJ,MAAM,yBACG,MAAM,wBACP,MAAM,yBACL,MAAM,6BACF,MAAM,2BACR,MAAM,6BACJ,MAAM,KAChC,gBA6BF,CAAC;AAEF,eAAO,MAAM,gCAAgC,aACjC,MAAM,qBACG,MAAM,mBACR,MAAM,uBACF,MAAM,cACf,MAAM,aACP,MAAM,yBACM,MAAM,wBACP,MAAM,yBACL,MAAM,6BACF,MAAM,2BACR,MAAM,6BACJ,MAAM,KAChC,gBA6BF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"/","sources":["services/orders/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAKnE,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"/","sources":["services/orders/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAKnE,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG3C,eAAO,MAAM,gBAAgB,WACnB,MAAM,WACL,MAAM,gBACD,MAAM,aACT,MAAM,aACN,MAAM,mBACA,MAAM,0BACC,MAAM,EAAE,YACtB,MAAM,cACJ,MAAM,KACjB,QAAQ,gBAAgB,CAiC1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign.d.ts","sourceRoot":"/","sources":["services/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAa,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"/","sources":["services/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAa,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAcF,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,CAAC,CAiC1B;AAED,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,CAAC,CA6B1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@reyaxyz/common": "0.
|
|
32
|
+
"@reyaxyz/common": "0.60.0",
|
|
33
33
|
"bignumber.js": "^9.1.2",
|
|
34
34
|
"ethers": "6.9.0"
|
|
35
35
|
},
|
|
36
36
|
"packageManager": "pnpm@8.10.4",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "96caef995be80420d4a1f697d0470c01e41228f8"
|
|
38
38
|
}
|
|
@@ -12,9 +12,11 @@ import { abi as coreAbi } from '../../abis/CoreProxy.json';
|
|
|
12
12
|
import { abi as peripheryAbi } from '../../abis/Periphery.json';
|
|
13
13
|
import { abi as Socket_VaultWithPayloadAbi } from '../../abis/socket/VaultWithPayload.json';
|
|
14
14
|
import { EIP712Signature, signCoreCommands } from '../sign';
|
|
15
|
-
import { CORE_DEADLINE_IN_SECONDS
|
|
15
|
+
import { CORE_DEADLINE_IN_SECONDS } from '../../utils/consts';
|
|
16
16
|
import { getCurrentTimestampInSeconds } from '@reyaxyz/common';
|
|
17
17
|
import { Signer } from 'ethers';
|
|
18
|
+
import { ethers } from 'ethers';
|
|
19
|
+
import { ContractType, getAddress } from '../../utils/contractAddresses';
|
|
18
20
|
|
|
19
21
|
export const encodeCreateAccountCall = (
|
|
20
22
|
accountOwner: string,
|
|
@@ -76,7 +78,7 @@ export const encodeTransferMargin = async (
|
|
|
76
78
|
const eip712Signature = await signCoreCommands(
|
|
77
79
|
signer,
|
|
78
80
|
chainId,
|
|
79
|
-
|
|
81
|
+
getAddress(chainId, ContractType.PERIPHERY_PROXY),
|
|
80
82
|
fromMarginAccountId,
|
|
81
83
|
multiAction.commands,
|
|
82
84
|
coreSigNonce + 1,
|
|
@@ -89,6 +91,7 @@ export const encodeTransferMargin = async (
|
|
|
89
91
|
fromMarginAccountId,
|
|
90
92
|
multiAction.commands,
|
|
91
93
|
eip712Signature,
|
|
94
|
+
ethers.AbiCoder.defaultAbiCoder().encode([], []),
|
|
92
95
|
];
|
|
93
96
|
|
|
94
97
|
const INTERFACE = new Interface(coreAbi);
|
|
@@ -150,7 +153,7 @@ export const encodeBridgeAndDepositNewMA = (
|
|
|
150
153
|
const fallbackData = {
|
|
151
154
|
socketMsgGasLimit: fallbackSocketMsgGasLimit,
|
|
152
155
|
socketConnector: fallbackSocketConnector,
|
|
153
|
-
socketPayloadSize: fallbackSocketPayloadSize,
|
|
156
|
+
socketPayloadSize: fallbackSocketPayloadSize, // @todo update it
|
|
154
157
|
};
|
|
155
158
|
const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(
|
|
156
159
|
'depositNewMA((address,address,uint256),(uint256,uint256,address))',
|
|
@@ -2,9 +2,10 @@ import { MethodParameters, MultiAction } from '../../utils/action';
|
|
|
2
2
|
import { encodeSingleTrade } from '../encode';
|
|
3
3
|
import { signCoreCommands } from '../sign';
|
|
4
4
|
import { getCurrentTimestampInSeconds } from '@reyaxyz/common';
|
|
5
|
-
import { CORE_DEADLINE_IN_SECONDS
|
|
5
|
+
import { CORE_DEADLINE_IN_SECONDS } from '../../utils/consts';
|
|
6
6
|
import { Interface, Signer } from 'ethers';
|
|
7
|
-
import { abi } from '../../abis/
|
|
7
|
+
import { abi } from '../../abis/Periphery.json';
|
|
8
|
+
import { ContractType, getAddress } from '../../utils/contractAddresses';
|
|
8
9
|
export const encodeMatchOrder = async (
|
|
9
10
|
signer: Signer,
|
|
10
11
|
chainId: number,
|
|
@@ -29,7 +30,7 @@ export const encodeMatchOrder = async (
|
|
|
29
30
|
const eip712Signature = await signCoreCommands(
|
|
30
31
|
signer,
|
|
31
32
|
chainId,
|
|
32
|
-
|
|
33
|
+
getAddress(chainId, ContractType.PERIPHERY_PROXY),
|
|
33
34
|
accountId,
|
|
34
35
|
multiAction.commands,
|
|
35
36
|
coreSigNonce + 1,
|
|
@@ -37,8 +38,10 @@ export const encodeMatchOrder = async (
|
|
|
37
38
|
);
|
|
38
39
|
|
|
39
40
|
const value = BigInt(0);
|
|
40
|
-
const functionSignature = '
|
|
41
|
-
const parameters = [
|
|
41
|
+
const functionSignature = 'executeMatchOrders';
|
|
42
|
+
const parameters = [
|
|
43
|
+
{ accountId, commands: multiAction.commands, sig: eip712Signature },
|
|
44
|
+
];
|
|
42
45
|
|
|
43
46
|
const INTERFACE = new Interface(abi);
|
|
44
47
|
const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
|
package/src/services/sign.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { JsonRpcSigner, Signature, Signer, TypedDataField } from 'ethers';
|
|
|
2
2
|
import { ContractType, getAddress } from '../utils/contractAddresses';
|
|
3
3
|
import { Address, ReyaChainId } from '@reyaxyz/common';
|
|
4
4
|
import { Command } from '../utils/action';
|
|
5
|
+
import { ethers } from 'ethers';
|
|
5
6
|
|
|
6
7
|
export type EIP712Signature = {
|
|
7
8
|
v: number;
|
|
@@ -42,6 +43,7 @@ export async function signCoreCommands(
|
|
|
42
43
|
{ name: 'commands', type: 'Command[]' },
|
|
43
44
|
{ name: 'nonce', type: 'uint256' },
|
|
44
45
|
{ name: 'deadline', type: 'uint256' },
|
|
46
|
+
{ name: 'extraSignatureData', type: 'bytes' },
|
|
45
47
|
],
|
|
46
48
|
Command: [
|
|
47
49
|
{ name: 'commandType', type: 'uint8' },
|
|
@@ -57,6 +59,7 @@ export async function signCoreCommands(
|
|
|
57
59
|
commands: commands,
|
|
58
60
|
nonce: nonce,
|
|
59
61
|
deadline: deadline,
|
|
62
|
+
extraSignatureData: ethers.AbiCoder.defaultAbiCoder().encode([], []),
|
|
60
63
|
},
|
|
61
64
|
);
|
|
62
65
|
|