GEB Docs
Search…
Geb
The main package used to interact with the GEB system. Includes helper functions for safe management and the contract interface object to directly call smart contracts.

Constructors

+ new Geb(network: GebDeployment, provider: GebProviderInterface | Provider): Geb
Constructor of the main Geb.js object.
Parameters:
Name
Type
Description
network
GebDeployment
Either 'kovan', 'mainnet' or an actual list of contract addresses.
provider
GebProviderInterface | Provider
Either a Ethers.js provider or a Geb provider (Soon support for Web3 will be added)
Returns: Geb

Properties

contracts

contracts: ContractApis
Object containing all GEB core smart-contracts instances for direct level interactions. All of the following contracts object are one-to-one typed API to the underlying smart-contract. Read-only functions that do not change the blockchain state return a promise of the return data. State modifying function will return synchronously a pre-filled transaction request object:
1
{
2
to: "0x123abc.."
3
data: "0xabab234ab..."
4
}
Copied!
This object follow the TransactionRequest model of ethers.js (Also similar to the model used by web.js). The object can be completed with properties such as from, gasPrice, gas (gas limit, web3.js ony) or gasLimit (gas limit, ethers.js only). The object can then be passed to the sendTransaction of ehters.js or web3.js
Example:
1
// Setup geb.js an ethers
2
const provider = new ethers.providers.JsonRpcProvider('http://kovan.infura.io/<API KEY>')
3
const wallet = new ethers.Wallet('<Private key>', provider)
4
const geb = new Geb('kovan', provider)
5
6
// Contract read function: Fetch the debt ceiling
7
const debtCeiling = await geb.contracts.safeEngine.globalDebtCeiling()
8
9
// State changing function: manualy liquidate a SAFE
10
const tx = geb.contracts.liquidationEngine.liquidateSAFE(ETH_A, '0x1234abc...')
11
await wallet.sendTransaction(tx) // Send the Ethereum transaction
Copied!
Currently the following contracts are available:
  • SAFEEngine
  • AccountingEngine
  • TaxCollector
  • LiquidationEngine
  • OracleRelayer
  • GlobalSettlement
  • DebtAuctionHouse
  • PreSettlementSurplusAuctionHouse
  • PostSettlementSurplusAuctionHouse
  • SettlementSurplusAuctioneer
  • GebSafeManager
  • GetSafes
  • BasicCollateralJoin
  • CoinJoin
  • Coin (System coin ERC20 contract)
  • GebProxyRegistry
  • FixedDiscountCollateralAuctionHouse
  • Weth (ERC20)
For detailed information about the functions of each contract we recommend referring directly to the smart contract code and documentation.

Methods

deployProxy

deployProxy(): TransactionRequest
Deploy a new proxy owned by the sender.
Returns: TransactionRequest

getErc20Contract

getErc20Contract(tokenAddress: string): Erc20
Returns an object that can be used to interact with a ERC20 token. Example:
1
const USDCAddress = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
2
const USDC = geb.getErc20Contract(USDCAddress)
3
4
// Get 0xdefiisawesome's balance
5
const balance = USDC.balanceOf("0xdefiisawesome..")
6
7
// Send 1 USDC to 0xdefiisawesome (USDC has 6 decimals)
8
const tx = USDC.transfer("0xdefiisawesome..", "1000000")
9
await wallet.sendTransaction(tx)
Copied!
Parameters:
Name
Type
Description
tokenAddress
string
Token contract address
Returns: Erc20
Erc20

getGebContract

getGebContractT›(gebContractClass: GebContractAPIConstructorInterface‹T›, address: string): T
Returns an instance of a specific geb contract given a Geb contract API class at a specified address
1
import { contracts } from "geb.js"
2
const safeEngine = geb.getGebContract(contracts.SafeEngine, "0xabcd123..")
3
const globalDebt = safeEngine.globalDebt()
Copied!
Type parameters:
T: BaseContractAPI
Parameters:
Name
Type
Description
gebContractClass
GebContractAPIConstructorInterface‹T›
Class from contracts or adminContracts
address
string
Contract address of the instance
Returns: T

getIncentiveCampaignContract

getIncentiveCampaignContract(campaignNumber: number): Promise‹StakingRewards‹››
Help function to get the contract object of an incentive campaign given its number ID
Parameters:
Name
Type
Description
campaignNumber
number
incremental ID of the campaign
Returns: Promise‹StakingRewards‹››
StakingRewards

getProxyAction

getProxyAction(ownerAddress: string): Promise‹GebProxyActions‹››
Given an address returns a GebProxyActions object to execute bundled operations. Important: This requires the address to have deployed a GEB proxy through the proxy registry contract. It will throw a DOES_NOT_OWN_HAVE_PROXY error if the address specified does not have a proxy. Use the deployProxy function to get a new proxy.
Parameters:
Name
Type
Description
ownerAddress
string
Externally owned user account, Ethereum address that owns a GEB proxy.
Returns: Promise‹GebProxyActions‹››

getSafe

getSafe(idOrHandler: string | number, collateralType?: string): Promise‹Safe
Get the SAFE object given a safeManager id or a safeEngine handler address.
Parameters:
Name
Type
Description
idOrHandler
string | number
Safe Id or SAFE handler
collateralType?
string
-
Returns: Promise‹Safe

getSafeFromOwner

getSafeFromOwner(address: string): Promise‹Safe[]›
Fetch the list of safes owned by an address. This function will fetch safes owned directly through the safeManager and safes owned through the safe manager through a proxy. Safes owned directly by the address at the safeEngine level won't appear here.
Note that this function will make a lot of network calls and is therefore very slow. For front-ends we recommend using pre-indexed data such as the geb-subgraph.
Parameters:
Name
Type
Description
address
string
Returns: Promise‹Safe[]›

multiCall

multiCallO1, O2, O3›(calls: [MulticallRequest‹O1›, MulticallRequest‹O2›, MulticallRequest‹O3›]): Promise‹[O1, O2, O3]›
Bundles several read only GEB contract call into 1 RPC single request. Useful for front-ends or apps that need to fetch many parameters from the contracts but want to minimize the network request and the load on the underlying Ethereum node. The function takes as input an Array of GEB view contract calls. IMPORTANT: You have to set the multicall parameter of the contract function to true, it is the always the last parameter of the function. Multicall works for all contracts in the Geb.contracts and can be use with any contract that inherit the BaseContractApi. Note that it does not support non-view calls (Calls that require to pay gas and change the state of the blockchain).
Example:
1
import { ethers } from "ethers"
2
import { Geb } from "geb.js"
3
4
const provider = new ethers.providers.JsonRpcProvider("http://kovan.infura.io/...")
5
const geb = new Geb("kovan", provider);
6
7
const [ globalDebt, collateralInfo ] = await geb.multiCall([
8
geb.contracts.safeEngine.globalDebt(true), // !! Note the last parameter set to true.
9
geb.contracts.safeEngine.collateralTypes(ETH_A, true),
10
])
11
12
console.log(`Current global debt: ${globalDebt.toString()}`)
13
console.log(`Current ETH_A debt: ${collateralInfo.debtAmount}`)
Copied!
Type parameters:
O1
O2
O3
Parameters:
Name
Type
Description
calls
[MulticallRequest‹O1›, MulticallRequest‹O2›, MulticallRequest‹O3›]
Call a read only GEB contract function. The GEB contract object needs to be called with the parameter multicall set to true as seen in the example above.
Returns: Promise‹[O1, O2, O3]›
Promise Array with the result from their respective requests.

Static getGebContract

getGebContractT›(gebContractClass: GebContractAPIConstructorInterface‹T›, address: string, provider: GebProviderInterface | Provider): T
Returns an instance of a specific geb contract given Geb contract API class constructor at a specified address
Type parameters:
T: BaseContractAPI
Parameters:
Name
Type
Description
gebContractClass
GebContractAPIConstructorInterface‹T›
Class from contracts or adminContracts
address
string
Contract address of the instance
provider
GebProviderInterface | Provider
Either a Ethers.js provider or a Geb provider
Returns: T
Last modified 9mo ago