-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExchangeProxy.sol
81 lines (69 loc) · 3.18 KB
/
ExchangeProxy.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: MIT
pragma solidity >0.6.6;
import "./Exchange.sol";
import "./CosmosTypes.sol";
import "./ExchangeTypes.sol";
contract ExchangeProxy {
address constant exchangeContract = 0x0000000000000000000000000000000000000065;
IExchangeModule exchange = IExchangeModule(exchangeContract);
/// @dev Approves a message type, so that this contract can submit it on
/// 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,
uint256 duration
) external returns (bool success) {
ExchangeTypes.MsgType[] memory methods = new ExchangeTypes.MsgType[](1);
methods[0] = msgType;
try exchange.approve(address(this), methods, spendLimit, duration) returns (bool approved) {
return approved;
} catch {
revert("error approving msg with spend limit");
}
}
/// @dev Revokes a grant from the origin to this contract for a specific method
/// @param msgType The type of the message to revoke.
/// @return success Boolean value to indicate if the revocation was successful.
function revoke(ExchangeTypes.MsgType msgType) external returns (bool success) {
ExchangeTypes.MsgType[] memory methods = new ExchangeTypes.MsgType[](1);
methods[0] = msgType;
try exchange.revoke(address(this), methods) returns (bool revoked) {
return revoked;
} catch {
revert("error revoking method");
}
}
/// @dev Creates a derivative limit order on behalf of the specified sender.
/// It will revert with an error if this smart-contract doesn't have a grant
/// from the sender to perform this action on their behalf.
/// cf approveCreateDerivativeLimitOrder for granting authorization
/// @param sender The address of the sender.
/// @param order The derivative order to create.
/// @return response The response from the createDerivativeLimitOrder call.
function createDerivativeLimitOrder(
address sender,
IExchangeModule.DerivativeOrder calldata order
) external returns (IExchangeModule.CreateDerivativeLimitOrderResponse memory response) {
try exchange.createDerivativeLimitOrder(sender, order) returns (IExchangeModule.CreateDerivativeLimitOrderResponse memory resp) {
return resp;
} catch {
revert("error creating derivative limit order");
}
}
function queryAllowance(
address grantee,
address granter,
ExchangeTypes.MsgType msgType
) external view returns (bool allowed) {
try exchange.allowance(grantee, granter, msgType) returns (bool isAllowed) {
return isAllowed;
} catch {
revert("error querying allowance");
}
}
//*************************************************************************/
}