Skip to content

Commit

Permalink
Merge pull request #39 from jdogresorg/btns420-indexer
Browse files Browse the repository at this point in the history
v0.14.0 Release
  • Loading branch information
jdogresorg authored May 22, 2024
2 parents 53578fa + 55aa08c commit 742dbd2
Show file tree
Hide file tree
Showing 26 changed files with 1,004 additions and 162 deletions.
3 changes: 2 additions & 1 deletion docs/actions/CALLBACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ This command performs a callback on a `token`.
| --------- | ------ | ----------------------------- |
| `VERSION` | String | Broadcast Format Version |
| `TICK` | String | 1 to 250 characters in length |
| `MEMO` | String | An optional memo to include |

## Formats

### Version `0`
- `VERSION|TICK`
- `VERSION|TICK|MEMO`

## Examples
```
Expand Down
30 changes: 16 additions & 14 deletions docs/actions/DIVIDEND.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@
This command pays a dividend to `token` holders of a `token`.

## PARAMS
| Name | Type | Description |
| --------------- | ------ | ---------------------------------------- |
| `VERSION` | String | Broadcast Format Version |
| `TYPE` | String | Tick type (1=TICK, 2=ASSET) |
| `TICK` | String | Any valid `TICK` or `ASSET` |
| `DIVIDEND_TICK` | String | The `token` that dividends are paid in |
| `AMOUNT` | String | Amount of `tokens` to pay out per `UNIT` |
| Name | Type | Description |
| --------------- | ------ | --------------------------------------- |
| `VERSION` | String | Broadcast Format Version |
| `TICK` | String | 1 to 250 characters in length |
| `DIVIDEND_TICK` | String | The `token` that dividends are paid in |
| `AMOUNT` | String | Amount of `token` to pay out per `UNIT` |
| `MEMO` | String | An optional memo to include |

## Formats

### Version `0`
- `VERSION|TYPE|TICK|DIVIDEND_TICK|AMOUNT`
- `VERSION|TICK|DIVIDEND_TICK|AMOUNT|MEMO`

## Examples
```
bt:DIVIDEND|0|1|BRRR|BACON|1
bt:DIVIDEND|0|BRRR|BACON|1
This example pays a dividend of 1 BACON token to every holder of 1 BRRR token
```

```
bt:DIVIDEND|0|2|TEST|BACON|1
This example pays a dividend of 1 BACON token to every holder of 1 TEST ASSET
bt:DIVIDEND|0|TEST|BACON|1
This example pays a dividend of 1 BACON token to every holder of 1 TEST token
```

## Rules
- Dividends may only be paid out by the current `token` owner
- Dividends may be used on any `TICK` or `ASSET`
- Dividends may be used on any `TICK`
- If `TICK` or `DIVIDEND_TICK` is non-divisible, `AMOUNT` must be integer

## Notes
- `UNIT` - A specific unit of measure (1 or 1.0)
- To send large amounts of `tokens` to users, see the `AIRDROP` or `SEND` commands
- To send large amounts of `tokens` to users, see the `AIRDROP` or `SEND` commands
- If `TICK` is divisible and `DIVIDEND_TICK` is non-divisble, quantities under 1.0 will receive no `DIVIDEND_TICK`
- `SOURCE` address is excluded from receiving dividends
8 changes: 4 additions & 4 deletions docs/actions/ISSUE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This command creates or issues a `BTNS` `token`
| `LOCK_DESCRIPTION` | String | Lock `token` against `DESCRIPTION` changes |
| `LOCK_RUG` | String | Lock `token` against `RUG` command |
| `LOCK_SLEEP` | String | Lock `token` against `SLEEP` command |
| `LOCK_CALLBACK` | String | Lock `token` `CALLBACK` info |
| `LOCK_CALLBACK` | String | Lock `token` against `CALLBACK` command |
| `CALLBACK_BLOCK` | String | Enable `CALLBACK` command after `CALLBACK_BLOCK` |
| `CALLBACK_TICK` | String | `TICK` `token` users get when `CALLBACK` command is used |
| `CALLBACK_AMOUNT` | String | `TICK` `token` amount that users get when `CALLBACK` command is used |
Expand All @@ -46,7 +46,7 @@ This command creates or issues a `BTNS` `token`
- `VERSION|TICK|LOCK_MAX_SUPPLY|LOCK_MAX_MINT|LOCK_DESCRIPTION|LOCK_RUG|LOCK_SLEEP|LOCK_CALLBACK|LOCK_MINT|LOCK_MINT_SUPPLY`

### Version `4` - Edit `CALLBACK` `PARAMS`
- `VERSION|TICK|LOCK_CALLBACK|CALLBACK_BLOCK|CALLBACK_TICK`
- `VERSION|TICK|CALLBACK_BLOCK|CALLBACK_TICK|CALLBACK_AMOUNT`

### Version `5` - Edit `LIST` `PARAMS`
- `VERSION|TICK|ALLOW_LIST|BLOCK_LIST`
Expand Down Expand Up @@ -119,11 +119,11 @@ This example issues a TEST token with a max supply of 100, and a maximum mint of
- `ISSUE` `TICK` with `LOCK_MINT` set to `1` to permanently prevent use of the `MINT` command
- `ISSUE` `TICK` with `LOCK_RUG` set to `1` to permanently prevent use of the `RUG` command
- `ISSUE` `TICK` with `LOCK_SLEEP` set to `1` to permanently prevent use of the `SLEEP` command
- `ISSUE` `TICK` with `LOCK_CALLBACK` set to `1` to permanently lock `CALLBACK_BLOCK`, `CALLBACK_TICK`, and `CALLBACK_AMOUNT`
- `ISSUE` `TICK` with `LOCK_CALLBACK` set to `1` to permanently prevent use of the `CALLBACK` command
- `DESCRIPTION` can contain a URL to a an icon to use for this token (48x48 standard size)
- `DESCRIPTION` can contain a URL to a JSON file with additional information
- `DESCRIPTION` can NOT contain any pipe `|` or semi-colon `;` characters, as these are reserved
- `CALLBACK_BLOCK`, `CALLBACK_TICK`, and `CALLBACK_AMOUNT` can be edited via `ISSUE` action until `LOCK_CALLBACK` is set to `1`
- `CALLBACK_BLOCK`, `CALLBACK_TICK`, and `CALLBACK_AMOUNT` can be edited via `ISSUE` action if `token` supply is NOT distributed
- `DEPLOY` `ACTION` can be used for backwards-compatability with BRC20/SRC20 `DEPLOY`
- By default any address can interact with a BTNS token, to change this behavior use `ALLOW_LIST` and `BLOCK_LIST`
- If `TICK` contains any unicode characters, then `TICK` should be `base64` encoded
Expand Down
3 changes: 2 additions & 1 deletion docs/actions/MINT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ This command mints `BTNS` `token` supply
| `TICK` | String | 1 to 250 characters in length |
| `AMOUNT` | String | Amount of `tokens` to mint |
| `DESTINATION` | String | Address to transfer minted `tokens` to |
| `MEMO` | String | An optional memo to include |

## Formats

### Version `0`
- `VERSION|TICK|AMOUNT|DESTINATION`
- `VERSION|TICK|AMOUNT|DESTINATION|MEMO`

## Examples
```
Expand Down
28 changes: 16 additions & 12 deletions docs/actions/RUG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# RUG command
This command performs a rug pull on a `token`
This command performs a rug pull on a `token` using various methods

## PARAMS
| Name | Type | Description |
| --------- | ------ | ----------------------------- |
| `VERSION` | String | Broadcast Format Version |
| `TICK` | String | 1 to 250 characters in length |
| Name | Type | Description |
| -------------------- | ------ | ---------------------------------------------------------------- |
| `VERSION` | String | Broadcast Format Version |
| `TICK` | String | 1 to 250 characters in length |
| `MINT_MAX_SUPPLY` | String | Mint `token` supply to `MAX_SUPPLY` |
| `SLEEP_FOREVER` | String | `SLEEP` token actions permanently (`SLEEP` with `value` set to `-1`) |
| `CLOSE_DISPENSERS` | String | Close any open dispensers immediately |
| `RECALL_SUPPLY` | String | Recall all `token` balances to `SOURCE` address |
| `BURN_OWNERSHIP` | String | Burn `token` ownership permanently (send to `BURN_ADDRESSS`) |
| `BURN_SUPPLY` | String | Burn any `token` supply in `SOURCE` address (send to `BURN_ADDRESSS`) |
| `DESTROY_SUPPLY` | String | Destroy any `token` supply in `SOURCE` address |

## Formats

Expand All @@ -19,11 +26,8 @@ This example does a rugpull on the BRRR `token`
```

## Rules
- Mints `token` supply up to `MAX_SUPPLY`
- Locks `MAX_SUPPLY` via `LOCK_SUPPLY`
- Locks `MAX_MINT` via `LOCK_MINT`
- Cancels all future BTNS `ACTION` commands for `token`
- Transfers `token` ownership to burn address
- Destroys all `TICK` `token` supply (including `tokens` held in addresses)

## Notes

## Notes
- This is a _HIGHLY DANGEROUS_ function, built for entertainment purposes only!
- `ISSUE` `TICK` with `LOCK_RUG` set to `1` to permanently prevent use of the `RUG` command on a `token`
20 changes: 16 additions & 4 deletions docs/actions/SLEEP.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This command pauses all `token` `ACTIONS` until `RESUME_BLOCK` is reached
| `VERSION` | String | Broadcast Format Version |
| `TICK` | String | 1 to 250 characters in length |
| `RESUME_BLOCK` | String | Block index to resume BTNS `ACTION` commands |
| `MEMO` | String | An optional memo to include |

## Formats

Expand All @@ -22,7 +23,18 @@ This example pauses/sleeps ALL BTNS `ACTION` commands on JDOG `token` until bloc
## Rules

## Notes
- USE WITH CAUTION! `SLEEP` will stop/pause all BTNS actions, including dispenses.
- `SLEEP` can result in loss of user funds, as payments to BTNS dispensers will be ignored.
- Can use `LOCK_SLEEP` in `ISSUE` command to prevent `SLEEP` command
- Can issue a `SLEEP` before `RESUME_BLOCK` to extend a `SLEEP`
- `SLEEP` does _NOT_ prevent `DISPENSER` dispenses, as that could result in a loss of user funds.
- `SLEEP` does _NOT_ prevent usage of the `SLEEP` command
- `SLEEP` with `RESUME_BLOCK` set to `0` value, will unpause actions immediately.
- `SLEEP` with `RESUME_BLOCK` set to `-1` value, will pause actions indefinitely.
- `ISSUE` `TICK` with `LOCK_SLEEP` set to `1` to permanently prevent use of the `SLEEP` command
- Can use `BATCH` commands to stop `SLEEP`, execute `ACTION` commands, and then resume `SLEEP`, etc.
`
bt:BATCH|0|
SLEEP|0|JDOG|0;
ISSUE|1|JDOG|We are working to resolve the problem;
ISSUE|2|JDOG||1000;
SEND|0|JDOG|1000|1JDogZS6tQcSxwfxhv6XKKjcyicYA4Feev|Funding contract address;
MINT|0|JDOG||1000|1JDogZS6tQcSxwfxhv6XKKjcyicYA4Feev;
SLEEP|0|JDOG|-1
`
22 changes: 11 additions & 11 deletions docs/actions/SWEEP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
This command transfers all `token` balances and/or ownerships to a destination address

## PARAMS
| Name | Type | Description |
| ----------------- | ------ | ----------------------------------------------------------------- |
| `VERSION` | String | Broadcast Format Version |
| `DESTINATION` | String | address where `token` shall be swept |
| `SWEEP_BALANCES` | String | Indicates if address `token` balances should be swept (default=1) |
| `SWEEP_OWNERSHIP` | String | Indicates if address `token` balances should be swept (default=1) |
| `MEMO` | String | Optional memo to include |
| Name | Type | Description |
| ------------- | ------ | ------------------------------------------------------------------ |
| `VERSION` | String | Broadcast Format Version |
| `DESTINATION` | String | address where `token` shall be swept |
| `BALANCES` | String | Indicates if address `token` balances should be swept (default=1) |
| `OWNERSHIPS` | String | Indicates if address `token` ownership should be swept (default=1) |
| `MEMO` | String | Optional memo to include |

## Formats

### Version `0`
- `VERSION|DESTINATION|SWEEP_BALANCES|SWEEP_OWNERSHIP|MEMO`
- `VERSION|DESTINATION|BALANCES|OWNERSHIPS|MEMO`

## Examples
```
bt:SWEEP|0|1JDogZS6tQcSxwfxhv6XKKjcyicYA4Feev|1|1
This example sweeps both token balances and ownership from the broadcasting address to 1JDogZS6tQcSxwfxhv6XKKjcyicYA4Feev
This example sweeps both token balances and ownerships from the broadcasting address to 1JDogZS6tQcSxwfxhv6XKKjcyicYA4Feev
```

```
bt:SWEEP|0|1BoogrfDADPLQpq8LMASmWQUVYDp4t2hF9|0|1`
This example sweeps only token ownership from the broadcasting address to 1JDogZS6tQcSxwfxhv6XKKjcyicYA4Feev
bt:SWEEP|0|1BoogrfDADPLQpq8LMASmWQUVYDp4t2hF9|0|1
This example sweeps only token ownerships from the broadcasting address to 1BoogrfDADPLQpq8LMASmWQUVYDp4t2hF9
```

## Rules
Expand Down
9 changes: 9 additions & 0 deletions indexer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
CHANGELOG
---
0.14.0
- `DIVIDEND` support
- `SWEEP` support
- `CALLBACK` support (disabled for now)
- fixed issue with `getTokenInfo()` setting `DECIMALS` incorrectly
- Added support for `MEMO` in `MINT` action
- Cleanup transaction fees code
- Updated `SEND` to consolidate sends by DESTINATION and TICK

0.13.0
- Added support for `--compare=DB`
- start using `—block=#` instead of `—reparse=#`
Expand Down
68 changes: 14 additions & 54 deletions indexer/includes/actions/airdrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
********************************************************************/
function btnsAirdrop($params=null, $data=null, $error=null){
global $mysqli, $reparse, $addresses, $tickers;
global $mysqli, $reparse, $addresses, $tickers, $credits, $debits;

// Define list of known FORMATS
$formats = array(
Expand Down Expand Up @@ -89,22 +89,16 @@ function btnsAirdrop($params=null, $data=null, $error=null){
// Get source address balances
$balances = getAddressBalances($data->SOURCE, null, $data->BLOCK_INDEX, $data->TX_INDEX);

// Get SOURCE address preferences
$preferences = getAddressPreferences($data->SOURCE, $data->BLOCK_INDEX, $data->TX_INDEX);
// Create the fees object
$fees = createFeesObject($data);

// Store original error value
$origError = $error;

// Array of credits and debits
// reset credits and debits arrays
$credits = [];
$debits = [];

// Copy base BTNS transaction data object into fees object
$fees = clone($data);
$fees->TICK = 'GAS';
$fees->AMOUNT = 0;
$fees->METHOD = ($preferences->FEE_PREFERENCE==1) ? 1 : 2; // 1=Destroy, 2=Donate

// Loop through airdrops and process each
foreach($airdrops as $info){

Expand Down Expand Up @@ -197,8 +191,7 @@ function btnsAirdrop($params=null, $data=null, $error=null){
$db_hits += 4; // 1 debits, 1 balances, 1 airdrops

// Determine total transaction FEE based on database hits
$airdrop->FEE_TICK = 'GAS';
$airdrop->FEE_AMOUNT = getTransactionFee($db_hits, $airdrop->FEE_TICK);
$fees->AMOUNT = getTransactionFee($db_hits, $fees->TICK);

// Verify SOURCE has enough balances to cover TICK total DEBIT amount
if(!$error && !hasBalance($balances, $airdrop->TICK, $airdrop->DEBIT))
Expand All @@ -209,12 +202,12 @@ function btnsAirdrop($params=null, $data=null, $error=null){
$balances = debitBalances($balances, $airdrop->TICK, $airdrop->DEBIT);

// Verify SOURCE has enough balances to cover FEE AMOUNT
if(!$error && !hasBalance($balances, $airdrop->FEE_TICK, $airdrop->FEE_AMOUNT))
if(!$error && !hasBalance($balances, $fees->TICK, $fees->AMOUNT))
$error = 'invalid: insufficient funds (FEE)';

// Adjust balances to reduce by FEE amount
if(!$error)
$balances = debitBalances($balances, $airdrop->TICK, $airdrop->DEBIT);
$balances = debitBalances($balances, $fees->TICK, $fees->AMOUNT);

// Determine final status
$airdrop->STATUS = $status = ($error) ? $error : 'valid';
Expand All @@ -229,33 +222,13 @@ function btnsAirdrop($params=null, $data=null, $error=null){
if($status=='valid'){

// Store the SOURCE and TICK in addresses list
addAddressTicker($airdrop->SOURCE, [$airdrop->TICK, $airdrop->FEE_TICK]);

// Debit SOURCE with total DEBIT and FEE_AMOUNT
array_push($debits, array($airdrop->TICK, $airdrop->DEBIT));
array_push($debits, array($airdrop->FEE_TICK, $airdrop->FEE_AMOUNT));

// Update FEES object with to AMOUNT
$fees->AMOUNT = bcadd($fees->AMOUNT, $airdrop->FEE_AMOUNT, 8);

// Handle using FEE according the the users ADDRESS preferences
if($preferences->FEE_PREFERENCE>1){

// Determine what address to donate to
$address = ($preferences->FEE_PREFERENCE==2) ? DONATE_ADDRESS_1 : DONATE_ADDRESS_2;
addAddressTicker($airdrop->SOURCE, [$airdrop->TICK, $fees->TICK]);

// Update the $fees object with the destination address
$fees->DESTINATION = $address;
// Debit SOURCE with total DEBIT
array_push($debits, array($airdrop->TICK, $airdrop->DEBIT));

// Store the donation ADDRESS and TICK in addresses list
addAddressTicker($address, $airdrop->FEE_TICK);

// Credit donation address with FEE_AMOUNT
array_push($credits, array($airdrop->FEE_TICK, $airdrop->FEE_AMOUNT, $address));
}

// Create record of FEE in `fees` table
createFeeRecord($fees);
// Handle any transaction FEE according the users's ADDRESS preferences
processTransactionFees('AIRDROP', $fees);

// Loop through recipient addresses
foreach($recipients as $address){
Expand All @@ -269,21 +242,8 @@ function btnsAirdrop($params=null, $data=null, $error=null){
}
}

// Consolidate the credit and debit records to write as few records as possible
$debits = consolidateCreditDebitRecords('debits', $debits);
$credits = consolidateCreditDebitRecords('credits', $credits);

// Create records in debits table
foreach($debits as $debit){
[$tick, $amount] = $debit;
createDebit('AIRDROP', $data->BLOCK_INDEX, $data->TX_HASH, $tick, $amount, $data->SOURCE);
}

// Create records in credits table
foreach($credits as $credit){
[$tick, $amount, $destination] = $credit;
createCredit('AIRDROP', $data->BLOCK_INDEX, $data->TX_HASH, $tick, $amount, $destination);
}
// Process any transaction credit/debit records
processTransactionCreditsDebits('AIRDROP', $data);

// If this is a reparse, bail out before updating balances
if($reparse)
Expand Down
Loading

0 comments on commit 742dbd2

Please sign in to comment.