The example position hook is an easy way to get started.A user’s Divvi wallet invokes position hooks when determining the types, quantity, and value of assets a user owns. If a position hook detects a user owns one or more positions, it provides information about the positions for the app to show to the user.
Principle
A position pricing hook’s main job is to return user owned positions and to break them down into underlying base tokens. The pricing of base tokens is done separately and is not needed by hooks authors. Terms:- Base Tokens: base assets which have a token to represent them (ERC20, ERC721, etc). Examples: CELO, cUSD, cEUR, UBE, MOO, etc.
- App Tokens: tokens which represent more complex positions within a dapp, like liquidity pool (LP) tokens, or staked positions.
- Contract Positions: things that are not represented by a token (example: locked CELO, farming positions, claimable tokens).
- The liquidity pool is an app token.
- The pool’s assets are base tokens.
Developing a Position Pricing Hook
Structure
Hooks are organized by application. For instance Ubeswap hooks are located inhttps://github.com/divvi-xyz/hooks/tree/main/src/apps/ubeswap
.
Position pricing hooks must implement the PositionsHook
TypeScript interface.
Creating a Position Pricing Hook
To create a position pricing hook for your application namedMyApp
, you will need to create a new folder with the name my-app
in src/apps
and add a positions.ts
file. The file should export an object with the following properties:
Implementing getPositionDefinitions
The getPositionDefinitions
function is called by Divvi apps to get the positions owned by a user.
It receives the following arguments:
network
: the network for which the positions should be returned.address
: the address of the user for which the positions should be returned.
PositionDefinition
objects.
The PositionDefinition
is either an AppTokenPositionDefinition
or a ContractPositionDefinition
, representing an app token or a contract position respectively.
App Token Position Definition
TODOContract Position Definition
Locked CELO Example
Here’s a simplified example of agetPositionDefinitions
implementation for representing locked CELO owned by a user.
Please take a look at the full implementation for more details.
type
: the type of position definition. In this case, it’s acontract-position-definition
.network
: the network of the position definition.address
: the address of the contract for the position definition.tokens
: the base tokens that the position definition represents. In this case, it’s just CELO.label
: a human-readable label for the position definition.balances
: a function that returns the balances of the base tokens represented by the position definition.
Testing a Position Pricing Hook
The hooks live preview mode in a Divvi app is the easiest way to test your position hook while developing it. Alternatively, you can use thegetPositions
script via the command line.
LOG_LEVEL
environment variable to debug
.
Suggest changes to this pageLast updated: Feb 19, 2025, 2:27 PM