1
- //Contract: 0x73f5022bec0e01c0859634b0c7186301c5464b46
1
+ //MainNet Deployment: 0x8316b082621cfedab95bf4a44a1d4b64a6ffc336
2
+
2
3
//orfeed.org oracle aggregator
4
+
5
+
3
6
pragma experimental ABIEncoderV2;
4
7
5
8
interface IKyberNetworkProxy {
@@ -364,6 +367,7 @@ contract orfeed {
364
367
freeRateTokenSymbols['TUSD ' ] = 0x0000000000085d4780B73119b644AE5ecd22b376 ;
365
368
freeRateTokenSymbols['ETH ' ] = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE ;
366
369
freeRateTokenSymbols['WETH ' ] = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 ;
370
+ freeRateTokenSymbols['ETH2 ' ] = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 ;
367
371
freeRateTokenSymbols['SNX ' ] = 0xc011a72400e58ecd99ee497cf89e3775d4bd732f ;
368
372
freeRateTokenSymbols['CSAI ' ] = 0xf5dce57282a584d2746faf1593d3121fcac444dc ;
369
373
freeRateTokenSymbols['CUSDC ' ] = 0x39aa39c021dfbae8fac545936693ac917d5e7563 ;
@@ -384,12 +388,16 @@ contract orfeed {
384
388
freeRateForexSymbols['CHF ' ] = 0x0f83287ff768d1c1e17a42f44d644d7f22e8ee1d ;
385
389
freeRateForexSymbols['JPY ' ] = 0xf6b1c627e95bfc3c1b4c9b825a032ff0fbf3e07d ;
386
390
freeRateForexSymbols['GBP ' ] = 0x97fe22e7341a0cd8db6f6c021a24dc8f4dad855f ;
391
+ freeRateForexSymbols['sETH ' ] = 0x57ab1e02fee23774580c119740129eac7081e9d3 ;
392
+
387
393
388
394
freeRateForexBytes['USD ' ] = 0x7355534400000000000000000000000000000000000000000000000000000000 ;
389
395
freeRateForexBytes['EUR ' ] = 0x7345555200000000000000000000000000000000000000000000000000000000 ;
390
396
freeRateForexBytes['CHF ' ] = 0x7343484600000000000000000000000000000000000000000000000000000000 ;
391
397
freeRateForexBytes['JPY ' ] = 0x734a505900000000000000000000000000000000000000000000000000000000 ;
392
398
freeRateForexBytes['GBP ' ] = 0x7347425000000000000000000000000000000000000000000000000000000000 ;
399
+ freeRateForexBytes['sETH ' ] = 0x7345544800000000000000000000000000000000000000000000000000000000 ;
400
+
393
401
394
402
//when returning rates they will be first divided by and then multiplied by these rates
395
403
rateDivide1 = 100 ;
@@ -406,15 +414,15 @@ contract orfeed {
406
414
407
415
//erc20 price oracle address. Can be changed by DAO
408
416
tokenPriceOracleAddress = 0xFd9304Db24009694c680885e6aa0166C639727D6 ;
409
- synthetixExchangeAddress = 0x22a67ecd108f7a6fc52da9e2655ddfe88eccd9ca ;
417
+ synthetixExchangeAddress = 0xE95Ef4e7a04d2fB05cb625c62CA58da10112c605 ;
410
418
411
419
tokenPriceOracleAddress2 = 0xe9Cf7887b93150D4F2Da7dFc6D502B216438F244 ;
412
420
413
421
//forex price oracle address. Can be changed by DAO
414
422
forexPriceOracleAddress = 0xE86C848De6e4457720A1eb7f37B519010CD26d35 ;
415
423
416
424
//premium price oracle address. Can be changed by DAO
417
- premiumSubPriceOracleAddress = 0x5e00a16eb51157fb192bd4fcaef4f79a4f16f480 ;
425
+ premiumSubPriceOracleAddress = 0xbf2e5dc9b5c25911c68edcebd57438da1abd7ed6 ;
418
426
419
427
//arb proxy contract address. Can be cahnged... will be changed by DAO
420
428
arbContractAddress = 0x0 ;
@@ -449,15 +457,15 @@ contract orfeed {
449
457
uint256 ethAmount = kyber.getOutputAmount (token, ethToken, inputAmount);
450
458
uniswap = Uniswap (tokenPriceOracleAddress2);
451
459
uint256 sethAmount = uniswap.getEthToTokenInputPrice (ethAmount);
452
- synthetix = Synthetix (forexPriceOracleAddress );
453
- uint256 outputAmount = synthetix. getOutputAmount ( 'sETH ' , synth, sethAmount );
460
+ se = SynthetixExchange (synthetixExchangeAddress );
461
+ uint256 outputAmount = se. effectiveValue (freeRateForexBytes[ 'sETH ' ], sethAmount, synth );
454
462
return outputAmount;
455
463
}
456
464
457
465
function getSynthToTokenOutputAmount (bytes32 synth , ERC20 token , uint256 inputAmount ) returns (uint256 ) {
458
466
kyber = Kyber (tokenPriceOracleAddress);
459
- synthetix = Synthetix (forexPriceOracleAddress );
460
- uint256 sethAmount = synthetix. getOutputAmount (synth, 'sETH ' , inputAmount );
467
+ se = SynthetixExchange (synthetixExchangeAddress );
468
+ uint256 sethAmount = se. effectiveValue (synth, inputAmount, freeRateForexBytes[ 'sETH ' ] );
461
469
uniswap = Uniswap (tokenPriceOracleAddress2);
462
470
uint256 ethAmount = uniswap.getTokenToEthInputPrice (sethAmount);
463
471
uint256 outputAmount = kyber.getOutputAmount (ethToken, token, ethAmount);
@@ -520,6 +528,13 @@ contract orfeed {
520
528
}
521
529
522
530
531
+ function updateSynthAddress (address newOracle ) onlyOwner external returns (bool ) {
532
+ synthetixExchangeAddress = newOracle;
533
+ return true ;
534
+ }
535
+
536
+
537
+
523
538
//this will go to a DAO
524
539
function updatePremiumSubOracleAddress (address newOracle ) onlyOwner external returns (bool ) {
525
540
premiumSubPriceOracleAddress = newOracle;
@@ -745,13 +760,21 @@ contract orfeed {
745
760
//token to forex
746
761
else if (freeRateTokenSymbols[fromSymb] != 0x0 && freeRateTokenSymbols[toSymb] == 0x0 ) {
747
762
763
+ if (equal (fromSymb,"ETH " )){
764
+ fromSymb = "ETH2 " ;
765
+ }
766
+
748
767
uint256 toRate2 = getTokenToSynthOutputAmount (ERC20 (freeRateTokenSymbols[fromSymb]), freeRateForexBytes[toSymb], amount);
749
768
return toRate2.mul (rateMultiply2).div (rateDivide2);
750
769
}
751
770
752
771
//forex to token
753
772
else if (freeRateTokenSymbols[fromSymb] == 0x0 && freeRateTokenSymbols[toSymb] != 0x0 ) {
754
773
774
+ if (equal (toSymb,"ETH " )){
775
+ toSymb = "ETH2 " ;
776
+ }
777
+
755
778
uint256 toRate3 = getSynthToTokenOutputAmount (freeRateForexBytes[fromSymb], ERC20 (freeRateTokenSymbols[toSymb]), amount);
756
779
return toRate3.mul (rateMultiply3).div (rateDivide3);
757
780
}
@@ -760,7 +783,8 @@ contract orfeed {
760
783
//forex to forex
761
784
762
785
else if (freeRateTokenSymbols[fromSymb] == 0x0 && freeRateTokenSymbols[toSymb] == 0x0 ) {
763
-
786
+
787
+ se = SynthetixExchange (synthetixExchangeAddress);
764
788
uint256 toRate4 = se.effectiveValue (freeRateForexBytes[fromSymb], amount, freeRateForexBytes[toSymb]);
765
789
return toRate4.mul (rateMultiply4).div (rateDivide4);
766
790
}
@@ -780,6 +804,58 @@ contract orfeed {
780
804
result := mload (add (source, 32 ))
781
805
}
782
806
}
807
+
808
+ function compare (string _a , string _b ) returns (int ) {
809
+ bytes memory a = bytes (_a);
810
+ bytes memory b = bytes (_b);
811
+ uint minLength = a.length ;
812
+ if (b.length < minLength) minLength = b.length ;
813
+ //@todo unroll the loop into increments of 32 and do full 32 byte comparisons
814
+ for (uint i = 0 ; i < minLength; i ++ )
815
+ if (a[i] < b[i])
816
+ return - 1 ;
817
+ else if (a[i] > b[i])
818
+ return 1 ;
819
+ if (a.length < b.length )
820
+ return - 1 ;
821
+ else if (a.length > b.length )
822
+ return 1 ;
823
+ else
824
+ return 0 ;
825
+ }
826
+
827
+ function equal (string _a , string _b ) returns (bool ) {
828
+ return compare (_a, _b) == 0 ;
829
+ }
830
+
831
+ function indexOf (string _haystack , string _needle ) returns (int )
832
+ {
833
+ bytes memory h = bytes (_haystack);
834
+ bytes memory n = bytes (_needle);
835
+ if (h.length < 1 || n.length < 1 || (n.length > h.length ))
836
+ return - 1 ;
837
+ else if (h.length > (2 ** 128 - 1 )) // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1)
838
+ return - 1 ;
839
+ else
840
+ {
841
+ uint subindex = 0 ;
842
+ for (uint i = 0 ; i < h.length ; i ++ )
843
+ {
844
+ if (h[i] == n[0 ]) // found the first char of b
845
+ {
846
+ subindex = 1 ;
847
+ while (subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) // search until the chars don't match or until we reach the end of a or b
848
+ {
849
+ subindex++ ;
850
+ }
851
+ if (subindex == n.length )
852
+ return int (i);
853
+ }
854
+ }
855
+ return - 1 ;
856
+ }
857
+ }
858
+
783
859
784
860
785
861
//end contract
0 commit comments