Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payment contract functions - deploy and show #91

Merged
merged 3 commits into from
Feb 23, 2023
Merged

Conversation

elv-serban
Copy link
Contributor

As a tenant, create a payment contract for revenue splits.

At creation - specify the list of stakeholders: an array of addresses and a corresponding array of shares.
Shares are integers and represent proportions so they don't need to, for example, add up to 100 (but they can, for simplicity).

Examples:

Create a payment contract

./elv-live payment_contract_create 0xc05e0274158442b7d595e5ac6d483d18df8fc93e,0x165b828643eb0fa8a7c6b15330670106169941cc 80,20
Deploy new payment contract

contract_address: '0xcd6c150e4da4a22cdc3d128f4024e039234d6b59'
shares: 100

Show status of payment contract and stakeholders

./elv-live payment_contract_show 0xcd6c150e4da4a22cdc3d128f4024e039234d6b59 0x4c6C3547f81Ef23ED6e6562ab05a598DDdDd140d
Show payment contract status

contract_address: '0xcd6c150e4da4a22cdc3d128f4024e039234d6b59'
shares: 100
released: 0
payees:
  '0xC05e0274158442B7d595E5AC6D483d18DF8fc93e':
    shares: 80
    released:
      _hex: '0x00'
  '0x165B828643eB0fA8A7C6b15330670106169941cc':
    shares: 20
    released:
      _hex: '0x00'

Follow up items (can be done as separate PRs)

  • figure out how to call the payment 'releasable' function (currently fails)
  • could refine the 'show' output to represent the values with 'decimals' instead of big ints

@elv-preethi
Copy link
Contributor

releasable method was overloaded function.
Followed fix from here:
ethers-io/ethers.js#407
and made formatArguments false. It seems to work now.

./elv-live payment_contract_show 0xcd6c150e4da4a22cdc3d128f4024e039234d6b59 0x4c6C3547f81Ef23ED6e6562ab05a598DDdDd140d
Show payment contract status

contract_address: '0xcd6c150e4da4a22cdc3d128f4024e039234d6b59'
shares: 100
released: 0
payees:
  '0xC05e0274158442B7d595E5AC6D483d18DF8fc93e':
    shares: 80
    released: 0
    releasable: 0
  '0x165B828643eB0fA8A7C6b15330670106169941cc':
    shares: 20
    released: 0
    releasable: 0

@elv-serban

Copy link
Contributor Author

@elv-serban elv-serban left a comment

Choose a reason for hiding this comment

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

Great find!

Copy link
Contributor

@elv-wayne elv-wayne left a comment

Choose a reason for hiding this comment

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

Looks good, other than allowing shares to be non integer strings. Not sure how much input validation do we need on these contracts

* @param {string} addresses : list of stakeholder addresses
* @param {string} shares: list of stakeholder shares, in the order of addresses
*/
async PaymentDeploy({ addresses, shares }){
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the contract check for bad share values?

Copy link
Contributor

Choose a reason for hiding this comment

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

These are the checks done in constructor:

require(payees.length == shares_.length, "PaymentSplitter: payees and shares length mismatch");
require(payees.length > 0, "PaymentSplitter: no payees");


require(account != address(0), "PaymentSplitter: account is the zero address");
require(shares_ > 0, "PaymentSplitter: shares are 0");
require(_shares[account] == 0, "PaymentSplitter: account already has shares");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added validation for addresses and shares (integers)

@elv-serban elv-serban merged commit 0cf94f6 into main Feb 23, 2023
@elv-serban elv-serban deleted the payment branch February 23, 2023 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants