We are struggling to find Rust or Motoko code that would allow us to receive ckBTC, convert it to ICP, and then to cycles so that we can create storage canisters for our users.
To turn ckBTC to ICP you have to go through an exchange, which I don’t know enough about. To turn ICP into cycles, you either want to use an exchange and then unwrap XTC (a form of wrapped cycles, see dank), or via the Cycles Minting Canister’s notify_top_up function. For some Rust code that shows how to use it you can look at how dfx does it.
We truly want to avoid going through an exchange, unless that exchange can be automated, and the conversion can be programmed instead of doing it manually.
Given that the NNS supports ICP and ckBTC natively we were hoping that this conversion, at least the one from ICP to cycles could be done fully on-chain without an exchange.
I would appreciate very much any news from @ICPSwap, @cakemaker1, or @bitbruce about this. We do not mind the exchange as long as it can be automated.
As a suggestion, please do make the IC support this feature natively, it would be a huge improvement on all other chains. As of now, if there is truly no way to do this, it’s bad news for any software that wants to automate the creation of canisters for users. We want to do precisely this, take ICP or ckBTC from users and automate the creation of canisters for them, but for this we need cycles, and a way to convert those coins into those cycles.
Thank you for the mark, @domwoe , and thanks for the response, @Severin
Hello, @josephgranata , I’d like to inquire further. Based on your requirements, there’s a native method for ICP <> Cycles integration. Severin already mentioned.
And well, so we just aim to implement the method for ckBTC <> ICP. This will involve utilizing ICPSwap’s interface to facilitate ckBTC swapping into ICP. The ultimate goal is to programmatically manage ckBTC <> ICP <> Cycles, and to create cycles storage canisters for your users.
Is this understanding correct? Will you intend to use a programmatic to interact with ICPSwap’s interface for the swap functionality? If this is accurate, I will provide this feedback to the team to discuss potential solutions.
Just in case there is any confusion: Going from ICP to cycles is a functionality that is implemented by the cycles minting canister, which is part of the NNS. That transition, during which cycles are created and ICP is burned, is thus provided by the system and described in the developer documentation.
The route from ckBTC is a bit more complicated since it wouldn’t make sense to burn the ckBTC. So there needs to be some transition from ckBTC to ICP in the process. As @domwoe indicated, you can use Sonic or ICPSwap to swap ckBTC to ICP. Or, as @Severin indicated, you can even save some bucks by going through XTC, but that’s probably a bit more complicated to automate.
Thanks for your answer, it does help, the docs you mention show how to use DFX to convert ICP to cycles and send them to a canister.
Now, where is the code to do this in Rust? How could we do this in a smart contract? DFX is coded in Rust, so for sure this is possible, how? If anyone can share where this is in the code, or an example that does it, it would help us a lot.
The reason we need to do this programmatically is that we intend to do the following:
A user pays us to get a canister in the IC, that canister will hold their files, and will be used mostly for storage. To simplify, let’s say that he pays using ICP.
Once we receive payment we must then convert that ICP into cycles and create, and initialize a canister for that user. That is why we need to automate the process, there could be way more users that we can manually handle, also the speed of software is much faster than a batch process.
About ckBTC, I do realize the process is much more complicated, and indeed we will need to use an exchange. I will continue that conversation with them.
I just re-read @Severin’s answer, yes I noticed he does link to a canister top-up function of the NNS, I will have to examine the code, but it seems it is possible to convert ICP to cycles ourselves… I do hope so. Just for clarity, I repost here an explanation of what we intend to do, and the reason for the need for this conversion from ICP and ckBTC to cycles:
1.- A user pays us to get a canister in the IC, that canister will hold their files, and will be used mostly for storage. To simplify, let’s say that he pays using ICP or ckBTC.
2.- Once we receive payment we must then convert that ICP into cycles and create, and initialize a canister for that user. That is why we need to automate the process, there could be way more users that we can manually handle, also the speed of software is much faster than a batch process.
For ICP I think we have a clue thanks to @Severin’s response.
For ckBTC or Bitcoin, how could we first tell our users to send the money to an address that we can somehow automate to pay your DAPP the fees for the exchange, and ultimately just have ICP for us to do the work for the user? Could you help us integrate with your exchange? Feel free to DM me, this is quite important for us.
How to do it exactly, how to automate the whole process, as I explain on this thread, we receive tokens from users, we then use those tokens to buy canisters for the user.
Automation with Sonic and ICSwap is easy to say, the problem is how, I am asking them here, and fortunately ICSwap is helping.
So, to address this, we will work on invoking the swap interface of ICPSwap through your program to convert ckBTC to ICP, correct?
We’ve sent you a private message containing the “Swap process and API interface” that ICPSwap uses for integration with other projects. Please check if it meets your needs for programmatic swap calls. If you encounter any other issues, feel free to reach out, and we can discuss and resolve them together. Thank you!
Here you have a code example for converting ICP to cycles.
This is based on the code that dfx uses to do the same thing. Note that the memo needs to be set correctly for the action you are trying to do and the “to” AccountIdentifier for the transaction to the CMC canister needs to have the correct subaccount.
And to explain how it works, you send ICP to the canister that holds this code, run the “top_up_self” with the correct args and the canister itself gets topped up. Which then could be used to spin up other canisters for example
the one we use is where we add cycles to the “parent” canister that is doing the call to the CMC canister and spin up a “child” canister with an other call (which subtracts cycles from the parent canister)
directly spin up a canister through the CMC by passing in the correct memo as seen in the link.
I do not have experience in directly spinning up a canister from the CMC, but it should be pretty straight forward.
I prefer the method I choose because there is a single canister that holds all the cycles and all child canisters spun up from the parent canister are on the same subnet, this is valuable if you want to do composite query calls for example.
can one do this with Motoko?
if no, then how can I send ICP to a running canister so that the canister can convert it to Cycles and ready to consume it?