Skip to content

Commit 48cca34

Browse files
authored
Fix nonce collisions (#19)
* prevent nonce collision in GetNonce function
1 parent 952e4f6 commit 48cca34

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

hyperliquid/utils.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package hyperliquid
33
import (
44
"crypto/rand"
55
"strconv"
6+
"sync/atomic"
67
"time"
78

89
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -55,9 +56,11 @@ func GetSlippage(sl *float64) float64 {
5556
return slippage
5657
}
5758

59+
var nonceCounter = time.Now().UnixMilli()
60+
5861
// Hyperliquid uses timestamps in milliseconds for nonce
5962
func GetNonce() uint64 {
60-
return uint64(time.Now().UnixMilli())
63+
return uint64(atomic.AddInt64(&nonceCounter, 1))
6164
}
6265

6366
// Returns default time range of 90 days

0 commit comments

Comments
 (0)