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
12 changes: 6 additions & 6 deletions packages/account-sdk/src/interface/payment/charge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('charge', () => {
{
to: '0xabc123' as any,
data: '0xdef456' as any,
value: '0x0' as any,
value: 0n,
},
];

Expand Down Expand Up @@ -205,12 +205,12 @@ describe('charge', () => {
{
to: '0xabc123' as any,
data: '0xdef456' as any,
value: '0x0' as any,
value: 0n,
},
{
to: '0xfed321' as any,
data: '0xcba987' as any,
value: '0x0' as any,
value: 0n,
},
];

Expand Down Expand Up @@ -252,7 +252,7 @@ describe('charge', () => {
{
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' as any, // USDC address
data: '0xtransferData' as any,
value: '0x0' as any,
value: 0n,
},
];

Expand Down Expand Up @@ -306,7 +306,7 @@ describe('charge', () => {
{
to: '0x036CbD53842c5426634e7929541eC2318f3dCF7e' as any, // USDC testnet address
data: '0xtransferData' as any,
value: '0x0' as any,
value: 0n,
},
];

Expand Down Expand Up @@ -344,7 +344,7 @@ describe('charge', () => {
{
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' as any, // USDC address
data: '0xtransferData' as any,
value: '0x0' as any,
value: 0n,
},
];

Expand Down
3 changes: 1 addition & 2 deletions packages/account-sdk/src/interface/payment/charge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ export async function charge(options: ChargeOptions): Promise<ChargeResult> {

try {
// Build the calls array for the smart wallet
// Convert value from hex string to bigint if needed
const calls = chargeCalls.map((call) => ({
to: call.to,
data: call.data,
value: BigInt(call.value || '0x0'),
value: call.value,
}));

// For smart wallets, we can send all calls in a single user operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('prepareCharge', () => {
} as SpendPermission;

const mockCallData: PrepareChargeResult = [
{ to: '0xmock', data: '0xapprove', value: '0x0' },
{ to: '0xmock', data: '0xspend', value: '0x0' },
{ to: '0xmock', data: '0xapprove', value: 0n },
{ to: '0xmock', data: '0xspend', value: 0n },
];

it('should prepare charge for specific amount', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/account-sdk/src/interface/payment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export interface PrepareChargeCall {
to: Address;
/** The encoded call data */
data: Hex;
/** The value to send (always 0x0 for spend permissions) */
value: '0x0';
/** The value to send (always 0n for spend permissions) */
value: bigint;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { encodeFunctionData, parseUnits, type Address, type Hex } from 'viem';
import { encodeFunctionData, parseUnits, toHex, type Address, type Hex } from 'viem';
import { CHAIN_IDS, ERC20_TRANSFER_ABI, TOKENS } from '../constants.js';
import type { PayerInfo } from '../types.js';

Expand Down Expand Up @@ -35,7 +35,7 @@ export function buildSendCallsRequest(transferData: Hex, testnet: boolean, payer
const call = {
to: usdcAddress as Address,
data: transferData,
value: '0x0' as Hex, // No ETH value for ERC20 transfer
value: toHex(0n), // No ETH value for ERC20 transfer
};

// Build the capabilities object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('prepareRevokeCallData', () => {
expect(result).toEqual({
to: spendPermissionManagerAddress,
data: mockEncodedData,
value: '0x0',
value: 0n,
});
});

Expand Down Expand Up @@ -106,7 +106,7 @@ describe('prepareRevokeCallData', () => {
it('should always set value to 0x0', async () => {
const result = await prepareRevokeCallData(mockSpendPermission);

expect(result.value).toBe('0x0');
expect(result.value).toBe(0n);
});

it('should handle different spend permission structures', async () => {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('prepareRevokeCallData', () => {
expect(result).toEqual({
to: spendPermissionManagerAddress,
data: differentEncodedData,
value: '0x0',
value: 0n,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { withTelemetry } from '../withTelemetry.js';
type RevokeSpendPermissionResponse = {
to: Address;
data: Hex;
value: '0x0'; // explicitly set to 0x0
value: bigint;
};

/**
Expand Down Expand Up @@ -40,7 +40,7 @@ type RevokeSpendPermissionResponse = {
* const call = {
* to,
* data,
* value: '0x0'
* value: 0n
* };
* ```
*/
Expand All @@ -57,7 +57,7 @@ const prepareRevokeCallDataFn = async (
const response: RevokeSpendPermissionResponse = {
to: spendPermissionManagerAddress,
data,
value: '0x0', // explicitly set to 0x0
value: 0n,
};

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ describe('prepareSpendCallData', () => {
expect(result[0]).toEqual({
to: spendPermissionManagerAddress,
data: '0xapprovedata123456',
value: '0x0',
value: 0n,
});
expect(result[1]).toEqual({
to: spendPermissionManagerAddress,
data: '0xspenddata789abc',
value: '0x0',
value: 0n,
});
});

Expand All @@ -110,7 +110,7 @@ describe('prepareSpendCallData', () => {
expect(result[0]).toEqual({
to: spendPermissionManagerAddress,
data: '0xspenddata789abc',
value: '0x0',
value: 0n,
});

// Verify approve call is not made when permission is active
Expand Down Expand Up @@ -206,13 +206,13 @@ describe('prepareSpendCallData', () => {
expect(typedResult[0]).toHaveProperty('to');
expect(typedResult[0]).toHaveProperty('data');
expect(typedResult[0]).toHaveProperty('value');
expect(typedResult[0].value).toBe('0x0');
expect(typedResult[0].value).toBe(0n);

// Check spend call structure
expect(typedResult[1]).toHaveProperty('to');
expect(typedResult[1]).toHaveProperty('data');
expect(typedResult[1]).toHaveProperty('value');
expect(typedResult[1].value).toBe('0x0');
expect(typedResult[1].value).toBe(0n);
});

it('should return calls with correct structure when permission is active', async () => {
Expand All @@ -228,7 +228,7 @@ describe('prepareSpendCallData', () => {
expect(typedResult[0]).toHaveProperty('to');
expect(typedResult[0]).toHaveProperty('data');
expect(typedResult[0]).toHaveProperty('value');
expect(typedResult[0].value).toBe('0x0');
expect(typedResult[0].value).toBe(0n);
});

it('should handle zero amount', async () => {
Expand Down Expand Up @@ -323,14 +323,14 @@ describe('prepareSpendCallData', () => {
expect(result[0]).toEqual({
to: spendPermissionManagerAddress,
data: '0xspenddata789abc',
value: '0x0',
value: 0n,
});

// Second call should be the ERC20 transfer
expect(result[1]).toEqual({
to: mockSpendPermission.permission.token,
data: '0xtransferdata123',
value: '0x0',
value: 0n,
});

// Verify encodeFunctionData was called with correct args for transfer
Expand Down Expand Up @@ -398,14 +398,14 @@ describe('prepareSpendCallData', () => {

const result = await prepareSpendCallData(mockSpendPermission, 'max-remaining-allowance');

expect(result[0].value).toBe('0x0');
expect(result[1].value).toBe('0x0');
expect(result[0].value).toBe(0n);
expect(result[1].value).toBe(0n);
});

it('should set value to 0x0 for spend call when permission is active', async () => {
const result = await prepareSpendCallData(mockSpendPermission, 'max-remaining-allowance');

expect(result[0].value).toBe('0x0');
expect(result[0].value).toBe(0n);
});

it('should handle remaining spend of zero', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getPermissionStatus } from './getPermissionStatus.js';
type Call = {
to: Address;
data: Hex;
value: '0x0'; // explicitly set to 0x0
value: bigint;
};

export type PrepareSpendCallDataResponseType = Call[];
Expand Down Expand Up @@ -133,7 +133,7 @@ const prepareSpendCallDataFn = async (
approveCall = {
to: spendPermissionManagerAddress,
data: approveData,
value: '0x0', // explicitly set to 0x0
value: 0n,
};
}

Expand All @@ -145,7 +145,7 @@ const prepareSpendCallDataFn = async (
const spendCall: Call = {
to: spendPermissionManagerAddress,
data: spendData,
value: '0x0', // explicitly set to 0x0
value: 0n,
};

const calls: Call[] = [approveCall, spendCall].filter((item) => item !== null);
Expand All @@ -163,7 +163,7 @@ const prepareSpendCallDataFn = async (
calls.push({
to: permission.permission.token as Address,
data: transferCallData,
value: '0x0',
value: 0n,
});
}

Expand Down