This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
forked from zeriontech/defi-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DyDxAdapter.sol
executable file
·59 lines (52 loc) · 2.2 KB
/
DyDxAdapter.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
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.7.3;
pragma experimental ABIEncoderV2;
import { Info, Wei, SoloMargin } from "../../interfaces/SoloMargin.sol";
import { ProtocolAdapter } from "../ProtocolAdapter.sol";
/**
* @dev dYdX adapter abstract contract.
* @dev Base contract for dYdX adapters.
* @author Igor Sobolev <[email protected]>
*/
abstract contract DyDxAdapter is ProtocolAdapter {
address internal constant SOLO = 0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e;
address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant SAI = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359;
address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address internal constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
function getBalance(address token, address account) public override returns (int256) {
Wei memory accountWei = SoloMargin(SOLO).getAccountWei(
Info(account, 0),
getMarketId(token)
);
return accountWei.sign ? int256(accountWei.value) : int256(-accountWei.value);
}
function getMarketId(address token) internal pure returns (uint256) {
if (token == WETH) {
return uint256(0);
} else if (token == SAI) {
return uint256(1);
} else if (token == USDC) {
return uint256(2);
} else if (token == DAI) {
return uint256(3);
} else {
return type(uint256).max;
}
}
}