@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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Sponsor = void 0;
|
|
4
|
-
const PaymasterApis_1 = require("../apis/PaymasterApis");
|
|
5
4
|
const data_1 = require("../data");
|
|
6
5
|
class Sponsor {
|
|
7
6
|
constructor(options = globalThis.globalEnvOption, contractInterface, name, paymasterType) {
|
|
8
|
-
if (options.gasSponsor !== undefined &&
|
|
7
|
+
if (options.gasSponsor !== undefined &&
|
|
8
|
+
options.gasSponsor.sponsorAddress !== undefined) {
|
|
9
9
|
this.sponsorAddress = options.gasSponsor.sponsorAddress;
|
|
10
10
|
}
|
|
11
11
|
this.contractInterface = contractInterface;
|
|
@@ -24,69 +24,53 @@ class Sponsor {
|
|
|
24
24
|
/** True if the specified sponsor is in blacklist mode. **/
|
|
25
25
|
async getListMode(sponsor, options = globalThis.globalEnvOption) {
|
|
26
26
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
27
|
-
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options),
|
|
27
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getListMode', [sponsor], chain);
|
|
28
28
|
}
|
|
29
|
-
async setToBlacklistMode(
|
|
30
|
-
|
|
31
|
-
await (0, PaymasterApis_1.updatePaymasterMode)(await chain.getChainId(), { mode: "blacklist" }, this.paymasterType, sponsor);
|
|
32
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setListMode", [true]);
|
|
29
|
+
async setToBlacklistMode() {
|
|
30
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setListMode', [true]);
|
|
33
31
|
}
|
|
34
|
-
async setToWhitelistMode(
|
|
35
|
-
|
|
36
|
-
await (0, PaymasterApis_1.updatePaymasterMode)(await chain.getChainId(), { mode: "whitelist" }, this.paymasterType, sponsor);
|
|
37
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setListMode", [false]);
|
|
32
|
+
async setToWhitelistMode() {
|
|
33
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setListMode', [false]);
|
|
38
34
|
}
|
|
39
35
|
async batchTransaction(transactions) {
|
|
40
|
-
const batchActionsData = transactions.map((transaction) =>
|
|
41
|
-
const value = transactions.reduce((acc, transaction) =>
|
|
42
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(),
|
|
36
|
+
const batchActionsData = transactions.map((transaction) => transaction.data ? transaction.data : '0x');
|
|
37
|
+
const value = transactions.reduce((acc, transaction) => transaction.value ? acc + BigInt(transaction.value) : acc, 0n);
|
|
38
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'batchActions', [batchActionsData], value);
|
|
43
39
|
}
|
|
44
|
-
async addSpenderToWhitelist(
|
|
45
|
-
|
|
46
|
-
await (0, PaymasterApis_1.addToList)(await chain.getChainId(), [spender], "walletsWhiteList", this.paymasterType, sponsor);
|
|
47
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setSpenderWhitelistMode", [spender, true]);
|
|
40
|
+
async addSpenderToWhitelist(spender) {
|
|
41
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setSpenderWhitelistMode', [spender, true]);
|
|
48
42
|
}
|
|
49
|
-
async removeSpenderFromWhitelist(
|
|
50
|
-
|
|
51
|
-
await (0, PaymasterApis_1.removeFromList)(await chain.getChainId(), [spender], "walletsWhiteList", this.paymasterType, sponsor);
|
|
52
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setSpenderWhitelistMode", [spender, false]);
|
|
43
|
+
async removeSpenderFromWhitelist(spender) {
|
|
44
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setSpenderWhitelistMode', [spender, false]);
|
|
53
45
|
}
|
|
54
|
-
async batchWhitelistSpenders(
|
|
55
|
-
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
46
|
+
async batchWhitelistSpenders(spenders, modes) {
|
|
56
47
|
const calldata = [];
|
|
57
48
|
for (let i = 0; i < spenders.length; i++) {
|
|
58
49
|
if (modes[i]) {
|
|
59
|
-
calldata.push(await this.addSpenderToWhitelist(
|
|
50
|
+
calldata.push(await this.addSpenderToWhitelist(spenders[i]));
|
|
60
51
|
}
|
|
61
52
|
else {
|
|
62
|
-
calldata.push(await this.removeSpenderFromWhitelist(
|
|
53
|
+
calldata.push(await this.removeSpenderFromWhitelist(spenders[i]));
|
|
63
54
|
}
|
|
64
55
|
}
|
|
65
|
-
(0, PaymasterApis_1.batchOperation)(await chain.getChainId(), spenders, modes, "walletsWhiteList", this.paymasterType, sponsor);
|
|
66
56
|
return await this.batchTransaction(calldata);
|
|
67
57
|
}
|
|
68
|
-
async addSpenderToBlacklist(
|
|
69
|
-
|
|
70
|
-
await (0, PaymasterApis_1.addToList)(await chain.getChainId(), [spender], "walletsBlackList", this.paymasterType, sponsor);
|
|
71
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setSpenderBlacklistMode", [spender, true]);
|
|
58
|
+
async addSpenderToBlacklist(spender) {
|
|
59
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setSpenderBlacklistMode', [spender, true]);
|
|
72
60
|
}
|
|
73
|
-
async removeSpenderFromBlacklist(
|
|
74
|
-
|
|
75
|
-
await (0, PaymasterApis_1.removeFromList)(await chain.getChainId(), [spender], "walletsBlackList", this.paymasterType, sponsor);
|
|
76
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setSpenderBlacklistMode", [spender, false]);
|
|
61
|
+
async removeSpenderFromBlacklist(spender) {
|
|
62
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setSpenderBlacklistMode', [spender, false]);
|
|
77
63
|
}
|
|
78
|
-
async batchBlacklistSpenders(
|
|
79
|
-
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
64
|
+
async batchBlacklistSpenders(spenders, modes) {
|
|
80
65
|
const calldata = [];
|
|
81
66
|
for (let i = 0; i < spenders.length; i++) {
|
|
82
67
|
if (modes[i]) {
|
|
83
|
-
calldata.push(await this.addSpenderToBlacklist(
|
|
68
|
+
calldata.push(await this.addSpenderToBlacklist(spenders[i]));
|
|
84
69
|
}
|
|
85
70
|
else {
|
|
86
|
-
calldata.push(await this.removeSpenderFromBlacklist(
|
|
71
|
+
calldata.push(await this.removeSpenderFromBlacklist(spenders[i]));
|
|
87
72
|
}
|
|
88
73
|
}
|
|
89
|
-
(0, PaymasterApis_1.batchOperation)(await chain.getChainId(), spenders, modes, "walletsBlackList", this.paymasterType, sponsor);
|
|
90
74
|
return await this.batchTransaction(calldata);
|
|
91
75
|
}
|
|
92
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sponsor.js","sourceRoot":"","sources":["../../../src/sponsors/Sponsor.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Sponsor.js","sourceRoot":"","sources":["../../../src/sponsors/Sponsor.ts"],"names":[],"mappings":";;;AAIA,kCAA+B;AAI/B,MAAsB,OAAO;IAQ3B,YACE,UAAsB,UAAkB,CAAC,eAAe,EACxD,iBAAoC,EACpC,IAAY,EACZ,aAA4B;QAE5B,IACE,OAAO,CAAC,UAAU,KAAK,SAAS;YAChC,OAAO,CAAC,UAAU,CAAC,cAAc,KAAK,SAAS,EAC/C,CAAC;YACD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,cAAc,CAAA;QACzD,CAAC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AAC;gBACN,QAAQ,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACnE,CAAC;QACH,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAC9C,CAAC;CACF;AAzKD,0BAyKC"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Address } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { Auth } from '../auth';
|
|
3
|
+
import { TransactionParams } from '../common';
|
|
4
|
+
import { EnvOption } from '../config';
|
|
5
|
+
import { Operation } from '../data';
|
|
6
|
+
import { Sponsor } from './Sponsor';
|
|
7
|
+
import { AllTokenData } from './types';
|
|
8
8
|
export declare class TokenSponsor extends Sponsor {
|
|
9
9
|
token: string;
|
|
10
10
|
constructor(options?: EnvOption);
|
|
11
11
|
getFunSponsorAddress(options?: EnvOption): Promise<Address>;
|
|
12
12
|
getPaymasterAndData(options?: EnvOption): Promise<string>;
|
|
13
13
|
getPaymasterAndDataPermit(partialOp: Operation, walletAddr: Address, userId: string, auth: Auth, options?: EnvOption): Promise<string>;
|
|
14
|
-
stake(
|
|
15
|
-
unstake(
|
|
14
|
+
stake(sponsor: Address, amount: number, options?: EnvOption): Promise<TransactionParams>;
|
|
15
|
+
unstake(receiver: Address, amount: number, options?: EnvOption): Promise<TransactionParams>;
|
|
16
16
|
getUnlockBlock(sponsor: Address, token: string, options?: EnvOption): Promise<bigint>;
|
|
17
17
|
getLockState(sponsor: Address, token: string, options?: EnvOption): Promise<boolean>;
|
|
18
18
|
getTokenInfo(token: string, options?: EnvOption): Promise<any>;
|
|
@@ -20,8 +20,8 @@ export declare class TokenSponsor extends Sponsor {
|
|
|
20
20
|
getTokenBalance(spender: Address, token: string, options?: EnvOption): Promise<bigint>;
|
|
21
21
|
getAllTokens(options?: EnvOption): Promise<any>;
|
|
22
22
|
addUsableToken(oracle: string, token: string, aggregator: string, options?: EnvOption): Promise<TransactionParams>;
|
|
23
|
-
depositToken(
|
|
24
|
-
withdrawToken(
|
|
23
|
+
depositToken(token: string, spender: Address, amount: number, options?: EnvOption): Promise<TransactionParams>;
|
|
24
|
+
withdrawToken(token: string, receiver: Address, amount: number, options?: EnvOption): Promise<TransactionParams>;
|
|
25
25
|
lockTokenDeposit(token: string, options?: EnvOption): Promise<TransactionParams>;
|
|
26
26
|
unlockTokenDepositAfter(token: string, blocksToWait: number, options?: EnvOption): Promise<TransactionParams>;
|
|
27
27
|
lockDeposit(): Promise<TransactionParams>;
|
|
@@ -30,11 +30,11 @@ export declare class TokenSponsor extends Sponsor {
|
|
|
30
30
|
getSpenderBlacklisted(spender: Address, sponsor: Address, options?: EnvOption): Promise<boolean>;
|
|
31
31
|
getSpenderWhitelisted(spender: Address, sponsor: Address, options?: EnvOption): Promise<boolean>;
|
|
32
32
|
getTokenWhitelisted(sponsor: Address, token: string, options?: EnvOption): Promise<boolean>;
|
|
33
|
-
setTokenToWhitelistMode(
|
|
34
|
-
batchWhitelistTokens(
|
|
33
|
+
setTokenToWhitelistMode(): Promise<TransactionParams>;
|
|
34
|
+
batchWhitelistTokens(tokens: string[], modes: boolean[], options?: EnvOption): Promise<TransactionParams>;
|
|
35
35
|
getTokenListMode(sponsor: Address, options?: EnvOption): Promise<any>;
|
|
36
36
|
getTokenBlacklisted(sponsor: Address, token: string, options?: EnvOption): Promise<boolean>;
|
|
37
|
-
setTokenToBlacklistMode(
|
|
38
|
-
batchBlacklistTokens(
|
|
37
|
+
setTokenToBlacklistMode(): Promise<TransactionParams>;
|
|
38
|
+
batchBlacklistTokens(tokens: string[], modes: boolean[], options?: EnvOption): Promise<TransactionParams>;
|
|
39
39
|
static getPaymasterAddress(options?: EnvOption): Promise<Address>;
|
|
40
40
|
}
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenSponsor = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const Sponsor_1 = require("./Sponsor");
|
|
6
|
-
const types_1 = require("./types");
|
|
7
5
|
const PaymasterApis_1 = require("../apis/PaymasterApis");
|
|
8
6
|
const common_1 = require("../common");
|
|
9
7
|
const constants_1 = require("../common/constants");
|
|
10
8
|
const data_1 = require("../data");
|
|
11
9
|
const errors_1 = require("../errors");
|
|
12
10
|
const utils_1 = require("../utils");
|
|
11
|
+
const Sponsor_1 = require("./Sponsor");
|
|
12
|
+
const types_1 = require("./types");
|
|
13
13
|
class TokenSponsor extends Sponsor_1.Sponsor {
|
|
14
14
|
constructor(options = globalThis.globalEnvOption) {
|
|
15
|
-
super(options, constants_1.TOKEN_PAYMASTER_CONTRACT_INTERFACE,
|
|
15
|
+
super(options, constants_1.TOKEN_PAYMASTER_CONTRACT_INTERFACE, 'tokenPaymasterAddress', types_1.PaymasterType.TokenSponsor);
|
|
16
16
|
if (!options.gasSponsor?.token) {
|
|
17
|
-
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter,
|
|
17
|
+
throw new errors_1.InvalidParameterError(errors_1.ErrorCode.MissingParameter, 'token field is missing', { gasSponsor: options.gasSponsor }, 'Provide correct token name or address.', 'https://docs.fun.xyz');
|
|
18
18
|
}
|
|
19
19
|
this.token = options.gasSponsor.token.toLowerCase();
|
|
20
20
|
}
|
|
@@ -22,16 +22,23 @@ class TokenSponsor extends Sponsor_1.Sponsor {
|
|
|
22
22
|
if (!this.sponsorAddress) {
|
|
23
23
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
24
24
|
if (common_1.TOKEN_SPONSOR_SUPPORT_CHAINS.includes(await chain.getChainId())) {
|
|
25
|
-
this.sponsorAddress = await chain.getAddress(
|
|
25
|
+
this.sponsorAddress = await chain.getAddress('funTokenSponsorAddress');
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
throw new errors_1.ResourceNotFoundError(errors_1.ErrorCode.MissingParameter,
|
|
28
|
+
throw new errors_1.ResourceNotFoundError(errors_1.ErrorCode.MissingParameter, 'The network you are working with does not support token Fun Sponsor. You will need to run and manage your own token sponsor.', {
|
|
29
|
+
tokenSponsorSupportChains: common_1.TOKEN_SPONSOR_SUPPORT_CHAINS,
|
|
30
|
+
chain: await chain.getChainId(),
|
|
31
|
+
}, 'Manage your own token sponsor, or use a supported network', 'https://docs.fun.xyz');
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
return this.sponsorAddress;
|
|
32
35
|
}
|
|
33
36
|
async getPaymasterAndData(options = globalThis.globalEnvOption) {
|
|
34
|
-
|
|
37
|
+
// TODO: temporary fallback, remove after refactoring -- Panda
|
|
38
|
+
const chain = await data_1.Chain.getChain({
|
|
39
|
+
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
40
|
+
});
|
|
41
|
+
const tokenAddress = await data_1.Token.getAddress(this.token, chain);
|
|
35
42
|
const paymasterAddress = await this.getPaymasterAddress(options);
|
|
36
43
|
const sponsor = await this.getFunSponsorAddress(options);
|
|
37
44
|
return (0, viem_1.concat)([paymasterAddress, sponsor, tokenAddress]);
|
|
@@ -40,226 +47,202 @@ class TokenSponsor extends Sponsor_1.Sponsor {
|
|
|
40
47
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
41
48
|
const estimateGasSignature = await auth.getEstimateGasSignature(userId, partialOp);
|
|
42
49
|
partialOp.userOp.signature = estimateGasSignature.toLowerCase();
|
|
43
|
-
const estimationPaymasterAddress = await chain.getAddress(
|
|
50
|
+
const estimationPaymasterAddress = await chain.getAddress('estimationPaymasterAddress');
|
|
44
51
|
const { callGasLimit, verificationGasLimit, preVerificationGas } = await chain.estimateOpGas({
|
|
45
52
|
...partialOp.userOp,
|
|
46
|
-
paymasterAndData: estimationPaymasterAddress
|
|
53
|
+
paymasterAndData: estimationPaymasterAddress,
|
|
47
54
|
});
|
|
48
55
|
const { maxFeePerGas } = await chain.getFeeData();
|
|
49
56
|
const paymasterAddress = await this.getPaymasterAddress(options);
|
|
50
|
-
const requiredGas = (callGasLimit +
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
const requiredGas = (callGasLimit +
|
|
58
|
+
(verificationGasLimit + 400000n) * 3n +
|
|
59
|
+
preVerificationGas) *
|
|
60
|
+
BigInt(maxFeePerGas);
|
|
61
|
+
const tokenAddress = await data_1.Token.getAddress(this.token, chain);
|
|
62
|
+
const decAmount = await constants_1.TOKEN_PAYMASTER_CONTRACT_INTERFACE.readFromChain(paymasterAddress, 'getTokenValueOfEth', [tokenAddress, requiredGas], chain);
|
|
53
63
|
const nonce = await (0, utils_1.getWalletPermitNonce)(walletAddr, chain);
|
|
54
64
|
const client = await chain.getClient();
|
|
55
65
|
const chainId = await client.getChainId();
|
|
56
66
|
const hash = await (0, utils_1.getPermitHash)(tokenAddress, paymasterAddress, decAmount, nonce, walletAddr, BigInt(chainId));
|
|
57
67
|
const sig = await auth.signHash(hash);
|
|
58
|
-
const encodedSig = (0, viem_1.encodeAbiParameters)([
|
|
68
|
+
const encodedSig = (0, viem_1.encodeAbiParameters)([
|
|
69
|
+
{ type: 'address' },
|
|
70
|
+
{ type: 'address' },
|
|
71
|
+
{ type: 'uint256' },
|
|
72
|
+
{ type: 'uint256' },
|
|
73
|
+
{ type: 'bytes' },
|
|
74
|
+
], [tokenAddress, paymasterAddress, decAmount, nonce, sig]);
|
|
59
75
|
const sponsor = await this.getFunSponsorAddress(options);
|
|
60
|
-
const encodedAddresses = (0, viem_1.encodeAbiParameters)([{ type:
|
|
61
|
-
const encodedData = (0, viem_1.encodeAbiParameters)([{ type:
|
|
76
|
+
const encodedAddresses = (0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'address' }], [sponsor, tokenAddress]);
|
|
77
|
+
const encodedData = (0, viem_1.encodeAbiParameters)([{ type: 'bytes' }, { type: 'bytes' }], [encodedAddresses, encodedSig]);
|
|
62
78
|
return (0, viem_1.concat)([paymasterAddress, encodedData]);
|
|
63
79
|
}
|
|
64
|
-
async stake(
|
|
65
|
-
const
|
|
66
|
-
const chain = await data_1.Chain.getChain({ chainIdentifier
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
amount,
|
|
70
|
-
from: depositor,
|
|
71
|
-
to: await this.getPaymasterAddress(options),
|
|
72
|
-
token: "eth"
|
|
73
|
-
}, this.paymasterType, sponsor);
|
|
74
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "addEthDepositTo", [sponsor, amountdec], BigInt(amountdec));
|
|
80
|
+
async stake(sponsor, amount, options = globalThis.globalEnvOption) {
|
|
81
|
+
const chainIdentifier = options.chain ?? globalThis.globalEnvOption.chain;
|
|
82
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier });
|
|
83
|
+
const amountdec = await data_1.Token.getDecimalAmount('eth', amount, chain);
|
|
84
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'addEthDepositTo', [sponsor, amountdec], BigInt(amountdec));
|
|
75
85
|
}
|
|
76
|
-
async unstake(
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
from: sponsor,
|
|
83
|
-
to: await this.getPaymasterAddress(options),
|
|
84
|
-
token: "eth"
|
|
85
|
-
}, this.paymasterType, receiver);
|
|
86
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "withdrawEthDepositTo", [
|
|
87
|
-
receiver,
|
|
88
|
-
amountdec
|
|
89
|
-
]);
|
|
86
|
+
async unstake(receiver, amount, options = globalThis.globalEnvOption) {
|
|
87
|
+
// TODO: temporary fallback, remove after refactoring -- Panda
|
|
88
|
+
const chainIdentifier = options.chain ?? globalThis.globalEnvOption.chain;
|
|
89
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier });
|
|
90
|
+
const amountdec = await data_1.Token.getDecimalAmount('eth', amount, chain);
|
|
91
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'withdrawEthDepositTo', [receiver, amountdec]);
|
|
90
92
|
}
|
|
91
93
|
async getUnlockBlock(sponsor, token, options = globalThis.globalEnvOption) {
|
|
92
|
-
|
|
94
|
+
// TODO: temporary fallback, remove after refactoring -- Panda
|
|
95
|
+
const chain = await data_1.Chain.getChain({
|
|
96
|
+
chainIdentifier: globalThis.globalEnvOption.chain,
|
|
97
|
+
});
|
|
98
|
+
const tokenAddr = (await data_1.Token.isNative(token))
|
|
99
|
+
? constants_1.AddressZero
|
|
100
|
+
: await data_1.Token.getAddress(token, chain);
|
|
93
101
|
return (await this.getAllTokenData(tokenAddr, sponsor, options)).unlockBlock;
|
|
94
102
|
}
|
|
95
103
|
// false means unlocked, true means locked
|
|
96
104
|
async getLockState(sponsor, token, options = globalThis.globalEnvOption) {
|
|
97
|
-
const tokenAddr = (await data_1.Token.isNative(token)) ? constants_1.AddressZero : await data_1.Token.getAddress(token, options);
|
|
98
|
-
const unlockBlock = await this.getUnlockBlock(tokenAddr, sponsor);
|
|
99
105
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
106
|
+
const tokenAddr = (await data_1.Token.isNative(token))
|
|
107
|
+
? constants_1.AddressZero
|
|
108
|
+
: await data_1.Token.getAddress(token, chain);
|
|
109
|
+
const unlockBlock = await this.getUnlockBlock(tokenAddr, sponsor);
|
|
100
110
|
const provider = await chain.getClient();
|
|
101
111
|
const currentBlock = await provider.getBlockNumber();
|
|
102
112
|
return unlockBlock === 0n || unlockBlock > currentBlock;
|
|
103
113
|
}
|
|
104
114
|
async getTokenInfo(token, options = globalThis.globalEnvOption) {
|
|
105
|
-
const tokenAddress = await data_1.Token.getAddress(token, options);
|
|
106
115
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
107
|
-
|
|
116
|
+
const tokenAddress = await data_1.Token.getAddress(token, chain);
|
|
117
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getToken', [tokenAddress], chain);
|
|
108
118
|
}
|
|
109
119
|
async getAllTokenData(spender, token, options = globalThis.globalEnvOption) {
|
|
110
|
-
const tokenAddress = await data_1.Token.getAddress(token, options);
|
|
111
120
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
112
|
-
const
|
|
121
|
+
const tokenAddress = await data_1.Token.getAddress(token, chain);
|
|
122
|
+
const data = await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getAllTokenData', [tokenAddress, spender], chain);
|
|
113
123
|
return {
|
|
114
124
|
unlockBlock: data[0],
|
|
115
|
-
tokenAmount: data[1]
|
|
125
|
+
tokenAmount: data[1],
|
|
116
126
|
};
|
|
117
127
|
}
|
|
118
128
|
async getTokenBalance(spender, token, options = globalThis.globalEnvOption) {
|
|
119
|
-
const
|
|
129
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
130
|
+
const tokenData = new data_1.Token(token, chain);
|
|
120
131
|
let tokenAddress;
|
|
121
132
|
if (tokenData.isNative) {
|
|
122
133
|
tokenAddress = constants_1.AddressZero;
|
|
123
134
|
}
|
|
124
135
|
else {
|
|
125
|
-
tokenAddress = await tokenData.getAddress(
|
|
136
|
+
tokenAddress = await tokenData.getAddress();
|
|
126
137
|
}
|
|
127
|
-
|
|
128
|
-
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), "getTokenBalance", [tokenAddress, spender], chain);
|
|
138
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getTokenBalance', [tokenAddress, spender], chain);
|
|
129
139
|
}
|
|
130
140
|
async getAllTokens(options = globalThis.globalEnvOption) {
|
|
131
141
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
132
|
-
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options),
|
|
142
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getAllTokens', [], chain);
|
|
133
143
|
}
|
|
134
144
|
async addUsableToken(oracle, token, aggregator, options = globalThis.globalEnvOption) {
|
|
135
|
-
const
|
|
136
|
-
const
|
|
145
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
146
|
+
const decimals = await data_1.Token.getDecimals(token, chain);
|
|
147
|
+
const tokenAddress = await data_1.Token.getAddress(token, chain);
|
|
137
148
|
const data = [oracle, tokenAddress, decimals, aggregator];
|
|
138
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(),
|
|
149
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setTokenData', [data]);
|
|
139
150
|
}
|
|
140
|
-
async depositToken(
|
|
141
|
-
const tokenObj = new data_1.Token(token);
|
|
142
|
-
const tokenAddress = await tokenObj.getAddress(options);
|
|
143
|
-
const amountdec = await tokenObj.getDecimalAmount(amount, options);
|
|
151
|
+
async depositToken(token, spender, amount, options = globalThis.globalEnvOption) {
|
|
144
152
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
to: await this.getPaymasterAddress(options),
|
|
150
|
-
token
|
|
151
|
-
}, this.paymasterType, spender);
|
|
152
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "addTokenDepositTo", [
|
|
153
|
-
tokenAddress,
|
|
154
|
-
spender,
|
|
155
|
-
amountdec
|
|
156
|
-
]);
|
|
153
|
+
const tokenObj = new data_1.Token(token, chain);
|
|
154
|
+
const tokenAddress = await tokenObj.getAddress();
|
|
155
|
+
const amountDec = await tokenObj.getDecimalAmount(amount);
|
|
156
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'addTokenDepositTo', [tokenAddress, spender, amountDec]);
|
|
157
157
|
}
|
|
158
|
-
async withdrawToken(
|
|
159
|
-
const tokenObj = new data_1.Token(token);
|
|
160
|
-
const tokenAddress = await tokenObj.getAddress(options);
|
|
161
|
-
const amountdec = await tokenObj.getDecimalAmount(amount, options);
|
|
158
|
+
async withdrawToken(token, receiver, amount, options = globalThis.globalEnvOption) {
|
|
162
159
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
to: await this.getPaymasterAddress(options),
|
|
168
|
-
token
|
|
169
|
-
}, this.paymasterType, receiver);
|
|
170
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "withdrawTokenDepositTo", [
|
|
171
|
-
tokenAddress,
|
|
172
|
-
receiver,
|
|
173
|
-
amountdec
|
|
174
|
-
]);
|
|
160
|
+
const tokenObj = new data_1.Token(token, chain);
|
|
161
|
+
const tokenAddress = await tokenObj.getAddress();
|
|
162
|
+
const amountdec = await tokenObj.getDecimalAmount(amount);
|
|
163
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'withdrawTokenDepositTo', [tokenAddress, receiver, amountdec]);
|
|
175
164
|
}
|
|
176
165
|
async lockTokenDeposit(token, options = globalThis.globalEnvOption) {
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
|
|
166
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
167
|
+
const tokenData = new data_1.Token(token, chain);
|
|
168
|
+
const tokenAddress = tokenData.isNative
|
|
169
|
+
? constants_1.AddressZero
|
|
170
|
+
: await tokenData.getAddress();
|
|
171
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'lockTokenDeposit', [tokenAddress]);
|
|
180
172
|
}
|
|
181
173
|
async unlockTokenDepositAfter(token, blocksToWait, options = globalThis.globalEnvOption) {
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
]);
|
|
174
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
175
|
+
const tokenData = new data_1.Token(token, chain);
|
|
176
|
+
const tokenAddress = tokenData.isNative
|
|
177
|
+
? constants_1.AddressZero
|
|
178
|
+
: await tokenData.getAddress();
|
|
179
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'unlockTokenDepositAfter', [tokenAddress, blocksToWait]);
|
|
188
180
|
}
|
|
189
181
|
async lockDeposit() {
|
|
190
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(),
|
|
182
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'lockTokenDeposit', [constants_1.AddressZero]);
|
|
191
183
|
}
|
|
192
184
|
async unlockDepositAfter(blocksToWait) {
|
|
193
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(),
|
|
194
|
-
constants_1.AddressZero,
|
|
195
|
-
blocksToWait
|
|
196
|
-
]);
|
|
185
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'unlockTokenDepositAfter', [constants_1.AddressZero, blocksToWait]);
|
|
197
186
|
}
|
|
198
187
|
async approve(approver, token, amount, options = globalThis.globalEnvOption) {
|
|
199
188
|
const gasSponsorAddress = await this.getPaymasterAddress();
|
|
200
189
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
201
|
-
(0, PaymasterApis_1.addTransaction)(await chain.getChainId(), Date.now(),
|
|
202
|
-
action:
|
|
190
|
+
(0, PaymasterApis_1.addTransaction)(await chain.getChainId(), Date.now(), '0x', {
|
|
191
|
+
action: 'approve',
|
|
203
192
|
amount,
|
|
204
193
|
from: approver,
|
|
205
194
|
to: await this.getPaymasterAddress(options),
|
|
206
|
-
token
|
|
195
|
+
token,
|
|
207
196
|
}, this.paymasterType, approver);
|
|
208
|
-
return data_1.Token.approve(token, gasSponsorAddress, amount);
|
|
197
|
+
return data_1.Token.approve(token, gasSponsorAddress, amount, chain);
|
|
209
198
|
}
|
|
210
199
|
async getSpenderBlacklisted(spender, sponsor, options = globalThis.globalEnvOption) {
|
|
211
200
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
212
|
-
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options),
|
|
201
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getSpenderBlacklisted', [spender, sponsor], chain);
|
|
213
202
|
}
|
|
214
203
|
async getSpenderWhitelisted(spender, sponsor, options = globalThis.globalEnvOption) {
|
|
215
204
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
216
|
-
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options),
|
|
205
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getSpenderWhitelisted', [spender, sponsor], chain);
|
|
217
206
|
}
|
|
218
207
|
async getTokenWhitelisted(sponsor, token, options = globalThis.globalEnvOption) {
|
|
219
208
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
220
|
-
const tokenAddress = await data_1.Token.getAddress(token,
|
|
221
|
-
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options),
|
|
209
|
+
const tokenAddress = await data_1.Token.getAddress(token, chain);
|
|
210
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getTokenWhitelisted', [tokenAddress, sponsor], chain);
|
|
222
211
|
}
|
|
223
|
-
async setTokenToWhitelistMode(
|
|
224
|
-
|
|
225
|
-
await (0, PaymasterApis_1.updatePaymasterMode)(await chain.getChainId(), { tokenMode: "whitelist" }, this.paymasterType, sponsor);
|
|
226
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setTokenListMode", [false]);
|
|
212
|
+
async setTokenToWhitelistMode() {
|
|
213
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setTokenListMode', [false]);
|
|
227
214
|
}
|
|
228
|
-
async batchWhitelistTokens(
|
|
215
|
+
async batchWhitelistTokens(tokens, modes, options = globalThis.globalEnvOption) {
|
|
216
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
229
217
|
const calldata = [];
|
|
230
218
|
for (let i = 0; i < tokens.length; i++) {
|
|
231
|
-
const tokenAddress = await data_1.Token.getAddress(tokens[i],
|
|
232
|
-
calldata.push(this.contractInterface.encodeData(
|
|
219
|
+
const tokenAddress = await data_1.Token.getAddress(tokens[i], chain);
|
|
220
|
+
calldata.push(this.contractInterface.encodeData('setTokenWhitelistMode', [
|
|
221
|
+
tokenAddress,
|
|
222
|
+
modes[i],
|
|
223
|
+
]));
|
|
233
224
|
}
|
|
234
|
-
|
|
235
|
-
await (0, PaymasterApis_1.batchOperation)(await chain.getChainId(), tokens, modes, "tokensWhiteList", this.paymasterType, sponsor);
|
|
236
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "batchActions", [calldata]);
|
|
225
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'batchActions', [calldata]);
|
|
237
226
|
}
|
|
238
227
|
async getTokenListMode(sponsor, options = globalThis.globalEnvOption) {
|
|
239
228
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
240
|
-
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options),
|
|
229
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getTokenListMode', [sponsor], chain);
|
|
241
230
|
}
|
|
242
231
|
async getTokenBlacklisted(sponsor, token, options = globalThis.globalEnvOption) {
|
|
243
|
-
const tokenAddress = await data_1.Token.getAddress(token, options);
|
|
244
232
|
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
245
|
-
|
|
233
|
+
const tokenAddress = await data_1.Token.getAddress(token, chain);
|
|
234
|
+
return await this.contractInterface.readFromChain(await this.getPaymasterAddress(options), 'getTokenBlacklisted', [tokenAddress, sponsor], chain);
|
|
246
235
|
}
|
|
247
|
-
async setTokenToBlacklistMode(
|
|
248
|
-
|
|
249
|
-
await (0, PaymasterApis_1.updatePaymasterMode)(await chain.getChainId(), { tokenMode: "blacklist" }, this.paymasterType, sponsor);
|
|
250
|
-
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), "setTokenListMode", [true]);
|
|
236
|
+
async setTokenToBlacklistMode() {
|
|
237
|
+
return this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setTokenListMode', [true]);
|
|
251
238
|
}
|
|
252
|
-
async batchBlacklistTokens(
|
|
239
|
+
async batchBlacklistTokens(tokens, modes, options = globalThis.globalEnvOption) {
|
|
240
|
+
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
253
241
|
const calldata = [];
|
|
254
242
|
for (let i = 0; i < tokens.length; i++) {
|
|
255
|
-
const tokenAddress = await data_1.Token.getAddress(tokens[i],
|
|
256
|
-
calldata.push(this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(),
|
|
257
|
-
tokenAddress,
|
|
258
|
-
modes[i]
|
|
259
|
-
]));
|
|
243
|
+
const tokenAddress = await data_1.Token.getAddress(tokens[i], chain);
|
|
244
|
+
calldata.push(this.contractInterface.encodeTransactionParams(await this.getPaymasterAddress(), 'setTokenBlacklistMode', [tokenAddress, modes[i]]));
|
|
260
245
|
}
|
|
261
|
-
const chain = await data_1.Chain.getChain({ chainIdentifier: options.chain });
|
|
262
|
-
await (0, PaymasterApis_1.batchOperation)(await chain.getChainId(), tokens, modes, "tokensBlackList", this.paymasterType, sponsor);
|
|
263
246
|
return this.batchTransaction(calldata);
|
|
264
247
|
}
|
|
265
248
|
static async getPaymasterAddress(options = globalThis.globalEnvOption) {
|