Inspiration

Create a service powerd by ICP and nostr to allow swap satoshis between lightning testnetwork and rootstock testnetwork

What it does

The service uses ICP to send HTTP requests to an expressjs api that interacts with lightning network and rootstock testnetworks by using ECSDA API. The canister is responsible for getting users requests and triggering required actions like generation of invoices, payment of invoices and transactions at rootstock. The swap to rsk is done by paying an invoice generated by the service which contains the evm wallet address that is the receipt. After checking that the invoice has been paid, the canister triggers a transaction in a smart contract that updates the wallet balance. To claim those rbtcs, the wallet needs to call claimBTC() method in the smart contract. The swap to lightning network requires the user to generate an invoice to be payed (with any description) which is inserted in the smart contract by calling a payable swapToLighting method that requires rbtc to be sent alongside the invoice. Once triggered, the canister will read events emited by this method, checks if values are correct and trigger payment of those invoices by doing HTTP requests at the expressjs service created to interact with lightning. The API created exposes some necessary lightning methods and checks if requests comes from the canister address (by signatures of the invoices sent in the header) to perform payments.

How we built it

RSK Smart contract: stores invoices to be payed by service and users balances that can be updated by the canister; ICP canister: Interacts with rootstock and lightning by using an expressjs service; Expressjs: API to receive requests from the canister Nostr: Store and show lightning payments done by service and be a way of communication between service and users (by usage of other clients) Challenges we ran into At first instance it was hard to adapt to motoko language to do the ICP canister, we would like to do all lightning requests without doing expressjs api but we could not find a easy solution to encrypt necessary data in our canister (macaroon with permission to trigger payment) to perform requests in the test lightning node, we could do the canister work in local icp network but not in mainnet due "canister http responses being different across replicas, and no consensus was reached". After checking docs again we figure out ther we needed to add a "transform" method in the canister.

Accomplishments that we're proud of

After many tries we could do a demo swap using rsk testnet and lightning testnet, UI is using webln and ethersjs

What we learned

Motoko, usage of a test lightning network node, making app with webln and nostr alongside ethersjs

What's next for icp-canister-bridge

Improve current code performance, consider liquidity in rsk and lightning before allowing to make bridge. Allow users communicate with service's nostr npub from the UI. Make an way to replace invoices that have been expired or canceled and solve other issues we may not have noticed.

Built With

Share this project:

Updates