How to migrate state and balances of contract after redeploy?

Hey, guys, I have a question.
I have a landings protocol called swayland, for example, I found a small bug in it or was able to optimize a piece of code that it uses less gas, please tell me how to redesign it correctly so that all users retain their deposits and debts so that the state and balance of the application remain the same.

It’s my understanding that this is not currently possible, you would have had to have created some sort of novel upgradable proxy contract

1 Like

I’ve thought about it, I’m not sure it’s the only solution, sir.
How about indexing the contract state with indexer and migrating it with StorageConfiguration when redeploying it?

let storage_configuration = StorageConfiguration::from(vec![storage_slot]);

https://rust.fuel.network/v0.42.0/getting-started/contracts.html

@diyahir is right. You essentially have two choices: either develop an upgradable smart contract that maintains its state, or redeploy a new contract and facilitate a migration process for your users.

Choosing to redeploy every time with an indexed state involves significant trade-offs. You’ll face high gas costs and repeated instances of state bloat every time you choose to redeploy this way. Additionally, this approach increases the potential for errors and security vulnerabilities due to the complexities in state manipulation.

For instance, consider the challenge of ensuring all users withdraw their funds from the old contract before launching the new one. It’s virtually impossible. Users who fail to migrate in time could end up with duplicated balances in both the old and new contracts.

It’s much more efficient and safer to use one of the two initial options to avoid these complications.

1 Like

I want to add as of now, our compiler and tooling infrastructure does not fully support LDC. However, we’re actively working on integrating this feature and aim to have it available within this quarter. :slightly_smiling_face:

1 Like

Got it, sir. Thank you.
We’ll make a proxy :saluting_face:

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.