ts client
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
55c788cdc2
commit
38d7b03735
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"plugins": ["@typescript-eslint"],
|
||||||
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"prettier"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"es6": true,
|
||||||
|
"browser": true,
|
||||||
|
"jest": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/explicit-module-boundary-types": 0,
|
||||||
|
"@typescript-eslint/ban-ts-comment": 0,
|
||||||
|
"@typescript-eslint/explicit-function-return-type": 0,
|
||||||
|
"@typescript-eslint/explicit-member-accessibility": 0,
|
||||||
|
"@typescript-eslint/indent": 0,
|
||||||
|
"@typescript-eslint/member-delimiter-style": 0,
|
||||||
|
"@typescript-eslint/no-empty-function": 0,
|
||||||
|
"@typescript-eslint/no-explicit-any": 0,
|
||||||
|
"@typescript-eslint/no-var-requires": 0,
|
||||||
|
"@typescript-eslint/no-use-before-define": 0,
|
||||||
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
2,
|
||||||
|
{
|
||||||
|
"argsIgnorePattern": "^_"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,8 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
target
|
target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
|
|
@ -3216,7 +3216,7 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "voter-stake-registry"
|
name = "voter-stake-registry"
|
||||||
version = "0.1.0"
|
version = "0.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anchor-lang",
|
"anchor-lang",
|
||||||
"anchor-spl",
|
"anchor-spl",
|
||||||
|
|
22
README.md
22
README.md
|
@ -32,9 +32,31 @@ Users can:
|
||||||
|
|
||||||
# Development
|
# Development
|
||||||
|
|
||||||
|
## Rust
|
||||||
* Built and developed using - rust stable(`rustc 1.57.0 (f1edd0429 2021-11-29)`)
|
* Built and developed using - rust stable(`rustc 1.57.0 (f1edd0429 2021-11-29)`)
|
||||||
* Run rust based tests - `cargo test-bpf`
|
* Run rust based tests - `cargo test-bpf`
|
||||||
* `run-generate-anchor-types.sh` generates latest anchor types file and writes to `./voter_stake_registry.ts`
|
* `run-generate-anchor-types.sh` generates latest anchor types file and writes to `./voter_stake_registry.ts`
|
||||||
|
* To install the typescript client, do - `yarn add @blockworks-foundation/voter-stake-registry-client`
|
||||||
|
* usage
|
||||||
|
|
||||||
|
## Node/Typescript
|
||||||
|
* Built and developed using - node (`v16.13.1`)
|
||||||
|
* Usage
|
||||||
|
```
|
||||||
|
import { Provider, Wallet } from '@project-serum/anchor';
|
||||||
|
import { Connection, Keypair } from '@solana/web3.js';
|
||||||
|
import { VsrClient } from '@blockworks-foundation/voter-stake-registry-client';
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const options = Provider.defaultOptions();
|
||||||
|
const connection = new Connection('https://api.devnet.solana.com', options);
|
||||||
|
const wallet = new Wallet(Keypair.generate());
|
||||||
|
const provider = new Provider(connection, wallet, options);
|
||||||
|
const client = await VsrClient.connect(provider, true);
|
||||||
|
```
|
||||||
|
|
||||||
|
<img width="708" alt="image" src="https://user-images.githubusercontent.com/89031858/148725266-29459e80-623e-45c4-952d-5d9d1f0f15bc.png">
|
||||||
|
|
||||||
|
|
||||||
# Deployment
|
# Deployment
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { Provider, Wallet } from '@project-serum/anchor';
|
||||||
|
import { Connection, Keypair } from '@solana/web3.js';
|
||||||
|
import { VsrClient } from '../src';
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const options = Provider.defaultOptions();
|
||||||
|
const connection = new Connection('https://api.devnet.solana.com', options);
|
||||||
|
const wallet = new Wallet(Keypair.generate());
|
||||||
|
const provider = new Provider(connection, wallet, options);
|
||||||
|
const client = await VsrClient.connect(provider, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"name": "@blockworks-foundation/voter-stake-registry-client",
|
||||||
|
"version": "0.1.3",
|
||||||
|
"description": "Client for Voter-stake-registry which is a voter weight addin for Solana's spl-governance program.",
|
||||||
|
"main": "lib/src/index.js",
|
||||||
|
"types": "lib/src/index.d.ts",
|
||||||
|
"repository": "https://github.com/blockworks-foundation/voter-stake-registry-client",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"clean": "rm -rf dist",
|
||||||
|
"type-check": "tsc --pretty --noEmit",
|
||||||
|
"format": "prettier --check .",
|
||||||
|
"lint": "eslint . --ext ts --ext tsx --ext js --quiet"
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"name": "Blockworks Foundation",
|
||||||
|
"email": "hello@blockworks.foundation",
|
||||||
|
"url": "https://blockworks.foundation"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tsconfig/recommended": "^1.0.1",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
||||||
|
"@typescript-eslint/parser": "^4.14.2",
|
||||||
|
"eslint": "^7.28.0",
|
||||||
|
"eslint-config-prettier": "^7.2.0",
|
||||||
|
"prettier": "^2.0.5",
|
||||||
|
"ts-node": "^9.1.1",
|
||||||
|
"typedoc": "^0.22.5",
|
||||||
|
"typescript": "^4.1.3"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@project-serum/anchor": "^0.18.0",
|
||||||
|
"@project-serum/serum": "^0.13.61"
|
||||||
|
},
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "voter-stake-registry"
|
name = "voter-stake-registry"
|
||||||
version = "0.1.0"
|
version = "0.1.3"
|
||||||
description = "Created with Anchor"
|
description = "Created with Anchor"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e -o pipefail
|
||||||
|
anchor build
|
||||||
|
cp ./target/types/voter_stake_registry.ts src/idl.ts
|
||||||
|
yarn clean && yarn build && cp package.json ./dist/ && yarn publish dist
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Program, Provider } from '@project-serum/anchor';
|
||||||
|
import { PublicKey } from '@solana/web3.js';
|
||||||
|
import { VoterStakeRegistry } from './idl';
|
||||||
|
|
||||||
|
export const VSR_ID = new PublicKey(
|
||||||
|
'4Q6WW2ouZ6V3iaNm56MTd5n2tnTm4C5fiH8miFHnAFHo',
|
||||||
|
);
|
||||||
|
|
||||||
|
export class VsrClient {
|
||||||
|
constructor(
|
||||||
|
public program: Program<VoterStakeRegistry>,
|
||||||
|
public devnet?: boolean,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
static async connect(
|
||||||
|
provider: Provider,
|
||||||
|
devnet?: boolean,
|
||||||
|
): Promise<VsrClient> {
|
||||||
|
const idl = await Program.fetchIdl(VSR_ID, provider);
|
||||||
|
return new VsrClient(
|
||||||
|
new Program<VoterStakeRegistry>(
|
||||||
|
idl as VoterStakeRegistry,
|
||||||
|
VSR_ID,
|
||||||
|
provider,
|
||||||
|
),
|
||||||
|
devnet,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
||||||
|
export * from './client';
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"extends": "@tsconfig/recommended/tsconfig.json",
|
||||||
|
|
||||||
|
"compilerOptions": {
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"declaration": true,
|
||||||
|
"declarationDir": "dist",
|
||||||
|
"declarationMap": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"lib": ["es2019"],
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"outDir": "dist",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"target": "es6"
|
||||||
|
},
|
||||||
|
"include": ["./src/**/*"],
|
||||||
|
"exclude": ["./src/**/*.test.js", "node_modules", "**/node_modules"]
|
||||||
|
}
|
Loading…
Reference in New Issue