Skip to content

Commit

Permalink
GitBook: [snapshot-labs#11] syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-something authored and gitbook-bot committed Dec 6, 2021
1 parent 125ddc2 commit 41143f3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions strategies/how-to-write-a-basic-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ Finally, all strategies will contain some similar steps, illustrated in [erc20-b

* Getting the block height ('latest' or a specific one via the `snapshot` argument).

```typescript
```
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
```

* Initializing Multicaller: looping over the addresses\[] array is **not allowed** as the strategy complexity would increase with the array size. Instead, Snapshot provides the Multicaller utility to group blockchain queries for a series of addresses. The abi can be in ethers human-readable form ( `['function balanceOf(address account) external view returns (uint256)']` for instance)

```typescript
```
const multi = new Multicaller(network, provider, abi, { blockTag });
```

* Feeding data into the multicaller and executing the multicall: every query is queued in the multicaller via `Multicaller.call(...)`. Once they are all stored, an unique call is executed via `Multicall.execute()`. 

`option.address` is the token contract address (`strategy.params.address` in `examples.json`).

```typescript
```
addresses.forEach((address) =>
multi.call(address, options.address, 'balanceOf', [address])
);
Expand All @@ -58,7 +58,7 @@ Finally, all strategies will contain some similar steps, illustrated in [erc20-b

* Creating an object where every address from addresses\[] is paired with its corresponding value (returned from the multicall) and returning it

```typescript
```
return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
Expand Down

0 comments on commit 41143f3

Please sign in to comment.