starknet 7.2.0 → 7.3.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/CHANGELOG.md +11 -0
- package/dist/index.d.ts +225 -10
- package/dist/index.global.js +375 -9
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +376 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +372 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.global.js
CHANGED
|
@@ -60,6 +60,8 @@ var starknet = (() => {
|
|
|
60
60
|
OutsideExecutionTypesV1: () => OutsideExecutionTypesV1,
|
|
61
61
|
OutsideExecutionTypesV2: () => OutsideExecutionTypesV2,
|
|
62
62
|
OutsideExecutionVersion: () => OutsideExecutionVersion,
|
|
63
|
+
PaymasterInterface: () => PaymasterInterface,
|
|
64
|
+
PaymasterRpc: () => PaymasterRpc,
|
|
63
65
|
Provider: () => RpcProvider2,
|
|
64
66
|
ProviderInterface: () => ProviderInterface,
|
|
65
67
|
RPC: () => api_exports3,
|
|
@@ -98,6 +100,7 @@ var starknet = (() => {
|
|
|
98
100
|
config: () => config,
|
|
99
101
|
constants: () => constants_exports,
|
|
100
102
|
contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
|
|
103
|
+
defaultPaymaster: () => defaultPaymaster,
|
|
101
104
|
defaultProvider: () => defaultProvider,
|
|
102
105
|
ec: () => ec_exports,
|
|
103
106
|
encode: () => encode_exports,
|
|
@@ -127,6 +130,7 @@ var starknet = (() => {
|
|
|
127
130
|
num: () => num_exports,
|
|
128
131
|
outsideExecution: () => outsideExecution_exports,
|
|
129
132
|
parseCalldataField: () => parseCalldataField,
|
|
133
|
+
paymaster: () => paymaster_exports,
|
|
130
134
|
provider: () => provider_exports,
|
|
131
135
|
selector: () => selector_exports,
|
|
132
136
|
shortString: () => shortString_exports,
|
|
@@ -161,6 +165,7 @@ var starknet = (() => {
|
|
|
161
165
|
MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
|
|
162
166
|
NetworkName: () => _NetworkName,
|
|
163
167
|
OutsideExecutionCallerAny: () => OutsideExecutionCallerAny,
|
|
168
|
+
PAYMASTER_RPC_NODES: () => PAYMASTER_RPC_NODES,
|
|
164
169
|
PRIME: () => PRIME,
|
|
165
170
|
RANGE_FELT: () => RANGE_FELT,
|
|
166
171
|
RANGE_I128: () => RANGE_I128,
|
|
@@ -202,6 +207,7 @@ var starknet = (() => {
|
|
|
202
207
|
EVENT_ABI_TYPE: () => EVENT_ABI_TYPE,
|
|
203
208
|
JRPC: () => jsonrpc_exports,
|
|
204
209
|
L1_DA_MODE: () => L1_DA_MODE,
|
|
210
|
+
PAYMASTER_API: () => snip_29_exports,
|
|
205
211
|
PRICE_UNIT_FRI: () => PRICE_UNIT_FRI,
|
|
206
212
|
PRICE_UNIT_WEI: () => PRICE_UNIT_WEI,
|
|
207
213
|
Permission: () => Permission2,
|
|
@@ -377,6 +383,7 @@ var starknet = (() => {
|
|
|
377
383
|
ETransactionVersion3: () => ETransactionVersion32,
|
|
378
384
|
EVENT_ABI_TYPE: () => EVENT_ABI_TYPE,
|
|
379
385
|
L1_DA_MODE: () => L1_DA_MODE,
|
|
386
|
+
PAYMASTER_API: () => snip_29_exports,
|
|
380
387
|
PRICE_UNIT_FRI: () => PRICE_UNIT_FRI,
|
|
381
388
|
PRICE_UNIT_WEI: () => PRICE_UNIT_WEI,
|
|
382
389
|
Permission: () => Permission2,
|
|
@@ -571,6 +578,9 @@ var starknet = (() => {
|
|
|
571
578
|
LEGACY: "0"
|
|
572
579
|
};
|
|
573
580
|
|
|
581
|
+
// node_modules/starknet-types-08/dist/esm/snip-29/index.js
|
|
582
|
+
var snip_29_exports = {};
|
|
583
|
+
|
|
574
584
|
// src/utils/encode.ts
|
|
575
585
|
var encode_exports = {};
|
|
576
586
|
__export(encode_exports, {
|
|
@@ -919,6 +929,10 @@ var starknet = (() => {
|
|
|
919
929
|
`https://free-rpc.nethermind.io/sepolia-juno/`
|
|
920
930
|
]
|
|
921
931
|
};
|
|
932
|
+
var PAYMASTER_RPC_NODES = {
|
|
933
|
+
SN_MAIN: [`https://starknet.paymaster.avnu.fi`],
|
|
934
|
+
SN_SEPOLIA: [`https://sepolia.paymaster.avnu.fi`]
|
|
935
|
+
};
|
|
922
936
|
var SYSTEM_MESSAGES = {
|
|
923
937
|
legacyTxWarningMessage: "You are using a deprecated transaction version (V0,V1,V2)!\nUpdate to the latest V3 transactions!",
|
|
924
938
|
legacyTxRPC08Message: "RPC 0.8 do not support legacy transactions",
|
|
@@ -11962,7 +11976,18 @@ ${indent}}` : "}";
|
|
|
11962
11976
|
INVALID_SUBSCRIPTION_ID: 66,
|
|
11963
11977
|
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
11964
11978
|
TOO_MANY_BLOCKS_BACK: 68,
|
|
11965
|
-
COMPILATION_ERROR: 100
|
|
11979
|
+
COMPILATION_ERROR: 100,
|
|
11980
|
+
INVALID_ADDRESS: 150,
|
|
11981
|
+
TOKEN_NOT_SUPPORTED: 151,
|
|
11982
|
+
INVALID_SIGNATURE: 153,
|
|
11983
|
+
MAX_AMOUNT_TOO_LOW: 154,
|
|
11984
|
+
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
11985
|
+
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
11986
|
+
INVALID_TIME_BOUNDS: 157,
|
|
11987
|
+
INVALID_DEPLOYMENT_DATA: 158,
|
|
11988
|
+
INVALID_CLASS_HASH: 159,
|
|
11989
|
+
INVALID_ID: 160,
|
|
11990
|
+
UNKNOWN_ERROR: 163
|
|
11966
11991
|
};
|
|
11967
11992
|
var rpc_default = errorCodes;
|
|
11968
11993
|
|
|
@@ -17395,13 +17420,257 @@ ${indent}}` : "}";
|
|
|
17395
17420
|
}
|
|
17396
17421
|
}
|
|
17397
17422
|
|
|
17423
|
+
// src/utils/paymaster.ts
|
|
17424
|
+
var paymaster_exports = {};
|
|
17425
|
+
__export(paymaster_exports, {
|
|
17426
|
+
getDefaultPaymasterNodeUrl: () => getDefaultPaymasterNodeUrl
|
|
17427
|
+
});
|
|
17428
|
+
var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
|
|
17429
|
+
if (!mute) {
|
|
17430
|
+
logger.info("Using default public node url, please provide nodeUrl in provider options!");
|
|
17431
|
+
}
|
|
17432
|
+
const nodes = PAYMASTER_RPC_NODES[networkName ?? _NetworkName.SN_SEPOLIA];
|
|
17433
|
+
const randIdx = Math.floor(Math.random() * nodes.length);
|
|
17434
|
+
return nodes[randIdx];
|
|
17435
|
+
};
|
|
17436
|
+
|
|
17437
|
+
// src/paymaster/rpc.ts
|
|
17438
|
+
var convertCalls = (calls) => calls.map((call) => ({
|
|
17439
|
+
to: call.contractAddress,
|
|
17440
|
+
selector: getSelectorFromName(call.entrypoint),
|
|
17441
|
+
calldata: CallData.toHex(call.calldata)
|
|
17442
|
+
}));
|
|
17443
|
+
var convertFeeMode = (feeMode) => {
|
|
17444
|
+
if (feeMode.mode === "sponsored") {
|
|
17445
|
+
return { mode: "sponsored" };
|
|
17446
|
+
}
|
|
17447
|
+
return { mode: "default", gas_token: feeMode.gasToken };
|
|
17448
|
+
};
|
|
17449
|
+
var convertFEE_MODE = (feeMode) => {
|
|
17450
|
+
if (feeMode.mode === "sponsored") {
|
|
17451
|
+
return { mode: "sponsored" };
|
|
17452
|
+
}
|
|
17453
|
+
return { mode: "default", gasToken: feeMode.gas_token };
|
|
17454
|
+
};
|
|
17455
|
+
var convertTimeBounds = (timeBounds) => timeBounds && timeBounds.executeAfter && timeBounds.executeBefore ? {
|
|
17456
|
+
execute_after: timeBounds.executeAfter.getTime().toString(),
|
|
17457
|
+
execute_before: timeBounds.executeBefore.getTime().toString()
|
|
17458
|
+
} : void 0;
|
|
17459
|
+
var convertTIME_BOUNDS = (timeBounds) => timeBounds && timeBounds.execute_after && timeBounds.execute_before ? {
|
|
17460
|
+
executeAfter: new Date(timeBounds.execute_after),
|
|
17461
|
+
executeBefore: new Date(timeBounds.execute_before)
|
|
17462
|
+
} : void 0;
|
|
17463
|
+
var convertEXECUTION_PARAMETERS = (parameters) => ({
|
|
17464
|
+
version: parameters.version,
|
|
17465
|
+
feeMode: convertFEE_MODE(parameters.fee_mode),
|
|
17466
|
+
timeBounds: convertTIME_BOUNDS(parameters.time_bounds)
|
|
17467
|
+
});
|
|
17468
|
+
var defaultOptions3 = {
|
|
17469
|
+
headers: { "Content-Type": "application/json" }
|
|
17470
|
+
};
|
|
17471
|
+
var PaymasterRpc = class _PaymasterRpc {
|
|
17472
|
+
nodeUrl;
|
|
17473
|
+
headers;
|
|
17474
|
+
baseFetch;
|
|
17475
|
+
requestId;
|
|
17476
|
+
constructor(options) {
|
|
17477
|
+
if (options instanceof _PaymasterRpc) {
|
|
17478
|
+
this.nodeUrl = options.nodeUrl;
|
|
17479
|
+
this.headers = { ...defaultOptions3.headers, ...options.headers };
|
|
17480
|
+
this.baseFetch = options.baseFetch;
|
|
17481
|
+
this.requestId = options.requestId;
|
|
17482
|
+
return;
|
|
17483
|
+
}
|
|
17484
|
+
if (options && "nodeUrl" in options && "headers" in options && "baseFetch" in options) {
|
|
17485
|
+
this.nodeUrl = options.nodeUrl ?? getDefaultPaymasterNodeUrl(void 0);
|
|
17486
|
+
this.headers = { ...defaultOptions3.headers, ...options.headers };
|
|
17487
|
+
this.baseFetch = options.baseFetch ?? fetch_default;
|
|
17488
|
+
this.requestId = 0;
|
|
17489
|
+
return;
|
|
17490
|
+
}
|
|
17491
|
+
const { nodeUrl, headers, baseFetch } = options || {};
|
|
17492
|
+
if (nodeUrl && Object.values(_NetworkName).includes(nodeUrl)) {
|
|
17493
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(nodeUrl, options?.default);
|
|
17494
|
+
} else if (nodeUrl) {
|
|
17495
|
+
this.nodeUrl = nodeUrl;
|
|
17496
|
+
} else {
|
|
17497
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(void 0, options?.default);
|
|
17498
|
+
}
|
|
17499
|
+
this.baseFetch = baseFetch ?? fetch_default;
|
|
17500
|
+
this.headers = { ...defaultOptions3.headers, ...headers };
|
|
17501
|
+
this.requestId = 0;
|
|
17502
|
+
}
|
|
17503
|
+
fetch(method, params, id = 0) {
|
|
17504
|
+
const rpcRequestBody = {
|
|
17505
|
+
id,
|
|
17506
|
+
jsonrpc: "2.0",
|
|
17507
|
+
method,
|
|
17508
|
+
...params && { params }
|
|
17509
|
+
};
|
|
17510
|
+
return this.baseFetch(this.nodeUrl, {
|
|
17511
|
+
method: "POST",
|
|
17512
|
+
body: stringify2(rpcRequestBody),
|
|
17513
|
+
headers: this.headers
|
|
17514
|
+
});
|
|
17515
|
+
}
|
|
17516
|
+
errorHandler(method, params, rpcError, otherError) {
|
|
17517
|
+
if (rpcError) {
|
|
17518
|
+
throw new RpcError(rpcError, method, params);
|
|
17519
|
+
}
|
|
17520
|
+
if (otherError instanceof LibraryError) {
|
|
17521
|
+
throw otherError;
|
|
17522
|
+
}
|
|
17523
|
+
if (otherError) {
|
|
17524
|
+
throw Error(otherError.message);
|
|
17525
|
+
}
|
|
17526
|
+
}
|
|
17527
|
+
async fetchEndpoint(method, params) {
|
|
17528
|
+
try {
|
|
17529
|
+
this.requestId += 1;
|
|
17530
|
+
const rawResult = await this.fetch(method, params, this.requestId);
|
|
17531
|
+
const { error, result } = await rawResult.json();
|
|
17532
|
+
this.errorHandler(method, params, error);
|
|
17533
|
+
return result;
|
|
17534
|
+
} catch (error) {
|
|
17535
|
+
this.errorHandler(method, params, error?.response?.data, error);
|
|
17536
|
+
throw error;
|
|
17537
|
+
}
|
|
17538
|
+
}
|
|
17539
|
+
async isAvailable() {
|
|
17540
|
+
return this.fetchEndpoint("paymaster_isAvailable");
|
|
17541
|
+
}
|
|
17542
|
+
async buildTransaction(transaction, parameters) {
|
|
17543
|
+
let userTransaction;
|
|
17544
|
+
switch (transaction.type) {
|
|
17545
|
+
case "invoke":
|
|
17546
|
+
userTransaction = {
|
|
17547
|
+
...transaction,
|
|
17548
|
+
invoke: {
|
|
17549
|
+
user_address: transaction.invoke.userAddress,
|
|
17550
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
17551
|
+
}
|
|
17552
|
+
};
|
|
17553
|
+
break;
|
|
17554
|
+
case "deploy_and_invoke":
|
|
17555
|
+
userTransaction = {
|
|
17556
|
+
...transaction,
|
|
17557
|
+
invoke: {
|
|
17558
|
+
user_address: transaction.invoke.userAddress,
|
|
17559
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
17560
|
+
}
|
|
17561
|
+
};
|
|
17562
|
+
break;
|
|
17563
|
+
case "deploy":
|
|
17564
|
+
default:
|
|
17565
|
+
userTransaction = transaction;
|
|
17566
|
+
break;
|
|
17567
|
+
}
|
|
17568
|
+
const executionParameters = {
|
|
17569
|
+
version: parameters.version,
|
|
17570
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
17571
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
17572
|
+
};
|
|
17573
|
+
const response = await this.fetchEndpoint("paymaster_buildTransaction", {
|
|
17574
|
+
transaction: userTransaction,
|
|
17575
|
+
parameters: executionParameters
|
|
17576
|
+
});
|
|
17577
|
+
const fee = {
|
|
17578
|
+
gas_token_price_in_strk: BigInt(response.fee.gas_token_price_in_strk),
|
|
17579
|
+
estimated_fee_in_strk: BigInt(response.fee.estimated_fee_in_strk),
|
|
17580
|
+
estimated_fee_in_gas_token: BigInt(response.fee.estimated_fee_in_gas_token),
|
|
17581
|
+
suggested_max_fee_in_strk: BigInt(response.fee.suggested_max_fee_in_strk),
|
|
17582
|
+
suggested_max_fee_in_gas_token: BigInt(response.fee.suggested_max_fee_in_gas_token)
|
|
17583
|
+
};
|
|
17584
|
+
switch (response.type) {
|
|
17585
|
+
case "invoke":
|
|
17586
|
+
return {
|
|
17587
|
+
type: "invoke",
|
|
17588
|
+
typed_data: response.typed_data,
|
|
17589
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17590
|
+
fee
|
|
17591
|
+
};
|
|
17592
|
+
case "deploy_and_invoke":
|
|
17593
|
+
return {
|
|
17594
|
+
type: "deploy_and_invoke",
|
|
17595
|
+
deployment: response.deployment,
|
|
17596
|
+
typed_data: response.typed_data,
|
|
17597
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17598
|
+
fee
|
|
17599
|
+
};
|
|
17600
|
+
case "deploy":
|
|
17601
|
+
default:
|
|
17602
|
+
return {
|
|
17603
|
+
type: "deploy",
|
|
17604
|
+
deployment: response.deployment,
|
|
17605
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17606
|
+
fee
|
|
17607
|
+
};
|
|
17608
|
+
}
|
|
17609
|
+
}
|
|
17610
|
+
async executeTransaction(transaction, parameters) {
|
|
17611
|
+
let user_transaction;
|
|
17612
|
+
switch (transaction.type) {
|
|
17613
|
+
case "invoke":
|
|
17614
|
+
user_transaction = {
|
|
17615
|
+
...transaction,
|
|
17616
|
+
invoke: {
|
|
17617
|
+
user_address: transaction.invoke.userAddress,
|
|
17618
|
+
typed_data: transaction.invoke.typedData,
|
|
17619
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
17620
|
+
}
|
|
17621
|
+
};
|
|
17622
|
+
break;
|
|
17623
|
+
case "deploy_and_invoke":
|
|
17624
|
+
user_transaction = {
|
|
17625
|
+
...transaction,
|
|
17626
|
+
invoke: {
|
|
17627
|
+
user_address: transaction.invoke.userAddress,
|
|
17628
|
+
typed_data: transaction.invoke.typedData,
|
|
17629
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
17630
|
+
}
|
|
17631
|
+
};
|
|
17632
|
+
break;
|
|
17633
|
+
case "deploy":
|
|
17634
|
+
default:
|
|
17635
|
+
user_transaction = transaction;
|
|
17636
|
+
break;
|
|
17637
|
+
}
|
|
17638
|
+
const executionParameters = {
|
|
17639
|
+
version: parameters.version,
|
|
17640
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
17641
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
17642
|
+
};
|
|
17643
|
+
return this.fetchEndpoint("paymaster_executeTransaction", {
|
|
17644
|
+
transaction: user_transaction,
|
|
17645
|
+
parameters: executionParameters
|
|
17646
|
+
});
|
|
17647
|
+
}
|
|
17648
|
+
async getSupportedTokens() {
|
|
17649
|
+
return this.fetchEndpoint("paymaster_getSupportedTokens").then(
|
|
17650
|
+
(tokens) => tokens.map((token) => ({
|
|
17651
|
+
token_address: token.token_address,
|
|
17652
|
+
decimals: token.decimals,
|
|
17653
|
+
priceInStrk: BigInt(token.price_in_strk)
|
|
17654
|
+
}))
|
|
17655
|
+
);
|
|
17656
|
+
}
|
|
17657
|
+
};
|
|
17658
|
+
|
|
17659
|
+
// src/paymaster/interface.ts
|
|
17660
|
+
var PaymasterInterface = class {
|
|
17661
|
+
};
|
|
17662
|
+
|
|
17663
|
+
// src/paymaster/index.ts
|
|
17664
|
+
var defaultPaymaster = new PaymasterRpc({ default: true });
|
|
17665
|
+
|
|
17398
17666
|
// src/account/default.ts
|
|
17399
17667
|
var Account = class extends RpcProvider2 {
|
|
17400
17668
|
signer;
|
|
17401
17669
|
address;
|
|
17402
17670
|
cairoVersion;
|
|
17403
17671
|
transactionVersion;
|
|
17404
|
-
|
|
17672
|
+
paymaster;
|
|
17673
|
+
constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = config.get("transactionVersion"), paymaster) {
|
|
17405
17674
|
super(providerOrOptions);
|
|
17406
17675
|
this.address = address.toLowerCase();
|
|
17407
17676
|
this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
@@ -17409,6 +17678,7 @@ ${indent}}` : "}";
|
|
|
17409
17678
|
this.cairoVersion = cairoVersion.toString();
|
|
17410
17679
|
}
|
|
17411
17680
|
this.transactionVersion = transactionVersion;
|
|
17681
|
+
this.paymaster = paymaster ? new PaymasterRpc(paymaster) : defaultPaymaster;
|
|
17412
17682
|
logger.debug("Account setup", {
|
|
17413
17683
|
transactionVersion: this.transactionVersion,
|
|
17414
17684
|
cairoVersion: this.cairoVersion,
|
|
@@ -17601,6 +17871,13 @@ ${indent}}` : "}";
|
|
|
17601
17871
|
}
|
|
17602
17872
|
async execute(transactions, transactionsDetail = {}) {
|
|
17603
17873
|
const calls = Array.isArray(transactions) ? transactions : [transactions];
|
|
17874
|
+
if (transactionsDetail.paymaster) {
|
|
17875
|
+
return this.executePaymasterTransaction(
|
|
17876
|
+
calls,
|
|
17877
|
+
transactionsDetail.paymaster,
|
|
17878
|
+
transactionsDetail.maxFee
|
|
17879
|
+
);
|
|
17880
|
+
}
|
|
17604
17881
|
const nonce = toBigInt(transactionsDetail.nonce ?? await this.getNonce());
|
|
17605
17882
|
const version = toTransactionVersion(
|
|
17606
17883
|
this.getPreferredVersion(ETransactionVersion5.V1, ETransactionVersion5.V3),
|
|
@@ -17639,6 +17916,88 @@ ${indent}}` : "}";
|
|
|
17639
17916
|
}
|
|
17640
17917
|
);
|
|
17641
17918
|
}
|
|
17919
|
+
async buildPaymasterTransaction(calls, paymasterDetails) {
|
|
17920
|
+
if (!paymasterDetails.deploymentData) {
|
|
17921
|
+
const snip9Version = await this.getSnip9Version();
|
|
17922
|
+
if (snip9Version === OutsideExecutionVersion.UNSUPPORTED) {
|
|
17923
|
+
throw Error("Account is not compatible with SNIP-9");
|
|
17924
|
+
}
|
|
17925
|
+
}
|
|
17926
|
+
const parameters = {
|
|
17927
|
+
version: "0x1",
|
|
17928
|
+
feeMode: paymasterDetails.feeMode,
|
|
17929
|
+
timeBounds: paymasterDetails.timeBounds
|
|
17930
|
+
};
|
|
17931
|
+
let transaction;
|
|
17932
|
+
if (paymasterDetails.deploymentData) {
|
|
17933
|
+
if (calls.length > 0) {
|
|
17934
|
+
transaction = {
|
|
17935
|
+
type: "deploy_and_invoke",
|
|
17936
|
+
invoke: { userAddress: this.address, calls },
|
|
17937
|
+
deployment: paymasterDetails.deploymentData
|
|
17938
|
+
};
|
|
17939
|
+
} else {
|
|
17940
|
+
transaction = {
|
|
17941
|
+
type: "deploy",
|
|
17942
|
+
deployment: paymasterDetails.deploymentData
|
|
17943
|
+
};
|
|
17944
|
+
}
|
|
17945
|
+
} else {
|
|
17946
|
+
transaction = {
|
|
17947
|
+
type: "invoke",
|
|
17948
|
+
invoke: { userAddress: this.address, calls }
|
|
17949
|
+
};
|
|
17950
|
+
}
|
|
17951
|
+
return this.paymaster.buildTransaction(transaction, parameters);
|
|
17952
|
+
}
|
|
17953
|
+
async estimatePaymasterTransactionFee(calls, paymasterDetails) {
|
|
17954
|
+
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
17955
|
+
return preparedTransaction.fee;
|
|
17956
|
+
}
|
|
17957
|
+
async executePaymasterTransaction(calls, paymasterDetails, maxFee) {
|
|
17958
|
+
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
17959
|
+
if (maxFee && preparedTransaction.fee.gas_token_price_in_strk > maxFee) {
|
|
17960
|
+
throw Error("Gas token price is too high");
|
|
17961
|
+
}
|
|
17962
|
+
let transaction;
|
|
17963
|
+
switch (preparedTransaction.type) {
|
|
17964
|
+
case "deploy_and_invoke": {
|
|
17965
|
+
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
17966
|
+
transaction = {
|
|
17967
|
+
type: "deploy_and_invoke",
|
|
17968
|
+
invoke: {
|
|
17969
|
+
userAddress: this.address,
|
|
17970
|
+
typedData: preparedTransaction.typed_data,
|
|
17971
|
+
signature: signatureToHexArray(signature)
|
|
17972
|
+
},
|
|
17973
|
+
deployment: preparedTransaction.deployment
|
|
17974
|
+
};
|
|
17975
|
+
break;
|
|
17976
|
+
}
|
|
17977
|
+
case "invoke": {
|
|
17978
|
+
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
17979
|
+
transaction = {
|
|
17980
|
+
type: "invoke",
|
|
17981
|
+
invoke: {
|
|
17982
|
+
userAddress: this.address,
|
|
17983
|
+
typedData: preparedTransaction.typed_data,
|
|
17984
|
+
signature: signatureToHexArray(signature)
|
|
17985
|
+
}
|
|
17986
|
+
};
|
|
17987
|
+
break;
|
|
17988
|
+
}
|
|
17989
|
+
case "deploy": {
|
|
17990
|
+
transaction = {
|
|
17991
|
+
type: "deploy",
|
|
17992
|
+
deployment: preparedTransaction.deployment
|
|
17993
|
+
};
|
|
17994
|
+
break;
|
|
17995
|
+
}
|
|
17996
|
+
default:
|
|
17997
|
+
throw Error("Invalid transaction type");
|
|
17998
|
+
}
|
|
17999
|
+
return this.paymaster.executeTransaction(transaction, preparedTransaction.parameters).then((response) => ({ transaction_hash: response.transaction_hash }));
|
|
18000
|
+
}
|
|
17642
18001
|
/**
|
|
17643
18002
|
* First check if contract is already declared, if not declare it
|
|
17644
18003
|
* If contract already declared returned transaction_hash is ''.
|
|
@@ -18185,8 +18544,8 @@ ${indent}}` : "}";
|
|
|
18185
18544
|
// src/wallet/account.ts
|
|
18186
18545
|
var WalletAccount = class _WalletAccount extends Account {
|
|
18187
18546
|
walletProvider;
|
|
18188
|
-
constructor(providerOrOptions, walletProvider, address, cairoVersion) {
|
|
18189
|
-
super(providerOrOptions, address, "", cairoVersion);
|
|
18547
|
+
constructor(providerOrOptions, walletProvider, address, cairoVersion, paymaster) {
|
|
18548
|
+
super(providerOrOptions, address, "", cairoVersion, void 0, paymaster);
|
|
18190
18549
|
this.walletProvider = walletProvider;
|
|
18191
18550
|
this.walletProvider.on("accountsChanged", (res) => {
|
|
18192
18551
|
if (!res) return;
|
|
@@ -18227,7 +18586,14 @@ ${indent}}` : "}";
|
|
|
18227
18586
|
/**
|
|
18228
18587
|
* ACCOUNT METHODS
|
|
18229
18588
|
*/
|
|
18230
|
-
execute(calls) {
|
|
18589
|
+
execute(calls, arg2, transactionsDetail = {}) {
|
|
18590
|
+
const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
|
|
18591
|
+
if (details.paymaster) {
|
|
18592
|
+
return this.executePaymasterTransaction(
|
|
18593
|
+
Array.isArray(calls) ? calls : [calls],
|
|
18594
|
+
details.paymaster
|
|
18595
|
+
);
|
|
18596
|
+
}
|
|
18231
18597
|
const txCalls = [].concat(calls).map((it) => {
|
|
18232
18598
|
const { contractAddress, entrypoint, calldata } = it;
|
|
18233
18599
|
return {
|
|
@@ -18268,12 +18634,12 @@ ${indent}}` : "}";
|
|
|
18268
18634
|
signMessage(typedData) {
|
|
18269
18635
|
return signMessage(this.walletProvider, typedData);
|
|
18270
18636
|
}
|
|
18271
|
-
static async connect(provider, walletProvider, cairoVersion, silentMode = false) {
|
|
18637
|
+
static async connect(provider, walletProvider, cairoVersion, paymaster, silentMode = false) {
|
|
18272
18638
|
const [accountAddress] = await requestAccounts(walletProvider, silentMode);
|
|
18273
|
-
return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion);
|
|
18639
|
+
return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion, paymaster);
|
|
18274
18640
|
}
|
|
18275
|
-
static async connectSilent(provider, walletProvider, cairoVersion) {
|
|
18276
|
-
return _WalletAccount.connect(provider, walletProvider, cairoVersion, true);
|
|
18641
|
+
static async connectSilent(provider, walletProvider, cairoVersion, paymaster) {
|
|
18642
|
+
return _WalletAccount.connect(provider, walletProvider, cairoVersion, paymaster, true);
|
|
18277
18643
|
}
|
|
18278
18644
|
// TODO: MISSING ESTIMATES
|
|
18279
18645
|
};
|