@orb-labs/orby-core 0.0.23 → 0.0.25
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 +10 -0
- package/dist/cjs/actions/account_cluster.d.ts +1 -1
- package/dist/cjs/actions/account_cluster.js +2 -1
- package/dist/cjs/constants.d.ts +5 -4
- package/dist/cjs/constants.js +5 -3
- package/dist/cjs/entities/financial/fungible_token_amount.d.ts +6 -0
- package/dist/cjs/entities/financial/fungible_token_amount.js +14 -0
- package/dist/cjs/entities/library_request.js +14 -11
- package/dist/cjs/enums.d.ts +0 -25
- package/dist/cjs/enums.js +1 -29
- package/dist/cjs/interfaces/account_cluster.d.ts +1 -1
- package/dist/cjs/types.d.ts +4 -0
- package/dist/cjs/utils/utils.d.ts +8 -0
- package/dist/cjs/utils/utils.js +31 -13
- package/dist/esm/actions/account_cluster.d.ts +1 -1
- package/dist/esm/actions/account_cluster.js +2 -1
- package/dist/esm/constants.d.ts +5 -4
- package/dist/esm/constants.js +4 -2
- package/dist/esm/entities/financial/fungible_token_amount.d.ts +6 -0
- package/dist/esm/entities/financial/fungible_token_amount.js +14 -0
- package/dist/esm/entities/library_request.js +15 -12
- package/dist/esm/enums.d.ts +0 -25
- package/dist/esm/enums.js +0 -28
- package/dist/esm/interfaces/account_cluster.d.ts +1 -1
- package/dist/esm/types.d.ts +4 -0
- package/dist/esm/utils/utils.d.ts +8 -0
- package/dist/esm/utils/utils.js +27 -13
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
### Unreleased
|
4
4
|
|
5
|
+
### 0.0.24
|
6
|
+
|
7
|
+
- adding nativeCurrency field to blockchain
|
8
|
+
- exposing currency related util functions
|
9
|
+
|
10
|
+
### 0.0.24
|
11
|
+
|
12
|
+
- fetching blockchain list earlier
|
13
|
+
- remove some util functions that are not needed anymore
|
14
|
+
|
5
15
|
### 0.0.23
|
6
16
|
|
7
17
|
- refactoring how we get the blockchain list
|
@@ -28,5 +28,5 @@ export declare class AccountClusterActions extends LibraryRequest {
|
|
28
28
|
}>;
|
29
29
|
getPortfolioOverview(accountClusterId: string): Promise<FungibleTokenOverview>;
|
30
30
|
getFungibleTokenPortfolio(accountClusterId: string): Promise<StandardizedBalance[]>;
|
31
|
-
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[]): Promise<StandardizedBalance[]>;
|
31
|
+
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[], standardizedTokenIds?: string[]): Promise<StandardizedBalance[]>;
|
32
32
|
}
|
@@ -197,7 +197,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
|
|
197
197
|
}
|
198
198
|
return (0, action_helpers_js_1.extractStandardizedBalances)(fungibleTokenBalances);
|
199
199
|
}
|
200
|
-
async getFungibleTokenBalances(accountClusterId, offset, limit, chainId, tokensToOmit) {
|
200
|
+
async getFungibleTokenBalances(accountClusterId, offset, limit, chainId, tokensToOmit, standardizedTokenIds) {
|
201
201
|
const orbyChainId = await this.getOrbyChainId(chainId);
|
202
202
|
const { fungibleTokenBalances, code, message } = await this.sendRequest("orby_getFungibleTokenBalances", [
|
203
203
|
{
|
@@ -206,6 +206,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
|
|
206
206
|
limit,
|
207
207
|
chainId: orbyChainId,
|
208
208
|
tokensToOmit,
|
209
|
+
standardizedTokenIds,
|
209
210
|
},
|
210
211
|
]);
|
211
212
|
if (code && message) {
|
package/dist/cjs/constants.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
import { Blockchain } from "./enums.js";
|
2
1
|
import { Currency } from "./entities/financial/currency.js";
|
3
2
|
import { ChainConfigs } from "./types.js";
|
4
3
|
export declare const Big: any;
|
5
|
-
export declare const
|
6
|
-
export declare const
|
7
|
-
export declare const
|
4
|
+
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
5
|
+
export declare const ONE_ADDRESS = "0x0000000000000000000000000000000000000001";
|
6
|
+
export declare const TWO_ADDRESS = "0x0000000000000000000000000000000000000002";
|
7
|
+
export declare const NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
8
|
+
export declare const CHAIN_CONFIGS: Record<number, ChainConfigs>;
|
8
9
|
export declare const FIAT_CURRENCY: Currency;
|
package/dist/cjs/constants.js
CHANGED
@@ -3,12 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.FIAT_CURRENCY = exports.
|
6
|
+
exports.FIAT_CURRENCY = exports.CHAIN_CONFIGS = exports.NATIVE_TOKEN_ADDRESS = exports.TWO_ADDRESS = exports.ONE_ADDRESS = exports.ZERO_ADDRESS = exports.Big = void 0;
|
7
7
|
const toformat_1 = __importDefault(require("toformat"));
|
8
8
|
const big_js_1 = __importDefault(require("big.js"));
|
9
9
|
const currency_js_1 = require("./entities/financial/currency.js");
|
10
10
|
exports.Big = (0, toformat_1.default)(big_js_1.default);
|
11
|
-
exports.
|
11
|
+
exports.ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
12
|
+
exports.ONE_ADDRESS = "0x0000000000000000000000000000000000000001";
|
13
|
+
exports.TWO_ADDRESS = "0x0000000000000000000000000000000000000002";
|
14
|
+
exports.NATIVE_TOKEN_ADDRESS = exports.ZERO_ADDRESS;
|
12
15
|
exports.CHAIN_CONFIGS = {};
|
13
|
-
exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = {};
|
14
16
|
exports.FIAT_CURRENCY = new currency_js_1.Currency(6, "USD", "US Dollar", undefined, false, false);
|
@@ -20,6 +20,12 @@ export declare class FungibleTokenAmount extends Fraction {
|
|
20
20
|
*/
|
21
21
|
static fromFractionalAmount(fungibleToken: FungibleToken, numerator: BigintIsh, denominator: BigintIsh, amountInFiatCurrency?: CurrencyAmount): FungibleTokenAmount;
|
22
22
|
static toFungibleTokenAmount(amount?: any): FungibleTokenAmount;
|
23
|
+
/**
|
24
|
+
* Used to calculate the amount of token B that one can get for a given amount of token A.
|
25
|
+
* aPrice is the unit price of token A in fiat currency
|
26
|
+
* bPrice is the unit price of token B in fiat currency
|
27
|
+
*/
|
28
|
+
static exchange(a: FungibleTokenAmount, aPrice: CurrencyAmount, bPrice: CurrencyAmount, b: FungibleToken): FungibleTokenAmount;
|
23
29
|
protected constructor(fungibleToken: FungibleToken, numerator: BigintIsh | bigint, denominator?: BigintIsh | bigint, amountInFiatCurrency?: CurrencyAmount);
|
24
30
|
equals(other: FungibleTokenAmount): boolean;
|
25
31
|
add(other: FungibleTokenAmount): FungibleTokenAmount;
|
@@ -37,6 +37,20 @@ class FungibleTokenAmount extends sdk_core_1.Fraction {
|
|
37
37
|
const amountInFiatCurrency = currency_amount_js_1.CurrencyAmount.toCurrencyAmount(amount.amountInFiatCurrency);
|
38
38
|
return FungibleTokenAmount.fromRawAmount(fungible_token_js_1.FungibleToken.toFungibleToken(amount.token), amount.value, amountInFiatCurrency);
|
39
39
|
}
|
40
|
+
/**
|
41
|
+
* Used to calculate the amount of token B that one can get for a given amount of token A.
|
42
|
+
* aPrice is the unit price of token A in fiat currency
|
43
|
+
* bPrice is the unit price of token B in fiat currency
|
44
|
+
*/
|
45
|
+
static exchange(a, aPrice, bPrice, b) {
|
46
|
+
(0, tiny_invariant_1.default)(aPrice.currency.equals(bPrice.currency), "CURRENCY");
|
47
|
+
const ratio = aPrice.divide(bPrice);
|
48
|
+
const numberOfB = ratio.multiply(a);
|
49
|
+
const numerator = jsbi_1.default.multiply(numberOfB.numerator, jsbi_1.default.BigInt(10 ** b.decimals));
|
50
|
+
const denominator = jsbi_1.default.multiply(numberOfB.denominator, a.decimalScale);
|
51
|
+
const result = FungibleTokenAmount.fromFractionalAmount(b, numerator, denominator);
|
52
|
+
return result;
|
53
|
+
}
|
40
54
|
constructor(fungibleToken, numerator, denominator, amountInFiatCurrency) {
|
41
55
|
super(numerator.toString(), denominator?.toString());
|
42
56
|
(0, tiny_invariant_1.default)(jsbi_1.default.lessThanOrEqual(this.quotient, sdk_core_1.MaxUint256), "AMOUNT"); // TODO(imti): fix this
|
@@ -15,7 +15,6 @@ class LibraryRequest {
|
|
15
15
|
return undefined;
|
16
16
|
}
|
17
17
|
const environment = await this.getVirtualEnvironment(chainId);
|
18
|
-
console.log("ENVIRONMENT", environment);
|
19
18
|
switch (environment) {
|
20
19
|
case enums_js_1.VMType.SVM:
|
21
20
|
return `SVM-${chainId.toString()}`;
|
@@ -26,16 +25,10 @@ class LibraryRequest {
|
|
26
25
|
}
|
27
26
|
};
|
28
27
|
this.getVirtualEnvironment = async (id) => {
|
29
|
-
if (Object.keys(constants_js_1.
|
28
|
+
if (Object.keys(constants_js_1.CHAIN_CONFIGS).length == 0) {
|
30
29
|
await (0, utils_js_1.initializeBlockchainInformation)(this.providerUrl());
|
31
30
|
}
|
32
|
-
|
33
|
-
const blockchain = id ? constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
|
34
|
-
if (!blockchain) {
|
35
|
-
console.error("No blockchain found for chainId", id);
|
36
|
-
return undefined;
|
37
|
-
}
|
38
|
-
return constants_js_1.CHAIN_CONFIGS[blockchain]?.vmType;
|
31
|
+
return constants_js_1.CHAIN_CONFIGS[Number(id)]?.vmType;
|
39
32
|
};
|
40
33
|
if (library == enums_js_1.LIBRARY_TYPE.VIEM) {
|
41
34
|
(0, tiny_invariant_1.default)(client, "CLIENT");
|
@@ -55,6 +48,9 @@ class LibraryRequest {
|
|
55
48
|
this.provider = provider;
|
56
49
|
}
|
57
50
|
sendRequest(method, params) {
|
51
|
+
if (Object.keys(constants_js_1.CHAIN_CONFIGS).length == 0) {
|
52
|
+
(0, utils_js_1.initializeBlockchainInformation)(this.providerUrl());
|
53
|
+
}
|
58
54
|
if (this.library == enums_js_1.LIBRARY_TYPE.VIEM) {
|
59
55
|
return this.client.request({ method, params });
|
60
56
|
}
|
@@ -63,12 +59,19 @@ class LibraryRequest {
|
|
63
59
|
}
|
64
60
|
}
|
65
61
|
providerUrl() {
|
62
|
+
let url = "";
|
66
63
|
if (this.library == enums_js_1.LIBRARY_TYPE.VIEM) {
|
67
|
-
|
64
|
+
url = this.client?.transport?.url;
|
68
65
|
}
|
69
66
|
else if (this.library == enums_js_1.LIBRARY_TYPE.ETHERS) {
|
70
|
-
|
67
|
+
url = this.provider._getConnection().url;
|
71
68
|
}
|
69
|
+
const uuidRegex = /([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/i;
|
70
|
+
const match = url.match(uuidRegex);
|
71
|
+
if (!match)
|
72
|
+
return url;
|
73
|
+
const endIndex = url.indexOf(match[1]) + match[1].length;
|
74
|
+
return url.slice(0, endIndex);
|
72
75
|
}
|
73
76
|
}
|
74
77
|
exports.LibraryRequest = LibraryRequest;
|
package/dist/cjs/enums.d.ts
CHANGED
@@ -1,28 +1,3 @@
|
|
1
|
-
export declare enum Blockchain {
|
2
|
-
ETHEREUM = "ethereum",
|
3
|
-
POLYGON = "polygon",
|
4
|
-
BINANCE = "binance",
|
5
|
-
ARBITRUM = "arbitrum",
|
6
|
-
BASE = "base",
|
7
|
-
AVALANCHE = "avalanche",
|
8
|
-
ARBITRUM_NOVA = "arbitrum_nova",
|
9
|
-
OPTIMISM = "optimism",
|
10
|
-
EVMOS = "evmos",
|
11
|
-
MOONBEAM = "moonbeam",
|
12
|
-
SOLANA = "solana",
|
13
|
-
ETHEREUM_SEPOLIA = "ethereum_sepolia",
|
14
|
-
ETHEREUM_HOLESKY = "ethereum_holesky",
|
15
|
-
BASE_SEPOLIA = "base_sepolia",
|
16
|
-
ARBITRUM_SEPOLIA = "arbitrum_sepolia",
|
17
|
-
OPTIMISM_SEPOLIA = "optimism_sepolia",
|
18
|
-
POLYGON_AMOY = "polygon_amoy",
|
19
|
-
BINANCE_TESTNET = "binance_testnet",
|
20
|
-
OPBNB_TESTNET = "opbnb_testnet",
|
21
|
-
MOONBEAM_ALPHA = "moonbeam_alpha",
|
22
|
-
HARDHAT = "hardhat",
|
23
|
-
LOCAL_CHAIN_0 = "local_chain_0",
|
24
|
-
LOCAL_CHAIN_1 = "local_chain_1"
|
25
|
-
}
|
26
1
|
export declare enum TokenType {
|
27
2
|
FUNGIBLE_TOKEN = "FUNGIBLE_TOKEN",
|
28
3
|
NON_FUNGIBLE_TOKEN = "NON_FUNGIBLE_TOKEN",
|
package/dist/cjs/enums.js
CHANGED
@@ -1,34 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.LIBRARY_TYPE = exports.TimeIntervalUnits = exports.TokenAllowlistType = exports.BlockchainEnvironment = exports.ActivityStatus = exports.Order = exports.QuoteType = exports.OperationStatusType = exports.Category = exports.OperationType = exports.OperationDataFormat = exports.CreateOperationsStatus = exports.ChainSupportStatus = exports.VMType = exports.AccountType = exports.TokenType =
|
4
|
-
var Blockchain;
|
5
|
-
(function (Blockchain) {
|
6
|
-
Blockchain["ETHEREUM"] = "ethereum";
|
7
|
-
Blockchain["POLYGON"] = "polygon";
|
8
|
-
Blockchain["BINANCE"] = "binance";
|
9
|
-
Blockchain["ARBITRUM"] = "arbitrum";
|
10
|
-
Blockchain["BASE"] = "base";
|
11
|
-
Blockchain["AVALANCHE"] = "avalanche";
|
12
|
-
Blockchain["ARBITRUM_NOVA"] = "arbitrum_nova";
|
13
|
-
Blockchain["OPTIMISM"] = "optimism";
|
14
|
-
Blockchain["EVMOS"] = "evmos";
|
15
|
-
Blockchain["MOONBEAM"] = "moonbeam";
|
16
|
-
Blockchain["SOLANA"] = "solana";
|
17
|
-
// testnets
|
18
|
-
Blockchain["ETHEREUM_SEPOLIA"] = "ethereum_sepolia";
|
19
|
-
Blockchain["ETHEREUM_HOLESKY"] = "ethereum_holesky";
|
20
|
-
Blockchain["BASE_SEPOLIA"] = "base_sepolia";
|
21
|
-
Blockchain["ARBITRUM_SEPOLIA"] = "arbitrum_sepolia";
|
22
|
-
Blockchain["OPTIMISM_SEPOLIA"] = "optimism_sepolia";
|
23
|
-
Blockchain["POLYGON_AMOY"] = "polygon_amoy";
|
24
|
-
Blockchain["BINANCE_TESTNET"] = "binance_testnet";
|
25
|
-
Blockchain["OPBNB_TESTNET"] = "opbnb_testnet";
|
26
|
-
Blockchain["MOONBEAM_ALPHA"] = "moonbeam_alpha";
|
27
|
-
// local testing
|
28
|
-
Blockchain["HARDHAT"] = "hardhat";
|
29
|
-
Blockchain["LOCAL_CHAIN_0"] = "local_chain_0";
|
30
|
-
Blockchain["LOCAL_CHAIN_1"] = "local_chain_1";
|
31
|
-
})(Blockchain || (exports.Blockchain = Blockchain = {}));
|
3
|
+
exports.LIBRARY_TYPE = exports.TimeIntervalUnits = exports.TokenAllowlistType = exports.BlockchainEnvironment = exports.ActivityStatus = exports.Order = exports.QuoteType = exports.OperationStatusType = exports.Category = exports.OperationType = exports.OperationDataFormat = exports.CreateOperationsStatus = exports.ChainSupportStatus = exports.VMType = exports.AccountType = exports.TokenType = void 0;
|
32
4
|
var TokenType;
|
33
5
|
(function (TokenType) {
|
34
6
|
TokenType["FUNGIBLE_TOKEN"] = "FUNGIBLE_TOKEN";
|
@@ -26,5 +26,5 @@ export interface IAccountClusterActions {
|
|
26
26
|
}>;
|
27
27
|
getPortfolioOverview(accountClusterId: string): Promise<FungibleTokenOverview>;
|
28
28
|
getFungibleTokenPortfolio(accountClusterId: string): Promise<StandardizedBalance[]>;
|
29
|
-
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[]): Promise<StandardizedBalance[]>;
|
29
|
+
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[], standardizedTokenIds?: string[]): Promise<StandardizedBalance[]>;
|
30
30
|
}
|
package/dist/cjs/types.d.ts
CHANGED
@@ -165,6 +165,10 @@ export type ChainConfigs = {
|
|
165
165
|
environment: BlockchainEnvironment;
|
166
166
|
chainId: bigint;
|
167
167
|
vmType: VMType;
|
168
|
+
logoUrl: string;
|
169
|
+
name: string;
|
170
|
+
genesisBlockHash?: string;
|
171
|
+
nativeCurrency: Currency;
|
168
172
|
};
|
169
173
|
export type VirtualNodeRpcUrlForSupportedChain = {
|
170
174
|
chainId: string;
|
@@ -1,4 +1,8 @@
|
|
1
1
|
import { VMType } from "../enums.js";
|
2
|
+
import { Currency } from "../entities/financial/currency.js";
|
3
|
+
import { FungibleToken } from "../entities/financial/fungible_token.js";
|
4
|
+
import { FungibleTokenAmount } from "../entities/financial/fungible_token_amount.js";
|
5
|
+
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
2
6
|
export declare const initializeBlockchainInformation: (orbyUrl: string) => Promise<void>;
|
3
7
|
export declare const getChainIdFromOrbyChainId: (value: string) => bigint | undefined;
|
4
8
|
export declare const getVirtualEnvironment: (id: bigint) => Promise<VMType>;
|
@@ -6,3 +10,7 @@ export declare const hasError: (data: any) => {
|
|
6
10
|
code: number;
|
7
11
|
message: string;
|
8
12
|
};
|
13
|
+
export declare const getNativeCurrency: (chainId: bigint) => Currency;
|
14
|
+
export declare const getNativeFungibleToken: (chainId: bigint) => FungibleToken;
|
15
|
+
export declare const createNativeFungibleTokenAmount: (value: bigint, chainId: bigint) => FungibleTokenAmount;
|
16
|
+
export declare const createNativeCurrencyAmount: (value: bigint, chainId: bigint) => CurrencyAmount;
|
package/dist/cjs/utils/utils.js
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.hasError = exports.getVirtualEnvironment = exports.getChainIdFromOrbyChainId = exports.initializeBlockchainInformation = void 0;
|
3
|
+
exports.createNativeCurrencyAmount = exports.createNativeFungibleTokenAmount = exports.getNativeFungibleToken = exports.getNativeCurrency = exports.hasError = exports.getVirtualEnvironment = exports.getChainIdFromOrbyChainId = exports.initializeBlockchainInformation = void 0;
|
4
4
|
const constants_js_1 = require("../constants.js");
|
5
5
|
const validateAndParseAddress_js_1 = require("./validateAndParseAddress.js");
|
6
|
+
const currency_js_1 = require("../entities/financial/currency.js");
|
7
|
+
const fungible_token_js_1 = require("../entities/financial/fungible_token.js");
|
8
|
+
const fungible_token_amount_js_1 = require("../entities/financial/fungible_token_amount.js");
|
9
|
+
const currency_amount_js_1 = require("../entities/financial/currency_amount.js");
|
6
10
|
const initializeBlockchainInformation = async (orbyUrl) => {
|
7
11
|
const response = await fetch(orbyUrl, {
|
8
12
|
method: "POST",
|
@@ -23,14 +27,11 @@ const initializeBlockchainInformation = async (orbyUrl) => {
|
|
23
27
|
}
|
24
28
|
result.edges?.map((blockchainInfo) => {
|
25
29
|
const chainId = (0, exports.getChainIdFromOrbyChainId)(blockchainInfo.chainId);
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(chainId)] = blockchainName;
|
30
|
-
constants_js_1.CHAIN_CONFIGS[blockchainName] = {
|
31
|
-
environment: blockchainInfo.environment,
|
30
|
+
if (chainId && blockchainInfo?.name) {
|
31
|
+
constants_js_1.CHAIN_CONFIGS[Number(chainId)] = {
|
32
|
+
...blockchainInfo,
|
32
33
|
chainId: chainId,
|
33
|
-
|
34
|
+
nativeCurrency: currency_js_1.Currency.toCurrency(blockchainInfo?.nativeCurrency),
|
34
35
|
};
|
35
36
|
}
|
36
37
|
});
|
@@ -57,11 +58,7 @@ const getChainIdFromOrbyChainId = (value) => {
|
|
57
58
|
};
|
58
59
|
exports.getChainIdFromOrbyChainId = getChainIdFromOrbyChainId;
|
59
60
|
const getVirtualEnvironment = async (id) => {
|
60
|
-
|
61
|
-
if (!blockchain) {
|
62
|
-
return undefined;
|
63
|
-
}
|
64
|
-
return constants_js_1.CHAIN_CONFIGS[blockchain]?.vmType;
|
61
|
+
return constants_js_1.CHAIN_CONFIGS[Number(id)]?.vmType;
|
65
62
|
};
|
66
63
|
exports.getVirtualEnvironment = getVirtualEnvironment;
|
67
64
|
const hasError = (data) => {
|
@@ -71,3 +68,24 @@ const hasError = (data) => {
|
|
71
68
|
return undefined;
|
72
69
|
};
|
73
70
|
exports.hasError = hasError;
|
71
|
+
const getNativeCurrency = (chainId) => {
|
72
|
+
const currency = constants_js_1.CHAIN_CONFIGS[Number(chainId)]?.nativeCurrency;
|
73
|
+
return new currency_js_1.Currency(currency.decimals, currency.symbol, currency.name, undefined, false, false);
|
74
|
+
};
|
75
|
+
exports.getNativeCurrency = getNativeCurrency;
|
76
|
+
const getNativeFungibleToken = (chainId) => {
|
77
|
+
const currency = (0, exports.getNativeCurrency)(chainId);
|
78
|
+
return new fungible_token_js_1.FungibleToken(chainId, constants_js_1.NATIVE_TOKEN_ADDRESS, currency.decimals, currency.symbol, currency.name, false, true, currency.coinGeckoId);
|
79
|
+
};
|
80
|
+
exports.getNativeFungibleToken = getNativeFungibleToken;
|
81
|
+
const createNativeFungibleTokenAmount = (value, chainId) => {
|
82
|
+
const currency = (0, exports.getNativeCurrency)(chainId);
|
83
|
+
const fungibleToken = new fungible_token_js_1.FungibleToken(chainId, constants_js_1.NATIVE_TOKEN_ADDRESS, currency.decimals, currency.symbol, currency.name, false, true);
|
84
|
+
return fungible_token_amount_js_1.FungibleTokenAmount.fromRawAmount(fungibleToken, value);
|
85
|
+
};
|
86
|
+
exports.createNativeFungibleTokenAmount = createNativeFungibleTokenAmount;
|
87
|
+
const createNativeCurrencyAmount = (value, chainId) => {
|
88
|
+
const currency = (0, exports.getNativeCurrency)(chainId);
|
89
|
+
return currency_amount_js_1.CurrencyAmount.fromRawAmount(currency, value);
|
90
|
+
};
|
91
|
+
exports.createNativeCurrencyAmount = createNativeCurrencyAmount;
|
@@ -28,5 +28,5 @@ export declare class AccountClusterActions extends LibraryRequest {
|
|
28
28
|
}>;
|
29
29
|
getPortfolioOverview(accountClusterId: string): Promise<FungibleTokenOverview>;
|
30
30
|
getFungibleTokenPortfolio(accountClusterId: string): Promise<StandardizedBalance[]>;
|
31
|
-
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[]): Promise<StandardizedBalance[]>;
|
31
|
+
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[], standardizedTokenIds?: string[]): Promise<StandardizedBalance[]>;
|
32
32
|
}
|
@@ -194,7 +194,7 @@ export class AccountClusterActions extends LibraryRequest {
|
|
194
194
|
}
|
195
195
|
return extractStandardizedBalances(fungibleTokenBalances);
|
196
196
|
}
|
197
|
-
async getFungibleTokenBalances(accountClusterId, offset, limit, chainId, tokensToOmit) {
|
197
|
+
async getFungibleTokenBalances(accountClusterId, offset, limit, chainId, tokensToOmit, standardizedTokenIds) {
|
198
198
|
const orbyChainId = await this.getOrbyChainId(chainId);
|
199
199
|
const { fungibleTokenBalances, code, message } = await this.sendRequest("orby_getFungibleTokenBalances", [
|
200
200
|
{
|
@@ -203,6 +203,7 @@ export class AccountClusterActions extends LibraryRequest {
|
|
203
203
|
limit,
|
204
204
|
chainId: orbyChainId,
|
205
205
|
tokensToOmit,
|
206
|
+
standardizedTokenIds,
|
206
207
|
},
|
207
208
|
]);
|
208
209
|
if (code && message) {
|
package/dist/esm/constants.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
import { Blockchain } from "./enums.js";
|
2
1
|
import { Currency } from "./entities/financial/currency.js";
|
3
2
|
import { ChainConfigs } from "./types.js";
|
4
3
|
export declare const Big: any;
|
5
|
-
export declare const
|
6
|
-
export declare const
|
7
|
-
export declare const
|
4
|
+
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
5
|
+
export declare const ONE_ADDRESS = "0x0000000000000000000000000000000000000001";
|
6
|
+
export declare const TWO_ADDRESS = "0x0000000000000000000000000000000000000002";
|
7
|
+
export declare const NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
8
|
+
export declare const CHAIN_CONFIGS: Record<number, ChainConfigs>;
|
8
9
|
export declare const FIAT_CURRENCY: Currency;
|
package/dist/esm/constants.js
CHANGED
@@ -2,7 +2,9 @@ import toFormat from "toformat";
|
|
2
2
|
import _Big from "big.js";
|
3
3
|
import { Currency } from "./entities/financial/currency.js";
|
4
4
|
export const Big = toFormat(_Big);
|
5
|
-
export const
|
5
|
+
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
6
|
+
export const ONE_ADDRESS = "0x0000000000000000000000000000000000000001";
|
7
|
+
export const TWO_ADDRESS = "0x0000000000000000000000000000000000000002";
|
8
|
+
export const NATIVE_TOKEN_ADDRESS = ZERO_ADDRESS;
|
6
9
|
export const CHAIN_CONFIGS = {};
|
7
|
-
export const BLOCKCHAIN_ID_TO_BLOCKCHAIN = {};
|
8
10
|
export const FIAT_CURRENCY = new Currency(6, "USD", "US Dollar", undefined, false, false);
|
@@ -20,6 +20,12 @@ export declare class FungibleTokenAmount extends Fraction {
|
|
20
20
|
*/
|
21
21
|
static fromFractionalAmount(fungibleToken: FungibleToken, numerator: BigintIsh, denominator: BigintIsh, amountInFiatCurrency?: CurrencyAmount): FungibleTokenAmount;
|
22
22
|
static toFungibleTokenAmount(amount?: any): FungibleTokenAmount;
|
23
|
+
/**
|
24
|
+
* Used to calculate the amount of token B that one can get for a given amount of token A.
|
25
|
+
* aPrice is the unit price of token A in fiat currency
|
26
|
+
* bPrice is the unit price of token B in fiat currency
|
27
|
+
*/
|
28
|
+
static exchange(a: FungibleTokenAmount, aPrice: CurrencyAmount, bPrice: CurrencyAmount, b: FungibleToken): FungibleTokenAmount;
|
23
29
|
protected constructor(fungibleToken: FungibleToken, numerator: BigintIsh | bigint, denominator?: BigintIsh | bigint, amountInFiatCurrency?: CurrencyAmount);
|
24
30
|
equals(other: FungibleTokenAmount): boolean;
|
25
31
|
add(other: FungibleTokenAmount): FungibleTokenAmount;
|
@@ -31,6 +31,20 @@ export class FungibleTokenAmount extends Fraction {
|
|
31
31
|
const amountInFiatCurrency = CurrencyAmount.toCurrencyAmount(amount.amountInFiatCurrency);
|
32
32
|
return FungibleTokenAmount.fromRawAmount(FungibleToken.toFungibleToken(amount.token), amount.value, amountInFiatCurrency);
|
33
33
|
}
|
34
|
+
/**
|
35
|
+
* Used to calculate the amount of token B that one can get for a given amount of token A.
|
36
|
+
* aPrice is the unit price of token A in fiat currency
|
37
|
+
* bPrice is the unit price of token B in fiat currency
|
38
|
+
*/
|
39
|
+
static exchange(a, aPrice, bPrice, b) {
|
40
|
+
invariant(aPrice.currency.equals(bPrice.currency), "CURRENCY");
|
41
|
+
const ratio = aPrice.divide(bPrice);
|
42
|
+
const numberOfB = ratio.multiply(a);
|
43
|
+
const numerator = JSBI.multiply(numberOfB.numerator, JSBI.BigInt(10 ** b.decimals));
|
44
|
+
const denominator = JSBI.multiply(numberOfB.denominator, a.decimalScale);
|
45
|
+
const result = FungibleTokenAmount.fromFractionalAmount(b, numerator, denominator);
|
46
|
+
return result;
|
47
|
+
}
|
34
48
|
constructor(fungibleToken, numerator, denominator, amountInFiatCurrency) {
|
35
49
|
super(numerator.toString(), denominator?.toString());
|
36
50
|
invariant(JSBI.lessThanOrEqual(this.quotient, MaxUint256), "AMOUNT"); // TODO(imti): fix this
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { LIBRARY_TYPE, VMType } from "../enums.js";
|
2
2
|
import invariant from "tiny-invariant";
|
3
|
-
import {
|
3
|
+
import { CHAIN_CONFIGS } from "../constants.js";
|
4
4
|
import { initializeBlockchainInformation } from "../utils/utils.js";
|
5
5
|
export class LibraryRequest {
|
6
6
|
constructor(library, client, provider) {
|
@@ -9,7 +9,6 @@ export class LibraryRequest {
|
|
9
9
|
return undefined;
|
10
10
|
}
|
11
11
|
const environment = await this.getVirtualEnvironment(chainId);
|
12
|
-
console.log("ENVIRONMENT", environment);
|
13
12
|
switch (environment) {
|
14
13
|
case VMType.SVM:
|
15
14
|
return `SVM-${chainId.toString()}`;
|
@@ -20,16 +19,10 @@ export class LibraryRequest {
|
|
20
19
|
}
|
21
20
|
};
|
22
21
|
this.getVirtualEnvironment = async (id) => {
|
23
|
-
if (Object.keys(
|
22
|
+
if (Object.keys(CHAIN_CONFIGS).length == 0) {
|
24
23
|
await initializeBlockchainInformation(this.providerUrl());
|
25
24
|
}
|
26
|
-
|
27
|
-
const blockchain = id ? BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
|
28
|
-
if (!blockchain) {
|
29
|
-
console.error("No blockchain found for chainId", id);
|
30
|
-
return undefined;
|
31
|
-
}
|
32
|
-
return CHAIN_CONFIGS[blockchain]?.vmType;
|
25
|
+
return CHAIN_CONFIGS[Number(id)]?.vmType;
|
33
26
|
};
|
34
27
|
if (library == LIBRARY_TYPE.VIEM) {
|
35
28
|
invariant(client, "CLIENT");
|
@@ -49,6 +42,9 @@ export class LibraryRequest {
|
|
49
42
|
this.provider = provider;
|
50
43
|
}
|
51
44
|
sendRequest(method, params) {
|
45
|
+
if (Object.keys(CHAIN_CONFIGS).length == 0) {
|
46
|
+
initializeBlockchainInformation(this.providerUrl());
|
47
|
+
}
|
52
48
|
if (this.library == LIBRARY_TYPE.VIEM) {
|
53
49
|
return this.client.request({ method, params });
|
54
50
|
}
|
@@ -57,11 +53,18 @@ export class LibraryRequest {
|
|
57
53
|
}
|
58
54
|
}
|
59
55
|
providerUrl() {
|
56
|
+
let url = "";
|
60
57
|
if (this.library == LIBRARY_TYPE.VIEM) {
|
61
|
-
|
58
|
+
url = this.client?.transport?.url;
|
62
59
|
}
|
63
60
|
else if (this.library == LIBRARY_TYPE.ETHERS) {
|
64
|
-
|
61
|
+
url = this.provider._getConnection().url;
|
65
62
|
}
|
63
|
+
const uuidRegex = /([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/i;
|
64
|
+
const match = url.match(uuidRegex);
|
65
|
+
if (!match)
|
66
|
+
return url;
|
67
|
+
const endIndex = url.indexOf(match[1]) + match[1].length;
|
68
|
+
return url.slice(0, endIndex);
|
66
69
|
}
|
67
70
|
}
|
package/dist/esm/enums.d.ts
CHANGED
@@ -1,28 +1,3 @@
|
|
1
|
-
export declare enum Blockchain {
|
2
|
-
ETHEREUM = "ethereum",
|
3
|
-
POLYGON = "polygon",
|
4
|
-
BINANCE = "binance",
|
5
|
-
ARBITRUM = "arbitrum",
|
6
|
-
BASE = "base",
|
7
|
-
AVALANCHE = "avalanche",
|
8
|
-
ARBITRUM_NOVA = "arbitrum_nova",
|
9
|
-
OPTIMISM = "optimism",
|
10
|
-
EVMOS = "evmos",
|
11
|
-
MOONBEAM = "moonbeam",
|
12
|
-
SOLANA = "solana",
|
13
|
-
ETHEREUM_SEPOLIA = "ethereum_sepolia",
|
14
|
-
ETHEREUM_HOLESKY = "ethereum_holesky",
|
15
|
-
BASE_SEPOLIA = "base_sepolia",
|
16
|
-
ARBITRUM_SEPOLIA = "arbitrum_sepolia",
|
17
|
-
OPTIMISM_SEPOLIA = "optimism_sepolia",
|
18
|
-
POLYGON_AMOY = "polygon_amoy",
|
19
|
-
BINANCE_TESTNET = "binance_testnet",
|
20
|
-
OPBNB_TESTNET = "opbnb_testnet",
|
21
|
-
MOONBEAM_ALPHA = "moonbeam_alpha",
|
22
|
-
HARDHAT = "hardhat",
|
23
|
-
LOCAL_CHAIN_0 = "local_chain_0",
|
24
|
-
LOCAL_CHAIN_1 = "local_chain_1"
|
25
|
-
}
|
26
1
|
export declare enum TokenType {
|
27
2
|
FUNGIBLE_TOKEN = "FUNGIBLE_TOKEN",
|
28
3
|
NON_FUNGIBLE_TOKEN = "NON_FUNGIBLE_TOKEN",
|
package/dist/esm/enums.js
CHANGED
@@ -1,31 +1,3 @@
|
|
1
|
-
export var Blockchain;
|
2
|
-
(function (Blockchain) {
|
3
|
-
Blockchain["ETHEREUM"] = "ethereum";
|
4
|
-
Blockchain["POLYGON"] = "polygon";
|
5
|
-
Blockchain["BINANCE"] = "binance";
|
6
|
-
Blockchain["ARBITRUM"] = "arbitrum";
|
7
|
-
Blockchain["BASE"] = "base";
|
8
|
-
Blockchain["AVALANCHE"] = "avalanche";
|
9
|
-
Blockchain["ARBITRUM_NOVA"] = "arbitrum_nova";
|
10
|
-
Blockchain["OPTIMISM"] = "optimism";
|
11
|
-
Blockchain["EVMOS"] = "evmos";
|
12
|
-
Blockchain["MOONBEAM"] = "moonbeam";
|
13
|
-
Blockchain["SOLANA"] = "solana";
|
14
|
-
// testnets
|
15
|
-
Blockchain["ETHEREUM_SEPOLIA"] = "ethereum_sepolia";
|
16
|
-
Blockchain["ETHEREUM_HOLESKY"] = "ethereum_holesky";
|
17
|
-
Blockchain["BASE_SEPOLIA"] = "base_sepolia";
|
18
|
-
Blockchain["ARBITRUM_SEPOLIA"] = "arbitrum_sepolia";
|
19
|
-
Blockchain["OPTIMISM_SEPOLIA"] = "optimism_sepolia";
|
20
|
-
Blockchain["POLYGON_AMOY"] = "polygon_amoy";
|
21
|
-
Blockchain["BINANCE_TESTNET"] = "binance_testnet";
|
22
|
-
Blockchain["OPBNB_TESTNET"] = "opbnb_testnet";
|
23
|
-
Blockchain["MOONBEAM_ALPHA"] = "moonbeam_alpha";
|
24
|
-
// local testing
|
25
|
-
Blockchain["HARDHAT"] = "hardhat";
|
26
|
-
Blockchain["LOCAL_CHAIN_0"] = "local_chain_0";
|
27
|
-
Blockchain["LOCAL_CHAIN_1"] = "local_chain_1";
|
28
|
-
})(Blockchain || (Blockchain = {}));
|
29
1
|
export var TokenType;
|
30
2
|
(function (TokenType) {
|
31
3
|
TokenType["FUNGIBLE_TOKEN"] = "FUNGIBLE_TOKEN";
|
@@ -26,5 +26,5 @@ export interface IAccountClusterActions {
|
|
26
26
|
}>;
|
27
27
|
getPortfolioOverview(accountClusterId: string): Promise<FungibleTokenOverview>;
|
28
28
|
getFungibleTokenPortfolio(accountClusterId: string): Promise<StandardizedBalance[]>;
|
29
|
-
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[]): Promise<StandardizedBalance[]>;
|
29
|
+
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[], standardizedTokenIds?: string[]): Promise<StandardizedBalance[]>;
|
30
30
|
}
|
package/dist/esm/types.d.ts
CHANGED
@@ -165,6 +165,10 @@ export type ChainConfigs = {
|
|
165
165
|
environment: BlockchainEnvironment;
|
166
166
|
chainId: bigint;
|
167
167
|
vmType: VMType;
|
168
|
+
logoUrl: string;
|
169
|
+
name: string;
|
170
|
+
genesisBlockHash?: string;
|
171
|
+
nativeCurrency: Currency;
|
168
172
|
};
|
169
173
|
export type VirtualNodeRpcUrlForSupportedChain = {
|
170
174
|
chainId: string;
|
@@ -1,4 +1,8 @@
|
|
1
1
|
import { VMType } from "../enums.js";
|
2
|
+
import { Currency } from "../entities/financial/currency.js";
|
3
|
+
import { FungibleToken } from "../entities/financial/fungible_token.js";
|
4
|
+
import { FungibleTokenAmount } from "../entities/financial/fungible_token_amount.js";
|
5
|
+
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
2
6
|
export declare const initializeBlockchainInformation: (orbyUrl: string) => Promise<void>;
|
3
7
|
export declare const getChainIdFromOrbyChainId: (value: string) => bigint | undefined;
|
4
8
|
export declare const getVirtualEnvironment: (id: bigint) => Promise<VMType>;
|
@@ -6,3 +10,7 @@ export declare const hasError: (data: any) => {
|
|
6
10
|
code: number;
|
7
11
|
message: string;
|
8
12
|
};
|
13
|
+
export declare const getNativeCurrency: (chainId: bigint) => Currency;
|
14
|
+
export declare const getNativeFungibleToken: (chainId: bigint) => FungibleToken;
|
15
|
+
export declare const createNativeFungibleTokenAmount: (value: bigint, chainId: bigint) => FungibleTokenAmount;
|
16
|
+
export declare const createNativeCurrencyAmount: (value: bigint, chainId: bigint) => CurrencyAmount;
|