Skip to content

Commit

Permalink
Add option to issue tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-CZ committed Nov 27, 2024
1 parent d1726a4 commit 34f4108
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ contract ConstantsManager is Ownable {
// Zero to disable validators deactivation by this metric.
uint64 public minAverageUptime;

// The address of the recipient that receives issued tokens
// as a counterparty to the burnt FTM tokens
address public issuedTokensRecipient;

/**
* @dev Given value is too small
*/
Expand Down Expand Up @@ -177,4 +181,8 @@ contract ConstantsManager is Ownable {
}
minAverageUptime = v;
}

function updateIssuedTokensRecipient(address v) external virtual onlyOwner {
issuedTokensRecipient = v;
}
}
5 changes: 5 additions & 0 deletions contracts/sfc/NodeDriverAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {
driver.setBalance(acc, address(acc).balance + diff);
}

/// Issue tokens as a counterparty to burnt FTM tokens.
function issueTokens(address acc, uint256 diff) external onlySFC {
driver.setBalance(acc, address(acc).balance + diff);
}

/// Upgrade code of given contract by coping it from other deployed contract.
/// Avoids setting code to an external address.
function upgradeCode(address acc, address from) external onlyOwner {
Expand Down
9 changes: 9 additions & 0 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,15 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
_burnFTM(amount);
}

/// Issue tokens to the issued tokens recipient as a counterparty to the burnt FTM tokens.
function issueTokens(uint256 amount) external onlyOwner {
if (c.issuedTokensRecipient() == address(0)) {
revert ZeroAddress();
}
node.issueTokens(c.issuedTokensRecipient(), amount);
totalSupply += amount;
}

/// Update treasury address.
function updateTreasuryAddress(address v) external onlyOwner {
treasuryAddress = v;
Expand Down
24 changes: 24 additions & 0 deletions test/SFC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ describe('SFC', () => {
});
});

describe('Issue tokens', () => {
it('Should revert when not owner', async function () {
await expect(this.sfc.connect(this.user).issueTokens(ethers.parseEther('100'))).to.be.revertedWithCustomError(
this.sfc,
'OwnableUnauthorizedAccount',
);
});

it('Should revert when recipient is not set', async function () {
await expect(this.sfc.connect(this.owner).issueTokens(ethers.parseEther('100'))).to.be.revertedWithCustomError(
this.sfc,
'ZeroAddress',
);
});

it('Should succeed and issue tokens', async function () {
await this.constants.updateIssuedTokensRecipient(this.user);
const supply = await this.sfc.totalSupply();
const amount = ethers.parseEther('100');
await this.sfc.connect(this.owner).issueTokens(amount);
expect(await this.sfc.totalSupply()).to.equal(supply + amount);
});
});

describe('Create validator', () => {
const validatorsFixture = async () => {
const validatorPubKey =
Expand Down

0 comments on commit 34f4108

Please sign in to comment.