@argent/x-shared 1.39.0 → 1.40.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.
@@ -1,2 +1,3 @@
1
1
  export * from './seedphrase';
2
2
  export * from './multisigner';
3
+ export * from './mergeOwnerGuardianSignatures';
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("lodash-es"),n=require("starknet"),d=require("../chains/starknet/services/deploymentData/getAccountClassHash.cjs"),S=require("../chains/starknet/address.cjs"),m=async({ownerPubKey:e,ownerSignature:t,guardianPubKey:r,guardianSignature:s,classHash:c})=>{const a=l.isEmpty(s);if(p(c)){const i=o(e,t);if(a)return u(i);const g=o(r,s);return u(i,g)}return a?[t].flatMap(n.stark.signatureToDecimalArray):[t,s].flatMap(n.stark.signatureToDecimalArray)},o=(e,t)=>{const r=n.stark.formatSignature(t);return new n.CairoCustomEnum({Starknet:{signer:e,r:r[0],s:r[1]},Secp256k1:void 0,Secp256r1:void 0,Eip191:void 0,Webauthn:void 0})},u=(...e)=>{const t=e.length.toString(),r=n.CallData.compile(e);return[t,...r]},p=e=>d.getArgentAccountWithMultiSignerClassHashes().some(t=>S.isEqualAddress(t,e));exports.mergeOwnerGuardianSignatures=m;
@@ -0,0 +1,26 @@
1
+ import { Signature } from 'starknet';
2
+ interface MergeOwnerGuardianSignaturesParams {
3
+ ownerPubKey: string;
4
+ ownerSignature: Signature;
5
+ guardianPubKey: string;
6
+ guardianSignature: Signature;
7
+ classHash: string | undefined;
8
+ }
9
+ /**
10
+ * Merges the owner and guardian signatures into a single signature.
11
+ *
12
+ * @param {Object} params - The parameters for merging signatures.
13
+ * @param {string} params.ownerPubKey - The public key of the owner.
14
+ * @param {Signature} params.ownerSignature - The signature of the owner.
15
+ * @param {string} params.guardianPubKey - The public key of the guardian.
16
+ * @param {Signature} params.guardianSignature - The signature of the guardian.
17
+ * @param {string} params.classHash - The class hash of the account.
18
+ * @returns {Promise<Signature>} - A promise that resolves to the merged signature.
19
+ *
20
+ * @remarks
21
+ * - If the guardian signature is empty, it indicates that a co-signer is not required.
22
+ * - If multi-signer support is enabled, the signatures are formatted and prepended with their lengths.
23
+ * - If multi-signer support is not enabled, the signatures are converted to decimal arrays.
24
+ */
25
+ declare const mergeOwnerGuardianSignatures: ({ ownerPubKey, ownerSignature, guardianPubKey, guardianSignature, classHash, }: MergeOwnerGuardianSignaturesParams) => Promise<Signature>;
26
+ export { mergeOwnerGuardianSignatures };
@@ -0,0 +1,30 @@
1
+ import { isEmpty as p } from "lodash-es";
2
+ import { stark as i, CairoCustomEnum as g, CallData as l } from "starknet";
3
+ import { getArgentAccountWithMultiSignerClassHashes as S } from "../chains/starknet/services/deploymentData/getAccountClassHash.js";
4
+ import { isEqualAddress as d } from "../chains/starknet/address.js";
5
+ const y = async ({ ownerPubKey: r, ownerSignature: t, guardianPubKey: n, guardianSignature: e, classHash: c }) => {
6
+ const o = p(e);
7
+ if (f(c)) {
8
+ const a = s(r, t);
9
+ if (o)
10
+ return u(a);
11
+ const m = s(n, e);
12
+ return u(a, m);
13
+ }
14
+ return o ? [t].flatMap(i.signatureToDecimalArray) : [t, e].flatMap(i.signatureToDecimalArray);
15
+ }, s = (r, t) => {
16
+ const n = i.formatSignature(t);
17
+ return new g({
18
+ Starknet: { signer: r, r: n[0], s: n[1] },
19
+ Secp256k1: void 0,
20
+ Secp256r1: void 0,
21
+ Eip191: void 0,
22
+ Webauthn: void 0
23
+ });
24
+ }, u = (...r) => {
25
+ const t = r.length.toString(), n = l.compile(r);
26
+ return [t, ...n];
27
+ }, f = (r) => S().some((t) => d(t, r));
28
+ export {
29
+ y as mergeOwnerGuardianSignatures
30
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("async-retry"),c=require("url-join"),r=require("./types/backend.model.cjs"),d=require("../../utils/schemas.cjs");class u{constructor(s,e){this.apiBase=s,this.httpService=e,this.TOKENS_INFO_URL="/tokens/info",this.TOKENS_DEFI_DECOMPOSITION_URL="/tokens/defi/decomposition"}async fetchTokensInfoFromBackend(s){const e=c(this.apiBase,this.TOKENS_INFO_URL,s??"","?chain=starknet"),t=await this.httpService.get(e),n=r.apiTokensInfoResponseSchema.safeParse(t);if(n.success)return n.data.tokens;const o=r.apiTokenInfoResponseSchema.safeParse(t);if(o.success)return[o.data]}async fetchAddressTokenBalancesFromBackend(s,e,t){const n=c(this.apiBase,"activity","starknet",e,"account",s,"balance");return(await p(async a=>{let h;try{h=await this.httpService.get(n)}catch{return a(new Error("Error fetching")),[]}const i=r.apiAccountTokenBalancesSchema.safeParse(h);if(!i.success)return a(new Error("Error parsing response")),[];if(i.data.status!=="initialised")throw new Error("Not initialised yet");return i.data.balances},{retries:5,minTimeout:5e3,...t})).map(a=>({address:a.tokenAddress,balance:a.tokenBalance,networkId:e}))}async fetchDefiDecomposition(s){const e=c(this.apiBase,this.TOKENS_DEFI_DECOMPOSITION_URL,s,"?chain=starknet"),t=await this.httpService.get(e);return d.safeParseAndWarn(r.apiDefiPositionsSchema,t).success||console.error("Backend schema has changed. Make the changes to the models to prevent unknown/unhandled errors."),t.dapps}}exports.TokenServiceWeb=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("async-retry"),c=require("url-join"),o=require("./types/backend.model.cjs"),d=require("../../utils/schemas.cjs");class u{constructor(s,e){this.apiBase=s,this.httpService=e,this.TOKENS_INFO_URL="/tokens/info"}async fetchTokensInfoFromBackend(s){const e=c(this.apiBase,this.TOKENS_INFO_URL,s??"","?chain=starknet"),t=await this.httpService.get(e),n=o.apiTokensInfoResponseSchema.safeParse(t);if(n.success)return n.data.tokens;const r=o.apiTokenInfoResponseSchema.safeParse(t);if(r.success)return[r.data]}async fetchAddressTokenBalancesFromBackend(s,e,t){const n=c(this.apiBase,"activity","starknet",e,"account",s,"balance");return(await h(async a=>{let p;try{p=await this.httpService.get(n)}catch{return a(new Error("Error fetching")),[]}const i=o.apiAccountTokenBalancesSchema.safeParse(p);if(!i.success)return a(new Error("Error parsing response")),[];if(i.data.status!=="initialised")throw new Error("Not initialised yet");return i.data.balances},{retries:5,minTimeout:5e3,...t})).map(a=>({address:a.tokenAddress,balance:a.tokenBalance,networkId:e}))}async fetchDefiDecomposition(s,e){const t=c(this.apiBase,"tokens/defi",s,"investments","?chain=starknet",`&application=${e}`),n=await this.httpService.get(t);return d.safeParseAndWarn(o.apiDefiPositionsSchema,n).success||console.error("Backend schema has changed. Make the changes to the models to prevent unknown/unhandled errors."),n.dapps}}exports.TokenServiceWeb=u;
@@ -12,7 +12,6 @@ export declare class TokenServiceWeb implements ITokenServiceWeb {
12
12
  protected readonly apiBase: string;
13
13
  protected readonly httpService: IHttpService;
14
14
  private readonly TOKENS_INFO_URL;
15
- private readonly TOKENS_DEFI_DECOMPOSITION_URL;
16
15
  constructor(apiBase: string, httpService: IHttpService);
17
16
  /**
18
17
  * Fetch tokens info from backend
@@ -26,7 +25,7 @@ export declare class TokenServiceWeb implements ITokenServiceWeb {
26
25
  * @returns {Promise<WebBaseTokenWithBalance[]>} - The fetched balances for the account address.
27
26
  */
28
27
  fetchAddressTokenBalancesFromBackend(address: string, network: ArgentBackendNetworkId, opts?: retry.Options): Promise<WebBaseTokenWithBalance[]>;
29
- fetchDefiDecomposition(address: Address): Promise<{
28
+ fetchDefiDecomposition(address: Address, application: "mobile" | "webwallet" | "argentx"): Promise<{
30
29
  dappId: string;
31
30
  products: import('zod').objectOutputType<{
32
31
  name: import('zod').ZodString;
@@ -2,9 +2,9 @@ import p from "async-retry";
2
2
  import i from "url-join";
3
3
  import { apiTokensInfoResponseSchema as h, apiTokenInfoResponseSchema as d, apiAccountTokenBalancesSchema as u, apiDefiPositionsSchema as f } from "./types/backend.model.js";
4
4
  import { safeParseAndWarn as k } from "../../utils/schemas.js";
5
- class O {
5
+ class R {
6
6
  constructor(s, e) {
7
- this.apiBase = s, this.httpService = e, this.TOKENS_INFO_URL = "/tokens/info", this.TOKENS_DEFI_DECOMPOSITION_URL = "/tokens/defi/decomposition";
7
+ this.apiBase = s, this.httpService = e, this.TOKENS_INFO_URL = "/tokens/info";
8
8
  }
9
9
  /**
10
10
  * Fetch tokens info from backend
@@ -12,41 +12,41 @@ class O {
12
12
  * @returns {Promise<ApiTokenInfo[]>} - The fetched tokens or undefined if there was an error or not default network
13
13
  */
14
14
  async fetchTokensInfoFromBackend(s) {
15
- const e = i(this.apiBase, this.TOKENS_INFO_URL, s ?? "", "?chain=starknet"), t = await this.httpService.get(e), n = h.safeParse(t);
16
- if (n.success)
17
- return n.data.tokens;
18
- const o = d.safeParse(t);
19
- if (o.success)
20
- return [o.data];
15
+ const e = i(this.apiBase, this.TOKENS_INFO_URL, s ?? "", "?chain=starknet"), n = await this.httpService.get(e), t = h.safeParse(n);
16
+ if (t.success)
17
+ return t.data.tokens;
18
+ const r = d.safeParse(n);
19
+ if (r.success)
20
+ return [r.data];
21
21
  }
22
22
  /**
23
23
  * Fetch list of tokens and balances for given account from backend
24
24
  * @param {Address} address - The account address.
25
25
  * @returns {Promise<WebBaseTokenWithBalance[]>} - The fetched balances for the account address.
26
26
  */
27
- async fetchAddressTokenBalancesFromBackend(s, e, t) {
28
- const n = i(this.apiBase, "activity", "starknet", e, "account", s, "balance");
27
+ async fetchAddressTokenBalancesFromBackend(s, e, n) {
28
+ const t = i(this.apiBase, "activity", "starknet", e, "account", s, "balance");
29
29
  return (await p(
30
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
31
  async (a) => {
32
32
  let c;
33
33
  try {
34
- c = await this.httpService.get(n);
34
+ c = await this.httpService.get(t);
35
35
  } catch {
36
36
  return a(new Error("Error fetching")), [];
37
37
  }
38
- const r = u.safeParse(c);
39
- if (!r.success)
38
+ const o = u.safeParse(c);
39
+ if (!o.success)
40
40
  return a(new Error("Error parsing response")), [];
41
- if (r.data.status !== "initialised")
41
+ if (o.data.status !== "initialised")
42
42
  throw new Error("Not initialised yet");
43
- return r.data.balances;
43
+ return o.data.balances;
44
44
  },
45
45
  {
46
46
  /** seems to take 5-10 sec for initialised state */
47
47
  retries: 5,
48
48
  minTimeout: 5e3,
49
- ...t
49
+ ...n
50
50
  }
51
51
  )).map((a) => ({
52
52
  address: a.tokenAddress,
@@ -54,11 +54,11 @@ class O {
54
54
  networkId: e
55
55
  }));
56
56
  }
57
- async fetchDefiDecomposition(s) {
58
- const e = i(this.apiBase, this.TOKENS_DEFI_DECOMPOSITION_URL, s, "?chain=starknet"), t = await this.httpService.get(e);
57
+ async fetchDefiDecomposition(s, e) {
58
+ const n = i(this.apiBase, "tokens/defi", s, "investments", "?chain=starknet", `&application=${e}`), t = await this.httpService.get(n);
59
59
  return k(f, t).success || console.error("Backend schema has changed. Make the changes to the models to prevent unknown/unhandled errors."), t.dapps;
60
60
  }
61
61
  }
62
62
  export {
63
- O as TokenServiceWeb
63
+ R as TokenServiceWeb
64
64
  };
@@ -5,7 +5,7 @@ import { ApiDefiDecompositionSchema, ApiTokenInfo } from './types/backend.model'
5
5
  import { WebBaseTokenWithBalance } from './types/webToken.model';
6
6
  export type SelectorFn<T> = (value: T) => boolean;
7
7
  export interface ITokenServiceDefiDecomposition {
8
- fetchDefiDecomposition: (address: Address) => Promise<ApiDefiDecompositionSchema[]>;
8
+ fetchDefiDecomposition: (address: Address, application: "mobile" | "webwallet" | "argentx") => Promise<ApiDefiDecompositionSchema[]>;
9
9
  }
10
10
  /**
11
11
  * ITokenService interface provides methods for managing tokens, including storage methods, fetch methods, and get methods.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("zod"),o=require("../../../chains/starknet/address.cjs"),p=require("./backend.model.cjs"),z=require("./defiPositionType.model.cjs"),t=require("./webToken.model.cjs"),c=t.webTokenWithBalanceAndPriceSchema.extend({accruedFees:e.z.string(),currentPrice:e.z.string(),maxPrice:e.z.string(),minPrice:e.z.string(),principal:e.z.string()}),n=e.z.object({address:o.addressSchema.optional(),currencyValue:e.z.string().default("0")}),a=n.extend({poolFeePercentage:e.z.string(),tickSpacingPercentage:e.z.string().optional(),tokenId:e.z.string().optional(),unitCurrencyValueToken0:e.z.string().optional(),unitCurrencyValueToken1:e.z.string().optional(),token0:c,token1:c}),m=e.z.array(a),h=e.z.object({name:e.z.string().optional(),healthRatio:e.z.string().optional(),accountAddress:o.addressSchema.optional()}),i=n.extend({totalBalances:e.z.record(e.z.string()),collateral:e.z.boolean(),debt:e.z.boolean(),lending:e.z.boolean(),apy:e.z.string().optional(),group:e.z.string().optional(),unitCurrencyValue:e.z.string().optional(),positionToken:p.apiTokenInfoSchema.or(e.z.undefined()),token:t.webTokenWithBalanceAndPriceSchema.optional(),accountAddress:o.addressSchema.optional(),accountAddressGroup:e.z.string().optional()}),g=e.z.array(i),r=n.extend({delegatingTo:o.addressSchema,token:t.webTokenWithBalanceAndPriceSchema.optional(),balance:e.z.string(),unitCurrencyValue:e.z.string().optional().default("0")}),S=e.z.array(r),s=a.or(i).or(r),d=e.z.record(e.z.object({name:e.z.string().optional(),healthRatio:e.z.string().optional(),accountAddress:o.addressSchema.optional()})),l=e.z.object({type:z.defiPositionTypeSchema,manageUrl:e.z.string().url().optional(),name:e.z.string(),positions:e.z.array(s),positionsTotalValue:e.z.string(),brandColor:e.z.string().optional(),groups:d.optional(),accountAddress:o.addressSchema}),u=e.z.array(l),P=e.z.object({dappId:e.z.string(),products:u});exports.collateralizedDebtGroupSchema=h;exports.collateralizedDebtPositionSchema=i;exports.collateralizedDebtPositionsSchema=g;exports.concentratedLiquidityPositionSchema=a;exports.concentratedLiquidityPositionsSchema=m;exports.defiDappsProductsSchema=P;exports.defiPositionSchema=s;exports.defiProductSchema=l;exports.defiProductsSchema=u;exports.delegatedTokensArraySchema=S;exports.delegatedTokensSchema=r;exports.productGroupsSchema=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("zod"),o=require("../../../chains/starknet/address.cjs"),p=require("./backend.model.cjs"),z=require("./defiPositionType.model.cjs"),t=require("./webToken.model.cjs"),c=t.webTokenWithBalanceAndPriceSchema.extend({accruedFees:e.z.string(),currentPrice:e.z.string(),maxPrice:e.z.string(),minPrice:e.z.string(),principal:e.z.string()}),n=e.z.object({id:e.z.string(),address:o.addressSchema.optional(),currencyValue:e.z.string().default("0")}),a=n.extend({poolFeePercentage:e.z.string(),tickSpacingPercentage:e.z.string().optional(),tokenId:e.z.string().optional(),unitCurrencyValueToken0:e.z.string().optional(),unitCurrencyValueToken1:e.z.string().optional(),token0:c,token1:c}),m=e.z.array(a),h=e.z.object({name:e.z.string().optional(),healthRatio:e.z.string().optional(),accountAddress:o.addressSchema.optional()}),i=n.extend({totalBalances:e.z.record(e.z.string()),collateral:e.z.boolean(),debt:e.z.boolean(),lending:e.z.boolean(),apy:e.z.string().optional(),group:e.z.string().optional(),unitCurrencyValue:e.z.string().optional(),positionToken:p.apiTokenInfoSchema.or(e.z.undefined()),token:t.webTokenWithBalanceAndPriceSchema.optional(),accountAddress:o.addressSchema.optional(),accountAddressGroup:e.z.string().optional()}),g=e.z.array(i),r=n.extend({delegatingTo:o.addressSchema,token:t.webTokenWithBalanceAndPriceSchema.optional(),balance:e.z.string(),unitCurrencyValue:e.z.string().optional().default("0")}),S=e.z.array(r),s=a.or(i).or(r),d=e.z.record(e.z.object({name:e.z.string().optional(),healthRatio:e.z.string().optional(),accountAddress:o.addressSchema.optional()})),l=e.z.object({type:z.defiPositionTypeSchema,manageUrl:e.z.string().url().optional(),name:e.z.string(),positions:e.z.array(s),positionsTotalValue:e.z.string(),brandColor:e.z.string().optional(),groups:d.optional(),accountAddress:o.addressSchema}),u=e.z.array(l),P=e.z.object({dappId:e.z.string(),products:u});exports.collateralizedDebtGroupSchema=h;exports.collateralizedDebtPositionSchema=i;exports.collateralizedDebtPositionsSchema=g;exports.concentratedLiquidityPositionSchema=a;exports.concentratedLiquidityPositionsSchema=m;exports.defiDappsProductsSchema=P;exports.defiPositionSchema=s;exports.defiProductSchema=l;exports.defiProductsSchema=u;exports.delegatedTokensArraySchema=S;exports.delegatedTokensSchema=r;exports.productGroupsSchema=d;