Last active
April 13, 2023 19:34
-
-
Save maheshmurthy/cc352f8546f48855ca9efa907145c6e7 to your computer and use it in GitHub Desktop.
Revisions
-
maheshmurthy revised this gist
Apr 13, 2023 . 1 changed file with 2 additions and 2 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -35,15 +35,15 @@ contract DelegateRegistry { emit DelegateAdded(msg.sender, _tokenAddress, _tokenChainId, _metadata); } function removeDelegate() public { address delegateAddress = msg.sender; Delegate memory removedDelegate = delegates[delegateAddress][delegateAddress][0]; delete delegates[delegateAddress][removedDelegate.tokenAddress][removedDelegate.tokenChainId]; emit DelegateRemoved(removedDelegate.delegateAddress); } function updateDelegateMetadata(address _tokenAddress, uint256 _chainId, bytes memory _metadata) public { Delegate storage delegateToUpdate = delegates[msg.sender][_tokenAddress][_chainId]; require(delegateToUpdate.delegateAddress == msg.sender, "Delegate does not exist for this address, token address, and chain ID"); -
maheshmurthy revised this gist
Apr 10, 2023 . 1 changed file with 11 additions and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,7 @@ contract DelegateRegistry { event DelegateAdded(address indexed delegateAddress, address tokenAddress, uint256 tokenChainId); event DelegateRemoved(address indexed delegateAddress); event DelegateMetadataUpdated(address indexed delegateAddress, address tokenAddress, uint256 chainId, bytes metadata); constructor() { owner = msg.sender; @@ -41,6 +42,16 @@ contract DelegateRegistry { emit DelegateRemoved(removedDelegate.delegateAddress); } function updateDelegateMetadata(address _tokenAddress, uint256 _chainId, bytes memory _metadata) public onlyDelegate { Delegate storage delegateToUpdate = delegates[msg.sender][_tokenAddress][_chainId]; require(delegateToUpdate.delegateAddress == msg.sender, "Delegate does not exist for this address, token address, and chain ID"); delegateToUpdate.metadata = _metadata; emit DelegateMetadataUpdated(msg.sender, _tokenAddress, _chainId, _metadata); } function getDelegate(address _delegateAddress, address _tokenAddress, uint256 _tokenChainId) public view returns (Delegate memory) { return delegates[_delegateAddress][_tokenAddress][_tokenChainId]; -
maheshmurthy revised this gist
Apr 10, 2023 . 1 changed file with 10 additions and 12 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -5,47 +5,45 @@ contract DelegateRegistry { struct Delegate { address delegateAddress; address tokenAddress; uint256 tokenChainId; } mapping(address => mapping(address => mapping(uint256 => Delegate))) public delegates; address public owner; event DelegateAdded(address indexed delegateAddress, address tokenAddress, uint256 tokenChainId); event DelegateRemoved(address indexed delegateAddress); constructor() { owner = msg.sender; } function addDelegate(address _tokenAddress, uint256 _tokenChainId, bytes memory _metadata) public { Delegate memory newDelegate = Delegate({ delegateAddress: msg.sender, tokenAddress: _tokenAddress, tokenChainId: _tokenChainId, }); require(delegates[msg.sender][_tokenAddress][_tokenChainId].delegateAddress == address(0), "Delegate already exists for this address, token address, and chain ID"); delegates[msg.sender][_tokenAddress][_tokenChainId] = newDelegate; emit DelegateAdded(msg.sender, _tokenAddress, _tokenChainId, _metadata); } function removeDelegate() public onlyDelegate { address delegateAddress = msg.sender; Delegate memory removedDelegate = delegates[delegateAddress][delegateAddress][0]; delete delegates[delegateAddress][removedDelegate.tokenAddress][removedDelegate.tokenChainId]; emit DelegateRemoved(removedDelegate.delegateAddress); } function getDelegate(address _delegateAddress, address _tokenAddress, uint256 _tokenChainId) public view returns (Delegate memory) { return delegates[_delegateAddress][_tokenAddress][_tokenChainId]; } } -
maheshmurthy created this gist
Apr 10, 2023 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract DelegateRegistry { struct Delegate { address delegateAddress; address tokenAddress; uint256 chainId; bytes metadata; // with predefined schema } mapping(address => mapping(address => mapping(uint256 => Delegate))) public delegates; address public owner; event DelegateAdded(address indexed delegateAddress, address tokenAddress, uint256 chainId); event DelegateRemoved(address indexed delegateAddress); constructor() { owner = msg.sender; } function addDelegate(address _tokenAddress, uint256 _chainId, bytes memory _metadata) public { Delegate memory newDelegate = Delegate({ delegateAddress: msg.sender, tokenAddress: _tokenAddress, chainId: _chainId, metadata: _metadata }); require(delegates[msg.sender][_tokenAddress][_chainId].delegateAddress == address(0), "Delegate already exists for this address, token address, and chain ID"); delegates[msg.sender][_tokenAddress][_chainId] = newDelegate; emit DelegateAdded(msg.sender, _tokenAddress, _chainId); } function removeDelegate() public onlyDelegate { address delegateAddress = msg.sender; Delegate memory removedDelegate = delegates[delegateAddress][delegateAddress][0]; delete delegates[delegateAddress][removedDelegate.tokenAddress][removedDelegate.chainId]; emit DelegateRemoved(removedDelegate.delegateAddress); } function getDelegate(address _delegateAddress, address _tokenAddress, uint256 _chainId) public view returns (Delegate memory) { return delegates[_delegateAddress][_tokenAddress][_chainId]; } }