@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,64 +0,0 @@
1
- import { Currency } from "./currency.js";
2
- import { checkValidAddress, validateAndParseAddress, } from "../../utils/validateAndParseAddress.js";
3
- import { TokenType } from "../../enums.js";
4
- /**
5
- * Represents an ERC20 token with a unique address and some metadata.
6
- */
7
- export class FungibleToken extends Currency {
8
- static toFungibleToken(token) {
9
- if (!token) {
10
- return undefined;
11
- }
12
- const { address, chainId, currency, coinGeckoId, isNative } = token;
13
- return new FungibleToken(BigInt(chainId), address, currency.decimals, currency.asset.symbol, currency.asset.name, undefined, isNative, coinGeckoId);
14
- }
15
- /**
16
- * @param chainId The chain ID on which this token resides
17
- * @param address The contract address on the chain on which this token lives
18
- * @param decimals {@link Currency#decimals}
19
- * @param symbol {@link Currency#symbol}
20
- * @param name {@link Currency#name}
21
- * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
22
- */
23
- constructor(chainId, address, decimals, symbol, name, bypassChecksum, isNative, coinGeckoId, logoUrl) {
24
- // TODO(felix): add this back
25
- // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
26
- super(decimals, symbol, name, logoUrl, isNative, true, coinGeckoId);
27
- this.isToken = true;
28
- // TODO(felix): bypassChecksum is a little confusing since when bypassChecksum is true, we still validate the address
29
- // bypassChecksum is derived from the isNative parameter, so we should remove it and just check if isNative here
30
- if (bypassChecksum) {
31
- this.address = checkValidAddress(address)?.toLowerCase();
32
- }
33
- else if (!isNative) {
34
- this.address = validateAndParseAddress(address)?.toLowerCase();
35
- }
36
- else {
37
- this.address = address;
38
- }
39
- this.isNative = isNative || false;
40
- this.chainId = chainId;
41
- }
42
- /**
43
- * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
44
- * @param other other token to compare
45
- */
46
- equals(other) {
47
- if (this === other)
48
- return true;
49
- return (this.chainId == other?.chainId &&
50
- this.address.toLowerCase() == other?.address?.toLowerCase());
51
- }
52
- /**
53
- * Returns the currency object that this token represents
54
- */
55
- currency() {
56
- return this;
57
- }
58
- type() {
59
- return TokenType.FUNGIBLE_TOKEN;
60
- }
61
- identifier() {
62
- return `${this.chainId}+${this.address.toLowerCase()}`;
63
- }
64
- }
@@ -1,36 +0,0 @@
1
- import JSBI from "jsbi";
2
- import { Fraction, BigintIsh, Rounding } from "@uniswap/sdk-core";
3
- import { FungibleToken } from "./fungible_token.js";
4
- import { CurrencyAmount } from "./currency_amount.js";
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
- toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
34
- toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
35
- toExact(format?: object): string;
36
- }
@@ -1,95 +0,0 @@
1
- import invariant from "tiny-invariant";
2
- import JSBI from "jsbi";
3
- import { Fraction, Rounding, MaxUint256 } from "@uniswap/sdk-core";
4
- import { FungibleToken } from "./fungible_token.js";
5
- import { CurrencyAmount } from "./currency_amount.js";
6
- import { Big } from "../../constants.js";
7
- // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
8
- // because we have a need to represent a currency amount that is not a fungible token amount.
9
- export class FungibleTokenAmount extends Fraction {
10
- /**
11
- * Returns a new fungibleToken amount instance from the unitless amount of token, i.e. the raw amount
12
- * @param fungibleToken the fungibleToken in the amount
13
- * @param rawAmount the raw token or ether amount
14
- */
15
- static fromRawAmount(fungibleToken, rawAmount, amountInFiatCurrency) {
16
- return new FungibleTokenAmount(fungibleToken, rawAmount, undefined, amountInFiatCurrency);
17
- }
18
- /**
19
- * Construct a fungibleToken amount with a denominator that is not equal to 1
20
- * @param fungibleToken the fungibleToken
21
- * @param numerator the numerator of the fractional token amount
22
- * @param denominator the denominator of the fractional token amount
23
- */
24
- static fromFractionalAmount(fungibleToken, numerator, denominator, amountInFiatCurrency) {
25
- return new FungibleTokenAmount(fungibleToken, numerator, denominator, amountInFiatCurrency);
26
- }
27
- static toFungibleTokenAmount(amount) {
28
- if (!amount) {
29
- return undefined;
30
- }
31
- const amountInFiatCurrency = CurrencyAmount.toCurrencyAmount(amount.amountInFiatCurrency);
32
- return FungibleTokenAmount.fromRawAmount(FungibleToken.toFungibleToken(amount.token), amount.value, amountInFiatCurrency);
33
- }
34
- constructor(fungibleToken, numerator, denominator, amountInFiatCurrency) {
35
- super(numerator.toString(), denominator?.toString());
36
- invariant(JSBI.lessThanOrEqual(this.quotient, MaxUint256), "AMOUNT"); // TODO(imti): fix this
37
- this.token = fungibleToken;
38
- this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(fungibleToken.decimals));
39
- this.amountInFiatCurrency = amountInFiatCurrency;
40
- }
41
- equals(other) {
42
- return (this.token.equals(other.token) &&
43
- this.toRawAmount() == other.toRawAmount());
44
- }
45
- add(other) {
46
- invariant(this.token.equals(other.token), "FUNGIBLE_TOKEN");
47
- const added = super.add(other);
48
- return FungibleTokenAmount.fromFractionalAmount(this.token, added.numerator, added.denominator);
49
- }
50
- subtract(other) {
51
- invariant(this.token.equals(other.token), "FUNGIBLE_TOKEN");
52
- const subtracted = super.subtract(other);
53
- return FungibleTokenAmount.fromFractionalAmount(this.token, subtracted.numerator, subtracted.denominator);
54
- }
55
- multiply(other) {
56
- const multiplied = super.multiply(other);
57
- return FungibleTokenAmount.fromFractionalAmount(this.token, multiplied.numerator, multiplied.denominator);
58
- }
59
- divide(other) {
60
- const divided = super.divide(other);
61
- return FungibleTokenAmount.fromFractionalAmount(this.token, divided.numerator, divided.denominator);
62
- }
63
- greaterThanOrEqual(other) {
64
- return this.greaterThan(other) || this.equals(other);
65
- }
66
- toRawAmount() {
67
- return BigInt(this.quotient.toString());
68
- }
69
- fiatValue() {
70
- return this.amountInFiatCurrency;
71
- }
72
- toCurrencyValue(price) {
73
- const fraction = price.multiply(this);
74
- const denominator = JSBI.multiply(fraction.denominator, this.decimalScale);
75
- this.amountInFiatCurrency = CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
76
- return this.amountInFiatCurrency;
77
- }
78
- toSignificant(significantDigits = 6, format, rounding = Rounding.ROUND_DOWN) {
79
- return super
80
- .divide(this.decimalScale)
81
- .toSignificant(significantDigits, format, rounding);
82
- }
83
- toFixed(decimalPlaces = this.token.decimals, format, rounding = Rounding.ROUND_DOWN) {
84
- invariant(decimalPlaces <= this.token.decimals, "DECIMALS");
85
- return super
86
- .divide(this.decimalScale)
87
- .toFixed(decimalPlaces, format, rounding);
88
- }
89
- toExact(format = { groupSeparator: "" }) {
90
- Big.DP = this.token.decimals;
91
- return new Big(this.quotient.toString())
92
- .div(this.decimalScale.toString())
93
- .toFormat(format);
94
- }
95
- }
@@ -1,39 +0,0 @@
1
- import { Asset } from "./asset.js";
2
- import { TokenType } from "../../enums.js";
3
- /**
4
- * Represents an ERC721 token with a unique address and some metadata.
5
- */
6
- export declare class NonFungibleToken extends Asset {
7
- readonly isNative: false;
8
- readonly isToken: true;
9
- /**
10
- * The contract address on the chain on which this token lives
11
- */
12
- readonly address: string;
13
- /**
14
- * The chain ID on which this token resides
15
- */
16
- readonly chainId: bigint;
17
- readonly url?: string;
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 symbol {@link Currency#symbol}
22
- * @param name {@link Currency#name}
23
- * @param url The URL of the token's metadata
24
- * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
25
- */
26
- constructor(chainId: bigint, address: string, symbol: string, name: string, url?: string, bypassChecksum?: boolean, coinGeckoId?: string);
27
- static toNonFungibleToken(nft?: any): NonFungibleToken;
28
- /**
29
- * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
30
- * @param other other token to compare
31
- */
32
- equals(other: NonFungibleToken): boolean;
33
- /**
34
- * Returns the asset representation of this currency
35
- */
36
- asset(): Asset;
37
- type(): TokenType;
38
- identifier(): string;
39
- }
@@ -1,61 +0,0 @@
1
- import { Asset } from "./asset.js";
2
- import { checkValidAddress, validateAndParseAddress, } from "../../utils/validateAndParseAddress.js";
3
- import { TokenType } from "../../enums.js";
4
- /**
5
- * Represents an ERC721 token with a unique address and some metadata.
6
- */
7
- export class NonFungibleToken extends Asset {
8
- /**
9
- * @param chainId The chain ID on which this token resides
10
- * @param address The contract address on the chain on which this token lives
11
- * @param symbol {@link Currency#symbol}
12
- * @param name {@link Currency#name}
13
- * @param url The URL of the token's metadata
14
- * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
15
- */
16
- constructor(chainId, address, symbol, name, url, bypassChecksum, coinGeckoId) {
17
- // TODO(felix): add this back
18
- // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
19
- super(symbol, name, coinGeckoId);
20
- this.isNative = false;
21
- this.isToken = true;
22
- if (bypassChecksum) {
23
- this.address = checkValidAddress(address)?.toLowerCase();
24
- }
25
- else {
26
- this.address = validateAndParseAddress(address)?.toLowerCase();
27
- }
28
- this.chainId = chainId;
29
- this.url = url;
30
- }
31
- static toNonFungibleToken(nft) {
32
- if (!nft) {
33
- return undefined;
34
- }
35
- const asset = Asset.toAsset(nft.asset);
36
- return new NonFungibleToken(nft.chainId, nft.address, asset.symbol, asset.name, nft.url);
37
- }
38
- /**
39
- * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
40
- * @param other other token to compare
41
- */
42
- equals(other) {
43
- // short circuit on reference equality
44
- if (this === other)
45
- return true;
46
- return (this.chainId === other.chainId &&
47
- this.address === other.address.toLowerCase());
48
- }
49
- /**
50
- * Returns the asset representation of this currency
51
- */
52
- asset() {
53
- return this;
54
- }
55
- type() {
56
- return TokenType.NON_FUNGIBLE_TOKEN;
57
- }
58
- identifier() {
59
- return `${this.chainId}+${this.address.toLowerCase()}`;
60
- }
61
- }
@@ -1,41 +0,0 @@
1
- import { Currency } from "./currency.js";
2
- import { TokenType } from "../../enums.js";
3
- /**
4
- * Represents an ERC1155 token with a unique address and some metadata.
5
- */
6
- export declare class SemiFungibleToken extends Currency {
7
- readonly isNative: false;
8
- readonly isToken: true;
9
- /**
10
- * The contract address on the chain on which this token lives
11
- */
12
- readonly address: string;
13
- /**
14
- * The chain ID on which this token resides
15
- */
16
- readonly chainId: bigint;
17
- readonly url?: string;
18
- /**
19
- *
20
- * @param chainId The chain ID on which this token resides
21
- * @param address The contract address on the chain on which this token lives
22
- * @param decimals {@link Currency#decimals}
23
- * @param symbol {@link Currency#symbol}
24
- * @param name {@link Currency#name}
25
- * @param url The URL of the token's metadata
26
- * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
27
- */
28
- constructor(chainId: bigint, address: string, decimals: number, symbol: string, name: string, url?: string, bypassChecksum?: boolean, coinGeckoId?: string);
29
- static toSemiFungibleToken(sft?: any): SemiFungibleToken;
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: SemiFungibleToken): boolean;
35
- /**
36
- * Returns the currency object that this token represents
37
- */
38
- currency(): Currency;
39
- type(): TokenType;
40
- identifier(): string;
41
- }
@@ -1,63 +0,0 @@
1
- import { Currency } from "./currency.js";
2
- import { checkValidAddress, validateAndParseAddress, } from "../../utils/validateAndParseAddress.js";
3
- import { TokenType } from "../../enums.js";
4
- /**
5
- * Represents an ERC1155 token with a unique address and some metadata.
6
- */
7
- export class SemiFungibleToken extends Currency {
8
- /**
9
- *
10
- * @param chainId The chain ID on which this token resides
11
- * @param address The contract address on the chain on which this token lives
12
- * @param decimals {@link Currency#decimals}
13
- * @param symbol {@link Currency#symbol}
14
- * @param name {@link Currency#name}
15
- * @param url The URL of the token's metadata
16
- * @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
17
- */
18
- constructor(chainId, address, decimals, symbol, name, url, bypassChecksum, coinGeckoId) {
19
- // TODO(felix): add this back
20
- // invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
21
- super(decimals, symbol, name, url, false, true, coinGeckoId);
22
- this.isNative = false;
23
- this.isToken = true;
24
- if (bypassChecksum) {
25
- this.address = checkValidAddress(address)?.toLowerCase();
26
- }
27
- else {
28
- this.address = validateAndParseAddress(address)?.toLowerCase();
29
- }
30
- this.chainId = chainId;
31
- this.url = url;
32
- }
33
- static toSemiFungibleToken(sft) {
34
- if (!sft) {
35
- return undefined;
36
- }
37
- const currency = Currency.toCurrency(sft.currency);
38
- return new SemiFungibleToken(sft.chainId, sft.address, currency.decimals, currency.symbol, currency.name, sft.url);
39
- }
40
- /**
41
- * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
42
- * @param other other token to compare
43
- */
44
- equals(other) {
45
- // short circuit on reference equality
46
- if (this === other)
47
- return true;
48
- return (this.chainId === other.chainId &&
49
- this.address === other.address.toLowerCase());
50
- }
51
- /**
52
- * Returns the currency object that this token represents
53
- */
54
- currency() {
55
- return this;
56
- }
57
- type() {
58
- return TokenType.SEMI_FUNGIBLE_TOKEN;
59
- }
60
- identifier() {
61
- return `${this.chainId}+${this.address.toLowerCase()}`;
62
- }
63
- }
@@ -1,8 +0,0 @@
1
- import { LIBRARY_TYPE } from "../enums.js";
2
- export declare class LibraryRequest {
3
- readonly library: LIBRARY_TYPE;
4
- readonly client?: any;
5
- readonly provider?: any;
6
- constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
7
- sendRequest(method: string, params: any[]): Promise<any>;
8
- }
@@ -1,30 +0,0 @@
1
- import { LIBRARY_TYPE } from "../enums.js";
2
- import invariant from "tiny-invariant";
3
- export class LibraryRequest {
4
- constructor(library, client, provider) {
5
- if (library == LIBRARY_TYPE.VIEM) {
6
- invariant(client, "CLIENT");
7
- invariant(!provider, "PROVIDER");
8
- this.client = client;
9
- }
10
- else if (library == LIBRARY_TYPE.ETHERS) {
11
- invariant(provider, "PROVIDER");
12
- invariant(!client, "CLIENT");
13
- this.provider = provider;
14
- }
15
- else {
16
- invariant(false, "LIBRARY");
17
- }
18
- this.library = library;
19
- this.client = client;
20
- this.provider = provider;
21
- }
22
- sendRequest(method, params) {
23
- if (this.library == LIBRARY_TYPE.VIEM) {
24
- return this.client.request({ method, params });
25
- }
26
- else if (this.library == LIBRARY_TYPE.ETHERS) {
27
- return this.provider.send(method, params);
28
- }
29
- }
30
- }
@@ -1,22 +0,0 @@
1
- import { FungibleToken } from "./financial/fungible_token.js";
2
- import { FungibleTokenAmount } from "./financial/fungible_token_amount.js";
3
- import { NonFungibleToken } from "./financial/non_fungible_token.js";
4
- import { SemiFungibleToken } from "./financial/semi_fungible_token.js";
5
- export declare class State {
6
- private readonly fungibleTokens;
7
- private readonly nonFungibleTokens;
8
- private readonly semiFungibleTokens;
9
- constructor(fungibleTokens: FungibleTokenAmount[], nonFungibleTokens: NonFungibleToken[], semiFungibleTokens: SemiFungibleToken[]);
10
- static fromFungibleTokenAmounts(fungibleTokenAmounts: FungibleTokenAmount[]): State;
11
- static fromTokenAndAmount(token?: FungibleToken, amount?: bigint): State;
12
- getFungibleTokens(): FungibleTokenAmount[];
13
- getNonFungibleTokens(): NonFungibleToken[];
14
- getSemiFungibleTokens(): SemiFungibleToken[];
15
- addTokens(fungibleTokens: FungibleTokenAmount[]): State;
16
- addState(other: State): State;
17
- deductState(other: State): State;
18
- equals(other?: State): boolean;
19
- addStates(states: State[]): State;
20
- static mergeStates(states: State[]): State;
21
- static toState(state: any): State;
22
- }
@@ -1,102 +0,0 @@
1
- import { FungibleTokenAmount } from "./financial/fungible_token_amount.js";
2
- import { NonFungibleToken } from "./financial/non_fungible_token.js";
3
- import { SemiFungibleToken } from "./financial/semi_fungible_token.js";
4
- export class State {
5
- constructor(fungibleTokens, nonFungibleTokens, semiFungibleTokens) {
6
- this.fungibleTokens = fungibleTokens.reduce((acc, amount) => {
7
- acc.set(amount.token.identifier(), amount);
8
- return acc;
9
- }, new Map());
10
- this.nonFungibleTokens = nonFungibleTokens.reduce((acc, token) => {
11
- acc.set(token.identifier(), token);
12
- return acc;
13
- }, new Map());
14
- this.semiFungibleTokens = semiFungibleTokens.reduce((acc, token) => {
15
- acc.set(token.identifier(), token);
16
- return acc;
17
- }, new Map());
18
- }
19
- static fromFungibleTokenAmounts(fungibleTokenAmounts) {
20
- return new State(fungibleTokenAmounts, [], []);
21
- }
22
- static fromTokenAndAmount(token, amount) {
23
- if (!token || !amount) {
24
- return undefined;
25
- }
26
- const fungibleTokenAmount = FungibleTokenAmount.fromRawAmount(token, amount);
27
- return State.fromFungibleTokenAmounts([fungibleTokenAmount]);
28
- }
29
- getFungibleTokens() {
30
- return Array.from(this.fungibleTokens.values());
31
- }
32
- getNonFungibleTokens() {
33
- return Array.from(this.nonFungibleTokens.values());
34
- }
35
- getSemiFungibleTokens() {
36
- return Array.from(this.semiFungibleTokens.values());
37
- }
38
- addTokens(fungibleTokens) {
39
- fungibleTokens.forEach((amount) => {
40
- const identifier = amount.token.identifier();
41
- const currentAmount = this.fungibleTokens.get(identifier);
42
- if (currentAmount) {
43
- this.fungibleTokens.set(identifier, currentAmount.add(amount));
44
- }
45
- else {
46
- this.fungibleTokens.set(identifier, amount);
47
- }
48
- });
49
- return this;
50
- }
51
- addState(other) {
52
- other?.fungibleTokens?.forEach((amount) => {
53
- const identifier = amount.token.identifier();
54
- const currentAmount = this.fungibleTokens.get(identifier);
55
- if (currentAmount) {
56
- this.fungibleTokens.set(identifier, currentAmount.add(amount));
57
- }
58
- else {
59
- this.fungibleTokens.set(identifier, amount);
60
- }
61
- });
62
- return this;
63
- }
64
- deductState(other) {
65
- other.fungibleTokens.forEach((amount) => {
66
- const identifier = amount.token.identifier();
67
- const currentAmount = this.fungibleTokens.get(identifier);
68
- if (currentAmount?.toRawAmount() > amount?.toRawAmount()) {
69
- this.fungibleTokens.set(identifier, currentAmount.subtract(amount));
70
- }
71
- else if (currentAmount) {
72
- this.fungibleTokens.delete(identifier);
73
- }
74
- });
75
- return this;
76
- }
77
- equals(other) {
78
- if (!other) {
79
- return false;
80
- }
81
- return (this.fungibleTokens.size == other.fungibleTokens.size &&
82
- Array.from(this.fungibleTokens.entries()).every(([key, value]) => {
83
- const otherValue = other.fungibleTokens.get(key);
84
- return otherValue && value.equals(otherValue);
85
- }));
86
- }
87
- addStates(states) {
88
- states.forEach((state) => this.addState(state));
89
- return this;
90
- }
91
- static mergeStates(states) {
92
- return states.reduce((acc, state) => acc.addState(state), new State([], [], []));
93
- }
94
- static toState(state) {
95
- if (!state)
96
- return undefined;
97
- const fungibleTokenAmounts = state.fungibleTokenAmounts.map((ft) => FungibleTokenAmount.toFungibleTokenAmount(ft));
98
- const nonFungibleTokenAmounts = state.nonFungibleTokenAmounts.map((nft) => NonFungibleToken.toNonFungibleToken(nft));
99
- const semiFungibleTokenAmounts = state.semiFungibleTokenAmounts.map((sft) => SemiFungibleToken.toSemiFungibleToken(sft));
100
- return new State(fungibleTokenAmounts, nonFungibleTokenAmounts, semiFungibleTokenAmounts);
101
- }
102
- }