@reyaxyz/sdk 0.80.0 → 0.81.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/services/encode.js +7 -7
- package/dist/services/encode.js.map +1 -1
- package/dist/services/lp/bridgeAndDepositPassivePool.js +3 -4
- package/dist/services/lp/bridgeAndDepositPassivePool.js.map +1 -1
- package/dist/services/lp/encode.js +6 -6
- package/dist/services/lp/encode.js.map +1 -1
- package/dist/services/lp/lp.js +3 -4
- package/dist/services/lp/lp.js.map +1 -1
- package/dist/services/lp/transferFromMAToPool.js +7 -8
- package/dist/services/lp/transferFromMAToPool.js.map +1 -1
- package/dist/services/lp/withdrawPassivePoolAndBridge.js +2 -6
- package/dist/services/lp/withdrawPassivePoolAndBridge.js.map +1 -1
- package/dist/services/margin-accounts/account.js +3 -3
- package/dist/services/margin-accounts/account.js.map +1 -1
- package/dist/services/margin-accounts/bridgeAndDepositExistingMA.js +5 -6
- package/dist/services/margin-accounts/bridgeAndDepositExistingMA.js.map +1 -1
- package/dist/services/margin-accounts/bridgeAndDepositNewMA.js +3 -4
- package/dist/services/margin-accounts/bridgeAndDepositNewMA.js.map +1 -1
- package/dist/services/margin-accounts/deposit.js +4 -5
- package/dist/services/margin-accounts/deposit.js.map +1 -1
- package/dist/services/margin-accounts/encode.js +14 -19
- package/dist/services/margin-accounts/encode.js.map +1 -1
- package/dist/services/margin-accounts/transferMarginBetweenAccounts.js +3 -3
- package/dist/services/margin-accounts/transferMarginBetweenAccounts.js.map +1 -1
- package/dist/services/margin-accounts/withdraw.js +4 -5
- package/dist/services/margin-accounts/withdraw.js.map +1 -1
- package/dist/services/margin-accounts/withdrawMAAndBridge.js +8 -8
- package/dist/services/margin-accounts/withdrawMAAndBridge.js.map +1 -1
- package/dist/services/orders/encode.js +7 -9
- package/dist/services/orders/encode.js.map +1 -1
- package/dist/services/orders/order.js +10 -10
- package/dist/services/orders/order.js.map +1 -1
- package/dist/services/{executeTransaction.js → signAndBroadcastTransaction.js} +9 -88
- package/dist/services/signAndBroadcastTransaction.js.map +1 -0
- package/dist/services/token/approve.js +3 -3
- package/dist/services/token/approve.js.map +1 -1
- package/dist/services/token/getAllowance.js +2 -3
- package/dist/services/token/getAllowance.js.map +1 -1
- package/dist/types/services/encode.d.ts +1 -1
- package/dist/types/services/encode.d.ts.map +1 -1
- package/dist/types/services/lp/encode.d.ts +2 -2
- package/dist/types/services/lp/encode.d.ts.map +1 -1
- package/dist/types/services/lp/lp.d.ts.map +1 -1
- package/dist/types/services/lp/transferFromMAToPool.d.ts.map +1 -1
- package/dist/types/services/lp/withdrawPassivePoolAndBridge.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/bridgeAndDepositExistingMA.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/bridgeAndDepositNewMA.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/deposit.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/encode.d.ts +2 -2
- package/dist/types/services/margin-accounts/encode.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/withdraw.d.ts.map +1 -1
- package/dist/types/services/orders/encode.d.ts +1 -1
- package/dist/types/services/orders/encode.d.ts.map +1 -1
- package/dist/types/services/signAndBroadcastTransaction.d.ts +8 -0
- package/dist/types/services/signAndBroadcastTransaction.d.ts.map +1 -0
- package/dist/types/services/token/getAllowance.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/encode.ts +3 -4
- package/src/services/lp/bridgeAndDepositPassivePool.ts +2 -2
- package/src/services/lp/encode.ts +5 -7
- package/src/services/lp/lp.ts +1 -2
- package/src/services/lp/transferFromMAToPool.ts +4 -5
- package/src/services/lp/withdrawPassivePoolAndBridge.ts +5 -4
- package/src/services/margin-accounts/account.ts +2 -2
- package/src/services/margin-accounts/bridgeAndDepositExistingMA.ts +2 -3
- package/src/services/margin-accounts/bridgeAndDepositNewMA.ts +1 -2
- package/src/services/margin-accounts/deposit.ts +1 -2
- package/src/services/margin-accounts/encode.ts +15 -12
- package/src/services/margin-accounts/transferMarginBetweenAccounts.ts +2 -2
- package/src/services/margin-accounts/withdraw.ts +1 -2
- package/src/services/margin-accounts/withdrawMAAndBridge.ts +5 -5
- package/src/services/orders/encode.ts +12 -6
- package/src/services/orders/order.ts +3 -3
- package/src/services/signAndBroadcastTransaction.ts +42 -0
- package/src/services/token/approve.ts +1 -1
- package/src/services/token/getAllowance.ts +2 -1
- package/dist/abis/CoreProxy.json +0 -5600
- package/dist/abis/Periphery.json +0 -1464
- package/dist/abis/socket/VaultWithPayload.json +0 -40
- package/dist/services/executeTransaction.js.map +0 -1
- package/dist/services/sign.js +0 -146
- package/dist/services/sign.js.map +0 -1
- package/dist/types/services/executeTransaction.d.ts +0 -20
- package/dist/types/services/executeTransaction.d.ts.map +0 -1
- package/dist/types/services/sign.d.ts +0 -12
- package/dist/types/services/sign.d.ts.map +0 -1
- package/dist/types/utils/action.d.ts +0 -27
- package/dist/types/utils/action.d.ts.map +0 -1
- package/dist/types/utils/consts.d.ts +0 -4
- package/dist/types/utils/consts.d.ts.map +0 -1
- package/dist/types/utils/contractAddresses.d.ts +0 -8
- package/dist/types/utils/contractAddresses.d.ts.map +0 -1
- package/dist/types/utils/routerCommands.d.ts +0 -23
- package/dist/types/utils/routerCommands.d.ts.map +0 -1
- package/dist/types/utils/trade.d.ts +0 -2
- package/dist/types/utils/trade.d.ts.map +0 -1
- package/dist/types/utils/txHelpers.d.ts +0 -2
- package/dist/types/utils/txHelpers.d.ts.map +0 -1
- package/dist/utils/action.js +0 -22
- package/dist/utils/action.js.map +0 -1
- package/dist/utils/consts.js +0 -7
- package/dist/utils/consts.js.map +0 -1
- package/dist/utils/contractAddresses.js +0 -37
- package/dist/utils/contractAddresses.js.map +0 -1
- package/dist/utils/routerCommands.js +0 -45
- package/dist/utils/routerCommands.js.map +0 -1
- package/dist/utils/trade.js +0 -24
- package/dist/utils/trade.js.map +0 -1
- package/dist/utils/txHelpers.js +0 -8
- package/dist/utils/txHelpers.js.map +0 -1
- package/src/abis/CoreProxy.json +0 -5600
- package/src/abis/Periphery.json +0 -1464
- package/src/abis/socket/VaultWithPayload.json +0 -40
- package/src/services/executeTransaction.ts +0 -123
- package/src/services/sign.ts +0 -135
- package/src/utils/action.ts +0 -41
- package/src/utils/consts.ts +0 -3
- package/src/utils/contractAddresses.ts +0 -43
- package/src/utils/routerCommands.ts +0 -62
- package/src/utils/trade.ts +0 -25
- package/src/utils/txHelpers.ts +0 -3
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"abi": [
|
|
3
|
-
{
|
|
4
|
-
"type": "function",
|
|
5
|
-
"name": "bridge",
|
|
6
|
-
"inputs": [
|
|
7
|
-
{
|
|
8
|
-
"name": "receiver_",
|
|
9
|
-
"type": "address",
|
|
10
|
-
"internalType": "address"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"name": "amount_",
|
|
14
|
-
"type": "uint256",
|
|
15
|
-
"internalType": "uint256"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"name": "msgGasLimit_",
|
|
19
|
-
"type": "uint256",
|
|
20
|
-
"internalType": "uint256"
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"name": "connector_",
|
|
24
|
-
"type": "address",
|
|
25
|
-
"internalType": "address"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"name": "execPayload_",
|
|
29
|
-
"type": "bytes",
|
|
30
|
-
"internalType": "bytes"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"name": "options_",
|
|
34
|
-
"type": "bytes",
|
|
35
|
-
"internalType": "bytes"
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
import { ContractType, getAddress } from '../utils/contractAddresses';
|
|
3
|
-
import { getGasBuffer } from '../utils/txHelpers';
|
|
4
|
-
import {
|
|
5
|
-
BroadcastTransactionMetadata,
|
|
6
|
-
getTransactionModuleClient,
|
|
7
|
-
} from '../config';
|
|
8
|
-
import { ReyaChainId } from '@reyaxyz/common';
|
|
9
|
-
|
|
10
|
-
export type Transaction = {
|
|
11
|
-
from: string;
|
|
12
|
-
to: string;
|
|
13
|
-
data: string;
|
|
14
|
-
value?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export async function estimateGas(
|
|
18
|
-
signer: Signer | JsonRpcSigner,
|
|
19
|
-
data: string,
|
|
20
|
-
value: string,
|
|
21
|
-
chainId: number,
|
|
22
|
-
targetContract: ContractType | string,
|
|
23
|
-
): Promise<
|
|
24
|
-
Transaction & {
|
|
25
|
-
gasLimit: bigint;
|
|
26
|
-
maxPriorityFeePerGas?: bigint;
|
|
27
|
-
maxFeePerGas?: bigint;
|
|
28
|
-
}
|
|
29
|
-
> {
|
|
30
|
-
const accountAddress = await signer.getAddress();
|
|
31
|
-
|
|
32
|
-
const contractAddress = Object.values(ContractType).includes(
|
|
33
|
-
targetContract as ContractType,
|
|
34
|
-
)
|
|
35
|
-
? getAddress(chainId, targetContract as ContractType)
|
|
36
|
-
: targetContract;
|
|
37
|
-
const tx = {
|
|
38
|
-
from: accountAddress, // @todo Update with relayer address
|
|
39
|
-
to: contractAddress,
|
|
40
|
-
data,
|
|
41
|
-
...(value && value !== '0' ? { value: value } : {}),
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
const gasEstimate = await signer.estimateGas(tx);
|
|
48
|
-
gasLimit = getGasBuffer(gasEstimate);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
// sentry error & thorw
|
|
51
|
-
console.warn(error);
|
|
52
|
-
throw new Error('Error executing transaction'); // @todo introduce error parsing
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {
|
|
56
|
-
const maxPriorityFeePerGas: bigint = BigInt('0');
|
|
57
|
-
const maxFeePerGas: bigint = BigInt('100000000');
|
|
58
|
-
return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { ...tx, gasLimit };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function executeTransaction(
|
|
65
|
-
signer: Signer | JsonRpcSigner,
|
|
66
|
-
data: string,
|
|
67
|
-
value: string,
|
|
68
|
-
chainId: number,
|
|
69
|
-
targetContract: ContractType | string,
|
|
70
|
-
) {
|
|
71
|
-
const txData = await estimateGas(
|
|
72
|
-
signer,
|
|
73
|
-
data,
|
|
74
|
-
value,
|
|
75
|
-
chainId,
|
|
76
|
-
targetContract,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const txResponse = await signer.sendTransaction(txData);
|
|
81
|
-
const txReceipt = await txResponse.wait();
|
|
82
|
-
return txReceipt;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.warn(error);
|
|
85
|
-
throw new Error('Transaction Execution Error');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export async function signAndBroadcastTransaction(
|
|
90
|
-
signer: Signer | JsonRpcSigner,
|
|
91
|
-
data: string,
|
|
92
|
-
value: string,
|
|
93
|
-
chainId: number,
|
|
94
|
-
targetContract: ContractType | string,
|
|
95
|
-
metadata: BroadcastTransactionMetadata,
|
|
96
|
-
): Promise<{ hash: string; accountId?: string }> {
|
|
97
|
-
const contractAddress = Object.values(ContractType).includes(
|
|
98
|
-
targetContract as ContractType,
|
|
99
|
-
)
|
|
100
|
-
? getAddress(chainId, targetContract as ContractType)
|
|
101
|
-
: targetContract;
|
|
102
|
-
|
|
103
|
-
// used to catch error in advance since gelato is slow in failing down
|
|
104
|
-
// on reya chain usually takes around 100ms, should be monitored!
|
|
105
|
-
await estimateGas(signer, data, value, chainId, targetContract);
|
|
106
|
-
try {
|
|
107
|
-
const transactionModuleClient = getTransactionModuleClient();
|
|
108
|
-
const { txHash, accountId } =
|
|
109
|
-
await transactionModuleClient.executeTransaction(
|
|
110
|
-
{ to: contractAddress, data: data },
|
|
111
|
-
contractAddress,
|
|
112
|
-
metadata,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
if (!txHash) {
|
|
116
|
-
throw new Error('Error sending transaction');
|
|
117
|
-
}
|
|
118
|
-
return { hash: txHash, accountId };
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.warn(error);
|
|
121
|
-
throw new Error('Transaction Execution Error');
|
|
122
|
-
}
|
|
123
|
-
}
|
package/src/services/sign.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { JsonRpcSigner, Signature, Signer, TypedDataField } from 'ethers';
|
|
2
|
-
import { ContractType, getAddress } from '../utils/contractAddresses';
|
|
3
|
-
import { Address, ReyaChainId } from '@reyaxyz/common';
|
|
4
|
-
import { Command } from '../utils/action';
|
|
5
|
-
import { ethers } from 'ethers';
|
|
6
|
-
|
|
7
|
-
export type EIP712Signature = {
|
|
8
|
-
v: number;
|
|
9
|
-
r: string;
|
|
10
|
-
s: string;
|
|
11
|
-
deadline: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function convertEthersSignatureToEIP712Signature(
|
|
15
|
-
signature: Signature,
|
|
16
|
-
deadline: number,
|
|
17
|
-
): EIP712Signature {
|
|
18
|
-
return {
|
|
19
|
-
v: signature.v,
|
|
20
|
-
r: signature.r,
|
|
21
|
-
s: signature.s,
|
|
22
|
-
deadline: deadline,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function signCoreCommands(
|
|
27
|
-
signer: Signer | JsonRpcSigner,
|
|
28
|
-
reyaChainId: ReyaChainId,
|
|
29
|
-
caller: Address,
|
|
30
|
-
accountId: number,
|
|
31
|
-
commands: Command[],
|
|
32
|
-
nonce: number,
|
|
33
|
-
deadline: number,
|
|
34
|
-
extraSignatureData: string,
|
|
35
|
-
): Promise<EIP712Signature> {
|
|
36
|
-
const signature = await signReyaTypedData(
|
|
37
|
-
signer,
|
|
38
|
-
getAddress(reyaChainId, ContractType.CORE_PROXY),
|
|
39
|
-
{
|
|
40
|
-
ExecuteBySig: [
|
|
41
|
-
{ name: 'verifyingChainId', type: 'uint256' },
|
|
42
|
-
{ name: 'caller', type: 'address' },
|
|
43
|
-
{ name: 'accountId', type: 'uint128' },
|
|
44
|
-
{ name: 'commands', type: 'Command[]' },
|
|
45
|
-
{ name: 'nonce', type: 'uint256' },
|
|
46
|
-
{ name: 'deadline', type: 'uint256' },
|
|
47
|
-
{ name: 'extraSignatureData', type: 'bytes' },
|
|
48
|
-
],
|
|
49
|
-
Command: [
|
|
50
|
-
{ name: 'commandType', type: 'uint8' },
|
|
51
|
-
{ name: 'inputs', type: 'bytes' },
|
|
52
|
-
{ name: 'marketId', type: 'uint128' },
|
|
53
|
-
{ name: 'exchangeId', type: 'uint128' },
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
verifyingChainId: reyaChainId,
|
|
58
|
-
caller: caller,
|
|
59
|
-
accountId: accountId,
|
|
60
|
-
commands: commands,
|
|
61
|
-
nonce: nonce,
|
|
62
|
-
deadline: deadline,
|
|
63
|
-
extraSignatureData: extraSignatureData,
|
|
64
|
-
},
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
return convertEthersSignatureToEIP712Signature(signature, deadline);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function signPoolRemoveLiquidity(
|
|
71
|
-
signer: Signer | JsonRpcSigner,
|
|
72
|
-
reyaChainId: ReyaChainId,
|
|
73
|
-
caller: Address,
|
|
74
|
-
owner: Address,
|
|
75
|
-
poolId: number,
|
|
76
|
-
sharesAmount: bigint,
|
|
77
|
-
minOut: bigint,
|
|
78
|
-
nonce: number,
|
|
79
|
-
deadline: number,
|
|
80
|
-
socketMsgGasLimit: bigint,
|
|
81
|
-
chainId: number,
|
|
82
|
-
receiver: string,
|
|
83
|
-
): Promise<EIP712Signature> {
|
|
84
|
-
const signature = await signReyaTypedData(
|
|
85
|
-
signer,
|
|
86
|
-
getAddress(reyaChainId, ContractType.PASSIVE_POOL_PROXY),
|
|
87
|
-
{
|
|
88
|
-
RemoveLiquidityBySig: [
|
|
89
|
-
{ name: 'verifyingChainId', type: 'uint256' },
|
|
90
|
-
{ name: 'caller', type: 'address' },
|
|
91
|
-
{ name: 'owner', type: 'address' },
|
|
92
|
-
{ name: 'poolId', type: 'uint128' },
|
|
93
|
-
{ name: 'sharesAmount', type: 'uint256' },
|
|
94
|
-
{ name: 'minOut', type: 'uint256' },
|
|
95
|
-
{ name: 'nonce', type: 'uint256' },
|
|
96
|
-
{ name: 'deadline', type: 'uint256' },
|
|
97
|
-
{ name: 'extraSignatureData', type: 'bytes' },
|
|
98
|
-
],
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
verifyingChainId: reyaChainId,
|
|
102
|
-
caller: caller,
|
|
103
|
-
owner: owner,
|
|
104
|
-
poolId: poolId,
|
|
105
|
-
sharesAmount: sharesAmount,
|
|
106
|
-
minOut: minOut,
|
|
107
|
-
nonce: nonce,
|
|
108
|
-
deadline: deadline,
|
|
109
|
-
extraSignatureData: ethers.AbiCoder.defaultAbiCoder().encode(
|
|
110
|
-
['address', 'uint256', 'uint256'],
|
|
111
|
-
[receiver, chainId, socketMsgGasLimit],
|
|
112
|
-
),
|
|
113
|
-
},
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
return convertEthersSignatureToEIP712Signature(signature, deadline);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function signReyaTypedData(
|
|
120
|
-
signer: Signer | JsonRpcSigner,
|
|
121
|
-
verifyingContract: string,
|
|
122
|
-
types: Record<string, Array<TypedDataField>>,
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
-
value: Record<string, any>,
|
|
125
|
-
): Promise<Signature> {
|
|
126
|
-
const domain = {
|
|
127
|
-
name: 'Reya',
|
|
128
|
-
version: '1',
|
|
129
|
-
verifyingContract: verifyingContract,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const signatureString = await signer.signTypedData(domain, types, value);
|
|
133
|
-
|
|
134
|
-
return Signature.from(signatureString);
|
|
135
|
-
}
|
package/src/utils/action.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// ENCODED ACTIONS
|
|
2
|
-
|
|
3
|
-
import { CommandType } from './routerCommands';
|
|
4
|
-
|
|
5
|
-
export type MethodParameters = {
|
|
6
|
-
/**
|
|
7
|
-
* The hex encoded calldata to perform the given operation
|
|
8
|
-
*/
|
|
9
|
-
calldata: string;
|
|
10
|
-
/**
|
|
11
|
-
* The amount of ether (wei) to send in hex.
|
|
12
|
-
*/
|
|
13
|
-
value: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type Command = {
|
|
17
|
-
commandType: CommandType;
|
|
18
|
-
inputs: string;
|
|
19
|
-
marketId: number;
|
|
20
|
-
exchangeId: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type SingleAction = {
|
|
24
|
-
command: Command;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export class MultiAction {
|
|
28
|
-
public commands: Command[];
|
|
29
|
-
|
|
30
|
-
constructor() {
|
|
31
|
-
this.commands = [];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public get length(): number {
|
|
35
|
-
return this.commands.length;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public newAction(singleAction: SingleAction): void {
|
|
39
|
-
this.commands.push(singleAction.command);
|
|
40
|
-
}
|
|
41
|
-
}
|
package/src/utils/consts.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export type Address = Lowercase<string>;
|
|
2
|
-
// @todo update with proper chainId for mainnet
|
|
3
|
-
import { ReyaChainId } from '@reyaxyz/common';
|
|
4
|
-
|
|
5
|
-
export enum ContractType {
|
|
6
|
-
CORE_PROXY = 'core_proxy',
|
|
7
|
-
PASSIVE_POOL_PROXY = 'passive_pool_proxy',
|
|
8
|
-
PERIPHERY_PROXY = 'periphery_proxy',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const addresses: Record<ReyaChainId, Record<ContractType, Address>> = {
|
|
12
|
-
[ReyaChainId.reyaCronos]: {
|
|
13
|
-
[ContractType.CORE_PROXY]: '0x20da8f7aa44f858a3a3e3f03ba6ffad039d1eb28',
|
|
14
|
-
[ContractType.PASSIVE_POOL_PROXY]:
|
|
15
|
-
'0x9afc30bed29d636e566fd9d7dd89d51773724be6',
|
|
16
|
-
[ContractType.PERIPHERY_PROXY]:
|
|
17
|
-
'0xa45d0566144956b6012d461ad509dad2bacacaaf',
|
|
18
|
-
},
|
|
19
|
-
[ReyaChainId.reyaNetwork]: {
|
|
20
|
-
[ContractType.CORE_PROXY]: '0xa763b6a5e09378434406c003dae6487fbbdc1a80',
|
|
21
|
-
[ContractType.PASSIVE_POOL_PROXY]:
|
|
22
|
-
'0xb4b77d6180cc14472a9a7bdff01cc2459368d413',
|
|
23
|
-
[ContractType.PERIPHERY_PROXY]:
|
|
24
|
-
'0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
export const getAddress = (
|
|
28
|
-
chainId: number,
|
|
29
|
-
contractName: ContractType,
|
|
30
|
-
): Address => {
|
|
31
|
-
const keyChainId = chainId.toString();
|
|
32
|
-
|
|
33
|
-
if (!Object.keys(addresses).includes(keyChainId)) {
|
|
34
|
-
throw new Error(`Unspecified addresses for chain id ${keyChainId}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const networkAddresses = addresses[chainId as ReyaChainId];
|
|
38
|
-
if (!Object.keys(networkAddresses).includes(contractName)) {
|
|
39
|
-
throw new Error(`Unspecified address for ${contractName} contract`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return networkAddresses[contractName];
|
|
43
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { AbiCoder } from 'ethers';
|
|
2
|
-
import { SingleAction } from './action';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* CommandTypes
|
|
6
|
-
* @description Flags that modify a command's execution
|
|
7
|
-
* @enum {number}
|
|
8
|
-
*/
|
|
9
|
-
export enum CommandType {
|
|
10
|
-
DEPOSIT,
|
|
11
|
-
WITHDRAW,
|
|
12
|
-
DUTCH_LIQUIDATION,
|
|
13
|
-
MATCH_ORDER,
|
|
14
|
-
PROPAGATE_CACHE_FLOW,
|
|
15
|
-
TRANSFER_MARGIN_ACCOUNT,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const ABI_DEFINITION: { [key in CommandType]: string[] } = {
|
|
19
|
-
[CommandType.DEPOSIT]: ['address', 'uint256'],
|
|
20
|
-
[CommandType.WITHDRAW]: ['address', 'uint256'],
|
|
21
|
-
[CommandType.MATCH_ORDER]: ['uint128[]', 'bytes'],
|
|
22
|
-
[CommandType.PROPAGATE_CACHE_FLOW]: [], // @todo Check if correct
|
|
23
|
-
[CommandType.DUTCH_LIQUIDATION]: [], // @todo update once needed
|
|
24
|
-
[CommandType.TRANSFER_MARGIN_ACCOUNT]: ['tuple(uint128,address,uint256)'], // @todo update once needed
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type RouterCommand = {
|
|
28
|
-
type: CommandType;
|
|
29
|
-
encodedInput: string;
|
|
30
|
-
marketId: number;
|
|
31
|
-
exchangeId: number;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export function createCommand(
|
|
35
|
-
type: CommandType,
|
|
36
|
-
parameters: unknown[],
|
|
37
|
-
marketId: number,
|
|
38
|
-
exchangeId: number,
|
|
39
|
-
): RouterCommand {
|
|
40
|
-
const encodedInput = AbiCoder.defaultAbiCoder().encode(
|
|
41
|
-
ABI_DEFINITION[type],
|
|
42
|
-
parameters,
|
|
43
|
-
);
|
|
44
|
-
return { type, encodedInput, marketId, exchangeId };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getCommand(
|
|
48
|
-
type: CommandType,
|
|
49
|
-
parameters: unknown[],
|
|
50
|
-
marketId: number,
|
|
51
|
-
exchangeId: number,
|
|
52
|
-
): SingleAction {
|
|
53
|
-
const command = createCommand(type, parameters, marketId, exchangeId);
|
|
54
|
-
return {
|
|
55
|
-
command: {
|
|
56
|
-
commandType: command.type,
|
|
57
|
-
inputs: command.encodedInput,
|
|
58
|
-
marketId: command.marketId,
|
|
59
|
-
exchangeId: command.exchangeId,
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
package/src/utils/trade.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
|
|
3
|
-
// todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance
|
|
4
|
-
export function calculatePriceLimitForTrade(
|
|
5
|
-
orderPrice: number,
|
|
6
|
-
amount: number,
|
|
7
|
-
): bigint {
|
|
8
|
-
// Ensure orderPrice is BigInt
|
|
9
|
-
const orderPriceBigInt = BigNumber(orderPrice);
|
|
10
|
-
|
|
11
|
-
// Calculate 50% of the order price
|
|
12
|
-
const offset = orderPriceBigInt.div(2);
|
|
13
|
-
|
|
14
|
-
// Determine if the amount is positive or negative and adjust the price accordingly
|
|
15
|
-
if (amount > 0) {
|
|
16
|
-
// Trade is long, so add
|
|
17
|
-
return BigInt(
|
|
18
|
-
BigNumber(orderPriceBigInt).plus(offset).times(1e18).toFixed(0),
|
|
19
|
-
);
|
|
20
|
-
} else {
|
|
21
|
-
return BigInt(
|
|
22
|
-
BigNumber(orderPriceBigInt).minus(offset).times(1e18).toFixed(0),
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
}
|
package/src/utils/txHelpers.ts
DELETED