Coder Social home page Coder Social logo

useverto / tippar Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 22 KB

Recursive method to choose which profit-sharing token holder receives a tip.

Home Page: https://www.npmjs.com/package/@verto/tippar

License: MIT License

JavaScript 13.52% TypeScript 86.48%
arweave pst profit-sharing token tip

tippar's Introduction

Tippar

A simple library to select which PST token holder receives a tip. With the addition of SmartWeave contracts being able to custody different types of PSTs, there now needs to be a way for tips to be distributed to contracts in addition to wallets.

How it works

Tippar chooses token holders from contract(s) in recursion until a wallet is selected. Take note of the following examples:

A tip needs to be given to a token holder in Contract A

Tippar Process:

select holder from contract (A)
if holder === contract (B)
  select new holder from contract (B)
  if new holder === wallet
    return new holder
  else
    ...continue recursion

Real-World Example:

An ArDrive user is sending a tip to an ArDrive holder. If the random token-holder selected to receive the tip is the Verto Contract, a new token-holder is calculated from the users who hold a balance of VRT. This means that the ArDrive tip will now be sent to the VRT token holder.

Usage

yarn add @verto/tippar

chooseRecipient

async function chooseRecipient(client: Arweave, contract: string, mode?: string): Promise<string>
  • client: Arweave client instance
  • contract: Profit-Sharing token contract to choose holder from
  • mode?: Optional parameter for setting type of selection
    • "weightedRandom": Select token holder based on a weighted-random
    • "greatest": Select token holder from the the greatest balance
    • Defaults to "weightedRandom"

Example:

import { chooseRecipient } from "@verto/tippar;

async function someUserInteraction() {
  ...
  const tipReceiver = await chooseRecipient(arweaveClient, pstContract);
  console.log(`Wallet of tip receiver: ${tipReceiver}`);
  ...
}

Contributing

Any and all contributions are welcome. Feel free to make a PR with any updates for fixes.

tippar's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.