-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,324 additions
and
48 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
apps/docs/pages/wallet/create-erc1155-batch-transfer-voucher.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
apps/docs/pages/wallet/create-erc1155-single-transfer-voucher.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.