Skip to content

Commit

Permalink
Merging dev to main branch (#136)
Browse files Browse the repository at this point in the history
* Merge dev_bakup to dev branch (#108)

* Add a past time test for dynamic dispatch task (#103)

* Add a past time test for dynamic dispatch task

* Specific errors were thrown during testing

* Fix past time test with time slot

* Auto compound interfaces (#99)

* Fix adapter

* Auto compound interfaces

* 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

* Add tests for auto-compound

* Listen events

* Return after the reject or resolve statement

* Revert "Return after the reject or resolve statement"

This reverts commit a5fe124.

* Change ensureBalance to hasEnoughFreeBalance

* Rename test case names

* If the delegation does not exist, getAutoCompoundingDelegationPercentage return undefined

* Add description for Compound tests

---------

Co-authored-by: imstar15 <[email protected]>

* Return different instruction numbers based on the transactType (#110)

* Renamed chainData to chainConfig in adapters

* Added moment library root to fix test/sdk/sdk.test.ts dependency missing problem

* Updated to getChainConfig() in test/sdk/sdk.test.ts

* Added a temporary fix for MoonbeamAdapter fetchAndUpdateConfigs

* Defined build order in package.json to make sure config builds first

* Remove from git add from package.json

* Upgraded yarn to use the workspace feature

* Added root:true to make sure .eslintrc.json works as the root path

* Added custom errors to adapter package

* Updated dependency of adapter to config@^1.0.0

* Updated the dependencies among our packages

* Added isEthereum to all chains in the config package

* Added util functions to adapter

* Fix WeightToFee function in MangataAdapter (#111)

* Fix WeightToFee function in MangataAdapter

* Caculate unit by decimals

* Change chainData to chainConfig

* Fix mangata crossChainTransfer function

* Rename x2Params to interior

* Format code with .prettierrc

* Fixed Github Actions caused by the new yarn berry version (#112)

* Try to fix yarn@2 issue caused in Actions

* Fix a typo in Release Action

* Try to fix dependency missing issue in Actions

* Run yarn install with yarn berry version in local environment

* Turn off installConfig.immutable in .yarnrc.yml in github Actions

* Turn off installConfig.immutable in .yarnrc.yml in github Actions

* Added continue-on-error: true to changeset Pull Release in Action

* Remove testing trigger branch from .github/workflows/release.yml

* Updated Github Actions using yarn berry version

* Optimize typescript files based on eslint suggestions

* docs(changeset): Updated dependencies among @oak-network/packages to refer to the latest code instead of fixed version

* Reverted package reference strategy back to workspace:^1.0.0 (#114)

* Reverted package reference strategy back to workspace:^1.0.0

* docs(changeset): Reverted package reference strategy back to workspace:^1.0.0

* Fix publish dev version to NPM Github Actions (#116)

* Added ls command to print out the current path in Action

* Make sure postbuild script run

* Clean up github actions

* RELEASING: Releasing 5 package(s) (#115)

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>

* RELEASING: Releasing 5 package(s) (#117)

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>

* Update script/package-setup.js (#118)

* docs(changeset): SDK and adapter upgrades with automationPrice support

* Update package-setup.js

* RELEASING: Releasing 2 package(s) (#119)

Releases:
  @oak-network/[email protected]
  @oak-network/[email protected]

[skip ci]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Export utils constants and errors from adapters (#120)

* Export utils constants and errors from adapters

* docs(changeset): Export utils constants and errors from adapters

* Set the release action to trigger only on main branch

* Revert "Set the release action to trigger only on main branch"

This reverts commit 67900f5.

* RELEASING: Releasing 1 package(s) (#121)

Releases:
  @oak-network/[email protected]

[skip ci]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Add scheduleAs to task params (#122)

* Add scheduleAs to task params

* docs(changeset): Add scheduleAs to task params

* The scheduleAs parameter should be pass into schedule task function

* RELEASING: Releasing 1 package(s) (#123)

Releases:
  @oak-network/[email protected]

[skip ci]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Change oakAdapter account derivation (#125)

* Change oakAdapter account derivation

* docs(changeset): Change oakAdapter account derivation

* RELEASING: Releasing 2 package(s) (#127)

Releases:
  @oak-network/[email protected]
  @oak-network/[email protected]

[skip ci]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Rename xtokens to xTokens in astarAdapter (#126)

* Rename xtokens to xTokens in astarAdapter

* docs(changeset): Rename xtokens to xTokens in astarAdapter

* RELEASING: Releasing 1 package(s) (#128)

Releases:
  @oak-network/[email protected]

[skip ci]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Added currencyId to tokens of Turing chains (#129)

* docs(changeset): Export utils constants and errors from adapters

* Added currencyId to tokens of Turing chains

* docs(changeset): Added currency Id to the tokens registered on Turing chains

* Revert "docs(changeset): Export utils constants and errors from adapters"

This reverts commit d89c5fd.

* RELEASING: Releasing 1 package(s) (#131)

Releases:
  @oak-network/[email protected]

[skip ci]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Fix a problem where currencyId is not set on Turing chains (#132)

* Fix a problem where currencyId is not set on Turing chains

* docs(changeset): Fix a problem where currencyId is not set on Turing chains

* RELEASING: Releasing 1 package(s) (#133)

Releases:
  @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>
  • Loading branch information
4 people authored Dec 28, 2023
1 parent 37c32e3 commit 185ace0
Show file tree
Hide file tree
Showing 57 changed files with 13,926 additions and 9,933 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"root": true,
"extends": ["airbnb-base", "airbnb-typescript/base", "prettier"],
"plugins": [
// this should be last
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/npm-publish-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ jobs:
- name: 🤘 checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Yarn v2
run: npm install -g yarn@berry

- name: Install dependencies
run: yarn install

Expand All @@ -36,16 +44,16 @@ jobs:
id: get-current-dev-version
run: |
# Get the dev tag version
tags=$(yarn info @oak-network/${{ matrix.package }} dist-tags --json)
tags=$(yarn npm info @oak-network/${{ matrix.package }} --fields dist-tags --json)
echo "Tag versions: $tags"
current_dev_version=$(echo $tags | jq -r '.data.dev')
current_dev_version=$(echo $tags | jq -r '.["dist-tags"].dev')
echo "Dev tag version: $current_dev_version"
echo "current_dev_version=$current_dev_version" >> "$GITHUB_ENV"
# Get the latest version;
all_versions=$(yarn info @oak-network/${{ matrix.package }} versions --json)
echo "All versions: $all_versions"
highest_version=$(echo "$all_versions" | jq -r '.data[]' | sort -V | tail -n1)
# Get the latest version
all_versions=$(yarn npm info @oak-network/${{ matrix.package }} --fields versions --json)
echo "All versions: $all_versions"
highest_version=$(echo "$all_versions" | jq -r '.versions[]' | sort -V | tail -n1)
echo "Highest version: $highest_version"
echo "highest_version=$highest_version" >> "$GITHUB_ENV"
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- name: 🤘 checkout
- name: checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Yarn v2
run: npm install -g yarn@berry

- name: Install dependencies
run: yarn install
Expand All @@ -24,6 +32,7 @@ jobs:

- name: Create Release Pull Request
uses: changesets/action@v1
continue-on-error: true
with:
title: Changeset Version Bump
commit: Update the version of packages with .changeset md files
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/update-package-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Yarn v2
run: npm install -g yarn@berry

- name: 🔐 Authenticate with NPM
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTOMATION_TOKEN_CHRIS }}" > ~/.npmrc

- name: Get dev version of ${{ matrix.package }}
id: get-version
run: |
tags=$(yarn info @oak-network/${{ matrix.package }} dist-tags --json)
tags=$(yarn npm info @oak-network/${{ matrix.package }} --fields dist-tags --json)
echo "Tag versions: $tags"
dev_version=$(echo $tags | jq -r '.data.dev')
dev_version=$(echo $tags | jq -r '.["dist-tags"].dev')
echo "Dev tag version: $dev_version"
echo "::set-output name=dev_version::$dev_version"
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"trailingComma": "all",
"printWidth": 150
}
Binary file added .yarn/install-state.gz
Binary file not shown.
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs

enableImmutableInstalls: false # turn off this to allow yarn to update the yarn.lock file; this is to prevent yarn install from interruption in the Release Github Actions
54 changes: 44 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ In addition, it provides an SDK to help developers simplify the use of automatio

### Installation

To begin, determine the runtime version of the blockchain your code is connecting to. You can find the runtime version in the top-right corner of the [Polkadot.js app](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.turing.oak.tech).

![Runtime version in Polkadot.js](/media/runtime-version.png)

Next, locate the version number of the blockchain from the [OAK-blockchain Releases](https://github.com/OAK-Foundation/OAK-blockchain/releases) page. For example, in the "293 runtime & v1.9.0" release, "1.9.0" is the version number.

Run the following commands to install the required packages:
Run the following commands to install the latest packages:

```bash
npm i @oak-network/api-augment@latest
npm i @oak-network/types@latest
npm i @oak-network/api-augment
npm i @oak-network/types
```

### Including the Library in Your Code
Expand Down Expand Up @@ -99,14 +93,32 @@ await Sdk().scheduleXcmpTaskWithPayThroughSoverignAccountFlow({
## Development
If you would like to develop or test the code in this repository, please follow the guidelines below.

### Pre-requisites
Yarn version needs to be equal to or higher than 2 to use Yarn Workspace feature of this monorepo. First run the following command to check the version of Yarn:
```
yarn --version
```

Then if yarn version is lower than 2, run the following command to upgrade:
```
yarn set version berry
```

### Installation
Run the following command to install the necessary dependencies:

```bash
yarn # Please use yarn to install dependencies due to the use of Yarn Workspace
```

### Running Foundational Tests
### Maintaining dependencies across packages
The packages are referring each other by source code, so when one is updated, the new version will be used by other packages. For example, ./packages/sdk/package.json has the following dependency:
```
"@oak-network/adapter": "../adapter",
"@oak-network/config": "../config"
```

### Running Functional Tests
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.

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).
Expand Down Expand Up @@ -151,6 +163,28 @@ Then, you'll need to specify a test suite since each suite executes tests for a
yarn run test:sdk -- -t test-mangata
```

### Compound Tests

If you wish to perform local testing, you'll need to launch the parachain test network yourself using the following command:

```bash
zombienet spawn zombienets/turing/single-chain.toml
```

If the account hasn't been delegated on-chain yet, you can execute the following command to test the `delegateWithAutoCompound` interface.

```bash
MNEMONIC="<MNEMONIC>" ENV="Turing Dev" yarn run test:delegate
```

If the account has already been delegated on-chain, or if you've previously tested the `delegateWithAutoCompound` interface, you can execute the following command to test the `delegatorBondMore`, `setAutoCompound`, `getDelegation`, and `getAutoCompoundingDelegationPercentage` interfaces.

```bash
MNEMONIC="<MNEMONIC>" ENV="Turing Dev" yarn test:compound
```



## File structure

```
Expand Down
84 changes: 44 additions & 40 deletions demo/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,51 @@ export const getKeyringPair = async (ss58Format) => {
return keyringPair;
};

/* eslint-disable consistent-return */
export const sendExtrinsic = (api, extrinsic, keyPair) =>
new Promise((resolve, reject) => {
const signAndSend = async () => {
try {
const unsub = await extrinsic.signAndSend(keyPair, (result) => {
const { status, events, dispatchError } = result;
console.log("status.type: ", status.type);

if (status?.isFinalized) {
unsub();

if (dispatchError) {
if (dispatchError.isModule) {
const metaError = api.registry.findMetaError(dispatchError.asModule);
const { name, section } = metaError;
return reject(new Error(`${section}.${name}`));
}

return reject(new Error(dispatchError.toString()));
}

const event = _.find(events, ({ event: eventData }) => api.events.system.ExtrinsicSuccess.is(eventData));
if (event) {
return resolve({
blockHash: status?.asFinalized?.toString(),
events,
extrinsicHash: extrinsic?.hash?.toString(),
});
} else {
return reject(new Error(events.toString()));
}
}
});
} catch (ex) {
// Handle signing error such as user manually cancel the transaction
return reject(ex);
}
};

signAndSend();
});
new Promise((resolve, reject) => {
const signAndSend = async () => {
try {
const unsub = await extrinsic.signAndSend(keyPair, (result) => {
const { status, events, dispatchError } = result;
console.log("status.type: ", status.type);

if (status?.isFinalized) {
unsub();

if (dispatchError) {
if (dispatchError.isModule) {
const metaError = api.registry.findMetaError(
dispatchError.asModule,
);
const { name, section } = metaError;
return reject(new Error(`${section}.${name}`));
}

return reject(new Error(dispatchError.toString()));
}

const event = _.find(events, ({ event: eventData }) =>
api.events.system.ExtrinsicSuccess.is(eventData),
);
if (event) {
return resolve({
blockHash: status?.asFinalized?.toString(),
events,
extrinsicHash: extrinsic?.hash?.toString(),
});
}
return reject(new Error(events.toString()));
}
});
} catch (ex) {
// Handle signing error such as user manually cancel the transaction
return reject(ex);
}
};

signAndSend();
});

export const findEvent = (events, section, method) =>
events.find((e) => e.event.section === section && e.event.method === method);
Expand Down
33 changes: 21 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
{
"name": "oak.js",
"version": "2.0.0-rc.1",
"version": "2.1.0",
"repository": "https://github.com/oak-foundation/oak.js",
"author": "OAK Team <[email protected]>",
"license": "Apache-2.0",
"private": true,
"engines": {
"node": ">=18.16.0",
"npm": ">=9.5.1"
"yarn": ">=2"
},
"scripts": {
"build": "npm exec -- tsc --build tsconfig.build.json",
"postbuild": "scripts/package-setup",
"clean": "npm exec -- tsc --build --clean tsconfig.build.json",
"test": "npm run build && jest --verbose --forceExit --runInBand ./test/functional",
"test:sdk": "npm run build && jest --verbose --runInBand ./test/sdk",
"build:config": "yarn workspace @oak-network/config build",
"build:adapter": "yarn workspace @oak-network/adapter build",
"build:rest": "yarn workspace @oak-network/types build && yarn workspace @oak-network/api-augment build && yarn workspace @oak-network/sdk build",
"build": "yarn run build:config && yarn run build:adapter && yarn run build:rest && yarn run postbuild",
"postbuild": "node scripts/package-setup.js",
"clean": "yarn workspaces foreach --all run clean",
"test": "yarn build && jest --verbose --forceExit --runInBand ./test/functional",
"test:sdk": "yarn build && jest --verbose --runInBand ./test/sdk",
"test:delegate": "yarn build && jest --verbose --runInBand ./test/compound/delegate",
"test:compound": "yarn build && jest --verbose --runInBand ./test/compound/compound",
"changeset": "changeset",
"lint": "eslint . --ext .ts",
"prepare": "husky install"
},
"devDependencies": {
"@babel/preset-env": "^7.19.4",
"@babel/core": "^7.23.5",
"@babel/preset-env": "^7.23.5",
"@babel/preset-typescript": "^7.18.6",
"@changesets/cli": "^2.26.2",
"@types/babel__core": "^7",
"@types/jest": "^29.5.4",
"@types/lodash": "^4.14.191",
"@types/node": "^20.10.3",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"eslint": "^8.50.0",
Expand All @@ -35,8 +43,9 @@
"eslint-plugin-jest": "^27.4.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^8.0.3",
"jest": "26.6.3",
"jest": "29.7.0",
"lint-staged": "^14.0.1",
"moment": "^2.29.4",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.2"
Expand All @@ -46,9 +55,9 @@
],
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
"eslint --fix"
],
"*.ts": "eslint --cache --fix"
}
},
"packageManager": "[email protected]"
}
33 changes: 33 additions & 0 deletions packages/adapter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# @oak-network/adapter

## 0.2.3

### Patch Changes

- 0eaa448: Rename xtokens to xTokens in astarAdapter

## 0.2.2

### Patch Changes

- 9cfa4a9: Change oakAdapter account derivation

## 0.2.1

### Patch Changes

- 74c4832: Export utils constants and errors from adapters

## 0.2.0

### Minor Changes

- afb2cda: SDK and adapter upgrades with automationPrice support

## 0.1.6

### Patch Changes

- e139d8f: Updated dependencies among @oak-network/packages to refer to the latest code instead of fixed version
- 62a7082: Reverted package reference strategy back to workspace:^1.0.0
- Updated dependencies [e139d8f]
- @oak-network/config@1.0.1

## 0.1.5

### Patch Changes
Expand Down
Loading

0 comments on commit 185ace0

Please sign in to comment.