Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit9bb2b4c

Browse files
committed
Add support for 1inch price aggregator
1 parent610b958 commit9bb2b4c

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

‎CHANGELOG.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
- Project Setup:heavy_check_mark:
66
- Initial commit:heavy_check_mark:
7-
- Add support for 1inch price aggregator
7+
- Add support for 1inch price aggregator:heavy_check_mark:
88
- Add ability to monitor multiple tokens concurrently
99
- Add ability to buy and sell tokens across various supported exchanges on different blockchains
10-
- Add support for ethereum blockchain
10+
- Add support for ethereum blockchain:heavy_check_mark:
1111

1212
`v1.0.0`
1313

‎src/lib/1inch.io.ts‎renamed to ‎src/lib/1inch.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ export class OneInch extends Aggr {
77
constructor(){
88
super(`1Inch`,`https://api.1inch.exchange/v3.0/`);
99
}
10+
/**
11+
* Gets the best exchange rate for a given pair
12+
*@param srcToken - from token
13+
*@param toToken - to token
14+
*@param srcAmount - from token amount
15+
*@param side - trade direction i.e buy or sell
16+
*@returns best quote found
17+
*/
1018
getQuote=async(params:{srcToken:string,toToken:string,srcAmount:number|string,side?:string}):Promise<Quote>=>{
1119
const{ srcToken, toToken, srcAmount, side}=params
1220
try{
@@ -26,18 +34,31 @@ export class OneInch extends Aggr {
2634

2735
}
2836
}
37+
/**
38+
* Builds a tx based on the given params
39+
*@param srcToken - from Token
40+
*@param toToken - to Token
41+
*@param srcAmount - from Token amount
42+
*@param slippage - slippage tolerance
43+
*@returns tx data that can be send to the network
44+
*/
2945
buildTx=async(srcToken:string,toToken:string,srcAmount:number,slippage?:number):Promise<string>=>{
3046
try{
47+
letdefaultSlippage=0.5
3148
const{ data}=awaitaxios({
3249
method:"GET",
33-
url:`${this.API_URL}${config.NETWORK.ID}/swap?fromTokenAddress=${srcToken}&toTokenAddress=${toToken}&amount=${srcAmount}&fromAddress=${config.WALLET.PUBLIC_KEY}&disableEstimate=true${slippage ?`&slippage=${slippage}` :''}`
50+
url:`${this.API_URL}${config.NETWORK.ID}/swap?fromTokenAddress=${srcToken}&toTokenAddress=${toToken}&amount=${srcAmount}&fromAddress=${config.WALLET.PUBLIC_KEY}&disableEstimate=false&slippage=${slippage ?`${slippage}` :defaultSlippage}`
3451
})
3552
returndata
3653
}catch(error:any){
3754
thrownewError(JSON.stringify(error));
3855
}
3956
}
4057

58+
/**
59+
* Gets supported protocols by 1inch price aggregator
60+
*@returns Supported protocols by 1inch price aggregator
61+
*/
4162
getProtocols=async():Promise<string[]>=>{
4263
try{
4364
const{ data}:any=awaitaxios({
@@ -51,4 +72,22 @@ export class OneInch extends Aggr {
5172
}
5273
}
5374

75+
/**
76+
* Approves spender to trade the given amount of a token
77+
*@param tokenAddress address of the token to approve
78+
*@param amount amount of the the quantity to approve: default is infinity
79+
*@returns approve data that can be send to the network
80+
*/
81+
approve=async(tokenAddress:string,amount?:string)=>{
82+
try{
83+
const{ data}=awaitaxios({
84+
method:"GET",
85+
url:`${this.API_URL}${config.NETWORK.ID}/approve/calldata?tokenAddress=${tokenAddress}`
86+
})
87+
returndata
88+
}catch(error:any){
89+
thrownewError(JSON.stringify(error));
90+
}
91+
}
92+
5493
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp