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

[Do not merge] dApp-friendly contract deployment #403

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

r-czajkowski
Copy link
Contributor

@r-czajkowski r-czajkowski commented Aug 16, 2022

Ref: threshold-network/token-dashboard#136

We need a dApp-friendly version of deployment allowing dashboard developers to build UI components without having to run geth/ganache/hardhat locally and deploying contracts locally.

This PR aims at presenting changes to smart contracts deployed to Sepolia that are used by the dApp development team for day-to-day work. Please do not merge this PR to main branch. Smart contract with the changes presented here are pushed to NPM registry with a tag dapp-development-sepolia.

TODO:

  • update the tag for @keep-network/ecdsa and @keep-network/random-beacon to dapp-development-sepolia in /solidity/pacakge.json.

We need to mock the off-chain clients' work to make the deposit/redemption flow faster so here we add a set of mocked functions that we have to call to mock the clients' work.

Wallets

We need the ECDSA wallet to create a deposit or request a redemption. The mock__registerEcdsaWallet function creates a mocked ECDSA wallet- to create wallet run:

npx hardhat dapp:register-wallet --network <network-name> --utxo-tx-hash 0x2f952bdc206bf51bb745b967cb7166149becada878d3191ffe341155ebcd4883 --utxo-tx-output-index 1 --utxo-tx-output-value 3933200

Deposit

The mock__submitDepositSweepProof function sweeps deposit and mint TBTC tokens to a depositor address. We have to run this function after revealing a deposit. You can submit deposit sweep proof using:

npx hardhat dapp:submit-deposit-sweep-proof --wallet-pub-key-hash 0x486b0ee2eed761f069f327034eb2ae5e07580bf3 --funding-tx-hash 0xc7f953290caafec7f71c9a90f4c7b87a4d6cb63d3f016c0447662afe6c7e9847 --funding-output-index 0 --network <network-name>

To find the necessary parameters to run dapp:submit-deposit-sweep-proof task run:

npx hardhat dapp:get-revealed-deposits --depositor-address <depositor-address> --network <network-name>

Redemption

The mock__submitRedemptionProof function submits the redemption proof. We have to run this function after requesting a redemption. To submit the redemption proof run:

npx hardhat dapp:submit-redemption-proof --wallet-pub-key-hash 0x486b0ee2eed761f069f327034eb2ae5e07580bf3 --redeemer-output-script 0x1600148db50eb52063ea9d98b3eac91489a90f738986f6 --network <network-name>

To find the necessary parameters to run dapp:submit-redemption-proof task run:

npx hardhat dapp:get-redemptions --redeemer-address <redeemer-address> --network <network-name>

Optimistic Minting (by @michalsmiarowski)

Set vault status

To be able to to optimistic minting we need to have trusted vault. To set a vault status to trusted (or not trusted) run:

npx hardhat dapp:set-vault-status --network goerli --address <vault_address> --is-trusted <true/false>

Note: This method can be called only by the owner of BridgeGovernance contract. To make this task work you will have to put a private key of the dapp-friendly contracts deployer inside hardhat.config.ts like this:

const config: HardhatUserConfig = {
  (...)
  networks: {
    (...)
    goerli: {
      url: <your_infura_url>,
      chainId: 5,
      accounts: [<deployer_private_key>],
      tags: ["tenderly"],
    },
  }
}

The <deployer_private_key> should be prefixed with 0x!

Add minter

Only minters can request and finalize an optimistic mint, so we've added a task to add the minter manually. To do that run:

npx hardhat dapp:add-minter --network goerli --address <your_address_that_will_become_a_minter>

Note: This method can be called only by the owner of TBTCVault contract. Please see the note from the Set vault status note to set the correct address as a deployer in hardhat config.

Request Optimistic Mint

Allows a Minter to request for an optimistic minting of TBTC. To request an optimistic mint run:

npx hardhat dapp:request-optimistic-minting --network goerli --funding-tx-hash <funding_tx_hash> --funding-output-index <funding_output_index>

Both values, funding_tx_hash and funding_output_index, can be extracted from the DepositRevealed event.

Finalize Optimistic Mint

Allows a Minter to finalize previously requested optimistic minting. To finalize the optimistic mint run:

npx hardhat dapp:finalize-optimistic-minting --network goerli --funding-tx-hash <funding_tx_hash> --funding-output-index <funding_output_index>

The funding_tx_hash and funding_output_index should be the same values that were used in Request Optimistic Mint.

To create a deposit or request redemption the ECDSA wallet is required.
To not involve the off-chain clients here we add a mock function that
registers the fake ECDSA wallet in the `Bridge` contract. Anyone can
execute this function. In this mocked function we also pass the main
utxo params because it is required for redemption flow.
This task is responsible for registering the ECDSA wallet with mocked
data. We need to trigger this task manually to mock the off-chain
clients work. This allows us to reveal deposit and request redemption.
The off-chain clients are responsible for sweeping deposit. We need to
create mocked version of this function and we will trigger it manually-
we will mock the client work. To simplify the deposit sweep flow this
mocked function will take only one deposit. In taht fact we can mock the
off-chain clients work and sweep a deposit.
Running this task we can sweep a deposit- in this way we mock the
off-chain clients work.
The off-chain clients are responsible for this part. We need to mock
`submitRedemptionProof` function and we will trigger it manually to mock
the off-chain clients work. This function removes the redemption from
the `pendingRedemptions` map.
The name of the task should be unique.
The previous amount was too high and EVM was throwing an error because
the deposited amount was `<0`.
We need to register the wallet in the `WalletRegistry` contract because
the tbtc-v2.ts lib calls this contract to get the wallet public key.
Please see: https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/ethereum.ts#L392-L395
Updates the hardhat task that submits the deposit sweep proof- get the
depoist by key for the contract and log the `sweptAt` param.
Add task that returns the revealed deposits/redemption request events by
the `depositor/redeemer` address. This task logs unnecessary parameters
to run the task that submits the deposit sweep/redemption proof.
To be consistent with the name of parameters auto-generated by hardhat.
Set `dapp-development-goerli` tag for `@keep-network/random-beacon` and
`@keep-network/ecdsa`. We need dapp-friendly contracts here.
We are publishing packages with code from `dapp-development` branch under
versions that use `-dapp-dev-goerli.X` suffix. Our `package.json` on this branch
should reflect that. If we do not set it up, the CI job used to pubblish the
package will not be able to correctly bump up the version of the package.
contractName:
process.env.TEST_USE_STUBS_TBTC === "true" ? "BridgeStub" : undefined,
// contractName:
// process.env.TEST_USE_STUBS_TBTC === "true" ? "BridgeStub" : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for this change? Unit tests are failing because of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

93de579. Regarding failing tests, as I remember we decided to switch off tests for this branch cc @michalinacienciala.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, they are getting switched off in #392. Once I get an approve on #392 and it gets to main, I'll merge main again to dapp-development and we should no longer see the fail in the checks.

Update number of optimizer runs to reduce the size of the
`WalletRegistry` contract. Lower values of runs will optimize more for
initial deployment cost(contract size) but the execution costs will be
higher. We don't have to worry about the execution cost of
`WalletRegistry` contract because changes from `dapp-development` branch
are only for testnet networks.
Commented out these lines because wanted to test local deployment with
the dapp-frielndy `Bridge` contract. Should't have pushed these changes
to the remote branch.
michalinacienciala and others added 8 commits September 19, 2022 16:01
We changed the version range for `@tenderly/hardhat-tenderly` in #440
and CI build fails on tenderly verification.  Since this is a
`dapp-development` branch, we do not actually need the tenderly
verification at least for now so here we remove the `tenderly` tag for
`goerli` network to skip the tenderly veirification.
Add tasks with which you will be able to do an optimistic minting.
Set to `120 s` -> `2min` to speed up the optimistic minting QA in T
dapp.
We changed the version range for `@tenderly/hardhat-tenderly` in #440
and CI build fails on tenderly verification.  Since this is a
`dapp-development` branch, we do not actually need the tenderly
verification at least for now so here we remove the `tenderly` tag for
`goerli` network to skip the tenderly veirification.
To QA the optimistic minting in T dapp we need to transfer the ownership
of the `TBTC` token contract. The `TBTCVault` should be an owner of the
`TBTC` token contract. The only way to do this is via `VendingMachine`
contract because is currently set as an owner of `TBTC` token contract
in deployment scripts.
Transfer the ownership of the TBTC token contract via `VendingMachine`
contract. In omptimistic minting, the `TBTCVault` contract should be the
owner of the `TBTC` token contract.
Update `ecdsa` and `random-beacon` package version.
We want the TBTCVault to be the owner of the TBTC token and we do it in
earlier deployment step. The script `94_*` was a workaround and now it's
unnecessary. See #488.
@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Solidity API documentation preview available in the artifacts of the https://github.com/keep-network/tbtc-v2/actions/runs/5749928453 check.

Add `redemptionTxHash` param it should be a Bitcoin testnet transaction
hash(byte order corresponds to the Bitcoin internal byte order) that was
made from a given wallet to a given redeemer output script. Thanks to
that we can find the tx on the Bitcoin chain and display data in the
dapp.
@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Solidity API documentation preview available in the artifacts of the https://github.com/keep-network/tbtc-v2/actions/runs/5750103008 check.

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Solidity API documentation preview available in the artifacts of the https://github.com/keep-network/tbtc-v2/actions/runs/5751598858 check.

We're switching deployment to the Sepolia testnet due to planned deprecation of
the Goerli testnet. In a previous commit we've updated the `dapp-development`
branch with the recent changes from `main` (among them were the changes adding
Sepolia to the list of supported networks). Now we're updating the
`dapp-development` branch to create `dapp-dev-sepolia` packages.
Copy link

github-actions bot commented Nov 8, 2023

Solidity API documentation preview available in the artifacts of the https://github.com/keep-network/tbtc-v2/actions/runs/6796536389 check.

@michalinacienciala
Copy link
Contributor

@lukasz-zimnoch, we don't need to worry about the failing typescript-docs workflow in this PR, right? This PR intentionally uses different contracts than on main and we don't intend to merge it to main.

@lukasz-zimnoch
Copy link
Member

@lukasz-zimnoch, we don't need to worry about the failing typescript-docs workflow in this PR, right? This PR intentionally uses different contracts than on main and we don't intend to merge it to main.

Yep!

Move documentation from Pull Request description to a separate .adoc file. This
way we can keep track of changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants