@jup-ag/plugin 1.0.12 → 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.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.12",
87
+ version: "1.0.13",
89
88
  private: false,
90
89
  license: "MIT",
91
90
  scripts: {
@@ -722,11 +721,30 @@ var formatNumber = {
722
721
  function shortenAddress(address, chars = 4) {
723
722
  return `${address.slice(0, chars)}...${address.slice(-chars)}`;
724
723
  }
725
- function readableValue(lamportsAmount, decimals) {
726
- 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
+ );
727
744
  }
728
- function fromLamports(lamportsAmount, decimals) {
729
- 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();
730
748
  }
731
749
  var detectedSeparator = formatNumber.format("1.1").substring(1, 2);
732
750
  function useDebounce(value, delay) {
@@ -1212,21 +1230,14 @@ var SwapContextProvider = (props) => {
1212
1230
  [form, debouncedForm]
1213
1231
  );
1214
1232
  const amount = (0, import_react7.useMemo)(() => {
1233
+ var _a3, _b2;
1215
1234
  if (!fromTokenInfo || !toTokenInfo) {
1216
1235
  return BigInt(0);
1217
1236
  }
1218
1237
  if (isToPairFocused.current === true) {
1219
- if (!debouncedForm.toValue || !hasNumericValue(debouncedForm.toValue)) {
1220
- return BigInt(0);
1221
- }
1222
- return 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);
1223
1239
  } else {
1224
- if (!debouncedForm.fromValue || !hasNumericValue(debouncedForm.fromValue)) {
1225
- return BigInt(0);
1226
- }
1227
- return BigInt(
1228
- new import_decimal2.default(debouncedForm.fromValue).mul(Math.pow(10, fromTokenInfo.decimals)).floor().toFixed()
1229
- );
1240
+ return (_b2 = parseUiAmount(debouncedForm.fromValue, fromTokenInfo)) != null ? _b2 : BigInt(0);
1230
1241
  }
1231
1242
  }, [debouncedForm.fromValue, debouncedForm.toValue, fromTokenInfo, toTokenInfo]);
1232
1243
  const [txStatus, setTxStatus] = (0, import_react7.useState)(void 0);
@@ -1309,9 +1320,9 @@ var SwapContextProvider = (props) => {
1309
1320
  if (!fromTokenInfo || !toTokenInfo) return prev;
1310
1321
  const { outAmount, inAmount } = (quoteResponseMeta == null ? void 0 : quoteResponseMeta.quoteResponse) || {};
1311
1322
  if (!isToPairFocused.current) {
1312
- newValue.toValue = outAmount ? new import_decimal2.default(outAmount.toString()).div(__pow(10, toTokenInfo.decimals)).toFixed() : "";
1323
+ newValue.toValue = outAmount ? formatUiAmount(outAmount, toTokenInfo) : "";
1313
1324
  } else {
1314
- newValue.fromValue = inAmount ? new import_decimal2.default(inAmount.toString()).div(__pow(10, fromTokenInfo.decimals)).toFixed() : "";
1325
+ newValue.fromValue = inAmount ? formatUiAmount(inAmount, fromTokenInfo) : "";
1315
1326
  }
1316
1327
  return newValue;
1317
1328
  });
@@ -1815,9 +1826,9 @@ var PrecisionTickSize_default = PrecisionTickSize;
1815
1826
 
1816
1827
  // src/components/ExchangeRate.tsx
1817
1828
  var import_jsx_runtime21 = require("react/jsx-runtime");
1818
- var calculateRate = ({ inAmount, inputDecimal, outAmount, outputDecimal }, reverse) => {
1819
- const input = fromLamports(inAmount, inputDecimal);
1820
- 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));
1821
1832
  const rate = !reverse ? new import_decimal5.default(input).div(output) : new import_decimal5.default(output).div(input);
1822
1833
  if (Number.isNaN(rate.toNumber())) {
1823
1834
  return new import_decimal5.default(0);
@@ -1947,10 +1958,10 @@ var Index = ({
1947
1958
  const rateParams = {
1948
1959
  inAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.inAmount) || BigInt(0),
1949
1960
  // If there's no selectedRoute, we will use first route value to temporarily calculate
1950
- inputDecimal: fromTokenInfo.decimals,
1961
+ inputAsset: fromTokenInfo,
1951
1962
  outAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.outAmount) || BigInt(0),
1952
1963
  // If there's no selectedRoute, we will use first route value to temporarily calculate
1953
- outputDecimal: toTokenInfo.decimals
1964
+ outputAsset: toTokenInfo
1954
1965
  };
1955
1966
  const priceImpact = formatNumber.format(
1956
1967
  new import_decimal6.default((quoteResponse == null ? void 0 : quoteResponse.quoteResponse.priceImpactPct) || 0).mul(100).toDP(2)
@@ -3398,13 +3409,13 @@ var SwappingScreen = () => {
3398
3409
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "mt-2 flex flex-col items-center justify-center text-center px-4", children: [
3399
3410
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "text-xs font-semibold text-primary-text", children: [
3400
3411
  "Swapped ",
3401
- readableValue(inputAmount, fromTokenInfo.decimals),
3412
+ formatUiAmount(inputAmount, fromTokenInfo),
3402
3413
  " ",
3403
3414
  fromTokenInfo.symbol,
3404
3415
  " to"
3405
3416
  ] }),
3406
3417
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "text-2xl font-semibold text-primary-text", children: [
3407
- readableValue(outputAmount, toTokenInfo.decimals),
3418
+ formatUiAmount(outputAmount, toTokenInfo),
3408
3419
  " ",
3409
3420
  toTokenInfo.symbol
3410
3421
  ] })