@orb-labs/orby-core 0.0.6 → 0.0.8

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 (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/actions/account_cluster.d.ts +12 -5
  3. package/dist/actions/account_cluster.js +185 -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/blockchain.d.ts +16 -0
  9. package/dist/actions/blockchain.js +35 -0
  10. package/dist/actions/instance.d.ts +3 -4
  11. package/dist/actions/instance.js +90 -255
  12. package/dist/actions/operation.d.ts +19 -10
  13. package/dist/actions/operation.js +323 -259
  14. package/dist/actions/token.d.ts +3 -3
  15. package/dist/actions/token.js +43 -119
  16. package/dist/constants.d.ts +3 -3
  17. package/dist/constants.js +70 -71
  18. package/dist/entities/account.d.ts +1 -1
  19. package/dist/entities/account.js +25 -30
  20. package/dist/entities/financial/account_balance.d.ts +2 -2
  21. package/dist/entities/financial/account_balance.js +20 -22
  22. package/dist/entities/financial/asset.js +13 -15
  23. package/dist/entities/financial/currency.d.ts +1 -1
  24. package/dist/entities/financial/currency.js +16 -35
  25. package/dist/entities/financial/currency_amount.d.ts +1 -1
  26. package/dist/entities/financial/currency_amount.js +49 -71
  27. package/dist/entities/financial/fungible_token.d.ts +3 -3
  28. package/dist/entities/financial/fungible_token.js +31 -52
  29. package/dist/entities/financial/fungible_token_amount.d.ts +2 -2
  30. package/dist/entities/financial/fungible_token_amount.js +53 -75
  31. package/dist/entities/financial/non_fungible_token.d.ts +2 -2
  32. package/dist/entities/financial/non_fungible_token.js +25 -45
  33. package/dist/entities/financial/semi_fungible_token.d.ts +2 -2
  34. package/dist/entities/financial/semi_fungible_token.js +25 -45
  35. package/dist/entities/library_request.d.ts +1 -1
  36. package/dist/entities/library_request.js +7 -9
  37. package/dist/entities/state.d.ts +4 -4
  38. package/dist/entities/state.js +57 -67
  39. package/dist/index.d.ts +29 -27
  40. package/dist/index.js +29 -27
  41. package/dist/interfaces/account_cluster.d.ts +11 -4
  42. package/dist/interfaces/admin.d.ts +1 -1
  43. package/dist/interfaces/blockchain.d.ts +13 -0
  44. package/dist/interfaces/blockchain.js +1 -0
  45. package/dist/interfaces/instance.d.ts +1 -2
  46. package/dist/interfaces/operation.d.ts +25 -10
  47. package/dist/interfaces/orby.d.ts +8 -7
  48. package/dist/interfaces/token.d.ts +1 -1
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/dist/types.d.ts +9 -9
  51. package/dist/utils/action_helpers.d.ts +1 -1
  52. package/dist/utils/action_helpers.js +43 -63
  53. package/dist/utils/utils.d.ts +2 -1
  54. package/dist/utils/utils.js +23 -19
  55. package/dist/utils/validateAndParseAddress.js +3 -3
  56. package/package.json +4 -2
@@ -1,27 +1,11 @@
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
- import { Asset } from "./asset";
2
+ import { Asset } from "./asset.js";
18
3
  // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Create this instance here
19
4
  // because we represent currency amounts that are not fungible token amounts.
20
5
  /**
21
6
  * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
22
7
  */
23
- var Currency = /** @class */ (function (_super) {
24
- __extends(Currency, _super);
8
+ export class Currency extends Asset {
25
9
  /**
26
10
  * Constructs an instance of the base class `Currency`.
27
11
  * @param decimals decimals of the currency
@@ -30,39 +14,36 @@ var Currency = /** @class */ (function (_super) {
30
14
  * @param isNative whether the currency is native to the chain and must be wrapped (e.g. Ether)
31
15
  * @param isToken whether the currency is a token that is usable in Uniswap without wrapping
32
16
  */
33
- function Currency(decimals, symbol, name, logoUrl, isNative, isToken, coinGeckoId) {
34
- var _this = _super.call(this, symbol, name, coinGeckoId) || this;
17
+ constructor(decimals, symbol, name, logoUrl, isNative, isToken, coinGeckoId) {
18
+ super(symbol, name, coinGeckoId);
35
19
  invariant(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), "DECIMALS");
36
- _this.decimals = decimals;
37
- _this.isNative = isNative !== null && isNative !== void 0 ? isNative : false;
38
- _this.isToken = isToken !== null && isToken !== void 0 ? isToken : true;
39
- _this.logoUrl = logoUrl;
40
- return _this;
20
+ this.decimals = decimals;
21
+ this.isNative = isNative ?? false;
22
+ this.isToken = isToken ?? true;
23
+ this.logoUrl = logoUrl;
41
24
  }
42
25
  /**
43
26
  * Returns whether this currency is functionally equivalent to the other currency
44
27
  * @param other the other currency
45
28
  */
46
- Currency.prototype.equals = function (other) {
29
+ equals(other) {
47
30
  if (this === other)
48
31
  return true;
49
32
  return (this.symbol === other.symbol &&
50
33
  this.name === other.name &&
51
34
  this.decimals === other.decimals);
52
- };
35
+ }
53
36
  /**
54
37
  * Returns the asset representation of this currency
55
38
  */
56
- Currency.prototype.asset = function () {
39
+ asset() {
57
40
  return this;
58
- };
59
- Currency.toCurrency = function (currency) {
41
+ }
42
+ static toCurrency(currency) {
60
43
  if (!currency) {
61
44
  return undefined;
62
45
  }
63
- var asset = currency.asset, decimals = currency.decimals, logoUrl = currency.logoUrl, isNative = currency.isNative;
46
+ const { asset, decimals, logoUrl, isNative } = currency;
64
47
  return new Currency(decimals, asset.symbol, asset.name, logoUrl, isNative);
65
- };
66
- return Currency;
67
- }(Asset));
68
- export { Currency };
48
+ }
49
+ }
@@ -1,6 +1,6 @@
1
1
  import JSBI from "jsbi";
2
2
  import { Fraction, BigintIsh, Rounding } from "@uniswap/sdk-core";
3
- import { Currency } from "./currency";
3
+ import { Currency } from "./currency.js";
4
4
  export declare class CurrencyAmount extends Fraction {
5
5
  readonly currency: Currency;
6
6
  readonly decimalScale: JSBI;
@@ -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
  */
@@ -26,7 +26,7 @@ export declare class FungibleToken extends Currency {
26
26
  * @param name {@link Currency#name}
27
27
  * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
28
28
  */
29
- constructor(chainId: bigint, address: string, decimals: number, symbol: string, name: string, bypassChecksum?: boolean, isNative?: boolean, coinGeckoId?: string);
29
+ constructor(chainId: bigint, address: string, decimals: number, symbol: string, name: string, bypassChecksum?: boolean, isNative?: boolean, coinGeckoId?: string, logoUrl?: string);
30
30
  /**
31
31
  * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
32
32
  * @param other other token to compare
@@ -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, logoUrl) {
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, logoUrl, 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
  */