Skip to content

Commit 46ac840

Browse files
Integrated Swing for advanceRoutes endpoint (#233)
1 parent 789364e commit 46ac840

12 files changed

Lines changed: 360 additions & 5 deletions

File tree

examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"28-number-of-transactions" : "../node_modules/.bin/ts-node ./src/28-number-of-transactions.ts",
3434
"29-trading-history" : "../node_modules/.bin/ts-node ./src/29-trading-history.ts",
3535
"30-market-details" : "../node_modules/.bin/ts-node ./src/30-market-details.ts",
36-
"31-net-curve-balances" : "../node_modules/.bin/ts-node ./src/31-net-curve-balances.ts"
36+
"31-net-curve-balances" : "../node_modules/.bin/ts-node ./src/31-net-curve-balances.ts",
37+
"32-advance-routes" : "../node_modules/.bin/ts-node ./src/32-advance-routes.ts"
3738
},
3839
"dependencies": {
3940
"dotenv": "16.0.1"

examples/src/32-advance-routes.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ethers, utils, Wallet } from 'ethers';
2+
import { EnvNames, NetworkNames, Sdk, NETWORK_NAME_TO_CHAIN_ID } from '../../src';
3+
import { logger } from './common';
4+
import * as dotenv from 'dotenv';
5+
dotenv.config();
6+
7+
async function main(): Promise<void> {
8+
const wallet = Wallet.createRandom();
9+
10+
logger.log('sender wallet', wallet.address);
11+
12+
const sdk = new Sdk(wallet, {
13+
env: EnvNames.LocalNets,
14+
networkName: NetworkNames.LocalA,
15+
});
16+
17+
const { state } = sdk;
18+
19+
logger.log('key account', state.account);
20+
21+
const fromChainId: number = NETWORK_NAME_TO_CHAIN_ID[NetworkNames.Mainnet];
22+
const toChainId: number = NETWORK_NAME_TO_CHAIN_ID[NetworkNames.Bsc];
23+
24+
const fromAmount = utils.parseUnits('1', 18);
25+
26+
const quoteRequestPayload = {
27+
fromChainId: fromChainId,
28+
toChainId: toChainId,
29+
fromTokenAddress: ethers.constants.AddressZero,
30+
toTokenAddress: ethers.constants.AddressZero,
31+
fromAmount: fromAmount,
32+
};
33+
34+
const quotes = await sdk.advanceRoutes(quoteRequestPayload);
35+
36+
logger.log('Advance Routes: ', quotes.items);
37+
}
38+
39+
main()
40+
.catch(logger.error)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "etherspot",
3-
"version": "1.43.8",
3+
"version": "1.43.9",
44
"description": "Etherspot SDK",
55
"keywords": [
66
"ether",

schema.graphql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,19 @@ type Query {
733733
numberOfTransactions(chainId: Int, tokenAddress: String!, provider: String): NumberOfTransactions!
734734
tradingHistory(chainId: Int, tokenAddress: String!, provider: String, page: Int): TradingHistories!
735735
marketDetails(chainId: Int, tokenAddress: String!, provider: String, timePeriod: String!): MarketDetails!
736+
advanceRoutes(
737+
serviceProvider: String
738+
account: String!
739+
fromTokenAddress: String!
740+
toTokenAddress: String!
741+
fromAmount: BigNumber!
742+
fromChainId: Int!
743+
toChainId: Int!
744+
toAddress: String
745+
allowSwitchChain: Boolean
746+
fromAddress: String!
747+
showZeroUsd: Boolean
748+
): AdvanceRoutes!
736749
resolveName(chainId: Int, name: String!): NameResolutionsNodes
737750
nativeCurrencies: NativeCurrencies!
738751
nftList(account: String!, chainId: Int): NftList!
@@ -939,6 +952,44 @@ type MarketDetails {
939952
priceChangePercentage1y?: number!
940953
}
941954

955+
type FeesToken {
956+
address: string!
957+
symbol: string!
958+
decimals: number
959+
chain: string!
960+
}
961+
962+
type FeesCost {
963+
type: string!
964+
token: FeesToken!
965+
amount: BigNumber!
966+
amountUSD: string
967+
}
968+
969+
type AdvanceRouteToken {
970+
address: string!
971+
symbol: string!
972+
decimals: number
973+
name: string!
974+
}
975+
976+
type AdvanceRoute {
977+
provider: string!
978+
fromToken: AdvanceRouteToken!
979+
toToken: AdvanceRouteToken!
980+
duration: number!
981+
gasUSD: string!
982+
tool: string!
983+
amount: BigNumber!
984+
amountUSD: string
985+
feeCosts: [FeesCost!]!
986+
gasCosts: [FeesCost!]!
987+
}
988+
989+
type AdvanceRoutes {
990+
items: [AdvanceRoute!]!
991+
}
992+
942993
type TokenLists {
943994
items: [TokenListPublic!]!
944995
}

src/sdk/dto/advance-routes.dto.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { BigNumber } from 'ethers';
2+
import { Type } from 'class-transformer';
3+
import { IsBoolean, IsInt, IsOptional, IsPositive } from 'class-validator';
4+
import { IsAddress, IsBigNumberish } from './validators';
5+
6+
export class GetAdvanceRoutesDto {
7+
@IsOptional()
8+
serviceProvider?: string;
9+
10+
@IsAddress()
11+
fromTokenAddress: string;
12+
13+
@IsAddress()
14+
toTokenAddress: string;
15+
16+
@IsPositive()
17+
@IsInt()
18+
@Type(() => Number)
19+
fromChainId: number | null;
20+
21+
@IsPositive()
22+
@IsInt()
23+
@Type(() => Number)
24+
toChainId: number;
25+
26+
@IsBigNumberish()
27+
fromAmount: BigNumber;
28+
29+
@IsOptional()
30+
@IsAddress()
31+
toAddress?: string;
32+
33+
@IsOptional()
34+
@IsAddress()
35+
fromAddress?: string;
36+
37+
@IsOptional()
38+
@IsBoolean()
39+
allowSwitchChain?: boolean;
40+
41+
@IsOptional()
42+
@IsBoolean()
43+
showZeroUsd?: boolean;
44+
}

src/sdk/dto/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ export * from './get-token-details.dto';
8282
export * from './get-historical-token-price.dto';
8383
export * from './get-pools-activity.dto';
8484
export * from './get-trading-history.dto';
85-
export * from './get-account-24hour-net-curve.dto';
85+
export * from './get-account-24hour-net-curve.dto';
86+
export * from './advance-routes.dto';
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { BigNumber } from 'ethers';
2+
import { TransformBigNumber } from '../../common/transformers/transform-big-number';
3+
4+
export class AdvanceRouteToken {
5+
address: string;
6+
7+
symbol: string;
8+
9+
decimals?: number;
10+
11+
name: string;
12+
}
13+
14+
export class FeesToken {
15+
address: string;
16+
17+
symbol: string;
18+
19+
decimals?: number;
20+
21+
chain: string;
22+
}
23+
24+
export class FeesCost {
25+
type: string;
26+
27+
token: FeesToken;
28+
29+
@TransformBigNumber()
30+
amount: BigNumber;
31+
32+
amountUSD?: string;
33+
}
34+
35+
export class AdvanceRoute {
36+
provider: string;
37+
38+
fromToken: AdvanceRouteToken;
39+
40+
toToken: AdvanceRouteToken;
41+
42+
duration: number;
43+
44+
gasUSD: string;
45+
46+
tool: string;
47+
48+
@TransformBigNumber()
49+
amount: BigNumber;
50+
51+
amountUSD: string;
52+
53+
feeCosts?: FeesCost[];
54+
55+
gasCosts?: FeesCost[];
56+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { AdvanceRoute } from './advance-route';
2+
3+
export class AdvanceRoutes {
4+
items: AdvanceRoute[];
5+
}

src/sdk/exchange/classes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ export * from './exchange-router-address';
1212
export * from './step-transactions-lifi';
1313
export * from './advance-routes-lifi';
1414
export * from './lifi-status';
15+
export * from './advance-route';
16+
export * from './advance-routes';

0 commit comments

Comments
 (0)