ts client

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-01-10 10:13:08 +01:00
parent 55c788cdc2
commit 38d7b03735
13 changed files with 4009 additions and 2 deletions

33
.eslintrc.json Normal file
View File

@ -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": "^_"
}
]
}
}

2
.gitignore vendored
View File

@ -3,6 +3,8 @@
.DS_Store
target
**/*.rs.bk
dist
node_modules
.idea

2
Cargo.lock generated
View File

@ -3216,7 +3216,7 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "voter-stake-registry"
version = "0.1.0"
version = "0.1.3"
dependencies = [
"anchor-lang",
"anchor-spl",

View File

@ -32,9 +32,31 @@ Users can:
# Development
## Rust
* Built and developed using - rust stable(`rustc 1.57.0 (f1edd0429 2021-11-29)`)
* Run rust based tests - `cargo test-bpf`
* `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

13
examples/example.ts Normal file
View File

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

43
package.json Normal file
View File

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

View File

@ -1,6 +1,6 @@
[package]
name = "voter-stake-registry"
version = "0.1.0"
version = "0.1.3"
description = "Created with Anchor"
edition = "2018"

7
run-publish.sh Executable file
View File

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

29
src/client.ts Normal file
View File

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

2171
src/idl.ts Normal file

File diff suppressed because it is too large Load Diff

1
src/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './client';

20
tsconfig.json Normal file
View File

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

1666
yarn.lock Normal file

File diff suppressed because it is too large Load Diff