예제 #1
0
    def handle(self):
        commit = Commit()

        commit.opcode = "created_debt_engine"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        debt = debt_engine_interface.get_debt_by_id(self._id)

        error = False
        balance = 0

        model = debt.get("model")
        creator = debt.get("creator")
        oracle = debt.get("oracle")

        created = str(self._block_timestamp())

        data = {
            "error": error,
            "balance": str(balance),
            "model": model,
            "creator": creator,
            "oracle": oracle,
            "created": created,
            "id": self._args.get("_id")
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #2
0
    def handle(self):
        commit = Commit()

        commit.opcode = "closed_auction"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        collateral_id = str(self._args.get("_entryId"))
        collateral = Collateral.objects.get(id=collateral_id)
        print(collateral.debt_id)
        loan = Loan.objects.get(id=collateral.debt_id)
        if loan.status == "2":
            status = str(CollateralState.TO_WITHDRAW.value)
        else:
            status = str(CollateralState.STARTED.value)

        data = {
            "id": collateral_id,
            "received": str(self._args.get("_received")),
            "leftover": str(self._args.get("_leftover")),
            "status": status
        }

        commit.data = data

        return [commit]
예제 #3
0
    def handle(self):
        commit = Commit()

        commit.opcode = "requested_loan_manager"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        oracle = self._args.get("_oracle")
        try:
            if oracle != "0x0000000000000000000000000000000000000000":
                oracle_contract = OracleInterface(oracle)
                currency = oracle_contract.currency()
            else:
                currency = loan_manager_interface.get_currency(
                    self._args.get('_id'))
                if currency:
                    currency = utils.add_0x_prefix(currency)
        except BadFunctionCallOutput:
            currency = "0x"

        print("currency: {}".format(currency))

        data = {
            "id": self._args.get("_id"),
            "open": True,
            "approved":
            self._args.get("_creator") == self._args.get("_borrower"),
            "position": "0",
            "expiration": str(self._args.get("_expiration")),
            "amount": str(self._args.get("_amount")),
            "cosigner": "0x0000000000000000000000000000000000000000",
            "model": self._args.get("_model"),
            "creator": self._args.get("_creator"),
            "oracle": self._args.get("_oracle"),
            "borrower": self._args.get("_borrower"),
            "callback": self._args.get("_callback"),
            "salt": str(self._args.get("_salt")),
            "loanData": self._args.get("_loanData"),
            "created": str(self._block_timestamp()),
            "currency": currency,
            "status": "0"
        }

        descriptor = loan_manager_interface.get_descriptor(data)

        data["descriptor"] = descriptor

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #4
0
    def handle(self):
        commit = Commit()

        config_data = installments_model_interface.get_config_by_id(self._args.get("_id"))

        commit.opcode = "created_installments"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")
        commit.data = config_data
        commit.id_loan = self._args.get("_id")

        return [commit]
예제 #5
0
    def handle(self):
        commit = Commit()

        commit.opcode = "approved_loan_manager"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {"id": self._args.get("_id"), "approved": True}

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #6
0
    def handle(self):
        commit = Commit()

        commit.opcode = "error_recover_debt_engine"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {"id": self._args.get("_id"), "error": False}

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #7
0
    def handle(self):
        commit = Commit()

        commit.opcode = "redeemed_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": str(self._args.get("_entryId")),
            "to": str(self._args.get("_to")),
        }

        commit.data = data

        return [commit]
예제 #8
0
    def handle(self):
        commit = Commit()

        commit.opcode = "started_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": str(self._args.get("_entryId")),
            "status": str(CollateralState.STARTED.value)
        }

        commit.data = data

        return [commit]
예제 #9
0
    def handle(self):
        commit = Commit()

        commit.opcode = "provide_oracleFactory"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "oracle": self._args.get("_oracle"),
            "signer": self._args.get("_signer"),
            "rate": str(self._args.get("_rate"))
        }

        commit.data = data

        return [commit]
예제 #10
0
    def handle(self):
        commit = Commit()

        commit.opcode = "pay_batch_error_debt_engine"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": self._args.get("_id"),
            "oracle": self._args.get("_oracle")
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #11
0
    def handle(self):
        commit = Commit()

        commit.opcode = "ownership_transferred_debt_engine"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "previous_owner": self._args.get("_previousOwner"),
            "new_owner": self._args.get("_newOwner"),
        }

        commit.data = data

        # return [commit]
        return []
예제 #12
0
    def handle(self):
        commit = Commit()

        commit.opcode = "set_paid_base_installments"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": self._args.get("_id"),
            "paid_base": str(self._args.get("_paidBase"))
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #13
0
    def handle(self):
        commit = Commit()

        commit.opcode = "paid_ERC20D"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._address

        data = {
            "from": self._args.get("_from"),
            "value": self._args.get("_value"),
            "contractAddress": self._address
        }

        commit.data = data

        return [commit]
예제 #14
0
    def handle(self):
        commit = Commit()

        commit.opcode = "transfer_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "from": self._args.get("_from"),
            "to": self._args.get("_to"),
            "tokenId": str(self._args.get("_tokenId"))
        }

        commit.data = data

        return [commit]
예제 #15
0
    def handle(self):
        commit = Commit()

        commit.opcode = "borrow_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": str(self._args.get("_entryId")),
            "handler": self._args.get("_handler"),
            "newAmount": str(self._args.get("_newAmount")),
            "status": str(CollateralState.TO_WITHDRAW.value)
        }

        commit.data = data

        return [commit]
예제 #16
0
    def handle(self):
        commit = Commit()

        commit.opcode = "settled_lend_loan_manager"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": self._args.get("_id"),
            "lender": self._args.get("_lender"),
            "tokens": self._args.get("_tokens")
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #17
0
    def handle(self):
        commit = Commit()

        commit.opcode = "claimed_expired_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": str(self._args.get("_entryId")),
            "auctionId": str(self._args.get("_auctionId")),
            "obligation": str(self._args.get("_obligation")),
            "obligationToken": str(self._args.get("_obligationToken")),
            "status": str(CollateralState.IN_AUCTION.value)
        }

        commit.data = data

        return [commit]
예제 #18
0
    def handle(self):
        commit = Commit()

        commit.opcode = "withdrawn_debt_engine"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": self._args.get("_id"),
            "sender": self._args.get("_sender"),
            "to": self._args.get("_to"),
            "amount": str(self._args.get("_amount"))
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #19
0
    def handle(self):
        commit = Commit()

        commit.opcode = "claimed_liquidation_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": str(self._args.get("_entryId")),
            "auctionId": str(self._args.get("_auctionId")),
            "debt": str(self._args.get("_debt")),
            "required": str(self._args.get("_required")),
            "marketValue": str(self._args.get("_marketValue")),
            "status": str(CollateralState.IN_AUCTION.value)
        }

        commit.data = data

        return [commit]
예제 #20
0
    def handle(self):
        commit = Commit()

        commit.opcode = "added_paid_installments"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        state = State.objects.get(id=self._args.get("_id"))

        data = {
            "id": self._args.get("_id"),
            "real": str(self._args.get("_paid")),
            "paid": str(int(state.paid) + self._args.get("_paid")),
            "state_last_payment": state.clock,
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #21
0
    def handle(self):
        commit = Commit()

        commit.opcode = "deposited_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        id = str(self._args.get("_entryId"))
        amount = str(self._args.get("_amount"))
        collateral = Collateral.objects.get(id=id)
        if collateral.status == CollateralState.FINISH.value and amount != '0':
            status = str(CollateralState.TO_WITHDRAW.value)
        else:
            status = str(collateral.status)

        data = {"id": id, "amount": amount, "status": status}

        commit.data = data

        return [commit]
예제 #22
0
    def handle(self):
        if self._args.get("_from") != "0x0000000000000000000000000000000000000000":

            commit = Commit()

            commit.opcode = "transfer_debt_engine"
            commit.timestamp = self._block_timestamp()
            commit.proof = self._transaction
            commit.address = self._tx.get("from")

            data = {
                "id": self._args.get("_tokenId"),
                "from": self._args.get("_from"),
                "to": self._args.get("_to")
            }

            commit.id_loan = self._args.get("_tokenId")
            commit.data = data

            return [commit]
        else:
            return []
예제 #23
0
    def handle(self):
        commit = Commit()

        commit.opcode = "paid_debt_engine"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": self._args.get("_id"),
            "sender": self._args.get("_sender"),
            "origin": self._args.get("_origin"),
            "requested": str(self._args.get("_requested")),
            "requested_tokens": str(self._args.get("_requestedTokens")),
            "paid": str(self._args.get("_paid")),
            "tokens": str(self._args.get("_tokens"))
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data

        return [commit]
예제 #24
0
    def handle(self):
        commits = []

        commit = Commit()

        commit.opcode = "changed_status_installments"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.address = self._tx.get("from")

        data = {
            "id": self._args.get("_id"),
            "timestamp": str(self._args.get("_timestamp")),
            "status": str(self._args.get("_status"))
        }

        commit.id_loan = self._args.get("_id")
        commit.data = data
        commits.append(commit)

        # commit full payment loan manager
        commit_full_payment = Commit()
        commit_full_payment.opcode = "full_payment_loan_manager"
        commit_full_payment.timestamp = commit.timestamp
        commit_full_payment.proof = self._transaction
        commit_full_payment.proof = self._tx.get("from")

        data = {
            "id": self._args.get("_id"),
            "status": str(self._args.get("_status"))
        }

        commit_full_payment.id_loan = self._args.get("_id")
        commit_full_payment.data = data

        commits.append(commit_full_payment)

        return commits
예제 #25
0
    def handle(self):
        commit = Commit()

        commit.opcode = "created_collateral"
        commit.timestamp = self._block_timestamp()
        commit.proof = self._transaction
        commit.id_loan = self._args.get("_debtId")
        commit.address = self._tx.get("from")

        data = {
            "id": str(self._args.get("_entryId")),
            "debt_id": self._args.get("_debtId"),
            "oracle": self._args.get("_oracle"),
            "token": self._args.get("_token"),
            "liquidation_ratio": str(self._args.get("_liquidationRatio")),
            "balance_ratio": str(self._args.get("_balanceRatio")),
            "amount": str(self._args.get("_amount")),
            "status": str(CollateralState.CREATED.value)
        }

        commit.data = data

        return [commit]