diff --git a/README.md b/README.md index f66ac2a..f217d66 100644 --- a/README.md +++ b/README.md @@ -45,19 +45,19 @@ sdk.configure({ }); // Discover yield opportunities -const yields = await sdk.api.yieldsGetYields({ +const yields = await sdk.api.getYields({ network: 'ethereum', limit: 10 }); // Get balances for a specific yield and address -const balances = await sdk.api.yieldsGetYieldBalances('yield-id', { +const balances = await sdk.api.getYieldBalances('yield-id', { address: '0x1234567890123456789012345678901234567890', arguments: {} }); // Enter a yield position -const action = await sdk.api.actionsEnterYield({ +const action = await sdk.api.enterYield({ yieldId: 'yield-id', address: '0x1234567890123456789012345678901234567890', arguments: { @@ -72,7 +72,7 @@ const action = await sdk.api.actionsEnterYield({ #### Get All Yields ```typescript -const yields = await sdk.api.yieldsGetYields({ +const yields = await sdk.api.getYields({ network?: string; limit?: number; offset?: number; @@ -81,12 +81,12 @@ const yields = await sdk.api.yieldsGetYields({ #### Get Specific Yield ```typescript -const yieldDetails = await sdk.api.yieldsGetYield('yield-id'); +const yieldDetails = await sdk.api.getYield('yield-id'); ``` #### Get Yield Balances ```typescript -const balances = await sdk.api.yieldsGetYieldBalances('yield-id', { +const balances = await sdk.api.getYieldBalances('yield-id', { address: '0x...', arguments?: object }); @@ -94,8 +94,8 @@ const balances = await sdk.api.yieldsGetYieldBalances('yield-id', { #### Get Aggregate Balances ```typescript -const aggregateBalances = await sdk.api.yieldsGetAggregateBalances({ - requests: [ +const aggregateBalances = await sdk.api.getAggregateBalances({ + queries: [ { yieldId: 'yield-id-1', address: '0x...', @@ -114,7 +114,7 @@ const aggregateBalances = await sdk.api.yieldsGetAggregateBalances({ #### Enter Yield Position ```typescript -const enterAction = await sdk.api.actionsEnterYield({ +const enterAction = await sdk.api.enterYield({ yieldId: 'yield-id', address: '0x...', arguments: { @@ -125,7 +125,7 @@ const enterAction = await sdk.api.actionsEnterYield({ #### Exit Yield Position ```typescript -const exitAction = await sdk.api.actionsExitYield({ +const exitAction = await sdk.api.exitYield({ yieldId: 'yield-id', address: '0x...', arguments: { @@ -136,17 +136,18 @@ const exitAction = await sdk.api.actionsExitYield({ #### Manage Yield Position ```typescript -const manageAction = await sdk.api.actionsManageYield({ +const manageAction = await sdk.api.manageYield({ yieldId: 'yield-id', address: '0x...', - action: 'claim', // or other management actions + action: 'CLAIM_REWARDS', // or other management actions + passthrough: 'server-generated-passthrough', arguments: {} }); ``` #### Get Actions ```typescript -const actions = await sdk.api.actionsGetActions({ +const actions = await sdk.api.getActions({ address: '0x...', status?: 'pending' | 'completed' | 'failed', yieldId?: 'yield-id', @@ -157,14 +158,14 @@ const actions = await sdk.api.actionsGetActions({ #### Get Action Details ```typescript -const action = await sdk.api.actionsGetAction('action-id'); +const action = await sdk.api.getAction('action-id'); ``` ### Transactions #### Submit Transaction Hash ```typescript -const transaction = await sdk.api.transactionsSubmitTransactionHash( +const transaction = await sdk.api.submitTransactionHash( 'transaction-id', { hash: '0x...' @@ -174,19 +175,19 @@ const transaction = await sdk.api.transactionsSubmitTransactionHash( #### Get Transaction Details ```typescript -const transaction = await sdk.api.transactionsGetTransaction('transaction-id'); +const transaction = await sdk.api.getTransaction('transaction-id'); ``` ### Networks & Providers #### Get Networks ```typescript -const networks = await sdk.api.networksGetNetworks(); +const networks = await sdk.api.getNetworks(); ``` #### Get Providers ```typescript -const providers = await sdk.api.providersGetProviders({ +const providers = await sdk.api.getProviders({ limit?: 10, offset?: 0 }); @@ -194,14 +195,14 @@ const providers = await sdk.api.providersGetProviders({ #### Get Provider Details ```typescript -const provider = await sdk.api.providersGetProvider('provider-id'); +const provider = await sdk.api.getProvider('provider-id'); ``` ### Validators #### Get Yield Validators ```typescript -const validators = await sdk.api.yieldsGetYieldValidators('yield-id', { +const validators = await sdk.api.getYieldValidators('yield-id', { limit?: 10, offset?: 0 }); @@ -211,7 +212,7 @@ const validators = await sdk.api.yieldsGetYieldValidators('yield-id', { #### Get Health Status ```typescript -const healthStatus = await sdk.api.healthHealth(); +const healthStatus = await sdk.api.health(); ``` ## Advanced Configuration @@ -236,7 +237,7 @@ const customFetch: FetchInstance = async (url: string, init: RequestInit): Pr sdk.configure({ apiKey: 'your-api-key', - baseURL: 'https://api.stakek.it/', + baseURL: 'https://api.yield.xyz/', fetchInstance: customFetch }); ``` @@ -284,7 +285,7 @@ import { sdk } from '@yieldxyz/sdk'; try { // This will throw an error if not configured - const yields = await sdk.api.yieldsGetYields(); + const yields = await sdk.api.getYields(); } catch (error) { console.error('SDK not configured:', error.message); } @@ -293,7 +294,7 @@ try { sdk.configure({ apiKey: 'your-api-key' }); // Now API calls will work -const yields = await sdk.api.yieldsGetYields(); +const yields = await sdk.api.getYields(); ``` ## Development diff --git a/example/index.ts b/example/index.ts index cc2be2d..b6af366 100644 --- a/example/index.ts +++ b/example/index.ts @@ -3,7 +3,7 @@ import { sdk } from "../src"; sdk.configure({ apiKey: "your-api-key" }); const main = async () => { - const res = await sdk.api.yieldsGetYield("yieldId"); + const res = await sdk.api.getYield("yieldId"); console.log(res); }; diff --git a/orval.config.ts b/orval.config.ts index 4b6ecd8..7cfc78c 100644 --- a/orval.config.ts +++ b/orval.config.ts @@ -22,10 +22,34 @@ export default defineConfig({ path: apiClientPath, name: "customFetch", }, - transformer: (val) => ({ - ...val, - operationName: val.operationName?.replace(/controller/i, ""), - }), + transformer: (val) => { + let operationName = val.operationName?.replace(/controller/i, ""); + + // Remove redundant prefixes to clean up function names + if (operationName) { + operationName = operationName + .replace(/^yields/i, "") + .replace(/^actions/i, "") + .replace(/^transactions/i, "") + .replace(/^networks/i, "") + .replace(/^providers/i, "") + .replace(/^health/i, ""); + + // Ensure the first letter is lowercase + operationName = + operationName.charAt(0).toLowerCase() + operationName.slice(1); + + // Handle special cases where removing prefix leaves empty or awkward names + if (operationName === "health" || operationName === "") { + operationName = "health"; + } + } + + return { + ...val, + operationName, + }; + }, }, }, input: { diff --git a/src/api-client.ts b/src/api-client.ts index 82a1081..aae034e 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -17,7 +17,7 @@ export const customFetch = async ({ }): Promise => { const { apiKey, - baseURL = "https://api.stakek.it/", + baseURL = "https://api.yield.xyz/", fetchInstance, } = sdkConfig; diff --git a/src/api/index.ts b/src/api/index.ts index 391edea..096c5c3 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -27,7 +27,7 @@ import type { * Retrieve a paginated list of available yield opportunities across all supported networks and protocols. * @summary List all yield opportunities */ -export const yieldsGetYields = (params?: YieldsControllerGetYieldsParams) => { +export const getYields = (params?: YieldsControllerGetYieldsParams) => { return customFetch({ url: `/v1/yields`, method: "GET", @@ -39,7 +39,7 @@ export const yieldsGetYields = (params?: YieldsControllerGetYieldsParams) => { * Retrieve balances for multiple wallet addresses across different networks and yield opportunities. Send an array of balance requests - each request can specify a yieldId (optional for chain scanning), address, network, and custom arguments. This is the same format as the single yield balance endpoint but in array form. Duplicate requests (same yieldId + address + network) are automatically deduplicated, with specific yield requests taking precedence over chain scans. * @summary Get balances across multiple yields and networks */ -export const yieldsGetAggregateBalances = ( +export const getAggregateBalances = ( balancesRequestDto: BalancesRequestDto, ) => { return customFetch({ @@ -54,7 +54,7 @@ export const yieldsGetAggregateBalances = ( * Retrieve detailed information about a specific yield opportunity including APY, tokens, protocol details, and more. * @summary Get yield metadata */ -export const yieldsGetYield = (yieldId: string) => { +export const getYield = (yieldId: string) => { return customFetch({ url: `/v1/yields/${yieldId}`, method: "GET" }); }; @@ -62,7 +62,7 @@ export const yieldsGetYield = (yieldId: string) => { * Retrieve all balances associated with a yield position for a specific wallet address, including active, pending, claimable, and withdrawable balances. The network is automatically determined from the yield configuration. * @summary Get balances for a specific yield and address */ -export const yieldsGetYieldBalances = ( +export const getYieldBalances = ( yieldId: string, params: YieldsControllerGetYieldBalancesParams, ) => { @@ -77,7 +77,7 @@ export const yieldsGetYieldBalances = ( * Retrieve a paginated list of validators available for staking or delegation for this yield opportunity. * @summary Get yield validators */ -export const yieldsGetYieldValidators = ( +export const getYieldValidators = ( yieldId: string, params?: YieldsControllerGetYieldValidatorsParams, ) => { @@ -92,9 +92,7 @@ export const yieldsGetYieldValidators = ( * Retrieve all actions performed by a user, with optional filtering by yield, status, category, etc. In the future, this may include personalized action recommendations. * @summary Get user actions */ -export const actionsGetActions = ( - params: ActionsControllerGetActionsParams, -) => { +export const getActions = (params: ActionsControllerGetActionsParams) => { return customFetch({ url: `/v1/actions`, method: "GET", @@ -106,7 +104,7 @@ export const actionsGetActions = ( * Retrieve detailed information about a specific action including current status, transactions, and execution details. * @summary Get action details */ -export const actionsGetAction = (actionId: string) => { +export const getAction = (actionId: string) => { return customFetch({ url: `/v1/actions/${actionId}`, method: "GET", @@ -117,7 +115,7 @@ export const actionsGetAction = (actionId: string) => { * Generate the transactions needed to enter a yield position with the provided parameters. * @summary Enter a yield */ -export const actionsEnterYield = (createActionDto: CreateActionDto) => { +export const enterYield = (createActionDto: CreateActionDto) => { return customFetch({ url: `/v1/actions/enter`, method: "POST", @@ -130,7 +128,7 @@ export const actionsEnterYield = (createActionDto: CreateActionDto) => { * Generate the transactions needed to exit a yield position with the provided parameters. * @summary Exit a yield */ -export const actionsExitYield = (createActionDto: CreateActionDto) => { +export const exitYield = (createActionDto: CreateActionDto) => { return customFetch({ url: `/v1/actions/exit`, method: "POST", @@ -143,9 +141,7 @@ export const actionsExitYield = (createActionDto: CreateActionDto) => { * Generate the transactions needed to perform management actions on a yield position. * @summary Manage a yield */ -export const actionsManageYield = ( - createManageActionDto: CreateManageActionDto, -) => { +export const manageYield = (createManageActionDto: CreateManageActionDto) => { return customFetch({ url: `/v1/actions/manage`, method: "POST", @@ -158,7 +154,7 @@ export const actionsManageYield = ( * Submit the transaction hash after broadcasting a transaction to the blockchain. This updates the transaction status and enables tracking. * @summary Submit transaction hash */ -export const transactionsSubmitTransactionHash = ( +export const submitTransactionHash = ( transactionId: string, submitHashDto: SubmitHashDto, ) => { @@ -174,7 +170,7 @@ export const transactionsSubmitTransactionHash = ( * Retrieve detailed information about a specific transaction including current status, hash, and execution details. * @summary Get transaction details */ -export const transactionsGetTransaction = (transactionId: string) => { +export const getTransaction = (transactionId: string) => { return customFetch({ url: `/v1/transactions/${transactionId}`, method: "GET", @@ -185,7 +181,7 @@ export const transactionsGetTransaction = (transactionId: string) => { * Retrieve a list of all supported networks that can be used for filtering yields and other operations. * @summary List all available networks */ -export const networksGetNetworks = () => { +export const getNetworks = () => { return customFetch({ url: `/v1/networks`, method: "GET" }); }; @@ -193,7 +189,7 @@ export const networksGetNetworks = () => { * Returns a paginated list of all providers, including both protocol and validator providers. * @summary Get all providers */ -export const providersGetProviders = ( +export const getProviders = ( params?: ProvidersControllerGetProvidersParams, ) => { return customFetch({ @@ -207,7 +203,7 @@ export const providersGetProviders = ( * Returns detailed information about a specific provider. * @summary Get provider by ID */ -export const providersGetProvider = (providerId: string) => { +export const getProvider = (providerId: string) => { return customFetch({ url: `/v1/providers/${providerId}`, method: "GET", @@ -218,55 +214,51 @@ export const providersGetProvider = (providerId: string) => { * Get the health status of the yield API with current timestamp * @summary Health check */ -export const healthHealth = () => { +export const health = () => { return customFetch({ url: `/health`, method: "GET" }); }; -export type YieldsGetYieldsResult = NonNullable< - Awaited> ->; -export type YieldsGetAggregateBalancesResult = NonNullable< - Awaited> ->; -export type YieldsGetYieldResult = NonNullable< - Awaited> +export type GetYieldsResult = NonNullable< + Awaited> >; -export type YieldsGetYieldBalancesResult = NonNullable< - Awaited> +export type GetAggregateBalancesResult = NonNullable< + Awaited> >; -export type YieldsGetYieldValidatorsResult = NonNullable< - Awaited> +export type GetYieldResult = NonNullable>>; +export type GetYieldBalancesResult = NonNullable< + Awaited> >; -export type ActionsGetActionsResult = NonNullable< - Awaited> +export type GetYieldValidatorsResult = NonNullable< + Awaited> >; -export type ActionsGetActionResult = NonNullable< - Awaited> +export type GetActionsResult = NonNullable< + Awaited> >; -export type ActionsEnterYieldResult = NonNullable< - Awaited> +export type GetActionResult = NonNullable< + Awaited> >; -export type ActionsExitYieldResult = NonNullable< - Awaited> +export type EnterYieldResult = NonNullable< + Awaited> >; -export type ActionsManageYieldResult = NonNullable< - Awaited> +export type ExitYieldResult = NonNullable< + Awaited> >; -export type TransactionsSubmitTransactionHashResult = NonNullable< - Awaited> +export type ManageYieldResult = NonNullable< + Awaited> >; -export type TransactionsGetTransactionResult = NonNullable< - Awaited> +export type SubmitTransactionHashResult = NonNullable< + Awaited> >; -export type NetworksGetNetworksResult = NonNullable< - Awaited> +export type GetTransactionResult = NonNullable< + Awaited> >; -export type ProvidersGetProvidersResult = NonNullable< - Awaited> +export type GetNetworksResult = NonNullable< + Awaited> >; -export type ProvidersGetProviderResult = NonNullable< - Awaited> +export type GetProvidersResult = NonNullable< + Awaited> >; -export type HealthHealthResult = NonNullable< - Awaited> +export type GetProviderResult = NonNullable< + Awaited> >; +export type HealthResult = NonNullable>>;