Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7524d7a
wip
ciaranightingale Jul 5, 2023
de65f04
merge main
ciaranightingale Jul 5, 2023
98c7018
wip
ciaranightingale Jul 12, 2023
820d4cc
Merge branch 'main' into ciara/tba
ciaranightingale Jul 12, 2023
4755ac0
merge main
ciaranightingale Jul 24, 2023
2580d13
wip
ciaranightingale Jul 24, 2023
279b260
update with clientId & secretKey & requested changes
ciaranightingale Jul 24, 2023
c8445b9
Merge branch 'ciara/tba' of https://github.com/thirdweb-dev/js into c…
ciaranightingale Jul 24, 2023
af57f47
Merge branch 'main' into ciara/tba
ciaranightingale Jul 24, 2023
2db5249
fix build
ciaranightingale Jul 24, 2023
73a51fa
wip
ciaranightingale Jul 26, 2023
39e22b9
wip
ciaranightingale Jul 26, 2023
f34654b
Merge branch 'ciara/tba' of https://github.com/thirdweb-dev/js into c…
ciaranightingale Jul 26, 2023
7477b73
restructure
Jul 26, 2023
5ab826b
cleanup
joaquim-verges Jul 27, 2023
909ca2f
Merge branch 'main' into ciara/tba
joaquim-verges Jul 27, 2023
0c9ada2
Merge branch 'main' into ciara/tba
ciaranightingale Jul 27, 2023
cf5bb93
working code & fix factoryAddress required
ciaranightingale Jul 27, 2023
fdee3f5
Merge branch 'main' into ciara/tba
joaquim-verges Aug 9, 2023
0bdddc0
Merge branch 'main' into ciara/tba
joaquim-verges Aug 9, 2023
f11c12a
Merge branch 'main' into ciara/tba
joaquim-verges Oct 13, 2023
e93da7f
fix types
joaquim-verges Oct 14, 2023
6b4642a
linting
joaquim-verges Oct 14, 2023
8a07db2
fix build
joaquim-verges Oct 14, 2023
a8464f6
Merge branch 'main' into ciara/tba
joaquim-verges Oct 24, 2023
4c8dd1c
require account impl for now
joaquim-verges Oct 24, 2023
c9616ed
changeset
joaquim-verges Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
ciaranightingale committed Jul 26, 2023
commit 73a51fac6177b77363de554042a6215152f79861
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { SmartWalletConfig } from "../smart-wallet/types";

let SmartWalletConnector = module.SmartWalletConnector;

export class TokenBoundConnnector extends SmartWalletConnector {
export class TokenBoundSmartWalletConnector extends SmartWalletConnector {
protected config: TokenBoundSmartWalletConfig;

constructor(config: TokenBoundSmartWalletConfig) {
const smartWalletConfig: SmartWalletConfig = {
const tokenBoundSmartWalletConfig: TokenBoundSmartWalletConfig = {
chain: config.chain,
factoryAddress: config.factoryAddress,
clientId: config.clientId,
Expand All @@ -25,8 +25,11 @@ export class TokenBoundConnnector extends SmartWalletConnector {
paymasterUrl: config.paymasterUrl,
paymasterAPI: config.paymasterAPI,
entryPointAddress: config.entryPointAddress,
tokenContract: config.tokenContract,
tokenId: config.tokenId,
implementation: config.implementation,
}
super(smartWalletConfig);
super(tokenBoundSmartWalletConfig);
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import type {
import { WalletConnectReceiverConfig } from "../../../core/types/walletConnect";
import { SmartWalletConfig } from "../smart-wallet/types";

export type TokenBoundSmartWalletConfig = SmartWalletConfig & {
export type TokenBoundSmartWalletConfig = {
tokenContract: SmartContract;
tokenId: Number;
implementation: SmartContract;
owner: string;
} & ContractInfoInput &
} & SmartWalletConfig & ContractInfoInput &
WalletConnectReceiverConfig;

export type ContractInfoInput = {
Expand Down
1 change: 1 addition & 0 deletions packages/wallets/src/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export * from "./wallets/wallet-connect-v1";
export * from "./wallets/safe";
export * from "./wallets/magic";
export * from "./wallets/smart-wallet";
export * from "./wallets/token-bound-smart-wallet";
export * from "./wallets/ethers";
export * from "./wallets/private-key";
export * from "./wallets/zerion";
Expand Down
40 changes: 20 additions & 20 deletions packages/wallets/src/evm/wallets/smart-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SmartWallet
connector?: SmartWalletConnectorType;

public enableConnectApp: boolean = false;
#wcWallet: WalletConnectHandler;
protected wcWallet: WalletConnectHandler;

static meta = {
name: "Smart Wallet",
Expand All @@ -38,7 +38,7 @@ export class SmartWallet

static id = walletIds.smartWallet;
public get walletName() {
return "Smart Wallet" as const;
return "Smart Wallet";
}

constructor(options: WalletOptions<SmartWalletConfig>) {
Expand All @@ -47,7 +47,7 @@ export class SmartWallet
});

this.enableConnectApp = options?.enableConnectApp || false;
this.#wcWallet = this.enableConnectApp
this.wcWallet = this.enableConnectApp
? new WalletConnectV2Handler({
walletConnectWalletMetadata: options?.walletConnectWalletMetadata,
walletConenctV2ProjectId: options?.walletConenctV2ProjectId,
Expand All @@ -59,9 +59,9 @@ export class SmartWallet
async getConnector(): Promise<SmartWalletConnectorType> {
if (!this.connector) {
if (this.enableConnectApp) {
await this.#wcWallet.init();
await this.wcWallet.init();

this.#setupWalletConnectEventsListeners();
this.setupWalletConnectEventsListeners();
}

const { SmartWalletConnector } = await import(
Expand Down Expand Up @@ -127,75 +127,75 @@ export class SmartWallet
throw new Error("enableConnectApp is set to false in this wallet config");
}

this.#wcWallet?.connectApp(uri);
this.wcWallet?.connectApp(uri);
}

async approveSession(): Promise<void> {
await this.#wcWallet.approveSession(this);
await this.wcWallet.approveSession(this);

this.emit("message", { type: "session_approved" });
}

rejectSession() {
return this.#wcWallet.rejectSession();
return this.wcWallet.rejectSession();
}

approveRequest() {
return this.#wcWallet.approveEIP155Request(this);
return this.wcWallet.approveEIP155Request(this);
}

rejectRequest() {
return this.#wcWallet.rejectEIP155Request();
return this.wcWallet.rejectEIP155Request();
}

getActiveSessions(): WCSession[] {
if (!this.#wcWallet) {
if (!this.wcWallet) {
throw new Error(
"Please, init the wallet before making session requests.",
);
}

return this.#wcWallet.getActiveSessions();
return this.wcWallet.getActiveSessions();
}

disconnectSession(): Promise<void> {
return this.#wcWallet?.disconnectSession();
return this.wcWallet?.disconnectSession();
}

isWCReceiverEnabled() {
return this.enableConnectApp;
}

#setupWalletConnectEventsListeners() {
if (!this.#wcWallet) {
setupWalletConnectEventsListeners() {
if (!this.wcWallet) {
throw new Error(
"Please, init the wallet before making session requests.",
);
}

this.#wcWallet.on("session_proposal", (proposal: WCProposal) => {
this.wcWallet.on("session_proposal", (proposal: WCProposal) => {
this.emit("message", {
type: "session_proposal",
data: proposal,
});
});

this.#wcWallet.on("session_delete", () => {
this.wcWallet.on("session_delete", () => {
this.emit("message", { type: "session_delete" });
});

this.#wcWallet.on("switch_chain", (request: WCRequest) => {
this.wcWallet.on("switch_chain", (request: WCRequest) => {
const chainId = request.params[0].chainId;

this.emit("message", {
type: "switch_chain",
data: { chainId },
});

this.#wcWallet.disconnectSession();
this.wcWallet.disconnectSession();
});

this.#wcWallet.on("session_request", (request: WCRequest) => {
this.wcWallet.on("session_request", (request: WCRequest) => {
this.emit("message", {
type: "session_request",
data: request,
Expand Down
43 changes: 33 additions & 10 deletions packages/wallets/src/evm/wallets/token-bound-smart-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
import { SmartWallet } from "./smart-wallet";
import { SmartWallet, SmartWalletConfig } from "./smart-wallet";
import type { TokenBoundSmartWalletConnector as TokenBoundSmartWalletConnectorType } from "../connectors/token-bound-smart-wallet";
import { walletIds } from "../constants/walletIds";
import { TokenBoundSmartWalletConfig } from "../connectors/token-bound-smart-wallet/types";
import { WalletOptions } from "./base";
import type {
TokenBoundSmartWalletConfig
} from "../connectors/token-bound-smart-wallet/types";
import { AbstractClientWallet, WalletOptions } from "./base";
import type { SmartWalletConnectionArgs } from "../connectors/smart-wallet/types";
import { WalletConnectV2Handler } from "../../core/WalletConnect/WalletConnectV2Handler";
import { NoOpWalletConnectHandler } from "../../core/WalletConnect/constants";

export class TokenBoundSmartWallet extends SmartWallet {
connector?: TokenBoundSmartWalletConnectorType;

static meta = {
name: "Token Bound Smart Wallet",
// TODO: change this URL
iconURL:
"ipfs://QmeAJVqn17aDNQhjEU3kcWVZCFBrfta8LzaDGkS8Egdiyk/smart-wallet.svg",
"ipfs://QmeAJVqn17aDNQhjEU3kcWVZCFBrfta8LzaDGkS8Egdiyk/token-bound-smart-wallet.svg",
};

static id = walletIds.tokenBoundSmartWallet;
public get walletName() {
return "Token Bound Smart Wallet" as "Smart Wallet";
return "Token Bound Smart Wallet";
}

constructor(options: WalletOptions<TokenBoundSmartWalletConfig>) {
options.walletId = walletIds.tokenBoundSmartWallet;
super(options
);
super(options);
}

async getConnector(): Promise<TokenBoundSmartWalletConnectorType> {
if (!this.connector) {
if (this.enableConnectApp) {
await this.wcWallet.init();
this.setupWalletConnectEventsListeners();
}

const { TokenBoundSmartWalletConnector } = await import(
"../connectors/token-bound-smart-wallet"
);
this.connector = new TokenBoundSmartWalletConnector(
this.options as TokenBoundSmartWalletConfig,
);
}
return this.connector;
}
}
}