Skip to content

Commit

Permalink
Merge pull request #1 from InjectiveLabs/feat/authz-expiration
Browse files Browse the repository at this point in the history
feat: add duration param to approve method
  • Loading branch information
arrivets authored Jan 27, 2025
2 parents 71abc13 + 7958a56 commit 0feb308
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 6 additions & 4 deletions Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ interface IExchangeModule {
****************************************************************************/

/// @dev Approves a list of Cosmos messages.
/// @param grantee The account address which will have an authorization to spend the origin funds.
/// @param grantee The account address which will be authorized to spend the origin's funds.
/// @param methods The message type URLs of the methods to approve.
/// @param spendLimit The spend limit for the methods.
/// @param duration The time period for which the authorization is valid (in seconds).
/// @return approved Boolean value to indicate if the approval was successful.
function approve(
address grantee,
ExchangeTypes.MsgType[] calldata methods,
Cosmos.Coin[] calldata spendLimit
Cosmos.Coin[] calldata spendLimit,
uint256 duration
) external returns (bool approved);

/// @dev Revokes a list of Cosmos messages.
/// @param grantee The contract address which will have its allowances revoked.
/// @param grantee The account address which will have its allowances revoked.
/// @param methods The message type URLs of the methods to revoke.
/// @return revoked Boolean value to indicate if the revocation was successful.
function revoke(
Expand All @@ -31,7 +33,7 @@ interface IExchangeModule {

/// @dev Checks if there is a valid grant from granter to grantee for specified
/// message type
/// @param grantee The contract address which has the Authorization.
/// @param grantee The account address which has the Authorization.
/// @param granter The account address that grants an Authorization.
/// @param method The message type URL of the methods for which the approval should be queried.
/// @return allowed Boolean value to indicatie if the grant exists and is not expired
Expand Down
8 changes: 5 additions & 3 deletions ExchangeProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ contract ExchangeProxy {
/// behalf of the origin.
/// @param msgType The type of the message to approve.
/// @param spendLimit The spend limit for the message type.
/// @param duration The time period for which the authorization is valid (in seconds).
/// @return success Boolean value to indicate if the approval was successful.
function approve(
ExchangeTypes.MsgType msgType,
Cosmos.Coin[] memory spendLimit
Cosmos.Coin[] memory spendLimit,
uint256 duration
) external returns (bool success) {
ExchangeTypes.MsgType[] memory methods = new ExchangeTypes.MsgType[](1);
methods[0] = msgType;

try exchange.approve(address(this), methods, spendLimit) returns (bool approved) {
try exchange.approve(address(this), methods, spendLimit, duration) returns (bool approved) {
return approved;
} catch {
revert("error approving msg with spend limit");
Expand Down
6 changes: 4 additions & 2 deletions ExchangeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ contract ExchangeTest {
/// behalf of the origin.
/// @param msgType The type of the message to approve.
/// @param spendLimit The spend limit for the message type.
/// @param duration The time period for which the authorization is valid (in seconds).
/// @return success Boolean value to indicate if the approval was successful.
function approve(
ExchangeTypes.MsgType msgType,
Cosmos.Coin[] memory spendLimit
Cosmos.Coin[] memory spendLimit,
uint256 duration
) external returns (bool success) {
ExchangeTypes.MsgType[] memory methods = new ExchangeTypes.MsgType[](1);
methods[0] = msgType;

try exchange.approve(address(this), methods, spendLimit) returns (bool approved) {
try exchange.approve(address(this), methods, spendLimit, duration) returns (bool approved) {
return approved;
} catch {
revert("error approving msg with spend limit");
Expand Down

0 comments on commit 0feb308

Please sign in to comment.