Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI command to submit a deposit sweep proposal #3549

Merged
merged 20 commits into from
May 9, 2023
Merged

Conversation

nkuba
Copy link
Member

@nkuba nkuba commented May 4, 2023

We added a CLI command to submit a deposit sweep proposal. The command verifies the proposal with the same rules as nodes will do and submits the proposal to the chain.

To submit a deposit sweep proposal run:

keep-client coordinator propose-deposits-sweep --wallet <wallet_address> --fee <fee> <deposit_1> <deposit_2> ...

Following flags can be used with the command:

  • --wallet <address> - wallet to sweep
  • --fee - fee to use for the sweep transaction

The command requires ethereum and bitcoin.electrum node details to be provided in the config.

Deposits

The command requires the deposits details to be provided as variadic arguments in a specific format:
<unprefixed bitcoin transaction hash>:<bitcoin transaction output index>:<ethereum reveal block number>
e.g.
bd99d1d0a61fd104925d9b7ac997958aa8af570418b3fde091f7bfc561608865:1:8392394

Sample command

keep-client --config ./configs/forked/config.toml \
  --goerli \
  coordinator \
  propose-deposits-sweep \
  --wallet 0x03b74d6893ad46dfdd01b9e0e3b3385f4fce2d1e \
  --fee 12 \
  da3ec4f5620f686d5013c37d49a411fa49daac5077c98809402572f481c6ea0:0:8502238 \
  214a85db0871b537d4cd649a8d74aecdbee112919983ad22fb85cfa2704a3593:0:8502224 \
  3704d01b48212ddacc77e613be0491978a8c19ad11af6b8536eacf9e9953eb13:0:8502070

Testing

To test this feature WalletCoordinator contract is required to be deployed. It is not yet available on Goerli or Mainnet. To have the contract available you can run a hardhat node as Goerli fork (https://github.com/nkuba/hardhat-forked-node) and deploy the WalletCoordinator contract there.

Depends on: #3545

nkuba added 2 commits May 3, 2023 16:12
The function can be used to validate the proposal with bitcoin and
ethereum chains.
@nkuba nkuba changed the base branch from main to wallet-cli-deposits May 4, 2023 10:39
@nkuba nkuba force-pushed the wallet-cli-sweep branch from e09ddac to 4bef810 Compare May 4, 2023 11:01
We added a CLI command to submit a deposit sweep proposal. The command
verifies the proposal with the same rules as nodes will do and submits
the proposal to the chain.

To submit a deposit sweep proposal run:
```
keep-client wallet sweep --wallet <wallet_address> --fee <fee> <btc_tx_1> <btc_tx_2> ...
```

Bitcoin transactions are expected to be provided as variadic arguments
in the following format: `<transaction hash>:<output index>`

Sample command:
```
keep-client wallet sweep --wallet 0x03b74d6893ad46dfdd01b9e0e3b3385f4fce2d1e --fee 12 bd99d1d0a61fd104925d9b7ac997958aa8af570418b3fde091f7bfc561608865:1 178628f0fd77ca04a31e771805277405288404da38eb86a0e369f2b26d45fe97:1 b71c0bbe43f23e162739b80b7bae9f0fb650e90e56fea0b92f169553505c398d:1
```
@nkuba nkuba force-pushed the wallet-cli-sweep branch from 4bef810 to 195ab9f Compare May 4, 2023 11:02
@nkuba nkuba marked this pull request as ready for review May 4, 2023 11:02
@nkuba nkuba requested review from lukasz-zimnoch and pdyraga May 4, 2023 11:02
@nkuba nkuba self-assigned this May 4, 2023
nkuba added 3 commits May 4, 2023 13:11
We want to make the flag required only in sweep command so we define
separate flags for deposits and sweep commands.
If the --dry-run flag is used the command will validate the proposal but not submit the proposal
to the chain.
Copy link
Member

@lukasz-zimnoch lukasz-zimnoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick pass. I'll do a thorough review once #3545 is merged.

cmd/wallet.go Outdated
@@ -68,6 +71,70 @@ var depositsCommand = cobra.Command{
},
}

var sweepCommand = cobra.Command{
Use: "sweep",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this command propose-deposit-sweep? First, this command just submits the proposal and sweeping is purely a wallet action. Second, in the future, we will also have "moved funds sweep" so it would be good to make it specific that we are dealing with "deposit sweep" here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe propose-sweep to keep it shorter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember that we will also have "propose moved funds sweep". Unfortunately, we must be specific here and make the command a bit longer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there will be more we could make the sub-commands nested, e.g.:

deposits list
deposits sweep propose
deposits sweep bump-fee
deposits redeem

redemptions list

moved-funds list
moved-funds sweep propose
moved-funds sweep bump-fee

But for now, I updated it the way that was proposed: 31b7d30

Copy link
Member

@lukasz-zimnoch lukasz-zimnoch May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good idea regarding the sub-commands! Leaving this discussion open for future reference.

Base automatically changed from wallet-cli-deposits to main May 8, 2023 18:54
@nkuba nkuba requested a review from lukasz-zimnoch May 9, 2023 09:14
nkuba added 3 commits May 9, 2023 11:16
Since keep-network/tbtc-v2#613 deposit sweep
proposal requires a block numebr of the reveal deposit transaction.
We need to output the data in the deposits list and pass it to the
propose sweep function.
@nkuba nkuba force-pushed the wallet-cli-sweep branch from 5639656 to 7066cf5 Compare May 9, 2023 10:15
We should use the value stored in the chain implementation, as it gets
overwritten in test.
pkg/coordinator/deposits.go Show resolved Hide resolved
pkg/coordinator/sweep.go Outdated Show resolved Hide resolved
pkg/coordinator/sweep.go Outdated Show resolved Hide resolved
pkg/coordinator/sweep.go Outdated Show resolved Hide resolved
pkg/coordinator/sweep.go Outdated Show resolved Hide resolved
pkg/coordinator/sweep.go Show resolved Hide resolved
pkg/coordinator/sweep.go Outdated Show resolved Hide resolved
Couple of modifications to the function.
@nkuba nkuba force-pushed the wallet-cli-sweep branch from acfbba4 to c7098d0 Compare May 9, 2023 13:00
@lukasz-zimnoch lukasz-zimnoch mentioned this pull request May 9, 2023
6 tasks
cmd/coordinator.go Show resolved Hide resolved
pkg/chain/ethereum/tbtc.go Outdated Show resolved Hide resolved
nkuba added 6 commits May 9, 2023 15:22
For easier maintanance of the format and examples in the code we defined
variables and used them in various places.
The propery is passed directly to the contract. The contract expects
value for the whole transaction in satoshi.
@nkuba nkuba requested review from pdyraga and lukasz-zimnoch May 9, 2023 14:30
Copy link
Member

@lukasz-zimnoch lukasz-zimnoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as advertised! I used the following command:

./keep-client --config ./configs/config.coordinator.toml \
  --goerli \
  coordinator \
  propose-deposits-sweep \
  --wallet 0x03b74d6893ad46dfdd01b9e0e3b3385f4fce2d1e \
  --fee 10000 \
  4ef58d68e35783695d898786bb29432be32325b1bb2cc6a9cf58c622cf2a1e94:0:8381106 \
  167d96e203fc91d014026ab2ffa9e44b6a2a425c22febd9bffe88b6dddca1979:0:8381194 \
  63cb18fdbe4ceb8b0747dbfcb11989605f78cffbe4379b9047124118cfc20aef:0:8381671 \
  46a9b50dd44f11364d9924bd7995830cd7cd1a772910f22ed7ab507137653c6d:0:8381974 \
  cec3d569224ebeeaf7aef922fbac498c4c75633529acff28d50a94cac332e87c:0:8382422

and the sweep proposal was submitted as expected: https://goerli.etherscan.io/tx/0x2c9d6c3f865b5aa52080ecea25a1c75f3fdc0401dccaa6987f4c8ced5e85e8cd

@lukasz-zimnoch lukasz-zimnoch merged commit 6c6c6d0 into main May 9, 2023
@lukasz-zimnoch lukasz-zimnoch deleted the wallet-cli-sweep branch May 9, 2023 19:55
@pdyraga pdyraga added this to the v2.0.0-m3 milestone May 30, 2023
pdyraga added a commit that referenced this pull request Jun 14, 2023
The changes here are a step on the road to the fully automated sweeps
(#3614).

We update the `propose-deposits-sweep` command initially implemented in
#3549.

The main change to the command is that if deposits are not provided as
arguments, they will be automatically fetched from the chain.

The command will find the oldest unswept deposits for the oldest unswept
wallet and construct a sweep proposal for them.

Number of deposits for the proposal is based on the
[`depositSweepMaxSize`](https://github.com/keep-network/tbtc-v2/blob/66a04c618e140230d25ea0d784ed75e6ba3030a2/solidity/contracts/bridge/WalletCoordinator.sol#L191)
defined in the `WalletCoordinator` contract. The value can be
overwritten with `--deposit-sweep-max-size <number>`.

If `--wallet <wallet-public-key-hash>` is provided the command will find
unswept deposits for the particular wallet.

If `--fee <number>` is not provided the command will estimate a fee for
the sweep transaction.

## Sample Command
To execute the command in dry-run mode:
```sh
# Sweep deposits from the oldest unswept wallet:
LOG_LEVEL=debug go run . coordinator --testnet propose-deposits-sweep --dry-run

# Sweep deposits from a specific wallet:
LOG_LEVEL=debug go run . coordinator --testnet propose-deposits-sweep --wallet 0x7670343fc00ccc2d0cd65360e6ad400697ea0fed --dry-run
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants