@airgap/stellar 0.13.45-beta.2 → 0.13.45-beta.3
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/package.json +4 -4
- package/v1/block-explorer/StellarBlockExplorer.js +12 -61
- package/v1/block-explorer/StellarBlockExplorer.js.map +1 -1
- package/v1/data/StellarAddress.js +13 -14
- package/v1/data/StellarAddress.js.map +1 -1
- package/v1/index.js +4 -4
- package/v1/index.js.map +1 -1
- package/v1/module/StellarModule.js +41 -110
- package/v1/module/StellarModule.js.map +1 -1
- package/v1/module.js +2 -3
- package/v1/module.js.map +1 -1
- package/v1/protocol/StellarProtocol.js +591 -859
- package/v1/protocol/StellarProtocol.js.map +1 -1
- package/v1/protocol/stellarAssets/StellarAsset.js +259 -466
- package/v1/protocol/stellarAssets/StellarAsset.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +8 -20
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +61 -134
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +14 -61
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +18 -62
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/crypto.d.ts +1 -1
- package/v1/types/protocol.d.ts +2 -2
- package/v1/types/protocol.js +2 -2
- package/v1/types/protocol.js.map +1 -1
- package/v1/utils/convert.js +6 -7
- package/v1/utils/convert.js.map +1 -1
- package/v1/utils/key.js +9 -10
- package/v1/utils/key.js.map +1 -1
- package/v1/utils/signature.js +4 -5
- package/v1/utils/signature.js.map +1 -1
- package/v1/utils/transaction.d.ts +0 -1
- package/v1/utils/transaction.js +9 -10
- package/v1/utils/transaction.js.map +1 -1
|
@@ -1,67 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
4
|
};
|
|
52
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
6
|
+
exports.STELLAR_MAINNET_PROTOCOL_NETWORK = exports.StellarProtocolImpl = void 0;
|
|
7
|
+
exports.createStellarProtocol = createStellarProtocol;
|
|
8
|
+
exports.createStellarProtocolOptions = createStellarProtocolOptions;
|
|
9
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
10
|
+
const index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
11
|
+
const errors_1 = require("@airgap/coinlib-core/errors");
|
|
12
|
+
const module_kit_1 = require("@airgap/module-kit");
|
|
13
|
+
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
14
|
+
const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
15
|
+
const protocol_1 = require("../types/protocol");
|
|
16
|
+
const StellarAddress_1 = require("../data/StellarAddress");
|
|
17
|
+
class StellarProtocolImpl {
|
|
18
|
+
constructor(options = {}) {
|
|
65
19
|
this.units = {
|
|
66
20
|
XLM: {
|
|
67
21
|
symbol: { value: 'XLM', market: 'xlm' },
|
|
@@ -92,7 +46,7 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
92
46
|
}
|
|
93
47
|
},
|
|
94
48
|
account: {
|
|
95
|
-
standardDerivationPath:
|
|
49
|
+
standardDerivationPath: `m/44h/148h/0h`,
|
|
96
50
|
address: {
|
|
97
51
|
isCaseSensitive: false,
|
|
98
52
|
placeholder: 'GABC...',
|
|
@@ -111,846 +65,624 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
111
65
|
this.options = createStellarProtocolOptions(options.network);
|
|
112
66
|
this.server = new stellar_sdk_1.Horizon.Server(this.options.network.rpcUrl);
|
|
113
67
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
68
|
+
async getMultisigStatus(publicKey) {
|
|
69
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
70
|
+
try {
|
|
71
|
+
const account = await this.server.loadAccount(address);
|
|
72
|
+
return account.signers.length > 1;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async getSigners(publicKey) {
|
|
79
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
80
|
+
try {
|
|
81
|
+
const account = await this.server.loadAccount(address);
|
|
82
|
+
return account.signers;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async getThresholds(publicKey) {
|
|
89
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
90
|
+
try {
|
|
91
|
+
const account = await this.server.loadAccount(address);
|
|
92
|
+
return account.thresholds;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async getThresholdReachedStatus(transaction) {
|
|
99
|
+
try {
|
|
100
|
+
const tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
101
|
+
const sourceAccountId = tx.source;
|
|
102
|
+
const account = await this.server.loadAccount(sourceAccountId);
|
|
103
|
+
const signers = account.signers;
|
|
104
|
+
const thresholds = account.thresholds;
|
|
105
|
+
const requiredThreshold = tx.operations.some((op) => ['setOptions', 'accountMerge'].includes(op.type))
|
|
106
|
+
? thresholds.high_threshold
|
|
107
|
+
: tx.operations.some((op) => [
|
|
108
|
+
'createAccount',
|
|
109
|
+
'payment',
|
|
110
|
+
'pathPaymentStrictReceive',
|
|
111
|
+
'pathPaymentStrictSend',
|
|
112
|
+
'manageSellOffer',
|
|
113
|
+
'manageBuyOffer',
|
|
114
|
+
'createPassiveSellOffer',
|
|
115
|
+
'changeTrust',
|
|
116
|
+
'manageData',
|
|
117
|
+
'createClaimableBalance',
|
|
118
|
+
'beginSponsoringFutureReserves',
|
|
119
|
+
'endSponsoringFutureReserves',
|
|
120
|
+
'revokeSponsorship',
|
|
121
|
+
'clawback',
|
|
122
|
+
'clawbackClaimableBalance',
|
|
123
|
+
'liquidityPoolDeposit',
|
|
124
|
+
'liquidityPoolWithdraw',
|
|
125
|
+
'invokeHostFunction',
|
|
126
|
+
'extendFootprintTtl',
|
|
127
|
+
'restoreFootprint'
|
|
128
|
+
].includes(op.type))
|
|
129
|
+
? thresholds.med_threshold
|
|
130
|
+
: thresholds.low_threshold;
|
|
131
|
+
let totalWeight = 0;
|
|
132
|
+
for (const sig of tx.signatures) {
|
|
133
|
+
for (const signer of signers) {
|
|
134
|
+
const keypair = stellar_sdk_1.Keypair.fromPublicKey(signer.key);
|
|
135
|
+
const hint = keypair.signatureHint();
|
|
136
|
+
if (hint.equals(sig.hint())) {
|
|
137
|
+
totalWeight += signer.weight;
|
|
138
|
+
}
|
|
133
139
|
}
|
|
134
|
-
}
|
|
140
|
+
}
|
|
141
|
+
const threshold = {
|
|
142
|
+
thresholdRequired: requiredThreshold,
|
|
143
|
+
currentThreshold: totalWeight
|
|
144
|
+
};
|
|
145
|
+
return threshold;
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return {
|
|
149
|
+
thresholdRequired: 0,
|
|
150
|
+
currentThreshold: 0
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async adjustSigner(masterPublicky, signerPublicKey, weight, lowThreshold, medThreshold, highThreshold) {
|
|
155
|
+
const masterAddress = await this.getAddressFromPublicKey(masterPublicky);
|
|
156
|
+
const signerAddress = await this.getAddressFromPublicKey(signerPublicKey);
|
|
157
|
+
const account = await this.server.loadAccount(masterAddress);
|
|
158
|
+
const signers = account.signers;
|
|
159
|
+
const txBuilder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
160
|
+
fee: stellar_sdk_1.BASE_FEE,
|
|
161
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
135
162
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
_a.trys.push([2, 4, , 5]);
|
|
148
|
-
return [4 /*yield*/, this.server.loadAccount(address)];
|
|
149
|
-
case 3:
|
|
150
|
-
account = _a.sent();
|
|
151
|
-
return [2 /*return*/, account.signers];
|
|
152
|
-
case 4:
|
|
153
|
-
error_2 = _a.sent();
|
|
154
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_2);
|
|
155
|
-
case 5: return [2 /*return*/];
|
|
163
|
+
if (signers.length === 1) {
|
|
164
|
+
const masterWeight = weight;
|
|
165
|
+
txBuilder
|
|
166
|
+
.addOperation(stellar_sdk_1.Operation.setOptions({
|
|
167
|
+
masterWeight,
|
|
168
|
+
lowThreshold,
|
|
169
|
+
medThreshold,
|
|
170
|
+
highThreshold,
|
|
171
|
+
signer: {
|
|
172
|
+
ed25519PublicKey: signerAddress,
|
|
173
|
+
weight
|
|
156
174
|
}
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
case 2:
|
|
170
|
-
_a.trys.push([2, 4, , 5]);
|
|
171
|
-
return [4 /*yield*/, this.server.loadAccount(address)];
|
|
172
|
-
case 3:
|
|
173
|
-
account = _a.sent();
|
|
174
|
-
return [2 /*return*/, account.thresholds];
|
|
175
|
-
case 4:
|
|
176
|
-
error_3 = _a.sent();
|
|
177
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_3);
|
|
178
|
-
case 5: return [2 /*return*/];
|
|
175
|
+
}))
|
|
176
|
+
.setTimeout(600);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
txBuilder
|
|
180
|
+
.addOperation(stellar_sdk_1.Operation.setOptions({
|
|
181
|
+
lowThreshold,
|
|
182
|
+
medThreshold,
|
|
183
|
+
highThreshold,
|
|
184
|
+
signer: {
|
|
185
|
+
ed25519PublicKey: signerAddress,
|
|
186
|
+
weight
|
|
179
187
|
}
|
|
180
|
-
})
|
|
188
|
+
}))
|
|
189
|
+
.setTimeout(600);
|
|
190
|
+
}
|
|
191
|
+
return (0, module_kit_1.newUnsignedTransaction)({
|
|
192
|
+
transaction: txBuilder.build().toXDR()
|
|
181
193
|
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
'extendFootprintTtl',
|
|
220
|
-
'restoreFootprint'
|
|
221
|
-
].includes(op.type);
|
|
222
|
-
})
|
|
223
|
-
? thresholds.med_threshold
|
|
224
|
-
: thresholds.low_threshold;
|
|
225
|
-
totalWeight = 0;
|
|
226
|
-
for (_i = 0, _a = tx.signatures; _i < _a.length; _i++) {
|
|
227
|
-
sig = _a[_i];
|
|
228
|
-
for (_b = 0, signers_1 = signers; _b < signers_1.length; _b++) {
|
|
229
|
-
signer = signers_1[_b];
|
|
230
|
-
keypair = stellar_sdk_1.Keypair.fromPublicKey(signer.key);
|
|
231
|
-
hint = keypair.signatureHint();
|
|
232
|
-
if (hint.equals(sig.hint())) {
|
|
233
|
-
totalWeight += signer.weight;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
threshold = {
|
|
238
|
-
thresholdRequired: requiredThreshold,
|
|
239
|
-
currentThreshold: totalWeight
|
|
240
|
-
};
|
|
241
|
-
return [2 /*return*/, threshold];
|
|
242
|
-
case 2:
|
|
243
|
-
error_4 = _c.sent();
|
|
244
|
-
return [2 /*return*/, {
|
|
245
|
-
thresholdRequired: 0,
|
|
246
|
-
currentThreshold: 0
|
|
247
|
-
}];
|
|
248
|
-
case 3: return [2 /*return*/];
|
|
249
|
-
}
|
|
194
|
+
}
|
|
195
|
+
async getTransactionsForPublicKey(publicKey, limit, cursor) {
|
|
196
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
197
|
+
return this.getTransactionsForAddress(address, limit, cursor);
|
|
198
|
+
}
|
|
199
|
+
async getTransactionsForAddress(address, limit, cursor) {
|
|
200
|
+
try {
|
|
201
|
+
const endpoint = cursor?.next ?? `/accounts/${address}/payments?limit=${limit}&order=desc&join=transactions`;
|
|
202
|
+
const url = `${this.options.network.rpcUrl}${endpoint}`;
|
|
203
|
+
const response = await index_1.default.get(url);
|
|
204
|
+
const data = response.data;
|
|
205
|
+
const paymentTransactions = data._embedded?.records ?? [];
|
|
206
|
+
const transactions = paymentTransactions
|
|
207
|
+
.filter((tx) => (tx.type === protocol_1.StellarTransactionType.PAYMENT && tx.asset_type === protocol_1.StellarAssetType.NATIVE) || tx.type === 'create_account')
|
|
208
|
+
.map((tx) => {
|
|
209
|
+
const txData = tx.transaction;
|
|
210
|
+
const isPayment = tx.type === protocol_1.StellarTransactionType.PAYMENT;
|
|
211
|
+
const txAmount = isPayment ? tx.amount : tx.starting_balance;
|
|
212
|
+
const amount = new bignumber_1.default(txAmount).multipliedBy(1e7).toString();
|
|
213
|
+
const from = isPayment ? tx.from : tx.funder;
|
|
214
|
+
const to = isPayment ? tx.to : tx.account;
|
|
215
|
+
const isInbound = to.toLowerCase() === address.toLowerCase();
|
|
216
|
+
return {
|
|
217
|
+
from: [from],
|
|
218
|
+
to: [to],
|
|
219
|
+
isInbound,
|
|
220
|
+
amount: (0, module_kit_1.newAmount)(amount, 'blockchain'),
|
|
221
|
+
fee: (0, module_kit_1.newAmount)(txData.fee_charged, 'blockchain'),
|
|
222
|
+
network: this.options.network,
|
|
223
|
+
timestamp: Math.floor(new Date(tx.created_at).getTime() / 1000),
|
|
224
|
+
status: {
|
|
225
|
+
type: tx.transaction_successful ? 'applied' : 'failed',
|
|
226
|
+
hash: tx.transaction_hash,
|
|
227
|
+
block: txData.ledger.toString()
|
|
228
|
+
},
|
|
229
|
+
arbitraryData: txData.memo
|
|
230
|
+
};
|
|
250
231
|
});
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return __generator(this, function (_a) {
|
|
257
|
-
switch (_a.label) {
|
|
258
|
-
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(masterPublicky)];
|
|
259
|
-
case 1:
|
|
260
|
-
masterAddress = _a.sent();
|
|
261
|
-
return [4 /*yield*/, this.getAddressFromPublicKey(signerPublicKey)];
|
|
262
|
-
case 2:
|
|
263
|
-
signerAddress = _a.sent();
|
|
264
|
-
return [4 /*yield*/, this.server.loadAccount(masterAddress)];
|
|
265
|
-
case 3:
|
|
266
|
-
account = _a.sent();
|
|
267
|
-
signers = account.signers;
|
|
268
|
-
txBuilder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
269
|
-
fee: stellar_sdk_1.BASE_FEE,
|
|
270
|
-
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
271
|
-
});
|
|
272
|
-
if (signers.length === 1) {
|
|
273
|
-
masterWeight = weight;
|
|
274
|
-
txBuilder
|
|
275
|
-
.addOperation(stellar_sdk_1.Operation.setOptions({
|
|
276
|
-
masterWeight: masterWeight,
|
|
277
|
-
lowThreshold: lowThreshold,
|
|
278
|
-
medThreshold: medThreshold,
|
|
279
|
-
highThreshold: highThreshold,
|
|
280
|
-
signer: {
|
|
281
|
-
ed25519PublicKey: signerAddress,
|
|
282
|
-
weight: weight
|
|
283
|
-
}
|
|
284
|
-
}))
|
|
285
|
-
.setTimeout(600);
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
txBuilder
|
|
289
|
-
.addOperation(stellar_sdk_1.Operation.setOptions({
|
|
290
|
-
lowThreshold: lowThreshold,
|
|
291
|
-
medThreshold: medThreshold,
|
|
292
|
-
highThreshold: highThreshold,
|
|
293
|
-
signer: {
|
|
294
|
-
ed25519PublicKey: signerAddress,
|
|
295
|
-
weight: weight
|
|
296
|
-
}
|
|
297
|
-
}))
|
|
298
|
-
.setTimeout(600);
|
|
299
|
-
}
|
|
300
|
-
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
301
|
-
transaction: txBuilder.build().toXDR()
|
|
302
|
-
})];
|
|
232
|
+
return {
|
|
233
|
+
transactions,
|
|
234
|
+
cursor: {
|
|
235
|
+
hasNext: data._links?.next?.href !== undefined,
|
|
236
|
+
next: data._links?.next?.href?.replace(this.options.network.rpcUrl, '') ?? undefined
|
|
303
237
|
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
if (error.response?.status === 404) {
|
|
242
|
+
return {
|
|
243
|
+
transactions: [],
|
|
244
|
+
cursor: {
|
|
245
|
+
hasNext: false,
|
|
246
|
+
next: ''
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async getTransactionMaxAmountWithPublicKey(publicKey, to, configuration) {
|
|
254
|
+
try {
|
|
255
|
+
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
256
|
+
const balanceBn = new bignumber_1.default(balance.total.value || '0');
|
|
257
|
+
let fee;
|
|
258
|
+
if (configuration?.fee !== undefined) {
|
|
259
|
+
fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
fee = new bignumber_1.default(stellar_sdk_1.BASE_FEE).multipliedBy(to.length).dividedBy(1e7);
|
|
263
|
+
}
|
|
264
|
+
if (fee.gte(balanceBn)) {
|
|
265
|
+
return (0, module_kit_1.newAmount)(0, 'blockchain');
|
|
266
|
+
}
|
|
267
|
+
let amountWithoutFees = balanceBn.minus(fee);
|
|
268
|
+
return (0, module_kit_1.newAmount)(amountWithoutFees, 'blockchain');
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async getTransactionFeeWithPublicKey(publicKey, details, configuration) {
|
|
275
|
+
return this.feeDefaults;
|
|
276
|
+
}
|
|
277
|
+
async getMetadata() {
|
|
278
|
+
return this.metadata;
|
|
279
|
+
}
|
|
280
|
+
async getAddressFromPublicKey(publicKey) {
|
|
281
|
+
return StellarAddress_1.StellarAddress.from(publicKey).asString();
|
|
282
|
+
}
|
|
283
|
+
async getDetailsFromTransaction(transaction, _publicKey) {
|
|
284
|
+
switch (transaction.type) {
|
|
285
|
+
case 'signed':
|
|
286
|
+
case 'unsigned':
|
|
287
|
+
return this.getDetailsFromEncodedTransaction(transaction.transaction, _publicKey);
|
|
288
|
+
default:
|
|
289
|
+
(0, coinlib_core_1.assertNever)(transaction);
|
|
290
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.STELLAR, 'Unsupported transaction type.');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async getDetailsFromEncodedGenericTransaction(transaction) {
|
|
294
|
+
return stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
295
|
+
}
|
|
296
|
+
async getDetailsFromEncodedTransaction(transaction, publicKey) {
|
|
297
|
+
const transactions = [];
|
|
298
|
+
const tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
299
|
+
for (const txDetails of tx.operations) {
|
|
300
|
+
let amount;
|
|
301
|
+
let op;
|
|
302
|
+
let to;
|
|
303
|
+
let fee;
|
|
304
|
+
let isInbound;
|
|
305
|
+
let type;
|
|
306
|
+
let uiAlerts = [];
|
|
307
|
+
let displayFromTo = true;
|
|
308
|
+
if (txDetails.type === protocol_1.StellarTransactionType.PAYMENT) {
|
|
309
|
+
op = txDetails;
|
|
310
|
+
if (op.asset.code === protocol_1.StellarAssetType.XLM) {
|
|
311
|
+
amount = new bignumber_1.default(op.amount).multipliedBy(1e7).toString();
|
|
316
312
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
var _this = this;
|
|
325
|
-
return __generator(this, function (_l) {
|
|
326
|
-
switch (_l.label) {
|
|
327
|
-
case 0:
|
|
328
|
-
_l.trys.push([0, 2, , 3]);
|
|
329
|
-
endpoint = (_a = cursor === null || cursor === void 0 ? void 0 : cursor.next) !== null && _a !== void 0 ? _a : "/accounts/".concat(address, "/payments?limit=").concat(limit, "&order=desc&join=transactions");
|
|
330
|
-
url = "".concat(this.options.network.rpcUrl).concat(endpoint);
|
|
331
|
-
return [4 /*yield*/, index_1.default.get(url)];
|
|
332
|
-
case 1:
|
|
333
|
-
response = _l.sent();
|
|
334
|
-
data = response.data;
|
|
335
|
-
paymentTransactions = (_c = (_b = data._embedded) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : [];
|
|
336
|
-
transactions = paymentTransactions
|
|
337
|
-
.filter(function (tx) {
|
|
338
|
-
return (tx.type === protocol_1.StellarTransactionType.PAYMENT && tx.asset_type === protocol_1.StellarAssetType.NATIVE) || tx.type === 'create_account';
|
|
339
|
-
})
|
|
340
|
-
.map(function (tx) {
|
|
341
|
-
var txData = tx.transaction;
|
|
342
|
-
var isPayment = tx.type === protocol_1.StellarTransactionType.PAYMENT;
|
|
343
|
-
var txAmount = isPayment ? tx.amount : tx.starting_balance;
|
|
344
|
-
var amount = new bignumber_1.default(txAmount).multipliedBy(1e7).toString();
|
|
345
|
-
var from = isPayment ? tx.from : tx.funder;
|
|
346
|
-
var to = isPayment ? tx.to : tx.account;
|
|
347
|
-
var isInbound = to.toLowerCase() === address.toLowerCase();
|
|
348
|
-
return {
|
|
349
|
-
from: [from],
|
|
350
|
-
to: [to],
|
|
351
|
-
isInbound: isInbound,
|
|
352
|
-
amount: (0, module_kit_1.newAmount)(amount, 'blockchain'),
|
|
353
|
-
fee: (0, module_kit_1.newAmount)(txData.fee_charged, 'blockchain'),
|
|
354
|
-
network: _this.options.network,
|
|
355
|
-
timestamp: Math.floor(new Date(tx.created_at).getTime() / 1000),
|
|
356
|
-
status: {
|
|
357
|
-
type: tx.transaction_successful ? 'applied' : 'failed',
|
|
358
|
-
hash: tx.transaction_hash,
|
|
359
|
-
block: txData.ledger.toString()
|
|
360
|
-
},
|
|
361
|
-
arbitraryData: txData.memo
|
|
362
|
-
};
|
|
363
|
-
});
|
|
364
|
-
return [2 /*return*/, {
|
|
365
|
-
transactions: transactions,
|
|
366
|
-
cursor: {
|
|
367
|
-
hasNext: ((_e = (_d = data._links) === null || _d === void 0 ? void 0 : _d.next) === null || _e === void 0 ? void 0 : _e.href) !== undefined,
|
|
368
|
-
next: (_j = (_h = (_g = (_f = data._links) === null || _f === void 0 ? void 0 : _f.next) === null || _g === void 0 ? void 0 : _g.href) === null || _h === void 0 ? void 0 : _h.replace(this.options.network.rpcUrl, '')) !== null && _j !== void 0 ? _j : undefined
|
|
369
|
-
}
|
|
370
|
-
}];
|
|
371
|
-
case 2:
|
|
372
|
-
error_5 = _l.sent();
|
|
373
|
-
if (((_k = error_5.response) === null || _k === void 0 ? void 0 : _k.status) === 404) {
|
|
374
|
-
return [2 /*return*/, {
|
|
375
|
-
transactions: [],
|
|
376
|
-
cursor: {
|
|
377
|
-
hasNext: false,
|
|
378
|
-
next: ''
|
|
379
|
-
}
|
|
380
|
-
}];
|
|
313
|
+
else {
|
|
314
|
+
uiAlerts.push({
|
|
315
|
+
type: 'warning',
|
|
316
|
+
title: { value: protocol_1.StellarTransactionType.PAYMENT, type: 'plain' },
|
|
317
|
+
description: {
|
|
318
|
+
value: `${op.amount} ${op.asset.code} will be deducted from the source wallet`,
|
|
319
|
+
type: 'plain'
|
|
381
320
|
}
|
|
382
|
-
|
|
383
|
-
|
|
321
|
+
});
|
|
322
|
+
amount = new bignumber_1.default(0).multipliedBy(1e7).toString();
|
|
384
323
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
fee = new bignumber_1.default(stellar_sdk_1.BASE_FEE).multipliedBy(to.length).dividedBy(1e7);
|
|
405
|
-
}
|
|
406
|
-
if (fee.gte(balanceBn)) {
|
|
407
|
-
return [2 /*return*/, (0, module_kit_1.newAmount)(0, 'blockchain')];
|
|
408
|
-
}
|
|
409
|
-
amountWithoutFees = balanceBn.minus(fee);
|
|
410
|
-
return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees, 'blockchain')];
|
|
411
|
-
case 2:
|
|
412
|
-
error_6 = _a.sent();
|
|
413
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_6);
|
|
414
|
-
case 3: return [2 /*return*/];
|
|
324
|
+
fee = tx.fee;
|
|
325
|
+
to = [op.destination];
|
|
326
|
+
type = protocol_1.StellarTransactionType.PAYMENT;
|
|
327
|
+
isInbound = to[0].toLowerCase() === publicKey.value.toLowerCase();
|
|
328
|
+
}
|
|
329
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.CREATE_ACCOUNT) {
|
|
330
|
+
op = txDetails;
|
|
331
|
+
amount = new bignumber_1.default(op.startingBalance).multipliedBy(1e7).toString();
|
|
332
|
+
to = [op.destination];
|
|
333
|
+
fee = tx.fee;
|
|
334
|
+
isInbound = to[0].toLowerCase() === publicKey.value.toLowerCase();
|
|
335
|
+
type = protocol_1.StellarTransactionType.CREATE_ACCOUNT;
|
|
336
|
+
}
|
|
337
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.CHANGE_TRUST) {
|
|
338
|
+
op = txDetails;
|
|
339
|
+
amount = new bignumber_1.default(0).toString();
|
|
340
|
+
if (op.line instanceof stellar_sdk_1.Asset) {
|
|
341
|
+
const asetType = op.line;
|
|
342
|
+
to = [asetType.getIssuer()];
|
|
415
343
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
StellarProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details, configuration) {
|
|
420
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
421
|
-
return __generator(this, function (_a) {
|
|
422
|
-
return [2 /*return*/, this.feeDefaults];
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
};
|
|
426
|
-
StellarProtocolImpl.prototype.getMetadata = function () {
|
|
427
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
428
|
-
return __generator(this, function (_a) {
|
|
429
|
-
return [2 /*return*/, this.metadata];
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
};
|
|
433
|
-
StellarProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
434
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
435
|
-
return __generator(this, function (_a) {
|
|
436
|
-
return [2 /*return*/, StellarAddress_1.StellarAddress.from(publicKey).asString()];
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
};
|
|
440
|
-
StellarProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, _publicKey) {
|
|
441
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
442
|
-
return __generator(this, function (_a) {
|
|
443
|
-
switch (transaction.type) {
|
|
444
|
-
case 'signed':
|
|
445
|
-
case 'unsigned':
|
|
446
|
-
return [2 /*return*/, this.getDetailsFromEncodedTransaction(transaction.transaction, _publicKey)];
|
|
447
|
-
default:
|
|
448
|
-
(0, coinlib_core_1.assertNever)(transaction);
|
|
449
|
-
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.STELLAR, 'Unsupported transaction type.');
|
|
344
|
+
else if (op.line instanceof stellar_sdk_1.LiquidityPoolAsset) {
|
|
345
|
+
const asetType = op.line;
|
|
346
|
+
to = [asetType.assetA.getIssuer() ?? protocol_1.StellarAssetType.NATIVE, asetType.assetB.getIssuer() ?? protocol_1.StellarAssetType.NATIVE];
|
|
450
347
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
type
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
op = txDetails;
|
|
481
|
-
if (op.asset.code === protocol_1.StellarAssetType.XLM) {
|
|
482
|
-
amount = new bignumber_1.default(op.amount).multipliedBy(1e7).toString();
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
uiAlerts.push({
|
|
486
|
-
type: 'warning',
|
|
487
|
-
title: { value: protocol_1.StellarTransactionType.PAYMENT, type: 'plain' },
|
|
488
|
-
description: {
|
|
489
|
-
value: "".concat(op.amount, " ").concat(op.asset.code, " will be deducted from the source wallet"),
|
|
490
|
-
type: 'plain'
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
amount = new bignumber_1.default(0).multipliedBy(1e7).toString();
|
|
494
|
-
}
|
|
495
|
-
fee = tx.fee;
|
|
496
|
-
to = [op.destination];
|
|
497
|
-
type = protocol_1.StellarTransactionType.PAYMENT;
|
|
498
|
-
isInbound = to[0].toLowerCase() === publicKey.value.toLowerCase();
|
|
499
|
-
}
|
|
500
|
-
else if (txDetails.type === protocol_1.StellarTransactionType.CREATE_ACCOUNT) {
|
|
501
|
-
op = txDetails;
|
|
502
|
-
amount = new bignumber_1.default(op.startingBalance).multipliedBy(1e7).toString();
|
|
503
|
-
to = [op.destination];
|
|
504
|
-
fee = tx.fee;
|
|
505
|
-
isInbound = to[0].toLowerCase() === publicKey.value.toLowerCase();
|
|
506
|
-
type = protocol_1.StellarTransactionType.CREATE_ACCOUNT;
|
|
507
|
-
}
|
|
508
|
-
else if (txDetails.type === protocol_1.StellarTransactionType.CHANGE_TRUST) {
|
|
509
|
-
op = txDetails;
|
|
510
|
-
amount = new bignumber_1.default(0).toString();
|
|
511
|
-
if (op.line instanceof stellar_sdk_1.Asset) {
|
|
512
|
-
asetType = op.line;
|
|
513
|
-
to = [asetType.getIssuer()];
|
|
514
|
-
}
|
|
515
|
-
else if (op.line instanceof stellar_sdk_1.LiquidityPoolAsset) {
|
|
516
|
-
asetType = op.line;
|
|
517
|
-
to = [(_a = asetType.assetA.getIssuer()) !== null && _a !== void 0 ? _a : protocol_1.StellarAssetType.NATIVE, (_b = asetType.assetB.getIssuer()) !== null && _b !== void 0 ? _b : protocol_1.StellarAssetType.NATIVE];
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
to = [tx.source];
|
|
521
|
-
}
|
|
522
|
-
fee = new bignumber_1.default(tx.fee).dividedBy(tx.operations.length).toString();
|
|
523
|
-
isInbound = false;
|
|
524
|
-
type = protocol_1.StellarTransactionType.CHANGE_TRUST;
|
|
525
|
-
}
|
|
526
|
-
else if (txDetails.type === protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION) {
|
|
527
|
-
isInbound = false;
|
|
528
|
-
op = txDetails;
|
|
529
|
-
fee = tx.fee;
|
|
530
|
-
cont = op.func.value();
|
|
531
|
-
amount = new bignumber_1.default(0).toString();
|
|
532
|
-
try {
|
|
533
|
-
Buffer.from(cont.contractAddress().value(), 'hex');
|
|
534
|
-
contractAddress = stellar_sdk_1.StrKey.encodeContract(Buffer.from(cont.contractAddress().value(), 'hex'));
|
|
535
|
-
to = [contractAddress];
|
|
536
|
-
}
|
|
537
|
-
catch (error) {
|
|
538
|
-
to = [tx.source];
|
|
539
|
-
}
|
|
540
|
-
type = protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION;
|
|
541
|
-
displayFromTo = false;
|
|
542
|
-
uiAlerts.push({
|
|
543
|
-
type: 'warning',
|
|
544
|
-
title: { value: protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION, type: 'plain' },
|
|
545
|
-
description: {
|
|
546
|
-
value: "Transaction ".concat(txDetails.type, " type was not decoded. Please understand what you are signing before proceeding."),
|
|
547
|
-
type: 'plain'
|
|
548
|
-
}
|
|
549
|
-
});
|
|
348
|
+
else {
|
|
349
|
+
to = [tx.source];
|
|
350
|
+
}
|
|
351
|
+
fee = new bignumber_1.default(tx.fee).dividedBy(tx.operations.length).toString();
|
|
352
|
+
isInbound = false;
|
|
353
|
+
type = protocol_1.StellarTransactionType.CHANGE_TRUST;
|
|
354
|
+
}
|
|
355
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION) {
|
|
356
|
+
isInbound = false;
|
|
357
|
+
op = txDetails;
|
|
358
|
+
fee = tx.fee;
|
|
359
|
+
const cont = op.func.value();
|
|
360
|
+
amount = new bignumber_1.default(0).toString();
|
|
361
|
+
try {
|
|
362
|
+
Buffer.from(cont.contractAddress().value(), 'hex');
|
|
363
|
+
const contractAddress = stellar_sdk_1.StrKey.encodeContract(Buffer.from(cont.contractAddress().value(), 'hex'));
|
|
364
|
+
to = [contractAddress];
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
to = [tx.source];
|
|
368
|
+
}
|
|
369
|
+
type = protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION;
|
|
370
|
+
displayFromTo = false;
|
|
371
|
+
uiAlerts.push({
|
|
372
|
+
type: 'warning',
|
|
373
|
+
title: { value: protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION, type: 'plain' },
|
|
374
|
+
description: {
|
|
375
|
+
value: `Transaction ${txDetails.type} type was not decoded. Please understand what you are signing before proceeding.`,
|
|
376
|
+
type: 'plain'
|
|
550
377
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.PATH_PAYMENT_RECIEVE) {
|
|
381
|
+
op = txDetails;
|
|
382
|
+
fee = tx.fee;
|
|
383
|
+
const sendAssetIsNative = op.sendAsset.isNative();
|
|
384
|
+
amount = new bignumber_1.default(sendAssetIsNative ? op.sendMax : 0).multipliedBy(1e7).toString();
|
|
385
|
+
to = [txDetails.destination];
|
|
386
|
+
isInbound = false;
|
|
387
|
+
type = protocol_1.StellarTransactionType.PATH_PAYMENT_RECIEVE;
|
|
388
|
+
if (!sendAssetIsNative) {
|
|
389
|
+
uiAlerts.push({
|
|
390
|
+
type: 'warning',
|
|
391
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
392
|
+
description: {
|
|
393
|
+
value: `Maximum of ${op.sendMax} ${op.sendAsset} will be deducted from the source wallet`,
|
|
394
|
+
type: 'plain'
|
|
568
395
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
uiAlerts.push({
|
|
400
|
+
type: 'info',
|
|
401
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
402
|
+
description: {
|
|
403
|
+
value: `${op.destAmount} ${op.destAsset} will added to your wallet`,
|
|
404
|
+
type: 'plain'
|
|
578
405
|
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.PATH_PAYMENT_SEND) {
|
|
410
|
+
op = txDetails;
|
|
411
|
+
fee = tx.fee;
|
|
412
|
+
const sendAssetIsNative = op.sendAsset.isNative();
|
|
413
|
+
amount = new bignumber_1.default(sendAssetIsNative ? op.sendAmount : 0).multipliedBy(1e7).toString();
|
|
414
|
+
to = [txDetails.destination];
|
|
415
|
+
isInbound = false;
|
|
416
|
+
type = protocol_1.StellarTransactionType.PATH_PAYMENT_SEND;
|
|
417
|
+
if (!sendAssetIsNative) {
|
|
418
|
+
uiAlerts.push({
|
|
419
|
+
type: 'warning',
|
|
420
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
421
|
+
description: {
|
|
422
|
+
value: `${op.sendAmount} ${op.sendAsset} will be deducted from the source wallet`,
|
|
423
|
+
type: 'plain'
|
|
597
424
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
uiAlerts.push({
|
|
429
|
+
type: 'info',
|
|
430
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
431
|
+
description: {
|
|
432
|
+
value: `Minimum of ${op.destMin} ${op.destAsset} will added to your wallet`,
|
|
433
|
+
type: 'plain'
|
|
607
434
|
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT) {
|
|
439
|
+
amount = new bignumber_1.default(0).toString();
|
|
440
|
+
op = txDetails;
|
|
441
|
+
fee = tx.fee;
|
|
442
|
+
to = [op.liquidityPoolId];
|
|
443
|
+
uiAlerts.push({
|
|
444
|
+
type: 'warning',
|
|
445
|
+
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT, type: 'plain' },
|
|
446
|
+
description: {
|
|
447
|
+
value: `Transaction is not fully decoded`,
|
|
448
|
+
type: 'plain'
|
|
608
449
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT, type: 'plain' },
|
|
617
|
-
description: {
|
|
618
|
-
value: "Transaction is not fully decoded",
|
|
619
|
-
type: 'plain'
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
uiAlerts.push({
|
|
623
|
-
type: 'warning',
|
|
624
|
-
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT, type: 'plain' },
|
|
625
|
-
description: {
|
|
626
|
-
value: "".concat(op.maxAmountA, " & ").concat(op.maxAmountB, " of two different assets will be deducted from the source wallet"),
|
|
627
|
-
type: 'plain'
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
type = protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT;
|
|
450
|
+
});
|
|
451
|
+
uiAlerts.push({
|
|
452
|
+
type: 'warning',
|
|
453
|
+
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT, type: 'plain' },
|
|
454
|
+
description: {
|
|
455
|
+
value: `${op.maxAmountA} & ${op.maxAmountB} of two different assets will be deducted from the source wallet`,
|
|
456
|
+
type: 'plain'
|
|
631
457
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
type
|
|
458
|
+
});
|
|
459
|
+
type = protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT;
|
|
460
|
+
}
|
|
461
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.LIQUIDITY_POOL_WITHDRAW) {
|
|
462
|
+
amount = new bignumber_1.default(0).toString();
|
|
463
|
+
op = txDetails;
|
|
464
|
+
fee = tx.fee;
|
|
465
|
+
to = [op.liquidityPoolId];
|
|
466
|
+
uiAlerts.push({
|
|
467
|
+
type: 'info',
|
|
468
|
+
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_WITHDRAW, type: 'plain' },
|
|
469
|
+
description: {
|
|
470
|
+
value: `${op.minAmountA} & ${op.minAmountB} of two different assets will be added to your wallet`,
|
|
471
|
+
type: 'plain'
|
|
646
472
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
type = protocol_1.StellarTransactionType.SET_OPTIONS;
|
|
473
|
+
});
|
|
474
|
+
type = protocol_1.StellarTransactionType.LIQUIDITY_POOL_WITHDRAW;
|
|
475
|
+
}
|
|
476
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.SET_OPTIONS) {
|
|
477
|
+
op = txDetails;
|
|
478
|
+
fee = tx.fee;
|
|
479
|
+
const signer = op.signer;
|
|
480
|
+
if ('ed25519PublicKey' in signer && signer.ed25519PublicKey) {
|
|
481
|
+
to = [signer.ed25519PublicKey];
|
|
482
|
+
}
|
|
483
|
+
else if ('ed25519SignedPayload' in signer && signer.ed25519SignedPayload) {
|
|
484
|
+
to = [signer.ed25519SignedPayload];
|
|
485
|
+
}
|
|
486
|
+
else if ('preAuthTx' in signer && signer.preAuthTx) {
|
|
487
|
+
to = [signer.preAuthTx.toString('hex')];
|
|
488
|
+
}
|
|
489
|
+
else if ('sha256Hash' in signer && signer.sha256Hash) {
|
|
490
|
+
to = [signer.sha256Hash.toString('hex')];
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
to = [tx.source];
|
|
494
|
+
}
|
|
495
|
+
const descriptionParts = [
|
|
496
|
+
to[0] && `Signer: ${to[0]}`,
|
|
497
|
+
op.masterWeight !== undefined && `MasterWeight: ${op.masterWeight}`,
|
|
498
|
+
op.lowThreshold !== undefined && `LowThreshold: ${op.lowThreshold}`,
|
|
499
|
+
op.medThreshold !== undefined && `MedThreshold: ${op.medThreshold}`,
|
|
500
|
+
op.highThreshold !== undefined && `HighThreshold: ${op.highThreshold}`
|
|
501
|
+
]
|
|
502
|
+
.filter(Boolean)
|
|
503
|
+
.join('\n');
|
|
504
|
+
uiAlerts.push({
|
|
505
|
+
type: 'info',
|
|
506
|
+
title: { value: protocol_1.StellarTransactionType.SET_OPTIONS, type: 'plain' },
|
|
507
|
+
description: {
|
|
508
|
+
value: `You are setting the following parameters:\n${descriptionParts}`,
|
|
509
|
+
type: 'plain'
|
|
685
510
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
511
|
+
});
|
|
512
|
+
amount = new bignumber_1.default(0).toString();
|
|
513
|
+
type = protocol_1.StellarTransactionType.SET_OPTIONS;
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
to = [tx.source];
|
|
517
|
+
fee = tx.fee;
|
|
518
|
+
amount = new bignumber_1.default(0).toString();
|
|
519
|
+
isInbound = false;
|
|
520
|
+
type = txDetails.type;
|
|
521
|
+
uiAlerts.push({
|
|
522
|
+
type: 'warning',
|
|
523
|
+
title: { value: txDetails.type, type: 'plain' },
|
|
524
|
+
description: {
|
|
525
|
+
value: `Transaction ${txDetails.type} type was not decoded. Please understand what you are signing before proceeding.`,
|
|
526
|
+
type: 'plain'
|
|
701
527
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
});
|
|
723
|
-
});
|
|
724
|
-
};
|
|
725
|
-
StellarProtocolImpl.prototype.getCryptoConfiguration = function () {
|
|
726
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
727
|
-
return __generator(this, function (_a) {
|
|
728
|
-
return [2 /*return*/, this.cryptoConfiguration];
|
|
729
|
-
});
|
|
730
|
-
});
|
|
731
|
-
};
|
|
732
|
-
StellarProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
|
|
733
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
734
|
-
return __generator(this, function (_a) {
|
|
735
|
-
return [2 /*return*/, {
|
|
736
|
-
secretKey: (0, module_kit_1.newSecretKey)(derivative.secretKey, 'hex'),
|
|
737
|
-
publicKey: (0, module_kit_1.newPublicKey)(derivative.publicKey, 'hex')
|
|
738
|
-
}];
|
|
739
|
-
});
|
|
740
|
-
});
|
|
741
|
-
};
|
|
742
|
-
StellarProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
|
|
743
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
744
|
-
var tx;
|
|
745
|
-
return __generator(this, function (_a) {
|
|
746
|
-
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction.transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
747
|
-
tx.sign(stellar_sdk_1.Keypair.fromSecret(stellar_sdk_1.StrKey.encodeEd25519SecretSeed(Buffer.from(secretKey.value, 'hex'))));
|
|
748
|
-
return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({
|
|
749
|
-
transaction: tx.toXDR()
|
|
750
|
-
})];
|
|
751
|
-
});
|
|
752
|
-
});
|
|
753
|
-
};
|
|
754
|
-
StellarProtocolImpl.prototype.getNetwork = function () {
|
|
755
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
756
|
-
return __generator(this, function (_a) {
|
|
757
|
-
return [2 /*return*/, this.options.network];
|
|
528
|
+
});
|
|
529
|
+
displayFromTo = false;
|
|
530
|
+
}
|
|
531
|
+
const memo = tx.memo.type === 'text' || tx.memo.type === 'id'
|
|
532
|
+
? tx.memo.value?.toString()
|
|
533
|
+
: tx.memo.type === 'hash' || tx.memo.type === 'return'
|
|
534
|
+
? tx.memo.value?.toString('hex')
|
|
535
|
+
: undefined;
|
|
536
|
+
transactions.push({
|
|
537
|
+
from: [tx.source],
|
|
538
|
+
to,
|
|
539
|
+
isInbound,
|
|
540
|
+
amount: (0, module_kit_1.newAmount)(amount, 'blockchain'),
|
|
541
|
+
fee: (0, module_kit_1.newAmount)(fee, 'blockchain'),
|
|
542
|
+
network: this.options.network,
|
|
543
|
+
arbitraryData: memo,
|
|
544
|
+
type,
|
|
545
|
+
uiAlerts,
|
|
546
|
+
json: JSON.stringify(tx),
|
|
547
|
+
displayFromTo
|
|
758
548
|
});
|
|
549
|
+
}
|
|
550
|
+
return transactions;
|
|
551
|
+
}
|
|
552
|
+
async getCryptoConfiguration() {
|
|
553
|
+
return this.cryptoConfiguration;
|
|
554
|
+
}
|
|
555
|
+
async getKeyPairFromDerivative(derivative) {
|
|
556
|
+
return {
|
|
557
|
+
secretKey: (0, module_kit_1.newSecretKey)(derivative.secretKey, 'hex'),
|
|
558
|
+
publicKey: (0, module_kit_1.newPublicKey)(derivative.publicKey, 'hex')
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
async signTransactionWithSecretKey(transaction, secretKey) {
|
|
562
|
+
const tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction.transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
563
|
+
tx.sign(stellar_sdk_1.Keypair.fromSecret(stellar_sdk_1.StrKey.encodeEd25519SecretSeed(Buffer.from(secretKey.value, 'hex'))));
|
|
564
|
+
return (0, module_kit_1.newSignedTransaction)({
|
|
565
|
+
transaction: tx.toXDR()
|
|
759
566
|
});
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
return
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
567
|
+
}
|
|
568
|
+
async getNetwork() {
|
|
569
|
+
return this.options.network;
|
|
570
|
+
}
|
|
571
|
+
async getBalanceOfPublicKey(publicKey) {
|
|
572
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
573
|
+
return this.getBalanceOfAddress(address);
|
|
574
|
+
}
|
|
575
|
+
async getBalanceOfAddress(address) {
|
|
576
|
+
try {
|
|
577
|
+
const { data } = await index_1.default.get(`${this.options.network.rpcUrl}/accounts/${address}`);
|
|
578
|
+
const balance = data.balances.find((b) => b.asset_type === protocol_1.StellarAssetType.NATIVE);
|
|
579
|
+
const btnBalance = new bignumber_1.default(balance.balance).multipliedBy(1e7).toString();
|
|
580
|
+
return {
|
|
581
|
+
total: (0, module_kit_1.newAmount)(btnBalance, 'blockchain')
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
catch (error) {
|
|
585
|
+
return { total: (0, module_kit_1.newAmount)('0', 'blockchain') };
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
async prepareTransactionWithPublicKey(publicKey, details, configuration) {
|
|
589
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
590
|
+
const account = await this.server.loadAccount(address);
|
|
591
|
+
const fee = configuration?.fee !== undefined ? configuration?.fee?.value : stellar_sdk_1.BASE_FEE;
|
|
592
|
+
const txBuilder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
593
|
+
fee,
|
|
594
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
772
595
|
});
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/accounts/").concat(address))];
|
|
782
|
-
case 1:
|
|
783
|
-
data = (_a.sent()).data;
|
|
784
|
-
balance = data.balances.find(function (b) { return b.asset_type === protocol_1.StellarAssetType.NATIVE; });
|
|
785
|
-
btnBalance = new bignumber_1.default(balance.balance).multipliedBy(1e7).toString();
|
|
786
|
-
return [2 /*return*/, {
|
|
787
|
-
total: (0, module_kit_1.newAmount)(btnBalance, 'blockchain')
|
|
788
|
-
}];
|
|
789
|
-
case 2:
|
|
790
|
-
error_7 = _a.sent();
|
|
791
|
-
return [2 /*return*/, { total: (0, module_kit_1.newAmount)('0', 'blockchain') }];
|
|
792
|
-
case 3: return [2 /*return*/];
|
|
596
|
+
for (const detail of details) {
|
|
597
|
+
let destinationExists = true;
|
|
598
|
+
try {
|
|
599
|
+
await this.server.loadAccount(detail.to);
|
|
600
|
+
}
|
|
601
|
+
catch (e) {
|
|
602
|
+
if (e.response?.status === 404) {
|
|
603
|
+
destinationExists = false;
|
|
793
604
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
};
|
|
797
|
-
StellarProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
|
|
798
|
-
var _a, _b;
|
|
799
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
800
|
-
var address, account, fee, txBuilder, _i, details_1, detail, destinationExists, e_1, amount, memo, tx;
|
|
801
|
-
return __generator(this, function (_c) {
|
|
802
|
-
switch (_c.label) {
|
|
803
|
-
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
804
|
-
case 1:
|
|
805
|
-
address = _c.sent();
|
|
806
|
-
return [4 /*yield*/, this.server.loadAccount(address)];
|
|
807
|
-
case 2:
|
|
808
|
-
account = _c.sent();
|
|
809
|
-
fee = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined ? (_a = configuration === null || configuration === void 0 ? void 0 : configuration.fee) === null || _a === void 0 ? void 0 : _a.value : stellar_sdk_1.BASE_FEE;
|
|
810
|
-
txBuilder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
811
|
-
fee: fee,
|
|
812
|
-
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
813
|
-
});
|
|
814
|
-
_i = 0, details_1 = details;
|
|
815
|
-
_c.label = 3;
|
|
816
|
-
case 3:
|
|
817
|
-
if (!(_i < details_1.length)) return [3 /*break*/, 9];
|
|
818
|
-
detail = details_1[_i];
|
|
819
|
-
destinationExists = true;
|
|
820
|
-
_c.label = 4;
|
|
821
|
-
case 4:
|
|
822
|
-
_c.trys.push([4, 6, , 7]);
|
|
823
|
-
return [4 /*yield*/, this.server.loadAccount(detail.to)];
|
|
824
|
-
case 5:
|
|
825
|
-
_c.sent();
|
|
826
|
-
return [3 /*break*/, 7];
|
|
827
|
-
case 6:
|
|
828
|
-
e_1 = _c.sent();
|
|
829
|
-
if (((_b = e_1.response) === null || _b === void 0 ? void 0 : _b.status) === 404) {
|
|
830
|
-
destinationExists = false;
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
833
|
-
throw e_1;
|
|
834
|
-
}
|
|
835
|
-
return [3 /*break*/, 7];
|
|
836
|
-
case 7:
|
|
837
|
-
amount = new bignumber_1.default(detail.amount.value).dividedBy(1e7).toString();
|
|
838
|
-
if (destinationExists) {
|
|
839
|
-
txBuilder.addOperation(stellar_sdk_1.Operation.payment({
|
|
840
|
-
destination: detail.to,
|
|
841
|
-
asset: stellar_sdk_1.Asset.native(),
|
|
842
|
-
amount: amount
|
|
843
|
-
}));
|
|
844
|
-
}
|
|
845
|
-
else {
|
|
846
|
-
txBuilder.addOperation(stellar_sdk_1.Operation.createAccount({
|
|
847
|
-
destination: detail.to,
|
|
848
|
-
startingBalance: amount
|
|
849
|
-
}));
|
|
850
|
-
}
|
|
851
|
-
_c.label = 8;
|
|
852
|
-
case 8:
|
|
853
|
-
_i++;
|
|
854
|
-
return [3 /*break*/, 3];
|
|
855
|
-
case 9:
|
|
856
|
-
if (configuration === null || configuration === void 0 ? void 0 : configuration.arbitraryData) {
|
|
857
|
-
memo = configuration === null || configuration === void 0 ? void 0 : configuration.arbitraryData;
|
|
858
|
-
txBuilder.addMemo(stellar_sdk_1.Memo.id(memo));
|
|
859
|
-
}
|
|
860
|
-
tx = txBuilder.setTimeout(600).build();
|
|
861
|
-
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
862
|
-
transaction: tx.toXDR()
|
|
863
|
-
})];
|
|
605
|
+
else {
|
|
606
|
+
throw e;
|
|
864
607
|
}
|
|
865
|
-
}
|
|
608
|
+
}
|
|
609
|
+
const amount = new bignumber_1.default(detail.amount.value).dividedBy(1e7).toString();
|
|
610
|
+
if (destinationExists) {
|
|
611
|
+
txBuilder.addOperation(stellar_sdk_1.Operation.payment({
|
|
612
|
+
destination: detail.to,
|
|
613
|
+
asset: stellar_sdk_1.Asset.native(),
|
|
614
|
+
amount
|
|
615
|
+
}));
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
txBuilder.addOperation(stellar_sdk_1.Operation.createAccount({
|
|
619
|
+
destination: detail.to,
|
|
620
|
+
startingBalance: amount
|
|
621
|
+
}));
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (configuration?.arbitraryData) {
|
|
625
|
+
const memo = configuration?.arbitraryData;
|
|
626
|
+
txBuilder.addMemo(stellar_sdk_1.Memo.id(memo));
|
|
627
|
+
}
|
|
628
|
+
const tx = txBuilder.setTimeout(600).build();
|
|
629
|
+
return (0, module_kit_1.newUnsignedTransaction)({
|
|
630
|
+
transaction: tx.toXDR()
|
|
866
631
|
});
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
params.append('tx', transaction.transaction);
|
|
876
|
-
return [4 /*yield*/, index_1.default.post("".concat(this.options.network.rpcUrl, "/transactions"), params.toString(), {
|
|
877
|
-
headers: {
|
|
878
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
879
|
-
}
|
|
880
|
-
})];
|
|
881
|
-
case 1:
|
|
882
|
-
data = (_a.sent()).data;
|
|
883
|
-
return [2 /*return*/, data.hash];
|
|
884
|
-
}
|
|
885
|
-
});
|
|
632
|
+
}
|
|
633
|
+
async broadcastTransaction(transaction) {
|
|
634
|
+
const params = new URLSearchParams();
|
|
635
|
+
params.append('tx', transaction.transaction);
|
|
636
|
+
const { data } = await index_1.default.post(`${this.options.network.rpcUrl}/transactions`, params.toString(), {
|
|
637
|
+
headers: {
|
|
638
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
639
|
+
}
|
|
886
640
|
});
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
641
|
+
return data.hash;
|
|
642
|
+
}
|
|
643
|
+
async getWalletConnectChain() {
|
|
644
|
+
const chain = this.options.network.type === 'mainnet' ? 'pubnet' : 'testnet';
|
|
645
|
+
return `stellar:${chain}`;
|
|
646
|
+
}
|
|
647
|
+
async prepareWalletConnectTransactionWithPublicKey(publicKey, request) {
|
|
648
|
+
const sourceAddress = await this.getAddressFromPublicKey(publicKey);
|
|
649
|
+
const sourceAccount = await this.server.loadAccount(sourceAddress);
|
|
650
|
+
const destination = request.to ?? '';
|
|
651
|
+
const value = request.value ?? '0';
|
|
652
|
+
const amount = new bignumber_1.default(value).dividedBy(1e7).toString(); // convert from stroops to XLM
|
|
653
|
+
const fee = stellar_sdk_1.BASE_FEE;
|
|
654
|
+
const txBuilder = new stellar_sdk_1.TransactionBuilder(sourceAccount, {
|
|
655
|
+
fee,
|
|
656
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
895
657
|
});
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
case 2:
|
|
908
|
-
sourceAccount = _c.sent();
|
|
909
|
-
destination = (_a = request.to) !== null && _a !== void 0 ? _a : '';
|
|
910
|
-
value = (_b = request.value) !== null && _b !== void 0 ? _b : '0';
|
|
911
|
-
amount = new bignumber_1.default(value).dividedBy(1e7).toString() // convert from stroops to XLM
|
|
912
|
-
;
|
|
913
|
-
fee = stellar_sdk_1.BASE_FEE;
|
|
914
|
-
txBuilder = new stellar_sdk_1.TransactionBuilder(sourceAccount, {
|
|
915
|
-
fee: fee,
|
|
916
|
-
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
917
|
-
});
|
|
918
|
-
txBuilder.addOperation(stellar_sdk_1.Operation.payment({
|
|
919
|
-
destination: destination,
|
|
920
|
-
asset: stellar_sdk_1.Asset.native(),
|
|
921
|
-
amount: amount
|
|
922
|
-
}));
|
|
923
|
-
if (request.data) {
|
|
924
|
-
txBuilder.addMemo(stellar_sdk_1.Memo.id(request.data.toString()));
|
|
925
|
-
}
|
|
926
|
-
tx = txBuilder.setTimeout(600).build();
|
|
927
|
-
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
928
|
-
transaction: tx.toXDR()
|
|
929
|
-
})];
|
|
930
|
-
}
|
|
931
|
-
});
|
|
658
|
+
txBuilder.addOperation(stellar_sdk_1.Operation.payment({
|
|
659
|
+
destination,
|
|
660
|
+
asset: stellar_sdk_1.Asset.native(),
|
|
661
|
+
amount
|
|
662
|
+
}));
|
|
663
|
+
if (request.data) {
|
|
664
|
+
txBuilder.addMemo(stellar_sdk_1.Memo.id(request.data.toString()));
|
|
665
|
+
}
|
|
666
|
+
const tx = txBuilder.setTimeout(600).build();
|
|
667
|
+
return (0, module_kit_1.newUnsignedTransaction)({
|
|
668
|
+
transaction: tx.toXDR()
|
|
932
669
|
});
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
}());
|
|
670
|
+
}
|
|
671
|
+
}
|
|
936
672
|
exports.StellarProtocolImpl = StellarProtocolImpl;
|
|
937
|
-
function createStellarProtocol(options) {
|
|
938
|
-
if (options === void 0) { options = {}; }
|
|
673
|
+
function createStellarProtocol(options = {}) {
|
|
939
674
|
return new StellarProtocolImpl(options);
|
|
940
675
|
}
|
|
941
|
-
exports.createStellarProtocol = createStellarProtocol;
|
|
942
676
|
exports.STELLAR_MAINNET_PROTOCOL_NETWORK = {
|
|
943
677
|
name: 'Mainnet',
|
|
944
678
|
type: 'mainnet',
|
|
945
679
|
rpcUrl: 'https://horizon.stellar.org',
|
|
946
680
|
blockExplorerUrl: 'https://stellar.expert/explorer/public'
|
|
947
681
|
};
|
|
948
|
-
|
|
949
|
-
function createStellarProtocolOptions(network) {
|
|
950
|
-
if (network === void 0) { network = {}; }
|
|
682
|
+
const DEFAULT_STELLAR_PROTOCOL_NETWORK = exports.STELLAR_MAINNET_PROTOCOL_NETWORK;
|
|
683
|
+
function createStellarProtocolOptions(network = {}) {
|
|
951
684
|
return {
|
|
952
|
-
network:
|
|
685
|
+
network: { ...DEFAULT_STELLAR_PROTOCOL_NETWORK, ...network }
|
|
953
686
|
};
|
|
954
687
|
}
|
|
955
|
-
exports.createStellarProtocolOptions = createStellarProtocolOptions;
|
|
956
688
|
//# sourceMappingURL=StellarProtocol.js.map
|