-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wait-for-btc-tx
- Loading branch information
Showing
50 changed files
with
6,027 additions
and
2,340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
/* solhint-disable func-name-mixedcase */ | ||
pragma solidity ^0.8.21; | ||
|
||
import {AcreBitcoinDepositor} from "../AcreBitcoinDepositor.sol"; | ||
import {MockBridge, MockTBTCVault} from "@keep-network/tbtc-v2/contracts/test/TestTBTCDepositor.sol"; | ||
import {IBridge} from "@keep-network/tbtc-v2/contracts/integrator/IBridge.sol"; | ||
import {IBridgeTypes} from "@keep-network/tbtc-v2/contracts/integrator/IBridge.sol"; | ||
|
||
import {TestERC20} from "./TestERC20.sol"; | ||
|
||
/// @dev A test contract to expose internal function from AcreBitcoinDepositor contract. | ||
/// This solution follows Foundry recommendation: | ||
/// https://book.getfoundry.sh/tutorials/best-practices#internal-functions | ||
contract AcreBitcoinDepositorHarness is AcreBitcoinDepositor { | ||
constructor( | ||
address bridge, | ||
address tbtcVault, | ||
address tbtcToken, | ||
address stbtc | ||
) AcreBitcoinDepositor(bridge, tbtcVault, tbtcToken, stbtc) {} | ||
|
||
function exposed_finalizeBridging( | ||
uint256 depositKey | ||
) external returns (uint256 amountToStake, address staker) { | ||
return finalizeBridging(depositKey); | ||
} | ||
|
||
function exposed_setQueuedStakesBalance(uint256 amount) external { | ||
queuedStakesBalance = amount; | ||
} | ||
} | ||
|
||
/// @dev A test contract to stub tBTC Bridge contract. | ||
contract BridgeStub is MockBridge {} | ||
|
||
/// @dev A test contract to stub tBTC Vault contract. | ||
contract TBTCVaultStub is MockTBTCVault { | ||
TestERC20 public immutable tbtc; | ||
IBridge public immutable bridge; | ||
|
||
/// @notice Multiplier to convert satoshi to TBTC token units. | ||
uint256 public constant SATOSHI_MULTIPLIER = 10 ** 10; | ||
|
||
constructor(TestERC20 _tbtc, IBridge _bridge) { | ||
tbtc = _tbtc; | ||
bridge = _bridge; | ||
} | ||
|
||
function finalizeOptimisticMintingRequest( | ||
uint256 depositKey | ||
) public override { | ||
IBridgeTypes.DepositRequest memory deposit = bridge.deposits( | ||
depositKey | ||
); | ||
|
||
uint256 amountSubTreasury = (deposit.amount - deposit.treasuryFee) * | ||
SATOSHI_MULTIPLIER; | ||
|
||
uint256 omFee = optimisticMintingFeeDivisor > 0 | ||
? (amountSubTreasury / optimisticMintingFeeDivisor) | ||
: 0; | ||
|
||
// The deposit transaction max fee is in the 1e8 satoshi precision. | ||
// We need to convert them to the 1e18 TBTC precision. | ||
// slither-disable-next-line unused-return | ||
(, , uint64 depositTxMaxFee, ) = bridge.depositParameters(); | ||
uint256 txMaxFee = depositTxMaxFee * SATOSHI_MULTIPLIER; | ||
|
||
uint256 amountToMint = amountSubTreasury - omFee - txMaxFee; | ||
|
||
finalizeOptimisticMintingRequestWithAmount(depositKey, amountToMint); | ||
} | ||
|
||
function finalizeOptimisticMintingRequestWithAmount( | ||
uint256 depositKey, | ||
uint256 amountToMint | ||
) public { | ||
MockTBTCVault.finalizeOptimisticMintingRequest(depositKey); | ||
|
||
tbtc.mint(bridge.deposits(depositKey).depositor, amountToMint); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { DeployFunction } from "hardhat-deploy/types" | ||
import type { | ||
HardhatNetworkConfig, | ||
HardhatRuntimeEnvironment, | ||
} from "hardhat/types" | ||
import { isNonZeroAddress } from "../helpers/address" | ||
import { waitConfirmationsNumber } from "../helpers/deployment" | ||
|
||
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
const { getNamedAccounts, deployments } = hre | ||
const { log } = deployments | ||
const { deployer } = await getNamedAccounts() | ||
|
||
const bridge = await deployments.getOrNull("Bridge") | ||
|
||
if (bridge && isNonZeroAddress(bridge.address)) { | ||
log(`using Bridge contract at ${bridge.address}`) | ||
} else if ((hre.network.config as HardhatNetworkConfig)?.forking?.enabled) { | ||
throw new Error("deployed Bridge contract not found") | ||
} else { | ||
log("deploying Bridge contract stub") | ||
|
||
await deployments.deploy("Bridge", { | ||
contract: "BridgeStub", | ||
args: [], | ||
from: deployer, | ||
log: true, | ||
waitConfirmations: waitConfirmationsNumber(hre), | ||
}) | ||
} | ||
} | ||
|
||
export default func | ||
|
||
func.tags = ["TBTC", "Bridge"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { DeployFunction } from "hardhat-deploy/types" | ||
import type { | ||
HardhatNetworkConfig, | ||
HardhatRuntimeEnvironment, | ||
} from "hardhat/types" | ||
import { isNonZeroAddress } from "../helpers/address" | ||
import { waitConfirmationsNumber } from "../helpers/deployment" | ||
|
||
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
const { getNamedAccounts, deployments } = hre | ||
const { log } = deployments | ||
const { deployer } = await getNamedAccounts() | ||
|
||
const tbtcVault = await deployments.getOrNull("TBTCVault") | ||
|
||
if (tbtcVault && isNonZeroAddress(tbtcVault.address)) { | ||
log(`using TBTCVault contract at ${tbtcVault.address}`) | ||
} else if ( | ||
!hre.network.tags.allowStubs || | ||
(hre.network.config as HardhatNetworkConfig)?.forking?.enabled | ||
) { | ||
throw new Error("deployed TBTCVault contract not found") | ||
} else { | ||
log("deploying TBTCVault contract stub") | ||
|
||
const tbtc = await deployments.get("TBTC") | ||
const bridge = await deployments.get("Bridge") | ||
|
||
await deployments.deploy("TBTCVault", { | ||
contract: "TBTCVaultStub", | ||
args: [tbtc.address, bridge.address], | ||
from: deployer, | ||
log: true, | ||
waitConfirmations: waitConfirmationsNumber(hre), | ||
}) | ||
} | ||
} | ||
|
||
export default func | ||
|
||
func.tags = ["TBTC", "TBTCVault"] | ||
func.dependencies = ["TBTCToken", "Bridge"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { DeployFunction } from "hardhat-deploy/types" | ||
import type { HardhatRuntimeEnvironment } from "hardhat/types" | ||
import { waitConfirmationsNumber } from "../helpers/deployment" | ||
|
||
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
const { getNamedAccounts, deployments, helpers } = hre | ||
const { deployer } = await getNamedAccounts() | ||
|
||
const bridge = await deployments.get("Bridge") | ||
const tbtcVault = await deployments.get("TBTCVault") | ||
const tbtc = await deployments.get("TBTC") | ||
const stbtc = await deployments.get("stBTC") | ||
|
||
const depositor = await deployments.deploy("AcreBitcoinDepositor", { | ||
contract: | ||
process.env.HARDHAT_TEST === "true" | ||
? "AcreBitcoinDepositorHarness" | ||
: "AcreBitcoinDepositor", | ||
from: deployer, | ||
args: [bridge.address, tbtcVault.address, tbtc.address, stbtc.address], | ||
log: true, | ||
waitConfirmations: waitConfirmationsNumber(hre), | ||
}) | ||
|
||
if (hre.network.tags.etherscan) { | ||
await helpers.etherscan.verify(depositor) | ||
} | ||
|
||
// TODO: Add Tenderly verification | ||
} | ||
|
||
export default func | ||
|
||
func.tags = ["AcreBitcoinDepositor"] | ||
func.dependencies = ["TBTC", "stBTC"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { HardhatRuntimeEnvironment } from "hardhat/types" | ||
import type { DeployFunction } from "hardhat-deploy/types" | ||
|
||
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
const { getNamedAccounts, deployments } = hre | ||
const { deployer } = await getNamedAccounts() | ||
|
||
const minimumDepositAmount = 10000000000000 // 0.00001 tBTC | ||
const maximumTotalAssets: bigint = (await deployments.read( | ||
"stBTC", | ||
"maximumTotalAssets", | ||
)) as bigint | ||
|
||
await deployments.execute( | ||
"stBTC", | ||
{ from: deployer, log: true, waitConfirmations: 1 }, | ||
"updateDepositParameters", | ||
minimumDepositAmount, | ||
maximumTotalAssets, | ||
) | ||
} | ||
|
||
export default func | ||
|
||
func.tags = ["stBTCUpdateDepositParameters"] | ||
func.dependencies = ["stBTC"] | ||
|
||
// Run only on Sepolia testnet. | ||
func.skip = async (hre: HardhatRuntimeEnvironment): Promise<boolean> => | ||
Promise.resolve(hre.network.name !== "sepolia") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.