@cityofzion/bs-neo3 1.2.0 → 1.3.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/dist/BSNeo3.d.ts +3 -3
- package/dist/BSNeo3.js +9 -9
- package/dist/builder/invocation/FlamingoSwapInvocationBuilderNeo3.d.ts +7 -0
- package/dist/builder/invocation/FlamingoSwapInvocationBuilderNeo3.js +95 -0
- package/dist/builder/invocation/NeonDappKitInvocationBuilderNeo3.d.ts +34 -0
- package/dist/builder/invocation/NeonDappKitInvocationBuilderNeo3.js +102 -0
- package/dist/constants/FlamingoSwapConstants.d.ts +36 -0
- package/dist/constants/FlamingoSwapConstants.js +853 -0
- package/dist/{BSNeo3Helper.js → helpers/BSNeo3Helper.js} +2 -2
- package/dist/helpers/FlamingoSwapHelper.d.ts +19 -0
- package/dist/helpers/FlamingoSwapHelper.js +84 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/{DoraBDSNeo3.d.ts → services/blockchain-data/DoraBDSNeo3.d.ts} +4 -4
- package/dist/{DoraBDSNeo3.js → services/blockchain-data/DoraBDSNeo3.js} +3 -3
- package/dist/{RpcBDSNeo3.d.ts → services/blockchain-data/RpcBDSNeo3.d.ts} +2 -2
- package/dist/{RpcBDSNeo3.js → services/blockchain-data/RpcBDSNeo3.js} +4 -4
- package/dist/{FlamingoEDSNeo3.d.ts → services/exchange-data/FlamingoEDSNeo3.d.ts} +1 -1
- package/dist/{FlamingoEDSNeo3.js → services/exchange-data/FlamingoEDSNeo3.js} +1 -1
- package/dist/{DoraESNeo3.d.ts → services/explorer/DoraESNeo3.d.ts} +2 -2
- package/dist/{DoraESNeo3.js → services/explorer/DoraESNeo3.js} +1 -1
- package/dist/{NeonDappKitLedgerServiceNeo3.d.ts → services/ledger/NeonDappKitLedgerServiceNeo3.d.ts} +2 -4
- package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.js +135 -0
- package/dist/{GhostMarketNDSNeo3.d.ts → services/nft-data/GhostMarketNDSNeo3.d.ts} +2 -2
- package/dist/{RpcNDSNeo3.d.ts → services/nft-data/RpcNDSNeo3.d.ts} +1 -1
- package/dist/services/swap/FlamingoSwapServiceNeo3.d.ts +23 -0
- package/dist/services/swap/FlamingoSwapServiceNeo3.js +271 -0
- package/dist/services/swap/handlers/FlamingoSwapDetailsHandler.d.ts +24 -0
- package/dist/services/swap/handlers/FlamingoSwapDetailsHandler.js +178 -0
- package/dist/services/swap/handlers/FlamingoSwapRouteHandler.d.ts +13 -0
- package/dist/services/swap/handlers/FlamingoSwapRouteHandler.js +181 -0
- package/dist/services/swap/handlers/FlamingoSwapSocketHandler.d.ts +9 -0
- package/dist/services/swap/handlers/FlamingoSwapSocketHandler.js +57 -0
- package/dist/services/swap/handlers/index.d.ts +3 -0
- package/dist/services/swap/handlers/index.js +19 -0
- package/package.json +7 -5
- package/dist/NeonDappKitLedgerServiceNeo3.js +0 -110
- package/dist/flamingo-swap/FlamingoSwapControllerService.d.ts +0 -20
- package/dist/flamingo-swap/FlamingoSwapControllerService.js +0 -290
- package/dist/flamingo-swap/FlamingoSwapHelper.d.ts +0 -48
- package/dist/flamingo-swap/FlamingoSwapHelper.js +0 -171
- package/dist/flamingo-swap/FlamingoSwapNeonDappKitInvocationBuilder.d.ts +0 -19
- package/dist/flamingo-swap/FlamingoSwapNeonDappKitInvocationBuilder.js +0 -208
- package/dist/{BSNeo3Helper.d.ts → helpers/BSNeo3Helper.d.ts} +0 -0
- package/dist/{GhostMarketNDSNeo3.js → services/nft-data/GhostMarketNDSNeo3.js} +1 -1
- /package/dist/{RpcNDSNeo3.js → services/nft-data/RpcNDSNeo3.js} +0 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _FlamingoSwapServiceNeo3_instances, _FlamingoSwapServiceNeo3_ledgerService, _FlamingoSwapServiceNeo3_network, _FlamingoSwapServiceNeo3_privateAccountToUse, _FlamingoSwapServiceNeo3_privateTokenToReceive, _FlamingoSwapServiceNeo3_privateTokenToUse, _FlamingoSwapServiceNeo3_privateAmountToReceive, _FlamingoSwapServiceNeo3_privateAmountToUse, _FlamingoSwapServiceNeo3_privateMinimumReceived, _FlamingoSwapServiceNeo3_privateMaximumSelling, _FlamingoSwapServiceNeo3_privateSlippage, _FlamingoSwapServiceNeo3_privateDeadline, _FlamingoSwapServiceNeo3_privatePriceInverse, _FlamingoSwapServiceNeo3_privatePriceImpact, _FlamingoSwapServiceNeo3_privateLiquidityProviderFee, _FlamingoSwapServiceNeo3_privateRoute, _FlamingoSwapServiceNeo3_privateLastAmountChanged, _FlamingoSwapServiceNeo3_socket, _FlamingoSwapServiceNeo3_setReserves, _FlamingoSwapServiceNeo3_clearFields, _FlamingoSwapServiceNeo3_recalculateSwapArguments, _FlamingoSwapServiceNeo3_recalculateRoute, _FlamingoSwapServiceNeo3_lastAmountChanged_get, _FlamingoSwapServiceNeo3_lastAmountChanged_set, _FlamingoSwapServiceNeo3_accountToUse_get, _FlamingoSwapServiceNeo3_accountToUse_set, _FlamingoSwapServiceNeo3_amountToUse_get, _FlamingoSwapServiceNeo3_amountToUse_set, _FlamingoSwapServiceNeo3_minimumReceived_get, _FlamingoSwapServiceNeo3_minimumReceived_set, _FlamingoSwapServiceNeo3_maximumSelling_get, _FlamingoSwapServiceNeo3_maximumSelling_set, _FlamingoSwapServiceNeo3_amountToReceive_get, _FlamingoSwapServiceNeo3_amountToReceive_set, _FlamingoSwapServiceNeo3_deadline_get, _FlamingoSwapServiceNeo3_deadline_set, _FlamingoSwapServiceNeo3_liquidityProviderFee_get, _FlamingoSwapServiceNeo3_liquidityProviderFee_set, _FlamingoSwapServiceNeo3_priceImpact_get, _FlamingoSwapServiceNeo3_priceImpact_set, _FlamingoSwapServiceNeo3_priceInverse_get, _FlamingoSwapServiceNeo3_priceInverse_set, _FlamingoSwapServiceNeo3_route_get, _FlamingoSwapServiceNeo3_route_set, _FlamingoSwapServiceNeo3_slippage_get, _FlamingoSwapServiceNeo3_slippage_set, _FlamingoSwapServiceNeo3_tokenToReceive_get, _FlamingoSwapServiceNeo3_tokenToReceive_set, _FlamingoSwapServiceNeo3_tokenToUse_get, _FlamingoSwapServiceNeo3_tokenToUse_set;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.FlamingoSwapServiceNeo3 = void 0;
|
|
28
|
+
const neon_core_1 = require("@cityofzion/neon-core");
|
|
29
|
+
const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
|
|
30
|
+
const events_1 = __importDefault(require("events"));
|
|
31
|
+
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
32
|
+
const FlamingoSwapInvocationBuilderNeo3_1 = require("../../builder/invocation/FlamingoSwapInvocationBuilderNeo3");
|
|
33
|
+
const FlamingoSwapHelper_1 = require("../../helpers/FlamingoSwapHelper");
|
|
34
|
+
const handlers_1 = require("./handlers");
|
|
35
|
+
class FlamingoSwapServiceNeo3 {
|
|
36
|
+
constructor(network, ledgerService) {
|
|
37
|
+
_FlamingoSwapServiceNeo3_instances.add(this);
|
|
38
|
+
_FlamingoSwapServiceNeo3_ledgerService.set(this, void 0);
|
|
39
|
+
_FlamingoSwapServiceNeo3_network.set(this, void 0);
|
|
40
|
+
_FlamingoSwapServiceNeo3_privateAccountToUse.set(this, null);
|
|
41
|
+
_FlamingoSwapServiceNeo3_privateTokenToReceive.set(this, null);
|
|
42
|
+
_FlamingoSwapServiceNeo3_privateTokenToUse.set(this, null);
|
|
43
|
+
_FlamingoSwapServiceNeo3_privateAmountToReceive.set(this, null);
|
|
44
|
+
_FlamingoSwapServiceNeo3_privateAmountToUse.set(this, null);
|
|
45
|
+
_FlamingoSwapServiceNeo3_privateMinimumReceived.set(this, null);
|
|
46
|
+
_FlamingoSwapServiceNeo3_privateMaximumSelling.set(this, null);
|
|
47
|
+
_FlamingoSwapServiceNeo3_privateSlippage.set(this, 0.5);
|
|
48
|
+
_FlamingoSwapServiceNeo3_privateDeadline.set(this, '10');
|
|
49
|
+
_FlamingoSwapServiceNeo3_privatePriceInverse.set(this, null);
|
|
50
|
+
_FlamingoSwapServiceNeo3_privatePriceImpact.set(this, null);
|
|
51
|
+
_FlamingoSwapServiceNeo3_privateLiquidityProviderFee.set(this, null);
|
|
52
|
+
_FlamingoSwapServiceNeo3_privateRoute.set(this, []);
|
|
53
|
+
_FlamingoSwapServiceNeo3_privateLastAmountChanged.set(this, null);
|
|
54
|
+
_FlamingoSwapServiceNeo3_socket.set(this, new handlers_1.FlamingoSwapSocketService());
|
|
55
|
+
this.eventEmitter = new events_1.default();
|
|
56
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_network, network, "f");
|
|
57
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_ledgerService, ledgerService, "f");
|
|
58
|
+
}
|
|
59
|
+
buildSwapInvocationArgs() {
|
|
60
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_accountToUse_get) ||
|
|
61
|
+
!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToReceive_get) ||
|
|
62
|
+
!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToUse_get) ||
|
|
63
|
+
!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get) ||
|
|
64
|
+
!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get) ||
|
|
65
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_route_get).length <= 0) {
|
|
66
|
+
throw new Error('Required parameters are not set');
|
|
67
|
+
}
|
|
68
|
+
const routePath = FlamingoSwapHelper_1.FlamingoSwapHelper.getRoutePath(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_route_get));
|
|
69
|
+
const baseSwapArgs = {
|
|
70
|
+
address: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_accountToUse_get).address,
|
|
71
|
+
deadline: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_deadline_get),
|
|
72
|
+
network: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f"),
|
|
73
|
+
routePath,
|
|
74
|
+
};
|
|
75
|
+
if (__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToReceive') {
|
|
76
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_maximumSelling_get))
|
|
77
|
+
throw new Error("maximumSelling is required for 'amountToReceive' swap type");
|
|
78
|
+
return Object.assign(Object.assign({}, baseSwapArgs), { amountToReceive: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToReceive_get), maximumSelling: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_maximumSelling_get), type: 'swapTokenToReceive' });
|
|
79
|
+
}
|
|
80
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_minimumReceived_get))
|
|
81
|
+
throw new Error("minimumReceived is required for 'amountToUse' swap type");
|
|
82
|
+
return Object.assign(Object.assign({}, baseSwapArgs), { amountToUse: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToUse_get), minimumReceived: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_minimumReceived_get), type: 'swapTokenToUse' });
|
|
83
|
+
}
|
|
84
|
+
listSwappableTokens(network) {
|
|
85
|
+
return handlers_1.FlamingoSwapRouteHandler.createPoolGraph(network);
|
|
86
|
+
}
|
|
87
|
+
swap(isLedger) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const swapInvocationArgs = this.buildSwapInvocationArgs();
|
|
90
|
+
let ledgerTransport;
|
|
91
|
+
if (isLedger) {
|
|
92
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_ledgerService, "f").getLedgerTransport) {
|
|
93
|
+
throw new Error('You must provide a getLedgerTransport function to use Ledger');
|
|
94
|
+
}
|
|
95
|
+
ledgerTransport = yield __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_ledgerService, "f").getLedgerTransport(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_accountToUse_get));
|
|
96
|
+
}
|
|
97
|
+
const account = new neon_core_1.wallet.Account(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_accountToUse_get).key);
|
|
98
|
+
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
99
|
+
rpcAddress: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f").url,
|
|
100
|
+
account,
|
|
101
|
+
signingCallback: ledgerTransport ? __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_ledgerService, "f").getSigningCallback(ledgerTransport) : undefined,
|
|
102
|
+
});
|
|
103
|
+
yield invoker.invokeFunction(FlamingoSwapInvocationBuilderNeo3_1.FlamingoSwapInvocationBuilderNeo3.swapInvocation(swapInvocationArgs));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
startListeningBlockGeneration() {
|
|
107
|
+
const callback = () => __awaiter(this, void 0, void 0, function* () { return yield __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_setReserves).call(this); });
|
|
108
|
+
callback();
|
|
109
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_socket, "f").onBlockAdded({ callback });
|
|
110
|
+
}
|
|
111
|
+
stopListeningBlockGeneration() {
|
|
112
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_socket, "f").closeConnection();
|
|
113
|
+
}
|
|
114
|
+
setAccountToUse(account) {
|
|
115
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, account, "a", _FlamingoSwapServiceNeo3_accountToUse_set);
|
|
116
|
+
}
|
|
117
|
+
setAmountToUse(val) {
|
|
118
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, val, "a", _FlamingoSwapServiceNeo3_amountToUse_set);
|
|
119
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, 'amountToUse', "a", _FlamingoSwapServiceNeo3_lastAmountChanged_set);
|
|
120
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateSwapArguments).call(this);
|
|
121
|
+
}
|
|
122
|
+
setAmountToReceive(val) {
|
|
123
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, val, "a", _FlamingoSwapServiceNeo3_amountToReceive_set);
|
|
124
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, 'amountToReceive', "a", _FlamingoSwapServiceNeo3_lastAmountChanged_set);
|
|
125
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateSwapArguments).call(this);
|
|
126
|
+
}
|
|
127
|
+
setDeadline(deadline) {
|
|
128
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, deadline, "a", _FlamingoSwapServiceNeo3_deadline_set);
|
|
129
|
+
}
|
|
130
|
+
setSlippage(slippage) {
|
|
131
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, slippage, "a", _FlamingoSwapServiceNeo3_slippage_set);
|
|
132
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateSwapArguments).call(this);
|
|
133
|
+
}
|
|
134
|
+
setTokenToUse(val) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, val, "a", _FlamingoSwapServiceNeo3_tokenToUse_set);
|
|
137
|
+
yield __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateRoute).call(this);
|
|
138
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateSwapArguments).call(this);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
setTokenToReceive(val) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, val, "a", _FlamingoSwapServiceNeo3_tokenToReceive_set);
|
|
144
|
+
yield __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateRoute).call(this);
|
|
145
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateSwapArguments).call(this);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.FlamingoSwapServiceNeo3 = FlamingoSwapServiceNeo3;
|
|
150
|
+
_FlamingoSwapServiceNeo3_ledgerService = new WeakMap(), _FlamingoSwapServiceNeo3_network = new WeakMap(), _FlamingoSwapServiceNeo3_privateAccountToUse = new WeakMap(), _FlamingoSwapServiceNeo3_privateTokenToReceive = new WeakMap(), _FlamingoSwapServiceNeo3_privateTokenToUse = new WeakMap(), _FlamingoSwapServiceNeo3_privateAmountToReceive = new WeakMap(), _FlamingoSwapServiceNeo3_privateAmountToUse = new WeakMap(), _FlamingoSwapServiceNeo3_privateMinimumReceived = new WeakMap(), _FlamingoSwapServiceNeo3_privateMaximumSelling = new WeakMap(), _FlamingoSwapServiceNeo3_privateSlippage = new WeakMap(), _FlamingoSwapServiceNeo3_privateDeadline = new WeakMap(), _FlamingoSwapServiceNeo3_privatePriceInverse = new WeakMap(), _FlamingoSwapServiceNeo3_privatePriceImpact = new WeakMap(), _FlamingoSwapServiceNeo3_privateLiquidityProviderFee = new WeakMap(), _FlamingoSwapServiceNeo3_privateRoute = new WeakMap(), _FlamingoSwapServiceNeo3_privateLastAmountChanged = new WeakMap(), _FlamingoSwapServiceNeo3_socket = new WeakMap(), _FlamingoSwapServiceNeo3_instances = new WeakSet(), _FlamingoSwapServiceNeo3_setReserves = function _FlamingoSwapServiceNeo3_setReserves() {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get) || !__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get))
|
|
153
|
+
return;
|
|
154
|
+
yield __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateRoute).call(this);
|
|
155
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_recalculateSwapArguments).call(this);
|
|
156
|
+
});
|
|
157
|
+
}, _FlamingoSwapServiceNeo3_clearFields = function _FlamingoSwapServiceNeo3_clearFields() {
|
|
158
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_amountToUse_set);
|
|
159
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_amountToReceive_set);
|
|
160
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_minimumReceived_set);
|
|
161
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_maximumSelling_set);
|
|
162
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_liquidityProviderFee_set);
|
|
163
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_priceImpact_set);
|
|
164
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_priceInverse_set);
|
|
165
|
+
}, _FlamingoSwapServiceNeo3_recalculateSwapArguments = function _FlamingoSwapServiceNeo3_recalculateSwapArguments() {
|
|
166
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get) || !__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get))
|
|
167
|
+
return;
|
|
168
|
+
if ((__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToReceive' && __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToReceive_get)) ||
|
|
169
|
+
(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToUse' && __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToUse_get))) {
|
|
170
|
+
const amountToReceive = __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToReceive' ? __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToReceive_get) : null;
|
|
171
|
+
const amountToUse = __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToUse' ? __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToUse_get) : null;
|
|
172
|
+
const { amountToUseToDisplay, amountToReceiveToDisplay, maximumSelling, minimumReceived, liquidityProviderFee, priceImpact, priceInverse, } = handlers_1.FlamingoSwapDetailsHandler.calculateSwapDetails({
|
|
173
|
+
network: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f"),
|
|
174
|
+
amountToReceive,
|
|
175
|
+
amountToUse,
|
|
176
|
+
tokenToUse: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get),
|
|
177
|
+
tokenToReceive: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get),
|
|
178
|
+
slippage: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_slippage_get),
|
|
179
|
+
route: (0, lodash_clonedeep_1.default)(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_route_get)),
|
|
180
|
+
});
|
|
181
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, amountToUseToDisplay, "a", _FlamingoSwapServiceNeo3_amountToUse_set);
|
|
182
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, amountToReceiveToDisplay, "a", _FlamingoSwapServiceNeo3_amountToReceive_set);
|
|
183
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, maximumSelling, "a", _FlamingoSwapServiceNeo3_maximumSelling_set);
|
|
184
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, minimumReceived, "a", _FlamingoSwapServiceNeo3_minimumReceived_set);
|
|
185
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, liquidityProviderFee, "a", _FlamingoSwapServiceNeo3_liquidityProviderFee_set);
|
|
186
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, priceImpact, "a", _FlamingoSwapServiceNeo3_priceImpact_set);
|
|
187
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, priceInverse, "a", _FlamingoSwapServiceNeo3_priceInverse_set);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "m", _FlamingoSwapServiceNeo3_clearFields).call(this);
|
|
191
|
+
}, _FlamingoSwapServiceNeo3_recalculateRoute = function _FlamingoSwapServiceNeo3_recalculateRoute() {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get) || !__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get))
|
|
194
|
+
return;
|
|
195
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, yield handlers_1.FlamingoSwapRouteHandler.calculateBestRouteForSwap({
|
|
196
|
+
tokenToReceive: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get),
|
|
197
|
+
tokenToUse: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get),
|
|
198
|
+
network: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f"),
|
|
199
|
+
}), "a", _FlamingoSwapServiceNeo3_route_set);
|
|
200
|
+
});
|
|
201
|
+
}, _FlamingoSwapServiceNeo3_lastAmountChanged_get = function _FlamingoSwapServiceNeo3_lastAmountChanged_get() {
|
|
202
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateLastAmountChanged, "f");
|
|
203
|
+
}, _FlamingoSwapServiceNeo3_lastAmountChanged_set = function _FlamingoSwapServiceNeo3_lastAmountChanged_set(val) {
|
|
204
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateLastAmountChanged, val, "f");
|
|
205
|
+
this.eventEmitter.emit('lastAmountChanged', val);
|
|
206
|
+
}, _FlamingoSwapServiceNeo3_accountToUse_get = function _FlamingoSwapServiceNeo3_accountToUse_get() {
|
|
207
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateAccountToUse, "f");
|
|
208
|
+
}, _FlamingoSwapServiceNeo3_accountToUse_set = function _FlamingoSwapServiceNeo3_accountToUse_set(val) {
|
|
209
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateAccountToUse, val, "f");
|
|
210
|
+
this.eventEmitter.emit('accountToUse', val);
|
|
211
|
+
}, _FlamingoSwapServiceNeo3_amountToUse_get = function _FlamingoSwapServiceNeo3_amountToUse_get() {
|
|
212
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateAmountToUse, "f");
|
|
213
|
+
}, _FlamingoSwapServiceNeo3_amountToUse_set = function _FlamingoSwapServiceNeo3_amountToUse_set(val) {
|
|
214
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateAmountToUse, val, "f");
|
|
215
|
+
this.eventEmitter.emit('amountToUse', val);
|
|
216
|
+
}, _FlamingoSwapServiceNeo3_minimumReceived_get = function _FlamingoSwapServiceNeo3_minimumReceived_get() {
|
|
217
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateMinimumReceived, "f");
|
|
218
|
+
}, _FlamingoSwapServiceNeo3_minimumReceived_set = function _FlamingoSwapServiceNeo3_minimumReceived_set(val) {
|
|
219
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateMinimumReceived, val, "f");
|
|
220
|
+
this.eventEmitter.emit('minimumReceived', val);
|
|
221
|
+
}, _FlamingoSwapServiceNeo3_maximumSelling_get = function _FlamingoSwapServiceNeo3_maximumSelling_get() {
|
|
222
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateMaximumSelling, "f");
|
|
223
|
+
}, _FlamingoSwapServiceNeo3_maximumSelling_set = function _FlamingoSwapServiceNeo3_maximumSelling_set(val) {
|
|
224
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateMaximumSelling, val, "f");
|
|
225
|
+
this.eventEmitter.emit('maximumSelling', val);
|
|
226
|
+
}, _FlamingoSwapServiceNeo3_amountToReceive_get = function _FlamingoSwapServiceNeo3_amountToReceive_get() {
|
|
227
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateAmountToReceive, "f");
|
|
228
|
+
}, _FlamingoSwapServiceNeo3_amountToReceive_set = function _FlamingoSwapServiceNeo3_amountToReceive_set(val) {
|
|
229
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateAmountToReceive, val, "f");
|
|
230
|
+
this.eventEmitter.emit('amountToReceive', val);
|
|
231
|
+
}, _FlamingoSwapServiceNeo3_deadline_get = function _FlamingoSwapServiceNeo3_deadline_get() {
|
|
232
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateDeadline, "f");
|
|
233
|
+
}, _FlamingoSwapServiceNeo3_deadline_set = function _FlamingoSwapServiceNeo3_deadline_set(val) {
|
|
234
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateDeadline, val, "f");
|
|
235
|
+
this.eventEmitter.emit('deadline', val);
|
|
236
|
+
}, _FlamingoSwapServiceNeo3_liquidityProviderFee_get = function _FlamingoSwapServiceNeo3_liquidityProviderFee_get() {
|
|
237
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateLiquidityProviderFee, "f");
|
|
238
|
+
}, _FlamingoSwapServiceNeo3_liquidityProviderFee_set = function _FlamingoSwapServiceNeo3_liquidityProviderFee_set(val) {
|
|
239
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateLiquidityProviderFee, val, "f");
|
|
240
|
+
this.eventEmitter.emit('liquidityProviderFee', val);
|
|
241
|
+
}, _FlamingoSwapServiceNeo3_priceImpact_get = function _FlamingoSwapServiceNeo3_priceImpact_get() {
|
|
242
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privatePriceImpact, "f");
|
|
243
|
+
}, _FlamingoSwapServiceNeo3_priceImpact_set = function _FlamingoSwapServiceNeo3_priceImpact_set(val) {
|
|
244
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privatePriceImpact, val, "f");
|
|
245
|
+
this.eventEmitter.emit('priceImpact', val);
|
|
246
|
+
}, _FlamingoSwapServiceNeo3_priceInverse_get = function _FlamingoSwapServiceNeo3_priceInverse_get() {
|
|
247
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privatePriceInverse, "f");
|
|
248
|
+
}, _FlamingoSwapServiceNeo3_priceInverse_set = function _FlamingoSwapServiceNeo3_priceInverse_set(val) {
|
|
249
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privatePriceInverse, val, "f");
|
|
250
|
+
this.eventEmitter.emit('priceInverse', val);
|
|
251
|
+
}, _FlamingoSwapServiceNeo3_route_get = function _FlamingoSwapServiceNeo3_route_get() {
|
|
252
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateRoute, "f");
|
|
253
|
+
}, _FlamingoSwapServiceNeo3_route_set = function _FlamingoSwapServiceNeo3_route_set(val) {
|
|
254
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateRoute, val, "f");
|
|
255
|
+
this.eventEmitter.emit('route', val);
|
|
256
|
+
}, _FlamingoSwapServiceNeo3_slippage_get = function _FlamingoSwapServiceNeo3_slippage_get() {
|
|
257
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateSlippage, "f");
|
|
258
|
+
}, _FlamingoSwapServiceNeo3_slippage_set = function _FlamingoSwapServiceNeo3_slippage_set(val) {
|
|
259
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateSlippage, val, "f");
|
|
260
|
+
this.eventEmitter.emit('slippage', val);
|
|
261
|
+
}, _FlamingoSwapServiceNeo3_tokenToReceive_get = function _FlamingoSwapServiceNeo3_tokenToReceive_get() {
|
|
262
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateTokenToReceive, "f");
|
|
263
|
+
}, _FlamingoSwapServiceNeo3_tokenToReceive_set = function _FlamingoSwapServiceNeo3_tokenToReceive_set(val) {
|
|
264
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateTokenToReceive, val, "f");
|
|
265
|
+
this.eventEmitter.emit('tokenToReceive', val);
|
|
266
|
+
}, _FlamingoSwapServiceNeo3_tokenToUse_get = function _FlamingoSwapServiceNeo3_tokenToUse_get() {
|
|
267
|
+
return __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_privateTokenToUse, "f");
|
|
268
|
+
}, _FlamingoSwapServiceNeo3_tokenToUse_set = function _FlamingoSwapServiceNeo3_tokenToUse_set(val) {
|
|
269
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_privateTokenToUse, val, "f");
|
|
270
|
+
this.eventEmitter.emit('tokenToUse', val);
|
|
271
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Network, SwapRoute, Token } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { BSNeo3NetworkId } from '../../../helpers/BSNeo3Helper';
|
|
3
|
+
type CalculateSwapDetailsArgs = {
|
|
4
|
+
amountToUse: string | null;
|
|
5
|
+
amountToReceive: string | null;
|
|
6
|
+
tokenToUse: Token;
|
|
7
|
+
tokenToReceive: Token;
|
|
8
|
+
slippage: number;
|
|
9
|
+
network: Network<BSNeo3NetworkId>;
|
|
10
|
+
route: SwapRoute[];
|
|
11
|
+
};
|
|
12
|
+
export declare class FlamingoSwapDetailsHandler {
|
|
13
|
+
#private;
|
|
14
|
+
static calculateSwapDetails({ amountToReceive, amountToUse, network, route, slippage, tokenToReceive, tokenToUse, }: CalculateSwapDetailsArgs): {
|
|
15
|
+
amountToReceiveToDisplay: string;
|
|
16
|
+
amountToUseToDisplay: string;
|
|
17
|
+
liquidityProviderFee: string;
|
|
18
|
+
priceImpact: string | null;
|
|
19
|
+
priceInverse: string | null;
|
|
20
|
+
minimumReceived: string | null;
|
|
21
|
+
maximumSelling: string | null;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
var _a, _FlamingoSwapDetailsHandler_calculateUsingAmountToReceive, _FlamingoSwapDetailsHandler_calculateUsingAmountToUse, _FlamingoSwapDetailsHandler_formatSwapDetails, _FlamingoSwapDetailsHandler_createTradeData, _FlamingoSwapDetailsHandler_calculateAmountToUse, _FlamingoSwapDetailsHandler_calculateAmountToReceive;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FlamingoSwapDetailsHandler = void 0;
|
|
13
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
14
|
+
const FlamingoSwapConstants_1 = require("../../../constants/FlamingoSwapConstants");
|
|
15
|
+
const FlamingoSwapHelper_1 = require("../../../helpers/FlamingoSwapHelper");
|
|
16
|
+
class FlamingoSwapDetailsHandler {
|
|
17
|
+
static calculateSwapDetails({ amountToReceive, amountToUse, network, route, slippage, tokenToReceive, tokenToUse, }) {
|
|
18
|
+
const overrodeTokenToUse = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToUse);
|
|
19
|
+
const overrodeTokenToReceive = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
|
|
20
|
+
const overrodeRoute = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoute(network, route);
|
|
21
|
+
const slippageFormatted = new bignumber_js_1.default(slippage * 10).shiftedBy(-3);
|
|
22
|
+
if (amountToReceive) {
|
|
23
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_calculateUsingAmountToReceive).call(this, {
|
|
24
|
+
network,
|
|
25
|
+
amountToReceive,
|
|
26
|
+
overrodeRoute,
|
|
27
|
+
overrodeTokenToUse,
|
|
28
|
+
overrodeTokenToReceive,
|
|
29
|
+
slippageFormatted,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (amountToUse) {
|
|
33
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_calculateUsingAmountToUse).call(this, {
|
|
34
|
+
network,
|
|
35
|
+
amountToUse,
|
|
36
|
+
overrodeRoute,
|
|
37
|
+
overrodeTokenToUse,
|
|
38
|
+
overrodeTokenToReceive,
|
|
39
|
+
slippageFormatted,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error('AmountToReceive or amountToUse are required, but both aren`t provided');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.FlamingoSwapDetailsHandler = FlamingoSwapDetailsHandler;
|
|
48
|
+
_a = FlamingoSwapDetailsHandler, _FlamingoSwapDetailsHandler_calculateUsingAmountToReceive = function _FlamingoSwapDetailsHandler_calculateUsingAmountToReceive({ network, amountToReceive, overrodeRoute, overrodeTokenToUse, overrodeTokenToReceive, slippageFormatted, }) {
|
|
49
|
+
const amountToReceiveBn = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideAmountInput(network, amountToReceive, overrodeTokenToReceive);
|
|
50
|
+
const amountToUse = __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_calculateAmountToUse).call(this, {
|
|
51
|
+
amountToReceive,
|
|
52
|
+
route: overrodeRoute,
|
|
53
|
+
});
|
|
54
|
+
const amountToUseBn = new bignumber_js_1.default(amountToUse);
|
|
55
|
+
const maximumSelling = amountToUseBn
|
|
56
|
+
.times(FlamingoSwapConstants_1.FlamingoSwapConstants.BN_1.plus(slippageFormatted))
|
|
57
|
+
.dp(0)
|
|
58
|
+
.shiftedBy(-overrodeTokenToUse.decimals)
|
|
59
|
+
.toFixed();
|
|
60
|
+
const amountToUseToDisplay = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideAmountToDisplay(network, amountToUse, overrodeTokenToUse);
|
|
61
|
+
const { fee, price, priceImpact } = __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_createTradeData).call(this, {
|
|
62
|
+
amountToReceive: amountToReceiveBn,
|
|
63
|
+
amountToUse: amountToUseBn,
|
|
64
|
+
route: overrodeRoute,
|
|
65
|
+
});
|
|
66
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_formatSwapDetails).call(this, {
|
|
67
|
+
amountToReceiveToDisplay: amountToReceive,
|
|
68
|
+
amountToUseToDisplay,
|
|
69
|
+
fee,
|
|
70
|
+
price,
|
|
71
|
+
priceImpact,
|
|
72
|
+
overrodeTokenToUse,
|
|
73
|
+
overrodeTokenToReceive,
|
|
74
|
+
slippageFormatted,
|
|
75
|
+
minimumReceived: null,
|
|
76
|
+
maximumSelling,
|
|
77
|
+
});
|
|
78
|
+
}, _FlamingoSwapDetailsHandler_calculateUsingAmountToUse = function _FlamingoSwapDetailsHandler_calculateUsingAmountToUse({ network, amountToUse, overrodeRoute, overrodeTokenToUse, overrodeTokenToReceive, slippageFormatted, }) {
|
|
79
|
+
const amountToUseBn = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideAmountInput(network, amountToUse, overrodeTokenToUse);
|
|
80
|
+
const amountToReceive = __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_calculateAmountToReceive).call(this, {
|
|
81
|
+
amountToUse,
|
|
82
|
+
route: overrodeRoute,
|
|
83
|
+
});
|
|
84
|
+
const amountToReceiveBn = new bignumber_js_1.default(amountToReceive);
|
|
85
|
+
const minimumReceived = amountToReceiveBn
|
|
86
|
+
.times(FlamingoSwapConstants_1.FlamingoSwapConstants.BN_1.minus(slippageFormatted))
|
|
87
|
+
.dp(0)
|
|
88
|
+
.shiftedBy(-overrodeTokenToReceive.decimals)
|
|
89
|
+
.toFixed();
|
|
90
|
+
const amountToReceiveToDisplay = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideAmountToDisplay(network, amountToReceiveBn.toString(), overrodeTokenToReceive);
|
|
91
|
+
const { fee, price, priceImpact } = __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_createTradeData).call(this, {
|
|
92
|
+
amountToReceive: amountToReceiveBn,
|
|
93
|
+
amountToUse: amountToUseBn,
|
|
94
|
+
route: overrodeRoute,
|
|
95
|
+
});
|
|
96
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapDetailsHandler_formatSwapDetails).call(this, {
|
|
97
|
+
amountToReceiveToDisplay,
|
|
98
|
+
amountToUseToDisplay: amountToUse,
|
|
99
|
+
fee,
|
|
100
|
+
price,
|
|
101
|
+
priceImpact,
|
|
102
|
+
overrodeTokenToUse,
|
|
103
|
+
overrodeTokenToReceive,
|
|
104
|
+
slippageFormatted,
|
|
105
|
+
minimumReceived,
|
|
106
|
+
maximumSelling: null,
|
|
107
|
+
});
|
|
108
|
+
}, _FlamingoSwapDetailsHandler_formatSwapDetails = function _FlamingoSwapDetailsHandler_formatSwapDetails({ amountToReceiveToDisplay, amountToUseToDisplay, fee, price, priceImpact, overrodeTokenToUse, overrodeTokenToReceive, minimumReceived, maximumSelling, }) {
|
|
109
|
+
const priceInverse = FlamingoSwapConstants_1.FlamingoSwapConstants.BN_1.div(price);
|
|
110
|
+
const diffDecimals = overrodeTokenToUse.decimals - overrodeTokenToReceive.decimals;
|
|
111
|
+
return {
|
|
112
|
+
amountToReceiveToDisplay,
|
|
113
|
+
amountToUseToDisplay,
|
|
114
|
+
liquidityProviderFee: fee.shiftedBy(-8).plus(FlamingoSwapConstants_1.FlamingoSwapConstants.BN_0).toFixed(4),
|
|
115
|
+
priceImpact: isFinite(Number(priceImpact)) ? priceImpact.shiftedBy(2).toFixed(4) : null,
|
|
116
|
+
priceInverse: isFinite(Number(priceInverse)) ? priceInverse.multipliedBy(Math.pow(10, diffDecimals)).toFixed() : null,
|
|
117
|
+
minimumReceived,
|
|
118
|
+
maximumSelling,
|
|
119
|
+
};
|
|
120
|
+
}, _FlamingoSwapDetailsHandler_createTradeData = function _FlamingoSwapDetailsHandler_createTradeData({ amountToReceive, amountToUse, route }) {
|
|
121
|
+
const fee = amountToUse.minus(route.reduce(acc => acc.times(FlamingoSwapConstants_1.FlamingoSwapConstants.BN_1.minus(FlamingoSwapConstants_1.FlamingoSwapConstants.FEE_RATE)), amountToUse));
|
|
122
|
+
const price = amountToUse.div(amountToReceive);
|
|
123
|
+
const midPrice = route.reduce((acc, item) => acc.times(item.reserveTokenToUse).div(item.reserveTokenToReceive), FlamingoSwapConstants_1.FlamingoSwapConstants.BN_1);
|
|
124
|
+
const priceImpact = price.minus(midPrice).div(price).minus(fee.div(amountToUse));
|
|
125
|
+
return {
|
|
126
|
+
fee,
|
|
127
|
+
price,
|
|
128
|
+
priceImpact,
|
|
129
|
+
midPrice,
|
|
130
|
+
};
|
|
131
|
+
}, _FlamingoSwapDetailsHandler_calculateAmountToUse = function _FlamingoSwapDetailsHandler_calculateAmountToUse({ amountToReceive, route }) {
|
|
132
|
+
let amountToUse = '';
|
|
133
|
+
let tempAmountToReceive = amountToReceive;
|
|
134
|
+
route
|
|
135
|
+
.reverse()
|
|
136
|
+
.map(({ tokenToUse: tradeTokenToUse, tokenToReceive: tradeTokenToReceive, reserveTokenToUse, reserveTokenToReceive, }, index) => {
|
|
137
|
+
if (amountToUse) {
|
|
138
|
+
tempAmountToReceive = amountToUse;
|
|
139
|
+
}
|
|
140
|
+
const reserveTokenToUseBn = new bignumber_js_1.default(reserveTokenToUse);
|
|
141
|
+
const reserveTokenToReceiveBn = new bignumber_js_1.default(reserveTokenToReceive);
|
|
142
|
+
const tempAmountToReceiveBn = new bignumber_js_1.default(tempAmountToReceive).shiftedBy(tradeTokenToReceive.decimals);
|
|
143
|
+
amountToUse = reserveTokenToUseBn
|
|
144
|
+
.times(tempAmountToReceiveBn)
|
|
145
|
+
.times(1000)
|
|
146
|
+
.idiv(reserveTokenToReceiveBn.minus(tempAmountToReceiveBn).times(997))
|
|
147
|
+
.plus(1)
|
|
148
|
+
.toFixed();
|
|
149
|
+
if (route.length > 1) {
|
|
150
|
+
amountToUse = new bignumber_js_1.default(amountToUse).shiftedBy(-tradeTokenToUse.decimals).toFixed();
|
|
151
|
+
if (index === route.length - 1) {
|
|
152
|
+
amountToUse = new bignumber_js_1.default(amountToUse).shiftedBy(tradeTokenToUse.decimals).toFixed();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return amountToUse;
|
|
157
|
+
}, _FlamingoSwapDetailsHandler_calculateAmountToReceive = function _FlamingoSwapDetailsHandler_calculateAmountToReceive({ amountToUse, route }) {
|
|
158
|
+
let amountToReceive = '';
|
|
159
|
+
let tempAmountToUse = amountToUse;
|
|
160
|
+
route.map(({ tokenToUse: tradeTokenToUse, tokenToReceive: tradeTokenToReceive, reserveTokenToUse, reserveTokenToReceive }, index) => {
|
|
161
|
+
if (amountToReceive) {
|
|
162
|
+
tempAmountToUse = amountToReceive;
|
|
163
|
+
}
|
|
164
|
+
const reserveTokenToUseBn = new bignumber_js_1.default(reserveTokenToUse);
|
|
165
|
+
const tempAmountToUseWithFee = new bignumber_js_1.default(tempAmountToUse).times(997).shiftedBy(tradeTokenToUse.decimals);
|
|
166
|
+
amountToReceive = tempAmountToUseWithFee
|
|
167
|
+
.times(reserveTokenToReceive)
|
|
168
|
+
.idiv(reserveTokenToUseBn.times(1000).plus(tempAmountToUseWithFee))
|
|
169
|
+
.toFixed();
|
|
170
|
+
if (route.length > 1) {
|
|
171
|
+
amountToReceive = new bignumber_js_1.default(amountToReceive).shiftedBy(-tradeTokenToReceive.decimals).toFixed();
|
|
172
|
+
if (index === route.length - 1) {
|
|
173
|
+
amountToReceive = new bignumber_js_1.default(amountToReceive).shiftedBy(tradeTokenToReceive.decimals).toFixed();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return amountToReceive;
|
|
178
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Network, PoolGraph, SwapRoute, Token } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { BSNeo3NetworkId } from '../../../helpers/BSNeo3Helper';
|
|
3
|
+
type CalculateBestRouteForSwapArgs = {
|
|
4
|
+
tokenToUse: Token;
|
|
5
|
+
tokenToReceive: Token;
|
|
6
|
+
network: Network<BSNeo3NetworkId>;
|
|
7
|
+
};
|
|
8
|
+
export declare class FlamingoSwapRouteHandler {
|
|
9
|
+
#private;
|
|
10
|
+
static calculateBestRouteForSwap({ tokenToUse, tokenToReceive, network, }: CalculateBestRouteForSwapArgs): Promise<SwapRoute[]>;
|
|
11
|
+
static createPoolGraph(network: Network<BSNeo3NetworkId>): PoolGraph;
|
|
12
|
+
}
|
|
13
|
+
export {};
|