diff --git a/contracts/AirDrop.sol b/contracts/AirDrop.sol index 8678c088..80c49680 100644 --- a/contracts/AirDrop.sol +++ b/contracts/AirDrop.sol @@ -3,15 +3,17 @@ pragma solidity 0.6.4; import "./interface/IBEP20.sol"; import "./interface/ITokenHub.sol"; import "./interface/IAirDrop.sol"; +import "./interface/IParamSubscriber.sol"; import "./lib/SafeMath.sol"; +import "./lib/BytesToTypes.sol"; import "./System.sol"; import "./MerkleProof.sol"; -contract AirDrop is IAirDrop, System { +contract AirDrop is IAirDrop, IParamSubscriber, System { using SafeMath for uint256; string public constant sourceChainID = "Binance-Chain-Tigris"; // TODO: replace with the real chain id - address public constant approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address + address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root // This is a packed array of booleans. @@ -59,7 +61,7 @@ contract AirDrop is IAirDrop, System { emit Claimed(tokenSymbol, msg.sender, amount); } - function _verifySignature(address account, bytes memory ownerSignature, bytes memory approvalSignature, bytes32 extra) private pure { + function _verifySignature(address account, bytes memory ownerSignature, bytes memory approvalSignature, bytes32 extra) private view { // Ensure the account is not the zero address require(account != address(0), "InvalidSignature"); @@ -163,4 +165,16 @@ contract AirDrop is IAirDrop, System { } return string(converted); } + + /*********************** Param update ********************************/ + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ + if (Memory.compareStrings(key,"approvalAddress")) { + require(value.length == 20, "length of approvalAddress mismatch"); + address newApprovalAddress = BytesToTypes.bytesToAddress(20, value); + approvalAddress = newApprovalAddress; + } else { + require(false, "unknown param"); + } + emit paramChange(key,value); + } } \ No newline at end of file diff --git a/contracts/AirDrop.template b/contracts/AirDrop.template index 68c4d7cb..823cb83d 100644 --- a/contracts/AirDrop.template +++ b/contracts/AirDrop.template @@ -3,7 +3,9 @@ pragma solidity 0.6.4; import "./interface/IBEP20.sol"; import "./interface/ITokenHub.sol"; import "./interface/IAirDrop.sol"; +import "./interface/IParamSubscriber.sol"; import "./lib/SafeMath.sol"; +import "./lib/BytesToTypes.sol"; import "./System.sol"; import "./MerkleProof.sol"; @@ -12,19 +14,19 @@ contract AirDrop is IAirDrop, System { {% if network == 'local' %} string public constant sourceChainID = "Binance-Chain-Ganges"; // TODO: replace with the real chain id - address public constant approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address + address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root {% elif network == 'QA' %} string public constant sourceChainID = "Binance-Chain-Ganges"; // TODO: replace with the real chain id - address public constant approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address + address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root {% elif network == 'testnet' %} string public constant sourceChainID = "Binance-Chain-Ganges"; // TODO: replace with the real chain id - address public constant approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address + address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root {% else %} string public constant sourceChainID = "Binance-Chain-Tigris"; // TODO: replace with the real chain id - address public constant approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address + address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root {% endif %} // This is a packed array of booleans. @@ -72,7 +74,7 @@ contract AirDrop is IAirDrop, System { emit Claimed(tokenSymbol, msg.sender, amount); } - function _verifySignature(address account, bytes memory ownerSignature, bytes memory approvalSignature, bytes32 extra) private pure { + function _verifySignature(address account, bytes memory ownerSignature, bytes memory approvalSignature, bytes32 extra) private view { // Ensure the account is not the zero address require(account != address(0), "InvalidSignature"); @@ -176,4 +178,16 @@ contract AirDrop is IAirDrop, System { } return string(converted); } + + /*********************** Param update ********************************/ + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ + if (Memory.compareStrings(key,"approvalAddress")) { + require(value.length == 20, "length of approvalAddress mismatch"); + address newApprovalAddress = BytesToTypes.bytesToAddress(20, value); + approvalAddress = newApprovalAddress; + } else { + require(false, "unknown param"); + } + emit paramChange(key,value); + } } \ No newline at end of file diff --git a/contracts/interface/IAirDrop.sol b/contracts/interface/IAirDrop.sol index 5c18ec76..9f2029d9 100644 --- a/contracts/interface/IAirDrop.sol +++ b/contracts/interface/IAirDrop.sol @@ -12,4 +12,6 @@ interface IAirDrop { bytes32[] calldata merkleProof) external; // This event is triggered whenever a call to #claim succeeds. event Claimed(bytes32 tokenSymbol, address account, uint256 amount); + // This event is triggered whenever a call to #paramChange succeeds. + event paramChange(string key, bytes value); }