@@ -73,6 +73,7 @@ contract InterchainTokenService is
73
73
/**
74
74
* @dev The message types that are sent between InterchainTokenService on different chains.
75
75
*/
76
+
76
77
uint256 private constant MESSAGE_TYPE_INTERCHAIN_TRANSFER = 0 ;
77
78
uint256 private constant MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1 ;
78
79
uint256 private constant MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2 ;
@@ -81,12 +82,18 @@ contract InterchainTokenService is
81
82
* @dev Tokens and token managers deployed via the Token Factory contract use a special deployer address.
82
83
* This removes the dependency on the address the token factory was deployed too to be able to derive the same tokenId.
83
84
*/
84
- address private constant TOKEN_FACTORY_DEPLOYER = address (0 );
85
+ address internal constant TOKEN_FACTORY_DEPLOYER = address (0 );
85
86
86
87
/**
87
88
* @dev Latest version of metadata that's supported.
88
89
*/
89
- uint32 private constant LATEST_METADATA_VERSION = 0 ;
90
+
91
+ enum MetadataVersion {
92
+ CONTRACT_CALL,
93
+ EXPRESS_CALL
94
+ }
95
+
96
+ uint32 internal constant LATEST_METADATA_VERSION = 1 ;
90
97
91
98
/**
92
99
* @notice Constructor for the Interchain Token Service.
@@ -453,7 +460,7 @@ contract InterchainTokenService is
453
460
) external payable whenNotPaused {
454
461
(amount, ) = _takeToken (tokenId, msg .sender , amount);
455
462
456
- (uint32 metadataVersion , bytes memory data ) = _decodeMetadata (metadata);
463
+ (MetadataVersion metadataVersion , bytes memory data ) = _decodeMetadata (metadata);
457
464
458
465
_transmitInterchainTransfer (tokenId, msg .sender , destinationChain, destinationAddress, amount, metadataVersion, data);
459
466
}
@@ -475,12 +482,12 @@ contract InterchainTokenService is
475
482
) external payable whenNotPaused {
476
483
(amount, ) = _takeToken (tokenId, msg .sender , amount);
477
484
478
- _transmitInterchainTransfer (tokenId, msg .sender , destinationChain, destinationAddress, amount, LATEST_METADATA_VERSION , data);
485
+ _transmitInterchainTransfer (tokenId, msg .sender , destinationChain, destinationAddress, amount, MetadataVersion.CONTRACT_CALL , data);
479
486
}
480
487
481
- /********************* \
488
+ /******************\
482
489
TOKEN ONLY FUNCTIONS
483
- \********************* /
490
+ \******************/
484
491
485
492
/**
486
493
* @notice Transmit an interchain transfer for the given tokenId.
@@ -507,7 +514,7 @@ contract InterchainTokenService is
507
514
508
515
if (sender != tokenAddress) revert NotToken (sender, tokenAddress);
509
516
510
- (uint32 metadataVersion , bytes memory data ) = _decodeMetadata (metadata);
517
+ (MetadataVersion metadataVersion , bytes memory data ) = _decodeMetadata (metadata);
511
518
512
519
_transmitInterchainTransfer (tokenId, sourceAddress, destinationChain, destinationAddress, amount, metadataVersion, data);
513
520
}
@@ -750,18 +757,33 @@ contract InterchainTokenService is
750
757
* @param payload The data payload for the transaction.
751
758
* @param gasValue The amount of gas to be paid for the transaction.
752
759
*/
753
- function _callContract (string calldata destinationChain , bytes memory payload , uint256 gasValue ) internal {
760
+ function _callContract (
761
+ string calldata destinationChain ,
762
+ bytes memory payload ,
763
+ MetadataVersion metadataVersion ,
764
+ uint256 gasValue
765
+ ) internal {
754
766
string memory destinationAddress = trustedAddress (destinationChain);
755
767
if (bytes (destinationAddress).length == 0 ) revert UntrustedChain ();
756
768
757
769
if (gasValue > 0 ) {
758
- gasService.payNativeGasForContractCall { value: gasValue }(
759
- address (this ),
760
- destinationChain,
761
- destinationAddress,
762
- payload, // solhint-disable-next-line avoid-tx-origin
763
- tx .origin
764
- );
770
+ if (metadataVersion == MetadataVersion.CONTRACT_CALL) {
771
+ gasService.payNativeGasForContractCall { value: gasValue }(
772
+ address (this ),
773
+ destinationChain,
774
+ destinationAddress,
775
+ payload, // solhint-disable-next-line avoid-tx-origin
776
+ tx .origin
777
+ );
778
+ } else if (metadataVersion == MetadataVersion.EXPRESS_CALL) {
779
+ gasService.payNativeGasForExpressCall { value: gasValue }(
780
+ address (this ),
781
+ destinationChain,
782
+ destinationAddress,
783
+ payload, // solhint-disable-next-line avoid-tx-origin
784
+ tx .origin
785
+ );
786
+ }
765
787
}
766
788
767
789
gateway.callContract (destinationChain, destinationAddress, payload);
@@ -789,7 +811,7 @@ contract InterchainTokenService is
789
811
790
812
bytes memory payload = abi.encode (MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, tokenManagerType, params);
791
813
792
- _callContract (destinationChain, payload, gasValue);
814
+ _callContract (destinationChain, payload, MetadataVersion.CONTRACT_CALL, gasValue);
793
815
}
794
816
795
817
/**
@@ -819,7 +841,7 @@ contract InterchainTokenService is
819
841
820
842
bytes memory payload = abi.encode (MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, name, symbol, decimals, minter);
821
843
822
- _callContract (destinationChain, payload, gasValue);
844
+ _callContract (destinationChain, payload, MetadataVersion.CONTRACT_CALL, gasValue);
823
845
}
824
846
825
847
/**
@@ -898,10 +920,13 @@ contract InterchainTokenService is
898
920
* @return version The version number extracted from the metadata.
899
921
* @return data The data bytes extracted from the metadata.
900
922
*/
901
- function _decodeMetadata (bytes calldata metadata ) internal pure returns (uint32 version , bytes memory data ) {
902
- if (metadata.length < 4 ) return (LATEST_METADATA_VERSION, data);
923
+ function _decodeMetadata (bytes calldata metadata ) internal pure returns (MetadataVersion version , bytes memory data ) {
924
+ if (metadata.length < 4 ) return (MetadataVersion.CONTRACT_CALL, data);
925
+
926
+ uint32 versionUint = uint32 (bytes4 (metadata[:4 ]));
927
+ if (versionUint > LATEST_METADATA_VERSION) revert InvalidMetadataVersion (versionUint);
903
928
904
- version = uint32 ( bytes4 (metadata[: 4 ]) );
929
+ version = MetadataVersion (versionUint );
905
930
906
931
if (metadata.length == 4 ) return (version, data);
907
932
@@ -924,11 +949,9 @@ contract InterchainTokenService is
924
949
string calldata destinationChain ,
925
950
bytes memory destinationAddress ,
926
951
uint256 amount ,
927
- uint32 metadataVersion ,
952
+ MetadataVersion metadataVersion ,
928
953
bytes memory data
929
954
) internal {
930
- if (metadataVersion > LATEST_METADATA_VERSION) revert InvalidMetadataVersion (metadataVersion);
931
-
932
955
// slither-disable-next-line reentrancy-events
933
956
emit InterchainTransfer (
934
957
tokenId,
@@ -948,7 +971,7 @@ contract InterchainTokenService is
948
971
data
949
972
);
950
973
951
- _callContract (destinationChain, payload, msg .value );
974
+ _callContract (destinationChain, payload, metadataVersion, msg .value );
952
975
}
953
976
954
977
/**
0 commit comments