Skip to content

Commit cbfafd8

Browse files
authored
Merge pull request #90 from okto-hq/fee-payer
feat: add fee payer address to user operation transactions and …
2 parents ca13fcb + 24248fa commit cbfafd8

File tree

7 files changed

+50
-10
lines changed

7 files changed

+50
-10
lines changed

.changeset/brown-kids-heal.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@okto_web3/react-native-sdk": minor
3+
"@okto_web3/core-js-sdk": minor
4+
"@okto_web3/react-sdk": minor
5+
---
6+
7+
update job manager abi

packages/core-js/src/userop/abi.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export const INTENT_ABI = [
1111
type: 'address',
1212
},
1313
{
14-
name: '_jobCreatorId',
14+
name: '_userSWA',
15+
type: 'address',
16+
},
17+
{
18+
name: '_feePayerAddress',
1519
type: 'address',
1620
},
1721
{

packages/core-js/src/userop/nftCollectionCreation.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type OktoClient from '@/core/index.js';
22
import { getChains } from '@/explorer/chain.js';
3-
import type { UserOp } from '@/types/core.js';
3+
import type { Address, UserOp } from '@/types/core.js';
44
import { Constants } from '@/utils/index.js';
55
import { generateUUID, nonceToBigInt } from '@/utils/nonce.js';
66
import {
@@ -32,11 +32,17 @@ import { BaseError } from '@/errors/index.js';
3232
async function nftCollectionCreation(
3333
oc: OktoClient,
3434
data: NFTCollectionCreationIntentParams,
35+
feePayerAddress?: Address,
3536
): Promise<UserOp> {
3637
if (!oc.isLoggedIn()) {
3738
throw new BaseError('User not logged in');
3839
}
3940
validateSchema(NFTCollectionCreationSchema, data);
41+
42+
if (!feePayerAddress) {
43+
feePayerAddress = Constants.FEE_PAYER_ADDRESS;
44+
}
45+
4046
const nonce = generateUUID();
4147

4248
const jobParametersAbiType =
@@ -67,6 +73,7 @@ async function nftCollectionCreation(
6773
toHex(nonceToBigInt(nonce), { size: 32 }),
6874
oc.clientSWA,
6975
oc.userSWA,
76+
feePayerAddress,
7077
encodeAbiParameters(
7178
parseAbiParameters('(bool gsnEnabled, bool sponsorshipEnabled)'),
7279
[

packages/core-js/src/userop/nftTransfer.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import GatewayClientRepository from '@/api/gateway.js';
22
import type OktoClient from '@/core/index.js';
33
import { getChains } from '@/explorer/chain.js';
4-
import type { UserOp } from '@/types/core.js';
4+
import type { Address, UserOp } from '@/types/core.js';
55
import { Constants } from '@/utils/index.js';
66
import { generateUUID, nonceToBigInt } from '@/utils/nonce.js';
77
import {
@@ -33,6 +33,7 @@ import {
3333
export async function nftTransfer(
3434
oc: OktoClient,
3535
data: NFTTransferIntentParams,
36+
feePayerAddress?: Address,
3637
): Promise<UserOp> {
3738
if (!oc.isLoggedIn()) {
3839
throw new BaseError('User not logged in');
@@ -46,8 +47,11 @@ export async function nftTransfer(
4647
);
4748
}
4849

49-
const nonce = generateUUID();
50+
if (!feePayerAddress) {
51+
feePayerAddress = Constants.FEE_PAYER_ADDRESS;
52+
}
5053

54+
const nonce = generateUUID();
5155
const jobParametersAbiType =
5256
'(string caip2Id, string nftId, string recipientWalletAddress, string collectionAddress, string nftType, uint amount)';
5357
const gsnDataAbiType = `(bool isRequired, string[] requiredNetworks, ${jobParametersAbiType}[] tokens)`;
@@ -74,6 +78,7 @@ export async function nftTransfer(
7478
toHex(nonceToBigInt(nonce), { size: 32 }),
7579
oc.clientSWA,
7680
oc.userSWA,
81+
feePayerAddress,
7782
encodeAbiParameters(
7883
parseAbiParameters('(bool gsnEnabled, bool sponsorshipEnabled)'),
7984
[

packages/core-js/src/userop/rawTransaction.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import GatewayClientRepository from '@/api/gateway.js';
22
import type OktoClient from '@/core/index.js';
33
import { BaseError } from '@/errors/base.js';
44
import { getChains } from '@/explorer/chain.js';
5-
import type { UserOp } from '@/types/core.js';
5+
import type { Address, UserOp } from '@/types/core.js';
66
import { Constants } from '@/utils/index.js';
77
import { generateUUID, nonceToBigInt } from '@/utils/nonce.js';
88
import {
@@ -26,12 +26,18 @@ import {
2626
export async function evmRawTransaction(
2727
oc: OktoClient,
2828
data: RawTransactionIntentParams,
29+
feePayerAddress?: Address,
2930
): Promise<UserOp> {
3031
if (!oc.isLoggedIn()) {
3132
throw new BaseError('User not logged in');
3233
}
34+
3335
validateSchema(RawTransactionIntentParamsSchema, data);
3436

37+
if (!feePayerAddress) {
38+
feePayerAddress = Constants.FEE_PAYER_ADDRESS;
39+
}
40+
3541
const transaction: EVMRawTransaction = {
3642
from: data.transaction.from,
3743
to: data.transaction.to,
@@ -78,6 +84,7 @@ export async function evmRawTransaction(
7884
toHex(nonceToBigInt(nonce), { size: 32 }),
7985
oc.clientSWA,
8086
oc.userSWA,
87+
feePayerAddress,
8188
encodeAbiParameters(
8289
parseAbiParameters('(bool gsnEnabled, bool sponsorshipEnabled)'),
8390
[

packages/core-js/src/userop/tokenTransfer.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import GatewayClientRepository from '@/api/gateway.js';
22
import type OktoClient from '@/core/index.js';
33
import { BaseError } from '@/errors/base.js';
44
import { getChains } from '@/explorer/chain.js';
5-
import type { UserOp } from '@/types/core.js';
5+
import type { Address, UserOp } from '@/types/core.js';
66
import { Constants } from '@/utils/index.js';
77
import { generateUUID, nonceToBigInt } from '@/utils/nonce.js';
88
import {
@@ -29,9 +29,11 @@ import {
2929
* @param data - The parameters for transferring the token (caip2Id, recipientWalletAddress, tokenAddress, amount).
3030
* @returns The User Operation (UserOp) for the token transfer.
3131
*/
32+
// TODO: Implement a destructured param instead before V1 release
3233
export async function tokenTransfer(
3334
oc: OktoClient,
3435
data: TokenTransferIntentParams,
36+
feePayerAddress?: Address,
3537
): Promise<UserOp> {
3638
if (!oc.isLoggedIn()) {
3739
throw new BaseError('User not logged in');
@@ -42,6 +44,10 @@ export async function tokenTransfer(
4244
throw new BaseError('Recipient address cannot be same as the user address');
4345
}
4446

47+
if (!feePayerAddress) {
48+
feePayerAddress = Constants.FEE_PAYER_ADDRESS;
49+
}
50+
4551
const nonce = generateUUID();
4652

4753
const jobParametersAbiType =
@@ -72,6 +78,7 @@ export async function tokenTransfer(
7278
toHex(nonceToBigInt(nonce), { size: 32 }),
7379
oc.clientSWA,
7480
oc.userSWA,
81+
feePayerAddress,
7582
encodeAbiParameters(
7683
parseAbiParameters('(bool gsnEnabled, bool sponsorshipEnabled)'),
7784
[

packages/core-js/src/utils/constants.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export class Constants {
99

1010
static readonly USEROP_VALUE = BigInt(0);
1111

12+
static readonly FEE_PAYER_ADDRESS =
13+
'0x0000000000000000000000000000000000000000';
14+
1215
static readonly GAS_LIMITS = {
1316
CALL_GAS_LIMIT: BigInt(300_000),
1417
VERIFICATION_GAS_LIMIT: BigInt(200_000),
@@ -28,11 +31,11 @@ export class Constants {
2831

2932
static readonly ENV_CONFIG = {
3033
STAGING: {
31-
PAYMASTER_ADDRESS: '0x0871051BfF8C7041c985dEddFA8eF63d23AD3Fa0' as Hex,
32-
JOB_MANAGER_ADDRESS: '0xED3D17cae886e008D325Ad7c34F3bdE030B80c2E' as Hex,
34+
PAYMASTER_ADDRESS: '0xdAa292E9B9a6B287c84d636F3b65f4A5Dc787e3f' as Hex,
35+
JOB_MANAGER_ADDRESS: '0xb5e77f7Ff1ab31Fc1bE99F484DB62f01a6b93D4d' as Hex,
3336
ENTRYPOINT_CONTRACT_ADDRESS:
34-
'0x8D29ECb381CA4874767Ef3744F6df37748B12715' as Hex,
35-
CHAIN_ID: 24879,
37+
'0xec3F5f7a3f0e43e61D8711A90B8c8Fc59B9a88ba' as Hex,
38+
CHAIN_ID: 124736089,
3639
},
3740
SANDBOX: {
3841
PAYMASTER_ADDRESS: '0x5408fAa7F005c46B85d82060c532b820F534437c' as Hex,

0 commit comments

Comments
 (0)