编译器
0.8.24+commit.e11b9ed9
文件 1 的 3:IERC20.sol
pragma solidity ^0.8.20;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
文件 2 的 3:MerkleProof.sol
pragma solidity ^0.8.20;
library MerkleProof {
error MerkleProofInvalidMultiproof();
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
if (leavesLen + proofLen != totalHashes + 1) {
revert MerkleProofInvalidMultiproof();
}
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
if (proofPos != proofLen) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
if (leavesLen + proofLen != totalHashes + 1) {
revert MerkleProofInvalidMultiproof();
}
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
if (proofPos != proofLen) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
文件 3 的 3:Migrator.sol
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract Migrator {
struct LockedMigration {
uint256 receiptAmount;
uint32 lockedAt;
uint32 unlockAfter;
uint32 claimedAt;
}
enum LockDuration {
None,
OneMonth,
ThreeMonths
}
IERC20 public immutable VAIX;
IERC20 public immutable VXV;
IERC20 public immutable SBIO;
address public immutable treasury;
mapping(address => LockedMigration[]) public locks;
bytes32 public immutable whitelistRoot;
uint32 public immutable migrationClosesAfter;
uint256 public immutable sbioMigrationCap;
uint256 public sbioMigrationTotal;
error WhitelistNotVerified();
error MigrationWindowOpen();
error MigrationWindowClosed();
error MigrationCapExceeded();
event Migrated(
address indexed user,
address indexed depositToken,
uint256 depositAmount,
uint256 receiptAmount,
LockDuration lockDuration
);
event Claimed(address indexed user, uint256 receiptAmount);
event TreasuryReceipt(address indexed user, uint256 treasuryReceiptAmount);
constructor(
address treasuryAddress,
address vaixAddress,
address vxvAddress,
address sbioAddress,
bytes32 sbioWhitelistRoot,
uint256 _sbioMigrationCap,
uint32 _migrationClosesAfter
) {
treasury = treasuryAddress;
VAIX = IERC20(vaixAddress);
VXV = IERC20(vxvAddress);
SBIO = IERC20(sbioAddress);
sbioMigrationCap = _sbioMigrationCap;
sbioMigrationTotal = 0;
whitelistRoot = sbioWhitelistRoot;
migrationClosesAfter = _migrationClosesAfter;
}
function maximumMigrationSupply() external view returns (uint256) {
return VXV.totalSupply() + sbioMigrationCap;
}
function migrateFromVXV(uint256 amount) external {
if (block.timestamp > migrationClosesAfter) {
revert MigrationWindowClosed();
}
VXV.transferFrom(msg.sender, address(this), amount);
VAIX.transfer(msg.sender, amount);
emit Migrated(
msg.sender,
address(VXV),
amount,
amount,
LockDuration.None
);
}
function migrateFromSBIO(
uint256 amount,
LockDuration lockDuration,
bytes32[] calldata whitelistProof
) external {
if (block.timestamp > migrationClosesAfter) {
revert MigrationWindowClosed();
}
bytes32 whitelistLeaf = keccak256(
bytes.concat(keccak256(abi.encode(msg.sender)))
);
if (
!MerkleProof.verifyCalldata(
whitelistProof,
whitelistRoot,
whitelistLeaf
)
) {
revert WhitelistNotVerified();
}
sbioMigrationTotal += amount;
if (sbioMigrationTotal > sbioMigrationCap) {
revert MigrationCapExceeded();
}
SBIO.transferFrom(msg.sender, address(this), amount);
LockedMigration memory lock = _makeSBIOLock(amount, lockDuration);
locks[msg.sender].push(lock);
emit Migrated(
msg.sender,
address(SBIO),
amount,
lock.receiptAmount,
lockDuration
);
uint256 remainder = amount - lock.receiptAmount;
if (remainder > 0) {
VAIX.transfer(treasury, remainder);
emit TreasuryReceipt(msg.sender, remainder);
}
_claimUnlockedMigrations(msg.sender);
}
function locksOf(
address user
) external view returns (LockedMigration[] memory) {
return locks[user];
}
function claim() external {
_claimUnlockedMigrations(msg.sender);
}
function claimableBalanceOf(
address user
) external view returns (uint256 balance) {
balance = 0;
if (block.timestamp > migrationClosesAfter) {
return 0;
}
LockedMigration[] storage userLocks = locks[user];
for (uint256 i = 0; i < userLocks.length; i++) {
LockedMigration storage lock = userLocks[i];
if (lock.unlockAfter < block.timestamp && lock.claimedAt == 0) {
balance += lock.receiptAmount;
}
}
}
function withdrawAfterClosing() external {
if (block.timestamp <= migrationClosesAfter) {
revert MigrationWindowOpen();
}
VAIX.transfer(treasury, VAIX.balanceOf(address(this)));
SBIO.transfer(treasury, SBIO.balanceOf(address(this)));
}
function isMigrationClosed() external view returns (bool) {
return block.timestamp > migrationClosesAfter;
}
function _claimUnlockedMigrations(address user) internal {
if (block.timestamp > migrationClosesAfter) {
revert MigrationWindowClosed();
}
LockedMigration[] storage userLocks = locks[user];
for (uint256 i = 0; i < userLocks.length; i++) {
LockedMigration storage lock = userLocks[i];
if (lock.unlockAfter < block.timestamp && lock.claimedAt == 0) {
lock.claimedAt = uint32(block.timestamp);
VAIX.transfer(user, lock.receiptAmount);
emit Claimed(user, lock.receiptAmount);
}
}
}
function _makeSBIOLock(
uint256 amount,
LockDuration duration
) private view returns (LockedMigration memory) {
LockedMigration memory lock;
lock.lockedAt = uint32(block.timestamp);
lock.claimedAt = 0;
if (duration == LockDuration.ThreeMonths) {
lock.unlockAfter = uint32(block.timestamp) + 90 days;
lock.receiptAmount = amount;
} else if (duration == LockDuration.OneMonth) {
lock.unlockAfter = uint32(block.timestamp) + 30 days;
lock.receiptAmount = amount / 2;
} else {
lock.unlockAfter = 0;
lock.receiptAmount = amount / 3;
}
return lock;
}
}
{
"compilationTarget": {
"contracts/Migrator.sol": "Migrator"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"treasuryAddress","type":"address"},{"internalType":"address","name":"vaixAddress","type":"address"},{"internalType":"address","name":"vxvAddress","type":"address"},{"internalType":"address","name":"sbioAddress","type":"address"},{"internalType":"bytes32","name":"sbioWhitelistRoot","type":"bytes32"},{"internalType":"uint256","name":"_sbioMigrationCap","type":"uint256"},{"internalType":"uint32","name":"_migrationClosesAfter","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"MigrationCapExceeded","type":"error"},{"inputs":[],"name":"MigrationWindowClosed","type":"error"},{"inputs":[],"name":"MigrationWindowOpen","type":"error"},{"inputs":[],"name":"WhitelistNotVerified","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"receiptAmount","type":"uint256"}],"name":"Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"depositToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"depositAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"receiptAmount","type":"uint256"},{"indexed":false,"internalType":"enum Migrator.LockDuration","name":"lockDuration","type":"uint8"}],"name":"Migrated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"treasuryReceiptAmount","type":"uint256"}],"name":"TreasuryReceipt","type":"event"},{"inputs":[],"name":"SBIO","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VAIX","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VXV","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"claimableBalanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isMigrationClosed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"locks","outputs":[{"internalType":"uint256","name":"receiptAmount","type":"uint256"},{"internalType":"uint32","name":"lockedAt","type":"uint32"},{"internalType":"uint32","name":"unlockAfter","type":"uint32"},{"internalType":"uint32","name":"claimedAt","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"locksOf","outputs":[{"components":[{"internalType":"uint256","name":"receiptAmount","type":"uint256"},{"internalType":"uint32","name":"lockedAt","type":"uint32"},{"internalType":"uint32","name":"unlockAfter","type":"uint32"},{"internalType":"uint32","name":"claimedAt","type":"uint32"}],"internalType":"struct Migrator.LockedMigration[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maximumMigrationSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum Migrator.LockDuration","name":"lockDuration","type":"uint8"},{"internalType":"bytes32[]","name":"whitelistProof","type":"bytes32[]"}],"name":"migrateFromSBIO","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"migrateFromVXV","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"migrationClosesAfter","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sbioMigrationCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sbioMigrationTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"whitelistRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawAfterClosing","outputs":[],"stateMutability":"nonpayable","type":"function"}]