Removed code for unnecessary requirement to include a private key for an existing account
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
ANCHOR_PRIVATE_KEY=246,79,83,235,227,63,148,45,236,118,164,3,0,99,197,152,7,161,4,247,132,15,56,14,71,41,175,39,108,68,32,37,233,229,35,89,133,166,36,228,162,196,142,255,237,118,168,210,61,163,132,32,11,89,22,89,116,119,126,116,203,65,29,77
|
||||
ENDPOINT=https://api.devnet.solana.com
|
||||
ENV=devnet
|
||||
PORT=6969
|
||||
31
src/index.ts
31
src/index.ts
@@ -1,4 +1,4 @@
|
||||
import { program, Option } from 'commander';
|
||||
import { program } from 'commander';
|
||||
|
||||
import responseTime = require('response-time');
|
||||
import express from 'express';
|
||||
@@ -7,7 +7,7 @@ import compression from 'compression';
|
||||
import morgan from 'morgan';
|
||||
import cors from 'cors';
|
||||
|
||||
import { Connection, Commitment, PublicKey } from '@solana/web3.js';
|
||||
import { Connection, Commitment, PublicKey, Keypair } from '@solana/web3.js';
|
||||
|
||||
import {
|
||||
getVariant,
|
||||
@@ -32,11 +32,11 @@ import {
|
||||
BN,
|
||||
groupL2,
|
||||
L2OrderBook,
|
||||
Wallet,
|
||||
} from '@drift-labs/sdk';
|
||||
|
||||
import { Mutex } from 'async-mutex';
|
||||
|
||||
import { getWallet } from './utils';
|
||||
import { logger, setLogLevel } from './logger';
|
||||
|
||||
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
|
||||
@@ -104,18 +104,6 @@ app.use((req, _res, next) => {
|
||||
next();
|
||||
});
|
||||
|
||||
program
|
||||
.option('-d, --dry-run', 'Dry run, do not send transactions on chain')
|
||||
.option('--test-liveness', 'Purposefully fail liveness test after 1 minute')
|
||||
.addOption(
|
||||
new Option(
|
||||
'-p, --private-key <string>',
|
||||
'private key, supports path to id.json, or list of comma separate numbers'
|
||||
).env('ANCHOR_PRIVATE_KEY')
|
||||
)
|
||||
.option('--debug', 'Enable debug logging')
|
||||
.parse();
|
||||
|
||||
const opts = program.opts();
|
||||
setLogLevel(opts.debug ? 'debug' : 'info');
|
||||
|
||||
@@ -301,7 +289,7 @@ const initializeAllMarketSubscribers = async (
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
const wallet = getWallet();
|
||||
const wallet = new Wallet(new Keypair());
|
||||
const clearingHousePublicKey = new PublicKey(sdkConfig.DRIFT_PROGRAM_ID);
|
||||
|
||||
const connection = new Connection(endpoint, {
|
||||
@@ -362,17 +350,6 @@ const main = async () => {
|
||||
});
|
||||
});
|
||||
|
||||
if (!(await driftClient.getUser().exists())) {
|
||||
logger.error(`User for ${wallet.publicKey} does not exist`);
|
||||
if (opts.initUser) {
|
||||
logger.info(`Creating User for ${wallet.publicKey}`);
|
||||
const [txSig] = await driftClient.initializeUserAccount();
|
||||
logger.info(`Initialized user account in transaction: ${txSig}`);
|
||||
} else {
|
||||
throw new Error("Run with '--init-user' flag to initialize a User");
|
||||
}
|
||||
}
|
||||
|
||||
const userMap = new UserMap(
|
||||
driftClient,
|
||||
driftClient.userAccountSubscriptionConfig,
|
||||
|
||||
36
src/utils.ts
36
src/utils.ts
@@ -1,36 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import { Keypair } from '@solana/web3.js';
|
||||
import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes';
|
||||
import { Wallet } from '@drift-labs/sdk';
|
||||
|
||||
import { logger } from './logger';
|
||||
|
||||
export function getWallet(): Wallet {
|
||||
const privateKey = process.env.ANCHOR_PRIVATE_KEY;
|
||||
if (!privateKey) {
|
||||
throw new Error(
|
||||
'Must set environment variable ANCHOR_PRIVATE_KEY with the path to a id.json or a list of commma separated numbers'
|
||||
);
|
||||
}
|
||||
// try to load privateKey as a filepath
|
||||
let loadedKey: Uint8Array;
|
||||
if (fs.existsSync(privateKey)) {
|
||||
logger.info(`loading private key from ${privateKey}`);
|
||||
loadedKey = new Uint8Array(
|
||||
JSON.parse(fs.readFileSync(privateKey).toString())
|
||||
);
|
||||
} else {
|
||||
if (privateKey.includes(',')) {
|
||||
logger.info(`Trying to load private key as comma separated numbers`);
|
||||
loadedKey = Uint8Array.from(
|
||||
privateKey.split(',').map((val) => Number(val))
|
||||
);
|
||||
} else {
|
||||
logger.info(`Trying to load private key as base58 string`);
|
||||
loadedKey = new Uint8Array(bs58.decode(privateKey));
|
||||
}
|
||||
}
|
||||
|
||||
const keypair = Keypair.fromSecretKey(Uint8Array.from(loadedKey));
|
||||
return new Wallet(keypair);
|
||||
}
|
||||
Reference in New Issue
Block a user