@goodaofi/bonds-sdk 3.0.174 → 3.0.176

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/main.js CHANGED
@@ -65519,9 +65519,6 @@ function useCurrencyPrice(currency, chainId) {
65519
65519
  chainId: chainId,
65520
65520
  };
65521
65521
  }
65522
- console.log('tokenPrices: ', tokenPrices?.find((tokenPrice) => chainId &&
65523
- tokenPrice.chainId === chainId &&
65524
- tokenPrice?.address?.toLowerCase() === tokenAddress?.toLowerCase()));
65525
65522
  return tokenPrices?.find((tokenPrice) => chainId &&
65526
65523
  tokenPrice.chainId === chainId &&
65527
65524
  tokenPrice?.address?.toLowerCase() === tokenAddress?.toLowerCase());
@@ -65977,7 +65974,6 @@ const YourBondsModal = ({ onDismiss, bill }) => {
65977
65974
  const lastBlockTimestamp = parseInt(userBill?.lastBlockTimestamp ?? '0');
65978
65975
  const isPendingCliff = vestingCliff ? currentTime - lastBlockTimestamp < vestingCliff : false;
65979
65976
  const cliffCountdown = getTimePeriods(lastBlockTimestamp + (vestingCliff ?? 0) - currentTime, true);
65980
- const showImage = false;
65981
65977
  const handleClaim = async (billId, billAddress) => {
65982
65978
  const address = billAddress;
65983
65979
  const isVestingNft = billAddress?.toLowerCase() === VESTING_NFT_ADDRESS.toLowerCase();
@@ -66031,7 +66027,10 @@ const YourBondsModal = ({ onDismiss, bill }) => {
66031
66027
  };
66032
66028
  const earnTokenPrice = useCurrencyPrice(userBill?.bond?.earnToken ?? null, userBill?.bond?.chainId ?? null);
66033
66029
  const BILL_ATTRIBUTES = ['The Legend', 'The Location', 'The Moment', 'The Trend', 'The Innovation'];
66034
- bondNFTData?.attributes?.filter((attrib) => BILL_ATTRIBUTES.includes(attrib.trait_type));
66030
+ const attributes = bondNFTData?.attributes?.filter((attrib) => BILL_ATTRIBUTES.includes(attrib.trait_type));
66031
+ const handleImageLoad = () => {
66032
+ setImgLoaded(true);
66033
+ };
66035
66034
  const [onTransferBondModal] = useModal(jsx$2(TransferBondModal, { userBill: userBill }), true, true, `transferModal${userBill?.id}}`);
66036
66035
  useEffect(() => {
66037
66036
  if (isConfirmed) {
@@ -66040,9 +66039,32 @@ const YourBondsModal = ({ onDismiss, bill }) => {
66040
66039
  }
66041
66040
  /* eslint-disable react-hooks/exhaustive-deps */
66042
66041
  }, [isConfirmed]);
66043
- return (jsx$2(Modal, { className: "modal", children: jsxs(Flex$1, { className: "yourbondsmodal-content", children: [jsx$2(Flex$1, { className: "yourbondsmodal-header", children: jsx$2(Flex$1, { className: "svg-close", onClick: onDismiss, children: jsx$2(Svg, { icon: "close" }) }) }), jsxs(Flex$1, { className: "yourbondsmodal table-container", children: [showImage, jsxs(Flex$1, { className: "yourbondsmodal yourbondinfo", children: [jsxs(Flex$1, { className: "yourbondinfo title-container", children: [jsx$2(Flex$1, { className: "title-container bondicon", children: userBill && (jsx$2(TokenImage, { symbol: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken?.symbol, size: 40, chain: userBill?.bond?.chainId })) }), jsx$2(Flex$1, { className: "title-container tokenname", children: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken.symbol }), jsx$2(Flex$1, { className: "title-container tokentags", children: userBill?.bond?.tags?.slice(0, 1).map((tag) => {
66042
+ return (jsx$2(Modal, { className: "modal", children: jsxs(Flex$1, { className: "yourbondsmodal-content", children: [jsx$2(Flex$1, { className: "yourbondsmodal-header", children: jsx$2(Flex$1, { className: "svg-close", onClick: onDismiss, children: jsx$2(Svg, { icon: "close" }) }) }), jsxs(Flex$1, { className: "yourbondsmodal table-container", children: [(jsxs(Flex$1, { className: "yourbondsmodal bondimage", children: [bondNFTData?.image && (jsx$2("img", { src: `${bondNFTData?.image}?img-width=720`, onLoad: handleImageLoad, style: { zIndex: 2 } })), !imgLoaded && (jsx$2(Flex$1, { sx: {
66043
+ position: 'absolute',
66044
+ top: 'calc(50% - 24px)',
66045
+ right: 'calc(50% - 50px)',
66046
+ justifyContent: 'center',
66047
+ alignItems: 'center',
66048
+ zIndex: 1,
66049
+ }, children: jsx$2(Spinner, { width: 100 }) }))] })), jsxs(Flex$1, { className: "yourbondsmodal yourbondinfo", children: [jsxs(Flex$1, { className: "yourbondinfo title-container", children: [jsx$2(Flex$1, { className: "title-container bondicon", children: userBill && (jsx$2(TokenImage, { symbol: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken?.symbol, size: 40, chain: userBill?.bond?.chainId })) }), jsx$2(Flex$1, { className: "title-container tokenname", children: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken.symbol }), jsx$2(Flex$1, { className: "title-container tokentags", children: userBill?.bond?.tags?.slice(0, 1).map((tag) => {
66044
66050
  return (jsx$2(Flex$1, { sx: { marginRight: '10px' }, children: jsx$2(ListTag, { text: tag?.toUpperCase() }) }, tag));
66045
- }) }), jsxs(Text, { sx: { color: 'text', opacity: '0.6', fontSize: ['12px', '12px', '12px', '16px'] }, children: ["#", userBill?.id] })] }), jsxs(Flex$1, { className: "yourbondinfo blocks-container", children: [showImage, bondNFTData?.data?.deposit && (jsxs(Flex$1, { className: "yourbondinfo-block row-vested", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "You Spent" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.YouSpent }), width: "270px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsx$2(Flex$1, { className: "yourbondinfo-block info", children: jsx$2(Flex$1, { className: "block-info text", children: jsxs(Text, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: ["$", bondNFTData?.data?.dollarValue.toFixed(2)] }) }) })] })), jsxs(Flex$1, { className: "yourbondinfo-block row-vested", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "Fully Vested" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.FullyVested }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsxs(Flex$1, { className: "yourbondinfo-block info", children: [jsx$2(Flex$1, { className: "block-info icon" }), jsx$2(Flex$1, { className: "block-info text", children: jsxs(Flex$1, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: [vestingTimeRemainingString(userBill), isPendingCliff && (jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsxs(Flex$1, { children: ["Bond will be claimable in", ' ', `${cliffCountdown.days !== 0 ? `${cliffCountdown.days} days` : cliffCountdown.hours !== 0 ? `${cliffCountdown.hours} hours` : `${cliffCountdown.minutes} mins`}`, "."] }), width: "180px", placement: "bottomRight", transformTip: "translate(13%, 0%)", children: jsx$2(Flex$1, { sx: { opacity: 0.6, ml: '6px' }, children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }))] }) })] })] }), jsxs(Flex$1, { className: "yourbondinfo-block row-pending", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "Pending" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.Pending }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsxs(Flex$1, { className: "yourbondinfo-block info", children: [jsx$2(Flex$1, { className: "block-info icon", children: userBill && (jsx$2(TokenImage, { symbol: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken?.symbol, size: 25, chain: userBill?.bond?.chainId })) }), jsxs(Flex$1, { className: "block-info text", children: [jsx$2(Text, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: formatNumberSI(parseFloat(totalPending(userBill).toFixed(4)), 4) }), jsx$2(Text, { sx: {
66051
+ }) }), jsxs(Text, { sx: { color: 'text', opacity: '0.6', fontSize: ['12px', '12px', '12px', '16px'] }, children: ["#", userBill?.id] })] }), jsxs(Flex$1, { className: "yourbondinfo blocks-container", children: [(jsxs(Flex$1, { className: "attributes-container", children: [jsxs(Flex$1, { className: "attributes-header", sx: {
66052
+ borderRadius: `${isOpenTraits ? '6px 6px 0px 0px' : 'normal'}`,
66053
+ }, onClick: () => setIsOpenTraits(!isOpenTraits), children: [jsxs(Flex$1, { sx: { gap: '10px', alignItems: 'center' }, children: [jsx$2(Svg, { icon: "tag", direction: "down" }), jsx$2(Text, { sx: { fontSize: '12px', fontWeight: 400, color: 'text', opacity: '0.6' }, children: "Traits" })] }), jsx$2(Svg, { icon: "caret", direction: isOpenTraits ? 'up' : 'down' })] }), userBill?.bond?.billType === 'staking' && (jsxs(Flex$1, { sx: {
66054
+ p: '5px 10px',
66055
+ width: '100%',
66056
+ background: '#8E568F',
66057
+ borderRadius: 'normal',
66058
+ mt: '10px',
66059
+ fontSize: '12px',
66060
+ fontWeight: 400,
66061
+ justifyContent: 'center',
66062
+ display: 'block',
66063
+ }, children: ["Tokens bought through this bond went directly to the", ' ', jsx$2("span", { onClick: () => window.open('https://basepad.finance/earn', '_blank'), style: { textDecoration: 'underline', cursor: 'pointer', color: 'blue' }, children: "$BPAD staking pool" }), ' ', "with a 365 days lock."] })), jsx$2(AnimatePresence, { children: isOpenTraits && (jsx$2(motion.div, { initial: { height: 0 }, animate: { height: 'fit-content' }, transition: { opacity: { duration: 0.2 } }, exit: { height: 0 }, sx: { overflow: 'hidden', width: '100%' }, children: jsx$2(Flex$1, { sx: { flexDirection: 'column', gap: '1px' }, children: attributes
66064
+ ? attributes.map((a) => (jsxs(Flex$1, { sx: { background: 'white4', width: '100%', padding: '2px 8px' }, children: [jsx$2(Text, { sx: { fontSize: '10px', fontWeight: 500 }, children: a?.trait_type }), jsx$2(Text, { sx: { fontSize: '10px', fontWeight: 500 }, children: a?.value })] }, a.value)))
66065
+ : BILL_ATTRIBUTES.map((attrib) => {
66066
+ return (jsxs(Flex$1, { sx: { background: 'white4', width: '100%', padding: '2px 8px' }, children: [jsx$2(Text, { sx: { fontSize: '10px', fontWeight: 500 }, children: attrib }), jsx$2(Skeleton, { width: "150px" })] }, attrib));
66067
+ }) }) })) })] })), bondNFTData?.data?.deposit && (jsxs(Flex$1, { className: "yourbondinfo-block row-vested", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "You Spent" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.YouSpent }), width: "270px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsx$2(Flex$1, { className: "yourbondinfo-block info", children: jsx$2(Flex$1, { className: "block-info text", children: jsxs(Text, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: ["$", bondNFTData?.data?.dollarValue.toFixed(2)] }) }) })] })), jsxs(Flex$1, { className: "yourbondinfo-block row-vested", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "Fully Vested" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.FullyVested }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsxs(Flex$1, { className: "yourbondinfo-block info", children: [jsx$2(Flex$1, { className: "block-info icon" }), jsx$2(Flex$1, { className: "block-info text", children: jsxs(Flex$1, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: [vestingTimeRemainingString(userBill), isPendingCliff && (jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsxs(Flex$1, { children: ["Bond will be claimable in", ' ', `${cliffCountdown.days !== 0 ? `${cliffCountdown.days} days` : cliffCountdown.hours !== 0 ? `${cliffCountdown.hours} hours` : `${cliffCountdown.minutes} mins`}`, "."] }), width: "180px", placement: "bottomRight", transformTip: "translate(13%, 0%)", children: jsx$2(Flex$1, { sx: { opacity: 0.6, ml: '6px' }, children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }))] }) })] })] }), jsxs(Flex$1, { className: "yourbondinfo-block row-pending", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "Pending" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.Pending }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsxs(Flex$1, { className: "yourbondinfo-block info", children: [jsx$2(Flex$1, { className: "block-info icon", children: userBill && (jsx$2(TokenImage, { symbol: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken?.symbol, size: 25, chain: userBill?.bond?.chainId })) }), jsxs(Flex$1, { className: "block-info text", children: [jsx$2(Text, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: formatNumberSI(parseFloat(totalPending(userBill).toFixed(4)), 4) }), jsx$2(Text, { sx: {
66046
66068
  fontSize: ['10px', '10px', '10px', '12px'],
66047
66069
  fontWeight: [500, 500, 500, 400],
66048
66070
  paddingLeft: '10px',
@@ -73122,7 +73144,7 @@ const useSoulZapTokenQuote = (typedValue, inputCurrency, outputToken, chainId, a
73122
73144
  const contractAddress = outputToken?.address[chainId];
73123
73145
  const chain = getChainParam(chainId);
73124
73146
  const isLP = outputToken?.lpToken ?? false;
73125
- const liquidityDex = outputToken?.liquidityDex?.[chainId];
73147
+ const liquidityDex = outputToken?.liquiditySource?.[chainId] ?? outputToken?.liquidityDex?.[chainId];
73126
73148
  const protocol = main.dexFactories[chainId]?.[liquidityDex]?.protocol;
73127
73149
  const lpType = outputToken?.lpToken ? getLpType(protocol) : 'single';
73128
73150
  const ichiUnderlyingDex = outputToken?.ichiUnderlyingDex;
@@ -73223,6 +73245,139 @@ const useSoulZapTokenQuote = (typedValue, inputCurrency, outputToken, chainId, a
73223
73245
  return [isLoading, response, estimateOutput, zapError];
73224
73246
  };
73225
73247
 
73248
+ const useSoulZapBondQuote = (typedValue, inputCurrency, bond, account, tierProofSig) => {
73249
+ const debouncedInput = useDebounce(typedValue, 400);
73250
+ const [slippage] = useSlippage();
73251
+ const principalToken = bond?.lpToken;
73252
+ const bondContractAddress = bond?.contractAddress[bond?.chainId];
73253
+ const chainId = bond?.chainId;
73254
+ const inputCurrencyString = inputCurrency === 'NATIVE' ? '0x0000000000000000000000000000000000000000' : inputCurrency?.address[chainId];
73255
+ const inputCurrencyDecimals = inputCurrency === 'NATIVE' ? 18 : inputCurrency?.decimals[chainId];
73256
+ const principalContractAddress = principalToken?.address[chainId];
73257
+ const chainName = getChainParam(chainId);
73258
+ const isReserveBond = bond?.billType === 'reserve' || bond?.billType === 'staking';
73259
+ const liquidityDex = principalToken?.liquiditySource?.[chainId] ?? principalToken?.liquidityDex?.[chainId];
73260
+ const protocol = main.dexFactories[chainId]?.[liquidityDex]?.protocol;
73261
+ const lpType = isReserveBond ? 'single' : getLpType(protocol);
73262
+ const ichiUnderlyingDex = principalToken?.ichiUnderlyingDex;
73263
+ const vault = principalToken?.address?.[chainId];
73264
+ const router = main.dexFactories[chainId]?.[liquidityDex]?.router;
73265
+ // Validates that the user did not pass an amount with 19 decimals or more
73266
+ const validated18DecimalAmount = new BigNumber$1(debouncedInput ?? '0').toFixed(18, 5);
73267
+ const bigishInputAmount = new BigNumber$1(validated18DecimalAmount ?? '0')
73268
+ .times(new BigNumber$1(10).pow(inputCurrencyDecimals ?? 18))
73269
+ .toString();
73270
+ const zapInputData = useMemo(() => {
73271
+ if (inputCurrencyString &&
73272
+ inputCurrencyDecimals &&
73273
+ bigishInputAmount !== 'NaN' &&
73274
+ bigishInputAmount !== '0' &&
73275
+ principalContractAddress &&
73276
+ chainName &&
73277
+ bondContractAddress &&
73278
+ (inputCurrency === 'NATIVE' || inputCurrency?.address[chainId] !== principalToken.address[chainId])) {
73279
+ return {
73280
+ chain: chainName,
73281
+ recipient: account ?? '0x0000000000000000000000000000000000000000',
73282
+ user: account ?? '0x0000000000000000000000000000000000000000',
73283
+ lpData: {
73284
+ lpType,
73285
+ fromToken: inputCurrencyString,
73286
+ fromAmount: bigishInputAmount,
73287
+ underlyingDex: ichiUnderlyingDex,
73288
+ vault: isReserveBond ? undefined : vault,
73289
+ slippage: slippage,
73290
+ lpAddress: lpType === 'solidly' || lpType === 'univ2' || lpType === 'curve' ? vault : undefined,
73291
+ router: lpType === 'solidly' || lpType === 'univ2' ? router : undefined,
73292
+ toToken: isReserveBond ? vault : undefined,
73293
+ },
73294
+ protocolData: {
73295
+ protocol: 'ApeBond',
73296
+ bond: bondContractAddress,
73297
+ depositer: account ?? '0x0000000000000000000000000000000000000000',
73298
+ tierProofSignature: bond.billVersion === main.BillVersion.V4 && tierProofSig ? tierProofSig : undefined,
73299
+ },
73300
+ };
73301
+ }
73302
+ else {
73303
+ return null;
73304
+ }
73305
+ /* eslint-disable react-hooks/exhaustive-deps */
73306
+ }, [
73307
+ bigishInputAmount,
73308
+ principalContractAddress,
73309
+ chainName,
73310
+ account,
73311
+ ichiUnderlyingDex,
73312
+ vault,
73313
+ lpType,
73314
+ router,
73315
+ slippage,
73316
+ ]);
73317
+ const queryKey = useMemo(() => {
73318
+ if (!zapInputData)
73319
+ return null;
73320
+ return [
73321
+ 'zapBondDetails',
73322
+ zapInputData.chain,
73323
+ zapInputData.user,
73324
+ zapInputData.lpData.lpType,
73325
+ zapInputData.lpData.fromToken,
73326
+ zapInputData.lpData.fromAmount,
73327
+ zapInputData.lpData.underlyingDex ?? '',
73328
+ zapInputData.lpData.vault,
73329
+ zapInputData.lpData.slippage,
73330
+ zapInputData.lpData.lpAddress,
73331
+ zapInputData.lpData.router ?? '',
73332
+ ];
73333
+ }, [zapInputData]);
73334
+ const fetchZapDetails = async () => {
73335
+ const response = await axios.post(SOUL_ZAP_API, {
73336
+ '0': zapInputData,
73337
+ });
73338
+ return response.data?.[0]?.result?.data;
73339
+ };
73340
+ const { data: response, isLoading, isFetching, error, } = useQuery({
73341
+ queryKey: [QUERY_KEYS.ZAP_TOKEN_QUOTE, queryKey],
73342
+ queryFn: fetchZapDetails,
73343
+ refetchInterval: 60000, // i.e. 60 sec
73344
+ enabled: !!queryKey,
73345
+ retry: 1,
73346
+ });
73347
+ const zapError = !!error;
73348
+ const tokenList = zapInputTokens[chainId] ? zapInputTokens[chainId] : [];
73349
+ // toToken0 data
73350
+ const toToken0Estimate = response?.lpQuote?.token0?.fromAmountEstimate;
73351
+ const toToken0 = [...tokenList, principalToken]?.find((token) => token?.address?.[chainId]?.toLowerCase() === response?.lpQuote?.token0?.address?.toLowerCase());
73352
+ const toToken0Price = useCurrencyPrice(toToken0 ?? null, chainId);
73353
+ // toToken1 data
73354
+ const toToken1Estimate = response?.lpQuote?.token1?.fromAmountEstimate;
73355
+ const toToken1 = zapInputTokens[chainId]?.find((token) => token.address[chainId]?.toLowerCase() === response?.lpQuote?.token1?.address?.toLowerCase());
73356
+ const toToken1Price = useCurrencyPrice(toToken1 ?? null, chainId);
73357
+ let toToken0USD = new BigNumber$1(toToken0Estimate ?? '0')
73358
+ ?.div(new BigNumber$1(10).pow(toToken0?.decimals[chainId] ?? 18)) // this is amount of swap output
73359
+ ?.times(new BigNumber$1(toToken0Price?.price ?? 0)); // convert it to usd price
73360
+ if (response?.lpQuote?.token0?.fromAmountUSD) {
73361
+ toToken0USD = new BigNumber$1(response?.lpQuote?.token0?.fromAmountUSD);
73362
+ }
73363
+ let toToken1USD = new BigNumber$1(toToken1Estimate ?? '0')
73364
+ ?.div(new BigNumber$1(10).pow(toToken1?.decimals[chainId] ?? 18)) // this is amount of swap output
73365
+ ?.times(new BigNumber$1(toToken1Price?.price ?? 0)); // convert it to usd price
73366
+ if (response?.lpQuote?.token1?.fromAmountUSD) {
73367
+ toToken1USD = new BigNumber$1(response?.lpQuote?.token1?.fromAmountUSD);
73368
+ }
73369
+ const youSpendUSD = toToken0USD.plus(toToken1USD); // youSpendUSD
73370
+ const estimatedDepositAmount = youSpendUSD.div(bond?.principalTokenPrice ?? '0');
73371
+ const isWrap = inputCurrency === 'NATIVE' &&
73372
+ bond?.lpToken?.address?.[chainId]?.toLowerCase() === WNATIVE[chainId]?.address?.[chainId]?.toLowerCase();
73373
+ const estimatedDepositAmountToReturn = isWrap ? typedValue : estimatedDepositAmount.toString();
73374
+ const trueBondPrice = response?.protocolQuote?.trueBondPrice;
73375
+ const zapLoading = isLoading || isFetching;
73376
+ if (zapLoading)
73377
+ return [true, undefined, '', false, undefined];
73378
+ return [zapLoading, response, estimatedDepositAmountToReturn, zapError, trueBondPrice];
73379
+ };
73380
+
73226
73381
  function useCurrencyBalance(currency, account, chainId) {
73227
73382
  return useQuery({
73228
73383
  queryKey: [
@@ -74299,7 +74454,7 @@ const SlippageModal = () => {
74299
74454
  }, children: jsx$2(Text, { weight: 700, children: "%" }) })] })] })] }) }) }) }));
74300
74455
  };
74301
74456
 
74302
- const ZapModal = ({ onDismiss, outputToken, account, chainId }) => {
74457
+ const ZapModal = ({ onDismiss, outputToken, account, chainId, bondData }) => {
74303
74458
  // State
74304
74459
  const [pendingTx, setPendingTx] = useState(false);
74305
74460
  const [typedValue, setTypedValue] = useState('');
@@ -74323,8 +74478,14 @@ const ZapModal = ({ onDismiss, outputToken, account, chainId }) => {
74323
74478
  const isWrap = inputTokenString === 'NATIVE' &&
74324
74479
  outputToken?.address?.[chainId]?.toLowerCase() === WNATIVE[chainId]?.address?.[chainId]?.toLowerCase();
74325
74480
  const outputTokenBalanceString = outputTokenBalance ? new BigNumber$1(outputTokenBalance).toPrecision(5) : 'loading';
74326
- // Zap Quote
74327
- const [fetchingQuote, zapData, outputValue, zapError] = useSoulZapTokenQuote(typedValue, inputToken, outputToken, chainId, account);
74481
+ // Zap Quote - use bond quote when bondData is present, token quote otherwise
74482
+ const [tokenFetchingQuote, tokenZapData, tokenOutputValue, tokenZapError] = useSoulZapTokenQuote(typedValue, inputToken, bondData ? undefined : outputToken, chainId, account);
74483
+ const [bondFetchingQuote, bondZapData, bondDepositAmount, bondZapError] = useSoulZapBondQuote(typedValue, inputToken, bondData, account);
74484
+ const isBondZap = !!bondData;
74485
+ const fetchingQuote = isBondZap ? bondFetchingQuote : tokenFetchingQuote;
74486
+ const zapData = isBondZap ? bondZapData : tokenZapData;
74487
+ const outputValue = isBondZap ? parseFloat(bondDepositAmount || '0') : tokenOutputValue;
74488
+ const zapError = isBondZap ? bondZapError : tokenZapError;
74328
74489
  // Functions
74329
74490
  const handleCurrencySelect = useCallback((newInputToken) => {
74330
74491
  setTypedValue('');
@@ -74412,139 +74573,6 @@ const ZapModal = ({ onDismiss, outputToken, account, chainId }) => {
74412
74573
  : 'BUY' })) }), jsx$2(Flex, { sx: { marginTop: '10px', justifyContent: 'center' }, children: jsx$2(Link, { href: "https://docs.ape.bond/apebond/products-and-features/zap", target: "_blank", rel: "noopener noreferrer", sx: { textDecoration: 'none' }, children: jsxs(Text, { style: { fontSize: '12px', lineHeight: '18px', fontWeight: 400, borderBottom: '1px solid' }, children: ["Learn more", '>'] }) }) })] })] }));
74413
74574
  };
74414
74575
 
74415
- const useSoulZapBondQuote = (typedValue, inputCurrency, bond, account, tierProofSig) => {
74416
- const debouncedInput = useDebounce(typedValue, 400);
74417
- const [slippage] = useSlippage();
74418
- const principalToken = bond?.lpToken;
74419
- const bondContractAddress = bond?.contractAddress[bond?.chainId];
74420
- const chainId = bond?.chainId;
74421
- const inputCurrencyString = inputCurrency === 'NATIVE' ? '0x0000000000000000000000000000000000000000' : inputCurrency?.address[chainId];
74422
- const inputCurrencyDecimals = inputCurrency === 'NATIVE' ? 18 : inputCurrency?.decimals[chainId];
74423
- const principalContractAddress = principalToken?.address[chainId];
74424
- const chainName = getChainParam(chainId);
74425
- const isReserveBond = bond?.billType === 'reserve' || bond?.billType === 'staking';
74426
- const liquidityDex = principalToken?.liquiditySource?.[chainId] ?? principalToken?.liquidityDex?.[chainId];
74427
- const protocol = main.dexFactories[chainId]?.[liquidityDex]?.protocol;
74428
- const lpType = isReserveBond ? 'single' : getLpType(protocol);
74429
- const ichiUnderlyingDex = principalToken?.ichiUnderlyingDex;
74430
- const vault = principalToken?.address?.[chainId];
74431
- const router = main.dexFactories[chainId]?.[liquidityDex]?.router;
74432
- // Validates that the user did not pass an amount with 19 decimals or more
74433
- const validated18DecimalAmount = new BigNumber$1(debouncedInput ?? '0').toFixed(18, 5);
74434
- const bigishInputAmount = new BigNumber$1(validated18DecimalAmount ?? '0')
74435
- .times(new BigNumber$1(10).pow(inputCurrencyDecimals ?? 18))
74436
- .toString();
74437
- const zapInputData = useMemo(() => {
74438
- if (inputCurrencyString &&
74439
- inputCurrencyDecimals &&
74440
- bigishInputAmount !== 'NaN' &&
74441
- bigishInputAmount !== '0' &&
74442
- principalContractAddress &&
74443
- chainName &&
74444
- bondContractAddress &&
74445
- (inputCurrency === 'NATIVE' || inputCurrency?.address[chainId] !== principalToken.address[chainId])) {
74446
- return {
74447
- chain: chainName,
74448
- recipient: account ?? '0x0000000000000000000000000000000000000000',
74449
- user: account ?? '0x0000000000000000000000000000000000000000',
74450
- lpData: {
74451
- lpType,
74452
- fromToken: inputCurrencyString,
74453
- fromAmount: bigishInputAmount,
74454
- underlyingDex: ichiUnderlyingDex,
74455
- vault: isReserveBond ? undefined : vault,
74456
- slippage: slippage,
74457
- lpAddress: lpType === 'solidly' || lpType === 'univ2' || lpType === 'curve' ? vault : undefined,
74458
- router: lpType === 'solidly' || lpType === 'univ2' ? router : undefined,
74459
- toToken: isReserveBond ? vault : undefined,
74460
- },
74461
- protocolData: {
74462
- protocol: 'ApeBond',
74463
- bond: bondContractAddress,
74464
- depositer: account ?? '0x0000000000000000000000000000000000000000',
74465
- tierProofSignature: bond.billVersion === main.BillVersion.V4 && tierProofSig ? tierProofSig : undefined,
74466
- },
74467
- };
74468
- }
74469
- else {
74470
- return null;
74471
- }
74472
- /* eslint-disable react-hooks/exhaustive-deps */
74473
- }, [
74474
- bigishInputAmount,
74475
- principalContractAddress,
74476
- chainName,
74477
- account,
74478
- ichiUnderlyingDex,
74479
- vault,
74480
- lpType,
74481
- router,
74482
- slippage,
74483
- ]);
74484
- const queryKey = useMemo(() => {
74485
- if (!zapInputData)
74486
- return null;
74487
- return [
74488
- 'zapBondDetails',
74489
- zapInputData.chain,
74490
- zapInputData.user,
74491
- zapInputData.lpData.lpType,
74492
- zapInputData.lpData.fromToken,
74493
- zapInputData.lpData.fromAmount,
74494
- zapInputData.lpData.underlyingDex ?? '',
74495
- zapInputData.lpData.vault,
74496
- zapInputData.lpData.slippage,
74497
- zapInputData.lpData.lpAddress,
74498
- zapInputData.lpData.router ?? '',
74499
- ];
74500
- }, [zapInputData]);
74501
- const fetchZapDetails = async () => {
74502
- const response = await axios.post(SOUL_ZAP_API, {
74503
- '0': zapInputData,
74504
- });
74505
- return response.data?.[0]?.result?.data;
74506
- };
74507
- const { data: response, isLoading, isFetching, error, } = useQuery({
74508
- queryKey: [QUERY_KEYS.ZAP_TOKEN_QUOTE, queryKey],
74509
- queryFn: fetchZapDetails,
74510
- refetchInterval: 60000, // i.e. 60 sec
74511
- enabled: !!queryKey,
74512
- retry: 1,
74513
- });
74514
- const zapError = !!error;
74515
- const tokenList = zapInputTokens[chainId] ? zapInputTokens[chainId] : [];
74516
- // toToken0 data
74517
- const toToken0Estimate = response?.lpQuote?.token0?.fromAmountEstimate;
74518
- const toToken0 = [...tokenList, principalToken]?.find((token) => token?.address?.[chainId]?.toLowerCase() === response?.lpQuote?.token0?.address?.toLowerCase());
74519
- const toToken0Price = useCurrencyPrice(toToken0 ?? null, chainId);
74520
- // toToken1 data
74521
- const toToken1Estimate = response?.lpQuote?.token1?.fromAmountEstimate;
74522
- const toToken1 = zapInputTokens[chainId]?.find((token) => token.address[chainId]?.toLowerCase() === response?.lpQuote?.token1?.address?.toLowerCase());
74523
- const toToken1Price = useCurrencyPrice(toToken1 ?? null, chainId);
74524
- let toToken0USD = new BigNumber$1(toToken0Estimate ?? '0')
74525
- ?.div(new BigNumber$1(10).pow(toToken0?.decimals[chainId] ?? 18)) // this is amount of swap output
74526
- ?.times(new BigNumber$1(toToken0Price?.price ?? 0)); // convert it to usd price
74527
- if (response?.lpQuote?.token0?.fromAmountUSD) {
74528
- toToken0USD = new BigNumber$1(response?.lpQuote?.token0?.fromAmountUSD);
74529
- }
74530
- let toToken1USD = new BigNumber$1(toToken1Estimate ?? '0')
74531
- ?.div(new BigNumber$1(10).pow(toToken1?.decimals[chainId] ?? 18)) // this is amount of swap output
74532
- ?.times(new BigNumber$1(toToken1Price?.price ?? 0)); // convert it to usd price
74533
- if (response?.lpQuote?.token1?.fromAmountUSD) {
74534
- toToken1USD = new BigNumber$1(response?.lpQuote?.token1?.fromAmountUSD);
74535
- }
74536
- const youSpendUSD = toToken0USD.plus(toToken1USD); // youSpendUSD
74537
- const estimatedDepositAmount = youSpendUSD.div(bond?.principalTokenPrice ?? '0');
74538
- const isWrap = inputCurrency === 'NATIVE' &&
74539
- bond?.lpToken?.address?.[chainId]?.toLowerCase() === WNATIVE[chainId]?.address?.[chainId]?.toLowerCase();
74540
- const estimatedDepositAmountToReturn = isWrap ? typedValue : estimatedDepositAmount.toString();
74541
- const trueBondPrice = response?.protocolQuote?.trueBondPrice;
74542
- const zapLoading = isLoading || isFetching;
74543
- if (zapLoading)
74544
- return [true, undefined, '', false, undefined];
74545
- return [zapLoading, response, estimatedDepositAmountToReturn, zapError, trueBondPrice];
74546
- };
74547
-
74548
74576
  const useSendReferenceId = () => {
74549
74577
  const config = useSDKConfig();
74550
74578
  const apiV2URL = useURLByEnvironment('apiV2');
@@ -75428,7 +75456,7 @@ const BuyBond$1 = ({ onDismiss, bondAddress, bondChain, handlePurchasedBond, isP
75428
75456
  // Modals
75429
75457
  const [openNewRateModal] = useModal(jsx$2(NewRateModal$1, { bond: bondData, zapTrueBondPrice: zapTrueBondPrice, depositAmount: depositAmount, youSpendString: youSpendString, fetchingZapQuote: fetchingZapQuote, zapError: zapError }), true, false, 'newRateModal');
75430
75458
  const [openTxModal] = useModal(jsx$2(TransactionModal$2, { txChain: bondChain, approvalState: approvalState, approveCallback: handleApprove, loadingTx: loadingTx, txCallback: handleBothPurchases, bondData: bondData, inputToken: inputToken, inputValue: inputValue, depositAmount: depositAmount, buyTxHash: buyTxHash, rateChanged: rateChanged }), false, true, 'transactionModal');
75431
- const [onOpenZapModal] = useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId }), true, true, 'zapModal');
75459
+ const [onOpenZapModal] = useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId, bondData: bondData }), true, true, 'zapModal');
75432
75460
  const [openNoBonusModal] = useModal(jsx$2(NoBonusModal, { onAcknowledge: openTxModal, showcaseTokenName: bondData?.showcaseTokenName }), true, true, 'NoBonusModal');
75433
75461
  // Effects
75434
75462
  const [hasChecked, setHasChecked] = useState(false);
@@ -99888,7 +99916,7 @@ const BuyBond = ({ onDismiss, bondAddress, bondChain, handlePurchasedBond, isPro
99888
99916
  // Modals
99889
99917
  useModal(jsx$2(NewRateModal, { bond: bondData, zapTrueBondPrice: zapTrueBondPrice, depositAmount: depositAmount, youSpendString: youSpendString, fetchingZapQuote: fetchingZapQuote, zapError: zapError }), true, false, 'newRateModal');
99890
99918
  const [openTxModal] = useModal(jsx$2(TransactionModal$1, { txChain: bondChain, approvalState: approvalState, approveCallback: handleApprove, loadingTx: loadingTx, txCallback: handleBothPurchases, bondData: bondData, inputToken: inputToken, inputValue: inputValue, depositAmount: depositAmount, buyTxHash: buyTxHash, rateChanged: rateChanged, onDismiss: onDismiss }), false, true, 'transactionModal');
99891
- useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId }), true, true, 'zapModal');
99919
+ useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId, bondData: bondData }), true, true, 'zapModal');
99892
99920
  // Effects
99893
99921
  const [hasChecked, setHasChecked] = useState(false);
99894
99922
  const [hasCheckedTrack, setHasCheckedTrack] = useState(false);
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ChainId, Token } from '@ape.swap/apeswap-lists';
3
+ import { BondsData } from '../../types/bonds';
3
4
  /**
4
5
  * @param chainId this is the chainId of the outputToken
5
6
  */
@@ -8,6 +9,7 @@ interface ZapModalProps {
8
9
  outputToken: Token;
9
10
  chainId: ChainId;
10
11
  account?: string;
12
+ bondData?: BondsData;
11
13
  }
12
- declare const ZapModal: ({ onDismiss, outputToken, account, chainId }: ZapModalProps) => React.JSX.Element;
14
+ declare const ZapModal: ({ onDismiss, outputToken, account, chainId, bondData }: ZapModalProps) => React.JSX.Element;
13
15
  export default ZapModal;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Goo Money Bond SDK",
4
4
  "author": "Goo Money",
5
5
  "license": "MIT",
6
- "version": "3.0.174",
6
+ "version": "3.0.176",
7
7
  "proxy": "https://realtime-api-pr-99.herokuapp.com",
8
8
  "module": "dist/main.js",
9
9
  "type": "module",