Commit 5860be39 authored by luxq's avatar luxq

update

parent 34b01480
......@@ -23,19 +23,11 @@ cd pancakeswaper
make
```
#### 2. fill in the `accounts.json` file with the accounts you want to do swap for.
The example of the `accounts.json` file is as follow:
```json
[
{
"address": "0x",
"private": "0x"
},
{
"address": "0x",
"private": "0x"
}
]
#### 2. fill in the `accounts.csv` file with the accounts you want to do swap for.
The example of the `accounts.csv` file is as follow:
```csv
useraddress, privatekey, recipient
0xeFbb75e446Ec2d8493B3d4d91aC3118953f69b55, 0x1111111111111111, 0xc437593d9C296bf9A5002522A86dad8a4d4Af808
```
#### 4. change configure
......@@ -55,6 +47,12 @@ param:
# tx deadline, unit is minutes, set 0 to disable.
deadline: 20
pair:
# pair address.
pair: "0xcB0AE3B8337f0Cc35563e6b9fC357F2298C0D24a"
# klko address
token: "0x215324115417a13879f865Dc5BB651B18A781a59"
rpc:
env: "bsc"
pool: 20
......@@ -62,7 +60,7 @@ rpc:
log:
level: "debug"
users: "accounts.json"
users: "accounts.csv"
```
#### 5. run the program
......
useraddress, privatekey, recipient
0xeFbb75e446Ec2d8493B3d4d91aC3118953f69b55, 0x1111111111111111, 0xc437593d9C296bf9A5002522A86dad8a4d4Af808
\ No newline at end of file
[
{"address":"","private":"0x"},
{"address":"","private":"0x"},
{"address":"","private":"0x"}
]
\ No newline at end of file
......@@ -12,6 +12,12 @@ param:
# tx deadline, unit is minutes, set 0 to disable.
deadline: 20
pair:
# pair address.
pair: "0xcB0AE3B8337f0Cc35563e6b9fC357F2298C0D24a"
# klko address
token: "0x215324115417a13879f865Dc5BB651B18A781a59"
rpc:
env: "bsc"
pool: 20
......@@ -19,4 +25,4 @@ rpc:
log:
level: "debug"
users: "accounts.json"
\ No newline at end of file
users: "accounts.csv"
\ No newline at end of file
......@@ -12,6 +12,7 @@ import (
type Config struct {
Log LogConfig `yaml:"log"`
Param ParamConfig `yaml:"param"`
Pair PairConfig `yaml:"pair"`
Rpc RpcConfig `yaml:"rpc"`
Users string `yaml:"users"`
}
......@@ -25,6 +26,11 @@ type ParamConfig struct {
Deadline int64 `yaml:"deadline"`
}
type PairConfig struct {
Pair string `yaml:"pair"`
Token string `yaml:"token"`
}
type RpcConfig struct {
Env string `yaml:"env"`
PoolSize int `yaml:"pool"`
......
package pancake
import (
"code.wuban.net.cn/service/pancakeswapper/config"
"code.wuban.net.cn/service/pancakeswapper/contracts/buildparam"
"code.wuban.net.cn/service/pancakeswapper/contracts/v3pool"
"code.wuban.net.cn/service/pancakeswapper/types"
......@@ -30,7 +31,7 @@ func leftPadding(data []byte, length int) []byte {
return append(padding, data...)
}
func MakeV3SwapExactInPathData(env types.Env) []byte {
func MakeV3SwapExactInPathData(env types.Env, cfg *config.Config) []byte {
//0000000000000000000000003e3b4d16ce35840c28f90edb7f38e5bdd976c7e3
//0000000000000000000000000000000000000000000000001bc16d674ec80000
//0000000000000000000000000000000000000000000000002620b5d4cdab6c04
......@@ -40,7 +41,7 @@ func MakeV3SwapExactInPathData(env types.Env) []byte {
//55d398326f99059ff775485246999027b3197955002710215324115417a13879f865dc5bb651b18a781a59000000000000000000000000000000000000000000
token0 := common.HexToAddress(env.USDT)
token1 := common.HexToAddress(env.KLKO)
token1 := common.HexToAddress(cfg.Pair.Token)
fee := big.NewInt(10000)
data := make([]byte, 0)
data = append(data, token0.Bytes()...)
......@@ -49,7 +50,7 @@ func MakeV3SwapExactInPathData(env types.Env) []byte {
return data
}
func MakeV3SwapExactInData(env types.Env, param ParamV3SwapExactIn) ([]byte, error) {
func MakeV3SwapExactInData(env types.Env, param ParamV3SwapExactIn, cfg *config.Config) ([]byte, error) {
//0000000000000000000000003e3b4d16ce35840c28f90edb7f38e5bdd976c7e3
//0000000000000000000000000000000000000000000000000de0b6b3a7640000
//00000000000000000000000000000000000000000000000012d0ee4f5819f972
......@@ -59,7 +60,7 @@ func MakeV3SwapExactInData(env types.Env, param ParamV3SwapExactIn) ([]byte, err
//55d398326f99059ff775485246999027b3197955002710215324115417a13879
//f865dc5bb651b18a781a59000000000000000000000000000000000000000000
param.Path = MakeV3SwapExactInPathData(env)
param.Path = MakeV3SwapExactInPathData(env, cfg)
buildAbi, _ := abi.JSON(strings.NewReader(buildparam.ParamContractMetaData.ABI))
data, err := buildAbi.Pack("buildParamV3_SWAP_EXACT_IN", param.Recipient, param.AmountIn, param.AmountOutMin, param.Path, param.PayerIsUser)
......@@ -103,10 +104,10 @@ func MakePermit2PermitData(acc *types.Account, env types.Env) ([]byte, error) {
// amountIn is the amount of input token (USDT) to swap.
// slippage is the maximum slippage allowed for the swap, the value is percent mul 1000, eg: 20 is 2%.
// feeRate is the fee charged by the pool, the value is percent mul 1000000, eg: 10000 is 1%.
func GetAmountOutMin(client *ethclient.Client, env types.Env, amountIn *big.Int,
func GetAmountOutMin(cfg *config.Config, client *ethclient.Client, env types.Env, amountIn *big.Int,
slippage int64, feeRate *big.Int) (*big.Int, error) {
// get slot0 data.
pool := common.HexToAddress(env.Pool)
pool := common.HexToAddress(cfg.Pair.Pair)
contract, err := v3pool.NewV3Pool(pool, client)
if err != nil {
return nil, err
......@@ -216,6 +217,7 @@ func MakePermit2PermitData2(acc *types.Account, env types.Env, client *ethclient
// Pack the data
buildAbi, _ := abi.JSON(strings.NewReader(buildparam.ParamContractMetaData.ABI))
// todo: check method name.
data, err := buildAbi.Pack("buildParamPermit2", permitSingle, signature)
if err != nil {
return nil, err
......
......@@ -26,7 +26,7 @@ func (s *Swapper) Run() {
work.WorkInit(env.ChainId)
// 1. read account info from json file
accs := work.LoadAccounts(s.cfg.Users)
accs := work.LoadAccountsFromCsv(s.cfg.Users)
work.SetTotalUser(len(accs))
waitCh := make(chan struct{})
......
......@@ -15,6 +15,7 @@ type Account struct {
//Nonce uint64 `json:"-"`
PK *ecdsa.PrivateKey `json:"-"`
Addr common.Address `json:"-"`
Recipient string `json:“recipient"`
}
func (a *Account) sign(chainid *big.Int, tx *types.Transaction) (*types.Transaction, error) {
......
......@@ -6,14 +6,11 @@ var (
func init() {
allEnv["bsc"] = Env{
//RPC: "https://bscnode.bitheart.org",
RPC: "https://four.rpc.48.club",
USDT: "0x55d398326f99059ff775485246999027b3197955",
KLKO: "0x215324115417a13879f865Dc5BB651B18A781a59", // KLKO
Permit2: "0x31c2F6fcFf4F8759b3Bd5Bf0e1084A055615c768",
Router: "0x1b81D678ffb9C0263b24A97847620C99d213eB14",
//Router: "0x1A0A18AC4BECDDbd6389559687d1A73d8927E416",
Pool: "0xcB0AE3B8337f0Cc35563e6b9fC357F2298C0D24a",
UniversalRouter: "0x1A0A18AC4BECDDbd6389559687d1A73d8927E416",
ChainId: 56,
}
}
......@@ -21,10 +18,11 @@ func init() {
type Env struct {
RPC string
USDT string
KLKO string
//KLKO string
Permit2 string
Router string
Pool string
Router string // v3 router.
UniversalRouter string
//Pool string
ChainId int64
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment