@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
package/dist/constants.js CHANGED
@@ -1,139 +1,134 @@
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.FIAT_CURRENCY = exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = exports.CHAIN_CONFIGS = exports.BLOCKCHAIN_ID = exports.Big = void 0;
7
- const toformat_1 = __importDefault(require("toformat"));
8
- const big_js_1 = __importDefault(require("big.js"));
9
- const enums_1 = require("./enums");
10
- const currency_1 = require("./entities/financial/currency");
11
- exports.Big = (0, toformat_1.default)(big_js_1.default);
12
- exports.BLOCKCHAIN_ID = {
13
- [enums_1.Blockchain.ETHEREUM]: 1,
14
- [enums_1.Blockchain.POLYGON]: 137,
15
- [enums_1.Blockchain.BINANCE]: 56,
16
- [enums_1.Blockchain.ARBITRUM]: 42161,
17
- [enums_1.Blockchain.ARBITRUM_NOVA]: 42170,
18
- [enums_1.Blockchain.OPTIMISM]: 10,
19
- [enums_1.Blockchain.EVMOS]: 9001,
20
- [enums_1.Blockchain.MOONBEAM]: 1284,
21
- [enums_1.Blockchain.BASE]: 8453,
22
- [enums_1.Blockchain.AVALANCHE]: 43114,
1
+ var _a, _b, _c;
2
+ import toFormat from "toformat";
3
+ import _Big from "big.js";
4
+ import { Blockchain, BlockchainEnvironment } from "./enums";
5
+ import { Currency } from "./entities/financial/currency";
6
+ export var Big = toFormat(_Big);
7
+ export var BLOCKCHAIN_ID = (_a = {},
8
+ _a[Blockchain.ETHEREUM] = 1,
9
+ _a[Blockchain.POLYGON] = 137,
10
+ _a[Blockchain.BINANCE] = 56,
11
+ _a[Blockchain.ARBITRUM] = 42161,
12
+ _a[Blockchain.ARBITRUM_NOVA] = 42170,
13
+ _a[Blockchain.OPTIMISM] = 10,
14
+ _a[Blockchain.EVMOS] = 9001,
15
+ _a[Blockchain.MOONBEAM] = 1284,
16
+ _a[Blockchain.BASE] = 8453,
17
+ _a[Blockchain.AVALANCHE] = 43114,
23
18
  // testnets
24
- [enums_1.Blockchain.ETHEREUM_SEPOLIA]: 11155111,
25
- [enums_1.Blockchain.ETHEREUM_HOLESKY]: 17000,
26
- [enums_1.Blockchain.ARBITRUM_SEPOLIA]: 421614,
27
- [enums_1.Blockchain.OPTIMISM_SEPOLIA]: 11155420,
28
- [enums_1.Blockchain.POLYGON_AMOY]: 80002,
29
- [enums_1.Blockchain.BINANCE_TESTNET]: 97,
30
- [enums_1.Blockchain.OPBNB_TESTNET]: 5611,
31
- [enums_1.Blockchain.MOONBEAM_ALPHA]: 1287,
32
- [enums_1.Blockchain.BASE_SEPOLIA]: 84532,
19
+ _a[Blockchain.ETHEREUM_SEPOLIA] = 11155111,
20
+ _a[Blockchain.ETHEREUM_HOLESKY] = 17000,
21
+ _a[Blockchain.ARBITRUM_SEPOLIA] = 421614,
22
+ _a[Blockchain.OPTIMISM_SEPOLIA] = 11155420,
23
+ _a[Blockchain.POLYGON_AMOY] = 80002,
24
+ _a[Blockchain.BINANCE_TESTNET] = 97,
25
+ _a[Blockchain.OPBNB_TESTNET] = 5611,
26
+ _a[Blockchain.MOONBEAM_ALPHA] = 1287,
27
+ _a[Blockchain.BASE_SEPOLIA] = 84532,
33
28
  // local testing
34
- [enums_1.Blockchain.HARDHAT]: 31337,
35
- [enums_1.Blockchain.LOCAL_CHAIN_0]: 1000000000001,
36
- [enums_1.Blockchain.LOCAL_CHAIN_1]: 1000000000002,
37
- };
38
- exports.CHAIN_CONFIGS = {
39
- [enums_1.Blockchain.ETHEREUM]: {
40
- environment: enums_1.BlockchainEnvironment.MAINNET,
29
+ _a[Blockchain.HARDHAT] = 31337,
30
+ _a[Blockchain.LOCAL_CHAIN_0] = 1000000000001,
31
+ _a[Blockchain.LOCAL_CHAIN_1] = 1000000000002,
32
+ _a);
33
+ export var CHAIN_CONFIGS = (_b = {},
34
+ _b[Blockchain.ETHEREUM] = {
35
+ environment: BlockchainEnvironment.MAINNET,
41
36
  chainId: BigInt(1),
42
37
  },
43
- [enums_1.Blockchain.POLYGON]: {
44
- environment: enums_1.BlockchainEnvironment.MAINNET,
38
+ _b[Blockchain.POLYGON] = {
39
+ environment: BlockchainEnvironment.MAINNET,
45
40
  chainId: BigInt(137),
46
41
  },
47
- [enums_1.Blockchain.BINANCE]: {
48
- environment: enums_1.BlockchainEnvironment.MAINNET,
42
+ _b[Blockchain.BINANCE] = {
43
+ environment: BlockchainEnvironment.MAINNET,
49
44
  chainId: BigInt(56),
50
45
  },
51
- [enums_1.Blockchain.ARBITRUM]: {
52
- environment: enums_1.BlockchainEnvironment.MAINNET,
46
+ _b[Blockchain.ARBITRUM] = {
47
+ environment: BlockchainEnvironment.MAINNET,
53
48
  chainId: BigInt(42161),
54
49
  },
55
- [enums_1.Blockchain.ARBITRUM_NOVA]: {
56
- environment: enums_1.BlockchainEnvironment.MAINNET,
50
+ _b[Blockchain.ARBITRUM_NOVA] = {
51
+ environment: BlockchainEnvironment.MAINNET,
57
52
  chainId: BigInt(42170),
58
53
  },
59
- [enums_1.Blockchain.OPTIMISM]: {
60
- environment: enums_1.BlockchainEnvironment.MAINNET,
54
+ _b[Blockchain.OPTIMISM] = {
55
+ environment: BlockchainEnvironment.MAINNET,
61
56
  chainId: BigInt(10),
62
57
  },
63
- [enums_1.Blockchain.EVMOS]: {
64
- environment: enums_1.BlockchainEnvironment.MAINNET,
58
+ _b[Blockchain.EVMOS] = {
59
+ environment: BlockchainEnvironment.MAINNET,
65
60
  chainId: BigInt(9001),
66
61
  },
67
- [enums_1.Blockchain.MOONBEAM]: {
68
- environment: enums_1.BlockchainEnvironment.MAINNET,
62
+ _b[Blockchain.MOONBEAM] = {
63
+ environment: BlockchainEnvironment.MAINNET,
69
64
  chainId: BigInt(1284),
70
65
  },
71
- [enums_1.Blockchain.BASE]: {
72
- environment: enums_1.BlockchainEnvironment.MAINNET,
66
+ _b[Blockchain.BASE] = {
67
+ environment: BlockchainEnvironment.MAINNET,
73
68
  chainId: BigInt(8453),
74
69
  },
75
- [enums_1.Blockchain.AVALANCHE]: {
76
- environment: enums_1.BlockchainEnvironment.MAINNET,
70
+ _b[Blockchain.AVALANCHE] = {
71
+ environment: BlockchainEnvironment.MAINNET,
77
72
  chainId: BigInt(43114),
78
73
  },
79
74
  // testnets
80
- [enums_1.Blockchain.ETHEREUM_SEPOLIA]: {
81
- environment: enums_1.BlockchainEnvironment.TESTNET,
75
+ _b[Blockchain.ETHEREUM_SEPOLIA] = {
76
+ environment: BlockchainEnvironment.TESTNET,
82
77
  chainId: BigInt(11155111),
83
78
  },
84
- [enums_1.Blockchain.ETHEREUM_HOLESKY]: {
85
- environment: enums_1.BlockchainEnvironment.TESTNET,
79
+ _b[Blockchain.ETHEREUM_HOLESKY] = {
80
+ environment: BlockchainEnvironment.TESTNET,
86
81
  chainId: BigInt(17000),
87
82
  },
88
- [enums_1.Blockchain.ARBITRUM_SEPOLIA]: {
89
- environment: enums_1.BlockchainEnvironment.TESTNET,
83
+ _b[Blockchain.ARBITRUM_SEPOLIA] = {
84
+ environment: BlockchainEnvironment.TESTNET,
90
85
  chainId: BigInt(421614),
91
86
  },
92
- [enums_1.Blockchain.BASE_SEPOLIA]: {
93
- environment: enums_1.BlockchainEnvironment.TESTNET,
87
+ _b[Blockchain.BASE_SEPOLIA] = {
88
+ environment: BlockchainEnvironment.TESTNET,
94
89
  chainId: BigInt(84532),
95
90
  },
96
- [enums_1.Blockchain.OPTIMISM_SEPOLIA]: {
97
- environment: enums_1.BlockchainEnvironment.TESTNET,
91
+ _b[Blockchain.OPTIMISM_SEPOLIA] = {
92
+ environment: BlockchainEnvironment.TESTNET,
98
93
  chainId: BigInt(11155420),
99
94
  },
100
- [enums_1.Blockchain.BINANCE_TESTNET]: {
101
- environment: enums_1.BlockchainEnvironment.TESTNET,
95
+ _b[Blockchain.BINANCE_TESTNET] = {
96
+ environment: BlockchainEnvironment.TESTNET,
102
97
  chainId: BigInt(97),
103
98
  },
104
- [enums_1.Blockchain.OPBNB_TESTNET]: {
105
- environment: enums_1.BlockchainEnvironment.TESTNET,
99
+ _b[Blockchain.OPBNB_TESTNET] = {
100
+ environment: BlockchainEnvironment.TESTNET,
106
101
  chainId: BigInt(5611),
107
102
  },
108
- [enums_1.Blockchain.MOONBEAM_ALPHA]: {
109
- environment: enums_1.BlockchainEnvironment.TESTNET,
103
+ _b[Blockchain.MOONBEAM_ALPHA] = {
104
+ environment: BlockchainEnvironment.TESTNET,
110
105
  chainId: BigInt(1287),
111
106
  },
112
- [enums_1.Blockchain.POLYGON_AMOY]: {
113
- environment: enums_1.BlockchainEnvironment.TESTNET,
107
+ _b[Blockchain.POLYGON_AMOY] = {
108
+ environment: BlockchainEnvironment.TESTNET,
114
109
  chainId: BigInt(80002),
115
110
  },
116
- };
117
- exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = {
118
- [1]: enums_1.Blockchain.ETHEREUM,
119
- [137]: enums_1.Blockchain.POLYGON,
120
- [56]: enums_1.Blockchain.BINANCE,
121
- [42161]: enums_1.Blockchain.ARBITRUM,
122
- [42170]: enums_1.Blockchain.ARBITRUM_NOVA,
123
- [10]: enums_1.Blockchain.OPTIMISM,
124
- [9001]: enums_1.Blockchain.EVMOS,
125
- [1284]: enums_1.Blockchain.MOONBEAM,
126
- [8453]: enums_1.Blockchain.BASE,
127
- [43114]: enums_1.Blockchain.AVALANCHE,
111
+ _b);
112
+ export var BLOCKCHAIN_ID_TO_BLOCKCHAIN = (_c = {},
113
+ _c[1] = Blockchain.ETHEREUM,
114
+ _c[137] = Blockchain.POLYGON,
115
+ _c[56] = Blockchain.BINANCE,
116
+ _c[42161] = Blockchain.ARBITRUM,
117
+ _c[42170] = Blockchain.ARBITRUM_NOVA,
118
+ _c[10] = Blockchain.OPTIMISM,
119
+ _c[9001] = Blockchain.EVMOS,
120
+ _c[1284] = Blockchain.MOONBEAM,
121
+ _c[8453] = Blockchain.BASE,
122
+ _c[43114] = Blockchain.AVALANCHE,
128
123
  // testnets
129
- [11155111]: enums_1.Blockchain.ETHEREUM_SEPOLIA,
130
- [84532]: enums_1.Blockchain.BASE_SEPOLIA,
131
- [17000]: enums_1.Blockchain.ETHEREUM_HOLESKY,
132
- [421614]: enums_1.Blockchain.ARBITRUM_SEPOLIA,
133
- [11155420]: enums_1.Blockchain.OPTIMISM_SEPOLIA,
134
- [80002]: enums_1.Blockchain.POLYGON_AMOY,
135
- [97]: enums_1.Blockchain.BINANCE_TESTNET,
136
- [5611]: enums_1.Blockchain.OPBNB_TESTNET,
137
- [1287]: enums_1.Blockchain.MOONBEAM_ALPHA,
138
- };
139
- exports.FIAT_CURRENCY = new currency_1.Currency(6, "USD", "US Dollar", undefined, false, false);
124
+ _c[11155111] = Blockchain.ETHEREUM_SEPOLIA,
125
+ _c[84532] = Blockchain.BASE_SEPOLIA,
126
+ _c[17000] = Blockchain.ETHEREUM_HOLESKY,
127
+ _c[421614] = Blockchain.ARBITRUM_SEPOLIA,
128
+ _c[11155420] = Blockchain.OPTIMISM_SEPOLIA,
129
+ _c[80002] = Blockchain.POLYGON_AMOY,
130
+ _c[97] = Blockchain.BINANCE_TESTNET,
131
+ _c[5611] = Blockchain.OPBNB_TESTNET,
132
+ _c[1287] = Blockchain.MOONBEAM_ALPHA,
133
+ _c);
134
+ export var FIAT_CURRENCY = new Currency(6, "USD", "US Dollar", undefined, false, false);
@@ -1,21 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Account = void 0;
4
- const enums_1 = require("../enums");
5
- const utils_1 = require("../utils/utils");
6
- class Account {
7
- static toAccount(account) {
8
- var _a;
9
- const chainId = (account === null || account === void 0 ? void 0 : account.chainId)
10
- ? (0, utils_1.getChainIdFromOrbyChainId)(account.chainId)
11
- : undefined;
12
- const formattedAccountType = (_a = account === null || account === void 0 ? void 0 : account.accountType) === null || _a === void 0 ? void 0 : _a.toLowerCase();
13
- if (!chainId && formattedAccountType == enums_1.AccountType.SCA) {
14
- return undefined;
15
- }
16
- return new Account(account.address, formattedAccountType, account.vmType, chainId);
17
- }
18
- constructor(address, accountType, vmType, chainId) {
1
+ import { AccountType } from "../enums";
2
+ import { getChainIdFromOrbyChainId } from "../utils/utils";
3
+ var Account = /** @class */ (function () {
4
+ function Account(address, accountType, vmType, chainId) {
19
5
  // TODO(felix): add this back
20
6
  // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
21
7
  this.address = address === null || address === void 0 ? void 0 : address.toLowerCase(); // validateAndParseAddress(address)?.toLowerCase();
@@ -23,20 +9,31 @@ class Account {
23
9
  this.accountType = accountType;
24
10
  this.vmType = vmType;
25
11
  this.key = Account.key(address, chainId);
26
- if (this.accountType == enums_1.AccountType.SCA) {
12
+ if (this.accountType == AccountType.SCA) {
27
13
  this.hasSufficientBalanceForGas = true;
28
14
  }
29
15
  else {
30
16
  this.hasSufficientBalanceForGas = false;
31
17
  }
32
18
  }
33
- static key(address, chainId) {
19
+ Account.toAccount = function (account) {
20
+ var _a;
21
+ var chainId = (account === null || account === void 0 ? void 0 : account.chainId)
22
+ ? getChainIdFromOrbyChainId(account.chainId)
23
+ : undefined;
24
+ var formattedAccountType = (_a = account === null || account === void 0 ? void 0 : account.accountType) === null || _a === void 0 ? void 0 : _a.toLowerCase();
25
+ if (!chainId && formattedAccountType == AccountType.SCA) {
26
+ return undefined;
27
+ }
28
+ return new Account(account.address, formattedAccountType, account.vmType, chainId);
29
+ };
30
+ Account.key = function (address, chainId) {
34
31
  var _a;
35
32
  return chainId
36
- ? `${(_a = chainId === null || chainId === void 0 ? void 0 : chainId.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase()}-${address}`
33
+ ? "".concat((_a = chainId === null || chainId === void 0 ? void 0 : chainId.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase(), "-").concat(address)
37
34
  : address;
38
- }
39
- toAccountModel() {
35
+ };
36
+ Account.prototype.toAccountModel = function () {
40
37
  var _a, _b;
41
38
  return {
42
39
  address: this.address,
@@ -44,9 +41,10 @@ class Account {
44
41
  vmType: (_b = this.vmType) === null || _b === void 0 ? void 0 : _b.toUpperCase(),
45
42
  chainId: this.chainId ? "EIP155-" + this.chainId : undefined,
46
43
  };
47
- }
48
- equals(other) {
44
+ };
45
+ Account.prototype.equals = function (other) {
49
46
  return this.key == other.key && this.accountType == other.accountType;
50
- }
51
- }
52
- exports.Account = Account;
47
+ };
48
+ return Account;
49
+ }());
50
+ export { Account };
@@ -1,35 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountBalance = void 0;
4
- const account_1 = require("../account");
5
- const fungible_token_amount_1 = require("./fungible_token_amount");
6
- class AccountBalance {
7
- static toAccountBalance(balance) {
1
+ import { Account } from "../account";
2
+ import { FungibleTokenAmount } from "./fungible_token_amount";
3
+ var AccountBalance = /** @class */ (function () {
4
+ function AccountBalance(amount, account) {
5
+ this.amount = amount;
6
+ this.account = account;
7
+ }
8
+ AccountBalance.toAccountBalance = function (balance) {
8
9
  if (!balance) {
9
10
  return undefined;
10
11
  }
11
- const amount = fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(balance.amount);
12
- const account = account_1.Account.toAccount(balance.account);
12
+ var amount = FungibleTokenAmount.toFungibleTokenAmount(balance.amount);
13
+ var account = Account.toAccount(balance.account);
13
14
  return new AccountBalance(amount, account);
14
- }
15
- constructor(amount, account) {
16
- this.amount = amount;
17
- this.account = account;
18
- }
19
- equals(other) {
15
+ };
16
+ AccountBalance.prototype.equals = function (other) {
20
17
  return (this.account.equals(other.account) && this.amount.equals(other.amount));
21
- }
22
- lessThan(other) {
18
+ };
19
+ AccountBalance.prototype.lessThan = function (other) {
23
20
  return (this.account.equals(other.account) && this.amount.lessThan(other.amount));
24
- }
25
- greaterThan(other) {
21
+ };
22
+ AccountBalance.prototype.greaterThan = function (other) {
26
23
  return (this.account.equals(other.account) &&
27
24
  this.amount.greaterThan(other.amount));
28
- }
29
- greaterThanOrEqual(other) {
25
+ };
26
+ AccountBalance.prototype.greaterThanOrEqual = function (other) {
30
27
  return (this.account.equals(other.account) &&
31
28
  (this.amount.greaterThan(other.amount) ||
32
29
  this.amount.equals(other.amount)));
33
- }
34
- }
35
- exports.AccountBalance = AccountBalance;
30
+ };
31
+ return AccountBalance;
32
+ }());
33
+ export { AccountBalance };
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Asset = void 0;
4
1
  /**
5
2
  * An Asset is any fungible financial instrument, including Ether, all ERC20 tokens, and NFTs
6
3
  */
7
- class Asset {
4
+ var Asset = /** @class */ (function () {
8
5
  /**
9
6
  * Constructs an instance of the `Asset`.
10
7
  * @param symbol symbol of the asset
11
8
  * @param name of the asset
12
9
  */
13
- constructor(symbol, name, coinGeckoId) {
10
+ function Asset(symbol, name, coinGeckoId) {
14
11
  this.symbol = symbol;
15
12
  this.name = name;
16
13
  this.coinGeckoId = coinGeckoId;
@@ -19,24 +16,25 @@ class Asset {
19
16
  * Returns whether this asset is functionally equivalent to the other asset
20
17
  * @param other the other asset
21
18
  */
22
- equals(other) {
19
+ Asset.prototype.equals = function (other) {
23
20
  if (this === other)
24
21
  return true;
25
22
  return this.symbol === other.symbol && this.name === other.name;
26
- }
23
+ };
27
24
  // return Asset in the "@domains/orby/src/api/graphql/generated" but could not set type here because the generated code is not available for other domains
28
- toAssetModel() {
25
+ Asset.prototype.toAssetModel = function () {
29
26
  return { symbol: this.symbol, name: this.name };
30
- }
31
- static toAsset(asset) {
27
+ };
28
+ Asset.toAsset = function (asset) {
32
29
  if (!asset) {
33
30
  return undefined;
34
31
  }
35
- const { symbol, name } = asset;
32
+ var symbol = asset.symbol, name = asset.name;
36
33
  return new Asset(symbol, name);
37
- }
38
- id() {
39
- return `${this.name}:${this.symbol}`;
40
- }
41
- }
42
- exports.Asset = Asset;
34
+ };
35
+ Asset.prototype.id = function () {
36
+ return "".concat(this.name, ":").concat(this.symbol);
37
+ };
38
+ return Asset;
39
+ }());
40
+ export { Asset };
@@ -1,17 +1,27 @@
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.Currency = void 0;
7
- const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
8
- const asset_1 = require("./asset");
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 { Asset } from "./asset";
9
18
  // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Create this instance here
10
19
  // because we represent currency amounts that are not fungible token amounts.
11
20
  /**
12
21
  * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
13
22
  */
14
- class Currency extends asset_1.Asset {
23
+ var Currency = /** @class */ (function (_super) {
24
+ __extends(Currency, _super);
15
25
  /**
16
26
  * Constructs an instance of the base class `Currency`.
17
27
  * @param decimals decimals of the currency
@@ -20,37 +30,39 @@ class Currency extends asset_1.Asset {
20
30
  * @param isNative whether the currency is native to the chain and must be wrapped (e.g. Ether)
21
31
  * @param isToken whether the currency is a token that is usable in Uniswap without wrapping
22
32
  */
23
- constructor(decimals, symbol, name, logoUrl, isNative, isToken, coinGeckoId) {
24
- super(symbol, name, coinGeckoId);
25
- (0, tiny_invariant_1.default)(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), "DECIMALS");
26
- this.decimals = decimals;
27
- this.isNative = isNative !== null && isNative !== void 0 ? isNative : false;
28
- this.isToken = isToken !== null && isToken !== void 0 ? isToken : true;
29
- this.logoUrl = logoUrl;
33
+ function Currency(decimals, symbol, name, logoUrl, isNative, isToken, coinGeckoId) {
34
+ var _this = _super.call(this, symbol, name, coinGeckoId) || this;
35
+ 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;
30
41
  }
31
42
  /**
32
43
  * Returns whether this currency is functionally equivalent to the other currency
33
44
  * @param other the other currency
34
45
  */
35
- equals(other) {
46
+ Currency.prototype.equals = function (other) {
36
47
  if (this === other)
37
48
  return true;
38
49
  return (this.symbol === other.symbol &&
39
50
  this.name === other.name &&
40
51
  this.decimals === other.decimals);
41
- }
52
+ };
42
53
  /**
43
54
  * Returns the asset representation of this currency
44
55
  */
45
- asset() {
56
+ Currency.prototype.asset = function () {
46
57
  return this;
47
- }
48
- static toCurrency(currency) {
58
+ };
59
+ Currency.toCurrency = function (currency) {
49
60
  if (!currency) {
50
61
  return undefined;
51
62
  }
52
- const { asset, decimals, logoUrl, isNative } = currency;
63
+ var asset = currency.asset, decimals = currency.decimals, logoUrl = currency.logoUrl, isNative = currency.isNative;
53
64
  return new Currency(decimals, asset.symbol, asset.name, logoUrl, isNative);
54
- }
55
- }
56
- exports.Currency = Currency;
65
+ };
66
+ return Currency;
67
+ }(Asset));
68
+ export { Currency };