Repository: ecadlabs/taquito (ts)

Issue:
Support new fields introduced by Granada in block metadata
**Is your feature request related to a problem and use case? Please describe.**
Metadata changes in Granada
1. In the balance updates of a block metadata, the new origin `subsidy` has been introduced, besides the existing ones: `block` and `migration`.
2. In block metadata, two new fields are added: 
- `liquidity_baking_escape_ema` representing the new value of the exponential moving average for the liquidity baking escape vote. 
- `implicit_operations_results` representing results of operations not explicitly appearing in the block, namely migration operations at protocol activation and the liquidity baking subsidy operation at each block.

**Describe the solution you'd like**
1. Add "subsidy" in the `MetadataBalanceUpdatesOriginEnum` in the RPC types file.
2. Add `liquidity_baking_escape_ema` and `implicit_operations_results` as optional properties of the BlockMetadata interface

**Additional context**
https://tezos.gitlab.io/protocols/010_granada.html#metadata-changes
https://tezos.gitlab.io/010/rpc.html



Pull request:
Support new fields introduced by Granada in block metadata (#918)
Closes #918 
Thank you for your contribution to Taquito.

Before submitting this PR, please make sure:

- [ ] Your code builds cleanly without any errors or warnings
- [ ] You have added unit tests
- [ ] You have added integration tests (if relevant/appropriate)
- [ ] All public methods or types have TypeDoc coverage with a complete description, and ideally an @example
- [ ] You have added or updated corresponding documentation
- [ ] If relevant, you have written a first draft summary describing the change for inclusion in Release Notes. 

## Release Note Draft Snippet

__If relevant, please write a summary of your change that will be suitable for
inclusion in the Release Notes for the next Taquito release.__


Patch:
diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts
index 726e48889..1c4b334a7 100644
--- a/packages/taquito-rpc/src/types.ts
+++ b/packages/taquito-rpc/src/types.ts
@@ -513,6 +513,12 @@ export type InternalOperationResultKindEnum =
   | OpKind.ORIGINATION
   | OpKind.DELEGATION;
 
+export type SuccessfulManagerOperationResultKindEnum =
+  | OpKind.REVEAL
+  | OpKind.TRANSACTION
+  | OpKind.ORIGINATION
+  | OpKind.DELEGATION;
+
 export type InternalOperationResultEnum =
   | OperationResultReveal
   | OperationResultTransaction
@@ -586,9 +592,22 @@ export interface InternalOperationResult {
   result: InternalOperationResultEnum;
 }
 
+export interface SuccessfulManagerOperationResult {
+  kind: SuccessfulManagerOperationResultKindEnum;
+  consumed_gas?: string;
+  consumed_milligas?: string;
+  storage?: MichelsonV1Expression;
+  big_map_diff?: ContractBigMapDiff;
+  balance_updates?: OperationBalanceUpdates;
+  originated_contracts?: string[];
+  storage_size?: string;
+  paid_storage_size_diff?: string;
+  lazy_storage_diff?: LazyStorageDiff[];
+}
+
 export type MetadataBalanceUpdatesKindEnum = 'contract' | 'freezer';
 export type MetadataBalanceUpdatesCategoryEnum = 'rewards' | 'fees' | 'deposits';
-export type MetadataBalanceUpdatesOriginEnum = 'block' | 'migration';
+export type MetadataBalanceUpdatesOriginEnum = 'block' | 'migration' | 'subsidy';
 
 export interface OperationMetadataBalanceUpdates {
   kind: MetadataBalanceUpdatesKindEnum;
@@ -804,6 +823,8 @@ export interface BlockMetadata {
   consumed_gas: string;
   deactivated: any[];
   balance_updates: OperationBalanceUpdates;
+  liquidity_baking_escape_ema?: number;
+  implicit_operations_results?: SuccessfulManagerOperationResult[];
 }
 
 export type RPCRunOperationParam = {


Test patch:
diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts
index f7a598584..dff5f1db8 100644
--- a/packages/taquito-rpc/test/taquito-rpc.spec.ts
+++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts
@@ -1,6 +1,14 @@
 import { RpcClient } from '../src/taquito-rpc';
 import BigNumber from 'bignumber.js';
-import { LazyStorageDiffBigMap, OperationContentsAndResultEndorsement, OperationContentsAndResultEndorsementWithSlot, OperationContentsAndResultOrigination, OperationResultTransaction, OperationContentsAndResultTransaction, LazyStorageDiffSaplingState } from '../src/types';
+import { 
+  LazyStorageDiffBigMap, 
+  OperationContentsAndResultEndorsement, 
+  OperationContentsAndResultEndorsementWithSlot, 
+  OperationContentsAndResultOrigination, 
+  OperationResultTransaction, 
+  OperationContentsAndResultTransaction, 
+  LazyStorageDiffSaplingState
+} from '../src/types';
 
 /**
  * RpcClient test
@@ -1827,6 +1835,123 @@ describe('RpcClient test', () => {
       done();
     });
 
+
+    it('Access new properties "liquidity_baking_escape_ema", "implicit_operations_results" and "subsidy" in block metadata, proto 10', async done => {
+      httpBackend.createRequest.mockReturnValue(
+        Promise.resolve(
+          {
+            "protocol": "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV",
+            "chain_id": "NetXz969SFaFn8k",
+            "hash": "BMUN7Jt6hv7pVwnVSULxujYXy6qVaFLVoUbd6sQXsagjXpH4iWw",
+            "header": {
+              "level": 218022,
+              "proto": 2,
+              "predecessor": "BKovSSUyqB2dfs5RtrVfFLDugyYavpQ4ULi5KexV8r6HPXA6QL3",
+              "timestamp": "2021-07-19T23:41:07Z",
+              "validation_pass": 4,
+              "operations_hash": "LLoasnx73KY1xekuqN6qnG7GQUrdr6MsuRxJB5S6rqphsR2oX7sDc",
+              "fitness": [ "01", "00000000000353a5" ],
+              "context": "CoWYkYRZg8KswUR8eq9CcXNUuUiqjnck1enWRXmtPRocSg4kPXo4",
+              "priority": 0,
+              "proof_of_work_nonce": "bc2cc86f02c40200",
+              "liquidity_baking_escape_vote": false,
+              "signature": "sigiHpzCAzTLxdSmuD8c3Tn4yHxfhbKErnZwrW8VGr2Q4Y848RNWfLhRrmp9FQExZtXc9ESQab3trtckRdukrvXd7ruBsL4n"
+            },
+            "metadata": {
+              "protocol": "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV",
+              "next_protocol": "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV",
+              "test_chain_status": { "status": "not_running" },
+              "max_operations_ttl": 120,
+              "max_operation_data_length": 32768,
+              "max_block_header_length": 239,
+              "max_operation_list_length": [
+                { "max_size": 4194304, "max_op": 2048 },
+                { "max_size": 32768 },
+                { "max_size": 135168, "max_op": 132 },
+                { "max_size": 524288 }
+              ],
+              "baker": "tz1aWXP237BLwNHJcCD4b3DutCevhqq2T1Z9",
+              "level_info": {
+                "level": 218022,
+                "level_position": 218021,
+                "cycle": 54,
+                "cycle_position": 933,
+                "expected_commitment": false
+              },
+              "voting_period_info": {
+                "voting_period": { "index": 10, "kind": "proposal", "start_position": 204801 },
+                "position": 13220,
+                "remaining": 7259
+              },
+              "nonce_hash": null,
+              "consumed_gas": "0",
+              "deactivated": [],
+              "balance_updates": [],
+              "liquidity_baking_escape_ema": 283204,
+              "implicit_operations_results": [
+                {
+                  "kind": "transaction",
+                  "storage": [
+                    { "int": "104" },
+                    { "int": "177311484916" },
+                    { "int": "118" },
+                    { "bytes": "01e927f00ef734dfc85919635e9afc9166c83ef9fc00" },
+                    { "bytes": "0115eb0104481a6d7921160bc982c5e0a561cd8a3a00" }
+                  ],
+                  "balance_updates": [
+                    {
+                      "kind": "contract",
+                      "contract": "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5",
+                      "change": "2500000",
+                      "origin": "subsidy"
+                    }
+                  ],
+                  "consumed_gas": "2118",
+                  "consumed_milligas": "2117037",
+                  "storage_size": "4633"
+                }
+              ]
+            },
+            "operations": []
+          }
+        )
+      );
+
+      const response = await client.getBlock();
+
+      expect(response.metadata.liquidity_baking_escape_ema).toEqual(283204);
+      expect(typeof response.metadata.liquidity_baking_escape_ema).toBe("number");
+
+      expect(response.metadata.implicit_operations_results).toBeDefined();
+      expect(response.metadata.implicit_operations_results!).toBeInstanceOf(Array);
+      expect(response.metadata.implicit_operations_results!.length).toEqual(1);
+
+      expect(response.metadata.implicit_operations_results![0].kind).toEqual('transaction');
+
+      expect(response.metadata.implicit_operations_results![0].consumed_gas).toBeDefined();
+      expect(response.metadata.implicit_operations_results![0].consumed_gas).toEqual('2118');
+
+      expect(response.metadata.implicit_operations_results![0].consumed_milligas).toBeDefined();
+      expect(response.metadata.implicit_operations_results![0].consumed_milligas).toEqual('2117037');
+
+      expect(response.metadata.implicit_operations_results![0].storage).toBeDefined();
+      expect(response.metadata.implicit_operations_results![0].big_map_diff).toBeUndefined();
+
+      expect(response.metadata.implicit_operations_results![0].balance_updates).toBeDefined();
+      expect(response.metadata.implicit_operations_results![0].balance_updates![0].origin).toBeDefined();
+      expect(response.metadata.implicit_operations_results![0].balance_updates![0].origin).toEqual('subsidy');
+
+      expect(response.metadata.implicit_operations_results![0].originated_contracts).toBeUndefined();
+
+      expect(response.metadata.implicit_operations_results![0].storage_size).toBeDefined();
+      expect(response.metadata.implicit_operations_results![0].storage_size).toEqual('4633');
+
+      expect(response.metadata.implicit_operations_results![0].paid_storage_size_diff).toBeUndefined();
+      expect(response.metadata.implicit_operations_results![0].lazy_storage_diff).toBeUndefined();
+
+      done();
+    });
+
   });
 
   describe('getBakingRights', () => {