@reyaxyz/common 0.341.0 → 0.343.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/dist/trading-api-types.js.map +1 -1
  3. package/dist/transactions/abis/OFT.json +201 -0
  4. package/dist/transactions/abis/Periphery.json +233 -0
  5. package/dist/transactions/index.js +3 -1
  6. package/dist/transactions/index.js.map +1 -1
  7. package/dist/types/trading-api-types.d.ts +8 -0
  8. package/dist/types/trading-api-types.d.ts.map +1 -1
  9. package/dist/types/transactions/index.d.ts +1 -0
  10. package/dist/types/transactions/index.d.ts.map +1 -1
  11. package/dist/types/types.d.ts +2 -1
  12. package/dist/types/types.d.ts.map +1 -1
  13. package/dist/types/utils/calculate.d.ts +32 -1
  14. package/dist/types/utils/calculate.d.ts.map +1 -1
  15. package/dist/types/utils/index.d.ts +1 -0
  16. package/dist/types/utils/index.d.ts.map +1 -1
  17. package/dist/types/utils/layerzero/index.d.ts +3 -0
  18. package/dist/types/utils/layerzero/index.d.ts.map +1 -0
  19. package/dist/types/utils/layerzero/oft-config.d.ts +4 -0
  20. package/dist/types/utils/layerzero/oft-config.d.ts.map +1 -0
  21. package/dist/types/utils/layerzero/types.d.ts +23 -0
  22. package/dist/types/utils/layerzero/types.d.ts.map +1 -0
  23. package/dist/types/utils/token/token-info.d.ts.map +1 -1
  24. package/dist/types.js.map +1 -1
  25. package/dist/utils/calculate.js +69 -2
  26. package/dist/utils/calculate.js.map +1 -1
  27. package/dist/utils/index.js +1 -0
  28. package/dist/utils/index.js.map +1 -1
  29. package/dist/utils/layerzero/index.js +19 -0
  30. package/dist/utils/layerzero/index.js.map +1 -0
  31. package/dist/utils/layerzero/oft-config.js +29 -0
  32. package/dist/utils/layerzero/oft-config.js.map +1 -0
  33. package/dist/utils/layerzero/types.js +3 -0
  34. package/dist/utils/layerzero/types.js.map +1 -0
  35. package/dist/utils/token/token-info.js +64 -0
  36. package/dist/utils/token/token-info.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/trading-api-types.ts +11 -0
  39. package/src/transactions/abis/OFT.json +201 -0
  40. package/src/transactions/abis/Periphery.json +233 -0
  41. package/src/transactions/index.ts +1 -0
  42. package/src/types.ts +3 -0
  43. package/src/utils/calculate.ts +86 -1
  44. package/src/utils/index.ts +1 -0
  45. package/src/utils/layerzero/index.ts +2 -0
  46. package/src/utils/layerzero/oft-config.ts +32 -0
  47. package/src/utils/layerzero/types.ts +25 -0
  48. package/src/utils/token/token-info.ts +64 -0
@@ -0,0 +1,201 @@
1
+ {
2
+ "abi": [
3
+ {
4
+ "inputs": [
5
+ {
6
+ "components": [
7
+ {
8
+ "internalType": "uint32",
9
+ "name": "dstEid",
10
+ "type": "uint32"
11
+ },
12
+ {
13
+ "internalType": "bytes32",
14
+ "name": "to",
15
+ "type": "bytes32"
16
+ },
17
+ {
18
+ "internalType": "uint256",
19
+ "name": "amountLD",
20
+ "type": "uint256"
21
+ },
22
+ {
23
+ "internalType": "uint256",
24
+ "name": "minAmountLD",
25
+ "type": "uint256"
26
+ },
27
+ {
28
+ "internalType": "bytes",
29
+ "name": "extraOptions",
30
+ "type": "bytes"
31
+ },
32
+ {
33
+ "internalType": "bytes",
34
+ "name": "composeMsg",
35
+ "type": "bytes"
36
+ },
37
+ {
38
+ "internalType": "bytes",
39
+ "name": "oftCmd",
40
+ "type": "bytes"
41
+ }
42
+ ],
43
+ "internalType": "struct SendParam",
44
+ "name": "_sendParam",
45
+ "type": "tuple"
46
+ },
47
+ {
48
+ "internalType": "bool",
49
+ "name": "_payInLzToken",
50
+ "type": "bool"
51
+ }
52
+ ],
53
+ "name": "quoteSend",
54
+ "outputs": [
55
+ {
56
+ "components": [
57
+ {
58
+ "internalType": "uint256",
59
+ "name": "nativeFee",
60
+ "type": "uint256"
61
+ },
62
+ {
63
+ "internalType": "uint256",
64
+ "name": "lzTokenFee",
65
+ "type": "uint256"
66
+ }
67
+ ],
68
+ "internalType": "struct MessagingFee",
69
+ "name": "msgFee",
70
+ "type": "tuple"
71
+ }
72
+ ],
73
+ "stateMutability": "view",
74
+ "type": "function"
75
+ },
76
+ {
77
+ "inputs": [
78
+ {
79
+ "components": [
80
+ {
81
+ "internalType": "uint32",
82
+ "name": "dstEid",
83
+ "type": "uint32"
84
+ },
85
+ {
86
+ "internalType": "bytes32",
87
+ "name": "to",
88
+ "type": "bytes32"
89
+ },
90
+ {
91
+ "internalType": "uint256",
92
+ "name": "amountLD",
93
+ "type": "uint256"
94
+ },
95
+ {
96
+ "internalType": "uint256",
97
+ "name": "minAmountLD",
98
+ "type": "uint256"
99
+ },
100
+ {
101
+ "internalType": "bytes",
102
+ "name": "extraOptions",
103
+ "type": "bytes"
104
+ },
105
+ {
106
+ "internalType": "bytes",
107
+ "name": "composeMsg",
108
+ "type": "bytes"
109
+ },
110
+ {
111
+ "internalType": "bytes",
112
+ "name": "oftCmd",
113
+ "type": "bytes"
114
+ }
115
+ ],
116
+ "internalType": "struct SendParam",
117
+ "name": "_sendParam",
118
+ "type": "tuple"
119
+ },
120
+ {
121
+ "components": [
122
+ {
123
+ "internalType": "uint256",
124
+ "name": "nativeFee",
125
+ "type": "uint256"
126
+ },
127
+ {
128
+ "internalType": "uint256",
129
+ "name": "lzTokenFee",
130
+ "type": "uint256"
131
+ }
132
+ ],
133
+ "internalType": "struct MessagingFee",
134
+ "name": "_fee",
135
+ "type": "tuple"
136
+ },
137
+ {
138
+ "internalType": "address",
139
+ "name": "_refundAddress",
140
+ "type": "address"
141
+ }
142
+ ],
143
+ "name": "send",
144
+ "outputs": [
145
+ {
146
+ "components": [
147
+ {
148
+ "internalType": "bytes32",
149
+ "name": "guid",
150
+ "type": "bytes32"
151
+ },
152
+ {
153
+ "internalType": "uint64",
154
+ "name": "nonce",
155
+ "type": "uint64"
156
+ },
157
+ {
158
+ "components": [
159
+ {
160
+ "internalType": "uint256",
161
+ "name": "nativeFee",
162
+ "type": "uint256"
163
+ },
164
+ {
165
+ "internalType": "uint256",
166
+ "name": "lzTokenFee",
167
+ "type": "uint256"
168
+ }
169
+ ],
170
+ "internalType": "struct MessagingFee",
171
+ "name": "fee",
172
+ "type": "tuple"
173
+ }
174
+ ],
175
+ "internalType": "struct MessagingReceipt",
176
+ "name": "msgReceipt",
177
+ "type": "tuple"
178
+ },
179
+ {
180
+ "components": [
181
+ {
182
+ "internalType": "uint256",
183
+ "name": "amountSentLD",
184
+ "type": "uint256"
185
+ },
186
+ {
187
+ "internalType": "uint256",
188
+ "name": "amountReceivedLD",
189
+ "type": "uint256"
190
+ }
191
+ ],
192
+ "internalType": "struct OFTReceipt",
193
+ "name": "oftReceipt",
194
+ "type": "tuple"
195
+ }
196
+ ],
197
+ "stateMutability": "payable",
198
+ "type": "function"
199
+ }
200
+ ]
201
+ }
@@ -1457,6 +1457,125 @@
1457
1457
  "outputs": [],
1458
1458
  "stateMutability": "nonpayable"
1459
1459
  },
1460
+ {
1461
+ "type": "function",
1462
+ "name": "withdrawMALZ",
1463
+ "inputs": [
1464
+ {
1465
+ "name": "inputs",
1466
+ "type": "tuple",
1467
+ "internalType": "struct WithdrawMALZInputs",
1468
+ "components": [
1469
+ {
1470
+ "name": "accountId",
1471
+ "type": "uint128",
1472
+ "internalType": "uint128"
1473
+ },
1474
+ {
1475
+ "name": "token",
1476
+ "type": "address",
1477
+ "internalType": "address"
1478
+ },
1479
+ {
1480
+ "name": "tokenAmount",
1481
+ "type": "uint256",
1482
+ "internalType": "uint256"
1483
+ },
1484
+ {
1485
+ "name": "sig",
1486
+ "type": "tuple",
1487
+ "internalType": "struct EIP712Signature",
1488
+ "components": [
1489
+ {
1490
+ "name": "v",
1491
+ "type": "uint8",
1492
+ "internalType": "uint8"
1493
+ },
1494
+ {
1495
+ "name": "r",
1496
+ "type": "bytes32",
1497
+ "internalType": "bytes32"
1498
+ },
1499
+ {
1500
+ "name": "s",
1501
+ "type": "bytes32",
1502
+ "internalType": "bytes32"
1503
+ },
1504
+ {
1505
+ "name": "deadline",
1506
+ "type": "uint256",
1507
+ "internalType": "uint256"
1508
+ }
1509
+ ]
1510
+ },
1511
+ {
1512
+ "name": "dstEid",
1513
+ "type": "uint32",
1514
+ "internalType": "uint32"
1515
+ },
1516
+ {
1517
+ "name": "receiver",
1518
+ "type": "address",
1519
+ "internalType": "address"
1520
+ }
1521
+ ]
1522
+ }
1523
+ ],
1524
+ "outputs": [
1525
+ {
1526
+ "name": "",
1527
+ "type": "tuple",
1528
+ "internalType": "struct MessagingReceipt",
1529
+ "components": [
1530
+ {
1531
+ "name": "guid",
1532
+ "type": "bytes32",
1533
+ "internalType": "bytes32"
1534
+ },
1535
+ {
1536
+ "name": "nonce",
1537
+ "type": "uint64",
1538
+ "internalType": "uint64"
1539
+ },
1540
+ {
1541
+ "name": "fee",
1542
+ "type": "tuple",
1543
+ "internalType": "struct MessagingFee",
1544
+ "components": [
1545
+ {
1546
+ "name": "nativeFee",
1547
+ "type": "uint256",
1548
+ "internalType": "uint256"
1549
+ },
1550
+ {
1551
+ "name": "lzTokenFee",
1552
+ "type": "uint256",
1553
+ "internalType": "uint256"
1554
+ }
1555
+ ]
1556
+ }
1557
+ ]
1558
+ },
1559
+ {
1560
+ "name": "",
1561
+ "type": "tuple",
1562
+ "internalType": "struct OFTReceipt",
1563
+ "components": [
1564
+ {
1565
+ "name": "amountSentLD",
1566
+ "type": "uint256",
1567
+ "internalType": "uint256"
1568
+ },
1569
+ {
1570
+ "name": "amountReceivedLD",
1571
+ "type": "uint256",
1572
+ "internalType": "uint256"
1573
+ }
1574
+ ]
1575
+ }
1576
+ ],
1577
+ "stateMutability": "nonpayable"
1578
+ },
1460
1579
  {
1461
1580
  "type": "function",
1462
1581
  "name": "withdrawPassivePool",
@@ -1869,6 +1988,120 @@
1869
1988
  ],
1870
1989
  "anonymous": false
1871
1990
  },
1991
+ {
1992
+ "type": "function",
1993
+ "name": "stakeReya",
1994
+ "inputs": [
1995
+ {
1996
+ "name": "inputs",
1997
+ "type": "tuple",
1998
+ "internalType": "struct StakeReyaInputs",
1999
+ "components": [
2000
+ {
2001
+ "name": "accountId",
2002
+ "type": "uint128",
2003
+ "internalType": "uint128"
2004
+ },
2005
+ {
2006
+ "name": "assetAmount",
2007
+ "type": "uint256",
2008
+ "internalType": "uint256"
2009
+ },
2010
+ {
2011
+ "name": "minShareAmount",
2012
+ "type": "uint256",
2013
+ "internalType": "uint256"
2014
+ },
2015
+ {
2016
+ "name": "withdrawSig",
2017
+ "type": "tuple",
2018
+ "internalType": "struct EIP712Signature",
2019
+ "components": [
2020
+ {
2021
+ "name": "v",
2022
+ "type": "uint8",
2023
+ "internalType": "uint8"
2024
+ },
2025
+ {
2026
+ "name": "r",
2027
+ "type": "bytes32",
2028
+ "internalType": "bytes32"
2029
+ },
2030
+ {
2031
+ "name": "s",
2032
+ "type": "bytes32",
2033
+ "internalType": "bytes32"
2034
+ },
2035
+ {
2036
+ "name": "deadline",
2037
+ "type": "uint256",
2038
+ "internalType": "uint256"
2039
+ }
2040
+ ]
2041
+ }
2042
+ ]
2043
+ }
2044
+ ],
2045
+ "outputs": [],
2046
+ "stateMutability": "nonpayable"
2047
+ },
2048
+ {
2049
+ "type": "function",
2050
+ "name": "unstakeStakedReya",
2051
+ "inputs": [
2052
+ {
2053
+ "name": "inputs",
2054
+ "type": "tuple",
2055
+ "internalType": "struct UnstakeStakedReyaInputs",
2056
+ "components": [
2057
+ {
2058
+ "name": "accountId",
2059
+ "type": "uint128",
2060
+ "internalType": "uint128"
2061
+ },
2062
+ {
2063
+ "name": "shareAmount",
2064
+ "type": "uint256",
2065
+ "internalType": "uint256"
2066
+ },
2067
+ {
2068
+ "name": "minAssetAmount",
2069
+ "type": "uint256",
2070
+ "internalType": "uint256"
2071
+ },
2072
+ {
2073
+ "name": "withdrawSig",
2074
+ "type": "tuple",
2075
+ "internalType": "struct EIP712Signature",
2076
+ "components": [
2077
+ {
2078
+ "name": "v",
2079
+ "type": "uint8",
2080
+ "internalType": "uint8"
2081
+ },
2082
+ {
2083
+ "name": "r",
2084
+ "type": "bytes32",
2085
+ "internalType": "bytes32"
2086
+ },
2087
+ {
2088
+ "name": "s",
2089
+ "type": "bytes32",
2090
+ "internalType": "bytes32"
2091
+ },
2092
+ {
2093
+ "name": "deadline",
2094
+ "type": "uint256",
2095
+ "internalType": "uint256"
2096
+ }
2097
+ ]
2098
+ }
2099
+ ]
2100
+ }
2101
+ ],
2102
+ "outputs": [],
2103
+ "stateMutability": "nonpayable"
2104
+ },
1872
2105
  {
1873
2106
  "type": "error",
1874
2107
  "name": "ValueAlreadyInSet",
@@ -7,6 +7,7 @@ export { abi as PeripheryAbi } from './abis/Periphery.json';
7
7
  export { abi as Socket_VaultWithPayloadAbi } from './abis/socket/VaultWithPayload.json';
8
8
  export { abi as OrdersGatewayAbi } from './abis/OrdersGateway.json';
9
9
  export { abi as PassivePerpAbi } from './abis/PassivePerpProxy.json';
10
+ export { abi as OFTAbi } from './abis/OFT.json';
10
11
  export * from './contractAddresses';
11
12
  export * from './routerCommands';
12
13
  export * from './sign';
package/src/types.ts CHANGED
@@ -586,6 +586,7 @@ export type TokenInfo = {
586
586
  isElixirToken?: boolean;
587
587
  isLmToken?: boolean;
588
588
  isPoolToken?: boolean;
589
+ isOFT?: boolean;
589
590
  };
590
591
 
591
592
  export type GetReyaCheckerResult = {
@@ -1063,6 +1064,8 @@ export type AssetPair =
1063
1064
  | 'REYALM#HEDGEUSDC'
1064
1065
  | 'SRUSDRUSD_RR'
1065
1066
  | 'REYAPOOL#1'
1067
+ | 'REYARUSD'
1068
+ | 'SREYARUSD'
1066
1069
  | 'ETHUSDMARK'
1067
1070
  | 'BTCUSDMARK'
1068
1071
  | 'SOLUSDMARK'
@@ -531,8 +531,93 @@ export const calculatePositionAdjustedQty = (
531
531
  };
532
532
 
533
533
  /**
534
- * Note: This function assumes all the inputs are scaled by 10^18.
534
+ * Linearly interpolate a depth ratio from a (thresholds, ratios) curve.
535
+ * The curve implicitly starts at (exposure=0, ratio=1.0).
536
+ * - Between thresholds: linear interpolation
537
+ * - Above last threshold: last ratio (flat extrapolation)
538
+ *
539
+ * @param thresholds - Sorted ascending exposure thresholds in notional USD (must be non-empty)
540
+ * @param ratios - Depth ratio at each threshold (same length as thresholds, must be non-empty)
541
+ * @param exposure - Absolute exposure notional (must be >= 0)
542
+ * @throws if thresholds or ratios are empty, or if they have different lengths
535
543
  */
544
+ export const interpolateDepthRatio = (
545
+ thresholds: number[],
546
+ ratios: number[],
547
+ exposure: number,
548
+ ): number => {
549
+ if (exposure < 0) {
550
+ throw new Error('interpolateDepthRatio: exposure must be >= 0');
551
+ }
552
+ if (thresholds.length === 0 || ratios.length === 0) {
553
+ throw new Error(
554
+ 'interpolateDepthRatio: thresholds and ratios must be non-empty',
555
+ );
556
+ }
557
+ if (thresholds.length !== ratios.length) {
558
+ throw new Error(
559
+ 'interpolateDepthRatio: thresholds and ratios must have equal length',
560
+ );
561
+ }
562
+
563
+ const allThresholds = [0, ...thresholds];
564
+ const allRatios = [1.0, ...ratios];
565
+
566
+ if (exposure === 0) return 1.0;
567
+ if (exposure >= allThresholds[allThresholds.length - 1]) {
568
+ return allRatios[allRatios.length - 1];
569
+ }
570
+
571
+ for (let i = 0; i < allThresholds.length - 1; i++) {
572
+ if (exposure <= allThresholds[i + 1]) {
573
+ const t =
574
+ (exposure - allThresholds[i]) /
575
+ (allThresholds[i + 1] - allThresholds[i]);
576
+ return allRatios[i] + t * (allRatios[i + 1] - allRatios[i]);
577
+ }
578
+ }
579
+
580
+ throw new Error('interpolateDepthRatio: unreachable');
581
+ };
582
+
583
+ /**
584
+ * Calculate the dynamic depth factor for a trade given pool state and config.
585
+ *
586
+ * The pool takes the opposite side of the trade, so:
587
+ * poolNotionalAfterTrade = currentPoolNotional - signedTradeNotional
588
+ *
589
+ * The depth ratio is interpolated from the exposure curve, then multiplied
590
+ * by baseDepth to produce the final depth factor.
591
+ *
592
+ * @param baseDepth - Base depth multiplier for this market
593
+ * @param thresholds - Sorted ascending exposure thresholds (notional USD)
594
+ * @param ratios - Depth ratio at each threshold
595
+ * @param currentPoolNotional - Pool's current notional in this market (signed)
596
+ * @param signedTradeNotional - Trade notional (positive=buy, negative=sell)
597
+ */
598
+ export const calculateDynamicDepthFactor = ({
599
+ baseDepth,
600
+ thresholds,
601
+ ratios,
602
+ currentPoolNotional,
603
+ signedTradeNotional,
604
+ }: {
605
+ baseDepth: number;
606
+ thresholds: number[];
607
+ ratios: number[];
608
+ currentPoolNotional: number;
609
+ signedTradeNotional: number;
610
+ }): number => {
611
+ const poolNotionalAfterTrade = currentPoolNotional - signedTradeNotional;
612
+ const absExposureNotional = Math.abs(poolNotionalAfterTrade);
613
+ const depthRatio = interpolateDepthRatio(
614
+ thresholds,
615
+ ratios,
616
+ absExposureNotional,
617
+ );
618
+ return depthRatio * baseDepth;
619
+ };
620
+
536
621
  export const calculatePositionAdlPnL = ({
537
622
  marketTrackerAdlUnwindPrice,
538
623
  marketTrackerBaseMultiplier,
@@ -13,3 +13,4 @@ export * from './whitelisted-wallets';
13
13
  export * from './stringify';
14
14
  export * from './delay';
15
15
  export * from './transaction-receipt';
16
+ export * from './layerzero';
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './oft-config';
@@ -0,0 +1,32 @@
1
+ import { MoneyInOutChainId, ReyaChainId, TokenName } from '../../types';
2
+ import { getTokenInfoByName } from '../token/token-info-getters';
3
+
4
+ export const getLzEndpointId = (
5
+ chainId: MoneyInOutChainId | ReyaChainId,
6
+ ): number => {
7
+ const chainToLzEid: Record<number, number> = {
8
+ [MoneyInOutChainId.ethereumMainnet]: 30101,
9
+ [MoneyInOutChainId.ethereumSepolia]: 40161,
10
+ [ReyaChainId.reyaNetwork]: 30313,
11
+ [ReyaChainId.reyaCronos]: 40319,
12
+ };
13
+
14
+ const lzEid = chainToLzEid[chainId];
15
+ if (!lzEid) {
16
+ throw new Error(`No LayerZero endpoint ID found for chain ${chainId}`);
17
+ }
18
+ return lzEid;
19
+ };
20
+
21
+ export const getOFTTokenAddress = (
22
+ tokenName: TokenName,
23
+ chainId: MoneyInOutChainId | ReyaChainId,
24
+ ): string => {
25
+ const tokenInfo = getTokenInfoByName(tokenName, chainId);
26
+ if (!tokenInfo.isOFT) {
27
+ throw new Error(
28
+ `getOFTTokenAddress: token ${tokenName} on chain ${chainId} is not an OFT token`,
29
+ );
30
+ }
31
+ return tokenInfo.address;
32
+ };
@@ -0,0 +1,25 @@
1
+ export type OFTSendParam = {
2
+ dstEid: number;
3
+ to: string;
4
+ amountLD: bigint;
5
+ minAmountLD: bigint;
6
+ extraOptions: string;
7
+ composeMsg: string;
8
+ oftCmd: string;
9
+ };
10
+
11
+ export type OFTMessagingFee = {
12
+ nativeFee: bigint;
13
+ lzTokenFee: bigint;
14
+ };
15
+
16
+ export type OFTMessagingReceipt = {
17
+ guid: string;
18
+ nonce: bigint;
19
+ fee: OFTMessagingFee;
20
+ };
21
+
22
+ export type OFTReceipt = {
23
+ amountSentLD: bigint;
24
+ amountReceivedLD: bigint;
25
+ };