Skip to content

Commit

Permalink
add PrivateKeyContractRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed Sep 3, 2024
1 parent 3b499ba commit c672085
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 56 deletions.
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
},
"name": "@cirlces-sdk/root",
"license": "MIT",
"version": "0.8.0"
"version": "0.8.1"
}
2 changes: 1 addition & 1 deletion packages/abi-v1/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/abi-v1",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/abi-v2",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-cometh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-cometh",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -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": [],
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-ethers",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -18,7 +18,7 @@
},
"dependencies": {
"ethers": "^6.13.2",
"@circles-sdk/adapter": "0.8.0"
"@circles-sdk/adapter": "0.8.1"
},
"keywords": [],
"author": "",
Expand Down
37 changes: 35 additions & 2 deletions packages/adapter-ethers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +20,39 @@ export abstract class EthersContractRunner implements ContractRunner {
abstract init(): Promise<void>;
}

export class PrivateKeyContractRunner implements EthersContractRunner {
constructor(public provider: Provider, private privateKey: string) {
}

private _wallet?: Wallet;

async init(): Promise<void> {
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<bigint>) | undefined = async (tx) => {
return this.ensureWallet().estimateGas(tx);
};
call?: ((tx: TransactionRequest) => Promise<string>) | undefined = async (tx) => {
return this.ensureWallet().call(tx);
};
resolveName?: ((name: string) => Promise<string | null>) | undefined = async (name) => {
return this.ensureWallet().resolveName(name);
};
sendTransaction?: ((tx: TransactionRequest) => Promise<TransactionResponse>) | undefined = async (tx) => {
return this.ensureWallet().sendTransaction(tx);
};
}

export class BrowserProviderContractRunner implements EthersContractRunner {
constructor() {
const w: any = window;
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-safe-app/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/data",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.8.0"
"@circles-sdk/utils": "0.8.1"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions packages/profiles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/profiles",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.8.0"
"@circles-sdk/utils": "0.8.1"
},
"keywords": [],
"author": "",
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/sdk",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -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"
},
Expand Down
22 changes: 11 additions & 11 deletions packages/tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/utils",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down

0 comments on commit c672085

Please sign in to comment.