Skip to content

Commit

Permalink
feat(npm): update versions
Browse files Browse the repository at this point in the history
  • Loading branch information
githubotoro committed Dec 4, 2024
1 parent 8caf8b7 commit ec799e9
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 153 deletions.
5 changes: 0 additions & 5 deletions .changeset/automated-minor-release.md

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

This file was deleted.

7 changes: 1 addition & 6 deletions sdk/constants/market-map/11155111/index.ts
Original file line number Diff line number Diff line change
@@ -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 = {};
55 changes: 23 additions & 32 deletions sdk/hooks/use-distinct-assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TypedObjectDistinctAsset>
>((acc, { ids, symbol }) => {
ids.forEach((id) => {
acc[id] = {
...getSupportedToken(id),
};
});
return acc;
}, {})
: null;
} else {
return null;
}
},
});

return { data, isLoading, isError, isRefetching };
};
54 changes: 23 additions & 31 deletions sdk/hooks/use-distinct-incentives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TypedObjectDistinctIncentive>
>((acc, { ids }) => {
ids.forEach((id) => {
acc[id] = {
...getSupportedToken(id),
};
});
return acc;
}, {})
: null;
} else {
return null;
}
},
});

return { data, isLoading, isError, isRefetching };
};
14 changes: 10 additions & 4 deletions sdk/hooks/use-highest-offers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useHighestOffers = ({
chain_id: number;
market_id: string;
market_type: number;
}) => {
}) => {
let data: {
ap_offers: Array<EnrichedOfferDataType>;
ip_offers: Array<EnrichedOfferDataType>;
Expand Down Expand Up @@ -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:
Expand All @@ -107,7 +110,10 @@ export const useHighestOffers = ({
(propsEnrichedOffersIP.data.data as Array<EnrichedOfferDataType>)
: [],
};
} 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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export const usePrepareMarketAction = ({
funding_vault,
custom_token_data,
frontend_fee_recipient,
offer_validation_url,
enabled: action_type === PrepareMarketActionType.RecipeAPMarketOffer,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
45 changes: 4 additions & 41 deletions sdk/hooks/use-prepare-market-action/use-recipe-ap-market-offer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -284,7 +284,6 @@ export const useRecipeAPMarketOffer = ({
funding_vault,
custom_token_data,
frontend_fee_recipient,
offer_validation_url,
enabled,
}: {
account: string | undefined;
Expand All @@ -299,7 +298,6 @@ export const useRecipeAPMarketOffer = ({
total_supply?: string;
}>;
frontend_fee_recipient?: string;
offer_validation_url: string;
enabled?: boolean;
}) => {
let preContractOptions: TransactionOptionsType[] = [];
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit ec799e9

Please sign in to comment.