-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #1017 from yanyanho/main
add 1inch script
- Loading branch information
Showing
19 changed files
with
507 additions
and
67 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,57 @@ | ||
require("@nomicfoundation/hardhat-toolbox"); | ||
require('dotenv').config(); | ||
|
||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
// This is a sample Hardhat task. To learn how to create your own go to | ||
// https://hardhat.org/guides/create-task.html | ||
task('accounts', 'Prints the list of accounts', async () => { | ||
const accounts = await ethers.getSigners(); | ||
|
||
for (const account of accounts) { | ||
console.log(account.address); | ||
} | ||
}); | ||
|
||
function mnemonic() { | ||
return process.env.PRIVATE_KEY; | ||
} | ||
|
||
/** | ||
* @type import('hardhat/config').HardhatUserConfig | ||
*/ | ||
module.exports = { | ||
solidity: "0.8.17", | ||
solidity: '0.8.17', | ||
networks: { | ||
localhost: { | ||
url: 'http://localhost:8545', | ||
//gasPrice: 125000000000, // you can adjust gasPrice locally to see how much it will cost on production | ||
/* | ||
notice no mnemonic here? it will just use account 0 of the hardhat node to deploy | ||
(you can put in a mnemonic here to set the deployer locally) | ||
*/ | ||
}, | ||
goerli: { | ||
url: 'https://goerli.infura.io/v3/' + process.env.INFURA_ID, //<---- CONFIG YOUR INFURA ID IN .ENV! (or it won't work) | ||
accounts: [mnemonic()], | ||
}, | ||
mainnet: { | ||
url: 'https://eth-mainnet.g.alchemy.com/v2/' + process.env.ALCHEMY, //<---- CONFIG YOUR INFURA ID IN .ENV! (or it won't work) | ||
accounts: [mnemonic()], | ||
}, | ||
ropsten: { | ||
url: 'https://ropsten.infura.io/v3/' + process.env.INFURA_ID, //<---- CONFIG YOUR INFURA ID IN .ENV! (or it won't work) | ||
accounts: [mnemonic()], | ||
}, | ||
arbitest: { | ||
url: 'https://arbitrum-rinkeby.infura.io/v3/' + process.env.INFURA_ID, //<---- CONFIG YOUR INFURA ID IN .ENV! (or it won't work) | ||
accounts: [mnemonic()], | ||
}, | ||
matic: { | ||
url: 'https://polygon-mainnet.infura.io/v3/' + process.env.PROJECT_ID, //<---- CONFIG YOUR INFURA ID IN .ENV! (or it won't work) | ||
accounts: [mnemonic()] | ||
}, | ||
op: { | ||
url: 'https://opt-mainnet.g.alchemy.com/v2/' + process.env.ALCHEMY, | ||
accounts: [mnemonic()], | ||
}, | ||
}, | ||
}; |
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,65 @@ | ||
const hre = require("hardhat"); | ||
const fetch = require('node-fetch'); | ||
const qs = require('qs'); | ||
require('dotenv').config(); | ||
|
||
//https://github.com/0xProject/0x-api-starter-guide-code/blob/master/src/direct-swap.js#L105-L113 | ||
async function main() { | ||
|
||
//const API_QUOTE_URL = 'https://api.0x.org/swap/v1/quote'; | ||
const API_QUOTE_URL = 'https://optimism.api.0x.org/swap/v1/quote'; | ||
console.info(`Fetching swap quote from 0x-API to sell WETH for DAI...`); | ||
|
||
const exchangeOP="0xdef1abe32c034e558cdd535791643c58a13acc10"; | ||
const apiKey = process.env.ZEROXAPIKEY; | ||
|
||
const usdcTokenAddress = '0x7F5c764cBc14f9669B88837ca1490cCa17c31607'; // Replace with actual USDC token address | ||
const opTokenAddress = '0x4200000000000000000000000000000000000042'; // Replace with actual OP token address | ||
const wethTokenAddress = '0x4200000000000000000000000000000000000006'; // Replace with actual OP token address | ||
|
||
const params = { | ||
// Not all token symbols are supported. The address of the token can be used instead. | ||
sellToken:usdcTokenAddress , | ||
buyToken: opTokenAddress, | ||
// Note that the DAI token uses 18 decimal places, so `sellAmount` is `100 * 10^18`. | ||
sellAmount: '5000000', | ||
} | ||
const quoteUrl = `${API_QUOTE_URL}?${qs}`; | ||
|
||
// const headers = { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` } } | ||
|
||
// const response = await fetch( | ||
// `https://api.0x.org/swap/v1/price?${qs.stringify(params)}`, {headers: {'0x-api-key': apiKey}} | ||
// ); | ||
|
||
const response = await fetch( | ||
`https://optimism.api.0x.org/swap/v1/quote?${qs.stringify(params)}`, {headers: {'0x-api-key': apiKey}} | ||
); | ||
|
||
const quote = await response.json(); | ||
console.log(quote) | ||
|
||
console.info(`Received a quote ${quote}`); | ||
console.info(`Received a quote with price ${quote.price}`); | ||
|
||
|
||
const [signer] = await ethers.getSigners(); | ||
|
||
console.log("send transaction ----") | ||
// | ||
// await signer.sendTransaction({ | ||
// gasLimit: quote.gas, | ||
// gasPrice: quote.gasPrice, | ||
// to: quote.to, | ||
// data: quote.data, | ||
// value: quote.value, | ||
// chainId: quote.chainId, | ||
// }); | ||
} | ||
|
||
// We recommend this pattern to be able to use async/await everywhere | ||
// and properly handle errors. | ||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
Oops, something went wrong.