@zebec-network/exchange-card-sdk 1.11.4 → 1.12.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.
- package/README.md +273 -30
- package/dist/helpers/apiHelpers.d.ts +15 -0
- package/dist/helpers/apiHelpers.js +36 -2
- package/dist/services/aleoService.d.ts +1 -1
- package/dist/services/aleoService.js +6 -6
- package/dist/services/algorandService.d.ts +1 -1
- package/dist/services/algorandService.js +4 -4
- package/dist/services/bobaService.d.ts +1 -2
- package/dist/services/bobaService.js +4 -4
- package/dist/services/nearService.d.ts +3 -3
- package/dist/services/nearService.js +7 -7
- package/dist/services/octaService.d.ts +2 -2
- package/dist/services/octaService.js +3 -3
- package/dist/services/quaiService.d.ts +2 -2
- package/dist/services/quaiService.js +3 -3
- package/dist/services/stellarService.d.ts +14 -14
- package/dist/services/stellarService.js +20 -20
- package/dist/services/xdbService.d.ts +8 -9
- package/dist/services/xdbService.js +10 -11
- package/dist/services/xrplService.d.ts +4 -4
- package/dist/services/xrplService.js +8 -20
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -1,56 +1,299 @@
|
|
|
1
|
-
# Zebec Card SDK
|
|
1
|
+
# Zebec Exchange Card SDK
|
|
2
2
|
|
|
3
|
-
The Zebec Card SDK
|
|
3
|
+
The Zebec Exchange Card SDK lets developers fund Zebec virtual cards from a variety of non-EVM and alt‑EVM chains by transferring native assets or supported tokens to a Zebec-managed deposit vault. Each chain is exposed through a dedicated service that wraps vault discovery, balance checks, and transaction submission.
|
|
4
|
+
|
|
5
|
+
Supported networks:
|
|
6
|
+
|
|
7
|
+
- Aleo (native credits, USAD/USDCX stablecoins, public & private transfers)
|
|
8
|
+
- Algorand (ALGO and ASA tokens, e.g. USDC)
|
|
9
|
+
- Boba Network (Mainnet / Sepolia testnet — ETH and ERC‑20)
|
|
10
|
+
- NEAR (NEAR and NEP‑141 fungible tokens)
|
|
11
|
+
- Octa Space (OCTA native transfers)
|
|
12
|
+
- Quai Network (QUAI native transfers)
|
|
13
|
+
- Stellar (XLM and USDC)
|
|
14
|
+
- XDB Chain (XDB native transfers)
|
|
15
|
+
- XRPL / Ripple (XRP and issued tokens, with trust line setup)
|
|
16
|
+
|
|
17
|
+
Every service can be toggled between mainnet (production) and testnet via the `sandbox` flag.
|
|
4
18
|
|
|
5
19
|
---
|
|
6
20
|
|
|
7
21
|
## Installation
|
|
8
22
|
|
|
9
|
-
Install the Zebec Card SDK via npm:
|
|
10
|
-
|
|
11
23
|
```bash
|
|
12
|
-
npm i @zebec-
|
|
24
|
+
npm i @zebec-network/exchange-card-sdk
|
|
13
25
|
```
|
|
14
26
|
|
|
27
|
+
Peer/runtime dependencies you may need depending on which service you use: `ethers`, `algosdk`, `xrpl`, `quais`, `@near-js/*`, `@provablehq/sdk`, `@stellar/stellar-sdk`.
|
|
28
|
+
|
|
29
|
+
## Common Concepts
|
|
30
|
+
|
|
31
|
+
### Sandbox mode
|
|
32
|
+
|
|
33
|
+
Every service constructor accepts an options bag with a `sandbox` boolean. When `sandbox: true`, the service:
|
|
34
|
+
|
|
35
|
+
- Talks to the Zebec sandbox API at `https://dev-super.api.zebec.io`.
|
|
36
|
+
- Uses the testnet RPC for its chain (e.g. Sepolia for Boba, Testnet for Algorand/Stellar/XRPL, Futurenet for XDB, etc.).
|
|
37
|
+
|
|
38
|
+
Defaults to `false` (production) when omitted.
|
|
39
|
+
|
|
40
|
+
### Vault address
|
|
41
|
+
|
|
42
|
+
Each service exposes `fetchVault(symbol?)` which calls Zebec's API to retrieve the destination deposit address (and optional memo `tag`) for a given asset symbol. All `transfer*` methods call `fetchVault` internally with the appropriate symbol — you generally do not need to call it yourself.
|
|
43
|
+
|
|
44
|
+
### API health check
|
|
45
|
+
|
|
46
|
+
The underlying `ZebecCardAPIService` exposes `ping()` which calls `/health` on the card API and returns `true` if reachable, otherwise throws.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
15
50
|
## Quick Start
|
|
16
51
|
|
|
17
|
-
|
|
52
|
+
Pick the service that matches your source chain. Each service takes a wallet/signer and an optional `{ sandbox }` config.
|
|
53
|
+
|
|
54
|
+
### Boba Network (EVM)
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { ethers } from "ethers";
|
|
58
|
+
import { BobaService } from "@zebec-network/exchange-card-sdk";
|
|
59
|
+
|
|
60
|
+
const provider = new ethers.JsonRpcProvider("https://sepolia.boba.network");
|
|
61
|
+
const signer = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
|
|
62
|
+
|
|
63
|
+
const boba = new BobaService(signer, { sandbox: true });
|
|
64
|
+
|
|
65
|
+
// Native ETH on Boba
|
|
66
|
+
await boba.transferBobaEth({ amount: "0.01" });
|
|
67
|
+
|
|
68
|
+
// ERC‑20 token on Boba
|
|
69
|
+
await boba.transferToken({
|
|
70
|
+
amount: "10",
|
|
71
|
+
symbol: "BOBA-USDC",
|
|
72
|
+
tokenAddress: "0x...",
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Octa Space (EVM)
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { ethers } from "ethers";
|
|
80
|
+
import { OctaService } from "@zebec-network/exchange-card-sdk";
|
|
81
|
+
|
|
82
|
+
const signer = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
|
|
83
|
+
const octa = new OctaService(signer, { sandbox: false });
|
|
84
|
+
|
|
85
|
+
await octa.transferOcta({ amount: "1.5" });
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Quai Network
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { QuaiService, QuaiWallet } from "@zebec-network/exchange-card-sdk";
|
|
92
|
+
|
|
93
|
+
const wallet: QuaiWallet = {
|
|
94
|
+
address: "0x...",
|
|
95
|
+
signAndSendTransaction: async (tx) => {
|
|
96
|
+
/* sign & submit */
|
|
97
|
+
return "0xhash";
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const quai = new QuaiService(wallet, { sandbox: false });
|
|
102
|
+
const txHash = await quai.transferQuai({ amount: "2.0" });
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### NEAR
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { NearService, NearWallet } from "@zebec-network/exchange-card-sdk";
|
|
109
|
+
|
|
110
|
+
const wallet: NearWallet = {
|
|
111
|
+
signerId: "alice.near",
|
|
112
|
+
signAndSendTransaction: async (transaction) => {
|
|
113
|
+
/* submit via near-api-js or wallet selector */
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const near = new NearService(wallet, { sandbox: false });
|
|
118
|
+
|
|
119
|
+
// Native NEAR
|
|
120
|
+
await near.transferNear({ amount: "1.25" });
|
|
121
|
+
|
|
122
|
+
// NEP‑141 token (e.g. USDC)
|
|
123
|
+
await near.transferTokens({
|
|
124
|
+
amount: "10",
|
|
125
|
+
tokenContractId: "usdc.fakes.testnet",
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`registerAccountInTokenContract({ tokenContractId })` is also available; `transferTokens` already invokes the same `storage_deposit` flow internally when the destination is not yet registered.
|
|
130
|
+
|
|
131
|
+
### XRPL (Ripple)
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { XRPLService, XRPLWallet } from "@zebec-network/exchange-card-sdk";
|
|
135
|
+
|
|
136
|
+
const wallet: XRPLWallet = {
|
|
137
|
+
address: "r...",
|
|
138
|
+
signTransaction: async (tx) => {
|
|
139
|
+
/* sign with xrpl.js Wallet or a wallet extension */
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const xrpl = new XRPLService(wallet, { sandbox: true });
|
|
144
|
+
|
|
145
|
+
// Native XRP
|
|
146
|
+
await xrpl.transferXRP({ amount: "5" });
|
|
147
|
+
|
|
148
|
+
// Issued token (requires a trust line)
|
|
149
|
+
await xrpl.createTrustLine({
|
|
150
|
+
amount: "1000000",
|
|
151
|
+
token: { currency: "USD", issuer: "rIssuer..." },
|
|
152
|
+
});
|
|
153
|
+
await xrpl.transferTokens({
|
|
154
|
+
amount: "10",
|
|
155
|
+
token: { currency: "USD", issuer: "rIssuer..." },
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Algorand
|
|
18
160
|
|
|
19
|
-
|
|
161
|
+
```typescript
|
|
162
|
+
import algosdk from "algosdk";
|
|
163
|
+
import { AlgorandService, AlgorandWallet } from "@zebec-network/exchange-card-sdk";
|
|
164
|
+
|
|
165
|
+
const wallet: AlgorandWallet = {
|
|
166
|
+
address: "ALGO_ADDRESS",
|
|
167
|
+
signAndSendTransaction: async (txn) => {
|
|
168
|
+
/* sign and submit, return tx id */
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const algo = new AlgorandService(wallet, { sandbox: true });
|
|
20
173
|
|
|
21
|
-
|
|
174
|
+
// Native ALGO
|
|
175
|
+
await algo.transferAlgo({ amount: "1.0", note: "card top-up" });
|
|
22
176
|
|
|
23
|
-
|
|
177
|
+
// ASA (e.g. USDC asset id 31566704 on mainnet, 10458941 on testnet)
|
|
178
|
+
await algo.transferAsset({ assetId: 10458941, amount: "10" });
|
|
179
|
+
```
|
|
24
180
|
|
|
25
|
-
|
|
26
|
-
For Bittensor Network:
|
|
181
|
+
### Stellar
|
|
27
182
|
|
|
28
183
|
```typescript
|
|
29
|
-
import {
|
|
184
|
+
import { StellarService, StellarWallet } from "@zebec-network/exchange-card-sdk";
|
|
30
185
|
|
|
31
|
-
const
|
|
186
|
+
const wallet: StellarWallet = {
|
|
187
|
+
address: "G...",
|
|
188
|
+
signTransaction: async (xdr) => {
|
|
189
|
+
/* sign and return signed xdr */
|
|
190
|
+
},
|
|
191
|
+
};
|
|
32
192
|
|
|
33
|
-
const
|
|
34
|
-
signer,
|
|
35
|
-
{
|
|
36
|
-
apiKey,
|
|
37
|
-
encryptionKey,
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
sandbox: true, // Set to true for development or testing
|
|
41
|
-
},
|
|
42
|
-
);
|
|
43
|
-
````
|
|
193
|
+
const stellar = new StellarService(wallet, { sandbox: true });
|
|
44
194
|
|
|
45
|
-
|
|
195
|
+
await stellar.transferXLM("5");
|
|
196
|
+
await stellar.transferUSDC("10");
|
|
197
|
+
```
|
|
46
198
|
|
|
47
|
-
|
|
199
|
+
`transferXLM` attaches the vault's `tag` as a `Memo.id` automatically. The USDC issuer is preconfigured for both mainnet and testnet (see `STELLAR_USDC_ISSUER`).
|
|
48
200
|
|
|
49
|
-
|
|
201
|
+
### XDB Chain
|
|
50
202
|
|
|
51
|
-
|
|
203
|
+
```typescript
|
|
204
|
+
import { XDBService, XDBWalletInterface } from "@zebec-network/exchange-card-sdk";
|
|
205
|
+
|
|
206
|
+
const wallet: XDBWalletInterface = {
|
|
207
|
+
address: "G...",
|
|
208
|
+
signTransaction: async (xdr) => {
|
|
209
|
+
/* sign and return signed xdr */
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const xdb = new XDBService(wallet, { sandbox: false });
|
|
214
|
+
await xdb.transferXDB("100");
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Aleo
|
|
52
218
|
|
|
53
219
|
```typescript
|
|
54
|
-
|
|
55
|
-
|
|
220
|
+
import { AleoService, AleoWallet } from "@zebec-network/exchange-card-sdk";
|
|
221
|
+
|
|
222
|
+
const wallet: AleoWallet = {
|
|
223
|
+
address: "aleo1...",
|
|
224
|
+
decrypt: async (ciphertext) => {
|
|
225
|
+
/* decrypt record ciphertext */
|
|
226
|
+
},
|
|
227
|
+
requestRecords: async (program, includePlaintext) => {
|
|
228
|
+
/* fetch records from wallet */
|
|
229
|
+
},
|
|
230
|
+
executeTransaction: async (opts) => {
|
|
231
|
+
/* execute program tx */
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const aleo = new AleoService(wallet, undefined, { sandbox: false });
|
|
236
|
+
|
|
237
|
+
// Native credits — public or private
|
|
238
|
+
await aleo.transferCredit({ amount: "1.5", transferType: "public" });
|
|
239
|
+
|
|
240
|
+
// Stablecoin (USAD / USDCX) — supports public and compliant private transfers
|
|
241
|
+
await aleo.transferStableCoin({
|
|
242
|
+
programId: "usad_stablecoin.aleo",
|
|
243
|
+
amount: "10",
|
|
244
|
+
transferType: "private",
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
For private stablecoin transfers, `AleoService` automatically:
|
|
249
|
+
|
|
250
|
+
1. Fetches an unspent record with sufficient balance for the program.
|
|
251
|
+
2. Builds a Sealance Merkle exclusion proof against the program's freeze list (`NETWORK_CONFIG[network].freezeListApi`) to prove the sender is not blocklisted.
|
|
252
|
+
|
|
253
|
+
Balance helpers: `getPublicBalance()`, `getPrivateBalance()`, `getPublicTokenBalance(programId, symbol)`, `getPrivateTokenBalance(programId, symbol)`.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Service Reference
|
|
258
|
+
|
|
259
|
+
| Service | Native transfer | Token transfer | Notes |
|
|
260
|
+
| ----------------- | ----------------- | ------------------------------------ | -------------------------------------------- |
|
|
261
|
+
| `BobaService` | `transferBobaEth` | `transferToken` | Boba Mainnet (288) / Sepolia testnet (28882) |
|
|
262
|
+
| `OctaService` | `transferOcta` | — | Hard-coded chainId `800001` |
|
|
263
|
+
| `QuaiService` | `transferQuai` | — | Mainnet (9) / Testnet (15000) |
|
|
264
|
+
| `NearService` | `transferNear` | `transferTokens` | Auto `storage_deposit` for NEP‑141 |
|
|
265
|
+
| `XRPLService` | `transferXRP` | `transferTokens` + `createTrustLine` | Memo / destination tag handled automatically |
|
|
266
|
+
| `AlgorandService` | `transferAlgo` | `transferAsset` | Validates ASA opt-in on recipient |
|
|
267
|
+
| `StellarService` | `transferXLM` | `transferUSDC` | Submission retries with exponential backoff |
|
|
268
|
+
| `XDBService` | `transferXDB` | — | LiveNet / Futurenet network passphrases |
|
|
269
|
+
| `AleoService` | `transferCredit` | `transferStableCoin` | Public + private with compliance proof |
|
|
270
|
+
|
|
271
|
+
### Utilities
|
|
272
|
+
|
|
273
|
+
The SDK re-exports helpers from `utils`:
|
|
274
|
+
|
|
275
|
+
- `parseAlgo` / `formatAlgo` — ALGO ↔ microAlgo conversion
|
|
276
|
+
- `parseAlgorandAsset` / `formatAlgorandAsset` — ASA base-unit conversion
|
|
277
|
+
- `getAssetDecimals(client, assetId)` — cached ASA decimals lookup
|
|
278
|
+
- `toMicroUnits` / `fromMicroUnits` — generic decimal conversion (used by Aleo)
|
|
279
|
+
- `getTokenBySymbol(symbol, network)` — fetch Aleo token metadata from `api.provable.com`
|
|
280
|
+
|
|
281
|
+
And from `constants`:
|
|
282
|
+
|
|
283
|
+
- `CARD_API_URL` — Production / Sandbox base URLs
|
|
284
|
+
- `NEAR_RPC_URL`, `XRPL_RPC_URL`, `STELLAR_RPC_URL`, `XDB_RPC_URL`, `ALGORAND_RPC_URL`
|
|
285
|
+
- `STELLAR_USDC_ISSUER`, `BITCOIN_ENDPOINTS`, `ALEO_NETWORK_CLIENT_URL`
|
|
286
|
+
- `BOBA_CHAIN_ID`, `QUAI_CHAIN_ID`, `XDB_NETWORK`
|
|
287
|
+
- Default EVM/Quai gas constants, `PLATFORM_FEE`
|
|
288
|
+
|
|
289
|
+
### Raw API client
|
|
290
|
+
|
|
291
|
+
If you need direct access to the Zebec card API:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { ZebecCardAPIService } from "@zebec-network/exchange-card-sdk";
|
|
295
|
+
|
|
296
|
+
const api = new ZebecCardAPIService(true); // sandbox
|
|
297
|
+
await api.ping();
|
|
298
|
+
const vault = await api.fetchVault("XRP");
|
|
56
299
|
```
|
|
@@ -3,8 +3,23 @@ export declare class ZebecCardAPIService {
|
|
|
3
3
|
private readonly api;
|
|
4
4
|
constructor(sandbox?: boolean);
|
|
5
5
|
ping(): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use {@link fetchVaultByTokenAddress} instead
|
|
8
|
+
*
|
|
9
|
+
* @param symbol Token symbol
|
|
10
|
+
* @returns An object containing address and tag (optional)
|
|
11
|
+
*/
|
|
6
12
|
fetchVault(symbol: string): Promise<{
|
|
7
13
|
address: string;
|
|
8
14
|
tag?: string;
|
|
9
15
|
}>;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param address mint address
|
|
19
|
+
* @returns An object containing address and tag (optional)
|
|
20
|
+
*/
|
|
21
|
+
fetchVaultByTokenAddress(address: string): Promise<{
|
|
22
|
+
address: string;
|
|
23
|
+
tag?: string;
|
|
24
|
+
}>;
|
|
10
25
|
}
|
|
@@ -13,12 +13,46 @@ export class ZebecCardAPIService {
|
|
|
13
13
|
await this.api.get("/health");
|
|
14
14
|
return true;
|
|
15
15
|
}
|
|
16
|
-
catch (
|
|
16
|
+
catch (_) {
|
|
17
17
|
throw new Error("Card service is down. Please try again later.");
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use {@link fetchVaultByTokenAddress} instead
|
|
22
|
+
*
|
|
23
|
+
* @param symbol Token symbol
|
|
24
|
+
* @returns An object containing address and tag (optional)
|
|
25
|
+
*/
|
|
20
26
|
async fetchVault(symbol) {
|
|
21
|
-
const { data } = await this.api.get(`/tokens/deposit-address`, {
|
|
27
|
+
const { data } = await this.api.get(`/tokens/deposit-address`, {
|
|
28
|
+
params: { symbol },
|
|
29
|
+
});
|
|
30
|
+
return data.data;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param address mint address
|
|
35
|
+
* @returns An object containing address and tag (optional)
|
|
36
|
+
*/
|
|
37
|
+
async fetchVaultByTokenAddress(address) {
|
|
38
|
+
const response = await this.api.get(`/tokens/deposit-address`, {
|
|
39
|
+
params: {
|
|
40
|
+
mintAddress: address,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const data = response.data;
|
|
44
|
+
if (!data ||
|
|
45
|
+
typeof data !== "object" ||
|
|
46
|
+
!("data" in data) ||
|
|
47
|
+
!data.data ||
|
|
48
|
+
typeof data.data !== "object" ||
|
|
49
|
+
!("address" in data.data) ||
|
|
50
|
+
typeof data.data.address !== "string") {
|
|
51
|
+
throw new Error(`Invalid response shape for fetching vault address by mint address. data:\n${String(data)}`);
|
|
52
|
+
}
|
|
53
|
+
if ("tag" in data.data && data.data.tag && typeof data.data.tag !== "string") {
|
|
54
|
+
throw new Error(`Invalid response shape for fetching vault address by mint address. data:\n${String(data)}`);
|
|
55
|
+
}
|
|
22
56
|
return data.data;
|
|
23
57
|
}
|
|
24
58
|
}
|
|
@@ -105,7 +105,7 @@ export declare class AleoService {
|
|
|
105
105
|
*
|
|
106
106
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
107
107
|
*/
|
|
108
|
-
|
|
108
|
+
fetchVaultByTokenAddress(address: string): Promise<{
|
|
109
109
|
address: string;
|
|
110
110
|
tag?: string;
|
|
111
111
|
}>;
|
|
@@ -54,8 +54,8 @@ export class AleoService {
|
|
|
54
54
|
*
|
|
55
55
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
56
56
|
*/
|
|
57
|
-
async
|
|
58
|
-
const data = await this.apiService.
|
|
57
|
+
async fetchVaultByTokenAddress(address) {
|
|
58
|
+
const data = await this.apiService.fetchVaultByTokenAddress(address);
|
|
59
59
|
return data;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
@@ -126,7 +126,7 @@ export class AleoService {
|
|
|
126
126
|
recipient = params.recipient;
|
|
127
127
|
}
|
|
128
128
|
else {
|
|
129
|
-
const vault = await this.
|
|
129
|
+
const vault = await this.fetchVaultByTokenAddress("credits.aleo");
|
|
130
130
|
if (!vault) {
|
|
131
131
|
throw new Error("Failed to fetch vault address");
|
|
132
132
|
}
|
|
@@ -163,14 +163,14 @@ export class AleoService {
|
|
|
163
163
|
const privateFee = params?.privateFee || false;
|
|
164
164
|
const fee = toMicroUnits(params.fee || 0.1, 6);
|
|
165
165
|
const programId = this.sandbox ? `test_${params.programId}` : params.programId;
|
|
166
|
-
const tokenSymbol = params.programId === "usad_stablecoin.aleo" ? "
|
|
166
|
+
const tokenSymbol = params.programId === "usad_stablecoin.aleo" ? "usad" : "usdcx";
|
|
167
167
|
const functionName = transferType === "public" ? "transfer_public" : "transfer_private";
|
|
168
168
|
let recipient;
|
|
169
169
|
if (params.recipient) {
|
|
170
170
|
recipient = params.recipient;
|
|
171
171
|
}
|
|
172
172
|
else {
|
|
173
|
-
const vault = await this.
|
|
173
|
+
const vault = await this.fetchVaultByTokenAddress(params.programId);
|
|
174
174
|
if (!vault) {
|
|
175
175
|
throw new Error("Failed to fetch vault address");
|
|
176
176
|
}
|
|
@@ -186,7 +186,7 @@ export class AleoService {
|
|
|
186
186
|
// For private transfer, we need to find a record with sufficient balance
|
|
187
187
|
const [record, complianceProof] = await Promise.all([
|
|
188
188
|
this._getRecord(programId),
|
|
189
|
-
this._getComplianceProof(tokenSymbol
|
|
189
|
+
this._getComplianceProof(tokenSymbol, this.wallet.address, this.sandbox ? Network.TESTNET : Network.MAINNET),
|
|
190
190
|
]);
|
|
191
191
|
inputs = [recipient, amountInMicroUnits, record, complianceProof];
|
|
192
192
|
break;
|
|
@@ -31,7 +31,7 @@ export declare class AlgorandService {
|
|
|
31
31
|
*
|
|
32
32
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
fetchVaultByAssetId(assetId: string): Promise<{
|
|
35
35
|
address: string;
|
|
36
36
|
tag?: string;
|
|
37
37
|
}>;
|
|
@@ -17,8 +17,8 @@ export class AlgorandService {
|
|
|
17
17
|
*
|
|
18
18
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
19
19
|
*/
|
|
20
|
-
async
|
|
21
|
-
const data = await this.apiService.
|
|
20
|
+
async fetchVaultByAssetId(assetId) {
|
|
21
|
+
const data = await this.apiService.fetchVaultByTokenAddress(assetId);
|
|
22
22
|
return data;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -35,7 +35,7 @@ export class AlgorandService {
|
|
|
35
35
|
if (senderBalance < parsedAmount + minBalance) {
|
|
36
36
|
throw new Error(`Insufficient balance. Need ${formatAlgo(parsedAmount + minBalance)} ALGO, have ${formatAlgo(senderBalance)} ALGO`);
|
|
37
37
|
}
|
|
38
|
-
const vault = await this.
|
|
38
|
+
const vault = await this.fetchVaultByAssetId("algo");
|
|
39
39
|
const recipientAddress = vault.address;
|
|
40
40
|
// Validate recipient address
|
|
41
41
|
if (!algosdk.isValidAddress(recipientAddress)) {
|
|
@@ -81,7 +81,7 @@ export class AlgorandService {
|
|
|
81
81
|
if (senderAlgoBalance < minAlgoForFees) {
|
|
82
82
|
throw new Error(`Insufficient ALGO for transaction fees. Need at least ${formatAlgo(minAlgoForFees)} ALGO for fees`);
|
|
83
83
|
}
|
|
84
|
-
const vault = await this.
|
|
84
|
+
const vault = await this.fetchVaultByAssetId(config.assetId.toString());
|
|
85
85
|
const recipientAddress = vault.address;
|
|
86
86
|
// Validate recipient address
|
|
87
87
|
if (!algosdk.isValidAddress(recipientAddress)) {
|
|
@@ -7,7 +7,6 @@ export type TransferBobaParams = {
|
|
|
7
7
|
export type TransferTokenParams = {
|
|
8
8
|
amount: string | number;
|
|
9
9
|
tokenAddress: string;
|
|
10
|
-
symbol: string;
|
|
11
10
|
overrides?: Omit<ethers.Overrides, "from" | "value" | "chainId">;
|
|
12
11
|
};
|
|
13
12
|
export declare class BobaService {
|
|
@@ -23,7 +22,7 @@ export declare class BobaService {
|
|
|
23
22
|
*
|
|
24
23
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
25
24
|
*/
|
|
26
|
-
|
|
25
|
+
fetchVaultByTokenAddress(address: string): Promise<{
|
|
27
26
|
address: string;
|
|
28
27
|
tag?: string;
|
|
29
28
|
}>;
|
|
@@ -18,14 +18,14 @@ export class BobaService {
|
|
|
18
18
|
*
|
|
19
19
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
20
20
|
*/
|
|
21
|
-
async
|
|
22
|
-
const data = await this.apiService.
|
|
21
|
+
async fetchVaultByTokenAddress(address) {
|
|
22
|
+
const data = await this.apiService.fetchVaultByTokenAddress(address);
|
|
23
23
|
return data;
|
|
24
24
|
}
|
|
25
25
|
async transferBobaEth(params) {
|
|
26
26
|
const parsedAmount = ethers.parseEther(params.amount.toString());
|
|
27
27
|
const provider = this.signer.provider;
|
|
28
|
-
const vault = await this.
|
|
28
|
+
const vault = await this.fetchVaultByTokenAddress("boba-eth");
|
|
29
29
|
const recipientAddress = vault.address;
|
|
30
30
|
if (!provider) {
|
|
31
31
|
throw new Error("There is no provider in signer instance.");
|
|
@@ -53,7 +53,7 @@ export class BobaService {
|
|
|
53
53
|
const tokenContract = ERC20__factory.connect(params.tokenAddress, this.signer);
|
|
54
54
|
const tokenDecimals = await tokenContract.decimals();
|
|
55
55
|
const parsedAmount = ethers.parseUnits(params.amount.toString(), tokenDecimals);
|
|
56
|
-
const vault = await this.
|
|
56
|
+
const vault = await this.fetchVaultByTokenAddress(params.tokenAddress);
|
|
57
57
|
const recipientAddress = vault.address;
|
|
58
58
|
const senderBalance = await tokenContract.balanceOf(this.signer);
|
|
59
59
|
if (senderBalance < parsedAmount) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Provider } from "@near-js/providers";
|
|
2
|
-
import { FinalExecutionOutcome } from "@near-js/types";
|
|
1
|
+
import { type Provider } from "@near-js/providers";
|
|
2
|
+
import type { FinalExecutionOutcome } from "@near-js/types";
|
|
3
3
|
export interface CreateAccountAction {
|
|
4
4
|
type: "CreateAccount";
|
|
5
5
|
}
|
|
@@ -89,7 +89,7 @@ export declare class NearService {
|
|
|
89
89
|
*
|
|
90
90
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
fetchVaultByTokenAddress(address: string): Promise<{
|
|
93
93
|
address: string;
|
|
94
94
|
tag?: string;
|
|
95
95
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
import { BigNumber } from "bignumber.js";
|
|
3
1
|
import { JsonRpcProvider } from "@near-js/providers";
|
|
4
2
|
import { parseNearAmount } from "@near-js/utils";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
import { BigNumber } from "bignumber.js";
|
|
5
5
|
import { NEAR_RPC_URL } from "../constants";
|
|
6
6
|
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
7
7
|
/**
|
|
@@ -38,13 +38,13 @@ export class NearService {
|
|
|
38
38
|
*
|
|
39
39
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
40
40
|
*/
|
|
41
|
-
async
|
|
42
|
-
const data = await this.apiService.
|
|
41
|
+
async fetchVaultByTokenAddress(address) {
|
|
42
|
+
const data = await this.apiService.fetchVaultByTokenAddress(address);
|
|
43
43
|
return data;
|
|
44
44
|
}
|
|
45
45
|
async transferNear(params) {
|
|
46
46
|
const signerId = params.signerId ? params.signerId : this.wallet.signerId;
|
|
47
|
-
const fetchVault = await this.
|
|
47
|
+
const fetchVault = await this.fetchVaultByTokenAddress("near");
|
|
48
48
|
const destination = fetchVault.address;
|
|
49
49
|
console.debug("destination:", destination);
|
|
50
50
|
const parsedAmount = parseNearAmount(params.amount);
|
|
@@ -101,10 +101,10 @@ export class NearService {
|
|
|
101
101
|
async transferTokens(params) {
|
|
102
102
|
const signerId = params.signerId ? params.signerId : this.wallet.signerId;
|
|
103
103
|
console.log("signerId:", signerId);
|
|
104
|
-
const fetchVault = await this.
|
|
104
|
+
const fetchVault = await this.fetchVaultByTokenAddress(params.tokenContractId);
|
|
105
105
|
const destination = fetchVault.address;
|
|
106
106
|
console.debug("destination:", destination);
|
|
107
|
-
|
|
107
|
+
const actions = [];
|
|
108
108
|
const GAS = "30000000000000";
|
|
109
109
|
const storageBalanceBoundsResult = await this.provider.query({
|
|
110
110
|
request_type: "call_function",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
1
|
+
import { type ethers } from "ethers";
|
|
2
2
|
export type TransferOctaParams = {
|
|
3
3
|
amount: string | number;
|
|
4
4
|
overrides?: Omit<ethers.Overrides, "from" | "value" | "chainId">;
|
|
@@ -14,7 +14,7 @@ export declare class OctaService {
|
|
|
14
14
|
*
|
|
15
15
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
fetchVaultByTokenAddress(address: string): Promise<{
|
|
18
18
|
address: string;
|
|
19
19
|
tag?: string;
|
|
20
20
|
}>;
|
|
@@ -13,14 +13,14 @@ export class OctaService {
|
|
|
13
13
|
*
|
|
14
14
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
15
15
|
*/
|
|
16
|
-
async
|
|
17
|
-
const data = await this.apiService.
|
|
16
|
+
async fetchVaultByTokenAddress(address) {
|
|
17
|
+
const data = await this.apiService.fetchVaultByTokenAddress(address);
|
|
18
18
|
return data;
|
|
19
19
|
}
|
|
20
20
|
async transferOcta(params) {
|
|
21
21
|
const parsedAmount = parseEther(params.amount.toString());
|
|
22
22
|
const provider = this.signer.provider;
|
|
23
|
-
const vault = await this.
|
|
23
|
+
const vault = await this.fetchVaultByTokenAddress("octa-native");
|
|
24
24
|
const recipientAddress = vault.address;
|
|
25
25
|
if (!provider) {
|
|
26
26
|
throw new Error("There is no provider in signer instance.");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QuaiTransactionRequest } from "quais/providers";
|
|
1
|
+
import type { QuaiTransactionRequest } from "quais/providers";
|
|
2
2
|
export type TransferQuaiParams = {
|
|
3
3
|
amount: string | number;
|
|
4
4
|
overrides?: Omit<QuaiTransactionRequest, "from" | "value" | "chainId">;
|
|
@@ -18,7 +18,7 @@ export declare class QuaiService {
|
|
|
18
18
|
*
|
|
19
19
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
fetchVaultByTokenAddress(address: string): Promise<{
|
|
22
22
|
address: string;
|
|
23
23
|
tag?: string;
|
|
24
24
|
}>;
|
|
@@ -13,13 +13,13 @@ export class QuaiService {
|
|
|
13
13
|
*
|
|
14
14
|
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
15
15
|
*/
|
|
16
|
-
async
|
|
17
|
-
const data = await this.apiService.
|
|
16
|
+
async fetchVaultByTokenAddress(address) {
|
|
17
|
+
const data = await this.apiService.fetchVaultByTokenAddress(address);
|
|
18
18
|
return data;
|
|
19
19
|
}
|
|
20
20
|
async transferQuai(params) {
|
|
21
21
|
const parsedAmount = parseQuai(params.amount.toString());
|
|
22
|
-
const vault = await this.
|
|
22
|
+
const vault = await this.fetchVaultByTokenAddress("quai");
|
|
23
23
|
const recipientAddress = vault.address;
|
|
24
24
|
const request = {
|
|
25
25
|
...params.overrides,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, Horizon } from "@
|
|
1
|
+
import { Asset, Horizon } from "@stellar/stellar-sdk";
|
|
2
2
|
export interface StellarWallet {
|
|
3
3
|
address: string;
|
|
4
4
|
signTransaction: (txXdr: string) => Promise<string>;
|
|
@@ -22,42 +22,42 @@ export declare class StellarService {
|
|
|
22
22
|
/**
|
|
23
23
|
* Fetches the Vault address.
|
|
24
24
|
*
|
|
25
|
-
* @returns
|
|
25
|
+
* @returns A promise that resolves to the Vault address.
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
fetchVaultByAsset(asset: string): Promise<{
|
|
28
28
|
address: string;
|
|
29
29
|
tag?: string;
|
|
30
30
|
}>;
|
|
31
31
|
/**
|
|
32
32
|
* Purchases a card by transferring XDB tokens.
|
|
33
33
|
*
|
|
34
|
-
* @param
|
|
34
|
+
* @param amount - The amount required to purchase a card.
|
|
35
35
|
* @returns A promise that resolves to an array containing the transaction details and the API response.
|
|
36
|
-
* @throws
|
|
37
|
-
* @throws
|
|
36
|
+
* @throws If the recipient's email address is invalid.
|
|
37
|
+
* @throws If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
|
|
38
38
|
*/
|
|
39
39
|
transferXLM(amount: string): Promise<string>;
|
|
40
40
|
/**
|
|
41
41
|
* Transfers USDC tokens.
|
|
42
42
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @returns
|
|
45
|
-
* @throws
|
|
43
|
+
* @param amount - The amount of USDC to transfer.
|
|
44
|
+
* @returns A promise that resolves to the transaction hash.
|
|
45
|
+
* @throws If there is not enough USDC balance or if the transaction fails.
|
|
46
46
|
*/
|
|
47
47
|
transferUSDC(amount: string): Promise<string>;
|
|
48
48
|
/**
|
|
49
49
|
* Retrieves the balance of the specified wallet.
|
|
50
50
|
*
|
|
51
|
-
* @param
|
|
52
|
-
* @returns
|
|
51
|
+
* @param wallet - The public key of the wallet to get the balance for.
|
|
52
|
+
* @returns - A promise that resolves to the balance of the wallet.
|
|
53
53
|
*/
|
|
54
54
|
getWalletBalance(wallet: string): Promise<string>;
|
|
55
55
|
/**
|
|
56
56
|
* Retrieves the balance of a specific token for the specified wallet.
|
|
57
57
|
*
|
|
58
|
-
* @param
|
|
59
|
-
* @param
|
|
60
|
-
* @returns
|
|
58
|
+
* @param wallet - The public key of the wallet to get the token balance for.
|
|
59
|
+
* @param asset - The asset object representing the token.
|
|
60
|
+
* @returns A promise that resolves to the balance of the token.
|
|
61
61
|
*/
|
|
62
62
|
getTokenBalance(wallet: string, asset: Asset): Promise<string>;
|
|
63
63
|
getAsset(assetCode: string, assetIssuer: string): Promise<Asset>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, Horizon, Memo, Networks, Operation, TimeoutInfinite, TransactionBuilder, } from "@
|
|
1
|
+
import { Asset, Horizon, Memo, Networks, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
|
|
2
2
|
import { STELLAR_RPC_URL, STELLAR_USDC_ISSUER } from "../constants";
|
|
3
3
|
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
4
|
export class StellarService {
|
|
@@ -23,27 +23,27 @@ export class StellarService {
|
|
|
23
23
|
/**
|
|
24
24
|
* Fetches the Vault address.
|
|
25
25
|
*
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns A promise that resolves to the Vault address.
|
|
27
27
|
*/
|
|
28
|
-
async
|
|
29
|
-
const data = await this.apiService.
|
|
28
|
+
async fetchVaultByAsset(asset) {
|
|
29
|
+
const data = await this.apiService.fetchVaultByTokenAddress(asset);
|
|
30
30
|
return data;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Purchases a card by transferring XDB tokens.
|
|
34
34
|
*
|
|
35
|
-
* @param
|
|
35
|
+
* @param amount - The amount required to purchase a card.
|
|
36
36
|
* @returns A promise that resolves to an array containing the transaction details and the API response.
|
|
37
|
-
* @throws
|
|
38
|
-
* @throws
|
|
37
|
+
* @throws If the recipient's email address is invalid.
|
|
38
|
+
* @throws If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
|
|
39
39
|
*/
|
|
40
40
|
async transferXLM(amount) {
|
|
41
41
|
// Fetch deposit address
|
|
42
|
-
const vault = await this.
|
|
42
|
+
const vault = await this.fetchVaultByAsset("CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA");
|
|
43
43
|
// Prepare transaction
|
|
44
44
|
const account = await this.server.loadAccount(this.wallet.address);
|
|
45
45
|
const fee = await this.server.fetchBaseFee();
|
|
46
|
-
const memo = Memo.id(vault.tag?.toString() || "");
|
|
46
|
+
const memo = Memo.id(vault.tag?.toString() || "0");
|
|
47
47
|
// Check Wallet balance
|
|
48
48
|
const balance = await this.getWalletBalance(this.wallet.address);
|
|
49
49
|
if (Number(balance) < Number(amount)) {
|
|
@@ -92,18 +92,18 @@ export class StellarService {
|
|
|
92
92
|
/**
|
|
93
93
|
* Transfers USDC tokens.
|
|
94
94
|
*
|
|
95
|
-
* @param
|
|
96
|
-
* @returns
|
|
97
|
-
* @throws
|
|
95
|
+
* @param amount - The amount of USDC to transfer.
|
|
96
|
+
* @returns A promise that resolves to the transaction hash.
|
|
97
|
+
* @throws If there is not enough USDC balance or if the transaction fails.
|
|
98
98
|
*/
|
|
99
99
|
async transferUSDC(amount) {
|
|
100
|
+
// Create USDC asset object
|
|
101
|
+
const usdcAsset = new Asset("USDC", this.sandbox ? STELLAR_USDC_ISSUER.Sandbox : STELLAR_USDC_ISSUER.Production);
|
|
100
102
|
// Fetch deposit address
|
|
101
|
-
const vault = await this.
|
|
103
|
+
const vault = await this.fetchVaultByAsset(`${usdcAsset.code}:${usdcAsset.issuer}`);
|
|
102
104
|
// Prepare transaction
|
|
103
105
|
const account = await this.server.loadAccount(this.wallet.address);
|
|
104
106
|
const fee = await this.server.fetchBaseFee();
|
|
105
|
-
// Create USDC asset object
|
|
106
|
-
const usdcAsset = new Asset("USDC", this.sandbox ? STELLAR_USDC_ISSUER.Sandbox : STELLAR_USDC_ISSUER.Production);
|
|
107
107
|
// Check Wallet balance
|
|
108
108
|
const balance = await this.getTokenBalance(this.wallet.address, usdcAsset);
|
|
109
109
|
if (Number(balance) < Number(amount)) {
|
|
@@ -151,8 +151,8 @@ export class StellarService {
|
|
|
151
151
|
/**
|
|
152
152
|
* Retrieves the balance of the specified wallet.
|
|
153
153
|
*
|
|
154
|
-
* @param
|
|
155
|
-
* @returns
|
|
154
|
+
* @param wallet - The public key of the wallet to get the balance for.
|
|
155
|
+
* @returns - A promise that resolves to the balance of the wallet.
|
|
156
156
|
*/
|
|
157
157
|
async getWalletBalance(wallet) {
|
|
158
158
|
const account = await this.server.loadAccount(wallet);
|
|
@@ -162,9 +162,9 @@ export class StellarService {
|
|
|
162
162
|
/**
|
|
163
163
|
* Retrieves the balance of a specific token for the specified wallet.
|
|
164
164
|
*
|
|
165
|
-
* @param
|
|
166
|
-
* @param
|
|
167
|
-
* @returns
|
|
165
|
+
* @param wallet - The public key of the wallet to get the token balance for.
|
|
166
|
+
* @param asset - The asset object representing the token.
|
|
167
|
+
* @returns A promise that resolves to the balance of the token.
|
|
168
168
|
*/
|
|
169
169
|
async getTokenBalance(wallet, asset) {
|
|
170
170
|
const account = await this.server.loadAccount(wallet);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, Horizon } from "@
|
|
1
|
+
import { Asset, Horizon } from "@stellar/stellar-sdk";
|
|
2
2
|
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
3
3
|
export interface XDBWalletInterface {
|
|
4
4
|
address: string;
|
|
@@ -25,7 +25,7 @@ export declare class XDBService {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns {Promise<string>} A promise that resolves to the Vault address.
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
fetchVaultByAsset(asset: string): Promise<{
|
|
29
29
|
address: string;
|
|
30
30
|
tag?: string;
|
|
31
31
|
}>;
|
|
@@ -34,23 +34,22 @@ export declare class XDBService {
|
|
|
34
34
|
*
|
|
35
35
|
* @param params - The parameters required to purchase a card.
|
|
36
36
|
* @returns A promise that resolves to an array containing the transaction details and the API response.
|
|
37
|
-
* @throws
|
|
38
|
-
* @throws {Error} If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
|
|
37
|
+
* @throws `Error` If there is not enough balance, or if the transaction fails.
|
|
39
38
|
*/
|
|
40
39
|
transferXDB(amount: string): Promise<string>;
|
|
41
40
|
/**
|
|
42
41
|
* Retrieves the balance of the specified wallet.
|
|
43
42
|
*
|
|
44
|
-
* @param
|
|
45
|
-
* @returns
|
|
43
|
+
* @param wallet - The public key of the wallet to get the balance for.
|
|
44
|
+
* @returns - A promise that resolves to the balance of the wallet.
|
|
46
45
|
*/
|
|
47
46
|
getNativeBalance(wallet: string): Promise<string>;
|
|
48
47
|
/**
|
|
49
48
|
* Retrieves the balance of a specific token for the specified wallet.
|
|
50
49
|
*
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @returns
|
|
50
|
+
* @param wallet - The public key of the wallet to get the token balance for.
|
|
51
|
+
* @param asset - The asset object representing the token.
|
|
52
|
+
* @returns - A promise that resolves to the balance of the token.
|
|
54
53
|
*/
|
|
55
54
|
getTokenBalance(wallet: string, asset: Asset): Promise<string>;
|
|
56
55
|
getAsset(assetCode: string, assetIssuer: string): Asset;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, Horizon, Memo, Operation, TimeoutInfinite, TransactionBuilder, } from "@
|
|
1
|
+
import { Asset, Horizon, Memo, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
|
|
2
2
|
import { XDB_NETWORK, XDB_RPC_URL } from "../constants";
|
|
3
3
|
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
4
|
export class XDBService {
|
|
@@ -25,8 +25,8 @@ export class XDBService {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns {Promise<string>} A promise that resolves to the Vault address.
|
|
27
27
|
*/
|
|
28
|
-
async
|
|
29
|
-
const data = await this.apiService.
|
|
28
|
+
async fetchVaultByAsset(asset) {
|
|
29
|
+
const data = await this.apiService.fetchVaultByTokenAddress(asset);
|
|
30
30
|
return data;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -34,12 +34,11 @@ export class XDBService {
|
|
|
34
34
|
*
|
|
35
35
|
* @param params - The parameters required to purchase a card.
|
|
36
36
|
* @returns A promise that resolves to an array containing the transaction details and the API response.
|
|
37
|
-
* @throws
|
|
38
|
-
* @throws {Error} If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
|
|
37
|
+
* @throws `Error` If there is not enough balance, or if the transaction fails.
|
|
39
38
|
*/
|
|
40
39
|
async transferXDB(amount) {
|
|
41
40
|
// Fetch deposit address
|
|
42
|
-
const vault = await this.
|
|
41
|
+
const vault = await this.fetchVaultByAsset("xdb");
|
|
43
42
|
const recipientAddress = vault.address;
|
|
44
43
|
const tag = vault.tag || "0";
|
|
45
44
|
// Prepare transaction
|
|
@@ -94,8 +93,8 @@ export class XDBService {
|
|
|
94
93
|
/**
|
|
95
94
|
* Retrieves the balance of the specified wallet.
|
|
96
95
|
*
|
|
97
|
-
* @param
|
|
98
|
-
* @returns
|
|
96
|
+
* @param wallet - The public key of the wallet to get the balance for.
|
|
97
|
+
* @returns - A promise that resolves to the balance of the wallet.
|
|
99
98
|
*/
|
|
100
99
|
async getNativeBalance(wallet) {
|
|
101
100
|
const account = await this.server.loadAccount(wallet);
|
|
@@ -105,9 +104,9 @@ export class XDBService {
|
|
|
105
104
|
/**
|
|
106
105
|
* Retrieves the balance of a specific token for the specified wallet.
|
|
107
106
|
*
|
|
108
|
-
* @param
|
|
109
|
-
* @param
|
|
110
|
-
* @returns
|
|
107
|
+
* @param wallet - The public key of the wallet to get the token balance for.
|
|
108
|
+
* @param asset - The asset object representing the token.
|
|
109
|
+
* @returns - A promise that resolves to the balance of the token.
|
|
111
110
|
*/
|
|
112
111
|
async getTokenBalance(wallet, asset) {
|
|
113
112
|
const account = await this.server.loadAccount(wallet);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseTransaction, Client, SubmittableTransaction, Transaction, TxResponse } from "xrpl";
|
|
1
|
+
import { type BaseTransaction, Client, type SubmittableTransaction, type Transaction, type TxResponse } from "xrpl";
|
|
2
2
|
export interface XRPLWallet {
|
|
3
3
|
address: string;
|
|
4
4
|
signTransaction: (transaction: SubmittableTransaction | BaseTransaction) => Promise<string>;
|
|
@@ -11,11 +11,11 @@ export declare class XRPLService {
|
|
|
11
11
|
sandbox?: boolean;
|
|
12
12
|
});
|
|
13
13
|
/**
|
|
14
|
-
* Fetches the
|
|
14
|
+
* Fetches the xrpl vault address.
|
|
15
15
|
*
|
|
16
|
-
* @returns
|
|
16
|
+
* @returns A promise that resolves to the vault address.
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
fetchVaultByTokenAddress(address: string): Promise<{
|
|
19
19
|
address: string;
|
|
20
20
|
tag?: string;
|
|
21
21
|
}>;
|
|
@@ -13,12 +13,12 @@ export class XRPLService {
|
|
|
13
13
|
this.client = new Client(xrplNetwork);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Fetches the
|
|
16
|
+
* Fetches the xrpl vault address.
|
|
17
17
|
*
|
|
18
|
-
* @returns
|
|
18
|
+
* @returns A promise that resolves to the vault address.
|
|
19
19
|
*/
|
|
20
|
-
async
|
|
21
|
-
const data = await this.apiService.
|
|
20
|
+
async fetchVaultByTokenAddress(address) {
|
|
21
|
+
const data = await this.apiService.fetchVaultByTokenAddress(address);
|
|
22
22
|
return data;
|
|
23
23
|
}
|
|
24
24
|
async transferXRP(params) {
|
|
@@ -27,13 +27,13 @@ export class XRPLService {
|
|
|
27
27
|
if (!isValidAddress(walletAddress)) {
|
|
28
28
|
throw new Error("Invalid wallet address");
|
|
29
29
|
}
|
|
30
|
-
const { address: destination, tag } = await this.
|
|
30
|
+
const { address: destination, tag } = await this.fetchVaultByTokenAddress("xrp");
|
|
31
31
|
console.debug("destination:", destination);
|
|
32
32
|
console.debug("tag:", tag);
|
|
33
33
|
if (!isValidAddress(destination)) {
|
|
34
34
|
throw new Error("Invalid destination address");
|
|
35
35
|
}
|
|
36
|
-
const destinationTag = tag && tag !== "" ? parseInt(tag) : undefined;
|
|
36
|
+
const destinationTag = tag && tag !== "" ? parseInt(tag, 10) : undefined;
|
|
37
37
|
const amountInDrops = xrpToDrops(params.amount);
|
|
38
38
|
const transaction = {
|
|
39
39
|
TransactionType: "Payment",
|
|
@@ -49,9 +49,6 @@ export class XRPLService {
|
|
|
49
49
|
const response = await this.client.submitAndWait(signedTx);
|
|
50
50
|
return response;
|
|
51
51
|
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
52
|
finally {
|
|
56
53
|
await this.client.disconnect();
|
|
57
54
|
}
|
|
@@ -62,13 +59,13 @@ export class XRPLService {
|
|
|
62
59
|
if (!isValidAddress(walletAddress)) {
|
|
63
60
|
throw new Error("Invalid wallet address");
|
|
64
61
|
}
|
|
65
|
-
const { address: destination, tag } = await this.
|
|
62
|
+
const { address: destination, tag } = await this.fetchVaultByTokenAddress(params.token.currency);
|
|
66
63
|
console.debug("destination:", destination);
|
|
67
64
|
console.debug("tag:", tag);
|
|
68
65
|
if (!isValidAddress(destination)) {
|
|
69
66
|
throw new Error("Invalid destination address");
|
|
70
67
|
}
|
|
71
|
-
const destinationTag = tag && tag !== "" ? parseInt(tag) : undefined;
|
|
68
|
+
const destinationTag = tag && tag !== "" ? parseInt(tag, 10) : undefined;
|
|
72
69
|
const transaction = {
|
|
73
70
|
TransactionType: "Payment",
|
|
74
71
|
Account: walletAddress,
|
|
@@ -87,9 +84,6 @@ export class XRPLService {
|
|
|
87
84
|
const response = await this.client.submitAndWait(signedTx);
|
|
88
85
|
return response;
|
|
89
86
|
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
87
|
finally {
|
|
94
88
|
await this.client.disconnect();
|
|
95
89
|
}
|
|
@@ -115,9 +109,6 @@ export class XRPLService {
|
|
|
115
109
|
const response = await this.client.submitAndWait(signedTx);
|
|
116
110
|
return response;
|
|
117
111
|
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
112
|
finally {
|
|
122
113
|
await this.client.disconnect();
|
|
123
114
|
}
|
|
@@ -134,9 +125,6 @@ export class XRPLService {
|
|
|
134
125
|
});
|
|
135
126
|
return balances;
|
|
136
127
|
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
128
|
finally {
|
|
141
129
|
await this.client.disconnect();
|
|
142
130
|
}
|
package/package.json
CHANGED
|
@@ -6,27 +6,27 @@
|
|
|
6
6
|
"@near-js/transactions": "^2.5.1",
|
|
7
7
|
"@near-js/types": "^2.5.1",
|
|
8
8
|
"@near-js/utils": "^2.5.1",
|
|
9
|
-
"@provablehq/sdk": "^0.
|
|
10
|
-
"@
|
|
11
|
-
"algosdk": "^3.
|
|
12
|
-
"axios": "^1.
|
|
13
|
-
"bignumber.js": "^
|
|
14
|
-
"ethers": "^6.
|
|
15
|
-
"quais": "^1.0.0-alpha.
|
|
16
|
-
"xrpl": "^4.
|
|
9
|
+
"@provablehq/sdk": "^0.11.0",
|
|
10
|
+
"@stellar/stellar-sdk": "^15.1.0",
|
|
11
|
+
"algosdk": "^3.5.2",
|
|
12
|
+
"axios": "^1.16.0",
|
|
13
|
+
"bignumber.js": "^11.1.1",
|
|
14
|
+
"ethers": "^6.16.0",
|
|
15
|
+
"quais": "^1.0.0-alpha.54",
|
|
16
|
+
"xrpl": "^4.6.0"
|
|
17
17
|
},
|
|
18
18
|
"description": "An sdk for purchasing silver card in zebec",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@algorandfoundation/algokit-utils": "^9.
|
|
20
|
+
"@algorandfoundation/algokit-utils": "^9.2.0",
|
|
21
21
|
"@near-js/accounts": "^2.5.1",
|
|
22
22
|
"@near-js/keystores": "^2.5.1",
|
|
23
23
|
"@near-js/signers": "^2.5.1",
|
|
24
24
|
"@near-js/tokens": "^2.5.1",
|
|
25
25
|
"@typechain/ethers-v6": "^0.5.1",
|
|
26
26
|
"@types/mocha": "^10.0.10",
|
|
27
|
-
"@types/node": "^25.
|
|
28
|
-
"dotenv": "^17.
|
|
29
|
-
"mocha": "^11.7.
|
|
27
|
+
"@types/node": "^25.7.0",
|
|
28
|
+
"dotenv": "^17.4.2",
|
|
29
|
+
"mocha": "^11.7.5",
|
|
30
30
|
"prettier": "^3.6.2",
|
|
31
31
|
"rimraf": "^6.0.1",
|
|
32
32
|
"ts-mocha": "^11.1.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
},
|
|
64
64
|
"type": "module",
|
|
65
65
|
"types": "dist/index.d.ts",
|
|
66
|
-
"version": "1.
|
|
66
|
+
"version": "1.12.0"
|
|
67
67
|
}
|