@hyperlane-xyz/utils 1.4.1 → 1.4.2-beta70

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 (81) hide show
  1. package/dist/src/addresses.d.ts +29 -0
  2. package/dist/src/addresses.d.ts.map +1 -0
  3. package/dist/src/addresses.js +202 -0
  4. package/dist/src/addresses.js.map +1 -0
  5. package/dist/src/amount.d.ts +9 -0
  6. package/dist/src/amount.d.ts.map +1 -0
  7. package/dist/src/amount.js +79 -0
  8. package/dist/src/amount.js.map +1 -0
  9. package/dist/src/arrays.d.ts +8 -0
  10. package/dist/src/arrays.d.ts.map +1 -0
  11. package/dist/src/arrays.js +16 -0
  12. package/dist/src/arrays.js.map +1 -0
  13. package/dist/src/async.d.ts +37 -0
  14. package/dist/src/async.d.ts.map +1 -0
  15. package/dist/src/async.js +91 -0
  16. package/dist/src/async.js.map +1 -0
  17. package/dist/src/base64.d.ts +3 -0
  18. package/dist/src/base64.d.ts.map +1 -0
  19. package/dist/src/base64.js +30 -0
  20. package/dist/src/base64.js.map +1 -0
  21. package/dist/src/big-numbers.d.ts +36 -0
  22. package/dist/src/big-numbers.d.ts.map +1 -0
  23. package/dist/src/big-numbers.js +93 -0
  24. package/dist/src/big-numbers.js.map +1 -0
  25. package/dist/src/big-numbers.test.d.ts +2 -0
  26. package/dist/src/big-numbers.test.d.ts.map +1 -0
  27. package/dist/src/big-numbers.test.js +41 -0
  28. package/dist/src/big-numbers.test.js.map +1 -0
  29. package/dist/src/calldata.d.ts +3 -0
  30. package/dist/src/calldata.d.ts.map +1 -0
  31. package/dist/src/calldata.js +8 -0
  32. package/dist/src/calldata.js.map +1 -0
  33. package/dist/src/checkpoints.d.ts +5 -0
  34. package/dist/src/checkpoints.d.ts.map +1 -0
  35. package/dist/src/checkpoints.js +30 -0
  36. package/dist/src/checkpoints.js.map +1 -0
  37. package/dist/src/domains.d.ts +2 -0
  38. package/dist/src/domains.d.ts.map +1 -0
  39. package/dist/src/domains.js +10 -0
  40. package/dist/src/domains.js.map +1 -0
  41. package/dist/src/env.d.ts +2 -0
  42. package/dist/src/env.d.ts.map +1 -0
  43. package/dist/src/env.js +15 -0
  44. package/dist/src/env.js.map +1 -0
  45. package/dist/src/ids.d.ts +20 -0
  46. package/dist/src/ids.d.ts.map +1 -0
  47. package/dist/src/ids.js +47 -0
  48. package/dist/src/ids.js.map +1 -0
  49. package/dist/src/math.d.ts +5 -0
  50. package/dist/src/math.d.ts.map +1 -0
  51. package/dist/src/math.js +25 -0
  52. package/dist/src/math.js.map +1 -0
  53. package/dist/src/messages.d.ts +21 -0
  54. package/dist/src/messages.d.ts.map +1 -0
  55. package/dist/src/messages.js +58 -0
  56. package/dist/src/messages.js.map +1 -0
  57. package/dist/src/multisig.d.ts +4 -0
  58. package/dist/src/multisig.d.ts.map +1 -0
  59. package/dist/src/multisig.js +57 -0
  60. package/dist/src/multisig.js.map +1 -0
  61. package/dist/src/objects.d.ts +18 -0
  62. package/dist/src/objects.d.ts.map +1 -0
  63. package/dist/src/objects.js +84 -0
  64. package/dist/src/objects.js.map +1 -0
  65. package/dist/src/sets.d.ts +4 -0
  66. package/dist/src/sets.d.ts.map +1 -0
  67. package/dist/src/sets.js +30 -0
  68. package/dist/src/sets.js.map +1 -0
  69. package/dist/src/strings.d.ts +7 -0
  70. package/dist/src/strings.d.ts.map +1 -0
  71. package/dist/src/strings.js +51 -0
  72. package/dist/src/strings.js.map +1 -0
  73. package/dist/src/typeof.d.ts +3 -0
  74. package/dist/src/typeof.d.ts.map +1 -0
  75. package/dist/src/typeof.js +15 -0
  76. package/dist/src/typeof.js.map +1 -0
  77. package/dist/src/validation.d.ts +2 -0
  78. package/dist/src/validation.d.ts.map +1 -0
  79. package/dist/src/validation.js +10 -0
  80. package/dist/src/validation.js.map +1 -0
  81. package/package.json +4 -3
@@ -0,0 +1,29 @@
1
+ import { Address, HexString, ProtocolType } from './types';
2
+ export declare function isAddressEvm(address: Address): boolean;
3
+ export declare function isAddressSealevel(address: Address): boolean;
4
+ export declare function getAddressProtocolType(address: Address): ProtocolType.Ethereum | ProtocolType.Sealevel | undefined;
5
+ export declare function isValidAddressEvm(address: Address): boolean;
6
+ export declare function isValidAddressSealevel(address: Address): boolean;
7
+ export declare function isValidAddress(address: Address, protocol?: ProtocolType): boolean;
8
+ export declare function normalizeAddressEvm(address: Address): string;
9
+ export declare function normalizeAddressSealevel(address: Address): string;
10
+ export declare function normalizeAddress(address: Address, protocol?: ProtocolType): string;
11
+ export declare function eqAddressEvm(a1: Address, a2: Address): boolean;
12
+ export declare function eqAddressSol(a1: Address, a2: Address): boolean;
13
+ export declare function eqAddress(a1: Address, a2: Address): boolean;
14
+ export declare function isValidTransactionHashEvm(input: string): boolean;
15
+ export declare function isValidTransactionHashSealevel(input: string): boolean;
16
+ export declare function isValidTransactionHash(input: string, protocol?: ProtocolType): boolean;
17
+ export declare function isZeroishAddress(address: Address): boolean;
18
+ export declare function shortenAddress(address: Address, capitalize?: boolean): string;
19
+ export declare function capitalizeAddress(address: Address): string;
20
+ export declare function addressToBytes32(address: Address): string;
21
+ export declare function bytes32ToAddress(bytes32: HexString): Address;
22
+ export declare function adressToBytesEvm(address: Address): Uint8Array;
23
+ export declare function addressToBytesSol(address: Address): Uint8Array;
24
+ export declare function addressToBytes(address: Address, protocol?: ProtocolType): Uint8Array;
25
+ export declare function addressToByteHexString(address: string, protocol?: ProtocolType): string;
26
+ export declare function convertToProtocolAddress(address: string, protocol: ProtocolType): string;
27
+ export declare function ensure0x(hexstr: string): string;
28
+ export declare function strip0x(hexstr: string): string;
29
+ //# sourceMappingURL=addresses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../src/addresses.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAU3D,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,WAE5C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gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAG7D;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAE9D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,cAQvE;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,YAAY,UAGxB;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,YAAY,UAyBvB;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,UAEtC;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,UAErC"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.strip0x = exports.ensure0x = exports.convertToProtocolAddress = exports.addressToByteHexString = exports.addressToBytes = exports.addressToBytesSol = exports.adressToBytesEvm = exports.bytes32ToAddress = exports.addressToBytes32 = exports.capitalizeAddress = exports.shortenAddress = exports.isZeroishAddress = exports.isValidTransactionHash = exports.isValidTransactionHashSealevel = exports.isValidTransactionHashEvm = exports.eqAddress = exports.eqAddressSol = exports.eqAddressEvm = exports.normalizeAddress = exports.normalizeAddressSealevel = exports.normalizeAddressEvm = exports.isValidAddress = exports.isValidAddressSealevel = exports.isValidAddressEvm = exports.getAddressProtocolType = exports.isAddressSealevel = exports.isAddressEvm = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const ethers_1 = require("ethers");
6
+ const types_1 = require("./types");
7
+ const EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
8
+ const SEALEVEL_ADDRESS_REGEX = /^[a-zA-Z0-9]{36,44}$/;
9
+ const EVM_TX_HASH_REGEX = /^0x([A-Fa-f0-9]{64})$/;
10
+ const SEALEVEL_TX_HASH_REGEX = /^[a-zA-Z1-9]{88}$/;
11
+ const ZEROISH_ADDRESS_REGEX = /^(0x)?0*$/;
12
+ function isAddressEvm(address) {
13
+ return EVM_ADDRESS_REGEX.test(address);
14
+ }
15
+ exports.isAddressEvm = isAddressEvm;
16
+ function isAddressSealevel(address) {
17
+ return SEALEVEL_ADDRESS_REGEX.test(address);
18
+ }
19
+ exports.isAddressSealevel = isAddressSealevel;
20
+ function getAddressProtocolType(address) {
21
+ if (!address)
22
+ return undefined;
23
+ if (isAddressEvm(address)) {
24
+ return types_1.ProtocolType.Ethereum;
25
+ }
26
+ else if (isAddressSealevel(address)) {
27
+ return types_1.ProtocolType.Sealevel;
28
+ }
29
+ else {
30
+ return undefined;
31
+ }
32
+ }
33
+ exports.getAddressProtocolType = getAddressProtocolType;
34
+ function routeAddressUtil(evmFn, sealevelFn, fallback, param, protocol) {
35
+ protocol = protocol || getAddressProtocolType(param);
36
+ if (protocol === types_1.ProtocolType.Ethereum) {
37
+ return evmFn(param);
38
+ }
39
+ else if (protocol === types_1.ProtocolType.Sealevel) {
40
+ return sealevelFn(param);
41
+ }
42
+ else {
43
+ return fallback;
44
+ }
45
+ }
46
+ // Slower than isAddressEvm above but actually validates content and checksum
47
+ function isValidAddressEvm(address) {
48
+ // Need to catch because ethers' isAddress throws in some cases (bad checksum)
49
+ try {
50
+ const isValid = address && ethers_1.utils.isAddress(address);
51
+ return !!isValid;
52
+ }
53
+ catch (error) {
54
+ return false;
55
+ }
56
+ }
57
+ exports.isValidAddressEvm = isValidAddressEvm;
58
+ // Slower than isAddressSealevel above but actually validates content and checksum
59
+ function isValidAddressSealevel(address) {
60
+ try {
61
+ const isValid = address && new web3_js_1.PublicKey(address).toBase58();
62
+ return !!isValid;
63
+ }
64
+ catch (error) {
65
+ return false;
66
+ }
67
+ }
68
+ exports.isValidAddressSealevel = isValidAddressSealevel;
69
+ function isValidAddress(address, protocol) {
70
+ return routeAddressUtil(isValidAddressEvm, isValidAddressSealevel, false, address, protocol);
71
+ }
72
+ exports.isValidAddress = isValidAddress;
73
+ function normalizeAddressEvm(address) {
74
+ if (isZeroishAddress(address))
75
+ return address;
76
+ try {
77
+ return ethers_1.utils.getAddress(address);
78
+ }
79
+ catch (error) {
80
+ return address;
81
+ }
82
+ }
83
+ exports.normalizeAddressEvm = normalizeAddressEvm;
84
+ function normalizeAddressSealevel(address) {
85
+ if (isZeroishAddress(address))
86
+ return address;
87
+ try {
88
+ return new web3_js_1.PublicKey(address).toBase58();
89
+ }
90
+ catch (error) {
91
+ return address;
92
+ }
93
+ }
94
+ exports.normalizeAddressSealevel = normalizeAddressSealevel;
95
+ function normalizeAddress(address, protocol) {
96
+ return routeAddressUtil(normalizeAddressEvm, normalizeAddressSealevel, address, address, protocol);
97
+ }
98
+ exports.normalizeAddress = normalizeAddress;
99
+ function eqAddressEvm(a1, a2) {
100
+ return normalizeAddressEvm(a1) === normalizeAddressEvm(a2);
101
+ }
102
+ exports.eqAddressEvm = eqAddressEvm;
103
+ function eqAddressSol(a1, a2) {
104
+ return normalizeAddressSealevel(a1) === normalizeAddressSealevel(a2);
105
+ }
106
+ exports.eqAddressSol = eqAddressSol;
107
+ function eqAddress(a1, a2) {
108
+ const p1 = getAddressProtocolType(a1);
109
+ const p2 = getAddressProtocolType(a2);
110
+ if (p1 !== p2)
111
+ return false;
112
+ return routeAddressUtil((_a1) => eqAddressEvm(_a1, a2), (_a1) => eqAddressSol(_a1, a2), false, a1, p1);
113
+ }
114
+ exports.eqAddress = eqAddress;
115
+ function isValidTransactionHashEvm(input) {
116
+ return EVM_TX_HASH_REGEX.test(input);
117
+ }
118
+ exports.isValidTransactionHashEvm = isValidTransactionHashEvm;
119
+ function isValidTransactionHashSealevel(input) {
120
+ return SEALEVEL_TX_HASH_REGEX.test(input);
121
+ }
122
+ exports.isValidTransactionHashSealevel = isValidTransactionHashSealevel;
123
+ function isValidTransactionHash(input, protocol) {
124
+ return routeAddressUtil(isValidTransactionHashEvm, isValidTransactionHashSealevel, false, input, protocol);
125
+ }
126
+ exports.isValidTransactionHash = isValidTransactionHash;
127
+ function isZeroishAddress(address) {
128
+ return ZEROISH_ADDRESS_REGEX.test(address);
129
+ }
130
+ exports.isZeroishAddress = isZeroishAddress;
131
+ function shortenAddress(address, capitalize) {
132
+ if (!address)
133
+ return '';
134
+ if (address.length < 8)
135
+ return address;
136
+ const normalized = normalizeAddress(address);
137
+ const shortened = normalized.substring(0, 5) +
138
+ '...' +
139
+ normalized.substring(normalized.length - 4);
140
+ return capitalize ? capitalizeAddress(shortened) : shortened;
141
+ }
142
+ exports.shortenAddress = shortenAddress;
143
+ function capitalizeAddress(address) {
144
+ if (address.startsWith('0x'))
145
+ return '0x' + address.substring(2).toUpperCase();
146
+ else
147
+ return address.toUpperCase();
148
+ }
149
+ exports.capitalizeAddress = capitalizeAddress;
150
+ function addressToBytes32(address) {
151
+ return ethers_1.utils
152
+ .hexZeroPad(ethers_1.utils.hexStripZeros(address), 32)
153
+ .toLowerCase();
154
+ }
155
+ exports.addressToBytes32 = addressToBytes32;
156
+ function bytes32ToAddress(bytes32) {
157
+ return ethers_1.utils.getAddress(bytes32.slice(-40));
158
+ }
159
+ exports.bytes32ToAddress = bytes32ToAddress;
160
+ function adressToBytesEvm(address) {
161
+ const addrBytes32 = addressToBytes32(address);
162
+ return Buffer.from(addrBytes32.substring(2), 'hex');
163
+ }
164
+ exports.adressToBytesEvm = adressToBytesEvm;
165
+ function addressToBytesSol(address) {
166
+ return new web3_js_1.PublicKey(address).toBytes();
167
+ }
168
+ exports.addressToBytesSol = addressToBytesSol;
169
+ function addressToBytes(address, protocol) {
170
+ return routeAddressUtil(adressToBytesEvm, addressToBytesSol, new Uint8Array(), address, protocol);
171
+ }
172
+ exports.addressToBytes = addressToBytes;
173
+ function addressToByteHexString(address, protocol) {
174
+ return '0x' + Buffer.from(addressToBytes(address, protocol)).toString('hex');
175
+ }
176
+ exports.addressToByteHexString = addressToByteHexString;
177
+ function convertToProtocolAddress(address, protocol) {
178
+ const currentProtocol = getAddressProtocolType(address);
179
+ if (currentProtocol === protocol)
180
+ return address;
181
+ if (currentProtocol === types_1.ProtocolType.Ethereum &&
182
+ protocol === types_1.ProtocolType.Sealevel) {
183
+ return new web3_js_1.PublicKey(addressToBytes(address, types_1.ProtocolType.Ethereum)).toBase58();
184
+ }
185
+ else if (currentProtocol === types_1.ProtocolType.Sealevel &&
186
+ protocol === types_1.ProtocolType.Ethereum) {
187
+ return bytes32ToAddress(Buffer.from(addressToBytes(address, types_1.ProtocolType.Sealevel)).toString('hex'));
188
+ }
189
+ else {
190
+ throw new Error(`Unsupported protocol combination ${currentProtocol} -> ${protocol}`);
191
+ }
192
+ }
193
+ exports.convertToProtocolAddress = convertToProtocolAddress;
194
+ function ensure0x(hexstr) {
195
+ return hexstr.startsWith('0x') ? hexstr : `0x${hexstr}`;
196
+ }
197
+ exports.ensure0x = ensure0x;
198
+ function strip0x(hexstr) {
199
+ return hexstr.startsWith('0x') ? hexstr.slice(2) : hexstr;
200
+ }
201
+ exports.strip0x = strip0x;
202
+ //# sourceMappingURL=addresses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../src/addresses.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAC5C,mCAA8C;AAE9C,mCAA2D;AAE3D,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAChD,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAEtD,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAClD,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAE1C,SAAgB,YAAY,CAAC,OAAgB;IAC3C,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAFD,oCAEC;AAED,SAAgB,iBAAiB,CAAC,OAAgB;IAChD,OAAO,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAFD,8CAEC;AAED,SAAgB,sBAAsB,CAAC,O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EC"}
@@ -0,0 +1,9 @@
1
+ import BigNumber from 'bignumber.js';
2
+ type NumberT = BigNumber.Value;
3
+ export declare function fromWei(value: NumberT | null | undefined, decimals?: number): number;
4
+ export declare function fromWeiRounded(value: NumberT | null | undefined, decimals?: number, roundDownIfSmall?: boolean): string;
5
+ export declare function toWei(value: NumberT | null | undefined, decimals?: number): BigNumber;
6
+ export declare function tryParseAmount(value: NumberT | null | undefined): BigNumber | null;
7
+ export declare function eqAmountApproximate(amountInWei1: BigNumber, amountInWei2: NumberT): boolean;
8
+ export {};
9
+ //# sourceMappingURL=amount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AAMrC,KAAK,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC;AAE/B,wBAAgB,OAAO,CACrB,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,SAAyB,GAChC,MAAM,CAQR;AAID,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,SAAyB,EACjC,gBAAgB,UAAO,GACtB,MAAM,CAaR;AAED,wBAAgB,KAAK,CACnB,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,SAAyB,GAChC,SAAS,CAcX;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAChC,SAAS,GAAG,IAAI,CASlB;AAID,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,SAAS,EACvB,YAAY,EAAE,OAAO,WAKtB"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.eqAmountApproximate = exports.tryParseAmount = exports.toWei = exports.fromWeiRounded = exports.fromWei = void 0;
7
+ const units_1 = require("@ethersproject/units");
8
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
9
+ const DEFAULT_MIN_ROUNDED_VALUE = 0.00001;
10
+ const DEFAULT_DISPLAY_DECIMALS = 5;
11
+ const DEFAULT_TOKEN_DECIMALS = 18;
12
+ function fromWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
13
+ if (!value)
14
+ return 0;
15
+ const valueString = value.toString().trim();
16
+ const flooredValue = new bignumber_js_1.default(valueString).toFixed(0, bignumber_js_1.default.ROUND_FLOOR);
17
+ return parseFloat((0, units_1.formatUnits)(flooredValue, decimals));
18
+ }
19
+ exports.fromWei = fromWei;
20
+ // Similar to fromWei above but rounds to set number of decimals
21
+ // with a minimum floor, configured per token
22
+ function fromWeiRounded(value, decimals = DEFAULT_TOKEN_DECIMALS, roundDownIfSmall = true) {
23
+ if (!value)
24
+ return '0';
25
+ const flooredValue = new bignumber_js_1.default(value).toFixed(0, bignumber_js_1.default.ROUND_FLOOR);
26
+ const amount = new bignumber_js_1.default((0, units_1.formatUnits)(flooredValue, decimals));
27
+ if (amount.isZero())
28
+ return '0';
29
+ // If amount is less than min value
30
+ if (amount.lt(DEFAULT_MIN_ROUNDED_VALUE)) {
31
+ if (roundDownIfSmall)
32
+ return '0';
33
+ else
34
+ return DEFAULT_MIN_ROUNDED_VALUE.toString();
35
+ }
36
+ return amount.toFixed(DEFAULT_DISPLAY_DECIMALS).toString();
37
+ }
38
+ exports.fromWeiRounded = fromWeiRounded;
39
+ function toWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
40
+ if (!value)
41
+ return new bignumber_js_1.default(0);
42
+ const valueString = value.toString().trim();
43
+ const components = valueString.split('.');
44
+ if (components.length === 1) {
45
+ return new bignumber_js_1.default((0, units_1.parseUnits)(valueString, decimals).toString());
46
+ }
47
+ else if (components.length === 2) {
48
+ const trimmedFraction = components[1].substring(0, decimals);
49
+ return new bignumber_js_1.default((0, units_1.parseUnits)(`${components[0]}.${trimmedFraction}`, decimals).toString());
50
+ }
51
+ else {
52
+ throw new Error(`Cannot convert ${valueString} to wei`);
53
+ }
54
+ }
55
+ exports.toWei = toWei;
56
+ function tryParseAmount(value) {
57
+ try {
58
+ if (!value)
59
+ return null;
60
+ const parsed = new bignumber_js_1.default(value);
61
+ if (!parsed || parsed.isNaN() || !parsed.isFinite())
62
+ return null;
63
+ else
64
+ return parsed;
65
+ }
66
+ catch (error) {
67
+ return null;
68
+ }
69
+ }
70
+ exports.tryParseAmount = tryParseAmount;
71
+ // Checks if an amount is equal of nearly equal to balance within a small margin of error
72
+ // Necessary because amounts in the UI are often rounded
73
+ function eqAmountApproximate(amountInWei1, amountInWei2) {
74
+ const minValueWei = toWei(DEFAULT_MIN_ROUNDED_VALUE);
75
+ // Is difference btwn amount and balance less than min amount shown for token
76
+ return amountInWei1.minus(amountInWei2).abs().lt(minValueWei);
77
+ }
78
+ exports.eqAmountApproximate = eqAmountApproximate;
79
+ //# sourceMappingURL=amount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA+D;AAC/D,gEAAqC;AAErC,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAC1C,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAIlC,SAAgB,OAAO,CACrB,KAAiC,EACjC,QAAQ,GAAG,sBAAsB;IAEjC,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,CAAC;IACrB,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;IAC5C,MAAM,YAAY,GAAG,IAAI,sBAAS,CAAC,WAAW,CAAC,CAAC,OAAO,CACrD,CAAC,EACD,sBAAS,CAAC,WAAW,CACtB,CAAC;IACF,OAAO,UAAU,CAAC,IAAA,mBAAW,EAA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,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAClC,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC7D,OAAO,IAAI,sBAAS,CAClB,IAAA,kBAAU,EAAC,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,eAAe,EAAE,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CACvE,CAAC;KACH;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,kBAAkB,WAAW,SAAS,CAAC,CAAC;KACzD;AACH,CAAC;AAjBD,sBAiBC;AAED,SAAgB,cAAc,CAC5B,KAAiC;IAEjC,IAAI;QACF,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,MAAM,MAAM,GAAG,IAAI,sBAAS,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YAAE,OAAO,IAAI,CAAC;;YAC5D,OAAO,MAAM,CAAC;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AAXD,wCAWC;AAED,yFAAyF;AACzF,wDAAwD;AACxD,SAAgB,mBAAmB,CACjC,YAAuB,EACvB,YAAqB;IAErB,MAAM,WAAW,GAAG,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACrD,6EAA6E;IAC7E,OAAO,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AAChE,CAAC;AAPD,kDAOC"}
@@ -0,0 +1,8 @@
1
+ interface Sliceable {
2
+ length: number;
3
+ slice: (i: number, j: number) => any;
4
+ }
5
+ export declare function chunk<T extends Sliceable>(str: T, size: number): T[];
6
+ export declare function exclude<T>(item: T, list: T[]): T[];
7
+ export {};
8
+ //# sourceMappingURL=arrays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../../src/arrays.ts"],"names":[],"mappings":"AAAA,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;CACtC;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,OAM9D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAE5C"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exclude = exports.chunk = void 0;
4
+ function chunk(str, size) {
5
+ const R = [];
6
+ for (let i = 0; i < str.length; i += size) {
7
+ R.push(str.slice(i, i + size));
8
+ }
9
+ return R;
10
+ }
11
+ exports.chunk = chunk;
12
+ function exclude(item, list) {
13
+ return list.filter((i) => i !== item);
14
+ }
15
+ exports.exclude = exclude;
16
+ //# sourceMappingURL=arrays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.js","sourceRoot":"","sources":["../../src/arrays.ts"],"names":[],"mappings":";;;AAKA,SAAgB,KAAK,CAAsB,GAAM,EAAE,IAAY;IAC7D,MAAM,CAAC,GAAa,EAAE,CAAC;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE;QACzC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;KAChC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAND,sBAMC;AAED,SAAgB,OAAO,CAAI,IAAO,EAAE,IAAS;IAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AACxC,CAAC;AAFD,0BAEC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Return a promise that resolves in ms milliseconds.
3
+ * @param ms Time to wait
4
+ */
5
+ export declare function sleep(ms: number): Promise<void>;
6
+ /**
7
+ * Wait up to a given amount of time, and throw an error if the promise does not resolve in time.
8
+ * @param promise The promise to timeout on.
9
+ * @param timeoutMs How long to wait for the promise in milliseconds.
10
+ * @param message The error message if a timeout occurs.
11
+ */
12
+ export declare function timeout<T>(promise: Promise<T>, timeoutMs?: number, message?: string): Promise<T>;
13
+ /**
14
+ * Run a callback with a timeout.
15
+ * @param timeoutMs How long to wait for the promise in milliseconds.
16
+ * @param callback The callback to run.
17
+ * @returns callback return value
18
+ */
19
+ export declare function runWithTimeout<T>(timeoutMs: number, callback: () => Promise<T>): Promise<T | void>;
20
+ /**
21
+ * Retries an async function if it raises an exception,
22
+ * using exponential backoff.
23
+ * @param runner callback to run
24
+ * @param attempts max number of attempts
25
+ * @param baseRetryMs base delay between attempts
26
+ * @returns runner return value
27
+ */
28
+ export declare function retryAsync<T>(runner: () => T, attempts?: number, baseRetryMs?: number): Promise<T>;
29
+ /**
30
+ * Run a callback with a timeout, and retry if the callback throws an error.
31
+ * @param runner callback to run
32
+ * @param delayMs base delay between attempts
33
+ * @param maxAttempts maximum number of attempts
34
+ * @returns runner return value
35
+ */
36
+ export declare function pollAsync<T>(runner: () => Promise<T>, delayMs?: number, maxAttempts?: number | undefined): Promise<T>;
37
+ //# sourceMappingURL=async.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,SAAoB,GAC1B,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAanB;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,MAAM,EAAE,MAAM,CAAC,EACf,QAAQ,SAAI,EACZ,WAAW,SAAK,cAajB;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,SAAM,EACb,WAAW,GAAE,MAAM,GAAG,SAAqB,cAe5C"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pollAsync = exports.retryAsync = exports.runWithTimeout = exports.timeout = exports.sleep = void 0;
4
+ /**
5
+ * Return a promise that resolves in ms milliseconds.
6
+ * @param ms Time to wait
7
+ */
8
+ function sleep(ms) {
9
+ return new Promise((resolve) => setTimeout(resolve, ms));
10
+ }
11
+ exports.sleep = sleep;
12
+ /**
13
+ * Wait up to a given amount of time, and throw an error if the promise does not resolve in time.
14
+ * @param promise The promise to timeout on.
15
+ * @param timeoutMs How long to wait for the promise in milliseconds.
16
+ * @param message The error message if a timeout occurs.
17
+ */
18
+ function timeout(promise, timeoutMs, message = 'Timeout reached') {
19
+ if (!timeoutMs || timeoutMs <= 0)
20
+ return promise;
21
+ return new Promise((resolve, reject) => {
22
+ setTimeout(() => {
23
+ reject(new Error(message));
24
+ }, timeoutMs);
25
+ promise.then(resolve).catch(reject);
26
+ });
27
+ }
28
+ exports.timeout = timeout;
29
+ /**
30
+ * Run a callback with a timeout.
31
+ * @param timeoutMs How long to wait for the promise in milliseconds.
32
+ * @param callback The callback to run.
33
+ * @returns callback return value
34
+ */
35
+ async function runWithTimeout(timeoutMs, callback) {
36
+ let timeout;
37
+ const timeoutProm = new Promise((_, reject) => (timeout = setTimeout(() => reject(new Error(`Timed out in ${timeoutMs}ms.`)), timeoutMs)));
38
+ const ret = await Promise.race([callback(), timeoutProm]);
39
+ // @ts-ignore timeout gets set immediately by the promise constructor
40
+ clearTimeout(timeout);
41
+ return ret;
42
+ }
43
+ exports.runWithTimeout = runWithTimeout;
44
+ /**
45
+ * Retries an async function if it raises an exception,
46
+ * using exponential backoff.
47
+ * @param runner callback to run
48
+ * @param attempts max number of attempts
49
+ * @param baseRetryMs base delay between attempts
50
+ * @returns runner return value
51
+ */
52
+ async function retryAsync(runner, attempts = 5, baseRetryMs = 50) {
53
+ let saveError;
54
+ for (let i = 0; i < attempts; i++) {
55
+ try {
56
+ const result = await runner();
57
+ return result;
58
+ }
59
+ catch (error) {
60
+ saveError = error;
61
+ await sleep(baseRetryMs * 2 ** i);
62
+ }
63
+ }
64
+ throw saveError;
65
+ }
66
+ exports.retryAsync = retryAsync;
67
+ /**
68
+ * Run a callback with a timeout, and retry if the callback throws an error.
69
+ * @param runner callback to run
70
+ * @param delayMs base delay between attempts
71
+ * @param maxAttempts maximum number of attempts
72
+ * @returns runner return value
73
+ */
74
+ async function pollAsync(runner, delayMs = 500, maxAttempts = undefined) {
75
+ let attempts = 0;
76
+ let saveError;
77
+ while (!maxAttempts || attempts < maxAttempts) {
78
+ try {
79
+ const ret = await runner();
80
+ return ret;
81
+ }
82
+ catch (error) {
83
+ saveError = error;
84
+ attempts += 1;
85
+ await sleep(delayMs);
86
+ }
87
+ }
88
+ throw saveError;
89
+ }
90
+ exports.pollAsync = pollAsync;
91
+ //# sourceMappingURL=async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/async.ts"],"names":[],"mappings":";;;AAAA;;;GA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QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,EAAE;IAEhB,IAAI,SAAS,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE;QACjC,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,MAAM,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,KAAK,EAAE;YACd,SAAS,GAAG,KAAK,CAAC;YAClB,MAAM,KAAK,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;SACnC;KACF;IACD,MAAM,SAAS,CAAC;AAClB,CAAC;AAhBD,gCAgBC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,SAAS,CAC7B,MAAwB,EACxB,OAAO,GAAG,GAAG,EACb,cAAkC,SAAS;IAE3C,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,SAAS,CAAC;IACd,OAAO,CAAC,WAAW,IAAI,QAAQ,GAAG,WAAW,EAAE;QAC7C,IAAI;YACF,MAAM,GAAG,GAAG,MAAM,MAAM,EAAE,CAAC;YAC3B,OAAO,GAAG,CAAC;SACZ;QAAC,OAAO,KAAK,EAAE;YACd,SAAS,GAAG,KAAK,CAAC;YAClB,QAAQ,IAAI,CAAC,CAAC;YACd,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;SACtB;KACF;IACD,MAAM,SAAS,CAAC;AAClB,CAAC;AAlBD,8BAkBC"}
@@ -0,0 +1,3 @@
1
+ export declare function toBase64(data: any): string | undefined;
2
+ export declare function fromBase64<T>(data: string | string[]): T | undefined;
3
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAQtD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CASpE"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromBase64 = exports.toBase64 = void 0;
4
+ const logging_1 = require("./logging");
5
+ function toBase64(data) {
6
+ try {
7
+ if (!data)
8
+ throw new Error('No data to encode');
9
+ return btoa(JSON.stringify(data));
10
+ }
11
+ catch (error) {
12
+ (0, logging_1.log)('Unable to serialize + encode data to base64', data);
13
+ return undefined;
14
+ }
15
+ }
16
+ exports.toBase64 = toBase64;
17
+ function fromBase64(data) {
18
+ try {
19
+ if (!data)
20
+ throw new Error('No data to decode');
21
+ const msg = Array.isArray(data) ? data[0] : data;
22
+ return JSON.parse(atob(msg));
23
+ }
24
+ catch (error) {
25
+ (0, logging_1.log)('Unable to decode + deserialize data from base64', data);
26
+ return undefined;
27
+ }
28
+ }
29
+ exports.fromBase64 = fromBase64;
30
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":";;;AAAA,uCAAgC;AAEhC,SAAgB,QAAQ,CAAC,IAAS;IAChC,IAAI;QACF,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACnC;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,aAAG,EAAC,6CAA6C,EAAE,IAAI,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AARD,4BAQC;AAED,SAAgB,UAAU,CAAI,IAAuB;IACnD,IAAI;QACF,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;KAC9B;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,aAAG,EAAC,iDAAiD,EAAE,IAAI,CAAC,CAAC;QAC7D,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AATD,gCASC"}
@@ -0,0 +1,36 @@
1
+ import { BigNumber, BigNumberish, FixedNumber } from 'ethers';
2
+ export declare function isBigNumberish(value: any): value is BigNumberish;
3
+ export declare function isZeroish(value: BigNumberish): boolean;
4
+ /**
5
+ * Converts a BigNumber to a FixedNumber of the format fixed128x18.
6
+ * @param big The BigNumber to convert.
7
+ * @returns A FixedNumber representation of a BigNumber.
8
+ */
9
+ export declare function bigToFixed(big: BigNumber): FixedNumber;
10
+ /**
11
+ * Converts a FixedNumber (of any format) to a BigNumber.
12
+ * @param fixed The FixedNumber to convert.
13
+ * @param ceil If true, the ceiling of fixed is used. Otherwise, the floor is used.
14
+ * @returns A BigNumber representation of a FixedNumber.
15
+ */
16
+ export declare function fixedToBig(fixed: FixedNumber, ceil?: boolean): BigNumber;
17
+ /**
18
+ * Multiplies a BigNumber by a FixedNumber, returning the BigNumber product.
19
+ * @param big The BigNumber to multiply.
20
+ * @param fixed The FixedNumber to multiply.
21
+ * @param ceil If true, the ceiling of the product is used. Otherwise, the floor is used.
22
+ * @returns The BigNumber product.
23
+ */
24
+ export declare function mulBigAndFixed(big: BigNumber, fixed: FixedNumber, ceil?: boolean): BigNumber;
25
+ /**
26
+ * Converts a value with `fromDecimals` decimals to a value with `toDecimals` decimals.
27
+ * Incurs a loss of precision when `fromDecimals` > `toDecimals`.
28
+ * @param value The value to convert.
29
+ * @param fromDecimals The number of decimals `value` has.
30
+ * @param toDecimals The number of decimals to convert `value` to.
31
+ * @returns `value` represented with `toDecimals` decimals.
32
+ */
33
+ export declare function convertDecimalValue(value: BigNumber, fromDecimals: number, toDecimals: number): BigNumber;
34
+ export declare function BigNumberMin(bn1: BigNumber, bn2: BigNumber): BigNumber;
35
+ export declare function BigNumberMax(bn1: BigNumber, bn2: BigNumber): BigNumber;
36
+ //# sourceMappingURL=big-numbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"big-numbers.d.ts","sourceRoot":"","sources":["../../src/big-numbers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAa,MAAM,QAAQ,CAAC;AAIzE,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,YAAY,CAOhE;AAGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,WAY5C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,WAAW,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,UAAQ,GAAG,SAAS,CAGtE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,WAAW,EAClB,IAAI,UAAQ,GACX,SAAS,CAIX;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,EAChB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,SAAS,CASX;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,aAE1D;AACD,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,aAE1D"}