|
| 1 | +# TWAP Oracle |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This oracle fetches price of assets from PancakeSwap |
| 6 | + |
| 7 | +## Solidity API |
| 8 | + |
| 9 | +### initialize |
| 10 | + |
| 11 | +```solidity |
| 12 | +function initialize(address WBNB_) public |
| 13 | +``` |
| 14 | + |
| 15 | +Initializes the owner of the contract and sets the contracts required |
| 16 | + |
| 17 | +#### Parameters |
| 18 | + |
| 19 | +| Name | Type | Description | |
| 20 | +| ---- | ---- | ----------- | |
| 21 | +| WBNB_ | address | Address of the WBNB token contract | |
| 22 | + |
| 23 | +### setTokenConfigs |
| 24 | + |
| 25 | +```solidity |
| 26 | +function setTokenConfigs(struct TokenConfig[] configs) external |
| 27 | +``` |
| 28 | + |
| 29 | +Add multiple token configs at the same time |
| 30 | + |
| 31 | +#### Parameters |
| 32 | + |
| 33 | +| Name | Type | Description | |
| 34 | +| ---- | ---- | ----------- | |
| 35 | +| configs | struct TokenConfig[] | config array | |
| 36 | + |
| 37 | +### setTokenConfig |
| 38 | + |
| 39 | +```solidity |
| 40 | +function setTokenConfig(struct TokenConfig config) public |
| 41 | +``` |
| 42 | + |
| 43 | +Add single token configs |
| 44 | + |
| 45 | +#### Parameters |
| 46 | + |
| 47 | +| Name | Type | Description | |
| 48 | +| ---- | ---- | ----------- | |
| 49 | +| config | struct TokenConfig | token config struct | |
| 50 | + |
| 51 | +### getUnderlyingPrice |
| 52 | + |
| 53 | +```solidity |
| 54 | +function getUnderlyingPrice(address vToken) external view returns (uint256) |
| 55 | +``` |
| 56 | + |
| 57 | +Get the underlying TWAP price of input vToken |
| 58 | + |
| 59 | +#### Parameters |
| 60 | + |
| 61 | +| Name | Type | Description | |
| 62 | +| ---- | ---- | ----------- | |
| 63 | +| vToken | address | vToken address | |
| 64 | + |
| 65 | +#### Return Values |
| 66 | + |
| 67 | +| Name | Type | Description | |
| 68 | +| ---- | ---- | ----------- | |
| 69 | +| [0] | uint256 | price in USD | |
| 70 | + |
| 71 | +### currentCumulativePrice |
| 72 | + |
| 73 | +```solidity |
| 74 | +function currentCumulativePrice(struct TokenConfig config) public view returns (uint256) |
| 75 | +``` |
| 76 | + |
| 77 | +Fetches the current token/WBNB and token/BUSD price accumulator from pancakeswap. |
| 78 | + |
| 79 | +#### Return Values |
| 80 | + |
| 81 | +| Name | Type | Description | |
| 82 | +| ---- | ---- | ----------- | |
| 83 | +| [0] | uint256 | cumulative price of target token regardless of pair order | |
| 84 | + |
| 85 | +### updateTwap |
| 86 | + |
| 87 | +```solidity |
| 88 | +function updateTwap(address vToken) public returns (uint256) |
| 89 | +``` |
| 90 | + |
| 91 | +Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision. |
| 92 | + |
| 93 | +#### Return Values |
| 94 | + |
| 95 | +| Name | Type | Description | |
| 96 | +| ---- | ---- | ----------- | |
| 97 | +| [0] | uint256 | vToken Address of vToken | |
0 commit comments