@argent/x-shared 1.62.2 → 1.62.3
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/src/features/paymaster/IPaymasterService.d.ts +3 -6
- package/dist/src/features/paymaster/PaymasterService.cjs +1 -1
- package/dist/src/features/paymaster/PaymasterService.d.ts +3 -6
- package/dist/src/features/paymaster/PaymasterService.js +30 -30
- package/dist/src/features/paymaster/types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { TypedData } from 'starknet';
|
|
2
|
-
import { PaymasterExecutionDataParams, PaymasterExecuteParams } from './types';
|
|
2
|
+
import { PaymasterExecutionDataParams, PaymasterExecuteParams, PaymasterOptions } from './types';
|
|
3
3
|
export interface IPaymasterService {
|
|
4
|
-
getExecutionData(params: PaymasterExecutionDataParams,
|
|
5
|
-
execute(params: PaymasterExecuteParams, options?:
|
|
6
|
-
useAvnu?: boolean;
|
|
7
|
-
isSubsidised?: boolean;
|
|
8
|
-
}): Promise<string>;
|
|
4
|
+
getExecutionData(params: PaymasterExecutionDataParams, options?: PaymasterOptions): Promise<TypedData>;
|
|
5
|
+
execute(params: PaymasterExecuteParams, options?: PaymasterOptions): Promise<string>;
|
|
9
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("starknet"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("starknet"),d=require("url-join"),y=require("./types.cjs"),h=require("../../utils/starknet/starknet.cjs");class f{constructor(e="",t){this.argentRelayerUrl=e,this.httpService=t}async getExecutionData(e,t={}){const{useAvnu:n,isSubsidised:a}=t,r=d(n?this.getAvnuUrl(e.networkId):this.argentRelayerUrl,"/build-typed-data"),i={calls:n?e.calls.map(c=>({contractAddress:s.num.toHex(c.contractAddress),calldata:s.CallData.toCalldata(c.calldata).map(p=>s.num.toHex(p)),entrypoint:c.entrypoint})):e.calls,userAddress:e.accountAddress,gasTokenAddress:a?null:s.num.toHex(e.feeTokenAddress),maxGasTokenAmount:a?null:s.num.toHex(e.feeTokenAddress),accountClassHash:e.accountClassHash},o=await this.httpService.post(r,{body:s.json.stringify(i),headers:{"Content-Type":"application/json"}}),u=h.typedDataSchema.safeParse(o);if(!u.success)throw new Error("Invalid response from paymaster");return u.data}getAvnuUrl(e){if(!e)throw new Error("Network id is required for Avnu paymaster");let t="";if(e==="mainnet"||e==="mainnet-alpha")t="starknet";else if(e==="sepolia"||e==="sepolia-alpha")t="sepolia";else throw new Error("Invalid network id");return`https://${t}.api.avnu.fi/paymaster/v1`}async execute(e,t={}){const{useAvnu:n,isSubsidised:a}=t;let r=d(n?this.getAvnuUrl(e.networkId):this.argentRelayerUrl,"/execute");a&&(r=d(r,"?isSubsidised=true"));const l={signature:e.signature,userAddress:e.accountAddress,typedData:n?s.json.stringify(e.typedData):e.typedData,deploymentData:e.deploymentData},i=await this.httpService.post(r,{body:s.json.stringify(l),headers:{"Content-Type":"application/json"}}),o=y.paymasterExecuteResponse.safeParse(i);if(!o.success)throw new Error("Invalid response from paymaster");return o.data.transactionHash}}exports.PaymasterService=f;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { TypedData } from '@starknet-io/types-js';
|
|
2
2
|
import { IHttpService } from '../../http';
|
|
3
3
|
import { IPaymasterService } from './IPaymasterService';
|
|
4
|
-
import { PaymasterExecuteParams, PaymasterExecutionDataParams } from './types';
|
|
4
|
+
import { PaymasterOptions, PaymasterExecuteParams, PaymasterExecutionDataParams } from './types';
|
|
5
5
|
export declare class PaymasterService implements IPaymasterService {
|
|
6
6
|
private readonly argentRelayerUrl;
|
|
7
7
|
private readonly httpService;
|
|
8
8
|
constructor(argentRelayerUrl: string | undefined, httpService: IHttpService);
|
|
9
|
-
getExecutionData(params: PaymasterExecutionDataParams,
|
|
9
|
+
getExecutionData(params: PaymasterExecutionDataParams, options?: PaymasterOptions): Promise<TypedData>;
|
|
10
10
|
getAvnuUrl(networkId?: string): string;
|
|
11
|
-
execute(params: PaymasterExecuteParams, options?:
|
|
12
|
-
useAvnu?: boolean;
|
|
13
|
-
isSubsidised?: boolean;
|
|
14
|
-
}): Promise<string>;
|
|
11
|
+
execute(params: PaymasterExecuteParams, options?: PaymasterOptions): Promise<string>;
|
|
15
12
|
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { CallData as
|
|
2
|
-
import
|
|
3
|
-
import { paymasterExecuteResponse as
|
|
4
|
-
import { typedDataSchema as
|
|
5
|
-
class
|
|
1
|
+
import { CallData as h, num as o, json as l } from "starknet";
|
|
2
|
+
import c from "url-join";
|
|
3
|
+
import { paymasterExecuteResponse as f } from "./types.js";
|
|
4
|
+
import { typedDataSchema as A } from "../../utils/starknet/starknet.js";
|
|
5
|
+
class b {
|
|
6
6
|
constructor(e = "", t) {
|
|
7
7
|
this.argentRelayerUrl = e, this.httpService = t;
|
|
8
8
|
}
|
|
9
|
-
async getExecutionData(e, t =
|
|
10
|
-
const r =
|
|
11
|
-
calls:
|
|
12
|
-
contractAddress: o.toHex(
|
|
13
|
-
calldata:
|
|
14
|
-
entrypoint:
|
|
9
|
+
async getExecutionData(e, t = {}) {
|
|
10
|
+
const { useAvnu: s, isSubsidised: a } = t, r = c(s ? this.getAvnuUrl(e.networkId) : this.argentRelayerUrl, "/build-typed-data"), i = {
|
|
11
|
+
calls: s ? e.calls.map((d) => ({
|
|
12
|
+
contractAddress: o.toHex(d.contractAddress),
|
|
13
|
+
calldata: h.toCalldata(d.calldata).map((y) => o.toHex(y)),
|
|
14
|
+
entrypoint: d.entrypoint
|
|
15
15
|
})) : e.calls,
|
|
16
16
|
userAddress: e.accountAddress,
|
|
17
|
-
gasTokenAddress: o.toHex(e.feeTokenAddress),
|
|
18
|
-
maxGasTokenAmount: o.toHex(e.
|
|
17
|
+
gasTokenAddress: a ? null : o.toHex(e.feeTokenAddress),
|
|
18
|
+
maxGasTokenAmount: a ? null : o.toHex(e.feeTokenAddress),
|
|
19
19
|
accountClassHash: e.accountClassHash
|
|
20
|
-
},
|
|
21
|
-
body:
|
|
20
|
+
}, n = await this.httpService.post(r, {
|
|
21
|
+
body: l.stringify(i),
|
|
22
22
|
headers: {
|
|
23
23
|
"Content-Type": "application/json"
|
|
24
24
|
}
|
|
25
|
-
}),
|
|
26
|
-
if (!
|
|
25
|
+
}), p = A.safeParse(n);
|
|
26
|
+
if (!p.success)
|
|
27
27
|
throw new Error("Invalid response from paymaster");
|
|
28
|
-
return
|
|
28
|
+
return p.data;
|
|
29
29
|
}
|
|
30
30
|
getAvnuUrl(e) {
|
|
31
31
|
if (!e)
|
|
@@ -39,26 +39,26 @@ class x {
|
|
|
39
39
|
throw new Error("Invalid network id");
|
|
40
40
|
return `https://${t}.api.avnu.fi/paymaster/v1`;
|
|
41
41
|
}
|
|
42
|
-
async execute(e, t) {
|
|
43
|
-
const { useAvnu:
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
const
|
|
42
|
+
async execute(e, t = {}) {
|
|
43
|
+
const { useAvnu: s, isSubsidised: a } = t;
|
|
44
|
+
let r = c(s ? this.getAvnuUrl(e.networkId) : this.argentRelayerUrl, "/execute");
|
|
45
|
+
a && (r = c(r, "?isSubsidised=true"));
|
|
46
|
+
const u = {
|
|
47
47
|
signature: e.signature,
|
|
48
48
|
userAddress: e.accountAddress,
|
|
49
|
-
typedData:
|
|
49
|
+
typedData: s ? l.stringify(e.typedData) : e.typedData,
|
|
50
50
|
deploymentData: e.deploymentData
|
|
51
|
-
},
|
|
52
|
-
body:
|
|
51
|
+
}, i = await this.httpService.post(r, {
|
|
52
|
+
body: l.stringify(u),
|
|
53
53
|
headers: {
|
|
54
54
|
"Content-Type": "application/json"
|
|
55
55
|
}
|
|
56
|
-
}),
|
|
57
|
-
if (!
|
|
56
|
+
}), n = f.safeParse(i);
|
|
57
|
+
if (!n.success)
|
|
58
58
|
throw new Error("Invalid response from paymaster");
|
|
59
|
-
return
|
|
59
|
+
return n.data.transactionHash;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
export {
|
|
63
|
-
|
|
63
|
+
b as PaymasterService
|
|
64
64
|
};
|
|
@@ -177,3 +177,7 @@ export declare const paymasterExecuteResponse: z.ZodObject<{
|
|
|
177
177
|
transactionHash: string;
|
|
178
178
|
}>;
|
|
179
179
|
export type PaymasterExecuteResponse = z.infer<typeof paymasterExecuteResponse>;
|
|
180
|
+
export type PaymasterOptions = {
|
|
181
|
+
useAvnu?: boolean;
|
|
182
|
+
isSubsidised?: boolean;
|
|
183
|
+
};
|