Skip to content

Commit

Permalink
Set confirm options
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao committed Jun 10, 2024
1 parent 1938ef2 commit a9fd31c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
8 changes: 6 additions & 2 deletions anchor/src/client/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,15 @@ export class BaseClient {
}

getManager(): PublicKey {
return this.provider?.publicKey;
const managerPublicKey = this.provider?.publicKey;
if (!managerPublicKey) {
throw new Error("Manager public key cannot be retrieved from provider");
}
return managerPublicKey;
}

getManagerAta(mint: PublicKey, manager?: PublicKey): PublicKey {
return getAssociatedTokenAddressSync(mint, this.getManager() || manager);
return getAssociatedTokenAddressSync(mint, manager || this.getManager());
}

getWalletSigner(): Keypair {
Expand Down
5 changes: 3 additions & 2 deletions anchor/src/client/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ export class JupiterClient {
this.ixDataToTransactionInstruction(swapInstruction);

let inputAta;
if (this.base.getManager()) {
try {
inputAta = this.base.getManagerAta(new PublicKey(inputMint));
} else {
} catch (e) {
console.log("Cannot get manager ata:", e);
// When called from API, we cannot get manager from provider
// We need to pass the manager from client side
inputAta = this.base.getManagerAta(new PublicKey(inputMint), manager);
Expand Down
29 changes: 23 additions & 6 deletions anchor/tests/glam_api_tx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@ import {
Transaction,
sendAndConfirmTransaction,
PublicKey,
VersionedTransaction
VersionedTransaction,
ConfirmOptions
} from "@solana/web3.js";
import { GlamClient } from "../src/client";

// const API = "https://api.glam.systems";
const API = "http://localhost:8080";
/**
* This test suite is a demonstration of how to interact with the glam API.
*
* Before running this test suite, make sure you [provider] is correclty set up in Anchor.toml:
* 1) cluster: set to "mainnet-beta"
* 2) wallet: set to the path of the manager wallet
*
* To run the tests (optional to skip build, must skip deploy):
* anchor test --skip-build --skip-deploy
*/

const API = "https://api.glam.systems";
const wsol = new PublicKey("So11111111111111111111111111111111111111112");
const msol = new PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So");
const manager = "gLJHKPrZLGBiBZ33hFgZh6YnsEhTVxuRT17UCqNp6ff";
const fund = "4gAcSdfSAxVPcxj2Hi3AvKKViGat3iUysDD5ZzbqhDTk";
const confirmOptions: ConfirmOptions = {
commitment: "confirmed",
maxRetries: 3
};

describe("glam_api_tx", () => {
const glamClient = new GlamClient();
Expand All @@ -30,7 +45,8 @@ describe("glam_api_tx", () => {
const txId = await sendAndConfirmTransaction(
glamClient.provider.connection,
Transaction.from(Buffer.from(tx, "hex")),
[glamClient.getWalletSigner()]
[glamClient.getWalletSigner()],
confirmOptions
);
console.log("Wrap txId:", txId);
} catch (error) {
Expand All @@ -52,7 +68,8 @@ describe("glam_api_tx", () => {
const txId = await sendAndConfirmTransaction(
glamClient.provider.connection,
Transaction.from(Buffer.from(tx, "hex")),
[glamClient.getWalletSigner()]
[glamClient.getWalletSigner()],
confirmOptions
);
console.log("Unwrap txId:", txId);
} catch (error) {
Expand Down Expand Up @@ -86,7 +103,7 @@ describe("glam_api_tx", () => {
try {
const txId = await (
glamClient.provider as anchor.AnchorProvider
).sendAndConfirm(vTx, [glamClient.getWalletSigner()]);
).sendAndConfirm(vTx, [glamClient.getWalletSigner()], confirmOptions);
console.log("jupiter swap txId", txId);
} catch (error) {
console.error("Error", error);
Expand Down

0 comments on commit a9fd31c

Please sign in to comment.