@orb-labs/orby-core 0.0.6 → 0.0.7

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 (54) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/actions/account_cluster.d.ts +4 -4
  3. package/dist/actions/account_cluster.js +147 -338
  4. package/dist/actions/admin.d.ts +3 -3
  5. package/dist/actions/admin.js +37 -127
  6. package/dist/actions/application.d.ts +2 -2
  7. package/dist/actions/application.js +14 -77
  8. package/dist/actions/instance.d.ts +3 -3
  9. package/dist/actions/instance.js +98 -255
  10. package/dist/actions/operation.d.ts +4 -4
  11. package/dist/actions/operation.js +92 -263
  12. package/dist/actions/token.d.ts +3 -3
  13. package/dist/actions/token.js +34 -119
  14. package/dist/constants.d.ts +3 -3
  15. package/dist/constants.js +70 -71
  16. package/dist/entities/account.d.ts +1 -1
  17. package/dist/entities/account.js +25 -30
  18. package/dist/entities/financial/account_balance.d.ts +2 -2
  19. package/dist/entities/financial/account_balance.js +20 -22
  20. package/dist/entities/financial/asset.js +13 -15
  21. package/dist/entities/financial/currency.d.ts +1 -1
  22. package/dist/entities/financial/currency.js +16 -35
  23. package/dist/entities/financial/currency_amount.d.ts +1 -1
  24. package/dist/entities/financial/currency_amount.js +49 -71
  25. package/dist/entities/financial/fungible_token.d.ts +2 -2
  26. package/dist/entities/financial/fungible_token.js +31 -52
  27. package/dist/entities/financial/fungible_token_amount.d.ts +2 -2
  28. package/dist/entities/financial/fungible_token_amount.js +53 -75
  29. package/dist/entities/financial/non_fungible_token.d.ts +2 -2
  30. package/dist/entities/financial/non_fungible_token.js +25 -45
  31. package/dist/entities/financial/semi_fungible_token.d.ts +2 -2
  32. package/dist/entities/financial/semi_fungible_token.js +25 -45
  33. package/dist/entities/library_request.d.ts +1 -1
  34. package/dist/entities/library_request.js +7 -9
  35. package/dist/entities/state.d.ts +4 -4
  36. package/dist/entities/state.js +57 -67
  37. package/dist/index.d.ts +27 -27
  38. package/dist/index.js +27 -27
  39. package/dist/interfaces/account_cluster.d.ts +3 -3
  40. package/dist/interfaces/admin.d.ts +1 -1
  41. package/dist/interfaces/instance.d.ts +1 -1
  42. package/dist/interfaces/operation.d.ts +3 -3
  43. package/dist/interfaces/orby.d.ts +6 -6
  44. package/dist/interfaces/token.d.ts +1 -1
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/dist/types.d.ts +7 -7
  47. package/dist/utils/action_helpers.d.ts +1 -1
  48. package/dist/utils/action_helpers.js +42 -58
  49. package/dist/utils/jsbi.d.ts +2 -0
  50. package/dist/utils/jsbi.js +2 -0
  51. package/dist/utils/utils.d.ts +1 -1
  52. package/dist/utils/utils.js +17 -19
  53. package/dist/utils/validateAndParseAddress.js +3 -3
  54. package/package.json +4 -2
@@ -1,114 +1,92 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
1
  import invariant from "tiny-invariant";
17
2
  import JSBI from "jsbi";
18
3
  import { Fraction, MaxUint256, Rounding } from "@uniswap/sdk-core";
19
- import { Currency } from "./currency";
20
- import { Big } from "../../constants";
4
+ import { Currency } from "./currency.js";
5
+ import { Big } from "../../constants.js";
21
6
  // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
22
7
  // because we have a need to represent a currency amount that is not a fungible token amount.
23
- var CurrencyAmount = /** @class */ (function (_super) {
24
- __extends(CurrencyAmount, _super);
25
- function CurrencyAmount(currency, numerator, denominator) {
26
- var _this = _super.call(this, numerator.toString(), denominator === null || denominator === void 0 ? void 0 : denominator.toString()) || this;
27
- invariant(JSBI.lessThanOrEqual(_this.quotient, MaxUint256), "AMOUNT");
28
- _this.currency = currency;
29
- _this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(currency.decimals));
30
- return _this;
31
- }
8
+ export class CurrencyAmount extends Fraction {
32
9
  /**
33
10
  * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
34
11
  * @param currency the currency in the amount
35
12
  * @param rawAmount the raw token or ether amount
36
13
  */
37
- CurrencyAmount.fromRawAmount = function (currency, rawAmount) {
14
+ static fromRawAmount(currency, rawAmount) {
38
15
  return new CurrencyAmount(currency, rawAmount);
39
- };
40
- CurrencyAmount.toCurrencyAmount = function (amount) {
16
+ }
17
+ static toCurrencyAmount(amount) {
41
18
  if (!amount) {
42
19
  return undefined;
43
20
  }
44
- var currency = Currency.toCurrency(amount.currency);
21
+ const currency = Currency.toCurrency(amount.currency);
45
22
  return CurrencyAmount.fromRawAmount(currency, amount.value);
46
- };
23
+ }
47
24
  /**
48
25
  * Construct a currency amount with a denominator that is not equal to 1
49
26
  * @param currency the currency
50
27
  * @param numerator the numerator of the fractional token amount
51
28
  * @param denominator the denominator of the fractional token amount
52
29
  */
53
- CurrencyAmount.fromFractionalAmount = function (currency, numerator, denominator) {
30
+ static fromFractionalAmount(currency, numerator, denominator) {
54
31
  return new CurrencyAmount(currency, numerator, denominator);
55
- };
56
- CurrencyAmount.prototype.add = function (other) {
32
+ }
33
+ constructor(currency, numerator, denominator) {
34
+ super(numerator.toString(), denominator?.toString());
35
+ invariant(JSBI.lessThanOrEqual(this.quotient, MaxUint256), "AMOUNT");
36
+ this.currency = currency;
37
+ this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(currency.decimals));
38
+ }
39
+ add(other) {
57
40
  if (!other) {
58
41
  return this;
59
42
  }
60
43
  invariant(this.currency.equals(other.currency), "CURRENCY");
61
- var added = _super.prototype.add.call(this, other);
44
+ const added = super.add(other);
62
45
  return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
63
- };
64
- CurrencyAmount.prototype.subtract = function (other) {
46
+ }
47
+ subtract(other) {
65
48
  invariant(this.currency.equals(other.currency), "CURRENCY");
66
- var subtracted = _super.prototype.subtract.call(this, other);
49
+ const subtracted = super.subtract(other);
67
50
  return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
68
- };
69
- CurrencyAmount.prototype.multiply = function (other) {
70
- var multiplied = _super.prototype.multiply.call(this, other);
51
+ }
52
+ multiply(other) {
53
+ const multiplied = super.multiply(other);
71
54
  return CurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
72
- };
73
- CurrencyAmount.prototype.divide = function (other) {
74
- var divided = _super.prototype.divide.call(this, other);
55
+ }
56
+ divide(other) {
57
+ const divided = super.divide(other);
75
58
  return CurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
76
- };
77
- CurrencyAmount.prototype.cloneWithAmount = function (amount) {
59
+ }
60
+ cloneWithAmount(amount) {
78
61
  return CurrencyAmount.fromRawAmount(this.currency, amount);
79
- };
80
- CurrencyAmount.prototype.toRawAmount = function () {
62
+ }
63
+ toRawAmount() {
81
64
  return BigInt(this.quotient.toString());
82
- };
83
- CurrencyAmount.prototype.toCurrencyValue = function (price) {
84
- var fraction = price.multiply(this);
85
- var denominator = JSBI.multiply(fraction.denominator, this.decimalScale);
65
+ }
66
+ toCurrencyValue(price) {
67
+ const fraction = price.multiply(this);
68
+ const denominator = JSBI.multiply(fraction.denominator, this.decimalScale);
86
69
  this.amountInFiatCurrency = CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
87
70
  return this.amountInFiatCurrency;
88
- };
89
- CurrencyAmount.prototype.fiatValue = function () {
71
+ }
72
+ fiatValue() {
90
73
  return this.amountInFiatCurrency;
91
- };
92
- CurrencyAmount.prototype.toSignificant = function (significantDigits, format, rounding) {
93
- if (significantDigits === void 0) { significantDigits = 6; }
94
- if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; }
95
- return _super.prototype.divide.call(this, this.decimalScale)
74
+ }
75
+ toSignificant(significantDigits = 6, format, rounding = Rounding.ROUND_DOWN) {
76
+ return super
77
+ .divide(this.decimalScale)
96
78
  .toSignificant(significantDigits, format, rounding);
97
- };
98
- CurrencyAmount.prototype.toFixed = function (decimalPlaces, format, rounding) {
99
- if (decimalPlaces === void 0) { decimalPlaces = this.currency.decimals; }
100
- if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; }
79
+ }
80
+ toFixed(decimalPlaces = this.currency.decimals, format, rounding = Rounding.ROUND_DOWN) {
101
81
  invariant(decimalPlaces <= this.currency.decimals, "DECIMALS");
102
- return _super.prototype.divide.call(this, this.decimalScale)
82
+ return super
83
+ .divide(this.decimalScale)
103
84
  .toFixed(decimalPlaces, format, rounding);
104
- };
105
- CurrencyAmount.prototype.toExact = function (format) {
106
- if (format === void 0) { format = { groupSeparator: "" }; }
85
+ }
86
+ toExact(format = { groupSeparator: "" }) {
107
87
  Big.DP = this.currency.decimals;
108
88
  return new Big(this.quotient.toString())
109
89
  .div(this.decimalScale.toString())
110
90
  .toFormat(format);
111
- };
112
- return CurrencyAmount;
113
- }(Fraction));
114
- export { CurrencyAmount };
91
+ }
92
+ }
@@ -1,5 +1,5 @@
1
- import { Currency } from "./currency";
2
- import { TokenType } from "../../enums";
1
+ import { Currency } from "./currency.js";
2
+ import { TokenType } from "../../enums.js";
3
3
  /**
4
4
  * Represents an ERC20 token with a unique address and some metadata.
5
5
  */
@@ -1,26 +1,17 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- import { Currency } from "./currency";
17
- import { checkValidAddress, validateAndParseAddress, } from "../../utils/validateAndParseAddress";
18
- import { TokenType } from "../../enums";
1
+ import { Currency } from "./currency.js";
2
+ import { checkValidAddress, validateAndParseAddress, } from "../../utils/validateAndParseAddress.js";
3
+ import { TokenType } from "../../enums.js";
19
4
  /**
20
5
  * Represents an ERC20 token with a unique address and some metadata.
21
6
  */
22
- var FungibleToken = /** @class */ (function (_super) {
23
- __extends(FungibleToken, _super);
7
+ export class FungibleToken extends Currency {
8
+ static toFungibleToken(token) {
9
+ if (!token) {
10
+ return undefined;
11
+ }
12
+ const { address, chainId, currency, coinGeckoId, isNative } = token;
13
+ return new FungibleToken(BigInt(chainId), address, currency.decimals, currency.asset.symbol, currency.asset.name, undefined, isNative, coinGeckoId);
14
+ }
24
15
  /**
25
16
  * @param chainId The chain ID on which this token resides
26
17
  * @param address The contract address on the chain on which this token lives
@@ -29,57 +20,45 @@ var FungibleToken = /** @class */ (function (_super) {
29
20
  * @param name {@link Currency#name}
30
21
  * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
31
22
  */
32
- function FungibleToken(chainId, address, decimals, symbol, name, bypassChecksum, isNative, coinGeckoId) {
23
+ constructor(chainId, address, decimals, symbol, name, bypassChecksum, isNative, coinGeckoId) {
33
24
  // TODO(felix): add this back
34
25
  // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
35
- var _a, _b;
36
- var _this = _super.call(this, decimals, symbol, name, undefined, isNative, true, coinGeckoId) || this;
37
- _this.isToken = true;
26
+ super(decimals, symbol, name, undefined, isNative, true, coinGeckoId);
27
+ this.isToken = true;
38
28
  // TODO(felix): bypassChecksum is a little confusing since when bypassChecksum is true, we still validate the address
39
29
  // bypassChecksum is derived from the isNative parameter, so we should remove it and just check if isNative here
40
30
  if (bypassChecksum) {
41
- _this.address = (_a = checkValidAddress(address)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
31
+ this.address = checkValidAddress(address)?.toLowerCase();
42
32
  }
43
33
  else if (!isNative) {
44
- _this.address = (_b = validateAndParseAddress(address)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
34
+ this.address = validateAndParseAddress(address)?.toLowerCase();
45
35
  }
46
36
  else {
47
- _this.address = address;
37
+ this.address = address;
48
38
  }
49
- _this.isNative = isNative || false;
50
- _this.chainId = chainId;
51
- return _this;
39
+ this.isNative = isNative || false;
40
+ this.chainId = chainId;
52
41
  }
53
- FungibleToken.toFungibleToken = function (token) {
54
- if (!token) {
55
- return undefined;
56
- }
57
- var address = token.address, chainId = token.chainId, currency = token.currency, coinGeckoId = token.coinGeckoId, isNative = token.isNative;
58
- return new FungibleToken(BigInt(chainId), address, currency.decimals, currency.asset.symbol, currency.asset.name, undefined, isNative, coinGeckoId);
59
- };
60
42
  /**
61
43
  * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
62
44
  * @param other other token to compare
63
45
  */
64
- FungibleToken.prototype.equals = function (other) {
65
- var _a;
46
+ equals(other) {
66
47
  if (this === other)
67
48
  return true;
68
- return (this.chainId == (other === null || other === void 0 ? void 0 : other.chainId) &&
69
- this.address.toLowerCase() == ((_a = other === null || other === void 0 ? void 0 : other.address) === null || _a === void 0 ? void 0 : _a.toLowerCase()));
70
- };
49
+ return (this.chainId == other?.chainId &&
50
+ this.address.toLowerCase() == other?.address?.toLowerCase());
51
+ }
71
52
  /**
72
53
  * Returns the currency object that this token represents
73
54
  */
74
- FungibleToken.prototype.currency = function () {
55
+ currency() {
75
56
  return this;
76
- };
77
- FungibleToken.prototype.type = function () {
57
+ }
58
+ type() {
78
59
  return TokenType.FUNGIBLE_TOKEN;
79
- };
80
- FungibleToken.prototype.identifier = function () {
81
- return "".concat(this.chainId, "+").concat(this.address.toLowerCase());
82
- };
83
- return FungibleToken;
84
- }(Currency));
85
- export { FungibleToken };
60
+ }
61
+ identifier() {
62
+ return `${this.chainId}+${this.address.toLowerCase()}`;
63
+ }
64
+ }
@@ -1,7 +1,7 @@
1
1
  import JSBI from "jsbi";
2
2
  import { Fraction, BigintIsh, Rounding } from "@uniswap/sdk-core";
3
- import { FungibleToken } from "./fungible_token";
4
- import { CurrencyAmount } from "./currency_amount";
3
+ import { FungibleToken } from "./fungible_token.js";
4
+ import { CurrencyAmount } from "./currency_amount.js";
5
5
  export declare class FungibleTokenAmount extends Fraction {
6
6
  readonly token: FungibleToken;
7
7
  readonly decimalScale: JSBI;
@@ -1,117 +1,95 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
1
  import invariant from "tiny-invariant";
17
2
  import JSBI from "jsbi";
18
3
  import { Fraction, Rounding, MaxUint256 } from "@uniswap/sdk-core";
19
- import { FungibleToken } from "./fungible_token";
20
- import { CurrencyAmount } from "./currency_amount";
21
- import { Big } from "../../constants";
4
+ import { FungibleToken } from "./fungible_token.js";
5
+ import { CurrencyAmount } from "./currency_amount.js";
6
+ import { Big } from "../../constants.js";
22
7
  // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
23
8
  // because we have a need to represent a currency amount that is not a fungible token amount.
24
- var FungibleTokenAmount = /** @class */ (function (_super) {
25
- __extends(FungibleTokenAmount, _super);
26
- function FungibleTokenAmount(fungibleToken, numerator, denominator, amountInFiatCurrency) {
27
- var _this = _super.call(this, numerator.toString(), denominator === null || denominator === void 0 ? void 0 : denominator.toString()) || this;
28
- invariant(JSBI.lessThanOrEqual(_this.quotient, MaxUint256), "AMOUNT");
29
- _this.token = fungibleToken;
30
- _this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(fungibleToken.decimals));
31
- _this.amountInFiatCurrency = amountInFiatCurrency;
32
- return _this;
33
- }
9
+ export class FungibleTokenAmount extends Fraction {
34
10
  /**
35
11
  * Returns a new fungibleToken amount instance from the unitless amount of token, i.e. the raw amount
36
12
  * @param fungibleToken the fungibleToken in the amount
37
13
  * @param rawAmount the raw token or ether amount
38
14
  */
39
- FungibleTokenAmount.fromRawAmount = function (fungibleToken, rawAmount, amountInFiatCurrency) {
15
+ static fromRawAmount(fungibleToken, rawAmount, amountInFiatCurrency) {
40
16
  return new FungibleTokenAmount(fungibleToken, rawAmount, undefined, amountInFiatCurrency);
41
- };
17
+ }
42
18
  /**
43
19
  * Construct a fungibleToken amount with a denominator that is not equal to 1
44
20
  * @param fungibleToken the fungibleToken
45
21
  * @param numerator the numerator of the fractional token amount
46
22
  * @param denominator the denominator of the fractional token amount
47
23
  */
48
- FungibleTokenAmount.fromFractionalAmount = function (fungibleToken, numerator, denominator, amountInFiatCurrency) {
24
+ static fromFractionalAmount(fungibleToken, numerator, denominator, amountInFiatCurrency) {
49
25
  return new FungibleTokenAmount(fungibleToken, numerator, denominator, amountInFiatCurrency);
50
- };
51
- FungibleTokenAmount.toFungibleTokenAmount = function (amount) {
26
+ }
27
+ static toFungibleTokenAmount(amount) {
52
28
  if (!amount) {
53
29
  return undefined;
54
30
  }
55
- var amountInFiatCurrency = CurrencyAmount.toCurrencyAmount(amount.amountInFiatCurrency);
31
+ const amountInFiatCurrency = CurrencyAmount.toCurrencyAmount(amount.amountInFiatCurrency);
56
32
  return FungibleTokenAmount.fromRawAmount(FungibleToken.toFungibleToken(amount.token), amount.value, amountInFiatCurrency);
57
- };
58
- FungibleTokenAmount.prototype.equals = function (other) {
33
+ }
34
+ constructor(fungibleToken, numerator, denominator, amountInFiatCurrency) {
35
+ super(numerator.toString(), denominator?.toString());
36
+ invariant(JSBI.lessThanOrEqual(this.quotient, MaxUint256), "AMOUNT"); // TODO(imti): fix this
37
+ this.token = fungibleToken;
38
+ this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(fungibleToken.decimals));
39
+ this.amountInFiatCurrency = amountInFiatCurrency;
40
+ }
41
+ equals(other) {
59
42
  return (this.token.equals(other.token) &&
60
43
  this.toRawAmount() == other.toRawAmount());
61
- };
62
- FungibleTokenAmount.prototype.add = function (other) {
44
+ }
45
+ add(other) {
63
46
  invariant(this.token.equals(other.token), "FUNGIBLE_TOKEN");
64
- var added = _super.prototype.add.call(this, other);
47
+ const added = super.add(other);
65
48
  return FungibleTokenAmount.fromFractionalAmount(this.token, added.numerator, added.denominator);
66
- };
67
- FungibleTokenAmount.prototype.subtract = function (other) {
49
+ }
50
+ subtract(other) {
68
51
  invariant(this.token.equals(other.token), "FUNGIBLE_TOKEN");
69
- var subtracted = _super.prototype.subtract.call(this, other);
52
+ const subtracted = super.subtract(other);
70
53
  return FungibleTokenAmount.fromFractionalAmount(this.token, subtracted.numerator, subtracted.denominator);
71
- };
72
- FungibleTokenAmount.prototype.multiply = function (other) {
73
- var multiplied = _super.prototype.multiply.call(this, other);
54
+ }
55
+ multiply(other) {
56
+ const multiplied = super.multiply(other);
74
57
  return FungibleTokenAmount.fromFractionalAmount(this.token, multiplied.numerator, multiplied.denominator);
75
- };
76
- FungibleTokenAmount.prototype.divide = function (other) {
77
- var divided = _super.prototype.divide.call(this, other);
58
+ }
59
+ divide(other) {
60
+ const divided = super.divide(other);
78
61
  return FungibleTokenAmount.fromFractionalAmount(this.token, divided.numerator, divided.denominator);
79
- };
80
- FungibleTokenAmount.prototype.greaterThanOrEqual = function (other) {
62
+ }
63
+ greaterThanOrEqual(other) {
81
64
  return this.greaterThan(other) || this.equals(other);
82
- };
83
- FungibleTokenAmount.prototype.toRawAmount = function () {
65
+ }
66
+ toRawAmount() {
84
67
  return BigInt(this.quotient.toString());
85
- };
86
- FungibleTokenAmount.prototype.fiatValue = function () {
68
+ }
69
+ fiatValue() {
87
70
  return this.amountInFiatCurrency;
88
- };
89
- FungibleTokenAmount.prototype.toCurrencyValue = function (price) {
90
- var fraction = price.multiply(this);
91
- var denominator = JSBI.multiply(fraction.denominator, this.decimalScale);
71
+ }
72
+ toCurrencyValue(price) {
73
+ const fraction = price.multiply(this);
74
+ const denominator = JSBI.multiply(fraction.denominator, this.decimalScale);
92
75
  this.amountInFiatCurrency = CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
93
76
  return this.amountInFiatCurrency;
94
- };
95
- FungibleTokenAmount.prototype.toSignificant = function (significantDigits, format, rounding) {
96
- if (significantDigits === void 0) { significantDigits = 6; }
97
- if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; }
98
- return _super.prototype.divide.call(this, this.decimalScale)
77
+ }
78
+ toSignificant(significantDigits = 6, format, rounding = Rounding.ROUND_DOWN) {
79
+ return super
80
+ .divide(this.decimalScale)
99
81
  .toSignificant(significantDigits, format, rounding);
100
- };
101
- FungibleTokenAmount.prototype.toFixed = function (decimalPlaces, format, rounding) {
102
- if (decimalPlaces === void 0) { decimalPlaces = this.token.decimals; }
103
- if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; }
82
+ }
83
+ toFixed(decimalPlaces = this.token.decimals, format, rounding = Rounding.ROUND_DOWN) {
104
84
  invariant(decimalPlaces <= this.token.decimals, "DECIMALS");
105
- return _super.prototype.divide.call(this, this.decimalScale)
85
+ return super
86
+ .divide(this.decimalScale)
106
87
  .toFixed(decimalPlaces, format, rounding);
107
- };
108
- FungibleTokenAmount.prototype.toExact = function (format) {
109
- if (format === void 0) { format = { groupSeparator: "" }; }
88
+ }
89
+ toExact(format = { groupSeparator: "" }) {
110
90
  Big.DP = this.token.decimals;
111
91
  return new Big(this.quotient.toString())
112
92
  .div(this.decimalScale.toString())
113
93
  .toFormat(format);
114
- };
115
- return FungibleTokenAmount;
116
- }(Fraction));
117
- export { FungibleTokenAmount };
94
+ }
95
+ }
@@ -1,5 +1,5 @@
1
- import { Asset } from "./asset";
2
- import { TokenType } from "../../enums";
1
+ import { Asset } from "./asset.js";
2
+ import { TokenType } from "../../enums.js";
3
3
  /**
4
4
  * Represents an ERC721 token with a unique address and some metadata.
5
5
  */
@@ -1,26 +1,10 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- import { Asset } from "./asset";
17
- import { checkValidAddress, validateAndParseAddress, } from "../../utils/validateAndParseAddress";
18
- import { TokenType } from "../../enums";
1
+ import { Asset } from "./asset.js";
2
+ import { checkValidAddress, validateAndParseAddress, } from "../../utils/validateAndParseAddress.js";
3
+ import { TokenType } from "../../enums.js";
19
4
  /**
20
5
  * Represents an ERC721 token with a unique address and some metadata.
21
6
  */
22
- var NonFungibleToken = /** @class */ (function (_super) {
23
- __extends(NonFungibleToken, _super);
7
+ export class NonFungibleToken extends Asset {
24
8
  /**
25
9
  * @param chainId The chain ID on which this token resides
26
10
  * @param address The contract address on the chain on which this token lives
@@ -29,53 +13,49 @@ var NonFungibleToken = /** @class */ (function (_super) {
29
13
  * @param url The URL of the token's metadata
30
14
  * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
31
15
  */
32
- function NonFungibleToken(chainId, address, symbol, name, url, bypassChecksum, coinGeckoId) {
16
+ constructor(chainId, address, symbol, name, url, bypassChecksum, coinGeckoId) {
33
17
  // TODO(felix): add this back
34
18
  // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
35
- var _a, _b;
36
- var _this = _super.call(this, symbol, name, coinGeckoId) || this;
37
- _this.isNative = false;
38
- _this.isToken = true;
19
+ super(symbol, name, coinGeckoId);
20
+ this.isNative = false;
21
+ this.isToken = true;
39
22
  if (bypassChecksum) {
40
- _this.address = (_a = checkValidAddress(address)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
23
+ this.address = checkValidAddress(address)?.toLowerCase();
41
24
  }
42
25
  else {
43
- _this.address = (_b = validateAndParseAddress(address)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
26
+ this.address = validateAndParseAddress(address)?.toLowerCase();
44
27
  }
45
- _this.chainId = chainId;
46
- _this.url = url;
47
- return _this;
28
+ this.chainId = chainId;
29
+ this.url = url;
48
30
  }
49
- NonFungibleToken.toNonFungibleToken = function (nft) {
31
+ static toNonFungibleToken(nft) {
50
32
  if (!nft) {
51
33
  return undefined;
52
34
  }
53
- var asset = Asset.toAsset(nft.asset);
35
+ const asset = Asset.toAsset(nft.asset);
54
36
  return new NonFungibleToken(nft.chainId, nft.address, asset.symbol, asset.name, nft.url);
55
- };
37
+ }
56
38
  /**
57
39
  * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
58
40
  * @param other other token to compare
59
41
  */
60
- NonFungibleToken.prototype.equals = function (other) {
42
+ equals(other) {
61
43
  // short circuit on reference equality
62
44
  if (this === other)
63
45
  return true;
64
46
  return (this.chainId === other.chainId &&
65
47
  this.address === other.address.toLowerCase());
66
- };
48
+ }
67
49
  /**
68
50
  * Returns the asset representation of this currency
69
51
  */
70
- NonFungibleToken.prototype.asset = function () {
52
+ asset() {
71
53
  return this;
72
- };
73
- NonFungibleToken.prototype.type = function () {
54
+ }
55
+ type() {
74
56
  return TokenType.NON_FUNGIBLE_TOKEN;
75
- };
76
- NonFungibleToken.prototype.identifier = function () {
77
- return "".concat(this.chainId, "+").concat(this.address.toLowerCase());
78
- };
79
- return NonFungibleToken;
80
- }(Asset));
81
- export { NonFungibleToken };
57
+ }
58
+ identifier() {
59
+ return `${this.chainId}+${this.address.toLowerCase()}`;
60
+ }
61
+ }
@@ -1,5 +1,5 @@
1
- import { Currency } from "./currency";
2
- import { TokenType } from "../../enums";
1
+ import { Currency } from "./currency.js";
2
+ import { TokenType } from "../../enums.js";
3
3
  /**
4
4
  * Represents an ERC1155 token with a unique address and some metadata.
5
5
  */