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

adds transfer-treasury script #91

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions token-dispenser/scripts/transfer-treasuries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

if [[ -z $SOLANA_RPC_URL || \
-z $AUTHORITY ]; then
echo "Error: One or more required environment variables are not set."
echo "SOLANA_RPC_URL: $SOLANA_RPC_URL"
echo "LEDGER_PUB_KEY: $AUTHORITY"
exit 1
fi

while IFS= read -r TREASURY; do
TREASURY=$TREASURY NEW_AUTHORITY=$AUTHORITY npx ts-node ./ts/scripts/transfer-treasury.ts
done < "$(dirname "$0")/treasuries"
38 changes: 38 additions & 0 deletions token-dispenser/ts/scripts/transfer-sol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
PublicKey,
SystemProgram,
ComputeBudgetInstruction,
ComputeBudgetProgram,
} from "@solana/web3.js";
import { ledgerSignAndSend } from "./helpers";
import { connection, getSigner, getEnv } from "./env";
type Config = {
to: PublicKey;
amount: bigint; // lamports
};

(async () => {
const config: Config = {
to: new PublicKey(getEnv("TO")),
amount: BigInt(getEnv("AMOUNT")),
};

const signer = await getSigner();
const signerPk = new PublicKey(await signer.getAddress());

const transferIx = SystemProgram.transfer({
fromPubkey: signerPk,
toPubkey: config.to,
lamports: config.amount,
});

const setComputePriceIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 1_200_000,
});

console.log(`Transferring ${config.amount} lamports to ${config.to.toBase58()}`);
const result = await ledgerSignAndSend([setComputePriceIx, transferIx], []);
console.log("Tx Sent: ", result);
const txIncluded = await connection.confirmTransaction(result);
console.log("Tx Included");
})();
38 changes: 38 additions & 0 deletions token-dispenser/ts/scripts/transfer-treasury.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
PublicKey,
} from "@solana/web3.js";
import {
AuthorityType,
createSetAuthorityInstruction,
} from "@solana/spl-token";

import { ledgerSignAndSend } from "./helpers";
import { connection, getSigner, getEnv } from "./env";

type Config = {
treasury: PublicKey;
newAuthority: PublicKey;
};

(async () => {
const config: Config = {
treasury: new PublicKey(getEnv("TREASURY")),
newAuthority: new PublicKey(getEnv("NEW_AUTHORITY")),
};

const signer = await getSigner();
const signerPk = new PublicKey(await signer.getAddress());

const setAuthorityIx = createSetAuthorityInstruction(
config.treasury,
signerPk,
AuthorityType.AccountOwner,
config.newAuthority,
);

console.log(`Setting account ${config.treasury.toBase58()} authority to ${config.newAuthority.toBase58()}`);
const result = await ledgerSignAndSend([setAuthorityIx], []);
console.log("Tx Sent: ", result);
const txIncluded = await connection.confirmTransaction(result);
console.log("Tx Included");
})();
Loading