@funkit/core 2.0.1 → 2.1.1
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/index.js +11 -27
- package/dist/index.js.map +1 -1
- package/dist/src/abis/ApproveAndExec.json +45 -9
- package/dist/src/abis/ApproveAndSwap.json +141 -1
- package/dist/src/abis/CheckoutPaymaster.json +3358 -1
- package/dist/src/abis/EntryPoint.json +590 -113
- package/dist/src/abis/EstimationPaymaster.json +134 -24
- package/dist/src/abis/FeePercentOracle.json +94 -18
- package/dist/src/abis/FunWallet.json +280 -56
- package/dist/src/abis/FunWalletFactory.json +112 -21
- package/dist/src/abis/GaslessPaymaster.json +279 -50
- package/dist/src/abis/RoleBasedAccessControl.json +2 -1
- package/dist/src/abis/TestNFT.json +71 -15
- package/dist/src/abis/TokenPriceOracle.json +17 -4
- package/dist/src/abis/UserAuthentication.json +147 -32
- package/dist/src/actions/AccessControl.js +39 -48
- package/dist/src/actions/AccessControl.js.map +1 -1
- package/dist/src/actions/BatchActions.js +3 -7
- package/dist/src/actions/BatchActions.js.map +1 -1
- package/dist/src/actions/Bridge.js +16 -20
- package/dist/src/actions/Bridge.js.map +1 -1
- package/dist/src/actions/FirstClassActions.js +74 -77
- package/dist/src/actions/FirstClassActions.js.map +1 -1
- package/dist/src/actions/Group.js +14 -20
- package/dist/src/actions/Group.js.map +1 -1
- package/dist/src/actions/LimitOrder.js +18 -22
- package/dist/src/actions/LimitOrder.js.map +1 -1
- package/dist/src/actions/Stake.js +40 -43
- package/dist/src/actions/Stake.js.map +1 -1
- package/dist/src/actions/Swap.js +40 -46
- package/dist/src/actions/Swap.js.map +1 -1
- package/dist/src/actions/Token.js +41 -53
- package/dist/src/actions/Token.js.map +1 -1
- package/dist/src/actions/index.js +7 -23
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/actions/types.js +4 -7
- package/dist/src/actions/types.js.map +1 -1
- package/dist/src/apis/AccessControlApis.js +10 -16
- package/dist/src/apis/AccessControlApis.js.map +1 -1
- package/dist/src/apis/BridgeApis.js +14 -20
- package/dist/src/apis/BridgeApis.js.map +1 -1
- package/dist/src/apis/ContractApis.js +4 -7
- package/dist/src/apis/ContractApis.js.map +1 -1
- package/dist/src/apis/GroupApis.js +6 -10
- package/dist/src/apis/GroupApis.js.map +1 -1
- package/dist/src/apis/InfoApis.js +16 -23
- package/dist/src/apis/InfoApis.js.map +1 -1
- package/dist/src/apis/ListenerApis.js +9 -13
- package/dist/src/apis/ListenerApis.js.map +1 -1
- package/dist/src/apis/NFTApis.js +6 -10
- package/dist/src/apis/NFTApis.js.map +1 -1
- package/dist/src/apis/OperationApis.js +26 -40
- package/dist/src/apis/OperationApis.js.map +1 -1
- package/dist/src/apis/PaymasterApis.js +4 -7
- package/dist/src/apis/PaymasterApis.js.map +1 -1
- package/dist/src/apis/SwapApis.js +8 -13
- package/dist/src/apis/SwapApis.js.map +1 -1
- package/dist/src/apis/UserApis.js +20 -29
- package/dist/src/apis/UserApis.js.map +1 -1
- package/dist/src/apis/index.js +8 -24
- package/dist/src/apis/index.js.map +1 -1
- package/dist/src/apis/types.js +1 -2
- package/dist/src/auth/Auth.js +60 -76
- package/dist/src/auth/Auth.js.map +1 -1
- package/dist/src/auth/SessionKeyAuth.js +30 -33
- package/dist/src/auth/SessionKeyAuth.js.map +1 -1
- package/dist/src/auth/index.js +2 -18
- package/dist/src/auth/index.js.map +1 -1
- package/dist/src/auth/types.js +1 -2
- package/dist/src/common/constants.d.ts +141 -3
- package/dist/src/common/constants.js +211 -191
- package/dist/src/common/constants.js.map +1 -1
- package/dist/src/common/index.js +2 -18
- package/dist/src/common/index.js.map +1 -1
- package/dist/src/common/types.js +1 -2
- package/dist/src/config/Config.js +8 -13
- package/dist/src/config/Config.js.map +1 -1
- package/dist/src/config/index.js +2 -18
- package/dist/src/config/index.js.map +1 -1
- package/dist/src/config/types.js +1 -2
- package/dist/src/data/Chain.js +35 -33
- package/dist/src/data/Chain.js.map +1 -1
- package/dist/src/data/NFT.js +28 -31
- package/dist/src/data/NFT.js.map +1 -1
- package/dist/src/data/Operation.js +28 -11
- package/dist/src/data/Operation.js.map +1 -1
- package/dist/src/data/SolidityData.js +23 -30
- package/dist/src/data/SolidityData.js.map +1 -1
- package/dist/src/data/Token.js +21 -23
- package/dist/src/data/Token.js.map +1 -1
- package/dist/src/data/index.js +6 -22
- package/dist/src/data/index.js.map +1 -1
- package/dist/src/data/types.js +6 -9
- package/dist/src/data/types.js.map +1 -1
- package/dist/src/errors/BaseError.js +6 -5
- package/dist/src/errors/BaseError.js.map +1 -1
- package/dist/src/errors/ClientError.js +21 -34
- package/dist/src/errors/ClientError.js.map +1 -1
- package/dist/src/errors/ServerError.js +6 -11
- package/dist/src/errors/ServerError.js.map +1 -1
- package/dist/src/errors/index.js +4 -20
- package/dist/src/errors/index.js.map +1 -1
- package/dist/src/errors/types.js +6 -9
- package/dist/src/errors/types.js.map +1 -1
- package/dist/src/sponsors/CheckoutSponsor.js +10 -14
- package/dist/src/sponsors/CheckoutSponsor.js.map +1 -1
- package/dist/src/sponsors/GaslessSponsor.js +23 -27
- package/dist/src/sponsors/GaslessSponsor.js.map +1 -1
- package/dist/src/sponsors/Sponsor.js +10 -8
- package/dist/src/sponsors/Sponsor.js.map +1 -1
- package/dist/src/sponsors/TokenSponsor.js +79 -82
- package/dist/src/sponsors/TokenSponsor.js.map +1 -1
- package/dist/src/sponsors/index.js +4 -20
- package/dist/src/sponsors/index.js.map +1 -1
- package/dist/src/sponsors/types.js +2 -5
- package/dist/src/sponsors/types.js.map +1 -1
- package/dist/src/utils/ApiUtils.js +30 -38
- package/dist/src/utils/ApiUtils.js.map +1 -1
- package/dist/src/utils/AuthUtils.js +9 -14
- package/dist/src/utils/AuthUtils.js.map +1 -1
- package/dist/src/utils/ChainUtils.js +38 -49
- package/dist/src/utils/ChainUtils.js.map +1 -1
- package/dist/src/utils/CheckoutUtils.js +13 -18
- package/dist/src/utils/CheckoutUtils.js.map +1 -1
- package/dist/src/utils/GroupUtils.js +6 -9
- package/dist/src/utils/GroupUtils.js.map +1 -1
- package/dist/src/utils/MerkleUtils.js +34 -47
- package/dist/src/utils/MerkleUtils.js.map +1 -1
- package/dist/src/utils/PaymasterUtils.js +5 -9
- package/dist/src/utils/PaymasterUtils.js.map +1 -1
- package/dist/src/utils/SwapUtils.js +44 -43
- package/dist/src/utils/SwapUtils.js.map +1 -1
- package/dist/src/utils/TypeUtils.js +5 -9
- package/dist/src/utils/TypeUtils.js.map +1 -1
- package/dist/src/utils/UserOpUtils.js +20 -29
- package/dist/src/utils/UserOpUtils.js.map +1 -1
- package/dist/src/utils/ViemUtils.js +6 -12
- package/dist/src/utils/ViemUtils.js.map +1 -1
- package/dist/src/utils/WalletUtils.js +28 -42
- package/dist/src/utils/WalletUtils.js.map +1 -1
- package/dist/src/utils/index.js +8 -24
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/viem/ContractInterface.js +14 -18
- package/dist/src/viem/ContractInterface.js.map +1 -1
- package/dist/src/viem/Converter.js +15 -20
- package/dist/src/viem/Converter.js.map +1 -1
- package/dist/src/viem/index.js +2 -18
- package/dist/src/viem/index.js.map +1 -1
- package/dist/src/wallet/FunWallet.js +141 -142
- package/dist/src/wallet/FunWallet.js.map +1 -1
- package/dist/src/wallet/index.js +2 -18
- package/dist/src/wallet/index.js.map +1 -1
- package/dist/src/wallet/types.js +1 -2
- package/package.json +4 -2
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { getAllWalletNFTs, getAllWalletNFTsByChainId, getAllWalletTokens, getAllWalletTokensByChainId, getMoonpayOffRampUrl, getMoonpayOnRampSupportedCurrencies, getMoonpayOnRampUrl, getWalletLidoWithdrawalsByChainId, } from '@funkit/api-base';
|
|
2
|
+
import { concat, createPublicClient, encodeAbiParameters, http, isAddress, isHex, keccak256, pad, toBytes, } from 'viem';
|
|
3
|
+
import { FirstClassActions } from '../actions/FirstClassActions';
|
|
4
|
+
import { checkWalletAccessInitialization, initializeWalletAccess, } from '../apis/AccessControlApis';
|
|
5
|
+
import { getGroups } from '../apis/GroupApis';
|
|
6
|
+
import { createOp, deleteOp, executeOp, getFullReceipt, getOps, getOpsOfWallet, scheduleOp, signOp, } from '../apis/OperationApis';
|
|
7
|
+
import { addTransaction } from '../apis/PaymasterApis';
|
|
8
|
+
import { addUserToWallet } from '../apis/UserApis';
|
|
9
|
+
import { ENTRYPOINT_CONTRACT_INTERFACE, WALLET_CONTRACT_INTERFACE, } from '../common';
|
|
10
|
+
import { AddressZero, FACTORY_CONTRACT_INTERFACE } from '../common/constants';
|
|
11
|
+
import { parseOptions } from '../config';
|
|
12
|
+
import { AuthType, Chain, encodeLoginData, encodeUserAuthInitData, Operation, OperationStatus, OperationType, toBytes32Arr, Token, } from '../data';
|
|
13
|
+
import { ErrorCode, InternalFailureError, InvalidParameterError, } from '../errors';
|
|
14
|
+
import { CheckoutSponsor, GaslessSponsor, TokenSponsor } from '../sponsors';
|
|
15
|
+
import { generateRandomNonceKey, getWalletAddress, isGroupOperation, isSignatureMissing, isWalletInitOp, } from '../utils';
|
|
16
|
+
import { getPaymasterType } from '../utils/PaymasterUtils';
|
|
17
|
+
import { isBytes32 } from '../utils/TypeUtils';
|
|
18
|
+
export class FunWallet extends FirstClassActions {
|
|
19
|
+
walletUniqueId;
|
|
20
|
+
userInfo;
|
|
21
|
+
address;
|
|
22
22
|
/**
|
|
23
23
|
* Creates FunWallet object
|
|
24
24
|
* @constructor
|
|
@@ -28,29 +28,29 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
28
28
|
const chain = globalThis.globalEnvOption.chain;
|
|
29
29
|
super(chain);
|
|
30
30
|
if (typeof params === 'string') {
|
|
31
|
-
if (
|
|
31
|
+
if (isAddress(params)) {
|
|
32
32
|
this.address = params;
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
throw new
|
|
35
|
+
throw new InvalidParameterError(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');
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
const { users, uniqueId } = params;
|
|
40
|
-
if (!uniqueId || !
|
|
41
|
-
throw new
|
|
40
|
+
if (!uniqueId || !isBytes32(uniqueId) || !users || users.length <= 0) {
|
|
41
|
+
throw new InvalidParameterError(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');
|
|
42
42
|
}
|
|
43
43
|
this.userInfo = new Map(users?.map((user) => {
|
|
44
|
-
if (!user.userId || !
|
|
45
|
-
throw new
|
|
44
|
+
if (!user.userId || !isHex(user.userId)) {
|
|
45
|
+
throw new InvalidParameterError(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');
|
|
46
46
|
}
|
|
47
47
|
if (user.groupInfo &&
|
|
48
48
|
(!Number.isInteger(user.groupInfo.threshold) ||
|
|
49
49
|
!Array.isArray(user.groupInfo.memberIds) ||
|
|
50
|
-
!user.groupInfo.memberIds.every((memberId) =>
|
|
51
|
-
throw new
|
|
50
|
+
!user.groupInfo.memberIds.every((memberId) => isHex(memberId)))) {
|
|
51
|
+
throw new InvalidParameterError(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');
|
|
52
52
|
}
|
|
53
|
-
return [
|
|
53
|
+
return [pad(user.userId, { size: 32 }), user];
|
|
54
54
|
}));
|
|
55
55
|
this.walletUniqueId = uniqueId;
|
|
56
56
|
}
|
|
@@ -63,7 +63,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
63
63
|
async getAddress(txOptions = globalThis.globalEnvOption) {
|
|
64
64
|
if (!this.address) {
|
|
65
65
|
const chainIdentifier = txOptions.chain;
|
|
66
|
-
this.address = await
|
|
66
|
+
this.address = await getWalletAddress(await Chain.getChain({ chainIdentifier: chainIdentifier ?? 137 }), this.walletUniqueId);
|
|
67
67
|
}
|
|
68
68
|
return this.address;
|
|
69
69
|
}
|
|
@@ -76,7 +76,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
76
76
|
static async getAddress(uniqueId, apiKey) {
|
|
77
77
|
;
|
|
78
78
|
globalThis.globalEnvOption.apiKey = apiKey;
|
|
79
|
-
return await
|
|
79
|
+
return await getWalletAddress(await Chain.getChain({ chainIdentifier: 137 }), keccak256(toBytes(uniqueId)));
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* Retrieves the wallet address associated with the provided unique ID in an offline environment.
|
|
@@ -86,10 +86,10 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
86
86
|
* @returns {Promise<Address>} The wallet address.
|
|
87
87
|
*/
|
|
88
88
|
static async getAddressOffline(uniqueId, rpcUrl, factoryAddress) {
|
|
89
|
-
const client = await
|
|
90
|
-
transport:
|
|
89
|
+
const client = await createPublicClient({
|
|
90
|
+
transport: http(rpcUrl),
|
|
91
91
|
});
|
|
92
|
-
return await
|
|
92
|
+
return await FACTORY_CONTRACT_INTERFACE.readFromChain(factoryAddress, 'getAddress', [keccak256(toBytes(uniqueId))], client);
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Get all tokens for a specific chain
|
|
@@ -100,7 +100,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
100
100
|
async getTokens(chainIdInput, onlyVerifiedTokens = false) {
|
|
101
101
|
let chainId;
|
|
102
102
|
if (!chainIdInput) {
|
|
103
|
-
const chain = await
|
|
103
|
+
const chain = await Chain.getChain({
|
|
104
104
|
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
105
105
|
});
|
|
106
106
|
chainId = await chain.getChainId();
|
|
@@ -110,12 +110,12 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
110
110
|
}
|
|
111
111
|
const walletAddress = await this.getAddress();
|
|
112
112
|
return chainId === 'ALL'
|
|
113
|
-
? await
|
|
113
|
+
? await getAllWalletTokens({
|
|
114
114
|
walletAddress,
|
|
115
115
|
onlyVerifiedTokens,
|
|
116
116
|
apiKey: globalThis.globalEnvOption.apiKey,
|
|
117
117
|
})
|
|
118
|
-
: await
|
|
118
|
+
: await getAllWalletTokensByChainId({
|
|
119
119
|
chainId,
|
|
120
120
|
walletAddress,
|
|
121
121
|
onlyVerifiedTokens,
|
|
@@ -130,7 +130,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
130
130
|
async getNFTs(chainIdInput) {
|
|
131
131
|
let chainId;
|
|
132
132
|
if (!chainIdInput) {
|
|
133
|
-
const chain = await
|
|
133
|
+
const chain = await Chain.getChain({
|
|
134
134
|
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
135
135
|
});
|
|
136
136
|
chainId = await chain.getChainId();
|
|
@@ -140,11 +140,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
140
140
|
}
|
|
141
141
|
const walletAddress = await this.getAddress();
|
|
142
142
|
return chainId === 'ALL'
|
|
143
|
-
? await
|
|
143
|
+
? await getAllWalletNFTs({
|
|
144
144
|
walletAddress,
|
|
145
145
|
apiKey: globalThis.globalEnvOption.apiKey,
|
|
146
146
|
})
|
|
147
|
-
: await
|
|
147
|
+
: await getAllWalletNFTsByChainId({
|
|
148
148
|
chainId,
|
|
149
149
|
walletAddress,
|
|
150
150
|
apiKey: globalThis.globalEnvOption.apiKey,
|
|
@@ -152,7 +152,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
152
152
|
}
|
|
153
153
|
async getLidoWithdrawals() {
|
|
154
154
|
const walletAddress = await this.getAddress();
|
|
155
|
-
return await
|
|
155
|
+
return await getWalletLidoWithdrawalsByChainId({
|
|
156
156
|
chainId: '1',
|
|
157
157
|
walletAddress,
|
|
158
158
|
apiKey: globalThis.globalEnvOption.apiKey,
|
|
@@ -168,7 +168,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
168
168
|
async getAssets(chainIdInput, onlyVerifiedTokens = false, checkStatus = false) {
|
|
169
169
|
let chainId;
|
|
170
170
|
if (!chainIdInput) {
|
|
171
|
-
const chain = await
|
|
171
|
+
const chain = await Chain.getChain({
|
|
172
172
|
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
173
173
|
});
|
|
174
174
|
chainId = await chain.getChainId();
|
|
@@ -188,13 +188,13 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
188
188
|
* @param {EnvOption} txOptions - Transaction environment options (default: global environment options).
|
|
189
189
|
* @returns {Promise<bigint>} The nonce value.
|
|
190
190
|
*/
|
|
191
|
-
async getNonce(sender, key =
|
|
192
|
-
const chain = await
|
|
191
|
+
async getNonce(sender, key = generateRandomNonceKey(), txOptions = globalThis.globalEnvOption) {
|
|
192
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
193
193
|
const entryPointAddress = await chain.getAddress('entryPointAddress');
|
|
194
194
|
let nonce = undefined;
|
|
195
195
|
let retryCount = 3;
|
|
196
196
|
while ((nonce === undefined || nonce === null) && retryCount > 0) {
|
|
197
|
-
nonce = await
|
|
197
|
+
nonce = await ENTRYPOINT_CONTRACT_INTERFACE.readFromChain(entryPointAddress, 'getNonce', [sender, key], chain);
|
|
198
198
|
retryCount--;
|
|
199
199
|
}
|
|
200
200
|
if (nonce !== undefined && nonce !== null) {
|
|
@@ -210,9 +210,9 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
210
210
|
* @param {EnvOption} txOptions - Transaction environment options (default: global environment options).
|
|
211
211
|
* @returns {Promise<Operation[]>} A list of operations.
|
|
212
212
|
*/
|
|
213
|
-
async getOperations(status =
|
|
214
|
-
const chain = await
|
|
215
|
-
return await
|
|
213
|
+
async getOperations(status = OperationStatus.ALL, txOptions = globalThis.globalEnvOption) {
|
|
214
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
215
|
+
return await getOpsOfWallet(await this.getAddress(txOptions), await chain.getChainId(), status);
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* Retrieves a specific operation by its ID.
|
|
@@ -221,8 +221,8 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
221
221
|
* @returns {Promise<Operation>} The requested operation.
|
|
222
222
|
*/
|
|
223
223
|
async getOperation(opId, txOptions = globalThis.globalEnvOption) {
|
|
224
|
-
const chain = await
|
|
225
|
-
return (await
|
|
224
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
225
|
+
return (await getOps([opId], await chain.getChainId()))[0];
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
228
|
* Retrieves a list of users associated with the wallet and their potential corresponding group information.
|
|
@@ -231,7 +231,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
231
231
|
* @returns {Promise<User[]>} A list of users with their group information.
|
|
232
232
|
*/
|
|
233
233
|
async getUsers(auth, txOptions = globalThis.globalEnvOption) {
|
|
234
|
-
const chain = await
|
|
234
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
235
235
|
const storedUserIds = await auth.getUserIds(await this.getAddress(txOptions), await chain.getChainId());
|
|
236
236
|
const userIds = new Set([...storedUserIds]);
|
|
237
237
|
if (this.userInfo) {
|
|
@@ -242,15 +242,15 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
242
242
|
const users = [];
|
|
243
243
|
const groupIds = [];
|
|
244
244
|
for (const userId of userIds) {
|
|
245
|
-
if (
|
|
246
|
-
users.push({ userId:
|
|
245
|
+
if (pad(userId, { size: 32 }).toLowerCase() === (await auth.getUserId())) {
|
|
246
|
+
users.push({ userId: pad(userId, { size: 32 }) });
|
|
247
247
|
}
|
|
248
248
|
else {
|
|
249
|
-
groupIds.push(
|
|
249
|
+
groupIds.push(pad(userId, { size: 32 }));
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
if (groupIds && groupIds.length > 0) {
|
|
253
|
-
const groups = await
|
|
253
|
+
const groups = await getGroups(groupIds, await chain.getChainId());
|
|
254
254
|
groups.forEach((group) => {
|
|
255
255
|
users.push({
|
|
256
256
|
userId: group.groupId,
|
|
@@ -269,7 +269,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
269
269
|
* @returns {Promise<boolean>} `true` if the address is a contract, `false` otherwise.
|
|
270
270
|
*/
|
|
271
271
|
async getDeploymentStatus(txOptions = globalThis.globalEnvOption) {
|
|
272
|
-
const chain = await
|
|
272
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
273
273
|
return await chain.addressIsContract(await this.getAddress(txOptions));
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
@@ -294,15 +294,15 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
294
294
|
* @returns A Promise that resolves when the wallet is saved to the authentication system.
|
|
295
295
|
*/
|
|
296
296
|
async saveWalletToAuth(auth, txOptions = globalThis.globalEnvOption) {
|
|
297
|
-
const chain = await
|
|
297
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
298
298
|
const walletAddr = await this.getAddress(txOptions);
|
|
299
299
|
const userId = await auth.getUserId();
|
|
300
300
|
const users = await auth.getUserIds(walletAddr, await chain.getChainId());
|
|
301
301
|
if (!users.includes(userId)) {
|
|
302
|
-
if ((await
|
|
303
|
-
await
|
|
302
|
+
if ((await checkWalletAccessInitialization(walletAddr)) === false) {
|
|
303
|
+
await initializeWalletAccess(walletAddr, await auth.getAddress());
|
|
304
304
|
}
|
|
305
|
-
await
|
|
305
|
+
await addUserToWallet(await auth.getAddress(), await chain.getChainId(), walletAddr, [userId], this.walletUniqueId);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
/**
|
|
@@ -312,7 +312,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
312
312
|
* @returns {Promise<string>} The on-ramp URL.
|
|
313
313
|
*/
|
|
314
314
|
async onRamp(address, currencyCode) {
|
|
315
|
-
return await
|
|
315
|
+
return await getMoonpayOnRampUrl({
|
|
316
316
|
apiKey: globalThis.globalEnvOption.apiKey,
|
|
317
317
|
walletAddr: address ? address : await this.getAddress(),
|
|
318
318
|
currencyCode: currencyCode ? currencyCode : undefined,
|
|
@@ -324,7 +324,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
324
324
|
* @returns {Promise<string>} The off-ramp URL.
|
|
325
325
|
*/
|
|
326
326
|
async offRamp(address) {
|
|
327
|
-
return await
|
|
327
|
+
return await getMoonpayOffRampUrl({
|
|
328
328
|
apiKey: globalThis.globalEnvOption.apiKey,
|
|
329
329
|
walletAddr: address ? address : await this.getAddress(),
|
|
330
330
|
});
|
|
@@ -334,7 +334,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
334
334
|
* @returns {Promise<MoonpayCurrency[]>} The supported currencies.
|
|
335
335
|
*/
|
|
336
336
|
async getSupportedCurrencies() {
|
|
337
|
-
return await
|
|
337
|
+
return await getMoonpayOnRampSupportedCurrencies({
|
|
338
338
|
apiKey: globalThis.globalEnvOption.apiKey,
|
|
339
339
|
});
|
|
340
340
|
}
|
|
@@ -348,10 +348,10 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
348
348
|
*/
|
|
349
349
|
async createOperation(auth, userId, transactionParams, txOptions = globalThis.globalEnvOption) {
|
|
350
350
|
if (!userId || userId === '') {
|
|
351
|
-
throw new
|
|
351
|
+
throw new InvalidParameterError(ErrorCode.MissingParameter, 'userId is required', { userId }, 'Provide userId when createOperation', 'https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions');
|
|
352
352
|
}
|
|
353
|
-
userId =
|
|
354
|
-
const chain = await
|
|
353
|
+
userId = pad(userId, { size: 32 }).toLowerCase();
|
|
354
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
355
355
|
const sender = await this.getAddress(txOptions);
|
|
356
356
|
const initCode = (await chain.addressIsContract(sender))
|
|
357
357
|
? '0x'
|
|
@@ -388,21 +388,21 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
388
388
|
partialOp.verificationGasLimit = BigInt(10e5);
|
|
389
389
|
}
|
|
390
390
|
const isGroupOp = (await auth.getUserId()) !== userId;
|
|
391
|
-
const operation = new
|
|
391
|
+
const operation = new Operation(partialOp, {
|
|
392
392
|
chainId: await chain.getChainId(),
|
|
393
393
|
opType: isGroupOp
|
|
394
|
-
?
|
|
395
|
-
:
|
|
396
|
-
authType: isGroupOp ?
|
|
394
|
+
? OperationType.GROUP_OPERATION
|
|
395
|
+
: OperationType.SINGLE_OPERATION,
|
|
396
|
+
authType: isGroupOp ? AuthType.MULTI_SIG : AuthType.ECDSA,
|
|
397
397
|
walletAddr: await this.getAddress(txOptions),
|
|
398
398
|
proposer: await auth.getAddress(),
|
|
399
399
|
});
|
|
400
400
|
if (isGroupOp) {
|
|
401
|
-
operation.groupId =
|
|
401
|
+
operation.groupId = pad(userId, { size: 32 });
|
|
402
402
|
}
|
|
403
403
|
if (txOptions.gasSponsor && Object.keys(txOptions.gasSponsor).length > 0) {
|
|
404
404
|
if (txOptions.gasSponsor.token) {
|
|
405
|
-
const sponsor = new
|
|
405
|
+
const sponsor = new TokenSponsor(txOptions);
|
|
406
406
|
if (txOptions.gasSponsor.usePermit) {
|
|
407
407
|
paymasterAndData = (await sponsor.getPaymasterAndDataPermit(operation, await this.getAddress(txOptions), userId, auth)).toLowerCase();
|
|
408
408
|
}
|
|
@@ -411,11 +411,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
else if (txOptions.gasSponsor.useCheckoutSponsor) {
|
|
414
|
-
const sponsor = new
|
|
414
|
+
const sponsor = new CheckoutSponsor(txOptions);
|
|
415
415
|
paymasterAndData = (await sponsor.getPaymasterAndData(txOptions)).toLowerCase();
|
|
416
416
|
}
|
|
417
417
|
else {
|
|
418
|
-
const sponsor = new
|
|
418
|
+
const sponsor = new GaslessSponsor(txOptions);
|
|
419
419
|
paymasterAndData = (await sponsor.getPaymasterAndData(txOptions)).toLowerCase();
|
|
420
420
|
}
|
|
421
421
|
}
|
|
@@ -425,12 +425,12 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
425
425
|
estimatedOperation.userOp.initCode = '0x';
|
|
426
426
|
}
|
|
427
427
|
// sign the userOp directly here as we do not have the opId yet
|
|
428
|
-
estimatedOperation.userOp.signature = await auth.signOp(estimatedOperation, chain,
|
|
428
|
+
estimatedOperation.userOp.signature = await auth.signOp(estimatedOperation, chain, isGroupOperation(operation));
|
|
429
429
|
if (txOptions.skipDBAction !== true) {
|
|
430
|
-
const opId = await
|
|
430
|
+
const opId = await createOp(estimatedOperation);
|
|
431
431
|
estimatedOperation.opId = opId;
|
|
432
|
-
if (!(await
|
|
433
|
-
await
|
|
432
|
+
if (!(await checkWalletAccessInitialization(sender))) {
|
|
433
|
+
await initializeWalletAccess(sender, await auth.getAddress());
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
return estimatedOperation;
|
|
@@ -443,11 +443,11 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
443
443
|
* @returns {Promise<Operation>} The signed operation.
|
|
444
444
|
*/
|
|
445
445
|
async signOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
|
|
446
|
-
const chain = await
|
|
447
|
-
operation =
|
|
448
|
-
operation.userOp.signature = await auth.signOp(operation, chain,
|
|
449
|
-
if (
|
|
450
|
-
await
|
|
446
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
447
|
+
operation = Operation.convertTypeToObject(operation);
|
|
448
|
+
operation.userOp.signature = await auth.signOp(operation, chain, isGroupOperation(operation));
|
|
449
|
+
if (isGroupOperation(operation) && txOptions.skipDBAction !== true) {
|
|
450
|
+
await signOp(operation.opId, await chain.getChainId(), operation.userOp.signature, await auth.getAddress(), this.userInfo?.get(operation.groupId)?.groupInfo?.threshold);
|
|
451
451
|
}
|
|
452
452
|
return operation;
|
|
453
453
|
}
|
|
@@ -459,14 +459,14 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
459
459
|
* @returns {Promise<ExecutionReceipt>} The execution receipt of the operation.
|
|
460
460
|
*/
|
|
461
461
|
async executeOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
|
|
462
|
-
txOptions =
|
|
463
|
-
operation =
|
|
464
|
-
const chain = await
|
|
462
|
+
txOptions = parseOptions(txOptions);
|
|
463
|
+
operation = Operation.convertTypeToObject(operation);
|
|
464
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
465
465
|
const chainId = await chain.getChainId();
|
|
466
466
|
if (txOptions.skipDBAction !== true) {
|
|
467
467
|
// cache group info
|
|
468
|
-
if (
|
|
469
|
-
const groups = await
|
|
468
|
+
if (isGroupOperation(operation)) {
|
|
469
|
+
const groups = await getGroups([operation.groupId], chainId);
|
|
470
470
|
if (groups && groups.length > 0) {
|
|
471
471
|
// could be empty as a new wallet wants to create a group
|
|
472
472
|
this.userInfo?.set(operation.groupId, {
|
|
@@ -482,36 +482,36 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
482
482
|
const threshold = this.userInfo?.get(operation.groupId)?.groupInfo?.threshold ?? 1;
|
|
483
483
|
if (threshold <= 1) {
|
|
484
484
|
if (!operation.userOp.signature || operation.userOp.signature === '0x') {
|
|
485
|
-
operation.userOp.signature = await auth.signOp(operation, chain,
|
|
485
|
+
operation.userOp.signature = await auth.signOp(operation, chain, isGroupOperation(operation));
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
else {
|
|
489
489
|
if (txOptions.skipDBAction !== true) {
|
|
490
490
|
// check remote collected signature
|
|
491
|
-
const storedOps = await
|
|
491
|
+
const storedOps = await getOps([operation.opId], chainId);
|
|
492
492
|
let collectedSigCount;
|
|
493
|
-
if (
|
|
493
|
+
if (isSignatureMissing(await auth.getUserId(), storedOps[0]?.signatures)) {
|
|
494
494
|
collectedSigCount = storedOps[0]?.signatures?.length
|
|
495
495
|
? storedOps[0]?.signatures?.length + 1
|
|
496
496
|
: 1;
|
|
497
497
|
if (collectedSigCount >= threshold) {
|
|
498
|
-
operation.userOp.signature = await auth.signOp(operation, chain,
|
|
498
|
+
operation.userOp.signature = await auth.signOp(operation, chain, isGroupOperation(operation));
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
else {
|
|
502
502
|
collectedSigCount = storedOps[0]?.signatures?.length ?? 1;
|
|
503
503
|
}
|
|
504
504
|
if (collectedSigCount < threshold) {
|
|
505
|
-
throw new
|
|
505
|
+
throw new InvalidParameterError(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');
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
else {
|
|
509
|
-
throw new
|
|
509
|
+
throw new InvalidParameterError(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');
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
let receipt;
|
|
513
|
-
if (
|
|
514
|
-
receipt = await
|
|
513
|
+
if (isGroupOperation(operation)) {
|
|
514
|
+
receipt = await executeOp({
|
|
515
515
|
opId: operation.opId,
|
|
516
516
|
chainId,
|
|
517
517
|
executedBy: await auth.getAddress(),
|
|
@@ -521,7 +521,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
521
521
|
});
|
|
522
522
|
}
|
|
523
523
|
else {
|
|
524
|
-
receipt = await
|
|
524
|
+
receipt = await executeOp({
|
|
525
525
|
opId: operation.opId,
|
|
526
526
|
chainId,
|
|
527
527
|
executedBy: await auth.getAddress(),
|
|
@@ -530,12 +530,12 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
530
530
|
userOp: operation.userOp,
|
|
531
531
|
});
|
|
532
532
|
}
|
|
533
|
-
receipt = await
|
|
534
|
-
if (
|
|
535
|
-
await
|
|
533
|
+
receipt = await getFullReceipt(operation.opId, chainId, receipt.userOpHash);
|
|
534
|
+
if (isWalletInitOp(operation.userOp) && txOptions.skipDBAction !== true) {
|
|
535
|
+
await addUserToWallet(await auth.getAddress(), chainId, await this.getAddress(txOptions), Array.from(this.userInfo.keys()), this.walletUniqueId);
|
|
536
536
|
if (txOptions?.gasSponsor?.sponsorAddress) {
|
|
537
|
-
const paymasterType =
|
|
538
|
-
|
|
537
|
+
const paymasterType = getPaymasterType(txOptions);
|
|
538
|
+
addTransaction(await chain.getChainId(), Date.now(), receipt.txId, {
|
|
539
539
|
action: 'sponsor',
|
|
540
540
|
amount: -1, //Get amount from lazy processing
|
|
541
541
|
from: txOptions.gasSponsor.sponsorAddress,
|
|
@@ -555,14 +555,14 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
555
555
|
* @returns {Promise<Hex>} The ID of the scheduled operation.
|
|
556
556
|
*/
|
|
557
557
|
async scheduleOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
|
|
558
|
-
txOptions =
|
|
559
|
-
operation =
|
|
560
|
-
const chain = await
|
|
558
|
+
txOptions = parseOptions(txOptions);
|
|
559
|
+
operation = Operation.convertTypeToObject(operation);
|
|
560
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
561
561
|
const chainId = await chain.getChainId();
|
|
562
562
|
if (txOptions.skipDBAction !== true) {
|
|
563
563
|
// cache group info
|
|
564
|
-
if (
|
|
565
|
-
const groups = await
|
|
564
|
+
if (isGroupOperation(operation)) {
|
|
565
|
+
const groups = await getGroups([operation.groupId], chainId);
|
|
566
566
|
if (groups && groups.length > 0) {
|
|
567
567
|
// could be empty as a new wallet wants to create a group
|
|
568
568
|
this.userInfo?.set(operation.groupId, {
|
|
@@ -578,35 +578,35 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
578
578
|
const threshold = this.userInfo?.get(operation.groupId)?.groupInfo?.threshold ?? 1;
|
|
579
579
|
if (threshold <= 1) {
|
|
580
580
|
if (!operation.userOp.signature || operation.userOp.signature === '0x') {
|
|
581
|
-
operation.userOp.signature = await auth.signOp(operation, chain,
|
|
581
|
+
operation.userOp.signature = await auth.signOp(operation, chain, isGroupOperation(operation));
|
|
582
582
|
}
|
|
583
583
|
}
|
|
584
584
|
else {
|
|
585
585
|
if (txOptions.skipDBAction !== true) {
|
|
586
586
|
// check remote collected signature
|
|
587
|
-
const storedOps = await
|
|
587
|
+
const storedOps = await getOps([operation.opId], chainId);
|
|
588
588
|
let collectedSigCount;
|
|
589
|
-
if (
|
|
589
|
+
if (isSignatureMissing(await auth.getUserId(), storedOps[0]?.signatures)) {
|
|
590
590
|
collectedSigCount = storedOps[0]?.signatures?.length
|
|
591
591
|
? storedOps[0]?.signatures?.length + 1
|
|
592
592
|
: 1;
|
|
593
593
|
if (collectedSigCount >= threshold) {
|
|
594
|
-
operation.userOp.signature = await auth.signOp(operation, chain,
|
|
594
|
+
operation.userOp.signature = await auth.signOp(operation, chain, isGroupOperation(operation));
|
|
595
595
|
}
|
|
596
596
|
}
|
|
597
597
|
else {
|
|
598
598
|
collectedSigCount = storedOps[0]?.signatures?.length ?? 1;
|
|
599
599
|
}
|
|
600
600
|
if (collectedSigCount < threshold) {
|
|
601
|
-
throw new
|
|
601
|
+
throw new InvalidParameterError(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');
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
else {
|
|
605
|
-
throw new
|
|
605
|
+
throw new InvalidParameterError(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');
|
|
606
606
|
}
|
|
607
607
|
}
|
|
608
|
-
if (
|
|
609
|
-
await
|
|
608
|
+
if (isGroupOperation(operation)) {
|
|
609
|
+
await scheduleOp({
|
|
610
610
|
opId: operation.opId,
|
|
611
611
|
chainId,
|
|
612
612
|
scheduledBy: await auth.getAddress(),
|
|
@@ -616,7 +616,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
616
616
|
});
|
|
617
617
|
}
|
|
618
618
|
else {
|
|
619
|
-
await
|
|
619
|
+
await scheduleOp({
|
|
620
620
|
opId: operation.opId,
|
|
621
621
|
chainId,
|
|
622
622
|
scheduledBy: await auth.getAddress(),
|
|
@@ -626,7 +626,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
626
626
|
});
|
|
627
627
|
}
|
|
628
628
|
if (!operation.opId) {
|
|
629
|
-
throw new
|
|
629
|
+
throw new InternalFailureError(ErrorCode.ServerFailure, 'Operation id is required', operation, 'Make sure you are scheduling a valid operation', 'https://docs.fun.xyz/');
|
|
630
630
|
}
|
|
631
631
|
return operation.opId;
|
|
632
632
|
}
|
|
@@ -638,8 +638,8 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
638
638
|
* @returns {Promise<void>} A promise that resolves after the operation is removed.
|
|
639
639
|
*/
|
|
640
640
|
async removeOperation(_, operationId, txOptions = globalThis.globalEnvOption) {
|
|
641
|
-
const chain = await
|
|
642
|
-
await
|
|
641
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
642
|
+
await deleteOp(operationId, await chain.getChainId());
|
|
643
643
|
}
|
|
644
644
|
/**
|
|
645
645
|
* Creates and prepares a rejection operation for an existing operation.
|
|
@@ -659,8 +659,8 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
659
659
|
if (rejectionMessage)
|
|
660
660
|
rejectOperation.message = rejectionMessage;
|
|
661
661
|
rejectOperation.relatedOpIds = [operation.opId];
|
|
662
|
-
rejectOperation.opType =
|
|
663
|
-
rejectOperation.opId = (await
|
|
662
|
+
rejectOperation.opType = OperationType.REJECTION;
|
|
663
|
+
rejectOperation.opId = (await createOp(rejectOperation));
|
|
664
664
|
return rejectOperation;
|
|
665
665
|
}
|
|
666
666
|
/**
|
|
@@ -672,7 +672,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
672
672
|
* @returns {Promise<Operation>} The updated operation with gas estimation details.
|
|
673
673
|
*/
|
|
674
674
|
async estimateOperation(auth, userId, operation, txOptions = globalThis.globalEnvOption) {
|
|
675
|
-
const chain = await
|
|
675
|
+
const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
|
|
676
676
|
const estimateGasSignature = await auth.getEstimateGasSignature(userId, operation);
|
|
677
677
|
operation.userOp.signature = estimateGasSignature.toLowerCase();
|
|
678
678
|
const estimationPaymasterAddress = await chain.getAddress('estimationPaymasterAddress');
|
|
@@ -700,16 +700,16 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
700
700
|
const loginData = {
|
|
701
701
|
salt: this.walletUniqueId,
|
|
702
702
|
};
|
|
703
|
-
const rbacInitData =
|
|
703
|
+
const rbacInitData = toBytes32Arr(owners);
|
|
704
704
|
let userAuthInitData = '0x';
|
|
705
705
|
const groupUsers = Array.from(this.userInfo.values()).filter((user) => user.groupInfo !== null && user.groupInfo !== undefined);
|
|
706
706
|
if (groupUsers.length > 0) {
|
|
707
|
-
userAuthInitData =
|
|
707
|
+
userAuthInitData = encodeUserAuthInitData(groupUsers);
|
|
708
708
|
}
|
|
709
709
|
const initCodeParams = {
|
|
710
710
|
entryPointAddress,
|
|
711
711
|
factoryAddress,
|
|
712
|
-
implementationAddress:
|
|
712
|
+
implementationAddress: AddressZero,
|
|
713
713
|
loginData,
|
|
714
714
|
verificationAddresses: [rbac, userAuth],
|
|
715
715
|
verificationData: [rbacInitData, userAuthInitData],
|
|
@@ -717,7 +717,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
717
717
|
return this.getInitCode(initCodeParams);
|
|
718
718
|
}
|
|
719
719
|
getInitCode(input) {
|
|
720
|
-
const encodedVerificationInitdata =
|
|
720
|
+
const encodedVerificationInitdata = encodeAbiParameters([
|
|
721
721
|
{
|
|
722
722
|
type: 'address[]',
|
|
723
723
|
name: 'verificationAddresses',
|
|
@@ -727,12 +727,12 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
727
727
|
name: 'verificationData',
|
|
728
728
|
},
|
|
729
729
|
], [input.verificationAddresses, input.verificationData]);
|
|
730
|
-
const initializerCallData =
|
|
731
|
-
const data =
|
|
730
|
+
const initializerCallData = WALLET_CONTRACT_INTERFACE.encodeData('initialize', [input.entryPointAddress, encodedVerificationInitdata]);
|
|
731
|
+
const data = FACTORY_CONTRACT_INTERFACE.encodeData('createAccount', [
|
|
732
732
|
initializerCallData,
|
|
733
|
-
|
|
733
|
+
encodeLoginData(input.loginData),
|
|
734
734
|
]);
|
|
735
|
-
return
|
|
735
|
+
return concat([input.factoryAddress, data]);
|
|
736
736
|
}
|
|
737
737
|
/**
|
|
738
738
|
* Encodes arbitrary transactions calls to include fees
|
|
@@ -751,18 +751,18 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
751
751
|
options.fee.token = options.gasSponsor.token;
|
|
752
752
|
}
|
|
753
753
|
if (!options.fee.token) {
|
|
754
|
-
throw new
|
|
754
|
+
throw new InvalidParameterError(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');
|
|
755
755
|
}
|
|
756
756
|
if (!options.fee.recipient) {
|
|
757
|
-
throw new
|
|
757
|
+
throw new InvalidParameterError(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');
|
|
758
758
|
}
|
|
759
|
-
const chain = await
|
|
760
|
-
const token = new
|
|
759
|
+
const chain = await Chain.getChain({ chainIdentifier: options.chain });
|
|
760
|
+
const token = new Token(options.fee.token, chain);
|
|
761
761
|
if (options.fee.gasPercent && !token.isNative) {
|
|
762
|
-
throw new
|
|
762
|
+
throw new InvalidParameterError(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');
|
|
763
763
|
}
|
|
764
764
|
if (token.isNative) {
|
|
765
|
-
options.fee.token =
|
|
765
|
+
options.fee.token = AddressZero;
|
|
766
766
|
}
|
|
767
767
|
else {
|
|
768
768
|
options.fee.token = await token.getAddress();
|
|
@@ -772,20 +772,20 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
772
772
|
}
|
|
773
773
|
else if (options.fee.gasPercent) {
|
|
774
774
|
const feedata = [options.fee.token, options.fee.recipient, 1];
|
|
775
|
-
const estimateGasCalldata =
|
|
775
|
+
const estimateGasCalldata = WALLET_CONTRACT_INTERFACE.encodeData('execFromEntryPointWithFee', [params.to, params.value, params.data, feedata]);
|
|
776
776
|
const operation = await this.createOperation(auth, userId, { to: params.to, value: params.value, data: estimateGasCalldata }, { ...options, fee: undefined });
|
|
777
777
|
const gasUsed = await operation.getMaxTxCost();
|
|
778
778
|
options.fee.amount = Math.ceil((Number(gasUsed) * options.fee.gasPercent) / 100);
|
|
779
779
|
}
|
|
780
780
|
else {
|
|
781
|
-
throw new
|
|
781
|
+
throw new InvalidParameterError(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');
|
|
782
782
|
}
|
|
783
783
|
const feedata = [
|
|
784
784
|
options.fee.token,
|
|
785
785
|
options.fee.recipient,
|
|
786
786
|
options.fee.amount,
|
|
787
787
|
];
|
|
788
|
-
return
|
|
788
|
+
return WALLET_CONTRACT_INTERFACE.encodeData('execFromEntryPointWithFee', [
|
|
789
789
|
params.to,
|
|
790
790
|
params.value,
|
|
791
791
|
params.data,
|
|
@@ -793,7 +793,7 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
793
793
|
]);
|
|
794
794
|
}
|
|
795
795
|
else {
|
|
796
|
-
return
|
|
796
|
+
return WALLET_CONTRACT_INTERFACE.encodeData('execFromEntryPoint', [
|
|
797
797
|
params.to,
|
|
798
798
|
params.value,
|
|
799
799
|
params.data,
|
|
@@ -801,5 +801,4 @@ class FunWallet extends FirstClassActions_1.FirstClassActions {
|
|
|
801
801
|
}
|
|
802
802
|
}
|
|
803
803
|
}
|
|
804
|
-
exports.FunWallet = FunWallet;
|
|
805
804
|
//# sourceMappingURL=FunWallet.js.map
|