This repository has been archived by the owner on Feb 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Airdrop Contract #49
Merged
Merged
Airdrop Contract #49
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5315d1e
contracts: proposal for Workers.sol to manage active workers
benjaminbollen 93c1933
contracts: (incomplete) proposal for Airdrop
benjaminbollen 4b9d49f
contracts: change return value to total paid for pay()
benjaminbollen 2cea8c7
Merge remote-tracking branch 'remotes/origin/ben/gh6/airdrop' into ai…
ab90149
Merge remote-tracking branch 'remotes/origin/develop' into airdrop
33342ef
rebased with develop
69c1a03
Airdrop Contract Changes
870649c
PR Review Changes
7059b15
Contracts: comment/uncomment for beneficiary validation modifier.
d45e084
Enabling Airdrop modifier for banks to test
340baa4
Requested PR Review Changes
69c7bbb
Added _currency in AirdropPayment event
380c39c
Added tokenAmount and commissionTokenAmount in Payment and AirdropPay…
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 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,167 @@ | ||
/* solhint-disable-next-line compiler-fixed */ | ||
pragma solidity ^0.4.17; | ||
|
||
// Copyright 2018 OpenST Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// Utility chain: Airdrop | ||
// | ||
// http://www.simpletoken.org/ | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
import "./Workers.sol"; | ||
import "./Pricer.sol"; | ||
|
||
|
||
contract Airdrop is Pricer { | ||
|
||
/* | ||
* Events | ||
*/ | ||
/// Emit AirdropPayment Event | ||
event AirdropPayment( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the event |
||
address indexed _beneficiary, | ||
uint256 _transferAmount, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: for alignment with |
||
address indexed _commissionBeneficiary, | ||
uint256 _commissionAmount, | ||
uint256 _actualPricePoint, | ||
address indexed _spender, | ||
uint256 _airdropAmount | ||
); | ||
|
||
/* | ||
* Storage | ||
*/ | ||
Workers public workers; | ||
address public airdropBudgetHolder; | ||
|
||
/* | ||
* Constructor | ||
*/ | ||
/// @dev Takes _brandedToken, _baseCurrency, _workers, _airdropBudgetHolder; | ||
/// constructor; | ||
/// public method; | ||
/// @param _brandedToken Branded Token | ||
/// @param _baseCurrency Base Currency | ||
/// @param _workers Workers contract address | ||
/// @param _airdropBudgetHolder Airdrop Budget Holder Address | ||
function Airdrop( | ||
address _brandedToken, | ||
bytes3 _baseCurrency, | ||
Workers _workers, | ||
address _airdropBudgetHolder) | ||
public | ||
Pricer(_brandedToken, _baseCurrency) | ||
OpsManaged() | ||
{ | ||
require(_workers != address(0)); | ||
require(airdropBudgetHolder != address(0)); | ||
|
||
workers = _workers; | ||
airdropBudgetHolder = _airdropBudgetHolder; | ||
} | ||
|
||
/* | ||
* External functions | ||
*/ | ||
/// payAirdrop matches the behaviour of Pricer:pay with extra functionality of airdrop evaluation | ||
/// @param _beneficiary beneficiary | ||
/// @param _transferAmount transferAmount | ||
/// @param _commissionBeneficiary commissionBeneficiary | ||
/// @param _commissionAmount commissionAmount | ||
/// @param _currency currency | ||
/// @param _intendedPricePoint intendedPricePoint | ||
/// @param _spender spender | ||
/// @param _airdropAmount airdropAmount | ||
/// @return uint256 totalPaid | ||
function payAirdrop( | ||
address _beneficiary, | ||
uint256 _transferAmount, | ||
address _commissionBeneficiary, | ||
uint256 _commissionAmount, | ||
bytes3 _currency, | ||
uint256 _intendedPricePoint, | ||
address _spender, | ||
uint256 _airdropAmount) | ||
public | ||
returns ( | ||
uint256 /* totalPaid */) | ||
{ | ||
require(workers.isWorker(msg.sender)); | ||
require(_spender != address(0)); | ||
|
||
require(isValidBeneficiaryData(_beneficiary, _transferAmount, | ||
_commissionBeneficiary, _commissionAmount)); | ||
|
||
uint256 tokenAmount = _transferAmount; | ||
uint256 commissionTokenAmount = _commissionAmount; | ||
uint256 pricePoint = _intendedPricePoint; | ||
|
||
// check Margin And Calculate BTAmount | ||
if (_currency != "") { | ||
(pricePoint, tokenAmount, commissionTokenAmount) = validateMarginAndCalculateBTAmount(_currency, | ||
_intendedPricePoint, _transferAmount, _commissionAmount); | ||
} | ||
|
||
require(performAirdropTransferToSpender(_spender, _airdropAmount, | ||
tokenAmount, commissionTokenAmount)); | ||
require(performTransfers(_spender, _beneficiary, tokenAmount, | ||
_commissionBeneficiary, commissionTokenAmount)); | ||
|
||
/// Emit AirdropPayment Event | ||
AirdropPayment(_beneficiary, _transferAmount, _commissionBeneficiary, | ||
_commissionAmount, pricePoint, _spender, _airdropAmount); | ||
|
||
return ((tokenAmount + commissionTokenAmount)); | ||
} | ||
|
||
/* | ||
* Private functions | ||
*/ | ||
/// @dev Takes _spender, _airdropAmount, _tokenAmount, _commissionTokenAmount; | ||
/// Calculate airdropUsed to transfer | ||
/// Perform perform Airdrop Transfer To Spender | ||
/// internal method; | ||
/// @param _spender spenderUser | ||
/// @param _airdropAmount airdropAmount | ||
/// @param _tokenAmount tokenAmount | ||
/// @param _commissionTokenAmount commissionTokenAmount | ||
/// @return uint256 airdropUsed | ||
function performAirdropTransferToSpender( | ||
address _spender, | ||
uint256 _airdropAmount, | ||
uint256 _tokenAmount, | ||
uint256 _commissionTokenAmount) | ||
private | ||
returns ( | ||
bool /* boolean value */) | ||
{ | ||
uint256 totalPaid = (_tokenAmount + _commissionTokenAmount); | ||
// Find out minimum of totalPaid and _airdropAmount | ||
uint256 airdropUsed = _airdropAmount; | ||
if (totalPaid < airdropUsed) { | ||
airdropUsed = totalPaid; | ||
} | ||
|
||
// Prefund the user from the airdrop budget holder | ||
if (airdropUsed > 0) { | ||
require(EIP20Interface(brandedToken()).transferFrom(airdropBudgetHolder, _spender, airdropUsed)); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
up to three arguments can be
indexed
and it makes them (expanded and) searchable in the logs; also for formatting on events we've previously filled the line (different from function signatures)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.
Indexing is cool. Does indexing cost extra gas or it's neglegible?
Can we do indexing on uint256 also?
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.
also for formatting on events we've previously filled the line (different from function signatures)
Didn't understand this point. Please explain with an example?
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.
@benjaminbollen: for consistency/ease, we started declaring events similar to functions,
This way it not subject to personal preference in terms of how many is too many arguments to list on the line. We can go back to the other way, if preferred, but that will mean changes in other rule for max number of arguments per line (so that how it looks in an individual dev's editor is not driving the decision).