Skip to content

Commit

Permalink
feat: bond contract update for stake
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Jul 6, 2024
1 parent 7af934d commit e3785e9
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 13 deletions.
64 changes: 51 additions & 13 deletions src/abis/core-mx-life-bonding-sc.abi.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
{
"buildInfo": {
"rustc": {
"version": "1.76.0-nightly",
"commitHash": "d86d65bbc19b928387f68427fcc3a0da498d8a19",
"commitDate": "2023-12-10",
"channel": "Nightly",
"short": "rustc 1.76.0-nightly (d86d65bbc 2023-12-10)"
"version": "1.78.0",
"commitHash": "9b00956e56009bab2aa15d7bff10916599e3d6d6",
"commitDate": "2024-04-29",
"channel": "Stable",
"short": "rustc 1.78.0 (9b00956e5 2024-04-29)"
},
"contractCrate": {
"name": "core-mx-life-bonding-sc",
"version": "1.0.0"
"version": "2.0.0"
},
"framework": {
"name": "multiversx-sc",
"version": "0.47.8"
"version": "0.51.0"
}
},
"name": "LifeBondingContract",
"constructor": {
"inputs": [],
"outputs": []
},
"upgradeConstructor": {
"inputs": [],
"outputs": []
},
"endpoints": [
{
"name": "upgrade",
"mutability": "mutable",
"inputs": [],
"outputs": []
},
{
"name": "bond",
"mutability": "mutable",
Expand Down Expand Up @@ -124,6 +122,16 @@
}
]
},
{
"name": "getTotalBondAmount",
"mutability": "readonly",
"inputs": [],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "getBond",
"mutability": "readonly",
Expand Down Expand Up @@ -279,6 +287,36 @@
}
]
},
{
"name": "getAddressBondsAvgScore",
"mutability": "readonly",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "getAddressBondsTotalValue",
"mutability": "readonly",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "getAllBonds",
"mutability": "readonly",
Expand Down
71 changes: 71 additions & 0 deletions src/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,77 @@ export class BondContract extends Contract {
}
}

/**
* Returns the total bond amount
*/
async viewTotalBondAmount(): Promise<BigNumber.Value> {
const interaction = this.contract.methodsExplicit.getTotalBondAmount([]);
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 BigNumber(firstValue?.valueOf());
} else {
throw new ErrContractQuery('viewTotalBondAmount', returnCode.toString());
}
}

/**
* Returns the total bond amount for a specific address
* @param address address to query
*/
async viewAddressTotalBondAmount(
address: IAddress
): Promise<BigNumber.Value> {
const interaction = this.contract.methodsExplicit.getAddressBondsTotalValue(
[new AddressValue(address)]
);
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 BigNumber(firstValue?.valueOf());
} else {
throw new ErrContractQuery(
'viewAddressTotalBondAmount',
returnCode.toString()
);
}
}

/**
* Returns the average liveliness score for a specific address
* @param address address to query
*/
async viewAddressAvgLivelinessScore(address: IAddress): Promise<number> {
const interaction = this.contract.methodsExplicit.getAddressBondsAvgScore([
new AddressValue(address)
]);
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 BigNumber(firstValue?.valueOf()).div(10000).toNumber();
} else {
throw new ErrContractQuery(
'viewAddressAvgLivelinessScore',
returnCode.toString()
);
}
}

/**
* Returns the contract owner address
*/
Expand Down

0 comments on commit e3785e9

Please sign in to comment.