@reyaxyz/sdk 0.34.4 → 0.36.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.
Files changed (106) hide show
  1. package/dist/abis/socket/VaultWithPayload.json +31 -1
  2. package/dist/index.js +0 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/services/lp/bridgeAndDepositPassivePool.js +14 -15
  5. package/dist/services/lp/bridgeAndDepositPassivePool.js.map +1 -1
  6. package/dist/services/lp/encode.js +4 -6
  7. package/dist/services/lp/encode.js.map +1 -1
  8. package/dist/services/lp/simulateWithdrawPassivePoolAndBridge.js +1 -1
  9. package/dist/services/lp/simulateWithdrawPassivePoolAndBridge.js.map +1 -1
  10. package/dist/services/lp/transferFromMAToPool.js +11 -7
  11. package/dist/services/lp/transferFromMAToPool.js.map +1 -1
  12. package/dist/services/lp/types.js.map +1 -1
  13. package/dist/services/lp/withdrawPassivePoolAndBridge.js +6 -9
  14. package/dist/services/lp/withdrawPassivePoolAndBridge.js.map +1 -1
  15. package/dist/services/margin-accounts/bridgeAndDepositExistingMA.js +27 -20
  16. package/dist/services/margin-accounts/bridgeAndDepositExistingMA.js.map +1 -1
  17. package/dist/services/margin-accounts/bridgeAndDepositNewMA.js +14 -15
  18. package/dist/services/margin-accounts/bridgeAndDepositNewMA.js.map +1 -1
  19. package/dist/services/margin-accounts/deposit.js +3 -3
  20. package/dist/services/margin-accounts/deposit.js.map +1 -1
  21. package/dist/services/margin-accounts/encode.js +20 -12
  22. package/dist/services/margin-accounts/encode.js.map +1 -1
  23. package/dist/services/margin-accounts/transferMarginBetweenAccounts.js +3 -3
  24. package/dist/services/margin-accounts/transferMarginBetweenAccounts.js.map +1 -1
  25. package/dist/services/margin-accounts/types.js.map +1 -1
  26. package/dist/services/margin-accounts/withdraw.js +3 -3
  27. package/dist/services/margin-accounts/withdraw.js.map +1 -1
  28. package/dist/services/margin-accounts/withdrawMAAndBridge.js +20 -17
  29. package/dist/services/margin-accounts/withdrawMAAndBridge.js.map +1 -1
  30. package/dist/services/sign.js +26 -9
  31. package/dist/services/sign.js.map +1 -1
  32. package/dist/services/token/approve.js +18 -4
  33. package/dist/services/token/approve.js.map +1 -1
  34. package/dist/services/token/getAllowance.js +18 -4
  35. package/dist/services/token/getAllowance.js.map +1 -1
  36. package/dist/services/token/{getBalanceByChainId.js → getUsdcBalance.js} +18 -21
  37. package/dist/services/token/getUsdcBalance.js.map +1 -0
  38. package/dist/services/token/index.js +1 -1
  39. package/dist/services/token/index.js.map +1 -1
  40. package/dist/services/token/types.js +1 -0
  41. package/dist/services/token/types.js.map +1 -1
  42. package/dist/types/index.d.ts +0 -1
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/types/services/lp/bridgeAndDepositPassivePool.d.ts.map +1 -1
  45. package/dist/types/services/lp/encode.d.ts +2 -2
  46. package/dist/types/services/lp/encode.d.ts.map +1 -1
  47. package/dist/types/services/lp/transferFromMAToPool.d.ts.map +1 -1
  48. package/dist/types/services/lp/types.d.ts +1 -1
  49. package/dist/types/services/lp/types.d.ts.map +1 -1
  50. package/dist/types/services/lp/withdrawPassivePoolAndBridge.d.ts.map +1 -1
  51. package/dist/types/services/margin-accounts/bridgeAndDepositExistingMA.d.ts +2 -2
  52. package/dist/types/services/margin-accounts/bridgeAndDepositExistingMA.d.ts.map +1 -1
  53. package/dist/types/services/margin-accounts/bridgeAndDepositNewMA.d.ts.map +1 -1
  54. package/dist/types/services/margin-accounts/encode.d.ts +3 -3
  55. package/dist/types/services/margin-accounts/encode.d.ts.map +1 -1
  56. package/dist/types/services/margin-accounts/types.d.ts +2 -2
  57. package/dist/types/services/margin-accounts/types.d.ts.map +1 -1
  58. package/dist/types/services/margin-accounts/withdrawMAAndBridge.d.ts +1 -1
  59. package/dist/types/services/margin-accounts/withdrawMAAndBridge.d.ts.map +1 -1
  60. package/dist/types/services/sign.d.ts +4 -2
  61. package/dist/types/services/sign.d.ts.map +1 -1
  62. package/dist/types/services/token/approve.d.ts.map +1 -1
  63. package/dist/types/services/token/getAllowance.d.ts.map +1 -1
  64. package/dist/types/services/token/getUsdcBalance.d.ts +3 -0
  65. package/dist/types/services/token/getUsdcBalance.d.ts.map +1 -0
  66. package/dist/types/services/token/index.d.ts +1 -1
  67. package/dist/types/services/token/index.d.ts.map +1 -1
  68. package/dist/types/services/token/types.d.ts +3 -4
  69. package/dist/types/services/token/types.d.ts.map +1 -1
  70. package/dist/types/utils/contractAddresses.d.ts +1 -1
  71. package/dist/types/utils/contractAddresses.d.ts.map +1 -1
  72. package/dist/utils/contractAddresses.js +3 -3
  73. package/dist/utils/contractAddresses.js.map +1 -1
  74. package/package.json +3 -3
  75. package/src/abis/socket/VaultWithPayload.json +31 -1
  76. package/src/index.ts +0 -1
  77. package/src/services/lp/bridgeAndDepositPassivePool.ts +6 -8
  78. package/src/services/lp/encode.ts +2 -7
  79. package/src/services/lp/simulateWithdrawPassivePoolAndBridge.ts +2 -2
  80. package/src/services/lp/transferFromMAToPool.ts +17 -10
  81. package/src/services/lp/types.ts +1 -1
  82. package/src/services/lp/withdrawPassivePoolAndBridge.ts +6 -11
  83. package/src/services/margin-accounts/bridgeAndDepositExistingMA.ts +45 -16
  84. package/src/services/margin-accounts/bridgeAndDepositNewMA.ts +16 -8
  85. package/src/services/margin-accounts/deposit.ts +3 -3
  86. package/src/services/margin-accounts/encode.ts +25 -16
  87. package/src/services/margin-accounts/transferMarginBetweenAccounts.ts +3 -3
  88. package/src/services/margin-accounts/types.ts +2 -2
  89. package/src/services/margin-accounts/withdraw.ts +3 -3
  90. package/src/services/margin-accounts/withdrawMAAndBridge.ts +25 -15
  91. package/src/services/sign.ts +33 -20
  92. package/src/services/token/approve.ts +29 -6
  93. package/src/services/token/getAllowance.ts +29 -5
  94. package/src/services/token/getUsdcBalance.ts +15 -0
  95. package/src/services/token/index.ts +1 -1
  96. package/src/services/token/types.ts +2 -3
  97. package/src/utils/contractAddresses.ts +5 -4
  98. package/dist/services/token/getBalanceByChainId.js.map +0 -1
  99. package/dist/types/services/token/getBalanceByChainId.d.ts +0 -3
  100. package/dist/types/services/token/getBalanceByChainId.d.ts.map +0 -1
  101. package/dist/types/utils/network.d.ts +0 -4
  102. package/dist/types/utils/network.d.ts.map +0 -1
  103. package/dist/utils/network.js +0 -25
  104. package/dist/utils/network.js.map +0 -1
  105. package/src/services/token/getBalanceByChainId.ts +0 -30
  106. package/src/utils/network.ts +0 -23
@@ -1,4 +1,4 @@
1
- import { ContractType } from '../../utils/contractAddresses';
1
+ import { ContractType, getAddress } from '../../utils/contractAddresses';
2
2
  import { executeTransaction } from '../executeTransaction';
3
3
  import { signPoolRemoveLiquidity } from '../sign';
4
4
  import {
@@ -10,8 +10,7 @@ import {
10
10
  ReyaChainId,
11
11
  getCurrentTimestampInSeconds,
12
12
  getSocketConnectors,
13
- getSocketController,
14
- getTokenDetails,
13
+ getTokenInfoByAddress,
15
14
  scale,
16
15
  } from '@reyaxyz/common';
17
16
  import { BRIDGE_DEADLINE_IN_SECONDS } from '../../utils/consts';
@@ -33,18 +32,18 @@ export const withdrawPassivePoolAndBridge = async (
33
32
  const eip712Signature = await signPoolRemoveLiquidity(
34
33
  params.signer,
35
34
  reyaChainId,
35
+ getAddress(reyaChainId, ContractType.PERIPHERY_PROXY),
36
36
  params.owner.address,
37
37
  params.pool.id,
38
38
  sharesAmount,
39
39
  BigInt(0),
40
- params.owner.poolSigNonce,
40
+ params.owner.poolSigNonce + 1,
41
41
  getCurrentTimestampInSeconds() + BRIDGE_DEADLINE_IN_SECONDS,
42
42
  );
43
43
 
44
- const { tokenName } = getTokenDetails(params.pool.tokenAddress);
44
+ const tokenInfo = getTokenInfoByAddress(params.pool.tokenAddress);
45
45
 
46
46
  const { calldata: data, value } = encodeWithdrawPassivePoolAndBridge(
47
- params.owner.address,
48
47
  params.pool.id,
49
48
  sharesAmount,
50
49
  BigInt(0),
@@ -52,12 +51,8 @@ export const withdrawPassivePoolAndBridge = async (
52
51
  BigInt('10000000'), //todo
53
52
  getSocketConnectors({
54
53
  moneyInOutChainId: params.moneyInOutChainId,
55
- tokenName: tokenName,
54
+ tokenName: tokenInfo.name,
56
55
  }).withdraw,
57
- getSocketController({
58
- reyaChainId: reyaChainId,
59
- tokenName: tokenName,
60
- }),
61
56
  params.owner.address,
62
57
  );
63
58
 
@@ -4,53 +4,82 @@ import {
4
4
  getSocketDepositFeesAsBigInt,
5
5
  getSocketVault,
6
6
  scale,
7
- getTokenDetails,
8
7
  MoneyInOutChainId,
8
+ getTokenInfoByAddress,
9
+ getTokenInfoByName,
10
+ getReyaNetworkFromMoneyInOutChainId,
9
11
  } from '@reyaxyz/common';
10
12
  import { ContractType, getAddress } from '../../utils/contractAddresses';
11
13
  import { executeTransaction } from '../executeTransaction';
12
14
  import { encodeBridgeAndDepositExistingMA } from './encode';
13
15
  import {
14
- BridgeAndDepositExisingMAParams,
15
- BridgeAndDepositExisingMAResult,
16
+ BridgeAndDepositExistingMAParams,
17
+ BridgeAndDepositExistingMAResult,
16
18
  } from './types';
17
19
  import { signCoreCommands } from '../sign';
18
20
  import { BRIDGE_DEADLINE_IN_SECONDS } from '../../utils/consts';
19
- import { getReyaNetworkFromMoneyInOutChainId } from '../../utils/network';
21
+ import { encodeSingleDeposit } from '../encode';
22
+ import { MultiAction } from '../../utils/action';
20
23
 
21
- export const bridgeAndDepositExisingMA = async (
22
- params: BridgeAndDepositExisingMAParams,
23
- ): Promise<BridgeAndDepositExisingMAResult> => {
24
+ export const bridgeAndDepositExistingMA = async (
25
+ params: BridgeAndDepositExistingMAParams,
26
+ ): Promise<BridgeAndDepositExistingMAResult> => {
24
27
  const network = await params.signer.provider?.getNetwork();
25
28
  const moneyInOutChainId: MoneyInOutChainId = Number(network?.chainId);
26
29
  const reyaChainId = getReyaNetworkFromMoneyInOutChainId(moneyInOutChainId);
30
+
31
+ const moneyInOutTokenInfo = getTokenInfoByAddress(
32
+ params.tokenAddress,
33
+ moneyInOutChainId,
34
+ );
35
+ const reyaPeripheryTokenInfo = getTokenInfoByName(
36
+ moneyInOutTokenInfo.name,
37
+ reyaChainId,
38
+ );
39
+ const reyaCoreTokenInfo =
40
+ reyaPeripheryTokenInfo.name === 'USDC'
41
+ ? getTokenInfoByName('RUSD', reyaChainId)
42
+ : reyaPeripheryTokenInfo;
43
+
44
+ const multiAction = new MultiAction();
45
+ encodeSingleDeposit(
46
+ reyaCoreTokenInfo.address,
47
+ scale(reyaPeripheryTokenInfo.decimals)(params.amount),
48
+ multiAction,
49
+ );
50
+
51
+ const peripheryAddress = getAddress(
52
+ reyaChainId,
53
+ ContractType.PERIPHERY_PROXY,
54
+ );
55
+
27
56
  const eip712Signature = await signCoreCommands(
28
57
  params.signer,
29
58
  reyaChainId,
59
+ peripheryAddress,
30
60
  params.marginAccountId,
31
- params.owner.coreSigNonce,
61
+ multiAction.commands,
62
+ params.owner.coreSigNonce + 1,
32
63
  getCurrentTimestampInSeconds() + BRIDGE_DEADLINE_IN_SECONDS,
33
64
  );
34
65
 
35
- const { tokenName, tokenDecimals } = getTokenDetails(params.tokenAddress);
36
- const amount = scale(tokenDecimals)(params.amount);
37
-
38
66
  const socketConnectors = getSocketConnectors({
39
67
  moneyInOutChainId: moneyInOutChainId,
40
- tokenName: tokenName,
68
+ tokenName: moneyInOutTokenInfo.name,
41
69
  });
42
70
 
43
71
  const { calldata: data, value } = encodeBridgeAndDepositExistingMA(
44
- getAddress(reyaChainId, ContractType.PERIPHERY_PROXY),
72
+ peripheryAddress,
45
73
  BigInt('10000000'),
46
74
  socketConnectors.deposit,
47
75
  getSocketDepositFeesAsBigInt({
48
76
  moneyInOutChainId: moneyInOutChainId,
49
77
  }),
50
78
  params.marginAccountId,
51
- params.tokenAddress,
52
- amount,
79
+ reyaPeripheryTokenInfo.address,
80
+ scale(reyaPeripheryTokenInfo.decimals)(params.amount),
53
81
  eip712Signature,
82
+ scale(moneyInOutTokenInfo.decimals)(params.amount),
54
83
  BigInt('10000000'),
55
84
  socketConnectors.withdraw,
56
85
  );
@@ -62,7 +91,7 @@ export const bridgeAndDepositExisingMA = async (
62
91
  moneyInOutChainId,
63
92
  getSocketVault({
64
93
  moneyInOutChainId: moneyInOutChainId,
65
- tokenName: tokenName,
94
+ tokenName: moneyInOutTokenInfo.name,
66
95
  }),
67
96
  );
68
97
 
@@ -3,8 +3,10 @@ import {
3
3
  getSocketDepositFeesAsBigInt,
4
4
  getSocketVault,
5
5
  scale,
6
- getTokenDetails,
7
6
  MoneyInOutChainId,
7
+ getTokenInfoByName,
8
+ getTokenInfoByAddress,
9
+ getReyaNetworkFromMoneyInOutChainId,
8
10
  } from '@reyaxyz/common';
9
11
  import { ContractType, getAddress } from '../../utils/contractAddresses';
10
12
  import { executeTransaction } from '../executeTransaction';
@@ -13,7 +15,6 @@ import {
13
15
  BridgeAndDepositNewMAParams,
14
16
  BridgeAndDepositNewMAResult,
15
17
  } from './types';
16
- import { getReyaNetworkFromMoneyInOutChainId } from '../../utils/network';
17
18
 
18
19
  export const bridgeAndDepositNewMA = async (
19
20
  params: BridgeAndDepositNewMAParams,
@@ -22,12 +23,18 @@ export const bridgeAndDepositNewMA = async (
22
23
  const moneyInOutChainId: MoneyInOutChainId = Number(network?.chainId);
23
24
  const reyaChainId = getReyaNetworkFromMoneyInOutChainId(moneyInOutChainId);
24
25
 
25
- const { tokenName, tokenDecimals } = getTokenDetails(params.tokenAddress);
26
- const amount = scale(tokenDecimals)(params.amount);
26
+ const moneyInOutTokenInfo = getTokenInfoByAddress(
27
+ params.tokenAddress,
28
+ moneyInOutChainId,
29
+ );
30
+ const reyaPeripheryTokenInfo = getTokenInfoByName(
31
+ moneyInOutTokenInfo.name,
32
+ reyaChainId,
33
+ );
27
34
 
28
35
  const socketConnectors = getSocketConnectors({
29
36
  moneyInOutChainId: moneyInOutChainId,
30
- tokenName: tokenName,
37
+ tokenName: moneyInOutTokenInfo.name,
31
38
  });
32
39
 
33
40
  const { calldata: data, value } = encodeBridgeAndDepositNewMA(
@@ -38,8 +45,9 @@ export const bridgeAndDepositNewMA = async (
38
45
  moneyInOutChainId: moneyInOutChainId,
39
46
  }),
40
47
  params.ownerAddress,
41
- params.tokenAddress,
42
- amount,
48
+ reyaPeripheryTokenInfo.address,
49
+ scale(reyaPeripheryTokenInfo.decimals)(params.amount),
50
+ scale(moneyInOutTokenInfo.decimals)(params.amount),
43
51
  BigInt('10000000'),
44
52
  socketConnectors.withdraw,
45
53
  );
@@ -51,7 +59,7 @@ export const bridgeAndDepositNewMA = async (
51
59
  moneyInOutChainId,
52
60
  getSocketVault({
53
61
  moneyInOutChainId: moneyInOutChainId,
54
- tokenName: tokenName,
62
+ tokenName: moneyInOutTokenInfo.name,
55
63
  }),
56
64
  );
57
65
 
@@ -2,13 +2,13 @@ import { DepositParams, DepositResult } from './types';
2
2
  import { encodeDeposit } from './encode';
3
3
  import { executeTransaction } from '../executeTransaction';
4
4
  import { ContractType } from '../../utils/contractAddresses';
5
- import { scale, getTokenDetails } from '@reyaxyz/common';
5
+ import { getTokenInfoByAddress, scale } from '@reyaxyz/common';
6
6
 
7
7
  export const deposit = async (
8
8
  params: DepositParams,
9
9
  ): Promise<DepositResult> => {
10
- const { tokenDecimals } = getTokenDetails(params.tokenAddress);
11
- const amount = scale(tokenDecimals)(params.amount);
10
+ const tokenInfo = getTokenInfoByAddress(params.tokenAddress);
11
+ const amount = scale(tokenInfo.decimals)(params.amount);
12
12
  const { calldata: data, value } = encodeDeposit(
13
13
  params.marginAccountId,
14
14
  params.tokenAddress,
@@ -76,24 +76,22 @@ export const encodeTransferMargin = (
76
76
 
77
77
  export const encodeWithdrawMAAndBridge = (
78
78
  accountId: number,
79
- token: string,
80
- tokenAmount: bigint,
79
+ corePeripheryTokenAddress: string,
80
+ corePeripheryTokenAmount: bigint,
81
81
  sig: EIP712Signature,
82
82
  socketMsgGasLimit: bigint,
83
83
  socketConnector: string,
84
- socketController: string,
85
84
  receiver: string,
86
85
  ): MethodParameters => {
87
86
  const functionSignature = 'withdrawMA';
88
87
  const parameters = [
89
88
  {
90
89
  accountId,
91
- token,
92
- tokenAmount,
90
+ token: corePeripheryTokenAddress,
91
+ tokenAmount: corePeripheryTokenAmount,
93
92
  sig,
94
93
  socketMsgGasLimit,
95
94
  socketConnector,
96
- socketController,
97
95
  receiver,
98
96
  },
99
97
  ];
@@ -108,26 +106,31 @@ export const encodeBridgeAndDepositNewMA = (
108
106
  socketConnector: string,
109
107
  socketFees: bigint,
110
108
  accountOwner: string,
111
- token: string,
112
- tokenAmount: bigint,
109
+ peripheryTokenAddress: string,
110
+ peripheryTokenAmount: bigint,
111
+ moneyInOutTokenAmount: bigint,
113
112
  fallbackSocketMsgGasLimit: bigint,
114
113
  fallbackSocketConnector: string,
115
114
  ): MethodParameters => {
116
115
  const PERIPHERY_INTERFACE = new Interface(peripheryAbi);
117
- const inputs = { accountOwner, token, tokenAmount };
116
+ const inputs = {
117
+ accountOwner,
118
+ token: peripheryTokenAddress,
119
+ tokenAmount: peripheryTokenAmount,
120
+ };
118
121
  const fallbackData = {
119
122
  socketMsgGasLimit: fallbackSocketMsgGasLimit,
120
123
  socketConnector: fallbackSocketConnector,
121
124
  };
122
125
  const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(
123
- 'depositNewMA',
126
+ 'depositNewMA((address,address,uint256),(uint256,address))',
124
127
  [inputs, fallbackData],
125
128
  );
126
129
 
127
130
  const functionSignature = 'depositToAppChain';
128
131
  const parameters = [
129
132
  receiver,
130
- tokenAmount,
133
+ moneyInOutTokenAmount,
131
134
  socketMsgGasLimit,
132
135
  socketConnector,
133
136
  peripheryCalldata,
@@ -143,27 +146,33 @@ export const encodeBridgeAndDepositExistingMA = (
143
146
  socketConnector: string,
144
147
  socketFees: bigint,
145
148
  accountId: number,
146
- token: string,
147
- tokenAmount: bigint,
149
+ peripheryTokenAddress: string,
150
+ peripheryTokenAmount: bigint,
148
151
  sig: EIP712Signature,
152
+ moneyInOutTokenAmount: bigint,
149
153
  fallbackSocketMsgGasLimit: bigint,
150
154
  fallbackSocketConnector: string,
151
155
  ): MethodParameters => {
152
156
  const PERIPHERY_INTERFACE = new Interface(peripheryAbi);
153
- const inputs = { accountId, token, tokenAmount, sig };
157
+ const inputs = {
158
+ accountId,
159
+ token: peripheryTokenAddress,
160
+ tokenAmount: peripheryTokenAmount,
161
+ sig,
162
+ };
154
163
  const fallbackData = {
155
164
  socketMsgGasLimit: fallbackSocketMsgGasLimit,
156
165
  socketConnector: fallbackSocketConnector,
157
166
  };
158
167
  const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(
159
- 'depositExistingMA',
168
+ 'depositExistingMA((uint128,address,uint256,(uint8,bytes32,bytes32,uint256)),(uint256,address))',
160
169
  [inputs, fallbackData],
161
170
  );
162
171
 
163
172
  const functionSignature = 'depositToAppChain';
164
173
  const parameters = [
165
174
  receiver,
166
- tokenAmount,
175
+ moneyInOutTokenAmount,
167
176
  socketMsgGasLimit,
168
177
  socketConnector,
169
178
  peripheryCalldata,
@@ -1,4 +1,4 @@
1
- import { scale, getTokenDetails } from '@reyaxyz/common';
1
+ import { scale, getTokenInfoByAddress } from '@reyaxyz/common';
2
2
  import { ContractType } from '../../utils/contractAddresses';
3
3
  import { executeTransaction } from '../executeTransaction';
4
4
  import { encodeTransferMargin } from './encode';
@@ -10,8 +10,8 @@ import {
10
10
  export const transferMarginBetweenAccounts = async (
11
11
  params: TransferMarginBetweenAccountsParams,
12
12
  ): Promise<TransferMarginBetweenAccountsResult> => {
13
- const { tokenDecimals } = getTokenDetails(params.tokenAddress);
14
- const amount = scale(tokenDecimals)(params.amount);
13
+ const tokenInfo = getTokenInfoByAddress(params.tokenAddress);
14
+ const amount = scale(tokenInfo.decimals)(params.amount);
15
15
  const { calldata: data, value } = encodeTransferMargin(
16
16
  params.fromMarginAccountId,
17
17
  params.toMarginAccountId,
@@ -105,7 +105,7 @@ export type BridgeAndDepositNewMAResult = {
105
105
  transactionHash: string | null;
106
106
  };
107
107
 
108
- export type BridgeAndDepositExisingMAParams = {
108
+ export type BridgeAndDepositExistingMAParams = {
109
109
  signer: Signer | JsonRpcSigner;
110
110
  owner: Pick<OwnerMetadataEntity, 'address' | 'coreSigNonce'>;
111
111
  marginAccountId: MarginAccountEntity['id'];
@@ -113,7 +113,7 @@ export type BridgeAndDepositExisingMAParams = {
113
113
  amount: number;
114
114
  };
115
115
 
116
- export type BridgeAndDepositExisingMAResult = {
116
+ export type BridgeAndDepositExistingMAResult = {
117
117
  transactionHash: string | null;
118
118
  };
119
119
 
@@ -2,13 +2,13 @@ import { WithdrawParams, WithdrawResult } from './types';
2
2
  import { encodeWithdraw } from './encode';
3
3
  import { executeTransaction } from '../executeTransaction';
4
4
  import { ContractType } from '../../utils/contractAddresses';
5
- import { scale, getTokenDetails } from '@reyaxyz/common';
5
+ import { getTokenInfoByAddress, scale } from '@reyaxyz/common';
6
6
 
7
7
  export const withdraw = async (
8
8
  params: WithdrawParams,
9
9
  ): Promise<WithdrawResult> => {
10
- const { tokenDecimals } = getTokenDetails(params.tokenAddress);
11
- const amount = scale(tokenDecimals)(params.amount);
10
+ const tokenInfo = getTokenInfoByAddress(params.tokenAddress);
11
+ const amount = scale(tokenInfo.decimals)(params.amount);
12
12
 
13
13
  const { calldata: data, value } = encodeWithdraw(
14
14
  params.marginAccountId,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  getCurrentTimestampInSeconds,
3
3
  getSocketConnectors,
4
- getSocketController,
5
4
  scale,
6
- getTokenDetails,
7
5
  ReyaChainId,
6
+ getTokenInfoByAddress,
7
+ getTokenInfoByName,
8
8
  } from '@reyaxyz/common';
9
- import { ContractType } from '../../utils/contractAddresses';
9
+ import { ContractType, getAddress } from '../../utils/contractAddresses';
10
10
  import { executeTransaction } from '../executeTransaction';
11
11
  import { signCoreCommands } from '../sign';
12
12
  import { encodeWithdrawMAAndBridge } from './encode';
@@ -15,45 +15,55 @@ import {
15
15
  WithdrawMAAndBridgeParamsResult,
16
16
  } from './types';
17
17
  import { BRIDGE_DEADLINE_IN_SECONDS } from '../../utils/consts';
18
+ import { encodeSingleWithdraw } from '../encode';
19
+ import { MultiAction } from '../../utils/action';
18
20
 
19
21
  export const withdrawMAAndBridge = async ({
20
22
  signer,
21
23
  moneyInOutChainId,
22
24
  marginAccountId,
23
25
  owner,
24
- amount,
26
+ amount: unscaledAmount,
25
27
  tokenAddress,
26
28
  receiverAddress = owner.address,
27
29
  }: WithdrawMAAndBridgeParams): Promise<WithdrawMAAndBridgeParamsResult> => {
28
30
  const network = await signer.provider?.getNetwork();
29
31
  const reyaChainId: ReyaChainId = Number(network?.chainId);
32
+
33
+ const bridgeTokenInfo = getTokenInfoByAddress(tokenAddress);
34
+ const corePeripheryTokenInfo =
35
+ bridgeTokenInfo.name === 'USDC'
36
+ ? getTokenInfoByName('RUSD', reyaChainId)
37
+ : bridgeTokenInfo;
38
+
39
+ const multiAction = new MultiAction();
40
+ encodeSingleWithdraw(
41
+ corePeripheryTokenInfo.address,
42
+ scale(corePeripheryTokenInfo.decimals)(unscaledAmount),
43
+ multiAction,
44
+ );
30
45
  const eip712Signature = await signCoreCommands(
31
46
  signer,
32
47
  reyaChainId,
48
+ getAddress(reyaChainId, ContractType.PERIPHERY_PROXY),
33
49
  marginAccountId,
34
- owner.coreSigNonce,
50
+ multiAction.commands,
51
+ owner.coreSigNonce + 1,
35
52
  getCurrentTimestampInSeconds() + BRIDGE_DEADLINE_IN_SECONDS,
36
53
  );
37
54
 
38
- const { tokenName, tokenDecimals } = getTokenDetails(tokenAddress);
39
- const scaledAmount = scale(tokenDecimals)(amount);
40
-
41
55
  const socketConnectors = getSocketConnectors({
42
56
  moneyInOutChainId: moneyInOutChainId,
43
- tokenName: tokenName,
57
+ tokenName: bridgeTokenInfo.name,
44
58
  });
45
59
 
46
60
  const { calldata: data, value } = encodeWithdrawMAAndBridge(
47
61
  marginAccountId,
48
- tokenAddress,
49
- scaledAmount,
62
+ corePeripheryTokenInfo.address,
63
+ scale(corePeripheryTokenInfo.decimals)(unscaledAmount),
50
64
  eip712Signature,
51
65
  BigInt('10000000'),
52
66
  socketConnectors.deposit,
53
- getSocketController({
54
- reyaChainId: reyaChainId,
55
- tokenName: tokenName,
56
- }),
57
67
  receiverAddress,
58
68
  );
59
69
 
@@ -1,5 +1,7 @@
1
1
  import { JsonRpcSigner, Signature, Signer, TypedDataField } from 'ethers';
2
2
  import { ContractType, getAddress } from '../utils/contractAddresses';
3
+ import { Address, ReyaChainId } from '@reyaxyz/common';
4
+ import { Command } from '../utils/action';
3
5
 
4
6
  export type EIP712Signature = {
5
7
  v: number;
@@ -22,25 +24,37 @@ function convertEthersSignatureToEIP712Signature(
22
24
 
23
25
  export async function signCoreCommands(
24
26
  signer: Signer | JsonRpcSigner,
25
- chainId: number,
27
+ reyaChainId: ReyaChainId,
28
+ caller: Address,
26
29
  accountId: number,
30
+ commands: Command[],
27
31
  nonce: number,
28
32
  deadline: number,
29
- // todo: add caller/commands/both once smart contracts are fixed
30
33
  ): Promise<EIP712Signature> {
31
34
  const signature = await signReyaTypedData(
32
35
  signer,
33
- chainId,
34
- getAddress(chainId, ContractType.CORE_PROXY),
36
+ getAddress(reyaChainId, ContractType.CORE_PROXY),
35
37
  {
36
38
  ExecuteBySig: [
39
+ { name: 'verifyingChainId', type: 'uint256' },
40
+ { name: 'caller', type: 'address' },
37
41
  { name: 'accountId', type: 'uint128' },
42
+ { name: 'commands', type: 'Command[]' },
38
43
  { name: 'nonce', type: 'uint256' },
39
44
  { name: 'deadline', type: 'uint256' },
40
45
  ],
46
+ Command: [
47
+ { name: 'commandType', type: 'uint8' },
48
+ { name: 'inputs', type: 'bytes' },
49
+ { name: 'marketId', type: 'uint128' },
50
+ { name: 'exchangeId', type: 'uint128' },
51
+ ],
41
52
  },
42
53
  {
54
+ verifyingChainId: reyaChainId,
55
+ caller: caller,
43
56
  accountId: accountId,
57
+ commands: commands,
44
58
  nonce: nonce,
45
59
  deadline: deadline,
46
60
  },
@@ -51,21 +65,22 @@ export async function signCoreCommands(
51
65
 
52
66
  export async function signPoolRemoveLiquidity(
53
67
  signer: Signer | JsonRpcSigner,
54
- chainId: number,
55
- owner: string,
68
+ reyaChainId: ReyaChainId,
69
+ caller: Address,
70
+ owner: Address,
56
71
  poolId: number,
57
72
  sharesAmount: bigint,
58
73
  minOut: bigint,
59
74
  nonce: number,
60
75
  deadline: number,
61
- // todo: add caller once smart contracts are fixed
62
76
  ): Promise<EIP712Signature> {
63
77
  const signature = await signReyaTypedData(
64
78
  signer,
65
- chainId,
66
- getAddress(chainId, ContractType.PASSIVE_POOL_PROXY),
79
+ getAddress(reyaChainId, ContractType.PASSIVE_POOL_PROXY),
67
80
  {
68
81
  RemoveLiquidityBySig: [
82
+ { name: 'verifyingChainId', type: 'uint256' },
83
+ { name: 'caller', type: 'address' },
69
84
  { name: 'owner', type: 'address' },
70
85
  { name: 'poolId', type: 'uint128' },
71
86
  { name: 'sharesAmount', type: 'uint256' },
@@ -75,6 +90,8 @@ export async function signPoolRemoveLiquidity(
75
90
  ],
76
91
  },
77
92
  {
93
+ verifyingChainId: reyaChainId,
94
+ caller: caller,
78
95
  owner: owner,
79
96
  poolId: poolId,
80
97
  sharesAmount: sharesAmount,
@@ -89,22 +106,18 @@ export async function signPoolRemoveLiquidity(
89
106
 
90
107
  async function signReyaTypedData(
91
108
  signer: Signer | JsonRpcSigner,
92
- chainId: number,
93
109
  verifyingContract: string,
94
110
  types: Record<string, Array<TypedDataField>>,
95
111
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
112
  value: Record<string, any>,
97
113
  ): Promise<Signature> {
98
- const signatureString = await signer.signTypedData(
99
- {
100
- name: 'Reya',
101
- version: '1',
102
- chainId: chainId,
103
- verifyingContract: verifyingContract,
104
- },
105
- types,
106
- value,
107
- );
114
+ const domain = {
115
+ name: 'Reya',
116
+ version: '1',
117
+ verifyingContract: verifyingContract,
118
+ };
119
+
120
+ const signatureString = await signer.signTypedData(domain, types, value);
108
121
 
109
122
  return Signature.from(signatureString);
110
123
  }
@@ -1,5 +1,11 @@
1
1
  import { ApprovalType, ApproveTokenParams } from './types';
2
- import { getERC20Allowance, getERC20TokenContract } from '@reyaxyz/common';
2
+ import {
3
+ getERC20Allowance,
4
+ getERC20TokenContract,
5
+ getSocketVault,
6
+ GetSocketVaultParams,
7
+ getTokenInfoByAddress,
8
+ } from '@reyaxyz/common';
3
9
  import { ContractType, getAddress } from '../../utils/contractAddresses';
4
10
 
5
11
  export const approveTokenSpending = async (
@@ -15,10 +21,28 @@ export const approveTokenSpending = async (
15
21
  params.signer,
16
22
  );
17
23
 
18
- const contractProxyAddress =
19
- params.type === ApprovalType.DEPOSIT
20
- ? getAddress(chainId, ContractType.CORE_PROXY)
21
- : getAddress(chainId, ContractType.PASSIVE_POOL_PROXY);
24
+ const tokenInfo = getTokenInfoByAddress(underLyingTokenAddress);
25
+
26
+ let contractProxyAddress;
27
+ switch (params.type) {
28
+ case ApprovalType.DEPOSIT:
29
+ contractProxyAddress = getAddress(chainId, ContractType.CORE_PROXY);
30
+ break;
31
+ case ApprovalType.LP:
32
+ contractProxyAddress = getAddress(
33
+ chainId,
34
+ ContractType.PASSIVE_POOL_PROXY,
35
+ );
36
+ break;
37
+ case ApprovalType.BRIDGE:
38
+ contractProxyAddress = getSocketVault({
39
+ moneyInOutChainId: chainId,
40
+ tokenName: tokenInfo.name,
41
+ } as GetSocketVaultParams);
42
+ break;
43
+ default:
44
+ throw new Error('Unexpected approval type in approveTokenSpending');
45
+ }
22
46
 
23
47
  // @todo validate if maxAllowance should be passed from UI
24
48
  const maxUint256Bn = BigInt(
@@ -32,7 +56,6 @@ export const approveTokenSpending = async (
32
56
  console.error(error);
33
57
  throw new Error('Transaction Confirmation Error');
34
58
  });
35
-
36
59
  try {
37
60
  await approvalTransaction.wait();
38
61
  } catch (error) {