@keep-network/tbtc-v2 1.6.0-dev.17 → 1.6.0-dev.18
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/artifacts/BLS.json +1 -1
- package/artifacts/Bank.json +2 -2
- package/artifacts/BeaconAuthorization.json +1 -1
- package/artifacts/BeaconDkg.json +1 -1
- package/artifacts/BeaconDkgValidator.json +1 -1
- package/artifacts/BeaconInactivity.json +1 -1
- package/artifacts/BeaconSortitionPool.json +3 -3
- package/artifacts/Bridge.json +5 -5
- package/artifacts/BridgeGovernance.json +2 -2
- package/artifacts/BridgeGovernanceParameters.json +1 -1
- package/artifacts/Deposit.json +1 -1
- package/artifacts/DepositSweep.json +1 -1
- package/artifacts/DonationVault.json +1 -1
- package/artifacts/EcdsaDkgValidator.json +1 -1
- package/artifacts/EcdsaInactivity.json +1 -1
- package/artifacts/EcdsaSortitionPool.json +3 -3
- package/artifacts/Fraud.json +1 -1
- package/artifacts/LightRelay.json +2 -2
- package/artifacts/LightRelayMaintainerProxy.json +2 -2
- package/artifacts/MaintainerProxy.json +2 -2
- package/artifacts/MovingFunds.json +1 -1
- package/artifacts/NuCypherToken.json +2 -2
- package/artifacts/RandomBeacon.json +2 -2
- package/artifacts/RandomBeaconChaosnet.json +2 -2
- package/artifacts/RandomBeaconGovernance.json +2 -2
- package/artifacts/Redemption.json +1 -1
- package/artifacts/ReimbursementPool.json +2 -2
- package/artifacts/T.json +2 -2
- package/artifacts/TBTC.json +2 -2
- package/artifacts/TBTCToken.json +2 -2
- package/artifacts/TBTCVault.json +2 -2
- package/artifacts/TokenStaking.json +1 -1
- package/artifacts/TokenholderGovernor.json +9 -9
- package/artifacts/TokenholderTimelock.json +8 -8
- package/artifacts/VendingMachine.json +2 -2
- package/artifacts/VendingMachineNuCypher.json +1 -1
- package/artifacts/VendingMachineV2.json +2 -2
- package/artifacts/VendingMachineV3.json +2 -2
- package/artifacts/WalletProposalValidator.json +1 -1
- package/artifacts/WalletRegistry.json +5 -5
- package/artifacts/WalletRegistryGovernance.json +2 -2
- package/artifacts/Wallets.json +1 -1
- package/build/contracts/test/BankStub.sol/BankStub.dbg.json +4 -0
- package/build/contracts/test/BankStub.sol/BankStub.json +555 -0
- package/build/contracts/test/BridgeStub.sol/BridgeStub.dbg.json +4 -0
- package/build/contracts/test/BridgeStub.sol/BridgeStub.json +3318 -0
- package/build/contracts/test/HeartbeatStub.sol/HeartbeatStub.dbg.json +4 -0
- package/build/contracts/test/HeartbeatStub.sol/HeartbeatStub.json +30 -0
- package/build/contracts/test/LightRelayStub.sol/LightRelayStub.dbg.json +4 -0
- package/build/contracts/test/LightRelayStub.sol/LightRelayStub.json +467 -0
- package/build/contracts/test/ReceiveApprovalStub.sol/ReceiveApprovalStub.dbg.json +4 -0
- package/build/contracts/test/ReceiveApprovalStub.sol/ReceiveApprovalStub.json +96 -0
- package/build/contracts/test/SepoliaLightRelay.sol/SepoliaLightRelay.dbg.json +4 -0
- package/build/contracts/test/SepoliaLightRelay.sol/SepoliaLightRelay.json +456 -0
- package/build/contracts/test/SystemTestRelay.sol/SystemTestRelay.dbg.json +4 -0
- package/build/contracts/test/SystemTestRelay.sol/SystemTestRelay.json +89 -0
- package/build/contracts/test/TestBitcoinTx.sol/TestBitcoinTx.dbg.json +4 -0
- package/build/contracts/test/TestBitcoinTx.sol/TestBitcoinTx.json +102 -0
- package/build/contracts/test/TestERC20.sol/TestERC20.dbg.json +4 -0
- package/build/contracts/test/TestERC20.sol/TestERC20.json +508 -0
- package/build/contracts/test/TestERC721.sol/TestERC721.dbg.json +4 -0
- package/build/contracts/test/TestERC721.sol/TestERC721.json +390 -0
- package/build/contracts/test/TestEcdsaLib.sol/TestEcdsaLib.dbg.json +4 -0
- package/build/contracts/test/TestEcdsaLib.sol/TestEcdsaLib.json +35 -0
- package/build/contracts/test/TestTBTCDepositor.sol/MockBridge.dbg.json +4 -0
- package/build/contracts/test/TestTBTCDepositor.sol/MockBridge.json +224 -0
- package/build/contracts/test/TestTBTCDepositor.sol/MockTBTCVault.dbg.json +4 -0
- package/build/contracts/test/TestTBTCDepositor.sol/MockTBTCVault.json +87 -0
- package/build/contracts/test/TestTBTCDepositor.sol/TestTBTCDepositor.dbg.json +4 -0
- package/build/contracts/test/TestTBTCDepositor.sol/TestTBTCDepositor.json +283 -0
- package/build/contracts/test/WormholeBridgeStub.sol/WormholeBridgeStub.dbg.json +4 -0
- package/build/contracts/test/WormholeBridgeStub.sol/WormholeBridgeStub.json +372 -0
- package/contracts/test/BankStub.sol +11 -0
- package/contracts/test/BridgeStub.sol +174 -0
- package/contracts/test/HeartbeatStub.sol +16 -0
- package/contracts/test/LightRelayStub.sol +15 -0
- package/contracts/test/ReceiveApprovalStub.sol +33 -0
- package/contracts/test/SepoliaLightRelay.sol +48 -0
- package/contracts/test/SystemTestRelay.sol +57 -0
- package/contracts/test/TestBitcoinTx.sol +24 -0
- package/contracts/test/TestERC20.sol +12 -0
- package/contracts/test/TestERC721.sol +16 -0
- package/contracts/test/TestEcdsaLib.sol +17 -0
- package/contracts/test/TestTBTCDepositor.sol +196 -0
- package/contracts/test/WormholeBridgeStub.sol +125 -0
- package/package.json +1 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
// ██████████████ ▐████▌ ██████████████
|
|
4
|
+
// ██████████████ ▐████▌ ██████████████
|
|
5
|
+
// ▐████▌ ▐████▌
|
|
6
|
+
// ▐████▌ ▐████▌
|
|
7
|
+
// ██████████████ ▐████▌ ██████████████
|
|
8
|
+
// ██████████████ ▐████▌ ██████████████
|
|
9
|
+
// ▐████▌ ▐████▌
|
|
10
|
+
// ▐████▌ ▐████▌
|
|
11
|
+
// ▐████▌ ▐████▌
|
|
12
|
+
// ▐████▌ ▐████▌
|
|
13
|
+
// ▐████▌ ▐████▌
|
|
14
|
+
// ▐████▌ ▐████▌
|
|
15
|
+
|
|
16
|
+
pragma solidity 0.8.17;
|
|
17
|
+
|
|
18
|
+
import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
|
|
19
|
+
|
|
20
|
+
import "../relay/LightRelay.sol";
|
|
21
|
+
|
|
22
|
+
/// @title Sepolia Light Relay
|
|
23
|
+
/// @notice SepoliaLightRelay is a stub version of LightRelay intended to be
|
|
24
|
+
/// used on the Sepolia test network. It allows to set the relay's
|
|
25
|
+
/// difficulty based on arbitrary Bitcoin headers thus effectively
|
|
26
|
+
/// bypass the validation of difficulties of Bitcoin testnet blocks.
|
|
27
|
+
/// Since difficulty in Bitcoin testnet often falls to `1` it would not
|
|
28
|
+
/// be possible to validate blocks with the real LightRelay.
|
|
29
|
+
/// @dev Notice that SepoliaLightRelay is derived from LightRelay so that the two
|
|
30
|
+
/// contracts have the same API and correct bindings can be generated.
|
|
31
|
+
contract SepoliaLightRelay is LightRelay {
|
|
32
|
+
using BTCUtils for bytes;
|
|
33
|
+
using BTCUtils for uint256;
|
|
34
|
+
|
|
35
|
+
/// @notice Sets the current and previous difficulty based on the difficulty
|
|
36
|
+
/// inferred from the provided Bitcoin headers.
|
|
37
|
+
function setDifficultyFromHeaders(bytes memory bitcoinHeaders)
|
|
38
|
+
external
|
|
39
|
+
onlyOwner
|
|
40
|
+
{
|
|
41
|
+
uint256 firstHeaderDiff = bitcoinHeaders
|
|
42
|
+
.extractTarget()
|
|
43
|
+
.calculateDifficulty();
|
|
44
|
+
|
|
45
|
+
currentEpochDifficulty = firstHeaderDiff;
|
|
46
|
+
prevEpochDifficulty = firstHeaderDiff;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
|
|
6
|
+
|
|
7
|
+
import "../bridge/Bridge.sol";
|
|
8
|
+
|
|
9
|
+
/// @notice Used only for system tests.
|
|
10
|
+
contract SystemTestRelay is IRelay {
|
|
11
|
+
using BTCUtils for bytes;
|
|
12
|
+
using BTCUtils for uint256;
|
|
13
|
+
|
|
14
|
+
uint256 private currentEpochDifficulty;
|
|
15
|
+
uint256 private prevEpochDifficulty;
|
|
16
|
+
|
|
17
|
+
function setCurrentEpochDifficulty(uint256 _difficulty) external {
|
|
18
|
+
currentEpochDifficulty = _difficulty;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function setPrevEpochDifficulty(uint256 _difficulty) external {
|
|
22
|
+
prevEpochDifficulty = _difficulty;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setCurrentEpochDifficultyFromHeaders(bytes memory bitcoinHeaders)
|
|
26
|
+
external
|
|
27
|
+
{
|
|
28
|
+
uint256 firstHeaderDiff = bitcoinHeaders
|
|
29
|
+
.extractTarget()
|
|
30
|
+
.calculateDifficulty();
|
|
31
|
+
|
|
32
|
+
currentEpochDifficulty = firstHeaderDiff;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function setPrevEpochDifficultyFromHeaders(bytes memory bitcoinHeaders)
|
|
36
|
+
external
|
|
37
|
+
{
|
|
38
|
+
uint256 firstHeaderDiff = bitcoinHeaders
|
|
39
|
+
.extractTarget()
|
|
40
|
+
.calculateDifficulty();
|
|
41
|
+
|
|
42
|
+
prevEpochDifficulty = firstHeaderDiff;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getCurrentEpochDifficulty()
|
|
46
|
+
external
|
|
47
|
+
view
|
|
48
|
+
override
|
|
49
|
+
returns (uint256)
|
|
50
|
+
{
|
|
51
|
+
return currentEpochDifficulty;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getPrevEpochDifficulty() external view override returns (uint256) {
|
|
55
|
+
return prevEpochDifficulty;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import "../bridge/BitcoinTx.sol";
|
|
6
|
+
import "../bridge/BridgeState.sol";
|
|
7
|
+
import "../bridge/IRelay.sol";
|
|
8
|
+
|
|
9
|
+
contract TestBitcoinTx {
|
|
10
|
+
BridgeState.Storage internal self;
|
|
11
|
+
|
|
12
|
+
event ProofValidated(bytes32 txHash);
|
|
13
|
+
|
|
14
|
+
constructor(address _relay) {
|
|
15
|
+
self.relay = IRelay(_relay);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function validateProof(
|
|
19
|
+
BitcoinTx.Info calldata txInfo,
|
|
20
|
+
BitcoinTx.Proof calldata proof
|
|
21
|
+
) external {
|
|
22
|
+
emit ProofValidated(BitcoinTx.validateProof(self, txInfo, proof));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import "@thesis/solidity-contracts/contracts/token/ERC20WithPermit.sol";
|
|
6
|
+
|
|
7
|
+
contract TestERC20 is ERC20WithPermit {
|
|
8
|
+
string public constant NAME = "Test ERC20 Token";
|
|
9
|
+
string public constant SYMBOL = "TT";
|
|
10
|
+
|
|
11
|
+
constructor() ERC20WithPermit(NAME, SYMBOL) {}
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
|
6
|
+
|
|
7
|
+
contract TestERC721 is ERC721 {
|
|
8
|
+
string public constant NAME = "Test ERC721 Token";
|
|
9
|
+
string public constant SYMBOL = "TT";
|
|
10
|
+
|
|
11
|
+
constructor() ERC721(NAME, SYMBOL) {}
|
|
12
|
+
|
|
13
|
+
function mint(address to, uint256 tokenId) public {
|
|
14
|
+
_mint(to, tokenId);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import "../bridge/EcdsaLib.sol";
|
|
6
|
+
|
|
7
|
+
// TODO: Rename to EcdsLibStub
|
|
8
|
+
/// @dev This is a contract implemented to test EcdsaLib library directly.
|
|
9
|
+
contract TestEcdsaLib {
|
|
10
|
+
function compressPublicKey(bytes32 x, bytes32 y)
|
|
11
|
+
public
|
|
12
|
+
pure
|
|
13
|
+
returns (bytes memory)
|
|
14
|
+
{
|
|
15
|
+
return EcdsaLib.compressPublicKey(x, y);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
|
|
5
|
+
import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
|
|
6
|
+
|
|
7
|
+
import "../integrator/AbstractTBTCDepositor.sol";
|
|
8
|
+
import "../integrator/IBridge.sol";
|
|
9
|
+
import "../integrator/ITBTCVault.sol";
|
|
10
|
+
|
|
11
|
+
contract TestTBTCDepositor is AbstractTBTCDepositor {
|
|
12
|
+
event InitializeDepositReturned(uint256 depositKey);
|
|
13
|
+
|
|
14
|
+
event FinalizeDepositReturned(
|
|
15
|
+
uint256 initialDepositAmount,
|
|
16
|
+
uint256 tbtcAmount,
|
|
17
|
+
bytes32 extraData
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
function initialize(address _bridge, address _tbtcVault) external {
|
|
21
|
+
__AbstractTBTCDepositor_initialize(_bridge, _tbtcVault);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function initializeDepositPublic(
|
|
25
|
+
IBridgeTypes.BitcoinTxInfo calldata fundingTx,
|
|
26
|
+
IBridgeTypes.DepositRevealInfo calldata reveal,
|
|
27
|
+
bytes32 extraData
|
|
28
|
+
) external {
|
|
29
|
+
uint256 depositKey = _initializeDeposit(fundingTx, reveal, extraData);
|
|
30
|
+
emit InitializeDepositReturned(depositKey);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function finalizeDepositPublic(uint256 depositKey) external {
|
|
34
|
+
(
|
|
35
|
+
uint256 initialDepositAmount,
|
|
36
|
+
uint256 tbtcAmount,
|
|
37
|
+
bytes32 extraData
|
|
38
|
+
) = _finalizeDeposit(depositKey);
|
|
39
|
+
emit FinalizeDepositReturned(
|
|
40
|
+
initialDepositAmount,
|
|
41
|
+
tbtcAmount,
|
|
42
|
+
extraData
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function calculateTbtcAmountPublic(
|
|
47
|
+
uint64 depositAmountSat,
|
|
48
|
+
uint64 depositTreasuryFeeSat
|
|
49
|
+
) external view returns (uint256) {
|
|
50
|
+
return _calculateTbtcAmount(depositAmountSat, depositTreasuryFeeSat);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
contract MockBridge is IBridge {
|
|
55
|
+
using BTCUtils for bytes;
|
|
56
|
+
|
|
57
|
+
mapping(uint256 => IBridgeTypes.DepositRequest) internal _deposits;
|
|
58
|
+
|
|
59
|
+
uint64 internal _depositTreasuryFeeDivisor = 50; // 1/50 == 100 bps == 2% == 0.02
|
|
60
|
+
uint64 internal _depositTxMaxFee = 1000; // 1000 satoshi = 0.00001 BTC
|
|
61
|
+
|
|
62
|
+
event DepositRevealed(uint256 depositKey);
|
|
63
|
+
|
|
64
|
+
function revealDepositWithExtraData(
|
|
65
|
+
IBridgeTypes.BitcoinTxInfo calldata fundingTx,
|
|
66
|
+
IBridgeTypes.DepositRevealInfo calldata reveal,
|
|
67
|
+
bytes32 extraData
|
|
68
|
+
) external {
|
|
69
|
+
bytes32 fundingTxHash = abi
|
|
70
|
+
.encodePacked(
|
|
71
|
+
fundingTx.version,
|
|
72
|
+
fundingTx.inputVector,
|
|
73
|
+
fundingTx.outputVector,
|
|
74
|
+
fundingTx.locktime
|
|
75
|
+
)
|
|
76
|
+
.hash256View();
|
|
77
|
+
|
|
78
|
+
uint256 depositKey = uint256(
|
|
79
|
+
keccak256(
|
|
80
|
+
abi.encodePacked(fundingTxHash, reveal.fundingOutputIndex)
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
require(
|
|
85
|
+
_deposits[depositKey].revealedAt == 0,
|
|
86
|
+
"Deposit already revealed"
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
bytes memory fundingOutput = fundingTx
|
|
90
|
+
.outputVector
|
|
91
|
+
.extractOutputAtIndex(reveal.fundingOutputIndex);
|
|
92
|
+
|
|
93
|
+
uint64 fundingOutputAmount = fundingOutput.extractValue();
|
|
94
|
+
|
|
95
|
+
IBridgeTypes.DepositRequest memory request;
|
|
96
|
+
|
|
97
|
+
request.depositor = msg.sender;
|
|
98
|
+
request.amount = fundingOutputAmount;
|
|
99
|
+
/* solhint-disable-next-line not-rely-on-time */
|
|
100
|
+
request.revealedAt = uint32(block.timestamp);
|
|
101
|
+
request.vault = reveal.vault;
|
|
102
|
+
request.treasuryFee = _depositTreasuryFeeDivisor > 0
|
|
103
|
+
? fundingOutputAmount / _depositTreasuryFeeDivisor
|
|
104
|
+
: 0;
|
|
105
|
+
request.sweptAt = 0;
|
|
106
|
+
request.extraData = extraData;
|
|
107
|
+
|
|
108
|
+
_deposits[depositKey] = request;
|
|
109
|
+
|
|
110
|
+
emit DepositRevealed(depositKey);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function sweepDeposit(uint256 depositKey) public {
|
|
114
|
+
require(_deposits[depositKey].revealedAt != 0, "Deposit not revealed");
|
|
115
|
+
require(_deposits[depositKey].sweptAt == 0, "Deposit already swept");
|
|
116
|
+
/* solhint-disable-next-line not-rely-on-time */
|
|
117
|
+
_deposits[depositKey].sweptAt = uint32(block.timestamp);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function deposits(uint256 depositKey)
|
|
121
|
+
external
|
|
122
|
+
view
|
|
123
|
+
returns (IBridgeTypes.DepositRequest memory)
|
|
124
|
+
{
|
|
125
|
+
return _deposits[depositKey];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function depositParameters()
|
|
129
|
+
external
|
|
130
|
+
view
|
|
131
|
+
returns (
|
|
132
|
+
uint64 depositDustThreshold,
|
|
133
|
+
uint64 depositTreasuryFeeDivisor,
|
|
134
|
+
uint64 depositTxMaxFee,
|
|
135
|
+
uint32 depositRevealAheadPeriod
|
|
136
|
+
)
|
|
137
|
+
{
|
|
138
|
+
depositDustThreshold = 0;
|
|
139
|
+
depositTreasuryFeeDivisor = 0;
|
|
140
|
+
depositTxMaxFee = _depositTxMaxFee;
|
|
141
|
+
depositRevealAheadPeriod = 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function setDepositTreasuryFeeDivisor(uint64 value) external {
|
|
145
|
+
_depositTreasuryFeeDivisor = value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function setDepositTxMaxFee(uint64 value) external {
|
|
149
|
+
_depositTxMaxFee = value;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
contract MockTBTCVault is ITBTCVault {
|
|
154
|
+
struct Request {
|
|
155
|
+
uint64 requestedAt;
|
|
156
|
+
uint64 finalizedAt;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
mapping(uint256 => Request) internal _requests;
|
|
160
|
+
|
|
161
|
+
uint32 public optimisticMintingFeeDivisor = 100; // 1%
|
|
162
|
+
|
|
163
|
+
function optimisticMintingRequests(uint256 depositKey)
|
|
164
|
+
external
|
|
165
|
+
returns (uint64 requestedAt, uint64 finalizedAt)
|
|
166
|
+
{
|
|
167
|
+
Request memory request = _requests[depositKey];
|
|
168
|
+
return (request.requestedAt, request.finalizedAt);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function createOptimisticMintingRequest(uint256 depositKey) external {
|
|
172
|
+
require(
|
|
173
|
+
_requests[depositKey].requestedAt == 0,
|
|
174
|
+
"Request already exists"
|
|
175
|
+
);
|
|
176
|
+
/* solhint-disable-next-line not-rely-on-time */
|
|
177
|
+
_requests[depositKey].requestedAt = uint64(block.timestamp);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function finalizeOptimisticMintingRequest(uint256 depositKey) public {
|
|
181
|
+
require(
|
|
182
|
+
_requests[depositKey].requestedAt != 0,
|
|
183
|
+
"Request does not exist"
|
|
184
|
+
);
|
|
185
|
+
require(
|
|
186
|
+
_requests[depositKey].finalizedAt == 0,
|
|
187
|
+
"Request already finalized"
|
|
188
|
+
);
|
|
189
|
+
/* solhint-disable-next-line not-rely-on-time */
|
|
190
|
+
_requests[depositKey].finalizedAt = uint64(block.timestamp);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function setOptimisticMintingFeeDivisor(uint32 value) external {
|
|
194
|
+
optimisticMintingFeeDivisor = value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import "./TestERC20.sol";
|
|
6
|
+
import "../l2/L2WormholeGateway.sol";
|
|
7
|
+
|
|
8
|
+
/// @dev Stub contract used in L2WormholeGateway unit tests.
|
|
9
|
+
/// Stub contract is used instead of a smock because of the token transfer
|
|
10
|
+
/// that needs to happen in completeTransferWithPayload function.
|
|
11
|
+
contract WormholeBridgeStub is IWormholeTokenBridge {
|
|
12
|
+
TestERC20 public wormholeToken;
|
|
13
|
+
|
|
14
|
+
uint256 public transferAmount;
|
|
15
|
+
bytes32 public receiverAddress;
|
|
16
|
+
|
|
17
|
+
// Two simple events allowing to assert Wormhole bridge functions are
|
|
18
|
+
// called.
|
|
19
|
+
event WormholeBridgeStub_completeTransferWithPayload(bytes encodedVm);
|
|
20
|
+
event WormholeBridgeStub_transferTokens(
|
|
21
|
+
address token,
|
|
22
|
+
uint256 amount,
|
|
23
|
+
uint16 recipientChain,
|
|
24
|
+
bytes32 recipient,
|
|
25
|
+
uint256 arbiterFee,
|
|
26
|
+
uint32 nonce
|
|
27
|
+
);
|
|
28
|
+
event WormholeBridgeStub_transferTokensWithPayload(
|
|
29
|
+
address token,
|
|
30
|
+
uint256 amount,
|
|
31
|
+
uint16 recipientChain,
|
|
32
|
+
bytes32 recipient,
|
|
33
|
+
uint32 nonce,
|
|
34
|
+
bytes payload
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
constructor(TestERC20 _wormholeToken) {
|
|
38
|
+
wormholeToken = _wormholeToken;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function completeTransferWithPayload(bytes memory encodedVm)
|
|
42
|
+
external
|
|
43
|
+
returns (bytes memory)
|
|
44
|
+
{
|
|
45
|
+
emit WormholeBridgeStub_completeTransferWithPayload(encodedVm);
|
|
46
|
+
wormholeToken.mint(msg.sender, transferAmount);
|
|
47
|
+
|
|
48
|
+
// In a real implementation, encodedVm is parsed. To avoid copy-pasting
|
|
49
|
+
// Wormhole code to this contract and then encoding parmaters in unit
|
|
50
|
+
// tests, we allow to set the receiver address on the stub contract and
|
|
51
|
+
// we return it here. The rest of the parameters does not matter.
|
|
52
|
+
IWormholeTokenBridge.TransferWithPayload memory transfer = IWormholeTokenBridge
|
|
53
|
+
.TransferWithPayload(
|
|
54
|
+
1, // payloadID
|
|
55
|
+
2, // amount
|
|
56
|
+
0x3000000000000000000000000000000000000000000000000000000000000000, // tokenAddress
|
|
57
|
+
4, // tokenChain
|
|
58
|
+
0x5000000000000000000000000000000000000000000000000000000000000000, // to
|
|
59
|
+
6, // toChain
|
|
60
|
+
0x7000000000000000000000000000000000000000000000000000000000000000, // fromAddress
|
|
61
|
+
abi.encode(receiverAddress) // payload
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return abi.encode(transfer);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function transferTokens(
|
|
68
|
+
address token,
|
|
69
|
+
uint256 amount,
|
|
70
|
+
uint16 recipientChain,
|
|
71
|
+
bytes32 recipient,
|
|
72
|
+
uint256 arbiterFee,
|
|
73
|
+
uint32 nonce
|
|
74
|
+
) external payable returns (uint64 sequence) {
|
|
75
|
+
emit WormholeBridgeStub_transferTokens(
|
|
76
|
+
token,
|
|
77
|
+
amount,
|
|
78
|
+
recipientChain,
|
|
79
|
+
recipient,
|
|
80
|
+
arbiterFee,
|
|
81
|
+
nonce
|
|
82
|
+
);
|
|
83
|
+
return 777;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function transferTokensWithPayload(
|
|
87
|
+
address token,
|
|
88
|
+
uint256 amount,
|
|
89
|
+
uint16 recipientChain,
|
|
90
|
+
bytes32 recipient,
|
|
91
|
+
uint32 nonce,
|
|
92
|
+
bytes memory payload
|
|
93
|
+
) external payable returns (uint64 sequence) {
|
|
94
|
+
emit WormholeBridgeStub_transferTokensWithPayload(
|
|
95
|
+
token,
|
|
96
|
+
amount,
|
|
97
|
+
recipientChain,
|
|
98
|
+
recipient,
|
|
99
|
+
nonce,
|
|
100
|
+
payload
|
|
101
|
+
);
|
|
102
|
+
return 888;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function parseTransferWithPayload(bytes memory encoded)
|
|
106
|
+
external
|
|
107
|
+
pure
|
|
108
|
+
returns (IWormholeTokenBridge.TransferWithPayload memory transfer)
|
|
109
|
+
{
|
|
110
|
+
return abi.decode(encoded, (IWormholeTokenBridge.TransferWithPayload));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function setTransferAmount(uint256 _transferAmount) external {
|
|
114
|
+
transferAmount = _transferAmount;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function setReceiverAddress(bytes32 _receiverAddress) external {
|
|
118
|
+
receiverAddress = _receiverAddress;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Allows to mint Wormhole tBTC for depositWormholeTbtc unit tests.
|
|
122
|
+
function mintWormholeToken(address to, uint256 amount) external {
|
|
123
|
+
wormholeToken.mint(to, amount);
|
|
124
|
+
}
|
|
125
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keep-network/tbtc-v2",
|
|
3
|
-
"version": "1.6.0-dev.
|
|
3
|
+
"version": "1.6.0-dev.18+main.7561ba72c3a0f2b4ede45cd751067bd8d0f8c78e",
|
|
4
4
|
"license": "GPL-3.0-only",
|
|
5
5
|
"files": [
|
|
6
6
|
"artifacts/",
|
|
7
7
|
"build/contracts/",
|
|
8
8
|
"contracts/",
|
|
9
|
-
"!**/test/",
|
|
10
9
|
"deploy/",
|
|
11
10
|
"export/",
|
|
12
11
|
"tasks/",
|