Skip to content

Commit

Permalink
cl4r : Redeem ids (#578)
Browse files Browse the repository at this point in the history
* Package version 0.2.86

* cl4r redeem for multiple lockingIds

* same redeemer address for all networks

* lint
  • Loading branch information
orenyodfat authored Jan 17, 2021
1 parent 226459e commit 7813b6a
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 70 deletions.
122 changes: 61 additions & 61 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc.js",
"version": "0.2.86",
"version": "0.2.87",
"description": "",
"keywords": [],
"main": "dist/lib/index.js",
Expand Down
72 changes: 65 additions & 7 deletions src/schemes/cl4rep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,44 @@ import { Address } from '../types'

import { Scheme } from '../scheme'

// same address for all networks (mainnet,kovan,xdai,rinkeby)
const CT4RRedeemerAddress = '0x829BDfd41d517f57E5eBf13AD0E181351cb16a96'

const CT4RRedeemerABI = [
{
constant: false,
inputs: [
{
internalType: 'contract ContinuousLocking4Reputation',
name: 'clt4Reputation',
type: 'address'
},
{
components: [
{
internalType: 'address',
name: 'beneficiary',
type: 'address'
},
{
internalType: 'uint256',
name: 'id',
type: 'uint256'
}
],
internalType: 'struct NectarReputationRedeemer.Redeem[]',
name: 'clt4rRedeems',
type: 'tuple[]'
}
],
name: 'redeemContinuousLocking4Reputation',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
}
]

export class CL4RScheme {

constructor(public scheme: Scheme) {
Expand Down Expand Up @@ -148,18 +186,30 @@ export class CL4RScheme {
return toIOperationObservable(observable)
}

public redeem(beneficiary: Address, lockingId: number): Operation<any> {
/**
* redeem redeem reputation for a beneficiary for all is lockingIds
* @param beneficiary
* @param lockingIds
* @param network network is a optional.
* @return RepuationRewardForBatch
*/
public redeem(beneficiary: Address, lockingIds: number[], ct4rRedeemerAddress?: Address): Operation<any> {
const mapReceipt = (receipt: any) => {
return receipt
}

const observable = from(this.getContract())
const ctl4rReedeems: any = []
for (const lockingId of lockingIds) {
ctl4rReedeems.push({beneficiary, id: lockingId.toString()})
}

const observable = from(this.getCT4RRedeemer(ct4rRedeemerAddress ? ct4rRedeemerAddress : CT4RRedeemerAddress))
.pipe(
concatMap((contract) => {
let transaction: any
transaction = contract.methods.redeem(
beneficiary,
lockingId
transaction = contract.methods.redeemContinuousLocking4Reputation(
(this.scheme.staticState as any).address,
ctl4rReedeems
)
const errorHandler = async (error: Error) => {
try {
Expand All @@ -176,12 +226,20 @@ export class CL4RScheme {
}

public async getContract() {
const state = await this.scheme.fetchStaticState()
const address = await this.getContractAddress()
await this.scheme.context.fetchContractInfos({fetchPolicy: 'network-only'})
const contract = this.scheme.context.getContract(state.address)
const contract = this.scheme.context.getContract(address)
return contract
}

public async getContractAddress() {
return (await this.scheme.fetchStaticState()).address
}

public async getCT4RRedeemer(ct4rRedeemerAddress?: Address) {
return await new this.scheme.context.web3.eth.Contract(CT4RRedeemerABI, ct4rRedeemerAddress)
}

public getScheme() {
return this.scheme
}
Expand Down
1 change: 0 additions & 1 deletion test/scheme-cl4rep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,5 @@ describe('Scheme', () => {
expect(repreward).toEqual(reputationRewardPerPeriod)
expect(await cl4r.getRepuationRewardForBatch(A,B,0)).toEqual(reputationRewardPerPeriod)
await cl4r.extendLocking(2,0,lockCounterAfter,agreementHash).send()

})
})

0 comments on commit 7813b6a

Please sign in to comment.