@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.
- package/dist/actions/account_cluster.d.ts +1 -1
- package/dist/actions/account_cluster.js +316 -158
- package/dist/actions/admin.js +115 -46
- package/dist/actions/application.js +68 -20
- package/dist/actions/instance.js +237 -113
- package/dist/actions/operation.js +242 -110
- package/dist/actions/token.js +107 -41
- package/dist/constants.js +92 -97
- package/dist/entities/account.js +26 -28
- package/dist/entities/financial/account_balance.js +22 -24
- package/dist/entities/financial/asset.js +15 -17
- package/dist/entities/financial/currency.js +37 -25
- package/dist/entities/financial/currency_amount.js +79 -64
- package/dist/entities/financial/fungible_token.js +49 -34
- package/dist/entities/financial/fungible_token_amount.js +85 -70
- package/dist/entities/financial/non_fungible_token.js +45 -30
- package/dist/entities/financial/semi_fungible_token.js +45 -30
- package/dist/entities/library_request.js +19 -24
- package/dist/entities/state.js +67 -60
- package/dist/enums.js +34 -37
- package/dist/index.js +27 -43
- package/dist/interfaces/account_cluster.d.ts +1 -1
- package/dist/interfaces/account_cluster.js +1 -2
- package/dist/interfaces/admin.js +1 -2
- package/dist/interfaces/application.js +1 -2
- package/dist/interfaces/instance.js +1 -2
- package/dist/interfaces/operation.js +1 -2
- package/dist/interfaces/orby.js +1 -2
- package/dist/interfaces/token.js +1 -2
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.js +1 -2
- package/dist/utils/action_helpers.js +99 -109
- package/dist/utils/utils.js +24 -32
- package/dist/utils/validateAndParseAddress.js +7 -11
- package/package.json +1 -1
package/dist/constants.js
CHANGED
@@ -1,139 +1,134 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
};
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
[
|
14
|
-
[
|
15
|
-
[
|
16
|
-
[
|
17
|
-
[
|
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
|
-
[
|
25
|
-
[
|
26
|
-
[
|
27
|
-
[
|
28
|
-
[
|
29
|
-
[
|
30
|
-
[
|
31
|
-
[
|
32
|
-
[
|
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
|
-
[
|
35
|
-
[
|
36
|
-
[
|
37
|
-
|
38
|
-
|
39
|
-
[
|
40
|
-
environment:
|
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
|
-
[
|
44
|
-
environment:
|
38
|
+
_b[Blockchain.POLYGON] = {
|
39
|
+
environment: BlockchainEnvironment.MAINNET,
|
45
40
|
chainId: BigInt(137),
|
46
41
|
},
|
47
|
-
[
|
48
|
-
environment:
|
42
|
+
_b[Blockchain.BINANCE] = {
|
43
|
+
environment: BlockchainEnvironment.MAINNET,
|
49
44
|
chainId: BigInt(56),
|
50
45
|
},
|
51
|
-
[
|
52
|
-
environment:
|
46
|
+
_b[Blockchain.ARBITRUM] = {
|
47
|
+
environment: BlockchainEnvironment.MAINNET,
|
53
48
|
chainId: BigInt(42161),
|
54
49
|
},
|
55
|
-
[
|
56
|
-
environment:
|
50
|
+
_b[Blockchain.ARBITRUM_NOVA] = {
|
51
|
+
environment: BlockchainEnvironment.MAINNET,
|
57
52
|
chainId: BigInt(42170),
|
58
53
|
},
|
59
|
-
[
|
60
|
-
environment:
|
54
|
+
_b[Blockchain.OPTIMISM] = {
|
55
|
+
environment: BlockchainEnvironment.MAINNET,
|
61
56
|
chainId: BigInt(10),
|
62
57
|
},
|
63
|
-
[
|
64
|
-
environment:
|
58
|
+
_b[Blockchain.EVMOS] = {
|
59
|
+
environment: BlockchainEnvironment.MAINNET,
|
65
60
|
chainId: BigInt(9001),
|
66
61
|
},
|
67
|
-
[
|
68
|
-
environment:
|
62
|
+
_b[Blockchain.MOONBEAM] = {
|
63
|
+
environment: BlockchainEnvironment.MAINNET,
|
69
64
|
chainId: BigInt(1284),
|
70
65
|
},
|
71
|
-
[
|
72
|
-
environment:
|
66
|
+
_b[Blockchain.BASE] = {
|
67
|
+
environment: BlockchainEnvironment.MAINNET,
|
73
68
|
chainId: BigInt(8453),
|
74
69
|
},
|
75
|
-
[
|
76
|
-
environment:
|
70
|
+
_b[Blockchain.AVALANCHE] = {
|
71
|
+
environment: BlockchainEnvironment.MAINNET,
|
77
72
|
chainId: BigInt(43114),
|
78
73
|
},
|
79
74
|
// testnets
|
80
|
-
[
|
81
|
-
environment:
|
75
|
+
_b[Blockchain.ETHEREUM_SEPOLIA] = {
|
76
|
+
environment: BlockchainEnvironment.TESTNET,
|
82
77
|
chainId: BigInt(11155111),
|
83
78
|
},
|
84
|
-
[
|
85
|
-
environment:
|
79
|
+
_b[Blockchain.ETHEREUM_HOLESKY] = {
|
80
|
+
environment: BlockchainEnvironment.TESTNET,
|
86
81
|
chainId: BigInt(17000),
|
87
82
|
},
|
88
|
-
[
|
89
|
-
environment:
|
83
|
+
_b[Blockchain.ARBITRUM_SEPOLIA] = {
|
84
|
+
environment: BlockchainEnvironment.TESTNET,
|
90
85
|
chainId: BigInt(421614),
|
91
86
|
},
|
92
|
-
[
|
93
|
-
environment:
|
87
|
+
_b[Blockchain.BASE_SEPOLIA] = {
|
88
|
+
environment: BlockchainEnvironment.TESTNET,
|
94
89
|
chainId: BigInt(84532),
|
95
90
|
},
|
96
|
-
[
|
97
|
-
environment:
|
91
|
+
_b[Blockchain.OPTIMISM_SEPOLIA] = {
|
92
|
+
environment: BlockchainEnvironment.TESTNET,
|
98
93
|
chainId: BigInt(11155420),
|
99
94
|
},
|
100
|
-
[
|
101
|
-
environment:
|
95
|
+
_b[Blockchain.BINANCE_TESTNET] = {
|
96
|
+
environment: BlockchainEnvironment.TESTNET,
|
102
97
|
chainId: BigInt(97),
|
103
98
|
},
|
104
|
-
[
|
105
|
-
environment:
|
99
|
+
_b[Blockchain.OPBNB_TESTNET] = {
|
100
|
+
environment: BlockchainEnvironment.TESTNET,
|
106
101
|
chainId: BigInt(5611),
|
107
102
|
},
|
108
|
-
[
|
109
|
-
environment:
|
103
|
+
_b[Blockchain.MOONBEAM_ALPHA] = {
|
104
|
+
environment: BlockchainEnvironment.TESTNET,
|
110
105
|
chainId: BigInt(1287),
|
111
106
|
},
|
112
|
-
[
|
113
|
-
environment:
|
107
|
+
_b[Blockchain.POLYGON_AMOY] = {
|
108
|
+
environment: BlockchainEnvironment.TESTNET,
|
114
109
|
chainId: BigInt(80002),
|
115
110
|
},
|
116
|
-
|
117
|
-
|
118
|
-
[1]
|
119
|
-
[137]
|
120
|
-
[56]
|
121
|
-
[42161]
|
122
|
-
[42170]
|
123
|
-
[10]
|
124
|
-
[9001]
|
125
|
-
[1284]
|
126
|
-
[8453]
|
127
|
-
[43114]
|
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]
|
130
|
-
[84532]
|
131
|
-
[17000]
|
132
|
-
[421614]
|
133
|
-
[11155420]
|
134
|
-
[80002]
|
135
|
-
[97]
|
136
|
-
[5611]
|
137
|
-
[1287]
|
138
|
-
|
139
|
-
|
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);
|
package/dist/entities/account.js
CHANGED
@@ -1,21 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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 ==
|
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
|
-
|
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
|
-
?
|
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
|
-
|
47
|
+
};
|
48
|
+
return Account;
|
49
|
+
}());
|
50
|
+
export { Account };
|
@@ -1,35 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
12
|
-
|
12
|
+
var amount = FungibleTokenAmount.toFungibleTokenAmount(balance.amount);
|
13
|
+
var account = Account.toAccount(balance.account);
|
13
14
|
return new AccountBalance(amount, account);
|
14
|
-
}
|
15
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
27
|
+
};
|
28
|
+
Asset.toAsset = function (asset) {
|
32
29
|
if (!asset) {
|
33
30
|
return undefined;
|
34
31
|
}
|
35
|
-
|
32
|
+
var symbol = asset.symbol, name = asset.name;
|
36
33
|
return new Asset(symbol, name);
|
37
|
-
}
|
38
|
-
id() {
|
39
|
-
return
|
40
|
-
}
|
41
|
-
|
42
|
-
|
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
|
-
|
2
|
-
var
|
3
|
-
|
4
|
-
};
|
5
|
-
Object.
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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
|
-
|
24
|
-
|
25
|
-
(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
58
|
+
};
|
59
|
+
Currency.toCurrency = function (currency) {
|
49
60
|
if (!currency) {
|
50
61
|
return undefined;
|
51
62
|
}
|
52
|
-
|
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
|
-
|
65
|
+
};
|
66
|
+
return Currency;
|
67
|
+
}(Asset));
|
68
|
+
export { Currency };
|