@orb-labs/orby-core 0.0.2 → 0.0.3

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.
@@ -1,12 +1,12 @@
1
- import { Operation, OperationStatus, SignedOperation } from "../types";
1
+ import { OperationSet, OperationStatus, SignedOperation } from "../types";
2
2
  import { CurrencyAmount } from "../entities/financial/currency_amount";
3
3
  import { LIBRARY_TYPE, QuoteType } from "../enums";
4
4
  import { LibraryRequest } from "../entities/library_request";
5
5
  export declare class OperationActions extends LibraryRequest {
6
6
  constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
7
- getOperationsToExecuteTransaction(accountClusterId: string, to: string, data: string, value?: string): Promise<Operation[]>;
8
- getOperationsToSignTypedData(accountClusterId: string, data: string): Promise<Operation[]>;
9
- getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<Operation[]>;
7
+ getOperationsToExecuteTransaction(accountClusterId: string, to: string, data: string, value?: bigint): Promise<OperationSet>;
8
+ getOperationsToSignTypedData(accountClusterId: string, data: string): Promise<OperationSet>;
9
+ getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
10
10
  isTransactionPreconditionSatisfied(accountClusterId: string, to: string, data: string, value?: string): Promise<boolean>;
11
11
  isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
12
12
  sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
@@ -25,7 +25,7 @@ export declare class OperationActions extends LibraryRequest {
25
25
  chainId: bigint;
26
26
  address?: string;
27
27
  }[];
28
- }): Promise<Operation[]>;
28
+ }): Promise<OperationSet>;
29
29
  getOperationsToSwap(accountClusterId: string, swapType: QuoteType, input: {
30
30
  standardizedTokenId: string;
31
31
  amount?: number;
@@ -46,7 +46,7 @@ export declare class OperationActions extends LibraryRequest {
46
46
  chainId: bigint;
47
47
  address?: string;
48
48
  }[];
49
- }): Promise<Operation[]>;
49
+ }): Promise<OperationSet>;
50
50
  getQuote(accountClusterId: string, swapType: QuoteType, input: {
51
51
  standardizedTokenId: string;
52
52
  amount?: number;
@@ -61,7 +61,7 @@ export declare class OperationActions extends LibraryRequest {
61
61
  chainId: string;
62
62
  address?: string;
63
63
  };
64
- }): Promise<Operation[]>;
64
+ }): Promise<OperationSet>;
65
65
  getOperationsToBridge(accountClusterId: string, standardizedTokenId: string, amount: bigint, tokenSources?: {
66
66
  chainId: string;
67
67
  address?: string;
@@ -74,5 +74,5 @@ export declare class OperationActions extends LibraryRequest {
74
74
  chainId: bigint;
75
75
  address?: string;
76
76
  }[];
77
- }): Promise<Operation[]>;
77
+ }): Promise<OperationSet>;
78
78
  }
@@ -1,4 +1,6 @@
1
+ import { Currency } from "./entities/financial/currency";
1
2
  export declare const Big: any;
2
3
  export declare const BLOCKCHAIN_ID: {
3
4
  [s: string]: number;
4
5
  };
6
+ export declare const FIAT_CURRENCY: Currency;
package/dist/constants.js CHANGED
@@ -3,10 +3,11 @@ 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.BLOCKCHAIN_ID = exports.Big = void 0;
6
+ exports.FIAT_CURRENCY = exports.BLOCKCHAIN_ID = 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 enums_1 = require("./enums");
10
+ const currency_1 = require("./entities/financial/currency");
10
11
  exports.Big = (0, toformat_1.default)(big_js_1.default);
11
12
  exports.BLOCKCHAIN_ID = {
12
13
  [enums_1.Blockchain.ETHEREUM]: 1,
@@ -34,3 +35,4 @@ exports.BLOCKCHAIN_ID = {
34
35
  [enums_1.Blockchain.LOCAL_CHAIN_0]: 1000000000001,
35
36
  [enums_1.Blockchain.LOCAL_CHAIN_1]: 1000000000002,
36
37
  };
38
+ exports.FIAT_CURRENCY = new currency_1.Currency(6, "USD", "US Dollar", undefined, false, false);
@@ -1,5 +1,5 @@
1
1
  import JSBI from "jsbi";
2
- import { Fraction, BigintIsh } from "@uniswap/sdk-core";
2
+ import { Fraction, BigintIsh, Rounding } from "@uniswap/sdk-core";
3
3
  import { Currency } from "./currency";
4
4
  export declare class CurrencyAmount extends Fraction {
5
5
  readonly currency: Currency;
@@ -28,4 +28,7 @@ export declare class CurrencyAmount extends Fraction {
28
28
  toRawAmount(): bigint;
29
29
  toCurrencyValue(price: CurrencyAmount): CurrencyAmount;
30
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;
31
34
  }
@@ -8,6 +8,7 @@ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
8
8
  const jsbi_1 = __importDefault(require("jsbi"));
9
9
  const sdk_core_1 = require("@uniswap/sdk-core");
10
10
  const currency_1 = require("./currency");
11
+ const constants_1 = require("../../constants");
11
12
  // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
12
13
  // because we have a need to represent a currency amount that is not a fungible token amount.
13
14
  class CurrencyAmount extends sdk_core_1.Fraction {
@@ -77,5 +78,22 @@ class CurrencyAmount extends sdk_core_1.Fraction {
77
78
  fiatValue() {
78
79
  return this.amountInFiatCurrency;
79
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_1.Big.DP = this.currency.decimals;
94
+ return new constants_1.Big(this.quotient.toString())
95
+ .div(this.decimalScale.toString())
96
+ .toFormat(format);
97
+ }
80
98
  }
81
99
  exports.CurrencyAmount = CurrencyAmount;
@@ -1,5 +1,5 @@
1
1
  import JSBI from "jsbi";
2
- import { Fraction, BigintIsh } from "@uniswap/sdk-core";
2
+ import { Fraction, BigintIsh, Rounding } from "@uniswap/sdk-core";
3
3
  import { FungibleToken } from "./fungible_token";
4
4
  import { CurrencyAmount } from "./currency_amount";
5
5
  export declare class FungibleTokenAmount extends Fraction {
@@ -30,4 +30,7 @@ export declare class FungibleTokenAmount extends Fraction {
30
30
  toRawAmount(): bigint;
31
31
  fiatValue(): CurrencyAmount;
32
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;
33
36
  }
@@ -9,6 +9,7 @@ const jsbi_1 = __importDefault(require("jsbi"));
9
9
  const sdk_core_1 = require("@uniswap/sdk-core");
10
10
  const fungible_token_1 = require("./fungible_token");
11
11
  const currency_amount_1 = require("./currency_amount");
12
+ const constants_1 = require("../../constants");
12
13
  // This class is inspired by the Uniswap SDK's (@uniswap/sdk-core) CurrencyAmount class. Created this instance here
13
14
  // because we have a need to represent a currency amount that is not a fungible token amount.
14
15
  class FungibleTokenAmount extends sdk_core_1.Fraction {
@@ -80,5 +81,22 @@ class FungibleTokenAmount extends sdk_core_1.Fraction {
80
81
  this.amountInFiatCurrency = currency_amount_1.CurrencyAmount.fromFractionalAmount(price.currency, fraction.numerator, denominator);
81
82
  return this.amountInFiatCurrency;
82
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_1.Big.DP = this.token.decimals;
97
+ return new constants_1.Big(this.quotient.toString())
98
+ .div(this.decimalScale.toString())
99
+ .toFormat(format);
100
+ }
83
101
  }
84
102
  exports.FungibleTokenAmount = FungibleTokenAmount;
@@ -1,10 +1,10 @@
1
- import { Operation, OperationStatus, SignedOperation } from "../types";
1
+ import { OperationSet, OperationStatus, SignedOperation } from "../types";
2
2
  import { CurrencyAmount } from "../entities/financial/currency_amount";
3
3
  import { QuoteType } from "../enums";
4
4
  export interface IOperationActions {
5
- getOperationsToExecuteTransaction(accountClusterId: string, to: string, data: string, value?: string): Promise<Operation[]>;
6
- getOperationsToSignTypedData(accountClusterId: string, data: string): Promise<Operation[]>;
7
- getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<Operation[]>;
5
+ getOperationsToExecuteTransaction(accountClusterId: string, to: string, data: string, value?: bigint): Promise<OperationSet>;
6
+ getOperationsToSignTypedData(accountClusterId: string, data: string): Promise<OperationSet>;
7
+ getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
8
8
  isTransactionPreconditionSatisfied(accountClusterId: string, to: string, data: string, value?: string): Promise<boolean>;
9
9
  isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
10
10
  sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
@@ -23,7 +23,7 @@ export interface IOperationActions {
23
23
  chainId: bigint;
24
24
  address?: string;
25
25
  }[];
26
- }): Promise<Operation[]>;
26
+ }): Promise<OperationSet>;
27
27
  getOperationsToSwap(accountClusterId: string, swapType: QuoteType, input: {
28
28
  standardizedTokenId: string;
29
29
  amount?: number;
@@ -44,7 +44,7 @@ export interface IOperationActions {
44
44
  chainId: bigint;
45
45
  address?: string;
46
46
  }[];
47
- }): Promise<Operation[]>;
47
+ }): Promise<OperationSet>;
48
48
  getQuote(accountClusterId: string, swapType: QuoteType, input: {
49
49
  standardizedTokenId: string;
50
50
  amount?: number;
@@ -59,7 +59,7 @@ export interface IOperationActions {
59
59
  chainId: string;
60
60
  address?: string;
61
61
  };
62
- }): Promise<Operation[]>;
62
+ }): Promise<OperationSet>;
63
63
  getOperationsToBridge(accountClusterId: string, standardizedTokenId: string, amount: bigint, tokenSources?: {
64
64
  chainId: string;
65
65
  address?: string;
@@ -72,5 +72,5 @@ export interface IOperationActions {
72
72
  chainId: bigint;
73
73
  address?: string;
74
74
  }[];
75
- }): Promise<Operation[]>;
75
+ }): Promise<OperationSet>;
76
76
  }
package/dist/types.d.ts CHANGED
@@ -14,7 +14,7 @@ export type ChainEndpoint = {
14
14
  customRpcUrls?: string[];
15
15
  customIndexerUrls?: string[];
16
16
  };
17
- export interface Operation {
17
+ export interface OperationSet {
18
18
  status: CreateOperationsStatus;
19
19
  primaryOperation?: OnchainOperation;
20
20
  primaryOperationPreconditions?: State;
@@ -37,7 +37,7 @@ export interface OnchainOperation {
37
37
  data: string;
38
38
  estimatedNetworkFees?: CurrencyAmount;
39
39
  estimatedNetworkFeesInFiatCurrency?: CurrencyAmount;
40
- estimatedTimeInMs?: bigint;
40
+ estimatedTimeInMs?: number;
41
41
  format: OperationDataFormat;
42
42
  from?: string;
43
43
  gasLimit?: bigint;
@@ -1,7 +1,7 @@
1
1
  import { Blockchain } from "../enums";
2
- import { AccountCluster, Activity, AllowlistWithOpenFallback, BlockchainInformation, FungibleTokenOverview, GasSpendForInstance, GasSponsorshipData, GasSponsorshipPolicy, Intent, MaxAmountPerInterval, OnchainOperation, Operation, OperationStatus, StandardizedBalance, StandardizedToken } from "../types";
2
+ import { AccountCluster, Activity, AllowlistWithOpenFallback, BlockchainInformation, FungibleTokenOverview, GasSpendForInstance, GasSponsorshipData, GasSponsorshipPolicy, Intent, MaxAmountPerInterval, OnchainOperation, OperationSet, OperationStatus, StandardizedBalance, StandardizedToken } from "../types";
3
3
  export declare const extractAccountCluster: (accountCluster?: any) => AccountCluster;
4
- export declare const extractOperationSet: (operations?: any) => Operation[];
4
+ export declare const extractOperationSet: (operationSet?: any) => OperationSet;
5
5
  export declare const extractOnchainOperation: (onchainOperation?: any) => OnchainOperation;
6
6
  export declare const extractIntent: (intent?: any) => Intent;
7
7
  export declare const extractOperationStatuses: (operationStatus?: any[]) => OperationStatus[];
@@ -20,24 +20,22 @@ const extractAccountCluster = (accountCluster) => {
20
20
  };
21
21
  };
22
22
  exports.extractAccountCluster = extractAccountCluster;
23
- const extractOperationSet = (operations) => {
24
- if (!operations) {
23
+ const extractOperationSet = (operationSet) => {
24
+ var _a;
25
+ if (!operationSet) {
25
26
  return undefined;
26
27
  }
27
- return operations.map((operation) => {
28
- var _a;
29
- return {
30
- status: operation.status,
31
- primaryOperation: (0, exports.extractOnchainOperation)(operation.primaryOperation),
32
- primaryOperationPreconditions: state_1.State.toState(operation.primaryOperationPreconditions),
33
- inputState: state_1.State.toState(operation.inputState),
34
- outputState: state_1.State.toState(operation.outputState),
35
- intents: (_a = operation.intents) === null || _a === void 0 ? void 0 : _a.map((intent) => (0, exports.extractIntent)(intent)),
36
- aggregateNetworkFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operation.aggregateNetworkFeeInFiatCurrency),
37
- aggregateOperationFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operation.aggregateOperationFeeInFiatCurrency),
38
- aggregateEstimatedTimeInMs: operation.aggregateEstimatedTimeInMs,
39
- };
40
- });
28
+ return {
29
+ status: operationSet.status,
30
+ primaryOperation: (0, exports.extractOnchainOperation)(operationSet.primaryOperation),
31
+ primaryOperationPreconditions: state_1.State.toState(operationSet.primaryOperationPreconditions),
32
+ inputState: state_1.State.toState(operationSet.inputState),
33
+ outputState: state_1.State.toState(operationSet.outputState),
34
+ intents: (_a = operationSet.intents) === null || _a === void 0 ? void 0 : _a.map((intent) => (0, exports.extractIntent)(intent)),
35
+ aggregateNetworkFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operationSet.aggregateNetworkFeeInFiatCurrency),
36
+ aggregateOperationFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operationSet.aggregateOperationFeeInFiatCurrency),
37
+ aggregateEstimatedTimeInMs: operationSet.aggregateEstimatedTimeInMs,
38
+ };
41
39
  };
42
40
  exports.extractOperationSet = extractOperationSet;
43
41
  const extractOnchainOperation = (onchainOperation) => {
@@ -49,9 +47,7 @@ const extractOnchainOperation = (onchainOperation) => {
49
47
  data: onchainOperation.data,
50
48
  estimatedNetworkFees: currency_amount_1.CurrencyAmount.toCurrencyAmount(onchainOperation.estimatedNetworkFees),
51
49
  estimatedNetworkFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(onchainOperation.estimatedNetworkFeesInFiatCurrency),
52
- estimatedTimeInMs: onchainOperation.estimatedTimeInMs
53
- ? BigInt(onchainOperation.estimatedTimeInMs)
54
- : undefined,
50
+ estimatedTimeInMs: onchainOperation.estimatedTimeInMs,
55
51
  format: onchainOperation.format,
56
52
  from: onchainOperation.from,
57
53
  gasLimit: onchainOperation.gasLimit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orb-labs/orby-core",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "exports": {
5
5
  ".": "./dist/index.js"
6
6
  },