@cityofzion/bs-neo3 1.4.1 → 1.4.2
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/builder/invocation/FlamingoSwapInvocationBuilderNeo3.js +164 -50
- package/dist/constants/FlamingoSwapConstants.d.ts +1 -1
- package/dist/constants/FlamingoSwapConstants.js +1 -1
- package/dist/helpers/FlamingoSwapHelper.d.ts +7 -1
- package/dist/helpers/FlamingoSwapHelper.js +37 -0
- package/dist/services/blockchain-data/DoraBDSNeo3.d.ts +1 -1
- package/dist/services/nft-data/GhostMarketNDSNeo3.d.ts +1 -1
- package/dist/services/swap/FlamingoSwapServiceNeo3.js +21 -0
- package/package.json +3 -3
|
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
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
5
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
6
|
};
|
|
7
|
-
var _a,
|
|
7
|
+
var _a, _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation, _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation, _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation, _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation, _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.FlamingoSwapInvocationBuilderNeo3 = void 0;
|
|
10
10
|
const neon_core_1 = require("@cityofzion/neon-core");
|
|
@@ -13,22 +13,56 @@ const FlamingoSwapHelper_1 = require("../../helpers/FlamingoSwapHelper");
|
|
|
13
13
|
const NeonDappKitInvocationBuilderNeo3_1 = require("./NeonDappKitInvocationBuilderNeo3");
|
|
14
14
|
class FlamingoSwapInvocationBuilderNeo3 {
|
|
15
15
|
static swapInvocation(data) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const { routePath, network, type } = data;
|
|
17
|
+
const [tokenToUse] = routePath;
|
|
18
|
+
const tokenToReceive = routePath[routePath.length - 1];
|
|
19
|
+
const scriptHashes = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapScriptHashes(network);
|
|
20
|
+
const swapParams = {
|
|
21
|
+
scriptHashes,
|
|
22
|
+
tokenToUse,
|
|
23
|
+
tokenToReceive,
|
|
24
|
+
};
|
|
25
|
+
if (type === 'swapTokenToReceive') {
|
|
26
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation).call(this, Object.assign(Object.assign({}, data), swapParams));
|
|
27
|
+
}
|
|
28
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation).call(this, Object.assign(Object.assign({}, data), swapParams));
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
31
|
exports.FlamingoSwapInvocationBuilderNeo3 = FlamingoSwapInvocationBuilderNeo3;
|
|
22
|
-
_a = FlamingoSwapInvocationBuilderNeo3,
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
_a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation(data) {
|
|
33
|
+
const { network, routePath } = data;
|
|
34
|
+
if (FlamingoSwapHelper_1.FlamingoSwapHelper.isSwapUnwrappingNeo(network, routePath)) {
|
|
35
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation).call(this, data);
|
|
36
|
+
}
|
|
37
|
+
if (FlamingoSwapHelper_1.FlamingoSwapHelper.isUnwrapNeo(network, routePath)) {
|
|
38
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation).call(this, data);
|
|
39
|
+
}
|
|
40
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation).call(this, data);
|
|
41
|
+
}, _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation(data) {
|
|
42
|
+
const { network, routePath } = data;
|
|
43
|
+
if (FlamingoSwapHelper_1.FlamingoSwapHelper.isSwapWrappingNeo(network, routePath)) {
|
|
44
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation).call(this, data);
|
|
45
|
+
}
|
|
46
|
+
if (FlamingoSwapHelper_1.FlamingoSwapHelper.isWrapNeo(network, routePath)) {
|
|
47
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation).call(this, data);
|
|
48
|
+
}
|
|
49
|
+
return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation).call(this, data);
|
|
50
|
+
}, _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation(data) {
|
|
51
|
+
const { address, amountToReceive, deadline, maximumSelling, network, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
|
|
28
52
|
const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
|
|
29
53
|
const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
|
|
30
54
|
const amountToReceiveFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToReceive, tokenToReceiveOverrode.decimals);
|
|
31
55
|
const maximumSellingFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(maximumSelling, tokenToUse.decimals);
|
|
56
|
+
const amountToReceiveTransfer = neon_core_1.u.BigInteger.fromNumber(Number(amountToReceiveFormatted) * FlamingoSwapConstants_1.FlamingoSwapConstants.UNWRAPPING_FEE).toString();
|
|
57
|
+
const GAS = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'GAS');
|
|
58
|
+
const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
|
|
59
|
+
const unwrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
|
|
60
|
+
contractHash: GAS.hash,
|
|
61
|
+
tokenHash: bNEO.hash,
|
|
62
|
+
senderAddress: address,
|
|
63
|
+
amount: amountToReceiveTransfer,
|
|
64
|
+
});
|
|
65
|
+
const unwrapAllowedContracts = [GAS.hash, bNEO.hash];
|
|
32
66
|
const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenOutForTokenInContractInvocation({
|
|
33
67
|
routerScriptHash: scriptHashes.flamingoSwapRouter,
|
|
34
68
|
senderAddress: address,
|
|
@@ -37,31 +71,122 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
37
71
|
deadline,
|
|
38
72
|
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
|
|
39
73
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
74
|
+
const swapAllowedContracts = [
|
|
75
|
+
scriptHashes.flamingoSwapRouter,
|
|
76
|
+
scriptHashes.flamingoFactory,
|
|
77
|
+
scriptHashes.flamingoPairWhiteList,
|
|
78
|
+
];
|
|
79
|
+
const allowedContracts = [
|
|
80
|
+
...new Set([...swapAllowedContracts, ...unwrapAllowedContracts, ...routePath.map(token => token.hash)]),
|
|
81
|
+
];
|
|
49
82
|
return {
|
|
50
|
-
invocations,
|
|
83
|
+
invocations: [swapInvocation, unwrapInvocation],
|
|
84
|
+
signers: [
|
|
85
|
+
{
|
|
86
|
+
scopes: neon_core_1.tx.WitnessScope.CustomContracts,
|
|
87
|
+
allowedContracts,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}, _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation(data) {
|
|
92
|
+
const { address, amountToReceive, network, tokenToReceive } = data;
|
|
93
|
+
const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
|
|
94
|
+
const amountToReceiveFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToReceive, tokenToReceiveOverrode.decimals);
|
|
95
|
+
const GAS = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'GAS');
|
|
96
|
+
const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
|
|
97
|
+
const unwrappedAmount = FlamingoSwapHelper_1.FlamingoSwapHelper.getUnwrappedAmount(amountToReceiveFormatted);
|
|
98
|
+
const unwrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
|
|
99
|
+
contractHash: GAS.hash,
|
|
100
|
+
tokenHash: bNEO.hash,
|
|
101
|
+
senderAddress: address,
|
|
102
|
+
amount: unwrappedAmount,
|
|
103
|
+
});
|
|
104
|
+
const unwrapAllowedContracts = [GAS.hash, bNEO.hash];
|
|
105
|
+
return {
|
|
106
|
+
invocations: [unwrapInvocation],
|
|
107
|
+
signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts: unwrapAllowedContracts }],
|
|
108
|
+
};
|
|
109
|
+
}, _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation(data) {
|
|
110
|
+
const { address, amountToReceive, deadline, maximumSelling, network, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
|
|
111
|
+
const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
|
|
112
|
+
const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
|
|
113
|
+
const amountToReceiveFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToReceive, tokenToReceiveOverrode.decimals);
|
|
114
|
+
const maximumSellingFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(maximumSelling, tokenToUse.decimals);
|
|
115
|
+
const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenOutForTokenInContractInvocation({
|
|
116
|
+
routerScriptHash: scriptHashes.flamingoSwapRouter,
|
|
117
|
+
senderAddress: address,
|
|
118
|
+
amountToReceive: amountToReceiveFormatted,
|
|
119
|
+
maximumSelling: maximumSellingFormatted,
|
|
120
|
+
deadline,
|
|
121
|
+
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
|
|
122
|
+
});
|
|
123
|
+
const swapAllowedContracts = [
|
|
124
|
+
scriptHashes.flamingoSwapRouter,
|
|
125
|
+
scriptHashes.flamingoFactory,
|
|
126
|
+
scriptHashes.flamingoPairWhiteList,
|
|
127
|
+
];
|
|
128
|
+
const allowedContracts = [...new Set([...swapAllowedContracts, ...routePath.map(token => token.hash)])];
|
|
129
|
+
return {
|
|
130
|
+
invocations: [swapInvocation],
|
|
51
131
|
signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts }],
|
|
52
132
|
};
|
|
53
|
-
},
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
133
|
+
}, _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation(data) {
|
|
134
|
+
const { address, amountToUse, network, deadline, minimumReceived, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
|
|
135
|
+
const tokenToUseOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToUse);
|
|
136
|
+
const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
|
|
137
|
+
const amountToUseFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToUse, tokenToUseOverrode.decimals);
|
|
138
|
+
const minimumReceivedFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(minimumReceived, tokenToReceive.decimals);
|
|
139
|
+
const NEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO');
|
|
140
|
+
const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
|
|
141
|
+
const wrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
|
|
142
|
+
contractHash: NEO.hash,
|
|
143
|
+
tokenHash: bNEO.hash,
|
|
144
|
+
senderAddress: address,
|
|
145
|
+
amount: amountToUse,
|
|
146
|
+
});
|
|
147
|
+
const wrapAllowedContracts = [NEO.hash, bNEO.hash];
|
|
148
|
+
const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenInForTokenOutContractInvocation({
|
|
149
|
+
routerScriptHash: scriptHashes.flamingoSwapRouter,
|
|
150
|
+
amountToUse: amountToUseFormatted,
|
|
151
|
+
minimumReceived: minimumReceivedFormatted,
|
|
152
|
+
senderAddress: address,
|
|
153
|
+
deadline,
|
|
154
|
+
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
|
|
155
|
+
});
|
|
156
|
+
const swapAllowedContracts = [
|
|
157
|
+
scriptHashes.flamingoSwapRouter,
|
|
158
|
+
scriptHashes.flamingoFactory,
|
|
159
|
+
scriptHashes.flamingoPairWhiteList,
|
|
160
|
+
];
|
|
161
|
+
const allowedContracts = [
|
|
162
|
+
...new Set([...swapAllowedContracts, ...wrapAllowedContracts, ...routePath.map(token => token.hash)]),
|
|
163
|
+
];
|
|
164
|
+
return {
|
|
165
|
+
invocations: [wrapInvocation, swapInvocation],
|
|
166
|
+
signers: [
|
|
167
|
+
{
|
|
168
|
+
scopes: neon_core_1.tx.WitnessScope.CustomContracts,
|
|
169
|
+
allowedContracts,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
}, _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation(data) {
|
|
174
|
+
const { address, amountToUse, network } = data;
|
|
175
|
+
const NEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO');
|
|
176
|
+
const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
|
|
177
|
+
const wrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
|
|
178
|
+
contractHash: NEO.hash,
|
|
179
|
+
tokenHash: bNEO.hash,
|
|
180
|
+
senderAddress: address,
|
|
181
|
+
amount: amountToUse,
|
|
182
|
+
});
|
|
183
|
+
const wrapAllowedContracts = [NEO.hash, bNEO.hash];
|
|
184
|
+
return {
|
|
185
|
+
invocations: [wrapInvocation],
|
|
186
|
+
signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts: wrapAllowedContracts }],
|
|
187
|
+
};
|
|
188
|
+
}, _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation(data) {
|
|
189
|
+
const { address, amountToUse, deadline, minimumReceived, network, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
|
|
65
190
|
const tokenToUseOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToUse);
|
|
66
191
|
const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
|
|
67
192
|
const amountToUseFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToUse, tokenToUseOverrode.decimals);
|
|
@@ -74,10 +199,14 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
74
199
|
deadline,
|
|
75
200
|
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
|
|
76
201
|
});
|
|
77
|
-
|
|
78
|
-
|
|
202
|
+
const swapAllowedContracts = [
|
|
203
|
+
scriptHashes.flamingoSwapRouter,
|
|
204
|
+
scriptHashes.flamingoFactory,
|
|
205
|
+
scriptHashes.flamingoPairWhiteList,
|
|
206
|
+
];
|
|
207
|
+
const allowedContracts = [...new Set([...swapAllowedContracts, ...routePath.map(token => token.hash)])];
|
|
79
208
|
return {
|
|
80
|
-
invocations,
|
|
209
|
+
invocations: [swapInvocation],
|
|
81
210
|
signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts }],
|
|
82
211
|
};
|
|
83
212
|
}, _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs = function _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs(routePath) {
|
|
@@ -85,19 +214,4 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
85
214
|
type: 'Hash160',
|
|
86
215
|
value: token.hash,
|
|
87
216
|
}));
|
|
88
|
-
}, _FlamingoSwapInvocationBuilderNeo3_getAllowedContracts = function _FlamingoSwapInvocationBuilderNeo3_getAllowedContracts(scriptHashes, routePath) {
|
|
89
|
-
return [
|
|
90
|
-
scriptHashes.flamingoSwapRouter,
|
|
91
|
-
scriptHashes.flamingoFactory,
|
|
92
|
-
scriptHashes.flamingoPairWhiteList,
|
|
93
|
-
...routePath.map(token => token.hash),
|
|
94
|
-
];
|
|
95
|
-
}, _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation = function _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation(senderAddress, contractHash, amount, network) {
|
|
96
|
-
const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
|
|
97
|
-
return NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
|
|
98
|
-
contractHash,
|
|
99
|
-
tokenHash: bNEO.hash,
|
|
100
|
-
senderAddress,
|
|
101
|
-
amount,
|
|
102
|
-
});
|
|
103
217
|
};
|
|
@@ -25,7 +25,7 @@ export declare class FlamingoSwapConstants {
|
|
|
25
25
|
static readonly BN_997: BigNumber;
|
|
26
26
|
static readonly BN_1000: BigNumber;
|
|
27
27
|
static readonly FEE_RATE: BigNumber;
|
|
28
|
-
static readonly
|
|
28
|
+
static readonly UNWRAPPING_FEE = 0.001;
|
|
29
29
|
static readonly TESTNET_FLAMINGO_SWAP_TOKENS: FlamingoSwapTokens;
|
|
30
30
|
static readonly MAINNET_FLAMINGO_SWAP_TOKENS: FlamingoSwapTokens;
|
|
31
31
|
static readonly FLAMINGO_SWAP_TOKENS: Record<BSNeo3NetworkId, FlamingoSwapTokens>;
|
|
@@ -16,7 +16,7 @@ FlamingoSwapConstants.BN_1 = new bignumber_js_1.default(1);
|
|
|
16
16
|
FlamingoSwapConstants.BN_997 = new bignumber_js_1.default(997);
|
|
17
17
|
FlamingoSwapConstants.BN_1000 = new bignumber_js_1.default(1000);
|
|
18
18
|
FlamingoSwapConstants.FEE_RATE = new bignumber_js_1.default(0.003);
|
|
19
|
-
FlamingoSwapConstants.
|
|
19
|
+
FlamingoSwapConstants.UNWRAPPING_FEE = 0.001;
|
|
20
20
|
FlamingoSwapConstants.TESTNET_FLAMINGO_SWAP_TOKENS = {
|
|
21
21
|
// ============ Neo Assets ============ //
|
|
22
22
|
FLM: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Network, SwapRoute, Token } from '@cityofzion/blockchain-service';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { FlamingoSwapPoolInfo, FlamingoSwapPools, FlamingoSwapScriptHashes, FlamingoSwapTokens } from '../constants/FlamingoSwapConstants';
|
|
4
3
|
import { BSNeo3NetworkId } from '../constants/BSNeo3Constants';
|
|
4
|
+
import { FlamingoSwapPoolInfo, FlamingoSwapPools, FlamingoSwapScriptHashes, FlamingoSwapTokens } from '../constants/FlamingoSwapConstants';
|
|
5
5
|
export declare class FlamingoSwapHelper {
|
|
6
6
|
static listSwappableTokensSymbol(network: Network<BSNeo3NetworkId>): string[];
|
|
7
7
|
static getFlamingoSwapPools(network: Network<BSNeo3NetworkId>): FlamingoSwapPools;
|
|
@@ -17,5 +17,11 @@ export declare class FlamingoSwapHelper {
|
|
|
17
17
|
static overrideRoutePath(network: Network<BSNeo3NetworkId>, routePath: Token[]): Token[];
|
|
18
18
|
static normalizeHash(hash: string): string;
|
|
19
19
|
static isNeoToken(network: Network<BSNeo3NetworkId>, token: Token): boolean;
|
|
20
|
+
static isBneoToken(network: Network<BSNeo3NetworkId>, token: Token): boolean;
|
|
20
21
|
static formatAmount(amount: string, decimals: number): string;
|
|
22
|
+
static isSwapUnwrappingNeo(network: Network<BSNeo3NetworkId>, route: Token[]): boolean;
|
|
23
|
+
static isSwapWrappingNeo(network: Network<BSNeo3NetworkId>, route: Token[]): boolean;
|
|
24
|
+
static isWrapNeo(network: Network<BSNeo3NetworkId>, route: Token[]): boolean;
|
|
25
|
+
static isUnwrapNeo(network: Network<BSNeo3NetworkId>, route: Token[]): boolean;
|
|
26
|
+
static getUnwrappedAmount(amount: string): string;
|
|
21
27
|
}
|
|
@@ -85,8 +85,45 @@ class FlamingoSwapHelper {
|
|
|
85
85
|
const NEO = this.getFlamingoSwapToken(network, 'NEO');
|
|
86
86
|
return this.normalizeHash(token.hash) === this.normalizeHash(NEO.hash);
|
|
87
87
|
}
|
|
88
|
+
static isBneoToken(network, token) {
|
|
89
|
+
const bNEO = this.getFlamingoSwapToken(network, 'bNEO');
|
|
90
|
+
return this.normalizeHash(token.hash) === this.normalizeHash(bNEO.hash);
|
|
91
|
+
}
|
|
88
92
|
static formatAmount(amount, decimals) {
|
|
89
93
|
return neon_core_1.u.BigInteger.fromDecimal(Number(amount), decimals).toString();
|
|
90
94
|
}
|
|
95
|
+
static isSwapUnwrappingNeo(network, route) {
|
|
96
|
+
if (route.length < 3) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const lastToken = route[route.length - 1];
|
|
100
|
+
return this.isNeoToken(network, lastToken);
|
|
101
|
+
}
|
|
102
|
+
static isSwapWrappingNeo(network, route) {
|
|
103
|
+
if (route.length < 3) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const firstToken = route[0];
|
|
107
|
+
return this.isNeoToken(network, firstToken);
|
|
108
|
+
}
|
|
109
|
+
static isWrapNeo(network, route) {
|
|
110
|
+
if (route.length !== 2) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const firstToken = route[0];
|
|
114
|
+
const lastToken = route[1];
|
|
115
|
+
return this.isNeoToken(network, firstToken) && this.isBneoToken(network, lastToken);
|
|
116
|
+
}
|
|
117
|
+
static isUnwrapNeo(network, route) {
|
|
118
|
+
if (route.length !== 2) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const firstToken = route[0];
|
|
122
|
+
const lastToken = route[1];
|
|
123
|
+
return this.isBneoToken(network, firstToken) && this.isNeoToken(network, lastToken);
|
|
124
|
+
}
|
|
125
|
+
static getUnwrappedAmount(amount) {
|
|
126
|
+
return neon_core_1.u.BigInteger.fromNumber(Number(amount) * FlamingoSwapConstants_1.FlamingoSwapConstants.UNWRAPPING_FEE).toString();
|
|
127
|
+
}
|
|
91
128
|
}
|
|
92
129
|
exports.FlamingoSwapHelper = FlamingoSwapHelper;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BalanceResponse, ContractResponse, Network, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
|
|
2
|
-
import { RpcBDSNeo3 } from './RpcBDSNeo3';
|
|
3
2
|
import { BSNeo3NetworkId } from '../../constants/BSNeo3Constants';
|
|
3
|
+
import { RpcBDSNeo3 } from './RpcBDSNeo3';
|
|
4
4
|
export declare class DoraBDSNeo3 extends RpcBDSNeo3 {
|
|
5
5
|
constructor(network: Network<BSNeo3NetworkId>, feeToken: Token, claimToken: Token, tokens: Token[]);
|
|
6
6
|
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetNftParam, GetNftsByAddressParams, Network, NftResponse, NftsResponse } from '@cityofzion/blockchain-service';
|
|
2
|
-
import { RpcNDSNeo3 } from './RpcNDSNeo3';
|
|
3
2
|
import { BSNeo3NetworkId } from '../../constants/BSNeo3Constants';
|
|
3
|
+
import { RpcNDSNeo3 } from './RpcNDSNeo3';
|
|
4
4
|
export declare class GhostMarketNDSNeo3 extends RpcNDSNeo3 {
|
|
5
5
|
#private;
|
|
6
6
|
static CONFIG_BY_NETWORK_ID: Partial<Record<BSNeo3NetworkId, {
|
|
@@ -160,6 +160,27 @@ _FlamingoSwapServiceNeo3_blockchainService = new WeakMap(), _FlamingoSwapService
|
|
|
160
160
|
(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToUse' && __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToUse_get))) {
|
|
161
161
|
const amountToReceive = __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToReceive' ? __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToReceive_get) : null;
|
|
162
162
|
const amountToUse = __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_lastAmountChanged_get) === 'amountToUse' ? __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToUse_get) : null;
|
|
163
|
+
const initialRoutePath = [__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get), __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get)];
|
|
164
|
+
if (FlamingoSwapHelper_1.FlamingoSwapHelper.isWrapNeo(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f"), initialRoutePath) ||
|
|
165
|
+
FlamingoSwapHelper_1.FlamingoSwapHelper.isUnwrapNeo(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f"), initialRoutePath)) {
|
|
166
|
+
const amount = amountToUse !== null && amountToUse !== void 0 ? amountToUse : amountToReceive;
|
|
167
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, amount, "a", _FlamingoSwapServiceNeo3_amountToUse_set);
|
|
168
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, amount, "a", _FlamingoSwapServiceNeo3_amountToReceive_set);
|
|
169
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, amount, "a", _FlamingoSwapServiceNeo3_maximumSelling_set);
|
|
170
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, amount, "a", _FlamingoSwapServiceNeo3_minimumReceived_set);
|
|
171
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_liquidityProviderFee_set);
|
|
172
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_priceImpact_set);
|
|
173
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, null, "a", _FlamingoSwapServiceNeo3_priceInverse_set);
|
|
174
|
+
__classPrivateFieldSet(this, _FlamingoSwapServiceNeo3_instances, [
|
|
175
|
+
{
|
|
176
|
+
reserveTokenToReceive: '0',
|
|
177
|
+
reserveTokenToUse: '0',
|
|
178
|
+
tokenToReceive: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToReceive_get),
|
|
179
|
+
tokenToUse: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_tokenToUse_get),
|
|
180
|
+
},
|
|
181
|
+
], "a", _FlamingoSwapServiceNeo3_route_set);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
163
184
|
const { amountToUseToDisplay, amountToReceiveToDisplay, maximumSelling, minimumReceived, liquidityProviderFee, priceImpact, priceInverse, } = handlers_1.FlamingoSwapDetailsHandler.calculateSwapDetails({
|
|
164
185
|
network: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f"),
|
|
165
186
|
amountToReceive,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-neo3",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"bignumber.js": "^9.1.2",
|
|
21
21
|
"isomorphic-ws": "^5.0.0",
|
|
22
22
|
"lodash.clonedeep": "^4.5.0",
|
|
23
|
-
"@cityofzion/
|
|
24
|
-
"@cityofzion/
|
|
23
|
+
"@cityofzion/bs-asteroid-sdk": "0.9.0",
|
|
24
|
+
"@cityofzion/blockchain-service": "1.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@cityofzion/neon-dappkit-types": "~0.3.1",
|