Skip to content

Commit

Permalink
CCIP & PoR (#58)
Browse files Browse the repository at this point in the history
* minter/burner addies on dlcBTC

* change fetching DLCs to paginated

* upgrade for devnet arbSepolia
  • Loading branch information
scolear authored May 3, 2024
1 parent 29e2d3d commit 3e041b2
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 27 deletions.
33 changes: 30 additions & 3 deletions contracts/DLCBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ contract DLCBTC is
OwnableUpgradeable
{
mapping(address => bool) public blacklisted;
uint256[50] __gap;
address private _minter;
address private _burner;
uint256[48] __gap;

error BlacklistedSender();
error BlacklistedRecipient();
error NotAuthorized();

event Blacklisted(address account);
event Unblacklisted(address account);
event MinterSet(address minter);
event BurnerSet(address burner);

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
Expand All @@ -46,16 +51,28 @@ contract DLCBTC is
__ERC20Permit_init("dlcBTC");
}

modifier onlyMinterOrOwner() {
if (msg.sender != _minter && this.owner() != msg.sender)
revert NotAuthorized();
_;
}

modifier onlyBurnerOrOwner() {
if (msg.sender != _burner && this.owner() != msg.sender)
revert NotAuthorized();
_;
}

// Representing Satoshis
function decimals() public view virtual override returns (uint8) {
return 8;
}

function mint(address to, uint256 amount) external onlyOwner {
function mint(address to, uint256 amount) external onlyMinterOrOwner {
_mint(to, amount);
}

function burn(address from, uint256 amount) external onlyOwner {
function burn(address from, uint256 amount) external onlyBurnerOrOwner {
_burn(from, amount);
}

Expand All @@ -78,4 +95,14 @@ contract DLCBTC is
if (blacklisted[from]) revert BlacklistedSender();
if (blacklisted[to]) revert BlacklistedRecipient();
}

function setMinter(address minter) external onlyOwner {
_minter = minter;
emit MinterSet(minter);
}

function setBurner(address burner) external onlyOwner {
_burner = burner;
emit BurnerSet(burner);
}
}
25 changes: 14 additions & 11 deletions contracts/DLCManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -368,25 +368,28 @@ contract DLCManager is
return dlcs[index];
}

function getFundedDLCs(
/**
* @notice Fetch DLCs, paginated.
* @param startIndex index to start from.
* @param endIndex end index (not inclusive).
* @return DLCLink.DLC[] list of DLCs.
*/
function getAllDLCs(
uint256 startIndex,
uint256 endIndex
) public view returns (DLCLink.DLC[] memory) {
) external view returns (DLCLink.DLC[] memory) {
if (startIndex >= endIndex) revert InvalidRange();
if (endIndex > _index) endIndex = _index;

uint256 _indexRange = endIndex - startIndex;
DLCLink.DLC[] memory fundedDLCs = new DLCLink.DLC[](_indexRange);

uint256 _fundedCount = 0;
DLCLink.DLC[] memory dlcSubset = new DLCLink.DLC[](
endIndex - startIndex
);

for (uint256 i = startIndex; i < endIndex; i++) {
if (dlcs[i].status == DLCLink.DLCStatus.FUNDED) {
fundedDLCs[_fundedCount] = dlcs[i];
_fundedCount++;
}
dlcSubset[i - startIndex] = dlcs[i];
}
return fundedDLCs;

return dlcSubset;
}

////////////////////////////////////////////////////////////////
Expand Down
8 changes: 8 additions & 0 deletions contracts/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,12 @@ contract TokenManager is
function unpauseContract() external onlyPauser {
_unpause();
}

function setMinterOnTokenContract(address minter) external onlyDLCAdmin {
dlcBTC.setMinter(minter);
}

function setBurnerOnTokenContract(address burner) external onlyDLCAdmin {
dlcBTC.setBurner(burner);
}
}
9 changes: 7 additions & 2 deletions deploymentFiles/arbsepolia/DLCBTC.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"network": "arbsepolia",
"updatedAt": "2024-04-11T19:21:14.236Z",
"gitSHA": "c0dfd2f",
"updatedAt": "2024-05-03T09:25:49.010Z",
"gitSHA": "4b9a9d3",
"contract": {
"name": "DLCBTC",
"address": "0x057e5597d6D3a0A2507187EcE2b008100A33CE84",
Expand All @@ -10,10 +10,13 @@
"constructor()",
"error BlacklistedRecipient()",
"error BlacklistedSender()",
"error NotAuthorized()",
"event Approval(address indexed owner, address indexed spender, uint256 value)",
"event Blacklisted(address account)",
"event BurnerSet(address burner)",
"event EIP712DomainChanged()",
"event Initialized(uint8 version)",
"event MinterSet(address minter)",
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
"event Transfer(address indexed from, address indexed to, uint256 value)",
"event Unblacklisted(address account)",
Expand All @@ -35,6 +38,8 @@
"function owner() view returns (address)",
"function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)",
"function renounceOwnership()",
"function setBurner(address burner)",
"function setMinter(address minter)",
"function symbol() view returns (string)",
"function totalSupply() view returns (uint256)",
"function transfer(address to, uint256 amount) returns (bool)",
Expand Down
6 changes: 3 additions & 3 deletions deploymentFiles/arbsepolia/DLCManager.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"network": "arbsepolia",
"updatedAt": "2024-04-11T19:21:01.315Z",
"gitSHA": "c0dfd2f",
"updatedAt": "2024-05-03T09:25:14.927Z",
"gitSHA": "4b9a9d3",
"contract": {
"name": "DLCManager",
"address": "0x334D9890b339A1B2e0f592F26b5374e22aFdfbDf",
Expand Down Expand Up @@ -55,9 +55,9 @@
"function defaultAdminDelayIncreaseWait() view returns (uint48)",
"function dlcIDsByUUID(bytes32) view returns (uint256)",
"function dlcs(uint256) view returns (bytes32 uuid, address protocolContract, uint256 timestamp, uint256 valueLocked, address creator, uint8 status, string fundingTxId, string closingTxId, string btcFeeRecipient, uint256 btcMintFeeBasisPoints, uint256 btcRedeemFeeBasisPoints, string taprootPubKey)",
"function getAllDLCs(uint256 startIndex, uint256 endIndex) view returns (tuple(bytes32 uuid, address protocolContract, uint256 timestamp, uint256 valueLocked, address creator, uint8 status, string fundingTxId, string closingTxId, string btcFeeRecipient, uint256 btcMintFeeBasisPoints, uint256 btcRedeemFeeBasisPoints, string taprootPubKey)[])",
"function getDLC(bytes32 uuid) view returns (tuple(bytes32 uuid, address protocolContract, uint256 timestamp, uint256 valueLocked, address creator, uint8 status, string fundingTxId, string closingTxId, string btcFeeRecipient, uint256 btcMintFeeBasisPoints, uint256 btcRedeemFeeBasisPoints, string taprootPubKey))",
"function getDLCByIndex(uint256 index) view returns (tuple(bytes32 uuid, address protocolContract, uint256 timestamp, uint256 valueLocked, address creator, uint8 status, string fundingTxId, string closingTxId, string btcFeeRecipient, uint256 btcMintFeeBasisPoints, uint256 btcRedeemFeeBasisPoints, string taprootPubKey))",
"function getFundedDLCs(uint256 startIndex, uint256 endIndex) view returns (tuple(bytes32 uuid, address protocolContract, uint256 timestamp, uint256 valueLocked, address creator, uint8 status, string fundingTxId, string closingTxId, string btcFeeRecipient, uint256 btcMintFeeBasisPoints, uint256 btcRedeemFeeBasisPoints, string taprootPubKey)[])",
"function getMinimumThreshold() view returns (uint16)",
"function getRoleAdmin(bytes32 role) view returns (bytes32)",
"function getSignerCount() view returns (uint16)",
Expand Down
6 changes: 4 additions & 2 deletions deploymentFiles/arbsepolia/TokenManager.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"network": "arbsepolia",
"updatedAt": "2024-04-11T19:21:24.849Z",
"gitSHA": "c0dfd2f",
"updatedAt": "2024-05-03T09:26:18.250Z",
"gitSHA": "4b9a9d3",
"contract": {
"name": "TokenManager",
"address": "0xE36502FB5F95702E4409957d0B0B7f8B37712Dc9",
Expand Down Expand Up @@ -82,8 +82,10 @@
"function setBtcFeeRecipient(string btcFeeRecipientToSet)",
"function setBtcMintFeeRate(uint256 newBtcMintFeeRate)",
"function setBtcRedeemFeeRate(uint256 newBtcRedeemFeeRate)",
"function setBurnerOnTokenContract(address burner)",
"function setMaximumDeposit(uint256 newMaximumDeposit)",
"function setMinimumDeposit(uint256 newMinimumDeposit)",
"function setMinterOnTokenContract(address minter)",
"function setStatusFunded(bytes32 uuid, string btcTxId)",
"function setWhitelistingEnabled(bool isWhitelistingEnabled)",
"function setupVault(uint256 btcDeposit) returns (bytes32)",
Expand Down
34 changes: 33 additions & 1 deletion scripts/50_contract-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module.exports = async function contractAdmin() {
description: 'Deploy contracts',
value: 'deploy',
},
{ title: 'Verify Contract', value: 'verify' },
{ title: 'Verify Contract On Etherscan', value: 'verify' },
{ title: 'Validate an Upgrade', value: 'validate-upgrade' },
{ title: 'Upgrade Proxy Implementation', value: 'upgrade' },
{
title: 'Transfer DLCBTC Ownership',
Expand Down Expand Up @@ -154,6 +155,37 @@ module.exports = async function contractAdmin() {

break;
}
case 'validate-upgrade': {
const contractSelectPrompt = await prompts({
type: 'select',
name: 'contracts',
message: `Select contract to upgrade on ${network}`,
choices: contractConfigs
.filter((config) => config.upgradeable)
.map((config) => ({
title: `${config.name}`,
value: config.name,
})),
});
await hardhat.run('compile');
const contractName = contractSelectPrompt.contracts;
const proxyAddress = await loadContractAddress(
contractName,
network
);
const newImplementation =
await hardhat.ethers.getContractFactory(contractName);
const validation = await hardhat.upgrades.validateUpgrade(
proxyAddress,
newImplementation
);
if (!validation) {
console.log('Upgrade is valid');
return;
}
console.log(validation);
break;
}
case 'upgrade': {
const contractSelectPrompt = await prompts({
type: 'select',
Expand Down
8 changes: 4 additions & 4 deletions test/DLCBTC.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ describe('DLCBTC', function () {
it('should revert on unauthorized mint', async () => {
await expect(
dlcBtc.connect(user).mint(user.address, deposit)
).to.be.revertedWith('Ownable: caller is not the owner');
).to.be.revertedWithCustomError(dlcBtc, 'NotAuthorized');
});

it('should revert on unauthorized burn', async () => {
await expect(
dlcBtc.connect(user).burn(user.address, deposit)
).to.be.revertedWith('Ownable: caller is not the owner');
).to.be.revertedWithCustomError(dlcBtc, 'NotAuthorized');
});

it('owner can mint tokens', async () => {
Expand All @@ -109,13 +109,13 @@ describe('DLCBTC', function () {
it('should revert on mint called by previous owner', async () => {
await expect(
dlcBtc.connect(deployer).mint(user.address, deposit)
).to.be.revertedWith('Ownable: caller is not the owner');
).to.be.revertedWithCustomError(dlcBtc, 'NotAuthorized');
});

it('should revert on burn called by previous owner', async () => {
await expect(
dlcBtc.connect(deployer).burn(user.address, deposit)
).to.be.revertedWith('Ownable: caller is not the owner');
).to.be.revertedWithCustomError(dlcBtc, 'NotAuthorized');
});

it('TokenManager can mint tokens', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/DLCManagerProxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function whitelistProtocolContractAndAddress(dlcManager, mockProtocol) {
const mockUUID =
'0x96eecb386fb10e82f510aaf3e2b99f52f8dcba03f9e0521f7551b367d8ad4967';

describe('DLCManager Proxy', function () {
xdescribe('DLCManager Proxy', function () {
let dlcManager, mockProtocol;
let tokenManager, dlcBtc;
let accounts, deployer, protocol, user, randomAccount, anotherAccount;
Expand Down

0 comments on commit 3e041b2

Please sign in to comment.