Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

351 - refactor pending community #353

Merged
merged 6 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions packages/api/src/routes/v2/community/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,23 @@ 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
* required: true
* incrementInterval:
* type: number
* required: true
* minTranche:
* type: number
* required: false
* maxTranche:
* type: number
* required: false
* placeId:
* type: string
* required: false
Expand Down Expand Up @@ -150,13 +156,19 @@ export default (route: Router): void => {
* required: false
* properties:
* claimAmount:
* type: string
* type: number
* maxClaim:
* type: string
* type: number
* baseInterval:
* type: number
* incrementInterval:
* type: number
* minTranche:
* type: number
* required: false
* maxTranche:
* type: number
* required: false
* placeId:
* type: string
* required: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {},
};
29 changes: 24 additions & 5 deletions packages/core/src/database/models/ubi/communityContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/interfaces/ubi/ubiCommunityContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Loading