@zebec-network/exchange-card-sdk 1.11.0-dev.1 → 1.11.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.
@@ -58,6 +58,7 @@ export type AleoTransferCreditParams = {
58
58
  transferType?: "public" | "private";
59
59
  fee?: number;
60
60
  privateFee?: boolean;
61
+ recipient?: string;
61
62
  };
62
63
  export type AleoTransferStableCoinParams = {
63
64
  programId: "usad_stablecoin.aleo" | "usdcx_stablecoin.aleo";
@@ -65,6 +66,7 @@ export type AleoTransferStableCoinParams = {
65
66
  transferType?: "public" | "private";
66
67
  fee?: number;
67
68
  privateFee?: boolean;
69
+ recipient?: string;
68
70
  };
69
71
  export declare const NETWORK_CONFIG: {
70
72
  mainnet: {
@@ -121,9 +121,17 @@ export class AleoService {
121
121
  const transferType = params.transferType || "public";
122
122
  const privateFee = params?.privateFee || false;
123
123
  const fee = toMicroUnits(params.fee || 0.1, 6);
124
- const vault = await this.fetchVault("ALEO");
125
- const recipient = vault.address;
126
- console.log("recipient:", recipient);
124
+ let recipient;
125
+ if (params.recipient) {
126
+ recipient = params.recipient;
127
+ }
128
+ else {
129
+ const vault = await this.fetchVault("ALEO");
130
+ if (!vault) {
131
+ throw new Error("Failed to fetch vault address");
132
+ }
133
+ recipient = vault.address;
134
+ }
127
135
  const amountInMicroCredits = toMicroUnits(amount, 6, "u64");
128
136
  const PROGRAM_NAME = "credits.aleo";
129
137
  const functionName = transferType === "public" ? "transfer_public" : "transfer_private";
@@ -157,8 +165,17 @@ export class AleoService {
157
165
  const programId = this.sandbox ? `test_${params.programId}` : params.programId;
158
166
  const tokenSymbol = params.programId === "usad_stablecoin.aleo" ? "USAD" : "USDCX";
159
167
  const functionName = transferType === "public" ? "transfer_public" : "transfer_private";
160
- const vault = await this.fetchVault(tokenSymbol);
161
- const recipient = vault.address;
168
+ let recipient;
169
+ if (params.recipient) {
170
+ recipient = params.recipient;
171
+ }
172
+ else {
173
+ const vault = await this.fetchVault(tokenSymbol);
174
+ if (!vault) {
175
+ throw new Error("Failed to fetch vault address");
176
+ }
177
+ recipient = vault.address;
178
+ }
162
179
  const amountInMicroUnits = toMicroUnits(amount, 6, "u128");
163
180
  let inputs;
164
181
  switch (functionName) {
@@ -1,5 +1,5 @@
1
1
  import { ethers } from "ethers";
2
- import { BobaChainId } from "../types";
2
+ import type { BobaChainId } from "../types";
3
3
  export type TransferBobaParams = {
4
4
  amount: string | number;
5
5
  overrides?: Omit<ethers.Overrides, "from" | "value" | "chainId">;
@@ -1,7 +1,6 @@
1
1
  export * from "./aleoService";
2
2
  export * from "./algorandService";
3
3
  export * from "./bobaService";
4
- export * from "./cantonService";
5
4
  export * from "./nearService";
6
5
  export * from "./octaService";
7
6
  export * from "./quaiService";
@@ -1,7 +1,6 @@
1
1
  export * from "./aleoService";
2
2
  export * from "./algorandService";
3
3
  export * from "./bobaService";
4
- export * from "./cantonService";
5
4
  export * from "./nearService";
6
5
  export * from "./octaService";
7
6
  export * from "./quaiService";
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "author": "Zebec Network | Ashish Sapkota",
3
3
  "dependencies": {
4
- "@canton-network/wallet-sdk": "^0.21.1",
5
4
  "@near-js/crypto": "^2.5.1",
6
5
  "@near-js/providers": "^2.5.1",
7
6
  "@near-js/transactions": "^2.5.1",
@@ -19,7 +18,6 @@
19
18
  "description": "An sdk for purchasing silver card in zebec",
20
19
  "devDependencies": {
21
20
  "@algorandfoundation/algokit-utils": "^9.1.2",
22
- "@canton-network/dapp-sdk": "^0.21.2",
23
21
  "@near-js/accounts": "^2.5.1",
24
22
  "@near-js/keystores": "^2.5.1",
25
23
  "@near-js/signers": "^2.5.1",
@@ -64,5 +62,5 @@
64
62
  },
65
63
  "type": "module",
66
64
  "types": "dist/index.d.ts",
67
- "version": "1.11.0-dev.1"
65
+ "version": "1.11.0"
68
66
  }
@@ -1,116 +0,0 @@
1
- import { type AuthTokenProvider, LedgerController, TokenStandardController, ValidatorController, type WalletSDK } from "@canton-network/wallet-sdk";
2
- export declare const CANTON_NATIVE_INSTRUMENT_ID = "Amulet";
3
- export declare const DEVNET_CANTON_NATIVE_INSTRUMENT_ADMIN = "DSO::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a";
4
- /**
5
- * Wallet adapter interface — the frontend implements this to bridge the
6
- * dApp wallet (e.g. Canton dApp SDK, browser extension) with CantonService.
7
- *
8
- * The service calls `executeTransaction` with the prepared command and
9
- * disclosed contracts produced by the wallet-sdk; the adapter is responsible
10
- * for signing and submitting them through whichever wallet integration the
11
- * frontend uses.
12
- */
13
- export interface CantonWalletAdapter {
14
- /** The Daml party ID of the connected user. */
15
- readonly partyId: string;
16
- /**
17
- * Sign and submit a transaction to the Canton ledger.
18
- *
19
- * @param command - The exercise command prepared by the wallet-sdk.
20
- * @param disclosedContracts - Contracts that must be disclosed alongside
21
- * the command for the transaction to succeed.
22
- * @returns The submitted transaction / command ID.
23
- */
24
- executeTransaction(command: {
25
- ExerciseCommand: {
26
- templateId: string;
27
- contractId: string;
28
- choice: string;
29
- choiceArgument: unknown;
30
- } | {
31
- templateId: string;
32
- contractId: string;
33
- choice: string;
34
- choiceArgument: unknown;
35
- };
36
- }, disclosedContracts: ({
37
- templateId?: string;
38
- contractId: string;
39
- createdEventBlob: string;
40
- synchronizerId: string;
41
- } | {
42
- templateId?: string;
43
- contractId: string;
44
- createdEventBlob: string;
45
- synchronizerId: string;
46
- })[]): Promise<string>;
47
- }
48
- export interface CantonConfig {
49
- ledgerApiUrl: string;
50
- validatorAppApiUrl: string;
51
- /**
52
- * Transfer-factory registry URL.
53
- * Defaults to `localNetStaticConfig.LOCALNET_REGISTRY_API_URL` when omitted.
54
- */
55
- registryApiUrl?: string | URL;
56
- }
57
- /** Parameters for transferring native Canton coin (Amulet). */
58
- export interface NativeTransferParams {
59
- amount: number | string;
60
- /**
61
- * The instrument admin party for the Amulet instrument on the target network
62
- * (typically the DSO party).
63
- */
64
- instrumentAdmin?: string;
65
- memo?: string;
66
- }
67
- /** Parameters for transferring a CIP-0056 standard token. */
68
- export interface TokenTransferParams {
69
- amount: number | string;
70
- /** The instrument / token identifier as registered in the token registry. */
71
- instrumentId: string;
72
- /** The admin party that governs this instrument. */
73
- instrumentAdmin: string;
74
- /**
75
- * Override the registry URL for this specific token.
76
- * Falls back to `CantonConfig.registryApiUrl` when omitted.
77
- */
78
- registryApiUrl?: string | URL;
79
- memo?: string;
80
- }
81
- export declare function createLedgerFactory(ledgerApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider, isAdmin: boolean) => LedgerController;
82
- export declare function createValidatorFactory(validatorAppApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider) => ValidatorController;
83
- export declare function createTokenStandardFactory(ledgerApiUrl: string, validatorAppApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider, isAdmin: boolean) => TokenStandardController;
84
- export declare class CantonService {
85
- readonly wallet: CantonWalletAdapter;
86
- readonly cantonConfig: CantonConfig;
87
- readonly cantonWalletSdk: WalletSDK;
88
- private readonly apiService;
89
- private readonly registryApiUrl;
90
- constructor(wallet: CantonWalletAdapter, cantonConfig: CantonConfig, sdkOptions?: {
91
- sandbox?: boolean;
92
- });
93
- connect(): Promise<void>;
94
- fetchVault(symbol?: string): Promise<{
95
- address: string;
96
- tag?: string;
97
- }>;
98
- private getTokenStandard;
99
- /**
100
- * Transfer native Canton coin (Amulet) to the Zebec vault.
101
- *
102
- * 1. Resolves the vault address for the "CANTON" symbol.
103
- * 2. Builds the transfer command via the wallet-sdk token-standard.
104
- * 3. Delegates signing and submission to the wallet adapter.
105
- */
106
- transferNative(params: NativeTransferParams): Promise<string>;
107
- /**
108
- * Transfer a CIP-0056 standard token to the Zebec vault.
109
- *
110
- * 1. Resolves the vault address for the given instrument symbol.
111
- * 2. Configures the token-standard with the appropriate registry URL.
112
- * 3. Builds the transfer command via the wallet-sdk token-standard.
113
- * 4. Delegates signing and submission to the wallet adapter.
114
- */
115
- transferToken(params: TokenTransferParams): Promise<string>;
116
- }
@@ -1,97 +0,0 @@
1
- import { LedgerController, localNetStaticConfig, TokenStandardController, ValidatorController, WalletSDKImpl, } from "@canton-network/wallet-sdk";
2
- import { ZebecCardAPIService } from "../helpers/apiHelpers";
3
- export const CANTON_NATIVE_INSTRUMENT_ID = "Amulet";
4
- export const DEVNET_CANTON_NATIVE_INSTRUMENT_ADMIN = "DSO::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a";
5
- // ---------------------------------------------------------------------------
6
- // SDK factory helpers
7
- // ---------------------------------------------------------------------------
8
- export function createLedgerFactory(ledgerApiUrl) {
9
- return (userId, authTokenProvider, isAdmin) => {
10
- return new LedgerController(userId, new URL(ledgerApiUrl), undefined, isAdmin, authTokenProvider);
11
- };
12
- }
13
- export function createValidatorFactory(validatorAppApiUrl) {
14
- return (userId, authTokenProvider) => {
15
- return new ValidatorController(userId, new URL(validatorAppApiUrl), authTokenProvider);
16
- };
17
- }
18
- export function createTokenStandardFactory(ledgerApiUrl, validatorAppApiUrl) {
19
- return (userId, authTokenProvider, isAdmin) => {
20
- return new TokenStandardController(userId, new URL(ledgerApiUrl), new URL(validatorAppApiUrl), undefined, authTokenProvider, isAdmin);
21
- };
22
- }
23
- // ---------------------------------------------------------------------------
24
- // CantonService
25
- // ---------------------------------------------------------------------------
26
- export class CantonService {
27
- wallet;
28
- cantonConfig;
29
- cantonWalletSdk;
30
- apiService;
31
- registryApiUrl;
32
- constructor(wallet, cantonConfig, sdkOptions) {
33
- this.wallet = wallet;
34
- this.cantonConfig = cantonConfig;
35
- this.apiService = new ZebecCardAPIService(sdkOptions?.sandbox ?? false);
36
- this.registryApiUrl = cantonConfig.registryApiUrl
37
- ? new URL(cantonConfig.registryApiUrl.toString())
38
- : localNetStaticConfig.LOCALNET_REGISTRY_API_URL;
39
- this.cantonWalletSdk = new WalletSDKImpl().configure({
40
- logger: console,
41
- ledgerFactory: createLedgerFactory(cantonConfig.ledgerApiUrl),
42
- validatorFactory: createValidatorFactory(cantonConfig.validatorAppApiUrl),
43
- tokenStandardFactory: createTokenStandardFactory(cantonConfig.ledgerApiUrl, cantonConfig.validatorAppApiUrl),
44
- });
45
- }
46
- async connect() {
47
- await this.cantonWalletSdk.connect();
48
- }
49
- async fetchVault(symbol = "CANTON") {
50
- return this.apiService.fetchVault(symbol);
51
- }
52
- getTokenStandard() {
53
- const ts = this.cantonWalletSdk.tokenStandard;
54
- if (!ts) {
55
- throw new Error("TokenStandardController is not initialized. Call connect() before transferring.");
56
- }
57
- return ts;
58
- }
59
- /**
60
- * Transfer native Canton coin (Amulet) to the Zebec vault.
61
- *
62
- * 1. Resolves the vault address for the "CANTON" symbol.
63
- * 2. Builds the transfer command via the wallet-sdk token-standard.
64
- * 3. Delegates signing and submission to the wallet adapter.
65
- */
66
- async transferNative(params) {
67
- const vault = await this.fetchVault("CANTON");
68
- const tokenStandard = this.getTokenStandard();
69
- tokenStandard.setTransferFactoryRegistryUrl(this.registryApiUrl);
70
- const [command, disclosedContracts] = await tokenStandard.createTransfer(this.wallet.partyId, vault.address, params.amount.toString(), {
71
- instrumentId: CANTON_NATIVE_INSTRUMENT_ID,
72
- instrumentAdmin: params.instrumentAdmin || DEVNET_CANTON_NATIVE_INSTRUMENT_ADMIN,
73
- }, [], vault.tag ?? params.memo);
74
- return this.wallet.executeTransaction(command, disclosedContracts);
75
- }
76
- /**
77
- * Transfer a CIP-0056 standard token to the Zebec vault.
78
- *
79
- * 1. Resolves the vault address for the given instrument symbol.
80
- * 2. Configures the token-standard with the appropriate registry URL.
81
- * 3. Builds the transfer command via the wallet-sdk token-standard.
82
- * 4. Delegates signing and submission to the wallet adapter.
83
- */
84
- async transferToken(params) {
85
- const vault = await this.fetchVault(params.instrumentId);
86
- const tokenStandard = this.getTokenStandard();
87
- const registryUrl = params.registryApiUrl
88
- ? new URL(params.registryApiUrl.toString())
89
- : this.registryApiUrl;
90
- tokenStandard.setTransferFactoryRegistryUrl(registryUrl);
91
- const [command, disclosedContracts] = await tokenStandard.createTransfer(this.wallet.partyId, vault.address, params.amount.toString(), {
92
- instrumentId: params.instrumentId,
93
- instrumentAdmin: params.instrumentAdmin,
94
- }, [], vault.tag ?? params.memo);
95
- return this.wallet.executeTransaction(command, disclosedContracts);
96
- }
97
- }