@orb-labs/orby-core 0.0.3 → 0.0.5

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 (43) hide show
  1. package/README.md +42 -1
  2. package/dist/actions/account_cluster.d.ts +1 -1
  3. package/dist/actions/account_cluster.js +308 -121
  4. package/dist/actions/admin.js +115 -28
  5. package/dist/actions/application.js +68 -14
  6. package/dist/actions/instance.js +237 -72
  7. package/dist/actions/operation.d.ts +12 -6
  8. package/dist/actions/operation.js +242 -90
  9. package/dist/actions/token.js +107 -31
  10. package/dist/constants.d.ts +8 -0
  11. package/dist/constants.js +132 -36
  12. package/dist/entities/account.js +26 -28
  13. package/dist/entities/financial/account_balance.js +22 -24
  14. package/dist/entities/financial/asset.js +15 -17
  15. package/dist/entities/financial/currency.js +37 -25
  16. package/dist/entities/financial/currency_amount.js +79 -64
  17. package/dist/entities/financial/fungible_token.js +49 -34
  18. package/dist/entities/financial/fungible_token_amount.js +85 -70
  19. package/dist/entities/financial/non_fungible_token.js +45 -30
  20. package/dist/entities/financial/semi_fungible_token.js +45 -30
  21. package/dist/entities/library_request.js +19 -24
  22. package/dist/entities/state.js +67 -60
  23. package/dist/enums.js +34 -37
  24. package/dist/index.d.ts +1 -3
  25. package/dist/index.js +27 -46
  26. package/dist/interfaces/account_cluster.d.ts +1 -1
  27. package/dist/interfaces/account_cluster.js +1 -2
  28. package/dist/interfaces/admin.js +1 -2
  29. package/dist/interfaces/application.js +1 -2
  30. package/dist/interfaces/instance.js +1 -2
  31. package/dist/interfaces/operation.d.ts +5 -5
  32. package/dist/interfaces/operation.js +1 -2
  33. package/dist/interfaces/orby.js +1 -2
  34. package/dist/interfaces/token.js +1 -2
  35. package/dist/tsconfig.tsbuildinfo +1 -0
  36. package/dist/types.d.ts +4 -0
  37. package/dist/types.js +1 -2
  38. package/dist/utils/action_helpers.d.ts +22 -0
  39. package/dist/utils/action_helpers.js +270 -0
  40. package/dist/utils/utils.d.ts +5 -22
  41. package/dist/utils/utils.js +30 -279
  42. package/dist/utils/validateAndParseAddress.js +7 -11
  43. package/package.json +6 -1
@@ -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 };
@@ -1,13 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SemiFungibleToken = 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 ERC1155 token with a unique address and some metadata.
9
21
  */
10
- class SemiFungibleToken extends currency_1.Currency {
22
+ var SemiFungibleToken = /** @class */ (function (_super) {
23
+ __extends(SemiFungibleToken, _super);
11
24
  /**
12
25
  *
13
26
  * @param chainId The chain ID on which this token resides
@@ -18,51 +31,53 @@ class SemiFungibleToken extends currency_1.Currency {
18
31
  * @param url The URL of the token's metadata
19
32
  * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
20
33
  */
21
- constructor(chainId, address, decimals, symbol, name, url, bypassChecksum, coinGeckoId) {
34
+ function SemiFungibleToken(chainId, address, decimals, symbol, name, url, bypassChecksum, coinGeckoId) {
22
35
  // TODO(felix): add this back
23
36
  // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
24
37
  var _a, _b;
25
- super(decimals, symbol, name, url, false, true, coinGeckoId);
26
- this.isNative = false;
27
- this.isToken = true;
38
+ var _this = _super.call(this, decimals, symbol, name, url, false, true, coinGeckoId) || this;
39
+ _this.isNative = false;
40
+ _this.isToken = true;
28
41
  if (bypassChecksum) {
29
- this.address = (_a = (0, validateAndParseAddress_1.checkValidAddress)(address)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
42
+ _this.address = (_a = checkValidAddress(address)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
30
43
  }
31
44
  else {
32
- this.address = (_b = (0, validateAndParseAddress_1.validateAndParseAddress)(address)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
45
+ _this.address = (_b = validateAndParseAddress(address)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
33
46
  }
34
- this.chainId = chainId;
35
- this.url = url;
47
+ _this.chainId = chainId;
48
+ _this.url = url;
49
+ return _this;
36
50
  }
37
- static toSemiFungibleToken(sft) {
51
+ SemiFungibleToken.toSemiFungibleToken = function (sft) {
38
52
  if (!sft) {
39
53
  return undefined;
40
54
  }
41
- const currency = currency_1.Currency.toCurrency(sft.currency);
55
+ var currency = Currency.toCurrency(sft.currency);
42
56
  return new SemiFungibleToken(sft.chainId, sft.address, currency.decimals, currency.symbol, currency.name, sft.url);
43
- }
57
+ };
44
58
  /**
45
59
  * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
46
60
  * @param other other token to compare
47
61
  */
48
- equals(other) {
62
+ SemiFungibleToken.prototype.equals = function (other) {
49
63
  // short circuit on reference equality
50
64
  if (this === other)
51
65
  return true;
52
66
  return (this.chainId === other.chainId &&
53
67
  this.address === other.address.toLowerCase());
54
- }
68
+ };
55
69
  /**
56
70
  * Returns the currency object that this token represents
57
71
  */
58
- currency() {
72
+ SemiFungibleToken.prototype.currency = function () {
59
73
  return this;
60
- }
61
- type() {
62
- return enums_1.TokenType.SEMI_FUNGIBLE_TOKEN;
63
- }
64
- identifier() {
65
- return `${this.chainId}+${this.address.toLowerCase()}`;
66
- }
67
- }
68
- exports.SemiFungibleToken = SemiFungibleToken;
74
+ };
75
+ SemiFungibleToken.prototype.type = function () {
76
+ return TokenType.SEMI_FUNGIBLE_TOKEN;
77
+ };
78
+ SemiFungibleToken.prototype.identifier = function () {
79
+ return "".concat(this.chainId, "+").concat(this.address.toLowerCase());
80
+ };
81
+ return SemiFungibleToken;
82
+ }(Currency));
83
+ export { SemiFungibleToken };
@@ -1,37 +1,32 @@
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.LibraryRequest = void 0;
7
- const enums_1 = require("../enums");
8
- const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
9
- class LibraryRequest {
10
- constructor(library, client, provider) {
11
- if (library == enums_1.LIBRARY_TYPE.VIEM) {
12
- (0, tiny_invariant_1.default)(client, "CLIENT");
13
- (0, tiny_invariant_1.default)(!provider, "PROVIDER");
1
+ import { LIBRARY_TYPE } from "../enums";
2
+ import invariant from "tiny-invariant";
3
+ var LibraryRequest = /** @class */ (function () {
4
+ function LibraryRequest(library, client, provider) {
5
+ if (library == LIBRARY_TYPE.VIEM) {
6
+ invariant(client, "CLIENT");
7
+ invariant(!provider, "PROVIDER");
14
8
  this.client = client;
15
9
  }
16
- else if (library == enums_1.LIBRARY_TYPE.ETHERS) {
17
- (0, tiny_invariant_1.default)(provider, "PROVIDER");
18
- (0, tiny_invariant_1.default)(!client, "CLIENT");
10
+ else if (library == LIBRARY_TYPE.ETHERS) {
11
+ invariant(provider, "PROVIDER");
12
+ invariant(!client, "CLIENT");
19
13
  this.provider = provider;
20
14
  }
21
15
  else {
22
- (0, tiny_invariant_1.default)(false, "LIBRARY");
16
+ invariant(false, "LIBRARY");
23
17
  }
24
18
  this.library = library;
25
19
  this.client = client;
26
20
  this.provider = provider;
27
21
  }
28
- sendRequest(method, params) {
29
- if (this.library == enums_1.LIBRARY_TYPE.VIEM) {
30
- return this.client.request({ method, params });
22
+ LibraryRequest.prototype.sendRequest = function (method, params) {
23
+ if (this.library == LIBRARY_TYPE.VIEM) {
24
+ return this.client.request({ method: method, params: params });
31
25
  }
32
- else if (this.library == enums_1.LIBRARY_TYPE.ETHERS) {
26
+ else if (this.library == LIBRARY_TYPE.ETHERS) {
33
27
  return this.provider.send(method, params);
34
28
  }
35
- }
36
- }
37
- exports.LibraryRequest = LibraryRequest;
29
+ };
30
+ return LibraryRequest;
31
+ }());
32
+ export { LibraryRequest };