-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from securesecrets/init-with-oracle
feat: oracle price queries #BE-33
- Loading branch information
Showing
29 changed files
with
4,882 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@commitlint/config-conventional"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: 'airbnb-base', | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: [ | ||
'.eslintrc.{js,cjs}', | ||
], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
}, | ||
], | ||
settings: { | ||
'import/resolver': { | ||
// Loads tsconfig from root | ||
typescript: {}, | ||
}, | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
parser: '@typescript-eslint/parser', | ||
sourceType: 'module', | ||
}, | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
rules: { | ||
// So we don't have to specify file extensions on this types | ||
'import/extensions': ['error', 'always', { | ||
js: 'never', | ||
mjs: 'never', | ||
jsx: 'never', | ||
ts: 'never', | ||
tsx: 'never', | ||
}], | ||
// Ignore base rule for unused inputs in declarations, | ||
// allows us to have unused vars in type declarations | ||
'no-unused-vars': 0, | ||
// enums showing they have already been used | ||
'no-shadow': 'off', | ||
'@typescript-eslint/no-shadow': 'error', | ||
// Allow non default exports: | ||
'import/prefer-default-export': 'off', | ||
// importing from vitest for test dependencies | ||
'import/no-extraneous-dependencies': ['error', { devDependencies: ['**/*.test.ts', '**/*.test.tsx'] }], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Tests, Typecheck, Eslint | ||
|
||
on: [push] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Node Version | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.16.0 | ||
cache: yarn | ||
- name: Install Dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Test | ||
run: yarn test | ||
typecheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Node Version | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.16.0 | ||
cache: yarn | ||
- name: Install Dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Type-Check | ||
run: yarn typecheck | ||
eslint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Node Version | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.16.0 | ||
cache: yarn | ||
- name: Install Dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Eslint-Check | ||
run: yarn lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# IDEs & Logs | ||
*.log | ||
.idea | ||
.nyc_output | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
# Vite default settings | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Vitest | ||
coverage | ||
|
||
# We use yarn | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
# shadejs | ||
# shadejs | ||
Library for interacting with Shade smart contracts | ||
|
||
## Yarn | ||
Yarn is the default package manager. | ||
|
||
## Build | ||
``` | ||
$ yarn | ||
``` | ||
|
||
## Test | ||
``` | ||
$ yarn test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Contributor Code of Conduct | ||
|
||
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. | ||
|
||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of the level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. | ||
|
||
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Git Commit Message Convention | ||
|
||
We follow the [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) guidelines. | ||
|
||
You can also use commitizen | ||
``` | ||
$ yarn cz | ||
``` | ||
and add #issue references when prompted with question: "Does this change affect any open issues?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# To make sure everything is fine before reaching github | ||
# | ||
|
||
commit-msg: | ||
parallel: true | ||
commands: | ||
# make sure we are using conventional commits | ||
# https://www.conventionalcommits.org/en/v1.0.0 | ||
lint-commit-msg: | ||
run: npx commitlint --edit | ||
|
||
pre-commit: | ||
parallel: true | ||
commands: | ||
type-check: | ||
glob: '*.{ts,tsx}' | ||
run: yarn typecheck | ||
eslint: | ||
glob: "*.{js,ts}" | ||
run: yarn lint:fix {staged_files} | ||
|
||
pre-push: | ||
parallel: true | ||
commands: | ||
test: | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "shadejs", | ||
"version": "0.0.1", | ||
"author": "Secure Secrets", | ||
"license": "MIT", | ||
"scripts": { | ||
"commitizen": "cz", | ||
"lint": "eslint \"**/*.{ts,js}\"", | ||
"lint:fix": "eslint \"**/*.{vue,ts,js}\" --fix", | ||
"test": "vitest --run", | ||
"test:coverage": "vitest run --coverage", | ||
"test:watch": "vitest watch", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"type": "module", | ||
"dependencies": { | ||
"@arkweid/lefthook": "^0.7.7", | ||
"@commitlint/cli": "^17.7.2", | ||
"@commitlint/config-conventional": "^17.7.0", | ||
"bignumber.js": "^9.1.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.51.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-import": "^2.28.1", | ||
"rxjs": "^7.8.1", | ||
"secretjs": "^1.9.3", | ||
"typescript": "^5.2.2", | ||
"vite": "^4.4.11", | ||
"vitest": "^0.34.6" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^6.7.4", | ||
"@typescript-eslint/parser": "^6.7.4" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { | ||
of, | ||
defer, | ||
tap, | ||
first, | ||
Observable, | ||
} from 'rxjs'; | ||
import { | ||
SecretNetworkClient, | ||
} from 'secretjs'; | ||
import { createFetchClient } from '~/client/services/createFetch'; | ||
import { WalletAccount } from '~/types/wallet'; | ||
import { | ||
DEFAULT_SECRET_LCD_ENDPOINT, | ||
SECRET_MAINNET_CHAIN_ID, | ||
} from '~/config'; | ||
import { ClientData } from '~/types/client'; | ||
|
||
/** | ||
* Create and returns Secret Network client | ||
* @param walletAccount not required for making public queries | ||
*/ | ||
const getSecretNetworkClient$ = ({ | ||
walletAccount, | ||
lcdEndpoint, | ||
chainId, | ||
}:{ | ||
walletAccount?: WalletAccount | ||
lcdEndpoint: string, | ||
chainId: string, | ||
}): Observable<ClientData> => createFetchClient(defer( | ||
() => { | ||
if (walletAccount) { | ||
return of({ | ||
client: new SecretNetworkClient({ | ||
url: lcdEndpoint, | ||
wallet: walletAccount.signer, | ||
walletAddress: walletAccount.walletAddress, | ||
chainId, | ||
encryptionUtils: walletAccount.encryptionUtils, | ||
encryptionSeed: walletAccount.encryptionSeed, | ||
}), | ||
endpoint: lcdEndpoint, | ||
chainId, | ||
}); | ||
} | ||
return of({ | ||
client: new SecretNetworkClient({ | ||
url: lcdEndpoint, | ||
chainId, | ||
}), | ||
endpoint: lcdEndpoint, | ||
chainId, | ||
}); | ||
}, | ||
)); | ||
|
||
let activeClient: ClientData | undefined; | ||
|
||
/** | ||
* Gets the active query client. If one does not exist, initialize it and stores it for | ||
* future use. | ||
* @param lcdEndpoint uses a default mainnet endpoint if one is not provided | ||
* @param chainId uses a default mainnet chainID if one is not provided | ||
*/ | ||
function getActiveQueryClient$(lcdEndpoint?: string, chainId?: string) { | ||
// check if a client exists and return it if it does | ||
// as long as the endpoint and chain Id haven't changed from previous. | ||
if (activeClient | ||
&& lcdEndpoint | ||
&& lcdEndpoint === activeClient.endpoint | ||
&& chainId | ||
&& chainId === activeClient.chainId | ||
) { | ||
return of(activeClient); | ||
} | ||
|
||
// if no endpoint/chainId is provided, assume mainnet and use defaults | ||
return getSecretNetworkClient$({ | ||
lcdEndpoint: lcdEndpoint ?? DEFAULT_SECRET_LCD_ENDPOINT, | ||
chainId: chainId ?? SECRET_MAINNET_CHAIN_ID, | ||
}).pipe( | ||
tap(({ client }) => { | ||
activeClient = { | ||
client, | ||
endpoint: lcdEndpoint ?? DEFAULT_SECRET_LCD_ENDPOINT, | ||
chainId: chainId ?? SECRET_MAINNET_CHAIN_ID, | ||
}; | ||
}), | ||
first(), | ||
); | ||
} | ||
|
||
export { | ||
getSecretNetworkClient$, | ||
getActiveQueryClient$, | ||
}; |
Oops, something went wrong.