4️PTB Functions

The PTB functions are designed to seamlessly integrate with other PTB codebases. These functions can be easily imported and used in various environments outside of the SDK, offering flexibility for broader application in your projects.

Deposit Coin

Deposits a specified coin into the pool.

depositCoin(txb: Transaction, _pool: PoolConfig, coinObject: any, amount: any)

Deposits a coin with account cap restrictions.

depositCoinWithAccountCap(txb: Transaction, _pool: PoolConfig, coinObject: any, accountCapAddress: string)

Withdraw Coin

Note: These PTB functions return a coin object, which needs to be either used or explicitly dropped within the PTB code.

Withdraws a specified amount of coin from the pool.

const [returnedCoin] = withdrawCoin(txb: Transaction, _pool: PoolConfig, amount: number)

Withdraws a coin with account cap restrictions.

const [returnedCoin] = withdrawCoinWithAccountCap(txb: Transaction, _pool: PoolConfig, account: string, withdrawAmount: number, sender: string)

Borrow Coin

Borrows a specified amount of coin from the pool.

const [returnedCoin] = borrowCoin(txb: Transaction, _pool: PoolConfig, borrowAmount: number)

Repay Debt

Repays a specified debt amount using a coin object.

repayDebt(txb: Transaction, _pool: PoolConfig, coinObject: any, repayAmount: n

Flashloan

Initiates a flashloan from the pool with a specified amount.

const [balance, receipt] = flashloan(txb: Transaction, _pool: PoolConfig, amount: number)

Repays the flashloan using the provided receipt and repayment coin.

const [e_balance] = repayFlashLoan(txb: Transaction, _pool: PoolConfig, receipt: any, repayCoin: any)

A flashloan demo is also provided: Sample TX

Liquidation

This function liquidates a position by paying debt and receiving collateral.

const [collateralBalance, remainDebtBalance] = liquidateFunction(txb: Transaction, payCoinType: CoinInfo, payCoinObj: any, collateralCoinType: CoinInfo, to_liquidate_address: string, to_liquidate_amount: string)
  • collateralBalance is collateral coin what liquidator get after paying for the debt.

  • remainDebtBalance is repay coin left after paying for debt.

Claim Reward

claimRewardFunction(txb: Transaction, incentiveFundsPool: string, assetId: string, option: OptionType)

Update Oracle PTB

updateOraclePTB(client: SuiClient, txb: Transaction)

Last updated