Skip to content

Commit aba27a6

Browse files
chrisli30imstar15github-actions[bot]
authored
Major upgrade of config, and minor upgrade of api-augment and types (#104)
* Initialize packages of config, provider, oak-sdk. fix #27 (#30) * Create code struct * Refine the code structure; Add assets; * Add chain configs; Add TuringChain, MoonbeamChain; * Add getXcmWeight, weightTofee to providers * Refactor some code * Rename packages * Test PayThroughSoverignAccount XCMP task * Test PayThroughRemoteDerivativeAccount XCMP task * Test Astar task * Support specifying schedule fee location and execution fee location. * Extract getDeriveAccount, getDeriveAccountV3 function * Rename TaskRegister to TaskScheduler * Rename provider to adapter. Refactor code. * Fix rocstar derive account on turing-staging * Optimize the retrieval of metadata. * Add crossChainTransfer to adapters * Fix weightToFee in mangata.ts * Export mangata sdk in mangata.ts * Update package-setup * Update package version * Pass polkadotApi to adapters * Fix scheduleTaskThroughXcm in astar.ts * Define AccountType in types.ts * import KeyringPair type * Clean code * Extract enum XcmInstructionNetworkType * import type ApiPromise * Fix issues * Add comments to utils functions * Add comments for adapters * Modify tests and README.md * Add eslint * Format code with eslint * Add comment for alith account * Revert version in package.json * Modify the way of checking 'undefined' * Revert XcmInstructionNetworkType * Remove changeset instructions in package.json * Format code with eslint * Add refund param to xcmTransactor.transactThroughSigned function * Extract xcm in chain cofig * Rename getEnv to getEnvOrDefault * Extract getChainPairConfig function * Check undefined in utils * Rename updateChainData to fetchAndUpdateConfigs * docs(changeset): Pre-release * RELEASING: Releasing 4 package(s) (#67) Releases: @oak-network/[email protected] @oak-network/[email protected] @oak-network/[email protected] @oak-network/[email protected] [skip ci] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * docs(changeset): Version 0.1.2 * RELEASING: Releasing 4 package(s) (#68) Releases: @oak-network/[email protected] @oak-network/[email protected] @oak-network/[email protected] @oak-network/[email protected] [skip ci] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Modify the issue in getting the network attribute (#70) * Set timeout for tests (#72) * Set timeout for tests * Dealing with issues when the Polkadot API cannot connect to a remote node * Fix a blocking usage issue in config package caused by node:util (#74) * Remove the deprecated publish script from package.json * Update author in package.json * Fix an usage issue: Module build failed: UnhandledSchemeError: Reading from node:util is not handled by plugins (Unhandled scheme) * Fix an usage issue: Module build failed: UnhandledSchemeError: Reading from node:util is not handled by plugins (Unhandled scheme) * Revert "Fix an usage issue: Module build failed: UnhandledSchemeError: Reading from node:util is not handled by plugins (Unhandled scheme)" This reverts commit 61bfde4. * docs(changeset): Fix a usage error casued by the reference of node:util * Update the logic of .github/workflows/npm-publish-dev.yml * RELEASING: Releasing 1 package(s) (#75) Releases: @oak-network/[email protected] [skip ci] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Fix a npm show command error in .github/workflows/npm-publish-dev.yml * Fix a run command mistake in .github/workflows/npm-publish-dev.yml * Fix a run command mistake in .github/workflows/npm-publish-dev.yml * Added more echo and comments to npm-publish-dev.yml * Adde compare version function to npm-publish-dev.yml * Replace the function in npm-publish-dev.yml * Update the compare function in npm-publish-dev.yml * Change instruction count to 4 in oak adapter (#76) * Update changeset (#78) * Changeset Version Bump (#77) * Fix issues in astar tests * RELEASING: Releasing 2 package(s) Releases: @oak-network/[email protected] @oak-network/[email protected] [skip ci] --------- Co-authored-by: imstar15 <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Try to fix version number comparison script in Publish Dev action (#79) * Try to fix version number comparison script in Publish Dev action * docs(changeset): Deprecate the concept of rc version number by bumping up to 2.0.7 * Try to fix version number comparison script in Publish Dev action * Try to fix version number comparison script in Publish Dev action * RELEASING: Releasing 2 package(s) (#80) Releases: @oak-network/[email protected] @oak-network/[email protected] [skip ci] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Install eslint dependencies * Ran npm run lint against all files * Install husky,commit hook and make sure husky run successfully * Custom SDK options (#82) * Custom SDK options * Remove options * Fix test * Schedule XCMP price task (#83) * Schedule XCMP price task * Extract scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow function * docs(changeset): Schedule XCMP price task; Custom SDK options; * RELEASING: Releasing 2 package(s) (#85) Releases: @oak-network/[email protected] @oak-network/[email protected] [skip ci] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Update api-augment corresponding to oak-blockchain 2c8650449f2226e3e87e3f395ba2d4a9d1d8a19e (#84) * Implement toJSON function in Weight type (#87) * Remove getTimeAutomationFees RPC function (#86) * Remove getTimeAutomationFees RPC function * Update PRC interfaces * Restructured @oak-network/config library and merged @oak-network/sdk-types into config (#89) * Merged sdk-types with config package * Cleaned up old chain configs * Changed the format of config export * Added name attribute to config/chains * Update config - tsconfig.json and added README.md * Updated config’s index.ts to export types * Remove sdk-types in project configs (#90) --------- Co-authored-by: imstar15 <[email protected]> * Add auto-compound demo (#91) * Add auto-staking demo * Schedule dynamic dispatch task to auto-compound * Check if the auto-compound task is already scheduled * Add auto-compound reward demo (#92) * Add auto-compound reward demo * Reuse utils.js * Fix dynamic task demo (#93) * Fix dynamic task demo * Reuse utils.js * Set auto compound (#98) * Set auto compound * Add comments * Switch package management from npm to yarn and .gitignore package-lock.json (#100) * Switch package management from npm to yarn and .gitignore package-lock.json * Added comments to .gitignore * Added engine field to package.json * Update adapter and api-augment to match 34ba6b42bef658f9963f3f2e4cc34ff07857a26e (#94) * Fix adapter * Remove eslint-disable-next-line import/no-extraneous-dependencies * Update @polkadot/typegen, "@polkadot/types version to ^10.9.1 * Remove ChainData; Add instructionNetworkType to XcmConfig * Update sendExtrinsic to capture immediate extrinsic error (#102) * Update sendExtrinsic to capture immediate extrinsic error * Improve sendExtrinsic error handling * Remove .eslintfc * docs(changeset): Added automationPrice pallet and upgraded polkadot core to 0.9.43 * Update .github/workflows/release.yml to use yarn install * RELEASING: Releasing 5 package(s) (#105) Releases: @oak-network/[email protected] @oak-network/[email protected] @oak-network/[email protected] @oak-network/[email protected] @oak-network/[email protected] [skip ci] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: imstar15 <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 230c90a commit aba27a6

File tree

104 files changed

+21912
-25312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+21912
-25312
lines changed

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
packages/api-augment
4+
packages/types

.eslintrc.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"extends": ["airbnb-base", "airbnb-typescript/base", "prettier"],
3+
"plugins": [
4+
// this should be last
5+
"prettier"
6+
],
7+
"parserOptions": {
8+
"project": "./tsconfig.json"
9+
},
10+
"ignorePatterns": ["**/build"],
11+
"overrides": [
12+
{
13+
"files": ["**/*.test.ts"],
14+
"plugins": ["jest"],
15+
"extends": ["plugin:jest/all"],
16+
"rules": {
17+
"jest/prefer-expect-assertions": "off",
18+
"jest/no-hooks": "off",
19+
"import/no-extraneous-dependencies": "off"
20+
}
21+
}
22+
],
23+
"rules": {
24+
"prettier/prettier": "error",
25+
"sort-keys": ["error"],
26+
"import/prefer-default-export": "off",
27+
"import/no-default-export": "error",
28+
"import/no-cycle": "off"
29+
}
30+
}

.github/workflows/npm-publish-dev.yml

+27-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
- types
1818
- config
1919
- adapter
20-
- sdk-types
2120
- sdk
2221

2322
steps:
@@ -39,23 +38,38 @@ jobs:
3938
- name: 🔐 Authenticate with NPM
4039
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTOMATION_TOKEN_CHRIS }}" > ~/.npmrc
4140

42-
- name: Get max published version from npm
43-
id: get-max-version
41+
- name: Get the current dev version from npm
42+
id: get-current-dev-version
4443
run: |
44+
# Get the dev tag version
45+
tags=$(npm show @oak-network/${{ matrix.package }} dist-tags --json)
46+
echo "Tag versions: $tags"
47+
current_dev_version=$(echo "$tags" | jq -r '.dev')
48+
echo "Dev tag version: $current_dev_version"
49+
echo "current_dev_version=$current_dev_version" >> "$GITHUB_ENV"
50+
51+
# Get the latest version;
4552
all_versions=$(npm show @oak-network/${{ matrix.package }} versions --json)
46-
all_versions=$(echo "$all_versions" | tr -d ' \t\n\r')
47-
max_version=$(echo $all_versions | jq 'max' -r)
48-
echo "::set-output name=max_version::$max_version"
53+
echo "All versions: $all_versions"
54+
highest_version=$(echo "$all_versions" | tr -d ' \t\n\r' | jq 'max' -r)
55+
echo "Highest version: $highest_version"
56+
echo "highest_version=$highest_version" >> "$GITHUB_ENV"
4957
50-
- name: 🚀 Publish ${{ matrix.package }} package
58+
- name: 🚀 Publish ${{ matrix.package }} package if newer than latest
5159
working-directory: ./packages/${{ matrix.package }}/build
5260
run: |
53-
current_version=$(node -p "require('./package.json').version")
54-
max_version="${{ steps.get-max-version.outputs.max_version }}"
55-
if [ "$current_version" '>' "$max_version" ]; then
56-
echo "Current version: $current_version"
57-
echo "Max version: $max_version"
61+
new_version=$(node -p "require('./package.json').version")
62+
echo "New version from local build folder: $new_version"
63+
64+
# Debugging: Print the values of $highest_version and $current_dev_version
65+
echo "Current Dev Version: $current_dev_version"
66+
echo "Highest Version: $highest_version"
67+
68+
# Compare the new version with the current dev version and the highest version; If we publish a lower than the highest version, it will be rejected by npm.
69+
# TODO: I was not able to check if the new version is higher than both the current dev version and the highest version yet, so the check is very simple here. Ideally, we should check if the new version is higher.
70+
if [ "$new_version" != "$current_dev_version" ]; then
71+
echo "New version $new_version is different from NPM dev tag version $current_dev_version; publishing..."
5872
npm publish --tag dev
5973
else
60-
echo "Package is up to date."
74+
echo "Skip publish since there’s no higher version number."
6175
fi

.github/workflows/release.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ jobs:
1616
- name: 🤘 checkout
1717
uses: actions/checkout@v3
1818

19-
- name: Setup Node.js environment
20-
uses: actions/[email protected]
21-
with:
22-
node-version: 18.x
23-
cache: 'npm'
24-
25-
- name: Install Dependencies
26-
run: npm ci --ignore-scripts
19+
- name: Install dependencies
20+
run: yarn install
21+
22+
- name: Run build
23+
run: yarn build
2724

2825
- name: Create Release Pull Request
2926
uses: changesets/action@v1

.github/workflows/update-package-tags.yml

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
- types
1818
- config
1919
- adapter
20-
- sdk-types
2120
- sdk
2221

2322
steps:

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ dist
106106
build
107107

108108
.DS_Store
109+
110+
# Ignore package-lock.json to solely rely on yarn.lock
111+
package-lock.json

.husky/pre-commit

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged
5+
# npm test
6+

README.md

+135-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# oak.js OAK Network JavaScript SDK
22

3-
The `oak.js` library is a JavaScript extension of `polkadot.js` that provides type decorations for OAK Network functions. It requires the installation of the following packages:
3+
The `oak.js` library is a JavaScript extension of `polkadot.js`.
44

5+
It provides type decorations for OAK Network functions. It requires the installation of the following packages:
56
- `@oak-network/api-augment`, available at [npmjs.com/@oak-network/api-augment](https://www.npmjs.com/package/@oak-network/api-augment)
67
- `@oak-network/types`, available at [npmjs.com/@oak-network/types](https://www.npmjs.com/package/@oak-network/types)
78

89
JavaScript and TypeScript developers can leverage this library to make OAK-specific API calls, such as `timeAutomation.scheduleXcmpTask`. For more information on OAK's unique API, refer to the [Time Automation Explained in Documentation](https://docs.oak.tech/docs/time-automation-explained/) guide.
910

10-
## Usage
11+
In addition, it provides an SDK to help developers simplify the use of automation. It includes the following packages:
12+
- `@oak-network/sdk-types`, available at [npmjs.com/@oak-network/sdk-types](https://www.npmjs.com/package/@oak-network/sdk-types)
13+
- `@oak-network/config`, available at [npmjs.com/@oak-network/config](https://www.npmjs.com/package/@oak-network/config)
14+
- `@oak-network/adapter`, available at [npmjs.com/@oak-network/adapter](https://www.npmjs.com/package/@oak-network/adapter)
15+
- `@oak-network/sdk`, available at [npmjs.com/@oak-network/sdk](https://www.npmjs.com/package/@oak-network/sdk)
16+
17+
## Usage for the Foundational library
1118

1219
### Installation
1320

@@ -32,17 +39,76 @@ const { rpc, types } = require('@oak-network/types');
3239
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
3340
```
3441

42+
## Usage of the SDK Library
43+
44+
### Installation
45+
46+
Run the following commands to install the required packages:
47+
48+
```bash
49+
npm i @oak-network/sdk-types@latest
50+
npm i @oak-network/config@latest
51+
npm i @oak-network/adapter@latest
52+
npm i @oak-network/sdk@latest
53+
```
54+
55+
### Developing Applications with the SDK
56+
57+
To develop applications using the SDK, you can refer to the test code as an example. Here's a step-by-step guide:
58+
59+
- Start by exporting configurations from @oak-network/config.
60+
61+
- Construct a Polkadot API.
62+
63+
- Build and initialize an adapter. Utilize the methods provided by the adapter for standard operations.
64+
65+
- For more complex operations that involve data exchange between multiple adapters, such as `scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow`, you can leverage the functions provided by the SDK package.
66+
67+
For example:
68+
69+
```
70+
// Create keyringPair
71+
keyringPair = await getKeyringPair();
72+
73+
// Get configs
74+
const turingConfig = getOakConfig();
75+
const mangataConfig = getMangataConfig();
76+
77+
// Initialize adapters
78+
turingApi = await ApiPromise.create({ provider: new WsProvider(turingConfig.endpoint), rpc, types, runtime });
79+
turingAdapter = new OakAdapter(turingApi, turingConfig);
80+
await turingAdapter.initialize();
81+
82+
mangataSdk = Mangata.getInstance([mangataConfig.endpoint]);
83+
mangataApi = await mangataSdk.getApi();
84+
mangataAdapter = new MangataAdapter(mangataApi, mangataConfig);
85+
await mangataAdapter.initialize();
86+
87+
// Make task payload extrinsic
88+
const taskPayloadExtrinsic = mangataApi.tx.system.remarkWithEvent('hello!');
89+
90+
// Schedule task with sdk
91+
const executionTimes = [getHourlyTimestamp(1)/1000];
92+
await Sdk().scheduleXcmpTaskWithPayThroughSoverignAccountFlow({
93+
oakAdapter: turingAdapter,
94+
destinationChainAdapter: mangataAdapter,
95+
taskPayloadExtrinsic,
96+
schedule: { Fixed: { executionTimes } },
97+
keyringPair,
98+
});
99+
```
100+
35101
## Development
36102
If you would like to develop or test the code in this repository, please follow the guidelines below.
37103

38104
### Installation
39105
Run the following command to install the necessary dependencies:
40106

41107
```bash
42-
npm i
108+
yarn # Please use yarn to install dependencies due to the use of Yarn Workspace
43109
```
44110

45-
### Running Tests
111+
### Running Foundational Tests
46112
By default, the tests are configured to target your local development environment. Before running any commands, please follow the steps in the [Quickstart: run Local Network with Zombienet](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9946#/accounts) guide to build and run a local relay chain and parachain.
47113

48114
Once the Turing Dev network is running, you should be able to see it on [polkadot.js.org/apps](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9946#/accounts).
@@ -51,20 +117,77 @@ The default WebSocket endpoint is `ws://127.0.0.1:9946` and the default test wa
51117

52118
You can start the tests by running the following command:
53119
```bash
54-
npm run test
120+
yarn run test
55121
```
56122

57123
Please note that the tests are not meant to be repeatedly run against live networks. However, you can run them against the Turing Staging environment using the following command:
58124
```bash
59-
ENV="Turing Staging" MNEMONIC="<MNEMONIC>" npm run test
125+
ENV="Turing Staging" MNEMONIC="<MNEMONIC>" yarn run test
60126
```
61127

62128
You can also specify the endpoint in the Turing Dev environment:
63129

64130
```bash
65-
MNEMONIC="<MNEMONIC>" ENDPOINT="ws://127.0.0.1:9944" npm run test
131+
MNEMONIC="<MNEMONIC>" ENDPOINT="ws://127.0.0.1:9944" yarn run test
66132
```
67133

134+
### SDK Tests
135+
136+
You can start the tests by running the following command:
137+
138+
```bash
139+
MNEMONIC="<MNEMONIC>" ENV="Turing Staging" yarn run test:sdk
140+
```
141+
142+
If you wish to perform local testing, you'll need to launch the parachain test network yourself using the following command:
143+
144+
```bash
145+
zombienet spawn zombienets/turing/moonbase.toml
146+
```
147+
148+
This command will initiate the test network for parachains.
149+
150+
Then, you'll need to specify a test suite since each suite executes tests for a single parachains.
151+
152+
```bash
153+
yarn run test:sdk -- -t test-mangata
154+
```
155+
156+
## File structure
157+
158+
```
159+
.
160+
├── LICENSE
161+
├── README.md
162+
├── babel.config.js
163+
├── demo
164+
├── jest.config.js
165+
├── media
166+
├── package.json
167+
├── packages
168+
│ ├── adapter
169+
│ ├── api-augment
170+
│ ├── config
171+
│ ├── sdk
172+
│ ├── sdk-types
173+
│ └── types
174+
├── scripts
175+
│ └── package-setup
176+
├── templates
177+
│ └── index.cjs
178+
├── test
179+
│ ├── functional
180+
│ ├── sdk
181+
│ └── utils
182+
├── tsconfig.build.json
183+
├── tsconfig.json
184+
```
185+
186+
- `packages`: It store individual code libraries for various parts of the project.
187+
- `scripts/package-setup`: It is a script used for building packages. It utilizes templates/index.cjs as a script.
188+
- `test`: The `test` folder contains test programs. `test/functional` is used for testing the Foundational library, while `test/sdk` is used for testing the SDK library.
189+
- `demo`: It contains example code for developers to learn from.
190+
68191
## Updating the packages
69192
To update the code of both packages in this repository, you will first need to run a local version of the Turing Network. Then, using a script and leveraging the chain's API, you can automatically update the TypeScript code in the packages.
70193

@@ -80,19 +203,19 @@ zombienet spawn zombienets/turing/single-chain.toml
80203
You are now ready to update the packages' code in this oak.js project. From the root of this project, run the following commands:
81204

82205
```bash
83-
npm install
206+
yarn
84207
cd packages/api-augment
85-
npm run clean:defs
86-
npm run generate
208+
yarn run clean:defs
209+
yarn run generate
87210
```
88211

89212
## 3. Rebuilding packages
90213

91214
The last step is to build the packages' source code in preparation for publishing. Navigate back to the root of the oak.js directory and run the following commands:
92215

93216
```bash
94-
npm run clean
95-
npm run build
217+
yarn run clean
218+
yarn run build
96219
```
97220

98221
The build command will generate distribution files under `packages/api-augment/build`.

babel.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
presets: [
3-
['@babel/preset-env', {targets: {node: 'current'}}],
4-
'@babel/preset-typescript',
3+
["@babel/preset-env", { targets: { node: "current" } }],
4+
"@babel/preset-typescript",
55
],
66
};

demo/babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
3+
};

0 commit comments

Comments
 (0)