# Tetsu Corp for agents Everything below is on Robinhood Chain (chain id 4663, RPC https://rpc.mainnet.chain.robinhood.com). Addresses: https://tetsucorp.si/contracts.json. Use your own wallet and node to sign; the site's /api/rpc/4663 only reads. ## Types MarketParams = (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) - loanToken: USDG 0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168 - collateralToken: the stock token (contracts.json markets[].token) - oracle: contracts.json markets[].oracle - irm: 0x2BD3d5965B26B51814AC95127B2b80dD6CcC0fa1 - lltv: contracts.json markets[].lltv The market id is keccak256(abi.encode(MarketParams)) and is listed as markets[].marketId (NVDA: 0xd7332755b50c2b6224837fbeb97676fccd93a92cc7aa3e319674afae0e802cf9). ## Borrow USDG against a stock token 1. stock.approve(0x9D53d5E3bd5E8d4Cbfa6DB1ca238AEA02E651010, collateral) 2. Morpho.supplyCollateral(marketParams, collateral, onBehalf = you, data = 0x) 3. If the market's free USDG (totalSupplyAssets - totalBorrowAssets from Morpho.market(id)) is short: agent.pull(bytes32 marketId, uint256 assets), on the agent of the stock's farm (contracts.json markets[].farm). 4. Morpho.borrow(marketParams, assets, shares = 0, onBehalf = you, receiver = you) Keep debt under 85% of collateral value x lltv; at 100% anyone can liquidate. ## Repay and withdraw 1. USDG.approve(0x9D53d5E3bd5E8d4Cbfa6DB1ca238AEA02E651010, amount + headroom for interest) 2. Morpho.repay(marketParams, assets, 0, you, 0x), or repay(marketParams, 0, yourBorrowShares, you, 0x) to close fully 3. Morpho.withdrawCollateral(marketParams, assets, you, you) ## Lend through a farm 1. USDG.approve(agent, assets) 2. agent.deposit(uint256 assets, address receiver) returns (uint256 shares) The agent deposits into its Morpho Vault V2 for the receiver and places the USDG by its playbook in the same call. 3. To exit: if USDG.balanceOf(vault) is below what you want, agent.free(uint256 assets) (up to your own position), then vault.withdraw(uint256 assets, address receiver, address onBehalf) or vault.redeem(uint256 shares, receiver, onBehalf). ## Keep a farm working - agent.work(): the full playbook. Public, at most once per 600 seconds. - agent.preview() returns, per market, (id, ours, supply, borrow, fill, target, room) plus the farm's idle cash and total. - Events: Placed(bytes32 indexed id, uint256 assets), Lifted(bytes32 indexed id, uint256 assets), Worked(address indexed caller, uint8 indexed mode, uint256 totalAssets, uint256 idle). ## Liquidate 1. Find a loan with health < 1 (GET https://tetsucorp.si/api/loans). 2. USDG.approve(0x9D53d5E3bd5E8d4Cbfa6DB1ca238AEA02E651010, repayment + headroom) 3. Morpho.liquidate(marketParams, borrower, seizedAssets, repaidShares, 0x): set exactly one of seizedAssets or repaidShares. Bonus factor: min(1.15, 1 / (1 - 0.3 x (1 - lltv))).