@reyaxyz/sdk 0.146.7 → 0.147.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/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/services/lp/encode.js +1 -31
- package/dist/services/lp/encode.js.map +1 -1
- package/dist/services/lp/index.js +0 -2
- package/dist/services/lp/index.js.map +1 -1
- package/dist/services/lp/types.js.map +1 -1
- package/dist/services/margin-accounts/account.js +3 -0
- package/dist/services/margin-accounts/account.js.map +1 -1
- package/dist/services/margin-accounts/bridgeAndDepositExistingMA.js +3 -0
- package/dist/services/margin-accounts/bridgeAndDepositExistingMA.js.map +1 -1
- package/dist/services/margin-accounts/encode.js +1 -93
- package/dist/services/margin-accounts/encode.js.map +1 -1
- package/dist/services/margin-accounts/index.js +0 -2
- package/dist/services/margin-accounts/index.js.map +1 -1
- package/dist/services/margin-accounts/transferMarginBetweenAccounts.js +3 -0
- package/dist/services/margin-accounts/transferMarginBetweenAccounts.js.map +1 -1
- package/dist/services/margin-accounts/types.js.map +1 -1
- package/dist/services/margin-accounts/withdrawMAAndBridge.js +3 -0
- package/dist/services/margin-accounts/withdrawMAAndBridge.js.map +1 -1
- package/dist/services/{lp/stakeReya.js → margin-accounts-v2/createAccount.js} +21 -23
- package/dist/services/margin-accounts-v2/createAccount.js.map +1 -0
- package/dist/services/margin-accounts-v2/deposit/index.js +12 -0
- package/dist/services/margin-accounts-v2/deposit/index.js.map +1 -0
- package/dist/services/margin-accounts-v2/deposit/lz/estimateFeeLzBridgeAndDepositMA.js +71 -0
- package/dist/services/margin-accounts-v2/deposit/lz/estimateFeeLzBridgeAndDepositMA.js.map +1 -0
- package/dist/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.js +91 -0
- package/dist/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.js.map +1 -0
- package/dist/services/margin-accounts-v2/deposit/socket/estimateFeeSocketBridgeAndDepositMA.js +62 -0
- package/dist/services/margin-accounts-v2/deposit/socket/estimateFeeSocketBridgeAndDepositMA.js.map +1 -0
- package/dist/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.js +82 -0
- package/dist/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.js.map +1 -0
- package/dist/services/margin-accounts-v2/erc20/approve.erc20.js +72 -0
- package/dist/services/margin-accounts-v2/erc20/approve.erc20.js.map +1 -0
- package/dist/services/margin-accounts-v2/erc20/getAllowance.erc20.js +64 -0
- package/dist/services/margin-accounts-v2/erc20/getAllowance.erc20.js.map +1 -0
- package/dist/services/margin-accounts-v2/erc20/getBalance.erc20.js +62 -0
- package/dist/services/margin-accounts-v2/erc20/getBalance.erc20.js.map +1 -0
- package/dist/services/margin-accounts-v2/erc20/index.js +10 -0
- package/dist/services/margin-accounts-v2/erc20/index.js.map +1 -0
- package/dist/services/margin-accounts-v2/index.js +23 -0
- package/dist/services/margin-accounts-v2/index.js.map +1 -0
- package/dist/services/{lp/unstakeStakedReya.js → margin-accounts-v2/transferMarginBetweenAccounts.js} +40 -21
- package/dist/services/margin-accounts-v2/transferMarginBetweenAccounts.js.map +1 -0
- package/dist/services/margin-accounts-v2/types.js +3 -0
- package/dist/services/margin-accounts-v2/types.js.map +1 -0
- package/dist/services/margin-accounts-v2/withdraw/index.js +8 -0
- package/dist/services/margin-accounts-v2/withdraw/index.js.map +1 -0
- package/dist/services/margin-accounts-v2/withdraw/lz/withdrawMAAndLzBridge.js +94 -0
- package/dist/services/margin-accounts-v2/withdraw/lz/withdrawMAAndLzBridge.js.map +1 -0
- package/dist/services/margin-accounts-v2/withdraw/socket/withdrawMAAndSocketBridge.js +95 -0
- package/dist/services/margin-accounts-v2/withdraw/socket/withdrawMAAndSocketBridge.js.map +1 -0
- package/dist/services/token/getBalanceByTokenAddress.js +1 -23
- package/dist/services/token/getBalanceByTokenAddress.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/lp/encode.d.ts +0 -2
- package/dist/types/services/lp/encode.d.ts.map +1 -1
- package/dist/types/services/lp/index.d.ts +0 -2
- package/dist/types/services/lp/index.d.ts.map +1 -1
- package/dist/types/services/lp/types.d.ts +0 -22
- package/dist/types/services/lp/types.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/account.d.ts +3 -0
- package/dist/types/services/margin-accounts/account.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/bridgeAndDepositExistingMA.d.ts +3 -0
- package/dist/types/services/margin-accounts/bridgeAndDepositExistingMA.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/encode.d.ts +1 -12
- package/dist/types/services/margin-accounts/encode.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/index.d.ts +0 -2
- package/dist/types/services/margin-accounts/index.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/transferMarginBetweenAccounts.d.ts +3 -0
- package/dist/types/services/margin-accounts/transferMarginBetweenAccounts.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/types.d.ts +0 -12
- package/dist/types/services/margin-accounts/types.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/withdrawMAAndBridge.d.ts +3 -0
- package/dist/types/services/margin-accounts/withdrawMAAndBridge.d.ts.map +1 -1
- package/dist/types/services/margin-accounts-v2/createAccount.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/createAccount.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/deposit/index.d.ts +5 -0
- package/dist/types/services/margin-accounts-v2/deposit/index.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/deposit/lz/estimateFeeLzBridgeAndDepositMA.d.ts +4 -0
- package/dist/types/services/margin-accounts-v2/deposit/lz/estimateFeeLzBridgeAndDepositMA.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/deposit/socket/estimateFeeSocketBridgeAndDepositMA.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/deposit/socket/estimateFeeSocketBridgeAndDepositMA.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/erc20/approve.erc20.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/erc20/approve.erc20.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/erc20/getAllowance.erc20.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/erc20/getAllowance.erc20.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/erc20/getBalance.erc20.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/erc20/getBalance.erc20.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/erc20/index.d.ts +4 -0
- package/dist/types/services/margin-accounts-v2/erc20/index.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/index.d.ts +7 -0
- package/dist/types/services/margin-accounts-v2/index.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/transferMarginBetweenAccounts.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/transferMarginBetweenAccounts.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/types.d.ts +121 -0
- package/dist/types/services/margin-accounts-v2/types.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/withdraw/index.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/withdraw/index.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/withdraw/lz/withdrawMAAndLzBridge.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/withdraw/lz/withdrawMAAndLzBridge.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/withdraw/socket/withdrawMAAndSocketBridge.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/withdraw/socket/withdrawMAAndSocketBridge.d.ts.map +1 -0
- package/dist/types/services/token/getBalanceByTokenAddress.d.ts +1 -2
- package/dist/types/services/token/getBalanceByTokenAddress.d.ts.map +1 -1
- package/dist/types/utils/checkChainId.d.ts +3 -0
- package/dist/types/utils/checkChainId.d.ts.map +1 -0
- package/dist/types/utils/network.d.ts +2 -1
- package/dist/types/utils/network.d.ts.map +1 -1
- package/dist/utils/checkChainId.js +59 -0
- package/dist/utils/checkChainId.js.map +1 -0
- package/dist/utils/network.js +6 -1
- package/dist/utils/network.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/services/lp/encode.ts +0 -40
- package/src/services/lp/index.ts +0 -2
- package/src/services/lp/types.ts +0 -26
- package/src/services/margin-accounts/account.ts +3 -1
- package/src/services/margin-accounts/bridgeAndDepositExistingMA.ts +3 -0
- package/src/services/margin-accounts/encode.ts +1 -151
- package/src/services/margin-accounts/index.ts +0 -2
- package/src/services/margin-accounts/transferMarginBetweenAccounts.ts +3 -0
- package/src/services/margin-accounts/types.ts +0 -16
- package/src/services/margin-accounts/withdrawMAAndBridge.ts +3 -0
- package/src/services/margin-accounts-v2/createAccount.ts +35 -0
- package/src/services/margin-accounts-v2/deposit/index.ts +4 -0
- package/src/services/margin-accounts-v2/deposit/lz/estimateFeeLzBridgeAndDepositMA.ts +30 -0
- package/src/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.ts +57 -0
- package/src/services/margin-accounts-v2/deposit/socket/estimateFeeSocketBridgeAndDepositMA.ts +24 -0
- package/src/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.ts +59 -0
- package/src/services/margin-accounts-v2/erc20/approve.erc20.ts +38 -0
- package/src/services/margin-accounts-v2/erc20/getAllowance.erc20.ts +22 -0
- package/src/services/margin-accounts-v2/erc20/getBalance.erc20.ts +17 -0
- package/src/services/margin-accounts-v2/erc20/index.ts +3 -0
- package/src/services/margin-accounts-v2/index.ts +6 -0
- package/src/services/margin-accounts-v2/transferMarginBetweenAccounts.ts +75 -0
- package/src/services/margin-accounts-v2/types.ts +151 -0
- package/src/services/margin-accounts-v2/withdraw/index.ts +2 -0
- package/src/services/margin-accounts-v2/withdraw/lz/withdrawMAAndLzBridge.ts +81 -0
- package/src/services/margin-accounts-v2/withdraw/socket/withdrawMAAndSocketBridge.ts +83 -0
- package/src/services/token/getBalanceByTokenAddress.ts +0 -16
- package/src/utils/checkChainId.ts +16 -0
- package/src/utils/network.ts +10 -1
- package/dist/services/lp/stakeReya.js.map +0 -1
- package/dist/services/lp/unstakeStakedReya.js.map +0 -1
- package/dist/services/margin-accounts/oftBridgeAndDepositExistingMA.js +0 -102
- package/dist/services/margin-accounts/oftBridgeAndDepositExistingMA.js.map +0 -1
- package/dist/services/margin-accounts/oftWithdrawMAAndBridge.js +0 -89
- package/dist/services/margin-accounts/oftWithdrawMAAndBridge.js.map +0 -1
- package/dist/types/services/lp/stakeReya.d.ts +0 -3
- package/dist/types/services/lp/stakeReya.d.ts.map +0 -1
- package/dist/types/services/lp/unstakeStakedReya.d.ts +0 -3
- package/dist/types/services/lp/unstakeStakedReya.d.ts.map +0 -1
- package/dist/types/services/margin-accounts/oftBridgeAndDepositExistingMA.d.ts +0 -3
- package/dist/types/services/margin-accounts/oftBridgeAndDepositExistingMA.d.ts.map +0 -1
- package/dist/types/services/margin-accounts/oftWithdrawMAAndBridge.d.ts +0 -3
- package/dist/types/services/margin-accounts/oftWithdrawMAAndBridge.d.ts.map +0 -1
- package/src/services/lp/stakeReya.ts +0 -66
- package/src/services/lp/unstakeStakedReya.ts +0 -66
- package/src/services/margin-accounts/oftBridgeAndDepositExistingMA.ts +0 -112
- package/src/services/margin-accounts/oftWithdrawMAAndBridge.ts +0 -93
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
+
import { Address, OFTMessagingFee } from '@reyaxyz/common';
|
|
3
|
+
|
|
4
|
+
export type CreateAccountParamsV2 = {
|
|
5
|
+
ownerAddress: string;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type CreateAccountResultV2 = {
|
|
10
|
+
transactionHash: string | null;
|
|
11
|
+
accountId: number | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type TransferMAParamsV2 = {
|
|
15
|
+
collateralAddress: Address;
|
|
16
|
+
collateralDecimals: number;
|
|
17
|
+
signer: Signer | JsonRpcSigner;
|
|
18
|
+
coreSigNonce: number;
|
|
19
|
+
fromMarginAccountId: number;
|
|
20
|
+
toMarginAccountId: number;
|
|
21
|
+
amount: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type TransferMAResultV2 = {
|
|
25
|
+
transactionHash: string | null;
|
|
26
|
+
coreSigNonce: number | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type SocketBridgeAndDepositMAParamsV2 = {
|
|
30
|
+
collateralAddressInReyaPeriphery: Address;
|
|
31
|
+
collateralDecimals: number;
|
|
32
|
+
chainId: number;
|
|
33
|
+
bridgeFee: string;
|
|
34
|
+
vaultAddress: Address;
|
|
35
|
+
connectorAddress: Address;
|
|
36
|
+
msgGasLimit: string;
|
|
37
|
+
signer: Signer | JsonRpcSigner;
|
|
38
|
+
accountId: number;
|
|
39
|
+
amount: number;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type SocketBridgeAndDepositMAResultV2 = {
|
|
43
|
+
transactionHash: string | null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type LzBridgeAndDepositMAParamsV2 = {
|
|
47
|
+
collateralAddress: Address;
|
|
48
|
+
collateralDecimals: number;
|
|
49
|
+
collateralAddressInReyaPeriphery: Address;
|
|
50
|
+
chainId: number;
|
|
51
|
+
dstEid: number;
|
|
52
|
+
bridgeFee: OFTMessagingFee;
|
|
53
|
+
extraOptions: string;
|
|
54
|
+
signer: Signer | JsonRpcSigner;
|
|
55
|
+
marginAccountId: number;
|
|
56
|
+
amount: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type LzBridgeAndDepositMAResultV2 = {
|
|
60
|
+
transactionHash: string | null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type EstimateFeeLzBridgeAndDepositMAParamsV2 = Pick<
|
|
64
|
+
LzBridgeAndDepositMAParamsV2,
|
|
65
|
+
| 'collateralAddress'
|
|
66
|
+
| 'collateralDecimals'
|
|
67
|
+
| 'collateralAddressInReyaPeriphery'
|
|
68
|
+
| 'chainId'
|
|
69
|
+
| 'dstEid'
|
|
70
|
+
| 'extraOptions'
|
|
71
|
+
> & {
|
|
72
|
+
signer: Signer | JsonRpcSigner;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type EstimateFeeSocketBridgeAndDepositMAParamsV2 = Pick<
|
|
76
|
+
SocketBridgeAndDepositMAParamsV2,
|
|
77
|
+
'vaultAddress' | 'connectorAddress' | 'msgGasLimit' | 'chainId'
|
|
78
|
+
> & {
|
|
79
|
+
signer: Signer | JsonRpcSigner;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type WithdrawMAAndSocketBridgeParamsV2 = {
|
|
83
|
+
collateralAddressInReyaCore: Address;
|
|
84
|
+
collateralDecimals: number;
|
|
85
|
+
destinationChainId: number;
|
|
86
|
+
msgGasLimit: string;
|
|
87
|
+
signer: Signer | JsonRpcSigner;
|
|
88
|
+
coreSigNonce: number;
|
|
89
|
+
marginAccountId: number;
|
|
90
|
+
amount: number;
|
|
91
|
+
receiverAddress: Address;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type WithdrawMAAndSocketBridgeResultV2 = {
|
|
95
|
+
transactionHash: string | null;
|
|
96
|
+
coreSigNonce: number | null;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type WithdrawMAAndLzBridgeParamsV2 = {
|
|
100
|
+
collateralAddressInReyaCore: Address;
|
|
101
|
+
collateralDecimals: number;
|
|
102
|
+
dstEid: number;
|
|
103
|
+
signer: Signer | JsonRpcSigner;
|
|
104
|
+
coreSigNonce: number;
|
|
105
|
+
marginAccountId: number;
|
|
106
|
+
amount: number;
|
|
107
|
+
receiverAddress: Address;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type WithdrawMAAndLzBridgeResultV2 = {
|
|
111
|
+
transactionHash: string | null;
|
|
112
|
+
coreSigNonce: number | null;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export type Erc20ApproveParamsV2 = {
|
|
116
|
+
collateralAddress: Address;
|
|
117
|
+
collateralDecimals: number;
|
|
118
|
+
spenderAddress: Address;
|
|
119
|
+
chainId: number;
|
|
120
|
+
signer: Signer | JsonRpcSigner;
|
|
121
|
+
amount: number;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export type Erc20ApproveResultV2 = {
|
|
125
|
+
transactionHash: string | null;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export type Erc20GetAllowanceParamsV2 = {
|
|
129
|
+
signer: Signer | JsonRpcSigner;
|
|
130
|
+
collateralAddress: Address;
|
|
131
|
+
collateralDecimals: number;
|
|
132
|
+
walletAddress: Address;
|
|
133
|
+
spenderAddress: Address;
|
|
134
|
+
chainId: number;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type Erc20GetAllowanceResultV2 = {
|
|
138
|
+
allowance: number;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type Erc20GetBalanceParamsV2 = {
|
|
142
|
+
signer: Signer | JsonRpcSigner;
|
|
143
|
+
collateralAddress: Address;
|
|
144
|
+
collateralDecimals: number;
|
|
145
|
+
chainId: number;
|
|
146
|
+
walletAddress: Address;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export type Erc20GetBalanceResultV2 = {
|
|
150
|
+
balance: number;
|
|
151
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommandType,
|
|
3
|
+
getCommand,
|
|
4
|
+
getCurrentTimestampInSeconds,
|
|
5
|
+
PeripheryAbi,
|
|
6
|
+
scaleV2,
|
|
7
|
+
BRIDGE_DEADLINE_IN_SECONDS,
|
|
8
|
+
signCoreCommands,
|
|
9
|
+
ContractType,
|
|
10
|
+
} from '@reyaxyz/common';
|
|
11
|
+
import { signAndBroadcastTransaction } from '../../../signAndBroadcastTransaction';
|
|
12
|
+
import {
|
|
13
|
+
WithdrawMAAndLzBridgeParamsV2,
|
|
14
|
+
WithdrawMAAndLzBridgeResultV2,
|
|
15
|
+
} from '../../types';
|
|
16
|
+
import { ethers, Interface } from 'ethers';
|
|
17
|
+
import { getPeripheryAddress, getReyaNetwork } from '../../../../utils/network';
|
|
18
|
+
|
|
19
|
+
const getCalldata = async (
|
|
20
|
+
params: WithdrawMAAndLzBridgeParamsV2,
|
|
21
|
+
): Promise<string> => {
|
|
22
|
+
const amount = scaleV2(params.collateralDecimals)(params.amount);
|
|
23
|
+
const reyaChainId = getReyaNetwork();
|
|
24
|
+
|
|
25
|
+
const { command } = getCommand(
|
|
26
|
+
CommandType.WITHDRAW,
|
|
27
|
+
[params.collateralAddressInReyaCore, amount],
|
|
28
|
+
0,
|
|
29
|
+
0,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const { signature: eip712Signature } = await signCoreCommands(
|
|
33
|
+
params.signer,
|
|
34
|
+
reyaChainId,
|
|
35
|
+
getPeripheryAddress(),
|
|
36
|
+
params.marginAccountId,
|
|
37
|
+
[command],
|
|
38
|
+
params.coreSigNonce + 1,
|
|
39
|
+
getCurrentTimestampInSeconds() + BRIDGE_DEADLINE_IN_SECONDS,
|
|
40
|
+
ethers.AbiCoder.defaultAbiCoder().encode(
|
|
41
|
+
['string', 'address', 'uint32'],
|
|
42
|
+
['withdrawMALZ', params.receiverAddress, params.dstEid],
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const functionSignature = 'withdrawMALZ';
|
|
47
|
+
const parameters = [
|
|
48
|
+
{
|
|
49
|
+
accountId: params.marginAccountId,
|
|
50
|
+
token: params.collateralAddressInReyaCore,
|
|
51
|
+
tokenAmount: amount,
|
|
52
|
+
sig: eip712Signature,
|
|
53
|
+
dstEid: params.dstEid,
|
|
54
|
+
receiver: params.receiverAddress,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const INTERFACE = new Interface(PeripheryAbi);
|
|
58
|
+
const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
|
|
59
|
+
return calldata;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const withdrawMAAndLzBridgeV2 = async (
|
|
63
|
+
params: WithdrawMAAndLzBridgeParamsV2,
|
|
64
|
+
): Promise<WithdrawMAAndLzBridgeResultV2> => {
|
|
65
|
+
const reyaChainId = getReyaNetwork();
|
|
66
|
+
|
|
67
|
+
const calldata = await getCalldata(params);
|
|
68
|
+
const result = await signAndBroadcastTransaction(
|
|
69
|
+
calldata,
|
|
70
|
+
reyaChainId,
|
|
71
|
+
ContractType.PERIPHERY_PROXY,
|
|
72
|
+
{
|
|
73
|
+
destinationType: 'account',
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
transactionHash: result?.txHash || null,
|
|
79
|
+
coreSigNonce: Number(result?.coreSigNonce) || null,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentTimestampInSeconds,
|
|
3
|
+
scaleV2,
|
|
4
|
+
PeripheryAbi,
|
|
5
|
+
getCommand,
|
|
6
|
+
CommandType,
|
|
7
|
+
signCoreCommands,
|
|
8
|
+
BRIDGE_DEADLINE_IN_SECONDS,
|
|
9
|
+
ContractType,
|
|
10
|
+
} from '@reyaxyz/common';
|
|
11
|
+
import { signAndBroadcastTransaction } from '../../../signAndBroadcastTransaction';
|
|
12
|
+
import {
|
|
13
|
+
WithdrawMAAndSocketBridgeParamsV2,
|
|
14
|
+
WithdrawMAAndSocketBridgeResultV2,
|
|
15
|
+
} from '../../types';
|
|
16
|
+
import { ethers, Interface } from 'ethers';
|
|
17
|
+
import { getPeripheryAddress, getReyaNetwork } from '../../../../utils/network';
|
|
18
|
+
|
|
19
|
+
const getCalldata = async (
|
|
20
|
+
params: WithdrawMAAndSocketBridgeParamsV2,
|
|
21
|
+
): Promise<string> => {
|
|
22
|
+
const amount = scaleV2(params.collateralDecimals)(params.amount);
|
|
23
|
+
const reyaChainId = getReyaNetwork();
|
|
24
|
+
|
|
25
|
+
const { command } = getCommand(
|
|
26
|
+
CommandType.WITHDRAW,
|
|
27
|
+
[params.collateralAddressInReyaCore, amount],
|
|
28
|
+
0,
|
|
29
|
+
0,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const { signature: eip712Signature } = await signCoreCommands(
|
|
33
|
+
params.signer,
|
|
34
|
+
reyaChainId,
|
|
35
|
+
getPeripheryAddress(),
|
|
36
|
+
params.marginAccountId,
|
|
37
|
+
[command],
|
|
38
|
+
params.coreSigNonce + 1,
|
|
39
|
+
getCurrentTimestampInSeconds() + BRIDGE_DEADLINE_IN_SECONDS,
|
|
40
|
+
ethers.AbiCoder.defaultAbiCoder().encode(
|
|
41
|
+
['address', 'uint256', 'uint256'],
|
|
42
|
+
[params.receiverAddress, params.destinationChainId, params.msgGasLimit],
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const functionSignature = 'withdrawMA';
|
|
47
|
+
const parameters = [
|
|
48
|
+
{
|
|
49
|
+
accountId: params.marginAccountId,
|
|
50
|
+
token: params.collateralAddressInReyaCore,
|
|
51
|
+
tokenAmount: amount,
|
|
52
|
+
sig: eip712Signature,
|
|
53
|
+
socketMsgGasLimit: params.msgGasLimit,
|
|
54
|
+
chainId: params.destinationChainId,
|
|
55
|
+
receiver: params.receiverAddress,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
const INTERFACE = new Interface(PeripheryAbi);
|
|
59
|
+
const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
|
|
60
|
+
|
|
61
|
+
return calldata;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const withdrawMAAndSocketBridgeV2 = async (
|
|
65
|
+
params: WithdrawMAAndSocketBridgeParamsV2,
|
|
66
|
+
): Promise<WithdrawMAAndSocketBridgeResultV2> => {
|
|
67
|
+
const reyaChainId = getReyaNetwork();
|
|
68
|
+
|
|
69
|
+
const calldata = await getCalldata(params);
|
|
70
|
+
const result = await signAndBroadcastTransaction(
|
|
71
|
+
calldata,
|
|
72
|
+
reyaChainId,
|
|
73
|
+
ContractType.PERIPHERY_PROXY,
|
|
74
|
+
{
|
|
75
|
+
destinationType: 'account',
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
transactionHash: result?.txHash || null,
|
|
81
|
+
coreSigNonce: Number(result?.coreSigNonce) || null,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
GetBalanceByTokenAddressParams,
|
|
3
2
|
GetBalancesForBridgeLPResult,
|
|
4
3
|
GetBalancesForBridgeLPV2Result,
|
|
5
4
|
GetBalancesForBridgeMAResult,
|
|
@@ -8,13 +7,11 @@ import {
|
|
|
8
7
|
MABalanceInfo,
|
|
9
8
|
} from './types';
|
|
10
9
|
import {
|
|
11
|
-
getERC20Balance,
|
|
12
10
|
GetBalancesForBridgeArgs,
|
|
13
11
|
getRUSDUnderlyingTokenInfo,
|
|
14
12
|
MoneyInOutChainId,
|
|
15
13
|
getTokenInfosByChain,
|
|
16
14
|
getERC20BalanceBatch,
|
|
17
|
-
getTokenInfoByAddress,
|
|
18
15
|
ReyaChainId,
|
|
19
16
|
getTokenInfoByName,
|
|
20
17
|
TokenName,
|
|
@@ -23,19 +20,6 @@ import {
|
|
|
23
20
|
} from '@reyaxyz/common';
|
|
24
21
|
import { getReyaNetwork } from '../../utils/network';
|
|
25
22
|
|
|
26
|
-
export const getBalanceByTokenAddress = async ({
|
|
27
|
-
signer,
|
|
28
|
-
tokenAddress,
|
|
29
|
-
}: GetBalanceByTokenAddressParams): Promise<number> => {
|
|
30
|
-
const walletAddress = await signer.getAddress();
|
|
31
|
-
const tokenInfo = getTokenInfoByAddress(tokenAddress);
|
|
32
|
-
return await getERC20Balance({
|
|
33
|
-
walletAddress,
|
|
34
|
-
tokenDecimals: tokenInfo.decimals,
|
|
35
|
-
subject: signer,
|
|
36
|
-
tokenAddress: tokenAddress,
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
23
|
export const getBalancesForBridgeLP = async ({
|
|
40
24
|
walletAddress,
|
|
41
25
|
}: GetBalancesForBridgeArgs): Promise<GetBalancesForBridgeLPResult> => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
+
|
|
3
|
+
export const checkChainId = async (
|
|
4
|
+
signer: Signer | JsonRpcSigner,
|
|
5
|
+
expectedChainId: number,
|
|
6
|
+
): Promise<void> => {
|
|
7
|
+
if (!signer.provider) {
|
|
8
|
+
throw new Error('Signer has no provider');
|
|
9
|
+
}
|
|
10
|
+
const network = await signer.provider.getNetwork();
|
|
11
|
+
if (Number(network.chainId) !== expectedChainId) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Signer connected to chain ${network.chainId}, expected ${expectedChainId}`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
};
|
package/src/utils/network.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
ContractType,
|
|
4
|
+
getAddress,
|
|
5
|
+
ReyaChainId,
|
|
6
|
+
} from '@reyaxyz/common';
|
|
2
7
|
import { getSdkConfig } from '../config';
|
|
3
8
|
|
|
4
9
|
export const getReyaNetwork = (): ReyaChainId => {
|
|
5
10
|
return getSdkConfig().chain;
|
|
6
11
|
};
|
|
12
|
+
|
|
13
|
+
export const getPeripheryAddress = (): Address => {
|
|
14
|
+
return getAddress(getReyaNetwork(), ContractType.PERIPHERY_PROXY);
|
|
15
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stakeReya.js","sourceRoot":"/","sources":["services/lp/stakeReya.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAqD;AACrD,0CASyB;AACzB,oCAAiD;AACjD,mCAA2C;AAC3C,8EAA6E;AAC7E,iCAAgC;AAEzB,IAAM,SAAS,GAAG,UACvB,MAAuB;;;;;gBAEjB,OAAO,GAAG,IAAA,wBAAc,GAAE,CAAC;gBAE3B,aAAa,GAAG,IAAA,2BAAkB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACpD,cAAc,GAAG,IAAA,2BAAkB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBACtD,WAAW,GAAG,IAAA,cAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3D,cAAc,GAAG,MAAM,CAAC,cAAc;oBAC1C,CAAC,CAAC,IAAA,cAAK,EAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;oBACvD,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAER,WAAW,GAAG,IAAI,oBAAW,EAAE,CAAC;gBACtC,IAAA,6BAAoB,EAAC,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;gBAEnC,qBAAM,IAAA,yBAAgB,EACvD,MAAM,CAAC,MAAM,EACb,OAAO,EACP,IAAA,mBAAU,EAAC,OAAO,EAAE,qBAAY,CAAC,eAAe,CAAC,EACjD,MAAM,CAAC,eAAe,EACtB,WAAW,CAAC,QAAQ,EACpB,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,EAC7B,IAAA,qCAA4B,GAAE,GAAG,iCAAwB,EACzD,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACtC,CAAC,QAAQ,EAAE,SAAS,CAAC,EACrB,CAAC,WAAW,EAAE,cAAc,CAAC,CAC9B,CACF,EAAA;;gBAZkB,WAAW,GAAK,CAAA,SAYlC,CAAA,UAZ6B;gBAcZ,IAAI,GAAK,IAAA,wBAAe,EACxC,MAAM,CAAC,eAAe,EACtB,WAAW,EACX,cAAc,EACd,WAAW,CACZ,SALqB,CAKpB;gBAEa,qBAAM,IAAA,yDAA2B,EAC9C,IAAI,EACJ,OAAO,EACP,qBAAY,CAAC,eAAe,EAC5B,EAAE,CACH,EAAA;;gBALK,MAAM,GAAG,SAKd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;wBACvC,YAAY,EACV,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,KAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI;qBACpE,EAAC;;;KACH,CAAC;AAhDW,QAAA,SAAS,aAgDpB","sourcesContent":["import { StakeReyaParams, StakeReyaResult } from './types';\nimport { getReyaNetwork } from '../../utils/network';\nimport {\n scale,\n getTokenInfoByName,\n ContractType,\n getAddress,\n signCoreCommands,\n getCurrentTimestampInSeconds,\n CORE_DEADLINE_IN_SECONDS,\n MultiAction,\n} from '@reyaxyz/common';\nimport { encodeSingleWithdraw } from '../encode';\nimport { encodeStakeReya } from './encode';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport { ethers } from 'ethers';\n\nexport const stakeReya = async (\n params: StakeReyaParams,\n): Promise<StakeReyaResult> => {\n const chainId = getReyaNetwork();\n\n const reyaTokenInfo = getTokenInfoByName('REYA', chainId);\n const sreyaTokenInfo = getTokenInfoByName('SREYA', chainId);\n const assetAmount = scale(reyaTokenInfo.decimals)(params.amount);\n const minShareAmount = params.minShareAmount\n ? scale(sreyaTokenInfo.decimals)(params.minShareAmount)\n : BigInt(0);\n\n const multiAction = new MultiAction();\n encodeSingleWithdraw(reyaTokenInfo.address, assetAmount, multiAction);\n\n const { signature: withdrawSig } = await signCoreCommands(\n params.signer,\n chainId,\n getAddress(chainId, ContractType.PERIPHERY_PROXY),\n params.marginAccountId,\n multiAction.commands,\n params.owner.coreSigNonce + 1,\n getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,\n ethers.AbiCoder.defaultAbiCoder().encode(\n ['string', 'uint256'],\n ['stakeReya', minShareAmount],\n ),\n );\n\n const { calldata: data } = encodeStakeReya(\n params.marginAccountId,\n assetAmount,\n minShareAmount,\n withdrawSig,\n );\n\n const result = await signAndBroadcastTransaction(\n data,\n chainId,\n ContractType.PERIPHERY_PROXY,\n {},\n );\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce:\n result?.coreSigNonce != null ? Number(result.coreSigNonce) : null,\n };\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unstakeStakedReya.js","sourceRoot":"/","sources":["services/lp/unstakeStakedReya.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAqD;AACrD,0CASyB;AACzB,oCAAiD;AACjD,mCAAmD;AACnD,8EAA6E;AAC7E,iCAAgC;AAEzB,IAAM,iBAAiB,GAAG,UAC/B,MAA+B;;;;;gBAEzB,OAAO,GAAG,IAAA,wBAAc,GAAE,CAAC;gBAE3B,cAAc,GAAG,IAAA,2BAAkB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBACtD,aAAa,GAAG,IAAA,2BAAkB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACpD,WAAW,GAAG,IAAA,cAAK,EAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;gBACjE,cAAc,GAAG,MAAM,CAAC,cAAc;oBAC1C,CAAC,CAAC,IAAA,cAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;oBACtD,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAER,WAAW,GAAG,IAAI,oBAAW,EAAE,CAAC;gBACtC,IAAA,6BAAoB,EAAC,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;gBAEpC,qBAAM,IAAA,yBAAgB,EACvD,MAAM,CAAC,MAAM,EACb,OAAO,EACP,IAAA,mBAAU,EAAC,OAAO,EAAE,qBAAY,CAAC,eAAe,CAAC,EACjD,MAAM,CAAC,eAAe,EACtB,WAAW,CAAC,QAAQ,EACpB,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,EAC7B,IAAA,qCAA4B,GAAE,GAAG,iCAAwB,EACzD,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACtC,CAAC,QAAQ,EAAE,SAAS,CAAC,EACrB,CAAC,mBAAmB,EAAE,cAAc,CAAC,CACtC,CACF,EAAA;;gBAZkB,WAAW,GAAK,CAAA,SAYlC,CAAA,UAZ6B;gBAcZ,IAAI,GAAK,IAAA,gCAAuB,EAChD,MAAM,CAAC,eAAe,EACtB,WAAW,EACX,cAAc,EACd,WAAW,CACZ,SALqB,CAKpB;gBAEa,qBAAM,IAAA,yDAA2B,EAC9C,IAAI,EACJ,OAAO,EACP,qBAAY,CAAC,eAAe,EAC5B,EAAE,CACH,EAAA;;gBALK,MAAM,GAAG,SAKd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;wBACvC,YAAY,EACV,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,KAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI;qBACpE,EAAC;;;KACH,CAAC;AAhDW,QAAA,iBAAiB,qBAgD5B","sourcesContent":["import { UnstakeStakedReyaParams, UnstakeStakedReyaResult } from './types';\nimport { getReyaNetwork } from '../../utils/network';\nimport {\n scale,\n getTokenInfoByName,\n ContractType,\n getAddress,\n signCoreCommands,\n getCurrentTimestampInSeconds,\n CORE_DEADLINE_IN_SECONDS,\n MultiAction,\n} from '@reyaxyz/common';\nimport { encodeSingleWithdraw } from '../encode';\nimport { encodeUnstakeStakedReya } from './encode';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport { ethers } from 'ethers';\n\nexport const unstakeStakedReya = async (\n params: UnstakeStakedReyaParams,\n): Promise<UnstakeStakedReyaResult> => {\n const chainId = getReyaNetwork();\n\n const sreyaTokenInfo = getTokenInfoByName('SREYA', chainId);\n const reyaTokenInfo = getTokenInfoByName('REYA', chainId);\n const shareAmount = scale(sreyaTokenInfo.decimals)(params.shareAmount);\n const minAssetAmount = params.minAssetAmount\n ? scale(reyaTokenInfo.decimals)(params.minAssetAmount)\n : BigInt(0);\n\n const multiAction = new MultiAction();\n encodeSingleWithdraw(sreyaTokenInfo.address, shareAmount, multiAction);\n\n const { signature: withdrawSig } = await signCoreCommands(\n params.signer,\n chainId,\n getAddress(chainId, ContractType.PERIPHERY_PROXY),\n params.marginAccountId,\n multiAction.commands,\n params.owner.coreSigNonce + 1,\n getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,\n ethers.AbiCoder.defaultAbiCoder().encode(\n ['string', 'uint256'],\n ['unstakeStakedReya', minAssetAmount],\n ),\n );\n\n const { calldata: data } = encodeUnstakeStakedReya(\n params.marginAccountId,\n shareAmount,\n minAssetAmount,\n withdrawSig,\n );\n\n const result = await signAndBroadcastTransaction(\n data,\n chainId,\n ContractType.PERIPHERY_PROXY,\n {},\n );\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce:\n result?.coreSigNonce != null ? Number(result.coreSigNonce) : null,\n };\n};\n"]}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.oftBridgeAndDepositExistingMA = void 0;
|
|
40
|
-
var common_1 = require("@reyaxyz/common");
|
|
41
|
-
var ethers_1 = require("ethers");
|
|
42
|
-
var encode_1 = require("./encode");
|
|
43
|
-
var oftBridgeAndDepositExistingMA = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
-
var moneyInOutChainId, _a, _b, reyaChainId, moneyInOutTokenInfo, reyaPeripheryTokenInfo, peripheryAddress, dstEid, amountLD, minAmountLD, sendParam, provider, oftContract, msgFee, messagingFee, callerAddress, _c, data, value, result;
|
|
45
|
-
var _d, _e, _f;
|
|
46
|
-
return __generator(this, function (_g) {
|
|
47
|
-
switch (_g.label) {
|
|
48
|
-
case 0:
|
|
49
|
-
if (!((_d = params.moneyInOutChainId) !== null && _d !== void 0)) return [3 /*break*/, 1];
|
|
50
|
-
_a = _d;
|
|
51
|
-
return [3 /*break*/, 3];
|
|
52
|
-
case 1:
|
|
53
|
-
_b = Number;
|
|
54
|
-
return [4 /*yield*/, ((_e = params.signer.provider) === null || _e === void 0 ? void 0 : _e.getNetwork())];
|
|
55
|
-
case 2:
|
|
56
|
-
_a = _b.apply(void 0, [(_f = (_g.sent())) === null || _f === void 0 ? void 0 : _f.chainId]);
|
|
57
|
-
_g.label = 3;
|
|
58
|
-
case 3:
|
|
59
|
-
moneyInOutChainId = _a;
|
|
60
|
-
reyaChainId = (0, common_1.getReyaNetworkFromMoneyInOutChainId)(moneyInOutChainId);
|
|
61
|
-
moneyInOutTokenInfo = (0, common_1.getTokenInfoByAddress)(params.tokenAddress, moneyInOutChainId);
|
|
62
|
-
if (!moneyInOutTokenInfo.isOFT) {
|
|
63
|
-
throw new Error("Token ".concat(moneyInOutTokenInfo.name, " at ").concat(params.tokenAddress, " is not an OFT token on chain ").concat(moneyInOutChainId));
|
|
64
|
-
}
|
|
65
|
-
reyaPeripheryTokenInfo = (0, common_1.getTokenInfoByName)(moneyInOutTokenInfo.name, reyaChainId);
|
|
66
|
-
peripheryAddress = (0, common_1.getAddress)(reyaChainId, common_1.ContractType.PERIPHERY_PROXY);
|
|
67
|
-
dstEid = (0, common_1.getLzEndpointId)(reyaChainId);
|
|
68
|
-
amountLD = (0, common_1.scale)(moneyInOutTokenInfo.decimals)(params.amount);
|
|
69
|
-
minAmountLD = amountLD;
|
|
70
|
-
sendParam = (0, encode_1.buildOFTBridgeAndDepositExistingMASendParam)(dstEid, peripheryAddress, params.marginAccountId, reyaPeripheryTokenInfo.address, amountLD, minAmountLD).sendParam;
|
|
71
|
-
provider = params.signer.provider;
|
|
72
|
-
if (!provider) {
|
|
73
|
-
throw new Error('Signer must have a provider to quote OFT messaging fees');
|
|
74
|
-
}
|
|
75
|
-
oftContract = new ethers_1.ethers.Contract(moneyInOutTokenInfo.address, common_1.OFTAbi, provider);
|
|
76
|
-
return [4 /*yield*/, oftContract.quoteSend.staticCall(sendParam, false)];
|
|
77
|
-
case 4:
|
|
78
|
-
msgFee = _g.sent();
|
|
79
|
-
messagingFee = {
|
|
80
|
-
nativeFee: msgFee.nativeFee,
|
|
81
|
-
lzTokenFee: msgFee.lzTokenFee,
|
|
82
|
-
};
|
|
83
|
-
return [4 /*yield*/, params.signer.getAddress()];
|
|
84
|
-
case 5:
|
|
85
|
-
callerAddress = _g.sent();
|
|
86
|
-
_c = (0, encode_1.encodeOFTBridgeAndDepositExistingMA)(dstEid, peripheryAddress, params.marginAccountId, reyaPeripheryTokenInfo.address, amountLD, minAmountLD, messagingFee, callerAddress), data = _c.calldata, value = _c.value;
|
|
87
|
-
return [4 /*yield*/, (0, common_1.executeTransaction)(params.signer, data, value, moneyInOutChainId, moneyInOutTokenInfo.address)];
|
|
88
|
-
case 6:
|
|
89
|
-
result = _g.sent();
|
|
90
|
-
if (!(result === null || result === void 0 ? void 0 : result.hash)) {
|
|
91
|
-
return [2 /*return*/, {
|
|
92
|
-
transactionHash: null,
|
|
93
|
-
}];
|
|
94
|
-
}
|
|
95
|
-
return [2 /*return*/, {
|
|
96
|
-
transactionHash: result === null || result === void 0 ? void 0 : result.hash,
|
|
97
|
-
}];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}); };
|
|
101
|
-
exports.oftBridgeAndDepositExistingMA = oftBridgeAndDepositExistingMA;
|
|
102
|
-
//# sourceMappingURL=oftBridgeAndDepositExistingMA.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oftBridgeAndDepositExistingMA.js","sourceRoot":"/","sources":["services/margin-accounts/oftBridgeAndDepositExistingMA.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAYyB;AACzB,iCAAgC;AAChC,mCAGkB;AAMX,IAAM,6BAA6B,GAAG,UAC3C,MAA2C;;;;;;4BAGzC,MAAM,CAAC,iBAAiB;;;;gBACxB,KAAA,MAAM,CAAA;gBAAE,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAAlD,KAAA,kBAAO,MAAA,CAAC,SAA0C,CAAC,0CAAE,OAAO,EAAC,CAAA;;;gBAFzD,iBAAiB,KAEwC;gBACzD,WAAW,GAAG,IAAA,4CAAmC,EAAC,iBAAiB,CAAC,CAAC;gBAErE,mBAAmB,GAAG,IAAA,8BAAqB,EAC/C,MAAM,CAAC,YAAY,EACnB,iBAAiB,CAClB,CAAC;gBAEF,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;oBAC/B,MAAM,IAAI,KAAK,CACb,gBAAS,mBAAmB,CAAC,IAAI,iBAAO,MAAM,CAAC,YAAY,2CAAiC,iBAAiB,CAAE,CAChH,CAAC;gBACJ,CAAC;gBAEK,sBAAsB,GAAG,IAAA,2BAAkB,EAC/C,mBAAmB,CAAC,IAAI,EACxB,WAAW,CACZ,CAAC;gBAEI,gBAAgB,GAAG,IAAA,mBAAU,EACjC,WAAW,EACX,qBAAY,CAAC,eAAe,CAC7B,CAAC;gBAEI,MAAM,GAAG,IAAA,wBAAe,EAAC,WAAW,CAAC,CAAC;gBACtC,QAAQ,GAAG,IAAA,cAAK,EAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC9D,WAAW,GAAG,QAAQ,CAAC;gBAErB,SAAS,GAAK,IAAA,oDAA2C,EAC/D,MAAM,EACN,gBAAgB,EAChB,MAAM,CAAC,eAAe,EACtB,sBAAsB,CAAC,OAAO,EAC9B,QAAQ,EACR,WAAW,CACZ,UAPgB,CAOf;gBAEI,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACxC,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACd,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;gBAC7E,CAAC;gBAEK,WAAW,GAAG,IAAI,eAAM,CAAC,QAAQ,CACrC,mBAAmB,CAAC,OAAO,EAC3B,eAAM,EACN,QAAQ,CACT,CAAC;gBAEa,qBAAM,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,EAAA;;gBAAjE,MAAM,GAAG,SAAwD;gBACjE,YAAY,GAAoB;oBACpC,SAAS,EAAE,MAAM,CAAC,SAAS;oBAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;iBAC9B,CAAC;gBAEoB,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAAhD,aAAa,GAAG,SAAgC;gBAChD,KAA4B,IAAA,4CAAmC,EACnE,MAAM,EACN,gBAAgB,EAChB,MAAM,CAAC,eAAe,EACtB,sBAAsB,CAAC,OAAO,EAC9B,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,aAAa,CACd,EATiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAS3B;gBAEa,qBAAM,IAAA,2BAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,iBAAiB,EACjB,mBAAmB,CAAC,OAAO,CAC5B,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAA,EAAE,CAAC;oBAClB,sBAAO;4BACL,eAAe,EAAE,IAAI;yBACtB,EAAC;gBACJ,CAAC;gBAED,sBAAO;wBACL,eAAe,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI;qBAC9B,EAAC;;;KACH,CAAC;AAxFW,QAAA,6BAA6B,iCAwFxC","sourcesContent":["import {\n scale,\n MoneyInOutChainId,\n getTokenInfoByAddress,\n getTokenInfoByName,\n getReyaNetworkFromMoneyInOutChainId,\n ContractType,\n getAddress,\n executeTransaction,\n getLzEndpointId,\n OFTMessagingFee,\n OFTAbi as OFTAbi,\n} from '@reyaxyz/common';\nimport { ethers } from 'ethers';\nimport {\n encodeOFTBridgeAndDepositExistingMA,\n buildOFTBridgeAndDepositExistingMASendParam,\n} from './encode';\nimport {\n OFTBridgeAndDepositExistingMAParams,\n OFTBridgeAndDepositExistingMAResult,\n} from './types';\n\nexport const oftBridgeAndDepositExistingMA = async (\n params: OFTBridgeAndDepositExistingMAParams,\n): Promise<OFTBridgeAndDepositExistingMAResult> => {\n const moneyInOutChainId: MoneyInOutChainId =\n params.moneyInOutChainId ??\n Number((await params.signer.provider?.getNetwork())?.chainId);\n const reyaChainId = getReyaNetworkFromMoneyInOutChainId(moneyInOutChainId);\n\n const moneyInOutTokenInfo = getTokenInfoByAddress(\n params.tokenAddress,\n moneyInOutChainId,\n );\n\n if (!moneyInOutTokenInfo.isOFT) {\n throw new Error(\n `Token ${moneyInOutTokenInfo.name} at ${params.tokenAddress} is not an OFT token on chain ${moneyInOutChainId}`,\n );\n }\n\n const reyaPeripheryTokenInfo = getTokenInfoByName(\n moneyInOutTokenInfo.name,\n reyaChainId,\n );\n\n const peripheryAddress = getAddress(\n reyaChainId,\n ContractType.PERIPHERY_PROXY,\n );\n\n const dstEid = getLzEndpointId(reyaChainId);\n const amountLD = scale(moneyInOutTokenInfo.decimals)(params.amount);\n const minAmountLD = amountLD;\n\n const { sendParam } = buildOFTBridgeAndDepositExistingMASendParam(\n dstEid,\n peripheryAddress,\n params.marginAccountId,\n reyaPeripheryTokenInfo.address,\n amountLD,\n minAmountLD,\n );\n\n const provider = params.signer.provider;\n if (!provider) {\n throw new Error('Signer must have a provider to quote OFT messaging fees');\n }\n\n const oftContract = new ethers.Contract(\n moneyInOutTokenInfo.address,\n OFTAbi,\n provider,\n );\n\n const msgFee = await oftContract.quoteSend.staticCall(sendParam, false);\n const messagingFee: OFTMessagingFee = {\n nativeFee: msgFee.nativeFee,\n lzTokenFee: msgFee.lzTokenFee,\n };\n\n const callerAddress = await params.signer.getAddress();\n const { calldata: data, value } = encodeOFTBridgeAndDepositExistingMA(\n dstEid,\n peripheryAddress,\n params.marginAccountId,\n reyaPeripheryTokenInfo.address,\n amountLD,\n minAmountLD,\n messagingFee,\n callerAddress,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n moneyInOutChainId,\n moneyInOutTokenInfo.address,\n );\n\n if (!result?.hash) {\n return {\n transactionHash: null,\n };\n }\n\n return {\n transactionHash: result?.hash,\n };\n};\n"]}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.oftWithdrawMAAndBridge = void 0;
|
|
40
|
-
var common_1 = require("@reyaxyz/common");
|
|
41
|
-
var common_2 = require("@reyaxyz/common");
|
|
42
|
-
var signAndBroadcastTransaction_1 = require("../signAndBroadcastTransaction");
|
|
43
|
-
var common_3 = require("@reyaxyz/common");
|
|
44
|
-
var encode_1 = require("./encode");
|
|
45
|
-
var common_4 = require("@reyaxyz/common");
|
|
46
|
-
var encode_2 = require("../encode");
|
|
47
|
-
var common_5 = require("@reyaxyz/common");
|
|
48
|
-
var ethers_1 = require("ethers");
|
|
49
|
-
var network_1 = require("../../utils/network");
|
|
50
|
-
var oftWithdrawMAAndBridge = function (_a) {
|
|
51
|
-
var signer = _a.signer, moneyInOutChainId = _a.moneyInOutChainId, marginAccountId = _a.marginAccountId, owner = _a.owner, unscaledAmount = _a.amount, tokenAddress = _a.tokenAddress, _b = _a.receiverAddress, receiverAddress = _b === void 0 ? owner.address : _b;
|
|
52
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
-
var reyaChainId, corePeripheryTokenInfo, multiAction, dstEid, eip712Signature, data, result;
|
|
54
|
-
return __generator(this, function (_c) {
|
|
55
|
-
switch (_c.label) {
|
|
56
|
-
case 0:
|
|
57
|
-
reyaChainId = (0, network_1.getReyaNetwork)();
|
|
58
|
-
corePeripheryTokenInfo = (0, common_1.getTokenInfoByAddress)(tokenAddress);
|
|
59
|
-
if (!corePeripheryTokenInfo.isOFT) {
|
|
60
|
-
throw new Error("Token ".concat(corePeripheryTokenInfo.name, " at ").concat(tokenAddress, " is not an OFT token"));
|
|
61
|
-
}
|
|
62
|
-
multiAction = new common_5.MultiAction();
|
|
63
|
-
(0, encode_2.encodeSingleWithdraw)(corePeripheryTokenInfo.address, (0, common_1.scale)(corePeripheryTokenInfo.decimals)(unscaledAmount), multiAction);
|
|
64
|
-
dstEid = (0, common_1.getLzEndpointId)(moneyInOutChainId);
|
|
65
|
-
return [4 /*yield*/, (0, common_3.signCoreCommands)(signer, reyaChainId, (0, common_2.getAddress)(reyaChainId, common_2.ContractType.PERIPHERY_PROXY), marginAccountId, multiAction.commands, owner.coreSigNonce + 1, (0, common_1.getCurrentTimestampInSeconds)() + common_4.BRIDGE_DEADLINE_IN_SECONDS, ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['string', 'address', 'uint32'], ['withdrawMALZ', receiverAddress, dstEid]))];
|
|
66
|
-
case 1:
|
|
67
|
-
eip712Signature = (_c.sent()).signature;
|
|
68
|
-
data = (0, encode_1.encodeWithdrawMALZ)(marginAccountId, corePeripheryTokenInfo.address, (0, common_1.scale)(corePeripheryTokenInfo.decimals)(unscaledAmount), eip712Signature, dstEid, receiverAddress).calldata;
|
|
69
|
-
return [4 /*yield*/, (0, signAndBroadcastTransaction_1.signAndBroadcastTransaction)(data, reyaChainId, common_2.ContractType.PERIPHERY_PROXY, {
|
|
70
|
-
destinationType: 'account',
|
|
71
|
-
})];
|
|
72
|
-
case 2:
|
|
73
|
-
result = _c.sent();
|
|
74
|
-
if (!(result === null || result === void 0 ? void 0 : result.txHash)) {
|
|
75
|
-
return [2 /*return*/, {
|
|
76
|
-
transactionHash: null,
|
|
77
|
-
coreSigNonce: null,
|
|
78
|
-
}];
|
|
79
|
-
}
|
|
80
|
-
return [2 /*return*/, {
|
|
81
|
-
transactionHash: (result === null || result === void 0 ? void 0 : result.txHash) || null,
|
|
82
|
-
coreSigNonce: (result === null || result === void 0 ? void 0 : result.coreSigNonce) != null ? Number(result.coreSigNonce) : null,
|
|
83
|
-
}];
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
exports.oftWithdrawMAAndBridge = oftWithdrawMAAndBridge;
|
|
89
|
-
//# sourceMappingURL=oftWithdrawMAAndBridge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oftWithdrawMAAndBridge.js","sourceRoot":"/","sources":["services/margin-accounts/oftWithdrawMAAndBridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AACzB,0CAA2D;AAC3D,8EAA6E;AAC7E,0CAAmD;AACnD,mCAA8C;AAK9C,0CAA6D;AAC7D,oCAAiD;AACjD,0CAA8C;AAC9C,iCAAgC;AAChC,+CAAqD;AAE9C,IAAM,sBAAsB,GAAG,UAAO,EAQd;QAP7B,MAAM,YAAA,EACN,iBAAiB,uBAAA,EACjB,eAAe,qBAAA,EACf,KAAK,WAAA,EACG,cAAc,YAAA,EACtB,YAAY,kBAAA,EACZ,uBAA+B,EAA/B,eAAe,mBAAG,KAAK,CAAC,OAAO,KAAA;;;;;;oBAEzB,WAAW,GAAG,IAAA,wBAAc,GAAE,CAAC;oBAE/B,sBAAsB,GAAG,IAAA,8BAAqB,EAAC,YAAY,CAAC,CAAC;oBAEnE,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAC;wBAClC,MAAM,IAAI,KAAK,CACb,gBAAS,sBAAsB,CAAC,IAAI,iBAAO,YAAY,yBAAsB,CAC9E,CAAC;oBACJ,CAAC;oBAEK,WAAW,GAAG,IAAI,oBAAW,EAAE,CAAC;oBACtC,IAAA,6BAAoB,EAClB,sBAAsB,CAAC,OAAO,EAC9B,IAAA,cAAK,EAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,EACtD,WAAW,CACZ,CAAC;oBAEI,MAAM,GAAG,IAAA,wBAAe,EAAC,iBAAiB,CAAC,CAAC;oBAEX,qBAAM,IAAA,yBAAgB,EAC3D,MAAM,EACN,WAAW,EACX,IAAA,mBAAU,EAAC,WAAW,EAAE,qBAAY,CAAC,eAAe,CAAC,EACrD,eAAe,EACf,WAAW,CAAC,QAAQ,EACpB,KAAK,CAAC,YAAY,GAAG,CAAC,EACtB,IAAA,qCAA4B,GAAE,GAAG,mCAA0B,EAC3D,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACtC,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,EAC/B,CAAC,cAAc,EAAE,eAAe,EAAE,MAAM,CAAC,CAC1C,CACF,EAAA;;oBAZkB,eAAe,GAAK,CAAA,SAYtC,CAAA,UAZiC;oBAchB,IAAI,GAAK,IAAA,2BAAkB,EAC3C,eAAe,EACf,sBAAsB,CAAC,OAAO,EAC9B,IAAA,cAAK,EAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,EACtD,eAAe,EACf,MAAM,EACN,eAAe,CAChB,SAPqB,CAOpB;oBAEa,qBAAM,IAAA,yDAA2B,EAC9C,IAAI,EACJ,WAAW,EACX,qBAAY,CAAC,eAAe,EAC5B;4BACE,eAAe,EAAE,SAAS;yBAC3B,CACF,EAAA;;oBAPK,MAAM,GAAG,SAOd;oBAED,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,CAAA,EAAE,CAAC;wBACpB,sBAAO;gCACL,eAAe,EAAE,IAAI;gCACrB,YAAY,EAAE,IAAI;6BACnB,EAAC;oBACJ,CAAC;oBAED,sBAAO;4BACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;4BACvC,YAAY,EACV,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,KAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI;yBACpE,EAAC;;;;CACH,CAAC;AAxEW,QAAA,sBAAsB,0BAwEjC","sourcesContent":["import {\n getCurrentTimestampInSeconds,\n scale,\n getTokenInfoByAddress,\n getLzEndpointId,\n} from '@reyaxyz/common';\nimport { ContractType, getAddress } from '@reyaxyz/common';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport { signCoreCommands } from '@reyaxyz/common';\nimport { encodeWithdrawMALZ } from './encode';\nimport {\n OFTWithdrawMAAndBridgeParams,\n OFTWithdrawMAAndBridgeResult,\n} from './types';\nimport { BRIDGE_DEADLINE_IN_SECONDS } from '@reyaxyz/common';\nimport { encodeSingleWithdraw } from '../encode';\nimport { MultiAction } from '@reyaxyz/common';\nimport { ethers } from 'ethers';\nimport { getReyaNetwork } from '../../utils/network';\n\nexport const oftWithdrawMAAndBridge = async ({\n signer,\n moneyInOutChainId,\n marginAccountId,\n owner,\n amount: unscaledAmount,\n tokenAddress,\n receiverAddress = owner.address,\n}: OFTWithdrawMAAndBridgeParams): Promise<OFTWithdrawMAAndBridgeResult> => {\n const reyaChainId = getReyaNetwork();\n\n const corePeripheryTokenInfo = getTokenInfoByAddress(tokenAddress);\n\n if (!corePeripheryTokenInfo.isOFT) {\n throw new Error(\n `Token ${corePeripheryTokenInfo.name} at ${tokenAddress} is not an OFT token`,\n );\n }\n\n const multiAction = new MultiAction();\n encodeSingleWithdraw(\n corePeripheryTokenInfo.address,\n scale(corePeripheryTokenInfo.decimals)(unscaledAmount),\n multiAction,\n );\n\n const dstEid = getLzEndpointId(moneyInOutChainId);\n\n const { signature: eip712Signature } = await signCoreCommands(\n signer,\n reyaChainId,\n getAddress(reyaChainId, ContractType.PERIPHERY_PROXY),\n marginAccountId,\n multiAction.commands,\n owner.coreSigNonce + 1,\n getCurrentTimestampInSeconds() + BRIDGE_DEADLINE_IN_SECONDS,\n ethers.AbiCoder.defaultAbiCoder().encode(\n ['string', 'address', 'uint32'],\n ['withdrawMALZ', receiverAddress, dstEid],\n ),\n );\n\n const { calldata: data } = encodeWithdrawMALZ(\n marginAccountId,\n corePeripheryTokenInfo.address,\n scale(corePeripheryTokenInfo.decimals)(unscaledAmount),\n eip712Signature,\n dstEid,\n receiverAddress,\n );\n\n const result = await signAndBroadcastTransaction(\n data,\n reyaChainId,\n ContractType.PERIPHERY_PROXY,\n {\n destinationType: 'account',\n },\n );\n\n if (!result?.txHash) {\n return {\n transactionHash: null,\n coreSigNonce: null,\n };\n }\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce:\n result?.coreSigNonce != null ? Number(result.coreSigNonce) : null,\n };\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stakeReya.d.ts","sourceRoot":"/","sources":["services/lp/stakeReya.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAiB3D,eAAO,MAAM,SAAS,WACZ,eAAe,KACtB,QAAQ,eAAe,CA8CzB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unstakeStakedReya.d.ts","sourceRoot":"/","sources":["services/lp/unstakeStakedReya.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAiB3E,eAAO,MAAM,iBAAiB,WACpB,uBAAuB,KAC9B,QAAQ,uBAAuB,CA8CjC,CAAC"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { OFTBridgeAndDepositExistingMAParams, OFTBridgeAndDepositExistingMAResult } from './types';
|
|
2
|
-
export declare const oftBridgeAndDepositExistingMA: (params: OFTBridgeAndDepositExistingMAParams) => Promise<OFTBridgeAndDepositExistingMAResult>;
|
|
3
|
-
//# sourceMappingURL=oftBridgeAndDepositExistingMA.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oftBridgeAndDepositExistingMA.d.ts","sourceRoot":"/","sources":["services/margin-accounts/oftBridgeAndDepositExistingMA.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,mCAAmC,EACnC,mCAAmC,EACpC,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,6BAA6B,WAChC,mCAAmC,KAC1C,QAAQ,mCAAmC,CAsF7C,CAAC"}
|