Skip to content

Commit

Permalink
remove from assets library
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Apr 12, 2024
1 parent c0d9b6b commit 42120cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
22 changes: 10 additions & 12 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,21 @@ library Assets {
IERC20(token).safeTransferFrom(sender, agent, amount);
}

function sendTokenCosts(
address token,
ParaID destinationChain,
uint128 destinationChainFee,
uint128 maxDestinationChainFee
) external view returns (Costs memory costs) {
function sendTokenCosts(address token, ParaID destinationChain, uint128 destinationChainFee)
external
view
returns (Costs memory costs)
{
AssetsStorage.Layout storage $ = AssetsStorage.layout();
TokenInfo storage info = $.tokenRegistry[token];
if (!info.isRegistered) {
revert TokenNotRegistered();
}

return _sendTokenCosts(destinationChain, destinationChainFee, maxDestinationChainFee);
return _sendTokenCosts(destinationChain, destinationChainFee);
}

function _sendTokenCosts(ParaID destinationChain, uint128 destinationChainFee, uint128 maxDestinationChainFee)
function _sendTokenCosts(ParaID destinationChain, uint128 destinationChainFee)
internal
view
returns (Costs memory costs)
Expand All @@ -67,7 +66,7 @@ library Assets {
costs.foreign = $.assetHubReserveTransferFee;
} else {
// Destination fee cannot be zero. MultiAssets are not allowed to be zero in xcm v4.
if (destinationChainFee == 0 || destinationChainFee > maxDestinationChainFee) {
if (destinationChainFee == 0) {
revert InvalidDestinationFee();
}

Expand All @@ -85,8 +84,7 @@ library Assets {
ParaID destinationChain,
MultiAddress calldata destinationAddress,
uint128 destinationChainFee,
uint128 amount,
uint128 maxDestinationChainFee
uint128 amount
) external returns (Ticket memory ticket) {
AssetsStorage.Layout storage $ = AssetsStorage.layout();

Expand All @@ -99,7 +97,7 @@ library Assets {
_transferToAgent($.assetHubAgent, token, sender, amount);

ticket.dest = $.assetHubParaID;
ticket.costs = _sendTokenCosts(destinationChain, destinationChainFee, maxDestinationChainFee);
ticket.costs = _sendTokenCosts(destinationChain, destinationChainFee);

// Construct a message payload
if (destinationChain == $.assetHubParaID) {
Expand Down
17 changes: 6 additions & 11 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ contract Gateway is IGateway, IInitializable {
view
returns (uint256)
{
return
_calculateFee(Assets.sendTokenCosts(token, destinationChain, destinationFee, MAX_DESTINATION_TRANSFER_FEE));
return _calculateFee(Assets.sendTokenCosts(token, destinationChain, destinationFee));
}

// Transfer ERC20 tokens to a Polkadot parachain
Expand All @@ -434,16 +433,12 @@ contract Gateway is IGateway, IInitializable {
uint128 destinationFee,
uint128 amount
) external payable {
if (destinationFee > MAX_DESTINATION_TRANSFER_FEE) {
revert Assets.InvalidDestinationFee();
}

_submitOutbound(
Assets.sendToken(
token,
msg.sender,
destinationChain,
destinationAddress,
destinationFee,
amount,
MAX_DESTINATION_TRANSFER_FEE
)
Assets.sendToken(token, msg.sender, destinationChain, destinationAddress, destinationFee, amount)
);
}

Expand Down
2 changes: 0 additions & 2 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,6 @@ contract GatewayTest is Test {
IGateway(address(gateway)).registerToken{value: fee}(address(token));

uint128 largeFee = destinationMaxTransferFee + 1; // greater than 10 DOT, 10 decimal places

vm.expectRevert(Assets.InvalidDestinationFee.selector);
fee = IGateway(address(gateway)).quoteSendTokenFee(address(token), destPara, largeFee);

vm.expectRevert(Assets.InvalidDestinationFee.selector);
Expand Down

0 comments on commit 42120cf

Please sign in to comment.