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

Deployments #76

Merged
merged 14 commits into from
Apr 2, 2024
2 changes: 1 addition & 1 deletion frontend/claim_sdk/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export class TokenDispenserProvider {
const cusPerPdaDerivation = 1500
return (maxBump - bump) * cusPerPdaDerivation
}
const safetyMargin = 1000
const safetyMargin = 10000
const ataCreationCost = 20460
//determined experimentally:
const ecosystemCUs = {
Expand Down
12 changes: 6 additions & 6 deletions frontend/claim_sdk/treasury.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { ClaimInfo } from './claim'
import { PublicKey } from '@solana/web3.js'

export const treasuries = [
new PublicKey('waTh9vNmRz8hHxQv1zW81ExKQ7fwaa1TR6tQT5fTkjg'),
new PublicKey('waTirsbdRyyxm8DFxH9Z9P5Pyrj74jJ7E74zqhmGX1k'),
new PublicKey('wAtMcoqwHb7obEL2USNXPqxg1CmJDSjjjsNcEm9bzCZ'),
new PublicKey('Wats1sM7W4UvxUuQPevGxexgcaFiaXMXxActKUmcvHx'),
new PublicKey('waTtgLt1WVRgoWYNZh97AYAUqoU4nN98jVThPdYQVwj'),
new PublicKey('WaTxa5w4TjYHRdHwG2zaN9ynA1c9z4J9TswsBCmzy4N'),
new PublicKey('WaTtAHa1YZB2DFHTZveUSqBnAWsDQtxfN6RC77gmifa'),
new PublicKey('wAT8vs52AcD7B77KpkwVVUgDm5vcb83uDUr1eSuvhTm'),
new PublicKey('wAt9yuPxmredtJxFxM19aeToc5wWZVEfN5L346XPR2o'),
new PublicKey('waTgcmvbUNBCW9h5sd6Fd2ziRJyRTvtTBPiYBNuQUNx'),
new PublicKey('WatWL18fpiB28zMg3mbxxnPfoemx6Pr4YA4rL56PQyg'),
new PublicKey('WaT7ACb6Zvibjh1NN6zNkpdMGBTqPjVigQKxU2MbBWs'),
]

export const funders = [
Expand Down
22 changes: 22 additions & 0 deletions token-dispenser/scripts/create-treasuries-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

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

while IFS= read -r TREASURY; do
MINT=$MINT TREASURY=$TREASURY npx tsx ./ts/scripts/create-treasury.ts

TREASURY=$TREASURY CONFIG_PDA=$CONFIG_PDA MINT_AMOUNT=$MINT_AMOUNT npx tsx ./ts/scripts/delegate-treasury.ts
done < "$(dirname "$0")/treasuries"
13 changes: 6 additions & 7 deletions token-dispenser/scripts/treasuries
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
waTiAKS8FBdnNnGLJv5aF2b1ouwn22ZP1WGd2NsFS1F
wAtQwJteMdGidPcvoeKSVPcvBj6brA38ZQDFSwTQqm3
WatsKcF7vbvxAMp26pz3yMc4X4R66gNvExCtHwc371H
WATY4JeitW6xZeZa9U4Wy8cxYdk1LtW6s6mmDFhUKuD
waTyocL9rFxerXZNsGP7v7G8VVoR7hDk74Tp4nC7uEV
waTZHsCNgr8SzkbXiwEPBd6PE1pb5owuR1NQotM4zJj
waTyocL9rFxerXZNsGP7v7G8VVoR7hDk74Tp4nC7uEV
WaTtAHa1YZB2DFHTZveUSqBnAWsDQtxfN6RC77gmifa
wAT8vs52AcD7B77KpkwVVUgDm5vcb83uDUr1eSuvhTm
wAt9yuPxmredtJxFxM19aeToc5wWZVEfN5L346XPR2o
waTgcmvbUNBCW9h5sd6Fd2ziRJyRTvtTBPiYBNuQUNx
WatWL18fpiB28zMg3mbxxnPfoemx6Pr4YA4rL56PQyg
WaT7ACb6Zvibjh1NN6zNkpdMGBTqPjVigQKxU2MbBWs
12 changes: 6 additions & 6 deletions token-dispenser/ts/scripts/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PublicKey } from "@solana/web3.js";

export const treasuries = [
new PublicKey("waTiAKS8FBdnNnGLJv5aF2b1ouwn22ZP1WGd2NsFS1F"),
new PublicKey("wAtQwJteMdGidPcvoeKSVPcvBj6brA38ZQDFSwTQqm3"),
new PublicKey("WatsKcF7vbvxAMp26pz3yMc4X4R66gNvExCtHwc371H"),
new PublicKey("WATY4JeitW6xZeZa9U4Wy8cxYdk1LtW6s6mmDFhUKuD"),
new PublicKey("waTyocL9rFxerXZNsGP7v7G8VVoR7hDk74Tp4nC7uEV"),
new PublicKey("waTZHsCNgr8SzkbXiwEPBd6PE1pb5owuR1NQotM4zJj"),
new PublicKey("WaTtAHa1YZB2DFHTZveUSqBnAWsDQtxfN6RC77gmifa"),
new PublicKey("wAT8vs52AcD7B77KpkwVVUgDm5vcb83uDUr1eSuvhTm"),
new PublicKey("wAt9yuPxmredtJxFxM19aeToc5wWZVEfN5L346XPR2o"),
new PublicKey("waTgcmvbUNBCW9h5sd6Fd2ziRJyRTvtTBPiYBNuQUNx"),
new PublicKey("WatWL18fpiB28zMg3mbxxnPfoemx6Pr4YA4rL56PQyg"),
new PublicKey("WaT7ACb6Zvibjh1NN6zNkpdMGBTqPjVigQKxU2MbBWs"),
];

export const funders = [
Expand Down
91 changes: 91 additions & 0 deletions token-dispenser/ts/scripts/create-treasury.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
PublicKey,
SystemProgram,
AddressLookupTableProgram,
SYSVAR_INSTRUCTIONS_PUBKEY,
Keypair,
ComputeBudgetProgram,
} 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 fs from "fs";
import { envOrErr } from "../../../frontend/claim_sdk/index";
import {
TOKEN_PROGRAM_ID,
createAccount,
getMint,
getAccountLenForMint,
createInitializeAccountInstruction,
} from "@solana/spl-token";

type Config = {
mint: PublicKey;
treasury: Keypair;
};

(async () => {
const config: Config = {
mint: new PublicKey(getEnv("MINT")),
treasury: Keypair.fromSecretKey(
new Uint8Array(loadJsonSync(`${getEnv("TREASURY")}.json`))
),
};

console.log(
"Creating token account for treasury: ",
config.treasury.publicKey.toBase58()
);

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

const mintState = await getMint(
connection,
config.mint,
"confirmed",
TOKEN_PROGRAM_ID
);
const space = getAccountLenForMint(mintState);
const lamports = await connection.getMinimumBalanceForRentExemption(space);

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

const createAccountIx = SystemProgram.createAccount({
fromPubkey: signerPk,
newAccountPubkey: config.treasury.publicKey,
space,
lamports,
programId: TOKEN_PROGRAM_ID,
});

const initializeInstructionIx = createInitializeAccountInstruction(
config.treasury.publicKey,
config.mint,
signerPk,
TOKEN_PROGRAM_ID
);

const result = await ledgerSignAndSend(
[setComputePriceIx, createAccountIx, initializeInstructionIx],
[config.treasury]
);

console.log(
`Token account ${config.treasury.publicKey.toBase58()} created. Signature: `,
result
);
})();

function loadJsonSync(filePath: string): any {
if (!fs.existsSync(filePath)) {
throw new Error("File does not exist");
}

const fileContent = fs.readFileSync(filePath, "utf-8");
return JSON.parse(fileContent);
}
54 changes: 54 additions & 0 deletions token-dispenser/ts/scripts/delegate-treasury.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
PublicKey,
SystemProgram,
AddressLookupTableProgram,
SYSVAR_INSTRUCTIONS_PUBKEY,
Keypair,
ComputeBudgetProgram,
} from "@solana/web3.js";

import { ledgerSignAndSend, ledgerSignAndSendV0 } from "./helpers";
import { connection, getSigner, getEnv } from "./env";
import { createApproveInstruction } from "@solana/spl-token";

type Config = {
treasury: PublicKey;
configAccount: PublicKey;
approveAmount: bigint;
};

(async () => {
const config: Config = {
treasury: new PublicKey(getEnv("TREASURY")),
configAccount: new PublicKey(getEnv("CONFIG_PDA")),
approveAmount: BigInt(getEnv("APPROVE_AMOUNT")),
};

console.log(
`Delegating ${config.approveAmount} of treasury: `,
config.treasury.toBase58()
);

const signer = await getSigner();
const signerPk = new PublicKey(await signer.getAddress());
const setComputePriceIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 1_000_000,
});

const approveInstruction = createApproveInstruction(
config.treasury,
config.configAccount,
signerPk,
config.approveAmount
);

const result = await ledgerSignAndSend(
[setComputePriceIx, approveInstruction],
[]
);

console.log(
`Token account ${config.treasury.toBase58()} delegated. Signature: `,
result
);
})();
43 changes: 43 additions & 0 deletions token-dispenser/ts/scripts/extend-lookup-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 { envOrErr } from "../../../frontend/claim_sdk/index";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";

type ExtendConfig = {
// Account Addresses (base58 encoded):
lookupTable: PublicKey;
tokenDispenser: string;
};

(async () => {
const config: ExtendConfig = {
lookupTable: new PublicKey(envOrErr("LOOKUP_TABLE")),
tokenDispenser: tokenDispenserProgramId,
};

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

const extendAddressLooupTableIx = AddressLookupTableProgram.extendLookupTable(
{
payer: signerPk,
authority: signerPk,
lookupTable: config.lookupTable,
addresses: [...treasuries],
}
);

await ledgerSignAndSendV0([extendAddressLooupTableIx], []);
})();
Loading