Skip to content

Commit

Permalink
Merge pull request #355 from vegaprotocol/adding-amm-support-to-perftest
Browse files Browse the repository at this point in the history
Adding AMM submission support
  • Loading branch information
peterbarrow authored May 20, 2024
2 parents 80fb9bc + 972f327 commit 6187dd8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func init() {
perfTestCmd.Flags().BoolVarP(&opts.UseLPsForOrders, "uselpsfororders", "U", true, "allow lp users to place orders during setup")
perfTestCmd.Flags().BoolVarP(&opts.BatchOnly, "batchonly", "B", false, "all transactions are sent in batches")
perfTestCmd.Flags().BoolVarP(&opts.SpotMarkets, "spotmarkets", "P", false, "use spot markets")
perfTestCmd.Flags().BoolVarP(&opts.AMMs, "amms", "A", false, "send AMMs")
perfTestCmd.MarkFlagRequired("address")
perfTestCmd.MarkFlagRequired("wallet")
perfTestCmd.MarkFlagRequired("faucet")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.5

require (
code.vegaprotocol.io/shared v0.0.0-20230119125558-bda6563e1c7a
code.vegaprotocol.io/vega v0.76.0
code.vegaprotocol.io/vega v0.76.2-0.20240520130421-ff0404a4a6cc
github.com/cometbft/cometbft-db v0.7.0
github.com/cosmos/iavl v0.20.0
github.com/ethereum/go-ethereum v1.11.6
Expand Down Expand Up @@ -66,7 +66,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
code.vegaprotocol.io/shared v0.0.0-20230119125558-bda6563e1c7a h1:sgniM6sgxPKAStJo2rNoYJR3NMlS/t55H12lvynkw5c=
code.vegaprotocol.io/shared v0.0.0-20230119125558-bda6563e1c7a/go.mod h1:XzX67GsyOHzvytMr0QOHX4CCTdCZDYKUUi88rx40Nt0=
code.vegaprotocol.io/vega v0.76.0 h1:Xl+OnHhnEpZ7N1Y4EqbQSsRca2iwFyBTnCBGMqa5muQ=
code.vegaprotocol.io/vega v0.76.0/go.mod h1:oTKpFh+pTLJaDcjkdkSS0BhTm5miMRkduNxaabuY0cE=
code.vegaprotocol.io/vega v0.76.2-0.20240520130421-ff0404a4a6cc h1:6SBDA1BDWWGPBv4Pmie7YS8MGkAgF+KBFRZTkpka1m8=
code.vegaprotocol.io/vega v0.76.2-0.20240520130421-ff0404a4a6cc/go.mod h1:8BBcogM5b/HtC6gz0TCnhQ1ks7uPMDgQVs1NXmBS6MU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
Expand Down Expand Up @@ -331,8 +331,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
51 changes: 50 additions & 1 deletion perftest/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Opts struct {
UseLPsForOrders bool
BatchOnly bool
SpotMarkets bool
AMMs bool
}

type perfLoadTesting struct {
Expand Down Expand Up @@ -521,6 +522,44 @@ func (p *perfLoadTesting) seedStopOrders(marketIDs []string, opts Opts) error {
return nil
}

func (p *perfLoadTesting) sendAMMs(marketIDs []string, opts Opts) error {
if opts.DoNotInitialise {
return nil
}

upperBound := fmt.Sprint(opts.StartingMidPrice + int64(opts.PriceLevels))
lowerBound := fmt.Sprint(max(1, opts.StartingMidPrice-int64(opts.PriceLevels)))
base := fmt.Sprint(opts.StartingMidPrice)
upperLeverage := "0.1"
lowerLeverage := "0.1"

// We need to go through all markets and all users
for _, marketID := range marketIDs {
for l := 0; l < opts.LpUserCount; l++ {
user := p.users[l]
amm := &commandspb.SubmitAMM{
MarketId: marketID,
CommitmentAmount: "2000",
SlippageTolerance: "0.1",
ProposedFee: "0.01",
ConcentratedLiquidityParameters: &commandspb.SubmitAMM_ConcentratedLiquidityParameters{
UpperBound: &upperBound,
LowerBound: &lowerBound,
Base: base,
LeverageAtUpperBound: &upperLeverage,
LeverageAtLowerBound: &lowerLeverage,
},
}
err := p.wallet.SendAMM(user, amm)
if err != nil {
return err
}
time.Sleep(time.Millisecond * 250)
}
}
return nil
}

func (p *perfLoadTesting) sendSLAOrders(marketID string, deleteFirst bool, opts Opts) error {
for l := 0; l < opts.LpUserCount; l++ {
batch := &BatchOrders{}
Expand Down Expand Up @@ -895,7 +934,7 @@ func (p *perfLoadTesting) sendBatchOnlyLoad(marketIDs []string, opts Opts) error
// Run is the main function of `perftest` package
func Run(opts Opts) error {

fmt.Println(opts)
fmt.Printf("%+v\n", opts)
f, err := os.OpenFile("perftest.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666)
if err != nil {
log.Fatalf("error opening file: %v", err)
Expand Down Expand Up @@ -1005,6 +1044,16 @@ func Run(opts Opts) error {
return nil
}

if opts.AMMs {
fmt.Print("Sending AMM submissions...")
err = plt.sendAMMs(marketIDs, opts)
if err != nil {
fmt.Println("FAILED")
return err
}
fmt.Println("Complete")
}

// Send off a controlled amount of orders and cancels
if opts.BatchOnly {
fmt.Print("Sending batched load transactions...")
Expand Down
5 changes: 5 additions & 0 deletions perftest/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,8 @@ func (w walletWrapper) SendVote(user UserDetails, propID string) error {
_, err := w.sendTransaction(user, "voteSubmission", &vote)
return err
}

func (w *walletWrapper) SendAMM(user UserDetails, amm *commandspb.SubmitAMM) error {
_, err := w.sendTransaction(user, "submitAmm", amm)
return err
}

0 comments on commit 6187dd8

Please sign in to comment.