Skip to content

Commit 7813b6a

Browse files
authored
cl4r : Redeem ids (#578)
* Package version 0.2.86 * cl4r redeem for multiple lockingIds * same redeemer address for all networks * lint
1 parent 226459e commit 7813b6a

File tree

4 files changed

+127
-70
lines changed

4 files changed

+127
-70
lines changed

Diff for: package-lock.json

+61-61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/arc.js",
3-
"version": "0.2.86",
3+
"version": "0.2.87",
44
"description": "",
55
"keywords": [],
66
"main": "dist/lib/index.js",

Diff for: src/schemes/cl4rep.ts

+65-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,44 @@ import { Address } from '../types'
1313

1414
import { Scheme } from '../scheme'
1515

16+
// same address for all networks (mainnet,kovan,xdai,rinkeby)
17+
const CT4RRedeemerAddress = '0x829BDfd41d517f57E5eBf13AD0E181351cb16a96'
18+
19+
const CT4RRedeemerABI = [
20+
{
21+
constant: false,
22+
inputs: [
23+
{
24+
internalType: 'contract ContinuousLocking4Reputation',
25+
name: 'clt4Reputation',
26+
type: 'address'
27+
},
28+
{
29+
components: [
30+
{
31+
internalType: 'address',
32+
name: 'beneficiary',
33+
type: 'address'
34+
},
35+
{
36+
internalType: 'uint256',
37+
name: 'id',
38+
type: 'uint256'
39+
}
40+
],
41+
internalType: 'struct NectarReputationRedeemer.Redeem[]',
42+
name: 'clt4rRedeems',
43+
type: 'tuple[]'
44+
}
45+
],
46+
name: 'redeemContinuousLocking4Reputation',
47+
outputs: [],
48+
payable: false,
49+
stateMutability: 'nonpayable',
50+
type: 'function'
51+
}
52+
]
53+
1654
export class CL4RScheme {
1755

1856
constructor(public scheme: Scheme) {
@@ -148,18 +186,30 @@ export class CL4RScheme {
148186
return toIOperationObservable(observable)
149187
}
150188

151-
public redeem(beneficiary: Address, lockingId: number): Operation<any> {
189+
/**
190+
* redeem redeem reputation for a beneficiary for all is lockingIds
191+
* @param beneficiary
192+
* @param lockingIds
193+
* @param network network is a optional.
194+
* @return RepuationRewardForBatch
195+
*/
196+
public redeem(beneficiary: Address, lockingIds: number[], ct4rRedeemerAddress?: Address): Operation<any> {
152197
const mapReceipt = (receipt: any) => {
153198
return receipt
154199
}
155200

156-
const observable = from(this.getContract())
201+
const ctl4rReedeems: any = []
202+
for (const lockingId of lockingIds) {
203+
ctl4rReedeems.push({beneficiary, id: lockingId.toString()})
204+
}
205+
206+
const observable = from(this.getCT4RRedeemer(ct4rRedeemerAddress ? ct4rRedeemerAddress : CT4RRedeemerAddress))
157207
.pipe(
158208
concatMap((contract) => {
159209
let transaction: any
160-
transaction = contract.methods.redeem(
161-
beneficiary,
162-
lockingId
210+
transaction = contract.methods.redeemContinuousLocking4Reputation(
211+
(this.scheme.staticState as any).address,
212+
ctl4rReedeems
163213
)
164214
const errorHandler = async (error: Error) => {
165215
try {
@@ -176,12 +226,20 @@ export class CL4RScheme {
176226
}
177227

178228
public async getContract() {
179-
const state = await this.scheme.fetchStaticState()
229+
const address = await this.getContractAddress()
180230
await this.scheme.context.fetchContractInfos({fetchPolicy: 'network-only'})
181-
const contract = this.scheme.context.getContract(state.address)
231+
const contract = this.scheme.context.getContract(address)
182232
return contract
183233
}
184234

235+
public async getContractAddress() {
236+
return (await this.scheme.fetchStaticState()).address
237+
}
238+
239+
public async getCT4RRedeemer(ct4rRedeemerAddress?: Address) {
240+
return await new this.scheme.context.web3.eth.Contract(CT4RRedeemerABI, ct4rRedeemerAddress)
241+
}
242+
185243
public getScheme() {
186244
return this.scheme
187245
}

Diff for: test/scheme-cl4rep.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,5 @@ describe('Scheme', () => {
121121
expect(repreward).toEqual(reputationRewardPerPeriod)
122122
expect(await cl4r.getRepuationRewardForBatch(A,B,0)).toEqual(reputationRewardPerPeriod)
123123
await cl4r.extendLocking(2,0,lockCounterAfter,agreementHash).send()
124-
125124
})
126125
})

0 commit comments

Comments
 (0)