Skip to content

Commit

Permalink
Merge pull request #435 from polywrap/prealpha-dev
Browse files Browse the repository at this point in the history
Prep 0.0.1-prealpha.31
  • Loading branch information
dOrgJelli authored Aug 18, 2021
2 parents 33085a8 + 174dc8d commit 696487f
Show file tree
Hide file tree
Showing 135 changed files with 3,006 additions and 2,814 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Web3API 0.0.1-prealpha.31
## Features
* Use Binaryen's Asyncify to support async Wasm import calls. Deprecate the Wasm threading model we were using previously. This now means that the client now supports all browsers, as it no longer requires `SharedArrayBuffer` & the `atomics` library.
* `@web3api/graph-node-plugin-js`: Finalized the graph-node plugin implementation, added e2e tests. It currently only works with the hosted service.

## Bugs
* Removed support for UInt64 & Int64 base types. More info [here](https://github.com/polywrap/monorepo/pull/414).
* `@web3api/cli`: Properly validate all required exports from Web3API Wasm modules at compile-time.
* `@web3api/ethereum-plugin-js`: Properly support smart contract methods with structures as arguments.

# Web3API 0.0.1-prealpha.30
## Bugs
* `@web3api/ethereum-plugin-js`: Fix ethers.js inconsistencies.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-prealpha.30
0.0.1-prealpha.31
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"reset": "yarn clean && yarn && yarn build",
"clean": "npx rimraf ./**/node_modules ./**/build ./**/coverage ./**/.w3",
"build": "lerna run build --no-private --ignore @web3api/cli* --ignore @web3api/react && lerna run build --scope @web3api/client-js --scope @web3api/react && lerna run build --scope @web3api/cli",
"lint": "lerna run lint",
"lint": "lerna run lint --ignore @web3api/uts46-plugin-js",
"lint:fix": "lerna run lint -- --fix",
"lint:ci": "lerna run lint",
"lint:ci": "yarn lint",
"test": "lerna run test --no-private --ignore @web3api/client-js && lerna run test --scope @web3api/client-js",
"test:ci": "lerna run test:ci --no-private --ignore @web3api/client-js && lerna run test:ci --scope @web3api/client-js",
"version:apply": "npx lerna version $(cat VERSION) --exact --no-git-tag-version --yes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Pair, Route, Token } from "./types";
import { getPairData, getRedirects, getTokenList, getUniPairs } from "../testUtils";
import * as uni from "@uniswap/sdk";

jest.setTimeout(90000);
jest.setTimeout(360000);

describe('Route', () => {

Expand Down
2 changes: 1 addition & 1 deletion packages/apis/uniswapv2/src/common/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum Rounding {
type TradeOptions {
allowedSlippage: String!
recipient: String!
unixTimestamp: UInt64!
unixTimestamp: UInt32!
ttl: UInt32
deadline: UInt32
feeOnTransfer: Boolean
Expand Down
60 changes: 30 additions & 30 deletions packages/apis/uniswapv2/src/utils/PriorityQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,68 @@
It is assumed that any mutations of Key don't change sort order.
*/
export class PriorityQueue<Key> {
private readonly pq: (Key | null)[];
private n: i32 = 0;
private readonly compareTo: (left: Key, right: Key) => i32;
private readonly _pq: (Key | null)[];
private _n: i32 = 0;
private readonly _compareTo: (left: Key, right: Key) => i32;

constructor(comparator: (left: Key, right: Key) => i32, capacity: i32 = 0) {
this.pq = new Array<Key | null>(capacity + 1);
this.pq[0] = null; // 0 index must be null for heap tree math
this.compareTo = comparator;
this._pq = new Array<Key | null>(capacity + 1);
this._pq[0] = null; // 0 index must be null for heap tree math
this._compareTo = comparator;
}

public toArray(): Key[] {
return this.pq
return this._pq
.filter((v: Key | null) => v != null)
.map<Key>((v: Key | null) => v!); // eslint-disable-line @typescript-eslint/no-non-null-assertion
}

public isEmpty(): boolean {
return this.n == 0;
return this._n == 0;
}

public length(): i32 {
return this.n;
return this._n;
}

public insert(v: Key): void {
this.pq.push(v);
this.swim(++this.n);
this._pq.push(v);
this._swim(++this._n);
}

public delMax(): Key | null {
if (this.n < 1) return null;
const max: Key | null = this.pq[1];
this.exch(1, this.n--);
this.pq.pop();
this.sink(1);
if (this._n < 1) return null;
const max: Key | null = this._pq[1];
this._exch(1, this._n--);
this._pq.pop();
this._sink(1);
return max;
}

private less(i: i32, j: i32): boolean {
private _less(i: i32, j: i32): boolean {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.compareTo(this.pq[i]!, this.pq[j]!) < 0;
return this._compareTo(this._pq[i]!, this._pq[j]!) < 0;
}

private exch(i: i32, j: i32): void {
const t: Key | null = this.pq[i];
this.pq[i] = this.pq[j];
this.pq[j] = t;
private _exch(i: i32, j: i32): void {
const t: Key | null = this._pq[i];
this._pq[i] = this._pq[j];
this._pq[j] = t;
}

private swim(k: i32): void {
while (k > 1 && this.less(k / 2, k)) {
this.exch(k / 2, k);
private _swim(k: i32): void {
while (k > 1 && this._less(k / 2, k)) {
this._exch(k / 2, k);
k = k / 2;
}
}

private sink(k: i32): void {
while (2 * k <= this.n) {
private _sink(k: i32): void {
while (2 * k <= this._n) {
let j: i32 = 2 * k;
if (j < this.n && this.less(j, j + 1)) j++;
if (!this.less(k, j)) break;
this.exch(k, j);
if (j < this._n && this._less(j, j + 1)) j++;
if (!this._less(k, j)) break;
this._exch(k, j);
k = j;
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
"lib_compiler_noInit": "WASM module is missing the _w3_init export. This should never happen...",
"lib_compiler_noInvoke": "WASM module is missing the _w3_invoke export. This should never happen...",
"lib_compiler_dup_code_folder": "Duplicate code generation folder found `{directory}`. Please ensure each module file is located in a unique directory.",
"lib_compiler_missing_export__w3_init": "_w3_init is not exported from the built module `{moduleName}`",
"lib_compiler_missing_export__w3_invoke": "_w3_invoke is not exported from the built module `{moduleName}`",
"lib_compiler_missing_export": "{missingExport} is not exported from the WASM module `{moduleName}`",
"lib_generators_projectGenerator_fallback": "Falling back to the local Yarn cache.",
"lib_generators_projectGenerator_offline": "You appear to be offline.",
"lib_helpers_manifest_loadError": "Failed to load manifest from {path}",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
"lib_compiler_noInit": "WASM module is missing the _w3_init export. This should never happen...",
"lib_compiler_noInvoke": "WASM module is missing the _w3_invoke export. This should never happen...",
"lib_compiler_dup_code_folder": "Duplicate code generation folder found `{directory}`. Please ensure each module file is located in a unique directory.",
"lib_compiler_missing_export__w3_init": "_w3_init is not exported from the built module `{moduleName}`",
"lib_compiler_missing_export__w3_invoke": "_w3_invoke is not exported from the built module `{moduleName}`",
"lib_compiler_missing_export": "{missingExport} is not exported from the WASM module `{moduleName}`",
"lib_generators_projectGenerator_fallback": "Falling back to the local Yarn cache.",
"lib_generators_projectGenerator_offline": "You appear to be offline.",
"lib_helpers_manifest_loadError": "Failed to load manifest from {path}",
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/__tests__/project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ RUN ./node_modules/.bin/asc src/mutation/w3/entry.ts \
--outFile ./build/mutation.wasm \
--use abort=src/mutation/w3/entry/w3Abort \
--optimize --debug --importMemory \
--runtime stub
--runtime stub \
--runPasses asyncify
# Build the module at src/query
RUN ./node_modules/.bin/asc src/query/w3/entry.ts \
--path ./node_modules \
--outFile ./build/query.wasm \
--use abort=src/query/w3/entry/w3Abort \
--optimize --debug --importMemory \
--runtime stub
--runtime stub \
--runPasses asyncify
6 changes: 0 additions & 6 deletions packages/cli/src/__tests__/project/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ scalar UInt
scalar UInt8
scalar UInt16
scalar UInt32
scalar UInt64
scalar Int
scalar Int8
scalar Int16
scalar Int32
scalar Int64
scalar Bytes
scalar BigInt
Expand Down Expand Up @@ -235,12 +233,10 @@ scalar UInt
scalar UInt8
scalar UInt16
scalar UInt32
scalar UInt64
scalar Int
scalar Int8
scalar Int16
scalar Int32
scalar Int64
scalar Bytes
scalar BigInt
Expand Down Expand Up @@ -461,12 +457,10 @@ scalar UInt
scalar UInt8
scalar UInt16
scalar UInt32
scalar UInt64
scalar Int
scalar Int8
scalar Int16
scalar Int32
scalar Int64
scalar Bytes
scalar BigInt
Expand Down
17 changes: 14 additions & 3 deletions packages/cli/src/lib/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,15 @@ export class Compiler {
private async _validateExports(
moduleName: InvokableModules,
buildDir: string
) {
): Promise<void> {
let missingExport: string | undefined;
const wasmSource = fs.readFileSync(
path.join(buildDir, `${moduleName}.wasm`)
);

const mod = await WebAssembly.compile(wasmSource);
const memory = new WebAssembly.Memory({ initial: 1 });

const instance = await WebAssembly.instantiate(mod, {
env: {
memory,
Expand All @@ -447,12 +450,20 @@ export class Compiler {
});

if (!instance.exports._w3_init) {
throw Error(intlMsg.lib_compiler_missing_export__w3_init({ moduleName }));
missingExport = "_w3_init";
}

if (!instance.exports._w3_invoke) {
missingExport = "_w3_invoke";
}

if (!instance.exports.w3Abort) {
missingExport = "w3Abort";
}

if (missingExport) {
throw Error(
intlMsg.lib_compiler_missing_export__w3_invoke({ moduleName })
intlMsg.lib_compiler_missing_export({ missingExport, moduleName })
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ RUN ./node_modules/.bin/asc {{dir}}/w3/entry.ts \
--outFile ./build/{{name}}.wasm \
--use abort={{dir}}/w3/entry/w3Abort \
--optimize --debug --importMemory \
--runtime stub
--runtime stub \
--runPasses asyncify
{{/web3api_modules}}
Empty file added packages/js/asyncify/README.md
Empty file.
11 changes: 11 additions & 0 deletions packages/js/asyncify/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
collectCoverage: true,
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"],
globals: {
'ts-jest': {
diagnostics: false
}
}
};
36 changes: 36 additions & 0 deletions packages/js/asyncify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@web3api/asyncify-js",
"description": "Async Wasm Imports Support Using Asyncify",
"version": "0.0.1-prealpha.30",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/web3-api/monorepo.git"
},
"main": "build/index.js",
"files": [
"build"
],
"scripts": {
"build": "rimraf ./build && tsc --project tsconfig.build.json",
"lint": "eslint --color --ext .ts --ignore-pattern src/__tests__/cases/* src/",
"test": "jest --passWithNoTests --runInBand --verbose=true",
"test:ci": "jest --passWithNoTests --runInBand --verbose",
"test:watch": "jest --watch --passWithNoTests --verbose"
},
"devDependencies": {
"@types/jest": "26.0.8",
"assemblyscript": "0.19.10",
"jest": "26.6.3",
"rimraf": "3.0.2",
"ts-jest": "26.5.4",
"ts-loader": "8.0.17",
"ts-morph": "10.0.1",
"ts-node": "8.10.2",
"typescript": "4.0.7"
},
"gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a",
"publishConfig": {
"access": "public"
}
}
Loading

0 comments on commit 696487f

Please sign in to comment.