Skip to content
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

feat: support gasless transactions #458

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions .changeset/nine-cheetahs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@fuel-connectors/burner-wallet-connector": minor
"@fuel-connectors/fuel-development-wallet": minor
"@fuel-connectors/walletconnect-connector": minor
"@fuel-connectors/solana-connector": minor
"@fuel-connectors/evm-predicates": minor
"@fuel-connectors/evm-connector": minor
"@fuel-connectors/fuelet-wallet": minor
"@fuel-connectors/fuel-wallet": minor
"@fuels/connectors": minor
"@fuel-connectors/bako-safe": minor
"@e2e-tests/runner": minor
"@fuel-connectors/common": minor
"@fuels/react": minor
"docs": minor
---

Upgrade Fuel SDK to 0.98.0
8 changes: 8 additions & 0 deletions .changeset/spicy-snails-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@fuel-connectors/fuel-development-wallet": minor
"@fuel-connectors/fuel-wallet": minor
"@fuels/connectors": minor
"@fuels/react": minor
---

Support gasless transactions on Fuel Wallet
3 changes: 2 additions & 1 deletion .github/workflows/pr-release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Release to @pr-<number> tag on npm
on:
pull_request:
workflow_dispatch:
types: [opened, synchronize, reopened]

jobs:
release-pr:
Expand All @@ -27,6 +27,7 @@ jobs:

- name: Build
run: pnpm build
env:
NEXT_PUBLIC_PROVIDER_URL: "http://localhost:4000/v1/graphql"
NEXT_PUBLIC_WC_PROJECT_ID: e01471314fc69cc4efba6dce12dfd710
NEXT_PUBLIC_CHAIN_ID_NAME: testnet
Expand Down
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.96.1",
"fuels": "0.98.0",
"clsx": "2.1.1",
"connectkit": "1.8.2",
"next": "14.2.22",
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/react-next/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const FUEL_CONFIG = {
wcProjectId: WC_PROJECT_ID,
ethWagmiConfig: wagmiConfig,
chainId: CHAIN_ID,
fuelProvider: Provider.create(PROVIDER_URL),
fuelProvider: new Provider(PROVIDER_URL),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test.describe('BurnerWalletConnector', async () => {
}

const burnerWallet = Wallet.fromPrivateKey(privateKey);
const fuelProvider = await Provider.create(VITE_FUEL_PROVIDER_URL);
const fuelProvider = new Provider(VITE_FUEL_PROVIDER_URL);
burnerWallet.connect(fuelProvider);
await transferMaxBalance({
fromWallet: burnerWallet,
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/runner/examples/connectors/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const testSetup = async ({
extensionId: string;
amountToFund: BNInput;
}) => {
const fuelProvider = await Provider.create(VITE_FUEL_PROVIDER_URL);
const fuelProvider = new Provider(VITE_FUEL_PROVIDER_URL);
const masterWallet = Wallet.fromMnemonic(VITE_MASTER_WALLET_MNEMONIC);
masterWallet.connect(fuelProvider);
if (VITE_WALLET_SECRET) {
Expand All @@ -54,7 +54,7 @@ export const testSetup = async ({
fuelExtensionId: extensionId,
fuelProvider: {
url: fuelProvider.url,
chainId: fuelProvider.getChainId(),
chainId: await fuelProvider.getChainId(),
},
chainName,
mnemonic: randomMnemonic,
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.96.1"
"fuels": "0.98.0"
}
}
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.96.1",
"fuels": "0.98.0",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/react-app/src/components/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function Transfer({ isSigning, setIsSigning }: Props) {
}

const receiverAddress = Address.fromString(receiver);
const asset_id = wallet?.provider.getBaseAssetId();
const asset_id = await wallet?.provider.getBaseAssetId();

const resp = await wallet?.transfer(
receiverAddress,
Expand Down
2 changes: 1 addition & 1 deletion examples/react-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const FUEL_CONFIG: FuelConfig = {
wcProjectId: WC_PROJECT_ID,
ethWagmiConfig: wagmiConfig,
chainId: CHAIN_ID,
fuelProvider: Provider.create(PROVIDER_URL),
fuelProvider: new Provider(PROVIDER_URL),
}),
};

Expand Down
7 changes: 2 additions & 5 deletions examples/react-app/src/types/contracts/Counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import { Contract, Interface } from 'fuels';
import type {
AbstractAddress,
Account,
Address,
BN,
BigNumberish,
FunctionFragment,
Expand Down Expand Up @@ -93,10 +93,7 @@ export class Counter extends Contract {
increment_counter: InvokeFunction<[], BN>;
};

constructor(
id: string | AbstractAddress,
accountOrProvider: Account | Provider,
) {
constructor(id: string | Address, accountOrProvider: Account | Provider) {
super(id, abi, accountOrProvider);
}
}
3 changes: 1 addition & 2 deletions examples/react-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"@fuels/react": "workspace:*",
"@tanstack/react-query": "5.35.1",
"connectkit": "1.8.2",
"fuels": "0.96.1",
"next": "14.2.22",
"next": "14.2.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"wagmi": "2.12.7"
Expand Down
2 changes: 1 addition & 1 deletion examples/react-next/src/components/FuelProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const FUEL_CONFIG = createConfig(() => {
wcProjectId: process.env.NEXT_PUBLIC_WC_PROJECT_ID,
ethWagmiConfig: DEFAULT_WAGMI_CONFIG,
chainId: NETWORKS[0].chainId,
fuelProvider: Provider.create(NETWORKS[0].url),
fuelProvider: new Provider(NETWORKS[0].url),
}),
};
});
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"node": "20.x",
"pnpm": "9.x"
},
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"braces@<3.0.3": ">=3.0.3",
Expand All @@ -61,8 +62,11 @@
"elliptic@<6.6.0": ">=6.6.0",
"next@>=10.0.0 <14.2.22": ">=14.2.22",
"cross-spawn@>=7.0.0 <7.0.5": ">=7.0.5",
"nanoid@<3.3.8": "3.3.8"
"nanoid@<3.3.8": "3.3.8",
"vite@>=5.2.0 <5.4.6": ">=5.4.6"
}
},
"packageManager": "[email protected]"
"dependencies": {
"fuels": "0.98.0"
}
}
3 changes: 1 addition & 2 deletions packages/bako-safe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
"socket.io-client": "4.7.2"
},
"peerDependencies": {
"fuels": ">=0.96.1",
"fuels": "0.98.0",
"socket.io-client": "4.7.2"
},
"devDependencies": {
"fuels": "0.96.1",
"tsup": "8.0.2",
"typescript": "5.4.2",
"undici": "6.9.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/bako-safe/src/BakoSafeConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ export class BakoSafeConnector extends FuelConnector {
`/connections/${this.sessionId}/currentNetwork`,
);

const provider = await Provider.create(data);
const provider = new Provider(data);

return {
url: provider.url,
chainId: provider.getChainId(),
chainId: await provider.getChainId(),
};
}

Expand Down
3 changes: 1 addition & 2 deletions packages/burner-wallet-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
"test": "vitest"
},
"peerDependencies": {
"fuels": ">=0.96.1"
"fuels": "0.98.0"
},
"devDependencies": {
"@fuel-connectors/common": "workspace:*",
"fuels": "0.96.1",
"jsdom": "24.0.0",
"tsup": "8.0.2",
"typescript": "5.4.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class BurnerWalletConnector extends FuelConnector {
private configProvider(config: BurnerWalletConfig = {}) {
const network = getProviderUrl(config.chainId ?? CHAIN_IDS.fuel.testnet);
this.config = Object.assign(config, {
fuelProvider: config.fuelProvider || Provider.create(network),
fuelProvider: config.fuelProvider || new Provider(network),
});
}

Expand Down Expand Up @@ -264,7 +264,7 @@ export class BurnerWalletConnector extends FuelConnector {

async currentNetwork(): Promise<Network> {
const { fuelProvider } = await this.getProvider();
const chainId = fuelProvider.getChainId();
const chainId = await fuelProvider.getChainId();

return {
chainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('Burner Wallet Connector', () => {
});

test('Creates a new BurnerWalletConnector instance with non default Provider url', async () => {
const nonDefaultProvider = await Provider.create(TESTNET_NETWORK.url);
const nonDefaultProvider = new Provider(TESTNET_NETWORK.url);

const config: BurnerWalletConfig = {
fuelProvider: nonDefaultProvider,
Expand All @@ -161,7 +161,7 @@ describe('Burner Wallet Connector', () => {
});

test('Creates a new BurnerWalletConnector instance with non default Promise Provider url', async () => {
const nonDefaultProvider = Provider.create(TESTNET_NETWORK.url);
const nonDefaultProvider = new Provider(TESTNET_NETWORK.url);

const config: BurnerWalletConfig = {
fuelProvider: nonDefaultProvider,
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('Burner Wallet Connector', () => {

const network = await connector.currentNetwork();

expect(network.chainId).to.be.equal(fuelProvider.getChainId());
expect(network.chainId).to.be.equal(await fuelProvider.getChainId());
expect(network.url).to.be.equal(fuelProvider.url);
});
});
Expand All @@ -304,7 +304,7 @@ describe('Burner Wallet Connector', () => {
const network = networks.pop();

const networkChainId = network?.chainId;
const expectedChainId = fuelProvider.getChainId();
const expectedChainId = await fuelProvider.getChainId();

expect(networks).to.be.an('array');

Expand Down
3 changes: 1 addition & 2 deletions 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.96.1"
"fuels": "0.98.0"
},
"dependencies": {
"@ethersproject/bytes": "5.7.0",
Expand All @@ -37,7 +37,6 @@
},
"devDependencies": {
"@types/memoizee": "0.4.11",
"fuels": "0.96.1",
"terser": "5.31.0",
"tsup": "8.0.2",
"typescript": "5.4.5",
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/PredicateConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export abstract class PredicateConnector extends FuelConnector {

const b256Address = Address.fromDynamicInput(address).toString();
const { fuelProvider } = await this.getProviders();
const chainId = fuelProvider.getChainId();
const chainId = await fuelProvider.getChainId();
const walletAccount = this.predicateAccount.getAccountAddress(
b256Address,
await this.walletAccounts(),
Expand Down Expand Up @@ -212,7 +212,7 @@ export abstract class PredicateConnector extends FuelConnector {
ZeroBytes32,
]);

const { gasPriceFactor } = predicate.provider.getGasConfig();
const { gasPriceFactor } = await predicate.provider.getGasConfig();
const { maxFee, gasPrice } = await predicate.provider.estimateTxGasAndFee({
transactionRequest: requestWithPredicateAttached,
});
Expand Down Expand Up @@ -301,7 +301,7 @@ export abstract class PredicateConnector extends FuelConnector {

public async currentNetwork(): Promise<Network> {
const { fuelProvider } = await this.getProviders();
const chainId = fuelProvider.getChainId();
const chainId = await fuelProvider.getChainId();

return { url: fuelProvider.url, chainId: chainId };
}
Expand Down
8 changes: 4 additions & 4 deletions packages/common/src/PredicateFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class PredicateFactory {

getMaxPredicateGasUsed = memoize(async (provider: Provider): Promise<BN> => {
const fakeAccount = this.adapter.generateFakeAccount();
const chainId = provider.getChainId();
const chainId = await provider.getChainId();
const fakePredicate = this.build(fakeAccount.getAddress(), provider, [0]);
const request = new ScriptTransactionRequest();
request.addCoinInput({
Expand Down Expand Up @@ -124,13 +124,13 @@ export class PredicateFactory {
* predicate with the correct witness index argument.
*/
export const getMockedSignatureIndex = (witnesses: BytesLike[]) => {
const hasPlaceholderWitness = witnesses.some(
const placeholderWitnessIndex = witnesses.findIndex(
(item) =>
item instanceof Uint8Array &&
item.length === 64 &&
item.every((value) => value === 0),
);

const hasPlaceholderWitness = placeholderWitnessIndex !== -1;
// if it is a placeholder witness, we can safely replace it, otherwise we will consider a new element.
return hasPlaceholderWitness ? witnesses.length - 1 : witnesses.length;
return hasPlaceholderWitness ? placeholderWitnessIndex : witnesses.length;
};
13 changes: 13 additions & 0 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type EventEmitter from 'node:events';
import type {
BN,
BytesLike,
Predicate as FuelPredicate,
Provider as FuelProvider,
Expand Down Expand Up @@ -53,3 +54,15 @@ export type SignedMessageCustomCurve = {
curve: string;
signature: string;
};

// export interface PaymasterParams {
// paymasterAddress: string;
// maxFeePerGas?: BN;
// deadline?: number;
// }

// export interface SendTransactionParams {
// skipCustomFee?: boolean;
// onBeforeSend?: (txRequest: TransactionRequest) => Promise<TransactionRequest>;
// paymaster?: PaymasterParams;
// }
5 changes: 2 additions & 3 deletions packages/connectors/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuels/connectors",
"version": "0.37.0",
"version": "0.38.1",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand All @@ -18,7 +18,7 @@
"ts:check": "tsc --noEmit"
},
"peerDependencies": {
"fuels": ">=0.96.1"
"fuels": "0.98.0"
},
"dependencies": {
"@ethereumjs/util": "9.0.3",
Expand All @@ -42,7 +42,6 @@
"@fuel-connectors/fuelet-wallet": "workspace:*",
"@fuel-connectors/solana-connector": "workspace:*",
"@fuel-connectors/walletconnect-connector": "workspace:*",
"fuels": "0.96.1",
"terser": "5.31.0",
"tsup": "8.0.2",
"typescript": "5.4.5"
Expand Down
Loading
Loading