-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from yuichiroaoki/dev
Dev
- Loading branch information
Showing
14 changed files
with
209 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Table } from "console-table-printer"; | ||
import { baseTokens, tradingTokens } from "../config"; | ||
const readline = require("readline"); | ||
|
||
export const initPriceTable = (p: Table, idx: number) => { | ||
baseTokens.forEach(async (baseToken) => { | ||
tradingTokens.forEach(async (tradingToken) => { | ||
if (baseToken.address > tradingToken.address) { | ||
p.addRow({ | ||
index: idx, | ||
|
||
fromToken: (baseToken === tradingToken | ||
? "" | ||
: baseToken.symbol | ||
).padEnd(6), | ||
toToken: (baseToken === tradingToken | ||
? "" | ||
: tradingToken.symbol | ||
).padEnd(6), | ||
|
||
fromAmount: "".padStart(7), | ||
toAmount: "".padStart(7), | ||
|
||
difference: "".padStart(7), | ||
percentage: "".padStart(5), | ||
|
||
time: "".padStart(6), | ||
timestamp: "".padStart(24), | ||
}); | ||
|
||
idx++; | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export const renderTables = (p: Table, pp: Table) => { | ||
// console.clear(); | ||
readline.cursorTo(process.stdout, 0, 0); | ||
|
||
p.printTable(); | ||
|
||
if (pp.table.rows.length > 0) { | ||
pp.printTable(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Table } from "console-table-printer"; | ||
|
||
export const priceTable = (maxX: number) => | ||
new Table({ | ||
// title: "Quotes", | ||
columns: [ | ||
{ name: "index", title: "#", alignment: "right" }, | ||
|
||
{ name: "fromToken", title: "From", alignment: "left" }, | ||
{ name: "fromAmount", title: "Amount", alignment: "right" }, | ||
|
||
{ name: "toToken", title: "To", alignment: "left" }, | ||
{ name: "toAmount", title: "Amount", alignment: "right" }, | ||
|
||
{ name: "difference", title: "±", alignment: "right" }, | ||
{ name: "percentage", title: "%", alignment: "right" }, | ||
|
||
{ name: "log", title: "Log", alignment: "left", maxLen: maxX - 101 }, | ||
|
||
{ name: "time", title: "Time", alignment: "right" }, | ||
{ name: "timestamp", title: "Timestamp", alignment: "right" }, | ||
], | ||
}); | ||
|
||
export const flashloanTable = (maxX: number) => | ||
new Table({ | ||
title: "Flash Loans", | ||
columns: [ | ||
{ name: "baseToken", title: "From", alignment: "left" }, | ||
{ name: "tradingToken", title: "To", alignment: "left" }, | ||
|
||
{ name: "amount", title: "Amount", alignment: "right" }, | ||
|
||
{ name: "difference", title: "±", alignment: "right" }, | ||
{ name: "percentage", title: "%", alignment: "right" }, | ||
|
||
{ | ||
name: "firstRoutes", | ||
title: "First Routes", | ||
alignment: "left", | ||
maxLen: maxX / 2 - 78, | ||
}, | ||
{ | ||
name: "secondRoutes", | ||
title: "Second Routes", | ||
alignment: "left", | ||
maxLen: maxX / 2 - 79, | ||
}, | ||
|
||
{ | ||
name: "txHash", | ||
title: "Transaction Hash", | ||
alignment: "left", | ||
}, | ||
|
||
{ name: "time", title: "Time", alignment: "right" }, | ||
{ name: "timestamp", title: "Timestamp", alignment: "right" }, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { BigNumber } from "ethers"; | ||
import { protocols } from "../../config"; | ||
|
||
/** | ||
* Will get the 1inch API call URL for a trade | ||
* @param chainId chain id of the network | ||
* @param fromTokenAddress token address of the token you want to sell | ||
* @param toTokenAddress token address of the token you want to buy | ||
* @param amount amount of the token you want to sell | ||
* @returns call URL for 1inch API | ||
*/ | ||
export function get1inchQuoteCallUrl( | ||
chainId: number, | ||
fromTokenAddress: string, | ||
toTokenAddress: string, | ||
amount: BigNumber | ||
): string { | ||
const params = { | ||
fromTokenAddress: fromTokenAddress, | ||
toTokenAddress: toTokenAddress, | ||
amount: amount.toString(), | ||
protocols: protocols, | ||
}; | ||
const apiURL = "https://api.1inch.exchange/v4.0/"; | ||
const searchString = new URLSearchParams(params); | ||
const callURL = `${apiURL}${chainId}/quote?${searchString}`; | ||
return callURL; | ||
} |
4 changes: 2 additions & 2 deletions
4
src/uniswap/v2/getPrice.ts → src/price/uniswap/v2/getPrice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.