Updated to use same formatting as monorepo

This commit is contained in:
Luke Steyn
2023-05-31 23:08:37 +09:00
parent a86a1f0e3e
commit c0c97c9b63
5 changed files with 771 additions and 763 deletions

8
.prettierrc.js Normal file
View File

@@ -0,0 +1,8 @@
module.exports = {
semi: true,
trailingComma: 'es5',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
useTabs: true,
};

28
.vscode/launch.json vendored
View File

@@ -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
}
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -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;
};

View File

@@ -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);
}