@zebec-network/exchange-card-sdk 1.5.0 → 1.6.1
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 +2 -2
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +4 -0
- package/dist/services/bobaService.d.ts +40 -0
- package/dist/services/bobaService.js +83 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/octaService.js +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Example:
|
|
|
22
22
|
|
|
23
23
|
For EVM compatible networks:
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
````typescript
|
|
26
26
|
For Bittensor Network:
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
@@ -40,7 +40,7 @@ const service = new ZebecCardTAOService(
|
|
|
40
40
|
sandbox: true, // Set to true for development or testing
|
|
41
41
|
},
|
|
42
42
|
);
|
|
43
|
-
|
|
43
|
+
````
|
|
44
44
|
|
|
45
45
|
### Fetch Quote
|
|
46
46
|
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BobaChainId } from "./types";
|
|
1
2
|
export declare const CARD_API_URL: Record<"Production" | "Sandbox", string>;
|
|
2
3
|
export declare const NEAR_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
3
4
|
export declare const XRPL_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
@@ -15,6 +16,7 @@ export declare const BITCOIN_ENDPOINTS: {
|
|
|
15
16
|
readonly Sandbox: "https://mempool.space/testnet/api";
|
|
16
17
|
readonly Production: "https://mempool.space/api";
|
|
17
18
|
};
|
|
19
|
+
export declare const BOBA_CHAIN_ID: Record<"mainnet" | "testnet", BobaChainId>;
|
|
18
20
|
export declare const DEFAULT_EVM_GAS_LIMIT = 3000000;
|
|
19
21
|
export declare const COUNTRIES_WITH_CCA3: readonly [{
|
|
20
22
|
readonly name: {
|
package/dist/constants.js
CHANGED
|
@@ -31,6 +31,10 @@ export const BITCOIN_ENDPOINTS = {
|
|
|
31
31
|
Sandbox: "https://mempool.space/testnet/api",
|
|
32
32
|
Production: "https://mempool.space/api",
|
|
33
33
|
};
|
|
34
|
+
export const BOBA_CHAIN_ID = {
|
|
35
|
+
mainnet: 288,
|
|
36
|
+
testnet: 28882,
|
|
37
|
+
};
|
|
34
38
|
export const DEFAULT_EVM_GAS_LIMIT = 3000000;
|
|
35
39
|
export const COUNTRIES_WITH_CCA3 = [
|
|
36
40
|
{
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
|
+
import { BobaChainId, Quote } from "../types";
|
|
4
|
+
export type TransferBobaParams = {
|
|
5
|
+
amount: string | number;
|
|
6
|
+
overrides?: Omit<ethers.Overrides, "from" | "value" | "chainId">;
|
|
7
|
+
};
|
|
8
|
+
export type TransferTokenParams = {
|
|
9
|
+
amount: string | number;
|
|
10
|
+
tokenAddress: string;
|
|
11
|
+
symbol: string;
|
|
12
|
+
overrides?: Omit<ethers.Overrides, "from" | "value" | "chainId">;
|
|
13
|
+
};
|
|
14
|
+
export declare class BobaService {
|
|
15
|
+
readonly signer: ethers.Signer;
|
|
16
|
+
readonly apiConfig: APIConfig;
|
|
17
|
+
readonly network: "mainnet" | "testnet";
|
|
18
|
+
readonly chainId: BobaChainId;
|
|
19
|
+
private readonly apiService;
|
|
20
|
+
constructor(signer: ethers.Signer, apiConfig: APIConfig, sdkOptions?: {
|
|
21
|
+
sandbox?: boolean;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Fetches a quote for Bitcoin transfer.
|
|
25
|
+
*
|
|
26
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
27
|
+
*/
|
|
28
|
+
fetchQuote(symbol: string): Promise<Quote>;
|
|
29
|
+
/**
|
|
30
|
+
* Fetches the Bitcoin vault address.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
33
|
+
*/
|
|
34
|
+
fetchVault(symbol: string): Promise<{
|
|
35
|
+
address: string;
|
|
36
|
+
tag?: string;
|
|
37
|
+
}>;
|
|
38
|
+
transferBobaEth(params: TransferBobaParams): Promise<ethers.TransactionReceipt | null>;
|
|
39
|
+
transferToken(params: TransferTokenParams): Promise<ethers.TransactionReceipt | null>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { ERC20__factory } from "../artifacts";
|
|
3
|
+
import { BOBA_CHAIN_ID, DEFAULT_EVM_GAS_LIMIT } from "../constants";
|
|
4
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
5
|
+
export class BobaService {
|
|
6
|
+
signer;
|
|
7
|
+
apiConfig;
|
|
8
|
+
network;
|
|
9
|
+
chainId;
|
|
10
|
+
apiService;
|
|
11
|
+
constructor(signer, apiConfig, sdkOptions) {
|
|
12
|
+
this.signer = signer;
|
|
13
|
+
this.apiConfig = apiConfig;
|
|
14
|
+
this.network = sdkOptions?.sandbox ? "testnet" : "mainnet";
|
|
15
|
+
this.chainId = BOBA_CHAIN_ID[this.network];
|
|
16
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fetches a quote for Bitcoin transfer.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
22
|
+
*/
|
|
23
|
+
async fetchQuote(symbol) {
|
|
24
|
+
const res = await this.apiService.fetchQuote(symbol);
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Fetches the Bitcoin vault address.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
31
|
+
*/
|
|
32
|
+
async fetchVault(symbol) {
|
|
33
|
+
const data = await this.apiService.fetchVault(symbol);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
async transferBobaEth(params) {
|
|
37
|
+
const parsedAmount = ethers.parseEther(params.amount.toString());
|
|
38
|
+
const provider = this.signer.provider;
|
|
39
|
+
const vault = await this.fetchVault("BOBA-ETH");
|
|
40
|
+
const recipientAddress = vault.address;
|
|
41
|
+
if (!provider) {
|
|
42
|
+
throw new Error("There is no provider in signer instance.");
|
|
43
|
+
}
|
|
44
|
+
const senderBalance = await provider.getBalance(this.signer);
|
|
45
|
+
if (senderBalance < parsedAmount) {
|
|
46
|
+
throw new Error("Insufficient balance for transaction.");
|
|
47
|
+
}
|
|
48
|
+
const overides = {
|
|
49
|
+
gasLimit: DEFAULT_EVM_GAS_LIMIT,
|
|
50
|
+
...params.overrides,
|
|
51
|
+
};
|
|
52
|
+
const response = await this.signer.sendTransaction({
|
|
53
|
+
...overides,
|
|
54
|
+
to: recipientAddress,
|
|
55
|
+
value: parsedAmount,
|
|
56
|
+
from: this.signer,
|
|
57
|
+
chainId: this.chainId,
|
|
58
|
+
});
|
|
59
|
+
console.debug("Boba Transaction Hash:", response.hash);
|
|
60
|
+
const receipt = await response.wait();
|
|
61
|
+
return receipt;
|
|
62
|
+
}
|
|
63
|
+
async transferToken(params) {
|
|
64
|
+
const tokenContract = ERC20__factory.connect(params.tokenAddress, this.signer);
|
|
65
|
+
const tokenDecimals = await tokenContract.decimals();
|
|
66
|
+
const parsedAmount = ethers.parseUnits(params.amount.toString(), tokenDecimals);
|
|
67
|
+
const vault = await this.fetchVault(params.symbol);
|
|
68
|
+
const recipientAddress = vault.address;
|
|
69
|
+
const senderBalance = await tokenContract.balanceOf(this.signer);
|
|
70
|
+
if (senderBalance < parsedAmount) {
|
|
71
|
+
throw new Error("Insufficient balance for transaction.");
|
|
72
|
+
}
|
|
73
|
+
const overides = {
|
|
74
|
+
gasLimit: DEFAULT_EVM_GAS_LIMIT,
|
|
75
|
+
...params.overrides,
|
|
76
|
+
chainId: this.chainId,
|
|
77
|
+
};
|
|
78
|
+
const response = await tokenContract.transfer(recipientAddress, parsedAmount, overides);
|
|
79
|
+
console.debug("Boba Transaction Hash:", response.hash);
|
|
80
|
+
const receipt = await response.wait();
|
|
81
|
+
return receipt;
|
|
82
|
+
}
|
|
83
|
+
}
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -41,8 +41,8 @@ export class OctaService {
|
|
|
41
41
|
throw new Error("Insufficient balance for transaction.");
|
|
42
42
|
}
|
|
43
43
|
const overides = {
|
|
44
|
-
...params.overrides,
|
|
45
44
|
gasLimit: DEFAULT_EVM_GAS_LIMIT,
|
|
45
|
+
...params.overrides,
|
|
46
46
|
};
|
|
47
47
|
const response = await this.signer.sendTransaction({
|
|
48
48
|
...overides,
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "An sdk for purchasing silver card in zebec",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"@near-js/keystores": "^2.3.0",
|
|
22
22
|
"@near-js/signers": "^2.3.0",
|
|
23
23
|
"@typechain/ethers-v6": "^0.5.1",
|
|
24
|
-
"@types/jsonwebtoken": "^9.0.7",
|
|
25
24
|
"@types/mocha": "^10.0.10",
|
|
26
25
|
"@types/node": "^24.3.1",
|
|
27
26
|
"dotenv": "^17.2.2",
|