Skip to content

Commit

Permalink
refactor(AddressBytes): using lib from SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
re1ro committed Nov 2, 2023
1 parent 34da8f0 commit 85be3e9
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 104 deletions.
6 changes: 3 additions & 3 deletions contracts/interchain-token-service/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ExpressExecutorTracker } from '@axelar-network/axelar-gmp-sdk-solidity/
import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';
import { Create3Address } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Create3Address.sol';
import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';
import { AddressBytes } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/AddressBytes.sol';
import { StringToBytes32, Bytes32ToString } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/Bytes32String.sol';
import { Multicall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/Multicall.sol';
import { IInterchainAddressTracker } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IInterchainAddressTracker.sol';
Expand All @@ -22,7 +23,6 @@ import { IInterchainTokenExpressExecutable } from '../interfaces/IInterchainToke
import { ITokenManager } from '../interfaces/ITokenManager.sol';
import { IERC20Named } from '../interfaces/IERC20Named.sol';

import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';
import { Operatable } from '../utils/Operatable.sol';

/**
Expand All @@ -42,8 +42,8 @@ contract InterchainTokenService is
{
using StringToBytes32 for string;
using Bytes32ToString for bytes32;
using AddressBytesUtils for bytes;
using AddressBytesUtils for address;
using AddressBytes for bytes;
using AddressBytes for address;
using SafeTokenTransferFrom for IERC20;

address internal immutable implementationLockUnlock;
Expand Down
38 changes: 0 additions & 38 deletions contracts/libraries/AddressBytesUtils.sol

This file was deleted.

6 changes: 0 additions & 6 deletions contracts/test/Imports.sol

This file was deleted.

5 changes: 3 additions & 2 deletions contracts/test/InvalidStandardizedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

pragma solidity ^0.8.0;

import { AddressBytes } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/AddressBytes.sol';

import { IERC20MintableBurnable } from '../interfaces/IERC20MintableBurnable.sol';
import { ITokenManager } from '../interfaces/ITokenManager.sol';

import { InterchainToken } from '../interchain-token/InterchainToken.sol';
import { ERC20Permit } from '../token-implementations/ERC20Permit.sol';
import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';
import { Implementation } from '../utils/Implementation.sol';
import { Distributable } from '../utils/Distributable.sol';

contract InvalidStandardizedToken is IERC20MintableBurnable, InterchainToken, ERC20Permit, Implementation, Distributable {
using AddressBytesUtils for bytes;
using AddressBytes for bytes;

string public name;
string public symbol;
Expand Down
18 changes: 0 additions & 18 deletions contracts/test/utils/AddressBytesUtilsTest.sol

This file was deleted.

5 changes: 3 additions & 2 deletions contracts/token-implementations/StandardizedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

pragma solidity ^0.8.0;

import { AddressBytes } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/AddressBytes.sol';

import { IImplementation } from '../interfaces/IImplementation.sol';
import { IStandardizedToken } from '../interfaces/IStandardizedToken.sol';
import { ITokenManager } from '../interfaces/ITokenManager.sol';

import { InterchainToken } from '../interchain-token/InterchainToken.sol';
import { ERC20Permit } from '../token-implementations/ERC20Permit.sol';
import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';
import { Implementation } from '../utils/Implementation.sol';
import { Distributable } from '../utils/Distributable.sol';

Expand All @@ -18,7 +19,7 @@ import { Distributable } from '../utils/Distributable.sol';
* This contract also inherits Distributable and Implementation logic.
*/
contract StandardizedToken is InterchainToken, ERC20Permit, Implementation, Distributable, IStandardizedToken {
using AddressBytesUtils for bytes;
using AddressBytes for bytes;

string public name;
string public symbol;
Expand Down
5 changes: 3 additions & 2 deletions contracts/token-manager/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

pragma solidity ^0.8.0;

import { AddressBytes } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/AddressBytes.sol';

import { ITokenManager } from '../interfaces/ITokenManager.sol';
import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol';

import { Operatable } from '../utils/Operatable.sol';
import { FlowLimit } from '../utils/FlowLimit.sol';
import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';
import { Implementation } from '../utils/Implementation.sol';

/**
* @title The main functionality of TokenManagers.
* @notice This contract is responsible for handling tokens before initiating a cross chain token transfer, or after receiving one.
*/
abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implementation {
using AddressBytesUtils for bytes;
using AddressBytes for bytes;

IInterchainTokenService public immutable interchainTokenService;

Expand Down
7 changes: 3 additions & 4 deletions contracts/token-registrars/StandardizedTokenRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;

import { SafeTokenTransfer } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';
import { Multicall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/Multicall.sol';
import { AddressBytes } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/AddressBytes.sol';

import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';

Expand All @@ -13,11 +14,9 @@ import { ITokenManagerType } from '../interfaces/ITokenManagerType.sol';
import { ITokenManager } from '../interfaces/ITokenManager.sol';
import { IStandardizedToken } from '../interfaces/IStandardizedToken.sol';

import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';

contract StandardizedTokenRegistrar is IStandardizedTokenRegistrar, ITokenManagerType, Multicall, Upgradable {
using AddressBytesUtils for bytes;
using AddressBytesUtils for address;
using AddressBytes for bytes;
using AddressBytes for address;
using SafeTokenTransfer for IStandardizedToken;

IInterchainTokenService public immutable service;
Expand Down
30 changes: 1 addition & 29 deletions test/UtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { ethers } = require('hardhat');
const { time } = require('@nomicfoundation/hardhat-network-helpers');
const { Wallet, Contract } = ethers;
const { AddressZero } = ethers.constants;
const { defaultAbiCoder, arrayify, toUtf8Bytes, hexlify } = ethers.utils;
const { defaultAbiCoder } = ethers.utils;
const { expect } = chai;
const { getRandomBytes32, expectRevert, isHardhat, waitFor } = require('./utils');
const { deployContract } = require('../scripts/deploy');
Expand Down Expand Up @@ -312,32 +312,4 @@ describe('InterchainTokenDeployer', () => {
'AlreadyDeployed',
);
});

describe('AddressBytesUtils', () => {
let addressBytesUtils;

before(async () => {
addressBytesUtils = await deployContract(ownerWallet, 'AddressBytesUtilsTest');
});

it('Should convert bytes address to address', async () => {
const bytesAddress = arrayify(ownerWallet.address);
const convertedAddress = await addressBytesUtils.toAddress(bytesAddress);
expect(convertedAddress).to.eq(ownerWallet.address);
});

it('Should revert on invalid bytes length', async () => {
const bytesAddress = defaultAbiCoder.encode(['bytes'], [toUtf8Bytes(ownerWallet.address)]);
await expectRevert(
(gasOptions) => addressBytesUtils.toAddress(bytesAddress, gasOptions),
addressBytesUtils,
'InvalidBytesLength',
);
});

it('Should convert address to bytes address', async () => {
const convertedAddress = await addressBytesUtils.toBytes(ownerWallet.address);
expect(convertedAddress).to.eq(hexlify(ownerWallet.address));
});
});
});

0 comments on commit 85be3e9

Please sign in to comment.