<jupyter_start><jupyter_text>PHASE 1 In Phase 1 , We deploy:    Router contract,    Fee handler contract and    Governance Contract (update)  DEPLOY ROUTER CONTRACT<jupyter_code># We need to set all the staking sicx and dex address on router on_install 
res = get_tx_result(deploy_contract(deployer_wallet.get_address(), GOVERNANCE_ADDRESS, './core_contracts/router',
                                   {"_governance": GOVERNANCE_SCORE}))
print('scoreAddress:', res.get('scoreAddress', ''))
router_score = res.get('scoreAddress', '')
check_tx_result(res)<jupyter_output>Retrying in 1 seconds...
Retrying in 2 seconds...
scoreAddress: cx2774afbaaf39fa395024fdb8d2a10dd9823c8490
Success<jupyter_text>UPDATE GOVERNANCE CONTRACT<jupyter_code>tx = get_tx_result(
    deploy_contract(deployer_wallet.get_address(), GOVERNANCE_SCORE, './core_contracts/governance', {}))
print('scoreAddress:', tx.get('scoreAddress', ''))
check_tx_result(tx)

# In this readonly-call , the feehandler and router score should show None.
print(call_tx(GOVERNANCE_SCORE, 'getAddresses', {}))<jupyter_output>Retrying in 1 seconds...
scoreAddress: cx06eaddea58321a98bd0e1c9bd70f4680d4f3a73a
Success
{'baln': 'cx44b142082a0612f60a5cff9e4204773b4799b102', 'bnUSD': 'cx50b5bc7d1088848ff106601d6a194aa16e6f9d83', 'bwt': 'cx655079c90d80b378819eddf3b05501392ecb0074', 'daofund': 'cx38e81d7b705784b2ddb586f0fdd3616e565b18b3', 'dex': 'cx113466143604608cbf58d84674d9360b29f08530', 'dividends': 'cxaab78dec61aded71309e9529feaf25e740526c63', 'feehandler': 'cx941a4bcca5c25d249e4ea7bef05edce854eabe40', 'loans': 'cx2148bdb92054b2306076f3579c0ab7fced91a9ca', 'oracle': 'cx0999df3af49a227fc8799f0d78d19cd8fe4bb76d', 'rebalancing': 'cxc2d1b9bbdfa51cf404c47e229c71773954acc453', 'reserve': 'cx513777210d38e8c3ba4a5f6ecd313f7bda86c4f2', 'rewards': 'cx4fb4db59d14adc6b9f6ed3d31f1154415bbe4e7e', 'router': 'cx7e58ab69fd019eaf56fd072d00f1634b64f80d13', 'sicx': 'cx0508faa2f6b1f333fa84190db7c80c9dbf822cb4', 'staking': 'cx6b88083a463739c94f1aa76341df1a21bddca2be'}<jupyter_text>DEPLOY FEE HANDLER<jupyter_code>res = get_tx_result(deploy_contract(deployer_wallet.get_address(), GOVERNANCE_ADDRESS, './core_contracts/fees',
                                   {"_governance": GOVERNANCE_SCORE}))
print('scoreAddress:', res.get('scoreAddress', ''))
FEEHANDLER_SCORE = res.get('scoreAddress', '')
check_tx_result(res)<jupyter_output>Retrying in 1 seconds...
Retrying in 2 seconds...
scoreAddress: cx4131b1b29bd66f162a4d7537fdc20f6aa3ae9782
Success<jupyter_text>PHASE 2 (Once the contract is accepted) We set the fee handler and router addresses in governance contract and also sets all the function of fee handler.  SET ROUTER ADDRESS AND FEEHANDLER ADDRESS IN GOVERNANCE<jupyter_code>contract_addresses['router'] = router_score
contract_addresses['feehandler'] = FEEHANDLER_SCORE
res = send_tx(deployer_wallet, GOVERNANCE_SCORE, "setAddresses", {"_addresses": contract_addresses}, 0)
check_tx_result(res)

# the read-only fn should return the fee handler and router address instead of None.
print(call_tx(GOVERNANCE_SCORE, 'getAddresses', {}))<jupyter_output>Retrying in 1 seconds...
Success
{'baln': 'cx44b142082a0612f60a5cff9e4204773b4799b102', 'bnUSD': 'cx50b5bc7d1088848ff106601d6a194aa16e6f9d83', 'bwt': 'cx655079c90d80b378819eddf3b05501392ecb0074', 'daofund': 'cx38e81d7b705784b2ddb586f0fdd3616e565b18b3', 'dex': 'cx113466143604608cbf58d84674d9360b29f08530', 'dividends': 'cxaab78dec61aded71309e9529feaf25e740526c63', 'feehandler': 'cx4131b1b29bd66f162a4d7537fdc20f6aa3ae9782', 'loans': 'cx2148bdb92054b2306076f3579c0ab7fced91a9ca', 'oracle': 'cx0999df3af49a227fc8799f0d78d19cd8fe4bb76d', 'rebalancing': 'cxc2d1b9bbdfa51cf404c47e229c71773954acc453', 'reserve': 'cx513777210d38e8c3ba4a5f6ecd313f7bda86c4f2', 'rewards': 'cx4fb4db59d14adc6b9f6ed3d31f1154415bbe4e7e', 'router': 'cx2774afbaaf39fa395024fdb8d2a10dd9823c8490', 'sicx': 'cx0508faa2f6b1f333fa84190db7c80c9dbf822cb4', 'staking': 'cx6b88083a463739c94f1aa76341df1a21bddca2be'}<jupyter_text>SET ACCEPTED DIVIDENDS TOKEN<jupyter_code># call the tx through Governance SCORE.

res2 = send_tx(deployer_wallet, GOVERNANCE_SCORE, "setAcceptedDividendTokens", {'_tokens': [contract_addresses['sicx'],
            contract_addresses['bnUSD'],
            contract_addresses["baln"]]}, 0)
check_tx_result(res2)
call_tx(FEEHANDLER_SCORE, 'getAcceptedDividendTokens', {})<jupyter_output>Retrying in 1 seconds...
Retrying in 2 seconds...
Success<jupyter_text>SET FEE PROCESSING INTERVAL<jupyter_code>res = send_tx(deployer_wallet, GOVERNANCE_SCORE, "setFeeProcessingInterval", {"_interval": 100}, 0)
check_tx_result(res)
call_tx(FEEHANDLER_SCORE, 'getFeeProcessingInterval', {})<jupyter_output>Retrying in 1 seconds...
Retrying in 2 seconds...
Success<jupyter_text>SET ROUTE<jupyter_code>toToken = contract_addresses['baln']     
#sejong_address
omm_score = "cx683c78174c740c3c6215de0c3ead1fad024324d6"
usds_score ="cx2e008873de78f5bf82008a46b529d94924d9b6ae" 
iusdc_score = "cxb2c075e9130440dd64e6bfd3fe09e5c629f6e183"

#mainnet address
# usdc_score = "cxbb2871f468a3008f80b08fdde5b8b951583acf06"
# iusdc_score = "cxae3034235540b924dfcc1b45836c293dcc82bfb7"
# omm_score = "cx1a29259a59f463a67bb2ef84398b30ca56b5830a"
# craft_score = "cx2e6d0fc0eca04965d06038c8406093337f085fcf"
# metanyx_score = "cx369a5f4ce4f4648dfc96ba0c8229be0693b4eca2"
# iusdt_score = "cx3a36ea1f6b9aa3d2dd9cb68e8987bcc3aabaaa88"

# FOR OMM
fromToken = omm_score
path = [ contract_addresses['sicx'],
        contract_addresses['baln']
        ]
res = send_tx(deployer_wallet, GOVERNANCE_SCORE, "setRoute",  {'_fromToken':fromToken, '_toToken':toToken, '_path': path}, 0)
check_tx_result(res)
print(call_tx(FEEHANDLER_SCORE, 'getRoute', {"_fromToken":fromToken,"_toToken":contract_addresses['baln']}))

# FOR usds
# fromToken = usds_score
# path = [ contract_addresses['bnUSD'],
#         contract_addresses['baln']
#         ]
# res = send_tx(deployer_wallet, GOVERNANCE_SCORE, "setRoute",  {'_fromToken':fromToken, '_toToken':toToken, '_path': path}, 0)
# check_tx_result(res)
# print(call_tx(FEEHANDLER_SCORE, 'getRoute', {"_fromToken":fromToken,"_toToken":contract_addresses['baln']}))

# FOR iusdc
# fromToken = iusdc_score
# path = [ contract_addresses['bnUSD'],
#         contract_addresses['baln']
#         ]
# res = send_tx(deployer_wallet, GOVERNANCE_SCORE, "setRoute",  {'_fromToken':fromToken, '_toToken':toToken, '_path': path}, 0)
# check_tx_result(res)
# print(call_tx(FEEHANDLER_SCORE, 'getRoute', {"_fromToken":fromToken,"_toToken":contract_addresses['baln']}))

# FOR craft
# fromToken = craft_score
# path = [ data['sicx'],
#         data['baln']
#         ]
# send_tx(deployer_wallet, FEEHANDLER_SCORE, "setRoute",  {'_fromToken':fromToken, '_toToken':toToken, '_path': path}, 0)

# FOR metanyx
# fromToken = metanyx_score
# path = [ data['bnUSD'],
#         data['baln']
#         ]
# send_tx(deployer_wallet, FEEHANDLER_SCORE, "setRoute",  {'_fromToken':fromToken, '_toToken':toToken, '_path': path}, 0)

# FOR iusdt
# fromToken = iusdt_score
# path = [ data['bnUSD'],
#         data['baln']
#         ]
# send_tx(deployer_wallet, FEEHANDLER_SCORE, "setRoute",  {'_fromToken':fromToken, '_toToken':toToken, '_path': path}, 0)<jupyter_output>Retrying in 1 seconds...
Retrying in 2 seconds...
Success
{'fromToken': 'cx683c78174c740c3c6215de0c3ead1fad024324d6', 'path': ['<KEY>', '<KEY>'], 'toToken': '<KEY>'}<jupyter_text>UPDATE DEX CONTRACT<jupyter_code># We need to set fee handler address on on_update.
tx = get_tx_result(
    deploy_contract(deployer_wallet.get_address(), DEX_SCORE, './core_contracts/dex', {}))
print('scoreAddress:', tx.get('scoreAddress', ''))
check_tx_result(tx)<jupyter_output>Retrying in 1 seconds...
Retrying in 2 seconds...
scoreAddress: cx113466143604608cbf58d84674d9360b29f08530
Success<jupyter_text>UPDATE LOANS CONTRACT<jupyter_code>tx = get_tx_result(
    deploy_contract(deployer_wallet.get_address(), LOANS_SCORE, './core_contracts/loans', {}))
print('scoreAddress:', tx.get('scoreAddress', ''))
check_tx_result(tx)

print("Taking loans")
res = send_tx(deployer_wallet, contract_addresses['loans'], "depositAndBorrow", {'_asset': 'bnUSD', '_amount': 100 * 10 **18}, 500 * 10 **18)
check_tx_result(res)

#Swapping bnUSD to sICX
res = swap(contract_addresses['bnUSD'], contract_addresses['sicx'],5*10**18,deployer_wallet)
check_tx_result(res)<jupyter_output>Taking loans
cx2148bdb92054b2306076f3579c0ab7fced91a9ca
cx50b5bc7d1088848ff106601d6a194aa16e6f9d83
cx0508faa2f6b1f333fa84190db7c80c9dbf822cb4
Retrying in 1 seconds...
Retrying in 2 seconds...
Retrying in 4 seconds...
Retrying in 8 seconds...
Retrying in 16 seconds...
Retrying in 32 seconds...
{'fraction_non_alphanumeric': 0.12260668973471742, 'fraction_numerical': 0.14336793540945791, 'mean_word_length': 8.08909853249476, 'pattern_counts': {'":': 10, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '298897', 'license': 'MIT', 'n_tokens_mistral': 4218, 'n_tokens_neox': 3615, 'n_words': 515, 'path': 'Balanced Upgrade.ipynb', 'repo_name': 'AntonAndell/balanced-contracts', 'size': '8781'}