Skip to content

Commit

Permalink
Add redeem to CL4R (#577)
Browse files Browse the repository at this point in the history
* Package version 0.2.85

* add redeem to cl4rep

* bump version

* update jest-ts
  • Loading branch information
orenyodfat authored Jan 16, 2021
1 parent ec64c17 commit 226459e
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 28 deletions.
179 changes: 154 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc.js",
"version": "0.2.85",
"version": "0.2.86",
"description": "",
"keywords": [],
"main": "dist/lib/index.js",
Expand Down Expand Up @@ -95,7 +95,7 @@
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.20.1",
"ts-jest": "^24.0.2",
"ts-jest": "^26.4.4",
"ts-node": "^7.0.1",
"tslint": "^5.18.0",
"tslint-config-standard": "^8.0.1",
Expand Down
28 changes: 27 additions & 1 deletion src/schemes/cl4rep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class CL4RScheme {
const constB = new Decimal(realMathToNumber(new BN(repRewardConstB)))
const constA = new Decimal(realMathToBN(new BN(repRewardConstA)).toString())
return constA.times(constB.toPower(batchIndex))

}

public async getAgreementHash(): Promise<string> {
Expand Down Expand Up @@ -149,6 +148,33 @@ export class CL4RScheme {
return toIOperationObservable(observable)
}

public redeem(beneficiary: Address, lockingId: number): Operation<any> {
const mapReceipt = (receipt: any) => {
return receipt
}

const observable = from(this.getContract())
.pipe(
concatMap((contract) => {
let transaction: any
transaction = contract.methods.redeem(
beneficiary,
lockingId
)
const errorHandler = async (error: Error) => {
try {
await transaction.call()
} catch (err) {
throw err
}
return error
}
return this.scheme.context.sendTransaction(transaction, mapReceipt, errorHandler)
})
)
return toIOperationObservable(observable)
}

public async getContract() {
const state = await this.scheme.fetchStaticState()
await this.scheme.context.fetchContractInfos({fetchPolicy: 'network-only'})
Expand Down

0 comments on commit 226459e

Please sign in to comment.