From 11163168a3ba1117d81b568609f7e02df8129a47 Mon Sep 17 00:00:00 2001 From: Bucur David Date: Wed, 6 Mar 2024 17:00:48 +0200 Subject: [PATCH 1/2] feat: view total bonds and compensations Refs:#99 --- src/abis/core-mx-life-bonding-sc.abi.json | 10 ++++++ src/bond.ts | 41 +++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/abis/core-mx-life-bonding-sc.abi.json b/src/abis/core-mx-life-bonding-sc.abi.json index 056fe21..aad89de 100644 --- a/src/abis/core-mx-life-bonding-sc.abi.json +++ b/src/abis/core-mx-life-bonding-sc.abi.json @@ -375,6 +375,16 @@ } ] }, + { + "name": "getCompensationsLen", + "mutability": "readonly", + "inputs": [], + "outputs": [ + { + "type": "u32" + } + ] + }, { "name": "getLockPeriodsBonds", "mutability": "readonly", diff --git a/src/bond.ts b/src/bond.ts index 7881de3..97ff509 100644 --- a/src/bond.ts +++ b/src/bond.ts @@ -322,6 +322,47 @@ export class BondContract extends Contract { } } + /** + * Returns the total number of bonds + */ + async viewTotalBonds(): Promise { + const interaction = this.contract.methodsExplicit.getBondsLen([]); + const query = interaction.buildQuery(); + const queryResponse = await this.networkProvider.queryContract(query); + const endpointDefinition = interaction.getEndpoint(); + const { firstValue, returnCode } = new ResultsParser().parseQueryResponse( + queryResponse, + endpointDefinition + ); + if (returnCode.isSuccess()) { + return firstValue?.valueOf().toNumber(); + } else { + throw new ErrContractQuery('viewTotalBonds', returnCode.toString()); + } + } + + /** + * Returns the total number of compensations + */ + async viewTotalCompensations(): Promise { + const interaction = this.contract.methodsExplicit.getCompensationsLen([]); + const query = interaction.buildQuery(); + const queryResponse = await this.networkProvider.queryContract(query); + const endpointDefinition = interaction.getEndpoint(); + const { firstValue, returnCode } = new ResultsParser().parseQueryResponse( + queryResponse, + endpointDefinition + ); + if (returnCode.isSuccess()) { + return firstValue?.valueOf().toNumber(); + } else { + throw new ErrContractQuery( + 'viewTotalCompensations', + returnCode.toString() + ); + } + } + /** * Returns a `Bond` object array for the given indexes * @param start_index index to start From f69074892d1fde88f8457d4acf7d1d3ffd48fa8d Mon Sep 17 00:00:00 2001 From: Bucur David Date: Thu, 7 Mar 2024 08:00:42 +0200 Subject: [PATCH 2/2] fix: new updated version of bond abi Refs: #99 --- src/abis/core-mx-life-bonding-sc.abi.json | 346 ++++++++++++++++++++++ 1 file changed, 346 insertions(+) diff --git a/src/abis/core-mx-life-bonding-sc.abi.json b/src/abis/core-mx-life-bonding-sc.abi.json index aad89de..d6b224e 100644 --- a/src/abis/core-mx-life-bonding-sc.abi.json +++ b/src/abis/core-mx-life-bonding-sc.abi.json @@ -622,6 +622,352 @@ ] } ], + "events": [ + { + "identifier": "minimum_penalty_event", + "inputs": [ + { + "name": "value", + "type": "u64", + "indexed": true + } + ] + }, + { + "identifier": "maximum_penalty_event", + "inputs": [ + { + "name": "value", + "type": "u64", + "indexed": true + } + ] + }, + { + "identifier": "withdraw_penalty_event", + "inputs": [ + { + "name": "value", + "type": "u64", + "indexed": true + } + ] + }, + { + "identifier": "contract_state_event", + "inputs": [ + { + "name": "state", + "type": "State", + "indexed": true + } + ] + }, + { + "identifier": "bond_event", + "inputs": [ + { + "name": "bond", + "type": "Bond", + "indexed": true + } + ] + }, + { + "identifier": "compensation_event", + "inputs": [ + { + "name": "compensation", + "type": "Compensation", + "indexed": true + } + ] + }, + { + "identifier": "withdraw_event", + "inputs": [ + { + "name": "bond_id", + "type": "u64", + "indexed": true + }, + { + "name": "caller", + "type": "Address", + "indexed": true + }, + { + "name": "withdraw_amount", + "type": "BigUint", + "indexed": true + }, + { + "name": "penalty_amount", + "type": "BigUint", + "indexed": true + } + ] + }, + { + "identifier": "renew_event", + "inputs": [ + { + "name": "bond_id", + "type": "u64", + "indexed": true + }, + { + "name": "caller", + "type": "Address", + "indexed": true + }, + { + "name": "unbound_timestmap", + "type": "u64", + "indexed": true + } + ] + }, + { + "identifier": "proof_event", + "inputs": [ + { + "name": "compensation_id", + "type": "u64", + "indexed": true + }, + { + "name": "token_identifier", + "type": "TokenIdentifier", + "indexed": true + }, + { + "name": "nonce", + "type": "u64", + "indexed": true + }, + { + "name": "proof_amount", + "type": "BigUint" + } + ] + }, + { + "identifier": "claim_refund_event", + "inputs": [ + { + "name": "compensation_id", + "type": "u64", + "indexed": true + }, + { + "name": "caller", + "type": "Address", + "indexed": true + }, + { + "name": "token_identifier", + "type": "TokenIdentifier", + "indexed": true + }, + { + "name": "nonce", + "type": "u64", + "indexed": true + }, + { + "name": "amount", + "type": "BigUint", + "indexed": true + }, + { + "name": "refund_token_identifier", + "type": "TokenIdentifier", + "indexed": true + }, + { + "name": "refund_token_nonce", + "type": "u64", + "indexed": true + }, + { + "name": "refund_amount", + "type": "BigUint", + "indexed": true + } + ] + }, + { + "identifier": "add_to_blacklist_event", + "inputs": [ + { + "name": "compensation_id", + "type": "u64", + "indexed": true + }, + { + "name": "addresses", + "type": "variadic
", + "indexed": true + } + ] + }, + { + "identifier": "remove_from_blacklist_event", + "inputs": [ + { + "name": "compensation_id", + "type": "u64", + "indexed": true + }, + { + "name": "addresses", + "type": "variadic
", + "indexed": true + } + ] + }, + { + "identifier": "initiate_refund_event", + "inputs": [ + { + "name": "compensation_id", + "type": "u64", + "indexed": true + }, + { + "name": "token_identifier", + "type": "TokenIdentifier", + "indexed": true + }, + { + "name": "nonce", + "type": "u64", + "indexed": true + }, + { + "name": "timestamp", + "type": "u64", + "indexed": true + } + ] + }, + { + "identifier": "sanction_event", + "inputs": [ + { + "name": "bond_id", + "type": "u64", + "indexed": true + }, + { + "name": "compensation_id", + "type": "u64", + "indexed": true + }, + { + "name": "token_identifier", + "type": "TokenIdentifier", + "indexed": true + }, + { + "name": "nonce", + "type": "u64", + "indexed": true + }, + { + "name": "penalty_amount", + "type": "BigUint", + "indexed": true + } + ] + }, + { + "identifier": "modify_bond_event", + "inputs": [ + { + "name": "bond_id", + "type": "u64", + "indexed": true + }, + { + "name": "unbound_timestamp", + "type": "u64", + "indexed": true + } + ] + }, + { + "identifier": "set_accepted_callers_event", + "inputs": [ + { + "name": "callers", + "type": "variadic
", + "indexed": true + } + ] + }, + { + "identifier": "remove_accepted_callers_event", + "inputs": [ + { + "name": "callers", + "type": "variadic
", + "indexed": true + } + ] + }, + { + "identifier": "set_bond_token_event", + "inputs": [ + { + "name": "token_identifier", + "type": "TokenIdentifier", + "indexed": true + } + ] + }, + { + "identifier": "set_period_and_bond_event", + "inputs": [ + { + "name": "period", + "type": "u64", + "indexed": true + }, + { + "name": "bond", + "type": "BigUint", + "indexed": true + } + ] + }, + { + "identifier": "remove_period_and_bond_event", + "inputs": [ + { + "name": "period", + "type": "u64", + "indexed": true + }, + { + "name": "bond", + "type": "BigUint", + "indexed": true + } + ] + }, + { + "identifier": "set_administrator_event", + "inputs": [ + { + "name": "administrator", + "type": "Address", + "indexed": true + } + ] + } + ], "esdtAttributes": [], "hasCallback": false, "types": {