Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events from contract calls back unhelpfully orgainsed #355

Open
4 tasks done
dishmop opened this issue May 18, 2023 · 0 comments
Open
4 tasks done

events from contract calls back unhelpfully orgainsed #355

dishmop opened this issue May 18, 2023 · 0 comments

Comments

@dishmop
Copy link

dishmop commented May 18, 2023

Prerequisites

Expected Behavior

When i make a contract call e.g.:
tx1 = cc.secured_asset.execute({"secure_asset": {}}, acc_admin)

and then view the events in the response:
tx1.response.events["wasm"]

I expect the results to be accessible in a list form as they are in cosmjs (though the current dictionary form is useful when making simple calls - so should not be removed)

Current Behavior

The result comes back as a dictionary of key value pairs. This is unhelpful when the contract call has made other contract calls as all the results come back munged into the same dictionary. this means:
A - You don't know which keyvalue pairs have come from which contracts
B - If two pairs have the same key then one overwrites the other.

To Reproduce

Get and build this project:
https://github.com/fetchai/atomix_contracts/tree/develop

start up a jenesis shell like this;
DT_MODE=stepped jenesis shell --profile local

Paste in this:

from atomix_contracts import *
import pprint
import time
import math
import json
import datetime

print("\nTEST_FUNCTION: def test_proxy_user(local_node, ledger, profile):\n")
# Deploy contracts, create user accounts
admin_mnemonic = "atmx141"
user_mnemonic = "user01"
cc = deployment.deploy(admin_mnemonic, ledger, profile)
(acc_trustee, acc_borrower, acc_liquidity_provider) = deployment.fund_demo_accounts(
    admin_mnemonic, user_mnemonic, cc
)
acc_borrower_to = dev_accounts.wallet_from_seed(user_mnemonic, 3)
acc_liquidity_provider_to = dev_accounts.wallet_from_seed("user01", 4)
acc_admin = dev_accounts.wallet_from_seed(admin_mnemonic)

cc.pathway_registry.execute(
    {"grant_role": {"address": acc_trustee, "role": "agent"}}, acc_admin
).wait_to_complete()

cc.proxy_user.execute(
    {"grant_role": {"address": acc_trustee, "role": "agent"}}, acc_admin
).wait_to_complete()

cc.proxy_user.execute(
    {"grant_role": {"address": acc_borrower, "role": "borrower"}}, acc_trustee
).wait_to_complete()

cc.proxy_user.execute(
    {"grant_role": {"address": acc_liquidity_provider, "role": "investor"}},
    acc_trustee,
).wait_to_complete()

# Loan parameters
collateral_value = 150000 * cc.one_unit
borrow_amount = 55000 * cc.one_unit
valuation_duration = 1 * cc.secs_per_year
loan_duration = 1 * cc.secs_per_year
guaranteed_recovery_ratio = 0.7 * cc.one_unit
max_recovery_time = 1 * cc.secs_per_year
max_discounted_apr = 0.12 * cc.one_unit
standard_apr = 0.15 * cc.one_unit

# Investment parameters
investment_amount = 75000 * cc.one_unit
investment_duration = 1 * cc.secs_per_year
min_apr = 0.05 * cc.one_unit

print("Set up payment pathway for liquidity providers")
txl = cc.pathway_registry.execute(
    {
        "add_pathway": {
            "pathway": {
                "control_address": str(acc_liquidity_provider.address()),
                "to_address": str(acc_liquidity_provider_to.address()),
                "meta_data": "Empty",
            }
        }
    },
    acc_trustee,
).wait_to_complete()
liquidity_provider_pathway_id = txl.response.logs[0].events["wasm"]["id"]

print("Approve the proxy user to transfer from liquidity provider")
txl = cc.agbp.execute(
    {
        "increase_allowance": {
            "spender": str(cc.proxy_user.address),
            "amount": cc.num_to_str(investment_amount),
        }
    },
    acc_liquidity_provider,
).wait_to_complete()

print("Proxy user invest in savings account")
txl = cc.proxy_user.execute(
    {
        "savings_invest": {
            "pathway_id": liquidity_provider_pathway_id,
            "investment": {
                "capped_rate_investment": {
                    "initial_deposit": cc.num_to_str(investment_amount),
                    "min_apr": cc.num_to_str(min_apr),
                    "duration": cc.num_to_str(investment_duration),
                },
            },
        },
    },
    acc_liquidity_provider,
).wait_to_complete()

pprint.pprint(txl.response.logs[0].events["wasm"])

print("Investment details")
investment_id = txl.response.logs[0].events["wasm"]["id"]
investment_value = (
    int(
        cc.savings_account.query(
            {"investment_details": {"investment_id": investment_id}}
        )["dynamic_details"]["value"]
    )
    / cc.one_unit
)
print("Total investment value: {}".format(investment_value))

print("Set up payment pathway for borrower")
borrower_meta_data = {
    "fiat_account_details": {
        "Ref": "Dummy ref 432",
    }
}

txb = cc.pathway_registry.execute(
    {
        "add_pathway": {
            "pathway": {
                "control_address": str(acc_borrower.address()),
                "to_address": str(acc_borrower_to.address()),
                "meta_data": json.dumps(borrower_meta_data),
            }
        }
    },
    acc_trustee,
).wait_to_complete()
borrower_pathway_id = txb.response.logs[0].events["wasm"]["id"]

print("Borrower mints ACT and borrows")
# suppose we have 20 document hashes to upload
doc_hashes = []
for i in range(20):
    doc_hashes.append(["hash_{}".format(i), "meta_{}".format(i)])

txb = cc.proxy_user.execute(
    {
        "loan_mint_act_and_borrow": {
            "pathway_id": borrower_pathway_id,
            "asset": {
                "secured_asset": {
                    "create": {
                        "initial_details": {
                            "description": "test asset01",
                            "borrower": str(acc_borrower.address()),
                            "denomination": "GBP",
                            "value": cc.num_to_str(collateral_value),
                            "valuation_duration": cc.num_to_str(valuation_duration),
                        },
                        "recovery_details": {
                            "guaranteed_recovery_ratio": cc.num_to_str(
                                guaranteed_recovery_ratio
                            ),
                            "max_recovery_time": cc.num_to_str(max_recovery_time),
                            "fixed_recovery_costs": "0",
                        },
                        "loan_mod_details": {
                            "max_rate_bias_inc": "0",
                            "max_rate_bias_dec": "0",
                            "fixed_fee": "0",
                        },
                    },
                },
            },
            "doc_hashes": doc_hashes,
            "loan": {
                "capped_rate_loan": {
                    "initial_drawdown": cc.num_to_str(borrow_amount),
                    "max_discounted_apr": cc.num_to_str(max_discounted_apr),
                    "standard_apr": cc.num_to_str(standard_apr),
                    "duration": cc.num_to_str(loan_duration),
                }
            },
        }
    },
    acc_borrower,
).wait_to_complete()

pprint.pprint(txb.response.events["wasm"])

See how the events pairs are printed out - the proxy user contract makes lots of calls to other contracts and it is all mungd together

Context

Max OS

Failure Logs

No response

@dishmop dishmop changed the title events from contract calls back unhelpfully events from contract calls back unhelpfully orgainsed May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant