From 5f427491570986759439342214efd4fb51a7718d Mon Sep 17 00:00:00 2001 From: salil-naik Date: Wed, 29 Nov 2023 12:41:19 +0530 Subject: [PATCH] feat: added socketRoute to quote response --- package.json | 4 ++-- src/baseSocket.ts | 26 +++++++++++------------ src/client/models/QuoteOutputDTO.ts | 2 ++ src/client/models/SocketRoute.ts | 33 +++++++++++++++++++++++++++++ yarn.lock | 18 ++++++++-------- 5 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 src/client/models/SocketRoute.ts diff --git a/package.json b/package.json index 2496c86..92db2e3 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ "typescript": "^4.6.4" }, "dependencies": { - "@socket.tech/ll-core": "0.1.46", - "@socket.tech/ll-core-v2": "^0.0.55", + "@socket.tech/ll-core": "^0.1.49", + "@socket.tech/ll-core-v2": "^0.0.66", "axios": "^0.27.2", "ethers": "^5.6.5", "form-data": "^4.0.0", diff --git a/src/baseSocket.ts b/src/baseSocket.ts index 4cbbc02..fbb18df 100644 --- a/src/baseSocket.ts +++ b/src/baseSocket.ts @@ -22,6 +22,7 @@ import { ChainId } from "@socket.tech/ll-core"; import { ActiveRoutesRequest } from "./client/models/ActiveRoutesRequest"; import { SocketPreferences } from "./client/models/SocketPreferences"; import { TokenListRequest } from "./client/models/TokenListRequest"; +import { SocketRoute } from "./client/models/SocketRoute"; export interface ActiveRouteGenerator extends AsyncGenerator { /** Active Route Id */ @@ -104,13 +105,12 @@ export abstract class BaseSocket { /** * get Balances for a user address - * @param userAddress The user address + * @param userAddress The user address */ - async getBalances({userAddress}) { - return await Balances.getBalances({userAddress}) + async getBalances({ userAddress }) { + return await Balances.getBalances({ userAddress }); } - /** * get Balance for a user address * @param tokenAddress The token address @@ -119,19 +119,14 @@ export abstract class BaseSocket { * @returns The balance */ - async getBalance({ - tokenAddress, - chainId, - userAddress, - }) { + async getBalance({ tokenAddress, chainId, userAddress }) { return await Balances.getBalance({ tokenAddress, chainId, userAddress, - }) + }); } - /** * Get the list of tokens available for each chain for a given path * @param options @@ -181,7 +176,7 @@ export abstract class BaseSocket { * @returns The best quote if found or null */ async getBestQuote(params: QuoteParams, preferences?: QuotePreferences) { - const {routes} = await this.getAllQuotes(params, preferences); + const { routes } = await this.getAllQuotes(params, preferences); // API returns the 'sort by time' in descending order of service time, hence reversing the order // To be removed once API response is fixed if (preferences?.sort === SortOptions.Time) { @@ -198,7 +193,11 @@ export abstract class BaseSocket { async getAllQuotes( { path, address, amount }: QuoteParams, preferences?: QuotePreferences - ): Promise<{ routes: SocketQuote[]; bridgeRouteErrors: BridgeRouteErrors }> { + ): Promise<{ + routes: SocketQuote[]; + bridgeRouteErrors: BridgeRouteErrors; + socketRoute: SocketRoute; + }> { const finalPreferences = { ...(this._options.defaultQuotePreferences || {}), ...(preferences || {}), @@ -228,6 +227,7 @@ export abstract class BaseSocket { errors: quote.bridgeRouteErrors, })) || [], bridgeRouteErrors: quote.bridgeRouteErrors, + socketRoute: quote.socketRoute, }; } diff --git a/src/client/models/QuoteOutputDTO.ts b/src/client/models/QuoteOutputDTO.ts index 839fc5e..77be04a 100644 --- a/src/client/models/QuoteOutputDTO.ts +++ b/src/client/models/QuoteOutputDTO.ts @@ -1,6 +1,7 @@ import { BridgeRouteErrors } from "./BridgeRouteErrors"; import { RefuelData } from "./RefuelData"; import type { Route } from "./Route"; +import { SocketRoute } from "./SocketRoute"; import type { Token } from "./Token"; export type Quote = { @@ -11,6 +12,7 @@ export type Quote = { toChainId?: number; toAsset?: Token; bridgeRouteErrors: BridgeRouteErrors; + socketRoute?: SocketRoute }; export type QuoteOutputDTO = { diff --git a/src/client/models/SocketRoute.ts b/src/client/models/SocketRoute.ts new file mode 100644 index 0000000..1687439 --- /dev/null +++ b/src/client/models/SocketRoute.ts @@ -0,0 +1,33 @@ +import { Token } from "./Token"; + +type FeeData = { + [time: string]: { + feesInUsd: number; + amount: string; + }; +}; + +export type SocketBridgeFees = { + asset: Token; + feeDeductedByMins: FeeData; +}; + +export type SocketRoute = { + bridgeFees: SocketBridgeFees; + bridgeSlippage: string; + fromAmount: string; + fromAsset: Token; + fromChainId: number; + inputValueInUsd: number; + isOnlySwapRoute: boolean; + minAmountOut: string; + minAmountOutInUsd: number; + outputValueInUsd: number; + recipient: string; + sender: string; + toAmount: string; + toAsset: Token; + toChainId: number; + fromTokenPriceInUsd: number; + toTokenPriceInUsd: number; +}; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 5c29336..d9bc44b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -969,15 +969,15 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@socket.tech/ll-core-v2@^0.0.55": - version "0.0.55" - resolved "https://registry.yarnpkg.com/@socket.tech/ll-core-v2/-/ll-core-v2-0.0.55.tgz#1e1210169dea9a54923245517b2a0ace6fe90061" - integrity sha512-f2aVQMBWhye49j0mvpWT90Lf01haqP5iZMRQRS4gaIIatw6Izrv0ah/OvVePsRz7TuXdc1xQ1vogGUdweV+DkA== - -"@socket.tech/ll-core@0.1.46": - version "0.1.46" - resolved "https://registry.yarnpkg.com/@socket.tech/ll-core/-/ll-core-0.1.46.tgz#0db6cd92c7eec4690b4fd6257ded8d059caa712e" - integrity sha512-yKsITqdgwXp6d5VeItkO/FG12sW/7J44q/Ln9Obi6mVBKQcTabCOYtguGz02rEpY+8iGJpiZrDWo9wcu+QPJYg== +"@socket.tech/ll-core-v2@^0.0.66": + version "0.0.66" + resolved "https://registry.yarnpkg.com/@socket.tech/ll-core-v2/-/ll-core-v2-0.0.66.tgz#3969a044b89d6143b470525aa5406e7493eff638" + integrity sha512-ecsuBSz83NKZXAt8pkIwVOJ+/XwzHOSrzlnVnYYGn2cRkn84UZyCns5G7lqglvYTO97LwHYcWyOAoUqn4/4/rA== + +"@socket.tech/ll-core@^0.1.49": + version "0.1.49" + resolved "https://registry.yarnpkg.com/@socket.tech/ll-core/-/ll-core-0.1.49.tgz#dd3c28ddb7fd43f2d91c482edd43ccfca2da4972" + integrity sha512-V/xPaXOeYEsKiFoEnHqhJM0tgHvGBjoO41AqHIPuZipK684WmAeYD+72Hz2W/S7ysrdqMp1B1leR/hc9UzbDjg== "@types/babel__core@^7.1.14": version "7.20.1"