Skip to content

Commit

Permalink
add SafeSdkPrivateKeyContractRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed Oct 14, 2024
1 parent 12ad5ac commit 51ab0b1
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
},
"name": "@cirlces-sdk/root",
"license": "MIT",
"version": "0.13.0"
"version": "0.13.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.13.0",
"version": "0.13.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.13.0",
"version": "0.13.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.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/adapter": "0.13.0",
"@circles-sdk/adapter": "0.13.1",
"@cometh/connect-sdk": "1.2.29"
},
"keywords": [],
Expand Down
6 changes: 3 additions & 3 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.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -18,8 +18,8 @@
},
"dependencies": {
"ethers": "^6.13.2",
"@circles-sdk/adapter": "0.13.0",
"@circles-sdk/utils": "0.13.0"
"@circles-sdk/adapter": "0.13.1",
"@circles-sdk/utils": "0.13.1"
},
"keywords": [],
"author": "",
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.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/adapter": "0.13.0",
"@circles-sdk/adapter": "0.13.1",
"@safe-global/safe-apps-sdk": "^9.1.0"
},
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-safe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-safe",
"version": "0.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
49 changes: 48 additions & 1 deletion packages/adapter-safe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,56 @@ import {
TransactionRequest, TransactionResponse as SdkTransactionResponse
} from '@circles-sdk/adapter';
import Safe, {SafeConfig} from "@safe-global/protocol-kit";
import {BrowserProvider, Eip1193Provider, Provider} from "ethers";
import {BrowserProvider, Eip1193Provider, ethers, Provider} from "ethers";
import {MetaTransaction, OperationType} from "ethers-multisend";

export class SafeSdkPrivateKeyContractRunner implements SdkContractRunner {
address?: string;
safe?: Safe;
private rpcUrl: string;
private privateKey: string;

constructor(privateKey: string, rpcUrl: string) {
this.privateKey = privateKey;
this.rpcUrl = rpcUrl;
this.provider = new ethers.JsonRpcProvider(this.rpcUrl);
}

async init(safeAddress: string): Promise<void> {
this.address = safeAddress;
this.safe = await Safe.init({
provider: this.rpcUrl,
signer: this.privateKey,
safeAddress: safeAddress
});
}

provider: Provider;
estimateGas?: ((tx: SdkTransactionRequest) => Promise<bigint>) | undefined = async (tx) => this.provider.estimateGas(tx);
call?: ((tx: SdkTransactionRequest) => Promise<string>) | undefined = async (tx) => this.provider.call(tx);
resolveName?: ((name: string) => Promise<string | null>) | undefined = async (name) => this.provider.resolveName(name);
sendTransaction?: ((tx: SdkTransactionRequest) => Promise<SdkTransactionResponse>) | undefined = async (tx) => {
if (!this.safe) {
throw new Error("Safe not initialized")
}
const txs = await this.safe.createTransaction({
transactions: [{
to: tx.to,
value: (tx.value?.toString() ?? "0"),
data: tx.data
}]
});
const txResponse = await this.safe.executeTransaction(txs);
return <SdkTransactionResponse><unknown>txResponse.transactionResponse;
};
sendBatchTransaction?: () => BatchRun = () => {
if (!this.safe) {
throw new Error("Not initialized");
}
return new SafeBatchRun(this.safe);
}
}

export class SafeSdkBrowserContractRunner implements SdkContractRunner {
address?: string;
browserProvider: BrowserProvider;
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.13.0",
"version": "0.13.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.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.13.0"
"@circles-sdk/utils": "0.13.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.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.13.0"
"@circles-sdk/utils": "0.13.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.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,11 +17,11 @@
"author": "",
"license": "MIT",
"dependencies": {
"@circles-sdk/abi-v1": "0.13.0",
"@circles-sdk/abi-v2": "0.13.0",
"@circles-sdk/data": "0.13.0",
"@circles-sdk/profiles": "0.13.0",
"@circles-sdk/adapter-ethers": "0.13.0",
"@circles-sdk/abi-v1": "0.13.1",
"@circles-sdk/abi-v2": "0.13.1",
"@circles-sdk/data": "0.13.1",
"@circles-sdk/profiles": "0.13.1",
"@circles-sdk/adapter-ethers": "0.13.1",
"ethers": "^6.13.2",
"multihashes": "^4.0.3"
},
Expand Down
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.13.0",
"version": "0.13.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down

0 comments on commit 51ab0b1

Please sign in to comment.