Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

chore: refactor delegatecall in deployToken method #103

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions contracts/examples/ERC20Messaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,16 @@ contract ERC20Messaging is IERC20Messaging, ToposMessaging {
// If token address is no specified, it indicates a request to deploy one.
bytes32 salt = keccak256(abi.encodePacked(msg.sender, symbol));

// slither-disable-start reentrancy-no-eth
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory data) = _tokenDeployerAddr.delegatecall(
abi.encodeWithSelector(
ITokenDeployer.deployToken.selector,
name,
symbol,
cap,
initialSupply,
msg.sender,
address(this),
salt
)
// Deploy the token contract
tokenAddress = ITokenDeployer(_tokenDeployerAddr).deployToken(
name,
symbol,
cap,
initialSupply,
msg.sender,
address(this),
salt
);
// slither-disable-end reentrancy-no-eth

if (!success) revert TokenDeployFailed();

tokenAddress = abi.decode(data, (address));

_setTokenType(tokenAddress, TokenType.InternalBurnableFrom);
} else {
revert UnsupportedTokenType();
Expand Down
1 change: 0 additions & 1 deletion contracts/interfaces/IERC20Messaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface IERC20Messaging is IToposMessaging {
error InvalidSubnetId();
error InvalidTokenDeployer();
error TokenAlreadyExists(address tokenAddress);
error TokenDeployFailed();
error TokenDoesNotExist(address tokenAddress);
error UnsupportedTokenType();

Expand Down
4 changes: 1 addition & 3 deletions test/topos-core/ToposMessaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ describe('ToposMessaging', () => {
deployERC20MessagingFixture
)
await erc20Messaging.deployToken(defaultToken)
await expect(
erc20Messaging.deployToken(defaultToken)
).to.be.revertedWithCustomError(erc20Messaging, 'TokenDeployFailed')
await expect(erc20Messaging.deployToken(defaultToken)).to.be.reverted
expect(await erc20Messaging.getTokenCount()).to.equal(1)
})

Expand Down
8 changes: 4 additions & 4 deletions test/topos-core/shared/constants/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class TransactionData {
}

export const MINT_EXCEED_TRANSACTION: TransactionData = new TransactionData(
'0xf9036f0180f9036af90367822080b90361f9035e0183010343b9010004000000000000000000000000000400000000000400000000000000000000000000000000000000000000000000080040000000000000000000000000200001000000000000000000000008000000000000000240000000000000000000000000000000020000000001000100000800000200000000000000000010000000800000000008000000000000000000000000000000000080000000000000000000120000000000001000000100000020000000000000000000000000000000000000000002000000200000000040000000000000002000001000000001000020000010000000000000000000000000000000000000008000000000000000000000f90253f89b9480470aae1435c000e381896adce853000cc58c13f863a08c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000005fc8d32690cc91d4c39d9d3abcbd16989f875707a00000000000000000000000000000000000000000000000000000000000000000f89b9480470aae1435c000e381896adce853000cc58c13f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000006df8bb945fc8d32690cc91d4c39d9d3abcbd16989f875707f842a0920718295e8e03a7fda1fe1d8d41ba008f378b1d679ea1a5f70eca3a389a2578a00000000000000000000000000000000000000000000000000000000000000002b86000000000000000000000000080470aae1435c000e381896adce853000cc58c1300000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8000000000000000000000000000000000000000000000000000000000000006df85a94cf7ed3acca5a467e9e704c703e8d87f634fb0fc9f842a0f27439dc0ef741d8be6e7efbd4f85c0995f73cc11fc82ad08ede2b7bf735a640a0000000000000000000000000000000000000000000000000000000000000000280',
'0x03bfbb51c66be456dcb0821b03c1ce7d95f0270982de7672d6f9af83ff38aa3a'
'0xf9036f0180f9036af90367822080b90361f9035e018301034fb9010004000000000000000000000000000000000100000400000000000000000000000000000000000000000000000000080040000000000000000000000000200001000000000000000000000008000000000000000240000000000000000800000000000000020000000001000100000800000200000000000000000010000000000000000008000000000000000000000000000000000080000000000000000000120000000000001000000100000000000000000000000000000000000000000000000002000000200000000040000000000000002000001000000001000020000010000000000000000000100000000000000000008000000000000000000000f90253f89b94aff00e3d9958009a7ad46df6b4a5b181dd5cbb38f863a08c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000005fc8d32690cc91d4c39d9d3abcbd16989f875707a00000000000000000000000000000000000000000000000000000000000000000f89b94aff00e3d9958009a7ad46df6b4a5b181dd5cbb38f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000006df8bb945fc8d32690cc91d4c39d9d3abcbd16989f875707f842a0920718295e8e03a7fda1fe1d8d41ba008f378b1d679ea1a5f70eca3a389a2578a00000000000000000000000000000000000000000000000000000000000000002b860000000000000000000000000aff00e3d9958009a7ad46df6b4a5b181dd5cbb3800000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8000000000000000000000000000000000000000000000000000000000000006df85a94cf7ed3acca5a467e9e704c703e8d87f634fb0fc9f842a0f27439dc0ef741d8be6e7efbd4f85c0995f73cc11fc82ad08ede2b7bf735a640a0000000000000000000000000000000000000000000000000000000000000000280',
'0xf00cc0c622198fd4cd84cf47433d704d38e374d6d7dc55df705864a457021093'
)

export const UNKNOWN_TOKEN_TRANSACTION: TransactionData = new TransactionData(
Expand All @@ -21,8 +21,8 @@ export const UNKNOWN_TOKEN_TRANSACTION: TransactionData = new TransactionData(
)

export const ZERO_ADDRESS_TRANSACTION: TransactionData = new TransactionData(
'0xf9036f0180f9036af90367822080b90361f9035e0183010253b9010004000000000000000000000000000400000000000400000000000000000000000000000000000000000000000000080040000000000000000000000000200001000000000000000000000008000000000000000240000000000000000000000000000000020000000001000100000800000200000000000000000010000000800000000008000000000000000000000000000000000080000000000000000000120000000000001000000100000020000000000000000000000000000000000000000002000000200000000040000000000000002000001000000001000020000010000000000000000000000000000000000000008000000000000000000000f90253f89b9480470aae1435c000e381896adce853000cc58c13f863a08c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000005fc8d32690cc91d4c39d9d3abcbd16989f875707a00000000000000000000000000000000000000000000000000000000000000000f89b9480470aae1435c000e381896adce853000cc58c13f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000032f8bb945fc8d32690cc91d4c39d9d3abcbd16989f875707f842a0920718295e8e03a7fda1fe1d8d41ba008f378b1d679ea1a5f70eca3a389a2578a00000000000000000000000000000000000000000000000000000000000000002b86000000000000000000000000080470aae1435c000e381896adce853000cc58c1300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032f85a94cf7ed3acca5a467e9e704c703e8d87f634fb0fc9f842a0f27439dc0ef741d8be6e7efbd4f85c0995f73cc11fc82ad08ede2b7bf735a640a0000000000000000000000000000000000000000000000000000000000000000280',
'0x3f10bcaa9ca2be4b5fa3493b2f2cb17c55a6494719335fb4139131e643f0d03f'
'0xf9036f0180f9036af90367822080b90361f9035e018301025fb9010004000000000000000000000000000000000100000400000000000000000000000000000000000000000000000000080040000000000000000000000000200001000000000000000000000008000000000000000240000000000000000800000000000000020000000001000100000800000200000000000000000010000000000000000008000000000000000000000000000000000080000000000000000000120000000000001000000100000000000000000000000000000000000000000000000002000000200000000040000000000000002000001000000001000020000010000000000000000000100000000000000000008000000000000000000000f90253f89b94aff00e3d9958009a7ad46df6b4a5b181dd5cbb38f863a08c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000005fc8d32690cc91d4c39d9d3abcbd16989f875707a00000000000000000000000000000000000000000000000000000000000000000f89b94aff00e3d9958009a7ad46df6b4a5b181dd5cbb38f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000032f8bb945fc8d32690cc91d4c39d9d3abcbd16989f875707f842a0920718295e8e03a7fda1fe1d8d41ba008f378b1d679ea1a5f70eca3a389a2578a00000000000000000000000000000000000000000000000000000000000000002b860000000000000000000000000aff00e3d9958009a7ad46df6b4a5b181dd5cbb3800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032f85a94cf7ed3acca5a467e9e704c703e8d87f634fb0fc9f842a0f27439dc0ef741d8be6e7efbd4f85c0995f73cc11fc82ad08ede2b7bf735a640a0000000000000000000000000000000000000000000000000000000000000000280',
'0xedbada940f7e82253305537b0a16b58b9d0b13e284eb175052042c5bb57b4847'
)

export const INVALID_STATUS_TRANSACTION: TransactionData = new TransactionData(
Expand Down
Loading