@reyaxyz/sdk 0.4.0 → 0.6.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.
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getERC20Allowance = exports.getTokenDetails = exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
39
+ exports.getERC20Balance = exports.getERC20Allowance = exports.getTokenDetails = exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
40
40
  var ethers_1 = require("ethers");
41
41
  var consts_1 = require("./consts");
42
42
  var retry_1 = require("../../utils/retry");
@@ -104,4 +104,24 @@ var getERC20Allowance = function (_a) {
104
104
  });
105
105
  };
106
106
  exports.getERC20Allowance = getERC20Allowance;
107
+ var getERC20Balance = function (_a) {
108
+ var tokenAddress = _a.tokenAddress, walletAddress = _a.walletAddress, subject = _a.subject;
109
+ return __awaiter(void 0, void 0, void 0, function () {
110
+ var token, tokenDescaler, currentBalance;
111
+ return __generator(this, function (_b) {
112
+ switch (_b.label) {
113
+ case 0:
114
+ token = (0, exports.getERC20TokenContract)(tokenAddress, subject);
115
+ tokenDescaler = (0, exports.getTokenDetails)(tokenAddress).tokenDescaler;
116
+ return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
117
+ return token.balanceOf(walletAddress);
118
+ })];
119
+ case 1:
120
+ currentBalance = _b.sent();
121
+ return [2 /*return*/, tokenDescaler(currentBalance)];
122
+ }
123
+ });
124
+ });
125
+ };
126
+ exports.getERC20Balance = getERC20Balance;
107
127
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"/","sources":["services/token/common.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAkD;AAClD,mCAAwC;AACxC,2CAAuD;AA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AAC;IAC7D,CAAC;IAEK,IAAA,KAA+B,qBAAY,CAAC,OAAO,CAAC,EAAlD,SAAS,eAAA,EAAE,aAAa,mBAA0B,CAAC;IAE3D,OAAO;QACL,SAAS,WAAA;QACT,aAAa,eAAA;QACb,aAAa,EAAE,IAAA,eAAO,EAAC,aAAa,CAAC;KACtC,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,eAAe,mBAoB1B;AAEK,IAAM,iBAAiB,GAAG,UAAO,EAKd;QAJxB,aAAa,mBAAA,EACb,YAAY,kBAAA,EACZ,cAAc,oBAAA,EACd,OAAO,aAAA;;;;;;oBAED,aAAa,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBAC3D,aAAa,GAAK,IAAA,uBAAe,EAAC,YAAY,CAAC,cAAlC,CAAmC;oBAEtC,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,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","sourcesContent":["import { Contract, ethers, Signer } from 'ethers';\nimport { tokenDetails } from './consts';\nimport { exponentialBackoff } from '../../utils/retry';\nimport { 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 type Address = Lowercase<string>;\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"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"/","sources":["services/token/common.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAkD;AAClD,mCAAwC;AACxC,2CAAuD;AAGhD,IAAM,OAAO,GAAG,UAAC,aAAqB;IAC3C,IAAM,CAAC,GAAG,UAAC,KAAa;QACtB,OAAO,MAAM,CAAC,eAAM,CAAC,WAAW,CAAC,KAAK,CAAC,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AC;AAdW,QAAA,eAAe,mBAc1B","sourcesContent":["import { Contract, ethers, Signer } from 'ethers';\nimport { tokenDetails } from './consts';\nimport { exponentialBackoff } from '../../utils/retry';\nimport { 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 type Address = Lowercase<string>;\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"]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getBalance = void 0;
40
+ var common_1 = require("./common");
41
+ var getBalance = function (_a) {
42
+ var signer = _a.signer, tokenAddress = _a.tokenAddress;
43
+ return __awaiter(void 0, void 0, void 0, function () {
44
+ var walletAddress, currentBalance;
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0: return [4 /*yield*/, signer.getAddress()];
48
+ case 1:
49
+ walletAddress = _b.sent();
50
+ return [4 /*yield*/, (0, common_1.getERC20Balance)({
51
+ walletAddress: walletAddress,
52
+ subject: signer,
53
+ tokenAddress: tokenAddress,
54
+ })];
55
+ case 2:
56
+ currentBalance = _b.sent();
57
+ return [2 /*return*/, currentBalance];
58
+ }
59
+ });
60
+ });
61
+ };
62
+ exports.getBalance = getBalance;
63
+ //# sourceMappingURL=getBalance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBalance.js","sourceRoot":"/","sources":["services/token/getBalance.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA2C;AAEpC,IAAM,UAAU,GAAG,UAAO,EAGd;QAFjB,MAAM,YAAA,EACN,YAAY,kBAAA;;;;;wBAEU,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAAzC,aAAa,GAAG,SAAyB;oBACxB,qBAAM,IAAA,wBAAe,EAAC;4BAC3C,aAAa,eAAA;4BACb,OAAO,EAAE,MAAM;4BACf,YAAY,EAAE,YAAY;yBAC3B,CAAC,EAAA;;oBAJI,cAAc,GAAG,SAIrB;oBAEF,sBAAO,cAAc,EAAC;;;;CACvB,CAAC;AAZW,QAAA,UAAU,cAYrB","sourcesContent":["import { GetBalanceParams } from './types';\nimport { getERC20Balance } from './common';\n\nexport const getBalance = async ({\n signer,\n tokenAddress,\n}: GetBalanceParams): Promise<number> => {\n const walletAddress = await signer.getAddress();\n const currentBalance = await getERC20Balance({\n walletAddress,\n subject: signer,\n tokenAddress: tokenAddress,\n });\n\n return currentBalance;\n};\n"]}
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
18
  __exportStar(require("./approve"), exports);
19
19
  __exportStar(require("./getAllowance"), exports);
20
+ __exportStar(require("./getBalance"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,iDAA+B","sourcesContent":["export * from './types';\nexport * from './approve';\nexport * from './getAllowance';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,iDAA+B;AAC/B,+CAA6B","sourcesContent":["export * from './types';\nexport * from './approve';\nexport * from './getAllowance';\nexport * from './getBalance';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2CAAE,CAAA;IACF,qDAAO,CAAA;AACT,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\n\nexport enum ApprovalType {\n LP,\n DEPOSIT,\n}\n\nexport type ApproveTokenParams = {\n signer: Signer | JsonRpcSigner;\n token: string; // token address\n type: ApprovalType;\n};\n\nexport type GetAllowanceParams = {\n signer: Signer | JsonRpcSigner;\n token: string; // token address\n type: ApprovalType;\n};\n\nexport type GetERC20AllowanceParams = {\n walletAddress: string;\n tokenAddress: string; // LP POOL entity tokean address\n spenderAddress: string;\n subject: Signer;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2CAAE,CAAA;IACF,qDAAO,CAAA;AACT,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\n\nexport enum ApprovalType {\n LP,\n DEPOSIT,\n}\n\nexport type ApproveTokenParams = {\n signer: Signer | JsonRpcSigner;\n token: string; // token address\n type: ApprovalType;\n};\n\nexport type GetAllowanceParams = {\n signer: Signer | JsonRpcSigner;\n token: string; // token address\n type: ApprovalType;\n};\n\nexport type GetERC20AllowanceParams = {\n walletAddress: string;\n tokenAddress: string; // LP POOL entity tokean address\n spenderAddress: string;\n subject: Signer;\n};\n\nexport type GetBalanceParams = {\n signer: Signer | JsonRpcSigner;\n tokenAddress: string;\n};\n"]}
@@ -11,4 +11,10 @@ export declare const getTokenDetails: (caseSensitiveAddress: string) => {
11
11
  tokenDescaler: (value: bigint) => number;
12
12
  };
13
13
  export declare const getERC20Allowance: ({ walletAddress, tokenAddress, spenderAddress, subject, }: GetERC20AllowanceParams) => Promise<number>;
14
+ export type GetERC20BalanceArgs = {
15
+ tokenAddress: string;
16
+ walletAddress: string;
17
+ subject: Signer;
18
+ };
19
+ export declare const getERC20Balance: ({ tokenAddress, walletAddress, subject, }: GetERC20BalanceArgs) => Promise<number>;
14
20
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"/","sources":["services/token/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAElD,eAAO,MAAM,OAAO,kBAAmB,MAAM,aACzB,MAAM,WAKzB,CAAC;AAEF,eAAO,MAAM,KAAK,kBAAmB,MAAM,aACvB,MAAM,WAOzB,CAAC;AAEF,eAAO,MAAM,qBAAqB,iBAClB,MAAM,WACX,MAAM,KACd,QAWF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAExC,eAAO,MAAM,gBAAgB,QAAS,MAAM,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,eAAe,yBACJ,MAAM;eAEjB,UAAU,MAAM,CAAC;mBACb,MAAM;2BACE,MAAM,KAAK,MAAM;CAezC,CAAC;AAEF,eAAO,MAAM,iBAAiB,8DAK3B,uBAAuB,KAAG,QAAQ,MAAM,CAW1C,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"/","sources":["services/token/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAElD,eAAO,MAAM,OAAO,kBAAmB,MAAM,aACzB,MAAM,WAKzB,CAAC;AAEF,eAAO,MAAM,KAAK,kBAAmB,MAAM,aACvB,MAAM,WAOzB,CAAC;AAEF,eAAO,MAAM,qBAAqB,iBAClB,MAAM,WACX,MAAM,KACd,QAWF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAExC,eAAO,MAAM,gBAAgB,QAAS,MAAM,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,eAAe,yBACJ,MAAM;eAEjB,UAAU,MAAM,CAAC;mBACb,MAAM;2BACE,MAAM,KAAK,MAAM;CAezC,CAAC;AAEF,eAAO,MAAM,iBAAiB,8DAK3B,uBAAuB,KAAG,QAAQ,MAAM,CAW1C,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,eAAe,8CAIzB,mBAAmB,KAAG,QAAQ,MAAM,CAUtC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { GetBalanceParams } from './types';
2
+ export declare const getBalance: ({ signer, tokenAddress, }: GetBalanceParams) => Promise<number>;
3
+ //# sourceMappingURL=getBalance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBalance.d.ts","sourceRoot":"/","sources":["services/token/getBalance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3C,eAAO,MAAM,UAAU,8BAGpB,gBAAgB,KAAG,QAAQ,MAAM,CASnC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './types';
2
2
  export * from './approve';
3
3
  export * from './getAllowance';
4
+ export * from './getBalance';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -19,4 +19,8 @@ export type GetERC20AllowanceParams = {
19
19
  spenderAddress: string;
20
20
  subject: Signer;
21
21
  };
22
+ export type GetBalanceParams = {
23
+ signer: Signer | JsonRpcSigner;
24
+ tokenAddress: string;
25
+ };
22
26
  //# 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;AAE/C,oBAAY,YAAY;IACtB,EAAE,IAAA;IACF,OAAO,IAAA;CACR;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,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;AAE/C,oBAAY,YAAY;IACtB,EAAE,IAAA;IACF,OAAO,IAAA;CACR;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -33,5 +33,5 @@
33
33
  "ethers": "6.9.0"
34
34
  },
35
35
  "packageManager": "pnpm@8.10.4",
36
- "gitHead": "87e449e615b82a9bcd2e38296f2c2c0daa09a61b"
36
+ "gitHead": "976fb33b721326e93652eb4db9c8224fd775de96"
37
37
  }
@@ -82,3 +82,25 @@ export const getERC20Allowance = async ({
82
82
  ? Number.MAX_SAFE_INTEGER
83
83
  : descale(tokenDecimals)(allowance);
84
84
  };
85
+
86
+ export type GetERC20BalanceArgs = {
87
+ tokenAddress: string;
88
+ walletAddress: string;
89
+ subject: Signer;
90
+ };
91
+
92
+ export const getERC20Balance = async ({
93
+ tokenAddress,
94
+ walletAddress,
95
+ subject,
96
+ }: GetERC20BalanceArgs): Promise<number> => {
97
+ const token = getERC20TokenContract(tokenAddress, subject);
98
+
99
+ const { tokenDescaler } = getTokenDetails(tokenAddress);
100
+
101
+ const currentBalance = await exponentialBackoff(() =>
102
+ token.balanceOf(walletAddress),
103
+ );
104
+
105
+ return tokenDescaler(currentBalance);
106
+ };
@@ -0,0 +1,16 @@
1
+ import { GetBalanceParams } from './types';
2
+ import { getERC20Balance } from './common';
3
+
4
+ export const getBalance = async ({
5
+ signer,
6
+ tokenAddress,
7
+ }: GetBalanceParams): Promise<number> => {
8
+ const walletAddress = await signer.getAddress();
9
+ const currentBalance = await getERC20Balance({
10
+ walletAddress,
11
+ subject: signer,
12
+ tokenAddress: tokenAddress,
13
+ });
14
+
15
+ return currentBalance;
16
+ };
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export * from './approve';
3
3
  export * from './getAllowance';
4
+ export * from './getBalance';
@@ -23,3 +23,8 @@ export type GetERC20AllowanceParams = {
23
23
  spenderAddress: string;
24
24
  subject: Signer;
25
25
  };
26
+
27
+ export type GetBalanceParams = {
28
+ signer: Signer | JsonRpcSigner;
29
+ tokenAddress: string;
30
+ };