@reyaxyz/sdk 0.146.8 → 0.147.1
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 +4 -4
- 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
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { OFTWithdrawMAAndBridgeParams, OFTWithdrawMAAndBridgeResult } from './types';
|
|
2
|
-
export declare const oftWithdrawMAAndBridge: ({ signer, moneyInOutChainId, marginAccountId, owner, amount: unscaledAmount, tokenAddress, receiverAddress, }: OFTWithdrawMAAndBridgeParams) => Promise<OFTWithdrawMAAndBridgeResult>;
|
|
3
|
-
//# sourceMappingURL=oftWithdrawMAAndBridge.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oftWithdrawMAAndBridge.d.ts","sourceRoot":"/","sources":["services/margin-accounts/oftWithdrawMAAndBridge.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAOjB,eAAO,MAAM,sBAAsB,kHAQhC,4BAA4B,KAAG,QAAQ,4BAA4B,CAgErE,CAAC"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { StakeReyaParams, StakeReyaResult } from './types';
|
|
2
|
-
import { getReyaNetwork } from '../../utils/network';
|
|
3
|
-
import {
|
|
4
|
-
scale,
|
|
5
|
-
getTokenInfoByName,
|
|
6
|
-
ContractType,
|
|
7
|
-
getAddress,
|
|
8
|
-
signCoreCommands,
|
|
9
|
-
getCurrentTimestampInSeconds,
|
|
10
|
-
CORE_DEADLINE_IN_SECONDS,
|
|
11
|
-
MultiAction,
|
|
12
|
-
} from '@reyaxyz/common';
|
|
13
|
-
import { encodeSingleWithdraw } from '../encode';
|
|
14
|
-
import { encodeStakeReya } from './encode';
|
|
15
|
-
import { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';
|
|
16
|
-
import { ethers } from 'ethers';
|
|
17
|
-
|
|
18
|
-
export const stakeReya = async (
|
|
19
|
-
params: StakeReyaParams,
|
|
20
|
-
): Promise<StakeReyaResult> => {
|
|
21
|
-
const chainId = getReyaNetwork();
|
|
22
|
-
|
|
23
|
-
const reyaTokenInfo = getTokenInfoByName('REYA', chainId);
|
|
24
|
-
const sreyaTokenInfo = getTokenInfoByName('SREYA', chainId);
|
|
25
|
-
const assetAmount = scale(reyaTokenInfo.decimals)(params.amount);
|
|
26
|
-
const minShareAmount = params.minShareAmount
|
|
27
|
-
? scale(sreyaTokenInfo.decimals)(params.minShareAmount)
|
|
28
|
-
: BigInt(0);
|
|
29
|
-
|
|
30
|
-
const multiAction = new MultiAction();
|
|
31
|
-
encodeSingleWithdraw(reyaTokenInfo.address, assetAmount, multiAction);
|
|
32
|
-
|
|
33
|
-
const { signature: withdrawSig } = await signCoreCommands(
|
|
34
|
-
params.signer,
|
|
35
|
-
chainId,
|
|
36
|
-
getAddress(chainId, ContractType.PERIPHERY_PROXY),
|
|
37
|
-
params.marginAccountId,
|
|
38
|
-
multiAction.commands,
|
|
39
|
-
params.owner.coreSigNonce + 1,
|
|
40
|
-
getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,
|
|
41
|
-
ethers.AbiCoder.defaultAbiCoder().encode(
|
|
42
|
-
['string', 'uint256'],
|
|
43
|
-
['stakeReya', minShareAmount],
|
|
44
|
-
),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const { calldata: data } = encodeStakeReya(
|
|
48
|
-
params.marginAccountId,
|
|
49
|
-
assetAmount,
|
|
50
|
-
minShareAmount,
|
|
51
|
-
withdrawSig,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const result = await signAndBroadcastTransaction(
|
|
55
|
-
data,
|
|
56
|
-
chainId,
|
|
57
|
-
ContractType.PERIPHERY_PROXY,
|
|
58
|
-
{},
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
transactionHash: result?.txHash || null,
|
|
63
|
-
coreSigNonce:
|
|
64
|
-
result?.coreSigNonce != null ? Number(result.coreSigNonce) : null,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { UnstakeStakedReyaParams, UnstakeStakedReyaResult } from './types';
|
|
2
|
-
import { getReyaNetwork } from '../../utils/network';
|
|
3
|
-
import {
|
|
4
|
-
scale,
|
|
5
|
-
getTokenInfoByName,
|
|
6
|
-
ContractType,
|
|
7
|
-
getAddress,
|
|
8
|
-
signCoreCommands,
|
|
9
|
-
getCurrentTimestampInSeconds,
|
|
10
|
-
CORE_DEADLINE_IN_SECONDS,
|
|
11
|
-
MultiAction,
|
|
12
|
-
} from '@reyaxyz/common';
|
|
13
|
-
import { encodeSingleWithdraw } from '../encode';
|
|
14
|
-
import { encodeUnstakeStakedReya } from './encode';
|
|
15
|
-
import { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';
|
|
16
|
-
import { ethers } from 'ethers';
|
|
17
|
-
|
|
18
|
-
export const unstakeStakedReya = async (
|
|
19
|
-
params: UnstakeStakedReyaParams,
|
|
20
|
-
): Promise<UnstakeStakedReyaResult> => {
|
|
21
|
-
const chainId = getReyaNetwork();
|
|
22
|
-
|
|
23
|
-
const sreyaTokenInfo = getTokenInfoByName('SREYA', chainId);
|
|
24
|
-
const reyaTokenInfo = getTokenInfoByName('REYA', chainId);
|
|
25
|
-
const shareAmount = scale(sreyaTokenInfo.decimals)(params.shareAmount);
|
|
26
|
-
const minAssetAmount = params.minAssetAmount
|
|
27
|
-
? scale(reyaTokenInfo.decimals)(params.minAssetAmount)
|
|
28
|
-
: BigInt(0);
|
|
29
|
-
|
|
30
|
-
const multiAction = new MultiAction();
|
|
31
|
-
encodeSingleWithdraw(sreyaTokenInfo.address, shareAmount, multiAction);
|
|
32
|
-
|
|
33
|
-
const { signature: withdrawSig } = await signCoreCommands(
|
|
34
|
-
params.signer,
|
|
35
|
-
chainId,
|
|
36
|
-
getAddress(chainId, ContractType.PERIPHERY_PROXY),
|
|
37
|
-
params.marginAccountId,
|
|
38
|
-
multiAction.commands,
|
|
39
|
-
params.owner.coreSigNonce + 1,
|
|
40
|
-
getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,
|
|
41
|
-
ethers.AbiCoder.defaultAbiCoder().encode(
|
|
42
|
-
['string', 'uint256'],
|
|
43
|
-
['unstakeStakedReya', minAssetAmount],
|
|
44
|
-
),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const { calldata: data } = encodeUnstakeStakedReya(
|
|
48
|
-
params.marginAccountId,
|
|
49
|
-
shareAmount,
|
|
50
|
-
minAssetAmount,
|
|
51
|
-
withdrawSig,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const result = await signAndBroadcastTransaction(
|
|
55
|
-
data,
|
|
56
|
-
chainId,
|
|
57
|
-
ContractType.PERIPHERY_PROXY,
|
|
58
|
-
{},
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
transactionHash: result?.txHash || null,
|
|
63
|
-
coreSigNonce:
|
|
64
|
-
result?.coreSigNonce != null ? Number(result.coreSigNonce) : null,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
scale,
|
|
3
|
-
MoneyInOutChainId,
|
|
4
|
-
getTokenInfoByAddress,
|
|
5
|
-
getTokenInfoByName,
|
|
6
|
-
getReyaNetworkFromMoneyInOutChainId,
|
|
7
|
-
ContractType,
|
|
8
|
-
getAddress,
|
|
9
|
-
executeTransaction,
|
|
10
|
-
getLzEndpointId,
|
|
11
|
-
OFTMessagingFee,
|
|
12
|
-
OFTAbi as OFTAbi,
|
|
13
|
-
} from '@reyaxyz/common';
|
|
14
|
-
import { ethers } from 'ethers';
|
|
15
|
-
import {
|
|
16
|
-
encodeOFTBridgeAndDepositExistingMA,
|
|
17
|
-
buildOFTBridgeAndDepositExistingMASendParam,
|
|
18
|
-
} from './encode';
|
|
19
|
-
import {
|
|
20
|
-
OFTBridgeAndDepositExistingMAParams,
|
|
21
|
-
OFTBridgeAndDepositExistingMAResult,
|
|
22
|
-
} from './types';
|
|
23
|
-
|
|
24
|
-
export const oftBridgeAndDepositExistingMA = async (
|
|
25
|
-
params: OFTBridgeAndDepositExistingMAParams,
|
|
26
|
-
): Promise<OFTBridgeAndDepositExistingMAResult> => {
|
|
27
|
-
const moneyInOutChainId: MoneyInOutChainId =
|
|
28
|
-
params.moneyInOutChainId ??
|
|
29
|
-
Number((await params.signer.provider?.getNetwork())?.chainId);
|
|
30
|
-
const reyaChainId = getReyaNetworkFromMoneyInOutChainId(moneyInOutChainId);
|
|
31
|
-
|
|
32
|
-
const moneyInOutTokenInfo = getTokenInfoByAddress(
|
|
33
|
-
params.tokenAddress,
|
|
34
|
-
moneyInOutChainId,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (!moneyInOutTokenInfo.isOFT) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`Token ${moneyInOutTokenInfo.name} at ${params.tokenAddress} is not an OFT token on chain ${moneyInOutChainId}`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const reyaPeripheryTokenInfo = getTokenInfoByName(
|
|
44
|
-
moneyInOutTokenInfo.name,
|
|
45
|
-
reyaChainId,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const peripheryAddress = getAddress(
|
|
49
|
-
reyaChainId,
|
|
50
|
-
ContractType.PERIPHERY_PROXY,
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const dstEid = getLzEndpointId(reyaChainId);
|
|
54
|
-
const amountLD = scale(moneyInOutTokenInfo.decimals)(params.amount);
|
|
55
|
-
const minAmountLD = amountLD;
|
|
56
|
-
|
|
57
|
-
const { sendParam } = buildOFTBridgeAndDepositExistingMASendParam(
|
|
58
|
-
dstEid,
|
|
59
|
-
peripheryAddress,
|
|
60
|
-
params.marginAccountId,
|
|
61
|
-
reyaPeripheryTokenInfo.address,
|
|
62
|
-
amountLD,
|
|
63
|
-
minAmountLD,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const provider = params.signer.provider;
|
|
67
|
-
if (!provider) {
|
|
68
|
-
throw new Error('Signer must have a provider to quote OFT messaging fees');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const oftContract = new ethers.Contract(
|
|
72
|
-
moneyInOutTokenInfo.address,
|
|
73
|
-
OFTAbi,
|
|
74
|
-
provider,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const msgFee = await oftContract.quoteSend.staticCall(sendParam, false);
|
|
78
|
-
const messagingFee: OFTMessagingFee = {
|
|
79
|
-
nativeFee: msgFee.nativeFee,
|
|
80
|
-
lzTokenFee: msgFee.lzTokenFee,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const callerAddress = await params.signer.getAddress();
|
|
84
|
-
const { calldata: data, value } = encodeOFTBridgeAndDepositExistingMA(
|
|
85
|
-
dstEid,
|
|
86
|
-
peripheryAddress,
|
|
87
|
-
params.marginAccountId,
|
|
88
|
-
reyaPeripheryTokenInfo.address,
|
|
89
|
-
amountLD,
|
|
90
|
-
minAmountLD,
|
|
91
|
-
messagingFee,
|
|
92
|
-
callerAddress,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const result = await executeTransaction(
|
|
96
|
-
params.signer,
|
|
97
|
-
data,
|
|
98
|
-
value,
|
|
99
|
-
moneyInOutChainId,
|
|
100
|
-
moneyInOutTokenInfo.address,
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (!result?.hash) {
|
|
104
|
-
return {
|
|
105
|
-
transactionHash: null,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
transactionHash: result?.hash,
|
|
111
|
-
};
|
|
112
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getCurrentTimestampInSeconds,
|
|
3
|
-
scale,
|
|
4
|
-
getTokenInfoByAddress,
|
|
5
|
-
getLzEndpointId,
|
|
6
|
-
} from '@reyaxyz/common';
|
|
7
|
-
import { ContractType, getAddress } from '@reyaxyz/common';
|
|
8
|
-
import { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';
|
|
9
|
-
import { signCoreCommands } from '@reyaxyz/common';
|
|
10
|
-
import { encodeWithdrawMALZ } from './encode';
|
|
11
|
-
import {
|
|
12
|
-
OFTWithdrawMAAndBridgeParams,
|
|
13
|
-
OFTWithdrawMAAndBridgeResult,
|
|
14
|
-
} from './types';
|
|
15
|
-
import { BRIDGE_DEADLINE_IN_SECONDS } from '@reyaxyz/common';
|
|
16
|
-
import { encodeSingleWithdraw } from '../encode';
|
|
17
|
-
import { MultiAction } from '@reyaxyz/common';
|
|
18
|
-
import { ethers } from 'ethers';
|
|
19
|
-
import { getReyaNetwork } from '../../utils/network';
|
|
20
|
-
|
|
21
|
-
export const oftWithdrawMAAndBridge = async ({
|
|
22
|
-
signer,
|
|
23
|
-
moneyInOutChainId,
|
|
24
|
-
marginAccountId,
|
|
25
|
-
owner,
|
|
26
|
-
amount: unscaledAmount,
|
|
27
|
-
tokenAddress,
|
|
28
|
-
receiverAddress = owner.address,
|
|
29
|
-
}: OFTWithdrawMAAndBridgeParams): Promise<OFTWithdrawMAAndBridgeResult> => {
|
|
30
|
-
const reyaChainId = getReyaNetwork();
|
|
31
|
-
|
|
32
|
-
const corePeripheryTokenInfo = getTokenInfoByAddress(tokenAddress);
|
|
33
|
-
|
|
34
|
-
if (!corePeripheryTokenInfo.isOFT) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
`Token ${corePeripheryTokenInfo.name} at ${tokenAddress} is not an OFT token`,
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const multiAction = new MultiAction();
|
|
41
|
-
encodeSingleWithdraw(
|
|
42
|
-
corePeripheryTokenInfo.address,
|
|
43
|
-
scale(corePeripheryTokenInfo.decimals)(unscaledAmount),
|
|
44
|
-
multiAction,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const dstEid = getLzEndpointId(moneyInOutChainId);
|
|
48
|
-
|
|
49
|
-
const { signature: eip712Signature } = await signCoreCommands(
|
|
50
|
-
signer,
|
|
51
|
-
reyaChainId,
|
|
52
|
-
getAddress(reyaChainId, ContractType.PERIPHERY_PROXY),
|
|
53
|
-
marginAccountId,
|
|
54
|
-
multiAction.commands,
|
|
55
|
-
owner.coreSigNonce + 1,
|
|
56
|
-
getCurrentTimestampInSeconds() + BRIDGE_DEADLINE_IN_SECONDS,
|
|
57
|
-
ethers.AbiCoder.defaultAbiCoder().encode(
|
|
58
|
-
['string', 'address', 'uint32'],
|
|
59
|
-
['withdrawMALZ', receiverAddress, dstEid],
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const { calldata: data } = encodeWithdrawMALZ(
|
|
64
|
-
marginAccountId,
|
|
65
|
-
corePeripheryTokenInfo.address,
|
|
66
|
-
scale(corePeripheryTokenInfo.decimals)(unscaledAmount),
|
|
67
|
-
eip712Signature,
|
|
68
|
-
dstEid,
|
|
69
|
-
receiverAddress,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const result = await signAndBroadcastTransaction(
|
|
73
|
-
data,
|
|
74
|
-
reyaChainId,
|
|
75
|
-
ContractType.PERIPHERY_PROXY,
|
|
76
|
-
{
|
|
77
|
-
destinationType: 'account',
|
|
78
|
-
},
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
if (!result?.txHash) {
|
|
82
|
-
return {
|
|
83
|
-
transactionHash: null,
|
|
84
|
-
coreSigNonce: null,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
transactionHash: result?.txHash || null,
|
|
90
|
-
coreSigNonce:
|
|
91
|
-
result?.coreSigNonce != null ? Number(result.coreSigNonce) : null,
|
|
92
|
-
};
|
|
93
|
-
};
|