import {
PublicKey,
Keypair,
Transaction,
Connection,
SystemProgram,
} from "@solana/web3.js";
import {
TokenSwap,
TOKEN_SWAP_PROGRAM_ID,
TokenSwapLayout,
CurveType,
} from "@solana/spl-token-swap";
import createAccount from "../createAccountToken";
import createTokenFunction from "../createTokenFunction";
import GetAccount from "../getAssociatedTokenAddress";
import { tokenAccountPool, tokenSwapStateAccount } from "../../utils/constants";
import { getAccount, TOKEN_PROGRAM_ID } from "@solana/spl-token";
const createSwap = async (
connection: Connection,
payer: PublicKey,
tokenA: PublicKey,
tokenB: PublicKey
) => {
// number 1 -> create account that cointain information on swap
const transaction = new Transaction();
const tokenSwapAccount = Keypair.generate();
const rent = await TokenSwap.getMinBalanceRentForExemptTokenSwap(connection);
const tokenSwapStateAccountInstruction = await SystemProgram.createAccount({
newAccountPubkey: tokenSwapAccount.publicKey,
fromPubkey: payer,
lamports: rent,
space: TokenSwapLayout.span,
programId: TOKEN_SWAP_PROGRAM_ID,
});
transaction.add(tokenSwapStateAccountInstruction);
/// ==================================
// number 2 -> find PDA
const [swapAuthority, bump] = await PublicKey.findProgramAddress(
[tokenSwapAccount.publicKey.toBuffer()],
TOKEN_SWAP_PROGRAM_ID
);
// number 3 -> create token accounts for Token A and Token B
const tokenAAccount = await createAccount(swapAuthority, tokenA, true);
const tokenBAccount = await createAccount(swapAuthority, tokenB, true);
transaction.add(tokenAAccount, tokenBAccount);
// number 4 -> create token that rappresenting receipt of deposit (LP token)
const { transaction: poolTokenMintTX, mintAccountKeypair: poolTokenMint } =
await createTokenFunction(
"non serve",
connection,
payer,
swapAuthority,
null,
2
);
transaction.add(poolTokenMintTX);
// number 5 -> create Account that contain miter token before send to user
const accountPoolTokenMint = await createAccount(
payer,
poolTokenMint.publicKey
);
transaction.add(accountPoolTokenMint);
// number 6 -> create Pool Token Fee Account (in this case is a specific serum account (still serum in this moment? ????))
const feeOwner = new PublicKey(
"HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN"
);
const poolTokenFeeAccount = await createAccount(
feeOwner,
poolTokenMint.publicKey
);
transaction.add(poolTokenFeeAccount);
//const _tokenSwapAccount = await getAccount(connection,poolTokenMint.publicKey)
const poolAccountTokenA = await GetAccount(connection, swapAuthority, tokenA);
const poolAccountTokenB = await GetAccount(connection, swapAuthority, tokenB);
const accountFeeOwner = await GetAccount(
connection,
feeOwner,
poolTokenMint.publicKey
);
if (!poolAccountTokenA || !poolAccountTokenB || !accountFeeOwner) {
return;
}
const createSwapInstruction = TokenSwap.createInitSwapInstruction(
tokenSwapAccount.publicKey, **** error *******
swapAuthority,
poolAccountTokenA,
poolAccountTokenB,
poolTokenMint.publicKey,
accountFeeOwner,
poolTokenMint.publicKey,
TOKEN_PROGRAM_ID, // Token Program ID
TOKEN_SWAP_PROGRAM_ID, // Token Swap Program ID
0, // Trade fee numerator
10000, // Trade fee denominator
5, // Owner trade fee numerator
10000, // Owner trade fee denominator
0, // Owner withdraw fee numerator
0, // Owner withdraw fee denominator
20, // Host fee numerator
100, // Host fee denominator
CurveType.ConstantProduct // Curve type
);
transaction.add(createSwapInstruction);
return transaction;
};
export default createSwap;
ERROR _ L'argomento di tipo 'PublicKey' non è assegnabile al parametro di tipo 'Account'. Nel tipo 'PublicKey' mancano le proprietà seguenti del tipo 'Account': publicKey,secretKey
translate
The argument of type 'PublicKey' is not assignable to the parameter of type 'Account'. Type 'PublicKey' is missing the following properties of type 'Account': publicKey,secretKey
PublicKey
instead of anAccount
somewhere