-
Notifications
You must be signed in to change notification settings - Fork 370
/
Copy pathdefault.ts
428 lines (381 loc) · 11.2 KB
/
default.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
import { getAppMetadata } from "@walletconnect/utils";
import {
PartialTezosDelegationOperation,
PartialTezosIncreasePaidStorageOperation,
PartialTezosOriginationOperation as PartialTezosOriginationOperationOriginal,
PartialTezosTransactionOperation,
TezosOperationType,
} from "@airgap/beacon-types";
import { ScriptedContracts } from "@taquito/rpc";
if (!process.env.NEXT_PUBLIC_PROJECT_ID)
throw new Error("`NEXT_PUBLIC_PROJECT_ID` env variable is missing.");
export const DEFAULT_MAIN_CHAINS = [
// mainnets
"eip155:1",
"eip155:10",
"eip155:100",
"eip155:137",
"eip155:324",
"eip155:42161",
"eip155:42220",
"cosmos:cosmoshub-4",
"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"polkadot:91b171bb158e2d3848fa23a9f1c25182",
"mvx:1",
"tron:0x2b6653dc",
"tezos:mainnet",
"kadena:mainnet01",
];
export const DEFAULT_TEST_CHAINS = [
// testnets
"eip155:5",
"eip155:11155111",
"eip155:280",
"eip155:420",
"eip155:80001",
"eip155:421611",
"eip155:44787",
"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
"polkadot:e143f23803ac50e8f6f8e62695d1ce9e",
"near:testnet",
"mvx:D",
"tron:0xcd8690dc",
"tezos:ghostnet",
"kadena:testnet04",
];
export const DEFAULT_CHAINS = [...DEFAULT_MAIN_CHAINS, ...DEFAULT_TEST_CHAINS];
export const DEFAULT_PROJECT_ID = process.env.NEXT_PUBLIC_PROJECT_ID;
export const DEFAULT_RELAY_URL = process.env.NEXT_PUBLIC_RELAY_URL;
export const DEFAULT_LOGGER = "debug";
export const DEFAULT_APP_METADATA = {
name: "React App",
description: "React App for WalletConnect",
url: "https://walletconnect.com/",
icons: ["https://avatars.githubusercontent.com/u/37784886"],
verifyUrl: "https://verify.walletconnect.com",
};
/**
* EIP5792
*/
export const DEFAULT_EIP5792_METHODS = {
WALLET_GET_CAPABILITIES: "wallet_getCapabilities",
WALLET_SEND_CALLS: "wallet_sendCalls",
WALLET_GET_CALLS_STATUS: "wallet_getCallsStatus",
} as const;
export type SendCallsParams = {
version: string;
chainId: `0x${string}`; // Hex chain id
from: `0x${string}`;
calls: {
to?: `0x${string}` | undefined;
data?: `0x${string}` | undefined;
value?: `0x${string}` | undefined; // Hex value
}[];
capabilities?: Record<string, any> | undefined;
};
// capability names as string literals
export type CapabilityName = "atomicBatch" | "paymasterService" | "sessionKey";
// Capability type where each key is a capability name and value has `supported` field
export type Capabilities = {
[K in CapabilityName]: {
supported: boolean;
};
};
// GetCapabilitiesResult type using mapped types
export type GetCapabilitiesResult = Record<string, Capabilities>;
export type GetCallsResult = {
status: "PENDING" | "CONFIRMED";
receipts?: {
logs: {
address: `0x${string}`;
data: `0x${string}`;
topics: `0x${string}`[];
}[];
status: `0x${string}`; // Hex 1 or 0 for success or failure, respectively
blockHash: `0x${string}`;
blockNumber: `0x${string}`;
gasUsed: `0x${string}`;
transactionHash: `0x${string}`;
}[];
};
/**
* EIP7715
*/
export const DEFAULT_EIP7715_METHODS = {
WALLET_GRANT_PERMISSIONS: "wallet_grantPermissions",
} as const;
export type WalletGrantPermissionsParameters = {
signer?:
| {
type: string;
data?: unknown | undefined;
}
| undefined;
permissions: readonly {
data: unknown;
policies: readonly {
data: unknown;
type: string;
}[];
required?: boolean | undefined;
type: string;
}[];
expiry: number;
};
export type WalletGrantPermissionsReturnType = {
expiry: number;
factory?: `0x${string}` | undefined;
factoryData?: string | undefined;
grantedPermissions: readonly {
data: unknown;
policies: readonly {
data: unknown;
type: string;
}[];
required?: boolean | undefined;
type: string;
}[];
permissionsContext: string;
signerData?:
| {
userOpBuilder?: `0x${string}` | undefined;
submitToAddress?: `0x${string}` | undefined;
}
| undefined;
};
/**
* EIP155
*/
export const DEFAULT_EIP155_METHODS = {
ETH_SEND_TRANSACTION: "eth_sendTransaction",
PERSONAL_SIGN: "personal_sign",
};
export const DEFAULT_EIP155_OPTIONAL_METHODS = {
ETH_SIGN_TRANSACTION: "eth_signTransaction",
ETH_SIGN: "eth_sign",
ETH_SIGN_TYPED_DATA: "eth_signTypedData",
ETH_SIGN_TYPED_DATA_V4: "eth_signTypedData_v4",
} as const;
export const DEFAULT_OPTIONAL_METHODS = {
...DEFAULT_EIP155_OPTIONAL_METHODS,
...DEFAULT_EIP5792_METHODS,
...DEFAULT_EIP7715_METHODS,
};
export enum DEFAULT_EIP_155_EVENTS {
ETH_CHAIN_CHANGED = "chainChanged",
ETH_ACCOUNTS_CHANGED = "accountsChanged",
}
/**
* COSMOS
*/
export enum DEFAULT_COSMOS_METHODS {
COSMOS_SIGN_DIRECT = "cosmos_signDirect",
COSMOS_SIGN_AMINO = "cosmos_signAmino",
}
export enum DEFAULT_COSMOS_EVENTS {}
/**
* SOLANA
*/
export enum DEFAULT_SOLANA_METHODS {
SOL_SIGN_TRANSACTION = "solana_signTransaction",
SOL_SIGN_MESSAGE = "solana_signMessage",
}
export enum DEFAULT_SOLANA_EVENTS {}
/**
* POLKADOT
*/
export enum DEFAULT_POLKADOT_METHODS {
POLKADOT_SIGN_TRANSACTION = "polkadot_signTransaction",
POLKADOT_SIGN_MESSAGE = "polkadot_signMessage",
}
export enum DEFAULT_POLKADOT_EVENTS {}
/**
* NEAR
*/
export enum DEFAULT_NEAR_METHODS {
NEAR_SIGN_IN = "near_signIn",
NEAR_SIGN_OUT = "near_signOut",
NEAR_GET_ACCOUNTS = "near_getAccounts",
NEAR_SIGN_AND_SEND_TRANSACTION = "near_signAndSendTransaction",
NEAR_SIGN_AND_SEND_TRANSACTIONS = "near_signAndSendTransactions",
}
export enum DEFAULT_NEAR_EVENTS {}
/**
* MULTIVERSX
*/
export enum DEFAULT_MULTIVERSX_METHODS {
MULTIVERSX_SIGN_TRANSACTION = "mvx_signTransaction",
MULTIVERSX_SIGN_TRANSACTIONS = "mvx_signTransactions",
MULTIVERSX_SIGN_MESSAGE = "mvx_signMessage",
MULTIVERSX_SIGN_LOGIN_TOKEN = "mvx_signLoginToken",
MULTIVERSX_SIGN_NATIVE_AUTH_TOKEN = "mvx_signNativeAuthToken",
MULTIVERSX_CANCEL_ACTION = "mvx_cancelAction",
}
export enum DEFAULT_MULTIVERSX_EVENTS {}
/**
* TRON
*/
export enum DEFAULT_TRON_METHODS {
TRON_SIGN_TRANSACTION = "tron_signTransaction",
TRON_SIGN_MESSAGE = "tron_signMessage",
}
export enum DEFAULT_TRON_EVENTS {}
/**
* TEZOS
*/
// Can be removed when the fix for Origination is released:
// https://github.com/airgap-it/beacon-sdk/pull/806
interface PartialTezosOriginationOperation
extends Omit<PartialTezosOriginationOperationOriginal, "script"> {
script: ScriptedContracts;
}
export enum DEFAULT_TEZOS_METHODS {
GET_ACCOUNTS = "tezos_getAccounts",
SIGN = "tezos_sign",
SEND = "tezos_send",
SEND_TRANSACTION = "tezos_send:transaction",
SEND_ORGINATION = "tezos_send:origination",
SEND_CONTRACT_CALL = "tezos_send:contract_call",
SEND_DELEGATION = "tezos_send:delegation",
SEND_UNDELEGATION = "tezos_send:undelegation",
SEND_STAKE = "tezos_send:stake",
SEND_UNSTAKE = "tezos_send:unstake",
SEND_FINALIZE = "tezos_send:finalize",
SEND_INCREASE_PAID_STORAGE = "tezos_send:increase_paid_storage",
}
const tezosTransactionOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination: "tz3ZmB8oWUmi8YZXgeRpgAcPnEMD8VgUa4Ve", // Tezos Foundation Ghost Baker
amount: "100000",
};
const tezosOriginationOperation: PartialTezosOriginationOperation = {
kind: TezosOperationType.ORIGINATION,
balance: "1",
script: {
// This contract adds the parameter to the storage value
code: [
{ prim: "parameter", args: [{ prim: "int" }] },
{ prim: "storage", args: [{ prim: "int" }] },
{
prim: "code",
args: [
[
{ prim: "DUP" }, // Duplicate the parameter (parameter is pushed onto the stack)
{ prim: "CAR" }, // Access the parameter from the stack (parameter is on top)
{ prim: "DIP", args: [[{ prim: "CDR" }]] }, // Access the storage value (storage is on the stack)
{ prim: "ADD" }, // Add the parameter to the storage value
{ prim: "NIL", args: [{ prim: "operation" }] }, // Create an empty list of operations
{ prim: "PAIR" }, // Pair the updated storage with the empty list of operations
],
],
},
],
storage: { int: "10" },
},
};
const tezosContractCallOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination: "[contract address]",
amount: "0",
parameters: { entrypoint: "default", value: { int: "20" } }, // Add 20 to the current storage value
};
const tezosDelegationOperation: PartialTezosDelegationOperation = {
kind: TezosOperationType.DELEGATION,
delegate: "tz3ZmB8oWUmi8YZXgeRpgAcPnEMD8VgUa4Ve", // Tezos Foundation Ghost Baker. Cannot delegate to ourself as that would block undelegation
};
const tezosUndelegationOperation: PartialTezosDelegationOperation = {
kind: TezosOperationType.DELEGATION,
};
const tezosStakeOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination: "[own adress]",
amount: "1000000",
parameters: {
entrypoint: "stake",
value: { prim: "Unit" },
},
};
const tezosUnstakeOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination: "[own adress]",
amount: "1000000",
parameters: {
entrypoint: "unstake",
value: { prim: "Unit" },
},
};
const tezosFinalizeOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination: "[own adress]",
amount: "0",
parameters: {
entrypoint: "finalize_unstake",
value: { prim: "Unit" },
},
};
const TezosIncreasePaidStorageOperation: PartialTezosIncreasePaidStorageOperation =
{
kind: TezosOperationType.INCREASE_PAID_STORAGE,
amount: "10",
destination: "[contract address]",
};
export const TEZOS_SAMPLES = {
"tezos_send:transaction": tezosTransactionOperation,
"tezos_send:origination": tezosOriginationOperation,
"tezos_send:contract_call": tezosContractCallOperation,
"tezos_send:delegation": tezosDelegationOperation,
"tezos_send:undelegation": tezosUndelegationOperation,
"tezos_send:stake": tezosStakeOperation,
"tezos_send:unstake": tezosUnstakeOperation,
"tezos_send:finalize": tezosFinalizeOperation,
"tezos_send:increase_paid_storage": TezosIncreasePaidStorageOperation,
};
export enum DEFAULT_TEZOS_EVENTS {}
export const DEFAULT_GITHUB_REPO_URL =
"https://github.com/WalletConnect/web-examples/tree/main/dapps/react-dapp-v2";
type RelayerType = {
value: string | undefined;
label: string;
};
/**
* KADENA
*/
export enum DEFAULT_KADENA_METHODS {
KADENA_GET_ACCOUNTS = "kadena_getAccounts_v1",
KADENA_SIGN = "kadena_sign_v1",
KADENA_QUICKSIGN = "kadena_quicksign_v1",
}
export enum DEFAULT_KADENA_EVENTS {}
export const REGIONALIZED_RELAYER_ENDPOINTS: RelayerType[] = [
{
value: DEFAULT_RELAY_URL,
label: "Default",
},
{
value: "wss://us-east-1.relay.walletconnect.com",
label: "US",
},
{
value: "wss://eu-central-1.relay.walletconnect.com",
label: "EU",
},
{
value: "wss://ap-southeast-1.relay.walletconnect.com",
label: "Asia Pacific",
},
];
export const ORIGIN_OPTIONS = [
{
value: getAppMetadata().url,
label: "VALID",
},
{
value: "https://invalid.origin",
label: "INVALID",
},
{
value: "unknown",
label: "UNKNOWN",
},
];