@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,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.accountMerge = accountMerge;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ var _decode_encode_muxed_account = require("../util/decode_encode_muxed_account");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ /**
11
+ * Transfers native balance to destination account.
12
+ *
13
+ * @function
14
+ * @alias Operation.accountMerge
15
+ *
16
+ * @param {object} opts - options object
17
+ * @param {string} opts.destination - destination to merge the source account into
18
+ * @param {string} [opts.source] - operation source account (defaults to
19
+ * transaction source)
20
+ *
21
+ * @returns {xdr.Operation} an Account Merge operation (xdr.AccountMergeOp)
22
+ */
23
+ function accountMerge(opts) {
24
+ var opAttributes = {};
25
+ try {
26
+ opAttributes.body = _xdr["default"].OperationBody.accountMerge((0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(opts.destination));
27
+ } catch (e) {
28
+ throw new Error('destination is invalid');
29
+ }
30
+ this.setSourceAccount(opAttributes, opts);
31
+ return new _xdr["default"].Operation(opAttributes);
32
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowTrust = allowTrust;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ var _keypair = require("../keypair");
9
+ var _strkey = require("../strkey");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ /**
12
+ * @deprecated since v5.0
13
+ *
14
+ * Returns an XDR AllowTrustOp. An "allow trust" operation authorizes another
15
+ * account to hold your account's credit for a given asset.
16
+ *
17
+ * @function
18
+ * @alias Operation.allowTrust
19
+ *
20
+ * @param {object} opts Options object
21
+ * @param {string} opts.trustor - The trusting account (the one being authorized)
22
+ * @param {string} opts.assetCode - The asset code being authorized.
23
+ * @param {(0|1|2)} opts.authorize - `1` to authorize, `2` to authorize to maintain liabilities, and `0` to deauthorize.
24
+ * @param {string} [opts.source] - The source account (defaults to transaction source).
25
+ *
26
+ * @returns {xdr.AllowTrustOp} Allow Trust operation
27
+ */
28
+ function allowTrust(opts) {
29
+ if (!_strkey.StrKey.isValidEd25519PublicKey(opts.trustor)) {
30
+ throw new Error('trustor is invalid');
31
+ }
32
+ var attributes = {};
33
+ attributes.trustor = _keypair.Keypair.fromPublicKey(opts.trustor).xdrAccountId();
34
+ if (opts.assetCode.length <= 4) {
35
+ var code = opts.assetCode.padEnd(4, '\0');
36
+ attributes.asset = _xdr["default"].AssetCode.assetTypeCreditAlphanum4(code);
37
+ } else if (opts.assetCode.length <= 12) {
38
+ var _code = opts.assetCode.padEnd(12, '\0');
39
+ attributes.asset = _xdr["default"].AssetCode.assetTypeCreditAlphanum12(_code);
40
+ } else {
41
+ throw new Error('Asset code must be 12 characters at max.');
42
+ }
43
+ if (typeof opts.authorize === 'boolean') {
44
+ if (opts.authorize) {
45
+ attributes.authorize = _xdr["default"].TrustLineFlags.authorizedFlag().value;
46
+ } else {
47
+ attributes.authorize = 0;
48
+ }
49
+ } else {
50
+ attributes.authorize = opts.authorize;
51
+ }
52
+ var allowTrustOp = new _xdr["default"].AllowTrustOp(attributes);
53
+ var opAttributes = {};
54
+ opAttributes.body = _xdr["default"].OperationBody.allowTrust(allowTrustOp);
55
+ this.setSourceAccount(opAttributes, opts);
56
+ return new _xdr["default"].Operation(opAttributes);
57
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.beginSponsoringFutureReserves = beginSponsoringFutureReserves;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ var _strkey = require("../strkey");
9
+ var _keypair = require("../keypair");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ /**
12
+ * Create a "begin sponsoring future reserves" operation.
13
+ * @function
14
+ * @alias Operation.beginSponsoringFutureReserves
15
+ * @param {object} opts Options object
16
+ * @param {string} opts.sponsoredId - The sponsored account id.
17
+ * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
18
+ * @returns {xdr.Operation} xdr operation
19
+ *
20
+ * @example
21
+ * const op = Operation.beginSponsoringFutureReserves({
22
+ * sponsoredId: 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7'
23
+ * });
24
+ *
25
+ */
26
+ function beginSponsoringFutureReserves() {
27
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
+ if (!_strkey.StrKey.isValidEd25519PublicKey(opts.sponsoredId)) {
29
+ throw new Error('sponsoredId is invalid');
30
+ }
31
+ var op = new _xdr["default"].BeginSponsoringFutureReservesOp({
32
+ sponsoredId: _keypair.Keypair.fromPublicKey(opts.sponsoredId).xdrAccountId()
33
+ });
34
+ var opAttributes = {};
35
+ opAttributes.body = _xdr["default"].OperationBody.beginSponsoringFutureReserves(op);
36
+ this.setSourceAccount(opAttributes, opts);
37
+ return new _xdr["default"].Operation(opAttributes);
38
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.bumpSequence = bumpSequence;
7
+ var _jsXdr = require("@stellar/js-xdr");
8
+ var _bignumber = _interopRequireDefault(require("bignumber.js"));
9
+ var _xdr = _interopRequireDefault(require("../xdr"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ /**
12
+ * This operation bumps sequence number.
13
+ * @function
14
+ * @alias Operation.bumpSequence
15
+ * @param {object} opts Options object
16
+ * @param {string} opts.bumpTo - Sequence number to bump to.
17
+ * @param {string} [opts.source] - The optional source account.
18
+ * @returns {xdr.BumpSequenceOp} Operation
19
+ */
20
+ function bumpSequence(opts) {
21
+ var attributes = {};
22
+ if (typeof opts.bumpTo !== 'string') {
23
+ throw new Error('bumpTo must be a string');
24
+ }
25
+ try {
26
+ // eslint-disable-next-line no-new
27
+ new _bignumber["default"](opts.bumpTo);
28
+ } catch (e) {
29
+ throw new Error('bumpTo must be a stringified number');
30
+ }
31
+ attributes.bumpTo = _jsXdr.Hyper.fromString(opts.bumpTo);
32
+ var bumpSequenceOp = new _xdr["default"].BumpSequenceOp(attributes);
33
+ var opAttributes = {};
34
+ opAttributes.body = _xdr["default"].OperationBody.bumpSequence(bumpSequenceOp);
35
+ this.setSourceAccount(opAttributes, opts);
36
+ return new _xdr["default"].Operation(opAttributes);
37
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.changeTrust = changeTrust;
7
+ var _jsXdr = require("@stellar/js-xdr");
8
+ var _bignumber = _interopRequireDefault(require("bignumber.js"));
9
+ var _xdr = _interopRequireDefault(require("../xdr"));
10
+ var _asset = require("../asset");
11
+ var _liquidity_pool_asset = require("../liquidity_pool_asset");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+ var MAX_INT64 = '9223372036854775807';
14
+
15
+ /**
16
+ * Returns an XDR ChangeTrustOp. A "change trust" operation adds, removes, or updates a
17
+ * trust line for a given asset from the source account to another.
18
+ * @function
19
+ * @alias Operation.changeTrust
20
+ * @param {object} opts Options object
21
+ * @param {Asset | LiquidityPoolAsset} opts.asset - The asset for the trust line.
22
+ * @param {string} [opts.limit] - The limit for the asset, defaults to max int64.
23
+ * If the limit is set to "0" it deletes the trustline.
24
+ * @param {string} [opts.source] - The source account (defaults to transaction source).
25
+ * @returns {xdr.ChangeTrustOp} Change Trust operation
26
+ */
27
+ function changeTrust(opts) {
28
+ var attributes = {};
29
+ if (opts.asset instanceof _asset.Asset) {
30
+ attributes.line = opts.asset.toChangeTrustXDRObject();
31
+ } else if (opts.asset instanceof _liquidity_pool_asset.LiquidityPoolAsset) {
32
+ attributes.line = opts.asset.toXDRObject();
33
+ } else {
34
+ throw new TypeError('asset must be Asset or LiquidityPoolAsset');
35
+ }
36
+ if (opts.limit !== undefined && !this.isValidAmount(opts.limit, true)) {
37
+ throw new TypeError(this.constructAmountRequirementsError('limit'));
38
+ }
39
+ if (opts.limit) {
40
+ attributes.limit = this._toXDRAmount(opts.limit);
41
+ } else {
42
+ attributes.limit = _jsXdr.Hyper.fromString(new _bignumber["default"](MAX_INT64).toString());
43
+ }
44
+ if (opts.source) {
45
+ attributes.source = opts.source.masterKeypair;
46
+ }
47
+ var changeTrustOP = new _xdr["default"].ChangeTrustOp(attributes);
48
+ var opAttributes = {};
49
+ opAttributes.body = _xdr["default"].OperationBody.changeTrust(changeTrustOP);
50
+ this.setSourceAccount(opAttributes, opts);
51
+ return new _xdr["default"].Operation(opAttributes);
52
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.claimClaimableBalance = claimClaimableBalance;
7
+ exports.validateClaimableBalanceId = validateClaimableBalanceId;
8
+ var _xdr = _interopRequireDefault(require("../xdr"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ /**
11
+ * Create a new claim claimable balance operation.
12
+ * @function
13
+ * @alias Operation.claimClaimableBalance
14
+ * @param {object} opts Options object
15
+ * @param {string} opts.balanceId - The claimable balance id to be claimed.
16
+ * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
17
+ * @returns {xdr.Operation} Claim claimable balance operation
18
+ *
19
+ * @example
20
+ * const op = Operation.claimClaimableBalance({
21
+ * balanceId: '00000000da0d57da7d4850e7fc10d2a9d0ebc731f7afb40574c03395b17d49149b91f5be',
22
+ * });
23
+ *
24
+ */
25
+ function claimClaimableBalance() {
26
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
+ validateClaimableBalanceId(opts.balanceId);
28
+ var attributes = {};
29
+ attributes.balanceId = _xdr["default"].ClaimableBalanceId.fromXDR(opts.balanceId, 'hex');
30
+ var claimClaimableBalanceOp = new _xdr["default"].ClaimClaimableBalanceOp(attributes);
31
+ var opAttributes = {};
32
+ opAttributes.body = _xdr["default"].OperationBody.claimClaimableBalance(claimClaimableBalanceOp);
33
+ this.setSourceAccount(opAttributes, opts);
34
+ return new _xdr["default"].Operation(opAttributes);
35
+ }
36
+ function validateClaimableBalanceId(balanceId) {
37
+ if (typeof balanceId !== 'string' || balanceId.length !== 8 + 64 /* 8b discriminant + 64b string */) {
38
+ throw new Error('must provide a valid claimable balance id');
39
+ }
40
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clawback = clawback;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ var _decode_encode_muxed_account = require("../util/decode_encode_muxed_account");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ /**
11
+ * Creates a clawback operation.
12
+ *
13
+ * @function
14
+ * @alias Operation.clawback
15
+ *
16
+ * @param {object} opts - Options object
17
+ * @param {Asset} opts.asset - The asset being clawed back.
18
+ * @param {string} opts.amount - The amount of the asset to claw back.
19
+ * @param {string} opts.from - The public key of the (optionally-muxed)
20
+ * account to claw back from.
21
+ *
22
+ * @param {string} [opts.source] - The source account for the operation.
23
+ * Defaults to the transaction's source account.
24
+ *
25
+ * @return {xdr.ClawbackOp}
26
+ *
27
+ * @see https://github.com/stellar/stellar-protocol/blob/master/core/cap-0035.md#clawback-operation
28
+ */
29
+ function clawback(opts) {
30
+ var attributes = {};
31
+ if (!this.isValidAmount(opts.amount)) {
32
+ throw new TypeError(this.constructAmountRequirementsError('amount'));
33
+ }
34
+ attributes.amount = this._toXDRAmount(opts.amount);
35
+ attributes.asset = opts.asset.toXDRObject();
36
+ try {
37
+ attributes.from = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(opts.from);
38
+ } catch (e) {
39
+ throw new Error('from address is invalid');
40
+ }
41
+ var opAttributes = {
42
+ body: _xdr["default"].OperationBody.clawback(new _xdr["default"].ClawbackOp(attributes))
43
+ };
44
+ this.setSourceAccount(opAttributes, opts);
45
+ return new _xdr["default"].Operation(opAttributes);
46
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clawbackClaimableBalance = clawbackClaimableBalance;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ var _claim_claimable_balance = require("./claim_claimable_balance");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ /**
11
+ * Creates a clawback operation for a claimable balance.
12
+ *
13
+ * @function
14
+ * @alias Operation.clawbackClaimableBalance
15
+ * @param {object} opts - Options object
16
+ * @param {string} opts.balanceId - The claimable balance ID to be clawed back.
17
+ * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
18
+ *
19
+ * @return {xdr.ClawbackClaimableBalanceOp}
20
+ *
21
+ * @example
22
+ * const op = Operation.clawbackClaimableBalance({
23
+ * balanceId: '00000000da0d57da7d4850e7fc10d2a9d0ebc731f7afb40574c03395b17d49149b91f5be',
24
+ * });
25
+ *
26
+ * @link https://github.com/stellar/stellar-protocol/blob/master/core/cap-0035.md#clawback-claimable-balance-operation
27
+ */
28
+ function clawbackClaimableBalance() {
29
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
30
+ (0, _claim_claimable_balance.validateClaimableBalanceId)(opts.balanceId);
31
+ var attributes = {
32
+ balanceId: _xdr["default"].ClaimableBalanceId.fromXDR(opts.balanceId, 'hex')
33
+ };
34
+ var opAttributes = {
35
+ body: _xdr["default"].OperationBody.clawbackClaimableBalance(new _xdr["default"].ClawbackClaimableBalanceOp(attributes))
36
+ };
37
+ this.setSourceAccount(opAttributes, opts);
38
+ return new _xdr["default"].Operation(opAttributes);
39
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createAccount = createAccount;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ var _keypair = require("../keypair");
9
+ var _strkey = require("../strkey");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ /**
12
+ * Create and fund a non existent account.
13
+ * @function
14
+ * @alias Operation.createAccount
15
+ * @param {object} opts Options object
16
+ * @param {string} opts.destination - Destination account ID to create an account for.
17
+ * @param {string} opts.startingBalance - Amount in XLM the account should be funded for. Must be greater
18
+ * than the [reserve balance amount](https://developers.stellar.org/docs/glossary/fees/).
19
+ * @param {string} [opts.source] - The source account for the payment. Defaults to the transaction's source account.
20
+ * @returns {xdr.CreateAccountOp} Create account operation
21
+ */
22
+ function createAccount(opts) {
23
+ if (!_strkey.StrKey.isValidEd25519PublicKey(opts.destination)) {
24
+ throw new Error('destination is invalid');
25
+ }
26
+ if (!this.isValidAmount(opts.startingBalance, true)) {
27
+ throw new TypeError(this.constructAmountRequirementsError('startingBalance'));
28
+ }
29
+ var attributes = {};
30
+ attributes.destination = _keypair.Keypair.fromPublicKey(opts.destination).xdrAccountId();
31
+ attributes.startingBalance = this._toXDRAmount(opts.startingBalance);
32
+ var createAccountOp = new _xdr["default"].CreateAccountOp(attributes);
33
+ var opAttributes = {};
34
+ opAttributes.body = _xdr["default"].OperationBody.createAccount(createAccountOp);
35
+ this.setSourceAccount(opAttributes, opts);
36
+ return new _xdr["default"].Operation(opAttributes);
37
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createClaimableBalance = createClaimableBalance;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ var _asset = require("../asset");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ /**
11
+ * Create a new claimable balance operation.
12
+ *
13
+ * @function
14
+ * @alias Operation.createClaimableBalance
15
+ *
16
+ * @param {object} opts Options object
17
+ * @param {Asset} opts.asset - The asset for the claimable balance.
18
+ * @param {string} opts.amount - Amount.
19
+ * @param {Claimant[]} opts.claimants - An array of Claimants
20
+ * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
21
+ *
22
+ * @returns {xdr.Operation} Create claimable balance operation
23
+ *
24
+ * @example
25
+ * const asset = new Asset(
26
+ * 'USD',
27
+ * 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7'
28
+ * );
29
+ * const amount = '100.0000000';
30
+ * const claimants = [
31
+ * new Claimant(
32
+ * 'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
33
+ * Claimant.predicateBeforeAbsoluteTime("4102444800000")
34
+ * )
35
+ * ];
36
+ *
37
+ * const op = Operation.createClaimableBalance({
38
+ * asset,
39
+ * amount,
40
+ * claimants
41
+ * });
42
+ *
43
+ */
44
+ function createClaimableBalance(opts) {
45
+ if (!(opts.asset instanceof _asset.Asset)) {
46
+ throw new Error('must provide an asset for create claimable balance operation');
47
+ }
48
+ if (!this.isValidAmount(opts.amount)) {
49
+ throw new TypeError(this.constructAmountRequirementsError('amount'));
50
+ }
51
+ if (!Array.isArray(opts.claimants) || opts.claimants.length === 0) {
52
+ throw new Error('must provide at least one claimant');
53
+ }
54
+ var attributes = {};
55
+ attributes.asset = opts.asset.toXDRObject();
56
+ attributes.amount = this._toXDRAmount(opts.amount);
57
+ attributes.claimants = Object.values(opts.claimants).map(function (c) {
58
+ return c.toXDRObject();
59
+ });
60
+ var createClaimableBalanceOp = new _xdr["default"].CreateClaimableBalanceOp(attributes);
61
+ var opAttributes = {};
62
+ opAttributes.body = _xdr["default"].OperationBody.createClaimableBalance(createClaimableBalanceOp);
63
+ this.setSourceAccount(opAttributes, opts);
64
+ return new _xdr["default"].Operation(opAttributes);
65
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPassiveSellOffer = createPassiveSellOffer;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * Returns a XDR CreatePasiveSellOfferOp. A "create passive offer" operation creates an
11
+ * offer that won't consume a counter offer that exactly matches this offer. This is
12
+ * useful for offers just used as 1:1 exchanges for path payments. Use manage offer
13
+ * to manage this offer after using this operation to create it.
14
+ * @function
15
+ * @alias Operation.createPassiveSellOffer
16
+ * @param {object} opts Options object
17
+ * @param {Asset} opts.selling - What you're selling.
18
+ * @param {Asset} opts.buying - What you're buying.
19
+ * @param {string} opts.amount - The total amount you're selling. If 0, deletes the offer.
20
+ * @param {number|string|BigNumber|Object} opts.price - Price of 1 unit of `selling` in terms of `buying`.
21
+ * @param {number} opts.price.n - If `opts.price` is an object: the price numerator
22
+ * @param {number} opts.price.d - If `opts.price` is an object: the price denominator
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.CreatePassiveSellOfferOp} Create Passive Sell Offer operation
26
+ */
27
+ function createPassiveSellOffer(opts) {
28
+ var attributes = {};
29
+ attributes.selling = opts.selling.toXDRObject();
30
+ attributes.buying = opts.buying.toXDRObject();
31
+ if (!this.isValidAmount(opts.amount)) {
32
+ throw new TypeError(this.constructAmountRequirementsError('amount'));
33
+ }
34
+ attributes.amount = this._toXDRAmount(opts.amount);
35
+ if (opts.price === undefined) {
36
+ throw new TypeError('price argument is required');
37
+ }
38
+ attributes.price = this._toXDRPrice(opts.price);
39
+ var createPassiveSellOfferOp = new _xdr["default"].CreatePassiveSellOfferOp(attributes);
40
+ var opAttributes = {};
41
+ opAttributes.body = _xdr["default"].OperationBody.createPassiveSellOffer(createPassiveSellOfferOp);
42
+ this.setSourceAccount(opAttributes, opts);
43
+ return new _xdr["default"].Operation(opAttributes);
44
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.endSponsoringFutureReserves = endSponsoringFutureReserves;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * Create an "end sponsoring future reserves" operation.
11
+ * @function
12
+ * @alias Operation.endSponsoringFutureReserves
13
+ * @param {object} opts Options object
14
+ * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
15
+ * @returns {xdr.Operation} xdr operation
16
+ *
17
+ * @example
18
+ * const op = Operation.endSponsoringFutureReserves();
19
+ *
20
+ */
21
+ function endSponsoringFutureReserves() {
22
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
+ var opAttributes = {};
24
+ opAttributes.body = _xdr["default"].OperationBody.endSponsoringFutureReserves();
25
+ this.setSourceAccount(opAttributes, opts);
26
+ return new _xdr["default"].Operation(opAttributes);
27
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.extendFootprintTtl = extendFootprintTtl;
7
+ var _xdr = _interopRequireDefault(require("../xdr"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * Builds an operation to bump the expiration of a footprint (read and written
11
+ * ledger keys). Its only parameter is the number of ledgers to extend
12
+ * expiration for.
13
+ *
14
+ * The footprint itself is derived from the transaction (see
15
+ * {@link TransactionBuilder}'s `opts.sorobanData` parameter, which is a
16
+ * {@link xdr.SorobanTransactionData} instance that contains fee data & resource
17
+ * usage as part of {@link xdr.SorobanResources}).
18
+ *
19
+ * @function
20
+ * @alias Operation.extendFootprintTtl
21
+ *
22
+ * @param {object} opts - object holding operation parameters
23
+ * @param {number} opts.extendTo - the number of ledgers past the LCL
24
+ * (last closed ledger) by which to extend the validity of the ledger keys in
25
+ * this transaction
26
+ * @param {string} [opts.source] - an optional source account
27
+ *
28
+ * @returns {xdr.Operation} a Bump Footprint Expiration operation
29
+ * (xdr.ExtendFootprintTTLOp)
30
+ */
31
+ function extendFootprintTtl(opts) {
32
+ var _opts$extendTo;
33
+ if (((_opts$extendTo = opts.extendTo) !== null && _opts$extendTo !== void 0 ? _opts$extendTo : -1) <= 0) {
34
+ throw new RangeError("extendTo isn't a ledger quantity (uint32)");
35
+ }
36
+ var extendFootprintOp = new _xdr["default"].ExtendFootprintTtlOp({
37
+ ext: new _xdr["default"].ExtensionPoint(0),
38
+ extendTo: opts.extendTo
39
+ });
40
+ var opAttributes = {
41
+ body: _xdr["default"].OperationBody.extendFootprintTtl(extendFootprintOp)
42
+ };
43
+ this.setSourceAccount(opAttributes, opts);
44
+ return new _xdr["default"].Operation(opAttributes);
45
+ }