-
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 #78 from yuichiroaoki/without_1INCH
Without 1 inch
- Loading branch information
Showing
22 changed files
with
349 additions
and
810 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,46 +1,45 @@ | ||
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(); | ||
} | ||
}; | ||
// 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
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 |
---|---|---|
@@ -1,64 +1,64 @@ | ||
require("dotenv").config(); | ||
import { ethers } from "ethers"; | ||
import * as ABI from "./abis/Flashloan.json"; | ||
import { IFlashloanRoute } from "./interfaces/main"; | ||
import { findPool, findRouter, findToken } from "./utils"; | ||
// require("dotenv").config(); | ||
// import { ethers } from "ethers"; | ||
// import * as ABI from "./abis/Flashloan.json"; | ||
// import { IFlashloanRoute } from "./interfaces/main"; | ||
// import { findPool, findRouter, findToken } from "./utils"; | ||
|
||
if (process.env.ALCHEMY_POLYGON_RPC_URL === undefined) { | ||
throw new Error("Please set ALCHEMY_POLYGON_RPC_URL environment variable."); | ||
} | ||
// if (process.env.ALCHEMY_POLYGON_RPC_URL === undefined) { | ||
// throw new Error("Please set ALCHEMY_POLYGON_RPC_URL environment variable."); | ||
// } | ||
|
||
const maticProvider = new ethers.providers.JsonRpcProvider( | ||
process.env.ALCHEMY_POLYGON_RPC_URL | ||
); | ||
// const maticProvider = new ethers.providers.JsonRpcProvider( | ||
// process.env.ALCHEMY_POLYGON_RPC_URL | ||
// ); | ||
|
||
const inter = new ethers.utils.Interface(ABI.abi); | ||
// const inter = new ethers.utils.Interface(ABI.abi); | ||
|
||
const router = (route: IFlashloanRoute) => { | ||
const protocols = route.hops.map((hop) => { | ||
const tokenPair = `${findToken(hop.path[0])} → ${findToken(hop.path[1])}`; | ||
return `${tokenPair}: ${hop.swaps}`; | ||
}); | ||
return protocols; | ||
}; | ||
// const router = (route: IFlashloanRoute) => { | ||
// const protocols = route.hops.map((hop) => { | ||
// const tokenPair = `${findToken(hop.path[0])} → ${findToken(hop.path[1])}`; | ||
// return `${tokenPair}: ${hop.swaps}`; | ||
// }); | ||
// return protocols; | ||
// }; | ||
|
||
export const main = async () => { | ||
var args = process.argv.slice(2); | ||
// export const main = async () => { | ||
// var args = process.argv.slice(2); | ||
|
||
const tx = await maticProvider.getTransaction(args[0]); | ||
console.log({ | ||
hash: tx.hash, | ||
from: tx.from, | ||
to: tx.to, | ||
// const tx = await maticProvider.getTransaction(args[0]); | ||
// console.log({ | ||
// hash: tx.hash, | ||
// from: tx.from, | ||
// to: tx.to, | ||
|
||
gasPrice: tx.gasPrice?.toNumber(), | ||
gasLimit: tx.gasLimit?.toNumber(), | ||
// gasPrice: tx.gasPrice?.toNumber(), | ||
// gasLimit: tx.gasLimit?.toNumber(), | ||
|
||
nonce: tx.nonce, | ||
blockNumber: tx.blockNumber, | ||
}); | ||
// nonce: tx.nonce, | ||
// blockNumber: tx.blockNumber, | ||
// }); | ||
|
||
const decodedInput = inter.parseTransaction({ | ||
data: tx.data, | ||
value: tx.value, | ||
}); | ||
console.log({ | ||
name: decodedInput.name, | ||
// const decodedInput = inter.parseTransaction({ | ||
// data: tx.data, | ||
// value: tx.value, | ||
// }); | ||
// console.log({ | ||
// name: decodedInput.name, | ||
|
||
params: { | ||
flashLoanPool: findPool(decodedInput.args.params.flashLoanPool), | ||
loanAmount: decodedInput.args.params.loanAmount.toNumber(), | ||
firstRoutes: decodedInput.args.params.firstRoutes.map( | ||
(route: IFlashloanRoute) => JSON.stringify(router(route)) | ||
), | ||
secondRoutes: decodedInput.args.params.secondRoutes.map( | ||
(route: IFlashloanRoute) => JSON.stringify(router(route)) | ||
), | ||
}, | ||
}); | ||
}; | ||
// params: { | ||
// flashLoanPool: findPool(decodedInput.args.params.flashLoanPool), | ||
// loanAmount: decodedInput.args.params.loanAmount.toNumber(), | ||
// firstRoutes: decodedInput.args.params.firstRoutes.map( | ||
// (route: IFlashloanRoute) => JSON.stringify(router(route)) | ||
// ), | ||
// secondRoutes: decodedInput.args.params.secondRoutes.map( | ||
// (route: IFlashloanRoute) => JSON.stringify(router(route)) | ||
// ), | ||
// }, | ||
// }); | ||
// }; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
// main().catch((error) => { | ||
// console.error(error); | ||
// process.exit(1); | ||
// }); |
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.