UNPKG

10.3 kBPlain TextView Raw
1import { Address, AssetId, BigNumber, Bytes32, PublicIdentifier, SolidityValueType } from "./basic";
2import { AppState } from "./contracts";
3
4import { AppABIEncodings, AppInstanceJson } from "./app";
5import { OutcomeType } from "./contracts";
6import { PublicParams, PublicResults } from "./public";
7import { StateChannelJSON } from "./state";
8import { MinimalTransaction } from "./commitments";
9import { enumify } from "./utils";
10
11////////////////////////////////////////
12
13type CreateChannelParams = {
14 owners: PublicIdentifier[];
15 chainId: number;
16};
17
18type CreateChannelResult = {
19 multisigAddress: Address;
20 owners?: Address[];
21};
22
23////////////////////////////////////////
24
25type DepositParams = PublicParams.Deposit;
26
27type DepositResult = PublicResults.Deposit;
28
29////////////////////////////////////////
30
31type DeployStateDepositHolderParams = {
32 multisigAddress: Address;
33 retryCount?: number;
34};
35
36type DeployStateDepositHolderResult = {
37 transactionHash: Bytes32;
38};
39
40////////////////////////////////////////
41
42type GetChannelAddressesParams = {};
43
44type GetChannelAddressesResult = {
45 multisigAddresses: Address[];
46};
47
48////////////////////////////////////////
49
50type GetAppInstanceDetailsParams = {
51 appIdentityHash: Bytes32;
52};
53
54type GetAppInstanceDetailsResult = {
55 appInstance: AppInstanceJson;
56};
57
58////////////////////////////////////////
59
60type GetAppInstancesParams = {
61 multisigAddress: Address;
62};
63
64type GetAppInstancesResult = {
65 appInstances: AppInstanceJson[];
66};
67
68////////////////////////////////////////
69
70type GetStateDepositHolderAddressParams = {
71 owners: Address[]; // [initiator, responder]
72 chainId: number;
73};
74
75type GetStateDepositHolderAddressResult = {
76 address: Address;
77};
78
79////////////////////////////////////////
80
81type GetFreeBalanceStateParams = {
82 multisigAddress: Address;
83 assetId?: Address;
84};
85
86type GetFreeBalanceStateResult = {
87 [signerAddress: string]: BigNumber;
88};
89
90////////////////////////////////////////
91
92type GetTokenIndexedFreeBalanceStatesParams = {
93 multisigAddress: Address;
94};
95
96type GetTokenIndexedFreeBalanceStatesResult = {
97 [tokenAddress: string]: {
98 [s: string]: BigNumber;
99 };
100};
101
102////////////////////////////////////////
103
104type GetProposedAppInstanceParams = {
105 appIdentityHash: Bytes32;
106};
107
108type GetProposedAppInstanceResult = {
109 appInstance: AppInstanceJson;
110};
111
112////////////////////////////////////////
113
114type GetProposedAppInstancesParams = {
115 multisigAddress: Address;
116};
117
118type GetProposedAppInstancesResult = {
119 appInstances: AppInstanceJson[];
120};
121
122////////////////////////////////////////
123
124type GetStateChannelParams = {
125 multisigAddress: Address;
126};
127
128type GetStateChannelResult = {
129 data: StateChannelJSON;
130};
131
132////////////////////////////////////////
133
134type InstallParams = {
135 appIdentityHash: Bytes32;
136 multisigAddress: Address;
137 protocolMeta?: any;
138};
139
140type InstallResult = {
141 appInstance: AppInstanceJson;
142};
143
144////////////////////////////////////////
145
146type RequestDepositRightsParams = {
147 assetId?: Address;
148 multisigAddress: Address;
149};
150
151type RequestDepositRightsResult = {
152 appIdentityHash: Bytes32;
153 multisigAddress: Address;
154};
155
156////////////////////////////////////////
157
158type ProposeInstallParams = {
159 abiEncodings: AppABIEncodings;
160 appDefinition: Address;
161 defaultTimeout: BigNumber;
162 initialState: AppState;
163 initiatorDeposit: BigNumber;
164 initiatorDepositAssetId: AssetId;
165 meta?: any;
166 multisigAddress: Address;
167 outcomeType: OutcomeType;
168 responderIdentifier: PublicIdentifier;
169 responderDeposit: BigNumber;
170 responderDepositAssetId: AssetId;
171 stateTimeout?: BigNumber;
172 protocolMeta?: any;
173};
174
175type ProposeInstallResult = {
176 appIdentityHash: Bytes32;
177};
178
179////////////////////////////////////////
180
181type RejectInstallParams = {
182 appIdentityHash: Bytes32;
183 multisigAddress: Address;
184 reason?: string;
185};
186
187type RejectInstallResult = {};
188
189////////////////////////////////////////
190
191type TakeActionParams = {
192 appIdentityHash: Bytes32;
193 action: SolidityValueType;
194 multisigAddress: Address;
195 stateTimeout?: BigNumber;
196 protocolMeta?: any;
197};
198
199type TakeActionResult = {
200 newState: SolidityValueType;
201};
202
203////////////////////////////////////////
204
205type UninstallParams = {
206 appIdentityHash: Bytes32;
207 multisigAddress: Address;
208 action?: SolidityValueType;
209 protocolMeta?: any;
210};
211
212type UninstallResult = {
213 appIdentityHash: Bytes32;
214 multisigAddress: Address;
215 uninstalledApp: AppInstanceJson;
216 action?: SolidityValueType;
217};
218
219////////////////////////////////////////
220
221type RescindDepositRightsParams = {
222 assetId?: Address;
223 appIdentityHash?: Bytes32;
224 multisigAddress: Address;
225};
226
227type RescindDepositRightsResult = {
228 freeBalance: {
229 [s: string]: BigNumber;
230 };
231};
232
233////////////////////////////////////////
234
235type WithdrawParams = {
236 multisigAddress: Address;
237 recipient?: Address;
238 amount: BigNumber;
239 tokenAddress?: Address;
240};
241
242type WithdrawResult = {
243 recipient: Address;
244 txHash: Bytes32;
245};
246
247////////////////////////////////////////
248
249type WithdrawCommitmentParams = WithdrawParams;
250
251type WithdrawCommitmentResult = {
252 transaction: MinimalTransaction;
253};
254
255////////////////////////////////////////
256
257type SyncParams = {
258 multisigAddress: Address;
259 protocolMeta?: any;
260};
261
262type SyncResult = {
263 syncedChannel: StateChannelJSON;
264};
265
266////////////////////////////////////////
267// exports
268
269export const MethodNames = enumify({
270 chan_create: "chan_create",
271 chan_deployStateDepositHolder: "chan_deployStateDepositHolder",
272 chan_getAppInstance: "chan_getAppInstance",
273 chan_getAppInstances: "chan_getAppInstances",
274 chan_getChannelAddresses: "chan_getChannelAddresses",
275 chan_getFreeBalanceState: "chan_getFreeBalanceState",
276 chan_getProposedAppInstance: "chan_getProposedAppInstance",
277 chan_getProposedAppInstances: "chan_getProposedAppInstances",
278 chan_getStateChannel: "chan_getStateChannel",
279 chan_getStateDepositHolderAddress: "chan_getStateDepositHolderAddress",
280 chan_getTokenIndexedFreeBalanceStates: "chan_getTokenIndexedFreeBalanceStates",
281 chan_install: "chan_install",
282 chan_proposeInstall: "chan_proposeInstall",
283 chan_rejectInstall: "chan_rejectInstall",
284 chan_sync: "chan_sync",
285 chan_takeAction: "chan_takeAction",
286 chan_uninstall: "chan_uninstall",
287 chan_withdraw: "chan_withdraw",
288 chan_withdrawCommitment: "chan_withdrawCommitment",
289});
290type MethodNames = typeof MethodNames[keyof typeof MethodNames];
291export type MethodName = keyof typeof MethodNames;
292
293export namespace MethodParams {
294 export type CreateChannel = CreateChannelParams;
295 export type DeployStateDepositHolder = DeployStateDepositHolderParams;
296 export type Deposit = DepositParams;
297 export type GetAppInstanceDetails = GetAppInstanceDetailsParams;
298 export type GetAppInstances = GetAppInstancesParams;
299 export type GetChannelAddresses = GetChannelAddressesParams;
300 export type GetFreeBalanceState = GetFreeBalanceStateParams;
301 export type GetProposedAppInstance = GetProposedAppInstanceParams;
302 export type GetProposedAppInstances = GetProposedAppInstancesParams;
303 export type GetStateChannel = GetStateChannelParams;
304 export type GetStateDepositHolderAddress = GetStateDepositHolderAddressParams;
305 export type GetTokenIndexedFreeBalanceStates = GetTokenIndexedFreeBalanceStatesParams;
306 export type Install = InstallParams;
307 export type ProposeInstall = ProposeInstallParams;
308 export type RejectInstall = RejectInstallParams;
309 export type RequestDepositRights = RequestDepositRightsParams;
310 export type RescindDepositRights = RescindDepositRightsParams;
311 export type TakeAction = TakeActionParams;
312 export type Sync = SyncParams;
313 export type Uninstall = UninstallParams;
314 export type Withdraw = WithdrawParams;
315 export type WithdrawCommitment = WithdrawCommitmentParams;
316}
317
318export type MethodParam =
319 | CreateChannelParams
320 | DeployStateDepositHolderParams
321 | DepositParams
322 | GetAppInstanceDetailsParams
323 | GetAppInstancesParams
324 | GetChannelAddressesParams
325 | GetFreeBalanceStateParams
326 | GetProposedAppInstanceParams
327 | GetProposedAppInstancesParams
328 | GetStateChannelParams
329 | GetStateDepositHolderAddressParams
330 | GetTokenIndexedFreeBalanceStatesParams
331 | InstallParams
332 | ProposeInstallParams
333 | RejectInstallParams
334 | RequestDepositRightsParams
335 | RescindDepositRightsParams
336 | SyncParams
337 | TakeActionParams
338 | UninstallParams
339 | WithdrawParams
340 | WithdrawCommitmentParams;
341
342export namespace MethodResults {
343 export type CreateChannel = CreateChannelResult;
344 export type DeployStateDepositHolder = DeployStateDepositHolderResult;
345 export type Deposit = DepositResult;
346 export type GetAppInstanceDetails = GetAppInstanceDetailsResult;
347 export type GetAppInstances = GetAppInstancesResult;
348 export type GetChannelAddresses = GetChannelAddressesResult;
349 export type GetFreeBalanceState = GetFreeBalanceStateResult;
350 export type GetProposedAppInstance = GetProposedAppInstanceResult;
351 export type GetProposedAppInstances = GetProposedAppInstancesResult;
352 export type GetStateChannel = GetStateChannelResult;
353 export type GetStateDepositHolderAddress = GetStateDepositHolderAddressResult;
354 export type GetTokenIndexedFreeBalanceStates = GetTokenIndexedFreeBalanceStatesResult;
355 export type Install = InstallResult;
356 export type ProposeInstall = ProposeInstallResult;
357 export type RejectInstall = RejectInstallResult;
358 export type RequestDepositRights = RequestDepositRightsResult;
359 export type RescindDepositRights = RescindDepositRightsResult;
360 export type Sync = SyncResult;
361 export type TakeAction = TakeActionResult;
362 export type Uninstall = UninstallResult;
363 export type Withdraw = WithdrawResult;
364 export type WithdrawCommitment = WithdrawCommitmentResult;
365}
366
367export type MethodResult =
368 | CreateChannelResult
369 | DeployStateDepositHolderResult
370 | DepositResult
371 | GetAppInstanceDetailsResult
372 | GetAppInstancesResult
373 | GetChannelAddressesResult
374 | GetFreeBalanceStateResult
375 | GetProposedAppInstanceResult
376 | GetProposedAppInstancesResult
377 | GetStateChannelResult
378 | GetStateDepositHolderAddressResult
379 | GetTokenIndexedFreeBalanceStatesResult
380 | InstallResult
381 | ProposeInstallResult
382 | RejectInstallResult
383 | RequestDepositRightsResult
384 | RescindDepositRightsResult
385 | SyncResult
386 | TakeActionResult
387 | UninstallResult
388 | WithdrawResult
389 | WithdrawCommitmentResult;