From 7813b6ac5521bb373ecc4d6686738027d2d09236 Mon Sep 17 00:00:00 2001 From: orenyodfat Date: Sun, 17 Jan 2021 18:55:03 +0200 Subject: [PATCH] cl4r : Redeem ids (#578) * Package version 0.2.86 * cl4r redeem for multiple lockingIds * same redeemer address for all networks * lint --- package-lock.json | 122 ++++++++++++++++++------------------- package.json | 2 +- src/schemes/cl4rep.ts | 72 +++++++++++++++++++--- test/scheme-cl4rep.spec.ts | 1 - 4 files changed, 127 insertions(+), 70 deletions(-) diff --git a/package-lock.json b/package-lock.json index 798f3510..eb27d9d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc.js", - "version": "0.2.86", + "version": "0.2.87", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -474,9 +474,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==", + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==", "dev": true }, "bn.js": { @@ -644,9 +644,9 @@ }, "dependencies": { "@types/node": { - "version": "10.17.50", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.50.tgz", - "integrity": "sha512-vwX+/ija9xKc/z9VqMCdbf4WYcMTGsI0I/L/6shIF3qXURxZOhPQlPRHtjTpiNhAwn0paMJzlOQqw6mAGEQnTA==", + "version": "10.17.51", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.51.tgz", + "integrity": "sha512-KANw+MkL626tq90l++hGelbl67irOJzGhUJk6a1Bt8QHOeh9tztJx+L0AqttraWKinmZn7Qi5lJZJzx45Gq0dg==", "dev": true } } @@ -1787,9 +1787,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==", + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==", "dev": true } } @@ -1821,9 +1821,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==", + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==", "dev": true } } @@ -2009,9 +2009,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==", + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==", "dev": true } } @@ -2166,9 +2166,9 @@ } }, "@ethersproject/abstract-signer": { - "version": "5.0.10", - "resolved": "https://registry.npmjs.org/@ethersproject/abstract-signer/-/abstract-signer-5.0.10.tgz", - "integrity": "sha512-irx7kH7FDAeW7QChDPW19WsxqeB1d3XLyOLSXm0bfPqL1SS07LXWltBJUBUxqC03ORpAOcM3JQj57DU8JnVY2g==", + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/@ethersproject/abstract-signer/-/abstract-signer-5.0.11.tgz", + "integrity": "sha512-RKOgPSEYafknA62SrD3OCK42AllHE4YBfKYXyQeM+sBP7Nq3X5FpzeoY4uzC43P4wIhmNoTHCKQuwnX7fBqb6Q==", "requires": { "@ethersproject/abstract-provider": "^5.0.8", "@ethersproject/bignumber": "^5.0.13", @@ -3186,9 +3186,9 @@ "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==" }, "@sinonjs/commons": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz", - "integrity": "sha512-892K+kWUUi3cl+LlqEWIDrhvLgdL79tECi8JZUyq6IviKy/DNhuzCRlbHUjxK89f4ypPMMaFnFuR9Ie6DoIMsw==", + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz", + "integrity": "sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw==", "dev": true, "requires": { "type-detect": "4.0.8" @@ -3258,9 +3258,9 @@ }, "dependencies": { "@types/node": { - "version": "14.14.20", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz", - "integrity": "sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==" + "version": "14.14.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.21.tgz", + "integrity": "sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==" } } }, @@ -3280,9 +3280,9 @@ "dev": true }, "@types/express-serve-static-core": { - "version": "4.17.17", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.17.tgz", - "integrity": "sha512-YYlVaCni5dnHc+bLZfY908IG1+x5xuibKZMGv8srKkvtul3wUuanYvpIj9GXXoWkQbaAdR+kgX46IETKUALWNQ==", + "version": "4.17.18", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.18.tgz", + "integrity": "sha512-m4JTwx5RUBNZvky/JJ8swEJPKFd8si08pPF2PfizYjGZOKr/svUWPcoUmLow6MmPzhasphB7gSTINY67xn3JNA==", "dev": true, "requires": { "@types/node": "*", @@ -3425,9 +3425,9 @@ "dev": true }, "@types/node": { - "version": "10.17.50", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.50.tgz", - "integrity": "sha512-vwX+/ija9xKc/z9VqMCdbf4WYcMTGsI0I/L/6shIF3qXURxZOhPQlPRHtjTpiNhAwn0paMJzlOQqw6mAGEQnTA==", + "version": "10.17.51", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.51.tgz", + "integrity": "sha512-KANw+MkL626tq90l++hGelbl67irOJzGhUJk6a1Bt8QHOeh9tztJx+L0AqttraWKinmZn7Qi5lJZJzx45Gq0dg==", "dev": true }, "@types/normalize-package-data": { @@ -3451,9 +3451,9 @@ }, "dependencies": { "@types/node": { - "version": "14.14.20", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz", - "integrity": "sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==" + "version": "14.14.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.21.tgz", + "integrity": "sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==" } } }, @@ -3484,9 +3484,9 @@ }, "dependencies": { "@types/node": { - "version": "14.14.20", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz", - "integrity": "sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==" + "version": "14.14.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.21.tgz", + "integrity": "sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==" } } }, @@ -3575,9 +3575,9 @@ }, "dependencies": { "@types/node": { - "version": "14.14.20", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz", - "integrity": "sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==" + "version": "14.14.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.21.tgz", + "integrity": "sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==" } } }, @@ -4592,9 +4592,9 @@ "integrity": "sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA==" }, "binary-extensions": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz", - "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, "binaryen": { @@ -5036,9 +5036,9 @@ } }, "call-bind": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.1.tgz", - "integrity": "sha512-tvAvUwNcRikl3RVF20X9lsYmmepsovzTWeJiXjO0PkJp15uy/6xKFZOQtuiSULwYW+6ToZBprphCgWXC2dSgcQ==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", "dev": true, "requires": { "function-bind": "^1.1.1", @@ -5140,9 +5140,9 @@ } }, "chokidar": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.0.tgz", - "integrity": "sha512-JgQM9JS92ZbFR4P90EvmzNpSGhpPBGBSj10PILeDyYFwp4h2/D9OM03wsJ4zW1fEp4ka2DGrnUeD7FuvQ2aZ2Q==", + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz", + "integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==", "dev": true, "requires": { "anymatch": "~3.1.1", @@ -10107,9 +10107,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==", + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==", "dev": true }, "JSONStream": { @@ -20205,9 +20205,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==" + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==" } } }, @@ -20226,9 +20226,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==" + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==" } } }, @@ -20419,9 +20419,9 @@ }, "dependencies": { "@types/node": { - "version": "12.19.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.12.tgz", - "integrity": "sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw==" + "version": "12.19.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.14.tgz", + "integrity": "sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==" } } }, diff --git a/package.json b/package.json index 0fd35c29..3e65fd9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc.js", - "version": "0.2.86", + "version": "0.2.87", "description": "", "keywords": [], "main": "dist/lib/index.js", diff --git a/src/schemes/cl4rep.ts b/src/schemes/cl4rep.ts index 8d5904a0..1e50e0df 100644 --- a/src/schemes/cl4rep.ts +++ b/src/schemes/cl4rep.ts @@ -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) { @@ -148,18 +186,30 @@ export class CL4RScheme { return toIOperationObservable(observable) } - public redeem(beneficiary: Address, lockingId: number): Operation { + /** + * 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 { 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 { @@ -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 } diff --git a/test/scheme-cl4rep.spec.ts b/test/scheme-cl4rep.spec.ts index 2bd1876d..b782e30a 100644 --- a/test/scheme-cl4rep.spec.ts +++ b/test/scheme-cl4rep.spec.ts @@ -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() - }) })