Skip to content

Commit

Permalink
✨ Add direct transfer to the wallet migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Nov 10, 2023
1 parent 6d406e0 commit bf7fc64
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
15 changes: 8 additions & 7 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ RewarderTest:test_pay_PayedFraktions_ok() (gas: 405426)
RewarderTest:test_pay_TooLargeReward_ko() (gas: 231010)
VestingWalletFactoryTest:test_canBeDeployedAndInit_ok() (gas: 2093328)
VestingWalletFactoryTest:test_initialize_InitTwice_ko() (gas: 17926)
WalletMigratorTest:test_claimAllFoundsForUser_ok() (gas: 359098)
WalletMigratorTest:test_claimAllFoundsForUser_ok() (gas: 359120)
WalletMigratorTest:test_claimAllFounds_ok() (gas: 359246)
WalletMigratorTest:test_fullMigrationForUser_ok() (gas: 634767)
WalletMigratorTest:test_fullMigration_ok() (gas: 634068)
WalletMigratorTest:test_migrateFrationsForUser_ok() (gas: 269269)
WalletMigratorTest:test_migrateFrations_ok() (gas: 269384)
WalletMigratorTest:test_migrateFrkForUser_ok() (gas: 144705)
WalletMigratorTest:test_migrateFrk_ok() (gas: 144902)
WalletMigratorTest:test_fullMigrationForUserDirect_ok() (gas: 568197)
WalletMigratorTest:test_fullMigrationForUser_ok() (gas: 634824)
WalletMigratorTest:test_fullMigration_ok() (gas: 634148)
WalletMigratorTest:test_migrateFrationsForUser_ok() (gas: 269287)
WalletMigratorTest:test_migrateFrations_ok() (gas: 269401)
WalletMigratorTest:test_migrateFrkForUser_ok() (gas: 144729)
WalletMigratorTest:test_migrateFrk_ok() (gas: 144949)
11 changes: 11 additions & 0 deletions contracts/wallets/WalletMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ contract WalletMigrator is Multicallable {
_migrateFrk(user, newWallet, deadline, v, r, s);
}

/// @dev Migrate all the FRK of the current user to the `newWallet`
function migrateFrkForUserDirect(address user, address newWallet) external {
address(frkToken).safeTransferFrom(user, newWallet, frkToken.balanceOf(user));
}

/// @dev Migrate all the frk of the `user` to the `newWallet`, using EIP-2612 signature as approval
function _migrateFrk(address user, address newWallet, uint256 deadline, uint8 v, bytes32 r, bytes32 s) internal {
// We use the signature to allow the transfer all the FRK of the user
Expand Down Expand Up @@ -131,6 +136,12 @@ contract WalletMigrator is Multicallable {
_migrateFraktions(user, newWallet, deadline, v, r, s, ids);
}

/// @dev Migrate all the fraktions to the `newWallet`at once
function migrateFraktionsForUserDirect(address user, address newWallet, uint256[] calldata ids) external {
// And finally, we transfer all the FRK of the user to the new wallet
fraktionTokens.transferAllFrom(user, newWallet, ids);
}

/// @dev Migrate all the fraktions to the `newWallet`at once
function _migrateFraktions(
address user,
Expand Down
38 changes: 38 additions & 0 deletions script/DeployWalletMigrator.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: GNU GPLv3
pragma solidity 0.8.21;

import "forge-std/Script.sol";
import "forge-std/console.sol";
import { UpgradeScript } from "./utils/UpgradeScript.s.sol";
import { MonoPool } from "swap-pool/MonoPool.sol";
import { WalletMigrator } from "contracts/wallets/WalletMigrator.sol";

contract DeployWalletMigrator is UpgradeScript {
/// @dev The basis point for the pool to deploy
uint256 private constant BPS = 100;

function run() external {
// Get the current addresses
UpgradeScript.ContractProxyAddresses memory addresses = _currentProxyAddresses();

// Deploy the migrator contract
WalletMigrator walletMigrator = _deployMigrator(addresses);
console.log("Migrator deployed to %s", address(walletMigrator));
}

/// @dev Deploy the migrator contract
function _deployMigrator(UpgradeScript.ContractProxyAddresses memory addresses)
internal
deployerBroadcast
returns (WalletMigrator)
{
// Build the wallet migrator we will test
return new WalletMigrator(
addresses.frakToken,
addresses.fraktionTokens,
addresses.rewarder,
addresses.contentPool,
addresses.referralPool
);
}
}
33 changes: 33 additions & 0 deletions test/wallets/WalletMigrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,39 @@ contract WalletMigratorTest is FrakTest {
_assertFraktionTransfered();
}

function test_fullMigrationForUserDirect_ok() public withUserReward withFrk(user, 10 ether) withUserFraktions {
bytes[] memory migrationCallData = new bytes[](3);

// Allow the wallet migrator to move founds for the user
vm.prank(user);
frakToken.approve(address(walletMigrator), type(uint256).max);

// Allow the wallet migrator on the fraktions
vm.prank(user);
fraktionTokens.setApprovalForAll(address(walletMigrator), true);

// Build the claim function data
migrationCallData[0] = abi.encodeWithSelector(WalletMigrator.claimAllFoundsForUser.selector, user);

// Generate signature for frk transfer & encode function data
migrationCallData[1] = abi.encodeWithSelector(WalletMigrator.migrateFrkForUserDirect.selector, user, targetUser);

// Generate signature for fraktion transfer & encode function data
migrationCallData[2] = abi.encodeWithSelector(
WalletMigrator.migrateFraktionsForUserDirect.selector, user, targetUser, _allFraktionsIds()
);

// Perform the multicall
walletMigrator.multicall(migrationCallData);

// Ensure the user has no frk remaining
assertEq(frakToken.balanceOf(user), 0);

// Ensure the user has no more reward and fraktions
_assertRewardClaimed();
_assertFraktionTransfered();
}

/* -------------------------------------------------------------------------- */
/* Internal helper functions */
/* -------------------------------------------------------------------------- */
Expand Down

0 comments on commit bf7fc64

Please sign in to comment.