@riocrypto/common 1.0.483 → 1.0.485

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.
@@ -5,6 +5,11 @@ declare class FireblocksClient {
5
5
  constructor(privateKey: string, apiKey: string);
6
6
  estimateWithdrawFromExchangeFee(crypto: Crypto, address: string, amountCrypto: number): Promise<string | undefined>;
7
7
  estimateWithdrawFromVaultFee(crypto: Crypto, address: string, amountCrypto: number): Promise<string | undefined>;
8
+ withdrawFromExchange(crypto: Crypto, address: string, amountCrypto: number): Promise<void>;
9
+ withdrawFromVault(crypto: Crypto, address: string, amountCrypto: number): Promise<void>;
10
+ getVaultCryptoBalance(crypto: Crypto): Promise<number>;
11
+ getExchangeCryptoBalance(crypto: Crypto): Promise<number>;
12
+ getExchangeFiatBalance(): Promise<number>;
8
13
  }
9
14
  export declare const fireblocksClient: FireblocksClient;
10
15
  export {};
@@ -55,5 +55,86 @@ class FireblocksClient {
55
55
  return estimate.medium.networkFee;
56
56
  });
57
57
  }
58
+ withdrawFromExchange(crypto, address, amountCrypto) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ let withdraw = yield this.fireblocks.createTransaction({
61
+ assetId: crypto,
62
+ source: {
63
+ type: fireblocks_sdk_1.PeerType.EXCHANGE_ACCOUNT,
64
+ id: "b227e245-a32e-c7ab-ff37-b365fa361077",
65
+ },
66
+ destination: {
67
+ type: fireblocks_sdk_1.PeerType.ONE_TIME_ADDRESS,
68
+ oneTimeAddress: {
69
+ address,
70
+ },
71
+ },
72
+ amount: amountCrypto,
73
+ operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
74
+ });
75
+ });
76
+ }
77
+ withdrawFromVault(crypto, address, amountCrypto) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ let withdraw = yield this.fireblocks.createTransaction({
80
+ assetId: crypto,
81
+ source: {
82
+ type: fireblocks_sdk_1.PeerType.VAULT_ACCOUNT,
83
+ id: "2",
84
+ },
85
+ destination: {
86
+ type: fireblocks_sdk_1.PeerType.ONE_TIME_ADDRESS,
87
+ oneTimeAddress: {
88
+ address,
89
+ },
90
+ },
91
+ amount: amountCrypto,
92
+ operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
93
+ });
94
+ });
95
+ }
96
+ getVaultCryptoBalance(crypto) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ let vault = yield this.fireblocks.getVaultAccountById("2");
99
+ let balance = 0;
100
+ if (!(vault === null || vault === void 0 ? void 0 : vault.assets)) {
101
+ throw new Error();
102
+ }
103
+ vault.assets.forEach((asset) => {
104
+ if (asset.id === crypto) {
105
+ balance += Number(asset.available);
106
+ }
107
+ });
108
+ return balance;
109
+ });
110
+ }
111
+ getExchangeCryptoBalance(crypto) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ let exchanges = yield this.fireblocks.getExchangeAccounts();
114
+ let balance = 0;
115
+ exchanges.forEach((exchange) => {
116
+ exchange.assets.forEach((asset) => {
117
+ if (asset.id === crypto) {
118
+ balance += Number(asset.available);
119
+ }
120
+ });
121
+ });
122
+ return balance;
123
+ });
124
+ }
125
+ getExchangeFiatBalance() {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ let exchanges = yield this.fireblocks.getExchangeAccounts();
128
+ let balance = 0;
129
+ exchanges.forEach((exchange) => {
130
+ exchange.assets.forEach((asset) => {
131
+ if (asset.id === "USD") {
132
+ balance += Number(asset.available);
133
+ }
134
+ });
135
+ });
136
+ return balance;
137
+ });
138
+ }
58
139
  }
59
140
  exports.fireblocksClient = new FireblocksClient(process.env.FIREBLOCKS_PRIVATE_KEY, process.env.FIREBLOCKS_API_KEY);
@@ -0,0 +1,8 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class RioSettingsAlreadyExistsError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RioSettingsAlreadyExistsError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ class RioSettingsAlreadyExistsError extends custom_error_1.CustomError {
6
+ constructor() {
7
+ super("Rio settings already exists");
8
+ this.statusCode = 409;
9
+ Object.setPrototypeOf(this, RioSettingsAlreadyExistsError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return [{ message: "Rio settings already exists" }];
13
+ }
14
+ }
15
+ exports.RioSettingsAlreadyExistsError = RioSettingsAlreadyExistsError;
package/build/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export * from "./errors/partner-already-exists-error";
28
28
  export * from "./errors/invalid-order-size-error";
29
29
  export * from "./errors/partner-not-found-error";
30
30
  export * from "./errors/insufficient-liquidity-error";
31
+ export * from "./errors/rio-settings-already-exists-error";
31
32
  export * from "./middlewares/error-handler";
32
33
  export * from "./middlewares/validate-request";
33
34
  export * from "./middlewares/current-auth";
package/build/index.js CHANGED
@@ -44,6 +44,7 @@ __exportStar(require("./errors/partner-already-exists-error"), exports);
44
44
  __exportStar(require("./errors/invalid-order-size-error"), exports);
45
45
  __exportStar(require("./errors/partner-not-found-error"), exports);
46
46
  __exportStar(require("./errors/insufficient-liquidity-error"), exports);
47
+ __exportStar(require("./errors/rio-settings-already-exists-error"), exports);
47
48
  __exportStar(require("./middlewares/error-handler"), exports);
48
49
  __exportStar(require("./middlewares/validate-request"), exports);
49
50
  __exportStar(require("./middlewares/current-auth"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.483",
3
+ "version": "1.0.485",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",