Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update name for CrossChain Route #4

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ensofinance/use-defi",
"version": "0.2.2",
"version": "0.2.3",
"description": "React hooks library to use with enso shortcuts infrastructure",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions src/api/multichain.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import axios from 'axios';

import { ENSO_API } from '../constants';
import { API_MultichainOptions, API_MultichainResponse } from '../types/api';
import { API_CrossChainOptions, API_CrossChainResponse } from '../types/api';
import { API_Response } from '../types/enso';
import { parseApiErrorOrReturn } from '../utils/parseApiError';

export const getEnsoApiMultichainRoute = async (
options: API_MultichainOptions,
): Promise<API_MultichainResponse | undefined> => {
const { data } = await axios.post<API_Response<API_MultichainResponse>>(
export const getEnsoApiCrossChainRoute = async (
options: API_CrossChainOptions,
): Promise<API_CrossChainResponse | undefined> => {
const { data } = await axios.post<API_Response<API_CrossChainResponse>>(
`${ENSO_API}/api/experimental/multichain/shortcut/route/${options.sourceChainId}/${options.destinationChainId}/${options.fromAddress}`,
JSON.stringify({
tokenIn: options.tokenIn,
Expand Down
50 changes: 49 additions & 1 deletion src/generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export interface paths {
/** Build a shortcut from multiple contract calls */
post: operations["BuilderController_builderShortcutTransaction"];
};
"/api/experimental/multichain/shortcut/route/{sourceChainId}/{destinationChainId}/{fromAddress}": {
post: operations["SocketController_multichainRouteShortcutTransactionWithSocket"];
};
}

export type webhooks = Record<string, never>;
Expand Down Expand Up @@ -330,6 +333,29 @@ export interface components {
*/
calls: components["schemas"]["CallsToBuild"][];
};
MultichainRouteShortcutInputsBase: {
/**
* @description Ethereum address of the token to swap from. For ETH, use 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
* @example 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
*/
tokenIn: string;
/**
* @description Ethereum address of the token to swap from. For ETH, use 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
* @example 0x6b175474e89094c44da98b954eedeac495271d0f
*/
tokenOut: string;
/**
* @description Amount of tokenIn to swap in wei
* @example "1000000000000000000"
*/
amountIn: string;
/**
* @description Slippage in basis points (1/10000)
* @default 300
* @example 300
*/
slippage?: string;
};
};
responses: never;
parameters: never;
Expand Down Expand Up @@ -603,7 +629,12 @@ export interface operations {
*/
amountIn: string[];
/**
* @description Slippage in basis points (1/10000)
* @description Minimum amount out in wei. If specified, slippage should not be specified
* @example 1000000000000000000
*/
minAmountOut?: string[];
/**
* @description Slippage in basis points (1/10000). If specified, minAmountOut should not be specified
* @example 300
*/
slippage?: string;
Expand Down Expand Up @@ -720,4 +751,21 @@ export interface operations {
201: never;
};
};
SocketController_multichainRouteShortcutTransactionWithSocket: {
parameters: {
path: {
sourceChainId: number;
destinationChainId: number;
fromAddress: string;
};
};
requestBody: {
content: {
"application/json": components["schemas"]["MultichainRouteShortcutInputsBase"];
};
};
responses: {
201: never;
};
};
}
2 changes: 1 addition & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './usePositions';
export * from './useExecutePosition';
export * from './useMultichainRoute';
export * from './useCrossChainRoute';
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useCallback, useMemo } from 'react';
import { useQuery } from 'react-query';

import { getEnsoApiMultichainRoute } from '../../api/multichain';
import { API_MultichainOptions } from '../../types/api';
import { getEnsoApiCrossChainRoute } from '../../api/multichain';
import { API_CrossChainOptions } from '../../types/api';
import { useDeFiContext } from '../internal/useDeFiContext';
import { useDeFiWalletClient } from '../internal/useDeFiWalletClient';
import { useExecutor } from '../internal/useExecutor';

import { UseMultichainRouteArgs, UseMultichainRoutePayload } from './types';
import { UseCrossChainRouteArgs, UseCrossChainRoutePayload } from './types';

type QueryOptionsWithError = [API_MultichainOptions | undefined, string | undefined];
type QueryOptionsWithError = [API_CrossChainOptions | undefined, string | undefined];

export const useMultichainRoute = (args: UseMultichainRouteArgs | undefined): UseMultichainRoutePayload => {
export const useCrossChainRoute = (args: UseCrossChainRouteArgs | undefined): UseCrossChainRoutePayload => {
const { data: executor } = useExecutor();
const walletClient = useDeFiWalletClient();
const context = useDeFiContext();
Expand All @@ -36,7 +36,7 @@ export const useMultichainRoute = (args: UseMultichainRouteArgs | undefined): Us
];
}, [args, context, executor]);

const { data, status, error } = useQuery('useMultichainRoute', async () => getEnsoApiMultichainRoute(queryOptions!), {
const { data, status, error } = useQuery('useCrossChainRoute', async () => getEnsoApiCrossChainRoute(queryOptions!), {
enabled: !!queryOptions,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Address } from 'viem';

import { API_MultichainResponse } from '../../types/api';
import { API_CrossChainResponse } from '../../types/api';
import { BigNumberish, LoadingState, TransactionFunc } from '../../types/enso';

export type UseMultichainRouteArgs = {
export type UseCrossChainRouteArgs = {
sourceChainId: number;
destinationChainId: number;
tokenIn: Address;
Expand All @@ -14,9 +14,9 @@ export type UseMultichainRouteArgs = {
};
};

export type UseMultichainRoutePayload = {
export type UseCrossChainRoutePayload = {
status: LoadingState;
errorMessage?: string;
tx?: API_MultichainResponse['tx'];
tx?: API_CrossChainResponse['tx'];
execute: TransactionFunc;
};
4 changes: 2 additions & 2 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export type API_AllowancesResponse = {
}[];

// FIXME: Missing in API
export type API_MultichainOptions = {
export type API_CrossChainOptions = {
sourceChainId: number;
destinationChainId: number;
fromAddress: string;
Expand All @@ -133,7 +133,7 @@ export type API_MultichainOptions = {
};

// FIXME: Missing in API
export type API_MultichainResponse = {
export type API_CrossChainResponse = {
createdAt: number;
tx: Transaction & {
to: Address;
Expand Down