Skip to content

Commit

Permalink
feat: approvalAddress updatable
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Sep 28, 2023
1 parent b402a5b commit b714fde
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
20 changes: 17 additions & 3 deletions contracts/AirDrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
}
24 changes: 19 additions & 5 deletions contracts/AirDrop.template
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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.
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions contracts/interface/IAirDrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit b714fde

Please sign in to comment.