-
Notifications
You must be signed in to change notification settings - Fork 23
Add extension that emits erc20 events for etherscan visibility #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
arr00
wants to merge
6
commits into
master
Choose a base branch
from
feat/emit-erc20-events
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
937b24e
Add extension that emits erc20 events for etherscan visibility
arr00 6ed57a3
change contract name and emit non-zero amount
arr00 e9268c7
fix
arr00 4ee8ea1
update amount
arr00 ab43829
Add test
arr00 9b30819
add changelog
arr00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
--- | ||
'openzeppelin-confidential-contracts': minor | ||
--- | ||
|
||
`ConfidentialFungibleTokenERC20Events`: Extension of `ConfidentialFungibleToken` that emits ERC20 events on transfers. |
17 changes: 17 additions & 0 deletions
17
contracts/mocks/ConfidentialFungibleTokenERC20EventsMock.sol
This file contains hidden or 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,17 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {SepoliaConfig} from "@fhevm/solidity/config/ZamaConfig.sol"; | ||
import {FHE, euint64, externalEuint64} from "@fhevm/solidity/lib/FHE.sol"; | ||
import {ConfidentialFungibleTokenERC20Events} from "./../token/extensions/ConfidentialFungibleTokenERC20Events.sol"; | ||
|
||
// solhint-disable func-name-mixedcase | ||
abstract contract ConfidentialFungibleTokenERC20EventsMock is ConfidentialFungibleTokenERC20Events, SepoliaConfig { | ||
function $_mint( | ||
address to, | ||
externalEuint64 encryptedAmount, | ||
bytes calldata inputProof | ||
) public returns (euint64 transferred) { | ||
return _mint(to, FHE.fromExternal(encryptedAmount, inputProof)); | ||
} | ||
} |
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
contracts/token/extensions/ConfidentialFungibleTokenERC20Events.sol
This file contains hidden or 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,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {ConfidentialFungibleToken, euint64} from "../ConfidentialFungibleToken.sol"; | ||
|
||
/** | ||
* @dev Extension of `ConfidentialFungibleToken` that emits ERC20 events on transfers. This | ||
* can be useful for surfacing confidential transfers on applications that support ERC20 events such as Etherscan. | ||
* | ||
* NOTE: The ERC20 events emitted only have meaningful data for the `to` and `from` fields. The `amount` field | ||
* is fixed to 1. | ||
*/ | ||
abstract contract ConfidentialFungibleTokenERC20Events is ConfidentialFungibleToken { | ||
function _update(address from, address to, euint64 amount) internal virtual override returns (euint64) { | ||
emit IERC20.Transfer(from, to, 1); | ||
return super._update(from, to, amount); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
test/token/extensions/ConfidentialFungibleTokenERC20Events.test.ts
This file contains hidden or 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,31 @@ | ||
import { expect } from 'chai'; | ||
import { ethers, fhevm } from 'hardhat'; | ||
|
||
const name = 'ConfidentialFungibleToken'; | ||
const symbol = 'CFT'; | ||
const uri = 'https://example.com/metadata'; | ||
|
||
describe('ConfidentialFungibleTokenERC20Events', function () { | ||
beforeEach(async function () { | ||
const [holder] = await ethers.getSigners(); | ||
|
||
const token = await ethers.deployContract('$ConfidentialFungibleTokenERC20EventsMock', [name, symbol, uri]); | ||
this.token = token; | ||
this.holder = holder; | ||
}); | ||
|
||
it('should emit ERC20 transfer event', async function () { | ||
const encryptedInput = await fhevm | ||
.createEncryptedInput(this.token.target, this.holder.address) | ||
.add64(100) | ||
.encrypt(); | ||
|
||
await expect( | ||
this.token | ||
.connect(this.holder) | ||
['$_mint(address,bytes32,bytes)'](this.holder, encryptedInput.handles[0], encryptedInput.inputProof), | ||
) | ||
.to.emit(this.token, 'Transfer') | ||
.withArgs(ethers.ZeroAddress, this.holder.address, 1); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to use 1 over something else ? I'd personally use 0. That way the arithmetics of inbound - outbound would always be 0, and can never go negative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 value transfers are automatically hidden by Etherscan. Tried that first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, thank you for this test.
Considering what you say, I feel adding
Transfer
events (with this dummy value of 1), might not be the best path for being compatible with Etherscan (since it looks a bit twisted).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't disagree but without any dedicated support from etherescan this is likely the only way. We could do something with ERC1155 or ERC721 too but I feel like that isn't desirable.