Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 79 additions & 79 deletions .github/workflows/typescript-tests.yml
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
name: TypeScript

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SOLANA_CLI_VERSION: "2.1.21"
NODE_VERSION: "22"
SOLANA_CLI_VERSION: "2.1.21"
NODE_VERSION: "22"

jobs:
typescript-tests:
name: TypeScript Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Cache Solana CLI tools
uses: actions/cache@v4
with:
path: |
~/.cache/solana/
~/.local/share/solana/
key: solana-cli-${{ runner.os }}-${{ env.SOLANA_CLI_VERSION }}

- name: Install Solana CLI tools
run: |
sh -c "$(curl -sSfL https://release.anza.xyz/v${{ env.SOLANA_CLI_VERSION }}/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH

- name: Install Light CLI
run: npm install -g @lightprotocol/zk-compression-cli@alpha

- name: Install Rust (for Photon)
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
cache: false

- name: Cache Photon indexer
id: cache-photon
uses: actions/cache@v4
with:
path: ~/.cargo/bin/photon
key: photon-${{ runner.os }}-ac7df6c388db847b7693a7a1cb766a7c9d7809b5

- name: Install Photon indexer
if: steps.cache-photon.outputs.cache-hit != 'true'
run: cargo install --git https://github.com/lightprotocol/photon.git --rev ac7df6c388db847b7693a7a1cb766a7c9d7809b5 --locked
env:
RUSTFLAGS: "-A dead-code"

- name: Generate keypair
run: solana-keygen new --no-bip39-passphrase

- name: Install dependencies
working-directory: typescript-client
run: npm install

- name: Start test validator
run: |
light test-validator &
for i in $(seq 1 60); do
curl -s http://127.0.0.1:8784/health && break
sleep 2
done

- name: Run actions
working-directory: typescript-client
run: npm run test:actions

- name: Run instructions
working-directory: typescript-client
run: npm run test:instructions
typescript-tests:
name: TypeScript Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Cache Solana CLI tools
uses: actions/cache@v4
with:
path: |
~/.cache/solana/
~/.local/share/solana/
key: solana-cli-${{ runner.os }}-${{ env.SOLANA_CLI_VERSION }}

- name: Install Solana CLI tools
run: |
sh -c "$(curl -sSfL https://release.anza.xyz/v${{ env.SOLANA_CLI_VERSION }}/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH

- name: Install Light CLI
run: npm install -g @lightprotocol/zk-compression-cli@beta

- name: Install Rust (for Photon)
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
cache: false

- name: Cache Photon indexer
id: cache-photon
uses: actions/cache@v4
with:
path: ~/.cargo/bin/photon
key: photon-${{ runner.os }}-ac7df6c388db847b7693a7a1cb766a7c9d7809b5

- name: Install Photon indexer
if: steps.cache-photon.outputs.cache-hit != 'true'
run: cargo install --git https://github.com/lightprotocol/photon.git --rev ac7df6c388db847b7693a7a1cb766a7c9d7809b5 --locked
env:
RUSTFLAGS: "-A dead-code"

- name: Generate keypair
run: solana-keygen new --no-bip39-passphrase

- name: Install dependencies
working-directory: typescript-client
run: npm install

- name: Start test validator
run: |
light test-validator &
for i in $(seq 1 60); do
curl -s http://127.0.0.1:8784/health && break
sleep 2
done

- name: Run actions
working-directory: typescript-client
run: npm run test:actions

- name: Run instructions
working-directory: typescript-client
run: npm run test:instructions
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
cli/accounts
README.html
README_files/

**/.surfpool
.surfpool
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"toolkit:payments": "npm run -w toolkits/payments-and-wallets"
},
"dependencies": {
"@lightprotocol/compressed-token": "^0.23.0-beta.5",
"@lightprotocol/stateless.js": "^0.23.0-beta.5",
"@lightprotocol/compressed-token": "^0.23.0-beta.8",
"@lightprotocol/stateless.js": "^0.23.0-beta.8",
"@solana/spl-token": "^0.4.13",
"@solana/web3.js": "1.98.4",
"dotenv": "^16.5.0"
Expand Down
119 changes: 51 additions & 68 deletions toolkits/payments-and-wallets/comparison-spl-light.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ata = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mint,
recipient,
recipient
);
// Share ata.address with sender

Expand All @@ -70,8 +70,8 @@ const tx = new Transaction().add(
payer.publicKey,
ata,
recipient,
mint,
),
mint
)
);
```

Expand Down Expand Up @@ -102,15 +102,15 @@ const tx = new Transaction().add(
ata,
recipient,
mint,
LIGHT_TOKEN_PROGRAM_ID,
LIGHT_TOKEN_PROGRAM_ID
),
...(await createLoadAtaInstructions(
rpc,
ata,
recipient,
mint,
payer.publicKey,
)),
payer.publicKey
))
);
```

Expand All @@ -134,7 +134,7 @@ await transfer(
destinationAta,
owner,
amount,
decimals,
decimals
);
```

Expand All @@ -156,55 +156,50 @@ const tx = new Transaction().add(
sourceAta,
destinationAta,
owner.publicKey,
amount,
),
amount
)
);
```

**Light:**

```typescript
const sourceAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);
const destinationAta = getAssociatedTokenAddressInterface(mint, recipient);

await transferInterface(
rpc,
payer,
sourceAta,
mint,
destinationAta,
owner,
amount,
);
await transferInterface(rpc, payer, sourceAta, mint, recipient, owner, amount);
```

**Light:**
**Light (instruction-level):**

```typescript
import { Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
import {
createLoadAtaInstructions,
createTransferInterfaceInstruction,
getAssociatedTokenAddressInterface,
createTransferInterfaceInstructions,
sliceLast,
} from "@lightprotocol/compressed-token/unified";

const sourceAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);
const destinationAta = getAssociatedTokenAddressInterface(mint, recipient);

const tx = new Transaction().add(
...(await createLoadAtaInstructions(
rpc,
sourceAta,
owner.publicKey,
mint,
payer.publicKey,
)),
createTransferInterfaceInstruction(
sourceAta,
destinationAta,
owner.publicKey,
amount,
),
const batches = await createTransferInterfaceInstructions(
rpc,
payer.publicKey,
mint,
amount,
owner.publicKey,
recipient
);
const { rest: loadBatches, last: transferBatch } = sliceLast(batches);

await Promise.all(
loadBatches.map((batch) =>
sendAndConfirmTransaction(rpc, new Transaction().add(...batch), [
payer,
owner,
])
)
);
await sendAndConfirmTransaction(rpc, new Transaction().add(...transferBatch), [
payer,
owner,
]);
```

To ensure your recipient's ATA exists you can prepend an idempotent creation instruction in the same atomic transaction:
Expand All @@ -222,7 +217,7 @@ const createAtaIx = createAssociatedTokenAccountIdempotentInstruction(
payer.publicKey,
destinationAta,
recipient,
mint,
mint
);

new Transaction().add(createAtaIx, transferIx);
Expand All @@ -243,7 +238,7 @@ const createAtaIx = createAssociatedTokenAccountInterfaceIdempotentInstruction(
destinationAta,
recipient,
mint,
LIGHT_TOKEN_PROGRAM_ID,
LIGHT_TOKEN_PROGRAM_ID
);

new Transaction().add(createAtaIx, transferIx);
Expand Down Expand Up @@ -323,34 +318,22 @@ await unwrap(rpc, payer, splAta, owner, mint, amount);

```typescript
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
import {
createLoadAtaInstructions,
createUnwrapInstruction,
getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-token/unified";
import { getSplInterfaceInfos } from "@lightprotocol/compressed-token";
import { createUnwrapInstructions } from "@lightprotocol/compressed-token/unified";

const lightTokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);
const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey);

const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint);
const splInterfaceInfo = splInterfaceInfos.find((i) => i.isInitialized);

const tx = new Transaction().add(
...(await createLoadAtaInstructions(
rpc,
lightTokenAta,
owner.publicKey,
mint,
payer.publicKey,
)),
createUnwrapInstruction(
lightTokenAta,
splAta,
owner.publicKey,
mint,
amount,
splInterfaceInfo,
),
// Handles loading cold state + unwrapping in one go.
const instructions = await createUnwrapInstructions(
rpc,
splAta,
owner.publicKey,
mint,
amount,
payer.publicKey
);

for (const ixs of instructions) {
const tx = new Transaction().add(...ixs);
await sendAndConfirmTransaction(rpc, tx, [payer, owner]);
}
```
Loading
Loading