From 1b79726ba48b7bb7041e9acd6366b32cf34a12b7 Mon Sep 17 00:00:00 2001 From: Joao Pedro da Silva Date: Mon, 18 Jul 2022 22:06:29 -0300 Subject: [PATCH 1/5] fix list valid communities by ambassador address --- .../core/src/services/ubi/community/list.ts | 23 +++++++++++++--- .../core/src/subgraph/queries/community.ts | 27 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/packages/core/src/services/ubi/community/list.ts b/packages/core/src/services/ubi/community/list.ts index c6be15c72..eb14681d9 100644 --- a/packages/core/src/services/ubi/community/list.ts +++ b/packages/core/src/services/ubi/community/list.ts @@ -10,6 +10,7 @@ import { UbiCommunityLabel } from '../../../interfaces/ubi/ubiCommunityLabel'; import { getCommunityProposal, communityEntities, + getAmbassadorByAddress, } from '../../../subgraph/queries/community'; import { BaseError } from '../../../utils/baseError'; import { fetchData } from '../../../utils/dataFetching'; @@ -125,10 +126,24 @@ export class CommunityListService { } if (query.ambassadorAddress) { - extendedWhere = { - ...extendedWhere, - ambassadorAddress: query.ambassadorAddress, - }; + if (query.status === 'pending') { + extendedWhere = { + ...extendedWhere, + ambassadorAddress: query.ambassadorAddress, + }; + } else { + const ambassador = await getAmbassadorByAddress(query.ambassadorAddress); + if (!ambassador || !ambassador.communities) { + return { + count: 0, + rows: [], + }; + } + extendedWhere = { + ...extendedWhere, + contractAddress: { [Op.in]: ambassador.communities.map((address: string) => ethers.utils.getAddress(address)) }, + }; + } } if (query.orderBy) { diff --git a/packages/core/src/subgraph/queries/community.ts b/packages/core/src/subgraph/queries/community.ts index 55163ef23..81c7ece70 100644 --- a/packages/core/src/subgraph/queries/community.ts +++ b/packages/core/src/subgraph/queries/community.ts @@ -239,6 +239,33 @@ export const getCommunityAmbassador = async (community: string) => { } }; +export const getAmbassadorByAddress = async (ambassadorAddress: string) => { + try { + const query = gql` + { + ambassadorEntities( + where:{ + id: "${ambassadorAddress.toLocaleLowerCase()}" + status: 0 + } + ) { + id + communities + } + } + `; + + const queryResult = await clientCouncil.query({ + query, + fetchPolicy: 'no-cache', + }); + + return queryResult.data?.ambassadorEntities[0]; + } catch (error) { + throw new Error(error); + } +}; + export const getCommunityStateByAddresses = async ( addresses: string[] ): Promise< From b03188488b6ec0956abeb5738044cdef189bc146 Mon Sep 17 00:00:00 2001 From: Joao Pedro da Silva Date: Wed, 20 Jul 2022 19:11:00 -0300 Subject: [PATCH 2/5] add max and min tranche and update contract fields --- .../api/src/routes/v2/community/create.ts | 12 + .../z1658255456-update-communityContract.js | 48 ++++ .../database/models/ubi/communityContract.ts | 29 ++- .../interfaces/ubi/ubiCommunityContract.ts | 16 +- packages/core/src/services/ubi/community.ts | 105 ++++++-- .../src/services/ubi/community/contract.ts | 67 ++++- .../src/services/ubi/community/details.ts | 34 ++- .../core/src/services/ubi/community/list.ts | 10 +- .../src/services/ubi/communityContract.ts | 67 ++++- .../core/src/subgraph/queries/community.ts | 3 + packages/core/src/types.ts | 8 +- packages/core/tests/factories/claim.ts | 2 +- packages/core/tests/factories/community.ts | 6 +- packages/core/tests/fake/community.ts | 24 +- .../tests/integration/beneficiary.test.ts | 20 +- .../tests/integration/claimLocation.test.ts | 16 +- .../core/tests/integration/community.test.ts | 244 +++++++++--------- .../core/tests/integration/manager.test.ts | 4 +- packages/core/tests/integration/story.test.ts | 16 +- packages/core/tests/integration/user.test.ts | 12 +- .../tests/integration/v2/community.test.ts | 204 +++++++-------- .../core/tests/integration/v2/user.test.ts | 8 +- .../unit/services/globalDemographics.test.ts | 2 +- packages/worker/src/jobs/chainSubscribers.ts | 13 +- packages/worker/src/jobs/cron/community.ts | 1 - packages/worker/src/jobs/cron/global.ts | 4 +- .../cron/calcuateCommunitiesMetrics.test.ts | 12 +- .../cron/calcuateGlobalMetrics.test.ts | 60 ++--- .../cron/verifyDeletedAccounts.test.ts | 8 +- 29 files changed, 672 insertions(+), 383 deletions(-) create mode 100644 packages/core/src/database/migrations/z1658255456-update-communityContract.js diff --git a/packages/api/src/routes/v2/community/create.ts b/packages/api/src/routes/v2/community/create.ts index e962d8f52..927cc7422 100644 --- a/packages/api/src/routes/v2/community/create.ts +++ b/packages/api/src/routes/v2/community/create.ts @@ -81,6 +81,12 @@ export default (route: Router): void => { * incrementInterval: * type: number * required: true + * minTranche: + * type: number + * required: false + * maxTranche: + * type: number + * required: false * placeId: * type: string * required: false @@ -157,6 +163,12 @@ export default (route: Router): void => { * type: number * incrementInterval: * type: number + * minTranche: + * type: number + * required: false + * maxTranche: + * type: number + * required: false * placeId: * type: string * required: false diff --git a/packages/core/src/database/migrations/z1658255456-update-communityContract.js b/packages/core/src/database/migrations/z1658255456-update-communityContract.js new file mode 100644 index 000000000..b12e18975 --- /dev/null +++ b/packages/core/src/database/migrations/z1658255456-update-communityContract.js @@ -0,0 +1,48 @@ +'use strict'; + +// eslint-disable-next-line no-undef +module.exports = { + async up(queryInterface, Sequelize) { + if (process.env.NODE_ENV === 'test') { + return; + } + + // add new fields + await queryInterface.addColumn('ubi_community_contract', 'minTranche', { + type: Sequelize.FLOAT, + allowNull: true, + }); + await queryInterface.addColumn('ubi_community_contract', 'maxTranche', { + type: Sequelize.FLOAT, + allowNull: true, + }); + + // change fields type + await queryInterface.changeColumn('ubi_community_contract', 'maxClaim', { + type: Sequelize.FLOAT, + allowNull: false, + }); + await queryInterface.changeColumn('ubi_community_contract', 'claimAmount', { + type: Sequelize.FLOAT, + allowNull: false, + }); + await queryInterface.changeColumn('ubi_community_contract', 'decreaseStep', { + type: Sequelize.FLOAT, + allowNull: false, + }); + + // convert wei to ether + const query = ` + UPDATE ubi_community_contract + SET "maxClaim" = contract."maxClaim", "claimAmount" = contract."claimAmount", "decreaseStep" = contract."decreaseStep" + FROM (SELECT "maxClaim" / (10^18) as "maxClaim", "claimAmount" / (10^18) as "claimAmount", "decreaseStep" / (10^18) as "decreaseStep", "communityId" as community from ubi_community_contract) contract + WHERE contract."community" = "communityId"`; + + await queryInterface.sequelize.query(query, { + raw: true, + type: Sequelize.QueryTypes.UPDATE, + }); + }, + + down(queryInterface, Sequelize) {}, +}; diff --git a/packages/core/src/database/models/ubi/communityContract.ts b/packages/core/src/database/models/ubi/communityContract.ts index 27955c898..57e86f791 100644 --- a/packages/core/src/database/models/ubi/communityContract.ts +++ b/packages/core/src/database/models/ubi/communityContract.ts @@ -15,18 +15,27 @@ import { * - communityId * - claimAmount * - maxClaim + * - minTranche + * - maxTranche * - baseInterval * - incrementInterval + * - decreaseStep * properties: * communityId: * type: integer * description: The community id * claimAmount: - * type: string + * type: number * description: Amount per claim, same as in contract with 18 decimals * maxClaim: - * type: string + * type: number * description: Maximum claim per beneficiary, same as in contract with 18 decimals + * minTranche: + * type: number + * maxTranche: + * type: number + * decreaseStep: + * type: number * baseInterval: * type: integer * description: Base interval between claims @@ -39,12 +48,14 @@ export class UbiCommunityContractModel extends Model< UbiCommunityContractCreation > { public communityId!: number; - public claimAmount!: string; - public maxClaim!: string; + public claimAmount!: number; + public maxClaim!: number; public baseInterval!: number; public incrementInterval!: number; public blocked!: boolean; - public decreaseStep!: string; + public decreaseStep!: number; + public minTranche!: number; + public maxTranche!: number; // timestamps! public readonly createdAt!: Date; @@ -93,6 +104,14 @@ export function initializeUbiCommunityContract(sequelize: Sequelize): void { allowNull: false, defaultValue: 0, }, + minTranche: { + type: DataTypes.INTEGER, + allowNull: true, + }, + maxTranche: { + type: DataTypes.INTEGER, + allowNull: true, + }, createdAt: { allowNull: false, type: DataTypes.DATE, diff --git a/packages/core/src/interfaces/ubi/ubiCommunityContract.ts b/packages/core/src/interfaces/ubi/ubiCommunityContract.ts index f36ad6f25..5663c511a 100644 --- a/packages/core/src/interfaces/ubi/ubiCommunityContract.ts +++ b/packages/core/src/interfaces/ubi/ubiCommunityContract.ts @@ -29,12 +29,14 @@ */ export interface UbiCommunityContract { communityId: number; - claimAmount: string; - maxClaim: string; + claimAmount: number; + maxClaim: number; baseInterval: number; incrementInterval: number; blocked?: boolean; - decreaseStep?: string; + decreaseStep?: number; + minTranche?: number; + maxTranche?: number; // timestamps createdAt: Date; @@ -43,10 +45,12 @@ export interface UbiCommunityContract { export interface UbiCommunityContractCreation { communityId: number; - claimAmount: string; - maxClaim: string; + claimAmount: number; + maxClaim: number; baseInterval: number; incrementInterval: number; blocked?: boolean; - decreaseStep?: string; + decreaseStep?: number; + minTranche?: number; + maxTranche?: number; } diff --git a/packages/core/src/services/ubi/community.ts b/packages/core/src/services/ubi/community.ts index 9babe8950..d4cc506fa 100644 --- a/packages/core/src/services/ubi/community.ts +++ b/packages/core/src/services/ubi/community.ts @@ -489,16 +489,18 @@ export default class CommunityService { } } } else { - beneficiariesState = await this._getBeneficiaryState( - { - status: query.status, - limit: query.limit, - offset: query.offset, - }, - extendedWhere, - 'desc' - ); - communitiesId = beneficiariesState!.map((el) => el.id); + if (query.status !== 'pending') { + beneficiariesState = await this._getBeneficiaryState( + { + status: query.status, + limit: query.limit, + offset: query.offset, + }, + extendedWhere, + 'desc' + ); + communitiesId = beneficiariesState!.map((el) => el.id); + } } let include: Includeable[]; @@ -522,6 +524,7 @@ export default class CommunityService { attributes = { exclude, }; + if (query.status === 'pending') returnState = false; } const communityCount = await this.community.count({ @@ -719,8 +722,26 @@ export default class CommunityService { ); const raiseModel = inflowState?.find((el) => el.id === id); const backerModel = backerState?.find((el) => el.id === id); + const contract = community.contract + ? { + contract: { + ...community.contract, + maxClaim: new BigNumber( + community.contract.maxClaim + ) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + claimAmount: new BigNumber( + community.contract.claimAmount + ) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + }, + } + : {}; community = { ...community, + ...contract, state: { beneficiaries: beneficiariesModel ? Number(beneficiariesModel.beneficiaries) @@ -873,10 +894,20 @@ export default class CommunityService { }, raw: true, })) as any; + const resultJson = result!.toJSON(); return { - ...result!.toJSON(), + ...resultJson, state, reachedLastMonth, + contract: { + ...resultJson.contract, + maxClaim: new BigNumber(resultJson.contract!.maxClaim) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + claimAmount: new BigNumber(resultJson.contract!.claimAmount) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + }, } as CommunityAttributes & { reachedLastMonth: { reach: string; @@ -1071,9 +1102,18 @@ export default class CommunityService { communityId, }, }); - return result !== null - ? (result.toJSON() as UbiCommunityContract) - : null; + if (!result) return null; + + const resultJson = result.toJSON() as UbiCommunityContract; + return { + ...resultJson, + maxClaim: new BigNumber(resultJson.maxClaim) + .multipliedBy(10 ** config.cUSDDecimal) + .toString(), + claimAmount: new BigNumber(resultJson.claimAmount) + .multipliedBy(10 ** config.cUSDDecimal) + .toString(), + }; } public static async getState(communityId: number) { @@ -1678,6 +1718,15 @@ export default class CommunityService { const backerModel = backerState?.find((el) => el.id === id); community = { ...community, + contract: { + ...community.contract!, + maxClaim: new BigNumber(community.contract!.maxClaim) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + claimAmount: new BigNumber(community.contract!.claimAmount) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + }, state: { beneficiaries: beneficiariesModel ? Number(beneficiariesModel.beneficiaries) @@ -1778,7 +1827,21 @@ export default class CommunityService { }, order: orderOption, }); - return communitiesResult.map((c) => c.toJSON() as CommunityAttributes); + return communitiesResult.map((c) => { + const community = c.toJSON() as CommunityAttributes; + return { + ...community, + contract: { + ...community.contract!, + maxClaim: new BigNumber(community.contract!.maxClaim) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + claimAmount: new BigNumber(community.contract!.claimAmount) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + }, + }; + }); } /** @@ -1956,7 +2019,15 @@ export default class CommunityService { return { ...community, state: communityState!, - contract: communityContract!, + contract: { + ...communityContract!, + maxClaim: new BigNumber(communityContract!.maxClaim) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + claimAmount: new BigNumber(communityContract!.claimAmount) + .multipliedBy(10 ** config.cUSDDecimal) + .toString() as any, + }, metrics: communityDailyMetrics[0]!, } as any; } @@ -2161,7 +2232,7 @@ export default class CommunityService { ...community, email: showEmail ? community.email : '', suspect: suspect !== null ? [suspect] : undefined, - contract, + contract: contract as any, state, metrics: metrics !== null ? [metrics] : undefined, }; diff --git a/packages/core/src/services/ubi/community/contract.ts b/packages/core/src/services/ubi/community/contract.ts index 383829b3d..01e216988 100644 --- a/packages/core/src/services/ubi/community/contract.ts +++ b/packages/core/src/services/ubi/community/contract.ts @@ -1,3 +1,5 @@ +import { BigNumber } from 'bignumber.js'; +import config from '../../../config'; import { Transaction } from 'sequelize'; import { models, sequelize } from '../../../database'; @@ -10,15 +12,40 @@ export default class CommunityContractService { contractParams: ICommunityContractParams, t: Transaction | undefined = undefined ): Promise { - const { claimAmount, maxClaim, baseInterval, incrementInterval } = - contractParams; + let { + claimAmount, + maxClaim, + baseInterval, + incrementInterval, + decreaseStep, + minTranche, + maxTranche, + } = contractParams; + + if (typeof claimAmount === 'string' && claimAmount.length > 10) { + claimAmount = new BigNumber(claimAmount) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof maxClaim === 'string' && maxClaim.length > 10) { + maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + } + if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { + decreaseStep = new BigNumber(decreaseStep) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + return models.ubiCommunityContract.create( { communityId, - claimAmount, - maxClaim, + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, baseInterval, incrementInterval, + decreaseStep: decreaseStep as number, + minTranche, + maxTranche, }, { transaction: t } ); @@ -28,8 +55,29 @@ export default class CommunityContractService { communityId: number, contractParams: ICommunityContractParams ): Promise { - const { claimAmount, maxClaim, baseInterval, incrementInterval } = - contractParams; + let { + claimAmount, + maxClaim, + baseInterval, + incrementInterval, + decreaseStep, + minTranche, + maxTranche, + } = contractParams; + + if (typeof claimAmount === 'string' && claimAmount.length > 10) { + claimAmount = new BigNumber(claimAmount) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof maxClaim === 'string' && maxClaim.length > 10) { + maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + } + if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { + decreaseStep = new BigNumber(decreaseStep) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } const community = (await models.community.findOne({ attributes: ['publicId'], @@ -39,10 +87,13 @@ export default class CommunityContractService { await sequelize.transaction(async (t) => { await models.ubiCommunityContract.update( { - claimAmount, - maxClaim, + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, baseInterval, incrementInterval, + decreaseStep: decreaseStep as number, + minTranche, + maxTranche, }, { where: { communityId }, transaction: t } ); diff --git a/packages/core/src/services/ubi/community/details.ts b/packages/core/src/services/ubi/community/details.ts index 68879c115..7f6b4ab02 100644 --- a/packages/core/src/services/ubi/community/details.ts +++ b/packages/core/src/services/ubi/community/details.ts @@ -51,23 +51,39 @@ export class CommunityDetailsService { } public async getContract(communityId: number) { - const result = await models.ubiCommunityContract.findOne({ + const community = await models.community.findOne({ + attributes: ['contractAddress', 'status'], where: { - communityId, + id: communityId, }, }); - if (!result) { + if (!community) { return null; } - const contract = result.toJSON() as UbiCommunityContract; + if (community.status === 'pending') { + const result = await models.ubiCommunityContract.findOne({ + where: { + communityId, + }, + }); - return { - ...contract, - claimAmount: ethers.utils.formatEther(contract.claimAmount), - maxClaim: ethers.utils.formatEther(contract.maxClaim), - }; + if (!result) { + return null; + } + + return result.toJSON() as UbiCommunityContract; + } else { + const subgraphResult = await getCommunityUBIParams( + community.contractAddress! + ); + if (!subgraphResult) return null; + return { + ...subgraphResult, + communityId, + }; + } } public async getAmbassador(communityId: number) { diff --git a/packages/core/src/services/ubi/community/list.ts b/packages/core/src/services/ubi/community/list.ts index eb14681d9..070e675a5 100644 --- a/packages/core/src/services/ubi/community/list.ts +++ b/packages/core/src/services/ubi/community/list.ts @@ -132,7 +132,9 @@ export class CommunityListService { ambassadorAddress: query.ambassadorAddress, }; } else { - const ambassador = await getAmbassadorByAddress(query.ambassadorAddress); + const ambassador = await getAmbassadorByAddress( + query.ambassadorAddress + ); if (!ambassador || !ambassador.communities) { return { count: 0, @@ -141,7 +143,11 @@ export class CommunityListService { } extendedWhere = { ...extendedWhere, - contractAddress: { [Op.in]: ambassador.communities.map((address: string) => ethers.utils.getAddress(address)) }, + contractAddress: { + [Op.in]: ambassador.communities.map((address: string) => + ethers.utils.getAddress(address) + ), + }, }; } } diff --git a/packages/core/src/services/ubi/communityContract.ts b/packages/core/src/services/ubi/communityContract.ts index 30a114b27..f521ad938 100644 --- a/packages/core/src/services/ubi/communityContract.ts +++ b/packages/core/src/services/ubi/communityContract.ts @@ -1,3 +1,5 @@ +import BigNumber from 'bignumber.js'; +import config from '../../config'; import { Transaction } from 'sequelize'; import { models, sequelize } from '../../database'; @@ -15,15 +17,40 @@ export default class CommunityContractService { contractParams: ICommunityContractParams, t: Transaction | undefined = undefined ): Promise { - const { claimAmount, maxClaim, baseInterval, incrementInterval } = - contractParams; + let { + claimAmount, + maxClaim, + baseInterval, + incrementInterval, + decreaseStep, + minTranche, + maxTranche, + } = contractParams; + + if (typeof claimAmount === 'string' && claimAmount.length > 10) { + claimAmount = new BigNumber(claimAmount) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof maxClaim === 'string' && maxClaim.length > 10) { + maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + } + if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { + decreaseStep = new BigNumber(decreaseStep) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + return await this.ubiCommunityContract.create( { communityId, - claimAmount, - maxClaim, + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, baseInterval, incrementInterval, + minTranche, + maxTranche, + decreaseStep: decreaseStep as number, }, { transaction: t } ); @@ -33,8 +60,29 @@ export default class CommunityContractService { communityId: number, contractParams: ICommunityContractParams ): Promise { - const { claimAmount, maxClaim, baseInterval, incrementInterval } = - contractParams; + let { + claimAmount, + maxClaim, + baseInterval, + incrementInterval, + decreaseStep, + minTranche, + maxTranche, + } = contractParams; + + if (typeof claimAmount === 'string' && claimAmount.length > 10) { + claimAmount = new BigNumber(claimAmount) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof maxClaim === 'string' && maxClaim.length > 10) { + maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + } + if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { + decreaseStep = new BigNumber(decreaseStep) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } const community = (await this.community.findOne({ attributes: ['publicId'], @@ -44,10 +92,13 @@ export default class CommunityContractService { await sequelize.transaction(async (t) => { await this.ubiCommunityContract.update( { - claimAmount, - maxClaim, + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, baseInterval, incrementInterval, + minTranche, + maxTranche, + decreaseStep: decreaseStep as number, }, { where: { communityId }, transaction: t } ); diff --git a/packages/core/src/subgraph/queries/community.ts b/packages/core/src/subgraph/queries/community.ts index 81c7ece70..27388d6a7 100644 --- a/packages/core/src/subgraph/queries/community.ts +++ b/packages/core/src/subgraph/queries/community.ts @@ -138,6 +138,9 @@ export const getCommunityUBIParams = async ( maxClaim baseInterval incrementInterval + decreaseStep + minTranche + maxTranche } } `; diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 434f41482..e5961e3a8 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -91,12 +91,14 @@ export interface ICommunityVars { } export interface ICommunityContractParams { - claimAmount: string; - maxClaim: string; + claimAmount: string | number; + maxClaim: string | number; baseInterval: number; incrementInterval: number; blocked?: boolean; - decreaseStep?: string; + decreaseStep?: string | number; + minTranche?: number; + maxTranche?: number; } export interface ICommunityInfoBeneficiary { diff --git a/packages/core/tests/factories/claim.ts b/packages/core/tests/factories/claim.ts index f66e3de56..cbbb4a200 100644 --- a/packages/core/tests/factories/claim.ts +++ b/packages/core/tests/factories/claim.ts @@ -17,7 +17,7 @@ const data = async ( ) => { const defaultProps: UbiClaimCreation = { address: beneficiary.address, - amount: community.contract!.claimAmount, + amount: community.contract!.claimAmount.toString(), communityId: community.id, tx: randomTx(), txAt: new Date(), diff --git a/packages/core/tests/factories/community.ts b/packages/core/tests/factories/community.ts index 6ff68c5d9..8ec47465c 100644 --- a/packages/core/tests/factories/community.ts +++ b/packages/core/tests/factories/community.ts @@ -61,11 +61,11 @@ const data = async (props: ICreateProps) => { ? props.contract : { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', - decreaseStep: '1000000000000000000', + maxClaim: 450, + decreaseStep: 1, }, ...props, }; diff --git a/packages/core/tests/fake/community.ts b/packages/core/tests/fake/community.ts index 310992418..7aab503ff 100644 --- a/packages/core/tests/fake/community.ts +++ b/packages/core/tests/fake/community.ts @@ -44,8 +44,8 @@ communitiesContract.set( communityIds[0], new UbiCommunityContractModel({ communityId: communityIds[0], - claimAmount: '2000000000000000000', - maxClaim: '1500000000000000000000', + claimAmount: 2, + maxClaim: 1500, baseInterval: 86400, incrementInterval: 600, }) @@ -54,8 +54,8 @@ communitiesContract.set( communityIds[1], new UbiCommunityContractModel({ communityId: communityIds[1], - claimAmount: '1000000000000000000', - maxClaim: '600000000000000000000', + claimAmount: 1, + maxClaim: 600, baseInterval: 86400, incrementInterval: 300, }) @@ -64,8 +64,8 @@ communitiesContract.set( communityIds[2], new UbiCommunityContractModel({ communityId: communityIds[2], - claimAmount: '1500000000000000000', - maxClaim: '300000000000000000000', + claimAmount: 1.5, + maxClaim: 300, baseInterval: 86400, incrementInterval: 900, }) @@ -74,8 +74,8 @@ communitiesContract.set( communityIds[3], new UbiCommunityContractModel({ communityId: communityIds[3], - claimAmount: '1500000000000000000', - maxClaim: '300000000000000000000', + claimAmount: 1.5, + maxClaim: 300, baseInterval: 86400, incrementInterval: 600, }) @@ -84,8 +84,8 @@ communitiesContract.set( communityIds[4], new UbiCommunityContractModel({ communityId: communityIds[4], - claimAmount: '1000000000000000000', - maxClaim: '300000000000000000000', + claimAmount: 1, + maxClaim: 300, baseInterval: 86400, incrementInterval: 600, }) @@ -94,8 +94,8 @@ communitiesContract.set( communityIds[5], new UbiCommunityContractModel({ communityId: communityIds[5], - claimAmount: '1000000000000000000', - maxClaim: '300000000000000000000', + claimAmount: 1, + maxClaim: 300, baseInterval: 86400, incrementInterval: 600, }) diff --git a/packages/core/tests/integration/beneficiary.test.ts b/packages/core/tests/integration/beneficiary.test.ts index 59c69a68a..0b3bada2f 100644 --- a/packages/core/tests/integration/beneficiary.test.ts +++ b/packages/core/tests/integration/beneficiary.test.ts @@ -51,8 +51,8 @@ describe('beneficiary service', () => { let returnGetBeneficiarySubgraph: SinonStub; let returnGetBeneficiaryByAddressSubgraph: SinonStub; - const decreaseStep = '1000000000000000000'; - const maxClaim = '450000000000000000000'; + const decreaseStep = 1; + const maxClaim = 450; before(async () => { sequelize = sequelizeSetup(); @@ -67,7 +67,7 @@ describe('beneficiary service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, maxClaim, @@ -81,7 +81,7 @@ describe('beneficiary service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, maxClaim, @@ -237,10 +237,10 @@ describe('beneficiary service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -521,7 +521,7 @@ describe('beneficiary service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, maxClaim, @@ -839,8 +839,7 @@ describe('beneficiary service', () => { where: { communityId: communities[1].id }, }); - const newMaxClaim = - parseInt(maxClaim, 10) - parseInt(decreaseStep, 10) * 2; + const newMaxClaim = maxClaim - decreaseStep * 2; expect(contractUpdated!.maxClaim).to.be.equal( newMaxClaim.toString() ); @@ -886,8 +885,7 @@ describe('beneficiary service', () => { where: { communityId: communities[1].id }, }); - const newMaxClaim = - parseInt(maxClaim, 10) - parseInt(decreaseStep, 10) * 1; + const newMaxClaim = maxClaim - decreaseStep * 1; expect(contractUpdated!.maxClaim).to.be.equal( newMaxClaim.toString() ); diff --git a/packages/core/tests/integration/claimLocation.test.ts b/packages/core/tests/integration/claimLocation.test.ts index 4705712fe..17f926824 100644 --- a/packages/core/tests/integration/claimLocation.test.ts +++ b/packages/core/tests/integration/claimLocation.test.ts @@ -32,10 +32,10 @@ describe('claim location service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'BR', @@ -47,10 +47,10 @@ describe('claim location service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -61,10 +61,10 @@ describe('claim location service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -76,10 +76,10 @@ describe('claim location service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'AR', diff --git a/packages/core/tests/integration/community.test.ts b/packages/core/tests/integration/community.test.ts index 33e37ad43..2f95efd87 100644 --- a/packages/core/tests/integration/community.test.ts +++ b/packages/core/tests/integration/community.test.ts @@ -111,10 +111,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -155,10 +155,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -202,10 +202,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -249,10 +249,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -294,10 +294,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -309,10 +309,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -324,10 +324,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -382,10 +382,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -397,10 +397,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -443,10 +443,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -458,10 +458,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -473,10 +473,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'ES', @@ -512,10 +512,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -527,10 +527,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -542,10 +542,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'ES', @@ -557,10 +557,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'FR', @@ -572,10 +572,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'MZ', @@ -625,10 +625,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }); @@ -688,10 +688,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, suspect: index === 1 ? suspect : undefined, @@ -755,10 +755,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -773,10 +773,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -850,10 +850,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -868,10 +868,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -911,10 +911,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -929,10 +929,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -947,10 +947,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1042,10 +1042,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1060,10 +1060,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1078,10 +1078,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1157,10 +1157,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1207,10 +1207,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, proposalId: proposal.id, @@ -1254,10 +1254,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1348,10 +1348,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1443,10 +1443,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1461,10 +1461,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1479,10 +1479,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1537,10 +1537,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1555,10 +1555,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1591,10 +1591,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1645,10 +1645,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -1660,10 +1660,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -1675,10 +1675,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'ES', @@ -1716,10 +1716,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1757,10 +1757,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1799,10 +1799,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1852,10 +1852,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1897,10 +1897,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1939,10 +1939,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1963,9 +1963,9 @@ describe('community service', () => { email: 'test@email.com', contractParams: { baseInterval: 60 * 60 * 24 * 7, - claimAmount: '5000000000000000000', + claimAmount: 5, incrementInterval: 5 * 60 * 60, - maxClaim: '500000000000000000000', + maxClaim: 500, }, }); @@ -1979,9 +1979,9 @@ describe('community service', () => { }); expect(result.contract).to.include({ baseInterval: 60 * 60 * 24 * 7, - claimAmount: '5000000000000000000', + claimAmount: 5, incrementInterval: 5 * 60 * 60, - maxClaim: '500000000000000000000', + maxClaim: 500, }); }); @@ -1996,10 +1996,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2048,10 +2048,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2098,10 +2098,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2129,10 +2129,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2157,10 +2157,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2188,10 +2188,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2226,10 +2226,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2279,10 +2279,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2340,10 +2340,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2377,10 +2377,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2410,10 +2410,10 @@ describe('community service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, diff --git a/packages/core/tests/integration/manager.test.ts b/packages/core/tests/integration/manager.test.ts index 943105034..34ccc9551 100644 --- a/packages/core/tests/integration/manager.test.ts +++ b/packages/core/tests/integration/manager.test.ts @@ -37,10 +37,10 @@ describe('manager service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, diff --git a/packages/core/tests/integration/story.test.ts b/packages/core/tests/integration/story.test.ts index 5ceb2b37c..79d26a9a9 100644 --- a/packages/core/tests/integration/story.test.ts +++ b/packages/core/tests/integration/story.test.ts @@ -54,10 +54,10 @@ describe('story service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -68,10 +68,10 @@ describe('story service', () => { visibility: 'private', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -80,10 +80,10 @@ describe('story service', () => { ...communities[0], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, }; await BeneficiaryFactory(users.slice(0, 3), community1.id); @@ -91,10 +91,10 @@ describe('story service', () => { ...communities[0], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, }; await BeneficiaryFactory(users.slice(3, 6), community2.id); diff --git a/packages/core/tests/integration/user.test.ts b/packages/core/tests/integration/user.test.ts index 64ae82c99..23aa25187 100644 --- a/packages/core/tests/integration/user.test.ts +++ b/packages/core/tests/integration/user.test.ts @@ -377,10 +377,10 @@ describe('user service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -671,10 +671,10 @@ describe('user service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -774,10 +774,10 @@ describe('user service', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, ambassadorAddress: users[3].address, diff --git a/packages/core/tests/integration/v2/community.test.ts b/packages/core/tests/integration/v2/community.test.ts index b838081fb..3c8ba6c0c 100644 --- a/packages/core/tests/integration/v2/community.test.ts +++ b/packages/core/tests/integration/v2/community.test.ts @@ -81,10 +81,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -125,10 +125,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -172,10 +172,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -219,10 +219,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -264,10 +264,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -279,10 +279,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -294,10 +294,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -348,10 +348,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -363,10 +363,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -409,10 +409,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -424,10 +424,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -439,10 +439,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'ES', @@ -487,10 +487,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -502,10 +502,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'PT', @@ -517,10 +517,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'ES', @@ -532,10 +532,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'FR', @@ -547,10 +547,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, country: 'MZ', @@ -607,10 +607,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }); @@ -668,10 +668,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -686,10 +686,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -768,10 +768,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -786,10 +786,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -829,10 +829,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -847,10 +847,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -865,10 +865,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -962,10 +962,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -980,10 +980,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -998,10 +998,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1078,10 +1078,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1096,10 +1096,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1114,10 +1114,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1218,10 +1218,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1276,10 +1276,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, proposalId: proposal.id, @@ -1331,10 +1331,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1432,10 +1432,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1534,10 +1534,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1552,10 +1552,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1570,10 +1570,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1634,10 +1634,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1652,10 +1652,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1711,10 +1711,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1731,10 +1731,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1779,10 +1779,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1799,10 +1799,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, gps: { @@ -1844,10 +1844,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1858,10 +1858,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1888,10 +1888,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1902,10 +1902,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1940,10 +1940,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1976,10 +1976,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -2037,10 +2037,10 @@ describe('community service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, diff --git a/packages/core/tests/integration/v2/user.test.ts b/packages/core/tests/integration/v2/user.test.ts index a62b889c3..fe6bf222e 100644 --- a/packages/core/tests/integration/v2/user.test.ts +++ b/packages/core/tests/integration/v2/user.test.ts @@ -37,10 +37,10 @@ describe('user service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, ambassadorAddress: users[1].address, @@ -52,10 +52,10 @@ describe('user service v2', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, ambassadorAddress: users[3].address, diff --git a/packages/core/tests/unit/services/globalDemographics.test.ts b/packages/core/tests/unit/services/globalDemographics.test.ts index e0a5fb3f9..7383b8965 100644 --- a/packages/core/tests/unit/services/globalDemographics.test.ts +++ b/packages/core/tests/unit/services/globalDemographics.test.ts @@ -90,7 +90,7 @@ describe('calculate global demographics', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, maxClaim, diff --git a/packages/worker/src/jobs/chainSubscribers.ts b/packages/worker/src/jobs/chainSubscribers.ts index 05a08e01f..b10b0b633 100644 --- a/packages/worker/src/jobs/chainSubscribers.ts +++ b/packages/worker/src/jobs/chainSubscribers.ts @@ -5,6 +5,7 @@ import { contracts, database, } from '@impactmarket/core'; +import BigNumber from 'bignumber.js'; import { ethers } from 'ethers'; /* istanbul ignore next */ @@ -640,14 +641,20 @@ class ChainSubscribers { parsedLog.args[5][isProposalToCommunity[index]] ), ]; + + const maxClaim = calldatas[0][2].toString(); + const claimAmount = calldatas[0][1].toString(); // const community = await database.models.community.findOne({ attributes: ['id'], where: { requestByAddress: calldatas[0][0][0], - '$contract.claimAmount$': - calldatas[0][1].toString(), - '$contract.maxClaim$': calldatas[0][2].toString(), + '$contract.claimAmount$': new BigNumber(claimAmount) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(), + '$contract.maxClaim$': new BigNumber(maxClaim) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(), '$contract.baseInterval$': parseInt( calldatas[0][4].toString(), 10 diff --git a/packages/worker/src/jobs/cron/community.ts b/packages/worker/src/jobs/cron/community.ts index de6301663..bfeb680bc 100644 --- a/packages/worker/src/jobs/cron/community.ts +++ b/packages/worker/src/jobs/cron/community.ts @@ -613,7 +613,6 @@ export async function calcuateCommunitiesMetrics(): Promise { // calculate estimatedDuration estimatedDuration = parseFloat( new BigNumber(community.contract.maxClaim) - .dividedBy(10 ** config.cUSDDecimal) // set 18 decimals from onchain values .dividedBy(ubiRate) .dividedBy(30) .toFixed(2, 1) diff --git a/packages/worker/src/jobs/cron/global.ts b/packages/worker/src/jobs/cron/global.ts index e70507590..60384c8a7 100644 --- a/packages/worker/src/jobs/cron/global.ts +++ b/packages/worker/src/jobs/cron/global.ts @@ -262,7 +262,9 @@ async function calculateUbiPulse( raw: true, }) )[0] as any; - return result.avgComulativeUbi; + return new BigNumber(result.avgComulativeUbi) + .multipliedBy(10 ** config.cUSDDecimal) + .toString(); // convert to 18 decimals before return }; const backersAndFunding = await uniqueBackersAndFundingLast30Days( diff --git a/packages/worker/tests/integration/cron/calcuateCommunitiesMetrics.test.ts b/packages/worker/tests/integration/cron/calcuateCommunitiesMetrics.test.ts index 1d2c8aec5..2ebca856f 100644 --- a/packages/worker/tests/integration/cron/calcuateCommunitiesMetrics.test.ts +++ b/packages/worker/tests/integration/cron/calcuateCommunitiesMetrics.test.ts @@ -59,10 +59,10 @@ describe('calcuateCommunitiesMetrics', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -881,10 +881,10 @@ describe('calcuateCommunitiesMetrics', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -893,10 +893,10 @@ describe('calcuateCommunitiesMetrics', () => { ...communities[0], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, }; await tests.factories.InflowFactory(community); diff --git a/packages/worker/tests/integration/cron/calcuateGlobalMetrics.test.ts b/packages/worker/tests/integration/cron/calcuateGlobalMetrics.test.ts index d85056942..920728e21 100644 --- a/packages/worker/tests/integration/cron/calcuateGlobalMetrics.test.ts +++ b/packages/worker/tests/integration/cron/calcuateGlobalMetrics.test.ts @@ -59,10 +59,10 @@ describe('#calcuateGlobalMetrics()', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -71,10 +71,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[0], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, createdAt: new Date(), updatedAt: new Date(), }, @@ -376,10 +376,10 @@ describe('#calcuateGlobalMetrics()', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -390,10 +390,10 @@ describe('#calcuateGlobalMetrics()', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '750000000000000000', + claimAmount: 0.75, communityId: 0, incrementInterval: 10 * 60, - maxClaim: '300000000000000000000', + maxClaim: 300, }, hasAddress: true, }, @@ -402,10 +402,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[0], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, createdAt: new Date(), updatedAt: new Date(), }, @@ -414,10 +414,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[1], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '750000000000000000', + claimAmount: 0.75, communityId: 0, incrementInterval: 10 * 60, - maxClaim: '300000000000000000000', + maxClaim: 300, createdAt: new Date(), updatedAt: new Date(), }, @@ -1335,10 +1335,10 @@ describe('#calcuateGlobalMetrics()', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1349,10 +1349,10 @@ describe('#calcuateGlobalMetrics()', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '750000000000000000', + claimAmount: 0.75, communityId: 0, incrementInterval: 10 * 60, - maxClaim: '300000000000000000000', + maxClaim: 300, }, hasAddress: true, }, @@ -1363,10 +1363,10 @@ describe('#calcuateGlobalMetrics()', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -1377,10 +1377,10 @@ describe('#calcuateGlobalMetrics()', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '750000000000000000', + claimAmount: 0.75, communityId: 0, incrementInterval: 10 * 60, - maxClaim: '300000000000000000000', + maxClaim: 300, }, hasAddress: true, }, @@ -1389,10 +1389,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[0], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, createdAt: new Date(), updatedAt: new Date(), }, @@ -1401,10 +1401,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[1], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '750000000000000000', + claimAmount: 0.75, communityId: 0, incrementInterval: 10 * 60, - maxClaim: '300000000000000000000', + maxClaim: 300, createdAt: new Date(), updatedAt: new Date(), }, @@ -1413,10 +1413,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[2], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, createdAt: new Date(), updatedAt: new Date(), }, @@ -1425,10 +1425,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[3], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '750000000000000000', + claimAmount: 0.75, communityId: 0, incrementInterval: 10 * 60, - maxClaim: '300000000000000000000', + maxClaim: 300, createdAt: new Date(), updatedAt: new Date(), }, @@ -2786,10 +2786,10 @@ describe('#calcuateGlobalMetrics()', () => { ...communities[0], contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, }; diff --git a/packages/worker/tests/integration/cron/verifyDeletedAccounts.test.ts b/packages/worker/tests/integration/cron/verifyDeletedAccounts.test.ts index 108af86bd..969459c12 100644 --- a/packages/worker/tests/integration/cron/verifyDeletedAccounts.test.ts +++ b/packages/worker/tests/integration/cron/verifyDeletedAccounts.test.ts @@ -56,10 +56,10 @@ describe('[jobs - cron] verifyDeletedAccounts', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, @@ -468,10 +468,10 @@ describe('[jobs - cron] verifyDeletedAccounts', () => { visibility: 'public', contract: { baseInterval: 60 * 60 * 24, - claimAmount: '1000000000000000000', + claimAmount: 1, communityId: 0, incrementInterval: 5 * 60, - maxClaim: '450000000000000000000', + maxClaim: 450, }, hasAddress: true, }, From 2f59c8827797111ba51b27ffda109008f4769180 Mon Sep 17 00:00:00 2001 From: Joao Pedro da Silva Date: Fri, 22 Jul 2022 22:22:29 +0100 Subject: [PATCH 3/5] fix worker --- .../z1604506690-create-communityContract.js | 16 +++++++++++----- .../core/src/services/ubi/community/contract.ts | 10 +++++++--- .../core/src/services/ubi/communityContract.ts | 10 +++++++--- packages/core/tests/factories/claim.ts | 8 +++++++- packages/core/tests/factories/inflow.ts | 2 ++ .../core/tests/integration/beneficiary.test.ts | 8 ++------ .../core/tests/integration/community.test.ts | 12 ++++++++---- .../core/tests/integration/v2/community.test.ts | 12 ++++++++++++ .../unit/services/globalDemographics.test.ts | 4 ++-- packages/worker/tests/integration/DAO.test.ts | 8 ++++---- 10 files changed, 62 insertions(+), 28 deletions(-) diff --git a/packages/core/src/database/migrations/z1604506690-create-communityContract.js b/packages/core/src/database/migrations/z1604506690-create-communityContract.js index 3b5ab33d0..9e4aa4373 100644 --- a/packages/core/src/database/migrations/z1604506690-create-communityContract.js +++ b/packages/core/src/database/migrations/z1604506690-create-communityContract.js @@ -14,15 +14,21 @@ module.exports = { allowNull: false, }, claimAmount: { - // https://github.com/sequelize/sequelize/blob/2874c54915b2594225e939809ca9f8200b94f454/lib/dialects/postgres/data-types.js#L102 - type: Sequelize.DECIMAL(22), // max 9,999 - plus 18 decimals + type: Sequelize.FLOAT, allowNull: false, }, maxClaim: { - // https://github.com/sequelize/sequelize/blob/2874c54915b2594225e939809ca9f8200b94f454/lib/dialects/postgres/data-types.js#L102 - type: Sequelize.DECIMAL(24), // max 999,999 - plus 18 decimals + type: Sequelize.FLOAT, allowNull: false, }, + maxTranche: { + type: Sequelize.FLOAT, + allowNull: true, + }, + minTranche: { + type: Sequelize.FLOAT, + allowNull: true, + }, baseInterval: { type: Sequelize.INTEGER, allowNull: false, @@ -32,7 +38,7 @@ module.exports = { allowNull: false, }, decreaseStep: { - type: Sequelize.DECIMAL(22), // max 9,999 - plus 18 decimals + type: Sequelize.FLOAT, allowNull: false, defaultValue: 0, }, diff --git a/packages/core/src/services/ubi/community/contract.ts b/packages/core/src/services/ubi/community/contract.ts index 01e216988..9aa4c55bf 100644 --- a/packages/core/src/services/ubi/community/contract.ts +++ b/packages/core/src/services/ubi/community/contract.ts @@ -1,7 +1,7 @@ import { BigNumber } from 'bignumber.js'; -import config from '../../../config'; import { Transaction } from 'sequelize'; +import config from '../../../config'; import { models, sequelize } from '../../../database'; import { UbiCommunityContract } from '../../../interfaces/ubi/ubiCommunityContract'; import { ICommunityContractParams } from '../../../types'; @@ -28,7 +28,9 @@ export default class CommunityContractService { .toNumber(); } if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + maxClaim = new BigNumber(maxClaim) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); } if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { decreaseStep = new BigNumber(decreaseStep) @@ -71,7 +73,9 @@ export default class CommunityContractService { .toNumber(); } if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + maxClaim = new BigNumber(maxClaim) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); } if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { decreaseStep = new BigNumber(decreaseStep) diff --git a/packages/core/src/services/ubi/communityContract.ts b/packages/core/src/services/ubi/communityContract.ts index f521ad938..6ba0ccbbc 100644 --- a/packages/core/src/services/ubi/communityContract.ts +++ b/packages/core/src/services/ubi/communityContract.ts @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js'; -import config from '../../config'; import { Transaction } from 'sequelize'; +import config from '../../config'; import { models, sequelize } from '../../database'; import { UbiCommunityContract } from '../../interfaces/ubi/ubiCommunityContract'; import { ICommunityContractParams } from '../../types'; @@ -33,7 +33,9 @@ export default class CommunityContractService { .toNumber(); } if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + maxClaim = new BigNumber(maxClaim) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); } if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { decreaseStep = new BigNumber(decreaseStep) @@ -76,7 +78,9 @@ export default class CommunityContractService { .toNumber(); } if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim).dividedBy(10 ** config.cUSDDecimal).toNumber(); + maxClaim = new BigNumber(maxClaim) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); } if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { decreaseStep = new BigNumber(decreaseStep) diff --git a/packages/core/tests/factories/claim.ts b/packages/core/tests/factories/claim.ts index cbbb4a200..2fa60f6bf 100644 --- a/packages/core/tests/factories/claim.ts +++ b/packages/core/tests/factories/claim.ts @@ -1,3 +1,6 @@ +import BigNumber from 'bignumber.js'; + +import config from '../../src/config'; import { UbiClaimModel } from '../../src/database/models/ubi/ubiClaim'; import { BeneficiaryAttributes } from '../../src/interfaces/ubi/beneficiary'; import { CommunityAttributes } from '../../src/interfaces/ubi/community'; @@ -15,9 +18,12 @@ const data = async ( beneficiary: BeneficiaryAttributes, community: CommunityAttributes ) => { + const amount = new BigNumber(community.contract!.claimAmount) + .multipliedBy(10 ** config.cUSDDecimal) + .toString(); const defaultProps: UbiClaimCreation = { address: beneficiary.address, - amount: community.contract!.claimAmount.toString(), + amount, communityId: community.id, tx: randomTx(), txAt: new Date(), diff --git a/packages/core/tests/factories/inflow.ts b/packages/core/tests/factories/inflow.ts index 746b08085..0baeb5bcb 100644 --- a/packages/core/tests/factories/inflow.ts +++ b/packages/core/tests/factories/inflow.ts @@ -1,6 +1,7 @@ import BigNumber from 'bignumber.js'; import { ethers } from 'ethers'; +import config from '../../src/config'; import { Inflow, InflowCreationAttributes, @@ -18,6 +19,7 @@ import { randomTx } from '../config/utils'; const data = async (community: CommunityAttributes) => { const randomWallet = ethers.Wallet.createRandom(); const amount = new BigNumber(community.contract!.claimAmount) + .multipliedBy(10 ** config.cUSDDecimal) .multipliedBy(5) .toString(); const defaultProps: InflowCreationAttributes = { diff --git a/packages/core/tests/integration/beneficiary.test.ts b/packages/core/tests/integration/beneficiary.test.ts index 0b3bada2f..8ed667522 100644 --- a/packages/core/tests/integration/beneficiary.test.ts +++ b/packages/core/tests/integration/beneficiary.test.ts @@ -840,9 +840,7 @@ describe('beneficiary service', () => { }); const newMaxClaim = maxClaim - decreaseStep * 2; - expect(contractUpdated!.maxClaim).to.be.equal( - newMaxClaim.toString() - ); + expect(contractUpdated!.maxClaim).to.be.equal(newMaxClaim); }); it('update max claim when remove a beneficiary', async () => { @@ -886,9 +884,7 @@ describe('beneficiary service', () => { }); const newMaxClaim = maxClaim - decreaseStep * 1; - expect(contractUpdated!.maxClaim).to.be.equal( - newMaxClaim.toString() - ); + expect(contractUpdated!.maxClaim).to.be.equal(newMaxClaim); }); it('update max claim when a community does not have a decrease step', async () => { diff --git a/packages/core/tests/integration/community.test.ts b/packages/core/tests/integration/community.test.ts index 2f95efd87..de0488afb 100644 --- a/packages/core/tests/integration/community.test.ts +++ b/packages/core/tests/integration/community.test.ts @@ -1309,6 +1309,8 @@ describe('community service', () => { 'communityId', 'createdAt', 'updatedAt', + 'maxTranche', + 'minTranche', ]); expect(result.rows[0]).to.include({ id: communities[0].id, @@ -1407,6 +1409,8 @@ describe('community service', () => { 'decreaseStep', 'createdAt', 'updatedAt', + 'maxTranche', + 'minTranche', ]); expect(result.rows[0].cover).to.have.deep.keys([ 'id', @@ -1963,9 +1967,9 @@ describe('community service', () => { email: 'test@email.com', contractParams: { baseInterval: 60 * 60 * 24 * 7, - claimAmount: 5, + claimAmount: '5000000000000000000', incrementInterval: 5 * 60 * 60, - maxClaim: 500, + maxClaim: '500000000000000000000', }, }); @@ -1979,9 +1983,9 @@ describe('community service', () => { }); expect(result.contract).to.include({ baseInterval: 60 * 60 * 24 * 7, - claimAmount: 5, + claimAmount: '5000000000000000000', incrementInterval: 5 * 60 * 60, - maxClaim: 500, + maxClaim: '500000000000000000000', }); }); diff --git a/packages/core/tests/integration/v2/community.test.ts b/packages/core/tests/integration/v2/community.test.ts index 3c8ba6c0c..3e39f79c3 100644 --- a/packages/core/tests/integration/v2/community.test.ts +++ b/packages/core/tests/integration/v2/community.test.ts @@ -19,6 +19,7 @@ describe('community service v2', () => { let sequelize: Sequelize; let users: AppUser[]; let returnProposalsSubgraph: SinonStub; + let returnAmbassadorByAddressSubgraph: SinonStub; let returnClaimedSubgraph: SinonStub; let returnCommunityStateSubgraph: SinonStub; let returnCommunityEntities: SinonStub; @@ -46,6 +47,10 @@ describe('community service v2', () => { returnProposalsSubgraph = stub(subgraph, 'getCommunityProposal'); returnCommunityEntities = stub(subgraph, 'communityEntities'); returnClaimedSubgraph = stub(subgraph, 'getClaimed'); + returnAmbassadorByAddressSubgraph = stub( + subgraph, + 'getAmbassadorByAddress' + ); returnCommunityStateSubgraph = stub(subgraph, 'getCommunityState'); returnCommunityStateSubgraph.returns([ { @@ -1393,6 +1398,8 @@ describe('community service v2', () => { 'communityId', 'createdAt', 'updatedAt', + 'maxTranche', + 'minTranche', ]); expect(result.rows[0]).to.include({ id: communities[0].id, @@ -1498,6 +1505,8 @@ describe('community service v2', () => { 'decreaseStep', 'createdAt', 'updatedAt', + 'maxTranche', + 'minTranche', ]); expect(result.rows[0].cover).to.have.deep.keys([ 'id', @@ -1816,6 +1825,9 @@ describe('community service v2', () => { returnClaimedSubgraph.returns([]); returnCommunityEntities.returns([]); + returnAmbassadorByAddressSubgraph.returns({ + communities: [communities[0].contractAddress], + }); const result = await communityListService.list({ ambassadorAddress: ambassadors[0].address, diff --git a/packages/core/tests/unit/services/globalDemographics.test.ts b/packages/core/tests/unit/services/globalDemographics.test.ts index 7383b8965..7e7eaa62e 100644 --- a/packages/core/tests/unit/services/globalDemographics.test.ts +++ b/packages/core/tests/unit/services/globalDemographics.test.ts @@ -1,5 +1,5 @@ import { Sequelize } from 'sequelize'; -import { stub, assert, match, SinonStub, restore } from 'sinon'; +import { stub, assert, match, SinonStub } from 'sinon'; import { models } from '../../../src/database'; import { ManagerAttributes } from '../../../src/database/models/ubi/manager'; @@ -34,7 +34,7 @@ describe('calculate global demographics', () => { let communities: CommunityAttributes[]; let managers: ManagerAttributes[]; let beneficiaries: BeneficiaryAttributes[]; - const maxClaim = '450000000000000000000'; + const maxClaim = 450; let dbGlobalDemographicsInsertStub: SinonStub; before(async () => { diff --git a/packages/worker/tests/integration/DAO.test.ts b/packages/worker/tests/integration/DAO.test.ts index 6d555c698..9b39e4e89 100644 --- a/packages/worker/tests/integration/DAO.test.ts +++ b/packages/worker/tests/integration/DAO.test.ts @@ -88,8 +88,8 @@ describe('DAO', () => { contract: { baseInterval: 5 * 60, incrementInterval: 60, - claimAmount: parseEther('1').toString(), - maxClaim: parseEther('100').toString(), + claimAmount: 1, + maxClaim: 100, communityId: 0, }, }, @@ -98,8 +98,8 @@ describe('DAO', () => { contract: { baseInterval: 5 * 60, incrementInterval: 60, - claimAmount: parseEther('1').toString(), - maxClaim: parseEther('100').toString(), + claimAmount: 1, + maxClaim: 100, communityId: 1, }, }, From ef990517c86b6f045eec51f4271ed8c668cdf0f5 Mon Sep 17 00:00:00 2001 From: Joao Pedro da Silva Date: Fri, 22 Jul 2022 20:19:46 -0300 Subject: [PATCH 4/5] remove duplicated lines --- .../src/services/ubi/community/contract.ts | 103 ++++++----------- .../src/services/ubi/communityContract.ts | 105 ++++++------------ 2 files changed, 70 insertions(+), 138 deletions(-) diff --git a/packages/core/src/services/ubi/community/contract.ts b/packages/core/src/services/ubi/community/contract.ts index 9aa4c55bf..ea41e3471 100644 --- a/packages/core/src/services/ubi/community/contract.ts +++ b/packages/core/src/services/ubi/community/contract.ts @@ -12,42 +12,12 @@ export default class CommunityContractService { contractParams: ICommunityContractParams, t: Transaction | undefined = undefined ): Promise { - let { - claimAmount, - maxClaim, - baseInterval, - incrementInterval, - decreaseStep, - minTranche, - maxTranche, - } = contractParams; - - if (typeof claimAmount === 'string' && claimAmount.length > 10) { - claimAmount = new BigNumber(claimAmount) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { - decreaseStep = new BigNumber(decreaseStep) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } + const params = this.formatContractParams(contractParams); return models.ubiCommunityContract.create( { communityId, - claimAmount: claimAmount as number, - maxClaim: maxClaim as number, - baseInterval, - incrementInterval, - decreaseStep: decreaseStep as number, - minTranche, - maxTranche, + ...params, }, { transaction: t } ); @@ -57,31 +27,7 @@ export default class CommunityContractService { communityId: number, contractParams: ICommunityContractParams ): Promise { - let { - claimAmount, - maxClaim, - baseInterval, - incrementInterval, - decreaseStep, - minTranche, - maxTranche, - } = contractParams; - - if (typeof claimAmount === 'string' && claimAmount.length > 10) { - claimAmount = new BigNumber(claimAmount) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { - decreaseStep = new BigNumber(decreaseStep) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } + const params = this.formatContractParams(contractParams); const community = (await models.community.findOne({ attributes: ['publicId'], @@ -89,18 +35,10 @@ export default class CommunityContractService { }))!; try { await sequelize.transaction(async (t) => { - await models.ubiCommunityContract.update( - { - claimAmount: claimAmount as number, - maxClaim: maxClaim as number, - baseInterval, - incrementInterval, - decreaseStep: decreaseStep as number, - minTranche, - maxTranche, - }, - { where: { communityId }, transaction: t } - ); + await models.ubiCommunityContract.update(params, { + where: { communityId }, + transaction: t, + }); // TODO: migrate await models.ubiRequestChangeParams.destroy({ @@ -118,4 +56,31 @@ export default class CommunityContractService { return false; } } + + private formatContractParams(contractParams: ICommunityContractParams) { + let { claimAmount, maxClaim, decreaseStep } = contractParams; + + if (typeof claimAmount === 'string' && claimAmount.length > 10) { + claimAmount = new BigNumber(claimAmount) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof maxClaim === 'string' && maxClaim.length > 10) { + maxClaim = new BigNumber(maxClaim) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { + decreaseStep = new BigNumber(decreaseStep) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + + return { + ...contractParams, + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, + decreaseStep: decreaseStep as number, + }; + } } diff --git a/packages/core/src/services/ubi/communityContract.ts b/packages/core/src/services/ubi/communityContract.ts index 6ba0ccbbc..6445edc8b 100644 --- a/packages/core/src/services/ubi/communityContract.ts +++ b/packages/core/src/services/ubi/communityContract.ts @@ -17,42 +17,12 @@ export default class CommunityContractService { contractParams: ICommunityContractParams, t: Transaction | undefined = undefined ): Promise { - let { - claimAmount, - maxClaim, - baseInterval, - incrementInterval, - decreaseStep, - minTranche, - maxTranche, - } = contractParams; - - if (typeof claimAmount === 'string' && claimAmount.length > 10) { - claimAmount = new BigNumber(claimAmount) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { - decreaseStep = new BigNumber(decreaseStep) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } + const params = this.formatContractParams(contractParams); return await this.ubiCommunityContract.create( { communityId, - claimAmount: claimAmount as number, - maxClaim: maxClaim as number, - baseInterval, - incrementInterval, - minTranche, - maxTranche, - decreaseStep: decreaseStep as number, + ...params, }, { transaction: t } ); @@ -62,31 +32,7 @@ export default class CommunityContractService { communityId: number, contractParams: ICommunityContractParams ): Promise { - let { - claimAmount, - maxClaim, - baseInterval, - incrementInterval, - decreaseStep, - minTranche, - maxTranche, - } = contractParams; - - if (typeof claimAmount === 'string' && claimAmount.length > 10) { - claimAmount = new BigNumber(claimAmount) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { - decreaseStep = new BigNumber(decreaseStep) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } + const params = this.formatContractParams(contractParams); const community = (await this.community.findOne({ attributes: ['publicId'], @@ -94,18 +40,10 @@ export default class CommunityContractService { }))!; try { await sequelize.transaction(async (t) => { - await this.ubiCommunityContract.update( - { - claimAmount: claimAmount as number, - maxClaim: maxClaim as number, - baseInterval, - incrementInterval, - minTranche, - maxTranche, - decreaseStep: decreaseStep as number, - }, - { where: { communityId }, transaction: t } - ); + await this.ubiCommunityContract.update(params, { + where: { communityId }, + transaction: t, + }); // TODO: migrate await this.ubiRequestChangeParams.destroy({ @@ -146,4 +84,33 @@ export default class CommunityContractService { ) ); } + + private static formatContractParams( + contractParams: ICommunityContractParams + ) { + let { claimAmount, maxClaim, decreaseStep } = contractParams; + + if (typeof claimAmount === 'string' && claimAmount.length > 10) { + claimAmount = new BigNumber(claimAmount) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof maxClaim === 'string' && maxClaim.length > 10) { + maxClaim = new BigNumber(maxClaim) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { + decreaseStep = new BigNumber(decreaseStep) + .dividedBy(10 ** config.cUSDDecimal) + .toNumber(); + } + + return { + ...contractParams, + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, + decreaseStep: decreaseStep as number, + }; + } } From 30c4de38a9364896c641265f73235669a44bb0c6 Mon Sep 17 00:00:00 2001 From: Joao Pedro da Silva Date: Thu, 28 Jul 2022 18:16:45 -0300 Subject: [PATCH 5/5] refactor create/update community v2 --- .../api/src/routes/v2/community/create.ts | 8 ++-- .../src/services/ubi/community/contract.ts | 45 ++++++------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/packages/api/src/routes/v2/community/create.ts b/packages/api/src/routes/v2/community/create.ts index 927cc7422..0313ac115 100644 --- a/packages/api/src/routes/v2/community/create.ts +++ b/packages/api/src/routes/v2/community/create.ts @@ -70,10 +70,10 @@ export default (route: Router): void => { * required: true * properties: * claimAmount: - * type: string + * type: number * required: true * maxClaim: - * type: string + * type: number * required: true * baseInterval: * type: number @@ -156,9 +156,9 @@ export default (route: Router): void => { * required: false * properties: * claimAmount: - * type: string + * type: number * maxClaim: - * type: string + * type: number * baseInterval: * type: number * incrementInterval: diff --git a/packages/core/src/services/ubi/community/contract.ts b/packages/core/src/services/ubi/community/contract.ts index ea41e3471..a5dca9b0d 100644 --- a/packages/core/src/services/ubi/community/contract.ts +++ b/packages/core/src/services/ubi/community/contract.ts @@ -12,12 +12,16 @@ export default class CommunityContractService { contractParams: ICommunityContractParams, t: Transaction | undefined = undefined ): Promise { - const params = this.formatContractParams(contractParams); + let { claimAmount, maxClaim, decreaseStep, baseInterval, incrementInterval } = contractParams; return models.ubiCommunityContract.create( { communityId, - ...params, + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, + decreaseStep: decreaseStep as number, + baseInterval, + incrementInterval, }, { transaction: t } ); @@ -27,7 +31,7 @@ export default class CommunityContractService { communityId: number, contractParams: ICommunityContractParams ): Promise { - const params = this.formatContractParams(contractParams); + let { claimAmount, maxClaim, decreaseStep, baseInterval, incrementInterval } = contractParams; const community = (await models.community.findOne({ attributes: ['publicId'], @@ -35,7 +39,13 @@ export default class CommunityContractService { }))!; try { await sequelize.transaction(async (t) => { - await models.ubiCommunityContract.update(params, { + await models.ubiCommunityContract.update({ + claimAmount: claimAmount as number, + maxClaim: maxClaim as number, + decreaseStep: decreaseStep as number, + baseInterval, + incrementInterval, + }, { where: { communityId }, transaction: t, }); @@ -56,31 +66,4 @@ export default class CommunityContractService { return false; } } - - private formatContractParams(contractParams: ICommunityContractParams) { - let { claimAmount, maxClaim, decreaseStep } = contractParams; - - if (typeof claimAmount === 'string' && claimAmount.length > 10) { - claimAmount = new BigNumber(claimAmount) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof maxClaim === 'string' && maxClaim.length > 10) { - maxClaim = new BigNumber(maxClaim) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - if (typeof decreaseStep === 'string' && decreaseStep.length > 10) { - decreaseStep = new BigNumber(decreaseStep) - .dividedBy(10 ** config.cUSDDecimal) - .toNumber(); - } - - return { - ...contractParams, - claimAmount: claimAmount as number, - maxClaim: maxClaim as number, - decreaseStep: decreaseStep as number, - }; - } }