diff --git a/token-dispenser/scripts/transfer-treasuries.sh b/token-dispenser/scripts/transfer-treasuries.sh new file mode 100644 index 00000000..7f7e7475 --- /dev/null +++ b/token-dispenser/scripts/transfer-treasuries.sh @@ -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" diff --git a/token-dispenser/ts/scripts/transfer-treasury.ts b/token-dispenser/ts/scripts/transfer-treasury.ts new file mode 100644 index 00000000..574e2513 --- /dev/null +++ b/token-dispenser/ts/scripts/transfer-treasury.ts @@ -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"); +})();