Skip to content

Commit

Permalink
chore: reword for Mobile Stack (#678)
Browse files Browse the repository at this point in the history
Hooks is now for all Mobile Stack apps, not just Valora.
Updated the docs accordingly.

Co-authored-by: Silas Boyd-Wickizer <[email protected]>
  • Loading branch information
jeanregisser and silasbw authored Dec 5, 2024
1 parent 6e73c8a commit 67fb5fc
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 62 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Mobile Stack Hooks

[![GitHub License](https://img.shields.io/github/license/valora-inc/hooks?color=blue)](https://github.com/valora-inc/hooks/blob/main/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/valora-inc/hooks/.github/workflows/workflow.yaml?branch=main)](https://github.com/valora-inc/hooks/actions/workflows/workflow.yaml?query=branch%3Amain)
[![Codecov](https://img.shields.io/codecov/c/github/valora-inc/hooks)](https://codecov.io/gh/valora-inc/hooks)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/valora-inc/hooks#contributing)
[![GitHub License](https://img.shields.io/github/license/mobilestack-xyz/hooks?color=blue)](https://github.com/mobilestack-xyz/hooks/blob/main/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/mobilestack-xyz/hooks/.github/workflows/workflow.yaml?branch=main)](https://github.com/mobilestack-xyz/hooks/actions/workflows/workflow.yaml?query=branch%3Amain)
[![Codecov](https://img.shields.io/codecov/c/github/mobilestack-xyz/hooks)](https://codecov.io/gh/mobilestack-xyz/hooks)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/mobilestack-xyz/hooks#contributing)

Mobile Stack Hooks allows developers to extend an app's functionality (_e.g._, the Valora wallet) by writing short programs called "hooks". These hooks are called in response to certain in-app or blockchain events and are used to provide the application with additional information and features.

Check out the [Hooks documentation](https://docs.valora.xyz/hooks/) for more information.
Check out the [Hooks documentation](https://docs.mobilestack.xyz/hooks/) for more information.

Currently, this repository contains position pricing and shortcut hooks.

Expand Down
30 changes: 15 additions & 15 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
sidebar_position: 1
---

# Extend Valora using Hooks
# Extend Mobile Stack apps using Hooks

> If you want to start coding, check out the [Live
> Preview](live-preview) and the [example application](https://github.com/valora-inc/hooks/blob/master/src/apps/example)
> Preview](live-preview) and the [example application](https://github.com/mobilestack-xyz/hooks/blob/master/src/apps/example)
> with hook implementations.
Valora Hooks is a system that allows developers to extend Valora by
writing short programs called "hooks". Valora will call hooks in
Mobile Stack Hooks is a system that allows developers to extend apps (_e.g._, the Valora wallet and other Mobile Stack apps) by
writing short programs called "hooks". Mobile Stack apps will call hooks in
response to certain in-app or blockchain events and use the results
from hooks to extend Valora's functionality.
from hooks to extend the apps' functionality.

Valora Hooks is currently an experimental feature in Valora. We are
developing the Valora Hooks system incrementally based on feedback
Mobile Stack Hooks is currently an experimental feature. We are
developing the Mobile Stack Hooks system incrementally based on feedback
from developers. Eventually we hope developers will be able to publish
hooks that users can enable or disable at will.

Expand All @@ -24,32 +24,32 @@ Users often hold asset-like positions with dapps that are specific to
the dapp implementation. For example, DeFi dapps
implement yield farms with smart contracts specific to the dapp and
these contracts track each users' state in the yield farm, like
liquidity and unclaimed rewards. A developer can implement a Valora
liquidity and unclaimed rewards. A developer can implement a Mobile Stack
hook to detect these types of positions and price them. If a user is
yield farming they will see their yield farm positions directly in
Valora.
the app.

## Developing a hook

A developer can write a short TypeScript program that handles a
specific hook type. A user's Valora wallet passes information to the
specific hook type. A user's Mobile Stack wallet passes information to the
hook, the hook executes in an isolated environment and returns a
result, and Valora uses the results to extend its default behavior.
result, and the app uses the results to extend its default behavior.

Currently all hooks need to be approved by a Valora engineer before
being available to users in the Valora wallet. Please contact us if
being available to users in the app. Please contact us if
you're interested in developing a hook and haven't chatted with us
yet.

## Hook types

Valora supports or is working on support for the types of hooks we
Mobile Stack supports or is working on support for the types of hooks we
list below:

- Position pricing: show a custom contract position in Valora
- Position pricing: show a custom contract position in a Mobile Stack app
- Name resolution: map an arbitrary identifier or name to a wallet address
- Shortcut (coming soon): complete simple dapp (or inter-dapp) actions
within Valora
within a Mobile Stack app

We plan on adding support for more hook types. If you have a request
please reach out on Discord.
Expand Down
12 changes: 6 additions & 6 deletions docs/live-preview.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Live Preview in Valora
# Live Preview

Hooks in development can be easily tested in Valora using the live preview feature.
Hooks in development can be easily tested in a Mobile Stack app using the live preview feature.

<video controls muted playsInline width="100%">
<source src="https://raw.githubusercontent.com/valora-inc/hooks/main/docs/assets/live-preview.mp4"/>
<source src="https://raw.githubusercontent.com/mobilestack-xyz/hooks/main/docs/assets/live-preview.mp4"/>
</video>

## Steps

1. Run `yarn start` to start the development server.
2. Open Valora on your phone and go to the QR scanner screen.
2. Open the app (_e.g._, the Valora wallet or another Mobile Stack app) on your phone and go to the QR scanner screen.
3. Scan the QR code displayed in the terminal.

## Additional Information

While in preview mode, changes to your hooks will reload the development server automatically.
You may need to pull down to refresh the screen in Valora to see the changes.
You may need to pull down to refresh the screen in the app to see the changes.

Valora shows a banner at the top of the screen when in preview mode. The color of the banner changes based on the fetch status for hooks.
The app shows a banner at the top of the screen when in preview mode. The color of the banner changes based on the fetch status for hooks.

- grey -> idle/loading
- green -> success
Expand Down
14 changes: 7 additions & 7 deletions docs/platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
sidebar_position: 2
---

# Valora Hooks Platform
# Mobile Stack Hooks Platform

## Developing a hook

Developers must implement hooks in TypeScript and integrate them with
one of the existing per-hook type GitHub repositories.

We hope to make hooks easy to develop but also want to easily iterate
on the Valora Hooks Platform for developing and deploying hooks. For
now we require all deployed hook code to be located in Valora GitHub
on the Mobile Stack Hooks Platform for developing and deploying hooks. For
now we require all deployed hook code to be located in Mobile Stack GitHub
repositories so we can help improve and maintain them (e.g., when
we implement breaking changes to the platform), but in the future we
expect to impose fewer requirements on how hooks are developed.

## Execution environment

Each hook executes in a Node.js 18 environment. Currently we
Each hook executes in a Node.js 20 environment. Currently we
implement this as a [Google Cloud
Function](https://cloud.google.com/functions/docs/concepts/execution-environment), which has several important implications:

- statelessness: your hook cannot store data locally (_e.g._, in memory)
- timeout: Valora will timeout waiting for a hook to execute
- background: Valora destroys the hook environment after it returns so
- timeout: the app will timeout waiting for a hook to execute
- background: the app destroys the hook environment after it returns so
it's not possible to continue computation in the hook after
returning a result

Expand All @@ -36,7 +36,7 @@ high-level model in mind when developing their hooks and avoid
depending on Google Cloud Function specific attributes (_e.g._, reading
the reserved environment variable `K_SERVICE`)

## Deploying a hook to Valora
## Deploying a hook to a Mobile Stack app

To deploy your hook you must:

Expand Down
4 changes: 2 additions & 2 deletions docs/types/name-resolution.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Name Resolution Hooks

A user's Valora wallet invokes name resolution hooks when the user
A user's Mobile Stack wallet invokes name resolution hooks when the user
types a recipient for sending funds to. Each name resolution hook
returns a list of addresses matching the recipient. Valora enables
returns a list of addresses matching the recipient. Mobile Stack apps enable
name resolution hooks for
[SocialConnect](https://github.com/celo-org/SocialConnect),
[Nomspace](https://nom.space/) (a.k.a., ".nom"), and [Masa Finance's
Expand Down
20 changes: 10 additions & 10 deletions docs/types/position.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ sidebar_position: 1

# Position Pricing Hooks

> The [example position hook](https://github.com/valora-inc/hooks/blob/master/src/apps/example/positions.ts) is an easy way to get started.
> The [example position hook](https://github.com/mobilestack-xyz/hooks/blob/master/src/apps/example/positions.ts) is an easy way to get started.
A user's Valora 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 Valora to show to the user.
A user's Mobile Stack 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

Expand All @@ -23,15 +23,15 @@ For example, a position hook detects that a user owns a position in a liquidity
- The liquidity pool is an app token.
- The pool's assets are base tokens.

From the information provided by the hook, Valora can show the user the value of their position in the pool.
From the information provided by the hook, the Mobile Stack app can show the user the value of their position in the pool.

## Developing a Position Pricing Hook

### Structure

Hooks are organized by application. For instance Ubeswap hooks are located in [`https://github.com/valora-inc/hooks/tree/main/src/apps/ubeswap`](https://github.com/valora-inc/hooks/tree/main/src/apps/ubeswap).
Hooks are organized by application. For instance Ubeswap hooks are located in [`https://github.com/mobilestack-xyz/hooks/tree/main/src/apps/ubeswap`](https://github.com/mobilestack-xyz/hooks/tree/main/src/apps/ubeswap).

Position pricing hooks must implement the [`PositionsHook`](https://github.com/valora-inc/hooks/blob/main/src/types/positions.ts) TypeScript interface.
Position pricing hooks must implement the [`PositionsHook`](https://github.com/mobilestack-xyz/hooks/blob/main/src/types/positions.ts) TypeScript interface.

### Creating a Position Pricing Hook

Expand All @@ -54,14 +54,14 @@ export default hook

### Implementing `getPositionDefinitions`

The `getPositionDefinitions` function is called by Valora to get the positions owned by a user.
The `getPositionDefinitions` function is called by Mobile Stack 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.

It should return an array of [`PositionDefinition`](https://github.com/valora-inc/hooks/blob/main/src/types/positions.ts) objects.
It should return an array of [`PositionDefinition`](https://github.com/mobilestack-xyz/hooks/blob/main/src/types/positions.ts) objects.

The `PositionDefinition` is either an `AppTokenPositionDefinition` or a `ContractPositionDefinition`, representing an app token or a contract position respectively.

Expand All @@ -75,7 +75,7 @@ TODO

Here's a simplified example of a `getPositionDefinitions` implementation for representing locked CELO owned by a user.

Please take a look at the [full implementation](https://github.com/valora-inc/hooks/blob/main/src/apps/locked-celo/positions.ts) for more details.
Please take a look at the [full implementation](https://github.com/mobilestack-xyz/hooks/blob/main/src/apps/locked-celo/positions.ts) for more details.

```ts
const hook: PositionsHook = {
Expand Down Expand Up @@ -117,11 +117,11 @@ Here you can see that it contains the following properties:

This is how it fulfills the job of a position pricing hook, by declaratively defining the position with its underlying base tokens.

This is all that is needed for Valora to show the user the value of their locked CELO.
This is all that is needed for Mobile Stack apps to show the user the value of their locked CELO.

### Testing a Position Pricing Hook

The [hooks live preview](../live-preview.md) mode in Valora is the easiest way to test your position hook while developing it.
The [hooks live preview](../live-preview.md) mode in a Mobile Stack app is the easiest way to test your position hook while developing it.

Alternatively, you can use the `getPositions` script via the command line.

Expand Down
24 changes: 12 additions & 12 deletions docs/types/shortcut.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ sidebar_position: 2

# Shortcut Hooks

A user's Valora wallet invokes shortcut hooks when determining asset or dapp related calls-to-action for the user. For example, when a user opens Valora's homescreen. A shortcut hook returns a human readable summary of available actions (_e.g._, "Claim your 1 cUSD earnings") and if the user chooses to act on them, a set of blockchain or in-app transactions will be executed by Valora with the user's consent.
A user's Mobile Stack wallet invokes shortcut hooks when determining asset or dapp related calls-to-action for the user. For example, when a user opens a Mobile Stack app's homescreen. A shortcut hook returns a human readable summary of available actions (_e.g._, "Claim your 1 cUSD earnings") and if the user chooses to act on them, a set of blockchain or in-app transactions will be executed by the app with the user's consent.

> **Note**
> The UI/UX for shortcut hooks in Valora is currently focused on the "claim rewards" use case and requires a [position pricing hook](position.md) to be implemented as well. We plan to expand them to other use cases in the future (shortcuts with custom inputs, not linked to positions, or across dapps).
> The UI/UX for shortcut hooks in Mobile Stack apps is currently focused on "earn" and "claim rewards" use cases and requires a [position pricing hook](position.md) to be implemented as well. We plan to expand them to other use cases in the future (shortcuts with custom inputs, not linked to positions, or across dapps).
## Developing a Shortcut Hook

### Structure

Hooks are organized by application. For instance GoodDollar hooks are located in [`https://github.com/valora-inc/hooks/tree/main/src/apps/gooddollar`](https://github.com/valora-inc/hooks/tree/main/src/apps/gooddollar).
Hooks are organized by application. For instance GoodDollar hooks are located in [`https://github.com/mobilestack-xyz/hooks/tree/main/src/apps/gooddollar`](https://github.com/mobilestack-xyz/hooks/tree/main/src/apps/gooddollar).

Shortcut hooks must implement the [`ShortcutsHook`](https://github.com/valora-inc/hooks/blob/main/src/types/shortcuts.ts) TypeScript interface.
Shortcut hooks must implement the [`ShortcutsHook`](https://github.com/mobilestack-xyz/hooks/blob/main/src/types/shortcuts.ts) TypeScript interface.

### Creating a Shortcut Hook

Expand All @@ -35,15 +35,15 @@ export default hook

### Implementing `getShortcutDefinitions`

The `getShortcutDefinitions` function is called by Valora to get the list of shortcuts.
The `getShortcutDefinitions` function is called by a Mobile Stack app to get the list of shortcuts.

It should return an array of [`ShortcutDefinition`](https://github.com/valora-inc/hooks/blob/main/src/types/shortcuts.ts) objects.
It should return an array of [`ShortcutDefinition`](https://github.com/mobilestack-xyz/hooks/blob/main/src/types/shortcuts.ts) objects.

#### GoodDollar Example

Here's a simplified example of a `getShortcutDefinitions` implementation for claiming GoodDollar rewards.

Please take a look at the [full implementation](https://github.com/valora-inc/hooks/blob/main/src/apps/gooddollar/shortcuts.ts) for more details.
Please take a look at the [full implementation](https://github.com/mobilestack-xyz/hooks/blob/main/src/apps/gooddollar/shortcuts.ts) for more details.

```ts
const hook: ShortcutsHook = {
Expand Down Expand Up @@ -94,11 +94,11 @@ Here you can see that it contains the following properties:
- `category`: the category of the shortcut
- `onTrigger`: the function that is called when the shortcut is triggered

Once the shortcut is defined, Valora needs to know when to show it to the user, by linking it to an existing [position](position.md).
Once the shortcut is defined, the Mobile Stack app needs to know when to show it to the user, by linking it to an existing [position](position.md).

This is done by adding the `availableShortcutIds` property to the position definition and setting the `category` to `claimable` for the appropriate token(s).

This way Valora will be able to determine that the position has claimable token(s) and what shortcut to call to claim them.
This way the Mobile Stack app will be able to determine that the position has claimable token(s) and what shortcut to call to claim them.

```ts
const position: ContractPositionDefinition = {
Expand All @@ -111,11 +111,11 @@ const position: ContractPositionDefinition = {
}
```

Once this all done, Valora will show the GoodDollar shortcut in the rewards screen, with the available reward amount, and the button to claim it.
Once this all done, the Mobile Stack app will show the GoodDollar shortcut in the rewards screen, with the available reward amount, and the button to claim it.

### Testing a Shortcut Hook

The [hooks live preview](../live-preview.md) mode in Valora is the easiest way to test your shortcut hook while developing it.
The [hooks live preview](../live-preview.md) mode in a Mobile Stack app is the easiest way to test your shortcut hook while developing it.

Alternatively, you can use the following scripts via the command line.

Expand Down Expand Up @@ -155,7 +155,7 @@ To test triggering your shortcut hook, you can use the `triggerShortcut` script.
yarn triggerShortcut --network <network> --address <address> --app <app-name> --shortcut <shortcut-id> --positionAddress <position-address>
```

This will return the transactions that would be executed by Valora, after approval by the user.
This will return the transactions that would be executed by the Mobile Stack app, after approval by the user.

You can also optionally pass the `--mnemonic` and `--derivationPath` (defaults to the Celo derivation path: `m/44'/52752'/0'/0/0`) options to actually sign and send the returned transaction(s).

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@valora/hooks",
"name": "@mobilestack/hooks",
"version": "0.0.0-semantic-release",
"main": "dist/api/index.js",
"typings": "dist/api/index.d.ts",
"repository": "https://github.com/valora-inc/hooks.git",
"repository": "https://github.com/mobilestack-xyz/hooks.git",
"author": "Valora Inc",
"license": "Apache-2.0",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/compound/positions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const hook: PositionsHook = {
title: `${tokenDescription.symbol} ${type}`,
description: `${baseTokenDescription.symbol} Market`,
imageUrl:
'https://raw.githubusercontent.com/valora-inc/hooks/main/src/apps/compound/assets/compound.png',
'https://raw.githubusercontent.com/mobilestack-xyz/hooks/main/src/apps/compound/assets/compound.png',
manageUrl: COMPOUND_NETWORK_NAME[networkId]
? `https://app.compound.finance/markets/${baseTokenDescription.symbol}-${COMPOUND_NETWORK_NAME[networkId]}`
: undefined,
Expand Down
Loading

0 comments on commit 67fb5fc

Please sign in to comment.