Skip to content

Commit

Permalink
Adapter on Create (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Sep 13, 2024
1 parent 3caab0b commit ba88ea2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
9 changes: 5 additions & 4 deletions examples/send-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dotenv from "dotenv";
import { ethers } from "ethers";
import { loadArgs } from "./cli";
import { TransactionManager } from "../src";
import { nearAccountFromKeyPair } from "near-ca";
import { MpcContract, nearAccountFromKeyPair, NearEthAdapter } from "near-ca";
import { KeyPair } from "near-api-js";
import { KeyPairString } from "near-api-js/lib/utils";

Expand All @@ -20,13 +20,14 @@ async function main(): Promise<void> {
nodeUrl: "https://rpc.testnet.near.org",
},
});

const nearAdapter = await NearEthAdapter.fromConfig({
mpcContract: new MpcContract(nearAccount, options.mpcContractId),
});
const txManager = await TransactionManager.create({
ethRpc: process.env.ETH_RPC!,
erc4337BundlerUrl: process.env.ERC4337_BUNDLER_URL!,
nearAccount,
nearAdapter,
safeSaltNonce: options.safeSaltNonce,
mpcContractId: options.mpcContractId,
});
const transactions = [
// TODO: Replace dummy transaction with real user transaction.
Expand Down
20 changes: 7 additions & 13 deletions src/tx-manager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ethers } from "ethers";
import { NearEthAdapter, MpcContract, NearEthTxData, BaseTx } from "near-ca";
import { NearEthAdapter, NearEthTxData, BaseTx } from "near-ca";
import { Erc4337Bundler } from "./lib/bundler";
import { packSignature } from "./util";
import { getNearSignature } from "./lib/near";
import { UserOperation, UserOperationReceipt } from "./types";
import { MetaTransaction, encodeMulti } from "ethers-multisend";
import { ContractSuite } from "./lib/safe";
import { Account } from "near-api-js";

export class TransactionManager {
readonly provider: ethers.JsonRpcProvider;
Expand Down Expand Up @@ -41,25 +40,20 @@ export class TransactionManager {
static async create(config: {
ethRpc: string;
erc4337BundlerUrl: string;
nearAccount: Account;
mpcContractId: string;
nearAdapter: NearEthAdapter;
safeSaltNonce?: string;
}): Promise<TransactionManager> {
const adapter = config.nearAdapter;
const provider = new ethers.JsonRpcProvider(config.ethRpc);
const [nearAdapter, safePack] = await Promise.all([
NearEthAdapter.fromConfig({
mpcContract: new MpcContract(config.nearAccount, config.mpcContractId),
}),
ContractSuite.init(provider),
]);
const safePack = await ContractSuite.init(provider);
console.log(
`Near Adapter: ${nearAdapter.nearAccountId()} <> ${nearAdapter.address}`
`Near Adapter: ${adapter.nearAccountId()} <> ${adapter.address}`
);
const bundler = new Erc4337Bundler(
config.erc4337BundlerUrl,
await safePack.entryPoint.getAddress()
);
const setup = await safePack.getSetup([nearAdapter.address]);
const setup = await safePack.getSetup([adapter.address]);
const safeAddress = await safePack.addressForSetup(
setup,
config.safeSaltNonce
Expand All @@ -68,7 +62,7 @@ export class TransactionManager {
console.log(`Safe Address: ${safeAddress} - deployed? ${!safeNotDeployed}`);
return new TransactionManager(
provider,
nearAdapter,
adapter,
safePack,
bundler,
setup,
Expand Down

0 comments on commit ba88ea2

Please sign in to comment.