-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2: Fix IDA and fee calculation issues (#6)
* sushiswap oracle, tellor fallback, events * update tests and readme * eth->dai exchange testing * check IDA shares before distribute * misc. fixes for deploy * Added notes for v2 spec * calculate fee and distribute the actualAmount * tests for fee and v1.2 deploy config * script for setting rate tolerance * support verification
- Loading branch information
Showing
9 changed files
with
147 additions
and
23 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,34 @@ | ||
# Ricochet Exchange v2 (Draft) | ||
|
||
## Overview | ||
* Ricochet is a stream exchange that uses Superfluid | ||
* Each `RicochetExchange` contract supports two-way streaming swaps | ||
* Streamers can stream either `tokenA` or `tokenB` at any rate and RicochetExchange keepers will trigger swaps periodically | ||
* `RicochetExchange` will perform the following algorithm to swap: | ||
* Determine the `surplusToken`, which of tokenA or tokenB there's an excess amount of the other token available to swap with | ||
* Example: consider there is $100 DAI and $50 ETH that's been streamed into the contract | ||
* ETH is the `surplusToken` because there's _more_ than enough DAI to make the swap | ||
* Set the other token as the `deficitToken` | ||
* Consider the above example, DAI is the deficitToken because there's not enough ETH to swap for DAI | ||
* Next, perform the internal swap, swap the `surplusToken` for the `deficitToken` at the current `exchangeRate` | ||
* Then, take the remaining amount of the `deficitToken` and swap on Sushiswap | ||
* Finally, distribute to `tokenA` and `tokenB` their tokens | ||
|
||
## Protocol Speciciations | ||
|
||
### Structures | ||
* `Oracle` | ||
* `ITellor oracle` - Address of deployed simple oracle for input//output token | ||
* `uint256 requestId` - The id of the tellor request that has input/output exchange rate | ||
* `uint256 rateTolerance` - The percentage to deviate from the oracle scaled to 1e6 | ||
|
||
* `Exchange` | ||
* `ISuperfluid host` - Superfluid host contract | ||
* `IConstantFlowAgreementV1 cfa` - The stored constant flow agreement class address | ||
* `IInstantDistributionAgreementV1 ida` - The stored instant dist. agreement class address | ||
* `ISuperToken tokenA` - One of the tokens supported for streaming | ||
* `ISuperToken tokenB` - The other one of the tokens supported for streaming | ||
* `int96 totalInflow` - The fee taken as a % with 6 decimals | ||
* `uint128 feeRate` - The fee taken as a % with 6 decimals | ||
* `IUniswapV2Router02 sushiRouter` - Address of sushsiwap router to use for swapping | ||
* `Oracle oracle` - The oracle to use for the exchange |
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,25 @@ | ||
|
||
// Polygon Mainnet | ||
const HOST_ADDRESS = "0x3E14dC1b13c488a8d5D310918780c983bD5982E7"; | ||
const CFA_ADDRESS = "0x6EeE6060f715257b970700bc2656De21dEdF074C"; | ||
const IDA_ADDRESS = "0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1"; | ||
const DAIX_ADDRESS = "0x1305F6B6Df9Dc47159D12Eb7aC2804d4A33173c2"; | ||
const ETHX_ADDRESS = "0x27e1e4E6BC79D93032abef01025811B7E4727e85"; | ||
const SUSHISWAP_ROUTER_ADDRESS = "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"; | ||
const TELLOR_ORACLE_ADDRESS = "0xC79255821DA1edf8E1a8870ED5cED9099bf2eAAA"; | ||
const RIC_CONTRACT_ADDRESS = "0x263026e7e53dbfdce5ae55ade22493f828922965"; | ||
const TELLOR_REQUEST_ID = 1; | ||
|
||
|
||
module.exports = [ | ||
HOST_ADDRESS, | ||
CFA_ADDRESS, | ||
IDA_ADDRESS, | ||
process.env.INPUT_TOKEN_ADDRESS, | ||
process.env.OUTPUT_TOKEN_ADDRESS, | ||
RIC_CONTRACT_ADDRESS, | ||
SUSHISWAP_ROUTER_ADDRESS, | ||
TELLOR_ORACLE_ADDRESS, | ||
TELLOR_REQUEST_ID, | ||
process.env.SF_REG_KEY | ||
]; |
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
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
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
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
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
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,28 @@ | ||
async function main() { | ||
|
||
const [keeper] = await ethers.getSigners(); | ||
const RATE_TOLERANCE = "20000" | ||
const STREAM_EXCHANGE_HELPER_ADDRESS = "0x0C7776292AB9E95c54282fD74e47d73338c457D8" | ||
const RICOCHET_CONTRACT_ADDRESS = "0xe0B7907FA4B759FA4cB201F0E02E16374Bc523fd" | ||
|
||
const StreamExchangeHelper = await ethers.getContractFactory("StreamExchangeHelper") | ||
const seh = await StreamExchangeHelper.attach(STREAM_EXCHANGE_HELPER_ADDRESS) | ||
|
||
const StreamExchange = await ethers.getContractFactory("StreamExchange", { | ||
libraries: { | ||
StreamExchangeHelper: seh.address, | ||
}, | ||
}); | ||
const ricochet = await StreamExchange.attach(RICOCHET_CONTRACT_ADDRESS) | ||
|
||
console.log("rateTolerance", await ricochet.getRateTolerance()) | ||
console.log("setRateTolerance", RATE_TOLERANCE, await ricochet.setRateTolerance(RATE_TOLERANCE)) | ||
|
||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
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