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

Jayhwang sc 87905 gas subsidy change sendgaslesstransaction #638

Merged
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
6 changes: 4 additions & 2 deletions packages/@magic-sdk/provider/src/modules/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {
Events,
GasApiResponse,
MagicPayloadMethod,
GaslessTransactionRequest,
RequestUserInfoScope,
UserEnv,
UserInfo,
WalletInfo,
Wallets,
} from '@magic-sdk/types';

import { BaseModule } from './base-module';
import { createJsonRpcRequestPayload } from '../core/json-rpc';
import { createDeprecationWarning } from '../core/sdk-exceptions';
Expand Down Expand Up @@ -81,9 +83,9 @@ export class WalletModule extends BaseModule {
return this.request<boolean>(createJsonRpcRequestPayload(MagicPayloadMethod.ShowBalances));
}

public sendGaslessTransaction(address: string, serializedTransaction: string) {
public sendGaslessTransaction(address: string, transaction: GaslessTransactionRequest) {
return this.request<GasApiResponse>(
createJsonRpcRequestPayload(MagicPayloadMethod.SendGaslessTransaction, [address, serializedTransaction]),
createJsonRpcRequestPayload(MagicPayloadMethod.SendGaslessTransaction, [address, transaction]),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import browserEnv from '@ikscodes/browser-env';
import { GaslessTransactionRequest } from '@magic-sdk/types';
import { createMagicSDK } from '../../../factories';
import { isPromiEvent } from '../../../../src/util';

Expand All @@ -11,20 +12,28 @@ test('Generate JSON RPC request payload with method `eth_sendGaslessTransaction`
magic.wallet.request = jest.fn();

const address = '0x1234';
const sericalizedTranasction = '0x1234567890abcdef';
const transaction: GaslessTransactionRequest = {
from: '0x1234',
to: '0x5678',
value: BigInt('12'),
};

magic.wallet.sendGaslessTransaction(address, sericalizedTranasction);
magic.wallet.sendGaslessTransaction(address, transaction);

const requestPayload = magic.wallet.request.mock.calls[0][0];
expect(requestPayload.method).toBe('eth_sendGaslessTransaction');
expect(requestPayload.params).toEqual([address, sericalizedTranasction]);
expect(requestPayload.params).toEqual([address, transaction]);
});

test('method should return a PromiEvent', () => {
const magic = createMagicSDK();

const address = '0x1234';
const sericalizedTranasction = '0x1234567890abcdef';
const transaction: GaslessTransactionRequest = {
from: '0x1234',
to: '0x5678',
value: BigInt('12'),
};

expect(isPromiEvent(magic.wallet.sendGaslessTransaction(address, sericalizedTranasction))).toBeTruthy();
expect(isPromiEvent(magic.wallet.sendGaslessTransaction(address, transaction))).toBeTruthy();
});
82 changes: 82 additions & 0 deletions packages/@magic-sdk/types/src/modules/wallet-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,85 @@ export type GasApiResponse = {
state: string;
success: boolean;
};

export type AccessListEntry = { address: string; storageKeys: Array<string> };

/**
* An ordered collection of [[AccessList]] entries.
*/
export type AccessList = Array<AccessListEntry>;

export interface GaslessTransactionRequest {
/**
* The transaction type.
*/
type?: number;

/**
* The target of the transaction.
*/
to?: string;

/**
* The sender of the transaction.
*/
from?: string;

/**
* The nonce of the transaction, used to prevent replay attacks.
*/

nonce?: number;

/**
* The maximum amount of gas to allow this transaction to consime.
*/
gasLimit?: bigint;

/**
* The gas price to use for legacy transactions or transactions on
* legacy networks.
*
* Most of the time the ``max*FeePerGas`` is preferred.
*/
gasPrice?: bigint;

/**
* The [[link-eip-1559]] maximum priority fee to pay per gas.
*/
maxPriorityFeePerGas?: bigint;

/**
* The [[link-eip-1559]] maximum total fee to pay per gas. The actual
* value used is protocol enforced to be the block's base fee.
*/
maxFeePerGas?: bigint;

/**
* The transaction data.
*/
data?: string;

/**
* The transaction value (in wei).
*/
value?: bigint;

/**
* The chain ID for the network this transaction is valid on.
*/
chainId?: bigint;

/**
* The [[link-eip-2930]] access list. Storage slots included in the access
* list are //warmed// by pre-loading them, so their initial cost to
* fetch is guaranteed, but then each additional access is cheaper.
*/
accessList?: AccessList;

/**
* A custom object, which can be passed along for network-specific
* values.
*/
customData?: any;
}
Loading