Skip to content

Commit

Permalink
adds transfer-treasury script
Browse files Browse the repository at this point in the history
  • Loading branch information
solanoepalacio committed Apr 5, 2024
1 parent 450f18a commit 9521ad1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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"
46 changes: 46 additions & 0 deletions token-dispenser/ts/scripts/transfer-treasury.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
PublicKey,
SystemProgram,
AddressLookupTableProgram,
SYSVAR_INSTRUCTIONS_PUBKEY,
} from "@solana/web3.js";

import { TokenDispenserSdk } from "../sdk";
import { ledgerSignAndSend, ledgerSignAndSendV0 } from "./helpers";
import { connection, getSigner, getEnv } from "./env";
import { funders, tokenDispenserProgramId, treasuries } from "./config";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
AuthorityType,
TOKEN_PROGRAM_ID,
createSetAuthorityInstruction,
} from "@solana/spl-token";

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());

// AuthorityType.AccountOwner;
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 ledgerSignAndSendV0([setAuthorityIx], []);
console.log("Tx Sent: ", result);
const txIncluded = await connection.confirmTransaction(result);
console.log("Tx Included");
})();

0 comments on commit 9521ad1

Please sign in to comment.