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

Multi backend #154

Merged
merged 77 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
249a564
npm: Bump to v0.3.1
Apr 12, 2023
7d76842
ledger/backend: Move ethereum specific files to backend/ethereum
Aug 22, 2023
a8e6056
yarn: Add polkadot dependencies
Aug 22, 2023
a9efaff
erdstall: Create ErdstallBackend{Client|Session} interfaces
Aug 22, 2023
2b0d912
src: Adjust template parameters to multi-backend design
Aug 22, 2023
2474a0e
ledger/backend/ethereum: Implement ErdstallBackend{Client|Session}
Aug 22, 2023
5b1fbd7
ledger/backend: Move reader, writer, signer, tokenprovider to top level
Aug 22, 2023
33bb34b
ledger/backend/substrate: Implement stubs for substrate
Aug 22, 2023
e1a5155
ledger/backend: Define unique interface file for supported backend def
Aug 22, 2023
ce5258f
client: Make top-level ErdstallClient impl multi-backend ready
Aug 22, 2023
1982b6c
session: Make top level ErdstallSession impl multi-backend ready
Aug 22, 2023
308e47a
ledger: Boyscout compile errors for multi-backend adaptation
Aug 22, 2023
aa6a7b9
api/responses: Update ClientConfig w/ ChainConfig array
Aug 22, 2023
c619199
ledger/assets: Implement ChainAssets
Aug 22, 2023
e54bb79
api: Adapt transactions to new ABI and wire encoding
Sep 7, 2023
19af8ce
test: Update mocks to new Asset types
Sep 7, 2023
c0721f1
ledger/backend/eth: Update to new Address/Signer/Signature abstraction
Sep 7, 2023
e89a814
ledger/backend/substrate: Update to new Address/Signature/Signer abstr.
Sep 7, 2023
6a4802c
api: Update to new wire encoding
Sep 7, 2023
b58f1c3
ledger/backend: Define abstract signer
Sep 7, 2023
07856d8
src: Update types to new wire encoding
Sep 7, 2023
bb8536b
backend/ethereum: Implement EthereumSigner
Sep 7, 2023
fba888d
api/transactions: Canonicalize transactions before signing
Sep 7, 2023
6aaa92b
backend/ethereum: Update Erdstall bindings
Sep 15, 2023
4e31e4e
ledger/backend: Add BalanceProof encoder abstraction
Sep 15, 2023
c1be652
erdstall: Use correct asset abstraction in interfaces and impl
Sep 15, 2023
349cb09
src: Remove ABI from backend agnostic types
Sep 15, 2023
c3096b4
backend/ethereum: Update contract bindings
Oct 6, 2023
14fe56a
crypto: Distinguish Address and Signature by Crypto not Backend
Oct 6, 2023
1808302
api/transactions: Update to new Erdstall API
Oct 6, 2023
5169c7e
ledger: Update Chain enum to include all Erdstall supported chains
Oct 6, 2023
29c5c1c
src: Use update crypto package for Address/Signature types
Oct 6, 2023
f990475
ledger/backend: Add Encoder abstraction for sig-verification
Oct 6, 2023
efe4e47
api/responses: Make BalanceProofs API compatible
Oct 6, 2023
91086ec
backend/ethereum: Implement backend
Oct 6, 2023
2ad111a
backend/substrate: Implement backend stubs
Oct 6, 2023
5794217
src: Boyscout source files and compile errors
Oct 6, 2023
46894ee
crypto: Add Asset abstraction for chains
Oct 6, 2023
afa9d9f
ledger/assets: Define Types for Encoder
Oct 6, 2023
1431ba5
backend/ethereum: Implement BalanceEncoder
Oct 6, 2023
44e5ee0
api/responses: BalanceProofs signature verification
Oct 6, 2023
96a6ef2
src: Boyscout compiler errors and imports
Oct 6, 2023
2a3961a
backend/substrate: Boyscout compiler errors
ndzik Oct 30, 2023
52ffbd2
crypto/substrate: Stub implementation for substrate signature
ndzik Oct 30, 2023
7f30709
crypto: Remove unnecessary ABI functions
ndzik Oct 30, 2023
8b1f9bc
Crypto WIP:
RmbRT Nov 2, 2023
9c4027a
WIP: Clean up + implement missing stuff.
RmbRT Nov 22, 2023
7085bfa
API: lift chain ID into backend-agnostic commands.
RmbRT Nov 22, 2023
0364fdd
Fixed balance proof signature encoding.
RmbRT Nov 22, 2023
2cfc89a
Removed unused test files.
RmbRT Nov 22, 2023
df1697a
Cleanup:
RmbRT Apr 24, 2024
a9fad4d
Used LocalAsset for NFTs in getNFTMetadata().
RmbRT Nov 22, 2023
b7ca6d6
Improved Asset support & eth-ABI decoding.
RmbRT Nov 22, 2023
13fb05e
- Simplify FullExit (added omitEmpty).
RmbRT Mar 6, 2024
89b2491
- Removed metadata.
RmbRT Apr 20, 2024
211ca51
- Added getWrappedToken() query.
RmbRT Apr 24, 2024
00da055
- Move TokenType to ethereum backend.
RmbRT Mar 6, 2024
e5239ab
- Removed TokenTypeRegistered event.
RmbRT Mar 20, 2024
c3c95b4
- Updated bindings.
RmbRT Apr 24, 2024
8aeb099
- Reintroduced balance proof handling.
RmbRT Apr 24, 2024
87e7b8c
- Reworked asset ABI.
RmbRT Apr 24, 2024
9d2bd00
- Asset ABI
RmbRT Apr 24, 2024
83f0da5
- eth: Reintroduced withdraw
RmbRT Apr 24, 2024
035b6ba
- Updated to ethers v6.
RmbRT Apr 24, 2024
6e0b6c4
- Reworked serialisation.
RmbRT Apr 20, 2024
3a1a2b9
- Cleanup
RmbRT Apr 20, 2024
df1180f
- Signature test.
RmbRT Apr 20, 2024
e73f5f5
- Added Asset.erdstallUserToken()
RmbRT Apr 20, 2024
76e85ec
- Multi-backend sessions / clients
RmbRT Apr 20, 2024
ce1ecd1
- Updated Ethereum backend
RmbRT Apr 24, 2024
83b32ab
- Fixed substrate signer.
RmbRT Apr 20, 2024
f350ee0
- Fixed assets
RmbRT Apr 20, 2024
6047a0a
- Deactivated outdated tests.
RmbRT Apr 20, 2024
69c21d3
- Added session end-to-end test.
RmbRT Apr 20, 2024
e98e093
Shut up!
RmbRT Apr 24, 2024
fc51f9f
Bump node.js version in CI.
RmbRT Apr 24, 2024
16780cc
Disable end-to-end test in CI for now.
RmbRT Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 21 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ jobs:
steps:
- name: "Checkout SDK"
uses: actions/checkout@v3
- name: "Prettier Check"
uses: creyD/[email protected]
with:
dry: True
prettier_options: --config .prettierrc --check **/*.ts
# - name: "Prettier Check"
# uses: creyD/[email protected]
# with:
# dry: True
# prettier_options: --config .prettierrc --check **/*.ts
- name: "Setup Node.js"
uses: actions/setup-node@v3
with:
DragonDev1906 marked this conversation as resolved.
Show resolved Hide resolved
node-version: "16"
node-version: "20"
cache: "yarn"
- name: "Install dependencies"
run: yarn install
- name: "Build"
run: yarn build
- name: "Test"
run: yarn test
- name: "Checkout Erdstall Core"
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIV_KEY }}
repository: "perun-network/erdstall-ext"
path: "erdstall"
- name: "Set up Go 1.x"
uses: actions/setup-go@v3
with:
go-version: ^1.17
- name: "Build walkthrough operator"
working-directory: "erdstall"
run: go build -o wo ./cmd/walkthrough/main.go
- name: "End-2-End Test"
run: ERDSTALL_EXE=erdstall/wo yarn test:e2e
# - name: "Checkout Erdstall Core"
# uses: actions/checkout@v3
# with:
# ssh-key: ${{ secrets.SSH_PRIV_KEY }}
# repository: "perun-network/erdstall-ext"
# path: "erdstall"
# - name: "Set up Go 1.x"
# uses: actions/setup-go@v3
# with:
# go-version: ^1.17
# - name: "Build walkthrough operator"
# working-directory: "erdstall"
# run: go build -o wo ./cmd/walkthrough/main.go
# - name: "End-2-End Test"
# run: ERDSTALL_EXE=erdstall/wo yarn test:e2e
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,3 @@ dist

# TernJS port file
.tern-port

# Generated abi bindings
src/ledger/backend/ethereum/abi
src/ledger/backend/ethereum/contracts
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ all: ts

ts:
@yarn install -s
@yarn run build -s
@yarn run build
@echo "Built erdstall-ts-sdk."

bindings:
Expand All @@ -14,6 +14,10 @@ test:
@echo "Compiling and executing tests."
@yarn run test

test-e2e:
@echo "Compiling and executing end-to-end tests."
@yarn run test:e2e:session

integration:
@echo "Compiling and running integration test."
@yarn run test:integration
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ omitted after each event name in the following.
- **`"ChallengeResponded"`**: the Erdstall operator successfully responed with the correct balance proof.

- **`"TokenTypeRegistered"`**: a new token type (such as ETH, ERC20, ERC721, etc.) has been registered with Erdstall on-chain.

- **`"TokenRegistered"`**: a specific token contract has been registered on-chain.
</details>

## Development
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polycrypt/erdstall",
"version": "0.3.0",
"version": "0.3.1",
"description": "SDK to interact with Erdstall Layer-2 Networks",
"main": "./index.js",
"exports": {
Expand Down Expand Up @@ -30,7 +30,9 @@
"lint": "eslint ./src --ext .ts",
"bindings": "./scripts/genbindings.sh",
"test:e2e": "env TS_NODE_PROJECT=\"tsconfig.e2e.json\" mocha -b --timeout 120000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register 'src/e2e/**/*.spec.ts'",
"test:e2e:session": "env TS_NODE_PROJECT=\"tsconfig.e2e.json\" mocha -b --timeout 120000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register 'src/e2e/operator_e2e.spec.ts'",
"test": "env TS_NODE_PROJECT=\"tsconfig.test.json\" mocha --timeout 15000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register 'src/{,!(e2e)/**}/*.spec.ts'",
"test-file": "env TS_NODE_PROJECT=\"tsconfig.test.json\" mocha --timeout 15000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register",
"prepack": "yarn build && tsc-alias -p tsconfig.json && ts-node ./scripts/prepack.ts ./package.json ./dist/package.json",
"devpub": "yarn prepack",
"doc": "typedoc ./src ./src/api ./src/enclave ./src/ledger ./src/ledger/backend ./src/test ./src/utils"
Expand Down Expand Up @@ -72,7 +74,7 @@
"ganache": "^7.0.2",
"ganache-cli": "^6.12.2",
"ganache-core": "^2.13.2",
"hardhat": "^2.4.0",
"hardhat": "^2.22.1",
"hardhat-waffle": "^0.0.1-security",
"jsdom": "^16.6.0",
"jsdom-global": "^3.0.2",
Expand All @@ -89,9 +91,13 @@
"walk": "^2.3.14"
},
"dependencies": {
"@polkadot/api": "^10.10.1",
"@polkadot/api-contract": "^10.10.1",
"@polkadot/util-crypto": "^12.5.1",
"axios": "^0.21.4",
"canonicalize": "^2.0.0",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.1",
"ethers": "^6.11.1",
"isomorphic-ws": "^4.0.1",
"number-generator": "^4.0.5",
"reflect-metadata": "^0.1.13",
Expand Down
7 changes: 3 additions & 4 deletions scripts/genbindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function compileTo() {
# Clean up existing bindings.
rm -rf "${2}"/contracts
mkdir -p "${2}"/contracts/abi
yarn hardhat compile && cp -rl ./typechain/* "${2}"/contracts/ \
yarn hardhat compile && cp -rl ./typechain-types/* "${2}"/contracts/ \
&& find ./artifacts/contracts/*.sol/ \
| grep -v ".dbg" | grep ".json" | xargs cp -l -t "${2}"/contracts/abi/
# Clean up typechain generated files.
rm -rf ./artifacts ./cache ./typechain
rm -rf ./artifacts ./cache ./typechain-types
cd "${CWD}"
}

Expand All @@ -62,8 +62,7 @@ if [[ ! -d $CONTRACTSDIR ]]; then
fi

SRCDIR="${PWD}"
ETHBACKEND="${SRCDIR}"/src/ledger/backend
ETHBACKEND_TEST="${SRCDIR}"/src/test/ledger/backend
ETHBACKEND="${SRCDIR}"/src/ledger/backend/ethereum

checkInstalled npm
checkInstalledLocally typechain
Expand Down
6 changes: 3 additions & 3 deletions src/api/calls/getaccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import { jsonObject, jsonMember } from "#erdstall/export/typedjson";
import { ErdstallObject, registerErdstallType } from "#erdstall/api";
import { Address } from "#erdstall/ledger";
import { Address, Crypto } from "#erdstall/crypto";

const getAccountTypeName = "GetAccount";

@jsonObject
export class GetAccount extends ErdstallObject {
@jsonMember(Address) who: Address;
@jsonMember(Address) who: Address<Crypto>;

constructor(who: Address) {
constructor(who: Address<Crypto>) {
super();
this.who = who;
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/calls/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import { jsonObject, jsonMember } from "#erdstall/export/typedjson";
import { ErdstallObject } from "#erdstall/api";
import { Address } from "#erdstall/ledger";
import { Address, Crypto } from "#erdstall/crypto";

@jsonObject
export class Onboarding extends ErdstallObject {
@jsonMember(Address) who: Address;
@jsonMember(Address) who: Address<Crypto>;

constructor(who: Address) {
constructor(who: Address<Crypto>) {
super();
this.who = who;
}
Expand Down
41 changes: 36 additions & 5 deletions src/api/calls/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

import { ErdstallObject, registerErdstallType } from "#erdstall/api";
import { Address } from "#erdstall/ledger";
import { Address, Crypto } from "#erdstall/crypto";
import { jsonObject, jsonMember } from "#erdstall/export/typedjson";

const subBPsTypeName = "SubscribeBalanceProofs";
Expand All @@ -11,10 +11,10 @@ const subPhaseShiftName = "SubscribePhaseShifts";

@jsonObject
export class SubscribeBalanceProofs extends ErdstallObject {
@jsonMember(Address) who?: Address;
@jsonMember(Address) who?: Address<Crypto>;
@jsonMember(Boolean) cancel?: boolean;

constructor(who?: Address, cancel?: boolean) {
constructor(who?: Address<Crypto>, cancel?: boolean) {
super();
this.who = who;
this.cancel = cancel;
Expand All @@ -23,17 +23,33 @@ export class SubscribeBalanceProofs extends ErdstallObject {
public objectType(): any {
return SubscribeBalanceProofs;
}

protected objectTypeName(): string {
return subBPsTypeName;
}

public static fromJSON(json: any): SubscribeBalanceProofs {
if (!json.who) {
throw new Error("expected who field in subscribe balance proofs");
}
const who = Address.ensure(json.who);
return new SubscribeBalanceProofs(who, json.cancel);
}

public static toJSON(obj: SubscribeBalanceProofs): any {
return {
who: obj.who?.toJSON(),
cancel: obj.cancel,
};
}
}

@jsonObject
export class SubscribeTXs extends ErdstallObject {
@jsonMember(Address) who?: Address;
@jsonMember(Address) who?: Address<Crypto>;
@jsonMember(Boolean) cancel?: boolean;

constructor(who?: Address, cancel?: boolean) {
constructor(who?: Address<Crypto>, cancel?: boolean) {
super();
this.who = who;
this.cancel = cancel;
Expand All @@ -45,6 +61,21 @@ export class SubscribeTXs extends ErdstallObject {
protected objectTypeName(): string {
return subTXsTypeName;
}

// public static fromJSON(json: any): SubscribeTXs {
// if (!json.who) {
// throw new Error("expected who field in subscribe transaction");
// }
// const who = Address.ensure(json.who);
// return new SubscribeTXs(who, json.cancel);
// }

// public static toJSON(obj: SubscribeTXs): any {
// return {
// who: obj.who?.toJSON(),
// cancel: obj.cancel,
// };
// }
}

@jsonObject
Expand Down
1 change: 0 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
export * from "./object";
export * from "./call";
export * from "./result";
export * from "./signature";

export * as calls from "./calls";
export * as responses from "./responses";
4 changes: 2 additions & 2 deletions src/api/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"use strict";

import {
jsonObject,
TypedJSON,
Serializable,
jsonObject,
} from "#erdstall/export/typedjson";
import { customJSON } from "./util";

Expand Down Expand Up @@ -34,7 +34,7 @@ export abstract class ErdstallObject {
return TypedJSON.parse(data, objectImpls.get(js.type)!)!;
}

static toJSON(me: ErdstallObject) {
static toJSON(me: ErdstallObject): any {
return {
type: me.objectTypeName(),
data: JSON.parse(TypedJSON.stringify(me, me.objectType())),
Expand Down
5 changes: 3 additions & 2 deletions src/api/responses/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

import {
jsonBigIntMember,
jsonU64Member,
jsonObject,
jsonMember,
} from "#erdstall/export/typedjson";
Expand All @@ -14,7 +14,7 @@ const accountTypeName = "AccountResponse";
@jsonObject
export class Account extends ErdstallObject {
@jsonMember(ledger.Account) account: ledger.Account;
@jsonBigIntMember() epoch: bigint;
@jsonU64Member() epoch: bigint;

constructor(account: ledger.Account, epoch: bigint) {
super();
Expand All @@ -25,6 +25,7 @@ export class Account extends ErdstallObject {
public objectType(): any {
return Account;
}

protected objectTypeName(): string {
return accountTypeName;
}
Expand Down
Loading
Loading