Skip to content

Commit

Permalink
Wallet reference docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Aug 23, 2024
1 parent e250115 commit 0a25240
Show file tree
Hide file tree
Showing 32 changed files with 1,324 additions and 48 deletions.
63 changes: 63 additions & 0 deletions apps/docs/pages/wallet/create-erc1155-batch-transfer-voucher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# createERC1155BatchTransferVoucher

Utility to create a `Voucher` to transfer ERC-1155 tokens from one address to another on the base layer.

## Usage

The example below shows how to create a `Voucher` to withdraw 1 token of token id 1 and 2 from the application to the `msg_sender` of the an input.

```ts twoslash
import { createApp } from "@deroll/app";
import { createERC1155BatchTransferVoucher } from "@deroll/wallet";
import { parseUnits } from "viem";

// create app
const app = createApp({ url: "http://127.0.0.1:5004" });

const application = "0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e";
const token = "0x04d724738873CB6a86328D2EbAEb2079D715e61e"; // ERC-1155 address
app.addAdvanceHandler(async ({ metadata }) => {
const value1 = parseUnits("1", 18);
const value2 = parseUnits("1", 18);
const voucher = createERC1155BatchTransferVoucher( // [!code focus]
token, // [!code focus]
application, // [!code focus]
metadata.msg_sender, // [!code focus]
[1n, 2n], // [!code focus]
[value1, value2], // [!code focus]
"0x", // [!code focus]
); // [!code focus]
await app.createVoucher(voucher);
return "accept";
});
```

## Returns

Type: `Voucher`

## Parameters

Type: `Address`

ERC-1155 token address.

Type: `Address`

Source address.

Type: `Address`

Destination address.

Type: `bigint[]`

Token ids.

Type: `bigint[]`

Token amounts.

Type: `Hex`

Extra payload sent to the base layer.
62 changes: 62 additions & 0 deletions apps/docs/pages/wallet/create-erc1155-single-transfer-voucher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# createERC1155SingleTransferVoucher

Utility to create a `Voucher` to transfer ERC-1155 token from one address to another on the base layer.

## Usage

The example below shows how to create a `Voucher` to withdraw 1 token of token id 1 from the application to the `msg_sender` of the an input.

```ts twoslash
import { createApp } from "@deroll/app";
import { createERC1155SingleTransferVoucher } from "@deroll/wallet";
import { parseUnits } from "viem";

// create app
const app = createApp({ url: "http://127.0.0.1:5004" });

const application = "0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e";
const token = "0x04d724738873CB6a86328D2EbAEb2079D715e61e"; // ERC-1155 address
app.addAdvanceHandler(async ({ metadata }) => {
const value = parseUnits("1", 18);
const voucher = createERC1155SingleTransferVoucher( // [!code focus]
token, // [!code focus]
application, // [!code focus]
metadata.msg_sender, // [!code focus]
1n, // [!code focus]
value, // [!code focus]
"0x", // [!code focus]
); // [!code focus]
await app.createVoucher(voucher);
return "accept";
});
```

## Returns

Type: `Voucher`

## Parameters

Type: `Address`

ERC-1155 token address.

Type: `Address`

Source address.

Type: `Address`

Destination address.

Type: `bigint`

Token id.

Type: `bigint`

Token amount.

Type: `Hex`

Extra payload sent to the base layer.
46 changes: 46 additions & 0 deletions apps/docs/pages/wallet/create-erc20-transfer-voucher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# createERC20TransferVoucher

Utility to create a `Voucher` to transfer ERC-20 from the application to a destination address on the base layer.

## Usage

The example below shows how to create a `Voucher` to withdraw 1 CTSI to the `msg_sender` of the an input.

```ts twoslash
import { createApp } from "@deroll/app";
import { createERC20TransferVoucher } from "@deroll/wallet";
import { parseUnits } from "viem";

// create app
const app = createApp({ url: "http://127.0.0.1:5004" });

const token = "0x491604c0FDF08347Dd1fa4Ee062a822A5DD06B5D"; // CTSI address
app.addAdvanceHandler(async ({ metadata }) => {
const value = parseUnits("1", 18);
const voucher = createERC20TransferVoucher( // [!code focus]
token, // [!code focus]
metadata.msg_sender, // [!code focus]
value, // [!code focus]
); // [!code focus]
await app.createVoucher(voucher);
return "accept";
});
```

## Returns

Type: `Voucher`

## Parameters

Type: `Address`

ERC-20 token address.

Type: `Address`

Destination address.

Type: `bigint`

Amount to transfer.
50 changes: 50 additions & 0 deletions apps/docs/pages/wallet/create-erc721-transfer-voucher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# createERC721TransferVoucher

Utility to create a `Voucher` to transfer ERC-721 from the application to a destination address on the base layer.

## Usage

The example below shows how to create a `Voucher` to withdraw 1 CTSI to the `msg_sender` of the an input.

```ts twoslash
import { createApp } from "@deroll/app";
import { createERC721TransferVoucher } from "@deroll/wallet";

// create app
const app = createApp({ url: "http://127.0.0.1:5004" });

const application = "0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e";
const token = "0xc6582A9b48F211Fa8c2B5b16CB615eC39bcA653B"; // ERC-721 address
app.addAdvanceHandler(async ({ metadata }) => {
const voucher = createERC721TransferVoucher( // [!code focus]
token, // [!code focus]
application, // [!code focus]
metadata.msg_sender, // [!code focus]
1n, // [!code focus]
); // [!code focus]
await app.createVoucher(voucher);
return "accept";
});
```

## Returns

Type: `Voucher`

## Parameters

Type: `Address`

ERC-721 token address.

Type: `Address`

Source address.

Type: `Address`

Destination address.

Type: `bigint`

Token id.
23 changes: 20 additions & 3 deletions apps/docs/pages/wallet/create-wallet.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# createWallet

:::warning
Work in progress
:::
Creates a wallet object that provides a handler to process asssets deposits and an in-memory wallet management data structure.

## Usage

The example below creates a new wallet management object, and attaches a handler to automatically process assets deposits.

```ts twoslash
import { createApp } from "@deroll/app";
import { createWallet } from "@deroll/wallet";

// create app
const app = createApp({ url: "http://127.0.0.1:5004" });

// create wallet // [!code focus]
const wallet = createWallet(); // [!code focus]

app.addAdvanceHandler(wallet.handler); // [!code focus]
```

## Returns

Type: `WalletApp`

## Parameters

None
46 changes: 46 additions & 0 deletions apps/docs/pages/wallet/create-withdraw-ether-voucher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# createWithdrawEtherVoucher

Utility to create a `Voucher` to withdraw ether to a destination address on the base layer.

## Usage

The example below shows how to create a `Voucher` to withdraw 1 ether to the `msg_sender` of the an input.

```ts twoslash
import { createApp } from "@deroll/app";
import { createWithdrawEtherVoucher } from "@deroll/wallet";
import { parseEther } from "viem";

// create app
const app = createApp({ url: "http://127.0.0.1:5004" });

const application = "0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e";
app.addAdvanceHandler(async ({ metadata }) => {
const value = parseEther("1");
const voucher = createWithdrawEtherVoucher( // [!code focus]
application, // [!code focus]
metadata.msg_sender, // [!code focus]
value, // [!code focus]
); // [!code focus]
await app.createVoucher(voucher);
return "accept";
});
```

## Returns

Type: `Voucher`

## Parameters

Type: `Address`

Application address.

Type: `Address`

Destination address.

Type: `bigint`

Amount to transfer.
42 changes: 39 additions & 3 deletions apps/docs/pages/wallet/erc1155-balance-of.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
# erc1155BalanceOf

:::warning
Work in progress
:::
Returns an ERC-1155 balance of a token and user managed by a wallet module.

## Usage

The following example creates an inspect request handler that assumes the `payload` is an user address and just prints the balance of token id 1 of token `0x04d724738873CB6a86328D2EbAEb2079D715e61e`.

```ts twoslash
import { createApp } from "@deroll/app";
import { createWallet } from "@deroll/wallet";

// create app
const app = createApp({ url: "http://127.0.0.1:5004" });

// create wallet
const wallet = createWallet();

app.addAdvanceHandler(wallet.handler);

const token = "0x04d724738873CB6a86328D2EbAEb2079D715e61e"; // ERC-1155 address // [!code focus]
app.addInspectHandler(async ({ payload }) => { // [!code focus]
const address = payload; // [!code focus]
const balance = wallet.erc1155BalanceOf(token, address, 1n); // [!code focus]
console.log(balance); // [!code focus]
}); // [!code focus]
```

## Returns

Type: `bigint`

The ERC-1155 balance of the given token and address.

## Parameters

Type: `Address`

The ERC-1155 token address.

Type: `string`

The address of the user to get the balance from.

Type: `bigint`

The id of the token to check balance.
Loading

0 comments on commit 0a25240

Please sign in to comment.