-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
533 lines (478 loc) · 15.1 KB
/
index.js
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
import express from 'express'
export const router = express.Router()
import bodyParser from 'body-parser'
import dotenv from 'dotenv'
dotenv.config()
import { NFTBalance } from './functions/NFTBalance.js'
import { TokenBalance } from './functions/TokenBalance.js'
import { Relay } from './functions/Relay.js'
import { GetSelector } from './functions/GetSelector.js'
import { GetEncodedParams } from './functions/GetEncodedParams.js'
import { GetRelayNonce } from './functions/GetRelayNonce.js'
import { OwnedNFTs } from './functions/OwnedNFTs.js'
import { ContractOwners } from './functions/ContractOwners.js'
import { MerkleProof } from './functions/MerkleProof.js'
import { MerkleRoot } from './functions/MerkleRoot.js'
import { DeployNFT } from './functions/DeployNFT.js'
import { AppendWhitelist } from './functions/AppendWhitelist.js'
import { ETHBalance } from './functions/ETHBalance.js'
import { SignatureAuth } from './functions/SignatureAuth.js'
import { GetOwnedContracts } from './functions/GetOwnedContracts.js'
import { SetState } from './functions/SetState.js'
import { GetCollectionOwner } from './functions/GetCollectionOwner.js'
import { SetALPrice } from './functions/SetALPrice.js'
import { IsOriginalMinter } from './functions/IsOriginalMinter.js'
import { Drip } from './functions/Drip.js'
import { AddFaucetUser } from './functions/AddFaucetUser.js'
import { GetAuthTokens } from './functions/GetAuthTokens.js'
import { TwitterLookup, getAccessToken, getAuthUrl } from './functions/TwitterLookup.js'
import { UpdateUser } from './functions/UpdateUser.js'
import { GetUser } from './functions/GetUser.js'
import { GetFaucetUserCount } from './functions/GetFaucetUserCount.js'
import { GetDripAmount } from './functions/GetDripAmount.js'
router.use(bodyParser.json())
router.get('/is_original_minter', async (req, res) => {
try {
const result = await IsOriginalMinter(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
/**
* Returns the amount of NFTs owned by the wallet for the given contract address
* @param req has following members
* wallet - wallet address whose balance is being checked
* contract - contract address of NFT
* network - 'goerli', 'mainnet', 'arbitrum', 'optimism', 'polygon', 'avax'
*/
router.get('/nft_balance', async (req, res) => {
try{
const result = await NFTBalance(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
/**
* Returns the amount of ERC20 tokens owned by the wallet for the given contract address
* @param req has following members
* wallet - wallet address whose balance is being checked
* contract - contract address of ERC20 token
* network - 'goerli', 'mainnet', 'arbitrum', 'optimism', 'polygon', 'avax'
*/
router.get('/token_balance', async (req, res) => {
try {
const result = await TokenBalance(req)
res.json(result)
} catch(err) {
res.json({success: false, error: err})
}
})
/**
* Returns the amount of ETH owned by the wallet
* @param req has following members
* wallet - wallet address whose balance is being checked
* network - 'goerli', 'mainnet', 'arbitrum', 'optimism', 'polygon', 'avax'
*/
router.get('/eth_balance', async (req, res) => {
try{
const result = await ETHBalance(req)
res.json(result)
} catch (error) {
res.json({success: false, errors: error})
}
})
/**
* @param req has following members
* wallet - wallet address on behalf of whom the tx is being sent
* contract - address of recipient of tx
* network - 'goerli', 'mainnet', 'arbitrum', 'optimism', 'polygon', 'avax' //currently only goerli supported
* signature - wallet's signature of the tx data
* reqStruct - struct containing tx data {from: address, to: address, value: uint, gas: uint, nonce: uint, data: (hash of tx data)}
*
* @returns tx hash of resulting tx
*/
router.get('/relay', async (req, res) => {
try{
const auth = await SignatureAuth(req)
if(!auth) {
res.status(401).send('Access Denied')
return
}
const result = await Relay(req)
res.json(result)
} catch(error) {
res.json({success: false, errors: error})
}
})
/**
* @param req has following members
* network - 'goerli'
* func - name of function with parameter types, ex. functionName(uint256,address,string)
*
* @returns hash of tx data to be used in relay function
*/
router.get('/get_selector', async (req, res) => {
try{
const result = await GetSelector(req)
res.json(result)
} catch(error) {
res.send(error)
}
})
/**
* @param req includes following members
* types - comma separated list of parameter types, ex. uint,address,string
* values - comma separated list of parameter values, ex. 100,0x7B3AF414448ba906f02a1CA307C56c4ADFF27ce7,hello world
*
* @returns hash of these parameters to be used in relay function
*/
router.get('/get_encoded_params', async (req, res) => {
try{
const result = await GetEncodedParams(req)
res.json(result)
} catch(error) {
res.send(error)
}
})
/**
* @param req includes following members
* network - 'goerli', 'mainnet', 'arbitrum', 'optimism', 'polygon', 'avax' -> only goerli currently supported
* wallet - wallet address of user
*
* @returns nonce of wallet according to relayer contract - needed for relay function
*/
router.get('/get_relay_nonce', async (req, res) => {
try{
const result = await GetRelayNonce(req)
res.json(result)
} catch (error) {
res.send(error)
}
})
/**
* @param req includes following members
* wallet - wallet address of user whose balance is being checked
*
* @returns array of details about which NFTs are held by this wallet on this network
*/
router.get('/owned_nfts', async(req, res) => {
try{
const result = await OwnedNFTs(req)
res.json(result)
} catch (error) {
console.log(error)
res.json({success: false, error: error})
}
})
/**
* @param req includes the following members
* contract - address of NFT smart contract
*
* @returns all wallets who own at least one NFT from given contract
*/
router.get('/contract_owners', async (req, res) => {
try{
const result = await ContractOwners(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
/**
* @param req includes the following members
* wallet - address of user
* contract - address of smart contract
*
* @returns merkle proof which cryptographically proves
* the given wallet address is on the whitelist for the
* given smart contract address.
*
* If wallet is not on whitelist, throws an error.
*/
router.get('/merkle_proof', async (req, res) => {
try{
const result = await MerkleProof(req)
res.json(result)
} catch (error) {
res.json({error: error, success: false})
}
})
/**
* @param req includes the following members
* contract - address of smart contract in question
*
* @returns merkle root for whitelist associated with
* contract. Useful to add to smart contract.
*/
router.get('/merkle_root', async (req, res) => {
try{
const result = await MerkleRoot(req)
res.json(result)
} catch (error) {
res.json({error: error, success: false})
}
})
/**
* @param req includes the following members
* name - name of NFT
* symbol
* maxSupply
* price
* whitelist_price
* wallet - wallet address on whose behalf the contract is being deployed
* network - network to deploy contract on - currently only 'goerli' supported
*
* signature - signature of wallet
* message - message signed by wallet
*
* ^ used to authenticate that the request came from the wallet provided
*
* @returns address of resulting smart contract
*/
router.get('/deploy_nft', async (req, res) => {
try{
const auth = await SignatureAuth(req)
if(!auth) {
res.status(401).send('Access Denied')
return
}
const result = await DeployNFT(req)
res.json(result)
} catch (error) {
res.json({error: error, success: false})
}
})
/**
* @description updates whitelist associated with given smart contract address in
* database and on the smart contract itself - at not cost to the caller.
*
* @param req includes following members
* contract - address of smart contract
* wallets - comma separated list of addresses to add to whitelist
* ex. 0x7B3AF414448ba906f02a1CA307C56c4ADFF27ce7,0x1Dd7134A77f5e3E2E63162bBdcFD494140908270,0x007FB487100f74Bf425B7AdE9Ca0Ae1916f54f11
* network - currently only 'goerli' is supported
* wallet - address of sender of request - must be owner of the smart contract
*
* signature - signature of wallet
* message - message signed by wallet
*
* ^ used to authenticate that the request came from the wallet provided
*/
router.get('/append_whitelist', async (req, res) => {
try{
const auth = await SignatureAuth(req)
if(!auth) {
res.status(401).send('Access Denied')
return
}
const result = await AppendWhitelist(req)
res.json(result)
} catch(error) {
console.log(error)
res.json({error: error, success: false})
}
})
/**
* @param req includes following members
* wallet - wallet address being queried about
*
* @returns array of smart contract addresses owned by given wallet
*
* @note only returns data about contracts deployed through this API
*/
router.get('/get_owned_contracts', async (req, res) => {
try {
const auth = await SignatureAuth(req)
if(!auth) {
res.status(401).send('Access Denied')
return
}
const result = await GetOwnedContracts(req)
res.json(result)
} catch (error) {
console.log(error)
res.json({error: error, success: false})
}
})
/**
* @param req includes following members
* wallet - address of user being authenticated
* message - message being signed by wallet
* signature - hash resulting from wallet signature of message
*
* @returns true if signature and message recover to given wallet address
* false otherwise
*/
router.get('/signature_auth', async (req, res) => {
try {
const auth = await SignatureAuth(req)
res.json(auth)
} catch (error) {
console.log(error)
res.json({success: false, error: error})
}
})
/**
* @param req includes the following members
* wallet - address of user (must be contract owner)
* contract - address of contract being updated
* state - integer from 0 - 2 (0->closed, 1->allow list only, 2->public mint)
* network - 'goerli', 'mainnet', 'arbitrum', 'optimism', 'polygon', 'avax', whichever the contract is on
*
* message - message being signed by wallet
* signature - hash resulting from wallet signature of message
*
* @returns tx hash of state update call
*/
router.get('/set_state', async (req, res) => {
try {
const auth = await SignatureAuth(req)
if(!auth) {
res.status(401).send('Access Denied')
return
}
const result = await SetState(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
/**
* @param req contains the following members
* contract - address of smart contract to update
* price - new price
* wallet - originator of function call (verified by SignatureAuth)
* network - network where the smart contract is deployed
*
* @note signature and message are also members sent in the request for SignatureAuth
*/
router.get('/set_price', async (req,res) => {
try{
const auth = await SignatureAuth(req)
if(!auth) {
res.status(401).send('Access Denied')
return
}
const result = await SetPrice(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
/**
* @param req contains the following members
* contract - address of smart contract to update
* price - new price
* wallet - originator of function call (verified by SignatureAuth)
* network - network where the smart contract is deployed
*
* @note signature and message are also members sent in the request for SignatureAuth
*/
router.get('/set_al_price', async (req,res) => {
try{
const auth = await SignatureAuth(req)
!auth ? res.status(401).send('Access Denied') : console.log('authorized')
const result = await SetALPrice(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
/**
* @param req contains the following members
* contract - address of smart contract
* network - network where smart contract is deployed
*
* @returns wallet address that currently owns that smart contract
*/
router.get('/get_collection_owner', async (req,res) => {
try{
const result = await GetCollectionOwner(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
router.get('/drip', async (req,res) => {
try{
const result = await Drip(req);
res.json(result);
} catch (error) {
res.json({success: false, error: error});
}
})
router.get('/add_faucet_user', async (req, res) => {
try{
const result = await AddFaucetUser(req);
res.json(result);
} catch (error) {
console.log(error)
res.json({success: false, error: error});
}
})
router.get('/get_auth_tokens', async (req, res) => {
try {
const result = await GetAuthTokens(req);
res.json(result);
} catch (error) {
res.json({success: false, error: error});
}
})
router.get('/get_auth_url', async (req, res) => {
try {
const result = await getAuthUrl(req);
res.json(result);
} catch (error) {
res.json({success: false, error: error});
}
})
router.get('/twitter_lookup', async (req, res) => {
try{
const result = await TwitterLookup(req);
res.json(result);
} catch (error) {
res.json({success: false, error: error});
}
})
router.get('/update_user', async (req, res) => {
try{
const result = await UpdateUser(req);
res.json(result);
} catch (error) {
res.json({success: false, error: error});
}
})
router.get('/get_access_token', async (req, res) => {
try{
const result = await getAccessToken(req)
res.json(result)
} catch (error) {
res.json({success: false, error: error})
}
})
router.get('/get_user', async (req, res) => {
try{
const result = await GetUser(req);
res.json(result);
} catch (error) {
res.json({success: false, error: error});
}
})
router.get('/get_faucet_user_count', async (req, res) => {
try{
const result = await GetFaucetUserCount(req);
res.json({users: result});
} catch (error) {
res.json({success: false, error: error});
}
})
router.get('/get_drip_amount', async (req, res) => {
try{
const result = await GetDripAmount();
res.json({amount: result});
} catch (error) {
res.json({success: false, error: error});
}
})