We made a version of the assets canister from which you can withdraw cycles again.
Say you have a canister loaded with assets and the frontend is already in operation. You have accidentally topped it up with too many cycles. Or you realized that it can host for far longer with the given cycles than you need. How do you get a portion of the cycles out again? With the standard asset canister the only option is to overwrite the asset canister with a wallet canister, take the cycles out, install the asset canister again. Problem 1 is that you have an interruption in the service (the hosted frontend). Problem 2 is that you lose all the assets in the process and have to upload them again. But maybe you don’t have them anymore or they are large and uploading them again takes a long time.
Hence we provide a patched version of the asset canister which has functions to withdraw cycles. To this end we simply merged some functions from the cycle wallet into the asset canister. The functions are:
wallet_balance: () -> (record { amount: nat64 }) query;
wallet_balance128: () -> (record { amount: nat }) query;
wallet_send: (record { canister: principal; amount: nat64 }) -> (WalletResult);
wallet_send128: (record { canister: principal; amount: nat }) -> (WalletResult);
So taking cycles out means sending them to a wallet just like you would send cycles between two wallets. The functions are guarded to be called by canister-level controllers only. The Prepare/Manage/Commit permissions inside the asset canister code are irrelevant.
You can use this version of the asset canister in your project from the beginning. But you can also use it to get cycles out of an already up and running standard asset canister as follows: You upgrade the standard asset canister to the patched version. The assets will survive and hosting will not be interrupted. Then you can take the cycles out. When done you can either keep the patched version or downgrade to the standard asset canister again without interrupting the service.
The patched version is available in this PR: feat: add wallet_send, wallet_balance functions to asset canister by timohanke · Pull Request #5 · research-ag/sdk · GitHub
The fully build wasm binary and did file are in the src/distributed
directory of the branch here: sdk/src/distributed at hostybot-0.0.1 · research-ag/sdk · GitHub (assetstorage.wasm.gz and assetstorage.did).