Skip to content

Commit

Permalink
fix eslint prettier config, rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolley committed Feb 23, 2024
1 parent 19ba03a commit ea107bf
Show file tree
Hide file tree
Showing 53 changed files with 485 additions and 1,146 deletions.
1 change: 0 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
"devDependencies": {
"@streamflow/eslint-config": "workspace:*",
"@streamflow/prettier-config": "workspace:*",
"@types/bn.js": "5.1.1",
"@types/jest": "29.2.4",
"date-fns": "2.28.0",
Expand Down
22 changes: 3 additions & 19 deletions packages/common/solana/instructions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Connection,
PublicKey,
SystemProgram,
TransactionInstruction,
} from "@solana/web3.js";
import { Connection, PublicKey, SystemProgram, TransactionInstruction } from "@solana/web3.js";
import BN from "bn.js";
import {
createAssociatedTokenAccountInstruction,
Expand All @@ -17,25 +12,14 @@ export const prepareWrappedAccount = async (
senderAddress: PublicKey,
amount: BN
): Promise<TransactionInstruction[]> => {
const tokenAccount = await getAssociatedTokenAddress(
NATIVE_MINT,
senderAddress,
true
);
const tokenAccount = await getAssociatedTokenAddress(NATIVE_MINT, senderAddress, true);

const accInfo = await connection.getParsedAccountInfo(tokenAccount);

const instructions =
(accInfo.value?.lamports ?? 0) > 0
? []
: [
createAssociatedTokenAccountInstruction(
senderAddress,
tokenAccount,
senderAddress,
NATIVE_MINT
),
];
: [createAssociatedTokenAccountInstruction(senderAddress, tokenAccount, senderAddress, NATIVE_MINT)];

return [
...instructions,
Expand Down
8 changes: 1 addition & 7 deletions packages/common/solana/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
import {
AccountInfo,
PublicKey,
Keypair,
TransactionSignature,
TransactionInstruction,
} from "@solana/web3.js";
import { AccountInfo, PublicKey, Keypair, TransactionSignature, TransactionInstruction } from "@solana/web3.js";

export { WalletAdapterNetwork as Cluster } from "@solana/wallet-adapter-base";

Expand Down
69 changes: 15 additions & 54 deletions packages/common/solana/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
createAssociatedTokenAccountInstruction,
getAssociatedTokenAddress,
} from "@solana/spl-token";
import { createAssociatedTokenAccountInstruction, getAssociatedTokenAddress } from "@solana/spl-token";
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
import {
BlockheightBasedTransactionConfirmationStrategy,
Expand Down Expand Up @@ -48,9 +45,7 @@ export async function getProgramAccounts(
* @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
* @return {boolean} - Returns true if parameter is a Wallet.
*/
export function isSignerWallet(
walletOrKeypair: Keypair | SignerWalletAdapter
): walletOrKeypair is SignerWalletAdapter {
export function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter {
return (<SignerWalletAdapter>walletOrKeypair).signTransaction !== undefined;
}

Expand All @@ -59,20 +54,15 @@ export function isSignerWallet(
* @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
* @returns {boolean} - Returns true if parameter is a Keypair.
*/
export function isSignerKeypair(
walletOrKeypair: Keypair | SignerWalletAdapter
): walletOrKeypair is Keypair {
export function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair {
return (
walletOrKeypair instanceof Keypair ||
walletOrKeypair.constructor === Keypair ||
walletOrKeypair.constructor.name === Keypair.prototype.constructor.name
);
}

export async function signTransaction(
invoker: Keypair | SignerWalletAdapter,
tx: Transaction
): Promise<Transaction> {
export async function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction> {
let signedTx: Transaction;
if (isSignerWallet(invoker)) {
signedTx = await invoker.signTransaction(tx);
Expand Down Expand Up @@ -103,17 +93,12 @@ export async function signAndExecuteTransaction(
if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
throw Error("Error with transaction parameters.");

const confirmationStrategy: BlockheightBasedTransactionConfirmationStrategy =
{
lastValidBlockHeight: hash.lastValidBlockHeight,
signature: bs58.encode(signedTx.signature),
blockhash: hash.blockhash,
};
const signature = await sendAndConfirmRawTransaction(
connection,
rawTx,
confirmationStrategy
);
const confirmationStrategy: BlockheightBasedTransactionConfirmationStrategy = {
lastValidBlockHeight: hash.lastValidBlockHeight,
signature: bs58.encode(signedTx.signature),
blockhash: hash.blockhash,
};
const signature = await sendAndConfirmRawTransaction(connection, rawTx, confirmationStrategy);
return signature;
}

Expand All @@ -133,10 +118,7 @@ export function ata(mint: PublicKey, owner: PublicKey): Promise<PublicKey> {
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
* @returns Array of boolean where each members corresponds to owners member
*/
export async function ataBatchExist(
connection: Connection,
paramsBatch: AtaParams[]
): Promise<boolean[]> {
export async function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]> {
const tokenAccounts = await Promise.all(
paramsBatch.map(async ({ mint, owner }) => {
const pubkey = await ata(mint, owner);
Expand Down Expand Up @@ -164,12 +146,7 @@ export async function generateCreateAtaBatchTx(
}> {
const ixs: TransactionInstruction[] = await Promise.all(
paramsBatch.map(async ({ mint, owner }) => {
return createAssociatedTokenAccountInstruction(
payer,
await ata(mint, owner),
owner,
mint
);
return createAssociatedTokenAccountInstruction(payer, await ata(mint, owner), owner, mint);
})
);
const hash = await connection.getLatestBlockhash();
Expand All @@ -193,17 +170,8 @@ export async function createAtaBatch(
invoker: Keypair | SignerWalletAdapter,
paramsBatch: AtaParams[]
): Promise<string> {
const { tx, hash } = await generateCreateAtaBatchTx(
connection,
invoker.publicKey!,
paramsBatch
);
const signature = await signAndExecuteTransaction(
connection,
invoker,
tx,
hash
);
const { tx, hash } = await generateCreateAtaBatchTx(connection, invoker.publicKey!, paramsBatch);
const signature = await signAndExecuteTransaction(connection, invoker, tx, hash);
return signature;
}

Expand All @@ -230,14 +198,7 @@ export async function checkOrCreateAtaBatch(
const response = await connection.getMultipleAccountsInfo(atas);
for (let i = 0; i < response.length; i++) {
if (!response[i]) {
ixs.push(
createAssociatedTokenAccountInstruction(
invoker.publicKey!,
atas[i],
owners[i],
mint
)
);
ixs.push(createAssociatedTokenAccountInstruction(invoker.publicKey!, atas[i], owners[i], mint));
}
}
return ixs;
Expand Down
4 changes: 1 addition & 3 deletions packages/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export const getBN = (value: number, decimals: number): BN => {
* @param {number} decimals - Number of decimals the token has.
*/
export const getNumberFromBN = (value: BN, decimals: number): number =>
value.gt(new BN(2 ** 53 - 1))
? value.div(new BN(10 ** decimals)).toNumber()
: value.toNumber() / 10 ** decimals;
value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;

/**
* Used to make on chain calls to the contract and wrap raised errors if any
Expand Down
1 change: 0 additions & 1 deletion packages/distributor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
"devDependencies": {
"@streamflow/eslint-config": "workspace:*",
"@streamflow/prettier-config": "workspace:*",
"@types/bn.js": "5.1.1",
"@types/jest": "29.2.4",
"date-fns": "2.28.0",
Expand Down
Loading

0 comments on commit ea107bf

Please sign in to comment.