@cityofzion/bs-multichain 3.0.4 → 3.0.5
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/BSAggregator.js +4 -15
- package/dist/features/bridge/Neo3NeoXBridgeOrchestrator.js +245 -241
- package/dist/features/swap/SimpleSwapApi.js +114 -144
- package/dist/features/swap/SimpleSwapOrchestrator.js +273 -295
- package/dist/features/swap/SimpleSwapService.js +20 -31
- package/dist/features/wallet-connect/WalletKitHelper.js +19 -32
- package/package.json +15 -18
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -56,194 +47,131 @@ class SimpleSwapOrchestrator {
|
|
|
56
47
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_blockchainServicesByName, params.blockchainServicesByName, "f");
|
|
57
48
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_chainsByServiceName, params.chainsByServiceName, "f");
|
|
58
49
|
}
|
|
59
|
-
init() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
});
|
|
50
|
+
async init() {
|
|
51
|
+
try {
|
|
52
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: true }, "a", _SimpleSwapOrchestrator_availableTokensToUse_set);
|
|
53
|
+
const tokens = await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_api, "f").getCurrencies({
|
|
54
|
+
blockchainServicesByName: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_blockchainServicesByName, "f"),
|
|
55
|
+
chainsByServiceName: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_chainsByServiceName, "f"),
|
|
56
|
+
});
|
|
57
|
+
const filteredTokens = tokens.filter(token => token.blockchain && token.hash);
|
|
58
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: filteredTokens }, "a", _SimpleSwapOrchestrator_availableTokensToUse_set);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: [] }, "a", _SimpleSwapOrchestrator_availableTokensToUse_set);
|
|
62
|
+
this.eventEmitter.emit('error', error.message);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
76
65
|
}
|
|
77
|
-
setTokenToUse(token) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
yield __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, ['amountToReceive', 'availableTokensToReceive', 'amountToUseMinMax', 'amountToUse']);
|
|
98
|
-
});
|
|
66
|
+
async setTokenToUse(token) {
|
|
67
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: null }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
68
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: null }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
69
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: true }, "a", _SimpleSwapOrchestrator_tokenToUse_set);
|
|
70
|
+
if (!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_availableTokensToUse_get).value)
|
|
71
|
+
throw new Error('Available tokens to use is not set');
|
|
72
|
+
let simpleSwapCurrency = null;
|
|
73
|
+
if (token) {
|
|
74
|
+
simpleSwapCurrency = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_availableTokensToUse_get).value.find(item => item.id === token.id) ?? null;
|
|
75
|
+
if (!simpleSwapCurrency)
|
|
76
|
+
throw new Error('You are trying to use a token that is not available');
|
|
77
|
+
if (!simpleSwapCurrency?.blockchain || !simpleSwapCurrency.hash)
|
|
78
|
+
throw new Error('Token is not valid');
|
|
79
|
+
}
|
|
80
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: simpleSwapCurrency }, "a", _SimpleSwapOrchestrator_tokenToUse_set);
|
|
81
|
+
if (__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value?.blockchain !== simpleSwapCurrency?.blockchain) {
|
|
82
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: null }, "a", _SimpleSwapOrchestrator_accountToUse_set);
|
|
83
|
+
}
|
|
84
|
+
await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, ['amountToReceive', 'availableTokensToReceive', 'amountToUseMinMax', 'amountToUse']);
|
|
99
85
|
}
|
|
100
|
-
setAccountToUse(account) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
yield __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, []);
|
|
104
|
-
});
|
|
86
|
+
async setAccountToUse(account) {
|
|
87
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: account }, "a", _SimpleSwapOrchestrator_accountToUse_set);
|
|
88
|
+
await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, []);
|
|
105
89
|
}
|
|
106
|
-
setAmountToUse(amount) {
|
|
107
|
-
|
|
90
|
+
async setAmountToUse(amount) {
|
|
91
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
92
|
+
value: amount,
|
|
93
|
+
}, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
94
|
+
if (__classPrivateFieldGet(this, _SimpleSwapOrchestrator_amountToUseTimeout, "f") !== null)
|
|
95
|
+
clearTimeout(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_amountToUseTimeout, "f"));
|
|
96
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_amountToUseTimeout, setTimeout(() => {
|
|
108
97
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
109
|
-
value:
|
|
98
|
+
value: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value
|
|
99
|
+
? blockchain_service_1.BSBigNumberHelper.format(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value, {
|
|
100
|
+
decimals: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value?.decimals,
|
|
101
|
+
})
|
|
102
|
+
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value,
|
|
110
103
|
}, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_amountToUseTimeout, setTimeout(() => {
|
|
114
|
-
var _a;
|
|
115
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
116
|
-
value: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value
|
|
117
|
-
? blockchain_service_1.BSBigNumberHelper.format(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value, {
|
|
118
|
-
decimals: (_a = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value) === null || _a === void 0 ? void 0 : _a.decimals,
|
|
119
|
-
})
|
|
120
|
-
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value,
|
|
121
|
-
}, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
122
|
-
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, ['amountToReceive']);
|
|
123
|
-
}, 1500), "f");
|
|
124
|
-
});
|
|
104
|
+
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, ['amountToReceive']);
|
|
105
|
+
}, 1500), "f");
|
|
125
106
|
}
|
|
126
|
-
setTokenToReceive(token) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}, "a", _SimpleSwapOrchestrator_tokenToReceive_set);
|
|
143
|
-
yield __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, ['amountToReceive', 'amountToUseMinMax', 'amountToUse']);
|
|
144
|
-
});
|
|
107
|
+
async setTokenToReceive(token) {
|
|
108
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null, valid: null }, "a", _SimpleSwapOrchestrator_extraIdToReceive_set);
|
|
109
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: null }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
110
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false, value: null }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
111
|
+
if (!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_availableTokensToReceive_get).value)
|
|
112
|
+
throw new Error('Available tokens to receive is not set');
|
|
113
|
+
let simpleSwapCurrency = null;
|
|
114
|
+
if (token) {
|
|
115
|
+
simpleSwapCurrency = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_availableTokensToReceive_get).value.find(item => item.id === token.id) ?? null;
|
|
116
|
+
if (!simpleSwapCurrency)
|
|
117
|
+
throw new Error('You are trying to use a token that is not available');
|
|
118
|
+
}
|
|
119
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
120
|
+
value: simpleSwapCurrency ? { ...token, ...simpleSwapCurrency } : null,
|
|
121
|
+
}, "a", _SimpleSwapOrchestrator_tokenToReceive_set);
|
|
122
|
+
await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, ['amountToReceive', 'amountToUseMinMax', 'amountToUse']);
|
|
145
123
|
}
|
|
146
|
-
setAddressToReceive(address) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
yield __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, []);
|
|
153
|
-
});
|
|
124
|
+
async setAddressToReceive(address) {
|
|
125
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
126
|
+
loading: false,
|
|
127
|
+
value: address,
|
|
128
|
+
}, "a", _SimpleSwapOrchestrator_addressToReceive_set);
|
|
129
|
+
await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, []);
|
|
154
130
|
}
|
|
155
|
-
setExtraIdToReceive(extraIdToReceive) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: extraIdToReceive, valid: null }, "a", _SimpleSwapOrchestrator_extraIdToReceive_set);
|
|
161
|
-
yield __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, []);
|
|
162
|
-
});
|
|
131
|
+
async setExtraIdToReceive(extraIdToReceive) {
|
|
132
|
+
if (!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value?.hasExtraId)
|
|
133
|
+
return;
|
|
134
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: extraIdToReceive, valid: null }, "a", _SimpleSwapOrchestrator_extraIdToReceive_set);
|
|
135
|
+
await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, []);
|
|
163
136
|
}
|
|
164
|
-
swap() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const service = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_blockchainServicesByName, "f")[__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value.blockchain];
|
|
198
|
-
const [transactionHash] = yield service.transfer({
|
|
199
|
-
senderAccount: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value,
|
|
200
|
-
intents: [
|
|
201
|
-
{
|
|
202
|
-
amount: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value,
|
|
203
|
-
receiverAddress: depositAddress,
|
|
204
|
-
token: {
|
|
205
|
-
decimals: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals,
|
|
206
|
-
hash: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.hash,
|
|
207
|
-
name: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.name,
|
|
208
|
-
symbol: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.symbol,
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
});
|
|
213
|
-
result.txFrom = transactionHash;
|
|
214
|
-
}
|
|
215
|
-
catch (_b) {
|
|
216
|
-
// empty
|
|
217
|
-
}
|
|
218
|
-
return result;
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
calculateFee() {
|
|
222
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
-
if (!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value ||
|
|
224
|
-
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value ||
|
|
225
|
-
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value ||
|
|
226
|
-
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value ||
|
|
227
|
-
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).valid ||
|
|
228
|
-
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value ||
|
|
229
|
-
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToReceive_get).value ||
|
|
230
|
-
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.hash ||
|
|
231
|
-
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals === undefined ||
|
|
232
|
-
isNaN(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals)) {
|
|
233
|
-
throw new Error('Not all required fields are set');
|
|
234
|
-
}
|
|
235
|
-
const { blockchain } = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value;
|
|
236
|
-
const service = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_blockchainServicesByName, "f")[blockchain];
|
|
237
|
-
if (!(0, blockchain_service_1.isCalculableFee)(service))
|
|
238
|
-
return '0';
|
|
239
|
-
return yield service.calculateTransferFee({
|
|
137
|
+
async swap() {
|
|
138
|
+
if (!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value ||
|
|
139
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value ||
|
|
140
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value ||
|
|
141
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value ||
|
|
142
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).valid ||
|
|
143
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value ||
|
|
144
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToReceive_get).value ||
|
|
145
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.hash ||
|
|
146
|
+
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals === undefined ||
|
|
147
|
+
isNaN(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals) ||
|
|
148
|
+
(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value.hasExtraId &&
|
|
149
|
+
(!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_extraIdToReceive_get).valid || !__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_extraIdToReceive_get).value?.trim()))) {
|
|
150
|
+
throw new Error('Not all required fields are set');
|
|
151
|
+
}
|
|
152
|
+
const result = {
|
|
153
|
+
id: '',
|
|
154
|
+
txFrom: undefined,
|
|
155
|
+
log: undefined,
|
|
156
|
+
};
|
|
157
|
+
try {
|
|
158
|
+
const { depositAddress, id, log } = await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_api, "f").createExchange({
|
|
159
|
+
currencyFrom: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value,
|
|
160
|
+
currencyTo: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value,
|
|
161
|
+
amount: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value,
|
|
162
|
+
refundAddress: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value.address,
|
|
163
|
+
address: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value,
|
|
164
|
+
extraIdToReceive: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_extraIdToReceive_get).value,
|
|
165
|
+
});
|
|
166
|
+
result.id = id;
|
|
167
|
+
result.log = log;
|
|
168
|
+
const service = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_blockchainServicesByName, "f")[__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value.blockchain];
|
|
169
|
+
const [transactionHash] = await service.transfer({
|
|
240
170
|
senderAccount: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value,
|
|
241
171
|
intents: [
|
|
242
172
|
{
|
|
243
173
|
amount: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value,
|
|
244
|
-
receiverAddress:
|
|
245
|
-
? __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value
|
|
246
|
-
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value.address,
|
|
174
|
+
receiverAddress: depositAddress,
|
|
247
175
|
token: {
|
|
248
176
|
decimals: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals,
|
|
249
177
|
hash: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.hash,
|
|
@@ -253,6 +181,46 @@ class SimpleSwapOrchestrator {
|
|
|
253
181
|
},
|
|
254
182
|
],
|
|
255
183
|
});
|
|
184
|
+
result.txFrom = transactionHash;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// empty
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
async calculateFee() {
|
|
192
|
+
if (!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value ||
|
|
193
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value ||
|
|
194
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value ||
|
|
195
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value ||
|
|
196
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).valid ||
|
|
197
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value ||
|
|
198
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToReceive_get).value ||
|
|
199
|
+
!__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.hash ||
|
|
200
|
+
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals === undefined ||
|
|
201
|
+
isNaN(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals)) {
|
|
202
|
+
throw new Error('Not all required fields are set');
|
|
203
|
+
}
|
|
204
|
+
const { blockchain } = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value;
|
|
205
|
+
const service = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_blockchainServicesByName, "f")[blockchain];
|
|
206
|
+
if (!(0, blockchain_service_1.isCalculableFee)(service))
|
|
207
|
+
return '0';
|
|
208
|
+
return await service.calculateTransferFee({
|
|
209
|
+
senderAccount: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value,
|
|
210
|
+
intents: [
|
|
211
|
+
{
|
|
212
|
+
amount: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value,
|
|
213
|
+
receiverAddress: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value.blockchain === blockchain
|
|
214
|
+
? __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value
|
|
215
|
+
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value.address,
|
|
216
|
+
token: {
|
|
217
|
+
decimals: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals,
|
|
218
|
+
hash: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.hash,
|
|
219
|
+
name: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.name,
|
|
220
|
+
symbol: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.symbol,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
],
|
|
256
224
|
});
|
|
257
225
|
}
|
|
258
226
|
}
|
|
@@ -274,168 +242,178 @@ _SimpleSwapOrchestrator_api = new WeakMap(), _SimpleSwapOrchestrator_blockchainS
|
|
|
274
242
|
}, _SimpleSwapOrchestrator_availableTokensToUse_get = function _SimpleSwapOrchestrator_availableTokensToUse_get() {
|
|
275
243
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, "f");
|
|
276
244
|
}, _SimpleSwapOrchestrator_availableTokensToUse_set = function _SimpleSwapOrchestrator_availableTokensToUse_set(availableTokens) {
|
|
277
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse,
|
|
278
|
-
this.eventEmitter.emit('availableTokensToUse',
|
|
245
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, "f"), ...availableTokens }, "f");
|
|
246
|
+
this.eventEmitter.emit('availableTokensToUse', {
|
|
247
|
+
...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, "f"),
|
|
248
|
+
value: !__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, "f").value
|
|
279
249
|
? __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, "f").value
|
|
280
|
-
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, "f").value.map(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken))
|
|
250
|
+
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToUse, "f").value.map(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken)),
|
|
251
|
+
});
|
|
281
252
|
}, _SimpleSwapOrchestrator_tokenToUse_get = function _SimpleSwapOrchestrator_tokenToUse_get() {
|
|
282
253
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToUse, "f");
|
|
283
254
|
}, _SimpleSwapOrchestrator_tokenToUse_set = function _SimpleSwapOrchestrator_tokenToUse_set(tokenToUse) {
|
|
284
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalTokenToUse,
|
|
285
|
-
this.eventEmitter.emit('tokenToUse',
|
|
255
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalTokenToUse, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToUse, "f"), ...tokenToUse }, "f");
|
|
256
|
+
this.eventEmitter.emit('tokenToUse', {
|
|
257
|
+
...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToUse, "f"),
|
|
258
|
+
value: !__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToUse, "f").value
|
|
286
259
|
? __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToUse, "f").value
|
|
287
|
-
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken).call(this, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToUse, "f").value)
|
|
260
|
+
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken).call(this, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToUse, "f").value),
|
|
261
|
+
});
|
|
288
262
|
}, _SimpleSwapOrchestrator_accountToUse_get = function _SimpleSwapOrchestrator_accountToUse_get() {
|
|
289
263
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAccountToUse, "f");
|
|
290
264
|
}, _SimpleSwapOrchestrator_accountToUse_set = function _SimpleSwapOrchestrator_accountToUse_set(accountToUse) {
|
|
291
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAccountToUse,
|
|
265
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAccountToUse, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAccountToUse, "f"), ...accountToUse }, "f");
|
|
292
266
|
this.eventEmitter.emit('accountToUse', __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAccountToUse, "f"));
|
|
293
267
|
}, _SimpleSwapOrchestrator_amountToUse_get = function _SimpleSwapOrchestrator_amountToUse_get() {
|
|
294
268
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToUse, "f");
|
|
295
269
|
}, _SimpleSwapOrchestrator_amountToUse_set = function _SimpleSwapOrchestrator_amountToUse_set(amountToUse) {
|
|
296
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAmountToUse,
|
|
270
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAmountToUse, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToUse, "f"), ...amountToUse }, "f");
|
|
297
271
|
this.eventEmitter.emit('amountToUse', __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToUse, "f"));
|
|
298
272
|
}, _SimpleSwapOrchestrator_amountToUseMinMax_get = function _SimpleSwapOrchestrator_amountToUseMinMax_get() {
|
|
299
273
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToUseMinMax, "f");
|
|
300
274
|
}, _SimpleSwapOrchestrator_amountToUseMinMax_set = function _SimpleSwapOrchestrator_amountToUseMinMax_set(amountToUseMinMax) {
|
|
301
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAmountToUseMinMax,
|
|
275
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAmountToUseMinMax, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToUseMinMax, "f"), ...amountToUseMinMax }, "f");
|
|
302
276
|
this.eventEmitter.emit('amountToUseMinMax', __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToUseMinMax, "f"));
|
|
303
277
|
}, _SimpleSwapOrchestrator_availableTokensToReceive_get = function _SimpleSwapOrchestrator_availableTokensToReceive_get() {
|
|
304
278
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, "f");
|
|
305
279
|
}, _SimpleSwapOrchestrator_availableTokensToReceive_set = function _SimpleSwapOrchestrator_availableTokensToReceive_set(availableTokens) {
|
|
306
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive,
|
|
307
|
-
this.eventEmitter.emit('availableTokensToReceive',
|
|
280
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, "f"), ...availableTokens }, "f");
|
|
281
|
+
this.eventEmitter.emit('availableTokensToReceive', {
|
|
282
|
+
...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, "f"),
|
|
283
|
+
value: !__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, "f").value
|
|
308
284
|
? __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, "f").value
|
|
309
|
-
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, "f").value.map(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken))
|
|
285
|
+
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAvailableTokensToReceive, "f").value.map(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken)),
|
|
286
|
+
});
|
|
310
287
|
}, _SimpleSwapOrchestrator_tokenToReceive_get = function _SimpleSwapOrchestrator_tokenToReceive_get() {
|
|
311
288
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToReceive, "f");
|
|
312
289
|
}, _SimpleSwapOrchestrator_tokenToReceive_set = function _SimpleSwapOrchestrator_tokenToReceive_set(tokenToReceive) {
|
|
313
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalTokenToReceive,
|
|
314
|
-
this.eventEmitter.emit('tokenToReceive',
|
|
290
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalTokenToReceive, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToReceive, "f"), ...tokenToReceive }, "f");
|
|
291
|
+
this.eventEmitter.emit('tokenToReceive', {
|
|
292
|
+
...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToReceive, "f"),
|
|
293
|
+
value: !__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToReceive, "f").value
|
|
315
294
|
? __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToReceive, "f").value
|
|
316
|
-
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken).call(this, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToReceive, "f").value)
|
|
295
|
+
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_createSwapToken).call(this, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalTokenToReceive, "f").value),
|
|
296
|
+
});
|
|
317
297
|
}, _SimpleSwapOrchestrator_addressToReceive_get = function _SimpleSwapOrchestrator_addressToReceive_get() {
|
|
318
298
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAddressToReceive, "f");
|
|
319
299
|
}, _SimpleSwapOrchestrator_addressToReceive_set = function _SimpleSwapOrchestrator_addressToReceive_set(addressToReceive) {
|
|
320
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAddressToReceive,
|
|
300
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAddressToReceive, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAddressToReceive, "f"), ...addressToReceive }, "f");
|
|
321
301
|
this.eventEmitter.emit('addressToReceive', __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAddressToReceive, "f"));
|
|
322
302
|
}, _SimpleSwapOrchestrator_extraIdToReceive_get = function _SimpleSwapOrchestrator_extraIdToReceive_get() {
|
|
323
303
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalExtraIdToReceive, "f");
|
|
324
304
|
}, _SimpleSwapOrchestrator_extraIdToReceive_set = function _SimpleSwapOrchestrator_extraIdToReceive_set(extraIdToReceive) {
|
|
325
305
|
if (extraIdToReceive.value === '')
|
|
326
306
|
extraIdToReceive.value = null;
|
|
327
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalExtraIdToReceive,
|
|
307
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalExtraIdToReceive, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalExtraIdToReceive, "f"), ...extraIdToReceive }, "f");
|
|
328
308
|
this.eventEmitter.emit('extraIdToReceive', __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalExtraIdToReceive, "f"));
|
|
329
309
|
}, _SimpleSwapOrchestrator_amountToReceive_get = function _SimpleSwapOrchestrator_amountToReceive_get() {
|
|
330
310
|
return __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToReceive, "f");
|
|
331
311
|
}, _SimpleSwapOrchestrator_amountToReceive_set = function _SimpleSwapOrchestrator_amountToReceive_set(amountToReceive) {
|
|
332
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAmountToReceive,
|
|
312
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_internalAmountToReceive, { ...__classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToReceive, "f"), ...amountToReceive }, "f");
|
|
333
313
|
this.eventEmitter.emit('amountToReceive', __classPrivateFieldGet(this, _SimpleSwapOrchestrator_internalAmountToReceive, "f"));
|
|
334
|
-
}, _SimpleSwapOrchestrator_recalculateValues = function _SimpleSwapOrchestrator_recalculateValues(fieldsToRecalculate) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
314
|
+
}, _SimpleSwapOrchestrator_recalculateValues = async function _SimpleSwapOrchestrator_recalculateValues(fieldsToRecalculate) {
|
|
315
|
+
try {
|
|
316
|
+
if (__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value === null) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value) {
|
|
320
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
321
|
+
valid: RegExp(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value.validationAddress).test(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_addressToReceive_get).value),
|
|
322
|
+
}, "a", _SimpleSwapOrchestrator_addressToReceive_set);
|
|
323
|
+
}
|
|
324
|
+
if (__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_extraIdToReceive_get).value && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value) {
|
|
325
|
+
const extraIdToReceive = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_extraIdToReceive_get).value.trim();
|
|
326
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
327
|
+
valid: !extraIdToReceive || !__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value.validationExtra
|
|
328
|
+
? true
|
|
329
|
+
: RegExp(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value.validationExtra).test(extraIdToReceive),
|
|
330
|
+
}, "a", _SimpleSwapOrchestrator_extraIdToReceive_set);
|
|
331
|
+
}
|
|
332
|
+
if (__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value) {
|
|
333
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { valid: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.blockchain === __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_accountToUse_get).value.blockchain }, "a", _SimpleSwapOrchestrator_accountToUse_set);
|
|
334
|
+
}
|
|
335
|
+
const shouldRecalculateAvailableTokensToReceive = fieldsToRecalculate.includes('availableTokensToReceive');
|
|
336
|
+
const shouldRecalculateAmountToUse = fieldsToRecalculate.includes('amountToUse') &&
|
|
337
|
+
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value === null &&
|
|
338
|
+
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value !== null;
|
|
339
|
+
const shouldRecalculateAmountToReceive = fieldsToRecalculate.includes('amountToReceive') && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value !== null;
|
|
340
|
+
const shouldRecalculateAmountToUseMinMax = fieldsToRecalculate.includes('amountToUseMinMax') && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value !== null;
|
|
341
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: shouldRecalculateAvailableTokensToReceive }, "a", _SimpleSwapOrchestrator_availableTokensToReceive_set);
|
|
342
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: shouldRecalculateAmountToUseMinMax }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
343
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: shouldRecalculateAmountToUse }, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
344
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: shouldRecalculateAmountToReceive }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
345
|
+
if (shouldRecalculateAvailableTokensToReceive) {
|
|
346
|
+
try {
|
|
347
|
+
const pairs = await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_api, "f").getPairs(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.ticker, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.network);
|
|
348
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: pairs }, "a", _SimpleSwapOrchestrator_availableTokensToReceive_set);
|
|
349
|
+
if (__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value && !pairs.some(pair => pair.ticker === __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.ticker)) {
|
|
350
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_tokenToReceive_set);
|
|
351
|
+
}
|
|
352
352
|
}
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
catch (error) {
|
|
354
|
+
this.eventEmitter.emit('error', error.message);
|
|
355
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_availableTokensToReceive_set);
|
|
356
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_tokenToReceive_set);
|
|
357
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
358
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
359
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null, valid: null }, "a", _SimpleSwapOrchestrator_addressToReceive_set);
|
|
360
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null, valid: null }, "a", _SimpleSwapOrchestrator_extraIdToReceive_set);
|
|
361
|
+
throw error;
|
|
355
362
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
363
|
+
}
|
|
364
|
+
if (shouldRecalculateAmountToUseMinMax || shouldRecalculateAmountToUse || shouldRecalculateAmountToReceive) {
|
|
365
|
+
let range = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUseMinMax_get).value;
|
|
366
|
+
try {
|
|
367
|
+
if ((shouldRecalculateAmountToUseMinMax || range === null) && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value) {
|
|
368
|
+
const { decimals } = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value;
|
|
369
|
+
const rangeResponse = await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_api, "f").getRange(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value);
|
|
370
|
+
// Add 1% because the SimpleSwap sends us a smaller minimum than the required
|
|
371
|
+
const minWithOnePercent = blockchain_service_1.BSBigNumberHelper.format((Number(rangeResponse.min) * 1.01).toString(), {
|
|
372
|
+
decimals,
|
|
373
|
+
});
|
|
374
|
+
// Add the smallest number to round up correctly because the SimpleSwap doesn't have the decimals, and we need to apply the decimals here
|
|
375
|
+
const smallestNumberToRoundUp = decimals ? `0.${'2'.padStart(decimals, '0')}` : '1';
|
|
376
|
+
range = {
|
|
377
|
+
min: blockchain_service_1.BSBigNumberHelper.format(Number(minWithOnePercent) + Number(smallestNumberToRoundUp), {
|
|
378
|
+
decimals,
|
|
379
|
+
}),
|
|
380
|
+
max: rangeResponse.max ? blockchain_service_1.BSBigNumberHelper.format(rangeResponse.max, { decimals }) : rangeResponse.max,
|
|
381
|
+
};
|
|
373
382
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null, valid: null }, "a", _SimpleSwapOrchestrator_extraIdToReceive_set);
|
|
382
|
-
throw error;
|
|
383
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: range }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
384
|
+
if (shouldRecalculateAmountToUse && range) {
|
|
385
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
386
|
+
value: range.min
|
|
387
|
+
? blockchain_service_1.BSBigNumberHelper.format(range.min, { decimals: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals })
|
|
388
|
+
: range.min,
|
|
389
|
+
}, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
383
390
|
}
|
|
384
391
|
}
|
|
385
|
-
|
|
386
|
-
|
|
392
|
+
catch (error) {
|
|
393
|
+
this.eventEmitter.emit('error', error.message);
|
|
394
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
395
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
if (shouldRecalculateAmountToReceive && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value) {
|
|
387
399
|
try {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const minWithOnePercent = blockchain_service_1.BSBigNumberHelper.format((Number(rangeResponse.min) * 1.01).toString(), {
|
|
393
|
-
decimals,
|
|
394
|
-
});
|
|
395
|
-
// Add the smallest number to round up correctly because the SimpleSwap doesn't have the decimals, and we need to apply the decimals here
|
|
396
|
-
const smallestNumberToRoundUp = decimals ? `0.${'2'.padStart(decimals, '0')}` : '1';
|
|
397
|
-
range = {
|
|
398
|
-
min: blockchain_service_1.BSBigNumberHelper.format(Number(minWithOnePercent) + Number(smallestNumberToRoundUp), {
|
|
399
|
-
decimals,
|
|
400
|
-
}),
|
|
401
|
-
max: rangeResponse.max ? blockchain_service_1.BSBigNumberHelper.format(rangeResponse.max, { decimals }) : rangeResponse.max,
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: range }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
405
|
-
if (shouldRecalculateAmountToUse && range) {
|
|
406
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
407
|
-
value: range.min
|
|
408
|
-
? blockchain_service_1.BSBigNumberHelper.format(range.min, { decimals: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals })
|
|
409
|
-
: range.min,
|
|
410
|
-
}, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
411
|
-
}
|
|
400
|
+
const estimate = await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_api, "f").getEstimate(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value);
|
|
401
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
402
|
+
value: estimate,
|
|
403
|
+
}, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
412
404
|
}
|
|
413
405
|
catch (error) {
|
|
414
406
|
this.eventEmitter.emit('error', error.message);
|
|
415
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
416
407
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
417
408
|
throw error;
|
|
418
409
|
}
|
|
419
|
-
if (shouldRecalculateAmountToReceive && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value && __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value) {
|
|
420
|
-
try {
|
|
421
|
-
const estimate = yield __classPrivateFieldGet(this, _SimpleSwapOrchestrator_api, "f").getEstimate(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value);
|
|
422
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
423
|
-
value: estimate,
|
|
424
|
-
}, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
425
|
-
}
|
|
426
|
-
catch (error) {
|
|
427
|
-
this.eventEmitter.emit('error', error.message);
|
|
428
|
-
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: null }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
429
|
-
throw error;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
410
|
}
|
|
433
411
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
}
|
|
412
|
+
}
|
|
413
|
+
finally {
|
|
414
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false }, "a", _SimpleSwapOrchestrator_availableTokensToReceive_set);
|
|
415
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
416
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false }, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
417
|
+
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { loading: false }, "a", _SimpleSwapOrchestrator_amountToReceive_set);
|
|
418
|
+
}
|
|
441
419
|
};
|