@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
package/dist/constants.js CHANGED
@@ -1,38 +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 = 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.FIAT_CURRENCY = new currency_1.Currency(6, "USD", "US Dollar", undefined, false, false);
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,
36
+ chainId: BigInt(1),
37
+ },
38
+ _b[Blockchain.POLYGON] = {
39
+ environment: BlockchainEnvironment.MAINNET,
40
+ chainId: BigInt(137),
41
+ },
42
+ _b[Blockchain.BINANCE] = {
43
+ environment: BlockchainEnvironment.MAINNET,
44
+ chainId: BigInt(56),
45
+ },
46
+ _b[Blockchain.ARBITRUM] = {
47
+ environment: BlockchainEnvironment.MAINNET,
48
+ chainId: BigInt(42161),
49
+ },
50
+ _b[Blockchain.ARBITRUM_NOVA] = {
51
+ environment: BlockchainEnvironment.MAINNET,
52
+ chainId: BigInt(42170),
53
+ },
54
+ _b[Blockchain.OPTIMISM] = {
55
+ environment: BlockchainEnvironment.MAINNET,
56
+ chainId: BigInt(10),
57
+ },
58
+ _b[Blockchain.EVMOS] = {
59
+ environment: BlockchainEnvironment.MAINNET,
60
+ chainId: BigInt(9001),
61
+ },
62
+ _b[Blockchain.MOONBEAM] = {
63
+ environment: BlockchainEnvironment.MAINNET,
64
+ chainId: BigInt(1284),
65
+ },
66
+ _b[Blockchain.BASE] = {
67
+ environment: BlockchainEnvironment.MAINNET,
68
+ chainId: BigInt(8453),
69
+ },
70
+ _b[Blockchain.AVALANCHE] = {
71
+ environment: BlockchainEnvironment.MAINNET,
72
+ chainId: BigInt(43114),
73
+ },
74
+ // testnets
75
+ _b[Blockchain.ETHEREUM_SEPOLIA] = {
76
+ environment: BlockchainEnvironment.TESTNET,
77
+ chainId: BigInt(11155111),
78
+ },
79
+ _b[Blockchain.ETHEREUM_HOLESKY] = {
80
+ environment: BlockchainEnvironment.TESTNET,
81
+ chainId: BigInt(17000),
82
+ },
83
+ _b[Blockchain.ARBITRUM_SEPOLIA] = {
84
+ environment: BlockchainEnvironment.TESTNET,
85
+ chainId: BigInt(421614),
86
+ },
87
+ _b[Blockchain.BASE_SEPOLIA] = {
88
+ environment: BlockchainEnvironment.TESTNET,
89
+ chainId: BigInt(84532),
90
+ },
91
+ _b[Blockchain.OPTIMISM_SEPOLIA] = {
92
+ environment: BlockchainEnvironment.TESTNET,
93
+ chainId: BigInt(11155420),
94
+ },
95
+ _b[Blockchain.BINANCE_TESTNET] = {
96
+ environment: BlockchainEnvironment.TESTNET,
97
+ chainId: BigInt(97),
98
+ },
99
+ _b[Blockchain.OPBNB_TESTNET] = {
100
+ environment: BlockchainEnvironment.TESTNET,
101
+ chainId: BigInt(5611),
102
+ },
103
+ _b[Blockchain.MOONBEAM_ALPHA] = {
104
+ environment: BlockchainEnvironment.TESTNET,
105
+ chainId: BigInt(1287),
106
+ },
107
+ _b[Blockchain.POLYGON_AMOY] = {
108
+ environment: BlockchainEnvironment.TESTNET,
109
+ chainId: BigInt(80002),
110
+ },
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,
123
+ // testnets
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 };
@@ -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 };