@funkit/core 0.8.6 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fetch-polyfill.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/src/abis/CheckoutPaymaster.json +1 -0
- package/dist/src/abis/EstimationPaymaster.json +1 -1
- package/dist/src/abis/UniswapV3LimitOrder.json +1 -1
- package/dist/src/actions/AccessControl.d.ts +6 -6
- package/dist/src/actions/AccessControl.js +23 -16
- package/dist/src/actions/AccessControl.js.map +1 -1
- package/dist/src/actions/BatchActions.d.ts +2 -2
- package/dist/src/actions/BatchActions.js +2 -2
- package/dist/src/actions/BatchActions.js.map +1 -1
- package/dist/src/actions/Bridge.d.ts +5 -4
- package/dist/src/actions/Bridge.js +13 -9
- package/dist/src/actions/Bridge.js.map +1 -1
- package/dist/src/actions/FirstClassActions.d.ts +8 -6
- package/dist/src/actions/FirstClassActions.js +44 -69
- package/dist/src/actions/FirstClassActions.js.map +1 -1
- package/dist/src/actions/Group.d.ts +3 -3
- package/dist/src/actions/Group.js +6 -14
- package/dist/src/actions/Group.js.map +1 -1
- package/dist/src/actions/LimitOrder.d.ts +4 -4
- package/dist/src/actions/LimitOrder.js +21 -19
- package/dist/src/actions/LimitOrder.js.map +1 -1
- package/dist/src/actions/Stake.d.ts +3 -3
- package/dist/src/actions/Stake.js +31 -44
- package/dist/src/actions/Stake.js.map +1 -1
- package/dist/src/actions/Swap.d.ts +4 -4
- package/dist/src/actions/Swap.js +43 -41
- package/dist/src/actions/Swap.js.map +1 -1
- package/dist/src/actions/Token.d.ts +6 -6
- package/dist/src/actions/Token.js +46 -33
- package/dist/src/actions/Token.js.map +1 -1
- package/dist/src/actions/index.d.ts +7 -7
- package/dist/src/actions/types.d.ts +4 -4
- package/dist/src/actions/types.js +2 -2
- package/dist/src/actions/types.js.map +1 -1
- package/dist/src/apis/AccessControlApis.d.ts +1 -1
- package/dist/src/apis/AccessControlApis.js +7 -3
- package/dist/src/apis/AccessControlApis.js.map +1 -1
- package/dist/src/apis/AssetApis.d.ts +10 -0
- package/dist/src/apis/AssetApis.js +11 -1
- package/dist/src/apis/AssetApis.js.map +1 -1
- package/dist/src/apis/BridgeApis.d.ts +1 -1
- package/dist/src/apis/BridgeApis.js +13 -13
- package/dist/src/apis/BridgeApis.js.map +1 -1
- package/dist/src/apis/CheckoutApis.d.ts +43 -0
- package/dist/src/apis/CheckoutApis.js +116 -0
- package/dist/src/apis/CheckoutApis.js.map +1 -0
- package/dist/src/apis/ContractApis.js +1 -1
- package/dist/src/apis/ContractApis.js.map +1 -1
- package/dist/src/apis/FaucetApis.js.map +1 -1
- package/dist/src/apis/GroupApis.d.ts +2 -6
- package/dist/src/apis/GroupApis.js +4 -29
- package/dist/src/apis/GroupApis.js.map +1 -1
- package/dist/src/apis/InfoApis.d.ts +1 -1
- package/dist/src/apis/InfoApis.js +9 -7
- package/dist/src/apis/InfoApis.js.map +1 -1
- package/dist/src/apis/ListenerApis.d.ts +1 -1
- package/dist/src/apis/ListenerApis.js +6 -6
- package/dist/src/apis/ListenerApis.js.map +1 -1
- package/dist/src/apis/MeshApis.d.ts +87 -0
- package/dist/src/apis/MeshApis.js +213 -0
- package/dist/src/apis/MeshApis.js.map +1 -0
- package/dist/src/apis/NFTApis.js.map +1 -1
- package/dist/src/apis/OnOffRampApis.d.ts +2 -0
- package/dist/src/apis/OnOffRampApis.js +24 -5
- package/dist/src/apis/OnOffRampApis.js.map +1 -1
- package/dist/src/apis/OnOffRampUtils.js +2 -2
- package/dist/src/apis/OnOffRampUtils.js.map +1 -1
- package/dist/src/apis/OperationApis.d.ts +4 -4
- package/dist/src/apis/OperationApis.js +21 -12
- package/dist/src/apis/OperationApis.js.map +1 -1
- package/dist/src/apis/PaymasterApis.d.ts +1 -6
- package/dist/src/apis/PaymasterApis.js +3 -70
- package/dist/src/apis/PaymasterApis.js.map +1 -1
- package/dist/src/apis/SwapApis.d.ts +2 -2
- package/dist/src/apis/SwapApis.js +6 -6
- package/dist/src/apis/SwapApis.js.map +1 -1
- package/dist/src/apis/TurnkeyApis.d.ts +3 -0
- package/dist/src/apis/TurnkeyApis.js +19 -0
- package/dist/src/apis/TurnkeyApis.js.map +1 -0
- package/dist/src/apis/UserApis.d.ts +2 -5
- package/dist/src/apis/UserApis.js +11 -22
- package/dist/src/apis/UserApis.js.map +1 -1
- package/dist/src/apis/index.d.ts +13 -10
- package/dist/src/apis/index.js +4 -1
- package/dist/src/apis/index.js.map +1 -1
- package/dist/src/apis/types.d.ts +79 -7
- package/dist/src/apis/types.js +16 -0
- package/dist/src/apis/types.js.map +1 -1
- package/dist/src/auth/Auth.d.ts +6 -6
- package/dist/src/auth/Auth.js +48 -46
- package/dist/src/auth/Auth.js.map +1 -1
- package/dist/src/auth/SessionKeyAuth.d.ts +5 -5
- package/dist/src/auth/SessionKeyAuth.js +29 -24
- package/dist/src/auth/SessionKeyAuth.js.map +1 -1
- package/dist/src/auth/index.d.ts +2 -2
- package/dist/src/auth/types.d.ts +1 -1
- package/dist/src/common/constants.d.ts +111 -17
- package/dist/src/common/constants.js +158 -85
- package/dist/src/common/constants.js.map +1 -1
- package/dist/src/common/index.d.ts +2 -2
- package/dist/src/common/types.d.ts +2 -2
- package/dist/src/config/Config.d.ts +1 -1
- package/dist/src/config/Config.js +10 -4
- package/dist/src/config/Config.js.map +1 -1
- package/dist/src/config/index.d.ts +2 -2
- package/dist/src/config/types.d.ts +4 -2
- package/dist/src/data/Chain.d.ts +4 -4
- package/dist/src/data/Chain.js +38 -27
- package/dist/src/data/Chain.js.map +1 -1
- package/dist/src/data/NFT.d.ts +3 -3
- package/dist/src/data/NFT.js +11 -11
- package/dist/src/data/NFT.js.map +1 -1
- package/dist/src/data/Operation.d.ts +5 -5
- package/dist/src/data/Operation.js +12 -10
- package/dist/src/data/Operation.js.map +1 -1
- package/dist/src/data/SolidityData.d.ts +3 -3
- package/dist/src/data/SolidityData.js +37 -17
- package/dist/src/data/SolidityData.js.map +1 -1
- package/dist/src/data/Token.d.ts +21 -20
- package/dist/src/data/Token.js +49 -51
- package/dist/src/data/Token.js.map +1 -1
- package/dist/src/data/index.d.ts +6 -6
- package/dist/src/data/index.js +2 -2
- package/dist/src/data/index.js.map +1 -1
- package/dist/src/data/types.d.ts +2 -2
- package/dist/src/data/types.js +3 -3
- package/dist/src/data/types.js.map +1 -1
- package/dist/src/errors/BaseError.js +4 -3
- package/dist/src/errors/BaseError.js.map +1 -1
- package/dist/src/errors/ClientError.d.ts +1 -1
- package/dist/src/errors/ClientError.js +3 -3
- package/dist/src/errors/ClientError.js.map +1 -1
- package/dist/src/errors/ServerError.d.ts +1 -1
- package/dist/src/errors/ServerError.js.map +1 -1
- package/dist/src/errors/index.d.ts +4 -4
- package/dist/src/errors/types.d.ts +2 -1
- package/dist/src/errors/types.js +4 -3
- package/dist/src/errors/types.js.map +1 -1
- package/dist/src/sponsors/CheckoutSponsor.d.ts +23 -0
- package/dist/src/sponsors/CheckoutSponsor.js +65 -0
- package/dist/src/sponsors/CheckoutSponsor.js.map +1 -0
- package/dist/src/sponsors/GaslessSponsor.d.ts +6 -6
- package/dist/src/sponsors/GaslessSponsor.js +20 -32
- package/dist/src/sponsors/GaslessSponsor.js.map +1 -1
- package/dist/src/sponsors/Sponsor.d.ts +15 -15
- package/dist/src/sponsors/Sponsor.js +24 -40
- package/dist/src/sponsors/Sponsor.js.map +1 -1
- package/dist/src/sponsors/TokenSponsor.d.ts +15 -15
- package/dist/src/sponsors/TokenSponsor.js +118 -135
- package/dist/src/sponsors/TokenSponsor.js.map +1 -1
- package/dist/src/sponsors/index.d.ts +4 -3
- package/dist/src/sponsors/index.js +2 -1
- package/dist/src/sponsors/index.js.map +1 -1
- package/dist/src/sponsors/types.d.ts +2 -1
- package/dist/src/sponsors/types.js +2 -1
- package/dist/src/sponsors/types.js.map +1 -1
- package/dist/src/utils/ApiUtils.js +21 -19
- package/dist/src/utils/ApiUtils.js.map +1 -1
- package/dist/src/utils/AuthUtils.d.ts +1 -2
- package/dist/src/utils/AuthUtils.js +7 -25
- package/dist/src/utils/AuthUtils.js.map +1 -1
- package/dist/src/utils/ChainUtils.d.ts +5 -5
- package/dist/src/utils/ChainUtils.js +35 -20
- package/dist/src/utils/ChainUtils.js.map +1 -1
- package/dist/src/utils/CheckoutUtils.d.ts +6 -0
- package/dist/src/utils/CheckoutUtils.js +24 -0
- package/dist/src/utils/CheckoutUtils.js.map +1 -0
- package/dist/src/utils/GroupUtils.d.ts +4 -0
- package/dist/src/utils/GroupUtils.js +30 -0
- package/dist/src/utils/GroupUtils.js.map +1 -0
- package/dist/src/utils/MerkleUtils.d.ts +1 -1
- package/dist/src/utils/MerkleUtils.js +5 -5
- package/dist/src/utils/MerkleUtils.js.map +1 -1
- package/dist/src/utils/PaymasterUtils.d.ts +3 -3
- package/dist/src/utils/PaymasterUtils.js +6 -2
- package/dist/src/utils/PaymasterUtils.js.map +1 -1
- package/dist/src/utils/SwapUtils.d.ts +2 -2
- package/dist/src/utils/SwapUtils.js +43 -34
- package/dist/src/utils/SwapUtils.js.map +1 -1
- package/dist/src/utils/TypeUtils.js.map +1 -1
- package/dist/src/utils/UserOpUtils.d.ts +2 -2
- package/dist/src/utils/UserOpUtils.js +79 -65
- package/dist/src/utils/UserOpUtils.js.map +1 -1
- package/dist/src/utils/ViemUtils.d.ts +2 -2
- package/dist/src/utils/ViemUtils.js +10 -6
- package/dist/src/utils/ViemUtils.js.map +1 -1
- package/dist/src/utils/WalletUtils.d.ts +2 -2
- package/dist/src/utils/WalletUtils.js +6 -5
- package/dist/src/utils/WalletUtils.js.map +1 -1
- package/dist/src/utils/index.d.ts +8 -7
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/viem/ContractInterface.d.ts +4 -4
- package/dist/src/viem/ContractInterface.js +8 -8
- package/dist/src/viem/ContractInterface.js.map +1 -1
- package/dist/src/viem/Converter.d.ts +823 -1107
- package/dist/src/viem/Converter.js +13 -11
- package/dist/src/viem/Converter.js.map +1 -1
- package/dist/src/viem/index.d.ts +2 -2
- package/dist/src/wallet/FunWallet.d.ts +8 -8
- package/dist/src/wallet/FunWallet.js +141 -97
- package/dist/src/wallet/FunWallet.js.map +1 -1
- package/dist/src/wallet/index.d.ts +2 -2
- package/dist/src/wallet/types.d.ts +1 -1
- package/package.json +15 -8
|
@@ -25,29 +25,30 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
25
25
|
* @param {object} params - The parameters for the constructing fun wallet - (users, uniqueId) or walletAddr
|
|
26
26
|
*/
|
|
27
27
|
constructor(params) {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const chain = globalThis.globalEnvOption.chain;
|
|
29
|
+
super(chain);
|
|
30
|
+
if (typeof params === 'string') {
|
|
30
31
|
if ((0, viem_1.isAddress)(params)) {
|
|
31
32
|
this.address = params;
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter,
|
|
35
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter, 'string input must be an address type', params, 'Provide either (uniqueId, users) or walletAddr when constructing a FunWallet', 'https://docs.fun.xyz/how-to-guides/execute-transactions/create-funwallet#create-funwallet-manual-funwallet-creation');
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
const { users, uniqueId } = params;
|
|
39
40
|
if (!uniqueId || !(0, TypeUtils_1.isBytes32)(uniqueId) || !users || users.length <= 0) {
|
|
40
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter,
|
|
41
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter, 'uniqueId must be bytes32 and users must be non-empty', params, 'The uniqueId field should be a 32 byte Hexstring and the users field should be an array of User objects', 'https://docs.fun.xyz/how-to-guides/execute-transactions/create-funwallet#create-funwallet-manual-funwallet-creation');
|
|
41
42
|
}
|
|
42
43
|
this.userInfo = new Map(users?.map((user) => {
|
|
43
44
|
if (!user.userId || !(0, viem_1.isHex)(user.userId)) {
|
|
44
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter,
|
|
45
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter, 'userId is required and must be a hex string', users, 'Provide hex string userId when creating a FunWallet', 'https://docs.fun.xyz/how-to-guides/execute-transactions/create-funwallet#create-funwallet-manual-funwallet-creation');
|
|
45
46
|
}
|
|
46
47
|
if (user.groupInfo &&
|
|
47
48
|
(!Number.isInteger(user.groupInfo.threshold) ||
|
|
48
49
|
!Array.isArray(user.groupInfo.memberIds) ||
|
|
49
50
|
!user.groupInfo.memberIds.every((memberId) => (0, viem_1.isHex)(memberId)))) {
|
|
50
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter,
|
|
51
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameter, 'groupInfo must be an object with threshold as integer and memberIds as array of hex strings', users, 'Provide valid groupInfo when creating a FunWallet', 'https://docs.fun.xyz/how-to-guides/execute-transactions/create-funwallet#create-funwallet-manual-funwallet-creation');
|
|
51
52
|
}
|
|
52
53
|
return [(0, viem_1.pad)(user.userId, { size: 32 }), user];
|
|
53
54
|
}));
|
|
@@ -85,9 +86,9 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
85
86
|
*/
|
|
86
87
|
static async getAddressOffline(uniqueId, rpcUrl, factoryAddress) {
|
|
87
88
|
const client = await (0, viem_1.createPublicClient)({
|
|
88
|
-
transport: (0, viem_1.http)(rpcUrl)
|
|
89
|
+
transport: (0, viem_1.http)(rpcUrl),
|
|
89
90
|
});
|
|
90
|
-
return await constants_1.FACTORY_CONTRACT_INTERFACE.readFromChain(factoryAddress,
|
|
91
|
+
return await constants_1.FACTORY_CONTRACT_INTERFACE.readFromChain(factoryAddress, 'getAddress', [(0, viem_1.keccak256)((0, viem_1.toBytes)(uniqueId))], client);
|
|
91
92
|
}
|
|
92
93
|
/**
|
|
93
94
|
* Get all tokens for a specific chain
|
|
@@ -98,13 +99,15 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
98
99
|
async getTokens(chainIdInput, onlyVerifiedTokens = false) {
|
|
99
100
|
let chainId;
|
|
100
101
|
if (!chainIdInput) {
|
|
101
|
-
const chain = await data_1.Chain.getChain({
|
|
102
|
+
const chain = await data_1.Chain.getChain({
|
|
103
|
+
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
104
|
+
});
|
|
102
105
|
chainId = await chain.getChainId();
|
|
103
106
|
}
|
|
104
107
|
else {
|
|
105
108
|
chainId = chainIdInput;
|
|
106
109
|
}
|
|
107
|
-
if (chainId ===
|
|
110
|
+
if (chainId === 'ALL') {
|
|
108
111
|
return await (0, apis_1.getAllTokens)(await this.getAddress(), onlyVerifiedTokens);
|
|
109
112
|
}
|
|
110
113
|
else {
|
|
@@ -119,13 +122,15 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
119
122
|
async getNFTs(chainIdInput) {
|
|
120
123
|
let chainId;
|
|
121
124
|
if (!chainIdInput) {
|
|
122
|
-
const chain = await data_1.Chain.getChain({
|
|
125
|
+
const chain = await data_1.Chain.getChain({
|
|
126
|
+
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
127
|
+
});
|
|
123
128
|
chainId = await chain.getChainId();
|
|
124
129
|
}
|
|
125
130
|
else {
|
|
126
131
|
chainId = chainIdInput;
|
|
127
132
|
}
|
|
128
|
-
if (chainId ===
|
|
133
|
+
if (chainId === 'ALL') {
|
|
129
134
|
return await (0, apis_1.getAllNFTs)(await this.getAddress());
|
|
130
135
|
}
|
|
131
136
|
else {
|
|
@@ -142,20 +147,25 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
142
147
|
async getAssets(chainIdInput, onlyVerifiedTokens = false, checkStatus = false) {
|
|
143
148
|
let chainId;
|
|
144
149
|
if (!chainIdInput) {
|
|
145
|
-
const chain = await data_1.Chain.getChain({
|
|
150
|
+
const chain = await data_1.Chain.getChain({
|
|
151
|
+
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
152
|
+
});
|
|
146
153
|
chainId = await chain.getChainId();
|
|
147
154
|
}
|
|
148
155
|
else {
|
|
149
156
|
chainId = chainIdInput;
|
|
150
157
|
}
|
|
151
158
|
let tokens = {}, nfts = {}, lidoWithdrawals = {};
|
|
152
|
-
if (chainId ===
|
|
159
|
+
if (chainId === 'ALL') {
|
|
153
160
|
tokens = await (0, apis_1.getAllTokens)(await this.getAddress(), onlyVerifiedTokens);
|
|
154
161
|
nfts = await (0, apis_1.getAllNFTs)(await this.getAddress());
|
|
155
162
|
if (checkStatus) {
|
|
156
|
-
const ethMainnetLidoWithdrawals = await (0, apis_1.getLidoWithdrawals)(
|
|
157
|
-
const goerliLidoWithdrawals = await (0, apis_1.getLidoWithdrawals)(
|
|
158
|
-
lidoWithdrawals = {
|
|
163
|
+
const ethMainnetLidoWithdrawals = await (0, apis_1.getLidoWithdrawals)('1', await this.getAddress());
|
|
164
|
+
const goerliLidoWithdrawals = await (0, apis_1.getLidoWithdrawals)('5', await this.getAddress());
|
|
165
|
+
lidoWithdrawals = {
|
|
166
|
+
...ethMainnetLidoWithdrawals,
|
|
167
|
+
...goerliLidoWithdrawals,
|
|
168
|
+
};
|
|
159
169
|
}
|
|
160
170
|
}
|
|
161
171
|
else {
|
|
@@ -177,11 +187,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
177
187
|
*/
|
|
178
188
|
async getNonce(sender, key = (0, utils_1.generateRandomNonceKey)(), txOptions = globalThis.globalEnvOption) {
|
|
179
189
|
const chain = await data_1.Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
180
|
-
const entryPointAddress = await chain.getAddress(
|
|
190
|
+
const entryPointAddress = await chain.getAddress('entryPointAddress');
|
|
181
191
|
let nonce = undefined;
|
|
182
192
|
let retryCount = 3;
|
|
183
193
|
while ((nonce === undefined || nonce === null) && retryCount > 0) {
|
|
184
|
-
nonce = await common_1.ENTRYPOINT_CONTRACT_INTERFACE.readFromChain(entryPointAddress,
|
|
194
|
+
nonce = await common_1.ENTRYPOINT_CONTRACT_INTERFACE.readFromChain(entryPointAddress, 'getNonce', [sender, key], chain);
|
|
185
195
|
retryCount--;
|
|
186
196
|
}
|
|
187
197
|
if (nonce !== undefined && nonce !== null) {
|
|
@@ -243,8 +253,8 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
243
253
|
userId: group.groupId,
|
|
244
254
|
groupInfo: {
|
|
245
255
|
threshold: group.threshold,
|
|
246
|
-
memberIds: group.memberIds
|
|
247
|
-
}
|
|
256
|
+
memberIds: group.memberIds,
|
|
257
|
+
},
|
|
248
258
|
});
|
|
249
259
|
});
|
|
250
260
|
}
|
|
@@ -267,7 +277,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
267
277
|
* @returns {Promise<Operation>} The operation to create the wallet.
|
|
268
278
|
*/
|
|
269
279
|
async create(auth, userId, txOptions = globalThis.globalEnvOption) {
|
|
270
|
-
const transactionParams = {
|
|
280
|
+
const transactionParams = {
|
|
281
|
+
to: await this.getAddress(),
|
|
282
|
+
data: '0x',
|
|
283
|
+
value: 0n,
|
|
284
|
+
};
|
|
271
285
|
return await this.createOperation(auth, userId, transactionParams, txOptions);
|
|
272
286
|
}
|
|
273
287
|
/**
|
|
@@ -321,17 +335,19 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
321
335
|
* @returns {Promise<Operation>} The created and prepared operation.
|
|
322
336
|
*/
|
|
323
337
|
async createOperation(auth, userId, transactionParams, txOptions = globalThis.globalEnvOption) {
|
|
324
|
-
if (!userId || userId ===
|
|
325
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter,
|
|
338
|
+
if (!userId || userId === '') {
|
|
339
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter, 'userId is required', { userId }, 'Provide userId when createOperation', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
326
340
|
}
|
|
327
341
|
userId = (0, viem_1.pad)(userId, { size: 32 }).toLowerCase();
|
|
328
342
|
const chain = await data_1.Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
329
343
|
const sender = await this.getAddress();
|
|
330
|
-
const initCode = (await chain.addressIsContract(sender))
|
|
331
|
-
|
|
344
|
+
const initCode = (await chain.addressIsContract(sender))
|
|
345
|
+
? '0x'
|
|
346
|
+
: await this.getThisInitCode(chain);
|
|
347
|
+
let paymasterAndData = '0x';
|
|
332
348
|
let maxFeePerGas, maxPriorityFeePerGas;
|
|
333
349
|
const chainId = await chain.getChainId();
|
|
334
|
-
const OPStackChains = [
|
|
350
|
+
const OPStackChains = ['10', '8453'];
|
|
335
351
|
if (OPStackChains.includes(chainId)) {
|
|
336
352
|
const gasPrice = await chain.getFeeData();
|
|
337
353
|
maxFeePerGas = gasPrice.maxFeePerGas;
|
|
@@ -348,18 +364,26 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
348
364
|
maxFeePerGas,
|
|
349
365
|
maxPriorityFeePerGas,
|
|
350
366
|
initCode,
|
|
351
|
-
nonce: txOptions.nonce !== null && txOptions.nonce !== undefined
|
|
367
|
+
nonce: txOptions.nonce !== null && txOptions.nonce !== undefined
|
|
368
|
+
? txOptions.nonce
|
|
369
|
+
: await this.getNonce(sender),
|
|
352
370
|
preVerificationGas: 100000n,
|
|
353
371
|
callGasLimit: BigInt(10e6),
|
|
354
|
-
verificationGasLimit: BigInt(10e6)
|
|
372
|
+
verificationGasLimit: BigInt(10e6),
|
|
355
373
|
};
|
|
374
|
+
if ((await chain.getChainId()) === '36865') {
|
|
375
|
+
partialOp.callGasLimit = BigInt(10e5);
|
|
376
|
+
partialOp.verificationGasLimit = BigInt(10e5);
|
|
377
|
+
}
|
|
356
378
|
const isGroupOp = (await auth.getUserId()) !== userId;
|
|
357
379
|
const operation = new data_1.Operation(partialOp, {
|
|
358
380
|
chainId: await chain.getChainId(),
|
|
359
|
-
opType: isGroupOp
|
|
381
|
+
opType: isGroupOp
|
|
382
|
+
? data_1.OperationType.GROUP_OPERATION
|
|
383
|
+
: data_1.OperationType.SINGLE_OPERATION,
|
|
360
384
|
authType: isGroupOp ? data_1.AuthType.MULTI_SIG : data_1.AuthType.ECDSA,
|
|
361
385
|
walletAddr: await this.getAddress(),
|
|
362
|
-
proposer: await auth.getAddress()
|
|
386
|
+
proposer: await auth.getAddress(),
|
|
363
387
|
});
|
|
364
388
|
if (isGroupOp) {
|
|
365
389
|
operation.groupId = (0, viem_1.pad)(userId, { size: 32 });
|
|
@@ -374,6 +398,10 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
374
398
|
paymasterAndData = (await sponsor.getPaymasterAndData(txOptions)).toLowerCase();
|
|
375
399
|
}
|
|
376
400
|
}
|
|
401
|
+
else if (txOptions.gasSponsor.useCheckoutSponsor) {
|
|
402
|
+
const sponsor = new sponsors_1.CheckoutSponsor(txOptions);
|
|
403
|
+
paymasterAndData = (await sponsor.getPaymasterAndData(txOptions)).toLowerCase();
|
|
404
|
+
}
|
|
377
405
|
else {
|
|
378
406
|
const sponsor = new sponsors_1.GaslessSponsor(txOptions);
|
|
379
407
|
paymasterAndData = (await sponsor.getPaymasterAndData(txOptions)).toLowerCase();
|
|
@@ -381,6 +409,9 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
381
409
|
}
|
|
382
410
|
operation.userOp.paymasterAndData = paymasterAndData;
|
|
383
411
|
const estimatedOperation = await this.estimateOperation(auth, userId, operation, txOptions);
|
|
412
|
+
if (txOptions.bypassInit) {
|
|
413
|
+
estimatedOperation.userOp.initCode = '0x';
|
|
414
|
+
}
|
|
384
415
|
// sign the userOp directly here as we do not have the opId yet
|
|
385
416
|
estimatedOperation.userOp.signature = await auth.signOp(estimatedOperation, chain, (0, utils_1.isGroupOperation)(operation));
|
|
386
417
|
if (txOptions.skipDBAction !== true) {
|
|
@@ -430,15 +461,15 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
430
461
|
userId: operation.groupId,
|
|
431
462
|
groupInfo: {
|
|
432
463
|
threshold: groups[0].threshold,
|
|
433
|
-
memberIds: groups[0].memberIds
|
|
434
|
-
}
|
|
464
|
+
memberIds: groups[0].memberIds,
|
|
465
|
+
},
|
|
435
466
|
});
|
|
436
467
|
}
|
|
437
468
|
}
|
|
438
469
|
}
|
|
439
470
|
const threshold = this.userInfo?.get(operation.groupId)?.groupInfo?.threshold ?? 1;
|
|
440
471
|
if (threshold <= 1) {
|
|
441
|
-
if (!operation.userOp.signature || operation.userOp.signature ===
|
|
472
|
+
if (!operation.userOp.signature || operation.userOp.signature === '0x') {
|
|
442
473
|
operation.userOp.signature = await auth.signOp(operation, chain, (0, utils_1.isGroupOperation)(operation));
|
|
443
474
|
}
|
|
444
475
|
}
|
|
@@ -448,7 +479,9 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
448
479
|
const storedOps = await (0, OperationApis_1.getOps)([operation.opId], chainId);
|
|
449
480
|
let collectedSigCount;
|
|
450
481
|
if ((0, utils_1.isSignatureMissing)(await auth.getUserId(), storedOps[0]?.signatures)) {
|
|
451
|
-
collectedSigCount = storedOps[0]?.signatures?.length
|
|
482
|
+
collectedSigCount = storedOps[0]?.signatures?.length
|
|
483
|
+
? storedOps[0]?.signatures?.length + 1
|
|
484
|
+
: 1;
|
|
452
485
|
if (collectedSigCount >= threshold) {
|
|
453
486
|
operation.userOp.signature = await auth.signOp(operation, chain, (0, utils_1.isGroupOperation)(operation));
|
|
454
487
|
}
|
|
@@ -457,11 +490,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
457
490
|
collectedSigCount = storedOps[0]?.signatures?.length ?? 1;
|
|
458
491
|
}
|
|
459
492
|
if (collectedSigCount < threshold) {
|
|
460
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures,
|
|
493
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures, 'Signatures are not sufficient to execute the operation', { threshold, collectedSigCount, chainId }, 'Only execute operation with enough signatures', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
461
494
|
}
|
|
462
495
|
}
|
|
463
496
|
else {
|
|
464
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures,
|
|
497
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures, 'Signatures are not sufficient to execute the operation', { threshold, chainId, skipDBAction: txOptions.skipDBAction }, 'Only execute operation with enough signatures', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
465
498
|
}
|
|
466
499
|
}
|
|
467
500
|
let receipt;
|
|
@@ -470,9 +503,9 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
470
503
|
opId: operation.opId,
|
|
471
504
|
chainId,
|
|
472
505
|
executedBy: await auth.getAddress(),
|
|
473
|
-
entryPointAddress: await chain.getAddress(
|
|
506
|
+
entryPointAddress: await chain.getAddress('entryPointAddress'),
|
|
474
507
|
signature: operation.userOp.signature,
|
|
475
|
-
groupInfo: this.userInfo?.get(operation.groupId)?.groupInfo
|
|
508
|
+
groupInfo: this.userInfo?.get(operation.groupId)?.groupInfo,
|
|
476
509
|
});
|
|
477
510
|
}
|
|
478
511
|
else {
|
|
@@ -480,29 +513,23 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
480
513
|
opId: operation.opId,
|
|
481
514
|
chainId,
|
|
482
515
|
executedBy: await auth.getAddress(),
|
|
483
|
-
entryPointAddress: await chain.getAddress(
|
|
516
|
+
entryPointAddress: await chain.getAddress('entryPointAddress'),
|
|
484
517
|
signature: operation.userOp.signature,
|
|
485
|
-
userOp: operation.userOp
|
|
518
|
+
userOp: operation.userOp,
|
|
486
519
|
});
|
|
487
520
|
}
|
|
488
521
|
receipt = await (0, OperationApis_1.getFullReceipt)(operation.opId, chainId, receipt.userOpHash);
|
|
489
522
|
if ((0, utils_1.isWalletInitOp)(operation.userOp) && txOptions.skipDBAction !== true) {
|
|
490
523
|
await (0, UserApis_1.addUserToWallet)(await auth.getAddress(), chainId, await this.getAddress(), Array.from(this.userInfo.keys()), this.walletUniqueId);
|
|
491
|
-
if ((0, utils_1.isGroupOperation)(operation)) {
|
|
492
|
-
const group = this.userInfo.get(operation.groupId);
|
|
493
|
-
if (group && group.groupInfo) {
|
|
494
|
-
await (0, GroupApis_1.createGroup)(operation.groupId, chainId, group.groupInfo.threshold, await this.getAddress(), group.groupInfo.memberIds);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
524
|
if (txOptions?.gasSponsor?.sponsorAddress) {
|
|
498
525
|
const paymasterType = (0, PaymasterUtils_1.getPaymasterType)(txOptions);
|
|
499
526
|
(0, PaymasterApis_1.addTransaction)(await chain.getChainId(), Date.now(), receipt.txId, {
|
|
500
|
-
action:
|
|
501
|
-
amount: -1,
|
|
527
|
+
action: 'sponsor',
|
|
528
|
+
amount: -1, //Get amount from lazy processing
|
|
502
529
|
from: txOptions.gasSponsor.sponsorAddress,
|
|
503
530
|
to: await this.getAddress(),
|
|
504
|
-
token:
|
|
505
|
-
txid: receipt.txId
|
|
531
|
+
token: 'eth',
|
|
532
|
+
txid: receipt.txId,
|
|
506
533
|
}, paymasterType, txOptions.gasSponsor.sponsorAddress);
|
|
507
534
|
}
|
|
508
535
|
}
|
|
@@ -530,15 +557,15 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
530
557
|
userId: operation.groupId,
|
|
531
558
|
groupInfo: {
|
|
532
559
|
threshold: groups[0].threshold,
|
|
533
|
-
memberIds: groups[0].memberIds
|
|
534
|
-
}
|
|
560
|
+
memberIds: groups[0].memberIds,
|
|
561
|
+
},
|
|
535
562
|
});
|
|
536
563
|
}
|
|
537
564
|
}
|
|
538
565
|
}
|
|
539
566
|
const threshold = this.userInfo?.get(operation.groupId)?.groupInfo?.threshold ?? 1;
|
|
540
567
|
if (threshold <= 1) {
|
|
541
|
-
if (!operation.userOp.signature || operation.userOp.signature ===
|
|
568
|
+
if (!operation.userOp.signature || operation.userOp.signature === '0x') {
|
|
542
569
|
operation.userOp.signature = await auth.signOp(operation, chain, (0, utils_1.isGroupOperation)(operation));
|
|
543
570
|
}
|
|
544
571
|
}
|
|
@@ -548,7 +575,9 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
548
575
|
const storedOps = await (0, OperationApis_1.getOps)([operation.opId], chainId);
|
|
549
576
|
let collectedSigCount;
|
|
550
577
|
if ((0, utils_1.isSignatureMissing)(await auth.getUserId(), storedOps[0]?.signatures)) {
|
|
551
|
-
collectedSigCount = storedOps[0]?.signatures?.length
|
|
578
|
+
collectedSigCount = storedOps[0]?.signatures?.length
|
|
579
|
+
? storedOps[0]?.signatures?.length + 1
|
|
580
|
+
: 1;
|
|
552
581
|
if (collectedSigCount >= threshold) {
|
|
553
582
|
operation.userOp.signature = await auth.signOp(operation, chain, (0, utils_1.isGroupOperation)(operation));
|
|
554
583
|
}
|
|
@@ -557,11 +586,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
557
586
|
collectedSigCount = storedOps[0]?.signatures?.length ?? 1;
|
|
558
587
|
}
|
|
559
588
|
if (collectedSigCount < threshold) {
|
|
560
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures,
|
|
589
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures, 'Signatures are not sufficient to execute the operation', { threshold, collectedSigCount, chainId }, 'Only execute operation with enough signatures', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
561
590
|
}
|
|
562
591
|
}
|
|
563
592
|
else {
|
|
564
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures,
|
|
593
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InsufficientSignatures, 'Signatures are not sufficient to execute the operation', { threshold, chainId, skipDBAction: txOptions.skipDBAction }, 'Only execute operation with enough signatures', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
565
594
|
}
|
|
566
595
|
}
|
|
567
596
|
if ((0, utils_1.isGroupOperation)(operation)) {
|
|
@@ -569,9 +598,9 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
569
598
|
opId: operation.opId,
|
|
570
599
|
chainId,
|
|
571
600
|
scheduledBy: await auth.getAddress(),
|
|
572
|
-
entryPointAddress: await chain.getAddress(
|
|
601
|
+
entryPointAddress: await chain.getAddress('entryPointAddress'),
|
|
573
602
|
signature: operation.userOp.signature,
|
|
574
|
-
groupInfo: this.userInfo?.get(operation.groupId)?.groupInfo
|
|
603
|
+
groupInfo: this.userInfo?.get(operation.groupId)?.groupInfo,
|
|
575
604
|
});
|
|
576
605
|
}
|
|
577
606
|
else {
|
|
@@ -579,13 +608,13 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
579
608
|
opId: operation.opId,
|
|
580
609
|
chainId,
|
|
581
610
|
scheduledBy: await auth.getAddress(),
|
|
582
|
-
entryPointAddress: await chain.getAddress(
|
|
611
|
+
entryPointAddress: await chain.getAddress('entryPointAddress'),
|
|
583
612
|
signature: operation.userOp.signature,
|
|
584
|
-
userOp: operation.userOp
|
|
613
|
+
userOp: operation.userOp,
|
|
585
614
|
});
|
|
586
615
|
}
|
|
587
616
|
if (!operation.opId) {
|
|
588
|
-
throw new errors_1.InternalFailureError(errors_1.ErrorCode.ServerFailure,
|
|
617
|
+
throw new errors_1.InternalFailureError(errors_1.ErrorCode.ServerFailure, 'Operation id is required', operation, 'Make sure you are scheduling a valid operation', 'https://docs.fun.xyz/');
|
|
589
618
|
}
|
|
590
619
|
return operation.opId;
|
|
591
620
|
}
|
|
@@ -610,7 +639,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
610
639
|
* @returns {Promise<Operation>} The prepared rejection operation.
|
|
611
640
|
*/
|
|
612
641
|
async createRejectOperation(auth, groupId, operation, rejectionMessage, txOptions = globalThis.globalEnvOption) {
|
|
613
|
-
const rejectOperation = await this.transfer(auth, groupId, { to: await this.getAddress(), amount: 0, token:
|
|
642
|
+
const rejectOperation = await this.transfer(auth, groupId, { to: await this.getAddress(), amount: 0, token: 'eth' }, {
|
|
643
|
+
...txOptions,
|
|
644
|
+
skipDBAction: true,
|
|
645
|
+
nonce: BigInt(operation.userOp.nonce),
|
|
646
|
+
});
|
|
614
647
|
if (rejectionMessage)
|
|
615
648
|
rejectOperation.message = rejectionMessage;
|
|
616
649
|
rejectOperation.relatedOpIds = [operation.opId];
|
|
@@ -633,7 +666,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
633
666
|
const res = await chain.estimateOpGas(operation.userOp);
|
|
634
667
|
operation.userOp = {
|
|
635
668
|
...operation.userOp,
|
|
636
|
-
...res
|
|
669
|
+
...res,
|
|
637
670
|
};
|
|
638
671
|
const { maxFeePerGas, maxPriorityFeePerGas } = await chain.getFeeData();
|
|
639
672
|
operation.userOp.maxFeePerGas = maxFeePerGas;
|
|
@@ -642,15 +675,15 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
642
675
|
}
|
|
643
676
|
async getThisInitCode(chain) {
|
|
644
677
|
const owners = Array.from(this.userInfo.keys());
|
|
645
|
-
const entryPointAddress = await chain.getAddress(
|
|
646
|
-
const factoryAddress = await chain.getAddress(
|
|
647
|
-
const rbac = await chain.getAddress(
|
|
648
|
-
const userAuth = await chain.getAddress(
|
|
678
|
+
const entryPointAddress = await chain.getAddress('entryPointAddress');
|
|
679
|
+
const factoryAddress = await chain.getAddress('factoryAddress');
|
|
680
|
+
const rbac = await chain.getAddress('rbacAddress');
|
|
681
|
+
const userAuth = await chain.getAddress('userAuthAddress');
|
|
649
682
|
const loginData = {
|
|
650
|
-
salt: this.walletUniqueId
|
|
683
|
+
salt: this.walletUniqueId,
|
|
651
684
|
};
|
|
652
685
|
const rbacInitData = (0, data_1.toBytes32Arr)(owners);
|
|
653
|
-
let userAuthInitData =
|
|
686
|
+
let userAuthInitData = '0x';
|
|
654
687
|
const groupUsers = Array.from(this.userInfo.values()).filter((user) => user.groupInfo !== null && user.groupInfo !== undefined);
|
|
655
688
|
if (groupUsers.length > 0) {
|
|
656
689
|
userAuthInitData = (0, data_1.encodeUserAuthInitData)(groupUsers);
|
|
@@ -659,28 +692,28 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
659
692
|
entryPointAddress,
|
|
660
693
|
factoryAddress,
|
|
661
694
|
implementationAddress: constants_1.AddressZero,
|
|
662
|
-
loginData
|
|
695
|
+
loginData,
|
|
663
696
|
verificationAddresses: [rbac, userAuth],
|
|
664
|
-
verificationData: [rbacInitData, userAuthInitData]
|
|
697
|
+
verificationData: [rbacInitData, userAuthInitData],
|
|
665
698
|
};
|
|
666
699
|
return this.getInitCode(initCodeParams);
|
|
667
700
|
}
|
|
668
701
|
getInitCode(input) {
|
|
669
702
|
const encodedVerificationInitdata = (0, viem_1.encodeAbiParameters)([
|
|
670
703
|
{
|
|
671
|
-
type:
|
|
672
|
-
name:
|
|
704
|
+
type: 'address[]',
|
|
705
|
+
name: 'verificationAddresses',
|
|
673
706
|
},
|
|
674
707
|
{
|
|
675
|
-
type:
|
|
676
|
-
name:
|
|
677
|
-
}
|
|
708
|
+
type: 'bytes[]',
|
|
709
|
+
name: 'verificationData',
|
|
710
|
+
},
|
|
678
711
|
], [input.verificationAddresses, input.verificationData]);
|
|
679
|
-
const initializerCallData = common_1.WALLET_CONTRACT_INTERFACE.encodeData(
|
|
680
|
-
|
|
681
|
-
|
|
712
|
+
const initializerCallData = common_1.WALLET_CONTRACT_INTERFACE.encodeData('initialize', [input.entryPointAddress, encodedVerificationInitdata]);
|
|
713
|
+
const data = constants_1.FACTORY_CONTRACT_INTERFACE.encodeData('createAccount', [
|
|
714
|
+
initializerCallData,
|
|
715
|
+
(0, data_1.encodeLoginData)(input.loginData),
|
|
682
716
|
]);
|
|
683
|
-
const data = constants_1.FACTORY_CONTRACT_INTERFACE.encodeData("createAccount", [initializerCallData, (0, data_1.encodeLoginData)(input.loginData)]);
|
|
684
717
|
return (0, viem_1.concat)([input.factoryAddress, data]);
|
|
685
718
|
}
|
|
686
719
|
/**
|
|
@@ -694,18 +727,21 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
694
727
|
params.value = 0n;
|
|
695
728
|
}
|
|
696
729
|
if (options.fee) {
|
|
697
|
-
if (!options.fee.token &&
|
|
730
|
+
if (!options.fee.token &&
|
|
731
|
+
options.gasSponsor &&
|
|
732
|
+
options.gasSponsor.token) {
|
|
698
733
|
options.fee.token = options.gasSponsor.token;
|
|
699
734
|
}
|
|
700
735
|
if (!options.fee.token) {
|
|
701
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter,
|
|
736
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter, 'EnvOption.fee.token or EnvOption.gasSponsor.token is required', { options }, 'Provide EnvOption.fee.token or EnvOption.gasSponsor.token when calling wallet.createOperation', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
702
737
|
}
|
|
703
738
|
if (!options.fee.recipient) {
|
|
704
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter,
|
|
739
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter, 'EnvOption.fee.recipient is required', { options }, 'Provide EnvOption.fee.recipient when calling wallet.createOperation', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
705
740
|
}
|
|
706
|
-
const
|
|
741
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
742
|
+
const token = new data_1.Token(options.fee.token, chain);
|
|
707
743
|
if (options.fee.gasPercent && !token.isNative) {
|
|
708
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameterCombination,
|
|
744
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.InvalidParameterCombination, 'GasPercent is only valid for native tokens', { options }, 'Use native token as the fee token if you want to charge fee based on percentage', 'https://docs.fun.xyz/how-to-guides/configure-environment/set-developer-fee');
|
|
709
745
|
}
|
|
710
746
|
if (token.isNative) {
|
|
711
747
|
options.fee.token = constants_1.AddressZero;
|
|
@@ -718,24 +754,32 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
718
754
|
}
|
|
719
755
|
else if (options.fee.gasPercent) {
|
|
720
756
|
const feedata = [options.fee.token, options.fee.recipient, 1];
|
|
721
|
-
const estimateGasCalldata = common_1.WALLET_CONTRACT_INTERFACE.encodeData(
|
|
722
|
-
params.to,
|
|
723
|
-
params.value,
|
|
724
|
-
params.data,
|
|
725
|
-
feedata
|
|
726
|
-
]);
|
|
757
|
+
const estimateGasCalldata = common_1.WALLET_CONTRACT_INTERFACE.encodeData('execFromEntryPointWithFee', [params.to, params.value, params.data, feedata]);
|
|
727
758
|
const operation = await this.createOperation(auth, userId, { to: params.to, value: params.value, data: estimateGasCalldata }, { ...options, fee: undefined });
|
|
728
759
|
const gasUsed = await operation.getMaxTxCost();
|
|
729
760
|
options.fee.amount = Math.ceil((Number(gasUsed) * options.fee.gasPercent) / 100);
|
|
730
761
|
}
|
|
731
762
|
else {
|
|
732
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter,
|
|
733
|
-
}
|
|
734
|
-
const feedata = [
|
|
735
|
-
|
|
763
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter, 'EnvOption.fee.amount or EnvOption.fee.gasPercent is required', { options }, 'Provide either EnvOption.fee.amount or EnvOption.fee.gasPercent when calling wallet.createOperation', 'https://docs.fun.xyz/how-to-guides/configure-environment/set-developer-fee');
|
|
764
|
+
}
|
|
765
|
+
const feedata = [
|
|
766
|
+
options.fee.token,
|
|
767
|
+
options.fee.recipient,
|
|
768
|
+
options.fee.amount,
|
|
769
|
+
];
|
|
770
|
+
return common_1.WALLET_CONTRACT_INTERFACE.encodeData('execFromEntryPointWithFee', [
|
|
771
|
+
params.to,
|
|
772
|
+
params.value,
|
|
773
|
+
params.data,
|
|
774
|
+
feedata,
|
|
775
|
+
]);
|
|
736
776
|
}
|
|
737
777
|
else {
|
|
738
|
-
return common_1.WALLET_CONTRACT_INTERFACE.encodeData(
|
|
778
|
+
return common_1.WALLET_CONTRACT_INTERFACE.encodeData('execFromEntryPoint', [
|
|
779
|
+
params.to,
|
|
780
|
+
params.value,
|
|
781
|
+
params.data,
|
|
782
|
+
]);
|
|
739
783
|
}
|
|
740
784
|
}
|
|
741
785
|
}
|