Skip to content

Instantly share code, notes, and snippets.

@davidp94
Created October 20, 2024 13:06
Show Gist options
  • Save davidp94/8fb8b468628b1b2d1366f108a86d1a7b to your computer and use it in GitHub Desktop.
Save davidp94/8fb8b468628b1b2d1366f108a86d1a7b to your computer and use it in GitHub Desktop.
Guide to migration XDEFI to CTRL for Gnosis Safe

Guide for XDEFI to CTRL Migration for Gnosis Safe User

This guide outlines two methods for migrating your XDEFI tokens to CTRL:

  1. Method 1: Using a Gnosis Safe or other multi-signature wallet for a manual batch transaction.
  2. Method 2: An easier alternative that involves sending tokens to a personal wallet and using the migration app.

Method 1: Batch Transaction Using Safe

In Method 1, you will manually create a batched transaction using a safe (such as Gnosis Safe) to approve and then migrate XDEFI tokens to CTRL.

Step 1: Approve the Migration Contract to Spend XDEFI Tokens

The first step is to approve the migration contract to spend your XDEFI tokens. This is necessary because the migration contract will transfer your XDEFI tokens and issue CTRL tokens in return.

Function to Call:
  • approve(address spender, uint256 amount)
Contract to Call:
  • XDEFI Token Contract: 0x72b886d09c117654ab7da13a14d603001de0b777
Parameters:
  • spender: The migration contract address (0x7c2230a01df134a632afddcec962bf1e9eb659ff).
  • amount: The number of XDEFI tokens you wish to migrate. This should be specified with 18 decimal places. For example, to approve 1000 XDEFI tokens, pass 1000000000000000000000 (since XDEFI has 18 decimal places).
Example Transaction:
approve(0x7c2230a01df134a632afddcec962bf1e9eb659ff, 1000000000000000000000);

This transaction grants the migration contract permission to transfer 1000 XDEFI tokens from your safe.

Batching the Transaction:

When using your safe, ensure that this approval transaction is the first part of a batch that will include the migration call next.


Step 2: Call the migrate(...) Function

Once the approval transaction is prepared, the next step is to call the migrate(...) function to trigger the migration.

Function to Call:
  • migrate(uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
Contract to Call:
  • Migration Contract: 0x7c2230a01df134a632afddcec962bf1e9eb659ff
Parameters:
  • amount: The same amount you approved (e.g., 1000000000000000000000).
  • deadline: A Unix timestamp in the future (e.g., 1700000000 for a safe future time).
  • v, r, s: These are components of the EIP-2612 permit signature. Since you've already pre-approved the tokens using the approve function, you can use dummy values:
    • v: 0
    • r: 0x0000000000000000000000000000000000000000000000000000000000000000
    • s: 0x0000000000000000000000000000000000000000000000000000000000000000
Example Transaction:
migrate(1000000000000000000000, 1700000000, 0, 0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000);

This transaction migrates 1000 XDEFI tokens from your safe to the migration contract, and the CTRL tokens are automatically sent back to your safe address.


Step 3: Submit the Batched Safe Transaction

Now that both the approval and migration transactions are prepared, batch them together in your safe. The approval transaction must happen first, followed by the migration transaction.

Once batched and signed by the necessary safe signers, submit the transaction.


Step 4: Verify the Migration

Once the batched transaction has been confirmed:

  1. Check Etherscan: Verify the transactions on Etherscan by reviewing the approval and migration calls.
  2. Check Your CTRL Balance: After the migration transaction is complete, your safe should receive the corresponding amount of CTRL tokens.

Handling Errors in Simulations

If you run a simulation using a tool like Tenderly, you may encounter partial errors related to the signature components (v, r, s) during the migrate function call. This is normal because you are using dummy values. The migration will still work correctly on-chain due to the earlier approval.


Method 2: Easier Alternative Using Migration App

If you'd like an easier and more user-friendly method for migrating your tokens, you can use a personal hardware wallet or hot wallet to interact with the migration app.

Step 1: Send XDEFI Tokens to a Hardware or Hot Wallet

To avoid the complexity of batching transactions, you can simply send your XDEFI tokens from your safe to a personal wallet (e.g., a hardware wallet like Ledger or a hot wallet like MetaMask).

  1. From your Safe, send your XDEFI tokens to your personal wallet.
  2. Ensure the wallet has enough ETH for gas fees during the migration process.

Step 2: Use the CTRL Migration App

Once your XDEFI tokens are in your personal wallet:

  1. Go to the Migration App: Visit CTRL’s Migration App.
  2. Connect Your Wallet: Connect your hardware or hot wallet containing the XDEFI tokens.
  3. Migrate: Follow the on-screen instructions to migrate your XDEFI to CTRL. The migration app will guide you through the process, including any necessary approvals and migration steps.

Step 3: Send the CTRL Tokens Back to Your Safe

After the migration is complete and your wallet has received the CTRL tokens, you can send them back to your safe:

  1. Send CTRL Tokens: Use your hardware or hot wallet to send the newly received CTRL tokens back to your safe address.
  2. Verify on Etherscan: Once the transaction is confirmed, you can verify that your safe now holds the CTRL tokens.

Conclusion

  • Method 1 involves manually handling the migration process by creating a batched transaction from your safe, which includes the approval and migration steps. This method keeps everything within the safe environment.
  • Method 2 is an easier, user-friendly alternative where you move your XDEFI tokens to a personal wallet, use the migration app, and then transfer the CTRL tokens back to your safe.

Both methods are valid, and you can choose the one that best suits your comfort level with handling multi-signature wallets and smart contract interactions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment