@reyaxyz/sdk 0.69.2 → 0.71.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/token/getBalanceByTokenAddress.js +74 -11
- package/dist/services/token/getBalanceByTokenAddress.js.map +1 -1
- package/dist/services/token/types.js.map +1 -1
- package/dist/types/services/token/getBalanceByTokenAddress.d.ts +3 -4
- package/dist/types/services/token/getBalanceByTokenAddress.d.ts.map +1 -1
- package/dist/types/services/token/types.d.ts +15 -1
- package/dist/types/services/token/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/token/getBalanceByTokenAddress.ts +65 -12
- package/src/services/token/types.ts +18 -1
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -36,10 +47,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
47
|
}
|
|
37
48
|
};
|
|
38
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
50
|
+
exports.getBalancesForBridgeMA = exports.getBalancesForBridgeLP = exports.getBalanceByTokenAddress = void 0;
|
|
40
51
|
var common_1 = require("@reyaxyz/common");
|
|
41
|
-
var ethers_1 = require("ethers");
|
|
42
52
|
var config_1 = require("../../config");
|
|
53
|
+
var common_2 = require("@reyaxyz/common");
|
|
43
54
|
var getBalanceByTokenAddress = function (_a) {
|
|
44
55
|
var signer = _a.signer, tokenAddress = _a.tokenAddress;
|
|
45
56
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -60,7 +71,7 @@ var getBalanceByTokenAddress = function (_a) {
|
|
|
60
71
|
});
|
|
61
72
|
};
|
|
62
73
|
exports.getBalanceByTokenAddress = getBalanceByTokenAddress;
|
|
63
|
-
var
|
|
74
|
+
var getBalancesForBridgeLP = function (_a) {
|
|
64
75
|
var walletAddress = _a.walletAddress;
|
|
65
76
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
66
77
|
var chains, balancePromises, balancesArray, balances;
|
|
@@ -69,20 +80,19 @@ var getBalancesForBridge = function (_a) {
|
|
|
69
80
|
case 0:
|
|
70
81
|
chains = (0, common_1.getMoneyInOutNetworks)((0, config_1.getSdkEnvironment)());
|
|
71
82
|
balancePromises = chains.map(function (chain) { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
-
var tokenInfo,
|
|
83
|
+
var tokenInfo, balance;
|
|
73
84
|
return __generator(this, function (_a) {
|
|
74
85
|
switch (_a.label) {
|
|
75
86
|
case 0:
|
|
76
87
|
tokenInfo = (0, common_1.getRUSDUnderlyingTokenInfo)(chain);
|
|
77
|
-
|
|
78
|
-
return [4 /*yield*/, (0, common_1.getERC20Balance)({
|
|
88
|
+
return [4 /*yield*/, (0, common_2.getERC20BalanceBatch)({
|
|
79
89
|
tokenAddress: tokenInfo.address,
|
|
80
90
|
walletAddress: walletAddress,
|
|
81
|
-
|
|
91
|
+
chain: chain,
|
|
82
92
|
})];
|
|
83
93
|
case 1:
|
|
84
94
|
balance = _a.sent();
|
|
85
|
-
return [2 /*return*/, { chain: chain, balance: balance }];
|
|
95
|
+
return [2 /*return*/, { chain: chain, tokenInfo: tokenInfo, balance: balance }];
|
|
86
96
|
}
|
|
87
97
|
});
|
|
88
98
|
}); });
|
|
@@ -90,8 +100,61 @@ var getBalancesForBridge = function (_a) {
|
|
|
90
100
|
case 1:
|
|
91
101
|
balancesArray = _b.sent();
|
|
92
102
|
balances = balancesArray.reduce(function (acc, _a) {
|
|
93
|
-
var chain = _a.chain, balance = _a.balance;
|
|
94
|
-
acc[chain] =
|
|
103
|
+
var chain = _a.chain, tokenInfo = _a.tokenInfo, balance = _a.balance;
|
|
104
|
+
acc[chain] = {
|
|
105
|
+
tokenEntity: {
|
|
106
|
+
name: tokenInfo.name,
|
|
107
|
+
address: tokenInfo.address,
|
|
108
|
+
},
|
|
109
|
+
balance: balance,
|
|
110
|
+
};
|
|
111
|
+
return acc;
|
|
112
|
+
}, {});
|
|
113
|
+
return [2 /*return*/, balances];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
exports.getBalancesForBridgeLP = getBalancesForBridgeLP;
|
|
119
|
+
var getBalancesForBridgeMA = function (_a) {
|
|
120
|
+
var walletAddress = _a.walletAddress;
|
|
121
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
122
|
+
var moneyInOutChainIds, balancePromises, balancesArray, balances;
|
|
123
|
+
return __generator(this, function (_b) {
|
|
124
|
+
switch (_b.label) {
|
|
125
|
+
case 0:
|
|
126
|
+
moneyInOutChainIds = (0, common_1.getMoneyInOutNetworks)((0, config_1.getSdkEnvironment)());
|
|
127
|
+
balancePromises = moneyInOutChainIds
|
|
128
|
+
.map(function (moneyInOutChainId) {
|
|
129
|
+
var tokenInfos = (0, common_1.getTokenInfosByChain)(moneyInOutChainId);
|
|
130
|
+
return tokenInfos.map(function (tokenInfo) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
|
+
var balance;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0: return [4 /*yield*/, (0, common_2.getERC20BalanceBatch)({
|
|
135
|
+
tokenAddress: tokenInfo.address,
|
|
136
|
+
walletAddress: walletAddress,
|
|
137
|
+
chain: moneyInOutChainId,
|
|
138
|
+
})];
|
|
139
|
+
case 1:
|
|
140
|
+
balance = _a.sent();
|
|
141
|
+
return [2 /*return*/, {
|
|
142
|
+
chain: moneyInOutChainId,
|
|
143
|
+
tokenName: tokenInfo.name,
|
|
144
|
+
balance: balance,
|
|
145
|
+
}];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}); });
|
|
149
|
+
})
|
|
150
|
+
.reduce(function (acc, value) { return acc.concat(value); }, []);
|
|
151
|
+
return [4 /*yield*/, Promise.all(balancePromises)];
|
|
152
|
+
case 1:
|
|
153
|
+
balancesArray = _b.sent();
|
|
154
|
+
balances = balancesArray.reduce(function (acc, _a) {
|
|
155
|
+
var _b;
|
|
156
|
+
var chain = _a.chain, tokenName = _a.tokenName, balance = _a.balance;
|
|
157
|
+
acc[chain] = __assign(__assign({}, acc[chain]), (_b = {}, _b[tokenName] = balance, _b));
|
|
95
158
|
return acc;
|
|
96
159
|
}, {});
|
|
97
160
|
return [2 /*return*/, balances];
|
|
@@ -99,5 +162,5 @@ var getBalancesForBridge = function (_a) {
|
|
|
99
162
|
});
|
|
100
163
|
});
|
|
101
164
|
};
|
|
102
|
-
exports.
|
|
165
|
+
exports.getBalancesForBridgeMA = getBalancesForBridgeMA;
|
|
103
166
|
//# sourceMappingURL=getBalanceByTokenAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBalanceByTokenAddress.js","sourceRoot":"/","sources":["services/token/getBalanceByTokenAddress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getBalanceByTokenAddress.js","sourceRoot":"/","sources":["services/token/getBalanceByTokenA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A3B,KAAK,WAAA,EAAE,SAAS,eAAA,EAAE,OAAO,aAAA;wBAClC,GAAG,CAAC,KAAK,CAAC,yBACL,GAAG,CAAC,KAAK,CAAC,gBACZ,SAAS,IAAG,OAAO,MACrB,CAAC;wBAEF,OAAO,GAAG,CAAC;oBACb,CAAC,EAAE,EAAE,CAAC,CAAC;oBAEP,sBAAO,QAAQ,EAAC;;;;CACjB,CAAC;AAxCW,QAAA,sBAAsB,0BAwCjC","sourcesContent":["import {\n GetBalanceByTokenAddressParams,\n GetBalancesForBridgeLPResult,\n GetBalancesForBridgeMAResult,\n LPBalanceInfo,\n MABalanceInfo,\n} from './types';\nimport {\n getERC20Balance,\n GetBalancesForBridgeArgs,\n getMoneyInOutNetworks,\n getRUSDUnderlyingTokenInfo,\n MoneyInOutChainId,\n getTokenInfosByChain,\n} from '@reyaxyz/common';\nimport { getSdkEnvironment } from '../../config';\nimport { getERC20BalanceBatch } from '@reyaxyz/common';\n\nexport const getBalanceByTokenAddress = async ({\n signer,\n tokenAddress,\n}: GetBalanceByTokenAddressParams): Promise<number> => {\n const walletAddress = await signer.getAddress();\n return await getERC20Balance({\n walletAddress,\n subject: signer,\n tokenAddress: tokenAddress,\n });\n};\n\nexport const getBalancesForBridgeLP = async ({\n walletAddress,\n}: GetBalancesForBridgeArgs): Promise<GetBalancesForBridgeLPResult> => {\n const chains: MoneyInOutChainId[] = getMoneyInOutNetworks(\n getSdkEnvironment() as 'production' | 'test',\n );\n\n // Use Promise.all to fetch balances for all chains in parallel\n const balancePromises = chains.map(async (chain) => {\n const tokenInfo = getRUSDUnderlyingTokenInfo(chain);\n const balance = await getERC20BalanceBatch({\n tokenAddress: tokenInfo.address,\n walletAddress: walletAddress,\n chain: chain,\n });\n\n return { chain, tokenInfo, balance };\n });\n\n const balancesArray = await Promise.all(balancePromises);\n\n const balances = balancesArray.reduce<{\n [key in MoneyInOutChainId]?: LPBalanceInfo;\n }>((acc, { chain, tokenInfo, balance }) => {\n acc[chain] = {\n tokenEntity: {\n name: tokenInfo.name,\n address: tokenInfo.address,\n },\n balance: balance,\n };\n return acc;\n }, {});\n\n return balances;\n};\n\nexport const getBalancesForBridgeMA = async ({\n walletAddress,\n}: GetBalancesForBridgeArgs): Promise<GetBalancesForBridgeMAResult> => {\n const moneyInOutChainIds: MoneyInOutChainId[] = getMoneyInOutNetworks(\n getSdkEnvironment() as 'production' | 'test',\n );\n\n const balancePromises = moneyInOutChainIds\n .map((moneyInOutChainId) => {\n const tokenInfos = getTokenInfosByChain(moneyInOutChainId);\n return tokenInfos.map(async (tokenInfo) => {\n const balance = await getERC20BalanceBatch({\n tokenAddress: tokenInfo.address,\n walletAddress: walletAddress,\n chain: moneyInOutChainId,\n });\n\n return {\n chain: moneyInOutChainId,\n tokenName: tokenInfo.name,\n balance: balance,\n };\n });\n })\n .reduce((acc, value) => acc.concat(value), []);\n\n const balancesArray = await Promise.all(balancePromises);\n\n const balances = balancesArray.reduce<{\n [key in MoneyInOutChainId]?: MABalanceInfo;\n }>((acc, { chain, tokenName, balance }) => {\n acc[chain] = {\n ...acc[chain],\n [tokenName]: balance,\n };\n\n return acc;\n }, {});\n\n return balances;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":";;;AAKA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,2CAAE,CAAA;IACF,qDAAO,CAAA;IACP,mDAAM,CAAA;AACR,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { TokenEntity, TokenName } from '@reyaxyz/common';\n\nexport { GetBalancesForBridgeArgs } from '@reyaxyz/common';\n\nexport enum ApprovalType {\n LP,\n DEPOSIT,\n BRIDGE,\n}\n\nexport type ApproveTokenParams = {\n signer: Signer | JsonRpcSigner;\n tokenAddress: TokenEntity['address'];\n amount: number;\n type: ApprovalType;\n};\n\nexport type GetAllowanceParams = {\n signer: Signer | JsonRpcSigner;\n tokenAddress: TokenEntity['address'];\n type: ApprovalType;\n};\n\nexport type GetBalanceByTokenAddressParams = {\n signer: Signer | JsonRpcSigner;\n tokenAddress: TokenEntity['address'];\n};\n\nexport type GetRUSDUnderlyingSignerInfoParams = {\n signer: Signer | JsonRpcSigner;\n};\n\nexport type GetRUSDUnderlyingSignerInfoResult = {\n balance: number;\n rusdUnderlying: TokenEntity;\n};\n\nexport type LPBalanceInfo = {\n tokenEntity: TokenEntity;\n balance: number;\n};\n\nexport type GetBalancesForBridgeLPResult = {\n [chainId: string]: LPBalanceInfo;\n};\n\nexport type MABalanceInfo = { [tokenName: TokenName]: number };\n\nexport type GetBalancesForBridgeMAResult = {\n [chainId: string]: MABalanceInfo;\n};\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { GetBalanceByTokenAddressParams } from './types';
|
|
1
|
+
import { GetBalanceByTokenAddressParams, GetBalancesForBridgeLPResult, GetBalancesForBridgeMAResult } from './types';
|
|
2
2
|
import { GetBalancesForBridgeArgs } from '@reyaxyz/common';
|
|
3
3
|
export declare const getBalanceByTokenAddress: ({ signer, tokenAddress, }: GetBalanceByTokenAddressParams) => Promise<number>;
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
6
|
-
}>;
|
|
4
|
+
export declare const getBalancesForBridgeLP: ({ walletAddress, }: GetBalancesForBridgeArgs) => Promise<GetBalancesForBridgeLPResult>;
|
|
5
|
+
export declare const getBalancesForBridgeMA: ({ walletAddress, }: GetBalancesForBridgeArgs) => Promise<GetBalancesForBridgeMAResult>;
|
|
7
6
|
//# sourceMappingURL=getBalanceByTokenAddress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBalanceByTokenAddress.d.ts","sourceRoot":"/","sources":["services/token/getBalanceByTokenAddress.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getBalanceByTokenAddress.d.ts","sourceRoot":"/","sources":["services/token/getBalanceByTokenAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,4BAA4B,EAG7B,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,wBAAwB,EAKzB,MAAM,iBAAiB,CAAC;AAIzB,eAAO,MAAM,wBAAwB,8BAGlC,8BAA8B,KAAG,QAAQ,MAAM,CAOjD,CAAC;AAEF,eAAO,MAAM,sBAAsB,uBAEhC,wBAAwB,KAAG,QAAQ,4BAA4B,CAiCjE,CAAC;AAEF,eAAO,MAAM,sBAAsB,uBAEhC,wBAAwB,KAAG,QAAQ,4BAA4B,CAsCjE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
import { TokenEntity } from '@reyaxyz/common';
|
|
2
|
+
import { TokenEntity, TokenName } from '@reyaxyz/common';
|
|
3
|
+
export { GetBalancesForBridgeArgs } from '@reyaxyz/common';
|
|
3
4
|
export declare enum ApprovalType {
|
|
4
5
|
LP = 0,
|
|
5
6
|
DEPOSIT = 1,
|
|
@@ -27,4 +28,17 @@ export type GetRUSDUnderlyingSignerInfoResult = {
|
|
|
27
28
|
balance: number;
|
|
28
29
|
rusdUnderlying: TokenEntity;
|
|
29
30
|
};
|
|
31
|
+
export type LPBalanceInfo = {
|
|
32
|
+
tokenEntity: TokenEntity;
|
|
33
|
+
balance: number;
|
|
34
|
+
};
|
|
35
|
+
export type GetBalancesForBridgeLPResult = {
|
|
36
|
+
[chainId: string]: LPBalanceInfo;
|
|
37
|
+
};
|
|
38
|
+
export type MABalanceInfo = {
|
|
39
|
+
[tokenName: TokenName]: number;
|
|
40
|
+
};
|
|
41
|
+
export type GetBalancesForBridgeMAResult = {
|
|
42
|
+
[chainId: string]: MABalanceInfo;
|
|
43
|
+
};
|
|
30
44
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,oBAAY,YAAY;IACtB,EAAE,IAAA;IACF,OAAO,IAAA;IACP,MAAM,IAAA;CACP;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,YAAY,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,YAAY,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrC,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,YAAY,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,WAAW,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,4BAA4B,GAAG;IACzC,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC;CAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@reyaxyz/common": "0.
|
|
32
|
+
"@reyaxyz/common": "0.78.0",
|
|
33
33
|
"bignumber.js": "^9.1.2",
|
|
34
34
|
"ethers": "6.9.0"
|
|
35
35
|
},
|
|
36
36
|
"packageManager": "pnpm@8.10.4",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "8b14b2df0a11bc31e97c569c7cc504143f8a5219"
|
|
38
38
|
}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
GetBalanceByTokenAddressParams,
|
|
3
|
+
GetBalancesForBridgeLPResult,
|
|
4
|
+
GetBalancesForBridgeMAResult,
|
|
5
|
+
LPBalanceInfo,
|
|
6
|
+
MABalanceInfo,
|
|
7
|
+
} from './types';
|
|
2
8
|
import {
|
|
3
9
|
getERC20Balance,
|
|
4
|
-
ChainRpcUrls,
|
|
5
10
|
GetBalancesForBridgeArgs,
|
|
6
11
|
getMoneyInOutNetworks,
|
|
7
12
|
getRUSDUnderlyingTokenInfo,
|
|
8
13
|
MoneyInOutChainId,
|
|
14
|
+
getTokenInfosByChain,
|
|
9
15
|
} from '@reyaxyz/common';
|
|
10
|
-
import { ethers } from 'ethers';
|
|
11
16
|
import { getSdkEnvironment } from '../../config';
|
|
17
|
+
import { getERC20BalanceBatch } from '@reyaxyz/common';
|
|
12
18
|
|
|
13
19
|
export const getBalanceByTokenAddress = async ({
|
|
14
20
|
signer,
|
|
@@ -22,9 +28,9 @@ export const getBalanceByTokenAddress = async ({
|
|
|
22
28
|
});
|
|
23
29
|
};
|
|
24
30
|
|
|
25
|
-
export const
|
|
31
|
+
export const getBalancesForBridgeLP = async ({
|
|
26
32
|
walletAddress,
|
|
27
|
-
}: GetBalancesForBridgeArgs): Promise<
|
|
33
|
+
}: GetBalancesForBridgeArgs): Promise<GetBalancesForBridgeLPResult> => {
|
|
28
34
|
const chains: MoneyInOutChainId[] = getMoneyInOutNetworks(
|
|
29
35
|
getSdkEnvironment() as 'production' | 'test',
|
|
30
36
|
);
|
|
@@ -32,22 +38,69 @@ export const getBalancesForBridge = async ({
|
|
|
32
38
|
// Use Promise.all to fetch balances for all chains in parallel
|
|
33
39
|
const balancePromises = chains.map(async (chain) => {
|
|
34
40
|
const tokenInfo = getRUSDUnderlyingTokenInfo(chain);
|
|
35
|
-
const
|
|
36
|
-
const balance = await getERC20Balance({
|
|
41
|
+
const balance = await getERC20BalanceBatch({
|
|
37
42
|
tokenAddress: tokenInfo.address,
|
|
38
43
|
walletAddress: walletAddress,
|
|
39
|
-
|
|
44
|
+
chain: chain,
|
|
40
45
|
});
|
|
41
46
|
|
|
42
|
-
return { chain, balance };
|
|
47
|
+
return { chain, tokenInfo, balance };
|
|
43
48
|
});
|
|
44
49
|
|
|
45
50
|
const balancesArray = await Promise.all(balancePromises);
|
|
46
51
|
|
|
47
52
|
const balances = balancesArray.reduce<{
|
|
48
|
-
[key in MoneyInOutChainId]?:
|
|
49
|
-
}>((acc, { chain, balance }) => {
|
|
50
|
-
acc[chain] =
|
|
53
|
+
[key in MoneyInOutChainId]?: LPBalanceInfo;
|
|
54
|
+
}>((acc, { chain, tokenInfo, balance }) => {
|
|
55
|
+
acc[chain] = {
|
|
56
|
+
tokenEntity: {
|
|
57
|
+
name: tokenInfo.name,
|
|
58
|
+
address: tokenInfo.address,
|
|
59
|
+
},
|
|
60
|
+
balance: balance,
|
|
61
|
+
};
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
|
64
|
+
|
|
65
|
+
return balances;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const getBalancesForBridgeMA = async ({
|
|
69
|
+
walletAddress,
|
|
70
|
+
}: GetBalancesForBridgeArgs): Promise<GetBalancesForBridgeMAResult> => {
|
|
71
|
+
const moneyInOutChainIds: MoneyInOutChainId[] = getMoneyInOutNetworks(
|
|
72
|
+
getSdkEnvironment() as 'production' | 'test',
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const balancePromises = moneyInOutChainIds
|
|
76
|
+
.map((moneyInOutChainId) => {
|
|
77
|
+
const tokenInfos = getTokenInfosByChain(moneyInOutChainId);
|
|
78
|
+
return tokenInfos.map(async (tokenInfo) => {
|
|
79
|
+
const balance = await getERC20BalanceBatch({
|
|
80
|
+
tokenAddress: tokenInfo.address,
|
|
81
|
+
walletAddress: walletAddress,
|
|
82
|
+
chain: moneyInOutChainId,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
chain: moneyInOutChainId,
|
|
87
|
+
tokenName: tokenInfo.name,
|
|
88
|
+
balance: balance,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
.reduce((acc, value) => acc.concat(value), []);
|
|
93
|
+
|
|
94
|
+
const balancesArray = await Promise.all(balancePromises);
|
|
95
|
+
|
|
96
|
+
const balances = balancesArray.reduce<{
|
|
97
|
+
[key in MoneyInOutChainId]?: MABalanceInfo;
|
|
98
|
+
}>((acc, { chain, tokenName, balance }) => {
|
|
99
|
+
acc[chain] = {
|
|
100
|
+
...acc[chain],
|
|
101
|
+
[tokenName]: balance,
|
|
102
|
+
};
|
|
103
|
+
|
|
51
104
|
return acc;
|
|
52
105
|
}, {});
|
|
53
106
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
import { TokenEntity } from '@reyaxyz/common';
|
|
2
|
+
import { TokenEntity, TokenName } from '@reyaxyz/common';
|
|
3
|
+
|
|
4
|
+
export { GetBalancesForBridgeArgs } from '@reyaxyz/common';
|
|
3
5
|
|
|
4
6
|
export enum ApprovalType {
|
|
5
7
|
LP,
|
|
@@ -33,3 +35,18 @@ export type GetRUSDUnderlyingSignerInfoResult = {
|
|
|
33
35
|
balance: number;
|
|
34
36
|
rusdUnderlying: TokenEntity;
|
|
35
37
|
};
|
|
38
|
+
|
|
39
|
+
export type LPBalanceInfo = {
|
|
40
|
+
tokenEntity: TokenEntity;
|
|
41
|
+
balance: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type GetBalancesForBridgeLPResult = {
|
|
45
|
+
[chainId: string]: LPBalanceInfo;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type MABalanceInfo = { [tokenName: TokenName]: number };
|
|
49
|
+
|
|
50
|
+
export type GetBalancesForBridgeMAResult = {
|
|
51
|
+
[chainId: string]: MABalanceInfo;
|
|
52
|
+
};
|