CoinAlpha / gateway-api

Apache License 2.0
47 stars 25 forks source link

(fix) Auto increase the nonce when Strategy connects to 2 DEFI projects #47

Closed osp-ng closed 3 years ago

osp-ng commented 3 years ago

When hummingbot connects to 2 DEFI projects, the current gateway will receive 2 requests. If the 2 projects are both in the same network and the same wallet address, the nonce will be the same. As a result, one of the transactions will be overwritten.

In this PR, we wrap the Signer with a ethersproject/NonceManager, the nonce will be automatically increased across the 2 projects. We also add a factory in utils.js to reuse the NonceManager only when the network and wallet address are both the same.

References:

  1. The strategy shall execute 2 transactions at the same time: https://github.com/CoinAlpha/hummingbot/blob/v0.37.1/hummingbot/strategy/spot_perpetual_arbitrage/spot_perpetual_arbitrage.py#L303
  2. We import the NonceManager: https://docs.ethers.io/v5/api/experimental/#experimental-noncemanager
osp-ng commented 3 years ago

Already partially merged at 3a963613b16cd65105ba14b6f1e3d62192c46ae5