-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Introduced the use of OptionsLib for decoding transaction options w…
…ithin the InterchainClientV1 contract. - Enabled dynamic gas limits for appReceive calls based on options specified in incoming interchain transactions.
- Loading branch information
1 parent
733e92d
commit 16e0850
Showing
6 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/contracts-communication/contracts/libs/Options.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
library OptionsLib { | ||
struct Options { | ||
uint8 version; | ||
uint256 gasLimit; | ||
// uint256 msgValue; | ||
uint256 gasAirdrop; | ||
} | ||
|
||
function encodeOptions(Options memory options) internal pure returns (bytes memory) { | ||
return abi.encode(options.version, options.gasLimit, options.gasAirdrop); | ||
} | ||
|
||
function decodeOptions(bytes memory data) internal pure returns (Options memory) { | ||
(uint8 version, uint256 gasLimit, uint256 gasAirdrop) = abi.decode(data, (uint8, uint256, uint256)); | ||
return Options(version, gasLimit, gasAirdrop); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/contracts-communication/test/harnesses/OptionsLibHarness.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
import {OptionsLib} from "../../contracts/libs/Options.sol"; | ||
|
||
contract OptionsLibHarness { | ||
function encodeOptions( | ||
uint8 version, | ||
uint256 gasLimit, | ||
// uint256 msgValue, | ||
uint256 gasAirdrop | ||
) | ||
external | ||
pure | ||
returns (bytes memory) | ||
{ | ||
OptionsLib.Options memory options = OptionsLib.Options(version, gasLimit, gasAirdrop); | ||
return OptionsLib.encodeOptions(options); | ||
} | ||
|
||
function decodeOptions(bytes calldata data) external pure returns (uint8, uint256, uint256) { | ||
OptionsLib.Options memory options = OptionsLib.decodeOptions(data); | ||
return (options.version, options.gasLimit, options.gasAirdrop); | ||
} | ||
} |
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
packages/contracts-communication/test/libs/OptionsLib.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
import { OptionsLib, OptionsLibHarness } from "../harnesses/OptionsLibHarness.sol"; | ||
|
||
contract OptionsLibTest is Test { | ||
OptionsLibHarness public libHarness; | ||
|
||
function setUp() public { | ||
libHarness = new OptionsLibHarness(); | ||
} | ||
|
||
function test_encodeOptions() public { | ||
uint8 version = 1; | ||
// 200k gas limit | ||
uint256 gasLimit = 200000; | ||
// 100k wei | ||
uint256 gasAirdrop = 100000; | ||
bytes memory expected = abi.encode(version, gasLimit, gasAirdrop); | ||
bytes memory actual = libHarness.encodeOptions(version, gasLimit, gasAirdrop); | ||
assertEq(actual, expected); | ||
} | ||
|
||
function test_decodeOptions() public { | ||
uint8 version = 1; | ||
// 200k gas limit | ||
uint256 gasLimit = 200000; | ||
// 100k wei | ||
uint256 gasAirdrop = 100000; | ||
bytes memory data = abi.encode(version, gasLimit, gasAirdrop); | ||
(uint8 actualVersion, uint256 actualGasLimit, uint256 actualGasAirdrop) = libHarness.decodeOptions(data); | ||
assertEq(actualVersion, version); | ||
assertEq(actualGasLimit, gasLimit); | ||
assertEq(actualGasAirdrop, gasAirdrop); | ||
} | ||
} |