Skip to content

feat: FE optimisations via TS SDK #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion e2e-tests/react-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@tanstack/react-query": "5.35.1",
"@wagmi/connectors": "5.1.7",
"@wagmi/core": "2.13.4",
"fuels": "0.100.0",
"fuels": "pr-3769",
"clsx": "2.1.1",
"connectkit": "1.8.2",
"next": "14.2.22",
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"@synthetixio/synpress-cache": "0.0.4",
"dotenv": "16.4.5",
"@phantom/synpress": "4.0.0-alpha.53",
"fuels": "0.100.0"
"fuels": "pr-3769"
}
}
2 changes: 1 addition & 1 deletion examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@wagmi/connectors": "5.1.7",
"@wagmi/core": "2.13.4",
"clsx": "2.1.1",
"fuels": "0.100.0",
"fuels": "pr-3769",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/node": "20.12.11",
"@vitest/coverage-v8": "2.1.9",
"compare-versions": "6.1.0",
"fuels": "0.100.0",
"fuels": "pr-3769",
"husky": "9.0.11",
"lint-staged": "15.2.2",
"tsx": "^4.16.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/bako-safe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"socket.io-client": "4.7.2"
},
"peerDependencies": {
"fuels": "0.100.0",
"fuels": "pr-3769",
"socket.io-client": "4.7.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/burner-wallet-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "vitest"
},
"peerDependencies": {
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"devDependencies": {
"@fuel-connectors/common": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test": "vitest"
},
"peerDependencies": {
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"dependencies": {
"@ethersproject/bytes": "5.7.0",
Expand Down
43 changes: 41 additions & 2 deletions packages/common/src/PredicateConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
FuelConnectorEventTypes,
type JsonAbi,
type Network,
type Predicate,
type SelectNetworkArguments,
type TransactionRequestLike,
type TransactionResponse,
type Version,
ZeroBytes32,
bn,
Expand Down Expand Up @@ -50,7 +52,7 @@ export abstract class PredicateConnector extends FuelConnector {
public abstract sendTransaction(
address: string,
transaction: TransactionRequestLike,
): Promise<string>;
): Promise<TransactionResponse | string>;
public abstract connect(): Promise<boolean>;
public abstract disconnect(): Promise<boolean>;

Expand Down Expand Up @@ -144,7 +146,6 @@ export abstract class PredicateConnector extends FuelConnector {
const predicate =
(await this.getCurrentUserPredicate()) ?? this.getNewestPredicate();
if (!predicate) throw new Error('No predicate found');

this.predicateAddress = predicate.getRoot();
this.predicateAccount = predicate;

Expand All @@ -155,6 +156,44 @@ export abstract class PredicateConnector extends FuelConnector {
this.subscriptions.push(listener);
}

protected async getPredicate(
address: string,
transaction: TransactionRequestLike,
): Promise<Predicate> {
if (!(await this.isConnected())) {
throw Error('No connected accounts');
}

if (!this.predicateAccount) {
throw Error('No predicate account found');
}

const walletAccount = this.predicateAccount.getAccountAddress(
address,
await this.walletAccounts(),
);

if (!walletAccount) {
throw Error(`No account found for ${address}`);
}

const transactionRequest = transactionRequestify(transaction);

const predicateSignatureIndex = getMockedSignatureIndex(
transactionRequest.witnesses,
);

const { fuelProvider } = await this.getProviders();

const predicate = this.predicateAccount.build(walletAccount, fuelProvider, [
predicateSignatureIndex,
]);

predicate.connect(fuelProvider);

return predicate;
}

protected async prepareTransaction(
address: string,
transaction: TransactionRequestLike,
Expand Down
2 changes: 1 addition & 1 deletion packages/connectors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ts:check": "tsc --noEmit"
},
"peerDependencies": {
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"dependencies": {
"@ethereumjs/util": "9.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"fuels": "0.100.0",
"fuels": "pr-3769",
"typedoc-plugin-markdown": "^3.15.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/evm-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "vitest"
},
"peerDependencies": {
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"dependencies": {
"@ethereumjs/util": "9.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/evm-predicates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"versions:generate": "pnpm fuels build && pnpm fuels deploy && tsx ./scripts/versions.ts"
},
"peerDependencies": {
"fuels": "0.100.0",
"fuels": "pr-3769",
"viem": ">=2.20.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-development-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test": "vitest"
},
"peerDependencies": {
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"devDependencies": {
"@fuel-connectors/fuel-wallet": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test": "vitest"
},
"peerDependencies": {
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"dependencies": {
"json-rpc-2.0": "1.7.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/fuelet-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test": "vitest"
},
"peerDependencies": {
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"devDependencies": {
"@fuel-connectors/fuel-wallet": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"peerDependencies": {
"@tanstack/react-query": ">=5.0.0",
"fuels": "0.100.0",
"fuels": "pr-3769",
"react": ">=18.0.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/solana-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"peerDependencies": {
"@web3modal/core": ">=5.0.0",
"@web3modal/scaffold": ">=5.0.0",
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"dependencies": {
"@ethereumjs/util": "9.0.3",
Expand Down
74 changes: 67 additions & 7 deletions packages/solana-connector/src/SolanaConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ import { ApiController } from '@web3modal/core';
import type { Web3Modal } from '@web3modal/solana';
import type { Provider as SolanaProvider } from '@web3modal/solana/dist/types/src/utils/scaffold';
import {
type AssembleTxParams,
CHAIN_IDS,
type ConnectorMetadata,
FuelConnectorEventTypes,
Provider as FuelProvider,
type TransactionRequestLike,
type TransactionResponse,
bn,
hexlify,
toUtf8Bytes,
transactionRequestify,
} from 'fuels';
import { HAS_WINDOW, SOLANA_ICON } from './constants';
import { PREDICATE_VERSIONS } from './generated/predicates';
Expand Down Expand Up @@ -226,12 +230,37 @@ export class SolanaConnector extends PredicateConnector {
return new TextEncoder().encode(txIdNo0x);
}

public async onBeforeAssembleTx(
params: AssembleTxParams,
): Promise<AssembleTxParams> {
const { request } = params;
const solAddress = this.web3Modal.getAddress() || '';
const fuelAddress = this.predicateAccount?.getPredicateAddress(solAddress);

if (!fuelAddress) {
throw new Error('No address found');
}

const predicate = await this.getPredicate(fuelAddress, request);

return { ...params, feePayerAccount: predicate, estimatePredicates: false };
}

public async sendTransaction(
address: string,
transaction: TransactionRequestLike,
): Promise<string> {
const { predicate, transactionId, transactionRequest } =
await this.prepareTransaction(address, transaction);
): Promise<TransactionResponse | string> {
const { fuelProvider } = await this.getProviders();
const solAddress = this.web3Modal.getAddress() || '';
const fuelAddress = this.predicateAccount?.getPredicateAddress(solAddress);

if (!fuelAddress || address !== fuelAddress) {
throw new Error('No address found');
}

const transactionRequest = transactionRequestify(transaction);
const chainId = await fuelProvider.getChainId();
const transactionId = transactionRequest.getTransactionId(chainId);

const predicateSignatureIndex = getMockedSignatureIndex(
transactionRequest.witnesses,
Expand All @@ -249,14 +278,45 @@ export class SolanaConnector extends PredicateConnector {
)) as Uint8Array;
transactionRequest.witnesses[predicateSignatureIndex] = signedMessage;

// Send transaction
await predicate.provider.estimatePredicates(transactionRequest);
await this.fuelProvider.estimatePredicates(transactionRequest);

const response = await predicate.sendTransaction(transactionRequest);
const response =
await this.fuelProvider.sendTransaction(transactionRequest);

return response.id;
return response;
}

// public async sendTransaction(
// address: string,
// transaction: TransactionRequestLike,
// ): Promise<string | TransactionResponse> {
// const { predicate, transactionId, transactionRequest } =
// await this.prepareTransaction(address, transaction);

// const predicateSignatureIndex = getMockedSignatureIndex(
// transactionRequest.witnesses,
// );

// const txId = this.encodeTxId(transactionId);
// const provider: Maybe<SolanaProvider> =
// this.web3Modal.getWalletProvider() as SolanaProvider;
// if (!provider) {
// throw new Error('No provider found');
// }

// const signedMessage: Uint8Array = (await provider.signMessage(
// txId,
// )) as Uint8Array;
// transactionRequest.witnesses[predicateSignatureIndex] = signedMessage;

// // Send transaction
// await predicate.provider.estimatePredicates(transactionRequest);

// const response = await predicate.sendTransaction(transactionRequest);

// return response.id;
// }

async signMessageCustomCurve(message: string) {
const provider: Maybe<SolanaProvider> =
this.web3Modal.getWalletProvider() as SolanaProvider;
Expand Down
2 changes: 1 addition & 1 deletion packages/walletconnect-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"peerDependencies": {
"@web3modal/core": ">=5.0.0",
"@web3modal/scaffold": ">=5.0.0",
"fuels": "0.100.0"
"fuels": "pr-3769"
},
"dependencies": {
"@ethereumjs/util": "9.0.3",
Expand Down
Loading
Loading