@vetro-protocol/gateway 1.0.0-beta → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -67
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vetro-protocol/gateway
|
|
2
2
|
|
|
3
|
-
Vetro Protocol gateway actions for viem.
|
|
3
|
+
Vetro Protocol gateway actions for viem clients. Mints pegged tokens (VUSD, vetBTC) from whitelisted underlying assets and handles redemptions back out.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,49 +8,42 @@ Vetro Protocol gateway actions for viem. Wraps the VUSD and vetBTC gateways with
|
|
|
8
8
|
pnpm add @vetro-protocol/gateway viem viem-erc20
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Overview
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// gateways is an array of { address, pegBaseSymbol } entries:
|
|
19
|
-
// { address: "0xDaD5…16F", pegBaseSymbol: "USD" } // VUSD
|
|
20
|
-
// { address: "0xCBA2…faB", pegBaseSymbol: "BTC" } // vetBTC
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Pass the address you want directly as `gatewayAddress` to any wallet action.
|
|
13
|
+
- Two gateways ship by default — the VUSD gateway and the vetBTC gateway — exported as `gateways` (with `address` + `pegBaseSymbol`) and `gatewayAddresses` (just the addresses).
|
|
14
|
+
- `deposit` mints the pegged token: checks `previewDeposit` for the expected output, runs an allowance + approval if needed, then calls `deposit(tokenIn, amountIn, minPeggedTokenOut, receiver)`.
|
|
15
|
+
- Redemptions follow the gateway's two-step flow: `requestRedeem` opens a request, `redeem` finalises it once the optional withdrawal delay has elapsed (or immediately if the caller is on the instant-redeem whitelist), and `cancelRedeemRequest` aborts an open request.
|
|
16
|
+
- Read actions cover everything a UI needs to drive these flows: previews, fee getters, request lookup, treasury / pegged-token addresses, and withdrawal-delay configuration.
|
|
24
17
|
|
|
25
18
|
## Usage
|
|
26
19
|
|
|
27
20
|
```ts
|
|
28
|
-
import { deposit,
|
|
29
|
-
import { gateways } from "@vetro-protocol/gateway";
|
|
21
|
+
import { deposit, gateways, previewDeposit } from "@vetro-protocol/gateway";
|
|
30
22
|
import { createPublicClient, createWalletClient, custom, http } from "viem";
|
|
31
|
-
import {
|
|
23
|
+
import { hemi } from "viem/chains";
|
|
32
24
|
|
|
33
|
-
const publicClient = createPublicClient({ chain:
|
|
25
|
+
const publicClient = createPublicClient({ chain: hemi, transport: http() });
|
|
34
26
|
const walletClient = createWalletClient({
|
|
35
|
-
chain:
|
|
27
|
+
chain: hemi,
|
|
36
28
|
transport: custom(window.ethereum),
|
|
37
29
|
});
|
|
38
30
|
|
|
39
|
-
const vusdGateway = gateways
|
|
31
|
+
const vusdGateway = gateways[0]; // VUSD gateway
|
|
40
32
|
|
|
41
|
-
// Quote
|
|
42
|
-
const
|
|
43
|
-
address: vusdGateway,
|
|
44
|
-
amountIn: 1_000_000n,
|
|
33
|
+
// 1. Quote how much VUSD a USDT deposit would mint.
|
|
34
|
+
const expectedOut = await previewDeposit(publicClient, {
|
|
35
|
+
address: vusdGateway.address,
|
|
36
|
+
amountIn: 1_000_000n, // 1 USDT (6 decimals)
|
|
37
|
+
tokenIn: "0x...", // USDT address
|
|
45
38
|
});
|
|
46
39
|
|
|
47
|
-
// Deposit
|
|
40
|
+
// 2. Deposit (approval handled automatically).
|
|
48
41
|
const { emitter, promise } = deposit(walletClient, {
|
|
49
42
|
amountIn: 1_000_000n,
|
|
50
|
-
gatewayAddress: vusdGateway,
|
|
51
|
-
minPeggedTokenOut:
|
|
43
|
+
gatewayAddress: vusdGateway.address,
|
|
44
|
+
minPeggedTokenOut: expectedOut,
|
|
52
45
|
receiver: "0x...",
|
|
53
|
-
tokenIn: "0x...",
|
|
46
|
+
tokenIn: "0x...",
|
|
54
47
|
});
|
|
55
48
|
|
|
56
49
|
emitter.on("user-signed-deposit", (hash) => console.log("tx hash:", hash));
|
|
@@ -61,46 +54,22 @@ emitter.on("deposit-transaction-succeeded", (receipt) =>
|
|
|
61
54
|
await promise;
|
|
62
55
|
```
|
|
63
56
|
|
|
64
|
-
The same actions are available via `.extend()` factories (`gatewayPublicActions()`, `gatewayWalletActions()`) for callers who prefer viem's extension pattern.
|
|
65
|
-
|
|
66
|
-
## Redeem model
|
|
67
|
-
|
|
68
|
-
Redeeming the pegged token back to collateral has two modes:
|
|
69
|
-
|
|
70
|
-
- **Instant** — if the account is on the instant-redeem whitelist (or withdrawal delay is disabled), `redeem` settles in one transaction.
|
|
71
|
-
- **Delayed** — otherwise, call `requestRedeem` to open a request, wait for the configured `withdrawalDelay`, then `redeem` claims the collateral. `cancelRedeemRequest` cancels a pending request.
|
|
72
|
-
|
|
73
|
-
Use the public actions to inspect state: `getMintFee`, `getRedeemFee`, `previewDeposit`, `previewRedeem`, `getMaxWithdraw`, `getPeggedToken`, `getTreasury`, `getWithdrawalDelay`, `getWithdrawalDelayEnabled`, `isInstantRedeemWhitelisted`, `getRedeemRequest`.
|
|
74
|
-
|
|
75
|
-
## Events
|
|
76
|
-
|
|
77
|
-
Every wallet action returns `{ emitter, promise }` (via `to-promise-event`). The emitter fires a granular lifecycle:
|
|
78
|
-
|
|
79
|
-
- `pre-approve` → `user-signed-approval` → `approve-transaction-succeeded` / `approve-transaction-reverted` (only when an ERC20 approval is needed)
|
|
80
|
-
- `pre-<action>` → `user-signed-<action>` → `<action>-transaction-succeeded` / `<action>-transaction-reverted`
|
|
81
|
-
- `user-signing-<action>-error` if the user rejects in the wallet
|
|
82
|
-
- `<action>-failed-validation` if input validation fails (payload is a human-readable reason)
|
|
83
|
-
- `unexpected-error` for anything that escapes
|
|
84
|
-
- `<action>-settled` always emitted in the `finally` block
|
|
85
|
-
|
|
86
|
-
Event-map types are exported per action: `DepositEvents`, `RedeemEvents`, `RequestRedeemEvents`, `CancelRedeemRequestEvents`.
|
|
57
|
+
The same actions are also available via `.extend()` factories (`gatewayPublicActions()`, `gatewayWalletActions()`) for callers who prefer viem's extension pattern.
|
|
87
58
|
|
|
88
59
|
## API
|
|
89
60
|
|
|
90
|
-
Public actions (
|
|
91
|
-
|
|
92
|
-
- `
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
- `
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- `
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
- `
|
|
105
|
-
|
|
106
|
-
Also exported: `gatewayAbi`, `gatewayAddresses`, `gateways`, and the `Gateway` type.
|
|
61
|
+
- Public actions (reads):
|
|
62
|
+
- `previewDeposit(client, params)` — expected pegged-token output for a deposit.
|
|
63
|
+
- `previewRedeem(client, params)` — expected underlying output for a redeem.
|
|
64
|
+
- `getMintFee(client, params)` / `getRedeemFee(client, params)` — current fees.
|
|
65
|
+
- `getMaxWithdraw(client, params)` — maximum withdrawable amount.
|
|
66
|
+
- `getPeggedToken(client, params)` — pegged-token address minted by the gateway.
|
|
67
|
+
- `getTreasury(client, params)` — treasury address backing the gateway.
|
|
68
|
+
- `getRedeemRequest(client, params)` — details for a specific redeem request.
|
|
69
|
+
- `getWithdrawalDelay(client, params)` / `getWithdrawalDelayEnabled(client, params)` — delay configuration.
|
|
70
|
+
- `isInstantRedeemWhitelisted(client, params)` — whether an account can bypass the delay.
|
|
71
|
+
- Wallet actions (writes): `deposit`, `requestRedeem`, `redeem`, `cancelRedeemRequest`. Each returns `{ emitter, promise }`.
|
|
72
|
+
- `gatewayPublicActions()` / `gatewayWalletActions()` — viem extension factories that wire the same actions onto a client via `.extend()`.
|
|
73
|
+
- `gatewayAbi` — the minimal ABI subset used by the package.
|
|
74
|
+
- Constants: `gateways`, `gatewayAddresses`.
|
|
75
|
+
- Types: `Gateway`, `CancelRedeemRequestEvents`, `DepositEvents`, `RedeemEvents`, `RequestRedeemEvents`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vetro-protocol/gateway",
|
|
3
|
-
"version": "1.0.0-beta",
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Vetro Protocol gateway actions for viem.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"_types",
|
|
11
11
|
"src"
|
|
12
12
|
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"directory": "packages/gateway",
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/vetro-protocol/vetro-monorepo.git"
|
|
17
|
+
},
|
|
13
18
|
"dependencies": {
|
|
14
19
|
"to-promise-event": "1.0.0",
|
|
15
20
|
"viem-erc20": "2.1.0"
|
|
@@ -31,7 +36,7 @@
|
|
|
31
36
|
"private": false,
|
|
32
37
|
"publishConfig": {
|
|
33
38
|
"access": "public",
|
|
34
|
-
"provenance":
|
|
39
|
+
"provenance": true
|
|
35
40
|
},
|
|
36
41
|
"type": "module",
|
|
37
42
|
"exports": {
|