@reyaxyz/common 0.46.1 → 0.48.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/dist/services/getSocketAddresses.js +74 -52
- package/dist/services/getSocketAddresses.js.map +1 -1
- package/dist/types/services/getSocketAddresses.d.ts +7 -1
- package/dist/types/services/getSocketAddresses.d.ts.map +1 -1
- package/dist/types/types.d.ts +17 -3
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/consts.d.ts +0 -7
- package/dist/types/utils/consts.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/network.d.ts +4 -0
- package/dist/types/utils/network.d.ts.map +1 -0
- package/dist/types/utils/token-info.d.ts +3 -0
- package/dist/types/utils/token-info.d.ts.map +1 -0
- package/dist/types/utils/token.d.ts +3 -6
- package/dist/types/utils/token.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/consts.js +1 -76
- package/dist/utils/consts.js.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/network.js +25 -0
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/socket/reyaCronos.json +77 -0
- package/dist/utils/token-info.js +77 -0
- package/dist/utils/token-info.js.map +1 -0
- package/dist/utils/token.js +38 -20
- package/dist/utils/token.js.map +1 -1
- package/package.json +2 -2
- package/src/services/getSocketAddresses.ts +113 -67
- package/src/types.ts +19 -3
- package/src/utils/consts.ts +0 -90
- package/src/utils/index.ts +1 -0
- package/src/utils/network.ts +23 -0
- package/src/utils/socket/reyaCronos.json +77 -0
- package/src/utils/token-info.ts +75 -0
- package/src/utils/token.ts +62 -24
package/src/utils/consts.ts
CHANGED
|
@@ -1,92 +1,2 @@
|
|
|
1
|
-
import { Address } from '../types';
|
|
2
|
-
|
|
3
1
|
export const MAX_UINT128 = 2 ** 128 - 1;
|
|
4
|
-
|
|
5
2
|
export const API_TIMEOUT: number = 2500;
|
|
6
|
-
|
|
7
|
-
// todo-token must add addresses of all tokens from all chains below (reya and source chains)
|
|
8
|
-
|
|
9
|
-
// @todo update values for mainnet
|
|
10
|
-
export const tokenDetails: {
|
|
11
|
-
[address: Address]: {
|
|
12
|
-
tokenName: Uppercase<string>;
|
|
13
|
-
tokenDecimals: number;
|
|
14
|
-
};
|
|
15
|
-
} = {
|
|
16
|
-
// ====== USDC ======
|
|
17
|
-
// mumbai
|
|
18
|
-
'0xd9edcc943ed9729b08e52bb1e110fe43d1930773': {
|
|
19
|
-
tokenName: 'USDC',
|
|
20
|
-
tokenDecimals: 6,
|
|
21
|
-
},
|
|
22
|
-
// arbitrum sepolia
|
|
23
|
-
'0x8537307810fc40f4073a12a38554d4ff78efff41': {
|
|
24
|
-
tokenName: 'USDC',
|
|
25
|
-
tokenDecimals: 6,
|
|
26
|
-
},
|
|
27
|
-
// op sepolia
|
|
28
|
-
'0x6d290609b3f5f02d52f28d97c75a443ed8564cbf': {
|
|
29
|
-
tokenName: 'USDC',
|
|
30
|
-
tokenDecimals: 6,
|
|
31
|
-
},
|
|
32
|
-
// ethereum sepolia
|
|
33
|
-
'0x565810cbfa3cf1390963e5afa2fb953795686339': {
|
|
34
|
-
tokenName: 'USDC',
|
|
35
|
-
tokenDecimals: 6,
|
|
36
|
-
},
|
|
37
|
-
// reya cronos
|
|
38
|
-
'0x1b700a40a0707dd5f0bc31cbc57d730558e5714d': {
|
|
39
|
-
tokenName: 'USDC',
|
|
40
|
-
tokenDecimals: 6,
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
// ====== wETH ======
|
|
44
|
-
// mumbai
|
|
45
|
-
'0xc199807af4fedb02ee567ed0feb814a077de4802': {
|
|
46
|
-
tokenName: 'WETH',
|
|
47
|
-
tokenDecimals: 18,
|
|
48
|
-
},
|
|
49
|
-
// reya cronos
|
|
50
|
-
'0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2': {
|
|
51
|
-
tokenName: 'WETH',
|
|
52
|
-
tokenDecimals: 18,
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
// ====== wBTC ======
|
|
56
|
-
// mumbai
|
|
57
|
-
'0x2fa2e7a6deb7bb51b625336dbe1da23511914a8a': {
|
|
58
|
-
tokenName: 'WBTC',
|
|
59
|
-
tokenDecimals: 8,
|
|
60
|
-
},
|
|
61
|
-
// mainnet
|
|
62
|
-
'0xaf21abab55a7c0ab143e0379a3c01054e4ebb514': {
|
|
63
|
-
tokenName: 'WBTC',
|
|
64
|
-
tokenDecimals: 8,
|
|
65
|
-
},
|
|
66
|
-
// reya orbit testnet
|
|
67
|
-
'0xd382e2f0df859ff9e82f963dcad1aaee939c5e4f': {
|
|
68
|
-
tokenName: 'WBTC',
|
|
69
|
-
tokenDecimals: 8,
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
// ====== USDT ======
|
|
73
|
-
// reya cronos
|
|
74
|
-
'0x9ade781dacbd220f0161d98f496a2982b231a9d6': {
|
|
75
|
-
tokenName: 'USDT',
|
|
76
|
-
tokenDecimals: 6,
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
// ====== dai ======
|
|
80
|
-
// reya cronos
|
|
81
|
-
'0x733299259c45726ee1bfc9bd0deeba58e48a1853': {
|
|
82
|
-
tokenName: 'DAI',
|
|
83
|
-
tokenDecimals: 18,
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
// ====== rUSD ======
|
|
87
|
-
// reya cronos
|
|
88
|
-
'0xcfbb14b2a2acb5779b6365a260e4a9d63a12100b': {
|
|
89
|
-
tokenName: 'RUSD',
|
|
90
|
-
tokenDecimals: 6,
|
|
91
|
-
},
|
|
92
|
-
};
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MoneyInOutChainId, ReyaChainId } from '../types';
|
|
2
|
+
|
|
3
|
+
export function getReyaNetwork(env: 'production' | 'test'): ReyaChainId {
|
|
4
|
+
if (env === 'production') return ReyaChainId.reyaNetwork;
|
|
5
|
+
if (env === 'test') return ReyaChainId.reyaCronos;
|
|
6
|
+
|
|
7
|
+
throw new Error('Unknown error passed');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getReyaNetworkFromMoneyInOutChainId(
|
|
11
|
+
moneyInOutChainId: MoneyInOutChainId,
|
|
12
|
+
): ReyaChainId {
|
|
13
|
+
switch (moneyInOutChainId) {
|
|
14
|
+
case MoneyInOutChainId.polygonMumbai:
|
|
15
|
+
case MoneyInOutChainId.arbitrumSepolia:
|
|
16
|
+
case MoneyInOutChainId.opSepolia:
|
|
17
|
+
case MoneyInOutChainId.ethereumSepolia:
|
|
18
|
+
return getReyaNetwork('test');
|
|
19
|
+
|
|
20
|
+
default:
|
|
21
|
+
throw new Error('getReyaNetwork: unexpected moneyInOutChainId');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"80001": {
|
|
3
|
+
"USDC": {
|
|
4
|
+
"isAppChain": false,
|
|
5
|
+
"NonMintableToken": "0xD9edcC943ed9729B08E52Bb1e110FE43d1930773",
|
|
6
|
+
"Vault": "0xEC5b7075F581D46983EBe2Be6baB0f58Bf1E8C4b",
|
|
7
|
+
"connectors": {
|
|
8
|
+
"89346161": {
|
|
9
|
+
"FAST": "0xF5541Ea3ee034D8f7C397bf77556f07e7562dF9A"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"ExecutionHelper": "0xA858f95c50240A6a28E5cd323869cE77ee7677Bd"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"421614": {
|
|
16
|
+
"USDC": {
|
|
17
|
+
"isAppChain": false,
|
|
18
|
+
"NonMintableToken": "0x8537307810fC40F4073A12a38554D4Ff78EfFf41",
|
|
19
|
+
"Vault": "0x85314b664cB2e443C93F09EDb51088f76b048212",
|
|
20
|
+
"connectors": {
|
|
21
|
+
"89346161": {
|
|
22
|
+
"FAST": "0x7dE4937420935c7C8767b06eCd7F7dC54e2D7C9b"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"ExecutionHelper": "0x4caE6101A2645AE58038Aeb04079621458b00753"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"11155111": {
|
|
29
|
+
"USDC": {
|
|
30
|
+
"isAppChain": false,
|
|
31
|
+
"NonMintableToken": "0x565810cbfa3Cf1390963E5aFa2fB953795686339",
|
|
32
|
+
"Vault": "0x8487daa5864a5cE18E5a89406c11EC748da33fbB",
|
|
33
|
+
"connectors": {
|
|
34
|
+
"89346161": {
|
|
35
|
+
"FAST": "0x42229a5DDC5E32149311265F6F4BC016EaB778FC"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"ExecutionHelper": "0x4F3e01e8f7d0224b5988Cb0FBf7f6D156B9255cD"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"11155420": {
|
|
42
|
+
"USDC": {
|
|
43
|
+
"isAppChain": false,
|
|
44
|
+
"NonMintableToken": "0x6D290609b3F5F02D52F28d97C75a443ED8564cBf",
|
|
45
|
+
"Vault": "0x1019958C2BD43B882a4e1349337a32Ef9563FC4D",
|
|
46
|
+
"connectors": {
|
|
47
|
+
"89346161": {
|
|
48
|
+
"FAST": "0x805Dc5ac616bCB1A59a446eb1777C0Cc3Aa0c3Fe"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"ExecutionHelper": "0xD664eF6159562190ea6D1AFa3f0Ea1C0D77D14E3"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"89346161": {
|
|
55
|
+
"USDC": {
|
|
56
|
+
"isAppChain": true,
|
|
57
|
+
"MintableToken": "0x1b700A40A0707Dd5f0BC31cbc57D730558E5714d",
|
|
58
|
+
"ExchangeRate": "0x1Aba89fC7ff67D27ccaa51893c46FD1e5fEE924B",
|
|
59
|
+
"Controller": "0x663dc7E91157c58079f55C1BF5ee1BdB6401Ca7a",
|
|
60
|
+
"connectors": {
|
|
61
|
+
"80001": {
|
|
62
|
+
"FAST": "0x54CAA0946dA179425e1abB169C020004284d64D3"
|
|
63
|
+
},
|
|
64
|
+
"421614": {
|
|
65
|
+
"FAST": "0xd7627d03dEA4006cBe8E701F6932dBF75d3269B3"
|
|
66
|
+
},
|
|
67
|
+
"11155111": {
|
|
68
|
+
"FAST": "0xdA089249ccE9d9726Fa6b755c5ec3d9C260C90C2"
|
|
69
|
+
},
|
|
70
|
+
"11155420": {
|
|
71
|
+
"FAST": "0x11695Ff9EE5E600b90BcbD651D1758A9B240A2d8"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"ExecutionHelper": "0xB6fb3062405985F700fa23758A3053162ddBeFb9"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { MoneyInOutChainId, ReyaChainId, TokenInfo } from '../types';
|
|
2
|
+
|
|
3
|
+
export const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =
|
|
4
|
+
{
|
|
5
|
+
/* ------------------------------------------------------ */
|
|
6
|
+
/* MAINNET */
|
|
7
|
+
/* ------------------------------------------------------ */
|
|
8
|
+
[ReyaChainId.reyaNetwork]: [
|
|
9
|
+
// todo
|
|
10
|
+
],
|
|
11
|
+
|
|
12
|
+
/* ------------------------------------------------------ */
|
|
13
|
+
/* TESTNET */
|
|
14
|
+
/* ------------------------------------------------------ */
|
|
15
|
+
[ReyaChainId.reyaCronos]: [
|
|
16
|
+
{
|
|
17
|
+
name: 'RUSD',
|
|
18
|
+
address: '0xcfbb14b2a2acb5779b6365a260e4a9d63a12100b',
|
|
19
|
+
decimals: 6,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'USDC',
|
|
23
|
+
address: '0x1b700a40a0707dd5f0bc31cbc57d730558e5714d',
|
|
24
|
+
decimals: 6,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'USDT',
|
|
28
|
+
address: '0x9ade781dacbd220f0161d98f496a2982b231a9d6',
|
|
29
|
+
decimals: 6,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'DAI',
|
|
33
|
+
address: '0x733299259c45726ee1bfc9bd0deeba58e48a1853',
|
|
34
|
+
decimals: 18,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'WETH',
|
|
38
|
+
address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',
|
|
39
|
+
decimals: 18,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'WBTC',
|
|
43
|
+
address: '0xd382e2f0df859ff9e82f963dcad1aaee939c5e4f',
|
|
44
|
+
decimals: 8,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
[MoneyInOutChainId.polygonMumbai]: [
|
|
48
|
+
{
|
|
49
|
+
name: 'USDC',
|
|
50
|
+
address: '0xd9edcc943ed9729b08e52bb1e110fe43d1930773',
|
|
51
|
+
decimals: 6,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
[MoneyInOutChainId.arbitrumSepolia]: [
|
|
55
|
+
{
|
|
56
|
+
name: 'USDC',
|
|
57
|
+
address: '0x8537307810fc40f4073a12a38554d4ff78efff41',
|
|
58
|
+
decimals: 6,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
[MoneyInOutChainId.opSepolia]: [
|
|
62
|
+
{
|
|
63
|
+
name: 'USDC',
|
|
64
|
+
address: '0x6d290609b3f5f02d52f28d97c75a443ed8564cbf',
|
|
65
|
+
decimals: 6,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
[MoneyInOutChainId.ethereumSepolia]: [
|
|
69
|
+
{
|
|
70
|
+
name: 'USDC',
|
|
71
|
+
address: '0x565810cbfa3cf1390963e5afa2fb953795686339',
|
|
72
|
+
decimals: 6,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
package/src/utils/token.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
|
|
3
3
|
import { Contract, Signer } from 'ethers';
|
|
4
|
-
import {
|
|
4
|
+
import { TOKEN_INFO } from './token-info';
|
|
5
5
|
import { exponentialBackoff } from './retry';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
Address,
|
|
8
|
+
GetERC20AllowanceParams,
|
|
9
|
+
MoneyInOutChainId,
|
|
10
|
+
ReyaChainId,
|
|
11
|
+
TokenInfo,
|
|
12
|
+
TokenName,
|
|
13
|
+
} from '../types';
|
|
7
14
|
|
|
8
15
|
export const descale = (tokenDecimals: number) => {
|
|
9
16
|
const f = (value: bigint) => {
|
|
@@ -43,26 +50,57 @@ export const convertToAddress = (str: string): Address => {
|
|
|
43
50
|
return str.toLowerCase() as Address;
|
|
44
51
|
};
|
|
45
52
|
|
|
46
|
-
export const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
53
|
+
export const getTokenInfoByAddress = (
|
|
54
|
+
tokenAddressParam: Address | string,
|
|
55
|
+
chainId?: ReyaChainId | MoneyInOutChainId,
|
|
56
|
+
): TokenInfo => {
|
|
57
|
+
const tokenAddress =
|
|
58
|
+
typeof tokenAddressParam === 'string'
|
|
59
|
+
? convertToAddress(tokenAddressParam)
|
|
60
|
+
: tokenAddressParam;
|
|
61
|
+
|
|
62
|
+
if (chainId) {
|
|
63
|
+
const tokenInfo = TOKEN_INFO[chainId].find(
|
|
64
|
+
(tokenInfo) => tokenInfo.address === tokenAddress,
|
|
65
|
+
);
|
|
66
|
+
if (!tokenInfo) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`getTokenInfoByAddress: no token info found [chainId ${chainId}, token address ${tokenAddress}]`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return tokenInfo;
|
|
72
|
+
} else {
|
|
73
|
+
for (const chainId in TOKEN_INFO) {
|
|
74
|
+
const tokenInfos =
|
|
75
|
+
TOKEN_INFO[chainId as unknown as keyof typeof TOKEN_INFO];
|
|
76
|
+
const tokenInfo = tokenInfos.find(
|
|
77
|
+
(tokenInfo) => tokenInfo.address === tokenAddress,
|
|
78
|
+
);
|
|
79
|
+
if (tokenInfo) {
|
|
80
|
+
return tokenInfo;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw new Error(
|
|
84
|
+
`getTokenInfoByAddress: no token info found [token address ${tokenAddress}]`,
|
|
85
|
+
);
|
|
57
86
|
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const getTokenInfoByName = (
|
|
90
|
+
tokenName: TokenName,
|
|
91
|
+
chainId: ReyaChainId | MoneyInOutChainId,
|
|
92
|
+
): TokenInfo => {
|
|
93
|
+
const tokenInfo = TOKEN_INFO[chainId].find(
|
|
94
|
+
(tokenInfo) => tokenInfo.name === tokenName,
|
|
95
|
+
);
|
|
58
96
|
|
|
59
|
-
|
|
97
|
+
if (!tokenInfo) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`getTokenInfoByName: no token info found [chain id ${chainId}, token name ${tokenName}]`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
60
102
|
|
|
61
|
-
return
|
|
62
|
-
tokenName,
|
|
63
|
-
tokenDecimals,
|
|
64
|
-
tokenDescaler: descale(tokenDecimals),
|
|
65
|
-
};
|
|
103
|
+
return tokenInfo;
|
|
66
104
|
};
|
|
67
105
|
|
|
68
106
|
export const getERC20Allowance = async ({
|
|
@@ -72,15 +110,15 @@ export const getERC20Allowance = async ({
|
|
|
72
110
|
subject,
|
|
73
111
|
}: GetERC20AllowanceParams): Promise<number> => {
|
|
74
112
|
const tokenContract = getERC20TokenContract(tokenAddress, subject);
|
|
75
|
-
const
|
|
113
|
+
const tokenInfo = getTokenInfoByAddress(tokenAddress);
|
|
76
114
|
|
|
77
115
|
const allowance = await exponentialBackoff(() =>
|
|
78
116
|
tokenContract.allowance(walletAddress, spenderAddress),
|
|
79
117
|
);
|
|
80
118
|
|
|
81
|
-
return BigInt(allowance) > scale(
|
|
119
|
+
return BigInt(allowance) > scale(tokenInfo.decimals)(Number.MAX_SAFE_INTEGER)
|
|
82
120
|
? Number.MAX_SAFE_INTEGER
|
|
83
|
-
: descale(
|
|
121
|
+
: descale(tokenInfo.decimals)(allowance);
|
|
84
122
|
};
|
|
85
123
|
|
|
86
124
|
export type GetERC20BalanceArgs = {
|
|
@@ -96,11 +134,11 @@ export const getERC20Balance = async ({
|
|
|
96
134
|
}: GetERC20BalanceArgs): Promise<number> => {
|
|
97
135
|
const token = getERC20TokenContract(tokenAddress, subject);
|
|
98
136
|
|
|
99
|
-
const
|
|
137
|
+
const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));
|
|
100
138
|
|
|
101
139
|
const currentBalance = await exponentialBackoff(() =>
|
|
102
140
|
token.balanceOf(walletAddress),
|
|
103
141
|
);
|
|
104
142
|
|
|
105
|
-
return
|
|
143
|
+
return descale(tokenInfo.decimals)(currentBalance);
|
|
106
144
|
};
|