Merge branch 'master' into mainnet-beta
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
|
||||
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,
|
||||
};
|
||||
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@@ -0,0 +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
|
||||
}
|
||||
]
|
||||
}
|
||||
101
package.json
101
package.json
@@ -1,52 +1,53 @@
|
||||
{
|
||||
"name": "@drift-labs/dlob-server",
|
||||
"version": "0.1.0",
|
||||
"author": "wphan",
|
||||
"main": "lib/index.js",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@drift-labs/sdk": "2.31.0-beta.1",
|
||||
"@opentelemetry/api": "^1.1.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
|
||||
"@opentelemetry/exporter-prometheus": "^0.31.0",
|
||||
"@opentelemetry/sdk-node": "^0.31.0",
|
||||
"@project-serum/anchor": "^0.19.1-beta.1",
|
||||
"@project-serum/serum": "^0.13.65",
|
||||
"@solana/web3.js": "^1.22.0",
|
||||
"async-mutex": "^0.4.0",
|
||||
"commander": "^9.4.0",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.18.2",
|
||||
"express-rate-limit": "^6.7.0",
|
||||
"morgan": "^1.10.0",
|
||||
"response-time": "^2.3.2",
|
||||
"typescript": "4.5.4",
|
||||
"winston": "^3.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||
"@typescript-eslint/parser": "^4.28.0",
|
||||
"eslint": "^7.29.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"husky": "^7.0.4",
|
||||
"prettier": "^2.4.1",
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "husky install",
|
||||
"build": "yarn clean && tsc",
|
||||
"clean": "rm -rf lib",
|
||||
"start": "node lib/index.js",
|
||||
"dev": "ts-node src/index.ts",
|
||||
"dev:inspect": "yarn build && node --inspect ./lib/index.js",
|
||||
"example": "ts-node example/client.ts",
|
||||
"exampleWithSlot": "ts-node example/clientWithSlot.ts",
|
||||
"prettify": "prettier --check './src/**/*.ts'",
|
||||
"prettify:fix": "prettier --write './src/**/*.ts'",
|
||||
"lint": "eslint . --ext ts --quiet",
|
||||
"lint:fix": "eslint . --ext ts --fix"
|
||||
}
|
||||
"name": "@drift-labs/dlob-server",
|
||||
"version": "0.1.0",
|
||||
"author": "wphan",
|
||||
"main": "lib/index.js",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@drift-labs/sdk": "2.31.0-beta.7",
|
||||
"@opentelemetry/api": "^1.1.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
|
||||
"@opentelemetry/exporter-prometheus": "^0.31.0",
|
||||
"@opentelemetry/sdk-node": "^0.31.0",
|
||||
"@project-serum/anchor": "^0.19.1-beta.1",
|
||||
"@project-serum/serum": "^0.13.65",
|
||||
"@solana/web3.js": "^1.22.0",
|
||||
"async-mutex": "^0.4.0",
|
||||
"commander": "^9.4.0",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.18.2",
|
||||
"express-rate-limit": "^6.7.0",
|
||||
"morgan": "^1.10.0",
|
||||
"response-time": "^2.3.2",
|
||||
"typescript": "4.5.4",
|
||||
"winston": "^3.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||
"@typescript-eslint/parser": "^4.28.0",
|
||||
"eslint": "^7.29.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"husky": "^7.0.4",
|
||||
"prettier": "^2.4.1",
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "husky install",
|
||||
"build": "yarn clean && tsc",
|
||||
"clean": "rm -rf lib",
|
||||
"start": "node lib/index.js",
|
||||
"dev": "ts-node src/index.ts",
|
||||
"dev:inspect": "yarn build && node --inspect ./lib/index.js",
|
||||
"dev:debug": "yarn build && node --inspect-brk --inspect=2230 ./lib/index.js",
|
||||
"example": "ts-node example/client.ts",
|
||||
"exampleWithSlot": "ts-node example/clientWithSlot.ts",
|
||||
"prettify": "prettier --check './src/**/*.ts'",
|
||||
"prettify:fix": "prettier --write './src/**/*.ts'",
|
||||
"lint": "eslint . --ext ts --quiet",
|
||||
"lint:fix": "eslint . --ext ts --fix"
|
||||
}
|
||||
}
|
||||
|
||||
1621
src/index.ts
1621
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;
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -80,10 +80,10 @@
|
||||
enabled "2.0.x"
|
||||
kuler "^2.0.0"
|
||||
|
||||
"@drift-labs/sdk@2.31.0-beta.1":
|
||||
version "2.31.0-beta.1"
|
||||
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.31.0-beta.1.tgz#60e14806430fdcd427e9949ab511ab659c8a83fc"
|
||||
integrity sha512-GQENFRU+qNIeFlC0k/JaaluTtgAQ4t6a9EHWfa4sIC6T+2KhBu2e6zZ0QiCSDYFm5cJleqE9z3EHEW3T2o5Exg==
|
||||
"@drift-labs/sdk@2.31.0-beta.7":
|
||||
version "2.31.0-beta.7"
|
||||
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.31.0-beta.7.tgz#d7337d80d7ed9bd8a660cfd5280d660987e42f37"
|
||||
integrity sha512-+SpE4gv8BXvr/y/Gdjk7VS96Qg7u8SCMM8cB+WyI8KrJJsz569ORSEUu4FE2PVcu5HeypzUosiphLfDmZuXDIA==
|
||||
dependencies:
|
||||
"@coral-xyz/anchor" "0.26.0"
|
||||
"@ellipsis-labs/phoenix-sdk" "^1.4.2"
|
||||
|
||||
Reference in New Issue
Block a user