@keep-network/tbtc-v2 0.1.0 → 0.1.1-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.adoc +12 -0
- package/artifacts/.chainId +1 -1
- package/artifacts/Bank.json +807 -0
- package/artifacts/Bridge.json +2300 -0
- package/artifacts/Deposit.json +117 -0
- package/artifacts/DepositSweep.json +77 -0
- package/artifacts/EcdsaDkgValidator.json +532 -0
- package/artifacts/EcdsaInactivity.json +156 -0
- package/artifacts/EcdsaSortitionPool.json +1004 -0
- package/artifacts/Fraud.json +164 -0
- package/artifacts/KeepRegistry.json +99 -0
- package/artifacts/KeepStake.json +286 -0
- package/artifacts/KeepToken.json +711 -0
- package/artifacts/KeepTokenStaking.json +483 -0
- package/artifacts/MovingFunds.json +249 -0
- package/artifacts/NuCypherStakingEscrow.json +256 -0
- package/artifacts/NuCypherToken.json +711 -0
- package/artifacts/RandomBeaconStub.json +141 -0
- package/artifacts/Redemption.json +174 -0
- package/artifacts/ReimbursementPool.json +509 -0
- package/artifacts/Relay.json +123 -0
- package/artifacts/T.json +1148 -0
- package/artifacts/TBTC.json +36 -35
- package/artifacts/TBTCToken.json +738 -0
- package/artifacts/TBTCVault.json +691 -0
- package/artifacts/TokenStaking.json +2288 -0
- package/artifacts/TokenholderGovernor.json +1795 -0
- package/artifacts/TokenholderTimelock.json +1058 -0
- package/artifacts/VendingMachine.json +34 -33
- package/artifacts/VendingMachineKeep.json +400 -0
- package/artifacts/VendingMachineNuCypher.json +400 -0
- package/artifacts/WalletRegistry.json +1843 -0
- package/artifacts/WalletRegistryGovernance.json +2754 -0
- package/artifacts/Wallets.json +186 -0
- package/artifacts/solcInputs/5e62cff1ead0900b07facca4b559e818.json +314 -0
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +4 -0
- package/build/contracts/bank/Bank.sol/Bank.json +542 -0
- package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +4 -0
- package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.json +34 -0
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +4 -0
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +10 -0
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +4 -0
- package/build/contracts/bridge/Bridge.sol/Bridge.json +2686 -0
- package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
- package/build/contracts/bridge/BridgeState.sol/BridgeState.json +226 -0
- package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
- package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
- package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
- package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +30 -0
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
- package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
- package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
- package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +4 -0
- package/build/contracts/bridge/Heartbeat.sol/Heartbeat.json +10 -0
- package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
- package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +138 -0
- package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
- package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
- package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
- package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
- package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
- package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/token/TBTC.sol/TBTC.json +4 -4
- package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +4 -0
- package/build/contracts/vault/DonationVault.sol/DonationVault.json +108 -0
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +4 -0
- package/build/contracts/vault/IVault.sol/IVault.json +52 -0
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +4 -0
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +449 -0
- package/contracts/GovernanceUtils.sol +4 -4
- package/contracts/bank/Bank.sol +436 -0
- package/contracts/bank/IReceiveBalanceApproval.sol +45 -0
- package/contracts/bridge/BitcoinTx.sol +326 -0
- package/contracts/bridge/Bridge.sol +1793 -0
- package/contracts/bridge/BridgeState.sol +739 -0
- package/contracts/bridge/Deposit.sol +269 -0
- package/contracts/bridge/DepositSweep.sol +574 -0
- package/contracts/bridge/EcdsaLib.sol +45 -0
- package/contracts/bridge/Fraud.sol +579 -0
- package/contracts/bridge/Heartbeat.sol +112 -0
- package/contracts/bridge/IRelay.sol +28 -0
- package/contracts/bridge/MovingFunds.sol +1077 -0
- package/contracts/bridge/Redemption.sol +1020 -0
- package/contracts/bridge/VendingMachine.sol +2 -2
- package/contracts/bridge/Wallets.sol +719 -0
- package/contracts/hardhat-dependency-compiler/.hardhat-dependency-compiler +1 -0
- package/contracts/hardhat-dependency-compiler/@keep-network/ecdsa/contracts/WalletRegistry.sol +3 -0
- package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol +3 -0
- package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +3 -0
- package/contracts/token/TBTC.sol +1 -1
- package/contracts/vault/DonationVault.sol +125 -0
- package/contracts/vault/IVault.sol +44 -0
- package/contracts/vault/TBTCVault.sol +305 -0
- package/deploy/00_resolve_relay.ts +28 -0
- package/deploy/00_resolve_tbtc_v1_token.ts +1 -1
- package/deploy/01_deploy_tbtc_v2_token.ts +8 -1
- package/deploy/02_deploy_vending_machine.ts +7 -0
- package/deploy/{03_transfer_roles.ts → 03_transfer_vending_machine_roles.ts} +1 -1
- package/deploy/04_deploy_bank.ts +27 -0
- package/deploy/05_deploy_bridge.ts +80 -0
- package/deploy/06_deploy_tbtc_vault.ts +30 -0
- package/deploy/07_bank_update_bridge.ts +19 -0
- package/deploy/08_transfer_bank_ownership.ts +15 -0
- package/deploy/09_transfer_tbtc_vault_ownership.ts +15 -0
- package/deploy/10_transfer_bridge_governance.ts +20 -0
- package/deploy/11_initialize_wallet_owner.ts +18 -0
- package/deploy/11_transfer_proxy_admin_ownership.ts +30 -0
- package/deploy/12_deploy_proxy_admin_with_deputy.ts +33 -0
- package/export/deploy/00_resolve_relay.js +24 -0
- package/export/deploy/00_resolve_tbtc_v1_token.js +24 -0
- package/export/deploy/01_deploy_tbtc_v2_token.js +19 -0
- package/export/deploy/02_deploy_vending_machine.js +25 -0
- package/export/deploy/03_transfer_vending_machine_roles.js +19 -0
- package/export/deploy/04_deploy_bank.js +21 -0
- package/export/deploy/05_deploy_bridge.js +69 -0
- package/export/deploy/06_deploy_tbtc_vault.js +24 -0
- package/export/deploy/07_bank_update_bridge.js +13 -0
- package/export/deploy/08_transfer_bank_ownership.js +11 -0
- package/export/deploy/09_transfer_tbtc_vault_ownership.js +11 -0
- package/export/deploy/10_transfer_bridge_governance.js +11 -0
- package/export/deploy/11_initialize_wallet_owner.js +14 -0
- package/export/deploy/11_transfer_proxy_admin_ownership.js +23 -0
- package/export/deploy/12_deploy_proxy_admin_with_deputy.js +22 -0
- package/export/hardhat.config.js +169 -0
- package/export/test/bank/Bank.test.js +1012 -0
- package/export/test/bridge/Bridge.Deployment.test.js +76 -0
- package/export/test/bridge/Bridge.Deposit.test.js +1834 -0
- package/export/test/bridge/Bridge.Frauds.test.js +1349 -0
- package/export/test/bridge/Bridge.MovingFunds.test.js +2437 -0
- package/export/test/bridge/Bridge.Parameters.test.js +400 -0
- package/export/test/bridge/Bridge.Redemption.test.js +2523 -0
- package/export/test/bridge/Bridge.Vaults.test.js +74 -0
- package/export/test/bridge/Bridge.Wallets.test.js +1017 -0
- package/export/test/bridge/EcdsaLib.test.js +46 -0
- package/export/test/bridge/Heartbeat.test.js +77 -0
- package/export/test/bridge/VendingMachine.Upgrade.test.js +160 -0
- package/export/test/bridge/VendingMachine.test.js +762 -0
- package/export/test/data/deposit-sweep.js +655 -0
- package/export/test/data/ecdsa.js +18 -0
- package/export/test/data/fraud.js +158 -0
- package/export/test/data/moving-funds.js +815 -0
- package/export/test/data/redemption.js +1011 -0
- package/export/test/fixtures/bridge.js +54 -0
- package/export/test/fixtures/index.js +57 -0
- package/export/test/helpers/contract-test-helpers.js +18 -0
- package/export/test/integration/Slashing.test.js +279 -0
- package/export/test/integration/WalleCreation.test.js +66 -0
- package/export/test/integration/utils/ecdsa-wallet-registry.js +137 -0
- package/export/test/integration/utils/fixture.js +77 -0
- package/export/test/integration/utils/gas.js +36 -0
- package/export/test/integration/utils/random-beacon.js +26 -0
- package/export/test/integration/utils/staking.js +19 -0
- package/export/test/vault/DonationVault.test.js +202 -0
- package/export/test/vault/TBTCVault.Redemption.test.js +357 -0
- package/export/test/vault/TBTCVault.test.js +768 -0
- package/export/typechain/BTCUtils.js +2 -0
- package/export/typechain/Bank.js +2 -0
- package/export/typechain/BankStub.js +2 -0
- package/export/typechain/Bridge.js +2 -0
- package/export/typechain/BridgeState.js +2 -0
- package/export/typechain/BridgeStub.js +2 -0
- package/export/typechain/Deposit.js +2 -0
- package/export/typechain/DepositSweep.js +2 -0
- package/export/typechain/DonationVault.js +2 -0
- package/export/typechain/ERC165.js +2 -0
- package/export/typechain/ERC1967Proxy.js +2 -0
- package/export/typechain/ERC1967Upgrade.js +2 -0
- package/export/typechain/ERC20WithPermit.js +2 -0
- package/export/typechain/ERC721.js +2 -0
- package/export/typechain/EcdsaAuthorization.js +2 -0
- package/export/typechain/EcdsaDkg.js +2 -0
- package/export/typechain/EcdsaDkgValidator.js +2 -0
- package/export/typechain/EcdsaInactivity.js +2 -0
- package/export/typechain/Fraud.js +2 -0
- package/export/typechain/Governable.js +2 -0
- package/export/typechain/HeartbeatStub.js +2 -0
- package/export/typechain/IApplication.js +2 -0
- package/export/typechain/IApproveAndCall.js +2 -0
- package/export/typechain/IBeacon.js +2 -0
- package/export/typechain/IERC165.js +2 -0
- package/export/typechain/IERC1822Proxiable.js +2 -0
- package/export/typechain/IERC20.js +2 -0
- package/export/typechain/IERC20Metadata.js +2 -0
- package/export/typechain/IERC20WithPermit.js +2 -0
- package/export/typechain/IERC721.js +2 -0
- package/export/typechain/IERC721Metadata.js +2 -0
- package/export/typechain/IERC721Receiver.js +2 -0
- package/export/typechain/IRandomBeacon.js +2 -0
- package/export/typechain/IRandomBeaconConsumer.js +2 -0
- package/export/typechain/IReceiveApproval.js +2 -0
- package/export/typechain/IReceiveBalanceApproval.js +2 -0
- package/export/typechain/IRelay.js +2 -0
- package/export/typechain/IStaking.js +2 -0
- package/export/typechain/IVault.js +2 -0
- package/export/typechain/IWalletOwner.js +2 -0
- package/export/typechain/IWalletRegistry.js +2 -0
- package/export/typechain/Initializable.js +2 -0
- package/export/typechain/MisfundRecovery.js +2 -0
- package/export/typechain/MovingFunds.js +2 -0
- package/export/typechain/Ownable.js +2 -0
- package/export/typechain/Proxy.js +2 -0
- package/export/typechain/ProxyAdmin.js +2 -0
- package/export/typechain/ReceiveApprovalStub.js +2 -0
- package/export/typechain/Redemption.js +2 -0
- package/export/typechain/Reimbursable.js +2 -0
- package/export/typechain/ReimbursementPool.js +2 -0
- package/export/typechain/Rewards.js +2 -0
- package/export/typechain/SortitionPool.js +2 -0
- package/export/typechain/SortitionTree.js +2 -0
- package/export/typechain/TBTC.js +2 -0
- package/export/typechain/TBTCVault.js +2 -0
- package/export/typechain/TestERC20.js +2 -0
- package/export/typechain/TestERC721.js +2 -0
- package/export/typechain/TestEcdsaLib.js +2 -0
- package/export/typechain/TestRelay.js +2 -0
- package/export/typechain/TransparentUpgradeableProxy.js +2 -0
- package/export/typechain/VendingMachine.js +2 -0
- package/export/typechain/WalletRegistry.js +2 -0
- package/export/typechain/Wallets.js +2 -0
- package/export/typechain/common.js +2 -0
- package/export/typechain/factories/BTCUtils__factory.js +94 -0
- package/export/typechain/factories/BankStub__factory.js +586 -0
- package/export/typechain/factories/Bank__factory.js +573 -0
- package/export/typechain/factories/BridgeState__factory.js +257 -0
- package/export/typechain/factories/BridgeStub__factory.js +2912 -0
- package/export/typechain/factories/Bridge__factory.js +2526 -0
- package/export/typechain/factories/DepositSweep__factory.js +61 -0
- package/export/typechain/factories/Deposit__factory.js +103 -0
- package/export/typechain/factories/DonationVault__factory.js +139 -0
- package/export/typechain/factories/ERC165__factory.js +38 -0
- package/export/typechain/factories/ERC1967Proxy__factory.js +111 -0
- package/export/typechain/factories/ERC1967Upgrade__factory.js +64 -0
- package/export/typechain/factories/ERC20WithPermit__factory.js +524 -0
- package/export/typechain/factories/ERC721__factory.js +388 -0
- package/export/typechain/factories/EcdsaAuthorization__factory.js +211 -0
- package/export/typechain/factories/EcdsaDkgValidator__factory.js +441 -0
- package/export/typechain/factories/EcdsaDkg__factory.js +192 -0
- package/export/typechain/factories/EcdsaInactivity__factory.js +134 -0
- package/export/typechain/factories/Fraud__factory.js +117 -0
- package/export/typechain/factories/Governable__factory.js +64 -0
- package/export/typechain/factories/HeartbeatStub__factory.js +61 -0
- package/export/typechain/factories/IApplication__factory.js +152 -0
- package/export/typechain/factories/IApproveAndCall__factory.js +48 -0
- package/export/typechain/factories/IBeacon__factory.js +32 -0
- package/export/typechain/factories/IERC165__factory.js +38 -0
- package/export/typechain/factories/IERC1822Proxiable__factory.js +32 -0
- package/export/typechain/factories/IERC20Metadata__factory.js +241 -0
- package/export/typechain/factories/IERC20WithPermit__factory.js +389 -0
- package/export/typechain/factories/IERC20__factory.js +202 -0
- package/export/typechain/factories/IERC721Metadata__factory.js +349 -0
- package/export/typechain/factories/IERC721Receiver__factory.js +53 -0
- package/export/typechain/factories/IERC721__factory.js +304 -0
- package/export/typechain/factories/IRandomBeaconConsumer__factory.js +37 -0
- package/export/typechain/factories/IRandomBeacon__factory.js +32 -0
- package/export/typechain/factories/IReceiveApproval__factory.js +47 -0
- package/export/typechain/factories/IReceiveBalanceApproval__factory.js +42 -0
- package/export/typechain/factories/IRelay__factory.js +45 -0
- package/export/typechain/factories/IStaking__factory.js +722 -0
- package/export/typechain/factories/IVault__factory.js +60 -0
- package/export/typechain/factories/IWalletOwner__factory.js +65 -0
- package/export/typechain/factories/IWalletRegistry__factory.js +138 -0
- package/export/typechain/factories/Initializable__factory.js +32 -0
- package/export/typechain/factories/MisfundRecovery__factory.js +145 -0
- package/export/typechain/factories/MovingFunds__factory.js +169 -0
- package/export/typechain/factories/Ownable__factory.js +71 -0
- package/export/typechain/factories/ProxyAdmin__factory.js +191 -0
- package/export/typechain/factories/Proxy__factory.js +27 -0
- package/export/typechain/factories/ReceiveApprovalStub__factory.js +127 -0
- package/export/typechain/factories/Redemption__factory.js +123 -0
- package/export/typechain/factories/Reimbursable__factory.js +58 -0
- package/export/typechain/factories/ReimbursementPool__factory.js +350 -0
- package/export/typechain/factories/Rewards__factory.js +117 -0
- package/export/typechain/factories/SortitionPool__factory.js +610 -0
- package/export/typechain/factories/SortitionTree__factory.js +149 -0
- package/export/typechain/factories/TBTCVault__factory.js +480 -0
- package/export/typechain/factories/TBTC__factory.js +564 -0
- package/export/typechain/factories/TestERC20__factory.js +539 -0
- package/export/typechain/factories/TestERC721__factory.js +421 -0
- package/export/typechain/factories/TestEcdsaLib__factory.js +66 -0
- package/export/typechain/factories/TestRelay__factory.js +94 -0
- package/export/typechain/factories/TransparentUpgradeableProxy__factory.js +186 -0
- package/export/typechain/factories/VendingMachine__factory.js +549 -0
- package/export/typechain/factories/WalletRegistry__factory.js +1919 -0
- package/export/typechain/factories/Wallets__factory.js +143 -0
- package/export/typechain/index.js +132 -0
- package/export.json +15932 -503
- package/package.json +47 -26
- package/artifacts/solcInputs/7cc3eda3cb3ff2522d18b5e7b31ea228.json +0 -104
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const hardhat_1 = require("hardhat");
|
|
7
|
+
const chai_1 = require("chai");
|
|
8
|
+
const fixtures_1 = require("../fixtures");
|
|
9
|
+
const bridge_1 = __importDefault(require("../fixtures/bridge"));
|
|
10
|
+
const { to1e18 } = hardhat_1.helpers.number;
|
|
11
|
+
const { createSnapshot, restoreSnapshot } = hardhat_1.helpers.snapshot;
|
|
12
|
+
const { increaseTime, lastBlockTime } = hardhat_1.helpers.time;
|
|
13
|
+
const { defaultAbiCoder } = hardhat_1.ethers.utils;
|
|
14
|
+
describe("TBTCVault - Redemption", () => {
|
|
15
|
+
const walletPubKeyHash = "0x8db50eb52063ea9d98b3eac91489a90f738986f6";
|
|
16
|
+
const mainUtxo = {
|
|
17
|
+
txHash: "0x3835ecdee2daa83c9a19b5012104ace55ecab197b5e16489c26d372e475f5d2a",
|
|
18
|
+
txOutputIndex: 0,
|
|
19
|
+
txOutputValue: 10000000,
|
|
20
|
+
};
|
|
21
|
+
let bridge;
|
|
22
|
+
let bank;
|
|
23
|
+
let tbtc;
|
|
24
|
+
let vendingMachine;
|
|
25
|
+
let tbtcVault;
|
|
26
|
+
let deployer;
|
|
27
|
+
let account1;
|
|
28
|
+
let account2;
|
|
29
|
+
before(async () => {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
31
|
+
;
|
|
32
|
+
({ deployer } = await hardhat_1.helpers.signers.getNamedSigners());
|
|
33
|
+
({ bridge, bank, tbtcVault, tbtc, vendingMachine } =
|
|
34
|
+
await hardhat_1.waffle.loadFixture(bridge_1.default));
|
|
35
|
+
// Deployment scripts deploy both `VendingMachine` and `TBTCVault` but they
|
|
36
|
+
// do not transfer the ownership of `TBTC` token to `TBTCVault`.
|
|
37
|
+
// We need to do it manually in tests covering `TBTCVault` behavior.
|
|
38
|
+
// Also, please note that `03_transfer_roles.ts` assigning `VendingMachine`
|
|
39
|
+
// upgrade initiator role to Keep Technical Wallet is skipped for Hardhat
|
|
40
|
+
// env deployment. That's why the upgrade initiator and `VendingMachine`
|
|
41
|
+
// owner is the deployer.
|
|
42
|
+
await vendingMachine
|
|
43
|
+
.connect(deployer)
|
|
44
|
+
.initiateVendingMachineUpgrade(tbtcVault.address);
|
|
45
|
+
await increaseTime(await vendingMachine.GOVERNANCE_DELAY());
|
|
46
|
+
await vendingMachine.connect(deployer).finalizeVendingMachineUpgrade();
|
|
47
|
+
const accounts = await (0, hardhat_1.getUnnamedAccounts)();
|
|
48
|
+
account1 = await hardhat_1.ethers.getSigner(accounts[0]);
|
|
49
|
+
account2 = await hardhat_1.ethers.getSigner(accounts[1]);
|
|
50
|
+
const initialBankBalance = to1e18(100);
|
|
51
|
+
await bank.setBalance(account1.address, initialBankBalance);
|
|
52
|
+
await bank.setBalance(account2.address, initialBankBalance);
|
|
53
|
+
await bank
|
|
54
|
+
.connect(account1)
|
|
55
|
+
.approveBalance(tbtcVault.address, initialBankBalance);
|
|
56
|
+
await bank
|
|
57
|
+
.connect(account2)
|
|
58
|
+
.approveBalance(tbtcVault.address, initialBankBalance);
|
|
59
|
+
await bridge.setWallet(walletPubKeyHash, {
|
|
60
|
+
ecdsaWalletID: hardhat_1.ethers.constants.HashZero,
|
|
61
|
+
mainUtxoHash: hardhat_1.ethers.constants.HashZero,
|
|
62
|
+
pendingRedemptionsValue: 0,
|
|
63
|
+
createdAt: await lastBlockTime(),
|
|
64
|
+
movingFundsRequestedAt: 0,
|
|
65
|
+
closingStartedAt: 0,
|
|
66
|
+
pendingMovedFundsSweepRequestsCount: 0,
|
|
67
|
+
state: fixtures_1.walletState.Live,
|
|
68
|
+
movingFundsTargetWalletsCommitmentHash: hardhat_1.ethers.constants.HashZero,
|
|
69
|
+
});
|
|
70
|
+
await bridge.setWalletMainUtxo(walletPubKeyHash, mainUtxo);
|
|
71
|
+
});
|
|
72
|
+
describe("unmintAndRedeem", () => {
|
|
73
|
+
const requestRedemption = async (redeemer, redeemerOutputScript, amount) => {
|
|
74
|
+
const data = defaultAbiCoder.encode(["address", "bytes20", "bytes32", "uint32", "uint64", "bytes"], [
|
|
75
|
+
redeemer.address,
|
|
76
|
+
walletPubKeyHash,
|
|
77
|
+
mainUtxo.txHash,
|
|
78
|
+
mainUtxo.txOutputIndex,
|
|
79
|
+
mainUtxo.txOutputValue,
|
|
80
|
+
redeemerOutputScript,
|
|
81
|
+
]);
|
|
82
|
+
return tbtcVault.connect(redeemer).unmintAndRedeem(amount, data);
|
|
83
|
+
};
|
|
84
|
+
context("when the redeemer has no TBTC", () => {
|
|
85
|
+
const amount = to1e18(1);
|
|
86
|
+
before(async () => {
|
|
87
|
+
await createSnapshot();
|
|
88
|
+
await tbtc.connect(account1).approve(tbtcVault.address, amount);
|
|
89
|
+
});
|
|
90
|
+
after(async () => {
|
|
91
|
+
await restoreSnapshot();
|
|
92
|
+
});
|
|
93
|
+
it("should revert", async () => {
|
|
94
|
+
await (0, chai_1.expect)(tbtcVault.connect(account1).unmintAndRedeem(to1e18(1), [])).to.be.revertedWith("Burn amount exceeds balance");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
context("when the redeemer has not enough TBTC", () => {
|
|
98
|
+
const mintedAmount = to1e18(1);
|
|
99
|
+
const redeemedAmount = mintedAmount.add(1);
|
|
100
|
+
before(async () => {
|
|
101
|
+
await createSnapshot();
|
|
102
|
+
await tbtcVault.connect(account1).mint(mintedAmount);
|
|
103
|
+
await tbtc.connect(account1).approve(tbtcVault.address, redeemedAmount);
|
|
104
|
+
});
|
|
105
|
+
after(async () => {
|
|
106
|
+
await restoreSnapshot();
|
|
107
|
+
});
|
|
108
|
+
it("should revert", async () => {
|
|
109
|
+
await (0, chai_1.expect)(tbtcVault.connect(account1).unmintAndRedeem(redeemedAmount, [])).to.be.revertedWith("Burn amount exceeds balance");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
context("when there is a single redeemer", () => {
|
|
113
|
+
const redeemerOutputScriptP2WPKH = "0x160014f4eedc8f40d4b8e30771f792b065ebec0abaddef";
|
|
114
|
+
const redeemerOutputScriptP2WSH = "0x220020ef0b4d985752aa5ef6243e4c6f6bebc2a007e7d671ef27d4b1d0db8dcc93bc1c";
|
|
115
|
+
const redeemerOutputScriptP2PKH = "0x1976a914f4eedc8f40d4b8e30771f792b065ebec0abaddef88ac";
|
|
116
|
+
const redeemerOutputScriptP2SH = "0x17a914f4eedc8f40d4b8e30771f792b065ebec0abaddef87";
|
|
117
|
+
const mintedAmount = 10000000;
|
|
118
|
+
const redeemedAmount1 = 1000000;
|
|
119
|
+
const redeemedAmount2 = 2000000;
|
|
120
|
+
const redeemedAmount3 = 3000000;
|
|
121
|
+
const redeemedAmount4 = 1500000;
|
|
122
|
+
const totalRedeemedAmount = redeemedAmount1 + redeemedAmount2 + redeemedAmount3 + redeemedAmount4;
|
|
123
|
+
const notRedeemedAmount = mintedAmount - totalRedeemedAmount;
|
|
124
|
+
const transactions = [];
|
|
125
|
+
before(async () => {
|
|
126
|
+
await createSnapshot();
|
|
127
|
+
await tbtcVault.connect(account1).mint(mintedAmount);
|
|
128
|
+
await tbtc.connect(account1).approve(tbtcVault.address, mintedAmount);
|
|
129
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2WPKH, redeemedAmount1));
|
|
130
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2WSH, redeemedAmount2));
|
|
131
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2PKH, redeemedAmount3));
|
|
132
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2SH, redeemedAmount4));
|
|
133
|
+
});
|
|
134
|
+
after(async () => {
|
|
135
|
+
await restoreSnapshot();
|
|
136
|
+
});
|
|
137
|
+
it("should transfer balances to Bridge", async () => {
|
|
138
|
+
(0, chai_1.expect)(await bank.balanceOf(tbtcVault.address)).to.equal(notRedeemedAmount);
|
|
139
|
+
(0, chai_1.expect)(await bank.balanceOf(bridge.address)).to.equal(totalRedeemedAmount);
|
|
140
|
+
});
|
|
141
|
+
it("should request redemptions in Bridge", async () => {
|
|
142
|
+
const redemptionRequest1 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WPKH));
|
|
143
|
+
(0, chai_1.expect)(redemptionRequest1.redeemer).to.be.equal(account1.address);
|
|
144
|
+
(0, chai_1.expect)(redemptionRequest1.requestedAmount).to.be.equal(redeemedAmount1);
|
|
145
|
+
const redemptionRequest2 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WSH));
|
|
146
|
+
(0, chai_1.expect)(redemptionRequest2.redeemer).to.be.equal(account1.address);
|
|
147
|
+
(0, chai_1.expect)(redemptionRequest2.requestedAmount).to.be.equal(redeemedAmount2);
|
|
148
|
+
const redemptionRequest3 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2PKH));
|
|
149
|
+
(0, chai_1.expect)(redemptionRequest3.redeemer).to.be.equal(account1.address);
|
|
150
|
+
(0, chai_1.expect)(redemptionRequest3.requestedAmount).to.be.equal(redeemedAmount3);
|
|
151
|
+
const redemptionRequest4 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2SH));
|
|
152
|
+
(0, chai_1.expect)(redemptionRequest4.redeemer).to.be.equal(account1.address);
|
|
153
|
+
(0, chai_1.expect)(redemptionRequest4.requestedAmount).to.be.equal(redeemedAmount4);
|
|
154
|
+
});
|
|
155
|
+
it("should burn TBTC", async () => {
|
|
156
|
+
(0, chai_1.expect)(await tbtc.balanceOf(account1.address)).to.equal(notRedeemedAmount);
|
|
157
|
+
(0, chai_1.expect)(await tbtc.totalSupply()).to.be.equal(notRedeemedAmount);
|
|
158
|
+
});
|
|
159
|
+
it("should emit Unminted events", async () => {
|
|
160
|
+
await (0, chai_1.expect)(transactions[0])
|
|
161
|
+
.to.emit(tbtcVault, "Unminted")
|
|
162
|
+
.withArgs(account1.address, redeemedAmount1);
|
|
163
|
+
await (0, chai_1.expect)(transactions[1])
|
|
164
|
+
.to.emit(tbtcVault, "Unminted")
|
|
165
|
+
.withArgs(account1.address, redeemedAmount2);
|
|
166
|
+
await (0, chai_1.expect)(transactions[2])
|
|
167
|
+
.to.emit(tbtcVault, "Unminted")
|
|
168
|
+
.withArgs(account1.address, redeemedAmount3);
|
|
169
|
+
await (0, chai_1.expect)(transactions[3])
|
|
170
|
+
.to.emit(tbtcVault, "Unminted")
|
|
171
|
+
.withArgs(account1.address, redeemedAmount4);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
context("when there are multiple redeemers", () => {
|
|
175
|
+
const redeemerOutputScriptP2WPKH = "0x160014f4eedc8f40d4b8e30771f792b065ebec0abaddef";
|
|
176
|
+
const redeemerOutputScriptP2WSH = "0x220020ef0b4d985752aa5ef6243e4c6f6bebc2a007e7d671ef27d4b1d0db8dcc93bc1c";
|
|
177
|
+
const mintedAmount1 = 10000000;
|
|
178
|
+
const mintedAmount2 = 20000000;
|
|
179
|
+
const redeemedAmount1 = 1000000;
|
|
180
|
+
const redeemedAmount2 = 2000000;
|
|
181
|
+
const totalMintedAmount = mintedAmount1 + mintedAmount2;
|
|
182
|
+
const totalRedeemedAmount = redeemedAmount1 + redeemedAmount2;
|
|
183
|
+
const totalNotRedeemedAmount = totalMintedAmount - totalRedeemedAmount;
|
|
184
|
+
const transactions = [];
|
|
185
|
+
before(async () => {
|
|
186
|
+
await createSnapshot();
|
|
187
|
+
await tbtcVault.connect(account1).mint(mintedAmount1);
|
|
188
|
+
await tbtc.connect(account1).approve(tbtcVault.address, mintedAmount1);
|
|
189
|
+
await tbtcVault.connect(account2).mint(mintedAmount2);
|
|
190
|
+
await tbtc.connect(account2).approve(tbtcVault.address, mintedAmount2);
|
|
191
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2WPKH, redeemedAmount1));
|
|
192
|
+
transactions.push(await requestRedemption(account2, redeemerOutputScriptP2WSH, redeemedAmount2));
|
|
193
|
+
});
|
|
194
|
+
after(async () => {
|
|
195
|
+
await restoreSnapshot();
|
|
196
|
+
});
|
|
197
|
+
it("should transfer balances to Bridge", async () => {
|
|
198
|
+
(0, chai_1.expect)(await bank.balanceOf(tbtcVault.address)).to.equal(totalNotRedeemedAmount);
|
|
199
|
+
(0, chai_1.expect)(await bank.balanceOf(bridge.address)).to.equal(totalRedeemedAmount);
|
|
200
|
+
});
|
|
201
|
+
it("should request redemptions in Bridge", async () => {
|
|
202
|
+
const redemptionRequest1 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WPKH));
|
|
203
|
+
(0, chai_1.expect)(redemptionRequest1.redeemer).to.be.equal(account1.address);
|
|
204
|
+
(0, chai_1.expect)(redemptionRequest1.requestedAmount).to.be.equal(redeemedAmount1);
|
|
205
|
+
const redemptionRequest2 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WSH));
|
|
206
|
+
(0, chai_1.expect)(redemptionRequest2.redeemer).to.be.equal(account2.address);
|
|
207
|
+
(0, chai_1.expect)(redemptionRequest2.requestedAmount).to.be.equal(redeemedAmount2);
|
|
208
|
+
});
|
|
209
|
+
it("should burn TBTC", async () => {
|
|
210
|
+
(0, chai_1.expect)(await tbtc.balanceOf(account1.address)).to.equal(mintedAmount1 - redeemedAmount1);
|
|
211
|
+
(0, chai_1.expect)(await tbtc.balanceOf(account2.address)).to.equal(mintedAmount2 - redeemedAmount2);
|
|
212
|
+
(0, chai_1.expect)(await tbtc.totalSupply()).to.be.equal(totalNotRedeemedAmount);
|
|
213
|
+
});
|
|
214
|
+
it("should emit Unminted events", async () => {
|
|
215
|
+
await (0, chai_1.expect)(transactions[0])
|
|
216
|
+
.to.emit(tbtcVault, "Unminted")
|
|
217
|
+
.withArgs(account1.address, redeemedAmount1);
|
|
218
|
+
await (0, chai_1.expect)(transactions[1])
|
|
219
|
+
.to.emit(tbtcVault, "Unminted")
|
|
220
|
+
.withArgs(account2.address, redeemedAmount2);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
describe("receiveApproval", () => {
|
|
225
|
+
const requestRedemption = async (redeemer, redeemerOutputScript, amount) => {
|
|
226
|
+
const data = defaultAbiCoder.encode(["address", "bytes20", "bytes32", "uint32", "uint64", "bytes"], [
|
|
227
|
+
redeemer.address,
|
|
228
|
+
walletPubKeyHash,
|
|
229
|
+
mainUtxo.txHash,
|
|
230
|
+
mainUtxo.txOutputIndex,
|
|
231
|
+
mainUtxo.txOutputValue,
|
|
232
|
+
redeemerOutputScript,
|
|
233
|
+
]);
|
|
234
|
+
return tbtc
|
|
235
|
+
.connect(redeemer)
|
|
236
|
+
.approveAndCall(tbtcVault.address, amount, data);
|
|
237
|
+
};
|
|
238
|
+
context("when called via approveAndCall", () => {
|
|
239
|
+
context("when called with non-empty extraData", () => {
|
|
240
|
+
context("when there is a single redeemer", () => {
|
|
241
|
+
const redeemerOutputScriptP2WPKH = "0x160014f4eedc8f40d4b8e30771f792b065ebec0abaddef";
|
|
242
|
+
const redeemerOutputScriptP2WSH = "0x220020ef0b4d985752aa5ef6243e4c6f6bebc2a007e7d671ef27d4b1d0db8dcc93bc1c";
|
|
243
|
+
const redeemerOutputScriptP2PKH = "0x1976a914f4eedc8f40d4b8e30771f792b065ebec0abaddef88ac";
|
|
244
|
+
const redeemerOutputScriptP2SH = "0x17a914f4eedc8f40d4b8e30771f792b065ebec0abaddef87";
|
|
245
|
+
const mintedAmount = 10000000;
|
|
246
|
+
const redeemedAmount1 = 1000000;
|
|
247
|
+
const redeemedAmount2 = 2000000;
|
|
248
|
+
const redeemedAmount3 = 3000000;
|
|
249
|
+
const redeemedAmount4 = 1500000;
|
|
250
|
+
const totalRedeemedAmount = redeemedAmount1 +
|
|
251
|
+
redeemedAmount2 +
|
|
252
|
+
redeemedAmount3 +
|
|
253
|
+
redeemedAmount4;
|
|
254
|
+
const notRedeemedAmount = mintedAmount - totalRedeemedAmount;
|
|
255
|
+
const transactions = [];
|
|
256
|
+
before(async () => {
|
|
257
|
+
await createSnapshot();
|
|
258
|
+
await tbtcVault.connect(account1).mint(mintedAmount);
|
|
259
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2WPKH, redeemedAmount1));
|
|
260
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2WSH, redeemedAmount2));
|
|
261
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2PKH, redeemedAmount3));
|
|
262
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2SH, redeemedAmount4));
|
|
263
|
+
});
|
|
264
|
+
after(async () => {
|
|
265
|
+
await restoreSnapshot();
|
|
266
|
+
});
|
|
267
|
+
it("should transfer balances to Bridge", async () => {
|
|
268
|
+
(0, chai_1.expect)(await bank.balanceOf(tbtcVault.address)).to.equal(notRedeemedAmount);
|
|
269
|
+
(0, chai_1.expect)(await bank.balanceOf(bridge.address)).to.equal(totalRedeemedAmount);
|
|
270
|
+
});
|
|
271
|
+
it("should request redemptions in Bridge", async () => {
|
|
272
|
+
const redemptionRequest1 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WPKH));
|
|
273
|
+
(0, chai_1.expect)(redemptionRequest1.redeemer).to.be.equal(account1.address);
|
|
274
|
+
(0, chai_1.expect)(redemptionRequest1.requestedAmount).to.be.equal(redeemedAmount1);
|
|
275
|
+
const redemptionRequest2 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WSH));
|
|
276
|
+
(0, chai_1.expect)(redemptionRequest2.redeemer).to.be.equal(account1.address);
|
|
277
|
+
(0, chai_1.expect)(redemptionRequest2.requestedAmount).to.be.equal(redeemedAmount2);
|
|
278
|
+
const redemptionRequest3 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2PKH));
|
|
279
|
+
(0, chai_1.expect)(redemptionRequest3.redeemer).to.be.equal(account1.address);
|
|
280
|
+
(0, chai_1.expect)(redemptionRequest3.requestedAmount).to.be.equal(redeemedAmount3);
|
|
281
|
+
const redemptionRequest4 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2SH));
|
|
282
|
+
(0, chai_1.expect)(redemptionRequest4.redeemer).to.be.equal(account1.address);
|
|
283
|
+
(0, chai_1.expect)(redemptionRequest4.requestedAmount).to.be.equal(redeemedAmount4);
|
|
284
|
+
});
|
|
285
|
+
it("should burn TBTC", async () => {
|
|
286
|
+
(0, chai_1.expect)(await tbtc.balanceOf(account1.address)).to.equal(notRedeemedAmount);
|
|
287
|
+
(0, chai_1.expect)(await tbtc.totalSupply()).to.be.equal(notRedeemedAmount);
|
|
288
|
+
});
|
|
289
|
+
it("should emit Unminted events", async () => {
|
|
290
|
+
await (0, chai_1.expect)(transactions[0])
|
|
291
|
+
.to.emit(tbtcVault, "Unminted")
|
|
292
|
+
.withArgs(account1.address, redeemedAmount1);
|
|
293
|
+
await (0, chai_1.expect)(transactions[1])
|
|
294
|
+
.to.emit(tbtcVault, "Unminted")
|
|
295
|
+
.withArgs(account1.address, redeemedAmount2);
|
|
296
|
+
await (0, chai_1.expect)(transactions[2])
|
|
297
|
+
.to.emit(tbtcVault, "Unminted")
|
|
298
|
+
.withArgs(account1.address, redeemedAmount3);
|
|
299
|
+
await (0, chai_1.expect)(transactions[3])
|
|
300
|
+
.to.emit(tbtcVault, "Unminted")
|
|
301
|
+
.withArgs(account1.address, redeemedAmount4);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
context("when there are multiple redeemers", () => {
|
|
305
|
+
const redeemerOutputScriptP2WPKH = "0x160014f4eedc8f40d4b8e30771f792b065ebec0abaddef";
|
|
306
|
+
const redeemerOutputScriptP2WSH = "0x220020ef0b4d985752aa5ef6243e4c6f6bebc2a007e7d671ef27d4b1d0db8dcc93bc1c";
|
|
307
|
+
const mintedAmount1 = 10000000;
|
|
308
|
+
const mintedAmount2 = 20000000;
|
|
309
|
+
const redeemedAmount1 = 1000000;
|
|
310
|
+
const redeemedAmount2 = 2000000;
|
|
311
|
+
const totalMintedAmount = mintedAmount1 + mintedAmount2;
|
|
312
|
+
const totalRedeemedAmount = redeemedAmount1 + redeemedAmount2;
|
|
313
|
+
const totalNotRedeemedAmount = totalMintedAmount - totalRedeemedAmount;
|
|
314
|
+
const transactions = [];
|
|
315
|
+
before(async () => {
|
|
316
|
+
await createSnapshot();
|
|
317
|
+
await tbtcVault.connect(account1).mint(mintedAmount1);
|
|
318
|
+
await tbtcVault.connect(account2).mint(mintedAmount2);
|
|
319
|
+
transactions.push(await requestRedemption(account1, redeemerOutputScriptP2WPKH, redeemedAmount1));
|
|
320
|
+
transactions.push(await requestRedemption(account2, redeemerOutputScriptP2WSH, redeemedAmount2));
|
|
321
|
+
});
|
|
322
|
+
after(async () => {
|
|
323
|
+
await restoreSnapshot();
|
|
324
|
+
});
|
|
325
|
+
it("should transfer balances to Bridge", async () => {
|
|
326
|
+
(0, chai_1.expect)(await bank.balanceOf(tbtcVault.address)).to.equal(totalNotRedeemedAmount);
|
|
327
|
+
(0, chai_1.expect)(await bank.balanceOf(bridge.address)).to.equal(totalRedeemedAmount);
|
|
328
|
+
});
|
|
329
|
+
it("should request redemptions in Bridge", async () => {
|
|
330
|
+
const redemptionRequest1 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WPKH));
|
|
331
|
+
(0, chai_1.expect)(redemptionRequest1.redeemer).to.be.equal(account1.address);
|
|
332
|
+
(0, chai_1.expect)(redemptionRequest1.requestedAmount).to.be.equal(redeemedAmount1);
|
|
333
|
+
const redemptionRequest2 = await bridge.pendingRedemptions(buildRedemptionKey(walletPubKeyHash, redeemerOutputScriptP2WSH));
|
|
334
|
+
(0, chai_1.expect)(redemptionRequest2.redeemer).to.be.equal(account2.address);
|
|
335
|
+
(0, chai_1.expect)(redemptionRequest2.requestedAmount).to.be.equal(redeemedAmount2);
|
|
336
|
+
});
|
|
337
|
+
it("should burn TBTC", async () => {
|
|
338
|
+
(0, chai_1.expect)(await tbtc.balanceOf(account1.address)).to.equal(mintedAmount1 - redeemedAmount1);
|
|
339
|
+
(0, chai_1.expect)(await tbtc.balanceOf(account2.address)).to.equal(mintedAmount2 - redeemedAmount2);
|
|
340
|
+
(0, chai_1.expect)(await tbtc.totalSupply()).to.be.equal(totalNotRedeemedAmount);
|
|
341
|
+
});
|
|
342
|
+
it("should emit Unminted events", async () => {
|
|
343
|
+
await (0, chai_1.expect)(transactions[0])
|
|
344
|
+
.to.emit(tbtcVault, "Unminted")
|
|
345
|
+
.withArgs(account1.address, redeemedAmount1);
|
|
346
|
+
await (0, chai_1.expect)(transactions[1])
|
|
347
|
+
.to.emit(tbtcVault, "Unminted")
|
|
348
|
+
.withArgs(account2.address, redeemedAmount2);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
function buildRedemptionKey(walletPubKeyHash, redeemerOutputScript) {
|
|
356
|
+
return hardhat_1.ethers.utils.solidityKeccak256(["bytes20", "bytes"], [walletPubKeyHash, redeemerOutputScript]);
|
|
357
|
+
}
|