Ooki
Searchโ€ฆ
๐Ÿ“”
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)

1
iUSDT.marginTrade('0x0000000000000000000000000000000000000000000000000000000000000000', 5e18, 0, 10e18, '0x0000000000000000000000000000000000000000', accounts[0], b'', {'from': accounts[0], "value": 10e18})
2
loan =BZX.getLoan(history[-1].return_value[0])
3
Loan has structure
4
โ€‹
5
struct Loan {
6
bytes32 id; // id of the loan
7
bytes32 loanParamsId; // the linked loan params id
8
bytes32 pendingTradesId; // the linked pending trades id
9
uint256 principal; // total borrowed amount outstanding
10
uint256 collateral; // total collateral escrowed for the loan
11
uint256 startTimestamp; // loan start time
12
uint256 endTimestamp; // for active loans, this is the expected loan end time, for in-active loans, is the actual (past) end time
13
uint256 startMargin; // initial margin when the loan opened
14
uint256 startRate; // reference rate when the loan opened for converting collateralToken to loanToken
15
address borrower; // borrower of this loan
16
address lender; // lender of this loan
17
bool active; // if false, the loan has been fully closed
18
}
Copied!

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.
โ€‹