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.
|
// Use IntelliSense to learn about possible attributes.
|
||||||
// Hover to view descriptions of existing attributes.
|
// Hover to view descriptions of existing attributes.
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "attach",
|
"request": "attach",
|
||||||
"name": "Debug",
|
"name": "Debug",
|
||||||
"port": 2230,
|
"port": 2230,
|
||||||
"timeout": 3000,
|
"timeout": 3000,
|
||||||
"restart": true,
|
"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({
|
export const logger = createLogger({
|
||||||
transports: [new transports.Console()],
|
transports: [new transports.Console()],
|
||||||
format: format.combine(
|
format: format.combine(
|
||||||
format.colorize(),
|
format.colorize(),
|
||||||
format.timestamp(),
|
format.timestamp(),
|
||||||
format.printf(({ timestamp, level, message }) => {
|
format.printf(({ timestamp, level, message }) => {
|
||||||
return `[${timestamp}] ${level}: ${message}`;
|
return `[${timestamp}] ${level}: ${message}`;
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setLogLevel = (logLevel: string) => {
|
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 fs from 'fs';
|
||||||
import { Keypair } from "@solana/web3.js";
|
import { Keypair } from '@solana/web3.js';
|
||||||
import { bs58 } from "@project-serum/anchor/dist/cjs/utils/bytes";
|
import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes';
|
||||||
import { Wallet } from "@drift-labs/sdk";
|
import { Wallet } from '@drift-labs/sdk';
|
||||||
|
|
||||||
import { logger } from "./logger";
|
import { logger } from './logger';
|
||||||
|
|
||||||
export function getWallet(): Wallet {
|
export function getWallet(): Wallet {
|
||||||
const privateKey = process.env.ANCHOR_PRIVATE_KEY;
|
const privateKey = process.env.ANCHOR_PRIVATE_KEY;
|
||||||
if (!privateKey) {
|
if (!privateKey) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Must set environment variable ANCHOR_PRIVATE_KEY with the path to a id.json or a list of commma separated numbers"
|
'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
|
// try to load privateKey as a filepath
|
||||||
let loadedKey: Uint8Array;
|
let loadedKey: Uint8Array;
|
||||||
if (fs.existsSync(privateKey)) {
|
if (fs.existsSync(privateKey)) {
|
||||||
logger.info(`loading private key from ${privateKey}`);
|
logger.info(`loading private key from ${privateKey}`);
|
||||||
loadedKey = new Uint8Array(
|
loadedKey = new Uint8Array(
|
||||||
JSON.parse(fs.readFileSync(privateKey).toString())
|
JSON.parse(fs.readFileSync(privateKey).toString())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (privateKey.includes(",")) {
|
if (privateKey.includes(',')) {
|
||||||
logger.info(`Trying to load private key as comma separated numbers`);
|
logger.info(`Trying to load private key as comma separated numbers`);
|
||||||
loadedKey = Uint8Array.from(
|
loadedKey = Uint8Array.from(
|
||||||
privateKey.split(",").map((val) => Number(val))
|
privateKey.split(',').map((val) => Number(val))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
logger.info(`Trying to load private key as base58 string`);
|
logger.info(`Trying to load private key as base58 string`);
|
||||||
loadedKey = new Uint8Array(bs58.decode(privateKey));
|
loadedKey = new Uint8Array(bs58.decode(privateKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const keypair = Keypair.fromSecretKey(Uint8Array.from(loadedKey));
|
const keypair = Keypair.fromSecretKey(Uint8Array.from(loadedKey));
|
||||||
return new Wallet(keypair);
|
return new Wallet(keypair);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user