@reyaxyz/common 0.47.0 → 0.48.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.
Files changed (37) hide show
  1. package/dist/services/getSocketAddresses.js +74 -52
  2. package/dist/services/getSocketAddresses.js.map +1 -1
  3. package/dist/types/services/getSocketAddresses.d.ts +7 -1
  4. package/dist/types/services/getSocketAddresses.d.ts.map +1 -1
  5. package/dist/types/types.d.ts +9 -3
  6. package/dist/types/types.d.ts.map +1 -1
  7. package/dist/types/utils/consts.d.ts +0 -7
  8. package/dist/types/utils/consts.d.ts.map +1 -1
  9. package/dist/types/utils/index.d.ts +1 -0
  10. package/dist/types/utils/index.d.ts.map +1 -1
  11. package/dist/types/utils/network.d.ts +4 -0
  12. package/dist/types/utils/network.d.ts.map +1 -0
  13. package/dist/types/utils/token-info.d.ts +3 -0
  14. package/dist/types/utils/token-info.d.ts.map +1 -0
  15. package/dist/types/utils/token.d.ts +3 -6
  16. package/dist/types/utils/token.d.ts.map +1 -1
  17. package/dist/types.js.map +1 -1
  18. package/dist/utils/consts.js +1 -76
  19. package/dist/utils/consts.js.map +1 -1
  20. package/dist/utils/index.js +1 -0
  21. package/dist/utils/index.js.map +1 -1
  22. package/dist/utils/network.js +25 -0
  23. package/dist/utils/network.js.map +1 -0
  24. package/dist/utils/socket/reyaCronos.json +77 -0
  25. package/dist/utils/token-info.js +77 -0
  26. package/dist/utils/token-info.js.map +1 -0
  27. package/dist/utils/token.js +38 -20
  28. package/dist/utils/token.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/services/getSocketAddresses.ts +121 -67
  31. package/src/types.ts +10 -3
  32. package/src/utils/consts.ts +0 -90
  33. package/src/utils/index.ts +1 -0
  34. package/src/utils/network.ts +23 -0
  35. package/src/utils/socket/reyaCronos.json +77 -0
  36. package/src/utils/token-info.ts +75 -0
  37. package/src/utils/token.ts +62 -24
@@ -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,77 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.TOKEN_INFO = void 0;
5
+ var types_1 = require("../types");
6
+ exports.TOKEN_INFO = (_a = {},
7
+ /* ------------------------------------------------------ */
8
+ /* MAINNET */
9
+ /* ------------------------------------------------------ */
10
+ _a[types_1.ReyaChainId.reyaNetwork] = [
11
+ // todo
12
+ ],
13
+ /* ------------------------------------------------------ */
14
+ /* TESTNET */
15
+ /* ------------------------------------------------------ */
16
+ _a[types_1.ReyaChainId.reyaCronos] = [
17
+ {
18
+ name: 'RUSD',
19
+ address: '0xcfbb14b2a2acb5779b6365a260e4a9d63a12100b',
20
+ decimals: 6,
21
+ },
22
+ {
23
+ name: 'USDC',
24
+ address: '0x1b700a40a0707dd5f0bc31cbc57d730558e5714d',
25
+ decimals: 6,
26
+ },
27
+ {
28
+ name: 'USDT',
29
+ address: '0x9ade781dacbd220f0161d98f496a2982b231a9d6',
30
+ decimals: 6,
31
+ },
32
+ {
33
+ name: 'DAI',
34
+ address: '0x733299259c45726ee1bfc9bd0deeba58e48a1853',
35
+ decimals: 18,
36
+ },
37
+ {
38
+ name: 'WETH',
39
+ address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',
40
+ decimals: 18,
41
+ },
42
+ {
43
+ name: 'WBTC',
44
+ address: '0xd382e2f0df859ff9e82f963dcad1aaee939c5e4f',
45
+ decimals: 8,
46
+ },
47
+ ],
48
+ _a[types_1.MoneyInOutChainId.polygonMumbai] = [
49
+ {
50
+ name: 'USDC',
51
+ address: '0xd9edcc943ed9729b08e52bb1e110fe43d1930773',
52
+ decimals: 6,
53
+ },
54
+ ],
55
+ _a[types_1.MoneyInOutChainId.arbitrumSepolia] = [
56
+ {
57
+ name: 'USDC',
58
+ address: '0x8537307810fc40f4073a12a38554d4ff78efff41',
59
+ decimals: 6,
60
+ },
61
+ ],
62
+ _a[types_1.MoneyInOutChainId.opSepolia] = [
63
+ {
64
+ name: 'USDC',
65
+ address: '0x6d290609b3f5f02d52f28d97c75a443ed8564cbf',
66
+ decimals: 6,
67
+ },
68
+ ],
69
+ _a[types_1.MoneyInOutChainId.ethereumSepolia] = [
70
+ {
71
+ name: 'USDC',
72
+ address: '0x565810cbfa3cf1390963e5afa2fb953795686339',
73
+ decimals: 6,
74
+ },
75
+ ],
76
+ _a);
77
+ //# sourceMappingURL=token-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-info.js","sourceRoot":"/","sources":["utils/token-info.ts"],"names":[],"mappings":";;;;AAAA,kCAAqE;AAExD,QAAA,UAAU;IAEnB,4DAA4D;IAC5D,4DAA4D;IAC5D,4DAA4D;IAC5D,GAAC,mBAAW,CAAC,WAAW,IAAG;IACzB,OAAO;KACR;IAED,4DAA4D;IAC5D,4DAA4D;IAC5D,4DAA4D;IAC5D,GAAC,mBAAW,CAAC,UAAU,IAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;QACD;YACE,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;KACF;IACD,GAAC,yBAAiB,CAAC,aAAa,IAAG;QACjC;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;KACF;IACD,GAAC,yBAAiB,CAAC,eAAe,IAAG;QACnC;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;KACF;IACD,GAAC,yBAAiB,CAAC,SAAS,IAAG;QAC7B;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;KACF;IACD,GAAC,yBAAiB,CAAC,eAAe,IAAG;QACnC;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,CAAC;SACZ;KACF;QACD","sourcesContent":["import { MoneyInOutChainId, ReyaChainId, TokenInfo } from '../types';\n\nexport const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =\n {\n /* ------------------------------------------------------ */\n /* MAINNET */\n /* ------------------------------------------------------ */\n [ReyaChainId.reyaNetwork]: [\n // todo\n ],\n\n /* ------------------------------------------------------ */\n /* TESTNET */\n /* ------------------------------------------------------ */\n [ReyaChainId.reyaCronos]: [\n {\n name: 'RUSD',\n address: '0xcfbb14b2a2acb5779b6365a260e4a9d63a12100b',\n decimals: 6,\n },\n {\n name: 'USDC',\n address: '0x1b700a40a0707dd5f0bc31cbc57d730558e5714d',\n decimals: 6,\n },\n {\n name: 'USDT',\n address: '0x9ade781dacbd220f0161d98f496a2982b231a9d6',\n decimals: 6,\n },\n {\n name: 'DAI',\n address: '0x733299259c45726ee1bfc9bd0deeba58e48a1853',\n decimals: 18,\n },\n {\n name: 'WETH',\n address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',\n decimals: 18,\n },\n {\n name: 'WBTC',\n address: '0xd382e2f0df859ff9e82f963dcad1aaee939c5e4f',\n decimals: 8,\n },\n ],\n [MoneyInOutChainId.polygonMumbai]: [\n {\n name: 'USDC',\n address: '0xd9edcc943ed9729b08e52bb1e110fe43d1930773',\n decimals: 6,\n },\n ],\n [MoneyInOutChainId.arbitrumSepolia]: [\n {\n name: 'USDC',\n address: '0x8537307810fc40f4073a12a38554d4ff78efff41',\n decimals: 6,\n },\n ],\n [MoneyInOutChainId.opSepolia]: [\n {\n name: 'USDC',\n address: '0x6d290609b3f5f02d52f28d97c75a443ed8564cbf',\n decimals: 6,\n },\n ],\n [MoneyInOutChainId.ethereumSepolia]: [\n {\n name: 'USDC',\n address: '0x565810cbfa3cf1390963e5afa2fb953795686339',\n decimals: 6,\n },\n ],\n };\n"]}
@@ -36,10 +36,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getERC20Balance = exports.getERC20Allowance = exports.getTokenDetails = exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
39
+ exports.getERC20Balance = exports.getERC20Allowance = exports.getTokenInfoByName = exports.getTokenInfoByAddress = exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
40
40
  var ethers_1 = require("ethers");
41
41
  var ethers_2 = require("ethers");
42
- var consts_1 = require("./consts");
42
+ var token_info_1 = require("./token-info");
43
43
  var retry_1 = require("./retry");
44
44
  var descale = function (tokenDecimals) {
45
45
  var f = function (value) {
@@ -70,36 +70,54 @@ var convertToAddress = function (str) {
70
70
  return str.toLowerCase();
71
71
  };
72
72
  exports.convertToAddress = convertToAddress;
73
- var getTokenDetails = function (caseSensitiveAddress) {
74
- var address = (0, exports.convertToAddress)(caseSensitiveAddress);
75
- if (!Object.keys(consts_1.tokenDetails).includes(address)) {
76
- throw new Error("Token details not found for ".concat(address, "."));
73
+ var getTokenInfoByAddress = function (tokenAddressParam, chainId) {
74
+ var tokenAddress = typeof tokenAddressParam === 'string'
75
+ ? (0, exports.convertToAddress)(tokenAddressParam)
76
+ : tokenAddressParam;
77
+ if (chainId) {
78
+ var tokenInfo = token_info_1.TOKEN_INFO[chainId].find(function (tokenInfo) { return tokenInfo.address === tokenAddress; });
79
+ if (!tokenInfo) {
80
+ throw new Error("getTokenInfoByAddress: no token info found [chainId ".concat(chainId, ", token address ").concat(tokenAddress, "]"));
81
+ }
82
+ return tokenInfo;
77
83
  }
78
- var _a = consts_1.tokenDetails[address], tokenName = _a.tokenName, tokenDecimals = _a.tokenDecimals;
79
- return {
80
- tokenName: tokenName,
81
- tokenDecimals: tokenDecimals,
82
- tokenDescaler: (0, exports.descale)(tokenDecimals),
83
- };
84
+ else {
85
+ for (var chainId_1 in token_info_1.TOKEN_INFO) {
86
+ var tokenInfos = token_info_1.TOKEN_INFO[chainId_1];
87
+ var tokenInfo = tokenInfos.find(function (tokenInfo) { return tokenInfo.address === tokenAddress; });
88
+ if (tokenInfo) {
89
+ return tokenInfo;
90
+ }
91
+ }
92
+ throw new Error("getTokenInfoByAddress: no token info found [token address ".concat(tokenAddress, "]"));
93
+ }
94
+ };
95
+ exports.getTokenInfoByAddress = getTokenInfoByAddress;
96
+ var getTokenInfoByName = function (tokenName, chainId) {
97
+ var tokenInfo = token_info_1.TOKEN_INFO[chainId].find(function (tokenInfo) { return tokenInfo.name === tokenName; });
98
+ if (!tokenInfo) {
99
+ throw new Error("getTokenInfoByName: no token info found [chain id ".concat(chainId, ", token name ").concat(tokenName, "]"));
100
+ }
101
+ return tokenInfo;
84
102
  };
85
- exports.getTokenDetails = getTokenDetails;
103
+ exports.getTokenInfoByName = getTokenInfoByName;
86
104
  var getERC20Allowance = function (_a) {
87
105
  var walletAddress = _a.walletAddress, tokenAddress = _a.tokenAddress, spenderAddress = _a.spenderAddress, subject = _a.subject;
88
106
  return __awaiter(void 0, void 0, void 0, function () {
89
- var tokenContract, tokenDecimals, allowance;
107
+ var tokenContract, tokenInfo, allowance;
90
108
  return __generator(this, function (_b) {
91
109
  switch (_b.label) {
92
110
  case 0:
93
111
  tokenContract = (0, exports.getERC20TokenContract)(tokenAddress, subject);
94
- tokenDecimals = (0, exports.getTokenDetails)(tokenAddress).tokenDecimals;
112
+ tokenInfo = (0, exports.getTokenInfoByAddress)(tokenAddress);
95
113
  return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
96
114
  return tokenContract.allowance(walletAddress, spenderAddress);
97
115
  })];
98
116
  case 1:
99
117
  allowance = _b.sent();
100
- return [2 /*return*/, BigInt(allowance) > (0, exports.scale)(tokenDecimals)(Number.MAX_SAFE_INTEGER)
118
+ return [2 /*return*/, BigInt(allowance) > (0, exports.scale)(tokenInfo.decimals)(Number.MAX_SAFE_INTEGER)
101
119
  ? Number.MAX_SAFE_INTEGER
102
- : (0, exports.descale)(tokenDecimals)(allowance)];
120
+ : (0, exports.descale)(tokenInfo.decimals)(allowance)];
103
121
  }
104
122
  });
105
123
  });
@@ -108,18 +126,18 @@ exports.getERC20Allowance = getERC20Allowance;
108
126
  var getERC20Balance = function (_a) {
109
127
  var tokenAddress = _a.tokenAddress, walletAddress = _a.walletAddress, subject = _a.subject;
110
128
  return __awaiter(void 0, void 0, void 0, function () {
111
- var token, tokenDescaler, currentBalance;
129
+ var token, tokenInfo, currentBalance;
112
130
  return __generator(this, function (_b) {
113
131
  switch (_b.label) {
114
132
  case 0:
115
133
  token = (0, exports.getERC20TokenContract)(tokenAddress, subject);
116
- tokenDescaler = (0, exports.getTokenDetails)(tokenAddress).tokenDescaler;
134
+ tokenInfo = (0, exports.getTokenInfoByAddress)((0, exports.convertToAddress)(tokenAddress));
117
135
  return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
118
136
  return token.balanceOf(walletAddress);
119
137
  })];
120
138
  case 1:
121
139
  currentBalance = _b.sent();
122
- return [2 /*return*/, tokenDescaler(currentBalance)];
140
+ return [2 /*return*/, (0, exports.descale)(tokenInfo.decimals)(currentBalance)];
123
141
  }
124
142
  });
125
143
  });
@@ -1 +1 @@
1
- {"version":3,"file":"token.js","sourceRoot":"/","sources":["utils/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAEhC,iCAA0C;AAC1C,mCAAwC;AACxC,iCAA6C;AAGtC,IAAM,OAAO,GAAG,UAAC,aAAqB;IAC3C,IAAM,CAAC,GAAG,UAAC,KAAa;QACtB,OAAO,MAAM,CAAC,eAAM,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC;IAEF,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AANW,QAAA,OAAO,WAMlB;AAEK,IAAM,KAAK,GAAG,UAAC,aAAqB;IACzC,IAAM,CAAC,GAAG,UAAC,KAAa;QACtB,OAAO,MAAM,CACX,eAAM,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC,CAC/D,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AARW,QAAA,KAAK,SAQhB;AAEK,IAAM,qBAAqB,GAAG,UACnC,YAAoB,EACpB,OAAe;IAEf,IAAM,GAAG,GAAa;QACpB,4DAA4D;QAC5D,6DAA6D;QAC7D,qEAAqE;QACrE,2DAA2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B;oBAED,sBAAO,MAAM,CAAC,SAAS,CAAC,GAAG,IAAA,aAAK,EAAC,aAAa,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC;4BACtE,CAAC,CAAC,MAAM,CAAC,gBAAgB;4BACzB,CAAC,CAAC,IAAA,eAAO,EAAC,aAAa,CAAC,CAAC,SAAS,CAAC,EAAC;;;;CACvC,CAAC;AAhBW,QAAA,iBAAiB,qBAgB5B;AAQK,IAAM,eAAe,GAAG,UAAO,EAIhB;QAHpB,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,OAAO,aAAA;;;;;;oBAED,KAAK,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBAEnD,aAAa,GAAK,IAAA,uBAAe,EAAC,YAAY,CAAC,cAAlC,CAAmC;oBAEjC,qBAAM,IAAA,0BAAkB,EAAC;4BAC9C,OAAA,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC;wBAA9B,CAA8B,CAC/B,EAAA;;oBAFK,cAAc,GAAG,SAEtB;oBAED,sBAAO,aAAa,CAAC,cAAc,CAAC,EAAC;;;;CACtC,CAAC;AAdW,QAAA,eAAe,mBAc1B","sourcesContent":["import { ethers } from 'ethers';\n\nimport { Contract, Signer } from 'ethers';\nimport { tokenDetails } from './consts';\nimport { exponentialBackoff } from './retry';\nimport { Address, GetERC20AllowanceParams } from '../types';\n\nexport const descale = (tokenDecimals: number) => {\n const f = (value: bigint) => {\n return Number(ethers.formatUnits(value.toString(), tokenDecimals));\n };\n\n return f;\n};\n\nexport const scale = (tokenDecimals: number) => {\n const f = (value: number) => {\n return BigInt(\n ethers.parseUnits(value.toFixed(tokenDecimals), tokenDecimals),\n );\n };\n\n return f;\n};\n\nexport const getERC20TokenContract = (\n tokenAddress: string,\n subject: Signer,\n): Contract => {\n const abi: string[] = [\n `function approve(address, uint256) external returns (bool)`,\n `function balanceOf(address) external view returns (uint256)`,\n `function allowance(address,address) external view returns (uint256)`,\n `function approve(address,uint256) external returns (bool)`,\n ];\n\n const contract = new Contract(tokenAddress, abi, subject);\n\n return contract;\n};\n\nexport const convertToAddress = (str: string): Address => {\n return str.toLowerCase() as Address;\n};\n\nexport const getTokenDetails = (\n caseSensitiveAddress: string,\n): {\n tokenName: Uppercase<string>;\n tokenDecimals: number;\n tokenDescaler: (value: bigint) => number;\n} => {\n const address = convertToAddress(caseSensitiveAddress);\n\n if (!Object.keys(tokenDetails).includes(address)) {\n throw new Error(`Token details not found for ${address}.`);\n }\n\n const { tokenName, tokenDecimals } = tokenDetails[address];\n\n return {\n tokenName,\n tokenDecimals,\n tokenDescaler: descale(tokenDecimals),\n };\n};\n\nexport const getERC20Allowance = async ({\n walletAddress,\n tokenAddress,\n spenderAddress,\n subject,\n}: GetERC20AllowanceParams): Promise<number> => {\n const tokenContract = getERC20TokenContract(tokenAddress, subject);\n const { tokenDecimals } = getTokenDetails(tokenAddress);\n\n const allowance = await exponentialBackoff(() =>\n tokenContract.allowance(walletAddress, spenderAddress),\n );\n\n return BigInt(allowance) > scale(tokenDecimals)(Number.MAX_SAFE_INTEGER)\n ? Number.MAX_SAFE_INTEGER\n : descale(tokenDecimals)(allowance);\n};\n\nexport type GetERC20BalanceArgs = {\n tokenAddress: string;\n walletAddress: string;\n subject: Signer;\n};\n\nexport const getERC20Balance = async ({\n tokenAddress,\n walletAddress,\n subject,\n}: GetERC20BalanceArgs): Promise<number> => {\n const token = getERC20TokenContract(tokenAddress, subject);\n\n const { tokenDescaler } = getTokenDetails(tokenAddress);\n\n const currentBalance = await exponentialBackoff(() =>\n token.balanceOf(walletAddress),\n );\n\n return tokenDescaler(currentBalance);\n};\n"]}
1
+ {"version":3,"file":"token.js","sourceRoot":"/","sources":["utils/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAEhC,iCAA0C;AAC1C,2CAA0C;AAC1C,iCAA6C;AAUtC,IAAM,OAAO,GAAG,UAAC,aAAqB;I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,OAAO,CAAC,CAAC;oBAC7D,SAAS,GAAG,IAAA,6BAAqB,EAAC,YAAY,CAAC,CAAC;oBAEpC,qBAAM,IAAA,0BAAkB,EAAC;4BACzC,OAAA,aAAa,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC;wBAAtD,CAAsD,CACvD,EAAA;;oBAFK,SAAS,GAAG,SAEjB;oBAED,sBAAO,MAAM,CAAC,SAAS,CAAC,GAAG,IAAA,aAAK,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC;4BAC3E,CAAC,CAAC,MAAM,CAAC,gBAAgB;4BACzB,CAAC,CAAC,IAAA,eAAO,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAC;;;;CAC5C,CAAC;AAhBW,QAAA,iBAAiB,qBAgB5B;AAQK,IAAM,eAAe,GAAG,UAAO,EAIhB;QAHpB,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,OAAO,aAAA;;;;;;oBAED,KAAK,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBAErD,SAAS,GAAG,IAAA,6BAAqB,EAAC,IAAA,wBAAgB,EAAC,YAAY,CAAC,CAAC,CAAC;oBAEjD,qBAAM,IAAA,0BAAkB,EAAC;4BAC9C,OAAA,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC;wBAA9B,CAA8B,CAC/B,EAAA;;oBAFK,cAAc,GAAG,SAEtB;oBAED,sBAAO,IAAA,eAAO,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAC;;;;CACpD,CAAC;AAdW,QAAA,eAAe,mBAc1B","sourcesContent":["import { ethers } from 'ethers';\n\nimport { Contract, Signer } from 'ethers';\nimport { TOKEN_INFO } from './token-info';\nimport { exponentialBackoff } from './retry';\nimport {\n Address,\n GetERC20AllowanceParams,\n MoneyInOutChainId,\n ReyaChainId,\n TokenInfo,\n TokenName,\n} from '../types';\n\nexport const descale = (tokenDecimals: number) => {\n const f = (value: bigint) => {\n return Number(ethers.formatUnits(value.toString(), tokenDecimals));\n };\n\n return f;\n};\n\nexport const scale = (tokenDecimals: number) => {\n const f = (value: number) => {\n return BigInt(\n ethers.parseUnits(value.toFixed(tokenDecimals), tokenDecimals),\n );\n };\n\n return f;\n};\n\nexport const getERC20TokenContract = (\n tokenAddress: string,\n subject: Signer,\n): Contract => {\n const abi: string[] = [\n `function approve(address, uint256) external returns (bool)`,\n `function balanceOf(address) external view returns (uint256)`,\n `function allowance(address,address) external view returns (uint256)`,\n `function approve(address,uint256) external returns (bool)`,\n ];\n\n const contract = new Contract(tokenAddress, abi, subject);\n\n return contract;\n};\n\nexport const convertToAddress = (str: string): Address => {\n return str.toLowerCase() as Address;\n};\n\nexport const getTokenInfoByAddress = (\n tokenAddressParam: Address | string,\n chainId?: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenAddress =\n typeof tokenAddressParam === 'string'\n ? convertToAddress(tokenAddressParam)\n : tokenAddressParam;\n\n if (chainId) {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.address === tokenAddress,\n );\n if (!tokenInfo) {\n throw new Error(\n `getTokenInfoByAddress: no token info found [chainId ${chainId}, token address ${tokenAddress}]`,\n );\n }\n return tokenInfo;\n } else {\n for (const chainId in TOKEN_INFO) {\n const tokenInfos =\n TOKEN_INFO[chainId as unknown as keyof typeof TOKEN_INFO];\n const tokenInfo = tokenInfos.find(\n (tokenInfo) => tokenInfo.address === tokenAddress,\n );\n if (tokenInfo) {\n return tokenInfo;\n }\n }\n throw new Error(\n `getTokenInfoByAddress: no token info found [token address ${tokenAddress}]`,\n );\n }\n};\n\nexport const getTokenInfoByName = (\n tokenName: TokenName,\n chainId: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.name === tokenName,\n );\n\n if (!tokenInfo) {\n throw new Error(\n `getTokenInfoByName: no token info found [chain id ${chainId}, token name ${tokenName}]`,\n );\n }\n\n return tokenInfo;\n};\n\nexport const getERC20Allowance = async ({\n walletAddress,\n tokenAddress,\n spenderAddress,\n subject,\n}: GetERC20AllowanceParams): Promise<number> => {\n const tokenContract = getERC20TokenContract(tokenAddress, subject);\n const tokenInfo = getTokenInfoByAddress(tokenAddress);\n\n const allowance = await exponentialBackoff(() =>\n tokenContract.allowance(walletAddress, spenderAddress),\n );\n\n return BigInt(allowance) > scale(tokenInfo.decimals)(Number.MAX_SAFE_INTEGER)\n ? Number.MAX_SAFE_INTEGER\n : descale(tokenInfo.decimals)(allowance);\n};\n\nexport type GetERC20BalanceArgs = {\n tokenAddress: string;\n walletAddress: string;\n subject: Signer;\n};\n\nexport const getERC20Balance = async ({\n tokenAddress,\n walletAddress,\n subject,\n}: GetERC20BalanceArgs): Promise<number> => {\n const token = getERC20TokenContract(tokenAddress, subject);\n\n const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));\n\n const currentBalance = await exponentialBackoff(() =>\n token.balanceOf(walletAddress),\n );\n\n return descale(tokenInfo.decimals)(currentBalance);\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/common",
3
- "version": "0.47.0",
3
+ "version": "0.48.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -42,5 +42,5 @@
42
42
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
43
43
  },
44
44
  "packageManager": "pnpm@8.10.4",
45
- "gitHead": "ea8ef18cda7e17a851d4c7eda0c807a85413d423"
45
+ "gitHead": "608397d08f0eea22a39a387037afc8e97ac46e5a"
46
46
  }
@@ -6,88 +6,142 @@ import {
6
6
  MoneyInOutChainId,
7
7
  GetSocketVaultParams,
8
8
  SocketTokenConnectors,
9
+ TokenName,
9
10
  } from '../types';
11
+ import { getReyaNetworkFromMoneyInOutChainId } from '../utils/network';
12
+ import { convertToAddress } from '../utils/token';
10
13
 
11
- const socketConnectors: Record<
12
- MoneyInOutChainId,
13
- Record<Uppercase<string>, SocketTokenConnectors>
14
- > = {
15
- [MoneyInOutChainId.polygonMumbai]: {
16
- USDC: {
17
- deposit:
18
- '0xF5b588306867992201fc78dE045bCe01BE6eA2fD'.toLowerCase() as Address,
19
- withdraw:
20
- '0x47E136cf4A96e1afa72e19022f9699Bbaa1BE60e'.toLowerCase() as Address,
21
- },
22
- },
23
- [MoneyInOutChainId.arbitrumSepolia]: {
24
- USDC: {
25
- deposit:
26
- '0xeD4F75f0C25963d2C61827261C2d7f84BF884c7F'.toLowerCase() as Address,
27
- withdraw:
28
- '0xCd2E3CCb0Eeec6F2762dcD5D24a76583b69f3Ee1'.toLowerCase() as Address,
29
- },
30
- },
31
- [MoneyInOutChainId.opSepolia]: {
32
- USDC: {
33
- deposit:
34
- '0x9838Fc33ea56F7664c677b1F2917c60d75a73BC6'.toLowerCase() as Address,
35
- withdraw:
36
- '0x9ca48cAF8AD2B081a0b633d6FCD803076F719fEa'.toLowerCase() as Address,
37
- },
38
- },
39
- [MoneyInOutChainId.ethereumSepolia]: {
40
- USDC: {
41
- deposit:
42
- '0x4BFDf43662cdf2Cc0A96C8697AC179819B6E5E91'.toLowerCase() as Address,
43
- withdraw:
44
- '0x1d43076909Ca139BFaC4EbB7194518bE3638fc76'.toLowerCase() as Address,
45
- },
46
- },
14
+ import * as REYA_CRONOS from '../utils/socket/reyaCronos.json';
15
+
16
+ type SocketDeploymentAddresses = {
17
+ [chain in ReyaChainId | MoneyInOutChainId]?: SocketChainAddresses;
18
+ };
19
+
20
+ type SocketChainAddresses = {
21
+ [token in TokenName]?: SocketTokenAddresses;
22
+ };
23
+
24
+ type SocketTokenAddresses =
25
+ | SocketAppChainAddresses
26
+ | SocketNonAppChainAddresses;
27
+
28
+ interface SocketAppChainAddresses {
29
+ isAppChain: true;
30
+ [SocketSuperBridgeContracts.MintableToken]?: string;
31
+ [SocketSuperBridgeContracts.Controller]?: string;
32
+ [SocketSuperBridgeContracts.ExchangeRate]?: string;
33
+ connectors?: SocketConnectors;
34
+ }
35
+ interface SocketNonAppChainAddresses {
36
+ isAppChain: false;
37
+ [SocketSuperBridgeContracts.NonMintableToken]?: string;
38
+ [SocketSuperBridgeContracts.Vault]?: string;
39
+ connectors?: SocketConnectors;
40
+ }
41
+
42
+ enum SocketSuperBridgeContracts {
43
+ MintableToken = 'MintableToken',
44
+ NonMintableToken = 'NonMintableToken',
45
+ Vault = 'Vault',
46
+ Controller = 'Controller',
47
+ FiatTokenV2_1_Controller = 'FiatTokenV2_1_Controller',
48
+ ExchangeRate = 'ExchangeRate',
49
+ ConnectorPlug = 'ConnectorPlug',
50
+ }
51
+
52
+ export type SocketConnectors = {
53
+ [chainSlug in ReyaChainId | MoneyInOutChainId]?: SocketConnectorAddresses;
54
+ };
55
+
56
+ export type SocketConnectorAddresses = {
57
+ ['FAST']?: string;
58
+ };
59
+
60
+ const getSocketDeploymentJSON = (
61
+ reyaChainId: ReyaChainId,
62
+ ): SocketDeploymentAddresses => {
63
+ switch (reyaChainId) {
64
+ case ReyaChainId.reyaNetwork:
65
+ throw new Error('getSocketDeploymentJSON unsupported chain id');
66
+ case ReyaChainId.reyaCronos:
67
+ return REYA_CRONOS;
68
+ }
47
69
  };
48
70
 
49
71
  export const getSocketConnectors = (
50
72
  params: GetSocketConnectorParams,
51
73
  ): SocketTokenConnectors => {
52
- return socketConnectors[params.moneyInOutChainId][params.tokenName];
53
- };
74
+ const reyaChainId = getReyaNetworkFromMoneyInOutChainId(
75
+ params.moneyInOutChainId,
76
+ );
77
+ const deploymentJSON = getSocketDeploymentJSON(reyaChainId);
78
+ const depositConnector =
79
+ deploymentJSON?.[params.moneyInOutChainId]?.[params.tokenName]
80
+ ?.connectors?.[reyaChainId]?.FAST;
54
81
 
55
- const socketControllers: Record<
56
- ReyaChainId,
57
- Record<Uppercase<string>, Address>
58
- > = {
59
- [ReyaChainId.reyaCronos]: {
60
- USDC: '0xc5a5Ac67fff82Da72d1F862f1363E2b217a2A61A'.toLowerCase() as Address,
61
- },
62
- [ReyaChainId.reyaNetwork]: {
63
- USDC: '',
64
- },
82
+ if (!depositConnector) {
83
+ throw new Error(
84
+ `getSocketConnectors: deposit connector not found ${JSON.stringify(
85
+ params,
86
+ )}`,
87
+ );
88
+ }
89
+
90
+ const withdrawConnector =
91
+ deploymentJSON?.[reyaChainId]?.[params.tokenName]?.connectors?.[
92
+ params.moneyInOutChainId
93
+ ]?.FAST;
94
+
95
+ if (!withdrawConnector) {
96
+ throw new Error(
97
+ `getSocketConnectors: withdraw connector not found ${JSON.stringify(
98
+ params,
99
+ )}`,
100
+ );
101
+ }
102
+
103
+ return {
104
+ deposit: convertToAddress(depositConnector),
105
+ withdraw: convertToAddress(withdrawConnector),
106
+ };
65
107
  };
66
108
 
67
109
  export const getSocketController = (
68
110
  params: GetSocketControllerParams,
69
111
  ): Address => {
70
- return socketControllers[params.reyaChainId][params.tokenName];
71
- };
112
+ const deploymentJSON = getSocketDeploymentJSON(params.reyaChainId);
113
+ const controller = (
114
+ deploymentJSON?.[params.reyaChainId]?.[
115
+ params.tokenName
116
+ ] as SocketAppChainAddresses
117
+ )?.[SocketSuperBridgeContracts.Controller];
72
118
 
73
- const socketVaults: Record<
74
- MoneyInOutChainId,
75
- Record<Uppercase<string>, Address>
76
- > = {
77
- [MoneyInOutChainId.polygonMumbai]: {
78
- USDC: '0xEC5b7075F581D46983EBe2Be6baB0f58Bf1E8C4b'.toLowerCase() as Address,
79
- },
80
- [MoneyInOutChainId.arbitrumSepolia]: {
81
- USDC: '0x85314b664cB2e443C93F09EDb51088f76b048212'.toLowerCase() as Address,
82
- },
83
- [MoneyInOutChainId.opSepolia]: {
84
- USDC: '0x1019958C2BD43B882a4e1349337a32Ef9563FC4D'.toLowerCase() as Address,
85
- },
86
- [MoneyInOutChainId.ethereumSepolia]: {
87
- USDC: '0x8487daa5864a5cE18E5a89406c11EC748da33fbB'.toLowerCase() as Address,
88
- },
119
+ if (!controller) {
120
+ throw new Error(
121
+ `getSocketController: controller not found ${JSON.stringify(params)}`,
122
+ );
123
+ }
124
+
125
+ return convertToAddress(controller);
89
126
  };
90
127
 
91
128
  export const getSocketVault = (params: GetSocketVaultParams): Address => {
92
- return socketVaults[params.moneyInOutChainId][params.tokenName];
129
+ const reyaChainId = getReyaNetworkFromMoneyInOutChainId(
130
+ params.moneyInOutChainId,
131
+ );
132
+ const deploymentJSON = getSocketDeploymentJSON(reyaChainId);
133
+
134
+ const vault = (
135
+ deploymentJSON?.[params.moneyInOutChainId]?.[
136
+ params.tokenName
137
+ ] as SocketNonAppChainAddresses
138
+ )?.[SocketSuperBridgeContracts.Vault];
139
+
140
+ if (!vault) {
141
+ throw new Error(
142
+ `getSocketVault: vault not found ${JSON.stringify(params)}`,
143
+ );
144
+ }
145
+
146
+ return convertToAddress(vault);
93
147
  };
package/src/types.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Signer } from 'ethers';
2
2
 
3
3
  export type Address = Lowercase<string>;
4
+ export type TokenName = Uppercase<string>;
4
5
 
5
6
  // -- Markets --
6
7
  export type MarketOrderInfo = {
@@ -249,17 +250,17 @@ export type SocketTokenConnectors = {
249
250
 
250
251
  export type GetSocketConnectorParams = {
251
252
  moneyInOutChainId: MoneyInOutChainId;
252
- tokenName: Uppercase<string>;
253
+ tokenName: TokenName;
253
254
  };
254
255
 
255
256
  export type GetSocketControllerParams = {
256
257
  reyaChainId: ReyaChainId;
257
- tokenName: Uppercase<string>;
258
+ tokenName: TokenName;
258
259
  };
259
260
 
260
261
  export type GetSocketVaultParams = {
261
262
  moneyInOutChainId: MoneyInOutChainId;
262
- tokenName: Uppercase<string>;
263
+ tokenName: TokenName;
263
264
  };
264
265
 
265
266
  export type GetSocketBridgeTimeParams = {
@@ -440,3 +441,9 @@ export type TokenEntityWithMinValue = TokenEntity & {
440
441
  minTransferAmount: number;
441
442
  stepSize: number;
442
443
  };
444
+
445
+ export type TokenInfo = {
446
+ name: TokenName;
447
+ address: Address;
448
+ decimals: number;
449
+ };
@@ -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
- };