Getting Started
Install
npm install geb.jsDependencies
npm install ethersDocumentation
Examples
import { ethers, utils as ethersUtils } from 'ethers'
import { Geb, utils } from 'geb.js'
// Setup Ether.js
const provider = new ethers.providers.JsonRpcProvider(
'http://kovan.infura.io/<API KEY>'
)
const wallet = new ethers.Wallet('0xdefiisawesome...', provider)
// Create the main GEB object
const geb = new Geb('kovan', provider)
// Get a SAFE
const safe = await geb.getSafe(4)
console.log(`Safe id 4 has: ${utils.wadToFixed(safe.debt).toString()} worth of debt.`)
console.log(`It will get liquidated if ETH price falls below ${(await safe.liquidationPrice())?.toString()} USD.`)
// Open a new SAFE, lock ETH and draw system coins in a single transaction using a proxy
// Note: Before doing this you need to create your own proxy
// We first need to check that the system didn't reach the debt ceiling so that we can
// mint more system coins.
const globalDebt = await geb.contracts.safeEngine.globalDebt()
const debtCeiling = await geb.contracts.safeEngine.globalDebtCeiling()
const systemCoinsToDraw = ethersUtils.parseEther('15')
if(globalDebt.add(systemCoinsToDraw).gt(debtCeiling)) {
throw new Error('Debt ceiling too low, not possible to draw this amount of system coins.')
}
// We're good to mint some system coins!
const proxy = await geb.getProxyAction(wallet.address)
const tx = proxy.openLockETHAndGenerateDebt(
ethersUtils.parseEther('1'), // Lock 1 Ether
utils.ETH_A, // Of collateral type ETH_A
systemCoinsToDraw // And draw 15 system coins
)
tx.gasPrice = ethers.BigNumber.from('80').mul('1000000000') // Set the gas price to 80 Gwei
const pending = await wallet.sendTransaction(tx) // Send the transaction
console.log(`Transaction ${pending.hash} waiting to be mined...`)
await pending.wait() // Wait for it to be mined
console.log('Transaction mined, safe opened!')Additional examples
Deploy a new proxy
Partial repayment of safe debt
Complete repayment of safe debt
Withdraw Ether collateral
Repay all debt and withdraw all collateral
Make direct contract calls
Multicall
Last updated
Was this helpful?