@zebec-network/exchange-card-sdk 1.9.0-dev.4 → 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.
- package/dist/services/aleoService.d.ts +32 -13
- package/dist/services/aleoService.js +15 -27
- package/package.json +1 -1
|
@@ -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
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Transaction creation options
|
|
6
|
+
*/
|
|
7
|
+
interface TransactionOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The program to execute
|
|
10
|
+
*/
|
|
5
11
|
program: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
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.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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