shogun-relay-sdk 1.0.0 → 1.0.1
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/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/modules/bridge.d.ts +146 -0
- package/dist/modules/bridge.js +74 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { NetworkModule } from './modules/network';
|
|
|
6
6
|
import { DealsModule } from './modules/deals';
|
|
7
7
|
import { RegistryModule } from './modules/registry';
|
|
8
8
|
import { UploadsModule } from './modules/uploads';
|
|
9
|
+
import { BridgeModule } from './modules/bridge';
|
|
9
10
|
export declare class ShogunRelaySDK {
|
|
10
11
|
private client;
|
|
11
12
|
system: SystemModule;
|
|
@@ -15,6 +16,7 @@ export declare class ShogunRelaySDK {
|
|
|
15
16
|
deals: DealsModule;
|
|
16
17
|
registry: RegistryModule;
|
|
17
18
|
uploads: UploadsModule;
|
|
19
|
+
bridge: BridgeModule;
|
|
18
20
|
constructor(config: ApiClientConfig);
|
|
19
21
|
setToken(token: string): void;
|
|
20
22
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const network_1 = require("./modules/network");
|
|
|
9
9
|
const deals_1 = require("./modules/deals");
|
|
10
10
|
const registry_1 = require("./modules/registry");
|
|
11
11
|
const uploads_1 = require("./modules/uploads");
|
|
12
|
+
const bridge_1 = require("./modules/bridge");
|
|
12
13
|
class ShogunRelaySDK {
|
|
13
14
|
constructor(config) {
|
|
14
15
|
this.client = new client_1.ApiClient(config);
|
|
@@ -19,6 +20,7 @@ class ShogunRelaySDK {
|
|
|
19
20
|
this.deals = new deals_1.DealsModule(this.client);
|
|
20
21
|
this.registry = new registry_1.RegistryModule(this.client);
|
|
21
22
|
this.uploads = new uploads_1.UploadsModule(this.client);
|
|
23
|
+
this.bridge = new bridge_1.BridgeModule(this.client);
|
|
22
24
|
}
|
|
23
25
|
setToken(token) {
|
|
24
26
|
this.client.setToken(token);
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ApiClient } from '../client';
|
|
2
|
+
export interface PendingWithdrawal {
|
|
3
|
+
user: string;
|
|
4
|
+
amount: string;
|
|
5
|
+
nonce: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
txHash?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface BridgeState {
|
|
10
|
+
currentStateRoot: string;
|
|
11
|
+
currentBatchId: string;
|
|
12
|
+
sequencer: string;
|
|
13
|
+
contractBalance: string;
|
|
14
|
+
contractBalanceEth: string;
|
|
15
|
+
}
|
|
16
|
+
export interface WithdrawalProof {
|
|
17
|
+
proof: string[];
|
|
18
|
+
batchId: string;
|
|
19
|
+
root: string;
|
|
20
|
+
withdrawal: {
|
|
21
|
+
user: string;
|
|
22
|
+
amount: string;
|
|
23
|
+
nonce: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface TransferResult {
|
|
27
|
+
from: string;
|
|
28
|
+
to: string;
|
|
29
|
+
amount: string;
|
|
30
|
+
txHash: string;
|
|
31
|
+
fromBalance: string;
|
|
32
|
+
toBalance: string;
|
|
33
|
+
}
|
|
34
|
+
export interface WithdrawalResult {
|
|
35
|
+
user: string;
|
|
36
|
+
amount: string;
|
|
37
|
+
nonce: string;
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}
|
|
40
|
+
export interface BatchResult {
|
|
41
|
+
batchId: string;
|
|
42
|
+
root: string;
|
|
43
|
+
withdrawalCount: number;
|
|
44
|
+
txHash: string;
|
|
45
|
+
blockNumber: number;
|
|
46
|
+
}
|
|
47
|
+
export declare class BridgeModule {
|
|
48
|
+
private client;
|
|
49
|
+
constructor(client: ApiClient);
|
|
50
|
+
/**
|
|
51
|
+
* Get user's L2 balance
|
|
52
|
+
* @param userAddress User's Ethereum address
|
|
53
|
+
* @returns Balance in wei and ETH
|
|
54
|
+
*/
|
|
55
|
+
getBalance(userAddress: string): Promise<{
|
|
56
|
+
success: boolean;
|
|
57
|
+
user: string;
|
|
58
|
+
balance: string;
|
|
59
|
+
balanceEth: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Transfer balance from one user to another (L2 -> L2)
|
|
63
|
+
* @param params Transfer parameters
|
|
64
|
+
* @returns Transfer result
|
|
65
|
+
*/
|
|
66
|
+
transfer(params: {
|
|
67
|
+
from: string;
|
|
68
|
+
to: string;
|
|
69
|
+
amount: string;
|
|
70
|
+
message: string;
|
|
71
|
+
seaSignature: string;
|
|
72
|
+
ethSignature: string;
|
|
73
|
+
gunPubKey: string;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
success: boolean;
|
|
76
|
+
transfer: TransferResult;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Request withdrawal from L2 (creates pending withdrawal)
|
|
80
|
+
* @param params Withdrawal parameters
|
|
81
|
+
* @returns Withdrawal result
|
|
82
|
+
*/
|
|
83
|
+
withdraw(params: {
|
|
84
|
+
user: string;
|
|
85
|
+
amount: string;
|
|
86
|
+
nonce: string;
|
|
87
|
+
message: string;
|
|
88
|
+
seaSignature: string;
|
|
89
|
+
ethSignature: string;
|
|
90
|
+
gunPubKey: string;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
success: boolean;
|
|
93
|
+
withdrawal: WithdrawalResult;
|
|
94
|
+
message: string;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Get all pending withdrawals (waiting for batch submission)
|
|
98
|
+
* @returns List of pending withdrawals
|
|
99
|
+
*/
|
|
100
|
+
getPendingWithdrawals(): Promise<{
|
|
101
|
+
success: boolean;
|
|
102
|
+
withdrawals: PendingWithdrawal[];
|
|
103
|
+
count: number;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Generate Merkle proof for a withdrawal
|
|
107
|
+
* The withdrawal must be included in the latest batch
|
|
108
|
+
* @param user User address
|
|
109
|
+
* @param amount Withdrawal amount
|
|
110
|
+
* @param nonce Withdrawal nonce
|
|
111
|
+
* @returns Merkle proof
|
|
112
|
+
*/
|
|
113
|
+
getProof(user: string, amount: string, nonce: string): Promise<{
|
|
114
|
+
success: boolean;
|
|
115
|
+
proof: WithdrawalProof;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Get current bridge state (root, batchId, contract balance, etc.)
|
|
119
|
+
* @returns Bridge state
|
|
120
|
+
*/
|
|
121
|
+
getState(): Promise<{
|
|
122
|
+
success: boolean;
|
|
123
|
+
state: BridgeState;
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Submit a batch with Merkle root (sequencer only)
|
|
127
|
+
* @returns Batch submission result
|
|
128
|
+
*/
|
|
129
|
+
submitBatch(): Promise<{
|
|
130
|
+
success: boolean;
|
|
131
|
+
batch: BatchResult;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Get deposit instructions (informational endpoint)
|
|
135
|
+
* Note: Actual deposits should be done on-chain by calling the contract's deposit() function
|
|
136
|
+
* @param amount Amount to deposit
|
|
137
|
+
* @returns Deposit instructions
|
|
138
|
+
*/
|
|
139
|
+
getDepositInstructions(amount: string): Promise<{
|
|
140
|
+
success: boolean;
|
|
141
|
+
message: string;
|
|
142
|
+
contractAddress: string;
|
|
143
|
+
amount: string;
|
|
144
|
+
instructions: string;
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BridgeModule = void 0;
|
|
4
|
+
class BridgeModule {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Get user's L2 balance
|
|
10
|
+
* @param userAddress User's Ethereum address
|
|
11
|
+
* @returns Balance in wei and ETH
|
|
12
|
+
*/
|
|
13
|
+
async getBalance(userAddress) {
|
|
14
|
+
return this.client.get(`/api/v1/bridge/balance/${userAddress}`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Transfer balance from one user to another (L2 -> L2)
|
|
18
|
+
* @param params Transfer parameters
|
|
19
|
+
* @returns Transfer result
|
|
20
|
+
*/
|
|
21
|
+
async transfer(params) {
|
|
22
|
+
return this.client.post('/api/v1/bridge/transfer', params);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Request withdrawal from L2 (creates pending withdrawal)
|
|
26
|
+
* @param params Withdrawal parameters
|
|
27
|
+
* @returns Withdrawal result
|
|
28
|
+
*/
|
|
29
|
+
async withdraw(params) {
|
|
30
|
+
return this.client.post('/api/v1/bridge/withdraw', params);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get all pending withdrawals (waiting for batch submission)
|
|
34
|
+
* @returns List of pending withdrawals
|
|
35
|
+
*/
|
|
36
|
+
async getPendingWithdrawals() {
|
|
37
|
+
return this.client.get('/api/v1/bridge/pending-withdrawals');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate Merkle proof for a withdrawal
|
|
41
|
+
* The withdrawal must be included in the latest batch
|
|
42
|
+
* @param user User address
|
|
43
|
+
* @param amount Withdrawal amount
|
|
44
|
+
* @param nonce Withdrawal nonce
|
|
45
|
+
* @returns Merkle proof
|
|
46
|
+
*/
|
|
47
|
+
async getProof(user, amount, nonce) {
|
|
48
|
+
return this.client.get(`/api/v1/bridge/proof/${user}/${amount}/${nonce}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get current bridge state (root, batchId, contract balance, etc.)
|
|
52
|
+
* @returns Bridge state
|
|
53
|
+
*/
|
|
54
|
+
async getState() {
|
|
55
|
+
return this.client.get('/api/v1/bridge/state');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Submit a batch with Merkle root (sequencer only)
|
|
59
|
+
* @returns Batch submission result
|
|
60
|
+
*/
|
|
61
|
+
async submitBatch() {
|
|
62
|
+
return this.client.post('/api/v1/bridge/submit-batch');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get deposit instructions (informational endpoint)
|
|
66
|
+
* Note: Actual deposits should be done on-chain by calling the contract's deposit() function
|
|
67
|
+
* @param amount Amount to deposit
|
|
68
|
+
* @returns Deposit instructions
|
|
69
|
+
*/
|
|
70
|
+
async getDepositInstructions(amount) {
|
|
71
|
+
return this.client.post('/api/v1/bridge/deposit', { amount });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.BridgeModule = BridgeModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogun-relay-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "SDK for interacting with Shogun Relay API - HTTP client for IPFS, deals, registry, and network operations",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"form-data": "^4.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"@types/node": "^20.0.0",
|
|
46
|
+
"typescript": "^5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=16.0.0"
|