Skip to main content

ERC20 Primitives

  • ERC20, keeping track of wallet balances for a specified ERC20 contract;
  • ERC20Deposit, keeping track of the total amount of a specified ERC20 contract sent by wallets to a

ERC20

Example

extensions:
- name: "Bar"
type: "erc20"
contractAddress: "0x01...ef"
startBlockHeight: 4567123

Meaning

This extension allows you to track the balances of a specified ERC20 token for all wallets by processing Transfer events the contract emits.

Paima Concise format

The ERC20 Primitive does not schedule any inputs, so the scheduledPrefix field can be omitted.

Utility functions

  • getFungibleTokenBalance, to fetch the balance of a specified wallet address:
export async function getFungibleTokenBalance(
readonlyDBConn: PoolClient,
extensionName: string,
walletAddress: string
): Promise<bigint | null>;

ERC20Deposit

Example

extensions:
- name: "Foo"
type: "erc20-deposit"
contractAddress: "0x01...ef"
startBlockHeight: 4567123
scheduledPrefix: "dp"
depositAddress: "0x23...cd"

Meaning

Unlike the ERC20 extension, which keeps track of the overall balances of the specified token, this one only keeps track of transfers made to a Deposit Address specified in the config file. It stores the total amount transferred, and triggers a scheduled input for each such transfer. The desired deposit address needs to be specified in the config file as the depositAddress field as seen in the example earlier.

Paima Concise format

A scheduled input is triggered every time a transfer is made to the deposit address. The scheduled input will have the following format:

prefix|fromAddr|value

where:

  • prefix is the scheduledPrefix specified in the config file,
  • fromAddr is the address from which tokens have been sent to the deposit address,
  • value is the amount transferred in base 10.

Utility functions

  • Fetch the total amount the specified address has deposited to the deposit address
// total amount the specified address has deposited to the deposit address
export async function totalAmountDeposited(
readonlyDBConn: PoolClient,
extensionName: string,
walletAddress: string
): Promise<bigint | null>;
  • Fetch the list of wallet addresses which have sent at least the specified threshold amount
export async function findUsersWithDepositsGreaterThan(
readonlyDBConn: PoolClient,
extensionName: string,
thresholdAmount: bigint
): Promise<string[]>;