@orb-labs/orby-core 0.0.4 → 0.0.6

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