diff --git a/.changeset/automated-minor-release.md b/.changeset/automated-minor-release.md deleted file mode 100644 index aeb434eb0..000000000 --- a/.changeset/automated-minor-release.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"royco": minor ---- - -New SDK version @ 2024-12-04 18:26:37 UTC diff --git a/CHANGELOG.md b/CHANGELOG.md index 07dad793f..3a00fe67b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # royco +## 0.7.0 + +### Minor Changes + +- 8caf8b7: New SDK version @ 2024-12-04 18:26:37 UTC + ## 0.6.0 ### Minor Changes diff --git a/package.json b/package.json index bb4ef9254..195a66fa8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "royco", "description": "SDK for building frontends on top of Royco Protocol", - "version": "0.6.0", + "version": "0.7.0", "type": "module", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/sdk/constants/market-map/11155111/definitions/11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17.ts b/sdk/constants/market-map/11155111/definitions/11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17.ts deleted file mode 100644 index 7ab609d60..000000000 --- a/sdk/constants/market-map/11155111/definitions/11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineMarket } from "@/sdk/constants"; - -export default defineMarket({ - id: "11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17", - name: "SDK Test Market", - description: "SDK Test Market", - is_verified: false, -}); diff --git a/sdk/constants/market-map/11155111/index.ts b/sdk/constants/market-map/11155111/index.ts index 91aecb792..58dd55a12 100644 --- a/sdk/constants/market-map/11155111/index.ts +++ b/sdk/constants/market-map/11155111/index.ts @@ -1,6 +1 @@ -import market_11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17 from "./definitions/11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17"; - -export const MarketMap11155111 = { - [market_11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17.id]: - market_11155111_0_0x836cf6113898237f5abd2ee613e8603f8d85a7ec5301e72bc556620209e6fb17, -}; +export const MarketMap11155111 = {}; diff --git a/sdk/hooks/use-distinct-assets.tsx b/sdk/hooks/use-distinct-assets.tsx index fe20d677d..0a1279a33 100644 --- a/sdk/hooks/use-distinct-assets.tsx +++ b/sdk/hooks/use-distinct-assets.tsx @@ -17,46 +17,37 @@ export type TypedObjectDistinctAsset = { contract_address: string; }; -export const useDistinctAssets = ({ - output = "array", -}: { - output?: "array" | "object"; -} = {}) => { +export const useDistinctAssets = () => { const client: RoycoClient = useRoycoClient(); - const { data, isLoading, isError, isRefetching, error } = useQuery({ + return useQuery({ ...getDistinctAssetsQueryOptions(client), select: (data) => { - if (output === "array") { - // - const new_data = data?.map((element) => { - const baseId = element.ids?.[0]; + if (data === undefined || data === null) { + return null; + } else { + let new_data = []; + + for (let i = 0; i < data.length; i++) { + const element = data[i]; + + if ( + !!element && + element.ids !== undefined && + element.ids !== null && + element.ids.length > 0 + ) { + const baseId = element.ids[0]; - return { - ...element, - ...getSupportedToken(baseId), - }; - }); + new_data.push({ + ...element, + ...getSupportedToken(baseId), + }); + } + } return new_data; - } else if (output === "object") { - return data - ? (data as TypedArrayDistinctAsset[]).reduce< - Record - >((acc, { ids, symbol }) => { - ids.forEach((id) => { - acc[id] = { - ...getSupportedToken(id), - }; - }); - return acc; - }, {}) - : null; - } else { - return null; } }, }); - - return { data, isLoading, isError, isRefetching }; }; diff --git a/sdk/hooks/use-distinct-incentives.tsx b/sdk/hooks/use-distinct-incentives.tsx index f2a89de44..55af88f90 100644 --- a/sdk/hooks/use-distinct-incentives.tsx +++ b/sdk/hooks/use-distinct-incentives.tsx @@ -17,45 +17,37 @@ export type TypedObjectDistinctIncentive = { contract_address: string; }; -export const useDistinctIncentives = ({ - output = "array", -}: { - output?: "array" | "object"; -}) => { +export const useDistinctIncentives = () => { const client: RoycoClient = useRoycoClient(); - const { data, isLoading, isError, isRefetching } = useQuery({ + return useQuery({ ...getDistinctIncentivesQueryOptions(client), select: (data) => { - if (output === "array") { - const new_data = data?.map((element) => { - const baseId = element.ids?.[0]; + if (data === undefined || data === null) { + return null; + } else { + let new_data = []; + + for (let i = 0; i < data.length; i++) { + const element = data[i]; + + if ( + !!element && + element.ids !== undefined && + element.ids !== null && + element.ids.length > 0 + ) { + const baseId = element.ids[0]; - return { - ...element, - ...getSupportedToken(baseId), - }; - }); + new_data.push({ + ...element, + ...getSupportedToken(baseId), + }); + } + } return new_data; - } else if (output === "object") { - return data - ? (data as TypedArrayDistinctIncentive[]).reduce< - Record - >((acc, { ids }) => { - ids.forEach((id) => { - acc[id] = { - ...getSupportedToken(id), - }; - }); - return acc; - }, {}) - : null; - } else { - return null; } }, }); - - return { data, isLoading, isError, isRefetching }; }; diff --git a/sdk/hooks/use-highest-offers.tsx b/sdk/hooks/use-highest-offers.tsx index 77697dd37..d87ec28f9 100644 --- a/sdk/hooks/use-highest-offers.tsx +++ b/sdk/hooks/use-highest-offers.tsx @@ -12,7 +12,7 @@ export const useHighestOffers = ({ chain_id: number; market_id: string; market_type: number; -}) => { +}) => { let data: { ap_offers: Array; ip_offers: Array; @@ -85,7 +85,10 @@ export const useHighestOffers = ({ ) { const enrichedMarket = propsEnrichedMarket.data[0]; - if (enrichedMarket && enrichedMarket.market_type === RoycoMarketType.recipe.value) { + if ( + enrichedMarket && + enrichedMarket.market_type === RoycoMarketType.recipe.value + ) { // Recipe Market data = { ap_offers: @@ -107,7 +110,10 @@ export const useHighestOffers = ({ (propsEnrichedOffersIP.data.data as Array) : [], }; - } else if (enrichedMarket && enrichedMarket.market_type === RoycoMarketType.vault.value) { + } else if ( + enrichedMarket && + enrichedMarket.market_type === RoycoMarketType.vault.value + ) { // Vault Market /** * This is the custom IP offer for the vault market, built for the UI @@ -124,7 +130,7 @@ export const useHighestOffers = ({ ? enrichedMarket.id.concat("_offer_id") : "no_offer_id", market_id: enrichedMarket.id, - creator: enrichedMarket.creator, + creator: enrichedMarket.owner, funding_vault: NULL_ADDRESS, input_token_id: enrichedMarket.input_token_id, quantity: enrichedMarket.locked_quantity, diff --git a/sdk/hooks/use-prepare-market-action/use-prepare-market-action.tsx b/sdk/hooks/use-prepare-market-action/use-prepare-market-action.tsx index 175fae869..abffca3d2 100644 --- a/sdk/hooks/use-prepare-market-action/use-prepare-market-action.tsx +++ b/sdk/hooks/use-prepare-market-action/use-prepare-market-action.tsx @@ -121,7 +121,6 @@ export const usePrepareMarketAction = ({ funding_vault, custom_token_data, frontend_fee_recipient, - offer_validation_url, enabled: action_type === PrepareMarketActionType.RecipeAPMarketOffer, }); diff --git a/sdk/hooks/use-prepare-market-action/use-recipe-ap-limit-offer.tsx b/sdk/hooks/use-prepare-market-action/use-recipe-ap-limit-offer.tsx index 9112ec2dc..6dbf270d1 100644 --- a/sdk/hooks/use-prepare-market-action/use-recipe-ap-limit-offer.tsx +++ b/sdk/hooks/use-prepare-market-action/use-recipe-ap-limit-offer.tsx @@ -194,7 +194,7 @@ export const calculateRecipeAPLimitOfferTokenData = ({ // Get input token data const input_token_data: TypedMarketActionInputTokenData = { ...input_token_quote, - raw_amount: quantity === "" ? "0" : quantity ?? "0", + raw_amount: quantity === "" ? "0" : (quantity ?? "0"), token_amount: parseRawAmountToTokenAmount( quantity ?? "0", input_token_quote.decimals, @@ -215,8 +215,8 @@ export const calculateRecipeAPLimitOfferTokenData = ({ token_quotes: propsTokenQuotes, }); - // Get incentive token raw amount - const incentive_token_raw_amount = tokenAmounts[index]; + // Get incentive token raw amount with default "0" + const incentive_token_raw_amount = tokenAmounts[index] ?? "0"; // Get incentive token amount const incentive_token_amount = parseFloat( diff --git a/sdk/hooks/use-prepare-market-action/use-recipe-ap-market-offer.tsx b/sdk/hooks/use-prepare-market-action/use-recipe-ap-market-offer.tsx index 348d99768..d6255287b 100644 --- a/sdk/hooks/use-prepare-market-action/use-recipe-ap-market-offer.tsx +++ b/sdk/hooks/use-prepare-market-action/use-recipe-ap-market-offer.tsx @@ -129,7 +129,7 @@ export const calculateRecipeAPMarketOfferTokenData = ({ (acc, offer) => { offer.token_ids.forEach((token_id, index) => { const base_amount: BigNumber = BigNumber.from( - offer.token_amounts[index].toString(), + offer.token_amounts?.[index]?.toString() ?? "0", ); const actual_amount: BigNumber = base_amount @@ -284,7 +284,6 @@ export const useRecipeAPMarketOffer = ({ funding_vault, custom_token_data, frontend_fee_recipient, - offer_validation_url, enabled, }: { account: string | undefined; @@ -299,7 +298,6 @@ export const useRecipeAPMarketOffer = ({ total_supply?: string; }>; frontend_fee_recipient?: string; - offer_validation_url: string; enabled?: boolean; }) => { let preContractOptions: TransactionOptionsType[] = []; @@ -336,29 +334,6 @@ export const useRecipeAPMarketOffer = ({ enabled: isValid.status, }); - // Get market offers validator - const propsMarketOffersValidator = useMarketOffersValidator({ - offer_ids: propsMarketOffers.data?.map((offer) => offer.id) ?? [], - offerValidationUrl: offer_validation_url, - enabled: isValid.status, - }); - - // Trigger refetch when validator returns non-empty array - React.useEffect(() => { - if ( - isValid.status && - !propsMarketOffersValidator.isLoading && - propsMarketOffersValidator.data && - propsMarketOffersValidator.data.length > 0 - ) { - propsMarketOffers.refetch(); - } - }, [ - isValid.status, - propsMarketOffersValidator.isLoading, - propsMarketOffersValidator.data, - ]); - // Get token quotes - Only proceed if offers are valid const propsTokenQuotes = useTokenQuotes({ token_ids: Array.from( @@ -368,11 +343,7 @@ export const useRecipeAPMarketOffer = ({ ]), ), custom_token_data, - enabled: - isValid.status && - // Only proceed if validation is complete and returned empty array (all offers valid) - !propsMarketOffersValidator.isLoading && - propsMarketOffersValidator.data?.length === 0, + enabled: isValid.status, }); // Get incentive data @@ -391,10 +362,7 @@ export const useRecipeAPMarketOffer = ({ !!baseMarket && !!enrichedMarket && !!incentiveData && - !!inputTokenData && - // Only proceed if validation is complete and returned empty array (all offers valid) - !propsMarketOffersValidator.isLoading && - propsMarketOffersValidator.data?.length === 0 + !!inputTokenData ) { // Get offer transaction options const offerTxOptions: TransactionOptionsType = @@ -495,16 +463,11 @@ export const useRecipeAPMarketOffer = ({ const isLoading = isLoadingDefaultMarketData || propsMarketOffers.isLoading || - propsMarketOffersValidator.isLoading || propsTokenAllowance.isLoading || propsTokenQuotes.isLoading; // Update isReady check to ensure offers are valid - const isReady = - writeContractOptions.length > 0 && - // Only proceed if validation is complete and returned empty array (all offers valid) - !propsMarketOffersValidator.isLoading && - propsMarketOffersValidator.data?.length === 0; + const isReady = writeContractOptions.length > 0; // Check if offer can be performed completely or partially if (isReady) { diff --git a/sdk/hooks/use-prepare-market-action/use-recipe-ip-market-offer.tsx b/sdk/hooks/use-prepare-market-action/use-recipe-ip-market-offer.tsx index b60ea0f57..40b8fce2d 100644 --- a/sdk/hooks/use-prepare-market-action/use-recipe-ip-market-offer.tsx +++ b/sdk/hooks/use-prepare-market-action/use-recipe-ip-market-offer.tsx @@ -113,7 +113,7 @@ export const calculateRecipeIPMarketOfferTokenData = ({ (acc, offer) => { offer.token_ids.forEach((token_id, index) => { const base_amount: BigNumber = BigNumber.from( - offer.token_amounts[index].toString(), + offer.token_amounts?.[index]?.toString() ?? "0", ); const actual_amount: BigNumber = base_amount @@ -429,7 +429,7 @@ export const useRecipeIPMarketOffer = ({ quantity: offer.quantity, expiry: offer.expiry, incentivesRequested: offer.token_ids.map((token_id) => { - const token_address = token_id.split("-")[1]; + const token_address = token_id.split("-")[1] ?? NULL_ADDRESS; return token_address; }), incentiveAmountsRequested: offer.token_amounts, diff --git a/sdk/hooks/use-prepare-market-action/use-vault-ap-market-offer.tsx b/sdk/hooks/use-prepare-market-action/use-vault-ap-market-offer.tsx index 0a6a026e5..23f354b24 100644 --- a/sdk/hooks/use-prepare-market-action/use-vault-ap-market-offer.tsx +++ b/sdk/hooks/use-prepare-market-action/use-vault-ap-market-offer.tsx @@ -144,7 +144,7 @@ export const calculateVaultAPMarketOfferTokenData = ({ // Get incentive token raw amount const incentive_token_raw_amount = - action_incentive_token_amounts[index]; + action_incentive_token_amounts[index] ?? "0"; // Get incentive token amount const incentive_token_amount = parseFloat( @@ -173,7 +173,7 @@ export const calculateVaultAPMarketOfferTokenData = ({ } else { annual_change_ratio = (incentive_token_amount_usd / input_token_data.token_amount_usd) * - ((365 * 24 * 60 * 60) / parseInt(time_left)); + ((365 * 24 * 60 * 60) / parseInt(time_left ?? "0")); } // Get incentive token data diff --git a/sdk/hooks/use-prepare-market-action/use-vault-ip-market-offer.tsx b/sdk/hooks/use-prepare-market-action/use-vault-ip-market-offer.tsx index ab101bb3d..882de1147 100644 --- a/sdk/hooks/use-prepare-market-action/use-vault-ip-market-offer.tsx +++ b/sdk/hooks/use-prepare-market-action/use-vault-ip-market-offer.tsx @@ -26,6 +26,7 @@ import type { TypedMarketActionInputTokenData, } from "./types"; import { useDefaultMarketData } from "./use-default-market-data"; +import { NULL_ADDRESS } from "@/sdk/constants"; export const isVaultIPMarketOfferValid = ({ quantity, @@ -109,7 +110,7 @@ export const calculateVaultIPMarketOfferTokenData = ({ (acc, offer) => { offer.token_ids.forEach((token_id, index) => { const base_amount: BigNumber = BigNumber.from( - offer.token_amounts[index].toString(), + offer.token_amounts[index]?.toString() ?? "0", ); const actual_amount: BigNumber = base_amount @@ -375,7 +376,7 @@ export const useVaultIPMarketOffer = ({ fundingVault: offer.funding_vault, expiry: offer.expiry, incentivesRequested: offer.token_ids.map((token_id) => { - const token_address = token_id.split("-")[1]; + const token_address = token_id.split("-")[1] ?? NULL_ADDRESS; return token_address; }), incentivesRatesRequested: offer.token_amounts, diff --git a/sdk/hooks/use-prepare-market-action/use-vault-ip-refund-incentives.tsx b/sdk/hooks/use-prepare-market-action/use-vault-ip-refund-incentives.tsx index 2d341fded..a4f240a2b 100644 --- a/sdk/hooks/use-prepare-market-action/use-vault-ip-refund-incentives.tsx +++ b/sdk/hooks/use-prepare-market-action/use-vault-ip-refund-incentives.tsx @@ -162,7 +162,7 @@ export const calculateVaultIPRefundIncentivesTokenData = ({ // Get incentive token raw amount const incentive_token_raw_amount = - action_incentive_token_amounts[existing_incentive_index]; + action_incentive_token_amounts[existing_incentive_index] ?? "0"; // Get incentive token amount const incentive_token_amount = parseRawAmountToTokenAmount( diff --git a/sdk/provider/RoycoProvider.tsx b/sdk/provider/RoycoProvider.tsx index 7585b87ff..41ca7676c 100644 --- a/sdk/provider/RoycoProvider.tsx +++ b/sdk/provider/RoycoProvider.tsx @@ -2,11 +2,7 @@ import { useState } from "react"; -import { - HydrationBoundary, - QueryClient, - QueryClientProvider, -} from "@tanstack/react-query"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import type { DefaultOptions } from "@tanstack/react-query"; diff --git a/sdk/queries/get-enriched-positions-recipe.tsx b/sdk/queries/get-enriched-positions-recipe.tsx index 5ab879767..df5d38901 100644 --- a/sdk/queries/get-enriched-positions-recipe.tsx +++ b/sdk/queries/get-enriched-positions-recipe.tsx @@ -18,20 +18,61 @@ import { const constructEnrichedPositionsRecipeFilterClauses = ( filters: Array, ): string => { - let filterClauses = ""; + let offerSideFilter = ""; + let canWithdrawFilter = ""; + let canClaimFilter = ""; /** * @note To filter string: wrap in single quotes * @note To filter number: no quotes */ - filters.forEach((filter, filterIndex) => { - filterClauses += ` ${filter.id} = ${filter.value} `; + // filters.forEach((filter, filterIndex) => { + // filterClauses += ` ${filter.id} = ${filter.value} `; + + // if (filterIndex !== filters.length - 1) { + // filterClauses += ` ${filter.join ?? "OR"} `; + // } + // }); - if (filterIndex !== filters.length - 1) { - filterClauses += ` ${filter.join ?? "OR"} `; + filters.forEach((filter) => { + switch (filter.id) { + case "offer_side": + if (offerSideFilter) offerSideFilter += " OR "; + if (filter.condition === "NOT") { + offerSideFilter += ` offer_side <> ${filter.value} `; + } else { + offerSideFilter += ` offer_side = ${filter.value} `; + } + break; + case "can_withdraw": + if (canWithdrawFilter) canWithdrawFilter += " OR "; + if (filter.condition === "NOT") { + canWithdrawFilter += ` can_withdraw <> ${filter.value} `; + } else { + canWithdrawFilter += ` can_withdraw = ${filter.value} `; + } + break; + case "can_claim": + if (canClaimFilter) canClaimFilter += " OR "; + if (filter.condition === "NOT") { + canClaimFilter += ` can_claim <> ${filter.value} `; + } else { + canClaimFilter += ` can_claim = ${filter.value} `; + } + break; } }); + let filterClauses = ""; + + if (offerSideFilter) filterClauses += `(${offerSideFilter}) AND `; + if (canWithdrawFilter) filterClauses += `(${canWithdrawFilter}) AND `; + if (canClaimFilter) filterClauses += `(${canClaimFilter}) AND `; + + if (filterClauses) { + filterClauses = filterClauses.slice(0, -5); // Remove the trailing " AND " + } + return filterClauses; }; @@ -69,7 +110,7 @@ export const getEnrichedPositionsRecipeQueryOptions = ( page_index: number = 0, filters: Array = [], sorting?: Array, -) => ({ +) => ({ queryKey: [ "enriched-positions-recipe", account_address, @@ -107,13 +148,13 @@ export const getEnrichedPositionsRecipeQueryOptions = ( ) { const tokens_data = row.token_ids.map((tokenId, tokenIndex) => { const token_price: number = row.token_price_values - ? row.token_price_values[tokenIndex] ?? 0 + ? (row.token_price_values[tokenIndex] ?? 0) : 0; const token_fdv: number = row.token_fdv_values - ? row.token_fdv_values[tokenIndex] ?? 0 + ? (row.token_fdv_values[tokenIndex] ?? 0) : 0; const token_total_supply: number = row.token_total_supply_values - ? row.token_total_supply_values[tokenIndex] ?? 0 + ? (row.token_total_supply_values[tokenIndex] ?? 0) : 0; const token_info: SupportedToken = getSupportedToken(tokenId); diff --git a/sdk/types/data.tsx b/sdk/types/data.tsx index dfeddefdb..b1447185e 100644 Binary files a/sdk/types/data.tsx and b/sdk/types/data.tsx differ