From c672085788f08092366683911a719265081c6e6b Mon Sep 17 00:00:00 2001 From: daniel <4954577+jaensen@users.noreply.github.com> Date: Wed, 4 Sep 2024 00:00:13 +0200 Subject: [PATCH] add PrivateKeyContractRunner --- package-lock.json | 44 +++++++++++++------------- package.json | 2 +- packages/abi-v1/package.json | 2 +- packages/abi-v2/package.json | 2 +- packages/adapter-cometh/package.json | 4 +-- packages/adapter-ethers/package.json | 4 +-- packages/adapter-ethers/src/index.ts | 37 ++++++++++++++++++++-- packages/adapter-safe-app/package.json | 4 +-- packages/adapter/package.json | 2 +- packages/data/package.json | 4 +-- packages/profiles/package.json | 4 +-- packages/sdk/package.json | 12 +++---- packages/tests/package-lock.json | 22 ++++++------- packages/utils/package.json | 2 +- 14 files changed, 89 insertions(+), 56 deletions(-) diff --git a/package-lock.json b/package-lock.json index b676b1b..8cac20d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cirlces-sdk/root", - "version": "0.8.0", + "version": "0.8.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cirlces-sdk/root", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "workspaces": [ "packages/abi-v1", @@ -6493,7 +6493,7 @@ }, "packages/abi-v1": { "name": "@circles-sdk/abi-v1", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "ethers": "^6.13.2" @@ -6504,7 +6504,7 @@ }, "packages/abi-v2": { "name": "@circles-sdk/abi-v2", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "ethers": "^6.13.2" @@ -6515,7 +6515,7 @@ }, "packages/adapter": { "name": "@circles-sdk/adapter", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "devDependencies": { "typescript": "^5.3.3" @@ -6523,10 +6523,10 @@ }, "packages/adapter-cometh": { "name": "@circles-sdk/adapter-cometh", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { - "@circles-sdk/adapter": "0.8.0", + "@circles-sdk/adapter": "0.8.1", "@cometh/connect-sdk": "1.2.29" }, "devDependencies": { @@ -6535,10 +6535,10 @@ }, "packages/adapter-ethers": { "name": "@circles-sdk/adapter-ethers", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { - "@circles-sdk/adapter": "0.8.0", + "@circles-sdk/adapter": "0.8.1", "ethers": "^6.13.2" }, "devDependencies": { @@ -6547,10 +6547,10 @@ }, "packages/adapter-safe-app": { "name": "@circles-sdk/adapter-safe-app", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { - "@circles-sdk/adapter": "0.8.0", + "@circles-sdk/adapter": "0.8.1", "@safe-global/safe-apps-sdk": "^9.1.0" }, "devDependencies": { @@ -6559,10 +6559,10 @@ }, "packages/data": { "name": "@circles-sdk/data", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { - "@circles-sdk/utils": "0.8.0" + "@circles-sdk/utils": "0.8.1" }, "devDependencies": { "typescript": "^5.3.3" @@ -6570,10 +6570,10 @@ }, "packages/profiles": { "name": "@circles-sdk/profiles", - "version": "0.8.0", + "version": "0.8.1", "license": "ISC", "dependencies": { - "@circles-sdk/utils": "0.8.0" + "@circles-sdk/utils": "0.8.1" }, "devDependencies": { "typescript": "^5.3.3" @@ -6581,14 +6581,14 @@ }, "packages/sdk": { "name": "@circles-sdk/sdk", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { - "@circles-sdk/abi-v1": "0.8.0", - "@circles-sdk/abi-v2": "0.8.0", - "@circles-sdk/adapter-ethers": "0.8.0", - "@circles-sdk/data": "0.8.0", - "@circles-sdk/profiles": "0.8.0", + "@circles-sdk/abi-v1": "0.8.1", + "@circles-sdk/abi-v2": "0.8.1", + "@circles-sdk/adapter-ethers": "0.8.1", + "@circles-sdk/data": "0.8.1", + "@circles-sdk/profiles": "0.8.1", "ethers": "^6.13.2", "multihashes": "^4.0.3" }, @@ -6599,7 +6599,7 @@ }, "packages/utils": { "name": "@circles-sdk/utils", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "bignumber.js": "^9.1.2" diff --git a/package.json b/package.json index f894c06..83acbae 100644 --- a/package.json +++ b/package.json @@ -35,5 +35,5 @@ }, "name": "@cirlces-sdk/root", "license": "MIT", - "version": "0.8.0" + "version": "0.8.1" } diff --git a/packages/abi-v1/package.json b/packages/abi-v1/package.json index 21ab6fb..2bce252 100644 --- a/packages/abi-v1/package.json +++ b/packages/abi-v1/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/abi-v1", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/packages/abi-v2/package.json b/packages/abi-v2/package.json index 3f8cde0..b67da78 100644 --- a/packages/abi-v2/package.json +++ b/packages/abi-v2/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/abi-v2", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/packages/adapter-cometh/package.json b/packages/adapter-cometh/package.json index e6da8c6..1fa9566 100644 --- a/packages/adapter-cometh/package.json +++ b/packages/adapter-cometh/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter-cometh", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/adapter": "0.8.0", + "@circles-sdk/adapter": "0.8.1", "@cometh/connect-sdk": "1.2.29" }, "keywords": [], diff --git a/packages/adapter-ethers/package.json b/packages/adapter-ethers/package.json index 9389ead..25d6e57 100644 --- a/packages/adapter-ethers/package.json +++ b/packages/adapter-ethers/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter-ethers", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -18,7 +18,7 @@ }, "dependencies": { "ethers": "^6.13.2", - "@circles-sdk/adapter": "0.8.0" + "@circles-sdk/adapter": "0.8.1" }, "keywords": [], "author": "", diff --git a/packages/adapter-ethers/src/index.ts b/packages/adapter-ethers/src/index.ts index 330a9fe..bd95eae 100644 --- a/packages/adapter-ethers/src/index.ts +++ b/packages/adapter-ethers/src/index.ts @@ -5,9 +5,9 @@ import { ContractRunner, Provider, TransactionRequest, - TransactionResponse + TransactionResponse, Wallet } from 'ethers'; -import { SdkContractRunner } from '@circles-sdk/adapter'; +import {SdkContractRunner} from '@circles-sdk/adapter'; export abstract class EthersContractRunner implements ContractRunner { abstract address?: string; @@ -20,6 +20,39 @@ export abstract class EthersContractRunner implements ContractRunner { abstract init(): Promise; } +export class PrivateKeyContractRunner implements EthersContractRunner { + constructor(public provider: Provider, private privateKey: string) { + } + + private _wallet?: Wallet; + + async init(): Promise { + this._wallet = new Wallet(this.privateKey, this.provider); + this.address = await this._wallet.getAddress(); + } + + private ensureWallet(): Wallet { + if (!this._wallet) { + throw new Error('Not initialized'); + } + return this._wallet; + } + + address?: string; + estimateGas?: ((tx: TransactionRequest) => Promise) | undefined = async (tx) => { + return this.ensureWallet().estimateGas(tx); + }; + call?: ((tx: TransactionRequest) => Promise) | undefined = async (tx) => { + return this.ensureWallet().call(tx); + }; + resolveName?: ((name: string) => Promise) | undefined = async (name) => { + return this.ensureWallet().resolveName(name); + }; + sendTransaction?: ((tx: TransactionRequest) => Promise) | undefined = async (tx) => { + return this.ensureWallet().sendTransaction(tx); + }; +} + export class BrowserProviderContractRunner implements EthersContractRunner { constructor() { const w: any = window; diff --git a/packages/adapter-safe-app/package.json b/packages/adapter-safe-app/package.json index bcc1383..a8fc6a0 100644 --- a/packages/adapter-safe-app/package.json +++ b/packages/adapter-safe-app/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter-safe-app", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/adapter": "0.8.0", + "@circles-sdk/adapter": "0.8.1", "@safe-global/safe-apps-sdk": "^9.1.0" }, "keywords": [], diff --git a/packages/adapter/package.json b/packages/adapter/package.json index f6fa908..6ea3743 100644 --- a/packages/adapter/package.json +++ b/packages/adapter/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/packages/data/package.json b/packages/data/package.json index 88b654c..29a0c9c 100644 --- a/packages/data/package.json +++ b/packages/data/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/data", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/utils": "0.8.0" + "@circles-sdk/utils": "0.8.1" }, "keywords": [], "author": "", diff --git a/packages/profiles/package.json b/packages/profiles/package.json index cf8aa84..b84a017 100644 --- a/packages/profiles/package.json +++ b/packages/profiles/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/profiles", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/utils": "0.8.0" + "@circles-sdk/utils": "0.8.1" }, "keywords": [], "author": "", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 1d96ca2..8c64813 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/sdk", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,11 +17,11 @@ "author": "", "license": "MIT", "dependencies": { - "@circles-sdk/abi-v1": "0.8.0", - "@circles-sdk/abi-v2": "0.8.0", - "@circles-sdk/data": "0.8.0", - "@circles-sdk/profiles": "0.8.0", - "@circles-sdk/adapter-ethers": "0.8.0", + "@circles-sdk/abi-v1": "0.8.1", + "@circles-sdk/abi-v2": "0.8.1", + "@circles-sdk/data": "0.8.1", + "@circles-sdk/profiles": "0.8.1", + "@circles-sdk/adapter-ethers": "0.8.1", "ethers": "^6.13.2", "multihashes": "^4.0.3" }, diff --git a/packages/tests/package-lock.json b/packages/tests/package-lock.json index 5b0acc3..f979375 100644 --- a/packages/tests/package-lock.json +++ b/packages/tests/package-lock.json @@ -27,7 +27,7 @@ }, "../abi-v1": { "name": "@circles-sdk/abi-v1", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "ethers": "^6.13.2" @@ -38,7 +38,7 @@ }, "../abi-v2": { "name": "@circles-sdk/abi-v2", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "ethers": "^6.13.2" @@ -85,10 +85,10 @@ }, "../data": { "name": "@circles-sdk/data", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { - "@circles-sdk/utils": "0.8.0" + "@circles-sdk/utils": "0.8.1" }, "devDependencies": { "typescript": "^5.3.3" @@ -96,14 +96,14 @@ }, "../sdk": { "name": "@circles-sdk/sdk", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { - "@circles-sdk/abi-v1": "0.8.0", - "@circles-sdk/abi-v2": "0.8.0", - "@circles-sdk/adapter-ethers": "0.8.0", - "@circles-sdk/data": "0.8.0", - "@circles-sdk/profiles": "0.8.0", + "@circles-sdk/abi-v1": "0.8.1", + "@circles-sdk/abi-v2": "0.8.1", + "@circles-sdk/adapter-ethers": "0.8.1", + "@circles-sdk/data": "0.8.1", + "@circles-sdk/profiles": "0.8.1", "ethers": "^6.13.2", "multihashes": "^4.0.3" }, @@ -114,7 +114,7 @@ }, "../utils": { "name": "@circles-sdk/utils", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "bignumber.js": "^9.1.2" diff --git a/packages/utils/package.json b/packages/utils/package.json index 96af883..33bff27 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/utils", - "version": "0.8.0", + "version": "0.8.1", "description": "", "type": "module", "main": "./dist/index.js",