Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pancakeSwaper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
pancakeSwaper
Commits
dd650af2
Commit
dd650af2
authored
Apr 11, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rpc proxy in config
parent
f68cffcd
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
67 additions
and
24 deletions
+67
-24
Makefile
Makefile
+4
-3
README.md
README.md
+5
-3
clientpool.go
clientpool/clientpool.go
+36
-3
root.go
command/root/root.go
+4
-4
config.yml
config.yml
+3
-1
config.go
config/config.go
+2
-0
default.go
config/default.go
+1
-1
swapper.go
core/swapper.go
+2
-2
pack.go
pancake/pack.go
+2
-3
env.go
types/env.go
+2
-2
account.go
work/account.go
+6
-2
No files found.
Makefile
View file @
dd650af2
.PHONY
:
default swapper docker
GOBIN
=
$(
shell
pwd
)
/build
/bin
GOBIN
=
$(
shell
pwd
)
/build
GO
?=
latest
GOFILES_NOVENDOR
:=
$(
shell
go list
-f
"{{.Dir}}"
./...
)
TAG
=
latest
...
...
@@ -13,11 +13,12 @@ swag:
swag init
-g
openapi/server.go
swapper
:
go build
-o
=
${
GOBIN
}
/
$@
-gcflags
"all=-N -l"
.
@
rm
-rf
${
GOBIN
}
go build
-o
$@
-gcflags
"all=-N -l"
.
@
echo
"Done building."
docker
:
docker build
-t
swapper:
${
TAG
}
.
clean
:
rm
-fr
build
/
*
rm
-fr
build
README.md
View file @
dd650af2
...
...
@@ -39,7 +39,7 @@ param:
# swap volume for each transaction, unit is 0.1 usdt. example: 1 is 0.1 usdt.
volume
:
1
# count of transactions per user.
count
:
2
count
:
1
# gas_price unit is Gwei.
gas_price
:
1
# slippage, unit is 1/1000. example: 20 means 2.0%.
...
...
@@ -50,12 +50,14 @@ param:
pair
:
# pair address.
pair
:
"
0xcB0AE3B8337f0Cc35563e6b9fC357F2298C0D24a"
# klko address
# klko
token
address
token
:
"
0x215324115417a13879f865Dc5BB651B18A781a59"
rpc
:
env
:
"
bsc"
pool
:
20
url
:
"
https://bscnode.bitheart.org"
proxy
:
"
http://127.0.0.1:7890"
log
:
level
:
"
debug"
...
...
@@ -67,7 +69,7 @@ users: "accounts.csv"
After check the configure, you can run the program.
```
shell
./
build/bin/
swapper
./swapper
```
#### 6. check result
...
...
clientpool/clientpool.go
View file @
dd650af2
package
clientpool
import
(
"context"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
log
"github.com/sirupsen/logrus"
"net/http"
"net/url"
"sync"
"time"
)
// use atomic pool
...
...
@@ -16,14 +22,41 @@ type poolConfig struct {
var
pconfig
=
&
poolConfig
{}
func
InitPool
(
cnt
int
,
rpc
string
)
{
func
dialUrl
(
rpcurl
string
,
proxy
string
)
(
*
ethclient
.
Client
,
error
)
{
if
proxy
==
""
{
return
ethclient
.
Dial
(
rpcurl
)
}
else
{
// set http proxy
purl
,
err
:=
url
.
Parse
(
proxy
)
if
err
!=
nil
{
return
ethclient
.
Dial
(
rpcurl
)
}
transport
:=
http
.
DefaultTransport
.
(
*
http
.
Transport
)
.
Clone
()
transport
.
Proxy
=
http
.
ProxyURL
(
purl
)
hcli
:=
&
http
.
Client
{
Transport
:
transport
,
Timeout
:
time
.
Second
*
20
,
}
rpcCli
,
err
:=
rpc
.
DialOptions
(
context
.
Background
(),
rpcurl
,
rpc
.
WithHTTPClient
(
hcli
))
if
err
!=
nil
{
return
ethclient
.
Dial
(
rpcurl
)
}
log
.
WithField
(
"proxy"
,
proxy
)
.
Info
(
"create eth client use proxy"
)
return
ethclient
.
NewClient
(
rpcCli
),
nil
}
}
func
InitPool
(
cnt
int
,
rpc
string
,
proxy
string
)
{
pconfig
.
Index
=
0
pconfig
.
RPCNode
=
rpc
pconfig
.
clients
=
make
([]
*
ethclient
.
Client
,
0
)
for
i
:=
0
;
i
<
cnt
;
i
++
{
c
,
_
:=
ethclient
.
Dial
(
pconfig
.
RPCNode
)
if
c
,
err
:=
dialUrl
(
pconfig
.
RPCNode
,
proxy
);
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"failed to connect to rpc node"
)
}
else
{
pconfig
.
clients
=
append
(
pconfig
.
clients
,
c
)
}
}
}
func
(
p
*
poolConfig
)
getClient
()
*
ethclient
.
Client
{
...
...
command/root/root.go
View file @
dd650af2
...
...
@@ -2,7 +2,7 @@ package root
import
(
"code.wuban.net.cn/service/pancakeswapper/config"
"code.wuban.net.cn/service/pancakeswapper/
swapper
"
"code.wuban.net.cn/service/pancakeswapper/
core
"
"fmt"
log
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
...
...
@@ -15,7 +15,7 @@ import (
var
(
cfgFile
string
rootCmd
=
&
cobra
.
Command
{
Use
:
"
swapper
[command]"
,
Use
:
"
core
[command]"
,
Short
:
"Swapper is a script for pancake."
,
PersistentPreRunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
bindFlags
(
cmd
)
...
...
@@ -64,13 +64,13 @@ func runCommand(cmd *cobra.Command, _ []string) {
setlog
(
cfg
.
Log
.
Level
)
log
.
WithField
(
"config"
,
cfg
)
.
Info
(
"load config success"
)
server
,
err
:=
swapper
.
NewSwapper
(
cfg
)
server
,
err
:=
core
.
NewSwapper
(
cfg
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
server
.
Run
()
log
.
Info
(
"app exit, bye bye !!!"
)
fmt
.
Println
(
"app exit, bye bye !!!"
)
return
}
...
...
config.yml
View file @
dd650af2
...
...
@@ -4,7 +4,7 @@ param:
# swap volume for each transaction, unit is 0.1 usdt. example: 1 is 0.1 usdt.
volume
:
1
# count of transactions per user.
count
:
2
count
:
1
# gas_price unit is Gwei.
gas_price
:
1
# slippage, unit is 1/1000. example: 20 means 2.0%.
...
...
@@ -21,6 +21,8 @@ pair:
rpc
:
env
:
"
bsc"
pool
:
20
url
:
"
https://bscnode.bitheart.org"
proxy
:
"
http://127.0.0.1:7890"
log
:
level
:
"
debug"
...
...
config/config.go
View file @
dd650af2
...
...
@@ -34,6 +34,8 @@ type PairConfig struct {
type
RpcConfig
struct
{
Env
string
`yaml:"env"`
PoolSize
int
`yaml:"pool"`
Url
string
`yaml:"url"`
Proxy
string
`yaml:"proxy"`
}
type
LogConfig
struct
{
...
...
config/default.go
View file @
dd650af2
...
...
@@ -11,5 +11,5 @@ var DefaultConfig = Config{
Slippage
:
20
,
Deadline
:
20
,
},
Users
:
"accounts.
json
"
,
Users
:
"accounts.
csv
"
,
}
swapper
/swapper.go
→
core
/swapper.go
View file @
dd650af2
package
swapper
package
core
import
(
"code.wuban.net.cn/service/pancakeswapper/clientpool"
...
...
@@ -22,7 +22,7 @@ func NewSwapper(conf *config.Config) (*Swapper, error) {
func
(
s
*
Swapper
)
Run
()
{
env
:=
types
.
GetEnv
(
s
.
cfg
.
Rpc
.
Env
)
clientpool
.
InitPool
(
s
.
cfg
.
Rpc
.
PoolSize
,
env
.
RPC
)
clientpool
.
InitPool
(
s
.
cfg
.
Rpc
.
PoolSize
,
s
.
cfg
.
Rpc
.
Url
,
s
.
cfg
.
Rpc
.
Proxy
)
work
.
WorkInit
(
env
.
ChainId
)
// 1. read account info from json file
...
...
pancake/pack.go
View file @
dd650af2
...
...
@@ -5,7 +5,6 @@ import (
"code.wuban.net.cn/service/pancakeswapper/contracts/buildparam"
"code.wuban.net.cn/service/pancakeswapper/contracts/v3pool"
"code.wuban.net.cn/service/pancakeswapper/types"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -126,11 +125,11 @@ func GetAmountOutMin(cfg *config.Config, client *ethclient.Client, env types.Env
fee
:=
new
(
big
.
Int
)
.
Div
(
new
(
big
.
Int
)
.
Mul
(
amountIn
,
feeRate
),
big
.
NewInt
(
1e6
))
amountIn
=
amountIn
.
Sub
(
amountIn
,
fee
)
fmt
.
Println
(
"sub fee"
,
amountIn
.
Text
(
10
))
//
fmt.Println("sub fee", amountIn.Text(10))
amountOut
:=
new
(
big
.
Int
)
.
Div
(
amountIn
,
price
)
fmt
.
Println
(
"amount out"
,
amountOut
.
Text
(
10
))
//
fmt.Println("amount out", amountOut.Text(10))
minAmountOut
:=
new
(
big
.
Int
)
.
Mul
(
amountOut
,
big
.
NewInt
(
1000
-
slippage
))
minAmountOut
=
minAmountOut
.
Div
(
minAmountOut
,
big
.
NewInt
(
1000
))
...
...
types/env.go
View file @
dd650af2
...
...
@@ -6,7 +6,7 @@ var (
func
init
()
{
allEnv
[
"bsc"
]
=
Env
{
RPC
:
"https://four.rpc.48.club"
,
//
RPC: "https://four.rpc.48.club",
USDT
:
"0x55d398326f99059ff775485246999027b3197955"
,
Permit2
:
"0x31c2F6fcFf4F8759b3Bd5Bf0e1084A055615c768"
,
Router
:
"0x1b81D678ffb9C0263b24A97847620C99d213eB14"
,
...
...
@@ -16,7 +16,7 @@ func init() {
}
type
Env
struct
{
RPC
string
//
RPC string
USDT
string
//KLKO string
Permit2
string
...
...
work/account.go
View file @
dd650af2
...
...
@@ -183,12 +183,16 @@ func accountApprove(client *ethclient.Client, acc *types.Account, env types.Env)
addNewTx
:=
func
(
tx
*
ethtypes
.
Transaction
)
{
waitTx
(
client
,
tx
)
}
allow
,
_
:=
usdt
.
Allowance
(
&
bind
.
CallOpts
{
allow
,
err
:=
usdt
.
Allowance
(
&
bind
.
CallOpts
{
From
:
acc
.
Addr
,
BlockNumber
:
nil
,
Context
:
context
.
Background
(),
},
acc
.
Addr
,
common
.
HexToAddress
(
env
.
Router
))
if
allow
.
Int64
()
==
0
{
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Warn
(
"allow permit2 permit failed"
)
return
fmt
.
Errorf
(
"get usdt allowance failed: %v"
,
err
)
}
if
allow
==
nil
||
allow
.
Int64
()
==
0
{
if
tx
,
err
:=
usdt
.
Approve
(
txopts
,
common
.
HexToAddress
(
env
.
Router
),
abi
.
MaxUint256
);
err
!=
nil
{
return
fmt
.
Errorf
(
"usdt approve pool failed: %v"
,
err
)
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment