@orb-labs/orby-core 0.0.24 → 0.0.26
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/actions/operation.d.ts +1 -1
- package/dist/cjs/actions/operation.js +9 -9
- package/dist/cjs/constants.d.ts +4 -0
- package/dist/cjs/constants.js +5 -1
- 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/interfaces/account_cluster.d.ts +1 -1
- package/dist/cjs/interfaces/operation.d.ts +1 -1
- package/dist/cjs/types.d.ts +1 -0
- package/dist/cjs/utils/utils.d.ts +8 -0
- package/dist/cjs/utils/utils.js +27 -1
- package/dist/esm/actions/account_cluster.d.ts +1 -1
- package/dist/esm/actions/account_cluster.js +2 -1
- package/dist/esm/actions/operation.d.ts +1 -1
- package/dist/esm/actions/operation.js +9 -9
- package/dist/esm/constants.d.ts +4 -0
- package/dist/esm/constants.js +4 -0
- 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/interfaces/account_cluster.d.ts +1 -1
- package/dist/esm/interfaces/operation.d.ts +1 -1
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/utils/utils.d.ts +8 -0
- package/dist/esm/utils/utils.js +23 -1
- 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.25
|
6
|
+
|
7
|
+
- updating variable name for getOperationsToTransferToken
|
8
|
+
- removing default array for gas token source
|
9
|
+
|
10
|
+
### 0.0.25
|
11
|
+
|
12
|
+
- adding nativeCurrency field to blockchain
|
13
|
+
- exposing currency related util functions
|
14
|
+
|
5
15
|
### 0.0.24
|
6
16
|
|
7
17
|
- fetching blockchain list earlier
|
@@ -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) {
|
@@ -37,7 +37,7 @@ export declare class OperationActions extends LibraryRequest {
|
|
37
37
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
38
38
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
39
39
|
chainId: bigint;
|
40
|
-
|
40
|
+
address: string;
|
41
41
|
}, gasToken?: {
|
42
42
|
standardizedTokenId: string;
|
43
43
|
tokenSources?: {
|
@@ -21,7 +21,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
21
21
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
22
22
|
chainId: await this.getOrbyChainId(chainId),
|
23
23
|
address,
|
24
|
-
}))
|
24
|
+
}))),
|
25
25
|
}
|
26
26
|
: undefined;
|
27
27
|
const operationSet = await this.sendRequest("orby_getOperationsToExecuteTransaction", [
|
@@ -42,7 +42,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
42
42
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
43
43
|
chainId: await this.getOrbyChainId(chainId),
|
44
44
|
address,
|
45
|
-
}))
|
45
|
+
}))),
|
46
46
|
}
|
47
47
|
: undefined;
|
48
48
|
const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
|
@@ -61,7 +61,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
61
61
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
62
62
|
chainId: await this.getOrbyChainId(chainId),
|
63
63
|
address,
|
64
|
-
}))
|
64
|
+
}))),
|
65
65
|
}
|
66
66
|
: undefined;
|
67
67
|
const operationSet = await this.sendRequest("orby_getOperationsToSignTransactionOrSignTypedData", [
|
@@ -157,12 +157,12 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
157
157
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
158
158
|
chainId: await this.getOrbyChainId(chainId),
|
159
159
|
address,
|
160
|
-
}))
|
160
|
+
}))),
|
161
161
|
}
|
162
162
|
: undefined;
|
163
163
|
const formattedRecepient = {
|
164
164
|
chainId: await this.getOrbyChainId(recipient.chainId),
|
165
|
-
|
165
|
+
address: recipient.address,
|
166
166
|
};
|
167
167
|
const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
|
168
168
|
{
|
@@ -182,7 +182,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
182
182
|
tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
|
183
183
|
chainId: await this.getOrbyChainId(chainId),
|
184
184
|
address,
|
185
|
-
}))
|
185
|
+
}))),
|
186
186
|
}
|
187
187
|
: undefined;
|
188
188
|
const formattedOutput = output
|
@@ -202,7 +202,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
202
202
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
203
203
|
chainId: await this.getOrbyChainId(chainId),
|
204
204
|
address,
|
205
|
-
}))
|
205
|
+
}))),
|
206
206
|
}
|
207
207
|
: undefined;
|
208
208
|
const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
|
@@ -223,7 +223,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
223
223
|
tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
|
224
224
|
chainId: await this.getOrbyChainId(chainId),
|
225
225
|
address,
|
226
|
-
}))
|
226
|
+
}))),
|
227
227
|
}
|
228
228
|
: undefined;
|
229
229
|
const formattedOutput = output
|
@@ -264,7 +264,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
264
264
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
265
265
|
chainId: await this.getOrbyChainId(chainId),
|
266
266
|
address,
|
267
|
-
}))
|
267
|
+
}))),
|
268
268
|
}
|
269
269
|
: undefined;
|
270
270
|
const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
|
package/dist/cjs/constants.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import { Currency } from "./entities/financial/currency.js";
|
2
2
|
import { ChainConfigs } from "./types.js";
|
3
3
|
export declare const Big: any;
|
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";
|
4
8
|
export declare const CHAIN_CONFIGS: Record<number, ChainConfigs>;
|
5
9
|
export declare const FIAT_CURRENCY: Currency;
|
package/dist/cjs/constants.js
CHANGED
@@ -3,10 +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.CHAIN_CONFIGS = exports.Big = void 0;
|
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.ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
12
|
+
exports.ONE_ADDRESS = "0x0000000000000000000000000000000000000001";
|
13
|
+
exports.TWO_ADDRESS = "0x0000000000000000000000000000000000000002";
|
14
|
+
exports.NATIVE_TOKEN_ADDRESS = exports.ZERO_ADDRESS;
|
11
15
|
exports.CHAIN_CONFIGS = {};
|
12
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
|
@@ -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
|
}
|
@@ -35,7 +35,7 @@ export interface IOperationActions {
|
|
35
35
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
36
36
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
37
37
|
chainId: bigint;
|
38
|
-
|
38
|
+
address: string;
|
39
39
|
}, gasToken?: {
|
40
40
|
standardizedTokenId: string;
|
41
41
|
tokenSources?: {
|
package/dist/cjs/types.d.ts
CHANGED
@@ -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",
|
@@ -27,6 +31,7 @@ const initializeBlockchainInformation = async (orbyUrl) => {
|
|
27
31
|
constants_js_1.CHAIN_CONFIGS[Number(chainId)] = {
|
28
32
|
...blockchainInfo,
|
29
33
|
chainId: chainId,
|
34
|
+
nativeCurrency: currency_js_1.Currency.toCurrency(blockchainInfo?.nativeCurrency),
|
30
35
|
};
|
31
36
|
}
|
32
37
|
});
|
@@ -63,3 +68,24 @@ const hasError = (data) => {
|
|
63
68
|
return undefined;
|
64
69
|
};
|
65
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) {
|
@@ -37,7 +37,7 @@ export declare class OperationActions extends LibraryRequest {
|
|
37
37
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
38
38
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
39
39
|
chainId: bigint;
|
40
|
-
|
40
|
+
address: string;
|
41
41
|
}, gasToken?: {
|
42
42
|
standardizedTokenId: string;
|
43
43
|
tokenSources?: {
|
@@ -18,7 +18,7 @@ export class OperationActions extends LibraryRequest {
|
|
18
18
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
19
19
|
chainId: await this.getOrbyChainId(chainId),
|
20
20
|
address,
|
21
|
-
}))
|
21
|
+
}))),
|
22
22
|
}
|
23
23
|
: undefined;
|
24
24
|
const operationSet = await this.sendRequest("orby_getOperationsToExecuteTransaction", [
|
@@ -39,7 +39,7 @@ export class OperationActions extends LibraryRequest {
|
|
39
39
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
40
40
|
chainId: await this.getOrbyChainId(chainId),
|
41
41
|
address,
|
42
|
-
}))
|
42
|
+
}))),
|
43
43
|
}
|
44
44
|
: undefined;
|
45
45
|
const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
|
@@ -58,7 +58,7 @@ export class OperationActions extends LibraryRequest {
|
|
58
58
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
59
59
|
chainId: await this.getOrbyChainId(chainId),
|
60
60
|
address,
|
61
|
-
}))
|
61
|
+
}))),
|
62
62
|
}
|
63
63
|
: undefined;
|
64
64
|
const operationSet = await this.sendRequest("orby_getOperationsToSignTransactionOrSignTypedData", [
|
@@ -154,12 +154,12 @@ export class OperationActions extends LibraryRequest {
|
|
154
154
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
155
155
|
chainId: await this.getOrbyChainId(chainId),
|
156
156
|
address,
|
157
|
-
}))
|
157
|
+
}))),
|
158
158
|
}
|
159
159
|
: undefined;
|
160
160
|
const formattedRecepient = {
|
161
161
|
chainId: await this.getOrbyChainId(recipient.chainId),
|
162
|
-
|
162
|
+
address: recipient.address,
|
163
163
|
};
|
164
164
|
const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
|
165
165
|
{
|
@@ -179,7 +179,7 @@ export class OperationActions extends LibraryRequest {
|
|
179
179
|
tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
|
180
180
|
chainId: await this.getOrbyChainId(chainId),
|
181
181
|
address,
|
182
|
-
}))
|
182
|
+
}))),
|
183
183
|
}
|
184
184
|
: undefined;
|
185
185
|
const formattedOutput = output
|
@@ -199,7 +199,7 @@ export class OperationActions extends LibraryRequest {
|
|
199
199
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
200
200
|
chainId: await this.getOrbyChainId(chainId),
|
201
201
|
address,
|
202
|
-
}))
|
202
|
+
}))),
|
203
203
|
}
|
204
204
|
: undefined;
|
205
205
|
const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
|
@@ -220,7 +220,7 @@ export class OperationActions extends LibraryRequest {
|
|
220
220
|
tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
|
221
221
|
chainId: await this.getOrbyChainId(chainId),
|
222
222
|
address,
|
223
|
-
}))
|
223
|
+
}))),
|
224
224
|
}
|
225
225
|
: undefined;
|
226
226
|
const formattedOutput = output
|
@@ -261,7 +261,7 @@ export class OperationActions extends LibraryRequest {
|
|
261
261
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
262
262
|
chainId: await this.getOrbyChainId(chainId),
|
263
263
|
address,
|
264
|
-
}))
|
264
|
+
}))),
|
265
265
|
}
|
266
266
|
: undefined;
|
267
267
|
const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
|
package/dist/esm/constants.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import { Currency } from "./entities/financial/currency.js";
|
2
2
|
import { ChainConfigs } from "./types.js";
|
3
3
|
export declare const Big: any;
|
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";
|
4
8
|
export declare const CHAIN_CONFIGS: Record<number, ChainConfigs>;
|
5
9
|
export declare const FIAT_CURRENCY: Currency;
|
package/dist/esm/constants.js
CHANGED
@@ -2,5 +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 ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
6
|
+
export const ONE_ADDRESS = "0x0000000000000000000000000000000000000001";
|
7
|
+
export const TWO_ADDRESS = "0x0000000000000000000000000000000000000002";
|
8
|
+
export const NATIVE_TOKEN_ADDRESS = ZERO_ADDRESS;
|
5
9
|
export const CHAIN_CONFIGS = {};
|
6
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
|
@@ -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
|
}
|
@@ -35,7 +35,7 @@ export interface IOperationActions {
|
|
35
35
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
36
36
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
37
37
|
chainId: bigint;
|
38
|
-
|
38
|
+
address: string;
|
39
39
|
}, gasToken?: {
|
40
40
|
standardizedTokenId: string;
|
41
41
|
tokenSources?: {
|
package/dist/esm/types.d.ts
CHANGED
@@ -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/esm/utils/utils.js
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
import { CHAIN_CONFIGS } from "../constants.js";
|
1
|
+
import { CHAIN_CONFIGS, NATIVE_TOKEN_ADDRESS } from "../constants.js";
|
2
2
|
import { validateAndLowerCase } from "./validateAndParseAddress.js";
|
3
|
+
import { Currency } from "../entities/financial/currency.js";
|
4
|
+
import { FungibleToken } from "../entities/financial/fungible_token.js";
|
5
|
+
import { FungibleTokenAmount } from "../entities/financial/fungible_token_amount.js";
|
6
|
+
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
7
|
export const initializeBlockchainInformation = async (orbyUrl) => {
|
4
8
|
const response = await fetch(orbyUrl, {
|
5
9
|
method: "POST",
|
@@ -24,6 +28,7 @@ export const initializeBlockchainInformation = async (orbyUrl) => {
|
|
24
28
|
CHAIN_CONFIGS[Number(chainId)] = {
|
25
29
|
...blockchainInfo,
|
26
30
|
chainId: chainId,
|
31
|
+
nativeCurrency: Currency.toCurrency(blockchainInfo?.nativeCurrency),
|
27
32
|
};
|
28
33
|
}
|
29
34
|
});
|
@@ -56,3 +61,20 @@ export const hasError = (data) => {
|
|
56
61
|
}
|
57
62
|
return undefined;
|
58
63
|
};
|
64
|
+
export const getNativeCurrency = (chainId) => {
|
65
|
+
const currency = CHAIN_CONFIGS[Number(chainId)]?.nativeCurrency;
|
66
|
+
return new Currency(currency.decimals, currency.symbol, currency.name, undefined, false, false);
|
67
|
+
};
|
68
|
+
export const getNativeFungibleToken = (chainId) => {
|
69
|
+
const currency = getNativeCurrency(chainId);
|
70
|
+
return new FungibleToken(chainId, NATIVE_TOKEN_ADDRESS, currency.decimals, currency.symbol, currency.name, false, true, currency.coinGeckoId);
|
71
|
+
};
|
72
|
+
export const createNativeFungibleTokenAmount = (value, chainId) => {
|
73
|
+
const currency = getNativeCurrency(chainId);
|
74
|
+
const fungibleToken = new FungibleToken(chainId, NATIVE_TOKEN_ADDRESS, currency.decimals, currency.symbol, currency.name, false, true);
|
75
|
+
return FungibleTokenAmount.fromRawAmount(fungibleToken, value);
|
76
|
+
};
|
77
|
+
export const createNativeCurrencyAmount = (value, chainId) => {
|
78
|
+
const currency = getNativeCurrency(chainId);
|
79
|
+
return CurrencyAmount.fromRawAmount(currency, value);
|
80
|
+
};
|