@zebec-network/exchange-card-sdk 1.9.0-dev.5 → 1.9.0-dev.6

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,21 +1,39 @@
1
1
  import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
2
2
  import { AleoNetworkClient as TestnetAleoNetworkClient } from "@provablehq/sdk/testnet.js";
3
3
  import { ZebecCardAPIService } from "../helpers/apiHelpers";
4
- export interface AleoTransition {
4
+ /**
5
+ * Transaction creation options
6
+ */
7
+ interface TransactionOptions {
8
+ /**
9
+ * The program to execute
10
+ */
5
11
  program: string;
6
- functionName: string;
7
- inputs: any[];
8
- }
9
- export interface AleoTransaction {
10
- address: string;
11
- chainId: string;
12
- transitions: AleoTransition[];
13
- fee: number;
14
- feePrivate: boolean;
12
+ /**
13
+ * The function to call
14
+ */
15
+ function: string;
16
+ /**
17
+ * The function inputs
18
+ */
19
+ inputs: string[];
20
+ /**
21
+ * The transaction fee to pay
22
+ */
23
+ fee?: number;
24
+ /**
25
+ * Record indices to use
26
+ */
27
+ recordIndices?: number[];
28
+ /**
29
+ * Whether the fee is private
30
+ */
31
+ privateFee?: boolean;
15
32
  }
16
33
  export interface AleoWallet {
17
34
  address: string;
18
- requestTransaction: (transaction: AleoTransaction) => Promise<{
35
+ requestRecords: (program: string, includePlaintext?: boolean | undefined) => Promise<unknown[]>;
36
+ executeTransaction: (options: TransactionOptions) => Promise<{
19
37
  transactionId: string;
20
38
  }>;
21
39
  }
@@ -23,7 +41,7 @@ export type AleoTransferCreditParams = {
23
41
  amount: number | string;
24
42
  transferType?: "public" | "private" | "privateToPublic" | "publicToPrivate";
25
43
  fee?: number;
26
- feePrivate?: boolean;
44
+ privateFee?: boolean;
27
45
  };
28
46
  export type AleoTransferTokenParams = {
29
47
  tokenProgramId: string;
@@ -31,7 +49,7 @@ export type AleoTransferTokenParams = {
31
49
  amount: number | string;
32
50
  transferType?: "public" | "private" | "privateToPublic" | "publicToPrivate";
33
51
  fee?: number;
34
- feePrivate?: boolean;
52
+ privateFee?: boolean;
35
53
  };
36
54
  export declare class AleoService {
37
55
  readonly wallet: AleoWallet;
@@ -62,3 +80,4 @@ export declare class AleoService {
62
80
  getBalance(walletAddress: string): Promise<string>;
63
81
  getTokenBalance(walletAddress: string, tokenProgramId: string, tokenSymbol: string): Promise<string>;
64
82
  }
83
+ export {};
@@ -2,7 +2,7 @@ import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
2
2
  import { AleoNetworkClient as TestnetAleoNetworkClient } from "@provablehq/sdk/testnet.js";
3
3
  import { ALEO_NETWORK_CLIENT_URL } from "../constants";
4
4
  import { ZebecCardAPIService } from "../helpers/apiHelpers";
5
- import { creditsToMicrocredits, getTokenBySymbol, microcreditsToCredits } from "../utils";
5
+ import { creditsToMicrocredits, getTokenBySymbol, microcreditsToCredits, } from "../utils";
6
6
  export class AleoService {
7
7
  wallet;
8
8
  sandbox;
@@ -31,7 +31,7 @@ export class AleoService {
31
31
  async transferCredits(params) {
32
32
  const { amount } = params;
33
33
  const transferType = params.transferType || "public";
34
- const feePrivate = params?.feePrivate || false;
34
+ const privateFee = params?.privateFee || false;
35
35
  const vault = await this.fetchVault("ALEO");
36
36
  const recipient = vault.address;
37
37
  console.log("recipient:", recipient);
@@ -44,18 +44,12 @@ export class AleoService {
44
44
  : transferType === "privateToPublic"
45
45
  ? "transfer_private_to_public"
46
46
  : "transfer_public_to_private";
47
- const result = await this.wallet.requestTransaction({
48
- address: this.wallet.address,
49
- chainId: this.sandbox ? "testnetbeta" : "mainnet",
50
- fee: Number(creditsToMicrocredits(params.fee || 0.035)),
51
- feePrivate,
52
- transitions: [
53
- {
54
- functionName,
55
- program: programName,
56
- inputs: [recipient, `${amountInMiroCredits}u64`],
57
- },
58
- ],
47
+ const result = await this.wallet.executeTransaction({
48
+ program: programName,
49
+ function: functionName,
50
+ inputs: [recipient, `${amountInMiroCredits}u64`],
51
+ fee: Number(creditsToMicrocredits(params.fee || 0.1)),
52
+ privateFee,
59
53
  });
60
54
  return result;
61
55
  }
@@ -75,7 +69,7 @@ export class AleoService {
75
69
  }
76
70
  const tokenIdDatatype = tokenMetadata.token_id_datatype;
77
71
  const transferType = params.transferType || "public";
78
- const feePrivate = params?.feePrivate || false;
72
+ const privateFee = params?.privateFee || false;
79
73
  const vault = await this.fetchVault(tokenSymbol);
80
74
  const recipient = vault.address;
81
75
  const amountInMicroTokens = creditsToMicrocredits(amount, tokenDecimals);
@@ -87,18 +81,12 @@ export class AleoService {
87
81
  : transferType === "privateToPublic"
88
82
  ? "transfer_private_to_public"
89
83
  : "transfer_public_to_private";
90
- const result = await this.wallet.requestTransaction({
91
- address: this.wallet.address,
92
- chainId: this.sandbox ? "testnetbeta" : "mainnet",
93
- fee: Number(creditsToMicrocredits(params.fee || 0.035)),
94
- feePrivate,
95
- transitions: [
96
- {
97
- functionName,
98
- program: programName,
99
- inputs: [`${tokenId}${tokenIdDatatype}`, recipient, `${amountInMicroTokens}u128`],
100
- },
101
- ],
84
+ const result = await this.wallet.executeTransaction({
85
+ fee: Number(creditsToMicrocredits(params.fee || 0.1)),
86
+ privateFee,
87
+ program: programName,
88
+ function: functionName,
89
+ inputs: [`${tokenId}${tokenIdDatatype}`, recipient, `${amountInMicroTokens}u128`],
102
90
  });
103
91
  return result;
104
92
  }
package/package.json CHANGED
@@ -62,5 +62,5 @@
62
62
  },
63
63
  "type": "module",
64
64
  "types": "dist/index.d.ts",
65
- "version": "1.9.0-dev.5"
65
+ "version": "1.9.0-dev.6"
66
66
  }