@cityofzion/bs-neo3 1.2.1 → 1.3.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/BSNeo3.d.ts +3 -3
- package/dist/BSNeo3.js +8 -8
- 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 +703 -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/{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 +8 -6
- 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/{NeonDappKitLedgerServiceNeo3.d.ts → services/ledger/NeonDappKitLedgerServiceNeo3.d.ts} +1 -1
- package/dist/{NeonDappKitLedgerServiceNeo3.js → services/ledger/NeonDappKitLedgerServiceNeo3.js} +1 -1
- package/dist/{GhostMarketNDSNeo3.js → services/nft-data/GhostMarketNDSNeo3.js} +1 -1
- /package/dist/{RpcNDSNeo3.js → services/nft-data/RpcNDSNeo3.js} +0 -0
|
@@ -1,290 +0,0 @@
|
|
|
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 _FlamingoSwapControllerService_instances, _FlamingoSwapControllerService_ws, _FlamingoSwapControllerService_network, _FlamingoSwapControllerService_privateAccountToUse, _FlamingoSwapControllerService_privateTokenToReceive, _FlamingoSwapControllerService_privateTokenToUse, _FlamingoSwapControllerService_privateAmountToReceive, _FlamingoSwapControllerService_privateAmountToUse, _FlamingoSwapControllerService_privateMinimumReceived, _FlamingoSwapControllerService_privateMaximumSelling, _FlamingoSwapControllerService_privateReservesToReceive, _FlamingoSwapControllerService_privateReservesToUse, _FlamingoSwapControllerService_privateSlippage, _FlamingoSwapControllerService_privateDeadline, _FlamingoSwapControllerService_privatePriceInverse, _FlamingoSwapControllerService_privatePriceImpact, _FlamingoSwapControllerService_privateLiquidityProviderFee, _FlamingoSwapControllerService_privateRoutes, _FlamingoSwapControllerService_privateLastAmountChange, _FlamingoSwapControllerService_recalculateSwapArguments, _FlamingoSwapControllerService_clearFields, _FlamingoSwapControllerService_lastAmountChange_get, _FlamingoSwapControllerService_lastAmountChange_set, _FlamingoSwapControllerService_accountToUse_get, _FlamingoSwapControllerService_accountToUse_set, _FlamingoSwapControllerService_amountToUse_get, _FlamingoSwapControllerService_amountToUse_set, _FlamingoSwapControllerService_minimumReceived_get, _FlamingoSwapControllerService_minimumReceived_set, _FlamingoSwapControllerService_maximumSelling_get, _FlamingoSwapControllerService_maximumSelling_set, _FlamingoSwapControllerService_amountToReceive_get, _FlamingoSwapControllerService_amountToReceive_set, _FlamingoSwapControllerService_deadline_get, _FlamingoSwapControllerService_deadline_set, _FlamingoSwapControllerService_liquidityProviderFee_get, _FlamingoSwapControllerService_liquidityProviderFee_set, _FlamingoSwapControllerService_priceImpact_get, _FlamingoSwapControllerService_priceImpact_set, _FlamingoSwapControllerService_priceInverse_get, _FlamingoSwapControllerService_priceInverse_set, _FlamingoSwapControllerService_routes_get, _FlamingoSwapControllerService_routes_set, _FlamingoSwapControllerService_reservesToUse_get, _FlamingoSwapControllerService_reservesToUse_set, _FlamingoSwapControllerService_reservesToReceive_get, _FlamingoSwapControllerService_reservesToReceive_set, _FlamingoSwapControllerService_slippage_get, _FlamingoSwapControllerService_slippage_set, _FlamingoSwapControllerService_tokenToReceive_get, _FlamingoSwapControllerService_tokenToReceive_set, _FlamingoSwapControllerService_tokenToUse_get, _FlamingoSwapControllerService_tokenToUse_set;
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.FlamingoSwapControllerService = void 0;
|
|
28
|
-
const events_1 = __importDefault(require("events"));
|
|
29
|
-
const FlamingoSwapNeonDappKitInvocationBuilder_1 = require("./FlamingoSwapNeonDappKitInvocationBuilder");
|
|
30
|
-
const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
|
|
31
|
-
const neon_core_1 = require("@cityofzion/neon-core");
|
|
32
|
-
const FlamingoSwapHelper_1 = require("./FlamingoSwapHelper");
|
|
33
|
-
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
34
|
-
const BLOCKCHAIN_WSS_URL = 'wss://rpc10.n3.nspcc.ru:10331/ws';
|
|
35
|
-
class FlamingoSwapControllerService {
|
|
36
|
-
constructor(network) {
|
|
37
|
-
_FlamingoSwapControllerService_instances.add(this);
|
|
38
|
-
_FlamingoSwapControllerService_ws.set(this, void 0);
|
|
39
|
-
_FlamingoSwapControllerService_network.set(this, void 0);
|
|
40
|
-
_FlamingoSwapControllerService_privateAccountToUse.set(this, null);
|
|
41
|
-
_FlamingoSwapControllerService_privateTokenToReceive.set(this, null);
|
|
42
|
-
_FlamingoSwapControllerService_privateTokenToUse.set(this, null);
|
|
43
|
-
_FlamingoSwapControllerService_privateAmountToReceive.set(this, null);
|
|
44
|
-
_FlamingoSwapControllerService_privateAmountToUse.set(this, null);
|
|
45
|
-
_FlamingoSwapControllerService_privateMinimumReceived.set(this, null);
|
|
46
|
-
_FlamingoSwapControllerService_privateMaximumSelling.set(this, null);
|
|
47
|
-
_FlamingoSwapControllerService_privateReservesToReceive.set(this, null);
|
|
48
|
-
_FlamingoSwapControllerService_privateReservesToUse.set(this, null);
|
|
49
|
-
_FlamingoSwapControllerService_privateSlippage.set(this, 0.5);
|
|
50
|
-
_FlamingoSwapControllerService_privateDeadline.set(this, '10');
|
|
51
|
-
_FlamingoSwapControllerService_privatePriceInverse.set(this, null);
|
|
52
|
-
_FlamingoSwapControllerService_privatePriceImpact.set(this, null);
|
|
53
|
-
_FlamingoSwapControllerService_privateLiquidityProviderFee.set(this, null);
|
|
54
|
-
_FlamingoSwapControllerService_privateRoutes.set(this, null);
|
|
55
|
-
_FlamingoSwapControllerService_privateLastAmountChange.set(this, null);
|
|
56
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_network, network, "f");
|
|
57
|
-
this.eventEmitter = new events_1.default();
|
|
58
|
-
}
|
|
59
|
-
buildSwapArgs() {
|
|
60
|
-
if (!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_accountToUse_get) ||
|
|
61
|
-
!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToReceive_get) ||
|
|
62
|
-
!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToUse_get) ||
|
|
63
|
-
!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToReceive_get) ||
|
|
64
|
-
!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToUse_get))
|
|
65
|
-
throw new Error('Required parameters are not set');
|
|
66
|
-
const baseSwapArgs = {
|
|
67
|
-
address: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_accountToUse_get).address,
|
|
68
|
-
amountToReceive: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToReceive_get),
|
|
69
|
-
amountToUse: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToUse_get),
|
|
70
|
-
tokenToReceive: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToReceive_get),
|
|
71
|
-
tokenToUse: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToUse_get),
|
|
72
|
-
deadline: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_deadline_get),
|
|
73
|
-
network: __classPrivateFieldGet(this, _FlamingoSwapControllerService_network, "f"),
|
|
74
|
-
};
|
|
75
|
-
if (__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_lastAmountChange_get) === 'amountToReceive') {
|
|
76
|
-
if (!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_maximumSelling_get))
|
|
77
|
-
throw new Error("maximumSelling is required for 'amountToReceive' swap type");
|
|
78
|
-
return Object.assign(Object.assign({}, baseSwapArgs), { maximumSelling: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_maximumSelling_get), type: 'swapTokenToReceive' });
|
|
79
|
-
}
|
|
80
|
-
if (!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_minimumReceived_get))
|
|
81
|
-
throw new Error("minimumReceived is required for 'amountToUse' swap type");
|
|
82
|
-
return Object.assign(Object.assign({}, baseSwapArgs), { minimumReceived: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_minimumReceived_get), type: 'swapTokenToUse' });
|
|
83
|
-
}
|
|
84
|
-
setAccountToUse(account) {
|
|
85
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, account, "a", _FlamingoSwapControllerService_accountToUse_set);
|
|
86
|
-
}
|
|
87
|
-
setAmountToUse(val) {
|
|
88
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, val, "a", _FlamingoSwapControllerService_amountToUse_set);
|
|
89
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, 'amountToUse', "a", _FlamingoSwapControllerService_lastAmountChange_set);
|
|
90
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "m", _FlamingoSwapControllerService_recalculateSwapArguments).call(this);
|
|
91
|
-
}
|
|
92
|
-
setAmountToReceive(val) {
|
|
93
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, val, "a", _FlamingoSwapControllerService_amountToReceive_set);
|
|
94
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, 'amountToReceive', "a", _FlamingoSwapControllerService_lastAmountChange_set);
|
|
95
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "m", _FlamingoSwapControllerService_recalculateSwapArguments).call(this);
|
|
96
|
-
}
|
|
97
|
-
setDeadline(deadline) {
|
|
98
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, deadline, "a", _FlamingoSwapControllerService_deadline_set);
|
|
99
|
-
}
|
|
100
|
-
setSlippage(slippage) {
|
|
101
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, slippage, "a", _FlamingoSwapControllerService_slippage_set);
|
|
102
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "m", _FlamingoSwapControllerService_recalculateSwapArguments).call(this);
|
|
103
|
-
}
|
|
104
|
-
setTokenToUse(val) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, val, "a", _FlamingoSwapControllerService_tokenToUse_set);
|
|
107
|
-
yield this.setReserves();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
setTokenToReceive(val) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, val, "a", _FlamingoSwapControllerService_tokenToReceive_set);
|
|
113
|
-
yield this.setReserves();
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
swap(isLedger) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
if (isLedger)
|
|
119
|
-
throw new Error('Method not implemented.');
|
|
120
|
-
const swapArguments = this.buildSwapArgs();
|
|
121
|
-
const neonInvokerAccount = new neon_core_1.wallet.Account(__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_accountToUse_get));
|
|
122
|
-
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
123
|
-
rpcAddress: __classPrivateFieldGet(this, _FlamingoSwapControllerService_network, "f").url,
|
|
124
|
-
account: neonInvokerAccount,
|
|
125
|
-
});
|
|
126
|
-
yield invoker.invokeFunction(FlamingoSwapNeonDappKitInvocationBuilder_1.FlamingoSwapNeonDappKitInvocationBuilder.swapInvocation(swapArguments));
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
setReserves() {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
if (!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToReceive_get) || !__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToUse_get))
|
|
132
|
-
return;
|
|
133
|
-
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
134
|
-
rpcAddress: __classPrivateFieldGet(this, _FlamingoSwapControllerService_network, "f").url,
|
|
135
|
-
});
|
|
136
|
-
const invocation = FlamingoSwapNeonDappKitInvocationBuilder_1.FlamingoSwapNeonDappKitInvocationBuilder.getReservesInvocation({
|
|
137
|
-
network: __classPrivateFieldGet(this, _FlamingoSwapControllerService_network, "f"),
|
|
138
|
-
tokenToReceiveScriptHash: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToReceive_get).hash,
|
|
139
|
-
tokenToUseScriptHash: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToUse_get).hash,
|
|
140
|
-
});
|
|
141
|
-
const { stack } = yield invoker.testInvoke(invocation);
|
|
142
|
-
if (!neon_dappkit_1.TypeChecker.isStackTypeArray(stack[0]) ||
|
|
143
|
-
!neon_dappkit_1.TypeChecker.isStackTypeInteger(stack[0].value[0]) ||
|
|
144
|
-
!neon_dappkit_1.TypeChecker.isStackTypeInteger(stack[0].value[1]))
|
|
145
|
-
throw new Error('Invalid reserves response');
|
|
146
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, stack[0].value[0].value, "a", _FlamingoSwapControllerService_reservesToReceive_set);
|
|
147
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, stack[0].value[1].value, "a", _FlamingoSwapControllerService_reservesToUse_set);
|
|
148
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "m", _FlamingoSwapControllerService_recalculateSwapArguments).call(this);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
startListeningBlockGeneration() {
|
|
152
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_ws, new isomorphic_ws_1.default(BLOCKCHAIN_WSS_URL), "f");
|
|
153
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_ws, "f").onopen = () => {
|
|
154
|
-
const block_added = {
|
|
155
|
-
jsonrpc: '2.0',
|
|
156
|
-
method: 'subscribe',
|
|
157
|
-
params: ['block_added'],
|
|
158
|
-
id: 1,
|
|
159
|
-
};
|
|
160
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_ws, "f").send(JSON.stringify(block_added));
|
|
161
|
-
};
|
|
162
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_ws, "f").onmessage = () => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
this.setReserves();
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
stopListeningBlockGeneration() {
|
|
167
|
-
if (__classPrivateFieldGet(this, _FlamingoSwapControllerService_ws, "f")) {
|
|
168
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_ws, "f").close();
|
|
169
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_ws, null, "f");
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.FlamingoSwapControllerService = FlamingoSwapControllerService;
|
|
174
|
-
_FlamingoSwapControllerService_ws = new WeakMap(), _FlamingoSwapControllerService_network = new WeakMap(), _FlamingoSwapControllerService_privateAccountToUse = new WeakMap(), _FlamingoSwapControllerService_privateTokenToReceive = new WeakMap(), _FlamingoSwapControllerService_privateTokenToUse = new WeakMap(), _FlamingoSwapControllerService_privateAmountToReceive = new WeakMap(), _FlamingoSwapControllerService_privateAmountToUse = new WeakMap(), _FlamingoSwapControllerService_privateMinimumReceived = new WeakMap(), _FlamingoSwapControllerService_privateMaximumSelling = new WeakMap(), _FlamingoSwapControllerService_privateReservesToReceive = new WeakMap(), _FlamingoSwapControllerService_privateReservesToUse = new WeakMap(), _FlamingoSwapControllerService_privateSlippage = new WeakMap(), _FlamingoSwapControllerService_privateDeadline = new WeakMap(), _FlamingoSwapControllerService_privatePriceInverse = new WeakMap(), _FlamingoSwapControllerService_privatePriceImpact = new WeakMap(), _FlamingoSwapControllerService_privateLiquidityProviderFee = new WeakMap(), _FlamingoSwapControllerService_privateRoutes = new WeakMap(), _FlamingoSwapControllerService_privateLastAmountChange = new WeakMap(), _FlamingoSwapControllerService_instances = new WeakSet(), _FlamingoSwapControllerService_recalculateSwapArguments = function _FlamingoSwapControllerService_recalculateSwapArguments() {
|
|
175
|
-
if (!__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToReceive_get) || !__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToUse_get) || !__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_reservesToReceive_get) || !__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_reservesToUse_get))
|
|
176
|
-
return;
|
|
177
|
-
if ((__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_lastAmountChange_get) === 'amountToReceive' && __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToReceive_get)) ||
|
|
178
|
-
(__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_lastAmountChange_get) === 'amountToUse' && __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToUse_get))) {
|
|
179
|
-
const amountToReceive = __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_lastAmountChange_get) === 'amountToReceive' ? __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToReceive_get) : null;
|
|
180
|
-
const amountToUse = __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_lastAmountChange_get) === 'amountToUse' ? __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_amountToUse_get) : null;
|
|
181
|
-
const { amountToUseToDisplay, amountToReceiveToDisplay, maximumSelling, minimumReceived, liquidityProviderFee, priceImpact, priceInverse, } = FlamingoSwapHelper_1.FlamingoSwapHelper.getSwapFields({
|
|
182
|
-
network: __classPrivateFieldGet(this, _FlamingoSwapControllerService_network, "f"),
|
|
183
|
-
amountToReceive,
|
|
184
|
-
amountToUse,
|
|
185
|
-
tokenToUse: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToUse_get),
|
|
186
|
-
tokenToReceive: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_tokenToReceive_get),
|
|
187
|
-
reservesToUse: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_reservesToUse_get),
|
|
188
|
-
reservesToReceive: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_reservesToReceive_get),
|
|
189
|
-
slippage: __classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "a", _FlamingoSwapControllerService_slippage_get),
|
|
190
|
-
});
|
|
191
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, amountToUseToDisplay, "a", _FlamingoSwapControllerService_amountToUse_set);
|
|
192
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, amountToReceiveToDisplay, "a", _FlamingoSwapControllerService_amountToReceive_set);
|
|
193
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, maximumSelling, "a", _FlamingoSwapControllerService_maximumSelling_set);
|
|
194
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, minimumReceived, "a", _FlamingoSwapControllerService_minimumReceived_set);
|
|
195
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, liquidityProviderFee, "a", _FlamingoSwapControllerService_liquidityProviderFee_set);
|
|
196
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, priceImpact, "a", _FlamingoSwapControllerService_priceImpact_set);
|
|
197
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, priceInverse, "a", _FlamingoSwapControllerService_priceInverse_set);
|
|
198
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, [], "a", _FlamingoSwapControllerService_routes_set); // TODO: It will be implemented in Swap Multi Invoke issue
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
__classPrivateFieldGet(this, _FlamingoSwapControllerService_instances, "m", _FlamingoSwapControllerService_clearFields).call(this);
|
|
202
|
-
}, _FlamingoSwapControllerService_clearFields = function _FlamingoSwapControllerService_clearFields() {
|
|
203
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, null, "a", _FlamingoSwapControllerService_amountToUse_set);
|
|
204
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, null, "a", _FlamingoSwapControllerService_amountToReceive_set);
|
|
205
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, null, "a", _FlamingoSwapControllerService_minimumReceived_set);
|
|
206
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, null, "a", _FlamingoSwapControllerService_maximumSelling_set);
|
|
207
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, null, "a", _FlamingoSwapControllerService_liquidityProviderFee_set);
|
|
208
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, null, "a", _FlamingoSwapControllerService_priceImpact_set);
|
|
209
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_instances, null, "a", _FlamingoSwapControllerService_priceInverse_set);
|
|
210
|
-
}, _FlamingoSwapControllerService_lastAmountChange_get = function _FlamingoSwapControllerService_lastAmountChange_get() {
|
|
211
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateLastAmountChange, "f");
|
|
212
|
-
}, _FlamingoSwapControllerService_lastAmountChange_set = function _FlamingoSwapControllerService_lastAmountChange_set(val) {
|
|
213
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateLastAmountChange, val, "f");
|
|
214
|
-
this.eventEmitter.emit('lastAmountChanged', val);
|
|
215
|
-
}, _FlamingoSwapControllerService_accountToUse_get = function _FlamingoSwapControllerService_accountToUse_get() {
|
|
216
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateAccountToUse, "f");
|
|
217
|
-
}, _FlamingoSwapControllerService_accountToUse_set = function _FlamingoSwapControllerService_accountToUse_set(val) {
|
|
218
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateAccountToUse, val, "f");
|
|
219
|
-
this.eventEmitter.emit('accountToUse', val);
|
|
220
|
-
}, _FlamingoSwapControllerService_amountToUse_get = function _FlamingoSwapControllerService_amountToUse_get() {
|
|
221
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateAmountToUse, "f");
|
|
222
|
-
}, _FlamingoSwapControllerService_amountToUse_set = function _FlamingoSwapControllerService_amountToUse_set(val) {
|
|
223
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateAmountToUse, val, "f");
|
|
224
|
-
this.eventEmitter.emit('amountToUse', val);
|
|
225
|
-
}, _FlamingoSwapControllerService_minimumReceived_get = function _FlamingoSwapControllerService_minimumReceived_get() {
|
|
226
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateMinimumReceived, "f");
|
|
227
|
-
}, _FlamingoSwapControllerService_minimumReceived_set = function _FlamingoSwapControllerService_minimumReceived_set(val) {
|
|
228
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateMinimumReceived, val, "f");
|
|
229
|
-
this.eventEmitter.emit('minimumReceived', val);
|
|
230
|
-
}, _FlamingoSwapControllerService_maximumSelling_get = function _FlamingoSwapControllerService_maximumSelling_get() {
|
|
231
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateMaximumSelling, "f");
|
|
232
|
-
}, _FlamingoSwapControllerService_maximumSelling_set = function _FlamingoSwapControllerService_maximumSelling_set(val) {
|
|
233
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateMaximumSelling, val, "f");
|
|
234
|
-
this.eventEmitter.emit('maximumSelling', val);
|
|
235
|
-
}, _FlamingoSwapControllerService_amountToReceive_get = function _FlamingoSwapControllerService_amountToReceive_get() {
|
|
236
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateAmountToReceive, "f");
|
|
237
|
-
}, _FlamingoSwapControllerService_amountToReceive_set = function _FlamingoSwapControllerService_amountToReceive_set(val) {
|
|
238
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateAmountToReceive, val, "f");
|
|
239
|
-
this.eventEmitter.emit('amountToReceive', val);
|
|
240
|
-
}, _FlamingoSwapControllerService_deadline_get = function _FlamingoSwapControllerService_deadline_get() {
|
|
241
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateDeadline, "f");
|
|
242
|
-
}, _FlamingoSwapControllerService_deadline_set = function _FlamingoSwapControllerService_deadline_set(val) {
|
|
243
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateDeadline, val, "f");
|
|
244
|
-
this.eventEmitter.emit('deadline', val);
|
|
245
|
-
}, _FlamingoSwapControllerService_liquidityProviderFee_get = function _FlamingoSwapControllerService_liquidityProviderFee_get() {
|
|
246
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateLiquidityProviderFee, "f");
|
|
247
|
-
}, _FlamingoSwapControllerService_liquidityProviderFee_set = function _FlamingoSwapControllerService_liquidityProviderFee_set(val) {
|
|
248
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateLiquidityProviderFee, val, "f");
|
|
249
|
-
this.eventEmitter.emit('liquidityProviderFee', val);
|
|
250
|
-
}, _FlamingoSwapControllerService_priceImpact_get = function _FlamingoSwapControllerService_priceImpact_get() {
|
|
251
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privatePriceImpact, "f");
|
|
252
|
-
}, _FlamingoSwapControllerService_priceImpact_set = function _FlamingoSwapControllerService_priceImpact_set(val) {
|
|
253
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privatePriceImpact, val, "f");
|
|
254
|
-
this.eventEmitter.emit('priceImpact', val);
|
|
255
|
-
}, _FlamingoSwapControllerService_priceInverse_get = function _FlamingoSwapControllerService_priceInverse_get() {
|
|
256
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privatePriceInverse, "f");
|
|
257
|
-
}, _FlamingoSwapControllerService_priceInverse_set = function _FlamingoSwapControllerService_priceInverse_set(val) {
|
|
258
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privatePriceInverse, val, "f");
|
|
259
|
-
this.eventEmitter.emit('priceInverse', val);
|
|
260
|
-
}, _FlamingoSwapControllerService_routes_get = function _FlamingoSwapControllerService_routes_get() {
|
|
261
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateRoutes, "f");
|
|
262
|
-
}, _FlamingoSwapControllerService_routes_set = function _FlamingoSwapControllerService_routes_set(val) {
|
|
263
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateRoutes, val, "f");
|
|
264
|
-
this.eventEmitter.emit('routes', val);
|
|
265
|
-
}, _FlamingoSwapControllerService_reservesToUse_get = function _FlamingoSwapControllerService_reservesToUse_get() {
|
|
266
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateReservesToUse, "f");
|
|
267
|
-
}, _FlamingoSwapControllerService_reservesToUse_set = function _FlamingoSwapControllerService_reservesToUse_set(val) {
|
|
268
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateReservesToUse, val, "f");
|
|
269
|
-
this.eventEmitter.emit('reservesToUse', val);
|
|
270
|
-
}, _FlamingoSwapControllerService_reservesToReceive_get = function _FlamingoSwapControllerService_reservesToReceive_get() {
|
|
271
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateReservesToReceive, "f");
|
|
272
|
-
}, _FlamingoSwapControllerService_reservesToReceive_set = function _FlamingoSwapControllerService_reservesToReceive_set(val) {
|
|
273
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateReservesToReceive, val, "f");
|
|
274
|
-
this.eventEmitter.emit('reservesToReceive', val);
|
|
275
|
-
}, _FlamingoSwapControllerService_slippage_get = function _FlamingoSwapControllerService_slippage_get() {
|
|
276
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateSlippage, "f");
|
|
277
|
-
}, _FlamingoSwapControllerService_slippage_set = function _FlamingoSwapControllerService_slippage_set(val) {
|
|
278
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateSlippage, val, "f");
|
|
279
|
-
this.eventEmitter.emit('slippage', val);
|
|
280
|
-
}, _FlamingoSwapControllerService_tokenToReceive_get = function _FlamingoSwapControllerService_tokenToReceive_get() {
|
|
281
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateTokenToReceive, "f");
|
|
282
|
-
}, _FlamingoSwapControllerService_tokenToReceive_set = function _FlamingoSwapControllerService_tokenToReceive_set(val) {
|
|
283
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateTokenToReceive, val, "f");
|
|
284
|
-
this.eventEmitter.emit('tokenToReceive', val);
|
|
285
|
-
}, _FlamingoSwapControllerService_tokenToUse_get = function _FlamingoSwapControllerService_tokenToUse_get() {
|
|
286
|
-
return __classPrivateFieldGet(this, _FlamingoSwapControllerService_privateTokenToUse, "f");
|
|
287
|
-
}, _FlamingoSwapControllerService_tokenToUse_set = function _FlamingoSwapControllerService_tokenToUse_set(val) {
|
|
288
|
-
__classPrivateFieldSet(this, _FlamingoSwapControllerService_privateTokenToUse, val, "f");
|
|
289
|
-
this.eventEmitter.emit('tokenToUse', val);
|
|
290
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { Network, Token } from '@cityofzion/blockchain-service';
|
|
3
|
-
import { BSNeo3NetworkId } from '../BSNeo3Helper';
|
|
4
|
-
type TGetSwapArgs = {
|
|
5
|
-
amountToUse: string | null;
|
|
6
|
-
amountToReceive: string | null;
|
|
7
|
-
tokenToUse: Token;
|
|
8
|
-
tokenToReceive: Token;
|
|
9
|
-
reservesToUse: string;
|
|
10
|
-
reservesToReceive: string;
|
|
11
|
-
slippage: number;
|
|
12
|
-
network: Network<BSNeo3NetworkId>;
|
|
13
|
-
};
|
|
14
|
-
export type SwapScriptHashes = {
|
|
15
|
-
flamingoSwapRouter: string;
|
|
16
|
-
flamingoPairWhiteList: string;
|
|
17
|
-
flamingoFactory: string;
|
|
18
|
-
neo: string;
|
|
19
|
-
gas: string;
|
|
20
|
-
bneo: string;
|
|
21
|
-
flpBneoGas: string;
|
|
22
|
-
};
|
|
23
|
-
export declare class FlamingoSwapHelper {
|
|
24
|
-
#private;
|
|
25
|
-
static readonly BN_0: BigNumber;
|
|
26
|
-
static readonly BN_1: BigNumber;
|
|
27
|
-
static readonly BN_997: BigNumber;
|
|
28
|
-
static readonly BN_1000: BigNumber;
|
|
29
|
-
static readonly FEE_RATE: BigNumber;
|
|
30
|
-
static readonly GAS_PER_NEO = 0.001;
|
|
31
|
-
static getSwapScriptHashes(network: Network<BSNeo3NetworkId>): SwapScriptHashes;
|
|
32
|
-
static getBneoToken(network: Network<BSNeo3NetworkId>): Token;
|
|
33
|
-
static getSwapFields(params: TGetSwapArgs): {
|
|
34
|
-
amountToReceiveToDisplay: string;
|
|
35
|
-
amountToUseToDisplay: string;
|
|
36
|
-
liquidityProviderFee: string;
|
|
37
|
-
priceImpact: string | null;
|
|
38
|
-
priceInverse: string | null;
|
|
39
|
-
minimumReceived: string | null;
|
|
40
|
-
maximumSelling: string | null;
|
|
41
|
-
};
|
|
42
|
-
static overrideToken(network: Network<BSNeo3NetworkId>, token: Token): Token;
|
|
43
|
-
private static createTradeData;
|
|
44
|
-
private static overrideAmountInput;
|
|
45
|
-
private static overrideAmountToDisplay;
|
|
46
|
-
private static normalizeHash;
|
|
47
|
-
}
|
|
48
|
-
export {};
|
|
@@ -1,171 +0,0 @@
|
|
|
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, _FlamingoSwapHelper_SWAP_SCRIPT_HASHES_BY_NETWORK_ID, _FlamingoSwapHelper_BNEO_TOKEN_BY_NETWORK_ID;
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.FlamingoSwapHelper = void 0;
|
|
13
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
14
|
-
class FlamingoSwapHelper {
|
|
15
|
-
static getSwapScriptHashes(network) {
|
|
16
|
-
const hashes = __classPrivateFieldGet(this, _a, "f", _FlamingoSwapHelper_SWAP_SCRIPT_HASHES_BY_NETWORK_ID)[network.id];
|
|
17
|
-
if (!hashes)
|
|
18
|
-
throw new Error('Unsupported network');
|
|
19
|
-
return hashes;
|
|
20
|
-
}
|
|
21
|
-
static getBneoToken(network) {
|
|
22
|
-
const token = __classPrivateFieldGet(this, _a, "f", _FlamingoSwapHelper_BNEO_TOKEN_BY_NETWORK_ID)[network.id];
|
|
23
|
-
if (!token)
|
|
24
|
-
throw new Error('Unsupported network');
|
|
25
|
-
return token;
|
|
26
|
-
}
|
|
27
|
-
static getSwapFields(params) {
|
|
28
|
-
const reservesToUseBn = new bignumber_js_1.default(params.reservesToUse);
|
|
29
|
-
const reservesToReceiveBn = new bignumber_js_1.default(params.reservesToReceive);
|
|
30
|
-
if (reservesToUseBn.lt(this.BN_0) || reservesToReceiveBn.lt(this.BN_0)) {
|
|
31
|
-
throw new Error('Reserve should be positive number');
|
|
32
|
-
}
|
|
33
|
-
let amountToUseBn;
|
|
34
|
-
let amountToReceiveBn;
|
|
35
|
-
let amountToUseToDisplay;
|
|
36
|
-
let amountToReceiveToDisplay;
|
|
37
|
-
let maximumSelling = null;
|
|
38
|
-
let minimumReceived = null;
|
|
39
|
-
const slippageFormatted = new bignumber_js_1.default(params.slippage * 10).shiftedBy(-3);
|
|
40
|
-
if (params.amountToReceive) {
|
|
41
|
-
amountToReceiveBn = this.overrideAmountInput(params.network, params.amountToReceive, params.tokenToReceive);
|
|
42
|
-
amountToUseBn = reservesToUseBn
|
|
43
|
-
.times(amountToReceiveBn)
|
|
44
|
-
.times(this.BN_1000)
|
|
45
|
-
.idiv(reservesToReceiveBn.minus(amountToReceiveBn).times(this.BN_997))
|
|
46
|
-
.plus(this.BN_1);
|
|
47
|
-
maximumSelling = amountToUseBn
|
|
48
|
-
.times(this.BN_1.plus(slippageFormatted))
|
|
49
|
-
.dp(0)
|
|
50
|
-
.shiftedBy(-params.tokenToUse.decimals)
|
|
51
|
-
.toFixed();
|
|
52
|
-
amountToUseToDisplay = this.overrideAmountToDisplay(params.network, amountToUseBn.toFixed(), params.tokenToUse);
|
|
53
|
-
amountToReceiveToDisplay = params.amountToReceive;
|
|
54
|
-
}
|
|
55
|
-
else if (params.amountToUse) {
|
|
56
|
-
amountToUseBn = this.overrideAmountInput(params.network, params.amountToUse, params.tokenToUse);
|
|
57
|
-
const amountToUseWithFee = amountToUseBn.times(this.BN_997);
|
|
58
|
-
amountToReceiveBn = amountToUseWithFee
|
|
59
|
-
.times(params.reservesToReceive)
|
|
60
|
-
.idiv(reservesToUseBn.times(this.BN_1000).plus(amountToUseWithFee));
|
|
61
|
-
minimumReceived = amountToReceiveBn
|
|
62
|
-
.times(this.BN_1.minus(slippageFormatted))
|
|
63
|
-
.dp(0)
|
|
64
|
-
.shiftedBy(-params.tokenToReceive.decimals)
|
|
65
|
-
.toFixed();
|
|
66
|
-
amountToReceiveToDisplay = this.overrideAmountToDisplay(params.network, amountToReceiveBn.toString(), params.tokenToReceive);
|
|
67
|
-
amountToUseToDisplay = params.amountToUse;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
throw new Error('AmountToReceive or amountToUse are required, but both aren`t provided');
|
|
71
|
-
}
|
|
72
|
-
const route = [
|
|
73
|
-
{
|
|
74
|
-
assetToUseSymbol: this.overrideToken(params.network, params.tokenToUse).symbol,
|
|
75
|
-
reservesToReceive: params.reservesToReceive,
|
|
76
|
-
assetToReceiveSymbol: this.overrideToken(params.network, params.tokenToReceive).symbol,
|
|
77
|
-
reservesToUse: params.reservesToUse,
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
const { fee, price, priceImpact } = this.createTradeData({
|
|
81
|
-
amountToReceive: amountToReceiveBn,
|
|
82
|
-
amountToUse: amountToUseBn,
|
|
83
|
-
route,
|
|
84
|
-
});
|
|
85
|
-
const priceInverse = this.BN_1.div(price);
|
|
86
|
-
const diffDecimals = params.tokenToUse.decimals - params.tokenToReceive.decimals;
|
|
87
|
-
return {
|
|
88
|
-
amountToReceiveToDisplay,
|
|
89
|
-
amountToUseToDisplay,
|
|
90
|
-
liquidityProviderFee: fee.shiftedBy(-8).plus(this.BN_0).toFixed(4),
|
|
91
|
-
priceImpact: isFinite(Number(priceImpact)) ? priceImpact.shiftedBy(2).toFixed(4) : null,
|
|
92
|
-
priceInverse: isFinite(Number(priceInverse)) ? priceInverse.multipliedBy(Math.pow(10, diffDecimals)).toFixed() : null,
|
|
93
|
-
minimumReceived,
|
|
94
|
-
maximumSelling,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
static overrideToken(network, token) {
|
|
98
|
-
const scriptHashes = this.getSwapScriptHashes(network);
|
|
99
|
-
const isNeoToken = this.normalizeHash(token.hash) === this.normalizeHash(scriptHashes.neo);
|
|
100
|
-
if (!isNeoToken) {
|
|
101
|
-
return token;
|
|
102
|
-
}
|
|
103
|
-
const bneoToken = this.getBneoToken(network);
|
|
104
|
-
return bneoToken;
|
|
105
|
-
}
|
|
106
|
-
static createTradeData({ amountToUse, amountToReceive, route }) {
|
|
107
|
-
const fee = amountToUse.minus(route.reduce((acc) => acc.times(this.BN_1.minus(this.FEE_RATE)), amountToUse));
|
|
108
|
-
const price = amountToUse.div(amountToReceive);
|
|
109
|
-
const midPrice = route.reduce((acc, item) => acc.times(item.reservesToUse).div(item.reservesToReceive), this.BN_1);
|
|
110
|
-
const priceImpact = price.minus(midPrice).div(price).minus(fee.div(amountToUse));
|
|
111
|
-
return {
|
|
112
|
-
fee,
|
|
113
|
-
price,
|
|
114
|
-
priceImpact,
|
|
115
|
-
midPrice,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
static overrideAmountInput(network, amount, token) {
|
|
119
|
-
const tokenOverrode = this.overrideToken(network, token);
|
|
120
|
-
return new bignumber_js_1.default(amount).shiftedBy(tokenOverrode.decimals);
|
|
121
|
-
}
|
|
122
|
-
static overrideAmountToDisplay(network, amount, token) {
|
|
123
|
-
const tokenOverrode = this.overrideToken(network, token);
|
|
124
|
-
return new bignumber_js_1.default(amount).shiftedBy(-tokenOverrode.decimals).toFixed();
|
|
125
|
-
}
|
|
126
|
-
static normalizeHash(hash) {
|
|
127
|
-
return hash.startsWith('0x') ? hash.slice(2) : hash;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
exports.FlamingoSwapHelper = FlamingoSwapHelper;
|
|
131
|
-
_a = FlamingoSwapHelper;
|
|
132
|
-
FlamingoSwapHelper.BN_0 = new bignumber_js_1.default(0);
|
|
133
|
-
FlamingoSwapHelper.BN_1 = new bignumber_js_1.default(1);
|
|
134
|
-
FlamingoSwapHelper.BN_997 = new bignumber_js_1.default(997);
|
|
135
|
-
FlamingoSwapHelper.BN_1000 = new bignumber_js_1.default(1000);
|
|
136
|
-
FlamingoSwapHelper.FEE_RATE = new bignumber_js_1.default(0.003);
|
|
137
|
-
FlamingoSwapHelper.GAS_PER_NEO = 0.001;
|
|
138
|
-
_FlamingoSwapHelper_SWAP_SCRIPT_HASHES_BY_NETWORK_ID = { value: {
|
|
139
|
-
mainnet: {
|
|
140
|
-
flamingoSwapRouter: '0xf970f4ccecd765b63732b821775dc38c25d74f23',
|
|
141
|
-
flamingoPairWhiteList: '0xfb75a5314069b56e136713d38477f647a13991b4',
|
|
142
|
-
flamingoFactory: '0xca2d20610d7982ebe0bed124ee7e9b2d580a6efc',
|
|
143
|
-
gas: '0xd2a4cff31913016155e38e474a2c06d08be276cf',
|
|
144
|
-
neo: '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
|
|
145
|
-
bneo: '0x48c40d4666f93408be1bef038b6722404d9a4c2a',
|
|
146
|
-
flpBneoGas: '0x3244fcadcccff190c329f7b3083e4da2af60fbce',
|
|
147
|
-
},
|
|
148
|
-
testnet: {
|
|
149
|
-
flamingoSwapRouter: '0x6f0910fa26290f4a423930c8f833395790c71705',
|
|
150
|
-
flamingoPairWhiteList: '0xfb75a5314069b56e136713d38477f647a13991b4',
|
|
151
|
-
flamingoFactory: '0xca2d20610d7982ebe0bed124ee7e9b2d580a6efc',
|
|
152
|
-
gas: '0xd2a4cff31913016155e38e474a2c06d08be276cf',
|
|
153
|
-
neo: '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
|
|
154
|
-
bneo: '0x85deac50febfd93988d3f391dea54e8289e43e9e',
|
|
155
|
-
flpBneoGas: '0x3244fcadcccff190c329f7b3083e4da2af60fbce',
|
|
156
|
-
},
|
|
157
|
-
} };
|
|
158
|
-
_FlamingoSwapHelper_BNEO_TOKEN_BY_NETWORK_ID = { value: {
|
|
159
|
-
mainnet: {
|
|
160
|
-
symbol: 'bNEO',
|
|
161
|
-
hash: '0x48c40d4666f93408be1bef038b6722404d9a4c2a',
|
|
162
|
-
decimals: 8,
|
|
163
|
-
name: 'BurgerNEO',
|
|
164
|
-
},
|
|
165
|
-
testnet: {
|
|
166
|
-
symbol: 'bNEO',
|
|
167
|
-
hash: '0x85deac50febfd93988d3f391dea54e8289e43e9e',
|
|
168
|
-
decimals: 8,
|
|
169
|
-
name: 'BurgerNEO',
|
|
170
|
-
},
|
|
171
|
-
} };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ContractInvocationMulti } from '@cityofzion/neon-dappkit-types';
|
|
2
|
-
import { Network, SwapControllerServiceSwapToUseArgs, SwapControllerServiceSwapToReceiveArgs } from '@cityofzion/blockchain-service';
|
|
3
|
-
import { BSNeo3NetworkId } from '../BSNeo3Helper';
|
|
4
|
-
type GetReservesArgs = {
|
|
5
|
-
network: Network<BSNeo3NetworkId>;
|
|
6
|
-
tokenToReceiveScriptHash: string;
|
|
7
|
-
tokenToUseScriptHash: string;
|
|
8
|
-
};
|
|
9
|
-
export declare class FlamingoSwapNeonDappKitInvocationBuilder {
|
|
10
|
-
static swapInvocation(data: SwapControllerServiceSwapToReceiveArgs<BSNeo3NetworkId> | SwapControllerServiceSwapToUseArgs<BSNeo3NetworkId>): ContractInvocationMulti;
|
|
11
|
-
static getReservesInvocation({ network, tokenToReceiveScriptHash, tokenToUseScriptHash, }: GetReservesArgs): ContractInvocationMulti;
|
|
12
|
-
private static swapTokenToReceiveForTokenToUseInvocation;
|
|
13
|
-
private static swapTokenToUseForTokenToReceiveInvocation;
|
|
14
|
-
private static transferContractInvocation;
|
|
15
|
-
private static allowedContractsSwap;
|
|
16
|
-
private static allowedContractsTransfer;
|
|
17
|
-
private static overrideScriptHash;
|
|
18
|
-
}
|
|
19
|
-
export {};
|