Commit 5860be39 authored by luxq's avatar luxq

update

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