@orb-labs/orby-core 0.0.15 → 0.0.17

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 (82) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/actions/operation.d.ts +2 -2
  3. package/dist/cjs/actions/operation.js +74 -4
  4. package/dist/cjs/entities/account.js +1 -1
  5. package/dist/cjs/interfaces/operation.d.ts +2 -2
  6. package/dist/cjs/types.d.ts +20 -0
  7. package/dist/esm/actions/operation.d.ts +2 -2
  8. package/dist/esm/actions/operation.js +75 -5
  9. package/dist/esm/actions/token.js +1 -1
  10. package/dist/esm/entities/account.js +1 -1
  11. package/dist/esm/interfaces/operation.d.ts +2 -2
  12. package/dist/esm/types.d.ts +20 -0
  13. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  14. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  15. package/package.json +1 -2
  16. package/dist/actions/account_cluster.d.ts +0 -32
  17. package/dist/actions/account_cluster.js +0 -207
  18. package/dist/actions/admin.d.ts +0 -17
  19. package/dist/actions/admin.js +0 -39
  20. package/dist/actions/application.d.ts +0 -6
  21. package/dist/actions/application.js +0 -16
  22. package/dist/actions/blockchain.d.ts +0 -16
  23. package/dist/actions/blockchain.js +0 -35
  24. package/dist/actions/instance.d.ts +0 -15
  25. package/dist/actions/instance.js +0 -94
  26. package/dist/actions/operation.d.ts +0 -99
  27. package/dist/actions/operation.js +0 -341
  28. package/dist/actions/token.d.ts +0 -15
  29. package/dist/actions/token.js +0 -46
  30. package/dist/constants.d.ts +0 -14
  31. package/dist/constants.js +0 -133
  32. package/dist/entities/account.d.ts +0 -14
  33. package/dist/entities/account.js +0 -45
  34. package/dist/entities/financial/account_balance.d.ts +0 -12
  35. package/dist/entities/financial/account_balance.js +0 -31
  36. package/dist/entities/financial/asset.d.ts +0 -31
  37. package/dist/entities/financial/asset.js +0 -38
  38. package/dist/entities/financial/currency.d.ts +0 -41
  39. package/dist/entities/financial/currency.js +0 -49
  40. package/dist/entities/financial/currency_amount.d.ts +0 -34
  41. package/dist/entities/financial/currency_amount.js +0 -92
  42. package/dist/entities/financial/fungible_token.d.ts +0 -41
  43. package/dist/entities/financial/fungible_token.js +0 -64
  44. package/dist/entities/financial/fungible_token_amount.d.ts +0 -36
  45. package/dist/entities/financial/fungible_token_amount.js +0 -95
  46. package/dist/entities/financial/non_fungible_token.d.ts +0 -39
  47. package/dist/entities/financial/non_fungible_token.js +0 -61
  48. package/dist/entities/financial/semi_fungible_token.d.ts +0 -41
  49. package/dist/entities/financial/semi_fungible_token.js +0 -63
  50. package/dist/entities/library_request.d.ts +0 -8
  51. package/dist/entities/library_request.js +0 -30
  52. package/dist/entities/state.d.ts +0 -22
  53. package/dist/entities/state.js +0 -102
  54. package/dist/enums.d.ts +0 -116
  55. package/dist/enums.js +0 -135
  56. package/dist/index.d.ts +0 -29
  57. package/dist/index.js +0 -33
  58. package/dist/interfaces/account_cluster.d.ts +0 -30
  59. package/dist/interfaces/account_cluster.js +0 -1
  60. package/dist/interfaces/admin.d.ts +0 -14
  61. package/dist/interfaces/admin.js +0 -1
  62. package/dist/interfaces/application.d.ts +0 -3
  63. package/dist/interfaces/application.js +0 -1
  64. package/dist/interfaces/blockchain.d.ts +0 -13
  65. package/dist/interfaces/blockchain.js +0 -1
  66. package/dist/interfaces/instance.d.ts +0 -12
  67. package/dist/interfaces/instance.js +0 -1
  68. package/dist/interfaces/operation.d.ts +0 -97
  69. package/dist/interfaces/operation.js +0 -1
  70. package/dist/interfaces/orby.d.ts +0 -9
  71. package/dist/interfaces/orby.js +0 -1
  72. package/dist/interfaces/token.d.ts +0 -12
  73. package/dist/interfaces/token.js +0 -1
  74. package/dist/tsconfig.tsbuildinfo +0 -1
  75. package/dist/types.d.ts +0 -152
  76. package/dist/types.js +0 -1
  77. package/dist/utils/action_helpers.d.ts +0 -22
  78. package/dist/utils/action_helpers.js +0 -250
  79. package/dist/utils/utils.d.ts +0 -10
  80. package/dist/utils/utils.js +0 -70
  81. package/dist/utils/validateAndParseAddress.d.ts +0 -10
  82. package/dist/utils/validateAndParseAddress.js +0 -25
@@ -1,15 +0,0 @@
1
- import { StandardizedToken } from "../types.js";
2
- import { LibraryRequest } from "../entities/library_request.js";
3
- import { LIBRARY_TYPE } from "../enums.js";
4
- export declare class TokenActions extends LibraryRequest {
5
- constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
6
- getStandardizedTokenIds(tokens: {
7
- tokenAddress: string;
8
- chainId: bigint;
9
- }[]): Promise<string[]>;
10
- getStandardizedTokens(tokens: {
11
- tokenAddress: string;
12
- chainId: bigint;
13
- }[]): Promise<StandardizedToken[]>;
14
- getFungibleTokenData(standardizedTokenIds: string[]): Promise<StandardizedToken[]>;
15
- }
@@ -1,46 +0,0 @@
1
- import { extractStandardizedTokens, } from "../utils/action_helpers.js";
2
- import { LibraryRequest } from "../entities/library_request.js";
3
- import { getOrbyChainId } from "../utils/utils.js";
4
- export class TokenActions extends LibraryRequest {
5
- constructor(library, client, provider) {
6
- super(library, client, provider);
7
- }
8
- async getStandardizedTokenIds(tokens) {
9
- const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
10
- return { chainId: getOrbyChainId(chainId), tokenAddress };
11
- });
12
- const { standardizedTokenIds, message, code } = await this.sendRequest("orby_getStandardizedTokenIds", [
13
- {
14
- tokens: formattedTokensInfo,
15
- },
16
- ]);
17
- if (code && message) {
18
- console.error("[getStandardizedTokenIds]", code, message);
19
- return undefined;
20
- }
21
- return standardizedTokenIds;
22
- }
23
- async getStandardizedTokens(tokens) {
24
- const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
25
- return { chainId: getOrbyChainId(chainId), tokenAddress };
26
- });
27
- const { standardizedTokens, message, code } = await this.sendRequest("orby_getStandardizedTokens", [
28
- {
29
- tokens: formattedTokensInfo,
30
- },
31
- ]);
32
- if (code && message) {
33
- console.error("[getStandardizedTokens]", code, message);
34
- return undefined;
35
- }
36
- return extractStandardizedTokens(standardizedTokens);
37
- }
38
- async getFungibleTokenData(standardizedTokenIds) {
39
- const { data, message, code } = await this.sendRequest("orby_getFungibleTokenData", [{ standardizedTokenIds }]);
40
- if (code && message) {
41
- console.error("[getFungibleTokenData]", code, message);
42
- return undefined;
43
- }
44
- return extractStandardizedTokens(data);
45
- }
46
- }
@@ -1,14 +0,0 @@
1
- import { Blockchain } from "./enums.js";
2
- import { Currency } from "./entities/financial/currency.js";
3
- import { ChainConfigs } from "./types.js";
4
- export declare const Big: any;
5
- export declare const BLOCKCHAIN_ID: {
6
- [s: string]: number;
7
- };
8
- export declare const CHAIN_CONFIGS: {
9
- [s: string]: ChainConfigs;
10
- };
11
- export declare const BLOCKCHAIN_ID_TO_BLOCKCHAIN: {
12
- [s: number]: Blockchain;
13
- };
14
- export declare const FIAT_CURRENCY: Currency;
package/dist/constants.js DELETED
@@ -1,133 +0,0 @@
1
- import toFormat from "toformat";
2
- import _Big from "big.js";
3
- import { Blockchain, BlockchainEnvironment } from "./enums.js";
4
- import { Currency } from "./entities/financial/currency.js";
5
- export const Big = toFormat(_Big);
6
- export const BLOCKCHAIN_ID = {
7
- [Blockchain.ETHEREUM]: 1,
8
- [Blockchain.POLYGON]: 137,
9
- [Blockchain.BINANCE]: 56,
10
- [Blockchain.ARBITRUM]: 42161,
11
- [Blockchain.ARBITRUM_NOVA]: 42170,
12
- [Blockchain.OPTIMISM]: 10,
13
- [Blockchain.EVMOS]: 9001,
14
- [Blockchain.MOONBEAM]: 1284,
15
- [Blockchain.BASE]: 8453,
16
- [Blockchain.AVALANCHE]: 43114,
17
- // testnets
18
- [Blockchain.ETHEREUM_SEPOLIA]: 11155111,
19
- [Blockchain.ETHEREUM_HOLESKY]: 17000,
20
- [Blockchain.ARBITRUM_SEPOLIA]: 421614,
21
- [Blockchain.OPTIMISM_SEPOLIA]: 11155420,
22
- [Blockchain.POLYGON_AMOY]: 80002,
23
- [Blockchain.BINANCE_TESTNET]: 97,
24
- [Blockchain.OPBNB_TESTNET]: 5611,
25
- [Blockchain.MOONBEAM_ALPHA]: 1287,
26
- [Blockchain.BASE_SEPOLIA]: 84532,
27
- // local testing
28
- [Blockchain.HARDHAT]: 31337,
29
- [Blockchain.LOCAL_CHAIN_0]: 1_000_000_000_001,
30
- [Blockchain.LOCAL_CHAIN_1]: 1_000_000_000_002,
31
- };
32
- export const CHAIN_CONFIGS = {
33
- [Blockchain.ETHEREUM]: {
34
- environment: BlockchainEnvironment.MAINNET,
35
- chainId: BigInt(1),
36
- },
37
- [Blockchain.POLYGON]: {
38
- environment: BlockchainEnvironment.MAINNET,
39
- chainId: BigInt(137),
40
- },
41
- [Blockchain.BINANCE]: {
42
- environment: BlockchainEnvironment.MAINNET,
43
- chainId: BigInt(56),
44
- },
45
- [Blockchain.ARBITRUM]: {
46
- environment: BlockchainEnvironment.MAINNET,
47
- chainId: BigInt(42161),
48
- },
49
- [Blockchain.ARBITRUM_NOVA]: {
50
- environment: BlockchainEnvironment.MAINNET,
51
- chainId: BigInt(42170),
52
- },
53
- [Blockchain.OPTIMISM]: {
54
- environment: BlockchainEnvironment.MAINNET,
55
- chainId: BigInt(10),
56
- },
57
- [Blockchain.EVMOS]: {
58
- environment: BlockchainEnvironment.MAINNET,
59
- chainId: BigInt(9001),
60
- },
61
- [Blockchain.MOONBEAM]: {
62
- environment: BlockchainEnvironment.MAINNET,
63
- chainId: BigInt(1284),
64
- },
65
- [Blockchain.BASE]: {
66
- environment: BlockchainEnvironment.MAINNET,
67
- chainId: BigInt(8453),
68
- },
69
- [Blockchain.AVALANCHE]: {
70
- environment: BlockchainEnvironment.MAINNET,
71
- chainId: BigInt(43114),
72
- },
73
- // testnets
74
- [Blockchain.ETHEREUM_SEPOLIA]: {
75
- environment: BlockchainEnvironment.TESTNET,
76
- chainId: BigInt(11155111),
77
- },
78
- [Blockchain.ETHEREUM_HOLESKY]: {
79
- environment: BlockchainEnvironment.TESTNET,
80
- chainId: BigInt(17000),
81
- },
82
- [Blockchain.ARBITRUM_SEPOLIA]: {
83
- environment: BlockchainEnvironment.TESTNET,
84
- chainId: BigInt(421614),
85
- },
86
- [Blockchain.BASE_SEPOLIA]: {
87
- environment: BlockchainEnvironment.TESTNET,
88
- chainId: BigInt(84532),
89
- },
90
- [Blockchain.OPTIMISM_SEPOLIA]: {
91
- environment: BlockchainEnvironment.TESTNET,
92
- chainId: BigInt(11155420),
93
- },
94
- [Blockchain.BINANCE_TESTNET]: {
95
- environment: BlockchainEnvironment.TESTNET,
96
- chainId: BigInt(97),
97
- },
98
- [Blockchain.OPBNB_TESTNET]: {
99
- environment: BlockchainEnvironment.TESTNET,
100
- chainId: BigInt(5611),
101
- },
102
- [Blockchain.MOONBEAM_ALPHA]: {
103
- environment: BlockchainEnvironment.TESTNET,
104
- chainId: BigInt(1287),
105
- },
106
- [Blockchain.POLYGON_AMOY]: {
107
- environment: BlockchainEnvironment.TESTNET,
108
- chainId: BigInt(80002),
109
- },
110
- };
111
- export const BLOCKCHAIN_ID_TO_BLOCKCHAIN = {
112
- [1]: Blockchain.ETHEREUM,
113
- [137]: Blockchain.POLYGON,
114
- [56]: Blockchain.BINANCE,
115
- [42161]: Blockchain.ARBITRUM,
116
- [42170]: Blockchain.ARBITRUM_NOVA,
117
- [10]: Blockchain.OPTIMISM,
118
- [9001]: Blockchain.EVMOS,
119
- [1284]: Blockchain.MOONBEAM,
120
- [8453]: Blockchain.BASE,
121
- [43114]: Blockchain.AVALANCHE,
122
- // testnets
123
- [11155111]: Blockchain.ETHEREUM_SEPOLIA,
124
- [84532]: Blockchain.BASE_SEPOLIA,
125
- [17000]: Blockchain.ETHEREUM_HOLESKY,
126
- [421614]: Blockchain.ARBITRUM_SEPOLIA,
127
- [11155420]: Blockchain.OPTIMISM_SEPOLIA,
128
- [80002]: Blockchain.POLYGON_AMOY,
129
- [97]: Blockchain.BINANCE_TESTNET,
130
- [5611]: Blockchain.OPBNB_TESTNET,
131
- [1287]: Blockchain.MOONBEAM_ALPHA,
132
- };
133
- export const FIAT_CURRENCY = new Currency(6, "USD", "US Dollar", undefined, false, false);
@@ -1,14 +0,0 @@
1
- import { AccountType, VMType } from "../enums.js";
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
- }
@@ -1,45 +0,0 @@
1
- import { AccountType } from "../enums.js";
2
- import { getChainIdFromOrbyChainId } from "../utils/utils.js";
3
- export class Account {
4
- static toAccount(account) {
5
- const chainId = account?.chainId
6
- ? getChainIdFromOrbyChainId(account.chainId)
7
- : undefined;
8
- const formattedAccountType = account?.accountType?.toLowerCase();
9
- if (!chainId && formattedAccountType == AccountType.SCA) {
10
- return undefined;
11
- }
12
- return new Account(account.address, formattedAccountType, account.vmType, chainId);
13
- }
14
- constructor(address, accountType, vmType, chainId) {
15
- // TODO(felix): add this back
16
- // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
17
- this.address = address?.toLowerCase(); // validateAndParseAddress(address)?.toLowerCase();
18
- this.chainId = chainId ? BigInt(chainId) : undefined;
19
- this.accountType = accountType;
20
- this.vmType = vmType;
21
- this.key = Account.key(address, chainId);
22
- if (this.accountType == AccountType.SCA) {
23
- this.hasSufficientBalanceForGas = true;
24
- }
25
- else {
26
- this.hasSufficientBalanceForGas = false;
27
- }
28
- }
29
- static key(address, chainId) {
30
- return chainId
31
- ? `${chainId?.toString()?.toLowerCase()}-${address}`
32
- : address;
33
- }
34
- toAccountModel() {
35
- return {
36
- address: this.address,
37
- accountType: this.accountType?.toUpperCase(),
38
- vmType: this.vmType?.toUpperCase(),
39
- chainId: this.chainId ? "EIP155-" + this.chainId : undefined,
40
- };
41
- }
42
- equals(other) {
43
- return this.key == other?.key && this.accountType == other?.accountType;
44
- }
45
- }
@@ -1,12 +0,0 @@
1
- import { Account } from "../account.js";
2
- import { FungibleTokenAmount } from "./fungible_token_amount.js";
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
- }
@@ -1,31 +0,0 @@
1
- import { Account } from "../account.js";
2
- import { FungibleTokenAmount } from "./fungible_token_amount.js";
3
- export class AccountBalance {
4
- static toAccountBalance(balance) {
5
- if (!balance) {
6
- return undefined;
7
- }
8
- const amount = FungibleTokenAmount.toFungibleTokenAmount(balance.amount);
9
- const account = Account.toAccount(balance.account);
10
- return new AccountBalance(amount, account);
11
- }
12
- constructor(amount, account) {
13
- this.amount = amount;
14
- this.account = account;
15
- }
16
- equals(other) {
17
- return (this.account.equals(other.account) && this.amount.equals(other.amount));
18
- }
19
- lessThan(other) {
20
- return (this.account.equals(other.account) && this.amount.lessThan(other.amount));
21
- }
22
- greaterThan(other) {
23
- return (this.account.equals(other.account) &&
24
- this.amount.greaterThan(other.amount));
25
- }
26
- greaterThanOrEqual(other) {
27
- return (this.account.equals(other.account) &&
28
- (this.amount.greaterThan(other.amount) ||
29
- this.amount.equals(other.amount)));
30
- }
31
- }
@@ -1,31 +0,0 @@
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
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * An Asset is any fungible financial instrument, including Ether, all ERC20 tokens, and NFTs
3
- */
4
- export class Asset {
5
- /**
6
- * Constructs an instance of the `Asset`.
7
- * @param symbol symbol of the asset
8
- * @param name of the asset
9
- */
10
- constructor(symbol, name, coinGeckoId) {
11
- this.symbol = symbol;
12
- this.name = name;
13
- this.coinGeckoId = coinGeckoId;
14
- }
15
- /**
16
- * Returns whether this asset is functionally equivalent to the other asset
17
- * @param other the other asset
18
- */
19
- equals(other) {
20
- if (this === other)
21
- return true;
22
- return this.symbol === other.symbol && this.name === other.name;
23
- }
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
25
- toAssetModel() {
26
- return { symbol: this.symbol, name: this.name };
27
- }
28
- static toAsset(asset) {
29
- if (!asset) {
30
- return undefined;
31
- }
32
- const { symbol, name } = asset;
33
- return new Asset(symbol, name);
34
- }
35
- id() {
36
- return `${this.name}:${this.symbol}`;
37
- }
38
- }
@@ -1,41 +0,0 @@
1
- import { Asset } from "./asset.js";
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
- }
@@ -1,49 +0,0 @@
1
- import invariant from "tiny-invariant";
2
- import { Asset } from "./asset.js";
3
- // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Create this instance here
4
- // because we represent currency amounts that are not fungible token amounts.
5
- /**
6
- * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
7
- */
8
- export class Currency extends Asset {
9
- /**
10
- * Constructs an instance of the base class `Currency`.
11
- * @param decimals decimals of the currency
12
- * @param symbol symbol of the currency
13
- * @param name of the currency
14
- * @param isNative whether the currency is native to the chain and must be wrapped (e.g. Ether)
15
- * @param isToken whether the currency is a token that is usable in Uniswap without wrapping
16
- */
17
- constructor(decimals, symbol, name, logoUrl, isNative, isToken, coinGeckoId) {
18
- super(symbol, name, coinGeckoId);
19
- invariant(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), "DECIMALS");
20
- this.decimals = decimals;
21
- this.isNative = isNative ?? false;
22
- this.isToken = isToken ?? true;
23
- this.logoUrl = logoUrl;
24
- }
25
- /**
26
- * Returns whether this currency is functionally equivalent to the other currency
27
- * @param other the other currency
28
- */
29
- equals(other) {
30
- if (this === other)
31
- return true;
32
- return (this.symbol === other.symbol &&
33
- this.name === other.name &&
34
- this.decimals === other.decimals);
35
- }
36
- /**
37
- * Returns the asset representation of this currency
38
- */
39
- asset() {
40
- return this;
41
- }
42
- static toCurrency(currency) {
43
- if (!currency) {
44
- return undefined;
45
- }
46
- const { asset, decimals, logoUrl, isNative } = currency;
47
- return new Currency(decimals, asset.symbol, asset.name, logoUrl, isNative);
48
- }
49
- }
@@ -1,34 +0,0 @@
1
- import JSBI from "jsbi";
2
- import { Fraction, BigintIsh, Rounding } from "@uniswap/sdk-core";
3
- import { Currency } from "./currency.js";
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
- toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
32
- toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
33
- toExact(format?: object): string;
34
- }
@@ -1,92 +0,0 @@
1
- import invariant from "tiny-invariant";
2
- import JSBI from "jsbi";
3
- import { Fraction, MaxUint256, Rounding } from "@uniswap/sdk-core";
4
- import { Currency } from "./currency.js";
5
- import { Big } from "../../constants.js";
6
- // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
7
- // because we have a need to represent a currency amount that is not a fungible token amount.
8
- export class CurrencyAmount extends Fraction {
9
- /**
10
- * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
11
- * @param currency the currency in the amount
12
- * @param rawAmount the raw token or ether amount
13
- */
14
- static fromRawAmount(currency, rawAmount) {
15
- return new CurrencyAmount(currency, rawAmount);
16
- }
17
- static toCurrencyAmount(amount) {
18
- if (!amount) {
19
- return undefined;
20
- }
21
- const currency = Currency.toCurrency(amount.currency);
22
- return CurrencyAmount.fromRawAmount(currency, amount.value);
23
- }
24
- /**
25
- * Construct a currency amount with a denominator that is not equal to 1
26
- * @param currency the currency
27
- * @param numerator the numerator of the fractional token amount
28
- * @param denominator the denominator of the fractional token amount
29
- */
30
- static fromFractionalAmount(currency, numerator, denominator) {
31
- return new CurrencyAmount(currency, numerator, denominator);
32
- }
33
- constructor(currency, numerator, denominator) {
34
- super(numerator.toString(), denominator?.toString());
35
- invariant(JSBI.lessThanOrEqual(this.quotient, MaxUint256), "AMOUNT");
36
- this.currency = currency;
37
- this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(currency.decimals));
38
- }
39
- add(other) {
40
- if (!other) {
41
- return this;
42
- }
43
- invariant(this.currency.equals(other.currency), "CURRENCY");
44
- const added = super.add(other);
45
- return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
46
- }
47
- subtract(other) {
48
- invariant(this.currency.equals(other.currency), "CURRENCY");
49
- const subtracted = super.subtract(other);
50
- return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
51
- }
52
- multiply(other) {
53
- const multiplied = super.multiply(other);
54
- return CurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
55
- }
56
- divide(other) {
57
- const divided = super.divide(other);
58
- return CurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
59
- }
60
- cloneWithAmount(amount) {
61
- return CurrencyAmount.fromRawAmount(this.currency, amount);
62
- }
63
- toRawAmount() {
64
- return BigInt(this.quotient.toString());
65
- }
66
- toCurrencyValue(price) {
67
- const fraction = price.multiply(this);
68
- const denominator = JSBI.multiply(fraction.denominator, this.decimalScale);
69
- this.amountInFiatCurrency = CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
70
- return this.amountInFiatCurrency;
71
- }
72
- fiatValue() {
73
- return this.amountInFiatCurrency;
74
- }
75
- toSignificant(significantDigits = 6, format, rounding = Rounding.ROUND_DOWN) {
76
- return super
77
- .divide(this.decimalScale)
78
- .toSignificant(significantDigits, format, rounding);
79
- }
80
- toFixed(decimalPlaces = this.currency.decimals, format, rounding = Rounding.ROUND_DOWN) {
81
- invariant(decimalPlaces <= this.currency.decimals, "DECIMALS");
82
- return super
83
- .divide(this.decimalScale)
84
- .toFixed(decimalPlaces, format, rounding);
85
- }
86
- toExact(format = { groupSeparator: "" }) {
87
- Big.DP = this.currency.decimals;
88
- return new Big(this.quotient.toString())
89
- .div(this.decimalScale.toString())
90
- .toFormat(format);
91
- }
92
- }
@@ -1,41 +0,0 @@
1
- import { Currency } from "./currency.js";
2
- import { TokenType } from "../../enums.js";
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, logoUrl?: 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
- }