Skip to content

cl4r : Redeem ids #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()

})
})