Skip to content
This repository has been archived by the owner on Feb 6, 2019. It is now read-only.

Airdrop Contract #49

Merged
merged 13 commits into from
Feb 17, 2018
Merged

Airdrop Contract #49

merged 13 commits into from
Feb 17, 2018

Conversation

abhayks1
Copy link
Contributor

  • Pricer Contract Refactoring
  • Airdrop Contract Changes
  • PricerInterface Contract Changes

Flow

  • msg.sender will be worker address
  • airdropBudgetHolder will hold total airdrop amount
  • performAirdropTransferToSpender => Approves that contract can transfer on behalf of airdropBudgetHolder
  • [ ]performTransfer => approves that contract on behalf of user can do transfer to beneficiary and
    commission beneficiary
  • Airdrop.sol line no 165 => Can't we transfer all _airdropAmount to _spender?

Copy link
Contributor

@benjaminbollen benjaminbollen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please already review comments, and we'll discuss more tomorrow during the call

@@ -4,6 +4,7 @@
"description": "",
"dependencies": {
"@openstfoundation/openst-notification": "1.0.0-beta.1",
"@ostdotcom/ost-price-oracle": "^1.0.0-beta.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openst-payments cannot have a dependency on ostdotcom/ost-price-oracle; we outlined the tasks for there to be a price oracle interface defined in openst-payments, and for testing we want a PriceOracleMock that fills that interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per discussion we will take in a different ticket.

* External functions
*/
/// clean up or revoke airdrop contract
function remove()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the remove function not be implemented in Pricer.sol, and can be inherited here without change.

external
onlyAdminOrOps
{
selfdestruct(msg.sender);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an event before self-destruct is useful

Copy link
Contributor Author

@abhayks1 abhayks1 Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding event "Removed"

import "./Pricer.sol";


contract Airdrop is Pricer, Workers {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Airdrop is not Workers

/*
* External functions
*/
/// performPay matches the behaviour of Pricer:pay with extra functionality of airdrop evaluation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performPay is not a suitable name;
least preferred, performAirPay on Airdrop; and performPay on Pricer; but we dont prefix with perform for core external function calls

so airdropPay on Airdrop; and pay on pricer;
or payAirdrop on Airdrop; and pay on pricer;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payAirdrop on Airdrop; and pay on pricer;
Sounds good.

* Events
*/
/// Event for AirdropPayment complete
event AirdropPayment(
Copy link
Contributor

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)

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Contributor

@jasonklein jasonklein Feb 15, 2018

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,

event EventName(
arg,
arg,
arg)

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).

@@ -1,3 +1,4 @@
/* solhint-disable-next-line compiler-fixed */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for PricerINterface.sol, please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we concluded we will keep it.


uint256 tokenAmount;
uint256 commissionTokenAmount;
(tokenAmount, commissionTokenAmount) = getBTAmountFromCurrencyValue(pricePoint, _transferAmount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function call to getBTAmountFromCurrencyValue should be inlined (as demonstrated that it calls again for getPricePoint; and the function itself on L221 should be removed;

the functionality of having this function (L221) public is achievable in the interaction layer by using getPricePoint;

Copy link
Contributor Author

@abhayks1 abhayks1 Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we concluded getPricePoint is called once in pay and payAirdrop flow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correction, getBTAmountFromCurrencyValue does not query getPricePoint; there is still value in looking to inline this function to reduce the stack depth;

in return getPricePointandCalculateAmounts can be moved to the interaction layer

Copy link
Contributor

@jasonklein jasonklein Feb 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjaminbollen: are you noting this for posterity or commenting that this is a change you would like Abhay to make for this PR (which I think contradicts what we agreed in the meeting)? And does this relate to #50?

_commissionAmount, _currency, _intendedPricePoint, pricePoint);
return true;
_commissionAmount, _currency, _intendedPricePoint, pricePoint);
return (tokenAmount + commissionTokenAmount);
}

/// @dev Takes _currency;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPricePoint needs to be a public view function; this produces a warning because Price Oracle can emit an event; but the conclusion is then to remove the event emission from getPrice in Price Oracle; this should also be be specified in the Price Oracle interface

again, the interaction layer can determine that there was no valid price point based on the return value, and an event on the get function is not needed

@@ -1,3 +1,4 @@
/* solhint-disable-next-line compiler-fixed */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on L34: Pricer is not PricerInterface; the dependency direction is reversed; pricer calls on contracts, for now other contracts dont call on pricer; neither is there anything general about pricer worthy of generalising in an interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we concluded we will keep PricerInterface.sol

/// @param _commissionBeneficiary commissionBeneficiary
/// @param _commissionAmount commissionAmount
/// @return bool isValid
function isValidBeneficiaryData(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is ideal to put as up in Pricer.sol as a modifier

/// @param _commissionBeneficiary commissionBeneficiary
/// @param _commissionTokenAmount commissionTokenAmount
/// @return (bool)
function performTransfer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to performTransfers

@abhayks1
Copy link
Contributor Author

@benjaminbollen Done with requested changes. Few points:

  • Airdrop.sol => https://github.com/OpenSTFoundation/openst-payments/blob/ben/gh6/airdrop/contracts/Airdrop.sol
    line no 155. Do we need this? Can't we transfer all _airdropAmount to _spender?

  • Making isValidBeneficiaryData modifier gives below error on airdrop contract compiling:
    ./contracts/Airdrop.sol:114:38: Compiler error: Stack too deep, try removing local variables.
    _intendedPricePoint, _transferAmount, _commissionAmount);
    Your thoughts?

  • "also for formatting on events we've previously filled the line (different from function signatures)"
    I didn't understand this point. Please explain with an example?

Copy link
Contributor

@benjaminbollen benjaminbollen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


/*
* Events
*/
/// Event for AirdropPayment complete
/// Emit AirdropPayment Event
event AirdropPayment(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the event AirdropPayment is missing the quote currency; worth adding if we have the price point?

address _commissionBeneficiary,
uint256 commissionTokenAmount,
address indexed _beneficiary,
uint256 _transferAmount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: for alignment with Payment event from tokenAmount to transferAmount; we can take input from Saas what the best set of return values;

onlyAdminOrOps
{
selfdestruct(msg.sender);
Removed(msg.sender);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the event before the selfdestruct; or does solidity change the order of execution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense,
Since the contract is killed off and there is no one/nothing left to return after destroyed. It obliterated the next step.

…ment event

Fire event before calling self destruct
Copy link
Contributor

@benjaminbollen benjaminbollen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@benjaminbollen benjaminbollen merged commit bc4a0d6 into develop Feb 17, 2018
@abhayks1 abhayks1 deleted the airdrop branch March 22, 2018 11:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants