Updated to use same formatting as monorepo
This commit is contained in:
8
.prettierrc.js
Normal file
8
.prettierrc.js
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
semi: true,
|
||||
trailingComma: 'es5',
|
||||
singleQuote: true,
|
||||
printWidth: 80,
|
||||
tabWidth: 2,
|
||||
useTabs: true,
|
||||
};
|
||||
30
.vscode/launch.json
vendored
30
.vscode/launch.json
vendored
@@ -1,16 +1,16 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"name": "Debug",
|
||||
"port": 2230,
|
||||
"timeout": 3000,
|
||||
"restart": true,
|
||||
},
|
||||
]
|
||||
}
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"name": "Debug",
|
||||
"port": 2230,
|
||||
"timeout": 3000,
|
||||
"restart": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
1414
src/index.ts
1414
src/index.ts
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,16 @@
|
||||
import { createLogger, transports, format } from "winston";
|
||||
import { createLogger, transports, format } from 'winston';
|
||||
|
||||
export const logger = createLogger({
|
||||
transports: [new transports.Console()],
|
||||
format: format.combine(
|
||||
format.colorize(),
|
||||
format.timestamp(),
|
||||
format.printf(({ timestamp, level, message }) => {
|
||||
return `[${timestamp}] ${level}: ${message}`;
|
||||
})
|
||||
),
|
||||
transports: [new transports.Console()],
|
||||
format: format.combine(
|
||||
format.colorize(),
|
||||
format.timestamp(),
|
||||
format.printf(({ timestamp, level, message }) => {
|
||||
return `[${timestamp}] ${level}: ${message}`;
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
export const setLogLevel = (logLevel: string) => {
|
||||
logger.level = logLevel;
|
||||
logger.level = logLevel;
|
||||
};
|
||||
|
||||
62
src/utils.ts
62
src/utils.ts
@@ -1,36 +1,36 @@
|
||||
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 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";
|
||||
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 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);
|
||||
const keypair = Keypair.fromSecretKey(Uint8Array.from(loadedKey));
|
||||
return new Wallet(keypair);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user