-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from zarbanio/update-dex-trader-deploy-script
chore: update dex trader deploy script
- Loading branch information
Showing
13 changed files
with
392 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package configs | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
EnvironmentMainnet = "mainnet" | ||
EnvironmentTestnet = "testnet" | ||
) | ||
|
||
type General struct { | ||
Environment string `yaml:"Environment"` | ||
LogLevel string `yaml:"LogLevel"` | ||
} | ||
|
||
type MarketMaker struct { | ||
StartQty float64 `yaml:"StartQty"` | ||
StepQty float64 `yaml:"StepQty"` | ||
EndQty int64 `yaml:"EndQty"` | ||
ProfitThreshold int64 `yaml:"ProfitThreshold"` | ||
Interval time.Duration `yaml:"Interval"` | ||
Slippage float64 `yaml:"Slippage"` | ||
} | ||
|
||
type Chain struct { | ||
Url string `yaml:"Url"` | ||
BlockInterval time.Duration `yaml:"BlockInterval"` | ||
} | ||
|
||
type Token struct { | ||
Address string `yaml:"Address"` | ||
Decimals int `yaml:"Decimals"` | ||
Symbol string `yaml:"Symbol"` | ||
} | ||
|
||
type Uniswap struct { | ||
PoolFee float64 `yaml:"PoolFee"` | ||
} | ||
|
||
type Nobitex struct { | ||
Url string `yaml:"Url"` | ||
Key string `yaml:"Key"` | ||
MinimumOrderToman int64 `yaml:"MinimumOrderToman"` | ||
Timeout time.Duration `yaml:"Timeout"` | ||
OrderStatusInterval time.Duration `yaml:"OrderStatusInterval"` | ||
RetryTimeOut time.Duration `yaml:"RetryTimeOut"` | ||
RetrySleepDuration time.Duration `yaml:"RetrySleepDuration"` | ||
} | ||
|
||
type Contracts struct { | ||
DexTrader string `yaml:"DexTrader"` | ||
UniswapV3Factory string `yaml:"UniswapV3Factory"` | ||
UniswapV3Quoter string `yaml:"UniswapV3Quoter"` | ||
} | ||
|
||
type Indexer struct { | ||
StartBlock uint64 `yaml:"StartBlock"` | ||
} | ||
|
||
type Postgres struct { | ||
Host string `yaml:"Host"` | ||
Port int `yaml:"Port"` | ||
User string `yaml:"User"` | ||
Password string `yaml:"Password"` | ||
DB string `yaml:"DB"` | ||
MigrationsPath string `yaml:"MigrationsPath"` | ||
} | ||
|
||
type Config struct { | ||
General General `yaml:"General"` | ||
MarketMaker MarketMaker `yaml:"MarketMaker"` | ||
Chain Chain `yaml:"Chain"` | ||
Tokens []Token `yaml:"Tokens"` | ||
Uniswap Uniswap `yaml:"Uniswap"` | ||
Nobitex Nobitex `yaml:"Nobitex"` | ||
Contracts Contracts `yaml:"Contracts"` | ||
Indexer Indexer `yaml:"Indexer"` | ||
Postgres Postgres `yaml:"Postgres"` | ||
} | ||
|
||
func ReadConfig(configFile string) Config { | ||
defaultConfig := DefaultConfig() | ||
|
||
c := &Config{} | ||
*c = defaultConfig | ||
|
||
err := c.Unmarshal(c, configFile) | ||
if err != nil { | ||
log.Fatalf("Unmarshal: %v", err) | ||
} | ||
return *c | ||
} | ||
|
||
func (c *Config) Unmarshal(rawVal interface{}, fileName string) error { | ||
viper.SetConfigFile(fileName) | ||
err := viper.ReadInConfig() | ||
if err != nil { | ||
return err | ||
} | ||
var input interface{} = viper.AllSettings() | ||
config := defaultDecoderConfig(rawVal) | ||
decoder, err := mapstructure.NewDecoder(config) | ||
if err != nil { | ||
return err | ||
} | ||
return decoder.Decode(input) | ||
} | ||
|
||
func defaultDecoderConfig(output interface{}) *mapstructure.DecoderConfig { | ||
c := &mapstructure.DecoderConfig{ | ||
Metadata: nil, | ||
Result: output, | ||
WeaklyTypedInput: true, | ||
DecodeHook: mapstructure.ComposeDecodeHookFunc( | ||
mapstructure.StringToTimeDurationHookFunc(), | ||
mapstructure.StringToSliceHookFunc(","), | ||
), | ||
} | ||
return c | ||
} |
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,8 @@ | ||
Chain: | ||
Url: "YOUR_ARBITRUM_CHAIN_URL" | ||
|
||
Nobitex: | ||
Key: "YOUR_NOBITEX_API_KEY" | ||
|
||
Contracts: | ||
DexTrader: "YOUR_DEX_TRADER_CONTRACT_ADDRESS" |
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,64 @@ | ||
package configs | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
func DefaultConfig() Config { | ||
return Config{ | ||
General: General{ | ||
Environment: EnvironmentMainnet, | ||
LogLevel: "info", | ||
}, | ||
MarketMaker: MarketMaker{ | ||
StartQty: 10.0, | ||
StepQty: 20.0, | ||
EndQty: 400, // max trade DAI in strategy0 and strategy1 | ||
ProfitThreshold: 50000, // 50_000 TMN | ||
Interval: time.Minute * 10, | ||
Slippage: 0.001, | ||
}, | ||
Chain: Chain{ | ||
BlockInterval: time.Millisecond * 500, | ||
}, | ||
Tokens: []Token{ | ||
{ | ||
Address: "0xd946188a614a0d9d0685a60f541bba1e8cc421ae", | ||
Decimals: 18, | ||
Symbol: "ZAR", | ||
}, | ||
{ | ||
Address: "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1", | ||
Decimals: 18, | ||
Symbol: "DAI", | ||
}, | ||
}, | ||
Uniswap: Uniswap{ | ||
PoolFee: 0.01, | ||
}, | ||
Nobitex: Nobitex{ | ||
Url: "https://api.nobitex.ir", | ||
Key: "", // Assuming no default value for Key | ||
MinimumOrderToman: 300000, | ||
Timeout: time.Second * 60, // 60s | ||
OrderStatusInterval: time.Second * 2, // 2s | ||
RetryTimeOut: time.Second * 360, // 360s | ||
RetrySleepDuration: time.Second * 5, // 5s | ||
}, | ||
Contracts: Contracts{ | ||
UniswapV3Factory: "0x1F98431c8aD98523631AE4a59f267346ea31F984", | ||
UniswapV3Quoter: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6", | ||
}, | ||
Indexer: Indexer{ | ||
StartBlock: 247010149, | ||
}, | ||
Postgres: Postgres{ | ||
Host: "localhost", | ||
Port: 5432, | ||
User: "postgres", | ||
Password: "postgres", | ||
DB: "postgres", | ||
MigrationsPath: "/migrations", | ||
}, | ||
} | ||
} |
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,11 +1,35 @@ | ||
require("@nomicfoundation/hardhat-toolbox"); | ||
|
||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
const PRIVATE_KEY = process.env.PRIVATE_KEY; | ||
const ARBISCAN_KEY = process.env.ARBISCAN_KEY; | ||
|
||
module.exports = { | ||
solidity: { | ||
version: "0.8.17", | ||
settings: { | ||
optimizer: { enabled: true, runs: 200 }, | ||
}, | ||
}, | ||
etherscan: { | ||
apiKey: { | ||
arb: ARBISCAN_KEY, | ||
}, | ||
customChains: [ | ||
{ | ||
network: "arb", | ||
chainId: 42161, | ||
urls: { | ||
apiURL: "https://api.arbiscan.io/api", | ||
browserURL: "https://arbiscan.io", | ||
}, | ||
}, | ||
], | ||
}, | ||
networks: { | ||
arb: { | ||
url: "https://1rpc.io/arb", | ||
chainId: 42161, | ||
accounts: [PRIVATE_KEY], | ||
}, | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { ethers } = require("hardhat"); | ||
const qrcode = require('qrcode-terminal'); // Import the qrcode-terminal package | ||
|
||
require('dotenv').config(); | ||
|
||
async function main() { | ||
const [executor] = await ethers.getSigners(); | ||
console.log(`Deploying contracts with the account: ${executor.address}`); | ||
console.log(`Account balance: ${ethers.utils.formatEther(await executor.getBalance())} ETH`); | ||
|
||
// Generate and display the QR code for the address | ||
qrcode.generate(executor.address, { small: true }, (qrCode) => { | ||
console.log('\nAccount Address QR Code:\n'); | ||
console.log(qrCode); | ||
}); | ||
|
||
console.log('\nCaution!'); | ||
console.log('To fund this account, transfer ETH to the following address on the Arbitrum network:'); | ||
console.log(`\n${executor.address}\n`); | ||
console.log('Scan the QR code above with your wallet to send ETH.'); | ||
console.log('Ensure you are connected to the Arbitrum network when making the transfer.'); | ||
console.log('Do not send ETH to this address on any other network.'); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { ethers } = require("hardhat"); | ||
const { verifyArbiscanContract } = require("./verify"); | ||
|
||
require('dotenv').config() | ||
|
||
const UniswapV3Router = '0xE592427A0AEce92De3Edee1F18E0157C05861564'; | ||
|
||
async function main() { | ||
const [executor] = await ethers.getSigners(); | ||
console.log(`Deploying contracts with the account: ${executor.address}`); | ||
console.log(`Account balance: ${ethers.utils.formatEther(await executor.getBalance())} ETH`); | ||
|
||
const DexTrader = await ethers.getContractFactory("DexTrader"); | ||
const dexTrader = await DexTrader.deploy(UniswapV3Router, executor.address); | ||
|
||
await dexTrader.deployed(); | ||
console.log(`DexTrader contract deployed to ${dexTrader.address}`); | ||
|
||
await verifyArbiscanContract(dexTrader.address, [UniswapV3Router, executor.address]) | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
Oops, something went wrong.