Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
feat: added socketRoute to quote response
Browse files Browse the repository at this point in the history
  • Loading branch information
salil-naik committed Nov 29, 2023
1 parent 927c8ae commit 5f42749
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 13 additions & 13 deletions src/baseSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketTx, void, string> {
/** Active Route Id */
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 || {}),
Expand Down Expand Up @@ -228,6 +227,7 @@ export abstract class BaseSocket {
errors: quote.bridgeRouteErrors,
})) || [],
bridgeRouteErrors: quote.bridgeRouteErrors,
socketRoute: quote.socketRoute,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/client/models/QuoteOutputDTO.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -11,6 +12,7 @@ export type Quote = {
toChainId?: number;
toAsset?: Token;
bridgeRouteErrors: BridgeRouteErrors;
socketRoute?: SocketRoute
};

export type QuoteOutputDTO = {
Expand Down
33 changes: 33 additions & 0 deletions src/client/models/SocketRoute.ts
Original file line number Diff line number Diff line change
@@ -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;
};
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].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"
Expand Down

0 comments on commit 5f42749

Please sign in to comment.