@reyaxyz/common 0.345.0 → 0.347.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/trading-api-types.js.map +1 -1
  3. package/dist/transactions/executeTransaction.js +8 -123
  4. package/dist/transactions/executeTransaction.js.map +1 -1
  5. package/dist/types/trading-api-types.d.ts +104 -1
  6. package/dist/types/trading-api-types.d.ts.map +1 -1
  7. package/dist/types/transactions/executeTransaction.d.ts +2 -15
  8. package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
  9. package/dist/types/utils/layerzero.d.ts +22 -0
  10. package/dist/types/utils/layerzero.d.ts.map +1 -0
  11. package/dist/types/utils/token/batch-token-getters.d.ts +0 -5
  12. package/dist/types/utils/token/batch-token-getters.d.ts.map +1 -1
  13. package/dist/types/utils/token/token-getters.d.ts +0 -2
  14. package/dist/types/utils/token/token-getters.d.ts.map +1 -1
  15. package/dist/utils/layerzero.js +31 -0
  16. package/dist/utils/layerzero.js.map +1 -0
  17. package/dist/utils/token/batch-token-getters.js +13 -64
  18. package/dist/utils/token/batch-token-getters.js.map +1 -1
  19. package/dist/utils/token/token-getters.js +1 -42
  20. package/dist/utils/token/token-getters.js.map +1 -1
  21. package/package.json +2 -2
  22. package/src/trading-api-types.ts +106 -1
  23. package/src/transactions/executeTransaction.ts +2 -130
  24. package/src/utils/layerzero.ts +66 -0
  25. package/src/utils/token/batch-token-getters.ts +0 -28
  26. package/src/utils/token/token-getters.ts +0 -29
  27. package/dist/types/utils/layerzero/index.d.ts +0 -3
  28. package/dist/types/utils/layerzero/index.d.ts.map +0 -1
  29. package/dist/types/utils/layerzero/oft-config.d.ts +0 -4
  30. package/dist/types/utils/layerzero/oft-config.d.ts.map +0 -1
  31. package/dist/types/utils/layerzero/types.d.ts +0 -23
  32. package/dist/types/utils/layerzero/types.d.ts.map +0 -1
  33. package/dist/utils/layerzero/index.js +0 -19
  34. package/dist/utils/layerzero/index.js.map +0 -1
  35. package/dist/utils/layerzero/oft-config.js +0 -29
  36. package/dist/utils/layerzero/oft-config.js.map +0 -1
  37. package/dist/utils/layerzero/types.js +0 -3
  38. package/dist/utils/layerzero/types.js.map +0 -1
  39. package/src/utils/layerzero/index.ts +0 -2
  40. package/src/utils/layerzero/oft-config.ts +0 -32
  41. package/src/utils/layerzero/types.ts +0 -25
@@ -1,14 +1,8 @@
1
1
  import { ethers } from 'ethers';
2
2
  import { MoneyInOutChainId, ReyaChainId } from '../../types';
3
3
  import { getPublicRpcUrlsOrThrow } from '../network';
4
- import { exponentialBackoff } from '../retry';
5
4
  import { descale, getERC20TokenContract } from './utils';
6
5
 
7
- export type GetETHBalanceBatchArgs = {
8
- walletAddress: string;
9
- chain: MoneyInOutChainId | ReyaChainId;
10
- };
11
-
12
6
  export type GetERC20BalanceBatchArgs = {
13
7
  tokenAddress: string;
14
8
  tokenDecimals: number;
@@ -24,28 +18,6 @@ export type GetERC20AllowanceBatchArgs = {
24
18
  chain: MoneyInOutChainId | ReyaChainId;
25
19
  };
26
20
 
27
- export const getETHBalanceBatch = async ({
28
- walletAddress,
29
- chain,
30
- }: GetETHBalanceBatchArgs): Promise<number> => {
31
- const rpcUrls = getPublicRpcUrlsOrThrow(chain);
32
- let lastError = null;
33
-
34
- for (const url of rpcUrls) {
35
- try {
36
- const provider = new ethers.JsonRpcProvider(url);
37
- const currentBalance = await exponentialBackoff(() =>
38
- provider.getBalance(ethers.getAddress(walletAddress)),
39
- );
40
- return descale(18)(currentBalance);
41
- } catch (error) {
42
- lastError = error;
43
- }
44
- }
45
-
46
- throw new Error('All RPC URLs failed; last error: ' + lastError);
47
- };
48
-
49
21
  export const getERC20BalanceBatch = async ({
50
22
  tokenAddress,
51
23
  tokenDecimals,
@@ -40,32 +40,3 @@ export const getERC20Allowance = async ({
40
40
  ? Number.MAX_SAFE_INTEGER
41
41
  : descale(tokenDecimals)(allowance);
42
42
  };
43
-
44
- export const getERC20Balance = async ({
45
- tokenAddress,
46
- tokenDecimals,
47
- walletAddress,
48
- subject,
49
- }: GetERC20BalanceArgs): Promise<number> => {
50
- const token = getERC20TokenContract(tokenAddress, subject);
51
-
52
- const currentBalance = await exponentialBackoff(() =>
53
- token.balanceOf(walletAddress),
54
- );
55
-
56
- return descale(tokenDecimals)(currentBalance);
57
- };
58
-
59
- export const getETHBalance = async ({
60
- walletAddress,
61
- subject,
62
- }: GetETHBalanceArgs): Promise<number> => {
63
- const provider = subject.provider;
64
- if (!provider) throw new Error("User's provider not found");
65
-
66
- const currentBalance = await exponentialBackoff(() =>
67
- provider.getBalance(ethers.getAddress(walletAddress)),
68
- );
69
-
70
- return descale(18)(currentBalance);
71
- };
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './oft-config';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/layerzero/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
@@ -1,4 +0,0 @@
1
- import { MoneyInOutChainId, ReyaChainId, TokenName } from '../../types';
2
- export declare const getLzEndpointId: (chainId: MoneyInOutChainId | ReyaChainId) => number;
3
- export declare const getOFTTokenAddress: (tokenName: TokenName, chainId: MoneyInOutChainId | ReyaChainId) => string;
4
- //# sourceMappingURL=oft-config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oft-config.d.ts","sourceRoot":"/","sources":["utils/layerzero/oft-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxE,eAAO,MAAM,eAAe,YACjB,iBAAiB,GAAG,WAAW,KACvC,MAaF,CAAC;AAEF,eAAO,MAAM,kBAAkB,cAClB,SAAS,WACX,iBAAiB,GAAG,WAAW,KACvC,MAQF,CAAC"}
@@ -1,23 +0,0 @@
1
- export type OFTSendParam = {
2
- dstEid: number;
3
- to: string;
4
- amountLD: bigint;
5
- minAmountLD: bigint;
6
- extraOptions: string;
7
- composeMsg: string;
8
- oftCmd: string;
9
- };
10
- export type OFTMessagingFee = {
11
- nativeFee: bigint;
12
- lzTokenFee: bigint;
13
- };
14
- export type OFTMessagingReceipt = {
15
- guid: string;
16
- nonce: bigint;
17
- fee: OFTMessagingFee;
18
- };
19
- export type OFTReceipt = {
20
- amountSentLD: bigint;
21
- amountReceivedLD: bigint;
22
- };
23
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["utils/layerzero/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./oft-config"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/layerzero/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,+CAA6B","sourcesContent":["export * from './types';\nexport * from './oft-config';\n"]}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOFTTokenAddress = exports.getLzEndpointId = void 0;
4
- var types_1 = require("../../types");
5
- var token_info_getters_1 = require("../token/token-info-getters");
6
- var getLzEndpointId = function (chainId) {
7
- var _a;
8
- var chainToLzEid = (_a = {},
9
- _a[types_1.MoneyInOutChainId.ethereumMainnet] = 30101,
10
- _a[types_1.MoneyInOutChainId.ethereumSepolia] = 40161,
11
- _a[types_1.ReyaChainId.reyaNetwork] = 30313,
12
- _a[types_1.ReyaChainId.reyaCronos] = 40319,
13
- _a);
14
- var lzEid = chainToLzEid[chainId];
15
- if (!lzEid) {
16
- throw new Error("No LayerZero endpoint ID found for chain ".concat(chainId));
17
- }
18
- return lzEid;
19
- };
20
- exports.getLzEndpointId = getLzEndpointId;
21
- var getOFTTokenAddress = function (tokenName, chainId) {
22
- var tokenInfo = (0, token_info_getters_1.getTokenInfoByName)(tokenName, chainId);
23
- if (!tokenInfo.isOFT) {
24
- throw new Error("getOFTTokenAddress: token ".concat(tokenName, " on chain ").concat(chainId, " is not an OFT token"));
25
- }
26
- return tokenInfo.address;
27
- };
28
- exports.getOFTTokenAddress = getOFTTokenAddress;
29
- //# sourceMappingURL=oft-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oft-config.js","sourceRoot":"/","sources":["utils/layerzero/oft-config.ts"],"names":[],"mappings":";;;AAAA,qCAAwE;AACxE,kEAAiE;AAE1D,IAAM,eAAe,GAAG,UAC7B,OAAwC;;IAExC,IAAM,YAAY;QAChB,GAAC,yBAAiB,CAAC,eAAe,IAAG,KAAK;QAC1C,GAAC,yBAAiB,CAAC,eAAe,IAAG,KAAK;QAC1C,GAAC,mBAAW,CAAC,WAAW,IAAG,KAAK;QAChC,GAAC,mBAAW,CAAC,UAAU,IAAG,KAAK;WAChC,CAAC;IAEF,IAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,mDAA4C,OAAO,CAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAfW,QAAA,eAAe,mBAe1B;AAEK,IAAM,kBAAkB,GAAG,UAChC,SAAoB,EACpB,OAAwC;IAExC,IAAM,SAAS,GAAG,IAAA,uCAAkB,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACzD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,oCAA6B,SAAS,uBAAa,OAAO,yBAAsB,CACjF,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC,OAAO,CAAC;AAC3B,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B","sourcesContent":["import { MoneyInOutChainId, ReyaChainId, TokenName } from '../../types';\nimport { getTokenInfoByName } from '../token/token-info-getters';\n\nexport const getLzEndpointId = (\n chainId: MoneyInOutChainId | ReyaChainId,\n): number => {\n const chainToLzEid: Record<number, number> = {\n [MoneyInOutChainId.ethereumMainnet]: 30101,\n [MoneyInOutChainId.ethereumSepolia]: 40161,\n [ReyaChainId.reyaNetwork]: 30313,\n [ReyaChainId.reyaCronos]: 40319,\n };\n\n const lzEid = chainToLzEid[chainId];\n if (!lzEid) {\n throw new Error(`No LayerZero endpoint ID found for chain ${chainId}`);\n }\n return lzEid;\n};\n\nexport const getOFTTokenAddress = (\n tokenName: TokenName,\n chainId: MoneyInOutChainId | ReyaChainId,\n): string => {\n const tokenInfo = getTokenInfoByName(tokenName, chainId);\n if (!tokenInfo.isOFT) {\n throw new Error(\n `getOFTTokenAddress: token ${tokenName} on chain ${chainId} is not an OFT token`,\n );\n }\n return tokenInfo.address;\n};\n"]}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["utils/layerzero/types.ts"],"names":[],"mappings":"","sourcesContent":["export type OFTSendParam = {\n dstEid: number;\n to: string;\n amountLD: bigint;\n minAmountLD: bigint;\n extraOptions: string;\n composeMsg: string;\n oftCmd: string;\n};\n\nexport type OFTMessagingFee = {\n nativeFee: bigint;\n lzTokenFee: bigint;\n};\n\nexport type OFTMessagingReceipt = {\n guid: string;\n nonce: bigint;\n fee: OFTMessagingFee;\n};\n\nexport type OFTReceipt = {\n amountSentLD: bigint;\n amountReceivedLD: bigint;\n};\n"]}
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './oft-config';
@@ -1,32 +0,0 @@
1
- import { MoneyInOutChainId, ReyaChainId, TokenName } from '../../types';
2
- import { getTokenInfoByName } from '../token/token-info-getters';
3
-
4
- export const getLzEndpointId = (
5
- chainId: MoneyInOutChainId | ReyaChainId,
6
- ): number => {
7
- const chainToLzEid: Record<number, number> = {
8
- [MoneyInOutChainId.ethereumMainnet]: 30101,
9
- [MoneyInOutChainId.ethereumSepolia]: 40161,
10
- [ReyaChainId.reyaNetwork]: 30313,
11
- [ReyaChainId.reyaCronos]: 40319,
12
- };
13
-
14
- const lzEid = chainToLzEid[chainId];
15
- if (!lzEid) {
16
- throw new Error(`No LayerZero endpoint ID found for chain ${chainId}`);
17
- }
18
- return lzEid;
19
- };
20
-
21
- export const getOFTTokenAddress = (
22
- tokenName: TokenName,
23
- chainId: MoneyInOutChainId | ReyaChainId,
24
- ): string => {
25
- const tokenInfo = getTokenInfoByName(tokenName, chainId);
26
- if (!tokenInfo.isOFT) {
27
- throw new Error(
28
- `getOFTTokenAddress: token ${tokenName} on chain ${chainId} is not an OFT token`,
29
- );
30
- }
31
- return tokenInfo.address;
32
- };
@@ -1,25 +0,0 @@
1
- export type OFTSendParam = {
2
- dstEid: number;
3
- to: string;
4
- amountLD: bigint;
5
- minAmountLD: bigint;
6
- extraOptions: string;
7
- composeMsg: string;
8
- oftCmd: string;
9
- };
10
-
11
- export type OFTMessagingFee = {
12
- nativeFee: bigint;
13
- lzTokenFee: bigint;
14
- };
15
-
16
- export type OFTMessagingReceipt = {
17
- guid: string;
18
- nonce: bigint;
19
- fee: OFTMessagingFee;
20
- };
21
-
22
- export type OFTReceipt = {
23
- amountSentLD: bigint;
24
- amountReceivedLD: bigint;
25
- };