Skip to content

Commit

Permalink
fix(AssetMigration): minor refactor, delete unused migrateERC721 func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
TuDo1403 committed Dec 31, 2024
1 parent 2b4b55f commit f4b6504
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
13 changes: 8 additions & 5 deletions soldeer.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@

[[dependencies]]
name = "@fdk"
version = "0.3.1-beta"
source = "https://github.com/axieinfinity/foundry-deployment-kit/archive/refs/tags/v0.3.1-beta.zip"
url = "https://github.com/axieinfinity/foundry-deployment-kit/archive/refs/tags/v0.3.1-beta.zip"
checksum = "53cb5bf15abdc909d177c64e78070387af24ef39b2a4b408651836ac9de059c4"
integrity = "112ec6a82b06c190e027635779b052ca4fb4ee534c42407ea73a5009fd160d53"

[[dependencies]]
name = "@openzeppelin"
version = "4.7.3"
source = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.7.3.zip"
url = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.7.3.zip"
checksum = "e25b51f352864703de7b35e5030d63b38cbe4e8d61d7858f9ff9f77e18e370dd"
integrity = "22307e72fcd0d9ba18b894af6b2efdcdb4b4b51c1e7822cb2f0983ef348048d4"

[[dependencies]]
name = "@prb-math"
version = "4.0.3"
source = "https://soldeer-revisions.s3.amazonaws.com/@prb-math/4_0_3_16-06-2024_05:46:20_math.zip"
url = "https://soldeer-revisions.s3.amazonaws.com/@prb-math/4_0_3_16-06-2024_05:46:20_math.zip"
checksum = "adb64170354454d3acefa986481f7231af28a329a81484bf96e59523a831960c"
integrity = "c53ac540d39b9c677764d808c4e14351169157fdf0367933a5f27d530c404164"

[[dependencies]]
name = "@prb-test"
version = "0.6.5"
source = "https://soldeer-revisions.s3.amazonaws.com/@prb-test/0_6_5_22-01-2024_13:22:11_test.zip"
url = "https://soldeer-revisions.s3.amazonaws.com/@prb-test/0_6_5_22-01-2024_13:22:11_test.zip"
checksum = "d0b38a301d86f583a3053bfb437d12795cda5709bfe74ea21a27ffa339a2b8e8"
integrity = "3acca4e1569c805ab7f56cca79f45b413fbfba849bdbab8d41c751823bbb72ee"
47 changes: 12 additions & 35 deletions src/extensions/AssetMigration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ pragma solidity ^0.8.27;

import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";

import { HasProxyAdmin } from "src/extensions/collections/HasProxyAdmin.sol";

import { IWETH } from "src/interfaces/IWETH.sol";
import { ICCIPLiquidityContainer } from "src/interfaces/ext/ICCIPLiquidityContainer.sol";
import { ErrLengthMismatch, ErrEmptyArray } from "src/utils/CommonErrors.sol";

interface ICCIPLiquidityContainer {
function provideLiquidity(uint64 remoteChainSelector, uint256 amount) external;

function provideLiquidity(
uint256 amount
) external;
}

abstract contract AssetMigration is HasProxyAdmin, AccessControlEnumerable {
/// @dev Error when the token is not whitelisted before
error ErrNotWhitelistedToken(address token);
Expand All @@ -36,8 +28,11 @@ abstract contract AssetMigration is HasProxyAdmin, AccessControlEnumerable {
}

struct WhitelistInfo {
address recipient;
uint64 remoteChainSelector;
// CCIP Pool address
address _recipient;
// Remote chain selector
// If zero, will interact `_recipient` via ICCIPLiquidityContainer.provideLiquidity(uint256)
uint64 _remoteChainSelector;
}

/// @dev Emitted when recipients are whitelisted.
Expand Down Expand Up @@ -95,24 +90,6 @@ abstract contract AssetMigration is HasProxyAdmin, AccessControlEnumerable {
}
}

/**
* @dev Migrates the given ERC721 tokens to the specified addresses.
*
* Requirements:
* - The caller must be the migrator.
* - The length of the arrays must be the same.
* - The length of the arrays must not be zero.
* - If `recipient` is not whitelisted and not inherit from the `ERC721Receiver` interface, it will revert.
*/
function migrateERC721(address[] calldata tokens, uint256[] calldata ids) external onlyRole(_MIGRATOR_ROLE) validInput(_toUint256s(tokens), ids) {
uint256 length = tokens.length;

for (uint256 i; i < length; ++i) {
address recipient = _getRecipient(tokens[i]);
IERC721(tokens[i]).safeTransferFrom(address(this), recipient, ids[i]);
}
}

/**
* @dev Whitelists the recipients for the given tokens, with targeted remote chain selector.
*
Expand Down Expand Up @@ -143,8 +120,8 @@ abstract contract AssetMigration is HasProxyAdmin, AccessControlEnumerable {
for (uint256 i; i < length; ++i) {
WhitelistInfo storage $wlInfo = $._wlInfo[tokens[i]];

whitelisteds[i] = $wlInfo.recipient;
remoteChainSelectors[i] = $wlInfo.remoteChainSelector;
whitelisteds[i] = $wlInfo._recipient;
remoteChainSelectors[i] = $wlInfo._remoteChainSelector;
}
}

Expand Down Expand Up @@ -186,8 +163,8 @@ abstract contract AssetMigration is HasProxyAdmin, AccessControlEnumerable {
require(tokens[i] != _NATIVE_TOKEN_INDICATOR, ErrWhitelistWrappedTokenInstead());

WhitelistInfo storage $wlInfo = $._wlInfo[tokens[i]];
$wlInfo.recipient = recipients[i];
$wlInfo.remoteChainSelector = remoteChainSelectors[i];
$wlInfo._recipient = recipients[i];
$wlInfo._remoteChainSelector = remoteChainSelectors[i];
}

emit WhitelistUpdated(msg.sender, tokens, recipients, remoteChainSelectors);
Expand All @@ -200,7 +177,7 @@ abstract contract AssetMigration is HasProxyAdmin, AccessControlEnumerable {
function _getRecipient(
address token
) internal view returns (address recipient) {
recipient = _getAssetMigration()._wlInfo[token].recipient;
recipient = _getAssetMigration()._wlInfo[token]._recipient;
require(recipient != address(0x0), ErrNotWhitelistedToken(token));
}

Expand All @@ -210,7 +187,7 @@ abstract contract AssetMigration is HasProxyAdmin, AccessControlEnumerable {
function _getRemoteChainSelector(
address token
) internal view returns (uint64 remoteChainSelector) {
remoteChainSelector = _getAssetMigration()._wlInfo[token].remoteChainSelector;
remoteChainSelector = _getAssetMigration()._wlInfo[token]._remoteChainSelector;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/ext/ICCIPLiquidityContainer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

interface ICCIPLiquidityContainer {
function provideLiquidity(uint64 remoteChainSelector, uint256 amount) external;

function provideLiquidity(
uint256 amount
) external;
}

0 comments on commit f4b6504

Please sign in to comment.