๐Ÿ“”Contracts

Using Brownie you can interact with the Ooki contracts. Below is an explanation for using each function. See our github for additional references: https://github.com/bZxNetwork/contractsV2

OOKI Token Contract

0x0De05F6447ab4D22c8827449EE4bA2D5C288379B

cOOKI/vBZRX Contract

0xb72b31907c1c95f3650b64b2469e08edacee5e8f

MintCoordinator

0x93c608Dc45FcDd9e7c5457ce6fc7f4dDec235b68

IToken Contract

Router Contract

Functions

Load protocol

  • BZX = Contract.from_abi("BZX", "0xfe4F0eb0A1Ad109185c9AaDE64C48ff8e928e54B", interface.IBZx.abi)

Load iTokens

  • iUSDTAddress = BZX.underlyingToLoanPool(USDT.address)

  • iUSDT = Contract.from_abi("iUSDT", address=iUSDTAddress, abi=LoanTokenLogicStandard.abi)

Approve

  • WMATIC.approve(iUSDT, 2256-1, {'from': accounts[0]})

  • USDT.approve(BZX, 2256-1, {'from': accounts[0]})

  • WMATIC.approve(BZX, 2**256-1, {'from': accounts[0]})

Open Long 5x MATIC/USDT (using matic as collateral)

iUSDT.marginTrade('0x0000000000000000000000000000000000000000000000000000000000000000', 5e18, 0, 10e18, '0x0000000000000000000000000000000000000000', accounts[0], b'', {'from': accounts[0], "value": 10e18}) 
loan =BZX.getLoan(history[-1].return_value[0]) 
Loan has structure

struct Loan {
   bytes32 id;                 // id of the loan
   bytes32 loanParamsId;       // the linked loan params id
   bytes32 pendingTradesId;    // the linked pending trades id
   uint256 principal;          // total borrowed amount outstanding
   uint256 collateral;         // total collateral escrowed for the loan
   uint256 startTimestamp;     // loan start time
   uint256 endTimestamp;       // for active loans, this is the expected loan end time, for in-active loans, is the actual (past) end time
   uint256 startMargin;        // initial margin when the loan opened
   uint256 startRate;          // reference rate when the loan opened for converting collateralToken to loanToken
   address borrower;           // borrower of this loan
   address lender;             // lender of this loan
   bool active;                // if false, the loan has been fully closed
}

Deposit collateral

  • BZX.depositCollateral(loan[0], 10e18, {'from': accounts[0]})

Close loan with swap

  • BZX.closeWithSwap(loan[0], accounts[0], loan[5], True, b'', {'from': accounts[0]})

Close loan with deposit

  • BZX.closeWithDeposit(loan[0], accounts[0], loan[4], {'from': accounts[0]})

Get loans

  • loans = BZX.getActiveLoansAdvanced(0,100,True,True)

  • loan = loans[0]

Returning loan and getting collateral:

BZX.liquidate(loan[0], accounts[0], loan[13], {'from': accounts[0]})

Rollover

BZX.rollover(loan[0], b'', {'from':accounts[0]})

Flash loans/Flash borrow

  • Flashborrow has the following arguments:

    • flashBorrow(uint256 borrowAmount, address borrower, address target, string signature, bytes data), it should be call from contract layer.

Last updated