borrow
params of yAssetParams -> (list(op), storage upd)
Take a loan from protocol. Accepts amount of wanted token and it's related yToken's tokenId.
Borrowing new market could fail if user already borrowed from maxMarkets of other markets.
The yToken contract expects that underlying token info of tokenId and all borrowed by user before tokenIds are updated by calling PriceFeed.getPrice and updateInterest in the same block before this contract method
Types
type yAssetParams is [@layout:comb] record [
tokenId : nat; // yToken token Id
amount : nat; // amount tokens to borrow
]tokenId
nat
yToken identifier
amount
nat
amount of underlying tokens to be borrowed from protocol
Usage
const borrowTokenId = 0; // or new BigNumber(0) or "0"
const amount = 10_000_000; // amount of borrow tokens.
const yupana = await tezos.contract.at(yTokenAddress);
const proxy = await tezos.contract.at(proxyAddress);
const borrowedTokenIds = [1, 2]; // user borrowed tokens
const updBorrowed = borrowedTokenIds.reduce(
(batch, tokenId) => {
batch.push({
kind: "transaction",
...yupana.methods.updateInterest(tokenId).toTransferParams(),
},
{
kind: "transaction",
...proxy.methods.getPrice([tokenId]).toTransferParams(),
});
return batch;
}
const batchArray = [
...updBorrowed,
{
kind: "transaction",
...yupana.methods.updateInterest(borrowTokenId).toTransferParams(),
},
{
kind: "transaction",
...proxy.methods.getPrice([borrowTokenId]).toTransferParams(),
},
{
kind: "transaction",
...yupana.methods.borrow(borrowTokenId, amount).toTransferParams(),
},
];
const batch = await tezos.wallet.batch(batchArray);
const operation = await batch.send();
await operation.confirmation();token_id = 0
amount = 10_000_000 # amount of borrow tokens.
yupana = ContractInterface.from_michelson(code) # or client.contract(contract_address)...
proxy = ContractInterface.from_michelson(prx_code) # or client.contract(prx_contract_address)...proxy = ContractInterface.from_michelson(code) # or client.contract(contract_address)...
borrow_ids = [1, 2] # user borrowed tokens
borrow_updates = [yupana.updateInterest(borrow_token_id) for borrow_token_id in borrow_ids]
borrow_updates.append(proxy.getPrice([borrow_token_id for borrow_token_id in borrow_ids]))
call = pytezos.bulk(
*borrow_updates,
yupana.updateInterest(token_id),
proxy.getPrice([token_id]),
yupana.borrow(token_id, amount)
).autofill().sign()
opg = call.inject()Errors
yToken/max-market-limit- limit of borrow markets exceeded.yToken/forbidden-for-borrow- market is paused for borrow.yToken/exceeds-the-permissible-debt- raised when outstanding borrow value greater than max collateral value.yToken/not-enough-liquidity- not enough liquidity of tokens to sendamountwanted by user.token/cant-get-contract-token- FA12 token contract address does not containtransferentrypoint from FA12 interface.token/cant-get-contract-fa2-token- FA2 token contract address does not containtransferentrypoint from FA2 interface.underflow/liquidity - reserves- liquidity more than reserves.yToken/amount-is-zero- passed zeroamount.ceil-div-error- division of two numbers fails.yToken/need-update- token price and interest not updated (see warning above)yToken/yToken-undefined- token identifier is not assigned to any known yTokens.
Last updated