From 2a0b4e8653c7da3427b626b137d706f78bfb6c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Criado-P=C3=A9rez?= Date: Wed, 26 Jul 2023 18:37:35 +0200 Subject: [PATCH 1/4] Corrected typos in various messages (#853) --- docs/reference/examples.md | 2 +- test/unit/horizon_axios_client_test.js | 2 +- test/unit/server_transaction_test.js | 2 +- test/unit/utils_test.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/reference/examples.md b/docs/reference/examples.md index 697ed4a89..7744affed 100644 --- a/docs/reference/examples.md +++ b/docs/reference/examples.md @@ -95,7 +95,7 @@ const server = new StellarSdk.Server('https://horizon-testnet.stellar.org'); console.log('\nSuccess! View the transaction at: '); console.log(transactionResult._links.transaction.href); } catch (e) { - console.log('An error has occured:'); + console.log('An error has occurred:'); console.log(e); } })(); diff --git a/test/unit/horizon_axios_client_test.js b/test/unit/horizon_axios_client_test.js index e0f75175f..a56e8622b 100644 --- a/test/unit/horizon_axios_client_test.js +++ b/test/unit/horizon_axios_client_test.js @@ -13,7 +13,7 @@ describe("getCurrentServerTime", () => { clock.restore(); }); - it("returns null when the hostname hasnt been hit", () => { + it("returns null when the hostname hasn't been hit", () => { expect(getCurrentServerTime("host")).to.be.null; }); diff --git a/test/unit/server_transaction_test.js b/test/unit/server_transaction_test.js index 537355809..645f99f76 100644 --- a/test/unit/server_transaction_test.js +++ b/test/unit/server_transaction_test.js @@ -241,7 +241,7 @@ describe("server.js transaction tests", function () { done(err); }); }); - it("doesnt add metadata to non-offers", function (done) { + it("doesn't add metadata to non-offers", function (done) { const response = { _links: { transaction: { diff --git a/test/unit/utils_test.js b/test/unit/utils_test.js index 4dc8feb61..ef07703d6 100644 --- a/test/unit/utils_test.js +++ b/test/unit/utils_test.js @@ -530,7 +530,7 @@ describe("Utils", function () { ); }); - it("throws an error if transaction doestn't contain any operation", function () { + it("throws an error if transaction doesn't contain any operation", function () { let keypair = StellarSdk.Keypair.random(); const account = new StellarSdk.Account(keypair.publicKey(), "-1"); const transaction = new StellarSdk.TransactionBuilder( @@ -2120,7 +2120,7 @@ describe("Utils", function () { ).to.eql([this.clientKP2.publicKey()]); }); - it("throws an error if no client but insted the server has signed the transaction", function () { + it("throws an error if no client but instead the server has signed the transaction", function () { const challenge = StellarSdk.Utils.buildChallengeTx( this.serverKP, this.clientKP1.publicKey(), From 0c99413f06c2c9ca6d6d16dfe6d46a04ba696957 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 15 Aug 2023 15:44:27 -0700 Subject: [PATCH 2/4] Add GitHub Action to check bundle size on new PRs (#852) --- .github/workflows/bundle_size.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/bundle_size.yml diff --git a/.github/workflows/bundle_size.yml b/.github/workflows/bundle_size.yml new file mode 100644 index 000000000..1efbd8b34 --- /dev/null +++ b/.github/workflows/bundle_size.yml @@ -0,0 +1,30 @@ +name: Bundle Size + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Node.js 16 + uses: actions/setup-node@v3 + with: + node-version: 16 + + # Workaround for some `yarn` nonsense, see: + # https://github.com/yarnpkg/yarn/issues/6312#issuecomment-429685210 + - name: Install Dependencies + run: yarn install --network-concurrency 1 + + - name: Build All + run: yarn build:prod + + - name: Report Bundle Size + uses: preactjs/compressed-size-action@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + pattern: "dist/*.js" + compression: "none" \ No newline at end of file From fc9ba11f75e5b2ac613ff4b9eee4748883510ac6 Mon Sep 17 00:00:00 2001 From: George Date: Mon, 21 Aug 2023 14:26:32 -0700 Subject: [PATCH 3/4] Add support for operation responses coming in Protocol 20. (#845) --- CHANGELOG.md | 32 ++++++++++++++++++++++--- src/horizon_api.ts | 46 ++++++++++++++++++++++++++++++++++++ src/server_api.ts | 58 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b4136679..27b519e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,35 @@ A breaking change will get clearly marked in this log. ### Add -- Asset stat records (`ServerApi.AssetRecord`) contain two new fields to support the Protocol 20 (Soroban) release ([#TODO](https://github.com/stellar/js-stellar-sdk/pulls/)): - * `num_contracts` - the integer quantity of contracts that hold this asset - * `contracts_amount` - the total units of that asset held by contracts +- Asset stat records (`ServerApi.AssetRecord`) contain two new fields to support the Protocol 20 (Soroban) release ([#841](https://github.com/stellar/js-stellar-sdk/pull/841)): + * `num_contracts` - the integer quantity of contracts that hold this asset + * `contracts_amount` - the total units of that asset held by contracts +- New operation responses ([#845](https://github.com/stellar/js-stellar-sdk/pull/845)): + * `invokeHostFunction`: see `Horizon.InvokeHostFunctionOperationResponse` + * `bumpFootprintExpiration`: see `Horizon.BumpFootprintExpirationOperationResponse` + * `restoreFootprint`: see `Horizon.RestoreFootprintOperationResponse` + * You can refer to the actual definitions for details, but the gist of the schemas is below: +```ts +interface InvokeHostFunctionOperationResponse { + function: string; + parameters: { + value: string; + type: string; + }[]; + address: string; + salt: string; + asset_balance_changes: { + type: string; + from: string; + to: string; + amount: string; + }[]; +} +interface BumpFootprintExpirationOperationResponse { + ledgersToExpire: string; +} +interface RestoreFootprintOperationResponse {}; +``` ## [v11.0.0-beta.1](https://github.com/stellar/js-stellar-sdk/compare/v11.0.0-beta.0...v11.0.0-beta.1) diff --git a/src/horizon_api.ts b/src/horizon_api.ts index 7b206905a..cb4116195 100644 --- a/src/horizon_api.ts +++ b/src/horizon_api.ts @@ -218,6 +218,9 @@ export namespace Horizon { setTrustLineFlags = "set_trust_line_flags", liquidityPoolDeposit = "liquidity_pool_deposit", liquidityPoolWithdraw = "liquidity_pool_withdraw", + invokeHostFunction = "invoke_host_function", + bumpFootprintExpiration = "bump_footprint_expiration", + restoreFootprint = "restore_footprint", } export enum OperationResponseTypeI { createAccount = 0, @@ -244,6 +247,9 @@ export namespace Horizon { setTrustLineFlags = 21, liquidityPoolDeposit = 22, liquidityPoolWithdraw = 23, + invokeHostFunction = 24, + bumpFootprintExpiration = 25, + restoreFootprint = 26, } export interface BaseOperationResponse< T extends OperationResponseType = OperationResponseType, @@ -563,6 +569,46 @@ export namespace Horizon { reserves_received: Reserve[]; } + export interface BalanceChange { + asset_type: string; + asset_code?: string; + asset_issuer?: string; + + type: string; + from: string; + to: string; + amount: string; + } + + export interface InvokeHostFunctionOperationResponse + extends BaseOperationResponse< + OperationResponseType.invokeHostFunction, + OperationResponseTypeI.invokeHostFunction + > { + function: string; + parameters: { + value: string; + type: string; + }[]; + address: string; + salt: string; + asset_balance_changes: BalanceChange[]; + } + + export interface BumpFootprintExpirationOperationResponse + extends BaseOperationResponse< + OperationResponseType.bumpFootprintExpiration, + OperationResponseTypeI.bumpFootprintExpiration + > { + ledgers_to_expire: number; + } + + export interface RestoreFootprintOperationResponse + extends BaseOperationResponse< + OperationResponseType.restoreFootprint, + OperationResponseTypeI.restoreFootprint + > {}; + export interface ResponseCollection { _links: { self: ResponseLink; diff --git a/src/server_api.ts b/src/server_api.ts index bb210b09d..5c3d4f2a2 100644 --- a/src/server_api.ts +++ b/src/server_api.ts @@ -304,6 +304,54 @@ export namespace ServerApi { OperationResponseTypeI.revokeSponsorship >, Horizon.RevokeSponsorshipOperationResponse {} + export interface ClawbackOperationRecord + extends BaseOperationRecord< + OperationResponseType.clawback, + OperationResponseTypeI.clawback + >, + Horizon.ClawbackOperationResponse {} + export interface ClawbackClaimableBalanceOperationRecord + extends BaseOperationRecord< + OperationResponseType.clawbackClaimableBalance, + OperationResponseTypeI.clawbackClaimableBalance + >, + Horizon.ClawbackClaimableBalanceOperationResponse {} + export interface SetTrustLineFlagsOperationRecord + extends BaseOperationRecord< + OperationResponseType.setTrustLineFlags, + OperationResponseTypeI.setTrustLineFlags + >, + Horizon.SetTrustLineFlagsOperationResponse {} + export interface DepositLiquidityOperationRecord + extends BaseOperationRecord< + OperationResponseType.liquidityPoolDeposit, + OperationResponseTypeI.liquidityPoolDeposit + >, + Horizon.DepositLiquidityOperationResponse {} + export interface WithdrawLiquidityOperationRecord + extends BaseOperationRecord< + OperationResponseType.liquidityPoolWithdraw, + OperationResponseTypeI.liquidityPoolWithdraw + >, + Horizon.WithdrawLiquidityOperationResponse {} + export interface InvokeHostFunctionOperationRecord + extends BaseOperationRecord< + OperationResponseType.invokeHostFunction, + OperationResponseTypeI.invokeHostFunction + >, + Horizon.InvokeHostFunctionOperationResponse {} + export interface BumpFootprintExpirationOperationRecord + extends BaseOperationRecord< + OperationResponseType.bumpFootprintExpiration, + OperationResponseTypeI.bumpFootprintExpiration + >, + Horizon.BumpFootprintExpirationOperationResponse {} + export interface RestoreFootprintOperationRecord + extends BaseOperationRecord< + OperationResponseType.restoreFootprint, + OperationResponseTypeI.restoreFootprint + >, + Horizon.RestoreFootprintOperationResponse {} export type OperationRecord = | CreateAccountOperationRecord @@ -323,7 +371,15 @@ export namespace ServerApi { | ClaimClaimableBalanceOperationRecord | BeginSponsoringFutureReservesOperationRecord | EndSponsoringFutureReservesOperationRecord - | RevokeSponsorshipOperationRecord; + | RevokeSponsorshipOperationRecord + | ClawbackClaimableBalanceOperationRecord + | ClawbackOperationRecord + | SetTrustLineFlagsOperationRecord + | DepositLiquidityOperationRecord + | WithdrawLiquidityOperationRecord + | InvokeHostFunctionOperationRecord + | BumpFootprintExpirationOperationRecord + | RestoreFootprintOperationRecord; export namespace TradeRecord { interface Base extends Horizon.BaseResponse { From a32a4503a406734c8d13460fe5581d4e540399f2 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 22 Aug 2023 08:49:33 -0700 Subject: [PATCH 4/4] Coalesce effect record naming to match the actual effect type. (#844) --- CHANGELOG.md | 40 +++++++++++++++++++++++++++++----------- src/server_api.ts | 16 ++++++++-------- src/types/effects.ts | 16 ++++++++-------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27b519e71..538cb5d65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,32 @@ interface RestoreFootprintOperationResponse {}; ``` +### Breaking Changes + +- Certain effects have been renamed to align better with the "tense" that other structures have ([#844](https://github.com/stellar/js-stellar-sdk/pull/844)): + * `DepositLiquidityEffect` -> `LiquidityPoolDeposited` + * `WithdrawLiquidityEffect` -> `LiquidityPoolWithdrew` + * `LiquidityPoolTradeEffect` -> `LiquidityPoolTrade` + * `LiquidityPoolCreatedEffect` -> `LiquidityPoolCreated` + * `LiquidityPoolRevokedEffect` -> `LiquidityPoolRevoked` + * `LiquidityPoolRemovedEffect` -> `LiquidityPoolRemoved` + +### Add + +- New effects have been added to support Protocol 20 (Soroban) ([#842](https://github.com/stellar/js-stellar-sdk/pull/842)): + * `ContractCredited` occurs when a Stellar asset moves **into** its corresponding Stellar Asset Contract instance + * `ContractDebited` occurs when a Stellar asset moves **out of** its corresponding Stellar Asset Contract instance +- Asset stat records (`ServerApi.AssetRecord`) contain two new fields to support the Protocol 20 (Soroban) release ([#TODO](https://github.com/stellar/js-stellar-sdk/pulls/)): + * `num_contracts` - the integer quantity of contracts that hold this asset + * `contracts_amount` - the total units of that asset held by contracts + +### Fixed + +- Some effect definitions that were missing have been added ([#842](https://github.com/stellar/js-stellar-sdk/pull/842)): + * `ClaimableBalanceClawedBack` is now defined + * `type EffectRecord` now has all of the effect types + + ## [v11.0.0-beta.1](https://github.com/stellar/js-stellar-sdk/compare/v11.0.0-beta.0...v11.0.0-beta.1) ### Update @@ -53,7 +79,6 @@ This version is marked by a major version bump because of the significant upgrad ### Update - Build system has been overhauled to support Webpack 5 ([#814](https://github.com/stellar/js-stellar-sdk/pull/814)). - - `stellar-base` has been updated to its corresponding overhaul ([#818](https://github.com/stellar/js-stellar-sdk/pull/818)). ### Fix @@ -73,7 +98,6 @@ This version is marked by a major version bump because of the significant upgrad ### Add - Add [SEP-1](https://stellar.org/protocol/sep-1) fields to `StellarTomlResolver` for type checks ([#794](https://github.com/stellar/js-stellar-sdk/pull/794)). - - Add support for passing `X-Auth-Token` as a custom header ([#795](https://github.com/stellar/js-stellar-sdk/pull/795)). ### Update @@ -115,7 +139,6 @@ This version is marked by a major version bump because of the significant upgrad ### Fix - Reverts a change from [v10.1.0](#v10.1.0) which caused streams to die prematurely ([#780](https://github.com/stellar/js-stellar-sdk/pull/780)). - - Bumps `stellar-base` version to [v8.0.1](https://github.com/stellar/js-stellar-base/releases/tag/v8.0.1) to include latest bugfixes. @@ -133,7 +156,6 @@ This is a promotion from the beta version without changes, besides upgrading the ### Add - Support for Protocol 19 ([#775](https://github.com/stellar/js-stellar-sdk/pull/775)): - * new precondition fields on a `TransactionResponse` * new account fields on `AccountResponse` and `AccountRecord` * bumping `stellar-base` to the latest beta version @@ -141,9 +163,7 @@ This is a promotion from the beta version without changes, besides upgrading the ### Fix - Add missing field to account responses: `last_modified_time` which is the time equivalent of the existing `last_modified_ledger` ([#770](https://github.com/stellar/js-stellar-sdk/pull/770)). - - Stop opening extra connections when SSE streams receive `event: close` events ([#772](https://github.com/stellar/js-stellar-sdk/pull/772)). - - Fix SSE streams not loading under React Native (thank you, @hunterpetersen!) ([#761](https://github.com/stellar/js-stellar-sdk/pull/761)). @@ -152,16 +172,14 @@ This is a promotion from the beta version without changes, besides upgrading the ### Fix - Add missing fields to the `LedgerRecord`: `successful_transaction_count` and `failed_transaction_count` ([#740](https://github.com/stellar/js-stellar-sdk/pull/740)). Note that this also marks several fields as _deprecated_ because they don't actually exist in the Horizon API response: - - - `transaction_count`: superceded by the sum of the aforementioned fields - - `base_fee`: superceded by the `base_fee_in_stroops` field - - `base_reserve`: superceded by the `base_reserve_in_stroops` field + * `transaction_count`: superceded by the sum of the aforementioned fields + * `base_fee`: superceded by the `base_fee_in_stroops` field + * `base_reserve`: superceded by the `base_reserve_in_stroops` field These deprecated fields will be removed in the next major version. It's unlikely that this breaking change should affect anyone, as these fields have likely been missing/invalid for some time. ### Update - Update a number of dependencies that needed various security updates: - * several dependencies bumped their patch version ([#736](https://github.com/stellar/js-stellar-sdk/pull/736), [#684](https://github.com/stellar/js-stellar-sdk/pull/684), [#672](https://github.com/stellar/js-stellar-sdk/pull/672), [#666](https://github.com/stellar/js-stellar-sdk/pull/666), [#644](https://github.com/stellar/js-stellar-sdk/pull/644), [#622](https://github.com/stellar/js-stellar-sdk/pull/622)) * axios has been bumped to 0.25.0 without causing breaking changes ([#742](https://github.com/stellar/js-stellar-sdk/pull/742)) * the `karma` suite of packages has been updated to the latest major version ([#743](https://github.com/stellar/js-stellar-sdk/pull/743)) diff --git a/src/server_api.ts b/src/server_api.ts index 5c3d4f2a2..05f18a20a 100644 --- a/src/server_api.ts +++ b/src/server_api.ts @@ -73,14 +73,14 @@ export namespace ServerApi { | Effects.SignerSponsorshipCreated | Effects.SignerSponsorshipUpdated | Effects.SignerSponsorshipRemoved - | Effects.DepositLiquidityEffect - | Effects.WithdrawLiquidityEffect - | Effects.LiquidityPoolCreatedEffect - | Effects.LiquidityPoolRemovedEffect - | Effects.LiquidityPoolRevokedEffect - | Effects.LiquidityPoolTradeEffect - | Effects.ContractCreditedEffect - | Effects.ContractDebitedEffect + | Effects.LiquidityPoolDeposited + | Effects.LiquidityPoolWithdrew + | Effects.LiquidityPoolCreated + | Effects.LiquidityPoolRemoved + | Effects.LiquidityPoolRevoked + | Effects.LiquidityPoolTrade + | Effects.ContractCredited + | Effects.ContractDebited | Trade; export type EffectRecord = BaseEffectRecordFromTypes & EffectRecordMethods; diff --git a/src/types/effects.ts b/src/types/effects.ts index a2888907d..4fa5999c9 100644 --- a/src/types/effects.ts +++ b/src/types/effects.ts @@ -275,33 +275,33 @@ export interface LiquidityPoolEffectRecord extends Horizon.BaseResponse { total_shares: string; reserves: Horizon.Reserve[]; } -export interface DepositLiquidityEffect extends BaseEffectRecord { +export interface LiquidityPoolDeposited extends BaseEffectRecord { type_i: EffectType.liquidity_pool_deposited; liquidity_pool: LiquidityPoolEffectRecord; reserves_deposited: Horizon.Reserve[]; shares_received: string; } -export interface WithdrawLiquidityEffect extends BaseEffectRecord { +export interface LiquidityPoolWithdrew extends BaseEffectRecord { type_i: EffectType.liquidity_pool_withdrew; liquidity_pool: LiquidityPoolEffectRecord; reserves_received: Horizon.Reserve[]; shares_redeemed: string; } -export interface LiquidityPoolTradeEffect extends BaseEffectRecord { +export interface LiquidityPoolTrade extends BaseEffectRecord { type_i: EffectType.liquidity_pool_trade; liquidity_pool: LiquidityPoolEffectRecord; sold: Horizon.Reserve; bought: Horizon.Reserve; } -export interface LiquidityPoolCreatedEffect extends BaseEffectRecord { +export interface LiquidityPoolCreated extends BaseEffectRecord { type_i: EffectType.liquidity_pool_created; liquidity_pool: LiquidityPoolEffectRecord; } -export interface LiquidityPoolRemovedEffect extends BaseEffectRecord { +export interface LiquidityPoolRemoved extends BaseEffectRecord { type_i: EffectType.liquidity_pool_removed; liquidity_pool_id: string; } -export interface LiquidityPoolRevokedEffect extends BaseEffectRecord { +export interface LiquidityPoolRevoked extends BaseEffectRecord { type_i: EffectType.liquidity_pool_revoked; liquidity_pool: LiquidityPoolEffectRecord; reserves_revoked: [ @@ -314,12 +314,12 @@ export interface LiquidityPoolRevokedEffect extends BaseEffectRecord { shares_revoked: string; } -export interface ContractCreditedEffect extends BaseEffectRecord, OfferAsset { +export interface ContractCredited extends BaseEffectRecord, OfferAsset { type_i: EffectType.contract_credited; contract: string; amount: string; } -export interface ContractDebitedEffect extends BaseEffectRecord, OfferAsset { +export interface ContractDebited extends BaseEffectRecord, OfferAsset { type_i: EffectType.contract_debited; contract: string; amount: string;