@stellar/stellar-base 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +1262 -0
  2. package/LICENSE +202 -0
  3. package/README.md +198 -0
  4. package/dist/stellar-base.js +30777 -0
  5. package/dist/stellar-base.min.js +2 -0
  6. package/lib/account.js +80 -0
  7. package/lib/address.js +169 -0
  8. package/lib/asset.js +323 -0
  9. package/lib/auth.js +253 -0
  10. package/lib/claimant.js +193 -0
  11. package/lib/contract.js +113 -0
  12. package/lib/events.js +42 -0
  13. package/lib/fee_bump_transaction.js +134 -0
  14. package/lib/generated/curr_generated.js +8315 -0
  15. package/lib/generated/next_generated.js +8315 -0
  16. package/lib/get_liquidity_pool_id.js +57 -0
  17. package/lib/hashing.js +12 -0
  18. package/lib/index.js +385 -0
  19. package/lib/invocation.js +195 -0
  20. package/lib/keypair.js +308 -0
  21. package/lib/liquidity_pool_asset.js +126 -0
  22. package/lib/liquidity_pool_id.js +101 -0
  23. package/lib/memo.js +270 -0
  24. package/lib/muxed_account.js +159 -0
  25. package/lib/network.js +22 -0
  26. package/lib/numbers/index.js +85 -0
  27. package/lib/numbers/int128.js +50 -0
  28. package/lib/numbers/int256.js +50 -0
  29. package/lib/numbers/sc_int.js +134 -0
  30. package/lib/numbers/uint128.js +50 -0
  31. package/lib/numbers/uint256.js +50 -0
  32. package/lib/numbers/xdr_large_int.js +267 -0
  33. package/lib/operation.js +715 -0
  34. package/lib/operations/account_merge.js +32 -0
  35. package/lib/operations/allow_trust.js +57 -0
  36. package/lib/operations/begin_sponsoring_future_reserves.js +38 -0
  37. package/lib/operations/bump_sequence.js +37 -0
  38. package/lib/operations/change_trust.js +52 -0
  39. package/lib/operations/claim_claimable_balance.js +40 -0
  40. package/lib/operations/clawback.js +46 -0
  41. package/lib/operations/clawback_claimable_balance.js +39 -0
  42. package/lib/operations/create_account.js +37 -0
  43. package/lib/operations/create_claimable_balance.js +65 -0
  44. package/lib/operations/create_passive_sell_offer.js +44 -0
  45. package/lib/operations/end_sponsoring_future_reserves.js +27 -0
  46. package/lib/operations/extend_footprint_ttl.js +45 -0
  47. package/lib/operations/index.js +254 -0
  48. package/lib/operations/inflation.js +23 -0
  49. package/lib/operations/invoke_host_function.js +219 -0
  50. package/lib/operations/liquidity_pool_deposit.js +64 -0
  51. package/lib/operations/liquidity_pool_withdraw.js +50 -0
  52. package/lib/operations/manage_buy_offer.js +50 -0
  53. package/lib/operations/manage_data.js +41 -0
  54. package/lib/operations/manage_sell_offer.js +50 -0
  55. package/lib/operations/path_payment_strict_receive.js +68 -0
  56. package/lib/operations/path_payment_strict_send.js +68 -0
  57. package/lib/operations/payment.js +47 -0
  58. package/lib/operations/restore_footprint.js +38 -0
  59. package/lib/operations/revoke_sponsorship.js +301 -0
  60. package/lib/operations/set_options.js +135 -0
  61. package/lib/operations/set_trustline_flags.js +84 -0
  62. package/lib/scval.js +369 -0
  63. package/lib/signerkey.js +103 -0
  64. package/lib/signing.js +96 -0
  65. package/lib/soroban.js +96 -0
  66. package/lib/sorobandata_builder.js +218 -0
  67. package/lib/strkey.js +400 -0
  68. package/lib/transaction.js +369 -0
  69. package/lib/transaction_base.js +248 -0
  70. package/lib/transaction_builder.js +753 -0
  71. package/lib/util/checksum.js +20 -0
  72. package/lib/util/continued_fraction.js +58 -0
  73. package/lib/util/decode_encode_muxed_account.js +116 -0
  74. package/lib/util/util.js +14 -0
  75. package/lib/xdr.js +9 -0
  76. package/package.json +133 -0
  77. package/types/curr.d.ts +14078 -0
  78. package/types/index.d.ts +1270 -0
  79. package/types/next.d.ts +14078 -0
  80. package/types/xdr.d.ts +1 -0
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "accountMerge", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _account_merge.accountMerge;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "allowTrust", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _allow_trust.allowTrust;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "beginSponsoringFutureReserves", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _begin_sponsoring_future_reserves.beginSponsoringFutureReserves;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "bumpSequence", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _bump_sequence.bumpSequence;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "changeTrust", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _change_trust.changeTrust;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "claimClaimableBalance", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _claim_claimable_balance.claimClaimableBalance;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "clawback", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _clawback.clawback;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "clawbackClaimableBalance", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _clawback_claimable_balance.clawbackClaimableBalance;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "createAccount", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _create_account.createAccount;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "createClaimableBalance", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return _create_claimable_balance.createClaimableBalance;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "createCustomContract", {
67
+ enumerable: true,
68
+ get: function get() {
69
+ return _invoke_host_function.createCustomContract;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "createPassiveSellOffer", {
73
+ enumerable: true,
74
+ get: function get() {
75
+ return _create_passive_sell_offer.createPassiveSellOffer;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "createStellarAssetContract", {
79
+ enumerable: true,
80
+ get: function get() {
81
+ return _invoke_host_function.createStellarAssetContract;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "endSponsoringFutureReserves", {
85
+ enumerable: true,
86
+ get: function get() {
87
+ return _end_sponsoring_future_reserves.endSponsoringFutureReserves;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "extendFootprintTtl", {
91
+ enumerable: true,
92
+ get: function get() {
93
+ return _extend_footprint_ttl.extendFootprintTtl;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "inflation", {
97
+ enumerable: true,
98
+ get: function get() {
99
+ return _inflation.inflation;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "invokeContractFunction", {
103
+ enumerable: true,
104
+ get: function get() {
105
+ return _invoke_host_function.invokeContractFunction;
106
+ }
107
+ });
108
+ Object.defineProperty(exports, "invokeHostFunction", {
109
+ enumerable: true,
110
+ get: function get() {
111
+ return _invoke_host_function.invokeHostFunction;
112
+ }
113
+ });
114
+ Object.defineProperty(exports, "liquidityPoolDeposit", {
115
+ enumerable: true,
116
+ get: function get() {
117
+ return _liquidity_pool_deposit.liquidityPoolDeposit;
118
+ }
119
+ });
120
+ Object.defineProperty(exports, "liquidityPoolWithdraw", {
121
+ enumerable: true,
122
+ get: function get() {
123
+ return _liquidity_pool_withdraw.liquidityPoolWithdraw;
124
+ }
125
+ });
126
+ Object.defineProperty(exports, "manageBuyOffer", {
127
+ enumerable: true,
128
+ get: function get() {
129
+ return _manage_buy_offer.manageBuyOffer;
130
+ }
131
+ });
132
+ Object.defineProperty(exports, "manageData", {
133
+ enumerable: true,
134
+ get: function get() {
135
+ return _manage_data.manageData;
136
+ }
137
+ });
138
+ Object.defineProperty(exports, "manageSellOffer", {
139
+ enumerable: true,
140
+ get: function get() {
141
+ return _manage_sell_offer.manageSellOffer;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "pathPaymentStrictReceive", {
145
+ enumerable: true,
146
+ get: function get() {
147
+ return _path_payment_strict_receive.pathPaymentStrictReceive;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, "pathPaymentStrictSend", {
151
+ enumerable: true,
152
+ get: function get() {
153
+ return _path_payment_strict_send.pathPaymentStrictSend;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "payment", {
157
+ enumerable: true,
158
+ get: function get() {
159
+ return _payment.payment;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, "restoreFootprint", {
163
+ enumerable: true,
164
+ get: function get() {
165
+ return _restore_footprint.restoreFootprint;
166
+ }
167
+ });
168
+ Object.defineProperty(exports, "revokeAccountSponsorship", {
169
+ enumerable: true,
170
+ get: function get() {
171
+ return _revoke_sponsorship.revokeAccountSponsorship;
172
+ }
173
+ });
174
+ Object.defineProperty(exports, "revokeClaimableBalanceSponsorship", {
175
+ enumerable: true,
176
+ get: function get() {
177
+ return _revoke_sponsorship.revokeClaimableBalanceSponsorship;
178
+ }
179
+ });
180
+ Object.defineProperty(exports, "revokeDataSponsorship", {
181
+ enumerable: true,
182
+ get: function get() {
183
+ return _revoke_sponsorship.revokeDataSponsorship;
184
+ }
185
+ });
186
+ Object.defineProperty(exports, "revokeLiquidityPoolSponsorship", {
187
+ enumerable: true,
188
+ get: function get() {
189
+ return _revoke_sponsorship.revokeLiquidityPoolSponsorship;
190
+ }
191
+ });
192
+ Object.defineProperty(exports, "revokeOfferSponsorship", {
193
+ enumerable: true,
194
+ get: function get() {
195
+ return _revoke_sponsorship.revokeOfferSponsorship;
196
+ }
197
+ });
198
+ Object.defineProperty(exports, "revokeSignerSponsorship", {
199
+ enumerable: true,
200
+ get: function get() {
201
+ return _revoke_sponsorship.revokeSignerSponsorship;
202
+ }
203
+ });
204
+ Object.defineProperty(exports, "revokeTrustlineSponsorship", {
205
+ enumerable: true,
206
+ get: function get() {
207
+ return _revoke_sponsorship.revokeTrustlineSponsorship;
208
+ }
209
+ });
210
+ Object.defineProperty(exports, "setOptions", {
211
+ enumerable: true,
212
+ get: function get() {
213
+ return _set_options.setOptions;
214
+ }
215
+ });
216
+ Object.defineProperty(exports, "setTrustLineFlags", {
217
+ enumerable: true,
218
+ get: function get() {
219
+ return _set_trustline_flags.setTrustLineFlags;
220
+ }
221
+ });
222
+ Object.defineProperty(exports, "uploadContractWasm", {
223
+ enumerable: true,
224
+ get: function get() {
225
+ return _invoke_host_function.uploadContractWasm;
226
+ }
227
+ });
228
+ var _manage_sell_offer = require("./manage_sell_offer");
229
+ var _create_passive_sell_offer = require("./create_passive_sell_offer");
230
+ var _account_merge = require("./account_merge");
231
+ var _allow_trust = require("./allow_trust");
232
+ var _bump_sequence = require("./bump_sequence");
233
+ var _change_trust = require("./change_trust");
234
+ var _create_account = require("./create_account");
235
+ var _create_claimable_balance = require("./create_claimable_balance");
236
+ var _claim_claimable_balance = require("./claim_claimable_balance");
237
+ var _clawback_claimable_balance = require("./clawback_claimable_balance");
238
+ var _inflation = require("./inflation");
239
+ var _manage_data = require("./manage_data");
240
+ var _manage_buy_offer = require("./manage_buy_offer");
241
+ var _path_payment_strict_receive = require("./path_payment_strict_receive");
242
+ var _path_payment_strict_send = require("./path_payment_strict_send");
243
+ var _payment = require("./payment");
244
+ var _set_options = require("./set_options");
245
+ var _begin_sponsoring_future_reserves = require("./begin_sponsoring_future_reserves");
246
+ var _end_sponsoring_future_reserves = require("./end_sponsoring_future_reserves");
247
+ var _revoke_sponsorship = require("./revoke_sponsorship");
248
+ var _clawback = require("./clawback");
249
+ var _set_trustline_flags = require("./set_trustline_flags");
250
+ var _liquidity_pool_deposit = require("./liquidity_pool_deposit");
251
+ var _liquidity_pool_withdraw = require("./liquidity_pool_withdraw");
252
+ var _invoke_host_function = require("./invoke_host_function");
253
+ var _extend_footprint_ttl = require("./extend_footprint_ttl");
254
+ var _restore_footprint = require("./restore_footprint");
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.inflation = inflation;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * This operation generates the inflation.
11
+ * @function
12
+ * @alias Operation.inflation
13
+ * @param {object} [opts] Options object
14
+ * @param {string} [opts.source] - The optional source account.
15
+ * @returns {xdr.InflationOp} Inflation operation
16
+ */
17
+ function inflation() {
18
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ var opAttributes = {};
20
+ opAttributes.body = _xdr["default"].OperationBody.inflation();
21
+ this.setSourceAccount(opAttributes, opts);
22
+ return new _xdr["default"].Operation(opAttributes);
23
+ }
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createCustomContract = createCustomContract;
7
+ exports.createStellarAssetContract = createStellarAssetContract;
8
+ exports.invokeContractFunction = invokeContractFunction;
9
+ exports.invokeHostFunction = invokeHostFunction;
10
+ exports.uploadContractWasm = uploadContractWasm;
11
+ var _xdr = _interopRequireDefault(require("../xdr"));
12
+ var _keypair = require("../keypair");
13
+ var _address = require("../address");
14
+ var _asset = require("../asset");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
19
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
20
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
21
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
+ /**
23
+ * Invokes a single smart contract host function.
24
+ *
25
+ * @function
26
+ * @alias Operation.invokeHostFunction
27
+ *
28
+ * @param {object} opts - options object
29
+ * @param {xdr.HostFunction} opts.func - host function to execute (with its
30
+ * wrapped parameters)
31
+ * @param {xdr.SorobanAuthorizationEntry[]} [opts.auth] - list outlining the
32
+ * tree of authorizations required for the call
33
+ * @param {string} [opts.source] - an optional source account
34
+ *
35
+ * @returns {xdr.Operation} an Invoke Host Function operation
36
+ * (xdr.InvokeHostFunctionOp)
37
+ *
38
+ * @see https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#function
39
+ * @see Operation.invokeContractFunction
40
+ * @see Operation.createCustomContract
41
+ * @see Operation.createStellarAssetContract
42
+ * @see Operation.uploadContractWasm
43
+ * @see Contract.call
44
+ */
45
+ function invokeHostFunction(opts) {
46
+ if (!opts.func) {
47
+ throw new TypeError("host function invocation ('func') required (got ".concat(JSON.stringify(opts), ")"));
48
+ }
49
+ var invokeHostFunctionOp = new _xdr["default"].InvokeHostFunctionOp({
50
+ hostFunction: opts.func,
51
+ auth: opts.auth || []
52
+ });
53
+ var opAttributes = {
54
+ body: _xdr["default"].OperationBody.invokeHostFunction(invokeHostFunctionOp)
55
+ };
56
+ this.setSourceAccount(opAttributes, opts);
57
+ return new _xdr["default"].Operation(opAttributes);
58
+ }
59
+
60
+ /**
61
+ * Returns an operation that invokes a contract function.
62
+ *
63
+ * @function
64
+ * @alias Operation.invokeContractFunction
65
+ *
66
+ * @param {any} opts - the set of parameters
67
+ * @param {string} opts.contract - a strkey-fied contract address (`C...`)
68
+ * @param {string} opts.function - the name of the contract fn to invoke
69
+ * @param {xdr.ScVal[]} opts.args - parameters to pass to the function
70
+ * invocation (try {@link nativeToScVal} or {@link ScInt} to make building
71
+ * these easier)
72
+ * @param {xdr.SorobanAuthorizationEntry[]} [opts.auth] - an optional list
73
+ * outlining the tree of authorizations required for the call
74
+ * @param {string} [opts.source] - an optional source account
75
+ *
76
+ * @returns {xdr.Operation} an Invoke Host Function operation
77
+ * (xdr.InvokeHostFunctionOp)
78
+ *
79
+ * @see Operation.invokeHostFunction
80
+ * @see Contract.call
81
+ * @see Address
82
+ */
83
+ function invokeContractFunction(opts) {
84
+ var c = new _address.Address(opts.contract);
85
+ if (c._type !== 'contract') {
86
+ throw new TypeError("expected contract strkey instance, got ".concat(c));
87
+ }
88
+ return this.invokeHostFunction({
89
+ source: opts.source,
90
+ auth: opts.auth,
91
+ func: _xdr["default"].HostFunction.hostFunctionTypeInvokeContract(new _xdr["default"].InvokeContractArgs({
92
+ contractAddress: c.toScAddress(),
93
+ functionName: opts["function"],
94
+ args: opts.args
95
+ }))
96
+ });
97
+ }
98
+
99
+ /**
100
+ * Returns an operation that creates a custom WASM contract.
101
+ *
102
+ * @function
103
+ * @alias Operation.createCustomContract
104
+ *
105
+ * @param {any} opts - the set of parameters
106
+ * @param {Address} opts.address - the contract uploader address
107
+ * @param {Uint8Array|Buffer} opts.wasmHash - the SHA-256 hash of the contract
108
+ * WASM you're uploading (see {@link hash} and
109
+ * {@link Operation.uploadContractWasm})
110
+ * @param {Uint8Array|Buffer} [opts.salt] - an optional, 32-byte salt to
111
+ * distinguish deployment instances of the same wasm from the same user (if
112
+ * omitted, one will be generated for you)
113
+ * @param {xdr.SorobanAuthorizationEntry[]} [opts.auth] - an optional list
114
+ * outlining the tree of authorizations required for the call
115
+ * @param {string} [opts.source] - an optional source account
116
+ *
117
+ * @returns {xdr.Operation} an Invoke Host Function operation
118
+ * (xdr.InvokeHostFunctionOp)
119
+ *
120
+ * @see
121
+ * https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#function
122
+ */
123
+ function createCustomContract(opts) {
124
+ var salt = Buffer.from(opts.salt || getSalty());
125
+ if (!opts.wasmHash || opts.wasmHash.length !== 32) {
126
+ throw new TypeError("expected hash(contract WASM) in 'opts.wasmHash', got ".concat(opts.wasmHash));
127
+ }
128
+ if (salt.length !== 32) {
129
+ throw new TypeError("expected 32-byte salt in 'opts.salt', got ".concat(opts.wasmHash));
130
+ }
131
+ return this.invokeHostFunction({
132
+ source: opts.source,
133
+ auth: opts.auth,
134
+ func: _xdr["default"].HostFunction.hostFunctionTypeCreateContract(new _xdr["default"].CreateContractArgs({
135
+ executable: _xdr["default"].ContractExecutable.contractExecutableWasm(Buffer.from(opts.wasmHash)),
136
+ contractIdPreimage: _xdr["default"].ContractIdPreimage.contractIdPreimageFromAddress(new _xdr["default"].ContractIdPreimageFromAddress({
137
+ address: opts.address.toScAddress(),
138
+ salt: salt
139
+ }))
140
+ }))
141
+ });
142
+ }
143
+
144
+ /**
145
+ * Returns an operation that wraps a Stellar asset into a token contract.
146
+ *
147
+ * @function
148
+ * @alias Operation.createStellarAssetContract
149
+ *
150
+ * @param {any} opts - the set of parameters
151
+ * @param {Asset|string} opts.asset - the Stellar asset to wrap, either as an
152
+ * {@link Asset} object or in canonical form (SEP-11, `code:issuer`)
153
+ * @param {xdr.SorobanAuthorizationEntry[]} [opts.auth] - an optional list
154
+ * outlining the tree of authorizations required for the call
155
+ * @param {string} [opts.source] - an optional source account
156
+ *
157
+ * @returns {xdr.Operation} an Invoke Host Function operation
158
+ * (xdr.InvokeHostFunctionOp)
159
+ *
160
+ * @see https://stellar.org/protocol/sep-11#alphanum4-alphanum12
161
+ * @see
162
+ * https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions
163
+ * @see
164
+ * https://soroban.stellar.org/docs/advanced-tutorials/stellar-asset-contract
165
+ * @see Operation.invokeHostFunction
166
+ */
167
+ function createStellarAssetContract(opts) {
168
+ var asset = opts.asset;
169
+ if (typeof asset === 'string') {
170
+ var _asset$split = asset.split(':'),
171
+ _asset$split2 = _slicedToArray(_asset$split, 2),
172
+ code = _asset$split2[0],
173
+ issuer = _asset$split2[1];
174
+ asset = new _asset.Asset(code, issuer); // handles 'xlm' by default
175
+ }
176
+ if (!(asset instanceof _asset.Asset)) {
177
+ throw new TypeError("expected Asset in 'opts.asset', got ".concat(asset));
178
+ }
179
+ return this.invokeHostFunction({
180
+ source: opts.source,
181
+ auth: opts.auth,
182
+ func: _xdr["default"].HostFunction.hostFunctionTypeCreateContract(new _xdr["default"].CreateContractArgs({
183
+ executable: _xdr["default"].ContractExecutable.contractExecutableStellarAsset(),
184
+ contractIdPreimage: _xdr["default"].ContractIdPreimage.contractIdPreimageFromAsset(asset.toXDRObject())
185
+ }))
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Returns an operation that uploads WASM for a contract.
191
+ *
192
+ * @function
193
+ * @alias Operation.uploadContractWasm
194
+ *
195
+ * @param {any} opts - the set of parameters
196
+ * @param {Uint8Array|Buffer} opts.wasm - a WASM blob to upload to the ledger
197
+ * @param {xdr.SorobanAuthorizationEntry[]} [opts.auth] - an optional list
198
+ * outlining the tree of authorizations required for the call
199
+ * @param {string} [opts.source] - an optional source account
200
+ *
201
+ * @returns {xdr.Operation} an Invoke Host Function operation
202
+ * (xdr.InvokeHostFunctionOp)
203
+ *
204
+ * @see
205
+ * https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#function
206
+ */
207
+ function uploadContractWasm(opts) {
208
+ return this.invokeHostFunction({
209
+ source: opts.source,
210
+ auth: opts.auth,
211
+ func: _xdr["default"].HostFunction.hostFunctionTypeUploadContractWasm(Buffer.from(opts.wasm) // coalesce so we can drop `Buffer` someday
212
+ )
213
+ });
214
+ }
215
+
216
+ /** @returns {Buffer} a random 256-bit "salt" value. */
217
+ function getSalty() {
218
+ return _keypair.Keypair.random().xdrPublicKey().value(); // ed25519 is 256 bits, too
219
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.liquidityPoolDeposit = liquidityPoolDeposit;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * Creates a liquidity pool deposit operation.
11
+ *
12
+ * @function
13
+ * @alias Operation.liquidityPoolDeposit
14
+ * @see https://developers.stellar.org/docs/start/list-of-operations/#liquidity-pool-deposit
15
+ *
16
+ * @param {object} opts - Options object
17
+ * @param {string} opts.liquidityPoolId - The liquidity pool ID.
18
+ * @param {string} opts.maxAmountA - Maximum amount of first asset to deposit.
19
+ * @param {string} opts.maxAmountB - Maximum amount of second asset to deposit.
20
+ * @param {number|string|BigNumber|Object} opts.minPrice - Minimum depositA/depositB price.
21
+ * @param {number} opts.minPrice.n - If `opts.minPrice` is an object: the price numerator
22
+ * @param {number} opts.minPrice.d - If `opts.minPrice` is an object: the price denominator
23
+ * @param {number|string|BigNumber|Object} opts.maxPrice - Maximum depositA/depositB price.
24
+ * @param {number} opts.maxPrice.n - If `opts.maxPrice` is an object: the price numerator
25
+ * @param {number} opts.maxPrice.d - If `opts.maxPrice` is an object: the price denominator
26
+ * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
27
+ *
28
+ * @returns {xdr.Operation} The resulting operation (xdr.LiquidityPoolDepositOp).
29
+ */
30
+ function liquidityPoolDeposit() {
31
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
+ var liquidityPoolId = opts.liquidityPoolId,
33
+ maxAmountA = opts.maxAmountA,
34
+ maxAmountB = opts.maxAmountB,
35
+ minPrice = opts.minPrice,
36
+ maxPrice = opts.maxPrice;
37
+ var attributes = {};
38
+ if (!liquidityPoolId) {
39
+ throw new TypeError('liquidityPoolId argument is required');
40
+ }
41
+ attributes.liquidityPoolId = _xdr["default"].PoolId.fromXDR(liquidityPoolId, 'hex');
42
+ if (!this.isValidAmount(maxAmountA, true)) {
43
+ throw new TypeError(this.constructAmountRequirementsError('maxAmountA'));
44
+ }
45
+ attributes.maxAmountA = this._toXDRAmount(maxAmountA);
46
+ if (!this.isValidAmount(maxAmountB, true)) {
47
+ throw new TypeError(this.constructAmountRequirementsError('maxAmountB'));
48
+ }
49
+ attributes.maxAmountB = this._toXDRAmount(maxAmountB);
50
+ if (minPrice === undefined) {
51
+ throw new TypeError('minPrice argument is required');
52
+ }
53
+ attributes.minPrice = this._toXDRPrice(minPrice);
54
+ if (maxPrice === undefined) {
55
+ throw new TypeError('maxPrice argument is required');
56
+ }
57
+ attributes.maxPrice = this._toXDRPrice(maxPrice);
58
+ var liquidityPoolDepositOp = new _xdr["default"].LiquidityPoolDepositOp(attributes);
59
+ var opAttributes = {
60
+ body: _xdr["default"].OperationBody.liquidityPoolDeposit(liquidityPoolDepositOp)
61
+ };
62
+ this.setSourceAccount(opAttributes, opts);
63
+ return new _xdr["default"].Operation(opAttributes);
64
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.liquidityPoolWithdraw = liquidityPoolWithdraw;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * Creates a liquidity pool withdraw operation.
11
+ *
12
+ * @function
13
+ * @alias Operation.liquidityPoolWithdraw
14
+ * @see https://developers.stellar.org/docs/start/list-of-operations/#liquidity-pool-withdraw
15
+ *
16
+ * @param {object} opts - Options object
17
+ * @param {string} opts.liquidityPoolId - The liquidity pool ID.
18
+ * @param {string} opts.amount - Amount of pool shares to withdraw.
19
+ * @param {string} opts.minAmountA - Minimum amount of first asset to withdraw.
20
+ * @param {string} opts.minAmountB - Minimum amount of second asset to withdraw.
21
+ * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
22
+ *
23
+ * @returns {xdr.Operation} The resulting operation (xdr.LiquidityPoolWithdrawOp).
24
+ */
25
+ function liquidityPoolWithdraw() {
26
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
+ var attributes = {};
28
+ if (!opts.liquidityPoolId) {
29
+ throw new TypeError('liquidityPoolId argument is required');
30
+ }
31
+ attributes.liquidityPoolId = _xdr["default"].PoolId.fromXDR(opts.liquidityPoolId, 'hex');
32
+ if (!this.isValidAmount(opts.amount)) {
33
+ throw new TypeError(this.constructAmountRequirementsError('amount'));
34
+ }
35
+ attributes.amount = this._toXDRAmount(opts.amount);
36
+ if (!this.isValidAmount(opts.minAmountA, true)) {
37
+ throw new TypeError(this.constructAmountRequirementsError('minAmountA'));
38
+ }
39
+ attributes.minAmountA = this._toXDRAmount(opts.minAmountA);
40
+ if (!this.isValidAmount(opts.minAmountB, true)) {
41
+ throw new TypeError(this.constructAmountRequirementsError('minAmountB'));
42
+ }
43
+ attributes.minAmountB = this._toXDRAmount(opts.minAmountB);
44
+ var liquidityPoolWithdrawOp = new _xdr["default"].LiquidityPoolWithdrawOp(attributes);
45
+ var opAttributes = {
46
+ body: _xdr["default"].OperationBody.liquidityPoolWithdraw(liquidityPoolWithdrawOp)
47
+ };
48
+ this.setSourceAccount(opAttributes, opts);
49
+ return new _xdr["default"].Operation(opAttributes);
50
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.manageBuyOffer = manageBuyOffer;
7
+ var _jsXdr = require("@stellar/js-xdr");
8
+ var _xdr = _interopRequireDefault(require("../xdr"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ /**
11
+ * Returns a XDR ManageBuyOfferOp. A "manage buy offer" operation creates, updates, or
12
+ * deletes a buy offer.
13
+ * @function
14
+ * @alias Operation.manageBuyOffer
15
+ * @param {object} opts Options object
16
+ * @param {Asset} opts.selling - What you're selling.
17
+ * @param {Asset} opts.buying - What you're buying.
18
+ * @param {string} opts.buyAmount - The total amount you're buying. If 0, deletes the offer.
19
+ * @param {number|string|BigNumber|Object} opts.price - Price of 1 unit of `buying` in terms of `selling`.
20
+ * @param {number} opts.price.n - If `opts.price` is an object: the price numerator
21
+ * @param {number} opts.price.d - If `opts.price` is an object: the price denominator
22
+ * @param {number|string} [opts.offerId ] - If `0`, will create a new offer (default). Otherwise, edits an exisiting offer.
23
+ * @param {string} [opts.source] - The source account (defaults to transaction source).
24
+ * @throws {Error} Throws `Error` when the best rational approximation of `price` cannot be found.
25
+ * @returns {xdr.ManageBuyOfferOp} Manage Buy Offer operation
26
+ */
27
+ function manageBuyOffer(opts) {
28
+ var attributes = {};
29
+ attributes.selling = opts.selling.toXDRObject();
30
+ attributes.buying = opts.buying.toXDRObject();
31
+ if (!this.isValidAmount(opts.buyAmount, true)) {
32
+ throw new TypeError(this.constructAmountRequirementsError('buyAmount'));
33
+ }
34
+ attributes.buyAmount = this._toXDRAmount(opts.buyAmount);
35
+ if (opts.price === undefined) {
36
+ throw new TypeError('price argument is required');
37
+ }
38
+ attributes.price = this._toXDRPrice(opts.price);
39
+ if (opts.offerId !== undefined) {
40
+ opts.offerId = opts.offerId.toString();
41
+ } else {
42
+ opts.offerId = '0';
43
+ }
44
+ attributes.offerId = _jsXdr.Hyper.fromString(opts.offerId);
45
+ var manageBuyOfferOp = new _xdr["default"].ManageBuyOfferOp(attributes);
46
+ var opAttributes = {};
47
+ opAttributes.body = _xdr["default"].OperationBody.manageBuyOffer(manageBuyOfferOp);
48
+ this.setSourceAccount(opAttributes, opts);
49
+ return new _xdr["default"].Operation(opAttributes);
50
+ }