Skip to content

Conversation

Copy link

Copilot AI commented Jan 4, 2026

Summary

  • Adds helper functions to wrap native SOL into wSOL and unwrap it back, eliminating manual ATA creation, SOL transfer, and syncNative instruction handling

Changes

Client Package (@solana/client)

  • createWsolHelper() with wrapSol() and unwrapSol() methods
  • Automatic ATA creation when wrapping, automatic account closure when unwrapping
  • Exported WSOL_MINT_ADDRESS constant (So11111111111111111111111111111111111111112)
  • Added wsol property to SolanaClient type and instance

React Hooks Package (@solana/react-hooks)

  • useWrapSol() hook with loading states, error handling, signature tracking
  • useUnwrapSol() hook with same capabilities

Documentation

  • Usage examples in both package READMEs

Usage

// Client
await client.wsol.wrapSol({
  amount: 100_000_000n,
  authority: wallet.session,
});

// React Hook
const { wrap, isWrapping, signature } = useWrapSol();
await wrap({ amount: 100_000_000n });

Testing

  • pnpm lint
  • pnpm test
  • pnpm build
Original prompt

This section details on the original issue you should resolve

<issue_title>Working with wSOL currently requires developers to manually:</issue_title>
<issue_description>### Summary

Summary
Add helper functions to easily wrap native SOL into Wrapped SOL (wSOL) and unwrap it back.

Problem to solve
Working with wSOL currently requires developers to manually:

Create an Associated Token Account for wSOL
Transfer SOL to that ATA using system program
Call syncNative instruction
This is complex for beginners and error-prone. Many DeFi protocols require SPL tokens, making wSOL wrapping a common need.

Proposed solution
Add helper functions to @solana/client:

wrapSol(amount: bigint) - Wraps native SOL into wSOL
unwrapSol(amount: bigint) - Unwraps wSOL back to native SOL

Could also be exposed as a React hook: useWrapSol()

Alternatives considered
Manual implementation using useSendTransaction - Works but requires deep Solana knowledge and multiple instructions
External tools/CLI - Doesn't integrate with the app's wallet connection
Third-party libraries - Adds dependencies and doesn't match the framework-kit patterns
Additional context
Discovered during DX testing of useSplToken. Testing wSOL transfers requires wrapping SOL first, but no built-in helper exists.

wSOL mint address: So11111111111111111111111111111111111111112

Problem to solve

jjj

Proposed solution

hg

Alternatives considered

jj

Additional context

jj</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@devloai
Copy link

devloai bot commented Jan 4, 2026

Unable to trigger custom agent "Code Reviewer"You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

Copilot AI changed the title [WIP] Add helper functions to wrap and unwrap wSOL Add wSOL wrap/unwrap helper functions and React hooks Jan 4, 2026
Copilot AI requested a review from 0xrinegade January 4, 2026 07:32
@0xrinegade
Copy link
Member

@copilot self-ask and refine, make sure everything is finished and well tested

Copy link
Author

Copilot AI commented Jan 4, 2026

@copilot self-ask and refine, make sure everything is finished and well tested

Self-Review Complete ✓

I've performed a comprehensive review of the wSOL implementation. Here's what I verified:

✅ Testing (100% Pass Rate)

  • 5 wSOL-specific unit tests: All passing
  • 224 total tests across all packages: All passing
  • Tests cover:
    • Wrapping SOL with wallet sessions
    • Wrapping SOL with transaction signers
    • Automatic ATA creation
    • Unwrapping wSOL
    • End-to-end transaction flows

✅ Type Safety

  • TypeScript compilation: ✓ No errors
  • Type definitions generated correctly
  • Proper exports in both packages

✅ Code Quality

  • Biome linting: ✓ No issues
  • Follows existing patterns (matches sol.ts, spl.ts, stake.ts)
  • Proper error handling and retry logic

✅ Build Verification

  • Client package builds successfully (67.67 KB)
  • React hooks package builds successfully (21.17 KB)
  • Type definitions generated correctly

✅ Documentation

  • Client README has complete usage examples
  • React hooks README has React component examples
  • JSDoc comments on all public APIs

✅ Exports

  • createWsolHelper, WSOL_MINT_ADDRESS, WsolHelper (client)
  • useWrapSol, useUnwrapSol (react-hooks)
  • All types properly exported

✅ Implementation Complete

  • ✓ wrapSol() - Creates ATA, transfers SOL, syncs native
  • ✓ unwrapSol() - Closes ATA, returns SOL
  • ✓ useWrapSol() hook with loading/error states
  • ✓ useUnwrapSol() hook with loading/error states
  • ✓ Automatic ATA handling
  • ✓ Support for wallet sessions and transaction signers
  • ✓ Commitment and lifetime support
  • ✓ Error retry on already-processed transactions

Everything is finished and well-tested. Ready for merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Working with wSOL currently requires developers to manually:

2 participants