-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9462223
commit e34e606
Showing
803 changed files
with
491,183 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.6.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Amm } from "./Amm.sol"; | ||
import { Decimal } from "./utils/MixedDecimal.sol"; | ||
|
||
contract AmmReader { | ||
using Decimal for Decimal.decimal; | ||
struct AmmStates { | ||
uint256 quoteAssetReserve; | ||
uint256 baseAssetReserve; | ||
uint256 tradeLimitRatio; | ||
uint256 fundingPeriod; | ||
string quoteAssetSymbol; | ||
string baseAssetSymbol; | ||
bytes32 priceFeedKey; | ||
address priceFeed; | ||
} | ||
|
||
function getAmmStates(address _amm) external view returns (AmmStates memory) { | ||
Amm amm = Amm(_amm); | ||
(bool getSymbolSuccess, bytes memory quoteAssetSymbolData) = address(amm.quoteAsset()).staticcall( | ||
abi.encodeWithSignature("symbol()") | ||
); | ||
(Decimal.decimal memory quoteAssetReserve, Decimal.decimal memory baseAssetReserve) = amm.getReserve(); | ||
|
||
bytes32 priceFeedKey = amm.priceFeedKey(); | ||
return | ||
AmmStates({ | ||
quoteAssetReserve: quoteAssetReserve.toUint(), | ||
baseAssetReserve: baseAssetReserve.toUint(), | ||
tradeLimitRatio: amm.tradeLimitRatio(), | ||
fundingPeriod: amm.fundingPeriod(), | ||
priceFeed: address(amm.priceFeed()), | ||
priceFeedKey: priceFeedKey, | ||
quoteAssetSymbol: getSymbolSuccess ? abi.decode(quoteAssetSymbolData, (string)) : "", | ||
baseAssetSymbol: bytes32ToString(priceFeedKey) | ||
}); | ||
} | ||
|
||
// TODO: move to library | ||
function bytes32ToString(bytes32 _key) private pure returns (string memory) { | ||
uint8 length; | ||
while (length <= 32 && _key[length] != 0) { | ||
length++; | ||
} | ||
bytes memory bytesArray = new bytes(length); | ||
for (uint256 i = 0; i < 32 && _key[i] != 0; i++) { | ||
bytesArray[i] = _key[i]; | ||
} | ||
return string(bytesArray); | ||
} | ||
} |
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,54 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.6.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Amm } from "./Amm.sol"; | ||
import { Decimal } from "./utils/MixedDecimal.sol"; | ||
|
||
contract AmmReader { | ||
using Decimal for Decimal.decimal; | ||
struct AmmStates { | ||
uint256 quoteAssetReserve; | ||
uint256 baseAssetReserve; | ||
uint256 tradeLimitRatio; | ||
uint256 fundingPeriod; | ||
string quoteAssetSymbol; | ||
string baseAssetSymbol; | ||
bytes32 priceFeedKey; | ||
address priceFeed; | ||
} | ||
|
||
function getAmmStates(address _amm) external view returns (AmmStates storage) { | ||
Amm amm = Amm(_amm); | ||
(bool getSymbolSuccess, bytes memory quoteAssetSymbolData) = address(amm.quoteAsset()).staticcall( | ||
abi.encodeWithSignature("symbol()") | ||
); | ||
(Decimal.decimal memory quoteAssetReserve, Decimal.decimal memory baseAssetReserve) = amm.getReserve(); | ||
|
||
bytes32 priceFeedKey = amm.priceFeedKey(); | ||
return | ||
AmmStates({ | ||
quoteAssetReserve: quoteAssetReserve.toUint(), | ||
baseAssetReserve: baseAssetReserve.toUint(), | ||
tradeLimitRatio: amm.tradeLimitRatio(), | ||
fundingPeriod: amm.fundingPeriod(), | ||
priceFeed: address(amm.priceFeed()), | ||
priceFeedKey: priceFeedKey, | ||
quoteAssetSymbol: getSymbolSuccess ? abi.decode(quoteAssetSymbolData, (string)) : "", | ||
baseAssetSymbol: bytes32ToString(priceFeedKey) | ||
}); | ||
} | ||
|
||
// TODO: move to library | ||
function bytes32ToString(bytes32 _key) private pure returns (string memory) { | ||
uint8 length; | ||
while (length < 32 && _key[length] != 0) { | ||
length++; | ||
} | ||
bytes memory bytesArray = new bytes(length); | ||
for (uint256 i = 0; i < 32 && _key[i] != 0; i++) { | ||
bytesArray[i] = _key[i]; | ||
} | ||
return string(bytesArray); | ||
} | ||
} |
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,54 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.6.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Amm } from "./Amm.sol"; | ||
import { Decimal } from "./utils/MixedDecimal.sol"; | ||
|
||
contract AmmReader { | ||
using Decimal for Decimal.decimal; | ||
struct AmmStates { | ||
uint256 quoteAssetReserve; | ||
uint256 baseAssetReserve; | ||
uint256 tradeLimitRatio; | ||
uint256 fundingPeriod; | ||
string quoteAssetSymbol; | ||
string baseAssetSymbol; | ||
bytes32 priceFeedKey; | ||
address priceFeed; | ||
} | ||
|
||
function getAmmStates(address _amm) external view returns (AmmStates memory) { | ||
Amm amm = Amm(_amm); | ||
(bool getSymbolSuccess, bytes memory quoteAssetSymbolData) = address(amm.quoteAsset()).call( | ||
abi.encodeWithSignature("symbol()") | ||
); | ||
(Decimal.decimal memory quoteAssetReserve, Decimal.decimal memory baseAssetReserve) = amm.getReserve(); | ||
|
||
bytes32 priceFeedKey = amm.priceFeedKey(); | ||
return | ||
AmmStates({ | ||
quoteAssetReserve: quoteAssetReserve.toUint(), | ||
baseAssetReserve: baseAssetReserve.toUint(), | ||
tradeLimitRatio: amm.tradeLimitRatio(), | ||
fundingPeriod: amm.fundingPeriod(), | ||
priceFeed: address(amm.priceFeed()), | ||
priceFeedKey: priceFeedKey, | ||
quoteAssetSymbol: getSymbolSuccess ? abi.decode(quoteAssetSymbolData, (string)) : "", | ||
baseAssetSymbol: bytes32ToString(priceFeedKey) | ||
}); | ||
} | ||
|
||
// TODO: move to library | ||
function bytes32ToString(bytes32 _key) private pure returns (string memory) { | ||
uint8 length; | ||
while (length < 32 && _key[length] != 0) { | ||
length++; | ||
} | ||
bytes memory bytesArray = new bytes(length); | ||
for (uint256 i = 0; i < 32 && _key[i] != 0; i++) { | ||
bytesArray[i] = _key[i]; | ||
} | ||
return string(bytesArray); | ||
} | ||
} |
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,54 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.6.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Amm } from "./Amm.sol"; | ||
import { Decimal } from "./utils/MixedDecimal.sol"; | ||
|
||
contract AmmReader { | ||
using Decimal for Decimal.decimal; | ||
struct AmmStates { | ||
uint256 quoteAssetReserve; | ||
uint256 baseAssetReserve; | ||
uint256 tradeLimitRatio; | ||
uint256 fundingPeriod; | ||
string quoteAssetSymbol; | ||
string baseAssetSymbol; | ||
bytes32 priceFeedKey; | ||
address priceFeed; | ||
} | ||
|
||
function getAmmStates(address _amm) public view returns (AmmStates memory) { | ||
Amm amm = Amm(_amm); | ||
(bool getSymbolSuccess, bytes memory quoteAssetSymbolData) = address(amm.quoteAsset()).staticcall( | ||
abi.encodeWithSignature("symbol()") | ||
); | ||
(Decimal.decimal memory quoteAssetReserve, Decimal.decimal memory baseAssetReserve) = amm.getReserve(); | ||
|
||
bytes32 priceFeedKey = amm.priceFeedKey(); | ||
return | ||
AmmStates({ | ||
quoteAssetReserve: quoteAssetReserve.toUint(), | ||
baseAssetReserve: baseAssetReserve.toUint(), | ||
tradeLimitRatio: amm.tradeLimitRatio(), | ||
fundingPeriod: amm.fundingPeriod(), | ||
priceFeed: address(amm.priceFeed()), | ||
priceFeedKey: priceFeedKey, | ||
quoteAssetSymbol: getSymbolSuccess ? abi.decode(quoteAssetSymbolData, (string)) : "", | ||
baseAssetSymbol: bytes32ToString(priceFeedKey) | ||
}); | ||
} | ||
|
||
// TODO: move to library | ||
function bytes32ToString(bytes32 _key) private pure returns (string memory) { | ||
uint8 length; | ||
while (length < 32 && _key[length] != 0) { | ||
length++; | ||
} | ||
bytes memory bytesArray = new bytes(length); | ||
for (uint256 i = 0; i < 32 && _key[i] != 0; i++) { | ||
bytesArray[i] = _key[i]; | ||
} | ||
return string(bytesArray); | ||
} | ||
} |
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,54 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.6.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Amm } from "./Amm.sol"; | ||
import { Decimal } from "./utils/MixedDecimal.sol"; | ||
|
||
contract AmmReader { | ||
using Decimal for Decimal.decimal; | ||
struct AmmStates { | ||
uint256 quoteAssetReserve; | ||
uint256 baseAssetReserve; | ||
uint256 tradeLimitRatio; | ||
uint256 fundingPeriod; | ||
string quoteAssetSymbol; | ||
string baseAssetSymbol; | ||
bytes32 priceFeedKey; | ||
address priceFeed; | ||
} | ||
|
||
function getAmmStates(address _amm) external view returns (AmmStates memory) { | ||
Amm amm = Amm(_amm); | ||
(bool getSymbolSuccess, bytes memory quoteAssetSymbolData) = address(amm.quoteAsset()).staticcall( | ||
abi.encodeWithSignature("symbol()") | ||
); | ||
(Decimal.decimal memory quoteAssetReserve, Decimal.decimal memory baseAssetReserve) = amm.getReserve(); | ||
|
||
bytes32 priceFeedKey = amm.priceFeedKey(); | ||
return | ||
AmmStates({ | ||
quoteAssetReserve: quoteAssetReserve.toUint(), | ||
baseAssetReserve: baseAssetReserve.toUint(), | ||
tradeLimitRatio: amm.tradeLimitRatio(), | ||
fundingPeriod: amm.fundingPeriod(), | ||
priceFeed: address(amm.priceFeed()), | ||
priceFeedKey: priceFeedKey, | ||
quoteAssetSymbol: getSymbolSuccess ? abi.decode(quoteAssetSymbolData, (string)) : "", | ||
baseAssetSymbol: bytes32ToString(priceFeedKey) | ||
}); | ||
} | ||
|
||
// TODO: move to library | ||
function bytes32ToString(bytes32 _key) private pure returns (string memory) { | ||
uint8 length; | ||
while (length < 31 && _key[length] != 0) { | ||
length++; | ||
} | ||
bytes memory bytesArray = new bytes(length); | ||
for (uint256 i = 0; i < 32 && _key[i] != 0; i++) { | ||
bytesArray[i] = _key[i]; | ||
} | ||
return string(bytesArray); | ||
} | ||
} |
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,54 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.6.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Amm } from "./Amm.sol"; | ||
import { Decimal } from "./utils/MixedDecimal.sol"; | ||
|
||
contract AmmReader { | ||
using Decimal for Decimal.decimal; | ||
struct AmmStates { | ||
uint256 quoteAssetReserve; | ||
uint256 baseAssetReserve; | ||
uint256 tradeLimitRatio; | ||
uint256 fundingPeriod; | ||
string quoteAssetSymbol; | ||
string baseAssetSymbol; | ||
bytes32 priceFeedKey; | ||
address priceFeed; | ||
} | ||
|
||
function getAmmStates(address _amm) external view returns (AmmStates memory) { | ||
Amm amm = Amm(_amm); | ||
(bool getSymbolSuccess, bytes memory quoteAssetSymbolData) = address(amm.quoteAsset()).staticcall( | ||
abi.encodeWithSignature("symbol()") | ||
); | ||
(Decimal.decimal memory quoteAssetReserve, Decimal.decimal memory baseAssetReserve) = amm.getReserve(); | ||
|
||
bytes32 priceFeedKey = amm.priceFeedKey(); | ||
/* return | ||
AmmStates({ | ||
quoteAssetReserve: quoteAssetReserve.toUint(), | ||
baseAssetReserve: baseAssetReserve.toUint(), | ||
tradeLimitRatio: amm.tradeLimitRatio(), | ||
fundingPeriod: amm.fundingPeriod(), | ||
priceFeed: address(amm.priceFeed()), | ||
priceFeedKey: priceFeedKey, | ||
quoteAssetSymbol: getSymbolSuccess ? abi.decode(quoteAssetSymbolData, (string)) : "", | ||
baseAssetSymbol: bytes32ToString(priceFeedKey) | ||
}); */ | ||
} | ||
|
||
// TODO: move to library | ||
function bytes32ToString(bytes32 _key) private pure returns (string memory) { | ||
uint8 length; | ||
while (length < 32 && _key[length] != 0) { | ||
length++; | ||
} | ||
bytes memory bytesArray = new bytes(length); | ||
for (uint256 i = 0; i < 32 && _key[i] != 0; i++) { | ||
bytesArray[i] = _key[i]; | ||
} | ||
return string(bytesArray); | ||
} | ||
} |
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,54 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.6.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Amm } from "./Amm.sol"; | ||
import { Decimal } from "./utils/MixedDecimal.sol"; | ||
|
||
contract AmmReader { | ||
using Decimal for Decimal.decimal; | ||
struct AmmStates { | ||
uint256 quoteAssetReserve; | ||
uint256 baseAssetReserve; | ||
uint256 tradeLimitRatio; | ||
uint256 fundingPeriod; | ||
string quoteAssetSymbol; | ||
string baseAssetSymbol; | ||
bytes32 priceFeedKey; | ||
address priceFeed; | ||
} | ||
|
||
function getAmmStates(address _amm) external view returns (AmmStates memory) { | ||
Amm amm = Amm(_amm); | ||
(bool getSymbolSuccess, bytes memory quoteAssetSymbolData) = address(amm.quoteAsset()).staticcall( | ||
abi.encodeWithSignature("") | ||
); | ||
(Decimal.decimal memory quoteAssetReserve, Decimal.decimal memory baseAssetReserve) = amm.getReserve(); | ||
|
||
bytes32 priceFeedKey = amm.priceFeedKey(); | ||
return | ||
AmmStates({ | ||
quoteAssetReserve: quoteAssetReserve.toUint(), | ||
baseAssetReserve: baseAssetReserve.toUint(), | ||
tradeLimitRatio: amm.tradeLimitRatio(), | ||
fundingPeriod: amm.fundingPeriod(), | ||
priceFeed: address(amm.priceFeed()), | ||
priceFeedKey: priceFeedKey, | ||
quoteAssetSymbol: getSymbolSuccess ? abi.decode(quoteAssetSymbolData, (string)) : "", | ||
baseAssetSymbol: bytes32ToString(priceFeedKey) | ||
}); | ||
} | ||
|
||
// TODO: move to library | ||
function bytes32ToString(bytes32 _key) private pure returns (string memory) { | ||
uint8 length; | ||
while (length < 32 && _key[length] != 0) { | ||
length++; | ||
} | ||
bytes memory bytesArray = new bytes(length); | ||
for (uint256 i = 0; i < 32 && _key[i] != 0; i++) { | ||
bytesArray[i] = _key[i]; | ||
} | ||
return string(bytesArray); | ||
} | ||
} |
Oops, something went wrong.