https://github.com/useverto/tippar
Recursive method to choose which profit-sharing token holder receives a tip.
https://github.com/useverto/tippar
arweave profit-sharing pst tip token
Last synced: over 1 year ago
JSON representation
Recursive method to choose which profit-sharing token holder receives a tip.
- Host: GitHub
- URL: https://github.com/useverto/tippar
- Owner: useverto
- License: mit
- Created: 2021-01-14T21:11:22.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-15T05:59:07.000Z (over 5 years ago)
- Last Synced: 2025-02-14T07:17:56.822Z (over 1 year ago)
- Topics: arweave, profit-sharing, pst, tip, token
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@verto/tippar
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```shell script
yarn add @verto/tippar
```
#### `chooseRecipient`
```js
async function chooseRecipient(client: Arweave, contract: string, mode?: string): Promise
```
- `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:**
```js
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.