Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create logic part 2 #11

Merged
merged 29 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
acc7fb7
[create-logic-part-2] create exitQueue
Cast0001 Sep 18, 2023
3a409e7
[create-logic-part-2] create logic for contracts
Cast0001 Sep 18, 2023
81e6e03
[create-logic-part-2] improve jest and rename fetch folder
Cast0001 Sep 18, 2023
bcc6841
[create-logic-part-2] logic for parse exit queue
Cast0001 Sep 18, 2023
59a75de
[create-logic-part-2] test for parseExitRequests
Cast0001 Sep 18, 2023
f361b5f
[create-logic-part-2] add osTokenAPY method
Cast0001 Sep 19, 2023
2e05a12
[create-logic-part-2] add configs
Cast0001 Sep 19, 2023
ae21c7c
[create-logic-part-2] new create contracts
Cast0001 Sep 19, 2023
119f6a2
[create-logic-part-2] create multicall
Cast0001 Sep 19, 2023
b6bec41
[create-logic-part-2] part of improves
Cast0001 Sep 19, 2023
95e080f
[create-logic-part-2] sdk api sketches
Cast0001 Sep 20, 2023
2cbaa5f
[create-logic-part-2] renames
Cast0001 Sep 20, 2023
617082f
[create-logic-part-2] fixes
Cast0001 Sep 20, 2023
cd5efd7
[create-logic-part-2] logic for custom endpoints
Cast0001 Sep 20, 2023
c4a5421
[create-logic-part-2] improve test
Cast0001 Sep 20, 2023
11a08d9
[create-logic-part-2] isolate namespaces
Cast0001 Sep 21, 2023
866c883
[create-logic-part-2] fetch os token data
Cast0001 Sep 21, 2023
aae6fef
[create-logic-part-2] fetch reward splitters
Cast0001 Sep 21, 2023
d7946bd
[create-logic-part-2] fetch stake balance
Cast0001 Sep 21, 2023
90d9d2f
[create-logic-part-2] fetch mint token balance and health
Cast0001 Sep 21, 2023
c128457
[create-logic-part-2] improves and tests
Cast0001 Sep 21, 2023
04d3b9e
[create-logic-part-2] fetch withdraw data
Cast0001 Sep 21, 2023
6c4b391
[create-logic-part-2] add test for withdraw
Cast0001 Sep 21, 2023
3a1d363
[create-logic-part-2] fetch max mint shares
Cast0001 Sep 21, 2023
4e155d4
[create-logic-part-2] fetch burm amount
Cast0001 Sep 21, 2023
4cff534
[create-logic-part-2] get rewards per year
Cast0001 Sep 21, 2023
b635b41
[create-logic-part-2] new tests and improves
Cast0001 Sep 21, 2023
d2013af
[create-logic-part-2] create sdk helpers
Cast0001 Sep 21, 2023
4fa920c
[create-logic-part-2] improve helpers
Cast0001 Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
],
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"object-curly-spacing": [ "error", "always" ],
"array-bracket-spacing": [ "error", "always" ],
"no-multiple-empty-lines": [ "error", { "max": 2 } ],
"@typescript-eslint/no-unnecessary-type-constraint": "off",
"jsx-a11y/alt-text": 0,
"comma-dangle": [
"warn", {
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
tsconfig.tsbuildinfo

dist
types
cache
coverage

# dependencies
node_modules

# Types
schema.graphql
*.graphql.ts
schema.graphql
src/types/graphql
src/contracts/types
4 changes: 2 additions & 2 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { CodegenConfig } from '@graphql-codegen/cli'

import { Network } from './src/helpers/enums'
import config from './src/helpers/config'
import configs from './src/helpers/configs'


// For every netwrok we have same gql shema, so we can use just Mainnet here
const urls = config[Network.Goerli].api // TODO replace on Mainnet
const urls = configs[Network.Goerli].api // TODO replace on Mainnet

// https://the-guild.dev/graphql/codegen/plugins/typescript/typescript
const typesConfig = {
Expand Down
14 changes: 11 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { Config } from 'jest'


const config: Config = {
rootDir: '.',
verbose: true,
rootDir: './src',
preset: 'ts-jest',
resetMocks: true,
testEnvironment: 'node',
Expand All @@ -13,13 +13,21 @@ const config: Config = {
modulePathIgnorePatterns: [ '<rootDir>/src/helpers' ],
transform: {
'\\.[jt]sx?$': 'ts-jest',
'\\.graphql$': '@graphql-tools/jest-transform',
},
globals: {
isolatedModules: true,
},
moduleNameMapper: {
'^helpers$': require.resolve('./src/helpers/index.ts'),
'^graphql$': require.resolve('./src/graphql/index.ts'),
'^graphql/(.*)': '<rootDir>/graphql/$1',
'^graphql$': '<rootDir>/graphql/index.ts',

'^requests/(.*)': '<rootDir>/requests/$1',
'^requests$': '<rootDir>/requests/index.ts',
'^requests/methods': '<rootDir>/requests/methods/indes.ts',

'^helpers$': '<rootDir>/helpers/index.ts',
'^contracts$': '<rootDir>/contracts/index.ts',
},
}

Expand Down
113 changes: 80 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"homepage": "https://app.stakewise.io",
"scripts": {
"test": "jest --clearCache && jest --onlyChanged",
"build": "npm run prepare && rm -rf ./dist && npm run rollup",
"prepare": "npm run typechain && npm run graphql && husky install",
"build": "npm run test && npm run prepare && rm -rf ./dist && npm run rollup",
"typechain": "typechain --target ethers-v6 --out-dir src/contracts/types 'src/contracts/abis/*.json'",
"graphql": "graphql-codegen && ts-node -O '{\"module\": \"commonjs\"}' ./scripts/generateGraphqlExports",
"rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs"
Expand All @@ -39,6 +39,7 @@
"@graphql-codegen/near-operation-file-preset": "2.5.0",
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-operations": "4.0.1",
"@graphql-tools/jest-transform": "2.0.0",
"@openzeppelin/test-environment": "0.1.9",
"@rollup/plugin-commonjs": "25.0.4",
"@rollup/plugin-json": "6.0.0",
Expand Down Expand Up @@ -67,5 +68,8 @@
"ts-node": "10.9.1",
"typechain": "8.3.1",
"typescript": "5.1.6"
},
"dependencies": {
"bignumber.js": "9.1.2"
}
}
2 changes: 1 addition & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const config: RollupOptions[] = [
exclude: [
'node_modules',
'**/*.spec.ts',
'**/*.stories.tsx',
],
}),
json(),
Expand All @@ -65,6 +64,7 @@ const config: RollupOptions[] = [
output: [
{
file: 'dist/index.d.ts',
sourcemap: false,
format: 'es',
},
],
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateGraphqlExports/addGraphqlNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const addGraphqlNamespace = (filePath: string, client: string) => {
.join('\n')

const graphqlTypesFileContent = [
`export declare namespace ${string.capitalize(client)}Graph {\n`,
`export declare namespace StakeWise${string.capitalize(client)}Graph {\n`,
graphqlTypesFile,
'}',
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const getFileTypes = (client: string, tsFilePath: string) => {
.replace(/import \* as Types from .*\n\n/, '')
.replace(/import \{ TypedDocumentNode .*/, '')
.replace(/;\n+/g, '\n')
.replace(/Types/g, `${string.capitalize(client)}Graph`)
.replace(/Types/g, `StakeWise${string.capitalize(client)}Graph`)
.replace(/export /g, '')
}

Expand Down
9 changes: 4 additions & 5 deletions scripts/generateGraphqlExports/mutationTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
export default `
import { config, Network } from 'helpers'
import { {ClientName}Graph } from 'types/graphql/{clientName}'
import { StakeWise{ClientName}Graph } from 'types/graphql/{clientName}'


type SubmitInput = {
network: Network
url: string
variables: {QueryName}Variables
}

const submit{QueryName} = ({ variables, network }: SubmitInput) =>
fetch(config[network].api.{clientName}, {
const submit{QueryName} = ({ variables, url }: SubmitInput) =>
fetch(url, {
method: 'POST',
body: JSON.stringify({
query,
Expand Down
7 changes: 3 additions & 4 deletions scripts/generateGraphqlExports/queryTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const queryImport = [
'import { graphqlFetch, FetchCodegenInput } from \'modules/gql-module\'',
'import { {ClientName}Graph } from \'types/graphql/{clientName}\'',
'import { config } from \'helpers\'',
'import { StakeWise{ClientName}Graph } from \'types/graphql/{clientName}\''
].join('\n')

const queryTemplate = `

const fetch{QueryName} = <ModifiedData = {QueryName}Payload>(
{ variables, network, modifyResult }: FetchCodegenInput<{QueryName}Payload, {QueryName}Variables, ModifiedData>
{ variables, url, modifyResult }: FetchCodegenInput<{QueryName}Payload, {QueryName}Variables, ModifiedData>
) => (
graphqlFetch<{QueryName}Payload, {QueryName}Variables, ModifiedData>({
url: config[network].api.{clientName},
url,
query,
variables,
modifyResult,
Expand Down
24 changes: 24 additions & 0 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { JsonRpcProvider } from 'ethers'
import { configs, apiUrls } from 'helpers'
import { createContracts } from 'contracts'
import { createRequests, getHealthFactor, getRewardsPerYear } from 'requests'


class StakeWiseSDK {
readonly requests: StakeWise.Requests
readonly contracts: StakeWise.Contracts

constructor(options: StakeWise.Options) {
const config = configs[options.network]
const provider = options.provider || new JsonRpcProvider(apiUrls.getWeb3Url(options))

this.contracts = createContracts({ provider, config })
this.requests = createRequests({ options, contracts: this.contracts })
}

getHealthFactor = getHealthFactor
getRewardsPerYear = getRewardsPerYear
}


export default StakeWiseSDK
16 changes: 16 additions & 0 deletions src/contracts/createContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Contract } from 'ethers'
import type { Provider, InterfaceAbi } from 'ethers'


const createContract = <T extends unknown>(
address: string,
abi: InterfaceAbi,
library: Provider
) : T => {
const contract = new Contract(address, abi, library) as T

return contract
}


export default createContract
Loading
Loading