@jup-ag/plugin 1.0.11 → 1.0.13

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/dist/index.d.ts CHANGED
@@ -6,7 +6,6 @@ import { WalletContextState } from '@jup-ag/wallet-adapter';
6
6
  import * as superstruct from 'superstruct';
7
7
  import { Infer } from 'superstruct';
8
8
  import { PublicKey } from '@solana/web3.js';
9
- import JSBI from 'jsbi';
10
9
 
11
10
  declare const AGGREGATOR_SOURCES: {
12
11
  readonly METIS: "metis";
@@ -46,10 +45,10 @@ interface UltraQuoteResponse {
46
45
  declare const FormattedUltraQuoteResponse: superstruct.Struct<{
47
46
  inputMint: PublicKey;
48
47
  outputMint: PublicKey;
49
- inAmount: JSBI;
50
- outAmount: JSBI;
48
+ inAmount: bigint;
49
+ outAmount: bigint;
51
50
  feeBps: number;
52
- otherAmountThreshold: JSBI;
51
+ otherAmountThreshold: bigint;
53
52
  priceImpactPct: string;
54
53
  routePlan: {
55
54
  swapInfo: {
@@ -57,8 +56,8 @@ declare const FormattedUltraQuoteResponse: superstruct.Struct<{
57
56
  outputMint: string;
58
57
  label: string;
59
58
  ammKey: PublicKey;
60
- inAmount: JSBI;
61
- outAmount: JSBI;
59
+ inAmount: bigint;
60
+ outAmount: bigint;
62
61
  };
63
62
  percent: number;
64
63
  }[];
@@ -82,10 +81,10 @@ declare const FormattedUltraQuoteResponse: superstruct.Struct<{
82
81
  errorMessage?: string | undefined;
83
82
  }, {
84
83
  inputMint: superstruct.Struct<PublicKey, null>;
85
- inAmount: superstruct.Struct<JSBI, null>;
84
+ inAmount: superstruct.Struct<bigint, null>;
86
85
  outputMint: superstruct.Struct<PublicKey, null>;
87
- outAmount: superstruct.Struct<JSBI, null>;
88
- otherAmountThreshold: superstruct.Struct<JSBI, null>;
86
+ outAmount: superstruct.Struct<bigint, null>;
87
+ otherAmountThreshold: superstruct.Struct<bigint, null>;
89
88
  priceImpactPct: superstruct.Struct<string, null>;
90
89
  routePlan: superstruct.Struct<{
91
90
  swapInfo: {
@@ -93,8 +92,8 @@ declare const FormattedUltraQuoteResponse: superstruct.Struct<{
93
92
  outputMint: string;
94
93
  label: string;
95
94
  ammKey: PublicKey;
96
- inAmount: JSBI;
97
- outAmount: JSBI;
95
+ inAmount: bigint;
96
+ outAmount: bigint;
98
97
  };
99
98
  percent: number;
100
99
  }[], superstruct.Struct<{
@@ -103,8 +102,8 @@ declare const FormattedUltraQuoteResponse: superstruct.Struct<{
103
102
  outputMint: string;
104
103
  label: string;
105
104
  ammKey: PublicKey;
106
- inAmount: JSBI;
107
- outAmount: JSBI;
105
+ inAmount: bigint;
106
+ outAmount: bigint;
108
107
  };
109
108
  percent: number;
110
109
  }, {
@@ -113,15 +112,15 @@ declare const FormattedUltraQuoteResponse: superstruct.Struct<{
113
112
  outputMint: string;
114
113
  label: string;
115
114
  ammKey: PublicKey;
116
- inAmount: JSBI;
117
- outAmount: JSBI;
115
+ inAmount: bigint;
116
+ outAmount: bigint;
118
117
  }, {
119
118
  ammKey: superstruct.Struct<PublicKey, null>;
120
119
  label: superstruct.Struct<string, null>;
121
120
  inputMint: superstruct.Struct<string, null>;
122
121
  outputMint: superstruct.Struct<string, null>;
123
- inAmount: superstruct.Struct<JSBI, null>;
124
- outAmount: superstruct.Struct<JSBI, null>;
122
+ inAmount: superstruct.Struct<bigint, null>;
123
+ outAmount: superstruct.Struct<bigint, null>;
125
124
  }>;
126
125
  percent: superstruct.Struct<number, null>;
127
126
  }>>;
package/dist/index.js CHANGED
@@ -9,7 +9,6 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
9
  var __getProtoOf = Object.getPrototypeOf;
10
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
11
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __pow = Math.pow;
13
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
13
  var __spreadValues = (a, b) => {
15
14
  for (var prop in b || (b = {}))
@@ -85,7 +84,7 @@ var require_package = __commonJS({
85
84
  "package.json"(exports2, module2) {
86
85
  module2.exports = {
87
86
  name: "@jup-ag/plugin",
88
- version: "1.0.11",
87
+ version: "1.0.13",
89
88
  private: false,
90
89
  license: "MIT",
91
90
  scripts: {
@@ -637,7 +636,6 @@ var ScreenProvider = ({ children }) => {
637
636
 
638
637
  // src/contexts/SwapContext.tsx
639
638
  var import_decimal2 = __toESM(require("decimal.js"));
640
- var import_jsbi2 = __toESM(require("jsbi"));
641
639
  var import_react7 = require("react");
642
640
 
643
641
  // src/constants/index.ts
@@ -723,11 +721,30 @@ var formatNumber = {
723
721
  function shortenAddress(address, chars = 4) {
724
722
  return `${address.slice(0, chars)}...${address.slice(-chars)}`;
725
723
  }
726
- function readableValue(lamportsAmount, decimals) {
727
- return new import_decimal.default(lamportsAmount.toString()).div(__pow(10, decimals)).toDP(decimals, import_decimal.default.ROUND_DOWN).toFixed();
724
+ function getEffectiveMultiplier(config) {
725
+ var _a2;
726
+ const { scaledUiConfig } = config;
727
+ if (!scaledUiConfig) return 1;
728
+ if (scaledUiConfig.newMultiplier && scaledUiConfig.newMultiplierEffectiveAt) {
729
+ const effectiveDate = new Date(scaledUiConfig.newMultiplierEffectiveAt);
730
+ if (/* @__PURE__ */ new Date() >= effectiveDate) {
731
+ return scaledUiConfig.newMultiplier;
732
+ }
733
+ }
734
+ return (_a2 = scaledUiConfig.multiplier) != null ? _a2 : 1;
735
+ }
736
+ function parseUiAmount(value, asset) {
737
+ if (!value || !hasNumericValue(value)) {
738
+ return void 0;
739
+ }
740
+ const multiplier = getEffectiveMultiplier(asset);
741
+ return BigInt(
742
+ new import_decimal.default(value).div(multiplier).mul(Math.pow(10, asset.decimals)).floor().toFixed()
743
+ );
728
744
  }
729
- function fromLamports(lamportsAmount, decimals) {
730
- return new import_decimal.default(lamportsAmount.toString()).div(__pow(10, decimals)).toDP(decimals, import_decimal.default.ROUND_DOWN).toNumber();
745
+ function formatUiAmount(rawAmount, asset) {
746
+ const multiplier = getEffectiveMultiplier(asset);
747
+ return new import_decimal.default(rawAmount.toString()).div(Math.pow(10, asset.decimals)).mul(multiplier).toFixed();
731
748
  }
732
749
  var detectedSeparator = formatNumber.format("1.1").substring(1, 2);
733
750
  function useDebounce(value, delay) {
@@ -979,10 +996,9 @@ var ultraSwapService = new UltraSwapService();
979
996
 
980
997
  // src/entity/FormattedUltraQuoteResponse.ts
981
998
  var import_web33 = require("@solana/web3.js");
982
- var import_jsbi = __toESM(require("jsbi"));
983
999
  var import_superstruct = require("superstruct");
984
1000
  var PublicKeyFromString = (0, import_superstruct.coerce)((0, import_superstruct.instance)(import_web33.PublicKey), (0, import_superstruct.string)(), (value) => new import_web33.PublicKey(value));
985
- var AmountFromString = (0, import_superstruct.coerce)((0, import_superstruct.instance)(import_jsbi.default), (0, import_superstruct.string)(), (value) => import_jsbi.default.BigInt(value));
1001
+ var AmountFromString = (0, import_superstruct.coerce)((0, import_superstruct.bigint)(), (0, import_superstruct.string)(), (value) => BigInt(value));
986
1002
  var NumberFromString = (0, import_superstruct.coerce)((0, import_superstruct.string)(), (0, import_superstruct.number)(), (value) => Number(value));
987
1003
  var SwapInfo = (0, import_superstruct.type)({
988
1004
  ammKey: PublicKeyFromString,
@@ -1214,21 +1230,14 @@ var SwapContextProvider = (props) => {
1214
1230
  [form, debouncedForm]
1215
1231
  );
1216
1232
  const amount = (0, import_react7.useMemo)(() => {
1233
+ var _a3, _b2;
1217
1234
  if (!fromTokenInfo || !toTokenInfo) {
1218
- return import_jsbi2.default.BigInt(0);
1235
+ return BigInt(0);
1219
1236
  }
1220
1237
  if (isToPairFocused.current === true) {
1221
- if (!debouncedForm.toValue || !hasNumericValue(debouncedForm.toValue)) {
1222
- return import_jsbi2.default.BigInt(0);
1223
- }
1224
- return import_jsbi2.default.BigInt(new import_decimal2.default(debouncedForm.toValue).mul(Math.pow(10, toTokenInfo.decimals)).floor().toFixed());
1238
+ return (_a3 = parseUiAmount(debouncedForm.toValue, toTokenInfo)) != null ? _a3 : BigInt(0);
1225
1239
  } else {
1226
- if (!debouncedForm.fromValue || !hasNumericValue(debouncedForm.fromValue)) {
1227
- return import_jsbi2.default.BigInt(0);
1228
- }
1229
- return import_jsbi2.default.BigInt(
1230
- new import_decimal2.default(debouncedForm.fromValue).mul(Math.pow(10, fromTokenInfo.decimals)).floor().toFixed()
1231
- );
1240
+ return (_b2 = parseUiAmount(debouncedForm.fromValue, fromTokenInfo)) != null ? _b2 : BigInt(0);
1232
1241
  }
1233
1242
  }, [debouncedForm.fromValue, debouncedForm.toValue, fromTokenInfo, toTokenInfo]);
1234
1243
  const [txStatus, setTxStatus] = (0, import_react7.useState)(void 0);
@@ -1311,9 +1320,9 @@ var SwapContextProvider = (props) => {
1311
1320
  if (!fromTokenInfo || !toTokenInfo) return prev;
1312
1321
  const { outAmount, inAmount } = (quoteResponseMeta == null ? void 0 : quoteResponseMeta.quoteResponse) || {};
1313
1322
  if (!isToPairFocused.current) {
1314
- newValue.toValue = outAmount ? new import_decimal2.default(outAmount.toString()).div(__pow(10, toTokenInfo.decimals)).toFixed() : "";
1323
+ newValue.toValue = outAmount ? formatUiAmount(outAmount, toTokenInfo) : "";
1315
1324
  } else {
1316
- newValue.fromValue = inAmount ? new import_decimal2.default(inAmount.toString()).div(__pow(10, fromTokenInfo.decimals)).toFixed() : "";
1325
+ newValue.fromValue = inAmount ? formatUiAmount(inAmount, fromTokenInfo) : "";
1317
1326
  }
1318
1327
  return newValue;
1319
1328
  });
@@ -1772,7 +1781,6 @@ var CoinBalanceUSD = (props) => {
1772
1781
 
1773
1782
  // src/components/PriceInfo/index.tsx
1774
1783
  var import_decimal6 = __toESM(require("decimal.js"));
1775
- var import_jsbi3 = __toESM(require("jsbi"));
1776
1784
  var import_react14 = require("react");
1777
1785
 
1778
1786
  // src/components/ExchangeRate.tsx
@@ -1818,9 +1826,9 @@ var PrecisionTickSize_default = PrecisionTickSize;
1818
1826
 
1819
1827
  // src/components/ExchangeRate.tsx
1820
1828
  var import_jsx_runtime21 = require("react/jsx-runtime");
1821
- var calculateRate = ({ inAmount, inputDecimal, outAmount, outputDecimal }, reverse) => {
1822
- const input = fromLamports(inAmount, inputDecimal);
1823
- const output = fromLamports(outAmount, outputDecimal);
1829
+ var calculateRate = ({ inAmount, inputAsset, outAmount, outputAsset }, reverse) => {
1830
+ const input = new import_decimal5.default(formatUiAmount(inAmount, inputAsset));
1831
+ const output = new import_decimal5.default(formatUiAmount(outAmount, outputAsset));
1824
1832
  const rate = !reverse ? new import_decimal5.default(input).div(output) : new import_decimal5.default(output).div(input);
1825
1833
  if (Number.isNaN(rate.toNumber())) {
1826
1834
  return new import_decimal5.default(0);
@@ -1948,12 +1956,12 @@ var Index = ({
1948
1956
  containerClassName
1949
1957
  }) => {
1950
1958
  const rateParams = {
1951
- inAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.inAmount) || import_jsbi3.default.BigInt(0),
1959
+ inAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.inAmount) || BigInt(0),
1952
1960
  // If there's no selectedRoute, we will use first route value to temporarily calculate
1953
- inputDecimal: fromTokenInfo.decimals,
1954
- outAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.outAmount) || import_jsbi3.default.BigInt(0),
1961
+ inputAsset: fromTokenInfo,
1962
+ outAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.outAmount) || BigInt(0),
1955
1963
  // If there's no selectedRoute, we will use first route value to temporarily calculate
1956
- outputDecimal: toTokenInfo.decimals
1964
+ outputAsset: toTokenInfo
1957
1965
  };
1958
1966
  const priceImpact = formatNumber.format(
1959
1967
  new import_decimal6.default((quoteResponse == null ? void 0 : quoteResponse.quoteResponse.priceImpactPct) || 0).mul(100).toDP(2)
@@ -1982,7 +1990,7 @@ var Index = ({
1982
1990
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: cn("mt-4 space-y-4 ", containerClassName), children: [
1983
1991
  /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center justify-between text-xs", children: [
1984
1992
  /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-primary-text/50", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: "Rate" }) }),
1985
- import_jsbi3.default.greaterThan(rateParams.inAmount, import_jsbi3.default.BigInt(0)) && import_jsbi3.default.greaterThan(rateParams.outAmount, import_jsbi3.default.BigInt(0)) ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1993
+ rateParams.inAmount > BigInt(0) && rateParams.outAmount > BigInt(0) ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1986
1994
  ExchangeRate_default,
1987
1995
  {
1988
1996
  loading,
@@ -3401,13 +3409,13 @@ var SwappingScreen = () => {
3401
3409
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "mt-2 flex flex-col items-center justify-center text-center px-4", children: [
3402
3410
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "text-xs font-semibold text-primary-text", children: [
3403
3411
  "Swapped ",
3404
- readableValue(inputAmount, fromTokenInfo.decimals),
3412
+ formatUiAmount(inputAmount, fromTokenInfo),
3405
3413
  " ",
3406
3414
  fromTokenInfo.symbol,
3407
3415
  " to"
3408
3416
  ] }),
3409
3417
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "text-2xl font-semibold text-primary-text", children: [
3410
- readableValue(outputAmount, toTokenInfo.decimals),
3418
+ formatUiAmount(outputAmount, toTokenInfo),
3411
3419
  " ",
3412
3420
  toTokenInfo.symbol
3413
3421
  ] })