Skip to content

Commit

Permalink
cli: clean up fund usage (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao authored Feb 1, 2025
1 parent 6ea81a8 commit 062dcaa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/post_commit_anchor_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build
run: cd anchor ; anchor test || anchor test -- --tools-version v1.43
- name: Build and run tests
run: pnpm run anchor-test
14 changes: 4 additions & 10 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ This project was generated with the [create-solana-dapp](https://github.com/sola
### Prerequisites

- Node v20.11.0 or higher
- Pnpm v8.15.1 or higher
- Pnpm v9.1.2 or higher
- Rust v1.75.0 or higher
- Anchor CLI 0.29.0 or higher
- Solana CLI 1.18.7
- Anchor CLI 0.30.1
- Solana CLI 1.18.23

Recommended:

```shell
sh -c "$(curl -sSfL https://release.solana.com/v1.18.7/install)"
sh -c "$(curl -sSfL https://release.anza.xyz/v1.18.23/install)"
```

### Installation
Expand Down Expand Up @@ -72,9 +72,3 @@ pnpm run anchor-test
```shell
pnpm run dev
```

### Start the api server

```shell
pnpm run api-serve
```
3 changes: 2 additions & 1 deletion anchor/src/client/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ export class BaseClient {
}

isPhantom(): boolean {
if (!isBrowser) return false;
// Phantom automatically estimates fees
// https://docs.phantom.app/developer-powertools/solana-priority-fees#how-phantom-applies-priority-fees-to-dapp-transactions
return (
//@ts-ignore
// @ts-ignore
window?.phantom?.solana?.isPhantom && window?.phantom?.solana?.isConnected
);
}
Expand Down
25 changes: 16 additions & 9 deletions anchor/tests/glam_crud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,25 @@ describe("glam_crud", () => {
console.error(e);
throw e;
}
let StateModel = await glamClient.fetchState(statePda);
expect(StateModel.delegateAcls?.length).toEqual(1);
expect(StateModel.delegateAcls![0].pubkey).toEqual(key1.publicKey);

// key1 now has wSolWrap permission, use key1 to wrap some SOL
await glamClientCustomWallet.wsol.wrap(statePda, new BN(30_000_000));
/*
let stateModel = await glamClient.fetchState(statePda);
expect(stateModel.delegateAcls?.length).toEqual(1);
expect(stateModel.delegateAcls![0].pubkey).toEqual(key1.publicKey);
*/

// key1 doesn't have wSolUnwrap permission, unwrap should fail
try {
const txId = await glamClientCustomWallet.wsol.unwrap(statePda);
console.log("Unwrap:", txId);
expect(txId).toBeUndefined();
// key1 now has wSolWrap permission, use key1 to wrap some SOL
let txSig = await glamClientCustomWallet.wsol.wrap(
statePda,
new BN(30_000_000),
);
console.log("Wrap:", txSig);

// key1 doesn't have wSolUnwrap permission, unwrap should fail
txSig = await glamClientCustomWallet.wsol.unwrap(statePda);
console.log("Unwrap:", txSig);
expect(txSig).toBeUndefined();
} catch (e) {
expect((e as GlamError).message).toEqual("Signer is not authorized.");
}
Expand Down
8 changes: 4 additions & 4 deletions cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ const vote = program
: null;

if (!statePda) {
console.error("Error: fund not set");
console.error("GLAM state not set");
process.exit(1);
}

Expand Down Expand Up @@ -656,7 +656,7 @@ program

program
.command("balances")
.description("Get fund balances")
.description("Get balances")
.option(
"-a, --all",
"Show all assets including token accounts with 0 balance",
Expand Down Expand Up @@ -708,7 +708,7 @@ program

program
.command("swap <from> <to> <amount>")
.description("Swap fund assets")
.description("Swap assets held in the vault")
.option("-m, --max-accounts <num>", "Specify max accounts allowed")
.option("-s, --slippage-bps <bps>", "Specify slippage bps")
.option("-d, --only-direct-routes", "Direct routes only")
Expand Down Expand Up @@ -951,7 +951,7 @@ lst

//
// Run the CLI in development mode as follows:
// npx nx run cli:dev -- --args="fund view <pubkey>"
// npx nx run cli:dev -- --args="view <pubkey>"
//
if (process.env.NODE_ENV === "development") {
const argv = [
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"anchor": "nx run anchor:anchor",
"anchor-build": "nx run anchor:anchor build",
"anchor-localnet": "nx run anchor:anchor localnet",
"anchor-test": "cd anchor && anchor test",
"anchor-test-detach": "cd anchor && anchor test --detach",
"anchor-test": "nx run anchor:anchor test",
"build": "nx run playground:build",
"dev": "nx run playground:dev",
"pg-dev": "nx run playground:dev",
Expand Down

0 comments on commit 062dcaa

Please sign in to comment.