@orb-labs/orby-core 0.0.13 → 0.0.15
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/CHANGELOG.md +9 -0
- package/dist/actions/operation.d.ts +1 -1
- package/dist/actions/operation.js +5 -3
- package/dist/cjs/actions/account_cluster.d.ts +32 -0
- package/dist/cjs/actions/account_cluster.js +211 -0
- package/dist/cjs/actions/admin.d.ts +17 -0
- package/dist/cjs/actions/admin.js +43 -0
- package/dist/cjs/actions/application.d.ts +6 -0
- package/dist/cjs/actions/application.js +20 -0
- package/dist/cjs/actions/blockchain.d.ts +16 -0
- package/dist/cjs/actions/blockchain.js +39 -0
- package/dist/cjs/actions/instance.d.ts +15 -0
- package/dist/cjs/actions/instance.js +98 -0
- package/dist/cjs/actions/operation.d.ts +99 -0
- package/dist/cjs/actions/operation.js +345 -0
- package/dist/cjs/actions/token.d.ts +15 -0
- package/dist/cjs/actions/token.js +50 -0
- package/dist/cjs/constants.d.ts +14 -0
- package/dist/cjs/constants.js +139 -0
- package/dist/cjs/entities/account.d.ts +14 -0
- package/dist/cjs/entities/account.js +49 -0
- package/dist/cjs/entities/financial/account_balance.d.ts +12 -0
- package/dist/cjs/entities/financial/account_balance.js +35 -0
- package/dist/cjs/entities/financial/asset.d.ts +31 -0
- package/dist/cjs/entities/financial/asset.js +42 -0
- package/dist/cjs/entities/financial/currency.d.ts +41 -0
- package/dist/cjs/entities/financial/currency.js +56 -0
- package/dist/cjs/entities/financial/currency_amount.d.ts +34 -0
- package/dist/cjs/entities/financial/currency_amount.js +99 -0
- package/dist/cjs/entities/financial/fungible_token.d.ts +41 -0
- package/dist/cjs/entities/financial/fungible_token.js +68 -0
- package/dist/cjs/entities/financial/fungible_token_amount.d.ts +36 -0
- package/dist/cjs/entities/financial/fungible_token_amount.js +102 -0
- package/dist/cjs/entities/financial/non_fungible_token.d.ts +39 -0
- package/dist/cjs/entities/financial/non_fungible_token.js +65 -0
- package/dist/cjs/entities/financial/semi_fungible_token.d.ts +41 -0
- package/dist/cjs/entities/financial/semi_fungible_token.js +67 -0
- package/dist/cjs/entities/library_request.d.ts +8 -0
- package/dist/cjs/entities/library_request.js +37 -0
- package/dist/cjs/entities/state.d.ts +22 -0
- package/dist/cjs/entities/state.js +106 -0
- package/dist/cjs/enums.d.ts +116 -0
- package/dist/cjs/enums.js +138 -0
- package/dist/cjs/index.d.ts +29 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/interfaces/account_cluster.d.ts +30 -0
- package/dist/cjs/interfaces/account_cluster.js +2 -0
- package/dist/cjs/interfaces/admin.d.ts +14 -0
- package/dist/cjs/interfaces/admin.js +2 -0
- package/dist/cjs/interfaces/application.d.ts +3 -0
- package/dist/cjs/interfaces/application.js +2 -0
- package/dist/cjs/interfaces/blockchain.d.ts +13 -0
- package/dist/cjs/interfaces/blockchain.js +2 -0
- package/dist/cjs/interfaces/instance.d.ts +12 -0
- package/dist/cjs/interfaces/instance.js +2 -0
- package/dist/cjs/interfaces/operation.d.ts +97 -0
- package/dist/cjs/interfaces/operation.js +2 -0
- package/dist/cjs/interfaces/orby.d.ts +9 -0
- package/dist/cjs/interfaces/orby.js +2 -0
- package/dist/cjs/interfaces/token.d.ts +12 -0
- package/dist/cjs/interfaces/token.js +2 -0
- package/dist/cjs/types.d.ts +152 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/action_helpers.d.ts +22 -0
- package/dist/cjs/utils/action_helpers.js +274 -0
- package/dist/cjs/utils/utils.d.ts +10 -0
- package/dist/cjs/utils/utils.js +79 -0
- package/dist/cjs/utils/validateAndParseAddress.d.ts +10 -0
- package/dist/cjs/utils/validateAndParseAddress.js +29 -0
- package/dist/esm/actions/account_cluster.d.ts +32 -0
- package/dist/esm/actions/account_cluster.js +207 -0
- package/dist/esm/actions/admin.d.ts +17 -0
- package/dist/esm/actions/admin.js +39 -0
- package/dist/esm/actions/application.d.ts +6 -0
- package/dist/esm/actions/application.js +16 -0
- package/dist/esm/actions/blockchain.d.ts +16 -0
- package/dist/esm/actions/blockchain.js +35 -0
- package/dist/esm/actions/instance.d.ts +15 -0
- package/dist/esm/actions/instance.js +94 -0
- package/dist/esm/actions/operation.d.ts +99 -0
- package/dist/esm/actions/operation.js +341 -0
- package/dist/esm/actions/token.d.ts +15 -0
- package/dist/esm/actions/token.js +46 -0
- package/dist/esm/constants.d.ts +14 -0
- package/dist/esm/constants.js +133 -0
- package/dist/esm/entities/account.d.ts +14 -0
- package/dist/esm/entities/account.js +45 -0
- package/dist/esm/entities/financial/account_balance.d.ts +12 -0
- package/dist/esm/entities/financial/account_balance.js +31 -0
- package/dist/esm/entities/financial/asset.d.ts +31 -0
- package/dist/esm/entities/financial/asset.js +38 -0
- package/dist/esm/entities/financial/currency.d.ts +41 -0
- package/dist/esm/entities/financial/currency.js +49 -0
- package/dist/esm/entities/financial/currency_amount.d.ts +34 -0
- package/dist/esm/entities/financial/currency_amount.js +92 -0
- package/dist/esm/entities/financial/fungible_token.d.ts +41 -0
- package/dist/esm/entities/financial/fungible_token.js +64 -0
- package/dist/esm/entities/financial/fungible_token_amount.d.ts +36 -0
- package/dist/esm/entities/financial/fungible_token_amount.js +95 -0
- package/dist/esm/entities/financial/non_fungible_token.d.ts +39 -0
- package/dist/esm/entities/financial/non_fungible_token.js +61 -0
- package/dist/esm/entities/financial/semi_fungible_token.d.ts +41 -0
- package/dist/esm/entities/financial/semi_fungible_token.js +63 -0
- package/dist/esm/entities/library_request.d.ts +8 -0
- package/dist/esm/entities/library_request.js +30 -0
- package/dist/esm/entities/state.d.ts +22 -0
- package/dist/esm/entities/state.js +102 -0
- package/dist/esm/enums.d.ts +116 -0
- package/dist/esm/enums.js +135 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/index.js +33 -0
- package/dist/esm/interfaces/account_cluster.d.ts +30 -0
- package/dist/esm/interfaces/account_cluster.js +1 -0
- package/dist/esm/interfaces/admin.d.ts +14 -0
- package/dist/esm/interfaces/admin.js +1 -0
- package/dist/esm/interfaces/application.d.ts +3 -0
- package/dist/esm/interfaces/application.js +1 -0
- package/dist/esm/interfaces/blockchain.d.ts +13 -0
- package/dist/esm/interfaces/blockchain.js +1 -0
- package/dist/esm/interfaces/instance.d.ts +12 -0
- package/dist/esm/interfaces/instance.js +1 -0
- package/dist/esm/interfaces/operation.d.ts +97 -0
- package/dist/esm/interfaces/operation.js +1 -0
- package/dist/esm/interfaces/orby.d.ts +9 -0
- package/dist/esm/interfaces/orby.js +1 -0
- package/dist/esm/interfaces/token.d.ts +12 -0
- package/dist/esm/interfaces/token.js +1 -0
- package/dist/esm/types.d.ts +152 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/action_helpers.d.ts +22 -0
- package/dist/esm/utils/action_helpers.js +250 -0
- package/dist/esm/utils/utils.d.ts +10 -0
- package/dist/esm/utils/utils.js +70 -0
- package/dist/esm/utils/validateAndParseAddress.d.ts +10 -0
- package/dist/esm/utils/validateAndParseAddress.js +25 -0
- package/dist/interfaces/operation.d.ts +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/action_helpers.js +1 -1
- package/package.json +16 -7
@@ -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.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
|
+
}
|
@@ -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_js_1 = require("./asset.js");
|
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_js_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 ?? false;
|
28
|
+
this.isToken = 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,34 @@
|
|
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
|
+
}
|
@@ -0,0 +1,99 @@
|
|
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_js_1 = require("./currency.js");
|
11
|
+
const constants_js_1 = require("../../constants.js");
|
12
|
+
// This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
|
13
|
+
// because we have a need to represent a currency amount that is not a fungible token amount.
|
14
|
+
class CurrencyAmount extends sdk_core_1.Fraction {
|
15
|
+
/**
|
16
|
+
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
17
|
+
* @param currency the currency in the amount
|
18
|
+
* @param rawAmount the raw token or ether amount
|
19
|
+
*/
|
20
|
+
static fromRawAmount(currency, rawAmount) {
|
21
|
+
return new CurrencyAmount(currency, rawAmount);
|
22
|
+
}
|
23
|
+
static toCurrencyAmount(amount) {
|
24
|
+
if (!amount) {
|
25
|
+
return undefined;
|
26
|
+
}
|
27
|
+
const currency = currency_js_1.Currency.toCurrency(amount.currency);
|
28
|
+
return CurrencyAmount.fromRawAmount(currency, amount.value);
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Construct a currency amount with a denominator that is not equal to 1
|
32
|
+
* @param currency the currency
|
33
|
+
* @param numerator the numerator of the fractional token amount
|
34
|
+
* @param denominator the denominator of the fractional token amount
|
35
|
+
*/
|
36
|
+
static fromFractionalAmount(currency, numerator, denominator) {
|
37
|
+
return new CurrencyAmount(currency, numerator, denominator);
|
38
|
+
}
|
39
|
+
constructor(currency, numerator, denominator) {
|
40
|
+
super(numerator.toString(), denominator?.toString());
|
41
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.lessThanOrEqual(this.quotient, sdk_core_1.MaxUint256), "AMOUNT");
|
42
|
+
this.currency = currency;
|
43
|
+
this.decimalScale = jsbi_1.default.exponentiate(jsbi_1.default.BigInt(10), jsbi_1.default.BigInt(currency.decimals));
|
44
|
+
}
|
45
|
+
add(other) {
|
46
|
+
if (!other) {
|
47
|
+
return this;
|
48
|
+
}
|
49
|
+
(0, tiny_invariant_1.default)(this.currency.equals(other.currency), "CURRENCY");
|
50
|
+
const added = super.add(other);
|
51
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
|
52
|
+
}
|
53
|
+
subtract(other) {
|
54
|
+
(0, tiny_invariant_1.default)(this.currency.equals(other.currency), "CURRENCY");
|
55
|
+
const subtracted = super.subtract(other);
|
56
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
|
57
|
+
}
|
58
|
+
multiply(other) {
|
59
|
+
const multiplied = super.multiply(other);
|
60
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
|
61
|
+
}
|
62
|
+
divide(other) {
|
63
|
+
const divided = super.divide(other);
|
64
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
|
65
|
+
}
|
66
|
+
cloneWithAmount(amount) {
|
67
|
+
return CurrencyAmount.fromRawAmount(this.currency, amount);
|
68
|
+
}
|
69
|
+
toRawAmount() {
|
70
|
+
return BigInt(this.quotient.toString());
|
71
|
+
}
|
72
|
+
toCurrencyValue(price) {
|
73
|
+
const fraction = price.multiply(this);
|
74
|
+
const denominator = jsbi_1.default.multiply(fraction.denominator, this.decimalScale);
|
75
|
+
this.amountInFiatCurrency = CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
|
76
|
+
return this.amountInFiatCurrency;
|
77
|
+
}
|
78
|
+
fiatValue() {
|
79
|
+
return this.amountInFiatCurrency;
|
80
|
+
}
|
81
|
+
toSignificant(significantDigits = 6, format, rounding = sdk_core_1.Rounding.ROUND_DOWN) {
|
82
|
+
return super
|
83
|
+
.divide(this.decimalScale)
|
84
|
+
.toSignificant(significantDigits, format, rounding);
|
85
|
+
}
|
86
|
+
toFixed(decimalPlaces = this.currency.decimals, format, rounding = sdk_core_1.Rounding.ROUND_DOWN) {
|
87
|
+
(0, tiny_invariant_1.default)(decimalPlaces <= this.currency.decimals, "DECIMALS");
|
88
|
+
return super
|
89
|
+
.divide(this.decimalScale)
|
90
|
+
.toFixed(decimalPlaces, format, rounding);
|
91
|
+
}
|
92
|
+
toExact(format = { groupSeparator: "" }) {
|
93
|
+
constants_js_1.Big.DP = this.currency.decimals;
|
94
|
+
return new constants_js_1.Big(this.quotient.toString())
|
95
|
+
.div(this.decimalScale.toString())
|
96
|
+
.toFormat(format);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
exports.CurrencyAmount = CurrencyAmount;
|
@@ -0,0 +1,41 @@
|
|
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
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FungibleToken = void 0;
|
4
|
+
const currency_js_1 = require("./currency.js");
|
5
|
+
const validateAndParseAddress_js_1 = require("../../utils/validateAndParseAddress.js");
|
6
|
+
const enums_js_1 = require("../../enums.js");
|
7
|
+
/**
|
8
|
+
* Represents an ERC20 token with a unique address and some metadata.
|
9
|
+
*/
|
10
|
+
class FungibleToken extends currency_js_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, logoUrl) {
|
27
|
+
// TODO(felix): add this back
|
28
|
+
// invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
|
29
|
+
super(decimals, symbol, name, logoUrl, isNative, true, coinGeckoId);
|
30
|
+
this.isToken = true;
|
31
|
+
// TODO(felix): bypassChecksum is a little confusing since when bypassChecksum is true, we still validate the address
|
32
|
+
// bypassChecksum is derived from the isNative parameter, so we should remove it and just check if isNative here
|
33
|
+
if (bypassChecksum) {
|
34
|
+
this.address = (0, validateAndParseAddress_js_1.checkValidAddress)(address)?.toLowerCase();
|
35
|
+
}
|
36
|
+
else if (!isNative) {
|
37
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndParseAddress)(address)?.toLowerCase();
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
this.address = address;
|
41
|
+
}
|
42
|
+
this.isNative = isNative || false;
|
43
|
+
this.chainId = chainId;
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
47
|
+
* @param other other token to compare
|
48
|
+
*/
|
49
|
+
equals(other) {
|
50
|
+
if (this === other)
|
51
|
+
return true;
|
52
|
+
return (this.chainId == other?.chainId &&
|
53
|
+
this.address.toLowerCase() == other?.address?.toLowerCase());
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* Returns the currency object that this token represents
|
57
|
+
*/
|
58
|
+
currency() {
|
59
|
+
return this;
|
60
|
+
}
|
61
|
+
type() {
|
62
|
+
return enums_js_1.TokenType.FUNGIBLE_TOKEN;
|
63
|
+
}
|
64
|
+
identifier() {
|
65
|
+
return `${this.chainId}+${this.address.toLowerCase()}`;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
exports.FungibleToken = FungibleToken;
|
@@ -0,0 +1,36 @@
|
|
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
|
+
}
|
@@ -0,0 +1,102 @@
|
|
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.FungibleTokenAmount = 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 fungible_token_js_1 = require("./fungible_token.js");
|
11
|
+
const currency_amount_js_1 = require("./currency_amount.js");
|
12
|
+
const constants_js_1 = require("../../constants.js");
|
13
|
+
// This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
|
14
|
+
// because we have a need to represent a currency amount that is not a fungible token amount.
|
15
|
+
class FungibleTokenAmount extends sdk_core_1.Fraction {
|
16
|
+
/**
|
17
|
+
* Returns a new fungibleToken amount instance from the unitless amount of token, i.e. the raw amount
|
18
|
+
* @param fungibleToken the fungibleToken in the amount
|
19
|
+
* @param rawAmount the raw token or ether amount
|
20
|
+
*/
|
21
|
+
static fromRawAmount(fungibleToken, rawAmount, amountInFiatCurrency) {
|
22
|
+
return new FungibleTokenAmount(fungibleToken, rawAmount, undefined, amountInFiatCurrency);
|
23
|
+
}
|
24
|
+
/**
|
25
|
+
* Construct a fungibleToken amount with a denominator that is not equal to 1
|
26
|
+
* @param fungibleToken the fungibleToken
|
27
|
+
* @param numerator the numerator of the fractional token amount
|
28
|
+
* @param denominator the denominator of the fractional token amount
|
29
|
+
*/
|
30
|
+
static fromFractionalAmount(fungibleToken, numerator, denominator, amountInFiatCurrency) {
|
31
|
+
return new FungibleTokenAmount(fungibleToken, numerator, denominator, amountInFiatCurrency);
|
32
|
+
}
|
33
|
+
static toFungibleTokenAmount(amount) {
|
34
|
+
if (!amount) {
|
35
|
+
return undefined;
|
36
|
+
}
|
37
|
+
const amountInFiatCurrency = currency_amount_js_1.CurrencyAmount.toCurrencyAmount(amount.amountInFiatCurrency);
|
38
|
+
return FungibleTokenAmount.fromRawAmount(fungible_token_js_1.FungibleToken.toFungibleToken(amount.token), amount.value, amountInFiatCurrency);
|
39
|
+
}
|
40
|
+
constructor(fungibleToken, numerator, denominator, amountInFiatCurrency) {
|
41
|
+
super(numerator.toString(), denominator?.toString());
|
42
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.lessThanOrEqual(this.quotient, sdk_core_1.MaxUint256), "AMOUNT"); // TODO(imti): fix this
|
43
|
+
this.token = fungibleToken;
|
44
|
+
this.decimalScale = jsbi_1.default.exponentiate(jsbi_1.default.BigInt(10), jsbi_1.default.BigInt(fungibleToken.decimals));
|
45
|
+
this.amountInFiatCurrency = amountInFiatCurrency;
|
46
|
+
}
|
47
|
+
equals(other) {
|
48
|
+
return (this.token.equals(other.token) &&
|
49
|
+
this.toRawAmount() == other.toRawAmount());
|
50
|
+
}
|
51
|
+
add(other) {
|
52
|
+
(0, tiny_invariant_1.default)(this.token.equals(other.token), "FUNGIBLE_TOKEN");
|
53
|
+
const added = super.add(other);
|
54
|
+
return FungibleTokenAmount.fromFractionalAmount(this.token, added.numerator, added.denominator);
|
55
|
+
}
|
56
|
+
subtract(other) {
|
57
|
+
(0, tiny_invariant_1.default)(this.token.equals(other.token), "FUNGIBLE_TOKEN");
|
58
|
+
const subtracted = super.subtract(other);
|
59
|
+
return FungibleTokenAmount.fromFractionalAmount(this.token, subtracted.numerator, subtracted.denominator);
|
60
|
+
}
|
61
|
+
multiply(other) {
|
62
|
+
const multiplied = super.multiply(other);
|
63
|
+
return FungibleTokenAmount.fromFractionalAmount(this.token, multiplied.numerator, multiplied.denominator);
|
64
|
+
}
|
65
|
+
divide(other) {
|
66
|
+
const divided = super.divide(other);
|
67
|
+
return FungibleTokenAmount.fromFractionalAmount(this.token, divided.numerator, divided.denominator);
|
68
|
+
}
|
69
|
+
greaterThanOrEqual(other) {
|
70
|
+
return this.greaterThan(other) || this.equals(other);
|
71
|
+
}
|
72
|
+
toRawAmount() {
|
73
|
+
return BigInt(this.quotient.toString());
|
74
|
+
}
|
75
|
+
fiatValue() {
|
76
|
+
return this.amountInFiatCurrency;
|
77
|
+
}
|
78
|
+
toCurrencyValue(price) {
|
79
|
+
const fraction = price.multiply(this);
|
80
|
+
const denominator = jsbi_1.default.multiply(fraction.denominator, this.decimalScale);
|
81
|
+
this.amountInFiatCurrency = currency_amount_js_1.CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
|
82
|
+
return this.amountInFiatCurrency;
|
83
|
+
}
|
84
|
+
toSignificant(significantDigits = 6, format, rounding = sdk_core_1.Rounding.ROUND_DOWN) {
|
85
|
+
return super
|
86
|
+
.divide(this.decimalScale)
|
87
|
+
.toSignificant(significantDigits, format, rounding);
|
88
|
+
}
|
89
|
+
toFixed(decimalPlaces = this.token.decimals, format, rounding = sdk_core_1.Rounding.ROUND_DOWN) {
|
90
|
+
(0, tiny_invariant_1.default)(decimalPlaces <= this.token.decimals, "DECIMALS");
|
91
|
+
return super
|
92
|
+
.divide(this.decimalScale)
|
93
|
+
.toFixed(decimalPlaces, format, rounding);
|
94
|
+
}
|
95
|
+
toExact(format = { groupSeparator: "" }) {
|
96
|
+
constants_js_1.Big.DP = this.token.decimals;
|
97
|
+
return new constants_js_1.Big(this.quotient.toString())
|
98
|
+
.div(this.decimalScale.toString())
|
99
|
+
.toFormat(format);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
exports.FungibleTokenAmount = FungibleTokenAmount;
|
@@ -0,0 +1,39 @@
|
|
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
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NonFungibleToken = void 0;
|
4
|
+
const asset_js_1 = require("./asset.js");
|
5
|
+
const validateAndParseAddress_js_1 = require("../../utils/validateAndParseAddress.js");
|
6
|
+
const enums_js_1 = require("../../enums.js");
|
7
|
+
/**
|
8
|
+
* Represents an ERC721 token with a unique address and some metadata.
|
9
|
+
*/
|
10
|
+
class NonFungibleToken extends asset_js_1.Asset {
|
11
|
+
/**
|
12
|
+
* @param chainId The chain ID on which this token resides
|
13
|
+
* @param address The contract address on the chain on which this token lives
|
14
|
+
* @param symbol {@link Currency#symbol}
|
15
|
+
* @param name {@link Currency#name}
|
16
|
+
* @param url The URL of the token's metadata
|
17
|
+
* @param bypassChecksum If true it only checks for length === 42, startsWith 0x and contains only hex characters
|
18
|
+
*/
|
19
|
+
constructor(chainId, address, symbol, name, url, bypassChecksum, coinGeckoId) {
|
20
|
+
// TODO(felix): add this back
|
21
|
+
// invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
|
22
|
+
super(symbol, name, coinGeckoId);
|
23
|
+
this.isNative = false;
|
24
|
+
this.isToken = true;
|
25
|
+
if (bypassChecksum) {
|
26
|
+
this.address = (0, validateAndParseAddress_js_1.checkValidAddress)(address)?.toLowerCase();
|
27
|
+
}
|
28
|
+
else {
|
29
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndParseAddress)(address)?.toLowerCase();
|
30
|
+
}
|
31
|
+
this.chainId = chainId;
|
32
|
+
this.url = url;
|
33
|
+
}
|
34
|
+
static toNonFungibleToken(nft) {
|
35
|
+
if (!nft) {
|
36
|
+
return undefined;
|
37
|
+
}
|
38
|
+
const asset = asset_js_1.Asset.toAsset(nft.asset);
|
39
|
+
return new NonFungibleToken(nft.chainId, nft.address, asset.symbol, asset.name, nft.url);
|
40
|
+
}
|
41
|
+
/**
|
42
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
43
|
+
* @param other other token to compare
|
44
|
+
*/
|
45
|
+
equals(other) {
|
46
|
+
// short circuit on reference equality
|
47
|
+
if (this === other)
|
48
|
+
return true;
|
49
|
+
return (this.chainId === other.chainId &&
|
50
|
+
this.address === other.address.toLowerCase());
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* Returns the asset representation of this currency
|
54
|
+
*/
|
55
|
+
asset() {
|
56
|
+
return this;
|
57
|
+
}
|
58
|
+
type() {
|
59
|
+
return enums_js_1.TokenType.NON_FUNGIBLE_TOKEN;
|
60
|
+
}
|
61
|
+
identifier() {
|
62
|
+
return `${this.chainId}+${this.address.toLowerCase()}`;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
exports.NonFungibleToken = NonFungibleToken;
|