An off-chain app handling BTC <-> Solana cross-chain swaps, utilizing SolLightning-program Solana on-chain program.
Principle of operation is described in depth here (for lightning network swaps) and here (for bitcoin on-chain swaps)
This software is made to be used in conjunction with client SDK.
NOTE: This implementation is still in alpha stage and MAY contain bugs and uncovered edge-cases, use at your own risk!
This app starts an http rest api server on port 4000 (by default). This is configurable by REST_PORT option in .env file.
REST_PORT="4001"
NOTE: Be sure to open this ports so client SDK can call the REST API.
- bitcoind node
- lnd node (Install instructions here)
- nodejs (requires v18 or higher)
- npm
- typescript
- Download latest version from here or build from source
- Use the configuration file bitcoin.conf
- Run the bitcoind with the configuration file:
bitcoind -conf=<path/to/bitcoin.conf>
- Wait till bitcoind finishes with IBD (initial block download), should take no more than a few hours for testnet on a regular PC with good internet connection
- Create a new wallet in bitcoind:
bitcoin-cli -testnet -conf=<path/to/bitcoin.conf> createwallet test true false "" false false true false
- Set the configured rpc ip, port, username and password in _.env file (not necessary if you used provided bitcoin.conf)
- Download latest version from here or build from source
- Use the provided configuration file lnd.conf
- Either place the lnd.conf file in ~/.lnd/ folder or run lnd with a --configfile argument:
lnd --configfile=<path/to/lnd.conf>
- Wait for the lnd to startup. It should then ask you to create a wallet.
- Create a new wallet with:
lncli -n testnet create
- Save password you used to create a wallet to some known file (e.g. ~/lnd-pass.txt), and add
wallet-unlock-password-file=<path/to/password-file>
option to lnd.conf, like so:[Application Options] tlsextraip=127.0.0.1 wallet-unlock-password-file=path/to/password-file
- Get the certificate by
base64 --wrap=0 ~/.lnd/tls.cert
and copy the output to LN_CERT field in _.env file - Get the admin macaroon by
base64 --wrap=0 ~/.lnd/data/chain/bitcoin/testnet/admin.macaroon
and copy the output to LN_MACAROON field in _.env file - Set the ip and port in the _.env (not needed if using provided lnd.conf)
- Get the bitcoin address
lncli -n testnet newaddress p2wkh
- Get some testnet bitcoin to that address through one of the faucets:
- Connect to a well connected bitcoin lightning node, you can find the list here. Pick a node and copy its connection string (should look like so: 038863cf8ab91046230f561cd5b386cbff8309fa02e3f0c3ed161a3aeb64a643b9@203.132.94.196:9735). Then use
lncli -n testnet connect <connection string>
to connect to that node. - Open a channel with the node you connected to. Take the public key from the connection string (the part before '@', e.g.: 038863cf8ab91046230f561cd5b386cbff8309fa02e3f0c3ed161a3aeb64a643b9). Open a channel with
lncli -n testnet openchannel <node public key> <amount> <push_amount>
. Be sure to push half of your channel's balance to the other node so you can receive, e.g.lncli -n testnet openchannel <node public key> 100000 50000
- Wait for the channel to be established, you can monitor pending channels with:
lncli -n testnet pendingchannels
Instructions available here. Skip steps 2.-4. as you already have bitcoind setup and running.
- Install necessary npm packages:
npm install
- Install typescript:
npm install -g typescript
- Compile to javascript:
tsc
- Rename _.env file to .env
- Generate a new solana keypair:
npm run genKey
- Airdrop some devnet tokens to your newly generated solana wallet:
npm run airdrop
- Create the WBTC, USDC and USDT tokens on devnet:
npm run createToken
- Mint some WBTC/USDC/USDT token to your new keypair:
npm run mint <WBTC/USDC/USDT> <amount to mint in base units>
- You can also mint some WBTC/USDC/USDT tokens to your phantom wallet:
npm run mint <WBTC/USDC/USDT> <amount to mint in base units> <wallet address>
- Deposit your WBTC/USDC/USDT to the program
npm run deposit <WBTC/USDC/USDT> <amount to deposit in base units>
- Be sure that bitcoind, lnd and btcrelay are running before starting the app.
- Run the app with:
npm start