@zebec-network/exchange-card-sdk 1.4.0 → 1.5.0-beta.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/dist/artifacts/abi/index.js +2 -8
- package/dist/artifacts/index.js +2 -18
- package/dist/artifacts/typechain-types/ERC20.js +1 -2
- package/dist/artifacts/typechain-types/common.js +1 -2
- package/dist/artifacts/typechain-types/factories/ERC20__factory.js +4 -8
- package/dist/artifacts/typechain-types/factories/index.js +1 -5
- package/dist/artifacts/typechain-types/index.js +2 -39
- package/dist/constants.js +11 -14
- package/dist/helpers/apiHelpers.js +12 -19
- package/dist/index.js +5 -21
- package/dist/services/algorandService.js +26 -33
- package/dist/services/bitcoinService.js +10 -50
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +7 -21
- package/dist/services/nearService.js +18 -26
- package/dist/services/octaService.js +7 -11
- package/dist/services/stellarService.js +20 -24
- package/dist/services/xdbService.js +14 -18
- package/dist/services/xrplService.js +14 -18
- package/dist/services/zanoService.d.ts +56 -0
- package/dist/services/zanoService.js +107 -0
- package/dist/types.js +1 -2
- package/dist/utils.js +13 -24
- package/package.json +4 -3
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ERC20_ABI = void 0;
|
|
7
|
-
const ERC20_json_1 = __importDefault(require("./ERC20.json"));
|
|
8
|
-
exports.ERC20_ABI = ERC20_json_1.default.abi;
|
|
1
|
+
import ERC20 from "./ERC20.json";
|
|
2
|
+
export const ERC20_ABI = ERC20.abi;
|
package/dist/artifacts/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./abi"), exports);
|
|
18
|
-
__exportStar(require("./typechain-types"), exports);
|
|
1
|
+
export * from "./abi";
|
|
2
|
+
export * from "./typechain-types";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ERC20__factory = void 0;
|
|
4
1
|
/* Autogenerated file. Do not edit manually. */
|
|
5
2
|
/* tslint:disable */
|
|
6
3
|
/* eslint-disable */
|
|
7
|
-
|
|
4
|
+
import { Contract, ContractFactory, Interface } from "ethers";
|
|
8
5
|
const _abi = [
|
|
9
6
|
{
|
|
10
7
|
inputs: [],
|
|
@@ -348,7 +345,7 @@ const _abi = [
|
|
|
348
345
|
];
|
|
349
346
|
const _bytecode = "0x608034620003fb5760406001600160401b0382820181811184821017620003e5578252600f835260206e21b0b932102a32b9ba102a37b5b2b760891b8185015282519383850185811084821117620003e55784526004928386526321aa25a760e11b83870152815195818711620003d057600390815497600194858a811c9a168015620003c5575b878b1014620003b0578190601f9a8b81116200035a575b5087908b8311600114620002f357600092620002e7575b505060001982851b1c191690851b1782555b8051928311620002d25785548481811c91168015620002c7575b86821014620002b25788811162000267575b5084978311600114620001fe5796829394959697600093620001f2575b505082841b92600019911b1c19161783555b600580546001600160a81b03191633600890811b610100600160a81b0316919091179290921790819055901c6001600160a01b0316918215620001db576002546a0422ca8b0a00a42500000091828201809211620001c6575060025560008381528083528481208054830190558451918252917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a3516107669081620004018239f35b601190634e487b7160e01b6000525260246000fd5b602490600085519163ec442f0560e01b8352820152fd5b01519150388062000110565b90601f1983169786600052856000209260005b8a811062000251575084869798999a1062000236575b50505050811b01835562000122565b01519060f884600019921b161c191690553880808062000227565b8183015185559386019391870191870162000211565b86600052856000208980860160051c820192888710620002a8575b0160051c019085905b8281106200029b575050620000f3565b600081550185906200028b565b9250819262000282565b602287634e487b7160e01b6000525260246000fd5b90607f1690620000e1565b604186634e487b7160e01b6000525260246000fd5b015190503880620000b5565b90879350601f1983169186600052896000209260005b8b8282106200034357505084116200032a575b505050811b018255620000c7565b015160001983871b60f8161c191690553880806200031c565b8385015186558b9790950194938401930162000309565b90915084600052876000208b80850160051c8201928a8610620003a6575b918991869594930160051c01915b828110620003965750506200009e565b6000815585945089910162000386565b9250819262000378565b602288634e487b7160e01b6000525260246000fd5b99607f169962000087565b604185634e487b7160e01b6000525260246000fd5b634e487b7160e01b600052604160045260246000fd5b600080fdfe608060408181526004918236101561001657600080fd5b600092833560e01c91826306fdde03146104b557508163075461721461048a578163095ea7b3146103de57816318160ddd146103bf5781631f2698ab1461039b57816323b872dd1461028c578163313ce5671461027057816370a082311461023a57816395d89b411461011957508063a9059cbb146100e95763dd62ed3e1461009e57600080fd5b346100e557806003193601126100e557806020926100ba6105d8565b6100c26105f3565b6001600160a01b0391821683526001865283832091168252845220549051908152f35b5080fd5b50346100e557806003193601126100e5576020906101126101086105d8565b6024359033610609565b5160018152f35b8383346100e557816003193601126100e55780519082845460018160011c9060018316928315610230575b602093848410811461021d5783885290811561020157506001146101ac575b505050829003601f01601f191682019267ffffffffffffffff841183851017610199575082918261019592528261058f565b0390f35b80604186634e487b7160e01b6024945252fd5b8787529192508591837f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b5b8385106101ed5750505050830101858080610163565b8054888601830152930192849082016101d7565b60ff1916878501525050151560051b8401019050858080610163565b60248960228c634e487b7160e01b835252fd5b91607f1691610144565b5050346100e55760203660031901126100e557806020926001600160a01b036102616105d8565b16815280845220549051908152f35b5050346100e557816003193601126100e5576020905160128152f35b90508234610398576060366003190112610398576102a86105d8565b6102b06105f3565b91604435936001600160a01b0383168083526001602052868320338452602052868320549160001983036102ed575b602088610112898989610609565b86831061035357811561033d57331561032757508252600160209081528683203384528152918690209085900390558290610112876102df565b60249084895191634a1406b160e11b8352820152fd5b6024908489519163e602df0560e01b8352820152fd5b87517ffb8f41b2000000000000000000000000000000000000000000000000000000008152339181019182526020820193909352604081018790528291506060010390fd5b80fd5b5050346100e557816003193601126100e55760209060ff6005541690519015158152f35b5050346100e557816003193601126100e5576020906002549051908152f35b9050346104865781600319360112610486576103f86105d8565b602435903315610470576001600160a01b031691821561045a57508083602095338152600187528181208582528752205582519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925843392a35160018152f35b60249085855191634a1406b160e11b8352820152fd5b6024838686519163e602df0560e01b8352820152fd5b8280fd5b5050346100e557816003193601126100e5576020906001600160a01b0360055460081c169051908152f35b849084346104865782600319360112610486578260035460018160011c9060018316928315610585575b602093848410811461021d57838852908115610201575060011461052f57505050829003601f01601f191682019267ffffffffffffffff841183851017610199575082918261019592528261058f565b600387529192508591837fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b8385106105715750505050830101858080610163565b80548886018301529301928490820161055b565b91607f16916104df565b6020808252825181830181905290939260005b8281106105c457505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016105a2565b600435906001600160a01b03821682036105ee57565b600080fd5b602435906001600160a01b03821682036105ee57565b916001600160a01b038084169283156106ff57169283156106ce5760009083825281602052604082205490838210610683575091604082827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef958760209652828652038282205586815220818154019055604051908152a3565b6040517fe450d38c0000000000000000000000000000000000000000000000000000000081526001600160a01b03919091166004820152602481019190915260448101839052606490fd5b60246040517fec442f0500000000000000000000000000000000000000000000000000000000815260006004820152fd5b60246040517f96c6fd1e00000000000000000000000000000000000000000000000000000000815260006004820152fdfea2646970667358221220a895ef5f3cf026b48a9ffb4320764182cae42330f3d36a62637bec75ffa74e3c64736f6c63430008180033";
|
|
350
347
|
const isSuperArgs = (xs) => xs.length > 1;
|
|
351
|
-
class ERC20__factory extends
|
|
348
|
+
export class ERC20__factory extends ContractFactory {
|
|
352
349
|
constructor(...args) {
|
|
353
350
|
if (isSuperArgs(args)) {
|
|
354
351
|
super(...args);
|
|
@@ -369,10 +366,9 @@ class ERC20__factory extends ethers_1.ContractFactory {
|
|
|
369
366
|
static bytecode = _bytecode;
|
|
370
367
|
static abi = _abi;
|
|
371
368
|
static createInterface() {
|
|
372
|
-
return new
|
|
369
|
+
return new Interface(_abi);
|
|
373
370
|
}
|
|
374
371
|
static connect(address, runner) {
|
|
375
|
-
return new
|
|
372
|
+
return new Contract(address, _abi, runner);
|
|
376
373
|
}
|
|
377
374
|
}
|
|
378
|
-
exports.ERC20__factory = ERC20__factory;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ERC20__factory = void 0;
|
|
4
1
|
/* Autogenerated file. Do not edit manually. */
|
|
5
2
|
/* tslint:disable */
|
|
6
3
|
/* eslint-disable */
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "ERC20__factory", { enumerable: true, get: function () { return ERC20__factory_1.ERC20__factory; } });
|
|
4
|
+
export { ERC20__factory } from "./ERC20__factory";
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ERC20__factory = exports.factories = void 0;
|
|
37
|
-
exports.factories = __importStar(require("./factories"));
|
|
38
|
-
var ERC20__factory_1 = require("./factories/ERC20__factory");
|
|
39
|
-
Object.defineProperty(exports, "ERC20__factory", { enumerable: true, get: function () { return ERC20__factory_1.ERC20__factory; } });
|
|
1
|
+
export * as factories from "./factories";
|
|
2
|
+
export { ERC20__factory } from "./factories/ERC20__factory";
|
package/dist/constants.js
CHANGED
|
@@ -1,41 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PLATFORM_FEE = exports.COUNTRIES_WITH_CCA3 = exports.DEFAULT_EVM_GAS_LIMIT = exports.BITCOIN_ENDPOINTS = exports.STELLAR_USDC_ISSUER = exports.XDB_NETWORK = exports.XDB_RPC_URL = exports.STELLAR_RPC_URL = exports.XRPL_RPC_URL = exports.NEAR_RPC_URL = exports.CARD_API_URL = void 0;
|
|
4
|
-
exports.CARD_API_URL = {
|
|
1
|
+
export const CARD_API_URL = {
|
|
5
2
|
Production: "https://cex.card.zebec.io",
|
|
6
3
|
Sandbox: "https://cex.card.zebec.io",
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export const NEAR_RPC_URL = {
|
|
9
6
|
Production: process.env.NEAR_RPC_URL ? process.env.NEAR_RPC_URL : "https://rpc.mainnet.near.org",
|
|
10
7
|
Sandbox: "https://rpc.testnet.near.org",
|
|
11
8
|
};
|
|
12
|
-
|
|
9
|
+
export const XRPL_RPC_URL = {
|
|
13
10
|
Production: "wss://xrplcluster.com",
|
|
14
11
|
Sandbox: "wss://s.altnet.rippletest.net:51233",
|
|
15
12
|
};
|
|
16
|
-
|
|
13
|
+
export const STELLAR_RPC_URL = {
|
|
17
14
|
Production: "https://horizon.stellar.org",
|
|
18
15
|
Sandbox: "https://horizon-testnet.stellar.org",
|
|
19
16
|
};
|
|
20
|
-
|
|
17
|
+
export const XDB_RPC_URL = {
|
|
21
18
|
Production: "https://horizon.livenet.xdbchain.com/",
|
|
22
19
|
Sandbox: "https://horizon.futurenet.xdbchain.com/",
|
|
23
20
|
};
|
|
24
|
-
|
|
21
|
+
export const XDB_NETWORK = {
|
|
25
22
|
PUBLIC: "LiveNet Global XDBChain Network ; November 2023",
|
|
26
23
|
TESTNET: "Futurenet XDBChain Network ; October 2023",
|
|
27
24
|
};
|
|
28
25
|
// Add USDC asset constants
|
|
29
|
-
|
|
26
|
+
export const STELLAR_USDC_ISSUER = {
|
|
30
27
|
Sandbox: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
|
|
31
28
|
Production: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
|
|
32
29
|
};
|
|
33
|
-
|
|
30
|
+
export const BITCOIN_ENDPOINTS = {
|
|
34
31
|
Sandbox: "https://mempool.space/testnet/api",
|
|
35
32
|
Production: "https://mempool.space/api",
|
|
36
33
|
};
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
export const DEFAULT_EVM_GAS_LIMIT = 3000000;
|
|
35
|
+
export const COUNTRIES_WITH_CCA3 = [
|
|
39
36
|
{
|
|
40
37
|
name: {
|
|
41
38
|
common: "South Georgia",
|
|
@@ -2486,4 +2483,4 @@ exports.COUNTRIES_WITH_CCA3 = [
|
|
|
2486
2483
|
cca3: "AIA",
|
|
2487
2484
|
},
|
|
2488
2485
|
];
|
|
2489
|
-
|
|
2486
|
+
export const PLATFORM_FEE = 5 * 100;
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ZebecCardAPIService = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
-
const constants_1 = require("../constants");
|
|
10
|
-
class ZebecCardAPIService {
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
import { CARD_API_URL } from "../constants";
|
|
4
|
+
export class ZebecCardAPIService {
|
|
11
5
|
apiConfig;
|
|
12
6
|
sdkVersion = "1.0.0";
|
|
13
7
|
api;
|
|
14
8
|
constructor(apiConfig, sandbox) {
|
|
15
9
|
this.apiConfig = {
|
|
16
10
|
...apiConfig,
|
|
17
|
-
apiUrl: sandbox ?
|
|
11
|
+
apiUrl: sandbox ? CARD_API_URL.Sandbox : CARD_API_URL.Production,
|
|
18
12
|
};
|
|
19
|
-
this.api =
|
|
13
|
+
this.api = axios.create({ baseURL: this.apiConfig.apiUrl });
|
|
20
14
|
}
|
|
21
15
|
// Generate request signature
|
|
22
16
|
generateSignature(method, path, timestamp, body) {
|
|
@@ -27,7 +21,7 @@ class ZebecCardAPIService {
|
|
|
27
21
|
this.apiConfig.apiKey,
|
|
28
22
|
body ? JSON.stringify(body) : "",
|
|
29
23
|
].join("");
|
|
30
|
-
return
|
|
24
|
+
return crypto
|
|
31
25
|
.createHmac("sha256", this.apiConfig.encryptionKey)
|
|
32
26
|
.update(stringToSign)
|
|
33
27
|
.digest("hex");
|
|
@@ -35,7 +29,7 @@ class ZebecCardAPIService {
|
|
|
35
29
|
// Generate request headers
|
|
36
30
|
generateRequestHeaders(method, path, body) {
|
|
37
31
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
38
|
-
const nonce =
|
|
32
|
+
const nonce = crypto.randomBytes(16).toString("hex");
|
|
39
33
|
return {
|
|
40
34
|
"X-API-Key": this.apiConfig.apiKey,
|
|
41
35
|
"X-Timestamp": timestamp.toString(),
|
|
@@ -47,9 +41,9 @@ class ZebecCardAPIService {
|
|
|
47
41
|
}
|
|
48
42
|
// Encrypt sensitive data fields
|
|
49
43
|
encryptSensitiveData(data) {
|
|
50
|
-
const iv =
|
|
51
|
-
const key =
|
|
52
|
-
const cipher =
|
|
44
|
+
const iv = crypto.randomBytes(16);
|
|
45
|
+
const key = crypto.pbkdf2Sync(this.apiConfig.encryptionKey, iv, 1000, 32, "sha256");
|
|
46
|
+
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
|
|
53
47
|
let encrypted = cipher.update(JSON.stringify(data), "utf8", "base64");
|
|
54
48
|
encrypted += cipher.final("base64");
|
|
55
49
|
const authTag = cipher.getAuthTag();
|
|
@@ -75,7 +69,7 @@ class ZebecCardAPIService {
|
|
|
75
69
|
const url = this.apiConfig.apiUrl + path;
|
|
76
70
|
const payload = { data: encryptedData };
|
|
77
71
|
const headers = this.generateRequestHeaders(method, path, payload);
|
|
78
|
-
const response = await
|
|
72
|
+
const response = await axios.post(url, payload, { headers });
|
|
79
73
|
return response;
|
|
80
74
|
}
|
|
81
75
|
// Fetch quote
|
|
@@ -89,4 +83,3 @@ class ZebecCardAPIService {
|
|
|
89
83
|
return data.data;
|
|
90
84
|
}
|
|
91
85
|
}
|
|
92
|
-
exports.ZebecCardAPIService = ZebecCardAPIService;
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./artifacts"), exports);
|
|
18
|
-
__exportStar(require("./constants"), exports);
|
|
19
|
-
__exportStar(require("./services"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
21
|
-
__exportStar(require("./utils"), exports);
|
|
1
|
+
export * from "./artifacts";
|
|
2
|
+
export * from "./constants";
|
|
3
|
+
export * from "./services";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export * from "./utils";
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const algosdk_1 = __importDefault(require("algosdk"));
|
|
8
|
-
const algokit_utils_1 = require("@algorandfoundation/algokit-utils");
|
|
9
|
-
const client_manager_1 = require("@algorandfoundation/algokit-utils/types/client-manager");
|
|
10
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
|
-
class AlgorandService {
|
|
1
|
+
import algosdk from "algosdk";
|
|
2
|
+
import { AlgorandClient } from "@algorandfoundation/algokit-utils";
|
|
3
|
+
import { ClientManager } from "@algorandfoundation/algokit-utils/types/client-manager";
|
|
4
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
5
|
+
import { formatAlgo, formatAlgorandAsset, getAssetDecimals, parseAlgo, parseAlgorandAsset, } from "../utils";
|
|
6
|
+
export class AlgorandService {
|
|
13
7
|
wallet;
|
|
14
8
|
apiConfig;
|
|
15
9
|
algodClient;
|
|
@@ -20,11 +14,11 @@ class AlgorandService {
|
|
|
20
14
|
this.wallet = wallet;
|
|
21
15
|
this.apiConfig = apiConfig;
|
|
22
16
|
this.network = sdkOptions?.sandbox ? "testnet" : "mainnet";
|
|
23
|
-
this.algodClient =
|
|
24
|
-
this.algorandClient =
|
|
17
|
+
this.algodClient = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig(this.network, "algod"));
|
|
18
|
+
this.algorandClient = AlgorandClient.fromClients({
|
|
25
19
|
algod: this.algodClient,
|
|
26
20
|
});
|
|
27
|
-
this.apiService = new
|
|
21
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
|
|
28
22
|
}
|
|
29
23
|
/**
|
|
30
24
|
* Fetches a quote for Bitcoin transfer.
|
|
@@ -51,23 +45,23 @@ class AlgorandService {
|
|
|
51
45
|
*/
|
|
52
46
|
async transferAlgo(config) {
|
|
53
47
|
try {
|
|
54
|
-
const parsedAmount =
|
|
48
|
+
const parsedAmount = parseAlgo(config.amount);
|
|
55
49
|
// Check if sender has sufficient balance
|
|
56
50
|
const senderBalance = await this.getAccountBalanceInMicroAlgo(this.wallet.address);
|
|
57
|
-
const minBalance =
|
|
51
|
+
const minBalance = parseAlgo(0.1); // Minimum account balance
|
|
58
52
|
if (senderBalance < parsedAmount + minBalance) {
|
|
59
|
-
throw new Error(`Insufficient balance. Need ${
|
|
53
|
+
throw new Error(`Insufficient balance. Need ${formatAlgo(parsedAmount + minBalance)} ALGO, have ${formatAlgo(senderBalance)} ALGO`);
|
|
60
54
|
}
|
|
61
55
|
const vault = await this.fetchVault("ALGO");
|
|
62
56
|
const recipientAddress = vault.address;
|
|
63
57
|
// Validate recipient address
|
|
64
|
-
if (!
|
|
58
|
+
if (!algosdk.isValidAddress(recipientAddress)) {
|
|
65
59
|
throw new Error("Invalid recipient address");
|
|
66
60
|
}
|
|
67
61
|
// Get suggested transaction parameters
|
|
68
62
|
const suggestedParams = await this.algodClient.getTransactionParams().do();
|
|
69
63
|
// Create payment transaction
|
|
70
|
-
const paymentTxn =
|
|
64
|
+
const paymentTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
|
|
71
65
|
sender: this.wallet.address,
|
|
72
66
|
receiver: recipientAddress,
|
|
73
67
|
amount: parsedAmount,
|
|
@@ -90,24 +84,24 @@ class AlgorandService {
|
|
|
90
84
|
*/
|
|
91
85
|
async transferAsset(config) {
|
|
92
86
|
try {
|
|
93
|
-
const assetDecimals = await
|
|
87
|
+
const assetDecimals = await getAssetDecimals(this.algodClient, config.assetId);
|
|
94
88
|
// const usdcConfig = USDC_ASSET_CONFIG[this.network];
|
|
95
|
-
const parsedAmount =
|
|
89
|
+
const parsedAmount = parseAlgorandAsset(config.amount, assetDecimals);
|
|
96
90
|
// Check if sender has sufficient USDC balance
|
|
97
91
|
const senderAssetBalance = await this.getAssetBalanceInMicroUnit(this.wallet.address, config.assetId);
|
|
98
92
|
if (senderAssetBalance < parsedAmount) {
|
|
99
|
-
throw new Error(`Insufficient Asset balance. Need ${
|
|
93
|
+
throw new Error(`Insufficient Asset balance. Need ${formatAlgorandAsset(parsedAmount, assetDecimals)} Asset, have ${formatAlgorandAsset(senderAssetBalance, assetDecimals)} Asset`);
|
|
100
94
|
}
|
|
101
95
|
// Check if sender has sufficient ALGO for transaction fees
|
|
102
96
|
const senderAlgoBalance = await this.getAccountBalanceInMicroAlgo(this.wallet.address);
|
|
103
|
-
const minAlgoForFees =
|
|
97
|
+
const minAlgoForFees = parseAlgo(0.002); // Minimum ALGO for transaction fees
|
|
104
98
|
if (senderAlgoBalance < minAlgoForFees) {
|
|
105
|
-
throw new Error(`Insufficient ALGO for transaction fees. Need at least ${
|
|
99
|
+
throw new Error(`Insufficient ALGO for transaction fees. Need at least ${formatAlgo(minAlgoForFees)} ALGO for fees`);
|
|
106
100
|
}
|
|
107
101
|
const vault = await this.fetchVault("ALGO-USDC");
|
|
108
102
|
const recipientAddress = vault.address;
|
|
109
103
|
// Validate recipient address
|
|
110
|
-
if (!
|
|
104
|
+
if (!algosdk.isValidAddress(recipientAddress)) {
|
|
111
105
|
throw new Error("Invalid recipient address");
|
|
112
106
|
}
|
|
113
107
|
// // Check if recipient is opted into USDC asset
|
|
@@ -118,7 +112,7 @@ class AlgorandService {
|
|
|
118
112
|
// Get suggested transaction parameters
|
|
119
113
|
const suggestedParams = await this.algodClient.getTransactionParams().do();
|
|
120
114
|
// Create asset transfer transaction
|
|
121
|
-
const assetTransferTxn =
|
|
115
|
+
const assetTransferTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
|
|
122
116
|
sender: this.wallet.address,
|
|
123
117
|
receiver: recipientAddress,
|
|
124
118
|
amount: parsedAmount,
|
|
@@ -170,8 +164,8 @@ class AlgorandService {
|
|
|
170
164
|
}
|
|
171
165
|
async getAssetBalance(walletAddress, assetId) {
|
|
172
166
|
const balance = await this.getAssetBalanceInMicroUnit(walletAddress, assetId);
|
|
173
|
-
const decimals = await
|
|
174
|
-
return
|
|
167
|
+
const decimals = await getAssetDecimals(this.algodClient, assetId);
|
|
168
|
+
return formatAlgorandAsset(balance, decimals);
|
|
175
169
|
}
|
|
176
170
|
async getAssetsBalance(walletAddress, assetIds) {
|
|
177
171
|
const map = new Map(Array.from(assetIds.map((id) => [id, "0"])));
|
|
@@ -184,8 +178,8 @@ class AlgorandService {
|
|
|
184
178
|
await Promise.all(assetIds.map(async (id) => {
|
|
185
179
|
const asset = assets.find((asset) => asset.assetId === BigInt(id));
|
|
186
180
|
if (asset) {
|
|
187
|
-
const decimals = await
|
|
188
|
-
const amount =
|
|
181
|
+
const decimals = await getAssetDecimals(this.algodClient, id);
|
|
182
|
+
const amount = formatAlgorandAsset(asset.amount, decimals);
|
|
189
183
|
map.set(id, amount);
|
|
190
184
|
}
|
|
191
185
|
}));
|
|
@@ -203,7 +197,7 @@ class AlgorandService {
|
|
|
203
197
|
*/
|
|
204
198
|
async getAccountBalance(address) {
|
|
205
199
|
const amount = await this.getAccountBalanceInMicroAlgo(address);
|
|
206
|
-
return
|
|
200
|
+
return formatAlgo(amount);
|
|
207
201
|
}
|
|
208
202
|
/**
|
|
209
203
|
* Get account balance in microAlgos (for internal calculations)
|
|
@@ -215,4 +209,3 @@ class AlgorandService {
|
|
|
215
209
|
return accountInfo.amount;
|
|
216
210
|
}
|
|
217
211
|
}
|
|
218
|
-
exports.AlgorandService = AlgorandService;
|
|
@@ -1,47 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.BitcoinService = void 0;
|
|
40
|
-
const axios_1 = __importDefault(require("axios"));
|
|
41
|
-
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
42
|
-
const constants_1 = require("../constants");
|
|
43
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
44
|
-
class BitcoinService {
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
3
|
+
import { BITCOIN_ENDPOINTS } from "../constants";
|
|
4
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
5
|
+
export class BitcoinService {
|
|
45
6
|
wallet;
|
|
46
7
|
apiService;
|
|
47
8
|
network;
|
|
@@ -49,9 +10,9 @@ class BitcoinService {
|
|
|
49
10
|
constructor(wallet, apiConfig, sdkOptions) {
|
|
50
11
|
this.wallet = wallet;
|
|
51
12
|
const sandbox = sdkOptions?.sandbox ?? false;
|
|
52
|
-
this.apiService = new
|
|
13
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
|
|
53
14
|
this.network = sandbox ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
54
|
-
this.apiEndpoint = sandbox ?
|
|
15
|
+
this.apiEndpoint = sandbox ? BITCOIN_ENDPOINTS.Sandbox : BITCOIN_ENDPOINTS.Production;
|
|
55
16
|
}
|
|
56
17
|
/**
|
|
57
18
|
* Fetches a quote for Bitcoin transfer.
|
|
@@ -72,10 +33,10 @@ class BitcoinService {
|
|
|
72
33
|
return data;
|
|
73
34
|
}
|
|
74
35
|
async getUTXOs() {
|
|
75
|
-
const response = await
|
|
36
|
+
const response = await axios.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
|
|
76
37
|
console.log("utxos:", response.data);
|
|
77
38
|
return Promise.all(response.data.map(async (utxo) => {
|
|
78
|
-
const rawTx = await
|
|
39
|
+
const rawTx = await axios.get(`${this.apiEndpoint}/tx/${utxo.txid}/hex`);
|
|
79
40
|
console.log("txHex:", rawTx.data);
|
|
80
41
|
if (!rawTx.data) {
|
|
81
42
|
throw new Error("Transaction not found");
|
|
@@ -90,7 +51,7 @@ class BitcoinService {
|
|
|
90
51
|
}));
|
|
91
52
|
}
|
|
92
53
|
async getBalance() {
|
|
93
|
-
const response = await
|
|
54
|
+
const response = await axios.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
|
|
94
55
|
const utxos = response.data;
|
|
95
56
|
return utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
96
57
|
}
|
|
@@ -192,4 +153,3 @@ class BitcoinService {
|
|
|
192
153
|
}
|
|
193
154
|
}
|
|
194
155
|
}
|
|
195
|
-
exports.BitcoinService = BitcoinService;
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
1
|
// export * from "./bitcoinService";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
export * from "./stellarService";
|
|
3
|
+
export * from "./xrplService";
|
|
4
|
+
export * from "./nearService";
|
|
5
|
+
export * from "./algorandService";
|
|
6
|
+
export * from "./xdbService";
|
|
7
|
+
export * from "./octaService";
|
|
8
|
+
export * from "./zanoService";
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.createFunctionCall = createFunctionCall;
|
|
8
|
-
const assert_1 = __importDefault(require("assert"));
|
|
9
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
10
|
-
const providers_1 = require("@near-js/providers");
|
|
11
|
-
const utils_1 = require("@near-js/utils");
|
|
12
|
-
const constants_1 = require("../constants");
|
|
13
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { JsonRpcProvider } from "@near-js/providers";
|
|
4
|
+
import { parseNearAmount } from "@near-js/utils";
|
|
5
|
+
import { NEAR_RPC_URL } from "../constants";
|
|
6
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
14
7
|
/**
|
|
15
8
|
* Makes action payload for function call in near contract
|
|
16
9
|
* @param methodName method name
|
|
@@ -18,7 +11,7 @@ const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
|
18
11
|
* @param gas gas fee
|
|
19
12
|
* @param deposit deposit amount
|
|
20
13
|
*/
|
|
21
|
-
function createFunctionCall(methodName, args, gas, deposit) {
|
|
14
|
+
export function createFunctionCall(methodName, args, gas, deposit) {
|
|
22
15
|
return {
|
|
23
16
|
type: "FunctionCall",
|
|
24
17
|
params: {
|
|
@@ -29,16 +22,16 @@ function createFunctionCall(methodName, args, gas, deposit) {
|
|
|
29
22
|
},
|
|
30
23
|
};
|
|
31
24
|
}
|
|
32
|
-
class NearService {
|
|
25
|
+
export class NearService {
|
|
33
26
|
wallet;
|
|
34
27
|
apiService;
|
|
35
28
|
provider;
|
|
36
29
|
constructor(wallet, apiConfig, options) {
|
|
37
30
|
this.wallet = wallet;
|
|
38
31
|
const sandbox = options?.sandbox ? options.sandbox : false;
|
|
39
|
-
this.apiService = new
|
|
40
|
-
const url = sandbox ?
|
|
41
|
-
this.provider = new
|
|
32
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
|
|
33
|
+
const url = sandbox ? NEAR_RPC_URL.Sandbox : NEAR_RPC_URL.Production;
|
|
34
|
+
this.provider = new JsonRpcProvider({ url });
|
|
42
35
|
}
|
|
43
36
|
/**
|
|
44
37
|
* Fetches a quote for Bitcoin transfer.
|
|
@@ -63,8 +56,8 @@ class NearService {
|
|
|
63
56
|
const fetchVault = await this.fetchVault();
|
|
64
57
|
const destination = fetchVault.address;
|
|
65
58
|
console.debug("destination:", destination);
|
|
66
|
-
const parsedAmount =
|
|
67
|
-
(
|
|
59
|
+
const parsedAmount = parseNearAmount(params.amount);
|
|
60
|
+
assert(parsedAmount, "Amount might be missing.");
|
|
68
61
|
const action = {
|
|
69
62
|
type: "Transfer",
|
|
70
63
|
params: {
|
|
@@ -100,7 +93,7 @@ class NearService {
|
|
|
100
93
|
console.debug("storageBalance:", storageBalance);
|
|
101
94
|
const GAS = "30000000000000";
|
|
102
95
|
if (!storageBalance ||
|
|
103
|
-
|
|
96
|
+
BigNumber(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
|
|
104
97
|
const action = createFunctionCall("storage_deposit", {
|
|
105
98
|
account_id: signerId,
|
|
106
99
|
registration_only: false,
|
|
@@ -141,7 +134,7 @@ class NearService {
|
|
|
141
134
|
const storageBalance = JSON.parse(Buffer.from(storageBalanceResult.result).toString());
|
|
142
135
|
console.debug("storageBalance:", storageBalance);
|
|
143
136
|
if (!storageBalance ||
|
|
144
|
-
|
|
137
|
+
BigNumber(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
|
|
145
138
|
const action = createFunctionCall("storage_deposit", {
|
|
146
139
|
account_id: destination,
|
|
147
140
|
registration_only: false,
|
|
@@ -157,8 +150,8 @@ class NearService {
|
|
|
157
150
|
});
|
|
158
151
|
const metadata = JSON.parse(Buffer.from(metadataResult.result).toString());
|
|
159
152
|
const tokenDecimals = metadata.decimals;
|
|
160
|
-
const parsedAmount =
|
|
161
|
-
.times(
|
|
153
|
+
const parsedAmount = BigNumber(params.amount)
|
|
154
|
+
.times(BigNumber(10).pow(tokenDecimals))
|
|
162
155
|
.toFixed(0);
|
|
163
156
|
const secutityDeposit = "1";
|
|
164
157
|
const transferAction = createFunctionCall("ft_transfer", {
|
|
@@ -204,7 +197,6 @@ class NearService {
|
|
|
204
197
|
const metadata = JSON.parse(Buffer.from(metadataResult.result).toString());
|
|
205
198
|
const decimals = metadata.decimals;
|
|
206
199
|
const data = JSON.parse(Buffer.from(result.result).toString());
|
|
207
|
-
return
|
|
200
|
+
return BigNumber(data).div(BigNumber(10).pow(decimals)).toFixed();
|
|
208
201
|
}
|
|
209
202
|
}
|
|
210
|
-
exports.NearService = NearService;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
|
-
class OctaService {
|
|
1
|
+
import { parseEther } from "ethers";
|
|
2
|
+
import { DEFAULT_EVM_GAS_LIMIT } from "../constants";
|
|
3
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
+
export class OctaService {
|
|
8
5
|
signer;
|
|
9
6
|
apiConfig;
|
|
10
7
|
apiService;
|
|
11
8
|
constructor(signer, apiConfig, sdkOptions) {
|
|
12
9
|
this.signer = signer;
|
|
13
10
|
this.apiConfig = apiConfig;
|
|
14
|
-
this.apiService = new
|
|
11
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
|
|
15
12
|
}
|
|
16
13
|
/**
|
|
17
14
|
* Fetches a quote for Bitcoin transfer.
|
|
@@ -32,7 +29,7 @@ class OctaService {
|
|
|
32
29
|
return data;
|
|
33
30
|
}
|
|
34
31
|
async transferOcta(params) {
|
|
35
|
-
const parsedAmount =
|
|
32
|
+
const parsedAmount = parseEther(params.amount.toString());
|
|
36
33
|
const provider = this.signer.provider;
|
|
37
34
|
const vault = await this.fetchVault();
|
|
38
35
|
const recipientAddress = vault.address;
|
|
@@ -45,7 +42,7 @@ class OctaService {
|
|
|
45
42
|
}
|
|
46
43
|
const overides = {
|
|
47
44
|
...params.overrides,
|
|
48
|
-
gasLimit:
|
|
45
|
+
gasLimit: DEFAULT_EVM_GAS_LIMIT,
|
|
49
46
|
};
|
|
50
47
|
const response = await this.signer.sendTransaction({
|
|
51
48
|
...overides,
|
|
@@ -59,4 +56,3 @@ class OctaService {
|
|
|
59
56
|
return receipt;
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
|
-
exports.OctaService = OctaService;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
|
-
class StellarService {
|
|
1
|
+
import { Asset, Horizon, Memo, Networks, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
|
|
2
|
+
import { STELLAR_RPC_URL, STELLAR_USDC_ISSUER } from "../constants";
|
|
3
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
+
export class StellarService {
|
|
8
5
|
wallet;
|
|
9
6
|
apiService;
|
|
10
7
|
server;
|
|
@@ -19,8 +16,8 @@ class StellarService {
|
|
|
19
16
|
constructor(wallet, apiConfig, sdkOptions) {
|
|
20
17
|
this.wallet = wallet;
|
|
21
18
|
const sandbox = sdkOptions?.sandbox ? sdkOptions.sandbox : false;
|
|
22
|
-
this.apiService = new
|
|
23
|
-
this.server = new
|
|
19
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
|
|
20
|
+
this.server = new Horizon.Server(sandbox ? STELLAR_RPC_URL.Sandbox : STELLAR_RPC_URL.Production);
|
|
24
21
|
this.sandbox = sandbox;
|
|
25
22
|
}
|
|
26
23
|
/**
|
|
@@ -56,28 +53,28 @@ class StellarService {
|
|
|
56
53
|
// Prepare transaction
|
|
57
54
|
const account = await this.server.loadAccount(this.wallet.address);
|
|
58
55
|
const fee = await this.server.fetchBaseFee();
|
|
59
|
-
const memo =
|
|
56
|
+
const memo = Memo.id(vault.tag?.toString() || "");
|
|
60
57
|
// Check Wallet balance
|
|
61
58
|
const balance = await this.getWalletBalance(this.wallet.address);
|
|
62
59
|
if (Number(balance) < Number(amount)) {
|
|
63
60
|
throw new Error("Insufficient balance");
|
|
64
61
|
}
|
|
65
62
|
// Build and submit transaction
|
|
66
|
-
const transaction = new
|
|
63
|
+
const transaction = new TransactionBuilder(account, {
|
|
67
64
|
fee: fee.toString(),
|
|
68
|
-
networkPassphrase: this.sandbox ?
|
|
65
|
+
networkPassphrase: this.sandbox ? Networks.TESTNET : Networks.PUBLIC,
|
|
69
66
|
})
|
|
70
|
-
.addOperation(
|
|
67
|
+
.addOperation(Operation.payment({
|
|
71
68
|
destination: vault.address,
|
|
72
|
-
asset:
|
|
69
|
+
asset: Asset.native(),
|
|
73
70
|
amount,
|
|
74
71
|
}))
|
|
75
72
|
.addMemo(memo)
|
|
76
|
-
.setTimeout(
|
|
73
|
+
.setTimeout(TimeoutInfinite)
|
|
77
74
|
.build();
|
|
78
75
|
// Sign the transaction
|
|
79
76
|
const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
|
|
80
|
-
const tx =
|
|
77
|
+
const tx = TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? Networks.TESTNET : Networks.PUBLIC);
|
|
81
78
|
let retries = 0;
|
|
82
79
|
const maxRetries = 5;
|
|
83
80
|
let delay = 1000;
|
|
@@ -116,27 +113,27 @@ class StellarService {
|
|
|
116
113
|
const account = await this.server.loadAccount(this.wallet.address);
|
|
117
114
|
const fee = await this.server.fetchBaseFee();
|
|
118
115
|
// Create USDC asset object
|
|
119
|
-
const usdcAsset = new
|
|
116
|
+
const usdcAsset = new Asset("USDC", this.sandbox ? STELLAR_USDC_ISSUER.Sandbox : STELLAR_USDC_ISSUER.Production);
|
|
120
117
|
// Check Wallet balance
|
|
121
118
|
const balance = await this.getTokenBalance(this.wallet.address, usdcAsset);
|
|
122
119
|
if (Number(balance) < Number(amount)) {
|
|
123
120
|
throw new Error("Insufficient USDC balance");
|
|
124
121
|
}
|
|
125
122
|
// Build and submit transaction
|
|
126
|
-
const transaction = new
|
|
123
|
+
const transaction = new TransactionBuilder(account, {
|
|
127
124
|
fee: fee.toString(),
|
|
128
|
-
networkPassphrase: this.sandbox ?
|
|
125
|
+
networkPassphrase: this.sandbox ? Networks.TESTNET : Networks.PUBLIC,
|
|
129
126
|
})
|
|
130
|
-
.addOperation(
|
|
127
|
+
.addOperation(Operation.payment({
|
|
131
128
|
destination: vault.address,
|
|
132
129
|
asset: usdcAsset,
|
|
133
130
|
amount,
|
|
134
131
|
}))
|
|
135
|
-
.setTimeout(
|
|
132
|
+
.setTimeout(TimeoutInfinite)
|
|
136
133
|
.build();
|
|
137
134
|
// Sign the transaction
|
|
138
135
|
const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
|
|
139
|
-
const tx =
|
|
136
|
+
const tx = TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? Networks.TESTNET : Networks.PUBLIC);
|
|
140
137
|
let retries = 0;
|
|
141
138
|
const maxRetries = 5;
|
|
142
139
|
let delay = 1000;
|
|
@@ -193,7 +190,6 @@ class StellarService {
|
|
|
193
190
|
}
|
|
194
191
|
}
|
|
195
192
|
async getAsset(assetCode, assetIssuer) {
|
|
196
|
-
return new
|
|
193
|
+
return new Asset(assetCode, assetIssuer);
|
|
197
194
|
}
|
|
198
195
|
}
|
|
199
|
-
exports.StellarService = StellarService;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
|
-
class XDBService {
|
|
1
|
+
import { Asset, Horizon, Memo, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
|
|
2
|
+
import { XDB_NETWORK, XDB_RPC_URL } from "../constants";
|
|
3
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
+
export class XDBService {
|
|
8
5
|
wallet;
|
|
9
6
|
apiService;
|
|
10
7
|
server;
|
|
@@ -19,8 +16,8 @@ class XDBService {
|
|
|
19
16
|
constructor(wallet, apiConfig, sdkOptions) {
|
|
20
17
|
this.wallet = wallet;
|
|
21
18
|
const sandbox = sdkOptions?.sandbox ? sdkOptions.sandbox : false;
|
|
22
|
-
this.apiService = new
|
|
23
|
-
this.server = new
|
|
19
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
|
|
20
|
+
this.server = new Horizon.Server(sandbox ? XDB_RPC_URL.Sandbox : XDB_RPC_URL.Production);
|
|
24
21
|
this.sandbox = sandbox;
|
|
25
22
|
}
|
|
26
23
|
/**
|
|
@@ -57,28 +54,28 @@ class XDBService {
|
|
|
57
54
|
// Prepare transaction
|
|
58
55
|
const account = await this.server.loadAccount(this.wallet.address);
|
|
59
56
|
const fee = await this.server.fetchBaseFee();
|
|
60
|
-
const memo =
|
|
57
|
+
const memo = Memo.id(tag);
|
|
61
58
|
// Check Wallet balance
|
|
62
59
|
const balance = await this.getNativeBalance(this.wallet.address);
|
|
63
60
|
if (Number(balance) < Number(amount)) {
|
|
64
61
|
throw new Error("Insufficient balance");
|
|
65
62
|
}
|
|
66
63
|
// Build and submit transaction
|
|
67
|
-
const transaction = new
|
|
64
|
+
const transaction = new TransactionBuilder(account, {
|
|
68
65
|
fee: fee.toString(),
|
|
69
|
-
networkPassphrase: this.sandbox ?
|
|
66
|
+
networkPassphrase: this.sandbox ? XDB_NETWORK.TESTNET : XDB_NETWORK.PUBLIC,
|
|
70
67
|
})
|
|
71
|
-
.addOperation(
|
|
68
|
+
.addOperation(Operation.payment({
|
|
72
69
|
destination: recipientAddress,
|
|
73
|
-
asset:
|
|
70
|
+
asset: Asset.native(),
|
|
74
71
|
amount,
|
|
75
72
|
}))
|
|
76
73
|
.addMemo(memo)
|
|
77
|
-
.setTimeout(
|
|
74
|
+
.setTimeout(TimeoutInfinite)
|
|
78
75
|
.build();
|
|
79
76
|
// Sign the transaction
|
|
80
77
|
const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
|
|
81
|
-
const tx =
|
|
78
|
+
const tx = TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? XDB_NETWORK.TESTNET : XDB_NETWORK.PUBLIC);
|
|
82
79
|
let retries = 0;
|
|
83
80
|
const maxRetries = 5;
|
|
84
81
|
let delay = 1000;
|
|
@@ -135,7 +132,6 @@ class XDBService {
|
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
getAsset(assetCode, assetIssuer) {
|
|
138
|
-
return new
|
|
135
|
+
return new Asset(assetCode, assetIssuer);
|
|
139
136
|
}
|
|
140
137
|
}
|
|
141
|
-
exports.XDBService = XDBService;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
|
-
class XRPLService {
|
|
1
|
+
import { Client, isValidAddress, xrpToDrops, } from "xrpl";
|
|
2
|
+
import { XRPL_RPC_URL } from "../constants";
|
|
3
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
+
export class XRPLService {
|
|
8
5
|
wallet;
|
|
9
6
|
apiService;
|
|
10
7
|
client;
|
|
11
8
|
constructor(wallet, apiConfig, options) {
|
|
12
9
|
this.wallet = wallet;
|
|
13
10
|
const sandbox = options?.sandbox ? options.sandbox : false;
|
|
14
|
-
this.apiService = new
|
|
15
|
-
const xrplNetwork = sandbox ?
|
|
16
|
-
this.client = new
|
|
11
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
|
|
12
|
+
const xrplNetwork = sandbox ? XRPL_RPC_URL.Sandbox : XRPL_RPC_URL.Production;
|
|
13
|
+
this.client = new Client(xrplNetwork);
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
16
|
* Fetches a quote for Bitcoin transfer.
|
|
@@ -36,16 +33,16 @@ class XRPLService {
|
|
|
36
33
|
async transferXRP(params) {
|
|
37
34
|
console.debug("walletAddress:", params.walletAddress);
|
|
38
35
|
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
39
|
-
if (!
|
|
36
|
+
if (!isValidAddress(walletAddress)) {
|
|
40
37
|
throw new Error("Invalid wallet address");
|
|
41
38
|
}
|
|
42
39
|
const fetchVault = await this.fetchVault();
|
|
43
40
|
const destination = fetchVault.address;
|
|
44
41
|
console.debug("destination:", destination);
|
|
45
|
-
if (!
|
|
42
|
+
if (!isValidAddress(destination)) {
|
|
46
43
|
throw new Error("Invalid destination address");
|
|
47
44
|
}
|
|
48
|
-
const amountInDrops =
|
|
45
|
+
const amountInDrops = xrpToDrops(params.amount);
|
|
49
46
|
const transaction = {
|
|
50
47
|
TransactionType: "Payment",
|
|
51
48
|
Account: walletAddress,
|
|
@@ -69,13 +66,13 @@ class XRPLService {
|
|
|
69
66
|
async transferTokens(params) {
|
|
70
67
|
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
71
68
|
console.log("walletAddress:", params.walletAddress);
|
|
72
|
-
if (!
|
|
69
|
+
if (!isValidAddress(walletAddress)) {
|
|
73
70
|
throw new Error("Invalid wallet address");
|
|
74
71
|
}
|
|
75
72
|
const fetchVault = await this.fetchVault("RLUSD");
|
|
76
73
|
const destination = fetchVault.address;
|
|
77
74
|
console.log("destination:", destination);
|
|
78
|
-
if (!
|
|
75
|
+
if (!isValidAddress(destination)) {
|
|
79
76
|
throw new Error("Invalid destination address");
|
|
80
77
|
}
|
|
81
78
|
const transaction = {
|
|
@@ -104,7 +101,7 @@ class XRPLService {
|
|
|
104
101
|
}
|
|
105
102
|
async createTrustLine(params) {
|
|
106
103
|
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
107
|
-
if (!
|
|
104
|
+
if (!isValidAddress(walletAddress)) {
|
|
108
105
|
throw new Error("Invalid wallet address");
|
|
109
106
|
}
|
|
110
107
|
const transaction = {
|
|
@@ -132,7 +129,7 @@ class XRPLService {
|
|
|
132
129
|
}
|
|
133
130
|
async getTokenBalances(walletAddress) {
|
|
134
131
|
const address = walletAddress ? walletAddress : this.wallet.address;
|
|
135
|
-
if (!
|
|
132
|
+
if (!isValidAddress(address)) {
|
|
136
133
|
throw new Error("Invalid wallet address");
|
|
137
134
|
}
|
|
138
135
|
await this.client.connect();
|
|
@@ -150,4 +147,3 @@ class XRPLService {
|
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
149
|
}
|
|
153
|
-
exports.XRPLService = XRPLService;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { APIAsset, BalanceInfo } from "zano_web3/server";
|
|
2
|
+
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
|
+
import { Quote } from "../types";
|
|
4
|
+
export interface ZanoServiceConfig {
|
|
5
|
+
walletUrl: string;
|
|
6
|
+
daemonUrl: string;
|
|
7
|
+
walletAuthToken: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ZanoTransferParams {
|
|
10
|
+
assetId: string;
|
|
11
|
+
amount: string;
|
|
12
|
+
comment?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class ZanoService {
|
|
15
|
+
readonly apiConfig: APIConfig;
|
|
16
|
+
private readonly serverWallet;
|
|
17
|
+
private readonly apiService;
|
|
18
|
+
constructor(config: ZanoServiceConfig, apiConfig: APIConfig, sdkOptions?: {
|
|
19
|
+
sandbox?: boolean;
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Fetches a quote for Bitcoin transfer.
|
|
23
|
+
*
|
|
24
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
25
|
+
*/
|
|
26
|
+
fetchQuote(symbol?: string): Promise<Quote>;
|
|
27
|
+
/**
|
|
28
|
+
* Fetches the Bitcoin vault address.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
31
|
+
*/
|
|
32
|
+
fetchVault(symbol?: string): Promise<{
|
|
33
|
+
address: string;
|
|
34
|
+
tag?: string;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Send a transfer
|
|
38
|
+
*/
|
|
39
|
+
transferAssets(params: ZanoTransferParams): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Get asset information
|
|
42
|
+
*/
|
|
43
|
+
getAssetDetails(assetId: string): Promise<APIAsset>;
|
|
44
|
+
/**
|
|
45
|
+
* Validate if the amount is valid for the given asset
|
|
46
|
+
*/
|
|
47
|
+
validateAmount(amount: string, decimalPoints: number): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get wallet balances
|
|
50
|
+
*/
|
|
51
|
+
getBalances(): Promise<BalanceInfo[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Get balance for a specific asset
|
|
54
|
+
*/
|
|
55
|
+
getAssetBalance(assetId: string): Promise<BalanceInfo | null>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { ServerWallet } from "zano_web3/server";
|
|
3
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
+
export class ZanoService {
|
|
5
|
+
apiConfig;
|
|
6
|
+
serverWallet;
|
|
7
|
+
apiService;
|
|
8
|
+
// private readonly network: "mainnet" | "testnet";
|
|
9
|
+
constructor(config, apiConfig, sdkOptions) {
|
|
10
|
+
this.apiConfig = apiConfig;
|
|
11
|
+
// this.network = sdkOptions?.sandbox ? "testnet" : "mainnet";
|
|
12
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
|
|
13
|
+
this.serverWallet = new ServerWallet({
|
|
14
|
+
walletUrl: config.walletUrl,
|
|
15
|
+
daemonUrl: config.daemonUrl,
|
|
16
|
+
walletAuthToken: config.walletAuthToken,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetches a quote for Bitcoin transfer.
|
|
21
|
+
*
|
|
22
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
23
|
+
*/
|
|
24
|
+
async fetchQuote(symbol = "ZANO") {
|
|
25
|
+
const res = await this.apiService.fetchQuote(symbol);
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Fetches the Bitcoin vault address.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
32
|
+
*/
|
|
33
|
+
async fetchVault(symbol = "ZANO") {
|
|
34
|
+
const data = await this.apiService.fetchVault(symbol);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Send a transfer
|
|
39
|
+
*/
|
|
40
|
+
async transferAssets(params) {
|
|
41
|
+
// Check if we have sufficient balance
|
|
42
|
+
const balances = await this.serverWallet.getBalances();
|
|
43
|
+
const assetBalance = balances.find((balance) => balance.asset_info.asset_id === params.assetId);
|
|
44
|
+
if (assetBalance) {
|
|
45
|
+
const availableBalance = BigNumber(assetBalance.unlocked);
|
|
46
|
+
const fee = BigNumber(0.1);
|
|
47
|
+
const transferAmount = BigNumber(params.amount).plus(fee);
|
|
48
|
+
if (transferAmount.isGreaterThan(availableBalance)) {
|
|
49
|
+
throw new Error(`Insufficient balance. Available: ${assetBalance.unlocked} ${assetBalance.ticker || "tokens"}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(`Sender does not have ${params.assetId} balance.`);
|
|
54
|
+
}
|
|
55
|
+
const vault = await this.fetchVault("ZANO");
|
|
56
|
+
const receiver = vault.address;
|
|
57
|
+
// Send the transfer
|
|
58
|
+
const result = await this.serverWallet.sendTransfer(params.assetId, receiver, params.amount);
|
|
59
|
+
console.debug("result:", result);
|
|
60
|
+
return result.tx_hash;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get asset information
|
|
64
|
+
*/
|
|
65
|
+
async getAssetDetails(assetId) {
|
|
66
|
+
try {
|
|
67
|
+
return await this.serverWallet.getAssetDetails(assetId);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(`Error getting asset info for ${assetId}:`, error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Validate if the amount is valid for the given asset
|
|
76
|
+
*/
|
|
77
|
+
validateAmount(amount, decimalPoints) {
|
|
78
|
+
const decimals = BigNumber(amount).decimalPlaces();
|
|
79
|
+
return Boolean(decimals) && decimals == decimalPoints;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get wallet balances
|
|
83
|
+
*/
|
|
84
|
+
async getBalances() {
|
|
85
|
+
try {
|
|
86
|
+
const balances = await this.serverWallet.getBalances();
|
|
87
|
+
return balances;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error("Error getting balances:", error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get balance for a specific asset
|
|
96
|
+
*/
|
|
97
|
+
async getAssetBalance(assetId) {
|
|
98
|
+
try {
|
|
99
|
+
const balances = await this.getBalances();
|
|
100
|
+
return balances.find((balance) => balance.asset_info.asset_id === assetId) || null;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(`Error getting balance for asset ${assetId}:`, error);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.hashSHA256 = hashSHA256;
|
|
7
|
-
exports.parseAlgo = parseAlgo;
|
|
8
|
-
exports.formatAlgo = formatAlgo;
|
|
9
|
-
exports.parseAlgorandAsset = parseAlgorandAsset;
|
|
10
|
-
exports.formatAlgorandAsset = formatAlgorandAsset;
|
|
11
|
-
exports.getAssetDecimals = getAssetDecimals;
|
|
12
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
13
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
14
|
-
function hashSHA256(input) {
|
|
15
|
-
const hash = crypto_1.default.createHash("sha256");
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
export function hashSHA256(input) {
|
|
4
|
+
const hash = crypto.createHash("sha256");
|
|
16
5
|
hash.update(input);
|
|
17
6
|
const hex = hash.digest("hex");
|
|
18
7
|
return hex;
|
|
@@ -22,16 +11,16 @@ function hashSHA256(input) {
|
|
|
22
11
|
* @param algos Amount in ALGO
|
|
23
12
|
* @returns Amount in microAlgos
|
|
24
13
|
*/
|
|
25
|
-
function parseAlgo(algos) {
|
|
26
|
-
return BigInt(
|
|
14
|
+
export function parseAlgo(algos) {
|
|
15
|
+
return BigInt(BigNumber(algos).times(1_000_000).toFixed(0));
|
|
27
16
|
}
|
|
28
17
|
/**
|
|
29
18
|
* Convert microAlgos to ALGO
|
|
30
19
|
* @param microAlgos Amount in microAlgos
|
|
31
20
|
* @returns Amount in ALGO
|
|
32
21
|
*/
|
|
33
|
-
function formatAlgo(microAlgos) {
|
|
34
|
-
return
|
|
22
|
+
export function formatAlgo(microAlgos) {
|
|
23
|
+
return BigNumber(microAlgos).div(1_000_000).toFixed();
|
|
35
24
|
}
|
|
36
25
|
/**
|
|
37
26
|
* Convert Amount to micro-token amount (base units)
|
|
@@ -39,8 +28,8 @@ function formatAlgo(microAlgos) {
|
|
|
39
28
|
* @param decimals Number of decimals for the asset
|
|
40
29
|
* @returns Amount in micro-token base units
|
|
41
30
|
*/
|
|
42
|
-
function parseAlgorandAsset(amount, decimals) {
|
|
43
|
-
return BigInt(
|
|
31
|
+
export function parseAlgorandAsset(amount, decimals) {
|
|
32
|
+
return BigInt(BigNumber(amount).times(BigNumber(10).pow(decimals)).toFixed(0));
|
|
44
33
|
}
|
|
45
34
|
/**
|
|
46
35
|
* Convert micro-token Amount to Amount
|
|
@@ -48,8 +37,8 @@ function parseAlgorandAsset(amount, decimals) {
|
|
|
48
37
|
* @param decimals Number of decimals for the asset
|
|
49
38
|
* @returns Amount in decimal units
|
|
50
39
|
*/
|
|
51
|
-
function formatAlgorandAsset(microAmount, decimals) {
|
|
52
|
-
return
|
|
40
|
+
export function formatAlgorandAsset(microAmount, decimals) {
|
|
41
|
+
return BigNumber(microAmount).div(BigNumber(10).pow(decimals)).toFixed();
|
|
53
42
|
}
|
|
54
43
|
const ALGORAND_ASSET_DECIMALS_CACHE = new Map();
|
|
55
44
|
/**
|
|
@@ -58,7 +47,7 @@ const ALGORAND_ASSET_DECIMALS_CACHE = new Map();
|
|
|
58
47
|
* @param assetId asset index of Asset
|
|
59
48
|
* @returns
|
|
60
49
|
*/
|
|
61
|
-
async function getAssetDecimals(client, assetId) {
|
|
50
|
+
export async function getAssetDecimals(client, assetId) {
|
|
62
51
|
// Check if we already have this value cached
|
|
63
52
|
if (ALGORAND_ASSET_DECIMALS_CACHE.has(assetId)) {
|
|
64
53
|
return ALGORAND_ASSET_DECIMALS_CACHE.get(assetId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0-beta.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",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "npm run clean && tsc",
|
|
14
14
|
"clean": "rimraf dist",
|
|
15
15
|
"format": "prettier --write .",
|
|
16
|
-
"test": "ts-mocha -p ./tsconfig.json -t 1000000",
|
|
16
|
+
"test": "ts-mocha -p ./tsconfig.test.json -t 1000000",
|
|
17
17
|
"gen:typechain": "typechain --target ethers-v6 --out-dir \"src/artifacts/typechain-types\" \"src/artifacts/abi/*.json\""
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"bignumber.js": "^9.3.0",
|
|
49
49
|
"bitcoinjs-lib": "^6.1.7",
|
|
50
50
|
"ethers": "^6.15.0",
|
|
51
|
-
"xrpl": "^4.2.5"
|
|
51
|
+
"xrpl": "^4.2.5",
|
|
52
|
+
"zano_web3": "^9.2.0"
|
|
52
53
|
},
|
|
53
54
|
"repository": {
|
|
54
55
|
"type": "git",
|