Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ export async function sendTransactionWithDelegationAction<
],
});

const {
value: _value,
permissionsContext: _permissionsContext,
delegationManager: _delegationManager,
...rest
} = args;

const hash = await client.sendTransaction({
...args,
...rest,
to: args.delegationManager,
data: calldata,
} as unknown as SendTransactionParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,20 @@ describe('erc7710RedeemDelegationAction', () => {
],
});

const { delegationManager } = args;

const expectedArgs = {
...args,
to: args.delegationManager,
account,
chain,
to: delegationManager,
// value is not passed to sendTransaction
data: redeemDelegationCallData,
// permissionsContext and delegationManager are not passed to sendTransaction
};

expect(sendTransaction.calledOnceWithExactly(expectedArgs)).to.equal(
true,
);
expect(sendTransaction.calledOnce).to.equal(true);

expect(sendTransaction.firstCall.args[0]).to.deep.equal(expectedArgs);
});

it('should throw an error when `to` is not provided', async () => {
Expand All @@ -345,5 +350,33 @@ describe('erc7710RedeemDelegationAction', () => {
'`to` is required. `sendTransactionWithDelegation` cannot be used to deploy contracts.',
);
});

it('should not encode the specified `value`, `permissionsContext` and `delegationManager` into the resulting transaction', async () => {
const extendedWalletClient = walletClient.extend(erc7710WalletActions());

const sendTransaction = stub(walletClient, 'sendTransaction');

const args: SendTransactionWithDelegationParameters = {
account,
chain,
to: randomAddress(),
value: 100n,
data: randomBytes(128),
permissionsContext: randomBytes(128),
delegationManager: randomAddress(),
};

await extendedWalletClient.sendTransactionWithDelegation(args);

expect(sendTransaction.calledOnce).to.equal(true);
const sendTransactionArgs = sendTransaction.firstCall.args[0];
expect(sendTransactionArgs.value).to.equal(undefined);
expect((sendTransactionArgs as any).permissionsContext).to.equal(
undefined,
);
expect((sendTransactionArgs as any).delegationManager).to.equal(
undefined,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
deploySmartAccount,
publicClient,
fundAddress,
randomAddress,
} from '../utils/helpers';
import { chain } from '../../src/config';

Expand Down Expand Up @@ -230,3 +231,54 @@ test('Bob attempts to call the increment function directly', async () => {

expect(countAfter).toEqual(0n);
});

test('Bob sends a native value transaction with delegation', async () => {
await deploySmartAccount(aliceSmartAccount);

const allowance = 100n;
const recipient = randomAddress();

const { DelegationManager: delegationManager } =
aliceSmartAccount.environment;

const caveats = createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
'nativeTokenTransferAmount',
allowance,
);

const delegation = createDelegation({
to: bob.address,
from: aliceSmartAccount.address,
caveats,
});

const signedDelegation = {
...delegation,
signature: await aliceSmartAccount.signDelegation({ delegation }),
};

const permissionsContext = encodeDelegations([signedDelegation]);

const bobWalletClient = createWalletClient({
account: bob,
transport,
chain,
}).extend(erc7710WalletActions());

await fundAddress(aliceSmartAccount.address, allowance);

const transactionHash = await bobWalletClient.sendTransactionWithDelegation({
account: bob,
chain,
to: recipient,
value: allowance,
permissionsContext,
delegationManager,
});

await publicClient.waitForTransactionReceipt({ hash: transactionHash });

const balance = await publicClient.getBalance({ address: recipient });

expect(balance).toEqual(allowance);
});
Loading