├── .eslintignore ├── .eslintrc.json ├── .gitattributes ├── .github └── workflows │ └── node.js.yml ├── .gitignore ├── .node-version ├── .prettierignore ├── .prettierrc ├── .snyk ├── .solcover.js ├── .solhint.json ├── ADD-POOLS.md ├── CHANGELOG.md ├── LICENSE ├── README.md ├── docs ├── BProOracle.md ├── ChainlinkBTCToUSDOracle.md ├── ChainlinkETHToETHOracle.md ├── ChainlinkUSDToBTCOracle.md ├── ContractRegistry.md ├── ContractRegistryClient.md ├── ConversionPathFinder.md ├── ConverterBase.md ├── ConverterFactory.md ├── ConverterRegistry.md ├── ConverterRegistryData.md ├── ConverterUpgrader.md ├── ConverterV27OrLowerWithFallback.md ├── ConverterV27OrLowerWithoutFallback.md ├── ConverterV28OrHigherWithFallback.md ├── ConverterV28OrHigherWithoutFallback.md ├── ERC20Token.md ├── EtherToken.md ├── IConsumerPriceOracle.md ├── IContractRegistry.md ├── IConversionPathFinder.md ├── IConverter.md ├── IConverterAnchor.md ├── IConverterFactory.md ├── IConverterRegistry.md ├── IConverterRegistryData.md ├── IConverterUpgrader.md ├── IERC20Token.md ├── IEtherToken.md ├── IFeeSharingProxy.md ├── IInternalSovrynSwapNetwork.md ├── ILegacyConverter.md ├── ILiquidityPoolV1Converter.md ├── ILiquidityPoolV2Converter.md ├── IMoCState.md ├── IOracle.md ├── IOwned.md ├── IPoolTokensContainer.md ├── IPriceOracle.md ├── ISmartToken.md ├── ISovrynSwapFormula.md ├── ISovrynSwapNetwork.md ├── ISovrynSwapX.md ├── ISovrynSwapXUpgrader.md ├── ISwapSettings.md ├── ITokenHolder.md ├── ITypedConverterAnchorFactory.md ├── ITypedConverterCustomFactory.md ├── ITypedConverterFactory.md ├── IWhitelist.md ├── LiquidTokenConverter.md ├── LiquidTokenConverterFactory.md ├── LiquidityPoolConverter.md ├── LiquidityPoolV1Converter.md ├── LiquidityPoolV1ConverterFactory.md ├── LiquidityPoolV1ConverterMultiAsset.md ├── LiquidityPoolV2Converter.md ├── LiquidityPoolV2ConverterAnchorFactory.md ├── LiquidityPoolV2ConverterCustomFactory.md ├── LiquidityPoolV2ConverterFactory.md ├── Medianizer.md ├── MocBTCToBTCOracle.md ├── MocBTCToUSDOracle.md ├── MocUSDToBTCOracle.md ├── MultiSigWallet.md ├── NewConverter.md ├── NonStandardToken.md ├── NonStandardTokenDetailed.md ├── OldConverter.md ├── Oracle.md ├── Owned.md ├── PoolTokensContainer.md ├── PriceOracle.md ├── ReentrancyGuard.md ├── SafeMath.md ├── SmartToken.md ├── SovrynSwapFormula.md ├── SovrynSwapNetwork.md ├── SovrynSwapX.md ├── SwapSettings.md ├── TokenHandler.md ├── TokenHolder.md ├── Utils.md ├── Whitelist.md └── XTransferRerouter.md ├── hardhat.config.js ├── package-lock.json ├── package.json ├── rbtcwrapperproxy ├── .minimum-gas-price-testnet.json ├── build │ └── contracts │ │ ├── Address.json │ │ ├── ContractRegistryClient.json │ │ ├── IConsumerPriceOracle.json │ │ ├── IContractRegistry.json │ │ ├── IConverterAnchor.json │ │ ├── IERC20.json │ │ ├── IERC20Token.json │ │ ├── IEtherToken.json │ │ ├── ILiquidityPoolV1Converter.json │ │ ├── ILiquidityPoolV2Converter.json │ │ ├── IOwned.json │ │ ├── ISmartToken.json │ │ ├── ISovrynSwapFormula.json │ │ ├── ISovrynSwapNetwork.json │ │ ├── ISovrynSwapX.json │ │ ├── ITokenHolder.json │ │ ├── IWrbtc.json │ │ ├── IWrbtcERC20.json │ │ ├── Migrations.json │ │ ├── Owned.json │ │ ├── ReentrancyGuard.json │ │ ├── SafeMath.json │ │ ├── Utils.json │ │ └── WRBTC.json ├── contracts │ ├── ContractRegistryClient.sol │ ├── Migrations.sol │ ├── RBTCWrapperProxy.sol │ ├── WRBTC.sol │ ├── interfaces │ │ ├── IConsumerPriceOracle.sol │ │ ├── IContractRegistry.sol │ │ ├── IConverterAnchor.sol │ │ ├── IERC20.sol │ │ ├── IERC20Token.sol │ │ ├── IEtherToken.sol │ │ ├── ILiquidityPoolV1Converter.sol │ │ ├── ILiquidityPoolV2Converter.sol │ │ ├── ILoanToken.sol │ │ ├── IOwned.sol │ │ ├── ISmartToken.sol │ │ ├── ISovrynSwapFormula.sol │ │ ├── ISovrynSwapNetwork.sol │ │ ├── ISovrynSwapX.sol │ │ ├── ITokenHolder.sol │ │ ├── IWrbtc.sol │ │ └── IWrbtcERC20.sol │ ├── mockups │ │ ├── LiquidityMining.sol │ │ └── LoanToken.sol │ └── openzeppelin │ │ ├── Address.sol │ │ ├── Owned.sol │ │ ├── ReentrancyGuard.sol │ │ ├── SafeMath.sol │ │ └── Utils.sol ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_RBTCWrapperProxy.js ├── test │ └── testRBTCWrapperProxy.js └── truffle-config.js ├── scripts ├── compile.sh ├── deploy-one.js ├── export.js ├── flatten.js └── verify-all.js ├── solidity ├── build │ ├── BProOracle.abi │ ├── BProOracle.bin │ ├── ChainlinkETHToETHOracle.abi │ ├── ChainlinkETHToETHOracle.bin │ ├── ContractRegistry.abi │ ├── ContractRegistry.bin │ ├── ContractRegistryClient.abi │ ├── ContractRegistryClient.bin │ ├── ConversionPathFinder.abi │ ├── ConversionPathFinder.bin │ ├── ConverterBase.abi │ ├── ConverterBase.bin │ ├── ConverterFactory.abi │ ├── ConverterFactory.bin │ ├── ConverterRegistry.abi │ ├── ConverterRegistry.bin │ ├── ConverterRegistryData.abi │ ├── ConverterRegistryData.bin │ ├── ConverterUpgrader.abi │ ├── ConverterUpgrader.bin │ ├── ERC20Token.abi │ ├── ERC20Token.bin │ ├── EtherToken.abi │ ├── EtherToken.bin │ ├── IConsumerPriceOracle.abi │ ├── IConsumerPriceOracle.bin │ ├── IContractRegistry.abi │ ├── IContractRegistry.bin │ ├── IConversionPathFinder.abi │ ├── IConversionPathFinder.bin │ ├── IConverter.abi │ ├── IConverter.bin │ ├── IConverterAnchor.abi │ ├── IConverterAnchor.bin │ ├── IConverterFactory.abi │ ├── IConverterFactory.bin │ ├── IConverterRegistry.abi │ ├── IConverterRegistry.bin │ ├── IConverterRegistryData.abi │ ├── IConverterRegistryData.bin │ ├── IConverterUpgrader.abi │ ├── IConverterUpgrader.bin │ ├── IERC20Token.abi │ ├── IERC20Token.bin │ ├── IEtherToken.abi │ ├── IEtherToken.bin │ ├── ILegacyConverter.abi │ ├── ILegacyConverter.bin │ ├── ILiquidityPoolV2Converter.abi │ ├── ILiquidityPoolV2Converter.bin │ ├── IMoCState.abi │ ├── IMoCState.bin │ ├── IOwned.abi │ ├── IOwned.bin │ ├── IPoolTokensContainer.abi │ ├── IPoolTokensContainer.bin │ ├── IPriceOracle.abi │ ├── IPriceOracle.bin │ ├── ISmartToken.abi │ ├── ISmartToken.bin │ ├── ISovrynSwapFormula.abi │ ├── ISovrynSwapFormula.bin │ ├── ISovrynSwapNetwork.abi │ ├── ISovrynSwapNetwork.bin │ ├── ISovrynSwapX.abi │ ├── ISovrynSwapX.bin │ ├── ISovrynSwapXUpgrader.abi │ ├── ISovrynSwapXUpgrader.bin │ ├── ITokenHolder.abi │ ├── ITokenHolder.bin │ ├── ITypedConverterAnchorFactory.abi │ ├── ITypedConverterAnchorFactory.bin │ ├── ITypedConverterCustomFactory.abi │ ├── ITypedConverterCustomFactory.bin │ ├── ITypedConverterFactory.abi │ ├── ITypedConverterFactory.bin │ ├── IWhitelist.abi │ ├── IWhitelist.bin │ ├── LiquidTokenConverter.abi │ ├── LiquidTokenConverter.bin │ ├── LiquidTokenConverterFactory.abi │ ├── LiquidTokenConverterFactory.bin │ ├── LiquidityPoolConverter.abi │ ├── LiquidityPoolConverter.bin │ ├── LiquidityPoolV1Converter.abi │ ├── LiquidityPoolV1Converter.bin │ ├── LiquidityPoolV1ConverterFactory.abi │ ├── LiquidityPoolV1ConverterFactory.bin │ ├── LiquidityPoolV2Converter.abi │ ├── LiquidityPoolV2Converter.bin │ ├── LiquidityPoolV2ConverterAnchorFactory.abi │ ├── LiquidityPoolV2ConverterAnchorFactory.bin │ ├── LiquidityPoolV2ConverterCustomFactory.abi │ ├── LiquidityPoolV2ConverterCustomFactory.bin │ ├── LiquidityPoolV2ConverterFactory.abi │ ├── LiquidityPoolV2ConverterFactory.bin │ ├── Medianizer.abi │ ├── Medianizer.bin │ ├── MoCMedianizerMock.abi │ ├── MoCMedianizerMock.bin │ ├── MoCOracleMock.abi │ ├── MoCOracleMock.bin │ ├── MoCStateMock.abi │ ├── MoCStateMock.bin │ ├── MocBTCToBTCOracle.abi │ ├── MocBTCToBTCOracle.bin │ ├── MocBTCToUSDOracle.abi │ ├── MocBTCToUSDOracle.bin │ ├── MocUSDToBTCOracle.abi │ ├── MocUSDToBTCOracle.bin │ ├── Owned.abi │ ├── Owned.bin │ ├── PoolTokensContainer.abi │ ├── PoolTokensContainer.bin │ ├── PriceOracle.abi │ ├── PriceOracle.bin │ ├── ReentrancyGuard.abi │ ├── ReentrancyGuard.bin │ ├── SafeMath.abi │ ├── SafeMath.bin │ ├── SmartToken.abi │ ├── SmartToken.bin │ ├── SovrynSwapFormula.abi │ ├── SovrynSwapFormula.bin │ ├── SovrynSwapNetwork.abi │ ├── SovrynSwapNetwork.bin │ ├── SovrynSwapX.abi │ ├── SovrynSwapX.bin │ ├── TokenHandler.abi │ ├── TokenHandler.bin │ ├── TokenHolder.abi │ ├── TokenHolder.bin │ ├── Utils.abi │ ├── Utils.bin │ ├── WRBTC.abi │ ├── WRBTC.bin │ ├── Whitelist.abi │ ├── Whitelist.bin │ ├── XTransferRerouter.abi │ └── XTransferRerouter.bin ├── contracts │ ├── ConversionPathFinder.sol │ ├── IConversionPathFinder.sol │ ├── ISovrynSwapNetwork.sol │ ├── SovrynSwapNetwork.sol │ ├── converter │ │ ├── ConverterBase.sol │ │ ├── ConverterFactory.sol │ │ ├── ConverterRegistry.sol │ │ ├── ConverterRegistryData.sol │ │ ├── ConverterUpgrader.sol │ │ ├── LiquidityPoolConverter.sol │ │ ├── SovrynSwapFormula.sol │ │ ├── SwapSettings.sol │ │ ├── interfaces │ │ │ ├── IConverter.sol │ │ │ ├── IConverterAnchor.sol │ │ │ ├── IConverterFactory.sol │ │ │ ├── IConverterRegistry.sol │ │ │ ├── IConverterRegistryData.sol │ │ │ ├── IConverterUpgrader.sol │ │ │ ├── ILiquidityPoolV1Converter.sol │ │ │ ├── ISovrynSwapFormula.sol │ │ │ ├── ITypedConverterAnchorFactory.sol │ │ │ ├── ITypedConverterCustomFactory.sol │ │ │ └── ITypedConverterFactory.sol │ │ └── types │ │ │ ├── liquid-token │ │ │ ├── LiquidTokenConverter.sol │ │ │ └── LiquidTokenConverterFactory.sol │ │ │ ├── liquidity-pool-v1 │ │ │ ├── LiquidityPoolV1Converter.sol │ │ │ ├── LiquidityPoolV1ConverterFactory.sol │ │ │ └── LiquidityPoolV1ConverterMultiAsset.sol │ │ │ └── liquidity-pool-v2 │ │ │ ├── LiquidityPoolV2Converter.sol │ │ │ ├── LiquidityPoolV2ConverterAnchorFactory.sol │ │ │ ├── LiquidityPoolV2ConverterCustomFactory.sol │ │ │ ├── LiquidityPoolV2ConverterFactory.sol │ │ │ ├── PoolTokensContainer.sol │ │ │ └── interfaces │ │ │ ├── ILiquidityPoolV2Converter.sol │ │ │ └── IPoolTokensContainer.sol │ ├── helpers │ │ ├── TestChainlinkPriceOracle.sol │ │ ├── TestContractRegistryClient.sol │ │ ├── TestConverterFactory.sol │ │ ├── TestConverterRegistry.sol │ │ ├── TestLiquidityPoolConverter.sol │ │ ├── TestLiquidityPoolV2Converter.sol │ │ ├── TestReentrancyGuard.sol │ │ ├── TestSafeMath.sol │ │ ├── TestSovrynSwapFormula.sol │ │ ├── TestSovrynSwapNetwork.sol │ │ ├── TestTokenHandler.sol │ │ ├── TestTokens.sol │ │ └── TestTypedConverterAnchorFactory.sol │ ├── mockup │ │ ├── FeeSharingProxyMockup.sol │ │ └── SovrynSwapNetworkMockup.sol │ ├── sovrynswapx │ │ ├── SovrynSwapX.sol │ │ ├── XTransferRerouter.sol │ │ └── interfaces │ │ │ ├── ISovrynSwapX.sol │ │ │ └── ISovrynSwapXUpgrader.sol │ ├── token │ │ ├── ERC20Token.sol │ │ ├── EtherToken.sol │ │ ├── SmartToken.sol │ │ └── interfaces │ │ │ ├── IERC20Token.sol │ │ │ ├── IEtherToken.sol │ │ │ └── ISmartToken.sol │ └── utility │ │ ├── BProOracle.sol │ │ ├── ChainlinkBTCToUSDOracle.sol │ │ ├── ChainlinkETHToETHOracle.sol │ │ ├── ChainlinkUSDToBTCOracle.sol │ │ ├── ContractRegistry.sol │ │ ├── ContractRegistryClient.sol │ │ ├── MoCMedianizerMock.sol │ │ ├── MoCStateMock.sol │ │ ├── MocBTCToBTCOracle.sol │ │ ├── MocBTCToUSDOracle.sol │ │ ├── MocUSDToBTCOracle.sol │ │ ├── MultiSigWallet.sol │ │ ├── Oracle.sol │ │ ├── Owned.sol │ │ ├── PriceOracle.sol │ │ ├── ReentrancyGuard.sol │ │ ├── SafeMath.sol │ │ ├── TokenHandler.sol │ │ ├── TokenHolder.sol │ │ ├── Utils.sol │ │ ├── Whitelist.sol │ │ └── interfaces │ │ ├── IConsumerPriceOracle.sol │ │ ├── IContractRegistry.sol │ │ ├── IMoCState.sol │ │ ├── IOracle.sol │ │ ├── IOwned.sol │ │ ├── IPriceOracle.sol │ │ ├── ITokenHolder.sol │ │ └── IWhitelist.sol ├── python │ ├── AutoGenerate │ │ ├── PrintFileFormulaConstants.py │ │ ├── PrintFunctionGeneralExp.py │ │ ├── PrintFunctionLambertNeg1.py │ │ ├── PrintFunctionLambertPos1.py │ │ ├── PrintFunctionOptimalExp.py │ │ ├── PrintFunctionOptimalLog.py │ │ ├── PrintIntScalingFactors.py │ │ ├── PrintLambertArray.py │ │ ├── PrintLambertFactors.py │ │ ├── PrintLn2ScalingFactors.py │ │ ├── PrintMaxExpArray.py │ │ ├── PrintMaxExpPerPrecision.py │ │ ├── PrintWeightFactors.py │ │ └── common │ │ │ ├── __init__.py │ │ │ ├── constants.py │ │ │ └── functions.py │ ├── BenchmarkTestPurchase.py │ ├── BenchmarkTestSale.py │ ├── CoverageExpTestPurchase.py │ ├── CoverageExpTestSale.py │ ├── CoverageUniTestPurchase.py │ ├── CoverageUniTestSale.py │ ├── EmulationExpTestCross.py │ ├── EmulationExpTestFund.py │ ├── EmulationExpTestFundInv.py │ ├── EmulationExpTestLiquidate.py │ ├── EmulationExpTestPurchase.py │ ├── EmulationExpTestSale.py │ ├── EmulationExpTestWeights.py │ ├── EmulationUniTestCross.py │ ├── EmulationUniTestFund.py │ ├── EmulationUniTestFundInv.py │ ├── EmulationUniTestLiquidate.py │ ├── EmulationUniTestPurchase.py │ ├── EmulationUniTestSale.py │ ├── EmulationUniTestWeights.py │ ├── FormulaNativePython │ │ └── __init__.py │ ├── FormulaSolidityPort │ │ └── __init__.py │ ├── InputGenerator │ │ └── __init__.py │ ├── MongoExpTestPurchase.py │ ├── MongoExpTestSale.py │ ├── MongoUniTestPurchase.py │ ├── MongoUniTestSale.py │ ├── PerformanceExpTestCross.py │ ├── PerformanceExpTestFund.py │ ├── PerformanceExpTestFundInv.py │ ├── PerformanceExpTestLiquidate.py │ ├── PerformanceExpTestPurchase.py │ ├── PerformanceExpTestSale.py │ ├── PerformanceExpTestWeights.py │ ├── PerformanceUniTestCross.py │ ├── PerformanceUniTestFund.py │ ├── PerformanceUniTestFundInv.py │ ├── PerformanceUniTestLiquidate.py │ ├── PerformanceUniTestPurchase.py │ ├── PerformanceUniTestSale.py │ ├── PerformanceUniTestWeights.py │ ├── README.md │ ├── RandomTestCross.py │ ├── RandomTestFund.py │ ├── RandomTestFundInv.py │ ├── RandomTestLambertNeg1.py │ ├── RandomTestLambertPos1.py │ ├── RandomTestLambertPos2.py │ ├── RandomTestLambertPos3.py │ ├── RandomTestLiquidate.py │ ├── RandomTestPower.py │ ├── RandomTestPurchase.py │ ├── RandomTestSale.py │ ├── RandomTestTradeCC.py │ ├── RandomTestTradeCPS.py │ ├── RandomTestTradeFSC.py │ ├── RandomTestTradeFSPS.py │ ├── RandomTestTradeLPP.py │ ├── RandomTestTradePS.py │ ├── RandomTestTradePSC.py │ ├── RandomTestTradeSP.py │ ├── RandomTestVerifyCross.py │ ├── RandomTestVerifyFund.py │ ├── RandomTestVerifyFundInv.py │ ├── RandomTestVerifyWeights.py │ ├── RunGanache.py │ ├── Utilities │ │ ├── Changer │ │ │ ├── Decrease.py │ │ │ └── Increase.py │ │ ├── Converter │ │ │ ├── engine │ │ │ │ └── __init__.py │ │ │ ├── example_commands.json │ │ │ ├── example_model.json │ │ │ └── run.py │ │ └── V2Flow │ │ │ ├── engine │ │ │ └── __init__.py │ │ │ ├── example_commands.json │ │ │ ├── example_report.csv │ │ │ └── run.py │ └── Web3Wrapper │ │ └── __init__.py ├── test │ ├── BProOracle.js │ ├── ChainlinkBTCToUSDOracle.js │ ├── ChainlinkETHToETHOracle.js │ ├── ContractRegistry.js │ ├── ContractRegistryClient.js │ ├── ConversionPathFinder.js │ ├── Converter.js │ ├── ConverterFactory.js │ ├── ConverterLiquidity.js │ ├── ConverterRegistry.js │ ├── ConverterRegistryData.js │ ├── ConverterUpgrader.js │ ├── ERC20Token.js │ ├── EtherToken.js │ ├── LiquidTokenConverter.js │ ├── LiquidityPoolConverter.js │ ├── LiquidityPoolV1Converter.js │ ├── LiquidityPoolV1ConverterMultiAsset.js │ ├── LiquidityPoolV2Converter.js │ ├── LiquidityPoolV2ConverterStateless.js │ ├── MocBTCToBTCOracle.js │ ├── MocBTCToUSDOracle.js │ ├── MocUSDToBTCOracle.js │ ├── Oracle.js │ ├── Owned.js │ ├── PoolTokensContainer.js │ ├── PriceOracle.js │ ├── ReentrancyGuard.js │ ├── SafeMath.js │ ├── SmartToken.js │ ├── SovrySwapX.js │ ├── SovrynSwapFormula.js │ ├── SovrynSwapNetwork.js │ ├── SovrynSwapNetworkWithOldConverter.js │ ├── SovrynSwapNetworkWithOldEtherToken.js │ ├── TokenHandler.js │ ├── TokenHolder.js │ ├── Whitelist.js │ ├── XConversions.js │ ├── XTransferRerouter.js │ ├── bin │ │ ├── converter_v10.abi │ │ ├── converter_v10.bin │ │ ├── converter_v11.abi │ │ ├── converter_v11.bin │ │ ├── converter_v23.abi │ │ ├── converter_v23.bin │ │ ├── converter_v4.abi │ │ ├── converter_v4.bin │ │ ├── converter_v9.abi │ │ └── converter_v9.bin │ └── helpers │ │ ├── Constants.js │ │ ├── Converter.js │ │ ├── FormulaConstants.js │ │ ├── FormulaFunctions.js │ │ └── lib.js └── utils │ ├── README.md │ ├── addBNBs_mainnet.json │ ├── addBNBs_testnet.json │ ├── addBPro.json │ ├── addConverter.js │ ├── addETH.json │ ├── addETH_mainnet.json │ ├── addETH_testnet.json │ ├── addETHs_mainnet.json │ ├── addETHs_testnet.json │ ├── addETHx_testnet.json │ ├── addMoC_mainnet.json │ ├── addMoC_testnet.json │ ├── addSOV.json │ ├── addUSDT.json │ ├── addXUSD_mainnet.json │ ├── addXUSD_testnet.json │ ├── addesETH.json │ ├── command.txt │ ├── config_rsk copy.json │ ├── config_rsk.json │ ├── data_mainnet.json │ ├── data_testnet.json │ ├── deployment_rsk.js │ ├── multisig.js │ ├── sampleETH.json │ ├── upgradeConverter.js │ └── upgrade_config.json ├── solidoc.json └── truffle-config.js /.eslintignore: -------------------------------------------------------------------------------- 1 | /coverage 2 | truffle-config.js -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "prettier", 3 | "parserOptions": { 4 | "ecmaVersion": 2020 5 | }, 6 | "env": { 7 | "es6": true, 8 | "mocha": true 9 | }, 10 | "rules": { 11 | }, 12 | "globals": { 13 | "assert": true, 14 | "expect": true, 15 | "artifacts": true, 16 | "contract": true, 17 | "web3": true 18 | }, 19 | "settings": { 20 | "react": { 21 | "version": "999.999.999" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | node-version: [12.x, 14.x] 17 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | - name: Use Node.js ${{ matrix.node-version }} 22 | uses: actions/setup-node@v2 23 | with: 24 | node-version: ${{ matrix.node-version }} 25 | - run: npm ci 26 | - run: npm run lint 27 | - run: npm run coverage 28 | - run: cat coverage/lcov.info | coveralls -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vscode/ 3 | */**/.DS_Store 4 | 5 | # node 6 | /node_modules 7 | npm-debug.log 8 | 9 | # python 10 | *.pyc 11 | 12 | solidity/build/contracts 13 | .coverage_artifacts 14 | .coverage_contracts 15 | coverage 16 | coverageEnv 17 | coverage.json 18 | allFiredEvents 19 | scTopics 20 | 21 | solidity/build/ConverterV* 22 | solidity/build/NewConverter* 23 | solidity/build/NonStandardToken* 24 | solidity/build/OldConverter* 25 | solidity/build/Test* 26 | 27 | .history 28 | *.iml 29 | .idea 30 | 31 | /rbtcwrapperproxy/.secrets 32 | /rbtcwrapperproxy/private-key 33 | /rbtcwrapperproxy/build 34 | 35 | *.code-workspace 36 | .env 37 | yarn.lock 38 | 39 | artifacts/ 40 | cache/ -------------------------------------------------------------------------------- /.node-version: -------------------------------------------------------------------------------- 1 | v10.16.0 -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .DS_Store 3 | .history 4 | .hypothesis/ 5 | build/ 6 | reports/ 7 | node_modules/ 8 | !.solhint.json 9 | package-lock.json 10 | coverage 11 | coverage.json -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "overrides": [ 3 | { 4 | "files": ["*.sol", "*.js"], 5 | "options": { 6 | "printWidth": 150, 7 | "tabWidth": 4, 8 | "useTabs": true, 9 | "singleQuote": false, 10 | "bracketSpacing": true, 11 | "explicitTypes": "always" 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /.snyk: -------------------------------------------------------------------------------- 1 | # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. 2 | version: v1.14.0 3 | ignore: {} 4 | # patches apply the minimum changes required to fix a vulnerability 5 | patch: 6 | SNYK-JS-TREEKILL-536781: 7 | - solidity-coverage > tree-kill: 8 | patched: '2019-12-12T13:55:11.672Z' 9 | SNYK-JS-LODASH-450202: 10 | - snyk > @snyk/dep-graph > lodash: 11 | patched: '2019-12-12T13:56:19.599Z' 12 | - snyk > @snyk/snyk-cocoapods-plugin > @snyk/dep-graph > lodash: 13 | patched: '2019-12-12T13:56:19.599Z' 14 | - snyk > snyk-nuget-plugin > dotnet-deps-parser > lodash: 15 | patched: '2019-12-12T13:56:19.599Z' 16 | - snyk > @snyk/snyk-cocoapods-plugin > @snyk/cocoapods-lockfile-parser > @snyk/dep-graph > lodash: 17 | patched: '2019-12-12T13:56:19.599Z' 18 | -------------------------------------------------------------------------------- /.solcover.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle run coverage', 3 | compileCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle compile', 4 | skipFiles: [ 5 | 'contracts/helpers' 6 | ], 7 | providerOptions: { 8 | default_balance_ether: 10000000000000000000 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "rules": { 4 | "avoid-throw": "off", 5 | "avoid-suicide": "error", 6 | "avoid-sha3": "warn", 7 | "not-rely-on-time": "off", 8 | "no-empty-blocks": "off", 9 | "mark-callable-contracts": "off", 10 | "compiler-version": [ 11 | "error", 12 | "0.4.26" 13 | ] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.8.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require( 10 | msg.sender == owner, 11 | "This function is restricted to the contract's owner" 12 | ); 13 | _; 14 | } 15 | 16 | function setCompleted(uint completed) public restricted { 17 | last_completed_migration = completed; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IConsumerPriceOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | /* 4 | Chainlink Price Oracle interface 5 | */ 6 | interface IConsumerPriceOracle { 7 | function latestAnswer() external view returns (int256); 8 | 9 | function latestTimestamp() external view returns (uint256); 10 | } 11 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IContractRegistry.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.5.16; 2 | 3 | /* 4 | Contract Registry interface 5 | */ 6 | contract IContractRegistry { 7 | function addressOf(bytes32 _contractName) public view returns (address); 8 | 9 | // deprecated, backward compatibility 10 | function getAddress(bytes32 _contractName) public view returns (address); 11 | } 12 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IConverterAnchor.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | import "./IOwned.sol"; 4 | import "./ITokenHolder.sol"; 5 | 6 | /* 7 | Converter Anchor interface 8 | */ 9 | contract IConverterAnchor is IOwned, ITokenHolder { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2020, bZeroX, LLC. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0. 4 | */ 5 | 6 | pragma solidity >=0.5.0 <0.6.0; 7 | 8 | contract IERC20 { 9 | string public name; 10 | uint8 public decimals; 11 | string public symbol; 12 | 13 | function totalSupply() public view returns (uint256); 14 | 15 | function balanceOf(address _who) public view returns (uint256); 16 | 17 | function transfer(address _to, uint256 _value) public returns (bool); 18 | 19 | function allowance(address _owner, address _spender) public view returns (uint256); 20 | 21 | function transferFrom( 22 | address _from, 23 | address _to, 24 | uint256 _value 25 | ) public returns (bool); 26 | 27 | function approve(address _spender, uint256 _value) public returns (bool); 28 | 29 | event Transfer(address indexed from, address indexed to, uint256 value); 30 | event Approval(address indexed owner, address indexed spender, uint256 value); 31 | } 32 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IERC20Token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | /* 4 | ERC20 Standard Token interface 5 | */ 6 | contract IERC20Token { 7 | // these functions aren't abstract since the compiler emits automatically generated getter functions as external 8 | function name() public view returns (string memory) { 9 | this; 10 | } 11 | 12 | function symbol() public view returns (string memory) { 13 | this; 14 | } 15 | 16 | function decimals() public view returns (uint8) { 17 | this; 18 | } 19 | 20 | function totalSupply() public view returns (uint256) { 21 | this; 22 | } 23 | 24 | function balanceOf(address _owner) public view returns (uint256) { 25 | _owner; 26 | this; 27 | } 28 | 29 | function allowance(address _owner, address _spender) public view returns (uint256) { 30 | _owner; 31 | _spender; 32 | this; 33 | } 34 | 35 | function transfer(address _to, uint256 _value) public returns (bool success); 36 | 37 | function transferFrom( 38 | address _from, 39 | address _to, 40 | uint256 _value 41 | ) public returns (bool success); 42 | 43 | function approve(address _spender, uint256 _value) public returns (bool success); 44 | } 45 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IEtherToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | import "./IERC20Token.sol"; 3 | 4 | /* 5 | Ether Token interface 6 | */ 7 | contract IEtherToken is IERC20Token { 8 | function deposit() public payable; 9 | 10 | function withdraw(uint256 _amount) public; 11 | 12 | function depositTo(address _to) public payable; 13 | 14 | function withdrawTo(address _to, uint256 _amount) public; 15 | } 16 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/ILoanToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.5.16; 2 | 3 | import "./IERC20Token.sol"; 4 | 5 | /** 6 | This is just a mockup for the Loan Token contract in the Sovryn-smart-contracts repository 7 | */ 8 | contract LoanToken is IERC20Token{ 9 | address public loanTokenAddress; 10 | 11 | /** 12 | * @notice lend to the pool 13 | * @param _amount the amount of underlying tokens 14 | * @param _user the address of user, tokens will be deposited to it or to msg.sender 15 | */ 16 | function mint(address _user, uint256 _amount) public returns (uint256 mintAmount){ 17 | 18 | } 19 | 20 | /** 21 | * @notice burns pool tokens and transfers underlying tokens 22 | * @param _user the address of the receiver 23 | * @param _amount the amount of pool tokens 24 | */ 25 | function burn(address _user, uint256 _amount) public returns (uint256 redeemedAmount){ 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IOwned.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | /* 4 | Owned contract interface 5 | */ 6 | contract IOwned { 7 | // this function isn't abstract since the compiler emits automatically generated getter functions as external 8 | function owner() public view returns (address) { 9 | this; 10 | } 11 | 12 | function transferOwnership(address _newOwner) public; 13 | 14 | function acceptOwnership() public; 15 | } 16 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/ISmartToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | import "./IERC20Token.sol"; 4 | import "./IConverterAnchor.sol"; 5 | import "./IOwned.sol"; 6 | 7 | /* 8 | Smart Token interface 9 | */ 10 | contract ISmartToken is IConverterAnchor, IERC20Token { 11 | function disableTransfers(bool _disable) public; 12 | 13 | function issue(address _to, uint256 _amount) public; 14 | 15 | function destroy(address _from, uint256 _amount) public; 16 | } 17 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/ISovrynSwapX.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | import "./IERC20Token.sol"; 3 | 4 | contract ISovrynSwapX { 5 | function token() public view returns (IERC20Token) { 6 | this; 7 | } 8 | 9 | function xTransfer( 10 | bytes32 _toBlockchain, 11 | bytes32 _to, 12 | uint256 _amount, 13 | uint256 _id 14 | ) public; 15 | 16 | function getXTransferAmount(uint256 _xTransferId, address _for) public view returns (uint256); 17 | } 18 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/ITokenHolder.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | import "./IOwned.sol"; 4 | import "./IERC20Token.sol"; 5 | 6 | /* 7 | Token Holder interface 8 | */ 9 | contract ITokenHolder is IOwned { 10 | function withdrawTokens( 11 | IERC20Token _token, 12 | address _to, 13 | uint256 _amount 14 | ) public; 15 | } 16 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IWrbtc.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2020, bZeroX, LLC. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0. 4 | */ 5 | 6 | pragma solidity >=0.5.0 <0.6.0; 7 | 8 | interface IWrbtc { 9 | function deposit() external payable; 10 | 11 | function withdraw(uint256 wad) external; 12 | } 13 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/interfaces/IWrbtcERC20.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2020, bZeroX, LLC. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0. 4 | */ 5 | 6 | pragma solidity >=0.5.0 <0.6.0; 7 | 8 | import "./IWrbtc.sol"; 9 | import "./IERC20.sol"; 10 | 11 | contract IWrbtcERC20 is IWrbtc, IERC20 {} 12 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/mockups/LiquidityMining.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.5.16; 2 | 3 | import "../interfaces/IERC20Token.sol"; 4 | 5 | /** 6 | This is just a mockup for the Liquidity Mining contract in the Sovryn-smart-contracts repository 7 | */ 8 | contract LiquidityMining{ 9 | address rewardToken; 10 | 11 | mapping( address => mapping(address => uint)) public userLPBalance; 12 | 13 | constructor(address rewardTokenAddress) public{ 14 | rewardToken = rewardTokenAddress; 15 | } 16 | /** 17 | * @notice deposits pool tokens 18 | * @param _poolToken the address of pool token 19 | * @param _amount the amount of pool tokens 20 | * @param _user the address of user, tokens will be deposited to it or to msg.sender 21 | */ 22 | function deposit(address _poolToken, uint256 _amount, address _user) public { 23 | IERC20Token(_poolToken).transferFrom(address(msg.sender), address(this), _amount); 24 | userLPBalance[_user][_poolToken] += _amount; 25 | } 26 | 27 | /** 28 | * @notice withdraws pool tokens and transfers reward tokens 29 | * @param _poolToken the address of pool token 30 | * @param _amount the amount of pool tokens 31 | */ 32 | function withdraw(address _poolToken, uint256 _amount, address _user) public { 33 | require(userLPBalance[_user][_poolToken] >= _amount, "insufficient LP balance"); 34 | userLPBalance[_user][_poolToken] -= _amount; 35 | IERC20Token(_poolToken).transfer(address(msg.sender), _amount); 36 | IERC20Token(rewardToken).transfer(address(_user), _amount); 37 | } 38 | } -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/openzeppelin/Owned.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.5.16; 2 | 3 | /** 4 | * @dev Provides support and utilities for contract ownership 5 | */ 6 | contract Owned { 7 | address public owner; 8 | address public newOwner; 9 | 10 | /** 11 | * @dev triggered when the owner is updated 12 | * 13 | * @param _prevOwner previous owner 14 | * @param _newOwner new owner 15 | */ 16 | event OwnerUpdate(address indexed _prevOwner, address indexed _newOwner); 17 | 18 | /** 19 | * @dev initializes a new Owned instance 20 | */ 21 | constructor() public { 22 | owner = msg.sender; 23 | } 24 | 25 | // allows execution by the owner only 26 | modifier ownerOnly { 27 | _ownerOnly(); 28 | _; 29 | } 30 | 31 | // error message binary size optimization 32 | function _ownerOnly() internal view { 33 | require(msg.sender == owner, "ERR_ACCESS_DENIED"); 34 | } 35 | 36 | /** 37 | * @dev allows transferring the contract ownership 38 | * the new owner still needs to accept the transfer 39 | * can only be called by the contract owner 40 | * 41 | * @param _newOwner new contract owner 42 | */ 43 | function transferOwnership(address _newOwner) public ownerOnly { 44 | require(_newOwner != owner, "ERR_SAME_OWNER"); 45 | newOwner = _newOwner; 46 | } 47 | 48 | /** 49 | * @dev used by a new owner to accept an ownership transfer 50 | */ 51 | function acceptOwnership() public { 52 | require(msg.sender == newOwner, "ERR_ACCESS_DENIED"); 53 | emit OwnerUpdate(owner, newOwner); 54 | owner = newOwner; 55 | newOwner = address(0); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/openzeppelin/ReentrancyGuard.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | /** 4 | * @title Helps contracts guard against reentrancy attacks. 5 | * @author Remco Bloemen , Eenae 6 | * @dev If you mark a function `nonReentrant`, you should also 7 | * mark it `external`. 8 | */ 9 | contract ReentrancyGuard { 10 | /// @dev Constant for unlocked guard state - non-zero to prevent extra gas costs. 11 | /// See: https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1056 12 | uint256 internal constant REENTRANCY_GUARD_FREE = 1; 13 | 14 | /// @dev Constant for locked guard state 15 | uint256 internal constant REENTRANCY_GUARD_LOCKED = 2; 16 | 17 | /** 18 | * @dev We use a single lock for the whole contract. 19 | */ 20 | uint256 internal reentrancyLock = REENTRANCY_GUARD_FREE; 21 | 22 | /** 23 | * @dev Prevents a contract from calling itself, directly or indirectly. 24 | * If you mark a function `nonReentrant`, you should also 25 | * mark it `external`. Calling one `nonReentrant` function from 26 | * another is not supported. Instead, you can implement a 27 | * `private` function doing the actual work, and an `external` 28 | * wrapper marked as `nonReentrant`. 29 | */ 30 | modifier nonReentrant() { 31 | require(reentrancyLock == REENTRANCY_GUARD_FREE, "nonReentrant"); 32 | reentrancyLock = REENTRANCY_GUARD_LOCKED; 33 | _; 34 | reentrancyLock = REENTRANCY_GUARD_FREE; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/openzeppelin/SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0 <0.6.0; 2 | 3 | /** 4 | * @dev Library for basic math operations with overflow/underflow protection 5 | */ 6 | library SafeMath { 7 | /** 8 | * @dev returns the sum of _x and _y, reverts if the calculation overflows 9 | * 10 | * @param _x value 1 11 | * @param _y value 2 12 | * 13 | * @return sum 14 | */ 15 | function add(uint256 _x, uint256 _y) internal pure returns (uint256) { 16 | uint256 z = _x + _y; 17 | require(z >= _x, "ERR_OVERFLOW"); 18 | return z; 19 | } 20 | 21 | /** 22 | * @dev returns the difference of _x minus _y, reverts if the calculation underflows 23 | * 24 | * @param _x minuend 25 | * @param _y subtrahend 26 | * 27 | * @return difference 28 | */ 29 | function sub(uint256 _x, uint256 _y) internal pure returns (uint256) { 30 | require(_x >= _y, "ERR_UNDERFLOW"); 31 | return _x - _y; 32 | } 33 | 34 | /** 35 | * @dev returns the product of multiplying _x by _y, reverts if the calculation overflows 36 | * 37 | * @param _x factor 1 38 | * @param _y factor 2 39 | * 40 | * @return product 41 | */ 42 | function mul(uint256 _x, uint256 _y) internal pure returns (uint256) { 43 | // gas optimization 44 | if (_x == 0) return 0; 45 | 46 | uint256 z = _x * _y; 47 | require(z / _x == _y, "ERR_OVERFLOW"); 48 | return z; 49 | } 50 | 51 | /** 52 | * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. 53 | * 54 | * @param _x dividend 55 | * @param _y divisor 56 | * 57 | * @return quotient 58 | */ 59 | function div(uint256 _x, uint256 _y) internal pure returns (uint256) { 60 | require(_y > 0, "ERR_DIVIDE_BY_ZERO"); 61 | uint256 c = _x / _y; 62 | return c; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/contracts/openzeppelin/Utils.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.5.16; 2 | 3 | /** 4 | * @dev Utilities & Common Modifiers 5 | */ 6 | contract Utils { 7 | // verifies that a value is greater than zero 8 | modifier greaterThanZero(uint256 _value) { 9 | _greaterThanZero(_value); 10 | _; 11 | } 12 | 13 | // error message binary size optimization 14 | function _greaterThanZero(uint256 _value) internal pure { 15 | require(_value > 0, "ERR_ZERO_VALUE"); 16 | } 17 | 18 | // validates an address - currently only checks that it isn't null 19 | modifier validAddress(address _address) { 20 | _validAddress(_address); 21 | _; 22 | } 23 | 24 | // error message binary size optimization 25 | function _validAddress(address _address) internal pure { 26 | require(_address != address(0), "ERR_INVALID_ADDRESS"); 27 | } 28 | 29 | // verifies that the address is different than this contract address 30 | modifier notThis(address _address) { 31 | _notThis(_address); 32 | _; 33 | } 34 | 35 | // error message binary size optimization 36 | function _notThis(address _address) internal view { 37 | require(_address != address(this), "ERR_ADDRESS_IS_SELF"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require("Migrations"); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /rbtcwrapperproxy/migrations/2_deploy_RBTCWrapperProxy.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | 3 | const RBTCWrapperProxy = artifacts.require("RBTCWrapperProxy"); 4 | const LiquidityMining = artifacts.require("LiquidityMining"); 5 | const LoanToken = artifacts.require("LoanToken"); 6 | 7 | const getConfig = () => { 8 | return JSON.parse(fs.readFileSync("../solidity/utils/config_rsk.json", { encoding: "utf8" })); 9 | }; 10 | const getSOVConfig = () => { 11 | return JSON.parse(fs.readFileSync("../solidity/utils/addSOV.json", { encoding: "utf8" })); 12 | }; 13 | 14 | module.exports = function (deployer, network) { 15 | if(network == "development"){ 16 | console.log(getConfig()["SUSD"].addr) 17 | return deployer.deploy(LoanToken, getConfig()["SUSD"].addr).then(function() { 18 | return deployer.deploy(LiquidityMining, getSOVConfig()["SOV"].addr).then(function() { 19 | return deployer.deploy(RBTCWrapperProxy, getConfig()["RBTC"].addr, getConfig()["sovrynSwapNetwork"].addr, getConfig()["contractRegistry"].addr, LiquidityMining.address); 20 | }); 21 | }); 22 | } 23 | 24 | else{ 25 | liquidityMiningAddress = '0xe28aEbA913c34EC8F10DF0D9C92D2Aa27545870e'; 26 | wrbtcAddress = '0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab'; 27 | swapNetworkAddress = '0x61172B53423E205a399640e5283e51FE60EC2256'; 28 | contractRegistry = '0x0E7CcF6A67e614B507Aa524572F72C7e5Dec23CB'; 29 | return deployer.deploy(RBTCWrapperProxy, wrbtcAddress, swapNetworkAddress, contractRegistry, liquidityMiningAddress); 30 | 31 | } 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /scripts/export.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | 4 | const BUILD_DIR = path.resolve(__dirname, '../solidity/build'); 5 | const CONTRACTS_DIR = path.join(BUILD_DIR, 'contracts'); 6 | const JSON_EXT = '.json'; 7 | const ABI_EXT = '.abi'; 8 | const BIN_EXT = '.bin'; 9 | 10 | const fileList = fs.readdirSync(CONTRACTS_DIR); 11 | 12 | fileList.forEach((filename) => { 13 | if (filename.endsWith(JSON_EXT)) { 14 | const basename = path.basename(filename, JSON_EXT); 15 | const data = fs.readFileSync(path.join(CONTRACTS_DIR, filename)); 16 | const jsonData = JSON.parse(data); 17 | const { abi, bytecode } = jsonData; 18 | if (abi) { 19 | fs.writeFileSync(path.format({ 20 | dir: BUILD_DIR, name: basename, ext: ABI_EXT 21 | }), JSON.stringify(abi)); 22 | } 23 | 24 | if (bytecode) { 25 | fs.writeFileSync(path.format({ 26 | dir: BUILD_DIR, name: basename, ext: BIN_EXT 27 | }), bytecode.substring(2)); 28 | } 29 | } 30 | }); 31 | -------------------------------------------------------------------------------- /scripts/flatten.js: -------------------------------------------------------------------------------- 1 | const WORK_DIR = './solidity'; 2 | const NODE_DIR = '../node_modules'; 3 | const CONTRACT_NAME = process.argv[2]; 4 | 5 | const fs = require('fs'); 6 | const path = require('path'); 7 | const spawnSync = require('child_process').spawnSync; 8 | 9 | const run = () => { 10 | for (const pathName of getPathNames('contracts')) { 11 | const contractName = path.basename(pathName, '.sol'); 12 | if (CONTRACT_NAME === contractName) { 13 | console.log(getSourceCode(pathName)); 14 | } 15 | } 16 | }; 17 | 18 | const getPathNames = (dirName) => { 19 | let pathNames = []; 20 | for (const fileName of fs.readdirSync(WORK_DIR + '/' + dirName)) { 21 | if (fs.statSync(WORK_DIR + '/' + dirName + '/' + fileName).isDirectory()) { 22 | pathNames = pathNames.concat(getPathNames(dirName + '/' + fileName)); 23 | } 24 | else if (fileName.endsWith('.sol')) { 25 | pathNames.push(dirName + '/' + fileName); 26 | } 27 | } 28 | return pathNames; 29 | }; 30 | 31 | const getSourceCode = (pathName) => { 32 | const result = spawnSync('node', [NODE_DIR + '/truffle-flattener/index.js', pathName], { 33 | cwd: WORK_DIR 34 | }); 35 | return result.output.toString().slice(1, -1); 36 | }; 37 | 38 | run(); 39 | -------------------------------------------------------------------------------- /solidity/build/BProOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_mocStateAddress","type":"address"}],"name":"setMoCStateAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"latestAnswer","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"latestTimestamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"mocStateAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_mocStateAddress","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"mocStateAddress","type":"address"},{"indexed":false,"name":"changerAddress","type":"address"}],"name":"SetMoCStateAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/build/ChainlinkETHToETHOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"latestAnswer","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"latestTimestamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ChainlinkETHToETHOracle.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b5060b88061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166350d25bcd8114604d5780638205bf6a146071575b600080fd5b348015605857600080fd5b50605f6083565b60408051918252519081900360200190f35b348015607c57600080fd5b50605f6088565b600190565b42905600a165627a7a72305820c7b5171cbf173f3678a966d9067e45042e7d2140bac85f0a4fe41c1cf91d2adf0029 -------------------------------------------------------------------------------- /solidity/build/ContractRegistryClient.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_onlyOwnerCanUpdateRegistry","type":"bool"}],"name":"restrictRegistryUpdate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"onlyOwnerCanUpdateRegistry","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"updateRegistry","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"prevRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"restoreRegistry","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_registry","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/build/ContractRegistryClient.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ContractRegistryClient.bin -------------------------------------------------------------------------------- /solidity/build/ConverterBase.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ConverterBase.bin -------------------------------------------------------------------------------- /solidity/build/IConsumerPriceOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"latestAnswer","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"latestTimestamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IConsumerPriceOracle.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConsumerPriceOracle.bin -------------------------------------------------------------------------------- /solidity/build/IContractRegistry.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"_contractName","type":"bytes32"}],"name":"getAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_contractName","type":"bytes32"}],"name":"addressOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IContractRegistry.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IContractRegistry.bin -------------------------------------------------------------------------------- /solidity/build/IConversionPathFinder.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"_sourceToken","type":"address"},{"name":"_targetToken","type":"address"}],"name":"findPath","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IConversionPathFinder.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConversionPathFinder.bin -------------------------------------------------------------------------------- /solidity/build/IConverter.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConverter.bin -------------------------------------------------------------------------------- /solidity/build/IConverterAnchor.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IConverterAnchor.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConverterAnchor.bin -------------------------------------------------------------------------------- /solidity/build/IConverterFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_type","type":"uint16"},{"name":"_anchor","type":"address"},{"name":"_registry","type":"address"},{"name":"_maxConversionFee","type":"uint32"}],"name":"createConverter","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_type","type":"uint16"},{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint8"}],"name":"createAnchor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_type","type":"uint16"}],"name":"customFactories","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IConverterFactory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConverterFactory.bin -------------------------------------------------------------------------------- /solidity/build/IConverterRegistry.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConverterRegistry.bin -------------------------------------------------------------------------------- /solidity/build/IConverterRegistryData.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConverterRegistryData.bin -------------------------------------------------------------------------------- /solidity/build/IConverterUpgrader.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_version","type":"uint16"}],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_version","type":"bytes32"}],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IConverterUpgrader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IConverterUpgrader.bin -------------------------------------------------------------------------------- /solidity/build/IERC20Token.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IERC20Token.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IERC20Token.bin -------------------------------------------------------------------------------- /solidity/build/IEtherToken.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IEtherToken.bin -------------------------------------------------------------------------------- /solidity/build/ILegacyConverter.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_sourceToken","type":"address"},{"name":"_targetToken","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_minReturn","type":"uint256"}],"name":"change","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ILegacyConverter.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ILegacyConverter.bin -------------------------------------------------------------------------------- /solidity/build/ILiquidityPoolV2Converter.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"_reserveToken","type":"address"}],"name":"reserveStakedBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"primaryReserveToken","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_primaryReserveToken","type":"address"},{"name":"_primaryReserveOracle","type":"address"},{"name":"_secondaryReserveOracle","type":"address"}],"name":"activate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"priceOracle","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_reserveToken","type":"address"},{"name":"_balance","type":"uint256"}],"name":"setReserveStakedBalance","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ILiquidityPoolV2Converter.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ILiquidityPoolV2Converter.bin -------------------------------------------------------------------------------- /solidity/build/IMoCState.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"bproUsdPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IMoCState.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IMoCState.bin -------------------------------------------------------------------------------- /solidity/build/IOwned.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IOwned.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IOwned.bin -------------------------------------------------------------------------------- /solidity/build/IPoolTokensContainer.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"poolTokens","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"createToken","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_from","type":"address"},{"name":"_amount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IPoolTokensContainer.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IPoolTokensContainer.bin -------------------------------------------------------------------------------- /solidity/build/IPriceOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"_tokenA","type":"address"},{"name":"_tokenB","type":"address"}],"name":"latestRate","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenA","type":"address"},{"name":"_tokenB","type":"address"}],"name":"latestRateAndUpdateTime","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenAOracle","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastUpdateTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenBOracle","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IPriceOracle.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IPriceOracle.bin -------------------------------------------------------------------------------- /solidity/build/ISmartToken.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ISmartToken.bin -------------------------------------------------------------------------------- /solidity/build/ISovrynSwapFormula.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ISovrynSwapFormula.bin -------------------------------------------------------------------------------- /solidity/build/ISovrynSwapNetwork.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ISovrynSwapNetwork.bin -------------------------------------------------------------------------------- /solidity/build/ISovrynSwapX.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_toBlockchain","type":"bytes32"},{"name":"_to","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_id","type":"uint256"}],"name":"xTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_xTransferId","type":"uint256"},{"name":"_for","type":"address"}],"name":"getXTransferAmount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"token","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ISovrynSwapX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ISovrynSwapX.bin -------------------------------------------------------------------------------- /solidity/build/ISovrynSwapXUpgrader.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_version","type":"uint16"},{"name":"_reporters","type":"address[]"}],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ISovrynSwapXUpgrader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ISovrynSwapXUpgrader.bin -------------------------------------------------------------------------------- /solidity/build/ITokenHolder.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ITokenHolder.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ITokenHolder.bin -------------------------------------------------------------------------------- /solidity/build/ITypedConverterAnchorFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint8"}],"name":"createAnchor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ITypedConverterAnchorFactory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ITypedConverterAnchorFactory.bin -------------------------------------------------------------------------------- /solidity/build/ITypedConverterCustomFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ITypedConverterCustomFactory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ITypedConverterCustomFactory.bin -------------------------------------------------------------------------------- /solidity/build/ITypedConverterFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_anchor","type":"address"},{"name":"_registry","type":"address"},{"name":"_maxConversionFee","type":"uint32"}],"name":"createConverter","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/ITypedConverterFactory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ITypedConverterFactory.bin -------------------------------------------------------------------------------- /solidity/build/IWhitelist.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"isWhitelisted","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/IWhitelist.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/IWhitelist.bin -------------------------------------------------------------------------------- /solidity/build/LiquidTokenConverterFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_anchor","type":"address"},{"name":"_registry","type":"address"},{"name":"_maxConversionFee","type":"uint32"}],"name":"createConverter","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/LiquidityPoolConverter.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/LiquidityPoolConverter.bin -------------------------------------------------------------------------------- /solidity/build/LiquidityPoolV1ConverterFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_anchor","type":"address"},{"name":"_registry","type":"address"},{"name":"_maxConversionFee","type":"uint32"}],"name":"createConverter","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/LiquidityPoolV2ConverterAnchorFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint8"}],"name":"createAnchor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/LiquidityPoolV2ConverterCustomFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_primaryReserveToken","type":"address"},{"name":"_secondaryReserveToken","type":"address"},{"name":"_primaryReserveOracle","type":"address"},{"name":"_secondaryReserveOracle","type":"address"}],"name":"createPriceOracle","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/LiquidityPoolV2ConverterFactory.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_anchor","type":"address"},{"name":"_registry","type":"address"},{"name":"_maxConversionFee","type":"uint32"}],"name":"createConverter","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"converterType","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/Medianizer.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"peek","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/Medianizer.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/Medianizer.bin -------------------------------------------------------------------------------- /solidity/build/MoCMedianizerMock.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"setValue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"peek","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_has","type":"bool"}],"name":"setHas","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"has","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/MoCMedianizerMock.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b50610183806100206000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f2458114610071578063552410771461009857806359e02dd7146100b257806361da0693146100e0578063b689d5ac146100fa575b600080fd5b34801561007d57600080fd5b50610086610123565b60408051918252519081900360200190f35b3480156100a457600080fd5b506100b0600435610129565b005b3480156100be57600080fd5b506100c761012e565b6040805192835290151560208301528051918290030190f35b3480156100ec57600080fd5b506100b0600435151561013b565b34801561010657600080fd5b5061010f61014e565b604080519115158252519081900360200190f35b60005481565b600055565b60005460015460ff169091565b6001805460ff1916911515919091179055565b60015460ff16815600a165627a7a723058207a3d8eeed219391adfd90dc96cf258457189758b7e1cd571ee3e38c5b740f84e0029 -------------------------------------------------------------------------------- /solidity/build/MoCOracleMock.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"setValue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"peek","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_has","type":"bool"}],"name":"setHas","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"has","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/MoCOracleMock.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b50610183806100206000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f2458114610071578063552410771461009857806359e02dd7146100b257806361da0693146100e0578063b689d5ac146100fa575b600080fd5b34801561007d57600080fd5b50610086610123565b60408051918252519081900360200190f35b3480156100a457600080fd5b506100b0600435610129565b005b3480156100be57600080fd5b506100c761012e565b6040805192835290151560208301528051918290030190f35b3480156100ec57600080fd5b506100b0600435151561013b565b34801561010657600080fd5b5061010f61014e565b604080519115158252519081900360200190f35b60005481565b600055565b60005460015460ff169091565b6001805460ff1916911515919091179055565b60015460ff16815600a165627a7a723058201fd2397fae142a9adf13c199df0469efb27b869419f259ec53441812017473d70029 -------------------------------------------------------------------------------- /solidity/build/MoCStateMock.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"setValue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"bproUsdPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/MoCStateMock.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b5060e18061001f6000396000f30060806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f245811460575780635524107714607b578063747a5663146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820df1a80460a5af553166dddbe52c68c72e45920769dc6596db0f54461e06af95f0029 -------------------------------------------------------------------------------- /solidity/build/MocBTCToBTCOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"latestAnswer","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"latestTimestamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /solidity/build/MocBTCToBTCOracle.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b5060b88061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166350d25bcd8114604d5780638205bf6a146071575b600080fd5b348015605857600080fd5b50605f6083565b60408051918252519081900360200190f35b348015607c57600080fd5b50605f6088565b600190565b42905600a165627a7a72305820a7b5c901fb478d4cb504eb15ecc2ff6d2937604ee43dacd9779f8089c2083c9e0029 -------------------------------------------------------------------------------- /solidity/build/MocBTCToUSDOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_mocOracleAddress","type":"address"}],"name":"setMoCOracleAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"latestAnswer","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"latestTimestamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"mocOracleAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_mocOracleAddress","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"mocOracleAddress","type":"address"},{"indexed":false,"name":"changerAddress","type":"address"}],"name":"SetMoCOracleAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/build/MocUSDToBTCOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"DECIMALS","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_mocOracleAddress","type":"address"}],"name":"setMoCOracleAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"latestAnswer","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"latestTimestamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"mocOracleAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_mocOracleAddress","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"mocOracleAddress","type":"address"},{"indexed":false,"name":"changerAddress","type":"address"}],"name":"SetMoCOracleAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/build/Owned.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/build/Owned.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b5060008054600160a060020a03191633179055610347806100326000396000f3006080604052600436106100615763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166379ba509781146100665780638da5cb5b1461007d578063d4ee1d90146100ae578063f2fde38b146100c3575b600080fd5b34801561007257600080fd5b5061007b6100e4565b005b34801561008957600080fd5b506100926101ce565b60408051600160a060020a039092168252519081900360200190f35b3480156100ba57600080fd5b506100926101dd565b3480156100cf57600080fd5b5061007b600160a060020a03600435166101ec565b600154600160a060020a0316331461015d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4552525f4143434553535f44454e494544000000000000000000000000000000604482015290519081900360640190fd5b60015460008054604051600160a060020a0393841693909116917f343765429aea5a34b3ff6a3785a98a5abb2597aca87bfbb58632c173d585373a91a3600180546000805473ffffffffffffffffffffffffffffffffffffffff19908116600160a060020a03841617909155169055565b600054600160a060020a031681565b600154600160a060020a031681565b6101f46102a0565b600054600160a060020a038281169116141561027157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f4552525f53414d455f4f574e4552000000000000000000000000000000000000604482015290519081900360640190fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600054600160a060020a0316331461031957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4552525f4143434553535f44454e494544000000000000000000000000000000604482015290519081900360640190fd5b5600a165627a7a72305820e3bd1149ed2a006a4539caeb68e5a1920479c0d8936c193cb3179761d9bb7d0c0029 -------------------------------------------------------------------------------- /solidity/build/PriceOracle.abi: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"tokenA","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenB","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"tokenDecimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenA","type":"address"},{"name":"_tokenB","type":"address"}],"name":"latestRate","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenA","type":"address"},{"name":"_tokenB","type":"address"}],"name":"latestRateAndUpdateTime","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenAOracle","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastUpdateTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"tokensToOracles","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenBOracle","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_tokenA","type":"address"},{"name":"_tokenB","type":"address"},{"name":"_tokenAOracle","type":"address"},{"name":"_tokenBOracle","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] -------------------------------------------------------------------------------- /solidity/build/ReentrancyGuard.abi: -------------------------------------------------------------------------------- 1 | [{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] -------------------------------------------------------------------------------- /solidity/build/ReentrancyGuard.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DistributedCollective/oracle-based-amm/c0cda95ad24e966c75782f94d5551c19620d6ab5/solidity/build/ReentrancyGuard.bin -------------------------------------------------------------------------------- /solidity/build/SafeMath.abi: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /solidity/build/SafeMath.bin: -------------------------------------------------------------------------------- 1 | 604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146080604052600080fd00a165627a7a72305820d54c512e211758a0a48db59eafa952083401bb0530c0d09aa380ebd065150ebc0029 -------------------------------------------------------------------------------- /solidity/build/TokenHandler.abi: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /solidity/build/TokenHandler.bin: -------------------------------------------------------------------------------- 1 | 6080604052348015600f57600080fd5b50603580601d6000396000f3006080604052600080fd00a165627a7a7230582066e2b0700eae98f9a08571a6ca23e786e9a2cc6edae272588dd0036408e4e74b0029 -------------------------------------------------------------------------------- /solidity/build/TokenHolder.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/build/Utils.abi: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /solidity/build/Utils.bin: -------------------------------------------------------------------------------- 1 | 6080604052348015600f57600080fd5b50603580601d6000396000f3006080604052600080fd00a165627a7a72305820ac8352e92267f511c72b606e871feba6fec54c6e940050f1e0db57a6d20556da0029 -------------------------------------------------------------------------------- /solidity/build/Whitelist.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_addresses","type":"address[]"}],"name":"addAddresses","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"addAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"isWhitelisted","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"removeAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_addresses","type":"address[]"}],"name":"removeAddresses","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_address","type":"address"}],"name":"AddressAddition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_address","type":"address"}],"name":"AddressRemoval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/build/XTransferRerouter.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_enable","type":"bool"}],"name":"enableRerouting","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"uint256"},{"name":"_blockchain","type":"bytes32"},{"name":"_to","type":"bytes32"}],"name":"rerouteTx","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"reroutingEnabled","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_reroutingEnabled","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_txId","type":"uint256"},{"indexed":false,"name":"_toBlockchain","type":"bytes32"},{"indexed":false,"name":"_to","type":"bytes32"}],"name":"TxReroute","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_prevOwner","type":"address"},{"indexed":true,"name":"_newOwner","type":"address"}],"name":"OwnerUpdate","type":"event"}] -------------------------------------------------------------------------------- /solidity/contracts/IConversionPathFinder.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./token/interfaces/IERC20Token.sol"; 3 | 4 | /* 5 | Conversion Path Finder interface 6 | */ 7 | contract IConversionPathFinder { 8 | function findPath(address _sourceToken, address _targetToken) public view returns (address[] memory); 9 | } 10 | -------------------------------------------------------------------------------- /solidity/contracts/ISovrynSwapNetwork.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./token/interfaces/IERC20Token.sol"; 3 | 4 | /* 5 | SovrynSwap Network interface 6 | */ 7 | contract ISovrynSwapNetwork { 8 | function convert2( 9 | IERC20Token[] _path, 10 | uint256 _amount, 11 | uint256 _minReturn, 12 | address _affiliateAccount, 13 | uint256 _affiliateFee 14 | ) public payable returns (uint256); 15 | 16 | function claimAndConvert2( 17 | IERC20Token[] _path, 18 | uint256 _amount, 19 | uint256 _minReturn, 20 | address _affiliateAccount, 21 | uint256 _affiliateFee 22 | ) public returns (uint256); 23 | 24 | function convertFor2( 25 | IERC20Token[] _path, 26 | uint256 _amount, 27 | uint256 _minReturn, 28 | address _for, 29 | address _affiliateAccount, 30 | uint256 _affiliateFee 31 | ) public payable returns (uint256); 32 | 33 | function claimAndConvertFor2( 34 | IERC20Token[] _path, 35 | uint256 _amount, 36 | uint256 _minReturn, 37 | address _for, 38 | address _affiliateAccount, 39 | uint256 _affiliateFee 40 | ) public returns (uint256); 41 | 42 | // deprecated, backward compatibility 43 | function convert( 44 | IERC20Token[] _path, 45 | uint256 _amount, 46 | uint256 _minReturn 47 | ) public payable returns (uint256); 48 | 49 | // deprecated, backward compatibility 50 | function claimAndConvert( 51 | IERC20Token[] _path, 52 | uint256 _amount, 53 | uint256 _minReturn 54 | ) public returns (uint256); 55 | 56 | // deprecated, backward compatibility 57 | function convertFor( 58 | IERC20Token[] _path, 59 | uint256 _amount, 60 | uint256 _minReturn, 61 | address _for 62 | ) public payable returns (uint256); 63 | 64 | // deprecated, backward compatibility 65 | function claimAndConvertFor( 66 | IERC20Token[] _path, 67 | uint256 _amount, 68 | uint256 _minReturn, 69 | address _for 70 | ) public returns (uint256); 71 | } -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/IConverterAnchor.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../../utility/interfaces/IOwned.sol"; 3 | import "../../utility/interfaces/ITokenHolder.sol"; 4 | 5 | /* 6 | Converter Anchor interface 7 | */ 8 | contract IConverterAnchor is IOwned, ITokenHolder { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/IConverterFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./IConverter.sol"; 3 | import "./IConverterAnchor.sol"; 4 | import "./ITypedConverterCustomFactory.sol"; 5 | import "../../utility/interfaces/IContractRegistry.sol"; 6 | 7 | /* 8 | Converter Factory interface 9 | */ 10 | contract IConverterFactory { 11 | function createAnchor( 12 | uint16 _type, 13 | string _name, 14 | string _symbol, 15 | uint8 _decimals 16 | ) public returns (IConverterAnchor); 17 | 18 | function createConverter( 19 | uint16 _type, 20 | IConverterAnchor _anchor, 21 | IContractRegistry _registry, 22 | uint32 _maxConversionFee 23 | ) public returns (IConverter); 24 | 25 | function customFactories(uint16 _type) public view returns (ITypedConverterCustomFactory) { 26 | _type; 27 | this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/IConverterRegistry.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | contract IConverterRegistry { 4 | function getAnchorCount() public view returns (uint256); 5 | 6 | function getAnchors() public view returns (address[]); 7 | 8 | function getAnchor(uint256 _index) public view returns (address); 9 | 10 | function isAnchor(address _value) public view returns (bool); 11 | 12 | function getLiquidityPoolCount() public view returns (uint256); 13 | 14 | function getLiquidityPools() public view returns (address[]); 15 | 16 | function getLiquidityPool(uint256 _index) public view returns (address); 17 | 18 | function isLiquidityPool(address _value) public view returns (bool); 19 | 20 | function getConvertibleTokenCount() public view returns (uint256); 21 | 22 | function getConvertibleTokens() public view returns (address[]); 23 | 24 | function getConvertibleToken(uint256 _index) public view returns (address); 25 | 26 | function isConvertibleToken(address _value) public view returns (bool); 27 | 28 | function getConvertibleTokenAnchorCount(address _convertibleToken) public view returns (uint256); 29 | 30 | function getConvertibleTokenAnchors(address _convertibleToken) public view returns (address[]); 31 | 32 | function getConvertibleTokenAnchor(address _convertibleToken, uint256 _index) public view returns (address); 33 | 34 | function isConvertibleTokenAnchor(address _convertibleToken, address _value) public view returns (bool); 35 | } 36 | -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/IConverterUpgrader.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | Converter Upgrader interface 5 | */ 6 | contract IConverterUpgrader { 7 | function upgrade(bytes32 _version) public; 8 | 9 | function upgrade(uint16 _version) public; 10 | } 11 | -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/ISovrynSwapFormula.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | SovrynSwap Formula interface 5 | */ 6 | contract ISovrynSwapFormula { 7 | function purchaseTargetAmount( 8 | uint256 _supply, 9 | uint256 _reserveBalance, 10 | uint32 _reserveWeight, 11 | uint256 _amount 12 | ) public view returns (uint256); 13 | 14 | function saleTargetAmount( 15 | uint256 _supply, 16 | uint256 _reserveBalance, 17 | uint32 _reserveWeight, 18 | uint256 _amount 19 | ) public view returns (uint256); 20 | 21 | function crossReserveTargetAmount( 22 | uint256 _sourceReserveBalance, 23 | uint32 _sourceReserveWeight, 24 | uint256 _targetReserveBalance, 25 | uint32 _targetReserveWeight, 26 | uint256 _amount 27 | ) public view returns (uint256); 28 | 29 | function fundCost( 30 | uint256 _supply, 31 | uint256 _reserveBalance, 32 | uint32 _reserveRatio, 33 | uint256 _amount 34 | ) public view returns (uint256); 35 | 36 | function fundSupplyAmount( 37 | uint256 _supply, 38 | uint256 _reserveBalance, 39 | uint32 _reserveRatio, 40 | uint256 _amount 41 | ) public view returns (uint256); 42 | 43 | function liquidateReserveAmount( 44 | uint256 _supply, 45 | uint256 _reserveBalance, 46 | uint32 _reserveRatio, 47 | uint256 _amount 48 | ) public view returns (uint256); 49 | 50 | function balancedWeights( 51 | uint256 _primaryReserveStakedBalance, 52 | uint256 _primaryReserveBalance, 53 | uint256 _secondaryReserveBalance, 54 | uint256 _reserveRateNumerator, 55 | uint256 _reserveRateDenominator 56 | ) public view returns (uint32, uint32); 57 | } 58 | -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/ITypedConverterAnchorFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./IConverterAnchor.sol"; 3 | 4 | /* 5 | Typed Converter Anchor Factory interface 6 | */ 7 | contract ITypedConverterAnchorFactory { 8 | function converterType() public pure returns (uint16); 9 | 10 | function createAnchor( 11 | string _name, 12 | string _symbol, 13 | uint8 _decimals 14 | ) public returns (IConverterAnchor); 15 | } 16 | -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/ITypedConverterCustomFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | Typed Converter Custom Factory interface 5 | */ 6 | contract ITypedConverterCustomFactory { 7 | function converterType() public pure returns (uint16); 8 | } 9 | -------------------------------------------------------------------------------- /solidity/contracts/converter/interfaces/ITypedConverterFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./IConverter.sol"; 3 | import "./IConverterAnchor.sol"; 4 | import "../../utility/interfaces/IContractRegistry.sol"; 5 | 6 | /* 7 | Typed Converter Factory interface 8 | */ 9 | contract ITypedConverterFactory { 10 | function converterType() public pure returns (uint16); 11 | 12 | function createConverter( 13 | IConverterAnchor _anchor, 14 | IContractRegistry _registry, 15 | uint32 _maxConversionFee 16 | ) public returns (IConverter); 17 | } 18 | -------------------------------------------------------------------------------- /solidity/contracts/converter/types/liquid-token/LiquidTokenConverterFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./LiquidTokenConverter.sol"; 3 | import "../../interfaces/IConverter.sol"; 4 | import "../../interfaces/ITypedConverterFactory.sol"; 5 | import "../../../token/interfaces/ISmartToken.sol"; 6 | 7 | /* 8 | LiquidTokenConverter Factory 9 | */ 10 | contract LiquidTokenConverterFactory is ITypedConverterFactory { 11 | /** 12 | * @dev returns the converter type the factory is associated with 13 | * 14 | * @return converter type 15 | */ 16 | function converterType() public pure returns (uint16) { 17 | return 0; 18 | } 19 | 20 | /** 21 | * @dev creates a new converter with the given arguments and transfers 22 | * the ownership to the caller 23 | * 24 | * @param _anchor anchor governed by the converter 25 | * @param _registry address of a contract registry contract 26 | * @param _maxConversionFee maximum conversion fee, represented in ppm 27 | * 28 | * @return a new converter 29 | */ 30 | function createConverter(IConverterAnchor _anchor, IContractRegistry _registry, uint32 _maxConversionFee) public returns (IConverter) { 31 | IConverter converter = new LiquidTokenConverter(ISmartToken(_anchor), _registry, _maxConversionFee); 32 | converter.transferOwnership(msg.sender); 33 | return converter; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /solidity/contracts/converter/types/liquidity-pool-v1/LiquidityPoolV1ConverterFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./LiquidityPoolV1Converter.sol"; 3 | import "../../interfaces/IConverter.sol"; 4 | import "../../interfaces/ITypedConverterFactory.sol"; 5 | import "../../../token/interfaces/ISmartToken.sol"; 6 | 7 | /* 8 | LiquidityPoolV1Converter Factory 9 | */ 10 | contract LiquidityPoolV1ConverterFactory is ITypedConverterFactory { 11 | /** 12 | * @dev returns the converter type the factory is associated with 13 | * 14 | * @return converter type 15 | */ 16 | function converterType() public pure returns (uint16) { 17 | return 1; 18 | } 19 | 20 | /** 21 | * @dev creates a new converter with the given arguments and transfers 22 | * the ownership to the caller 23 | * 24 | * @param _anchor anchor governed by the converter 25 | * @param _registry address of a contract registry contract 26 | * @param _maxConversionFee maximum conversion fee, represented in ppm 27 | * 28 | * @return a new converter 29 | */ 30 | function createConverter(IConverterAnchor _anchor, IContractRegistry _registry, uint32 _maxConversionFee) public returns (IConverter) { 31 | IConverter converter = new LiquidityPoolV1Converter(ISmartToken(_anchor), _registry, _maxConversionFee); 32 | converter.transferOwnership(msg.sender); 33 | return converter; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /solidity/contracts/converter/types/liquidity-pool-v2/LiquidityPoolV2ConverterAnchorFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./PoolTokensContainer.sol"; 3 | import "../../interfaces/ITypedConverterAnchorFactory.sol"; 4 | 5 | /* 6 | LiquidityPoolV2ConverterAnchorFactory Factory 7 | */ 8 | contract LiquidityPoolV2ConverterAnchorFactory is ITypedConverterAnchorFactory { 9 | /** 10 | * @dev returns the converter type the factory is associated with 11 | * 12 | * @return converter type 13 | */ 14 | function converterType() public pure returns (uint16) { 15 | return 2; 16 | } 17 | 18 | /** 19 | * @dev creates a new converter anchor with the given arguments and transfers 20 | * the ownership to the caller 21 | * 22 | * @param _name pool name 23 | * @param _symbol pool symbol 24 | * @param _decimals pool decimals 25 | * 26 | * @return new anchor 27 | */ 28 | function createAnchor(string _name, string _symbol, uint8 _decimals) public returns (IConverterAnchor) { 29 | IPoolTokensContainer container = new PoolTokensContainer(_name, _symbol, _decimals); 30 | container.transferOwnership(msg.sender); 31 | return container; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /solidity/contracts/converter/types/liquidity-pool-v2/LiquidityPoolV2ConverterCustomFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../../interfaces/ITypedConverterCustomFactory.sol"; 3 | import "../../../utility/PriceOracle.sol"; 4 | 5 | /* 6 | LiquidityPoolV2ConverterCustomFactory Factory 7 | */ 8 | contract LiquidityPoolV2ConverterCustomFactory is ITypedConverterCustomFactory { 9 | /** 10 | * @dev returns the converter type the factory is associated with 11 | * 12 | * @return converter type 13 | */ 14 | function converterType() public pure returns (uint16) { 15 | return 2; 16 | } 17 | 18 | /** 19 | * @dev creates a new price oracle 20 | * note that the oracles must have the same common denominator (USD, ETH etc.) 21 | * 22 | * @param _primaryReserveToken primary reserve token address 23 | * @param _secondaryReserveToken secondary reserve token address 24 | * @param _primaryReserveOracle primary reserve oracle address 25 | * @param _secondaryReserveOracle secondary reserve oracle address 26 | */ 27 | function createPriceOracle( 28 | IERC20Token _primaryReserveToken, 29 | IERC20Token _secondaryReserveToken, 30 | IConsumerPriceOracle _primaryReserveOracle, 31 | IConsumerPriceOracle _secondaryReserveOracle) 32 | public 33 | returns (IPriceOracle) 34 | { 35 | return new PriceOracle(_primaryReserveToken, _secondaryReserveToken, _primaryReserveOracle, _secondaryReserveOracle); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /solidity/contracts/converter/types/liquidity-pool-v2/LiquidityPoolV2ConverterFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./LiquidityPoolV2Converter.sol"; 3 | import "./interfaces/IPoolTokensContainer.sol"; 4 | import "../../interfaces/ITypedConverterFactory.sol"; 5 | 6 | /* 7 | LiquidityPoolV2Converter Factory 8 | */ 9 | contract LiquidityPoolV2ConverterFactory is ITypedConverterFactory { 10 | /** 11 | * @dev returns the converter type the factory is associated with 12 | * 13 | * @return converter type 14 | */ 15 | function converterType() public pure returns (uint16) { 16 | return 2; 17 | } 18 | 19 | /** 20 | * @dev creates a new converter with the given arguments and transfers 21 | * the ownership to the caller 22 | * 23 | * @param _anchor anchor governed by the converter 24 | * @param _registry address of a contract registry contract 25 | * @param _maxConversionFee maximum conversion fee, represented in ppm 26 | * 27 | * @return new converter 28 | */ 29 | function createConverter(IConverterAnchor _anchor, IContractRegistry _registry, uint32 _maxConversionFee) public returns (IConverter) { 30 | ConverterBase converter = new LiquidityPoolV2Converter(IPoolTokensContainer(_anchor), _registry, _maxConversionFee); 31 | converter.transferOwnership(msg.sender); 32 | return converter; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /solidity/contracts/converter/types/liquidity-pool-v2/interfaces/ILiquidityPoolV2Converter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../../../../token/interfaces/IERC20Token.sol"; 3 | import "../../../../utility/interfaces/IPriceOracle.sol"; 4 | 5 | /* 6 | Liquidity Pool V2 Converter interface 7 | */ 8 | contract ILiquidityPoolV2Converter { 9 | function reserveStakedBalance(IERC20Token _reserveToken) public view returns (uint256); 10 | function setReserveStakedBalance(IERC20Token _reserveToken, uint256 _balance) public; 11 | 12 | function primaryReserveToken() public view returns (IERC20Token); 13 | 14 | function priceOracle() public view returns (IPriceOracle); 15 | 16 | function activate(IERC20Token _primaryReserveToken, IConsumerPriceOracle _primaryReserveOracle, IConsumerPriceOracle _secondaryReserveOracle) public; 17 | } 18 | -------------------------------------------------------------------------------- /solidity/contracts/converter/types/liquidity-pool-v2/interfaces/IPoolTokensContainer.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../../../interfaces/IConverterAnchor.sol"; 3 | import "../../../../token/interfaces/ISmartToken.sol"; 4 | 5 | /* 6 | Pool Tokens Container interface 7 | */ 8 | contract IPoolTokensContainer is IConverterAnchor { 9 | function poolTokens() public view returns (ISmartToken[]); 10 | function createToken() public returns (ISmartToken); 11 | function mint(ISmartToken _token, address _to, uint256 _amount) public; 12 | function burn(ISmartToken _token, address _from, uint256 _amount) public; 13 | } 14 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestChainlinkPriceOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../utility/interfaces/IConsumerPriceOracle.sol"; 3 | 4 | /* 5 | Chainlink price oracle mock 6 | */ 7 | contract TestChainlinkPriceOracle is IConsumerPriceOracle { 8 | int256 private answer; 9 | uint256 private timestamp; 10 | 11 | function setAnswer(int256 _answer) public { 12 | answer = _answer; 13 | } 14 | 15 | function setTimestamp(uint256 _timestamp) public { 16 | timestamp = _timestamp; 17 | } 18 | 19 | function latestAnswer() external view returns (int256) { 20 | return answer; 21 | } 22 | 23 | function latestTimestamp() external view returns (uint256) { 24 | return timestamp; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestContractRegistryClient.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../utility/ContractRegistryClient.sol"; 3 | 4 | /* 5 | Utils test helper that exposes the contract registry client functions 6 | */ 7 | contract TestContractRegistryClient is ContractRegistryClient { 8 | constructor(IContractRegistry _registry) public ContractRegistryClient(_registry) {} 9 | } 10 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestConverterFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../converter/ConverterFactory.sol"; 3 | 4 | /* 5 | Utils test helper that exposes the converter factory functions 6 | */ 7 | contract TestConverterFactory is ConverterFactory { 8 | IConverter public createdConverter; 9 | IConverterAnchor public createdAnchor; 10 | 11 | function createAnchor( 12 | uint16 _converterType, 13 | string _name, 14 | string _symbol, 15 | uint8 _decimals 16 | ) public returns (IConverterAnchor) { 17 | createdAnchor = super.createAnchor(_converterType, _name, _symbol, _decimals); 18 | 19 | return createdAnchor; 20 | } 21 | 22 | function createConverter( 23 | uint16 _type, 24 | IConverterAnchor _anchor, 25 | IContractRegistry _registry, 26 | uint32 _maxConversionFee 27 | ) public returns (IConverter) { 28 | createdConverter = super.createConverter(_type, _anchor, _registry, _maxConversionFee); 29 | 30 | return createdConverter; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestConverterRegistry.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../converter/ConverterRegistry.sol"; 3 | 4 | /* 5 | Utils test helper that exposes the converter registry functions 6 | */ 7 | contract TestConverterRegistry is ConverterRegistry { 8 | IConverter public createdConverter; 9 | 10 | constructor(IContractRegistry _registry) public ConverterRegistry(_registry) {} 11 | 12 | function newConverter( 13 | uint16 _type, 14 | string _name, 15 | string _symbol, 16 | uint8 _decimals, 17 | uint32 _maxConversionFee, 18 | IERC20Token[] memory _reserveTokens, 19 | uint32[] memory _reserveWeights 20 | ) public returns (IConverter) { 21 | createdConverter = super.newConverter(_type, _name, _symbol, _decimals, _maxConversionFee, _reserveTokens, _reserveWeights); 22 | 23 | return createdConverter; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestLiquidityPoolConverter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../converter/types/liquidity-pool-v1/LiquidityPoolV1Converter.sol"; 3 | 4 | contract TestLiquidityPoolConverter is LiquidityPoolV1Converter { 5 | constructor( 6 | ISmartToken _token, 7 | IContractRegistry _registry, 8 | uint32 _maxConversionFee 9 | ) public LiquidityPoolV1Converter(_token, _registry, _maxConversionFee) {} 10 | 11 | function setEtherToken(IEtherToken _etherToken) public { 12 | etherToken = _etherToken; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestLiquidityPoolV2Converter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../converter/types/liquidity-pool-v2/LiquidityPoolV2Converter.sol"; 3 | 4 | contract TestLiquidityPoolV2Converter is LiquidityPoolV2Converter { 5 | uint256 public currentTime; 6 | 7 | constructor( 8 | IPoolTokensContainer _token, 9 | IContractRegistry _registry, 10 | uint32 _maxConversionFee 11 | ) public LiquidityPoolV2Converter(_token, _registry, _maxConversionFee) {} 12 | 13 | function setReferenceRateUpdateTime(uint256 _referenceRateUpdateTime) public { 14 | referenceRateUpdateTime = _referenceRateUpdateTime; 15 | } 16 | 17 | function time() internal view returns (uint256) { 18 | return currentTime != 0 ? currentTime : now; 19 | } 20 | 21 | function setTime(uint256 _currentTime) public { 22 | currentTime = _currentTime; 23 | } 24 | 25 | function calculateFeeToEquilibriumTest( 26 | uint256 _primaryReserveStaked, 27 | uint256 _secondaryReserveStaked, 28 | uint256 _primaryReserveWeight, 29 | uint256 _secondaryReserveWeight, 30 | uint256 _primaryReserveRate, 31 | uint256 _secondaryReserveRate, 32 | uint256 _dynamicFeeFactor 33 | ) external pure returns (uint256) { 34 | return 35 | calculateFeeToEquilibrium( 36 | _primaryReserveStaked, 37 | _secondaryReserveStaked, 38 | _primaryReserveWeight, 39 | _secondaryReserveWeight, 40 | _primaryReserveRate, 41 | _secondaryReserveRate, 42 | _dynamicFeeFactor 43 | ); 44 | } 45 | 46 | function setReserveWeight(IERC20Token _reserveToken, uint32 _weight) public validReserve(_reserveToken) { 47 | reserves[_reserveToken].weight = _weight; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestReentrancyGuard.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../utility/ReentrancyGuard.sol"; 3 | 4 | contract TestReentrancyGuardAttacker { 5 | TestReentrancyGuard public target; 6 | bool public reentrancy; 7 | bool public callProtectedMethod; 8 | bool public attacking; 9 | 10 | constructor(TestReentrancyGuard _target) public { 11 | target = _target; 12 | } 13 | 14 | function setReentrancy(bool _reentrancy) external { 15 | reentrancy = _reentrancy; 16 | } 17 | 18 | function setCallProtectedMethod(bool _callProtectedMethod) external { 19 | callProtectedMethod = _callProtectedMethod; 20 | } 21 | 22 | function run() public { 23 | callProtectedMethod ? target.protectedMethod() : target.unprotectedMethod(); 24 | } 25 | 26 | function callback() external { 27 | if (!reentrancy) { 28 | return; 29 | } 30 | 31 | if (!attacking) { 32 | attacking = true; 33 | 34 | run(); 35 | } 36 | 37 | attacking = false; 38 | } 39 | } 40 | 41 | contract TestReentrancyGuard is ReentrancyGuard { 42 | uint256 public calls; 43 | 44 | function protectedMethod() external protected { 45 | run(); 46 | } 47 | 48 | function unprotectedMethod() external { 49 | run(); 50 | } 51 | 52 | function run() private { 53 | calls++; 54 | 55 | TestReentrancyGuardAttacker(msg.sender).callback(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestSafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../utility/SafeMath.sol"; 3 | 4 | /* 5 | Utils test helper that exposes the safe math functions 6 | */ 7 | contract TestSafeMath { 8 | using SafeMath for uint256; 9 | 10 | function testSafeAdd(uint256 _x, uint256 _y) public pure returns (uint256) { 11 | return _x.add(_y); 12 | } 13 | 14 | function testSafeSub(uint256 _x, uint256 _y) public pure returns (uint256) { 15 | return _x.sub(_y); 16 | } 17 | 18 | function testSafeMul(uint256 _x, uint256 _y) public pure returns (uint256) { 19 | return _x.mul(_y); 20 | } 21 | 22 | function testSafeDiv(uint256 _x, uint256 _y) public pure returns (uint256) { 23 | return _x.div(_y); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestSovrynSwapFormula.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../converter/SovrynSwapFormula.sol"; 3 | 4 | /* 5 | SovrynSwapFormula test helper that exposes some SovrynSwapFormula functions 6 | */ 7 | contract TestSovrynSwapFormula is SovrynSwapFormula { 8 | function powerTest( 9 | uint256 _baseN, 10 | uint256 _baseD, 11 | uint32 _expN, 12 | uint32 _expD 13 | ) external view returns (uint256, uint8) { 14 | return super.power(_baseN, _baseD, _expN, _expD); 15 | } 16 | 17 | function generalLogTest(uint256 x) external pure returns (uint256) { 18 | return super.generalLog(x); 19 | } 20 | 21 | function floorLog2Test(uint256 _n) external pure returns (uint8) { 22 | return super.floorLog2(_n); 23 | } 24 | 25 | function findPositionInMaxExpArrayTest(uint256 _x) external view returns (uint8) { 26 | return super.findPositionInMaxExpArray(_x); 27 | } 28 | 29 | function generalExpTest(uint256 _x, uint8 _precision) external pure returns (uint256) { 30 | return super.generalExp(_x, _precision); 31 | } 32 | 33 | function optimalLogTest(uint256 x) external pure returns (uint256) { 34 | return super.optimalLog(x); 35 | } 36 | 37 | function optimalExpTest(uint256 x) external pure returns (uint256) { 38 | return super.optimalExp(x); 39 | } 40 | 41 | function normalizedWeightsTest(uint256 _a, uint256 _b) external pure returns (uint32, uint32) { 42 | return super.normalizedWeights(_a, _b); 43 | } 44 | 45 | function accurateWeightsTest(uint256 _a, uint256 _b) external pure returns (uint32, uint32) { 46 | return super.accurateWeights(_a, _b); 47 | } 48 | 49 | function roundDivTest(uint256 _n, uint256 _d) external pure returns (uint256) { 50 | return super.roundDiv(_n, _d); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestTokenHandler.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../utility/TokenHandler.sol"; 3 | 4 | /* 5 | Utils test helper that exposes the token handler functions 6 | */ 7 | contract TestTokenHandler is TokenHandler { 8 | function testSafeApprove( 9 | IERC20Token _token, 10 | address _spender, 11 | uint256 _value 12 | ) public { 13 | safeApprove(_token, _spender, _value); 14 | } 15 | 16 | function testSafeTransfer( 17 | IERC20Token _token, 18 | address _to, 19 | uint256 _value 20 | ) public { 21 | safeTransfer(_token, _to, _value); 22 | } 23 | 24 | function testSafeTransferFrom( 25 | IERC20Token _token, 26 | address _from, 27 | address _to, 28 | uint256 _value 29 | ) public { 30 | safeTransferFrom(_token, _from, _to, _value); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /solidity/contracts/helpers/TestTypedConverterAnchorFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../converter/interfaces/IConverterAnchor.sol"; 3 | import "../converter/interfaces/ITypedConverterAnchorFactory.sol"; 4 | import "../token/SmartToken.sol"; 5 | 6 | contract TestTypedConverterAnchorFactory is ITypedConverterAnchorFactory { 7 | string public name; 8 | 9 | constructor(string _name) public { 10 | name = _name; 11 | } 12 | 13 | function converterType() public pure returns (uint16) { 14 | return 8; 15 | } 16 | 17 | function createAnchor( 18 | string, /*_name */ 19 | string _symbol, 20 | uint8 _decimals 21 | ) public returns (IConverterAnchor) { 22 | IConverterAnchor anchor = new SmartToken(name, _symbol, _decimals); 23 | 24 | anchor.transferOwnership(msg.sender); 25 | 26 | return anchor; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solidity/contracts/mockup/FeeSharingProxyMockup.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | contract FeeSharingProxyMockup { 4 | event TokensTransferred(address indexed sender, address indexed token, uint256 amount); 5 | 6 | function transferTokens(address _token, uint96 _amount) public { 7 | emit TokensTransferred(msg.sender, _token, _amount); 8 | } 9 | 10 | function withdrawFees(address _converter, address _receiver) public { 11 | IConverterMockup(_converter).withdrawFees(_receiver); 12 | } 13 | } 14 | 15 | interface IConverterMockup { 16 | function withdrawFees(address receiver) public; 17 | } -------------------------------------------------------------------------------- /solidity/contracts/mockup/SovrynSwapNetworkMockup.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "../SovrynSwapNetwork.sol"; 4 | 5 | contract SovrynSwapNetworkMockup is SovrynSwapNetwork { 6 | uint256 public mockConversionValue; 7 | IERC20Token wrbtcToken; 8 | 9 | constructor(IContractRegistry _registry, uint256 _mockConversionValue, IERC20Token _wrbtcToken) public SovrynSwapNetwork(_registry) { 10 | mockConversionValue = _mockConversionValue; 11 | wrbtcToken = _wrbtcToken; 12 | } 13 | 14 | function conversionPath(IERC20Token _sourceToken, IERC20Token _targetToken) public view returns (address[]) { 15 | address[] memory _address; 16 | return _address; 17 | } 18 | 19 | function rateByPath(IERC20Token[] _path, uint256 _amount) public view returns (uint256) { 20 | return mockConversionValue; 21 | } 22 | 23 | /** 24 | * @dev used by converter withdraw fee function. 25 | * This function will act as token/WRBTC converter, and then directly send WRBTC (with total of mockConversionValue) into the caller. 26 | */ 27 | function convert( 28 | IERC20Token[] _path, 29 | uint256 _amount, 30 | uint256 _minReturn 31 | ) public payable returns (uint256) { 32 | wrbtcToken.transfer(msg.sender, mockConversionValue); 33 | return mockConversionValue; 34 | } 35 | 36 | function setMockConversionValue(uint256 _conversionValue) { 37 | mockConversionValue = _conversionValue; 38 | } 39 | } -------------------------------------------------------------------------------- /solidity/contracts/sovrynswapx/XTransferRerouter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../utility/Owned.sol"; 3 | 4 | contract XTransferRerouter is Owned { 5 | bool public reroutingEnabled; 6 | 7 | // triggered when a rerouteTx is called 8 | event TxReroute(uint256 indexed _txId, bytes32 _toBlockchain, bytes32 _to); 9 | 10 | /** 11 | * @dev initializes a new XTransferRerouter instance 12 | * 13 | * @param _reroutingEnabled intializes transactions routing to enabled/disabled 14 | */ 15 | constructor(bool _reroutingEnabled) public { 16 | reroutingEnabled = _reroutingEnabled; 17 | } 18 | 19 | /** 20 | * @dev allows the owner to disable/enable rerouting 21 | * 22 | * @param _enable true to enable, false to disable 23 | */ 24 | function enableRerouting(bool _enable) public ownerOnly { 25 | reroutingEnabled = _enable; 26 | } 27 | 28 | // allows execution only when rerouting enabled 29 | modifier reroutingAllowed { 30 | _reroutingAllowed(); 31 | _; 32 | } 33 | 34 | // error message binary size optimization 35 | function _reroutingAllowed() internal view { 36 | require(reroutingEnabled, "ERR_DISABLED"); 37 | } 38 | 39 | /** 40 | * @dev allows a user to reroute a transaction to a new blockchain/target address 41 | * 42 | * @param _txId the original transaction id 43 | * @param _blockchain the new blockchain name 44 | * @param _to the new target address/account 45 | */ 46 | function rerouteTx( 47 | uint256 _txId, 48 | bytes32 _blockchain, 49 | bytes32 _to 50 | ) public reroutingAllowed { 51 | emit TxReroute(_txId, _blockchain, _to); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /solidity/contracts/sovrynswapx/interfaces/ISovrynSwapX.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "../../token/interfaces/IERC20Token.sol"; 3 | 4 | contract ISovrynSwapX { 5 | function token() public view returns (IERC20Token) { 6 | this; 7 | } 8 | 9 | function xTransfer( 10 | bytes32 _toBlockchain, 11 | bytes32 _to, 12 | uint256 _amount, 13 | uint256 _id 14 | ) public; 15 | 16 | function getXTransferAmount(uint256 _xTransferId, address _for) public view returns (uint256); 17 | } 18 | -------------------------------------------------------------------------------- /solidity/contracts/sovrynswapx/interfaces/ISovrynSwapXUpgrader.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | SovrynSwap X Upgrader interface 5 | */ 6 | contract ISovrynSwapXUpgrader { 7 | function upgrade(uint16 _version, address[] _reporters) public; 8 | } 9 | -------------------------------------------------------------------------------- /solidity/contracts/token/interfaces/IERC20Token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | ERC20 Standard Token interface 5 | */ 6 | contract IERC20Token { 7 | // these functions aren't abstract since the compiler emits automatically generated getter functions as external 8 | function name() public view returns (string) { 9 | this; 10 | } 11 | 12 | function symbol() public view returns (string) { 13 | this; 14 | } 15 | 16 | function decimals() public view returns (uint8) { 17 | this; 18 | } 19 | 20 | function totalSupply() public view returns (uint256) { 21 | this; 22 | } 23 | 24 | function balanceOf(address _owner) public view returns (uint256) { 25 | _owner; 26 | this; 27 | } 28 | 29 | function allowance(address _owner, address _spender) public view returns (uint256) { 30 | _owner; 31 | _spender; 32 | this; 33 | } 34 | 35 | function transfer(address _to, uint256 _value) public returns (bool success); 36 | 37 | function transferFrom( 38 | address _from, 39 | address _to, 40 | uint256 _value 41 | ) public returns (bool success); 42 | 43 | function approve(address _spender, uint256 _value) public returns (bool success); 44 | } 45 | -------------------------------------------------------------------------------- /solidity/contracts/token/interfaces/IEtherToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./IERC20Token.sol"; 3 | 4 | /* 5 | Ether Token interface 6 | */ 7 | contract IEtherToken is IERC20Token { 8 | function deposit() public payable; 9 | 10 | function withdraw(uint256 _amount) public; 11 | 12 | function depositTo(address _to) public payable; 13 | 14 | function withdrawTo(address _to, uint256 _amount) public; 15 | } 16 | -------------------------------------------------------------------------------- /solidity/contracts/token/interfaces/ISmartToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./IERC20Token.sol"; 3 | import "../../converter/interfaces/IConverterAnchor.sol"; 4 | import "../../utility/interfaces/IOwned.sol"; 5 | 6 | /* 7 | Smart Token interface 8 | */ 9 | contract ISmartToken is IConverterAnchor, IERC20Token { 10 | function disableTransfers(bool _disable) public; 11 | 12 | function issue(address _to, uint256 _amount) public; 13 | 14 | function destroy(address _from, uint256 _amount) public; 15 | } 16 | -------------------------------------------------------------------------------- /solidity/contracts/utility/BProOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IMoCState.sol"; 4 | import "./interfaces/IConsumerPriceOracle.sol"; 5 | import "./Owned.sol"; 6 | 7 | contract BProOracle is IConsumerPriceOracle, Owned { 8 | address public mocStateAddress; 9 | 10 | event SetMoCStateAddress(address indexed mocStateAddress, address changerAddress); 11 | 12 | /** 13 | * @dev initializes a new MoC state 14 | * 15 | * @param _mocStateAddress MoC state address 16 | */ 17 | constructor(address _mocStateAddress) public { 18 | setMoCStateAddress(_mocStateAddress); 19 | } 20 | 21 | /** 22 | * @dev BPro USD PRICE 23 | * @return the BPro USD Price [using mocPrecision] 24 | */ 25 | function latestAnswer() external view returns (int256) { 26 | IMoCState _mocState = IMoCState(mocStateAddress); 27 | return int256(_mocState.bproUsdPrice()); 28 | } 29 | 30 | /** 31 | * @dev returns the update time. 32 | * 33 | * @return always returns current block's timestamp 34 | */ 35 | function latestTimestamp() external view returns (uint256) { 36 | return now; // MoC state doesn't return update timestamp 37 | } 38 | 39 | /** 40 | * @dev set MoC state address 41 | * 42 | * @param _mocStateAddress MoC state address 43 | */ 44 | function setMoCStateAddress(address _mocStateAddress) public ownerOnly { 45 | require(_mocStateAddress != address(0), "_mocStateAddress shall not be zero address"); 46 | mocStateAddress = _mocStateAddress; 47 | emit SetMoCStateAddress(mocStateAddress, msg.sender); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /solidity/contracts/utility/ChainlinkBTCToUSDOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IConsumerPriceOracle.sol"; 4 | 5 | /** 6 | * @dev Provides the BTC/USD rate 7 | */ 8 | contract ChainlinkBTCToUSDOracle is IConsumerPriceOracle { 9 | int256 private constant BTC_RATE = 10000; 10 | 11 | /** 12 | * @dev returns the BTC/USD rate. 13 | * 14 | * @return always returns the rate of 1 15 | */ 16 | function latestAnswer() external view returns (int256) { 17 | return BTC_RATE; 18 | } 19 | 20 | /** 21 | * @dev returns the BTC/USD update time. 22 | * 23 | * @return always returns current block's timestamp 24 | */ 25 | function latestTimestamp() external view returns (uint256) { 26 | return now; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solidity/contracts/utility/ChainlinkETHToETHOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IConsumerPriceOracle.sol"; 4 | 5 | /** 6 | * @dev Provides the trivial ETH/ETH rate to be used with other TKN/ETH rates 7 | */ 8 | contract ChainlinkETHToETHOracle is IConsumerPriceOracle { 9 | int256 private constant ETH_RATE = 1; 10 | 11 | /** 12 | * @dev returns the trivial ETH/ETH rate. 13 | * 14 | * @return always returns the trivial rate of 1 15 | */ 16 | function latestAnswer() external view returns (int256) { 17 | return ETH_RATE; 18 | } 19 | 20 | /** 21 | * @dev returns the trivial ETH/ETH update time. 22 | * 23 | * @return always returns current block's timestamp 24 | */ 25 | function latestTimestamp() external view returns (uint256) { 26 | return now; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solidity/contracts/utility/ChainlinkUSDToBTCOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IConsumerPriceOracle.sol"; 4 | 5 | /** 6 | * @dev Provides the USD/BTC rate 7 | */ 8 | contract ChainlinkUSDToBTCOracle is IConsumerPriceOracle { 9 | int256 private constant USD_RATE = 10000; 10 | 11 | /** 12 | * @dev returns the USD/BTC rate. 13 | * 14 | * @return always returns the rate of 10000 15 | */ 16 | function latestAnswer() external view returns (int256) { 17 | return USD_RATE; 18 | } 19 | 20 | /** 21 | * @dev returns the USD/BTC update time. 22 | * 23 | * @return always returns current block's timestamp 24 | */ 25 | function latestTimestamp() external view returns (uint256) { 26 | return now; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solidity/contracts/utility/MoCMedianizerMock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./MocBTCToUSDOracle.sol"; 3 | 4 | // This contract is only for test purposes 5 | // https://github.com/money-on-chain/Amphiraos-Oracle/blob/master/contracts/medianizer/medianizer.sol 6 | contract MoCMedianizerMock is Medianizer { 7 | uint256 public value; 8 | bool public has; 9 | 10 | function peek() external view returns (bytes32, bool) { 11 | return (bytes32(value), has); 12 | } 13 | 14 | function setValue(uint256 _value) public { 15 | value = _value; 16 | } 17 | 18 | function setHas(bool _has) public { 19 | has = _has; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /solidity/contracts/utility/MoCStateMock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IMoCState.sol"; 4 | 5 | contract MoCStateMock is IMoCState { 6 | uint256 public value; 7 | 8 | function bproUsdPrice() public view returns (uint256) { 9 | return value; 10 | } 11 | 12 | function setValue(uint256 _value) public { 13 | value = _value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /solidity/contracts/utility/MocBTCToBTCOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IConsumerPriceOracle.sol"; 4 | 5 | /** 6 | * @dev Provides the trivial ETH/ETH rate to be used with other TKN/ETH rates 7 | */ 8 | contract MocBTCToBTCOracle is IConsumerPriceOracle { 9 | int256 private constant BTC_RATE = 1; 10 | 11 | /** 12 | * @dev returns the trivial ETH/ETH rate. 13 | * 14 | * @return always returns the trivial rate of 1 15 | */ 16 | function latestAnswer() external view returns (int256) { 17 | return BTC_RATE; 18 | } 19 | 20 | /** 21 | * @dev returns the trivial ETH/ETH update time. 22 | * 23 | * @return always returns current block's timestamp 24 | */ 25 | function latestTimestamp() external view returns (uint256) { 26 | return now; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solidity/contracts/utility/MocBTCToUSDOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IConsumerPriceOracle.sol"; 4 | import "./Owned.sol"; 5 | 6 | interface Medianizer { 7 | function peek() external view returns (bytes32, bool); 8 | } 9 | 10 | contract MocBTCToUSDOracle is IConsumerPriceOracle, Owned { 11 | address public mocOracleAddress; 12 | 13 | event SetMoCOracleAddress(address indexed mocOracleAddress, address changerAddress); 14 | 15 | /** 16 | * @dev initializes a ne MoC oracle 17 | * 18 | * @param _mocOracleAddress MoC oracle address 19 | */ 20 | constructor(address _mocOracleAddress) public { 21 | setMoCOracleAddress(_mocOracleAddress); 22 | } 23 | 24 | /** 25 | * @dev returns the USD/BTC rate. 26 | * 27 | * @return MoC medianizer rate 28 | */ 29 | function latestAnswer() external view returns (int256) { 30 | (bytes32 value, bool hasValue) = Medianizer(mocOracleAddress).peek(); 31 | require(hasValue, "Doesn't has value"); 32 | return int256(value); 33 | } 34 | 35 | /** 36 | * @dev returns the USD/BTC update time. 37 | * 38 | * @return always returns current block's timestamp 39 | */ 40 | function latestTimestamp() external view returns (uint256) { 41 | return now; // MoC oracle doesn't return update timestamp 42 | } 43 | 44 | /** 45 | * @dev set MoC oracle address 46 | * 47 | * @param _mocOracleAddress MoC oracle address 48 | */ 49 | function setMoCOracleAddress(address _mocOracleAddress) public ownerOnly { 50 | require(_mocOracleAddress != address(0), "_mocOracleAddress shall not be zero address"); 51 | mocOracleAddress = _mocOracleAddress; 52 | emit SetMoCOracleAddress(mocOracleAddress, msg.sender); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /solidity/contracts/utility/MocUSDToBTCOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | import "./interfaces/IConsumerPriceOracle.sol"; 4 | import "./Owned.sol"; 5 | import "./SafeMath.sol"; 6 | 7 | interface Medianizer { 8 | function peek() external view returns (bytes32, bool); 9 | } 10 | 11 | contract MocUSDToBTCOracle is IConsumerPriceOracle, Owned { 12 | using SafeMath for uint256; 13 | 14 | uint256 public constant DECIMALS = 10**18; 15 | 16 | address public mocOracleAddress; 17 | 18 | event SetMoCOracleAddress(address indexed mocOracleAddress, address changerAddress); 19 | 20 | /** 21 | * @dev initializes a ne MoC oracle 22 | * 23 | * @param _mocOracleAddress MoC oracle address 24 | */ 25 | constructor(address _mocOracleAddress) public { 26 | setMoCOracleAddress(_mocOracleAddress); 27 | } 28 | 29 | /** 30 | * @dev returns the USD/BTC rate. 31 | * 32 | * @return always returns the rate of 10000 33 | */ 34 | function latestAnswer() external view returns (int256) { 35 | (bytes32 value, bool hasValue) = Medianizer(mocOracleAddress).peek(); 36 | require(hasValue, "Doesn't has value"); 37 | 38 | return int256(DECIMALS.div(uint256(value)).mul(DECIMALS)); 39 | } 40 | 41 | /** 42 | * @dev returns the USD/BTC update time. 43 | * 44 | * @return always returns current block's timestamp 45 | */ 46 | function latestTimestamp() external view returns (uint256) { 47 | return now; // MoC oracle doesn't return update timestamp 48 | } 49 | 50 | /** 51 | * @dev set MoC oracle address 52 | * 53 | * @param _mocOracleAddress MoC oracle address 54 | */ 55 | function setMoCOracleAddress(address _mocOracleAddress) public ownerOnly { 56 | require(_mocOracleAddress != address(0), "_mocOracleAddress shall not be zero address"); 57 | mocOracleAddress = _mocOracleAddress; 58 | emit SetMoCOracleAddress(mocOracleAddress, msg.sender); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /solidity/contracts/utility/Owned.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./interfaces/IOwned.sol"; 3 | 4 | /** 5 | * @dev Provides support and utilities for contract ownership 6 | */ 7 | contract Owned is IOwned { 8 | address public owner; 9 | address public newOwner; 10 | 11 | /** 12 | * @dev triggered when the owner is updated 13 | * 14 | * @param _prevOwner previous owner 15 | * @param _newOwner new owner 16 | */ 17 | event OwnerUpdate(address indexed _prevOwner, address indexed _newOwner); 18 | 19 | /** 20 | * @dev initializes a new Owned instance 21 | */ 22 | constructor() public { 23 | owner = msg.sender; 24 | } 25 | 26 | // allows execution by the owner only 27 | modifier ownerOnly { 28 | _ownerOnly(); 29 | _; 30 | } 31 | 32 | // error message binary size optimization 33 | function _ownerOnly() internal view { 34 | require(msg.sender == owner, "ERR_ACCESS_DENIED"); 35 | } 36 | 37 | /** 38 | * @dev allows transferring the contract ownership 39 | * the new owner still needs to accept the transfer 40 | * can only be called by the contract owner 41 | * 42 | * @param _newOwner new contract owner 43 | */ 44 | function transferOwnership(address _newOwner) public ownerOnly { 45 | require(_newOwner != owner, "ERR_SAME_OWNER"); 46 | newOwner = _newOwner; 47 | } 48 | 49 | /** 50 | * @dev used by a new owner to accept an ownership transfer 51 | */ 52 | function acceptOwnership() public { 53 | require(msg.sender == newOwner, "ERR_ACCESS_DENIED"); 54 | emit OwnerUpdate(owner, newOwner); 55 | owner = newOwner; 56 | newOwner = address(0); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /solidity/contracts/utility/ReentrancyGuard.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /** 4 | * @dev ReentrancyGuard 5 | * 6 | * The contract provides protection against re-entrancy - calling a function (directly or 7 | * indirectly) from within itself. 8 | */ 9 | contract ReentrancyGuard { 10 | uint256 private constant UNLOCKED = 1; 11 | uint256 private constant LOCKED = 2; 12 | 13 | // LOCKED while protected code is being executed, UNLOCKED otherwise 14 | uint256 private state = UNLOCKED; 15 | 16 | /** 17 | * @dev ensures instantiation only by sub-contracts 18 | */ 19 | constructor() internal {} 20 | 21 | // protects a function against reentrancy attacks 22 | modifier protected() { 23 | _protected(); 24 | state = LOCKED; 25 | _; 26 | state = UNLOCKED; 27 | } 28 | 29 | // error message binary size optimization 30 | function _protected() internal view { 31 | require(state == UNLOCKED, "ERR_REENTRANCY"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /solidity/contracts/utility/SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /** 4 | * @dev Library for basic math operations with overflow/underflow protection 5 | */ 6 | library SafeMath { 7 | /** 8 | * @dev returns the sum of _x and _y, reverts if the calculation overflows 9 | * 10 | * @param _x value 1 11 | * @param _y value 2 12 | * 13 | * @return sum 14 | */ 15 | function add(uint256 _x, uint256 _y) internal pure returns (uint256) { 16 | uint256 z = _x + _y; 17 | require(z >= _x, "ERR_OVERFLOW"); 18 | return z; 19 | } 20 | 21 | /** 22 | * @dev returns the difference of _x minus _y, reverts if the calculation underflows 23 | * 24 | * @param _x minuend 25 | * @param _y subtrahend 26 | * 27 | * @return difference 28 | */ 29 | function sub(uint256 _x, uint256 _y) internal pure returns (uint256) { 30 | require(_x >= _y, "ERR_UNDERFLOW"); 31 | return _x - _y; 32 | } 33 | 34 | /** 35 | * @dev returns the product of multiplying _x by _y, reverts if the calculation overflows 36 | * 37 | * @param _x factor 1 38 | * @param _y factor 2 39 | * 40 | * @return product 41 | */ 42 | function mul(uint256 _x, uint256 _y) internal pure returns (uint256) { 43 | // gas optimization 44 | if (_x == 0) return 0; 45 | 46 | uint256 z = _x * _y; 47 | require(z / _x == _y, "ERR_OVERFLOW"); 48 | return z; 49 | } 50 | 51 | /** 52 | * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. 53 | * 54 | * @param _x dividend 55 | * @param _y divisor 56 | * 57 | * @return quotient 58 | */ 59 | function div(uint256 _x, uint256 _y) internal pure returns (uint256) { 60 | require(_y > 0, "ERR_DIVIDE_BY_ZERO"); 61 | uint256 c = _x / _y; 62 | return c; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /solidity/contracts/utility/TokenHolder.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./Owned.sol"; 3 | import "./Utils.sol"; 4 | import "./TokenHandler.sol"; 5 | import "./interfaces/ITokenHolder.sol"; 6 | import "../token/interfaces/IERC20Token.sol"; 7 | 8 | /** 9 | * @dev We consider every contract to be a 'token holder' since it's currently not possible 10 | * for a contract to deny receiving tokens. 11 | * 12 | * The TokenHolder's contract sole purpose is to provide a safety mechanism that allows 13 | * the owner to send tokens that were sent to the contract by mistake back to their sender. 14 | * 15 | * Note that we use the non standard ERC-20 interface which has no return value for transfer 16 | * in order to support both non standard as well as standard token contracts. 17 | * see https://github.com/ethereum/solidity/issues/4116 18 | */ 19 | contract TokenHolder is ITokenHolder, TokenHandler, Owned, Utils { 20 | /** 21 | * @dev withdraws tokens held by the contract and sends them to an account 22 | * can only be called by the owner 23 | * 24 | * @param _token ERC20 token contract address 25 | * @param _to account to receive the new amount 26 | * @param _amount amount to withdraw 27 | */ 28 | function withdrawTokens( 29 | IERC20Token _token, 30 | address _to, 31 | uint256 _amount 32 | ) public ownerOnly validAddress(_token) validAddress(_to) notThis(_to) { 33 | safeTransfer(_token, _to, _amount); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /solidity/contracts/utility/Utils.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /** 4 | * @dev Utilities & Common Modifiers 5 | */ 6 | contract Utils { 7 | // verifies that a value is greater than zero 8 | modifier greaterThanZero(uint256 _value) { 9 | _greaterThanZero(_value); 10 | _; 11 | } 12 | 13 | // error message binary size optimization 14 | function _greaterThanZero(uint256 _value) internal pure { 15 | require(_value > 0, "ERR_ZERO_VALUE"); 16 | } 17 | 18 | // validates an address - currently only checks that it isn't null 19 | modifier validAddress(address _address) { 20 | _validAddress(_address); 21 | _; 22 | } 23 | 24 | // error message binary size optimization 25 | function _validAddress(address _address) internal pure { 26 | require(_address != address(0), "ERR_INVALID_ADDRESS"); 27 | } 28 | 29 | // verifies that the address is different than this contract address 30 | modifier notThis(address _address) { 31 | _notThis(_address); 32 | _; 33 | } 34 | 35 | // error message binary size optimization 36 | function _notThis(address _address) internal view { 37 | require(_address != address(this), "ERR_ADDRESS_IS_SELF"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/IConsumerPriceOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | Chainlink Price Oracle interface 5 | */ 6 | interface IConsumerPriceOracle { 7 | function latestAnswer() external view returns (int256); 8 | 9 | function latestTimestamp() external view returns (uint256); 10 | } 11 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/IContractRegistry.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | Contract Registry interface 5 | */ 6 | contract IContractRegistry { 7 | function addressOf(bytes32 _contractName) public view returns (address); 8 | 9 | // deprecated, backward compatibility 10 | function getAddress(bytes32 _contractName) public view returns (address); 11 | } 12 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/IMoCState.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | interface IMoCState { 4 | function bproUsdPrice() external view returns (uint256); 5 | } 6 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/IOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | interface IOracle { 4 | function setK(uint256 _k) external; 5 | 6 | function write(uint256 price0, uint256 price1) external; 7 | 8 | function read() 9 | external 10 | returns ( 11 | uint256 ema0, 12 | uint256 ema1, 13 | uint64 blockNumber, 14 | uint64 timestamp, 15 | uint256 lastCumulativePrice0, 16 | uint256 lastCumulativePrice1 17 | ); 18 | 19 | //returns the price of a reserve in BTC (assuming one of the reserve is always BTC) 20 | function latestAnswer() external view returns (uint256); 21 | } 22 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/IOwned.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | Owned contract interface 5 | */ 6 | contract IOwned { 7 | // this function isn't abstract since the compiler emits automatically generated getter functions as external 8 | function owner() public view returns (address) { 9 | this; 10 | } 11 | 12 | function transferOwnership(address _newOwner) public; 13 | 14 | function acceptOwnership() public; 15 | } 16 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/IPriceOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./IConsumerPriceOracle.sol"; 3 | import "../../token/interfaces/IERC20Token.sol"; 4 | 5 | /* 6 | Price Oracle interface 7 | */ 8 | contract IPriceOracle { 9 | function latestRate(IERC20Token _tokenA, IERC20Token _tokenB) public view returns (uint256, uint256); 10 | 11 | function lastUpdateTime() public view returns (uint256); 12 | 13 | function latestRateAndUpdateTime(IERC20Token _tokenA, IERC20Token _tokenB) 14 | public 15 | view 16 | returns ( 17 | uint256, 18 | uint256, 19 | uint256 20 | ); 21 | 22 | function tokenAOracle() public view returns (IConsumerPriceOracle) { 23 | this; 24 | } 25 | 26 | function tokenBOracle() public view returns (IConsumerPriceOracle) { 27 | this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/ITokenHolder.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | import "./IOwned.sol"; 3 | import "../../token/interfaces/IERC20Token.sol"; 4 | 5 | /* 6 | Token Holder interface 7 | */ 8 | contract ITokenHolder is IOwned { 9 | function withdrawTokens( 10 | IERC20Token _token, 11 | address _to, 12 | uint256 _amount 13 | ) public; 14 | } 15 | -------------------------------------------------------------------------------- /solidity/contracts/utility/interfaces/IWhitelist.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.26; 2 | 3 | /* 4 | Whitelist interface 5 | */ 6 | contract IWhitelist { 7 | function isWhitelisted(address _address) public view returns (bool); 8 | } 9 | -------------------------------------------------------------------------------- /solidity/python/AutoGenerate/PrintFileFormulaConstants.py: -------------------------------------------------------------------------------- 1 | from common.functions import getTaylorCoefs 2 | from common.functions import getMaxExpArray 3 | from common.functions import getMaxValArray 4 | from common.constants import NUM_OF_TAYLOR_COEFS 5 | from common.constants import MIN_PRECISION 6 | from common.constants import MAX_PRECISION 7 | 8 | 9 | coefficients = getTaylorCoefs(NUM_OF_TAYLOR_COEFS) 10 | maxExpArray = getMaxExpArray(coefficients,MAX_PRECISION+1) 11 | maxValArray = getMaxValArray(coefficients,maxExpArray) 12 | 13 | 14 | print('module.exports.MIN_PRECISION = {};'.format(MIN_PRECISION)) 15 | print('module.exports.MAX_PRECISION = {};'.format(MAX_PRECISION)) 16 | 17 | 18 | print('module.exports.maxExpArray = [') 19 | for precision in range(len(maxExpArray)): 20 | print(' /* {:3d} */ \'0x{:x}\','.format(precision,maxExpArray[precision])) 21 | print('];') 22 | 23 | 24 | print('module.exports.maxValArray = [') 25 | for precision in range(len(maxValArray)): 26 | print(' /* {:3d} */ \'0x{:x}\','.format(precision,maxValArray[precision])) 27 | print('];') 28 | -------------------------------------------------------------------------------- /solidity/python/AutoGenerate/PrintFunctionGeneralExp.py: -------------------------------------------------------------------------------- 1 | from common.functions import getTaylorCoefs 2 | from common.constants import NUM_OF_TAYLOR_COEFS 3 | 4 | 5 | coefficients = getTaylorCoefs(NUM_OF_TAYLOR_COEFS) 6 | 7 | 8 | valueMaxLen = len(hex(coefficients[1])) 9 | indexMaxLen = len(str(len(coefficients))) 10 | 11 | 12 | print(' function generalExp(uint256 _x, uint8 _precision) internal pure returns (uint256) {') 13 | print(' uint256 xi = _x;') 14 | print(' uint256 res = 0;') 15 | print('') 16 | for i in range(1,len(coefficients)): 17 | print(' xi = (xi * _x) >> _precision; res += xi * {0:#0{4}x}; // add x^{1:0{5}d} * ({2:0{5}d}! / {3:0{5}d}!)'.format(coefficients[i],i+1,len(coefficients),i+1,valueMaxLen,indexMaxLen)) 18 | print('') 19 | print(' return res / 0x{:x} + _x + (ONE << _precision); // divide by {}! and then add x^1 / 1! + x^0 / 0!'.format(coefficients[0],len(coefficients))) 20 | print(' }') 21 | -------------------------------------------------------------------------------- /solidity/python/AutoGenerate/PrintFunctionLambertNeg1.py: -------------------------------------------------------------------------------- 1 | from common.functions import getLambertCoefs 2 | from common.constants import NUM_OF_LAMBERT_COEFS 3 | 4 | 5 | coefficients = getLambertCoefs(NUM_OF_LAMBERT_COEFS) 6 | 7 | 8 | valueMaxLen = len(hex(coefficients[-1])) 9 | indexMaxLen = len(str(len(coefficients))) 10 | 11 | 12 | print(' function lambertNeg1(uint256 _x) internal pure returns (uint256) {') 13 | print(' uint256 xi = _x;') 14 | print(' uint256 res = 0;') 15 | print('') 16 | for i in range(2,len(coefficients)): 17 | print(' xi = (xi * _x) / FIXED_1; res += xi * {0:#0{3}x}; // add x^({1:0{4}d}-1) * ({2:d}! * {1:0{4}d}^({1:0{4}d}-1) / {1:0{4}d}!)'.format(coefficients[i],i+1,len(coefficients),valueMaxLen,indexMaxLen)) 18 | print('') 19 | print(' return res / 0x{:x} + _x + FIXED_1; // divide by {}! and then add x^(2-1) * ({}! * 2^(2-1) / 2!) + x^(1-1) * ({}! * 1^(1-1) / 1!)'.format(coefficients[0],len(coefficients),len(coefficients),len(coefficients))) 20 | print(' }') 21 | -------------------------------------------------------------------------------- /solidity/python/AutoGenerate/PrintFunctionLambertPos1.py: -------------------------------------------------------------------------------- 1 | from common.functions import getLambertCoefs 2 | from common.constants import NUM_OF_LAMBERT_COEFS 3 | 4 | 5 | coefficients = getLambertCoefs(NUM_OF_LAMBERT_COEFS) 6 | 7 | 8 | valueMaxLen = len(hex(coefficients[-1])) 9 | indexMaxLen = len(str(len(coefficients))) 10 | 11 | 12 | print(' function lambertPos1(uint256 _x) internal pure returns (uint256) {') 13 | print(' uint256 xi = _x;') 14 | print(' uint256 res = (FIXED_1 - _x) * 0x{:x}; // x^(1-1) * ({}! * 1^(1-1) / 1!) - x^(2-1) * ({}! * 2^(2-1) / 2!)'.format(coefficients[0],len(coefficients),len(coefficients))) 15 | print('') 16 | for i in range(2,len(coefficients)): 17 | print(' xi = (xi * _x) / FIXED_1; res {5:s}= xi * {0:#0{3}x}; // {6:s} x^({1:0{4}d}-1) * ({2:d}! * {1:0{4}d}^({1:0{4}d}-1) / {1:0{4}d}!)'.format(coefficients[i],i+1,len(coefficients),valueMaxLen,indexMaxLen,'+-'[i%2],['add','sub'][i%2])) 18 | print('') 19 | print(' return res / 0x{:x}; // divide by {}!'.format(coefficients[0],len(coefficients))) 20 | print(' }') 21 | -------------------------------------------------------------------------------- /solidity/python/AutoGenerate/PrintIntScalingFactors.py: -------------------------------------------------------------------------------- 1 | from common.constants import MAX_PRECISION 2 | 3 | 4 | FIXED_1 = 1< resultNativePython: 10 | error = ['Implementation Error:'] 11 | error.append('supply = {}'.format(supply)) 12 | error.append('balance = {}'.format(balance)) 13 | error.append('weight = {}'.format(weight)) 14 | error.append('amount = {}'.format(amount)) 15 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 16 | error.append('resultNativePython = {}'.format(resultNativePython)) 17 | raise BaseException('\n'.join(error)) 18 | return resultSolidityPort / resultNativePython 19 | 20 | 21 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 22 | if size == 0: 23 | size = int(input('How many test-cases would you like to execute? ')) 24 | 25 | 26 | bgn = 10 ** 14 27 | end = 10 ** 23 28 | gap = (end - bgn) // size 29 | 30 | 31 | worstAccuracy = 1 32 | numOfFailures = 0 33 | 34 | 35 | for n in range(size): 36 | supply = 10 ** 26 37 | balance = 10 ** 23 38 | weight = 100000 39 | amount = bgn + gap * n 40 | try: 41 | accuracy = formulaTest(supply, balance, weight, amount) 42 | worstAccuracy = min(worstAccuracy, accuracy) 43 | except Exception as error: 44 | accuracy = 0 45 | numOfFailures += 1 46 | except BaseException as error: 47 | print(error) 48 | break 49 | print('Test #{}: amount = {:23d}, accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, amount, accuracy, worstAccuracy, numOfFailures)) 50 | -------------------------------------------------------------------------------- /solidity/python/BenchmarkTestSale.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import FormulaSolidityPort 3 | import FormulaNativePython 4 | 5 | 6 | def formulaTest(supply, balance, weight, amount): 7 | resultSolidityPort = FormulaSolidityPort.saleTargetAmount(supply, balance, weight, amount) 8 | resultNativePython = FormulaNativePython.saleTargetAmount(supply, balance, weight, amount) 9 | if resultSolidityPort > resultNativePython: 10 | error = ['Implementation Error:'] 11 | error.append('supply = {}'.format(supply)) 12 | error.append('balance = {}'.format(balance)) 13 | error.append('weight = {}'.format(weight)) 14 | error.append('amount = {}'.format(amount)) 15 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 16 | error.append('resultNativePython = {}'.format(resultNativePython)) 17 | raise BaseException('\n'.join(error)) 18 | return resultSolidityPort / resultNativePython 19 | 20 | 21 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 22 | if size == 0: 23 | size = int(input('How many test-cases would you like to execute? ')) 24 | 25 | 26 | bgn = 10 ** 17 27 | end = 10 ** 26 28 | gap = (end - bgn) // size 29 | 30 | 31 | worstAccuracy = 1 32 | numOfFailures = 0 33 | 34 | 35 | for n in range(size): 36 | supply = 10 ** 26 37 | balance = 10 ** 23 38 | weight = 100000 39 | amount = bgn + gap * n 40 | try: 41 | accuracy = formulaTest(supply, balance, weight, amount) 42 | worstAccuracy = min(worstAccuracy, accuracy) 43 | except Exception as error: 44 | accuracy = 0 45 | numOfFailures += 1 46 | except BaseException as error: 47 | print(error) 48 | break 49 | print('Test #{}: amount = {:26d}, accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, amount, accuracy, worstAccuracy, numOfFailures)) 50 | -------------------------------------------------------------------------------- /solidity/python/InputGenerator/__init__.py: -------------------------------------------------------------------------------- 1 | from math import log 2 | 3 | 4 | def UniformDistribution(minimumValue,maximumValue,samplesCount): 5 | return [minimumValue+n*(maximumValue-minimumValue)//(samplesCount-1) for n in range(samplesCount)] 6 | 7 | 8 | def ExponentialDistribution(minimumValue,maximumValue,growthFactor): 9 | return [int(minimumValue*growthFactor**n) for n in range(int(log(float(maximumValue)/float(minimumValue),growthFactor))+1)] 10 | -------------------------------------------------------------------------------- /solidity/python/RandomTestFund.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(supply, balance, weights, amount): 8 | resultSolidityPort = FormulaSolidityPort.fundCost(supply, balance, weights, amount) 9 | resultNativePython = FormulaNativePython.fundCost(supply, balance, weights, amount) 10 | if resultNativePython > resultSolidityPort: 11 | error = ['Implementation Error:'] 12 | error.append('supply = {}'.format(supply)) 13 | error.append('balance = {}'.format(balance)) 14 | error.append('weights = {}'.format(weights)) 15 | error.append('amount = {}'.format(amount)) 16 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 17 | error.append('resultNativePython = {}'.format(resultNativePython)) 18 | raise BaseException('\n'.join(error)) 19 | return resultNativePython / resultSolidityPort 20 | 21 | 22 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 23 | if size == 0: 24 | size = int(input('How many test-cases would you like to execute? ')) 25 | 26 | 27 | worstAccuracy = 1 28 | numOfFailures = 0 29 | 30 | 31 | for n in range(size): 32 | supply = random.randrange(2, 10 ** 26) 33 | balance = random.randrange(1, 10 ** 23) 34 | weights = random.randrange(10000, 2000001) 35 | amount = random.randrange(1, supply // 10) 36 | try: 37 | accuracy = formulaTest(supply, balance, weights, amount) 38 | worstAccuracy = min(worstAccuracy, accuracy) 39 | except Exception as error: 40 | accuracy = 0 41 | numOfFailures += 1 42 | except BaseException as error: 43 | print(error) 44 | break 45 | print('Test #{}: accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, accuracy, worstAccuracy, numOfFailures)) 46 | -------------------------------------------------------------------------------- /solidity/python/RandomTestFundInv.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(supply, balance, weights, amount): 8 | resultSolidityPort = FormulaSolidityPort.fundSupplyAmount(supply, balance, weights, amount) 9 | resultNativePython = FormulaNativePython.fundSupplyAmount(supply, balance, weights, amount) 10 | if resultSolidityPort > resultNativePython: 11 | error = ['Implementation Error:'] 12 | error.append('supply = {}'.format(supply)) 13 | error.append('balance = {}'.format(balance)) 14 | error.append('weights = {}'.format(weights)) 15 | error.append('amount = {}'.format(amount)) 16 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 17 | error.append('resultNativePython = {}'.format(resultNativePython)) 18 | raise BaseException('\n'.join(error)) 19 | return resultNativePython / resultSolidityPort 20 | 21 | 22 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 23 | if size == 0: 24 | size = int(input('How many test-cases would you like to execute? ')) 25 | 26 | 27 | worstAccuracy = 1 28 | numOfFailures = 0 29 | 30 | 31 | for n in range(size): 32 | supply = random.randrange(2, 10 ** 26) 33 | balance = random.randrange(1, 10 ** 23) 34 | weights = random.randrange(10000, 2000001) 35 | amount = random.randrange(1, balance * 10) 36 | try: 37 | accuracy = formulaTest(supply, balance, weights, amount) 38 | worstAccuracy = min(worstAccuracy, accuracy) 39 | except Exception as error: 40 | accuracy = 0 41 | numOfFailures += 1 42 | except BaseException as error: 43 | print(error) 44 | break 45 | print('Test #{}: accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, accuracy, worstAccuracy, numOfFailures)) 46 | -------------------------------------------------------------------------------- /solidity/python/RandomTestLambertNeg1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(x): 8 | resultSolidityPort = FormulaSolidityPort.lambertNeg1(x) 9 | resultNativePython = FormulaNativePython.lambertNeg(x, FormulaSolidityPort.MAX_PRECISION) 10 | if resultSolidityPort > resultNativePython: 11 | error = ['Implementation Error:'] 12 | error.append('x = {}'.format(x)) 13 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 14 | error.append('resultNativePython = {}'.format(resultNativePython)) 15 | raise BaseException('\n'.join(error)) 16 | return resultSolidityPort / resultNativePython 17 | 18 | 19 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 20 | if size == 0: 21 | size = int(input('How many test-cases would you like to execute? ')) 22 | 23 | 24 | worstAccuracy = 1 25 | 26 | 27 | for n in range(size): 28 | x = random.randrange(1, FormulaSolidityPort.LAMBERT_CONV_RADIUS + 1) 29 | try: 30 | accuracy = formulaTest(x) 31 | worstAccuracy = min(worstAccuracy, accuracy) 32 | except BaseException as error: 33 | print(error) 34 | break 35 | print('Test #{}: accuracy = {:.18f}, worst accuracy = {:.18f}'.format(n, accuracy, worstAccuracy)) 36 | -------------------------------------------------------------------------------- /solidity/python/RandomTestLambertPos1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(x): 8 | resultSolidityPort = FormulaSolidityPort.lambertPos1(x) 9 | resultNativePython = FormulaNativePython.lambertPos(x, FormulaSolidityPort.MAX_PRECISION) 10 | return resultSolidityPort / resultNativePython 11 | 12 | 13 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 14 | if size == 0: 15 | size = int(input('How many test-cases would you like to execute? ')) 16 | 17 | 18 | minRatio = float('+inf') 19 | maxRatio = float('-inf') 20 | 21 | 22 | for n in range(size): 23 | x = random.randrange(1, FormulaSolidityPort.LAMBERT_CONV_RADIUS + 1) 24 | ratio = formulaTest(x) 25 | minRatio = min(minRatio, ratio) 26 | maxRatio = max(maxRatio, ratio) 27 | print('Test #{}: ratio = {:.18f}, minRatio = {:.18f}, maxRatio = {:.18f}'.format(n, ratio, minRatio, maxRatio)) 28 | -------------------------------------------------------------------------------- /solidity/python/RandomTestLambertPos2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(x): 8 | resultSolidityPort = FormulaSolidityPort.lambertPos2(x) 9 | resultNativePython = FormulaNativePython.lambertPos(x, FormulaSolidityPort.MAX_PRECISION) 10 | return resultSolidityPort / resultNativePython 11 | 12 | 13 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 14 | if size == 0: 15 | size = int(input('How many test-cases would you like to execute? ')) 16 | 17 | 18 | minRatio = float('+inf') 19 | maxRatio = float('-inf') 20 | 21 | 22 | for n in range(size): 23 | x = random.randrange(FormulaSolidityPort.LAMBERT_CONV_RADIUS + 1, FormulaSolidityPort.LAMBERT_POS2_MAXVAL + 1) 24 | ratio = formulaTest(x) 25 | minRatio = min(minRatio, ratio) 26 | maxRatio = max(maxRatio, ratio) 27 | print('Test #{}: ratio = {:.18f}, minRatio = {:.18f}, maxRatio = {:.18f}'.format(n, ratio, minRatio, maxRatio)) 28 | -------------------------------------------------------------------------------- /solidity/python/RandomTestLambertPos3.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(x): 8 | resultSolidityPort = FormulaSolidityPort.lambertPos3(x) 9 | resultNativePython = FormulaNativePython.lambertPos(x, FormulaSolidityPort.MAX_PRECISION) 10 | return resultSolidityPort / resultNativePython 11 | 12 | 13 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 14 | if size == 0: 15 | size = int(input('How many test-cases would you like to execute? ')) 16 | 17 | 18 | minRatio = float('+inf') 19 | maxRatio = float('-inf') 20 | 21 | 22 | for n in range(size): 23 | x = random.randrange(FormulaSolidityPort.LAMBERT_POS2_MAXVAL + 1, FormulaSolidityPort.LAMBERT_POS3_MAXVAL + 1) 24 | ratio = formulaTest(x) 25 | minRatio = min(minRatio, ratio) 26 | maxRatio = max(maxRatio, ratio) 27 | print('Test #{}: ratio = {:.18f}, minRatio = {:.18f}, maxRatio = {:.18f}'.format(n, ratio, minRatio, maxRatio)) 28 | -------------------------------------------------------------------------------- /solidity/python/RandomTestLiquidate.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(supply, balance, weights, amount): 8 | resultSolidityPort = FormulaSolidityPort.liquidateReserveAmount(supply, balance, weights, amount) 9 | resultNativePython = FormulaNativePython.liquidateReserveAmount(supply, balance, weights, amount) 10 | if resultSolidityPort > resultNativePython: 11 | error = ['Implementation Error:'] 12 | error.append('supply = {}'.format(supply)) 13 | error.append('balance = {}'.format(balance)) 14 | error.append('weights = {}'.format(weights)) 15 | error.append('amount = {}'.format(amount)) 16 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 17 | error.append('resultNativePython = {}'.format(resultNativePython)) 18 | raise BaseException('\n'.join(error)) 19 | return resultSolidityPort / resultNativePython 20 | 21 | 22 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 23 | if size == 0: 24 | size = int(input('How many test-cases would you like to execute? ')) 25 | 26 | 27 | worstAccuracy = 1 28 | numOfFailures = 0 29 | 30 | 31 | for n in range(size): 32 | supply = random.randrange(2, 10 ** 26) 33 | balance = random.randrange(1, 10 ** 23) 34 | weights = random.randrange(10000, 2000001) 35 | amount = random.randrange(1, supply // 10) 36 | try: 37 | accuracy = formulaTest(supply, balance, weights, amount) 38 | worstAccuracy = min(worstAccuracy, accuracy) 39 | except Exception as error: 40 | accuracy = 0 41 | numOfFailures += 1 42 | except BaseException as error: 43 | print(error) 44 | break 45 | print('Test #{}: accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, accuracy, worstAccuracy, numOfFailures)) 46 | -------------------------------------------------------------------------------- /solidity/python/RandomTestPower.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(baseN, baseD, expN, expD): 8 | resultSolidityPort, precision = FormulaSolidityPort.power(baseN, baseD, expN, expD) 9 | resultNativePython = FormulaNativePython.power(baseN, baseD, expN, expD, precision) 10 | if resultSolidityPort > resultNativePython: 11 | error = ['Implementation Error:'] 12 | error.append('baseN = {}'.format(baseN)) 13 | error.append('baseD = {}'.format(baseD)) 14 | error.append('expN = {}'.format(expN)) 15 | error.append('expD = {}'.format(expD)) 16 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 17 | error.append('resultNativePython = {}'.format(resultNativePython)) 18 | raise BaseException('\n'.join(error)) 19 | return resultSolidityPort / resultNativePython 20 | 21 | 22 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 23 | if size == 0: 24 | size = int(input('How many test-cases would you like to execute? ')) 25 | 26 | 27 | worstAccuracy = 1 28 | numOfFailures = 0 29 | 30 | 31 | for n in range(size): 32 | baseN = random.randrange(2, 10**26) 33 | baseD = random.randrange(1, baseN) 34 | expN = random.randrange(1, 1000000) 35 | expD = random.randrange(expN, 1000001) 36 | try: 37 | accuracy = formulaTest(baseN, baseD, expN, expD) 38 | worstAccuracy = min(worstAccuracy, accuracy) 39 | except Exception as error: 40 | accuracy = 0 41 | numOfFailures += 1 42 | except BaseException as error: 43 | print(error) 44 | break 45 | print('Test #{}: accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, accuracy, worstAccuracy, numOfFailures)) 46 | -------------------------------------------------------------------------------- /solidity/python/RandomTestPurchase.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(supply, balance, weight, amount): 8 | resultSolidityPort = FormulaSolidityPort.purchaseTargetAmount(supply, balance, weight, amount) 9 | resultNativePython = FormulaNativePython.purchaseTargetAmount(supply, balance, weight, amount) 10 | if resultSolidityPort > resultNativePython: 11 | error = ['Implementation Error:'] 12 | error.append('supply = {}'.format(supply)) 13 | error.append('balance = {}'.format(balance)) 14 | error.append('weight = {}'.format(weight)) 15 | error.append('amount = {}'.format(amount)) 16 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 17 | error.append('resultNativePython = {}'.format(resultNativePython)) 18 | raise BaseException('\n'.join(error)) 19 | return resultSolidityPort / resultNativePython 20 | 21 | 22 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 23 | if size == 0: 24 | size = int(input('How many test-cases would you like to execute? ')) 25 | 26 | 27 | worstAccuracy = 1 28 | numOfFailures = 0 29 | 30 | 31 | for n in range(size): 32 | supply = random.randrange(2, 10 ** 26) 33 | balance = random.randrange(1, 10 ** 23) 34 | weight = random.randrange(1, 1000000) 35 | amount = random.randrange(1, balance * 10) 36 | try: 37 | accuracy = formulaTest(supply, balance, weight, amount) 38 | worstAccuracy = min(worstAccuracy, accuracy) 39 | except Exception as error: 40 | accuracy = 0 41 | numOfFailures += 1 42 | except BaseException as error: 43 | print(error) 44 | break 45 | print('Test #{}: accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, accuracy, worstAccuracy, numOfFailures)) 46 | -------------------------------------------------------------------------------- /solidity/python/RandomTestSale.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | import FormulaNativePython 5 | 6 | 7 | def formulaTest(supply, balance, weight, amount): 8 | resultSolidityPort = FormulaSolidityPort.saleTargetAmount(supply, balance, weight, amount) 9 | resultNativePython = FormulaNativePython.saleTargetAmount(supply, balance, weight, amount) 10 | if resultSolidityPort > resultNativePython: 11 | error = ['Implementation Error:'] 12 | error.append('supply = {}'.format(supply)) 13 | error.append('balance = {}'.format(balance)) 14 | error.append('weight = {}'.format(weight)) 15 | error.append('amount = {}'.format(amount)) 16 | error.append('resultSolidityPort = {}'.format(resultSolidityPort)) 17 | error.append('resultNativePython = {}'.format(resultNativePython)) 18 | raise BaseException('\n'.join(error)) 19 | return resultSolidityPort / resultNativePython 20 | 21 | 22 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 23 | if size == 0: 24 | size = int(input('How many test-cases would you like to execute? ')) 25 | 26 | 27 | worstAccuracy = 1 28 | numOfFailures = 0 29 | 30 | 31 | for n in range(size): 32 | supply = random.randrange(2, 10 ** 26) 33 | balance = random.randrange(1, 10 ** 23) 34 | weight = random.randrange(1, 1000000) 35 | amount = random.randrange(1, supply) 36 | try: 37 | accuracy = formulaTest(supply, balance, weight, amount) 38 | worstAccuracy = min(worstAccuracy, accuracy) 39 | except Exception as error: 40 | accuracy = 0 41 | numOfFailures += 1 42 | except BaseException as error: 43 | print(error) 44 | break 45 | print('Test #{}: accuracy = {:.18f}, worst accuracy = {:.18f}, num of failures = {}'.format(n, accuracy, worstAccuracy, numOfFailures)) 46 | -------------------------------------------------------------------------------- /solidity/python/RandomTestVerifyFund.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | import FormulaSolidityPort 4 | 5 | 6 | from decimal import Decimal 7 | from decimal import getcontext 8 | getcontext().prec = 80 # 78 digits for a maximum of 2^256-1, and 2 more digits for after the decimal point 9 | 10 | 11 | def formulaTest(supply, balance1, weight1, balance2, weight2, amount0): 12 | amount1 = FormulaSolidityPort.fundCost(supply, balance1, weight1 + weight2, amount0) 13 | amount2 = FormulaSolidityPort.fundCost(supply, balance2, weight1 + weight2, amount0) 14 | amount3 = FormulaSolidityPort.purchaseTargetAmount(supply, balance1, weight1, amount1) 15 | amount4 = FormulaSolidityPort.purchaseTargetAmount(supply + amount3, balance2, weight2, amount2) 16 | return Decimal(amount0) / Decimal(amount3 + amount4) 17 | 18 | 19 | size = int(sys.argv[1]) if len(sys.argv) > 1 else 0 20 | if size == 0: 21 | size = int(input('How many test-cases would you like to execute? ')) 22 | 23 | 24 | minRatio = Decimal('+inf') 25 | maxRatio = Decimal('-inf') 26 | numOfFailures = 0 27 | 28 | 29 | for n in range(size): 30 | supply = random.randrange(2, 10 ** 26) 31 | balance1 = random.randrange(1, 10 ** 23) 32 | weight1 = random.randrange(1, 1000000) 33 | balance2 = random.randrange(1, 10 ** 23) 34 | weight2 = random.randrange(1, 1000000) 35 | amount0 = random.randrange(1, supply // 10) 36 | try: 37 | ratio = formulaTest(supply, balance1, weight1, balance2, weight2, amount0) 38 | minRatio = min(minRatio, ratio) 39 | maxRatio = max(maxRatio, ratio) 40 | except Exception as error: 41 | ratio = 0 42 | numOfFailures += 1 43 | print('Test #{}: ratio = {:.24f}, minRatio = {:.24f}, maxRatio = {:.24f}, num of failures = {}'.format(n, ratio, minRatio, maxRatio, numOfFailures)) 44 | -------------------------------------------------------------------------------- /solidity/python/RunGanache.py: -------------------------------------------------------------------------------- 1 | from sys import path 2 | from subprocess import run 3 | 4 | port = 7545 5 | gasPrice = 1 6 | gasLimit = 2**53-1 7 | privKey = 1 8 | balance = 2**256-1 9 | 10 | run([ 11 | 'node', 12 | '{}/../../node_modules/ganache-cli/cli.js'.format(path[0]), 13 | '--port={}'.format(port), 14 | '--gasPrice={}'.format(gasPrice), 15 | '--gasLimit={}'.format(gasLimit), 16 | '--account={0:#0{1}x},{2}'.format(privKey,65,balance) 17 | ]) -------------------------------------------------------------------------------- /solidity/python/Utilities/Changer/Decrease.py: -------------------------------------------------------------------------------- 1 | from sys import argv 2 | from os.path import basename 3 | from decimal import Decimal 4 | from decimal import getcontext 5 | 6 | 7 | MAX_WEIGHT = 1000000 8 | 9 | 10 | def calculate(supply, balance, weight, change): 11 | assert 0 < supply and 0 < balance and 0 < weight <= MAX_WEIGHT and 0 <= change < 100 12 | weight /= MAX_WEIGHT 13 | change /= 100 14 | cur_amount = supply * (1 - (1 - change) ** (weight / (1 - weight))) 15 | new_amount = balance * (1 - (1 - cur_amount / supply) ** (1 / weight)) 16 | cur_price = balance / (supply * weight) 17 | new_price = (balance - new_amount) / ((supply - cur_amount) * weight) 18 | print('At present:') 19 | print('- supply = {:.10f}'.format(supply)) 20 | print('- balance = {:.10f}'.format(balance)) 21 | print('- price = {:.10f}'.format(cur_price)) 22 | print('If you sell an amount of {:.10f}, then:'.format(cur_amount)) 23 | print('- supply = {:.10f}'.format(supply - cur_amount)) 24 | print('- balance = {:.10f}'.format(balance - new_amount)) 25 | print('- price = {:.10f}'.format(new_price)) 26 | print('Which reflects a price decrease of {:.10f} percent'.format((cur_price - new_price) / cur_price * 100)) 27 | 28 | 29 | if len(argv) == 5: 30 | getcontext().prec = 80 31 | supply, balance, weight, change = [Decimal(arg) for arg in argv[1:]] 32 | calculate(supply, balance, weight, change) 33 | else: 34 | print('{} '.format(basename(__file__))) 35 | -------------------------------------------------------------------------------- /solidity/python/Utilities/Changer/Increase.py: -------------------------------------------------------------------------------- 1 | from sys import argv 2 | from os.path import basename 3 | from decimal import Decimal 4 | from decimal import getcontext 5 | 6 | 7 | MAX_WEIGHT = 1000000 8 | 9 | 10 | def calculate(supply, balance, weight, change): 11 | assert 0 < supply and 0 < balance and 0 < weight <= MAX_WEIGHT and 0 <= change 12 | weight /= MAX_WEIGHT 13 | change /= 100 14 | cur_amount = balance * ((1 + change) ** (1 / (1 - weight)) - 1) 15 | new_amount = supply * ((1 + cur_amount / balance) ** weight - 1) 16 | cur_price = balance / (supply * weight) 17 | new_price = (balance + cur_amount) / ((supply + new_amount) * weight) 18 | print('At present:') 19 | print('- supply = {:.10f}'.format(supply)) 20 | print('- balance = {:.10f}'.format(balance)) 21 | print('- price = {:.10f}'.format(cur_price)) 22 | print('If you buy an amount of {:.10f}, then:'.format(cur_amount)) 23 | print('- supply = {:.10f}'.format(supply + new_amount)) 24 | print('- balance = {:.10f}'.format(balance + cur_amount)) 25 | print('- price = {:.10f}'.format(new_price)) 26 | print('Which reflects a price increase of {:.10f} percent'.format((new_price - cur_price) / cur_price * 100)) 27 | 28 | 29 | if len(argv) == 5: 30 | getcontext().prec = 80 31 | supply, balance, weight, change = [Decimal(arg) for arg in argv[1:]] 32 | calculate(supply, balance, weight, change) 33 | else: 34 | print('{} '.format(basename(__file__))) 35 | -------------------------------------------------------------------------------- /solidity/python/Utilities/Converter/example_model.json: -------------------------------------------------------------------------------- 1 | { 2 | "BNT": { 3 | "ETH": { 4 | "balance": 570339152000000000000000, 5 | "weight": 100000 6 | }, 7 | "supply": 76659917077000000000000000, 8 | "fee": 10000 9 | }, 10 | "GNOBNT": { 11 | "BNT": { 12 | "balance": 94111799713052300000000, 13 | "weight": 500000 14 | }, 15 | "GNO": { 16 | "balance": 1979279044556610000000, 17 | "weight": 500000 18 | }, 19 | "supply": 206554617391782000000000, 20 | "fee": 15000 21 | }, 22 | "STX": { 23 | "BNT": { 24 | "balance": 332513533000000000000000, 25 | "weight": 20000 26 | }, 27 | "supply": 59023617240000000000000000, 28 | "fee": 20000 29 | } 30 | } -------------------------------------------------------------------------------- /solidity/python/Utilities/V2Flow/example_commands.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"operation": "newPool", "amp": 20, "fee": 1000, "factor": 10000, "mainToken": "TKN", "sideToken": "BNT", "numOfUsers": 3, "initialAmount": 1000000}, 3 | {"operation": "setRates", "mainRate": 1, "sideRate": 1}, 4 | {"operation": "addLiquidity", "token": "TKN", "user": "user1", "amount": 100000}, 5 | {"operation": "addLiquidity", "token": "BNT", "user": "user1", "amount": 100000}, 6 | {"operation": "addLiquidity", "token": "TKN", "user": "user2", "amount": 10000}, 7 | {"operation": "addLiquidity", "token": "BNT", "user": "user2", "amount": 10000}, 8 | {"operation": "convert", "updateWeights": false, "sourceToken": "TKN", "targetToken": "BNT", "user": "user3", "amount": 1000}, 9 | {"operation": "closeArbitrage", "user": "user3"}, 10 | {"operation": "remLiquidity", "token": "TKN", "user": "user2", "amount": "all"}, 11 | {"operation": "remLiquidity", "token": "BNT", "user": "user2", "amount": "all"} 12 | ] -------------------------------------------------------------------------------- /solidity/python/Web3Wrapper/__init__.py: -------------------------------------------------------------------------------- 1 | from web3 import Web3 2 | from web3 import HTTPProvider 3 | from os.path import dirname 4 | from json import loads 5 | 6 | 7 | web3 = Web3(HTTPProvider('http://127.0.0.1:7545',request_kwargs={'timeout':60})) 8 | 9 | 10 | transaction = { 11 | 'from' :web3.eth.accounts[0], 12 | 'gasPrice':web3.eth.gasPrice, 13 | 'gas' :web3.eth.getBlock('latest').gasLimit 14 | } 15 | 16 | 17 | class Contract(): 18 | def __init__(self,moduleName,args=[]): 19 | path = dirname(dirname(dirname(__file__)))+'/build/' 20 | abi = open(path+moduleName+'.abi').read() 21 | bin = open(path+moduleName+'.bin').read() 22 | self.contract = web3.eth.contract(abi=loads(abi),bytecode=bin) 23 | self.address = web3.eth.getTransactionReceipt(self.contract.deploy(transaction,args))['contractAddress'] 24 | def balance(self): 25 | return web3.eth.getBalance(self.address) 26 | def getter(self,extension={}): 27 | return self.contract(self.address).call({**transaction,**extension}) 28 | def setter(self,extension={}): 29 | return self.contract(self.address).transact({**transaction,**extension}) 30 | def tester(self,extension={}): 31 | return self.contract(self.address).estimateGas({**transaction,**extension}) 32 | def decode(hash,index,params): 33 | event = {} 34 | index1 = 1 35 | index2 = 2 36 | log = web3.eth.getTransactionReceipt(hash)['logs'][index] 37 | for param in params: 38 | if param['indexed']: 39 | event[param['name']] = int(log['topics'][index1].hex(),16) 40 | index1 += 1 41 | else: 42 | event[param['name']] = int(log['data'][index2:index2+param['size']//4],16) 43 | index2 += param['size']//4 44 | return event 45 | def jump(seconds): 46 | web3.providers[0].make_request('evm_increaseTime',[seconds]) 47 | -------------------------------------------------------------------------------- /solidity/test/BProOracle.js: -------------------------------------------------------------------------------- 1 | require("@openzeppelin/test-helpers/configure")({ 2 | provider: web3.currentProvider, 3 | singletons: { 4 | abstraction: "truffle", 5 | }, 6 | }); 7 | 8 | const { expect } = require("chai"); 9 | const { BN, time } = require("@openzeppelin/test-helpers"); 10 | 11 | const { duration, latest, increase } = time; 12 | 13 | const BProOracle = artifacts.require("BProOracle"); 14 | 15 | contract("BProOracle", () => { 16 | let bproOracle; 17 | 18 | beforeEach(async () => { 19 | bproOracle = await BProOracle.deployed(); 20 | }); 21 | 22 | it("should always return BPro USD Price for latestAnswer", async () => { 23 | const bproUSDPrice = await bproOracle.latestAnswer.call(); 24 | 25 | expect(bproUSDPrice).to.be.above(0, "The Bpro USD Price must be larger than 0"); 26 | 27 | if (bproUSDPrice > 0) { 28 | console.log("The BPro USD Price is:", bproUSDPrice); 29 | } 30 | }); 31 | 32 | it("should always return the current time for latestTimestamp", async () => { 33 | expect(await bproOracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 34 | 35 | await increase(duration.days(1)); 36 | 37 | expect(await bproOracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /solidity/test/ChainlinkBTCToUSDOracle.js: -------------------------------------------------------------------------------- 1 | const { expect } = require("chai"); 2 | const { BN, time } = require("@openzeppelin/test-helpers"); 3 | 4 | const { duration, latest, increase } = time; 5 | 6 | const ChainlinkBTCToUSDOracle = artifacts.require("ChainlinkBTCToUSDOracle"); 7 | 8 | contract("ChainlinkBTCToUSDOracle", () => { 9 | let oracle; 10 | 11 | beforeEach(async () => { 12 | oracle = await ChainlinkBTCToUSDOracle.new(); 13 | }); 14 | 15 | it("should always return 10000 for latestAnswer", async () => { 16 | expect(await oracle.latestAnswer.call()).to.be.bignumber.equal(new BN(10000)); 17 | }); 18 | 19 | it("should always return the current time for latestTimestamp", async () => { 20 | expect(await oracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 21 | 22 | await increase(duration.days(1)); 23 | 24 | expect(await oracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /solidity/test/ChainlinkETHToETHOracle.js: -------------------------------------------------------------------------------- 1 | const { expect } = require("chai"); 2 | const { BN, time } = require("@openzeppelin/test-helpers"); 3 | 4 | const { duration, latest, increase } = time; 5 | 6 | const ChainlinkETHToETHOracle = artifacts.require("ChainlinkETHToETHOracle"); 7 | 8 | contract("ChainlinkETHToETHOracle", () => { 9 | let oracle; 10 | 11 | beforeEach(async () => { 12 | oracle = await ChainlinkETHToETHOracle.new(); 13 | }); 14 | 15 | it("should always return 1 for latestAnswer", async () => { 16 | expect(await oracle.latestAnswer.call()).to.be.bignumber.equal(new BN(1)); 17 | }); 18 | 19 | it("should always return the current time for latestTimestamp", async () => { 20 | expect(await oracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 21 | 22 | await increase(duration.days(1)); 23 | 24 | expect(await oracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /solidity/test/LiquidityPoolV2ConverterStateless.js: -------------------------------------------------------------------------------- 1 | const { expect } = require("chai"); 2 | const { BN } = require("@openzeppelin/test-helpers"); 3 | 4 | const LiquidityPoolV2Converter = artifacts.require("TestLiquidityPoolV2Converter"); 5 | 6 | contract("LiquidityPoolV2ConverterStateless", (accounts) => { 7 | let converter; 8 | 9 | before(async () => { 10 | const DUMMY_ADDRESS = "0x".padEnd(42, "f"); 11 | converter = await LiquidityPoolV2Converter.new(DUMMY_ADDRESS, DUMMY_ADDRESS, 0); 12 | }); 13 | 14 | describe("dynamic-fee:", () => { 15 | const AMPLIFICATION_FACTOR = new BN(20); 16 | const stakedValues = [1234, 2345, 3456, 4567, 5678, 6789].map((x) => AMPLIFICATION_FACTOR.mul(new BN(x))); 17 | const factorValues = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0].map((x) => new BN(x * 10000)); 18 | const tknWeight = new BN(1); 19 | const bntWeight = new BN(1); 20 | const tknRate = new BN(1); 21 | const bntRate = new BN(1); 22 | 23 | for (const tknStaked of stakedValues) { 24 | for (const bntStaked of stakedValues) { 25 | for (const feeFactor of factorValues) { 26 | const x = tknStaked.mul(tknRate).mul(bntWeight); 27 | const y = bntStaked.mul(bntRate).mul(tknWeight); 28 | const expected = y.gt(x) ? y.sub(x).mul(feeFactor).mul(AMPLIFICATION_FACTOR).div(y) : new BN(0); 29 | it(`calculateFeeToEquilibrium(${[ 30 | tknStaked, 31 | bntStaked, 32 | tknWeight, 33 | bntWeight, 34 | tknRate, 35 | bntRate, 36 | feeFactor, 37 | ]}) = ${expected.toString()}`, async () => { 38 | const actual = await converter.calculateFeeToEquilibriumTest.call( 39 | tknStaked, 40 | bntStaked, 41 | tknWeight, 42 | bntWeight, 43 | tknRate, 44 | bntRate, 45 | feeFactor 46 | ); 47 | expect(actual).to.be.bignumber.equal(expected); 48 | }); 49 | } 50 | } 51 | } 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /solidity/test/MocBTCToBTCOracle.js: -------------------------------------------------------------------------------- 1 | const { expect } = require("chai"); 2 | const { BN, time } = require("@openzeppelin/test-helpers"); 3 | 4 | const { duration, latest, increase } = time; 5 | 6 | const MocBTCToBTCOracle = artifacts.require("MocBTCToBTCOracle"); 7 | 8 | contract("MocBTCToBTCOracle", () => { 9 | let oracle; 10 | 11 | beforeEach(async () => { 12 | oracle = await MocBTCToBTCOracle.new(); 13 | }); 14 | 15 | it("should always return 1 for latestAnswer", async () => { 16 | expect(await oracle.latestAnswer.call()).to.be.bignumber.equal(new BN(1)); 17 | }); 18 | 19 | it("should always return the current time for latestTimestamp", async () => { 20 | expect(await oracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 21 | 22 | await increase(duration.days(1)); 23 | 24 | expect(await oracle.latestTimestamp.call()).to.be.bignumber.equal(await latest()); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /solidity/test/ReentrancyGuard.js: -------------------------------------------------------------------------------- 1 | const { expect } = require("chai"); 2 | const { expectRevert, BN } = require("@openzeppelin/test-helpers"); 3 | 4 | const TestReentrancyGuard = artifacts.require("TestReentrancyGuard"); 5 | const TestReentrancyGuardAttacker = artifacts.require("TestReentrancyGuardAttacker"); 6 | 7 | contract("ReentrancyGuard", () => { 8 | let guard; 9 | let attacker; 10 | 11 | beforeEach(async () => { 12 | guard = await TestReentrancyGuard.new(); 13 | attacker = await TestReentrancyGuardAttacker.new(guard.address); 14 | }); 15 | 16 | context("safe caller", async () => { 17 | it("should allow calling an unprotected method", async () => { 18 | await attacker.run(); 19 | expect(await guard.calls.call()).to.be.bignumber.equal(new BN(1)); 20 | }); 21 | 22 | it("should allow calling a protected method", async () => { 23 | await attacker.setCallProtectedMethod(true); 24 | await attacker.run(); 25 | expect(await guard.calls.call()).to.be.bignumber.equal(new BN(1)); 26 | }); 27 | }); 28 | 29 | context("attacker", async () => { 30 | beforeEach(async () => { 31 | await attacker.setReentrancy(true); 32 | }); 33 | 34 | it("should allow reentering an unprotected method", async () => { 35 | await attacker.run(); 36 | expect(await guard.calls.call()).to.be.bignumber.equal(new BN(2)); 37 | }); 38 | 39 | it("should revert when attempting to reetner a protected method", async () => { 40 | await attacker.setCallProtectedMethod(true); 41 | await expectRevert(attacker.run(), "ERR_REENTRANCY"); 42 | }); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /solidity/test/helpers/Constants.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | registry: { 3 | CONTRACT_REGISTRY: web3.utils.asciiToHex("ContractRegistry"), 4 | SOVRYNSWAP_NETWORK: web3.utils.asciiToHex("SovrynSwapNetwork"), 5 | SOVRYNSWAP_FORMULA: web3.utils.asciiToHex("SovrynSwapFormula"), 6 | CONVERTER_FACTORY: web3.utils.asciiToHex("ConverterFactory"), 7 | CONVERSION_PATH_FINDER: web3.utils.asciiToHex("ConversionPathFinder"), 8 | CONVERTER_UPGRADER: web3.utils.asciiToHex("SovrynSwapConverterUpgrader"), 9 | CONVERTER_REGISTRY: web3.utils.asciiToHex("SovrynSwapConverterRegistry"), 10 | CONVERTER_REGISTRY_DATA: web3.utils.asciiToHex("SovrynSwapConverterRegistryData"), 11 | BNT_TOKEN: web3.utils.asciiToHex("BNTToken"), 12 | SOVRYNSWAP_X: web3.utils.asciiToHex("SovrynSwapX"), 13 | SOVRYNSWAP_X_UPGRADER: web3.utils.asciiToHex("SovrynSwapXUpgrader"), 14 | CHAINLINK_ORACLE_WHITELIST: web3.utils.asciiToHex("ChainlinkOracleWhitelist"), 15 | SWAP_SETTINGS: web3.utils.asciiToHex("SwapSettings") 16 | }, 17 | 18 | ETH_RESERVE_ADDRESS: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", 19 | }; 20 | -------------------------------------------------------------------------------- /solidity/test/helpers/lib.js: -------------------------------------------------------------------------------- 1 | function decodeLogs(logs, emitter, eventName) { 2 | let abi; 3 | let address; 4 | abi = emitter.abi; 5 | try { 6 | address = emitter.address; 7 | } catch (e) { 8 | address = null; 9 | } 10 | 11 | let eventABI = abi.filter((x) => x.type === "event" && x.name === eventName); 12 | if (eventABI.length === 0) { 13 | throw new Error(`No ABI entry for event '${eventName}'`); 14 | } else if (eventABI.length > 1) { 15 | throw new Error(`Multiple ABI entries for event '${eventName}', only uniquely named events are supported`); 16 | } 17 | 18 | eventABI = eventABI[0]; 19 | 20 | // The first topic will equal the hash of the event signature 21 | const eventSignature = `${eventName}(${eventABI.inputs.map((input) => input.type).join(",")})`; 22 | const eventTopic = web3.utils.sha3(eventSignature); 23 | 24 | // Only decode events of type 'EventName' 25 | return logs 26 | .filter((log) => log.topics.length > 0 && log.topics[0] === eventTopic && (!address || log.address === address)) 27 | .map((log) => web3.eth.abi.decodeLog(eventABI.inputs, log.data, log.topics.slice(1))) 28 | .map((decoded) => ({ event: eventName, args: decoded })); 29 | } 30 | 31 | module.exports = { 32 | decodeLogs 33 | } -------------------------------------------------------------------------------- /solidity/utils/addBNBs_mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 7 | }, 8 | { 9 | "symbol": "BNBs", 10 | "decimals": 18, 11 | "address": "0x6d9659bdf5b1a1da217f7bbaf7dbaf8190e2e71b" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/BNBs", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.001" 25 | }, 26 | { 27 | "symbol": "BNBs", 28 | "weight": "50%", 29 | "balance": "0.111" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 38 | }, 39 | "BNBs": { 40 | "name": "BNBs", 41 | "addr": "0x6d9659bdf5b1a1da217f7bbaf7dbaf8190e2e71b" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0xf90558859d1bBC79544Cb2Da49bA7Ce471a6343e", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addBNBs_testnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 7 | }, 8 | { 9 | "symbol": "BNBs", 10 | "decimals": 18, 11 | "address": "0x801f223def9a4e3a543eaccefb79dce981fa2fb5" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/BNBs", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.03" 25 | }, 26 | { 27 | "symbol": "BNBs", 28 | "weight": "50%", 29 | "balance": "0.291" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 38 | }, 39 | "BNBs": { 40 | "name": "BNBs", 41 | "addr": "0x801f223def9a4e3a543eaccefb79dce981fa2fb5" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0x4B2b25526c42c4D5FC096d1f77589edCB21476e2", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addBPro.json: -------------------------------------------------------------------------------- 1 | { 2 | "privateKey": "", 3 | "nodeURL": "", 4 | "reserves": [ 5 | { 6 | "symbol": "RBTC", 7 | "decimals": 18, 8 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 9 | }, 10 | { 11 | "symbol": "BPro", 12 | "decimals": 18, 13 | "address": "0x4da7997a819bb46b6758b9102234c289dd2ad3bf" 14 | } 15 | ], 16 | "converters": [ 17 | { 18 | "type": 2, 19 | "symbol": "BProRBTC", 20 | "decimals": 18, 21 | "fee": "0.1%", 22 | "reserves": [ 23 | { 24 | "symbol": "RBTC", 25 | "weight": "50%", 26 | "balance": "1", 27 | "oracle": "0x0a6858f2E0f2b42dbDD21D248da589478c507cDD" 28 | }, 29 | { 30 | "symbol": "BPro", 31 | "weight": "50%", 32 | "balance": "0.5" 33 | } 34 | ] 35 | } 36 | ], 37 | "underlyingOracleAddress": "0x0adb40132cb0ffcef6ed81c26a1881e214100555", 38 | "phase": 11, 39 | "mocPriceOracleBProRBTCBPro": { 40 | "name": "BProOracle", 41 | "addr": "0xB7b9B10E04c36C3bB8Df34163331BBB0194d1DB4", 42 | "args": "0000000000000000000000000adb40132cb0ffcef6ed81c26a1881e214100555" 43 | } 44 | } -------------------------------------------------------------------------------- /solidity/utils/addETH.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0xe9191Bf14376824a5B844A524a8D1B1ce7581eCC" 7 | }, 8 | { 9 | "symbol": "esETH", 10 | "decimals": 18, 11 | "address": "0x4F2Fc8d55c1888A5AcA2503e2F3E5d74eef37C33" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/esETH", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "esETH", 28 | "weight": "50%", 29 | "balance": "0.1167268" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0xe9191Bf14376824a5B844A524a8D1B1ce7581eCC" 38 | }, 39 | "ETH": { 40 | "name": "ERC20Token", 41 | "addr": "0x230987e3e30B5b8Df889989b35097Fc3dDC659d9", 42 | "args": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000021e19e0c9bab24000000000000000000000000000000000000000000000000000000000000000000003455448000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034554480000000000000000000000000000000000000000000000000000000000" 43 | }, 44 | "newLiquidityPoolV1Converter": { 45 | "name": "LiquidityPoolV1Converter", 46 | "addr": "0xC51D74FF100075a1E1c64A53949D57A4d6938F9E", 47 | "args": "" 48 | } 49 | } -------------------------------------------------------------------------------- /solidity/utils/addETH_mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 7 | }, 8 | { 9 | "symbol": "ETH", 10 | "decimals": 18, 11 | "address": "" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/ETH", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "ETH", 28 | "weight": "50%", 29 | "balance": "0.1167268" 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /solidity/utils/addETH_testnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 7 | }, 8 | { 9 | "symbol": "esETH", 10 | "decimals": 18, 11 | "address": "0xC855FD4aF3526215d37b39Cc33fa3C352d42e6F8" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/esETH", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "esETH", 28 | "weight": "50%", 29 | "balance": "0.1167268" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 5, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 38 | }, 39 | "esETH": { 40 | "name": "esETH", 41 | "addr": "0xC855FD4aF3526215d37b39Cc33fa3C352d42e6F8" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0xBA25e656f4fb9389c1B07d23688867E88882E010", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addETHs_mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 7 | }, 8 | { 9 | "symbol": "ETHs", 10 | "decimals": 18, 11 | "address": "0x1D931Bf8656d795E50eF6D639562C5bD8Ac2B78f" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/ETHs", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "ETHs", 28 | "weight": "50%", 29 | "balance": "0.1408206" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 5, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 38 | }, 39 | "ETHs": { 40 | "name": "ETHs", 41 | "addr": "0x1D931Bf8656d795E50eF6D639562C5bD8Ac2B78f" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0x22Fc2cee6DC31e29dcB68f1DA77718c687551a20", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addETHs_testnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 7 | }, 8 | { 9 | "symbol": "ETHs", 10 | "decimals": 18, 11 | "address": "0x0fd0D8D78CE9299eE0e5676A8D51f938c234162c" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/ETHs", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "ETHs", 28 | "weight": "50%", 29 | "balance": "0.142067" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 5, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 38 | }, 39 | "ETHs": { 40 | "name": "ETHs", 41 | "addr": "0x0fd0D8D78CE9299eE0e5676A8D51f938c234162c" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0xC8717501Bb0c6640069fcD8BF0DD13904F861abE", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addETHx_testnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 7 | }, 8 | { 9 | "symbol": "ETHx", 10 | "decimals": 18, 11 | "address": "0x04D92DaA8f3Ef7bD222195e8D1DbE8D89A8CebD3" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/ETHx", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "ETHx", 28 | "weight": "50%", 29 | "balance": "0.14338772" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 38 | }, 39 | "ETHx": { 40 | "name": "ETHx", 41 | "addr": "0x04D92DaA8f3Ef7bD222195e8D1DbE8D89A8CebD3" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0x21475506d808DaAf757092a5675cfa3804AB7239", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addMoC_mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 7 | }, 8 | { 9 | "symbol": "MoC", 10 | "decimals": 18, 11 | "address": "0x9ac7fe28967b30e3a4e6e03286d715b42b453d10" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/MoC", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "MoC", 28 | "weight": "50%", 29 | "balance": "841.333008017903566" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 38 | }, 39 | "MoC": { 40 | "name": "MoC", 41 | "addr": "0x9ac7fe28967b30e3a4e6e03286d715b42b453d10" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0x52eD2aD69A44A431B393d28CE415c19348abAb16", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addMoC_testnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 7 | }, 8 | { 9 | "symbol": "MoC", 10 | "decimals": 18, 11 | "address": "0x45a97b54021a3f99827641afe1bfae574431e6ab" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/MoC", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.00081332" 25 | }, 26 | { 27 | "symbol": "MoC", 28 | "weight": "50%", 29 | "balance": "100" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 38 | }, 39 | "MoC": { 40 | "name": "MoC", 41 | "addr": "0x45a97b54021a3f99827641afe1bfae574431e6ab" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0xc137aD4Ef759D9206b15105532c05c866cc89f31", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addSOV.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0xFD2E6034Be9Fb1F54ae380a22d6b9FFFc01442F0" 7 | }, 8 | { 9 | "symbol": "SOV", 10 | "decimals": 18 11 | } 12 | ], 13 | "converters": [ 14 | { 15 | "type": 1, 16 | "symbol": "(WR)BTC/SOV", 17 | "decimals": 18, 18 | "fee": "0.1%", 19 | "reserves": [ 20 | { 21 | "symbol": "(WR)BTC", 22 | "weight": "50%", 23 | "balance": "0.01" 24 | }, 25 | { 26 | "symbol": "SOV", 27 | "weight": "50%", 28 | "balance": "67" 29 | } 30 | ] 31 | } 32 | ], 33 | "phase": 7, 34 | "(WR)BTC": { 35 | "name": "(WR)BTC", 36 | "addr": "0xFD2E6034Be9Fb1F54ae380a22d6b9FFFc01442F0" 37 | }, 38 | "SOV": { 39 | "name": "ERC20Token", 40 | "addr": "0x4c2462b1f9507Ca72Ee578c02F43740f7d6EB1dB", 41 | "args": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000021e19e0c9bab24000000000000000000000000000000000000000000000000000000000000000000003534f5600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003534f560000000000000000000000000000000000000000000000000000000000" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0x864Cf32F95CF809C1D8E73F547C51fE11597EaDA", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addUSDT.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "RBTC", 5 | "decimals": 18, 6 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab", 7 | "oracle": "0x0a6858f2E0f2b42dbDD21D248da589478c507cDD" 8 | }, 9 | { 10 | "symbol": "USDT", 11 | "decimals": 18, 12 | "address": "0x4d5A316d23EBe168D8f887b4447BF8DBfA4901cc", 13 | "oracle": "0xf37963592635c020E0AD3313bA39C9BA627a3FB5" 14 | } 15 | ], 16 | "converters": [ 17 | { 18 | "type": 2, 19 | "symbol": "USDTRBTC", 20 | "decimals": 18, 21 | "fee": "0.1%", 22 | "reserves": [ 23 | { 24 | "symbol": "RBTC", 25 | "weight": "50%", 26 | "balance": "0.1" 27 | }, 28 | { 29 | "symbol": "USDT", 30 | "weight": "50%", 31 | "balance": "1000" 32 | } 33 | ] 34 | } 35 | ], 36 | "phase": 11, 37 | "mocPriceOracleUSDTRBTCRBTC": { 38 | "name": "MocBTCToUSDOracle", 39 | "addr": "0x1314cEBAc1b2b9b73997C0A473a0e84D8C95D910", 40 | "args": "00000000000000000000000026a00af444928d689ddec7b4d17c0e4a8c9d407d" 41 | }, 42 | "mocPriceOracleUSDTRBTCUSDT": { 43 | "name": "MocBTCToBTCOracle", 44 | "addr": "0x78F0b35Edd78eD564830c45F4A22e4b553d7f042", 45 | "args": "" 46 | } 47 | } -------------------------------------------------------------------------------- /solidity/utils/addXUSD_mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 7 | }, 8 | { 9 | "symbol": "XUSD", 10 | "decimals": 18, 11 | "address": "0xb5999795be0ebb5bab23144aa5fd6a02d080299f" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/XUSD", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.001" 25 | }, 26 | { 27 | "symbol": "XUSD", 28 | "weight": "50%", 29 | "balance": "34.9" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d" 38 | }, 39 | "XUSD": { 40 | "name": "XUSD", 41 | "addr": "0xb5999795be0ebb5bab23144aa5fd6a02d080299f" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0x303401D9AB4394AEaE4156F1A21C620eED56E22C", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addXUSD_testnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 7 | }, 8 | { 9 | "symbol": "XUSD", 10 | "decimals": 18, 11 | "address": "0x849d38abd3962cb40d4887e4279ad0e4e5958e34" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/XUSD", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.5" 25 | }, 26 | { 27 | "symbol": "XUSD", 28 | "weight": "50%", 29 | "balance": "18435" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0x69FE5cEC81D5eF92600c1A0dB1F11986AB3758Ab" 38 | }, 39 | "XUSD": { 40 | "name": "XUSD", 41 | "addr": "0x849d38abd3962cb40d4887e4279ad0e4e5958e34" 42 | }, 43 | "newLiquidityPoolV1Converter": { 44 | "name": "LiquidityPoolV1Converter", 45 | "addr": "0xD449c0c468Cae235d3E320Ff48d05EbDdcde64c3", 46 | "args": "" 47 | } 48 | } -------------------------------------------------------------------------------- /solidity/utils/addesETH.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "(WR)BTC", 5 | "decimals": 18, 6 | "address": "0xe9191Bf14376824a5B844A524a8D1B1ce7581eCC" 7 | }, 8 | { 9 | "symbol": "esETH", 10 | "decimals": 18, 11 | "address": "" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "(WR)BTC/esETH", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "(WR)BTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "esETH", 28 | "weight": "50%", 29 | "balance": "0.1167268" 30 | } 31 | ] 32 | } 33 | ], 34 | "phase": 7, 35 | "(WR)BTC": { 36 | "name": "(WR)BTC", 37 | "addr": "0xe9191Bf14376824a5B844A524a8D1B1ce7581eCC" 38 | }, 39 | "esETH": { 40 | "name": "ERC20Token", 41 | "addr": "0x4BCC0179760207C9e714165a291434515E26519B", 42 | "args": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000021e19e0c9bab24000000000000000000000000000000000000000000000000000000000000000000005657345544800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000056573455448000000000000000000000000000000000000000000000000000000" 43 | }, 44 | "newLiquidityPoolV1Converter": { 45 | "name": "LiquidityPoolV1Converter", 46 | "addr": "0xC60933bA5fDfe0Dc49E74158dbf202F575E976Ea", 47 | "args": "" 48 | } 49 | } -------------------------------------------------------------------------------- /solidity/utils/command.txt: -------------------------------------------------------------------------------- 1 | RSK testnet with custom tokens 2 | 3 | node deployment_rsk.js config_rsk.json https://public-node.testnet.rsk.co [PRIVATE KEY] 4 | 5 | 6 | RSK ganache with custom tokens (start ganache with `--gasLimit 6700000`) 7 | 8 | node deployment_rsk.js config_rsk.json http://127.0.0.1:8545 [PRIVATE KEY] 9 | 10 | Deploy converter only: 11 | testnet: 12 | node addConverter.js ETH addETHs_testnet.json data_testnet.json https://public-node.testnet.rsk.co 13 | 14 | mainnet: 15 | node addConverter.js ETH addETHs_mainnet.json data_mainnet.json https://mainnet.sovryn.app/rpc 16 | -------------------------------------------------------------------------------- /solidity/utils/config_rsk.json: -------------------------------------------------------------------------------- 1 | { 2 | "privateKey": "0x", 3 | "nodeURL": "http://127.0.0.1:8545", 4 | "reserves": [ 5 | { 6 | "symbol": "RBTC", 7 | "decimals": 18, 8 | "address": "" 9 | }, 10 | { 11 | "symbol": "SUSD", 12 | "decimals": 18, 13 | "address": "" 14 | } 15 | ], 16 | "converters": [ 17 | { 18 | "type": 1, 19 | "symbol": "sUSDrBTC", 20 | "decimals": 18, 21 | "fee": "0.1%", 22 | "reserves": [ 23 | { 24 | "symbol": "RBTC", 25 | "weight": "50%", 26 | "balance": "0.1" 27 | }, 28 | { 29 | "symbol": "SUSD", 30 | "weight": "50%", 31 | "balance": "1000" 32 | } 33 | ] 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /solidity/utils/sampleETH.json: -------------------------------------------------------------------------------- 1 | { 2 | "reserves": [ 3 | { 4 | "symbol": "WRBTC", 5 | "decimals": 18, 6 | "address": "" 7 | }, 8 | { 9 | "symbol": "ETHs", 10 | "decimals": 18, 11 | "address": "" 12 | } 13 | ], 14 | "converters": [ 15 | { 16 | "type": 1, 17 | "symbol": "WRBTC/ETHs", 18 | "decimals": 18, 19 | "fee": "0.3%", 20 | "reserves": [ 21 | { 22 | "symbol": "WRBTC", 23 | "weight": "50%", 24 | "balance": "0.01" 25 | }, 26 | { 27 | "symbol": "ETHs", 28 | "weight": "50%", 29 | "balance": "0.1167268" 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /solidity/utils/upgrade_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "privateKey": "0x", 3 | "nodeURL": "https://mainnet.sovryn.app/rpc", 4 | "type": 1, 5 | "btcAddress": "0x542fDA317318eBF1d3DEAf76E0b632741A7e677d", 6 | "k": 6779, 7 | "block": 3550895, 8 | "converterFactory": { 9 | "name": "ConverterFactory", 10 | "addr": "0xcF46f24423B8da97E2c06B41df28163D55e80935", 11 | "args": "" 12 | }, 13 | "converterUpgrader": { 14 | "name": "ConverterUpgrader", 15 | "addr": "0x40346f7Ce14B3a10bAB22F6a0A444902CF0Bc598", 16 | "args": "" 17 | }, 18 | "converterRegistry": { 19 | "name": "ConverterRegistry", 20 | "addr": "0x31A0F8400c75d52FdB413372233F28E3bdFB1c06", 21 | "args": "" 22 | }, 23 | "multiSigWallet": { 24 | "name": "MultiSigWallet", 25 | "addr": "0x924f5ad34698Fd20c90Fe5D5A8A0abd3b42dc711", 26 | "args": "" 27 | }, 28 | "converterContract": { 29 | "name": "LiquidityPoolV1Converter", 30 | "addr": [ 31 | "0x9996E5F902d2d804E9eD0DdB1B628D1EBf6Bb6fE" 32 | ], 33 | "args": "" 34 | }, 35 | "liquidityPoolV1ConverterFactory": { 36 | "name": "LiquidityPoolV1ConverterFactory", 37 | "addr": "0x1E7428B34Af8FA6Dc40d7A38769efA948E065669", 38 | "args": "" 39 | }, 40 | "Oracle0": { 41 | "name": "Oracle", 42 | "addr": "0x345f2eC520431db542e33eD31a8f687E8eC705BB", 43 | "args": "00000000000000000000000034031d1cd14e2c80b0268b47eff49643375afaeb000000000000000000000000542fda317318ebf1d3deaf76e0b632741a7e677d" 44 | } 45 | } -------------------------------------------------------------------------------- /solidoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "pathToRoot": "solidity", 3 | "outputPath": "docs", 4 | "buildFolder": "build/contracts", 5 | "noCompilation": true, 6 | "compiler": "truffle compile", 7 | "language": "en", 8 | "ignoreFiles": ["**/*test*.json", "**/*[T|t]est*.json", "**/*[M|m]ock*.json"], 9 | "readme": "docs" 10 | } 11 | -------------------------------------------------------------------------------- /truffle-config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/no-extraneous-dependencies */ 2 | require('chai') 3 | .use(require('chai-as-promised')) 4 | .use(require('chai-bn')(require('bn.js'))) 5 | .use(require('chai-string')) 6 | .use(require('dirty-chai')) 7 | .expect(); 8 | 9 | const Decimal = require('decimal.js'); 10 | Decimal.set({ precision: 100, rounding: Decimal.ROUND_DOWN, toExpPos: 40 }); 11 | 12 | const ganache = require('ganache-core'); 13 | /* eslint-enable import/no-extraneous-dependencies */ 14 | 15 | module.exports = { 16 | contracts_directory: './solidity', 17 | contracts_build_directory: './solidity/build/contracts', 18 | test_directory: './solidity/test', 19 | networks: { 20 | development: { 21 | host: 'localhost', 22 | port: 7545, 23 | network_id: '*', 24 | gasPrice: 20000000000, 25 | gas: 9500000, 26 | provider: ganache.provider({ 27 | gasLimit: 9500000, 28 | gasPrice: 20000000000, 29 | default_balance_ether: 10000000000000000000 30 | }) 31 | }, 32 | production: { 33 | host: 'localhost', 34 | port: 7545, 35 | network_id: '*', 36 | gasPrice: 20000000000, 37 | gas: 9500000 38 | } 39 | }, 40 | plugins: ['solidity-coverage'], 41 | compilers: { 42 | solc: { 43 | version: '0.4.26', 44 | settings: { 45 | optimizer: { 46 | enabled: true, 47 | runs: 200 48 | } 49 | } 50 | } 51 | }, 52 | mocha: { 53 | before_timeout: 600000, 54 | timeout: 600000, 55 | useColors: true, 56 | reporter: 'list' 57 | } 58 | }; 59 | --------------------------------------------------------------------------------