@orb-labs/orby-core 0.0.1

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/actions/account_cluster.d.ts +24 -0
  4. package/dist/actions/account_cluster.js +147 -0
  5. package/dist/actions/admin.d.ts +17 -0
  6. package/dist/actions/admin.js +42 -0
  7. package/dist/actions/application.d.ts +6 -0
  8. package/dist/actions/application.js +25 -0
  9. package/dist/actions/instance.d.ts +16 -0
  10. package/dist/actions/instance.js +94 -0
  11. package/dist/actions/operation.d.ts +78 -0
  12. package/dist/actions/operation.js +113 -0
  13. package/dist/actions/token.d.ts +15 -0
  14. package/dist/actions/token.js +46 -0
  15. package/dist/constants.d.ts +4 -0
  16. package/dist/constants.js +36 -0
  17. package/dist/entities/account.d.ts +14 -0
  18. package/dist/entities/account.js +52 -0
  19. package/dist/entities/financial/account_balance.d.ts +12 -0
  20. package/dist/entities/financial/account_balance.js +35 -0
  21. package/dist/entities/financial/asset.d.ts +31 -0
  22. package/dist/entities/financial/asset.js +42 -0
  23. package/dist/entities/financial/currency.d.ts +41 -0
  24. package/dist/entities/financial/currency.js +56 -0
  25. package/dist/entities/financial/currency_amount.d.ts +31 -0
  26. package/dist/entities/financial/currency_amount.js +81 -0
  27. package/dist/entities/financial/fungible_token.d.ts +41 -0
  28. package/dist/entities/financial/fungible_token.js +70 -0
  29. package/dist/entities/financial/fungible_token_amount.d.ts +33 -0
  30. package/dist/entities/financial/fungible_token_amount.js +84 -0
  31. package/dist/entities/financial/non_fungible_token.d.ts +39 -0
  32. package/dist/entities/financial/non_fungible_token.js +66 -0
  33. package/dist/entities/financial/semi_fungible_token.d.ts +41 -0
  34. package/dist/entities/financial/semi_fungible_token.js +68 -0
  35. package/dist/entities/library_request.d.ts +8 -0
  36. package/dist/entities/library_request.js +37 -0
  37. package/dist/entities/state.d.ts +22 -0
  38. package/dist/entities/state.js +105 -0
  39. package/dist/enums.d.ts +115 -0
  40. package/dist/enums.js +137 -0
  41. package/dist/index.d.ts +26 -0
  42. package/dist/index.js +47 -0
  43. package/dist/interfaces/account_cluster.d.ts +22 -0
  44. package/dist/interfaces/account_cluster.js +2 -0
  45. package/dist/interfaces/admin.d.ts +14 -0
  46. package/dist/interfaces/admin.js +2 -0
  47. package/dist/interfaces/application.d.ts +3 -0
  48. package/dist/interfaces/application.js +2 -0
  49. package/dist/interfaces/instance.d.ts +13 -0
  50. package/dist/interfaces/instance.js +2 -0
  51. package/dist/interfaces/operation.d.ts +76 -0
  52. package/dist/interfaces/operation.js +2 -0
  53. package/dist/interfaces/orby.d.ts +8 -0
  54. package/dist/interfaces/orby.js +2 -0
  55. package/dist/interfaces/token.d.ts +12 -0
  56. package/dist/interfaces/token.js +2 -0
  57. package/dist/types.d.ts +143 -0
  58. package/dist/types.js +2 -0
  59. package/dist/utils/utils.d.ts +26 -0
  60. package/dist/utils/utils.js +319 -0
  61. package/dist/utils/validateAndParseAddress.d.ts +10 -0
  62. package/dist/utils/validateAndParseAddress.js +29 -0
  63. package/package.json +25 -0
@@ -0,0 +1,4 @@
1
+ export declare const Big: any;
2
+ export declare const BLOCKCHAIN_ID: {
3
+ [s: string]: number;
4
+ };
@@ -0,0 +1,36 @@
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.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
+ exports.Big = (0, toformat_1.default)(big_js_1.default);
11
+ exports.BLOCKCHAIN_ID = {
12
+ [enums_1.Blockchain.ETHEREUM]: 1,
13
+ [enums_1.Blockchain.POLYGON]: 137,
14
+ [enums_1.Blockchain.BINANCE]: 56,
15
+ [enums_1.Blockchain.ARBITRUM]: 42161,
16
+ [enums_1.Blockchain.ARBITRUM_NOVA]: 42170,
17
+ [enums_1.Blockchain.OPTIMISM]: 10,
18
+ [enums_1.Blockchain.EVMOS]: 9001,
19
+ [enums_1.Blockchain.MOONBEAM]: 1284,
20
+ [enums_1.Blockchain.BASE]: 8453,
21
+ [enums_1.Blockchain.AVALANCHE]: 43114,
22
+ // testnets
23
+ [enums_1.Blockchain.ETHEREUM_SEPOLIA]: 11155111,
24
+ [enums_1.Blockchain.ETHEREUM_HOLESKY]: 17000,
25
+ [enums_1.Blockchain.ARBITRUM_SEPOLIA]: 421614,
26
+ [enums_1.Blockchain.OPTIMISM_SEPOLIA]: 11155420,
27
+ [enums_1.Blockchain.POLYGON_AMOY]: 80002,
28
+ [enums_1.Blockchain.BINANCE_TESTNET]: 97,
29
+ [enums_1.Blockchain.OPBNB_TESTNET]: 5611,
30
+ [enums_1.Blockchain.MOONBEAM_ALPHA]: 1287,
31
+ [enums_1.Blockchain.BASE_SEPOLIA]: 84532,
32
+ // local testing
33
+ [enums_1.Blockchain.HARDHAT]: 31337,
34
+ [enums_1.Blockchain.LOCAL_CHAIN_0]: 1000000000001,
35
+ [enums_1.Blockchain.LOCAL_CHAIN_1]: 1000000000002,
36
+ };
@@ -0,0 +1,14 @@
1
+ import { AccountType, VMType } from "../enums";
2
+ export declare class Account {
3
+ readonly address: string;
4
+ readonly chainId?: bigint;
5
+ readonly accountType: AccountType;
6
+ readonly vmType: VMType;
7
+ readonly key: string;
8
+ hasSufficientBalanceForGas: boolean;
9
+ static toAccount(account: any): Account;
10
+ constructor(address: string, accountType: AccountType, vmType: VMType, chainId?: bigint);
11
+ static key(address: string, chainId?: bigint): string;
12
+ toAccountModel(): any;
13
+ equals(other: Account): boolean;
14
+ }
@@ -0,0 +1,52 @@
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) {
19
+ // TODO(felix): add this back
20
+ // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
21
+ this.address = address === null || address === void 0 ? void 0 : address.toLowerCase(); // validateAndParseAddress(address)?.toLowerCase();
22
+ this.chainId = chainId ? BigInt(chainId) : undefined;
23
+ this.accountType = accountType;
24
+ this.vmType = vmType;
25
+ this.key = Account.key(address, chainId);
26
+ if (this.accountType == enums_1.AccountType.SCA) {
27
+ this.hasSufficientBalanceForGas = true;
28
+ }
29
+ else {
30
+ this.hasSufficientBalanceForGas = false;
31
+ }
32
+ }
33
+ static key(address, chainId) {
34
+ var _a;
35
+ return chainId
36
+ ? `${(_a = chainId === null || chainId === void 0 ? void 0 : chainId.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase()}-${address}`
37
+ : address;
38
+ }
39
+ toAccountModel() {
40
+ var _a, _b;
41
+ return {
42
+ address: this.address,
43
+ accountType: (_a = this.accountType) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
44
+ vmType: (_b = this.vmType) === null || _b === void 0 ? void 0 : _b.toUpperCase(),
45
+ chainId: this.chainId ? "EIP155-" + this.chainId : undefined,
46
+ };
47
+ }
48
+ equals(other) {
49
+ return this.key == other.key && this.accountType == other.accountType;
50
+ }
51
+ }
52
+ exports.Account = Account;
@@ -0,0 +1,12 @@
1
+ import { Account } from "../account";
2
+ import { FungibleTokenAmount } from "./fungible_token_amount";
3
+ export declare class AccountBalance {
4
+ readonly amount: FungibleTokenAmount;
5
+ readonly account: Account;
6
+ static toAccountBalance(balance?: any): AccountBalance;
7
+ constructor(amount: FungibleTokenAmount, account: Account);
8
+ equals(other: AccountBalance): boolean;
9
+ lessThan(other: AccountBalance): boolean;
10
+ greaterThan(other: AccountBalance): boolean;
11
+ greaterThanOrEqual(other: AccountBalance): boolean;
12
+ }
@@ -0,0 +1,35 @@
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) {
8
+ if (!balance) {
9
+ return undefined;
10
+ }
11
+ const amount = fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(balance.amount);
12
+ const account = account_1.Account.toAccount(balance.account);
13
+ return new AccountBalance(amount, account);
14
+ }
15
+ constructor(amount, account) {
16
+ this.amount = amount;
17
+ this.account = account;
18
+ }
19
+ equals(other) {
20
+ return (this.account.equals(other.account) && this.amount.equals(other.amount));
21
+ }
22
+ lessThan(other) {
23
+ return (this.account.equals(other.account) && this.amount.lessThan(other.amount));
24
+ }
25
+ greaterThan(other) {
26
+ return (this.account.equals(other.account) &&
27
+ this.amount.greaterThan(other.amount));
28
+ }
29
+ greaterThanOrEqual(other) {
30
+ return (this.account.equals(other.account) &&
31
+ (this.amount.greaterThan(other.amount) ||
32
+ this.amount.equals(other.amount)));
33
+ }
34
+ }
35
+ exports.AccountBalance = AccountBalance;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * An Asset is any fungible financial instrument, including Ether, all ERC20 tokens, and NFTs
3
+ */
4
+ export declare class Asset {
5
+ /**
6
+ * The symbol of the asset, i.e. a short textual non-unique identifier
7
+ */
8
+ readonly symbol: string;
9
+ /**
10
+ * The name of the asset, i.e. a descriptive textual non-unique identifier
11
+ */
12
+ readonly name: string;
13
+ /**
14
+ * The name of the asset, i.e. a descriptive textual non-unique identifier
15
+ */
16
+ readonly coinGeckoId: string;
17
+ /**
18
+ * Constructs an instance of the `Asset`.
19
+ * @param symbol symbol of the asset
20
+ * @param name of the asset
21
+ */
22
+ constructor(symbol: string, name: string, coinGeckoId?: string);
23
+ /**
24
+ * Returns whether this asset is functionally equivalent to the other asset
25
+ * @param other the other asset
26
+ */
27
+ equals(other: Asset): boolean;
28
+ toAssetModel(): any;
29
+ static toAsset(asset?: any): Asset;
30
+ id(): string;
31
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Asset = void 0;
4
+ /**
5
+ * An Asset is any fungible financial instrument, including Ether, all ERC20 tokens, and NFTs
6
+ */
7
+ class Asset {
8
+ /**
9
+ * Constructs an instance of the `Asset`.
10
+ * @param symbol symbol of the asset
11
+ * @param name of the asset
12
+ */
13
+ constructor(symbol, name, coinGeckoId) {
14
+ this.symbol = symbol;
15
+ this.name = name;
16
+ this.coinGeckoId = coinGeckoId;
17
+ }
18
+ /**
19
+ * Returns whether this asset is functionally equivalent to the other asset
20
+ * @param other the other asset
21
+ */
22
+ equals(other) {
23
+ if (this === other)
24
+ return true;
25
+ return this.symbol === other.symbol && this.name === other.name;
26
+ }
27
+ // 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() {
29
+ return { symbol: this.symbol, name: this.name };
30
+ }
31
+ static toAsset(asset) {
32
+ if (!asset) {
33
+ return undefined;
34
+ }
35
+ const { symbol, name } = asset;
36
+ return new Asset(symbol, name);
37
+ }
38
+ id() {
39
+ return `${this.name}:${this.symbol}`;
40
+ }
41
+ }
42
+ exports.Asset = Asset;
@@ -0,0 +1,41 @@
1
+ import { Asset } from "./asset";
2
+ /**
3
+ * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
4
+ */
5
+ export declare class Currency extends Asset {
6
+ /**
7
+ * Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
8
+ */
9
+ readonly isNative: boolean;
10
+ /**
11
+ * Returns whether the currency is a token that is usable in Uniswap without wrapping
12
+ */
13
+ readonly isToken: boolean;
14
+ /**
15
+ * The decimals used in representing currency amounts
16
+ */
17
+ readonly decimals: number;
18
+ /**
19
+ * The url for the currency logo
20
+ */
21
+ readonly logoUrl?: string;
22
+ /**
23
+ * Constructs an instance of the base class `Currency`.
24
+ * @param decimals decimals of the currency
25
+ * @param symbol symbol of the currency
26
+ * @param name of the currency
27
+ * @param isNative whether the currency is native to the chain and must be wrapped (e.g. Ether)
28
+ * @param isToken whether the currency is a token that is usable in Uniswap without wrapping
29
+ */
30
+ constructor(decimals: number, symbol: string, name: string, logoUrl?: string, isNative?: boolean, isToken?: boolean, coinGeckoId?: string);
31
+ /**
32
+ * Returns whether this currency is functionally equivalent to the other currency
33
+ * @param other the other currency
34
+ */
35
+ equals(other: Currency): boolean;
36
+ /**
37
+ * Returns the asset representation of this currency
38
+ */
39
+ asset(): Asset;
40
+ static toCurrency(currency?: any): Currency;
41
+ }
@@ -0,0 +1,56 @@
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");
9
+ // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Create this instance here
10
+ // because we represent currency amounts that are not fungible token amounts.
11
+ /**
12
+ * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
13
+ */
14
+ class Currency extends asset_1.Asset {
15
+ /**
16
+ * Constructs an instance of the base class `Currency`.
17
+ * @param decimals decimals of the currency
18
+ * @param symbol symbol of the currency
19
+ * @param name of the currency
20
+ * @param isNative whether the currency is native to the chain and must be wrapped (e.g. Ether)
21
+ * @param isToken whether the currency is a token that is usable in Uniswap without wrapping
22
+ */
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;
30
+ }
31
+ /**
32
+ * Returns whether this currency is functionally equivalent to the other currency
33
+ * @param other the other currency
34
+ */
35
+ equals(other) {
36
+ if (this === other)
37
+ return true;
38
+ return (this.symbol === other.symbol &&
39
+ this.name === other.name &&
40
+ this.decimals === other.decimals);
41
+ }
42
+ /**
43
+ * Returns the asset representation of this currency
44
+ */
45
+ asset() {
46
+ return this;
47
+ }
48
+ static toCurrency(currency) {
49
+ if (!currency) {
50
+ return undefined;
51
+ }
52
+ const { asset, decimals, logoUrl, isNative } = currency;
53
+ return new Currency(decimals, asset.symbol, asset.name, logoUrl, isNative);
54
+ }
55
+ }
56
+ exports.Currency = Currency;
@@ -0,0 +1,31 @@
1
+ import JSBI from "jsbi";
2
+ import { Fraction, BigintIsh } from "@uniswap/sdk-core";
3
+ import { Currency } from "./currency";
4
+ export declare class CurrencyAmount extends Fraction {
5
+ readonly currency: Currency;
6
+ readonly decimalScale: JSBI;
7
+ private amountInFiatCurrency?;
8
+ /**
9
+ * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
10
+ * @param currency the currency in the amount
11
+ * @param rawAmount the raw token or ether amount
12
+ */
13
+ static fromRawAmount(currency: Currency, rawAmount: BigintIsh | bigint): CurrencyAmount;
14
+ static toCurrencyAmount(amount?: any): CurrencyAmount;
15
+ /**
16
+ * Construct a currency amount with a denominator that is not equal to 1
17
+ * @param currency the currency
18
+ * @param numerator the numerator of the fractional token amount
19
+ * @param denominator the denominator of the fractional token amount
20
+ */
21
+ static fromFractionalAmount(currency: Currency, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount;
22
+ protected constructor(currency: Currency, numerator: BigintIsh | bigint, denominator?: BigintIsh | bigint);
23
+ add(other: CurrencyAmount): CurrencyAmount;
24
+ subtract(other: CurrencyAmount): CurrencyAmount;
25
+ multiply(other: Fraction | BigintIsh): CurrencyAmount;
26
+ divide(other: Fraction | BigintIsh): CurrencyAmount;
27
+ cloneWithAmount(amount: bigint): CurrencyAmount;
28
+ toRawAmount(): bigint;
29
+ toCurrencyValue(price: CurrencyAmount): CurrencyAmount;
30
+ fiatValue(): CurrencyAmount;
31
+ }
@@ -0,0 +1,81 @@
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
+ // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
12
+ // because we have a need to represent a currency amount that is not a fungible token amount.
13
+ class CurrencyAmount extends sdk_core_1.Fraction {
14
+ /**
15
+ * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
16
+ * @param currency the currency in the amount
17
+ * @param rawAmount the raw token or ether amount
18
+ */
19
+ static fromRawAmount(currency, rawAmount) {
20
+ return new CurrencyAmount(currency, rawAmount);
21
+ }
22
+ static toCurrencyAmount(amount) {
23
+ if (!amount) {
24
+ return undefined;
25
+ }
26
+ const currency = currency_1.Currency.toCurrency(amount.currency);
27
+ return CurrencyAmount.fromRawAmount(currency, amount.value);
28
+ }
29
+ /**
30
+ * Construct a currency amount with a denominator that is not equal to 1
31
+ * @param currency the currency
32
+ * @param numerator the numerator of the fractional token amount
33
+ * @param denominator the denominator of the fractional token amount
34
+ */
35
+ static fromFractionalAmount(currency, numerator, denominator) {
36
+ return new CurrencyAmount(currency, numerator, denominator);
37
+ }
38
+ constructor(currency, numerator, denominator) {
39
+ super(numerator.toString(), denominator === null || denominator === void 0 ? void 0 : denominator.toString());
40
+ (0, tiny_invariant_1.default)(jsbi_1.default.lessThanOrEqual(this.quotient, sdk_core_1.MaxUint256), "AMOUNT");
41
+ this.currency = currency;
42
+ this.decimalScale = jsbi_1.default.exponentiate(jsbi_1.default.BigInt(10), jsbi_1.default.BigInt(currency.decimals));
43
+ }
44
+ add(other) {
45
+ if (!other) {
46
+ return this;
47
+ }
48
+ (0, tiny_invariant_1.default)(this.currency.equals(other.currency), "CURRENCY");
49
+ const added = super.add(other);
50
+ return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
51
+ }
52
+ subtract(other) {
53
+ (0, tiny_invariant_1.default)(this.currency.equals(other.currency), "CURRENCY");
54
+ const subtracted = super.subtract(other);
55
+ return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
56
+ }
57
+ multiply(other) {
58
+ const multiplied = super.multiply(other);
59
+ return CurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
60
+ }
61
+ divide(other) {
62
+ const divided = super.divide(other);
63
+ return CurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
64
+ }
65
+ cloneWithAmount(amount) {
66
+ return CurrencyAmount.fromRawAmount(this.currency, amount);
67
+ }
68
+ toRawAmount() {
69
+ return BigInt(this.quotient.toString());
70
+ }
71
+ toCurrencyValue(price) {
72
+ const fraction = price.multiply(this);
73
+ const denominator = jsbi_1.default.multiply(fraction.denominator, this.decimalScale);
74
+ this.amountInFiatCurrency = CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
75
+ return this.amountInFiatCurrency;
76
+ }
77
+ fiatValue() {
78
+ return this.amountInFiatCurrency;
79
+ }
80
+ }
81
+ exports.CurrencyAmount = CurrencyAmount;
@@ -0,0 +1,41 @@
1
+ import { Currency } from "./currency";
2
+ import { TokenType } from "../../enums";
3
+ /**
4
+ * Represents an ERC20 token with a unique address and some metadata.
5
+ */
6
+ export declare class FungibleToken extends Currency {
7
+ readonly isToken: true;
8
+ /**
9
+ * The contract address on the chain on which this token lives
10
+ */
11
+ readonly address: string;
12
+ /**
13
+ * The chain ID on which this token resides
14
+ */
15
+ readonly chainId: bigint;
16
+ /**
17
+ * @param isNative If true, it means that this token is the native token of the chain
18
+ */
19
+ readonly isNative: boolean;
20
+ static toFungibleToken(token?: any): FungibleToken;
21
+ /**
22
+ * @param chainId The chain ID on which this token resides
23
+ * @param address The contract address on the chain on which this token lives
24
+ * @param decimals {@link Currency#decimals}
25
+ * @param symbol {@link Currency#symbol}
26
+ * @param name {@link Currency#name}
27
+ * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
28
+ */
29
+ constructor(chainId: bigint, address: string, decimals: number, symbol: string, name: string, bypassChecksum?: boolean, isNative?: boolean, coinGeckoId?: string);
30
+ /**
31
+ * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
32
+ * @param other other token to compare
33
+ */
34
+ equals(other: FungibleToken): boolean;
35
+ /**
36
+ * Returns the currency object that this token represents
37
+ */
38
+ currency(): Currency;
39
+ type(): TokenType;
40
+ identifier(): string;
41
+ }
@@ -0,0 +1,70 @@
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");
7
+ /**
8
+ * Represents an ERC20 token with a unique address and some metadata.
9
+ */
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
+ }
18
+ /**
19
+ * @param chainId The chain ID on which this token resides
20
+ * @param address The contract address on the chain on which this token lives
21
+ * @param decimals {@link Currency#decimals}
22
+ * @param symbol {@link Currency#symbol}
23
+ * @param name {@link Currency#name}
24
+ * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
25
+ */
26
+ constructor(chainId, address, decimals, symbol, name, bypassChecksum, isNative, coinGeckoId) {
27
+ // TODO(felix): add this back
28
+ // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
29
+ var _a, _b;
30
+ super(decimals, symbol, name, undefined, isNative, true, coinGeckoId);
31
+ this.isToken = true;
32
+ // TODO(felix): bypassChecksum is a little confusing since when bypassChecksum is true, we still validate the address
33
+ // bypassChecksum is derived from the isNative parameter, so we should remove it and just check if isNative here
34
+ if (bypassChecksum) {
35
+ this.address = (_a = (0, validateAndParseAddress_1.checkValidAddress)(address)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
36
+ }
37
+ else if (!isNative) {
38
+ this.address = (_b = (0, validateAndParseAddress_1.validateAndParseAddress)(address)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
39
+ }
40
+ else {
41
+ this.address = address;
42
+ }
43
+ this.isNative = isNative || false;
44
+ this.chainId = chainId;
45
+ }
46
+ /**
47
+ * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
48
+ * @param other other token to compare
49
+ */
50
+ equals(other) {
51
+ var _a;
52
+ if (this === other)
53
+ return true;
54
+ return (this.chainId == (other === null || other === void 0 ? void 0 : other.chainId) &&
55
+ this.address.toLowerCase() == ((_a = other === null || other === void 0 ? void 0 : other.address) === null || _a === void 0 ? void 0 : _a.toLowerCase()));
56
+ }
57
+ /**
58
+ * Returns the currency object that this token represents
59
+ */
60
+ currency() {
61
+ 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;
@@ -0,0 +1,33 @@
1
+ import JSBI from "jsbi";
2
+ import { Fraction, BigintIsh } from "@uniswap/sdk-core";
3
+ import { FungibleToken } from "./fungible_token";
4
+ import { CurrencyAmount } from "./currency_amount";
5
+ export declare class FungibleTokenAmount extends Fraction {
6
+ readonly token: FungibleToken;
7
+ readonly decimalScale: JSBI;
8
+ private amountInFiatCurrency?;
9
+ /**
10
+ * Returns a new fungibleToken amount instance from the unitless amount of token, i.e. the raw amount
11
+ * @param fungibleToken the fungibleToken in the amount
12
+ * @param rawAmount the raw token or ether amount
13
+ */
14
+ static fromRawAmount(fungibleToken: FungibleToken, rawAmount: BigintIsh | bigint, amountInFiatCurrency?: CurrencyAmount): FungibleTokenAmount;
15
+ /**
16
+ * Construct a fungibleToken amount with a denominator that is not equal to 1
17
+ * @param fungibleToken the fungibleToken
18
+ * @param numerator the numerator of the fractional token amount
19
+ * @param denominator the denominator of the fractional token amount
20
+ */
21
+ static fromFractionalAmount(fungibleToken: FungibleToken, numerator: BigintIsh, denominator: BigintIsh, amountInFiatCurrency?: CurrencyAmount): FungibleTokenAmount;
22
+ static toFungibleTokenAmount(amount?: any): FungibleTokenAmount;
23
+ protected constructor(fungibleToken: FungibleToken, numerator: BigintIsh | bigint, denominator?: BigintIsh | bigint, amountInFiatCurrency?: CurrencyAmount);
24
+ equals(other: FungibleTokenAmount): boolean;
25
+ add(other: FungibleTokenAmount): FungibleTokenAmount;
26
+ subtract(other: FungibleTokenAmount): FungibleTokenAmount;
27
+ multiply(other: Fraction | BigintIsh): FungibleTokenAmount;
28
+ divide(other: Fraction | BigintIsh): FungibleTokenAmount;
29
+ greaterThanOrEqual(other: FungibleTokenAmount): boolean;
30
+ toRawAmount(): bigint;
31
+ fiatValue(): CurrencyAmount;
32
+ toCurrencyValue(price: CurrencyAmount): CurrencyAmount;
33
+ }