@zebec-network/exchange-card-sdk 1.9.0-dev.5 → 1.9.0-dev.7
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 +48 -24
- package/dist/services/aleoService.js +146 -67
- package/dist/services/cantonService.d.ts +31 -0
- package/dist/services/cantonService.js +57 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +3 -3
- package/package.json +4 -1
|
@@ -1,37 +1,51 @@
|
|
|
1
|
+
import { type TransactionOptions } from "@provablehq/aleo-types";
|
|
1
2
|
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2
3
|
import { AleoNetworkClient as TestnetAleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
3
4
|
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
-
export interface AleoTransition {
|
|
5
|
-
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;
|
|
15
|
-
}
|
|
16
5
|
export interface AleoWallet {
|
|
17
6
|
address: string;
|
|
18
|
-
|
|
7
|
+
decrypt: (cipherText: string) => Promise<string>;
|
|
8
|
+
requestRecords: (program: string, includePlaintext?: boolean | undefined) => Promise<unknown[]>;
|
|
9
|
+
executeTransaction: (options: TransactionOptions) => Promise<{
|
|
19
10
|
transactionId: string;
|
|
20
11
|
}>;
|
|
21
12
|
}
|
|
22
13
|
export type AleoTransferCreditParams = {
|
|
23
14
|
amount: number | string;
|
|
24
|
-
transferType?: "public" | "private"
|
|
15
|
+
transferType?: "public" | "private";
|
|
25
16
|
fee?: number;
|
|
26
|
-
|
|
17
|
+
privateFee?: boolean;
|
|
27
18
|
};
|
|
28
|
-
export type
|
|
29
|
-
|
|
30
|
-
tokenSymbol: string;
|
|
19
|
+
export type AleoTransferStableCoinParams = {
|
|
20
|
+
programId: "usad_stablecoin.aleo" | "usdcx_stablecoin.aleo";
|
|
31
21
|
amount: number | string;
|
|
32
|
-
transferType?: "public" | "private"
|
|
22
|
+
transferType?: "public" | "private";
|
|
33
23
|
fee?: number;
|
|
34
|
-
|
|
24
|
+
privateFee?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export declare const NETWORK_CONFIG: {
|
|
27
|
+
mainnet: {
|
|
28
|
+
explorer: string;
|
|
29
|
+
stablecoins: {
|
|
30
|
+
usad: string;
|
|
31
|
+
usdcx: string;
|
|
32
|
+
};
|
|
33
|
+
freezeListApi: {
|
|
34
|
+
usad: string;
|
|
35
|
+
usdcx: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
testnet: {
|
|
39
|
+
explorer: string;
|
|
40
|
+
stablecoins: {
|
|
41
|
+
usad: string;
|
|
42
|
+
usdcx: string;
|
|
43
|
+
};
|
|
44
|
+
freezeListApi: {
|
|
45
|
+
usad: string;
|
|
46
|
+
usdcx: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
35
49
|
};
|
|
36
50
|
export declare class AleoService {
|
|
37
51
|
readonly wallet: AleoWallet;
|
|
@@ -50,15 +64,25 @@ export declare class AleoService {
|
|
|
50
64
|
address: string;
|
|
51
65
|
tag?: string;
|
|
52
66
|
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Fetch unspent records for a program, decrypt them, and return the one
|
|
69
|
+
* with the highest non-zero balance as a single-line plaintext string.
|
|
70
|
+
*/
|
|
71
|
+
private _getRecord;
|
|
72
|
+
/**
|
|
73
|
+
* Build a Sealance Merkle exclusion proof proving the sender is NOT on the
|
|
74
|
+
* program's freeze list. Required for compliant stablecoin transfers.
|
|
75
|
+
*/
|
|
76
|
+
private _getComplianceProof;
|
|
53
77
|
/**
|
|
54
78
|
* Transfer native Aleo credits to the specified recipient.
|
|
55
79
|
*/
|
|
56
|
-
|
|
80
|
+
transferCredit(params: AleoTransferCreditParams): Promise<{
|
|
57
81
|
transactionId: string;
|
|
58
82
|
}>;
|
|
59
|
-
|
|
83
|
+
transferStableCoin(params: AleoTransferStableCoinParams): Promise<{
|
|
60
84
|
transactionId: string;
|
|
61
85
|
}>;
|
|
62
|
-
|
|
63
|
-
|
|
86
|
+
getPublicBalance(walletAddress: string): Promise<string>;
|
|
87
|
+
getPublicTokenBalance(walletAddress: string, tokenProgramId: string, tokenSymbol: string): Promise<string>;
|
|
64
88
|
}
|
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AleoNetworkClient
|
|
1
|
+
import { Network } from "@provablehq/aleo-types";
|
|
2
|
+
import { AleoNetworkClient, SealanceMerkleTree } from "@provablehq/sdk/mainnet.js";
|
|
3
|
+
import { AleoNetworkClient as TestnetAleoNetworkClient, SealanceMerkleTree as TestnetSealanceMerkleTree, } from "@provablehq/sdk/testnet.js";
|
|
3
4
|
import { ALEO_NETWORK_CLIENT_URL } from "../constants";
|
|
4
5
|
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
5
|
-
import {
|
|
6
|
+
import { fromMicroUnits, getTokenBySymbol, toMicroUnits } from "../utils";
|
|
7
|
+
export const NETWORK_CONFIG = {
|
|
8
|
+
[Network.MAINNET]: {
|
|
9
|
+
explorer: "https://explorer.provable.com/transaction",
|
|
10
|
+
stablecoins: {
|
|
11
|
+
usad: "usad_stablecoin.aleo",
|
|
12
|
+
usdcx: "usdcx_stablecoin.aleo",
|
|
13
|
+
},
|
|
14
|
+
freezeListApi: {
|
|
15
|
+
usad: "https://api.explorer.provable.com/v2/mainnet/programs/usad_freezelist.aleo/compliance/freeze-list",
|
|
16
|
+
usdcx: "https://api.explorer.provable.com/v2/mainnet/programs/usdcx_freezelist.aleo/compliance/freeze-list",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
[Network.TESTNET]: {
|
|
20
|
+
explorer: "https://explorer.provable.com/testnet/transaction",
|
|
21
|
+
stablecoins: {
|
|
22
|
+
usad: "test_usad_stablecoin.aleo",
|
|
23
|
+
usdcx: "test_usdcx_stablecoin.aleo",
|
|
24
|
+
},
|
|
25
|
+
freezeListApi: {
|
|
26
|
+
usad: "https://api.explorer.provable.com/v2/testnet/programs/test_usad_freezelist.aleo/compliance/freeze-list",
|
|
27
|
+
usdcx: "https://api.explorer.provable.com/v2/testnet/programs/test_usdcx_freezelist.aleo/compliance/freeze-list",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
6
31
|
export class AleoService {
|
|
7
32
|
wallet;
|
|
8
33
|
sandbox;
|
|
@@ -25,84 +50,138 @@ export class AleoService {
|
|
|
25
50
|
const data = await this.apiService.fetchVault(symbol);
|
|
26
51
|
return data;
|
|
27
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Fetch unspent records for a program, decrypt them, and return the one
|
|
55
|
+
* with the highest non-zero balance as a single-line plaintext string.
|
|
56
|
+
*/
|
|
57
|
+
async _getRecord(program, includePlaintext = false) {
|
|
58
|
+
const records = await this.wallet.requestRecords(program, includePlaintext);
|
|
59
|
+
console.debug("Fetched records:", records);
|
|
60
|
+
const unspent = records?.filter((r) => typeof r === "object" && r !== null && "spent" in r && !r.spent);
|
|
61
|
+
if (!unspent?.length) {
|
|
62
|
+
throw new Error(`No unspent ${program} records found`);
|
|
63
|
+
}
|
|
64
|
+
// Decrypt all unspent records in parallel (fast with AutoDecrypt permission)
|
|
65
|
+
const decrypted = await Promise.all(unspent.map(async (rec) => {
|
|
66
|
+
if (typeof rec !== "object" ||
|
|
67
|
+
rec === null ||
|
|
68
|
+
!("recordCiphertext" in rec) ||
|
|
69
|
+
typeof rec.recordCiphertext !== "string") {
|
|
70
|
+
throw new Error("Invalid record format");
|
|
71
|
+
}
|
|
72
|
+
console.debug("Decrypting record:", rec);
|
|
73
|
+
const plaintext = await this.wallet.decrypt(rec.recordCiphertext);
|
|
74
|
+
console.debug("Decrypted plaintext:", plaintext);
|
|
75
|
+
return plaintext.replace(/\s+/g, " ").trim();
|
|
76
|
+
}));
|
|
77
|
+
// Find records with non-zero balance, sorted highest-first
|
|
78
|
+
const withBalance = decrypted
|
|
79
|
+
.map((line) => {
|
|
80
|
+
const match = line.match(/microcredits:\s*(\d+)u64/) || line.match(/amount:\s*(\d+)u\d+/);
|
|
81
|
+
return { line, balance: match ? BigInt(match[1]) : 0n };
|
|
82
|
+
})
|
|
83
|
+
.filter((r) => r.balance > 0n)
|
|
84
|
+
.sort((a, b) => (b.balance > a.balance ? 1 : -1));
|
|
85
|
+
if (!withBalance.length) {
|
|
86
|
+
throw new Error(`No ${program} records with balance found`);
|
|
87
|
+
}
|
|
88
|
+
return withBalance[0].line;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Build a Sealance Merkle exclusion proof proving the sender is NOT on the
|
|
92
|
+
* program's freeze list. Required for compliant stablecoin transfers.
|
|
93
|
+
*/
|
|
94
|
+
async _getComplianceProof(stablecoinKey, senderAddress, network) {
|
|
95
|
+
if (network === Network.CANARY) {
|
|
96
|
+
throw new Error("Compliance proof generation is not supported on canary network");
|
|
97
|
+
}
|
|
98
|
+
const sealance = this.sandbox ? new TestnetSealanceMerkleTree() : new SealanceMerkleTree();
|
|
99
|
+
const url = NETWORK_CONFIG[network].freezeListApi[stablecoinKey];
|
|
100
|
+
const res = await fetch(url);
|
|
101
|
+
const freezeList = await res.json();
|
|
102
|
+
const tree = sealance.convertTreeToBigInt(freezeList);
|
|
103
|
+
const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, senderAddress);
|
|
104
|
+
const leftProof = sealance.getSiblingPath(tree, leftIdx, 16);
|
|
105
|
+
const rightProof = sealance.getSiblingPath(tree, rightIdx, 16);
|
|
106
|
+
return sealance.formatMerkleProof([leftProof, rightProof]);
|
|
107
|
+
}
|
|
28
108
|
/**
|
|
29
109
|
* Transfer native Aleo credits to the specified recipient.
|
|
30
110
|
*/
|
|
31
|
-
async
|
|
111
|
+
async transferCredit(params) {
|
|
32
112
|
const { amount } = params;
|
|
33
113
|
const transferType = params.transferType || "public";
|
|
34
|
-
const
|
|
114
|
+
const privateFee = params?.privateFee || false;
|
|
115
|
+
const fee = toMicroUnits(params.fee || 0.1, 6);
|
|
35
116
|
const vault = await this.fetchVault("ALEO");
|
|
36
117
|
const recipient = vault.address;
|
|
37
118
|
console.log("recipient:", recipient);
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const functionName = transferType === "public"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
119
|
+
const amountInMicroCredits = toMicroUnits(amount, 6, "u64");
|
|
120
|
+
const PROGRAM_NAME = "credits.aleo";
|
|
121
|
+
const functionName = transferType === "public" ? "transfer_public" : "transfer_private";
|
|
122
|
+
let inputs;
|
|
123
|
+
switch (functionName) {
|
|
124
|
+
case "transfer_public":
|
|
125
|
+
inputs = [recipient, `${amountInMicroCredits}u64`];
|
|
126
|
+
break;
|
|
127
|
+
case "transfer_private": {
|
|
128
|
+
const record = await this._getRecord(PROGRAM_NAME);
|
|
129
|
+
inputs = [record, recipient, amountInMicroCredits];
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
default:
|
|
133
|
+
throw new Error("Invalid or Unsupported transfer type");
|
|
134
|
+
}
|
|
135
|
+
if (functionName !== "transfer_public") {
|
|
136
|
+
throw new Error("Only public transfers are currently supported for credits. Private and cross-type transfers require additional implementation.");
|
|
137
|
+
}
|
|
138
|
+
const result = await this.wallet.executeTransaction({
|
|
139
|
+
program: PROGRAM_NAME,
|
|
140
|
+
function: functionName,
|
|
141
|
+
inputs,
|
|
142
|
+
fee: Number(fee),
|
|
143
|
+
privateFee,
|
|
59
144
|
});
|
|
60
145
|
return result;
|
|
61
146
|
}
|
|
62
|
-
async
|
|
63
|
-
const {
|
|
64
|
-
const tokenMetadata = await getTokenBySymbol(tokenSymbol, this.sandbox ? "testnet" : "mainnet");
|
|
65
|
-
if (!("decimals" in tokenMetadata)) {
|
|
66
|
-
throw new Error(`Token metadata for ${tokenSymbol} does not include decimals.`);
|
|
67
|
-
}
|
|
68
|
-
const tokenDecimals = tokenMetadata.decimals;
|
|
69
|
-
if (!("token_id" in tokenMetadata)) {
|
|
70
|
-
throw new Error(`Token metadata for ${tokenSymbol} does not include token_id.`);
|
|
71
|
-
}
|
|
72
|
-
const tokenId = tokenMetadata.token_id;
|
|
73
|
-
if (!("token_id_datatype" in tokenMetadata)) {
|
|
74
|
-
throw new Error(`Token metadata for ${tokenSymbol} does not include token_id_datatype.`);
|
|
75
|
-
}
|
|
76
|
-
const tokenIdDatatype = tokenMetadata.token_id_datatype;
|
|
147
|
+
async transferStableCoin(params) {
|
|
148
|
+
const { amount } = params;
|
|
77
149
|
const transferType = params.transferType || "public";
|
|
78
|
-
const
|
|
150
|
+
const privateFee = params?.privateFee || false;
|
|
151
|
+
const fee = toMicroUnits(params.fee || 0.1, 6);
|
|
152
|
+
const programId = this.sandbox ? `test_${params.programId}` : params.programId;
|
|
153
|
+
const tokenSymbol = params.programId === "usad_stablecoin.aleo" ? "USAD" : "USDCX";
|
|
154
|
+
const functionName = transferType === "public" ? "transfer_public" : "transfer_private";
|
|
79
155
|
const vault = await this.fetchVault(tokenSymbol);
|
|
80
156
|
const recipient = vault.address;
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
157
|
+
const amountInMicroUnits = toMicroUnits(amount, 6, "u128");
|
|
158
|
+
let inputs;
|
|
159
|
+
switch (functionName) {
|
|
160
|
+
case "transfer_public":
|
|
161
|
+
inputs = [recipient, amountInMicroUnits];
|
|
162
|
+
break;
|
|
163
|
+
case "transfer_private": {
|
|
164
|
+
// For private transfer, we need to find a record with sufficient balance
|
|
165
|
+
const [record, complianceProof] = await Promise.all([
|
|
166
|
+
this._getRecord(programId),
|
|
167
|
+
this._getComplianceProof(tokenSymbol.toLowerCase(), this.wallet.address, this.sandbox ? Network.TESTNET : Network.MAINNET),
|
|
168
|
+
]);
|
|
169
|
+
inputs = [recipient, amountInMicroUnits, record, complianceProof];
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
default:
|
|
173
|
+
throw new Error("Invalid or Unsupported transfer type");
|
|
174
|
+
}
|
|
175
|
+
const result = await this.wallet.executeTransaction({
|
|
176
|
+
fee: Number(fee),
|
|
177
|
+
privateFee,
|
|
178
|
+
program: programId,
|
|
179
|
+
function: functionName,
|
|
180
|
+
inputs,
|
|
102
181
|
});
|
|
103
182
|
return result;
|
|
104
183
|
}
|
|
105
|
-
async
|
|
184
|
+
async getPublicBalance(walletAddress) {
|
|
106
185
|
const programId = "credits.aleo";
|
|
107
186
|
const mappingName = "account";
|
|
108
187
|
const balance = await this.networkClient.getProgramMappingValue(programId, mappingName, walletAddress);
|
|
@@ -112,7 +191,7 @@ export class AleoService {
|
|
|
112
191
|
const match = balance.match(regex);
|
|
113
192
|
if (match) {
|
|
114
193
|
const amount = match[1];
|
|
115
|
-
const formattedAmount =
|
|
194
|
+
const formattedAmount = fromMicroUnits(amount);
|
|
116
195
|
return formattedAmount;
|
|
117
196
|
}
|
|
118
197
|
else {
|
|
@@ -123,7 +202,7 @@ export class AleoService {
|
|
|
123
202
|
return "0";
|
|
124
203
|
}
|
|
125
204
|
}
|
|
126
|
-
async
|
|
205
|
+
async getPublicTokenBalance(walletAddress, tokenProgramId, tokenSymbol) {
|
|
127
206
|
const tokenMetadata = await getTokenBySymbol(tokenSymbol, this.sandbox ? "testnet" : "mainnet");
|
|
128
207
|
if (!("decimals" in tokenMetadata)) {
|
|
129
208
|
throw new Error(`Token metadata for ${tokenSymbol} does not include decimals.`);
|
|
@@ -143,7 +222,7 @@ export class AleoService {
|
|
|
143
222
|
const match = balance.match(regex);
|
|
144
223
|
if (match) {
|
|
145
224
|
const amount = match[1];
|
|
146
|
-
const formattedAmount =
|
|
225
|
+
const formattedAmount = fromMicroUnits(amount, tokenMetadata.decimals);
|
|
147
226
|
return formattedAmount;
|
|
148
227
|
}
|
|
149
228
|
else {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type AuthTokenProvider, LedgerController, TokenStandardController, ValidatorController, type WalletSDK } from "@canton-network/wallet-sdk";
|
|
2
|
+
export interface CantonWallet {
|
|
3
|
+
partyId: string;
|
|
4
|
+
executeTransaction: (command: unknown, disclosedContractId: unknown[]) => Promise<string>;
|
|
5
|
+
}
|
|
6
|
+
export interface CantonConfig {
|
|
7
|
+
ledgerApiUrl: string;
|
|
8
|
+
validatorAppApiUrl: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createLedgerFactory(ledgerApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider, isAdmin: boolean) => LedgerController;
|
|
11
|
+
export declare function createValidatorFactory(validatorAppApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider) => ValidatorController;
|
|
12
|
+
export declare function createTokenStandardFactory(ledgerApiUrl: string, validatorAppApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider, isAdmin: boolean) => TokenStandardController;
|
|
13
|
+
export declare class CantonService {
|
|
14
|
+
readonly wallet: CantonWallet;
|
|
15
|
+
readonly cantonConfig: CantonConfig;
|
|
16
|
+
readonly cantonWalletSdk: WalletSDK;
|
|
17
|
+
private apiService;
|
|
18
|
+
constructor(wallet: CantonWallet, cantonConfig: CantonConfig, sdkOptions?: {
|
|
19
|
+
sandbox?: boolean;
|
|
20
|
+
});
|
|
21
|
+
connect(): Promise<void>;
|
|
22
|
+
fetchVault(symbol?: string): Promise<{
|
|
23
|
+
address: string;
|
|
24
|
+
tag?: string;
|
|
25
|
+
}>;
|
|
26
|
+
transferNative(params: {
|
|
27
|
+
amount: number | string;
|
|
28
|
+
instrumentId: string;
|
|
29
|
+
instrumentAdmin: string;
|
|
30
|
+
}): Promise<string>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LedgerController, localNetStaticConfig, TokenStandardController, ValidatorController, WalletSDKImpl, } from "@canton-network/wallet-sdk";
|
|
2
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
3
|
+
export function createLedgerFactory(ledgerApiUrl) {
|
|
4
|
+
return (userId, authTokenProvider, isAdmin) => {
|
|
5
|
+
return new LedgerController(userId, new URL(ledgerApiUrl), undefined, isAdmin, authTokenProvider);
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function createValidatorFactory(validatorAppApiUrl) {
|
|
9
|
+
return (userId, authTokenProvider) => {
|
|
10
|
+
return new ValidatorController(userId, new URL(validatorAppApiUrl), authTokenProvider);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function createTokenStandardFactory(ledgerApiUrl, validatorAppApiUrl) {
|
|
14
|
+
return (userId, authTokenProvider, isAdmin) => {
|
|
15
|
+
return new TokenStandardController(userId, new URL(ledgerApiUrl), new URL(validatorAppApiUrl), undefined, authTokenProvider, isAdmin);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export class CantonService {
|
|
19
|
+
wallet;
|
|
20
|
+
cantonConfig;
|
|
21
|
+
cantonWalletSdk;
|
|
22
|
+
apiService;
|
|
23
|
+
constructor(wallet, cantonConfig, sdkOptions) {
|
|
24
|
+
this.wallet = wallet;
|
|
25
|
+
this.cantonConfig = cantonConfig;
|
|
26
|
+
this.apiService = new ZebecCardAPIService(sdkOptions?.sandbox || false);
|
|
27
|
+
this.cantonWalletSdk = new WalletSDKImpl().configure({
|
|
28
|
+
logger: console,
|
|
29
|
+
ledgerFactory: createLedgerFactory(cantonConfig.ledgerApiUrl),
|
|
30
|
+
validatorFactory: createValidatorFactory(cantonConfig.validatorAppApiUrl),
|
|
31
|
+
tokenStandardFactory: createTokenStandardFactory(cantonConfig.ledgerApiUrl, cantonConfig.validatorAppApiUrl),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async connect() {
|
|
35
|
+
await this.cantonWalletSdk.connect();
|
|
36
|
+
}
|
|
37
|
+
async fetchVault(symbol = "CANTON") {
|
|
38
|
+
const data = await this.apiService.fetchVault(symbol);
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
// methods for transfering natve assets
|
|
42
|
+
async transferNative(params) {
|
|
43
|
+
const vault = await this.fetchVault("CANTON");
|
|
44
|
+
const sender = this.wallet.partyId;
|
|
45
|
+
const receiver = vault.address;
|
|
46
|
+
const memo = vault.tag;
|
|
47
|
+
// implement transfer logic here
|
|
48
|
+
this.cantonWalletSdk.tokenStandard?.setTransferFactoryRegistryUrl(localNetStaticConfig.LOCALNET_REGISTRY_API_URL);
|
|
49
|
+
const [transferCommand, disclosedContracts] =
|
|
50
|
+
// biome-ignore lint/style/noNonNullAssertion: we can be sure that tokenStandard is defined here since we set its factory in the SDK constructor
|
|
51
|
+
await this.cantonWalletSdk.tokenStandard.createTransfer(sender, receiver, params.amount.toString(), {
|
|
52
|
+
instrumentId: params.instrumentId,
|
|
53
|
+
instrumentAdmin: params.instrumentAdmin,
|
|
54
|
+
}, [], memo);
|
|
55
|
+
return this.wallet.executeTransaction(transferCommand, disclosedContracts);
|
|
56
|
+
}
|
|
57
|
+
}
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -35,11 +35,11 @@ export declare function getAssetDecimals(client: algosdk.Algodv2, assetId: numbe
|
|
|
35
35
|
/**
|
|
36
36
|
* Convert credits to microcredits
|
|
37
37
|
*/
|
|
38
|
-
export declare function
|
|
38
|
+
export declare function toMicroUnits(credits: BigNumber.Value, decimals?: number, typeSuffix?: string): string;
|
|
39
39
|
/**
|
|
40
40
|
* Convert microcredits to credits
|
|
41
41
|
*/
|
|
42
|
-
export declare function
|
|
42
|
+
export declare function fromMicroUnits(microcredits: BigNumber.Value, decimals?: number): string;
|
|
43
43
|
export type TokenMetadata = {
|
|
44
44
|
token_id: string;
|
|
45
45
|
token_id_datatype: string | null;
|
package/dist/utils.js
CHANGED
|
@@ -61,13 +61,13 @@ export async function getAssetDecimals(client, assetId) {
|
|
|
61
61
|
/**
|
|
62
62
|
* Convert credits to microcredits
|
|
63
63
|
*/
|
|
64
|
-
export function
|
|
65
|
-
return BigNumber(credits).times(BigNumber(10).pow(decimals)).toFixed(0)
|
|
64
|
+
export function toMicroUnits(credits, decimals = 6, typeSuffix) {
|
|
65
|
+
return `${BigNumber(credits).times(BigNumber(10).pow(decimals)).toFixed(0)}${typeSuffix || ""}`;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Convert microcredits to credits
|
|
69
69
|
*/
|
|
70
|
-
export function
|
|
70
|
+
export function fromMicroUnits(microcredits, decimals = 6) {
|
|
71
71
|
return BigNumber(microcredits).div(BigNumber(10).pow(decimals)).toFixed();
|
|
72
72
|
}
|
|
73
73
|
export async function getTokenBySymbol(tokenSymbol, network = "mainnet") {
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Zebec Network | Ashish Sapkota",
|
|
3
3
|
"dependencies": {
|
|
4
|
+
"@canton-network/wallet-sdk": "^0.21.1",
|
|
4
5
|
"@near-js/crypto": "^2.5.1",
|
|
5
6
|
"@near-js/providers": "^2.5.1",
|
|
6
7
|
"@near-js/transactions": "^2.5.1",
|
|
7
8
|
"@near-js/types": "^2.5.1",
|
|
8
9
|
"@near-js/utils": "^2.5.1",
|
|
10
|
+
"@provablehq/aleo-types": "^0.3.0-alpha.3",
|
|
9
11
|
"@provablehq/sdk": "^0.9.15",
|
|
10
12
|
"@stellar/stellar-sdk": "^14.4.3",
|
|
11
13
|
"algosdk": "^3.4.0",
|
|
@@ -19,6 +21,7 @@
|
|
|
19
21
|
"description": "An sdk for purchasing silver card in zebec",
|
|
20
22
|
"devDependencies": {
|
|
21
23
|
"@algorandfoundation/algokit-utils": "^9.1.2",
|
|
24
|
+
"@canton-network/dapp-sdk": "^0.21.2",
|
|
22
25
|
"@near-js/accounts": "^2.5.1",
|
|
23
26
|
"@near-js/keystores": "^2.5.1",
|
|
24
27
|
"@near-js/signers": "^2.5.1",
|
|
@@ -62,5 +65,5 @@
|
|
|
62
65
|
},
|
|
63
66
|
"type": "module",
|
|
64
67
|
"types": "dist/index.d.ts",
|
|
65
|
-
"version": "1.9.0-dev.
|
|
68
|
+
"version": "1.9.0-dev.7"
|
|
66
69
|
}
|