Skip to content

Commit

Permalink
- add balance management scripts
Browse files Browse the repository at this point in the history
 - add URL to all scripts
  • Loading branch information
diman-io committed Apr 6, 2022
1 parent 36371f4 commit 9e16e48
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 7 deletions.
63 changes: 58 additions & 5 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,81 @@
All this scripts support `$URL` variable for set another rpc end-point (default is api.mainnet-beta.solana.com).

Examples:
```
URL=https://localhost:8899/ ./rebalance-sol.sh 0.1
URL=https://free.rpcpool.com/ ./rebalance-sol.sh 0.1
URL=https://solana-api.projectserum.com/ ./rebalance-sol.sh 0.1
```

# Raydium scripts

For possible values for POOL use `../raydium ido --help`

## stake.sh

```
./stake.sh <POOL>
```
For possible values for POOL use `../raydium ido --help`

---
## claim.sh

```
./claim.sh <POOL>
```
For possible values for POOL use `../raydium ido --help`

Claim is smart. It try to do all possible actions and doesn't do not needed actions. Though if you want the transactions looks like as the official site make it you could use optional flags for this. `../raydium ido claim --help` helps you.

---
# Keypairs scripts

## keygen.sh

Restore your 100500 wallets from Phantom:
```
./keygen.sh
```
Restore your 100500 wallets from Phantom.

The results will be saved as `keys/[prefix]_[index]-[address].json`

You need to use `solana` v9. This doesn't work with 10th version.

# Balance management scripts

## rebalance-sol.sh

```
./rebalance-sol.sh <AIM> <VAULT>
```

`AIM` - the target value in SOLs in `keys/*.json` keypairs

`VAULT` - path to vault keypair

## rebalance-token.sh

```
./rebalance-token.sh <TOKEN> <AIM> <VAULT>
```

`TOKEN` - token mint address

`AIM` - the target value in Tokens in `keys/*.json` wallets

`VAULT` - path to vault keypair

## rebalance-token-usdc.sh

Just a helper for USDC rebalancing.

```
./rebalance-token-usdc.sh <AIM> <VAULT>
```

`AIM` - the target value in Tokens in `keys/*.json` wallets

`VAULT` - path to vault keypair

## balance-*.sh

They are like rebalance-* but only to show your accounts balances. `AIM` and `VAULT` aren't needed.

13 changes: 13 additions & 0 deletions scripts/balance-sol.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [[ -z ${URL} ]]; then
URL=mainnet-beta
fi

fmt="%-45s%s\n"
for keypair in keys/*.json
do
address=$(solana address -k $keypair)
balance=$(solana -u $URL balance -k $keypair | grep -o '[0-9.]*')
printf "$fmt" $address $balance
done
5 changes: 5 additions & 0 deletions scripts/balance-token-usdc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

TOKEN=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

./balance-token.sh $TOKEN
15 changes: 15 additions & 0 deletions scripts/balance-token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

TOKEN=$1

if [[ -z ${URL} ]]; then
URL=mainnet-beta
fi

fmt="%-45s%s\n"
for keypair in keys/*.json
do
address=$(solana address -k $keypair)
balance=$(spl-token -u $URL balance $TOKEN --owner $keypair)
printf "$fmt" $address $balance
done
6 changes: 5 additions & 1 deletion scripts/claim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ raydium_cli=../raydium

POOL=$1

if [[ -z ${URL} ]]; then
URL=mainnet-beta
fi

for keypair in keys/*.json
do
$raydium_cli ido $POOL claim -k $keypair
$raydium_cli ido $POOL claim -k $keypair -u $URL
done
37 changes: 37 additions & 0 deletions scripts/rebalance-sol.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

AIM=$1
VAULT=$2

if [[ -z ${URL} ]]; then
URL=mainnet-beta
fi

for keypair in keys/*.json
do
address=$(solana address -k $keypair)
balance=$(solana -u $URL balance -k $keypair | grep -o '[0-9.]*')
if (( $(echo "$balance < $AIM" | bc -l) )); then
amount=$(echo "$AIM - $balance" | bc -l)
from=$VAULT
to=$keypair
job=Funding
elif (( $(echo "$balance > $AIM" | bc -l) )); then
amount=$(echo "$balance - $AIM" | bc -l)
from=$keypair
to=$VAULT
job=Refunding
else
amount=0
job="Nothing to do"
fi
if [[ "$amount" == .* ]]; then
amount="0$amount"
fi
if [[ "$amount" == 0 ]]; then
echo $address: $balance SOL. $job
continue
fi
echo $address: $balance SOL. $job $amount SOL...
solana -u $URL transfer -k $from $to $amount --fee-payer $VAULT --allow-unfunded-recipient
done
7 changes: 7 additions & 0 deletions scripts/rebalance-token-usdc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

TOKEN=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
AIM=$1
VAULT=$2

./rebalance-token.sh $TOKEN $AIM $VAULT
38 changes: 38 additions & 0 deletions scripts/rebalance-token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

TOKEN=$1
AIM=$2
VAULT=$3

if [[ -z ${URL} ]]; then
URL=mainnet-beta
fi

for keypair in keys/*.json
do
address=$(solana address -k $keypair)
balance=$(spl-token -u $URL balance $TOKEN --owner $keypair)
if (( $(echo "$balance < $AIM" | bc -l) )); then
amount=$(echo "$AIM - $balance" | bc -l)
from=$VAULT
to=$keypair
job=Funding
elif (( $(echo "$balance > $AIM" | bc -l) )); then
amount=$(echo "$balance - $AIM" | bc -l)
from=$keypair
to=$VAULT
job=Refunding
else
amount=0
job="Nothing to do"
fi
if [[ "$amount" == .* ]]; then
amount="0$amount"
fi
if [[ "$amount" == 0 ]]; then
echo $address: $balance Tokens. $job
continue
fi
echo $address: $balance Tokens. $job $amount Tokens...
spl-token -u $URL transfer $TOKEN $amount $to --owner $from --fee-payer $VAULT --allow-unfunded-recipient --fund-recipient
done
6 changes: 5 additions & 1 deletion scripts/stake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ raydium_cli=../raydium

POOL=$1

if [[ -z ${URL} ]]; then
URL=mainnet-beta
fi

for keypair in keys/*.json
do
$raydium_cli ido $POOL stake MAX -k $keypair
$raydium_cli ido $POOL stake MAX -k $keypair -u $URL
done

0 comments on commit 9e16e48

Please sign in to comment.