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 solana-tokens #10011

Merged
merged 73 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
bb0665b
Initial commit
garious Apr 2, 2020
c8b5e17
Execute transfers
garious Apr 3, 2020
94a17f7
Refactor for testing
garious Apr 3, 2020
edf81b6
Cleanup readme
garious Apr 3, 2020
e3df5ab
Rewrite
garious Apr 3, 2020
449826c
Cleanup
garious Apr 3, 2020
30b1459
Cleanup
garious Apr 3, 2020
d3df313
Cleanup client
garious Apr 3, 2020
7932a48
Use a Null Client to move prints closer to where messages are sent
garious Apr 3, 2020
6213f14
Upgrade Solana
garious Apr 3, 2020
c49cdbe
Move core functionality into its own module
garious Apr 3, 2020
bc16911
Handle transaction errors
garious Apr 3, 2020
3a7653b
Merge allocations
garious Apr 3, 2020
984dde8
Fixes
garious Apr 3, 2020
74a925d
Cleanup readme
garious Apr 3, 2020
47a9d98
Fix markdown
garious Apr 3, 2020
e1fe1ef
Add example input
garious Apr 3, 2020
3f49c37
Add integration test - currently fails
garious Apr 3, 2020
93117f2
Add integration test
garious Apr 3, 2020
e85e80a
Add metrics
garious Apr 3, 2020
5d80ec0
Use RpcClient in dry-run, just don't send messages
garious Apr 3, 2020
0cf5c8c
More metrics
garious Apr 3, 2020
6c9821d
Fix dry run with no keys
garious Apr 3, 2020
0b421b0
Only require one approval if fee-payer is the sender keypair
garious Apr 3, 2020
7ce7376
Fix bugs
garious Apr 4, 2020
6a56399
Bail out of any account already has a balance
garious Apr 4, 2020
00cc299
Polish
garious Apr 4, 2020
4902060
Add new 'balances' command
garious Apr 4, 2020
b5cd54c
9 decimal places
garious Apr 4, 2020
b4fb233
Add missing file
garious Apr 4, 2020
6bf5f7c
Better dry-run; keypair options now optional
garious Apr 4, 2020
0c6da71
Change field name from 'bid' to 'accepted'
garious Apr 7, 2020
4373f20
Write to transaction log immediately
garious Apr 22, 2020
eee2a67
Rename allocations_csv to bids_csv
garious Apr 22, 2020
b929084
Upgrade Solana
garious Apr 23, 2020
24dc72c
Remove faucet from integration test
garious Apr 24, 2020
29dbb53
Cleaner integration test
garious Apr 27, 2020
3830038
Update README
garious Apr 27, 2020
4b44552
Add TravicCI script to build and test (#1)
garious Apr 27, 2020
2148fb3
Add distribute-stake command (#2)
garious Apr 29, 2020
d65b3be
Distribute -> DistributeTokens (#3)
garious Apr 29, 2020
d51871b
Cache cargo deps (#4)
garious Apr 29, 2020
09b5e0c
Add docs (#5)
garious May 3, 2020
9bb8473
Switch to latest Solana 1.1 release (#7)
garious May 3, 2020
07d9617
distribute -> distribute-tokens (#9)
danpaul000 May 4, 2020
ac7dd41
Switch from CSV to a pickledb database (#8)
garious May 4, 2020
3f75424
Add --sol-for-fees option for stake distributions
danpaul000 May 5, 2020
4e20253
Merge pull request #15 from danpaul000/sol-for-fees
danpaul000 May 5, 2020
0c36708
Add --allocations-csv option (#14)
danpaul000 May 5, 2020
e766d88
Update arg_parser.rs
danpaul000 May 5, 2020
a737e9e
Fix balances command (#17)
garious May 5, 2020
ee8e5ac
Add --force to transfer to non-empty accounts (#18)
danpaul000 May 5, 2020
fdb5f56
Add --no-wait (#16)
garious May 6, 2020
6885f1a
Continue when transactions not yet finalized (#20)
garious May 7, 2020
6dafeb5
Return the number of confirmations (#21)
garious May 7, 2020
5258447
Add read_allocations() unit-test (#22)
garious May 7, 2020
6f288be
Add a CSV printer (#23)
garious May 7, 2020
426ec4f
Remove all the copypasta (#24)
garious May 7, 2020
6007905
Rename print-database command to transaction-log (#25)
garious May 8, 2020
a29ae50
Send all transactions as quickly as possible, then wait (#26)
garious May 8, 2020
5f9d678
Move log to stderr
garious May 8, 2020
d3a9058
Add constructor, tuck away client (#30)
garious May 8, 2020
256c409
Fix optional option flagged as required
garious May 10, 2020
041565d
Bunch of cleanup (#31)
garious May 12, 2020
0ee429e
Sort transaction log by finalized date (#33)
garious May 12, 2020
8d35db1
Make --transaction-db option implicit (#34)
garious May 12, 2020
282c9f3
Move db functionality into its own module (#35)
garious May 12, 2020
8e9b2b4
Add 'tokens/' from commit '282c9f371d5ef3f136c20b709911559b3ce14a77'
garious May 12, 2020
ca5faf4
Add solana-tokens to build
garious May 12, 2020
b9d27e6
Remove Cargo.lock
garious May 12, 2020
07bcaac
Remove vscode file
garious May 12, 2020
8911841
Remove TravisCI build script
garious May 12, 2020
7f0e126
Install solana-tokens
garious May 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ members = [
"stake-accounts",
"stake-monitor",
"sys-tuner",
"tokens",
"transaction-status",
"upload-perf",
"net-utils",
Expand Down
2 changes: 2 additions & 0 deletions scripts/cargo-install-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if [[ $CI_OS_NAME = windows ]]; then
solana-install-init
solana-keygen
solana-stake-accounts
solana-tokens
)
else
./fetch-perf-libs.sh
Expand Down Expand Up @@ -100,6 +101,7 @@ else
solana-stake-accounts
solana-stake-monitor
solana-sys-tuner
solana-tokens
solana-validator
solana-watchtower
)
Expand Down
2 changes: 2 additions & 0 deletions tokens/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
*.csv
34 changes: 34 additions & 0 deletions tokens/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "solana-tokens"
description = "Blockchain, Rebuilt for Scale"
authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
version = "1.2.0"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
clap = "2.33.0"
console = "0.10.3"
csv = "1.1.3"
dirs = "2.0.2"
indexmap = "1.3.2"
indicatif = "0.14.0"
itertools = "0.9.0"
pickledb = "0.4.1"
serde = { version = "1.0", features = ["derive"] }
solana-clap-utils = { path = "../clap-utils", version = "1.2.0" }
solana-cli-config = { path = "../cli-config", version = "1.2.0" }
solana-client = { path = "../client", version = "1.2.0" }
solana-remote-wallet = { path = "../remote-wallet", version = "1.2.0" }
solana-runtime = { path = "../runtime", version = "1.2.0" }
solana-sdk = { path = "../sdk", version = "1.2.0" }
solana-stake-program = { path = "../programs/stake", version = "1.2.0" }
solana-transaction-status = { path = "../transaction-status", version = "1.2.0" }
tempfile = "3.1.0"
thiserror = "1.0"

[dev-dependencies]
solana-core = { path = "../core", version = "1.2.0" }
105 changes: 105 additions & 0 deletions tokens/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Distribute Solana tokens

A user may want to make payments to multiple accounts over multiple iterations.
The user will have a spreadsheet listing public keys and token amounts, and
some process for transferring tokens to them, and ensuring that no more than the
expected amount are sent. The command-line tool here automates that process.

## Distribute tokens

Send tokens to the recipients in `<BIDS_CSV>`.

Example bids.csv:

```text
primary_address,bid_amount_dollars
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,6.6
```

```bash
solana-tokens distribute-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --from-bids --input-csv <BIDS_CSV> --fee-payer <KEYPAIR>
```

Example transaction log before:

```text
recipient,amount,signature
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,30,1111111111111111111111111111111111111111111111111111111111111111
```

Send tokens to the recipients in `<BIDS_CSV>` if the distribution is
not already recordered in the transaction log.

```bash
solana-tokens distribute-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --from-bids --input-csv <BIDS_CSV> --fee-payer <KEYPAIR>
```

Example output:

```text
Recipient Amount
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv 70
3ihfUy1n9gaqihM5bJCiTAGLgWc5zo3DqVUS6T736NLM 42
UKUcTXgbeTYh65RaVV5gSf6xBHevqHvAXMo3e8Q6np8k 43
```


Example transaction log after:

```bash
solana-tokens transaction-log --output-path transactions.csv
```

```text
recipient,amount,signature
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,30,1111111111111111111111111111111111111111111111111111111111111111
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,70,1111111111111111111111111111111111111111111111111111111111111111
3ihfUy1n9gaqihM5bJCiTAGLgWc5zo3DqVUS6T736NLM,42,1111111111111111111111111111111111111111111111111111111111111111
UKUcTXgbeTYh65RaVV5gSf6xBHevqHvAXMo3e8Q6np8k,43,1111111111111111111111111111111111111111111111111111111111111111
```

### Calculate what tokens should be sent

List the differences between a list of expected distributions and the record of what
transactions have already been sent.

```bash
solana-tokens distribute-tokens --dollars-per-sol <NUMBER> --dry-run --from-bids --input-csv <BIDS_CSV>
```

Example bids.csv:

```text
primary_address,bid_amount_dollars
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,6.6
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,15.4
3ihfUy1n9gaqihM5bJCiTAGLgWc5zo3DqVUS6T736NLM,9.24
UKUcTXgbeTYh65RaVV5gSf6xBHevqHvAXMo3e8Q6np8k,9.46
```

Example output:

```text
Recipient Amount
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv 70
3ihfUy1n9gaqihM5bJCiTAGLgWc5zo3DqVUS6T736NLM 42
UKUcTXgbeTYh65RaVV5gSf6xBHevqHvAXMo3e8Q6np8k 43
```

## Distribute stake accounts

Distributing tokens via stake accounts works similarly to how tokens are distributed. The
big difference is that new stake accounts are split from existing ones. By splitting,
the new accounts inherit any lockup or custodian settings of the original.

```bash
solana-tokens distribute-stake --stake-account-address <ACCOUNT_ADDRESS> \
--input-csv <ALLOCATIONS_CSV> \
--stake-authority <KEYPAIR> --withdraw-authority <KEYPAIR> --fee-payer <KEYPAIR>
```

Currently, this will subtract 1 SOL from each allocation and store it the
recipient address. That SOL can be used to pay transaction fees on staking
operations such as delegating stake. The rest of the allocation is put in
a stake account. The new stake account address is output in the transaction
log.
Loading