Skip to content

Commit

Permalink
Merge pull request #128 from jupiter-project/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
reyesrene authored Jan 28, 2022
2 parents 93e6f29 + c528868 commit 05de44e
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 166 deletions.
Empty file modified Gravity Documentation - v1.pdf
100644 → 100755
Empty file.
Empty file modified certificates/apn.p12
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions config/appConf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// const gu = require("../utils/gravityUtils");
const mError = require("../errors/metisError");

const conf = {};
if(!process.env.NODE_ENV) throw new mError.MetisErrorBadEnvironmentVariable('','NODE_ENV');
// if(!process.env.NODE_OPTIONS) throw new mError.MetisErrorBadEnvironmentVariable('','NODE_OPTIONS');
Expand Down
49 changes: 49 additions & 0 deletions config/feeConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// const _ = require("lodash");
if(isNaN(process.env.REGULAR_TRANSACTION_FEE)) throw new Error(`Environment Variable REGULAR_TRANSACTION_FEE is not a number ${process.env.REGULAR_TRANSACTION_FEE}`);
const regularTransactionFee = +process.env.REGULAR_TRANSACTION_FEE;
// if(!process.env.REGULAR_TRANSACTION_FEE) throw new Error('Environment Variable missing: REGULAR_TRANSACTION_FEE');
if(isNaN(process.env.ACCOUNT_RECORD_FEE)) throw new Error(`Environment Variable ACCOUNT_RECORD_FEE is not a number ${process.env.ACCOUNT_RECORD_FEE}`);
const accountRecordFee = +process.env.ACCOUNT_RECORD_FEE;
// if(!process.env.ACCOUNT_RECORD_FEE) throw new Error('Environment Variable missing: ACCOUNT_RECORD_FEE');
if(isNaN(process.env.NEW_USER_FUNDING_FEE)) throw new Error(`Environment Variable NEW_USER_FUNDING_FEE is not a number ${process.env.NEW_USER_FUNDING_FEE}`);
const newUserFundingFee = +process.env.NEW_USER_FUNDING_FEE;
// if(!process.env.NEW_USER_FUNDING_FEE) throw new Error('Environment Variable missing: NEW_USER_FUNDING_FEE');
if(isNaN(process.env.ORDINARY_PAYMENT_FEE)) throw new Error(`Environment Variable ORDINARY_PAYMENT_FEE is not a number ${process.env.ORDINARY_PAYMENT_FEE}`);
const ordinaryPaymentFee = +process.env.ORDINARY_PAYMENT_FEE;
// if(!process.env.ORDINARY_PAYMENT_FEE) throw new Error('Environment Variable missing: ORDINARY_PAYMENT_FEE');
if(isNaN(process.env.ACCOUNT_PROPERTY_FEE)) throw new Error(`Environment Variable ACCOUNT_PROPERTY_FEE is not a number ${process.env.ACCOUNT_PROPERTY_FEE}`);
const accountPropertyFee = +process.env.ACCOUNT_PROPERTY_FEE;
// if(!process.env.ACCOUNT_PROPERTY_FEE) throw new Error('Environment Variable missing: ACCOUNT_PROPERTY_FEE');
if(isNaN(process.env.INVITATION_TO_CHANNEL_FEE)) throw new Error(`Environment Variable INVITATION_TO_CHANNEL_FEE is not a number ${process.env.INVITATION_TO_CHANNEL_FEE}`);
const invitationToChannelFee = +process.env.INVITATION_TO_CHANNEL_FEE;
// if(!process.env.INVITATION_TO_CHANNEL_FEE) throw new Error('Environment Variable missing: INVITATION_TO_CHANNEL_FEE');
if(isNaN(process.env.METIS_CHANNEL_MEMBER_FEE)) throw new Error(`Environment Variable METIS_CHANNEL_MEMBER_FEE is not a number ${process.env.METIS_CHANNEL_MEMBER_FEE}`);
const metisChannelMemberFee = +process.env.METIS_CHANNEL_MEMBER_FEE;
// if(!process.env.METIS_CHANNEL_MEMBER_FEE) throw new Error('Environment Variable missing: METIS_CHANNEL_MEMBER_FEE');
if(isNaN(process.env.ALIAS_ASSIGNMENT_FEE)) throw new Error(`Environment Variable ALIAS_ASSIGNMENT_FEE is not a number ${process.env.ALIAS_ASSIGNMENT_FEE}`);
const aliasAssignmentFee = +process.env.ALIAS_ASSIGNMENT_FEE;
// if(!process.env.ALIAS_ASSIGNMENT_FEE) throw new Error('Environment Variable missing: ALIAS_ASSIGNMENT_FEE');
if(isNaN(process.env.ACCOUNT_PROPERTY_DELETION_FEE)) throw new Error(`Environment Variable ACCOUNT_PROPERTY_DELETION_FEE is not a number ${process.env.ACCOUNT_PROPERTY_DELETION_FEE}`);
const accountPropertyDeletionFee = +process.env.ACCOUNT_PROPERTY_DELETION_FEE;
// if(!process.env.ACCOUNT_PROPERTY_DELETION_FEE) throw new Error('Environment Variable missing: ACCOUNT_PROPERTY_DELETION_FEE');
if(isNaN(process.env.METIS_MESSAGE_FEE)) throw new Error(`Environment Variable METIS_MESSAGE_FEE is not a number ${process.env.METIS_MESSAGE_FEE}`);
const metisMessageFee = +process.env.METIS_MESSAGE_FEE;
if(isNaN(process.env.MESSAGE_CHARACTER_FEE)) throw new Error(`Environment Variable MESSAGE_CHARACTER_FEE is not a number ${process.env.MESSAGE_CHARACTER_FEE}`);
const messageCharacterFee = +process.env.MESSAGE_CHARACTER_FEE;
// if(!process.env.MESSAGE_CHARACTER_FEE) throw new Error('Environment Variable missing: MESSAGE_CHARACTER_FEE');

module.exports.feeConf = {
regularTransaction: {NQT: regularTransactionFee},
accountRecord: {NQT: accountRecordFee},
newUserFunding: {NQT: newUserFundingFee},
ordinaryPayment: {NQT: ordinaryPaymentFee},
accountProperty: {NQT: accountPropertyFee},
accountPropertyDeletion: {NQT: accountPropertyDeletionFee},
invitationToChannel: {NQT: invitationToChannelFee},
channelMember: {NQT: metisChannelMemberFee},
aliasAssignment: {NQT: aliasAssignmentFee},
message: {NQT: metisMessageFee},
messageCharacter: {NQT: messageCharacterFee}
}


2 changes: 1 addition & 1 deletion controllers/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ module.exports = (app, passport, jobs, websocket) => {
logger.error(`****************************************************************`);
logger.error(`** JobQueue: channel-creation-confirmation.on(failed))`);
logger.error(`****************************************************************`);
logger.error(`error= ${error}`)
logger.error(`error= ${errorMessage}`)
logger.error(`errorMessage= ${JSON.stringify(errorMessage)}`);
websocket.of('/channels').to(memberAccountProperties.address).emit('channelCreationFailed', job.id);
console.log(errorMessage)
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- 28017:28017
redis:
image: "redis"
command: redis-server --requirepass 123
volumes:
- $PWD/redis-data:/var/lib/redis
- $PWD/redis.conf:/usr/local/etc/redis/redis.conf
Expand Down
30 changes: 19 additions & 11 deletions errors/metisError.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@ class MetisError extends Error {


class JupiterApiError extends Error {
constructor(messsage = '', httpResponseStatus = StatusCode.ServerErrorInternal) {
constructor(messsage = '', httpResponseStatus = StatusCode.ServerErrorInternal, serverErrorCode = null) {
super(`API Response Error: ${messsage}`);
this.name = `MetisApiError`;
this.status = httpResponseStatus;
this.code = MetisErrorCode.JupiterApiError;
this.serverErrorCode = serverErrorCode;
Object.setPrototypeOf(this, JupiterApiError.prototype); //fixes a problem with instanceof
}
}

class UnknownAliasError extends Error {
/**
*
* @param message
*/
constructor(message = '') {

class MetisErrorUnknownAlias extends Error {
constructor(message = '', aliasName = '') {
super(message);
this.name = `UnknownAliasError`;
this.code = MetisErrorCode.UnknownAliasError;
Object.setPrototypeOf(this, UnknownAliasError.prototype); //fixes a problem with instanceof
this.name = `MetisErrorUnknownAlias`;
this.code = MetisErrorCode.MetisErrorUnknownAlias;
this.aliasName = aliasName;
Object.setPrototypeOf(this, MetisErrorUnknownAlias.prototype); //fixes a problem with instanceof
}
}

Expand Down Expand Up @@ -294,9 +293,17 @@ class MetisErrorFileTooLarge extends MetisError {
Object.setPrototypeOf(this, MetisErrorFileTooLarge.prototype); //fixes a problem with instanceof
}
}
class MetisErrorJupiterUnknownTransaction extends MetisError {
constructor(message = '', transactionId='') {
super(`Unknown Transaction ${transactionId}. ${message}`);
this.name = "MetisErrorJupiterUnknownTransaction"
this.code = MetisErrorCode.MetisErrorJupiterUnknownTransaction;
Object.setPrototypeOf(this, MetisErrorJupiterUnknownTransaction.prototype); //fixes a problem with instanceof
}
}
module.exports.MetisError = MetisError;
module.exports.JupiterApiError = JupiterApiError;
module.exports.UnknownAliasError = UnknownAliasError;
module.exports.MetisErrorUnknownAlias = MetisErrorUnknownAlias;
// module.exports.BadJupiterAddressError = BadJupiterAddressError;
module.exports.BadGravityAccountPropertiesError = BadGravityAccountPropertiesError;
module.exports.ChannelRecordValidatorError = ChannelRecordValidatorError;
Expand Down Expand Up @@ -324,3 +331,4 @@ module.exports.MetisErrorBadRequestParams = MetisErrorBadRequestParams;
module.exports.MetisErrorPushNotificationFailed = MetisErrorPushNotificationFailed;
module.exports.MetisErrorSendMessageToJupiterFailed = MetisErrorSendMessageToJupiterFailed;
module.exports.MetisErrorFileTooLarge = MetisErrorFileTooLarge;
module.exports.MetisErrorJupiterUnknownTransaction = MetisErrorJupiterUnknownTransaction;
Empty file modified pixi.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 67 additions & 98 deletions services/FeeManager.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,77 @@
const {feeConf} = require("../config/feeConf");
const _ = require("lodash");
const {jimConfig} = require("../src/jim/config/jimConfig");
const logger = require('../utils/logger')(module);

// Jupiter v2.4.0 Fee Enhancements
// Regular transactions = 0.00005 JUP
// DEX orders = 0.00005 JUP
// alias = 0.00005 JUP
// Data, JIM, IO = 0.00007 JUP (~2400 JUP per GB of data)
// Metis text messages = 0.00001 JUP
// Shuffling = 10 JUP
// Asset Creation = 50 JUP
// NFT Creation = 50 JUP

class FeeManager {

constructor(
regularTransactionFee,
invitationToChannelFee,
metisChannelMemberFee,
arbitraryMessageFee,
aliasAssigmentFee,
accountPropertyFee,
accountPropertyDeletionFee,
newUserFundingFee,
newTableFundingFee,
accountRecordFee,
ordinaryPaymentFee,
metisMessageFee
) {

if(!regularTransactionFee){throw new Error('missing regularTransactionFee')}
if(!invitationToChannelFee){throw new Error('missing invitationToChannelFee')}
if(!metisChannelMemberFee){throw new Error('missing metisChannelMemberFee')}
if(!arbitraryMessageFee){throw new Error('missing arbitraryMessageFee')}
if(!aliasAssigmentFee){throw new Error('missing aliasAssigmentFee')}
if(!accountPropertyFee){throw new Error('missing accountPropertyFee')}
if(!accountPropertyDeletionFee){throw new Error('missing accountPropertyDeletionFee')}
if(!newUserFundingFee){throw new Error('missing newUserFundingFee')}
if(!newTableFundingFee){throw new Error('missing newTableFundingFee')}
if(!accountRecordFee){throw new Error('missing accountRecordFee')}
if(!ordinaryPaymentFee){throw new Error('missing ordinaryPaymentFee')}
if(!metisMessageFee){throw new Error('missing metisMessageFee')}

constructor() {
this.fees = [];
this.fees.push({
feeType: FeeManager.feeTypes.metisMessage,
fee: metisMessageFee,
fee: feeConf.message.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.metisMessage
})

this.fees.push({
feeType: FeeManager.feeTypes.regular_transaction,
fee: regularTransactionFee,
fee: feeConf.regularTransaction.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.arbitraryMessage
})


this.fees.push({
feeType: FeeManager.feeTypes.account_record,
fee: accountRecordFee,
fee: feeConf.accountRecord.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.metisAccountRecord
})

this.fees.push({
feeType: FeeManager.feeTypes.invitation_to_channel,
fee: invitationToChannelFee,
fee: feeConf.invitationToChannel.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.metisChannelInvitation
})
this.fees.push({
feeType: FeeManager.feeTypes.metis_channel_member,
fee: metisChannelMemberFee,
fee: feeConf.channelMember.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.metisChannelMember
});
this.fees.push({
feeType: FeeManager.feeTypes.alias_assignment,
fee: aliasAssigmentFee,
fee: feeConf.aliasAssignment.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.aliasAssignment
});
this.fees.push({
feeType: FeeManager.feeTypes.account_property,
fee: accountPropertyFee,
fee: feeConf.accountProperty.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.accountProperty
});
this.fees.push({
feeType: FeeManager.feeTypes.account_property_deletion,
fee: accountPropertyDeletionFee,
fee: feeConf.accountPropertyDeletion.NQT,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.accountPropertyDeletion
});

this.fees.push({
feeType: FeeManager.feeTypes.new_user_funding,
fee: newUserFundingFee,
fee: feeConf.newUserFunding.NQT,
type: FeeManager.TransactionTypes.payment,
subtype: FeeManager.JupiterTypZeroSubtypes.ordinaryPayment
});

this.fees.push({
feeType: FeeManager.feeTypes.new_table_funding,
fee: newTableFundingFee,
feeType: FeeManager.feeTypes.ordinary_payment,
fee: feeConf.ordinaryPayment.NQT ,
type: FeeManager.TransactionTypes.payment,
subtype: FeeManager.JupiterTypZeroSubtypes.ordinaryPayment
});

this.fees.push({
feeType: FeeManager.feeTypes.ordinary_payment,
fee: ordinaryPaymentFee ,
type: FeeManager.TransactionTypes.payment,
subtype: FeeManager.JupiterTypZeroSubtypes.ordinaryPayment
feeType: FeeManager.feeTypes.messageCharacter,
fee: feeConf.messageCharacter.NQT ,
type: FeeManager.TransactionTypes.messaging_voting_aliases,
subtype: FeeManager.JupiterTypeOneSubtypes.metisMessage
});
}

Expand All @@ -130,9 +89,9 @@ class FeeManager {
'account_property': 'account_property',
'account_property_deletion': 'account_property_deletion',
'new_user_funding':'new_user_funding',
'new_table_funding':'new_table_funding',
'ordinary_payment': 'ordinary_payment',
'metisMessage': 'metisMessage',
'messageCharacter': 'message_character',
}

static TransactionTypes = {
Expand Down Expand Up @@ -179,11 +138,7 @@ class FeeManager {
const fees = this.fees.filter(fee => {
return feeType === fee.feeType
})

if (fees.length) {
return fees[0].fee
}

if (fees.length) return fees[0].fee
throw new Error('Fee doesnt exist');
}

Expand All @@ -207,28 +162,54 @@ class FeeManager {
return typeSubType[0]
}

getTotalDataFee(bufferData){
const total = bufferData.reduce( (reduced,item)=>{
reduced = reduced + this.getCalculatedMessageFee(item);
}, 0 )

return total * 1.03
/**
*
* @param messageSize
* @return {number}
*/
calculateMessageFee(messageSize){
logger.verbose(`#### calculateMessageFee(messageSize)`);
if(!_.isNumber(messageSize)) throw new Error(`messageSize needs to be a number`);
const baseFee = this.getFee(FeeManager.feeTypes.metisMessage);
const charFee = +this.getFee(FeeManager.feeTypes.messageCharacter);
const calculatedFee = baseFee + (messageSize*charFee);
return calculatedFee;
}

getCalculatedMessageFee(message) {
const size = message.length;
const fee = this.getFee(FeeManager.feeTypes.metisMessage);
if (size === 0) return fee
if (size <= 5000) return 800000
if (size <= 10000) return 1600000
if (size <= 15000) return 2300000
if (size <= 20000) return 3100000
if (size <= 25000) return 3900000
if (size <= 30000) return 4700000
if (size <= 35000) return 5500000
if (size <= 40000) return 6300000
return 6500000
/**
*
* @param base64FileSize
* @return {number}
*/
calculateFileFee(base64FileSize){
if(!base64FileSize) return 0; //@TODO what should we return?
const numberOfChunks = Math.ceil(base64FileSize/+jimConfig.fileChunkSize);
let fee = 0;
for(let i=0; i<numberOfChunks; i++){
fee = fee + this.calculateMessageFee(+jimConfig.fileChunkSize);
}
return fee;
}





// getCalculatedMessageFee(message) {
// const size = message.length;
// const fee = this.getFee(FeeManager.feeTypes.metisMessage);
// if (size === 0) return fee
// if (size <= 5000) return 800000
// if (size <= 10000) return 1600000
// if (size <= 15000) return 2300000
// if (size <= 20000) return 3100000
// if (size <= 25000) return 3900000
// if (size <= 30000) return 4700000
// if (size <= 35000) return 5500000
// if (size <= 40000) return 6300000
// return 6500000
// }
// export function calculateExpectedFees(data: Array<string>): number {
// let expectedFees = 0;
// data.forEach((data) => expectedFees += calculateMessageFee(data.length));
Expand All @@ -237,17 +218,5 @@ class FeeManager {
}

module.exports.FeeManager = FeeManager;
module.exports.feeManagerSingleton = new FeeManager(
process.env.REGULAR_TRANSACTION_FEE,
process.env.INVITATION_TO_CHANNEL_FEE,
process.env.METIS_CHANNEL_MEMBER_FEE,
process.env.ARBITRARY_MESSAGE_FEE,
process.env.ALIAS_ASSIGNMENT_FEE,
process.env.ACCOUNT_PROPERTY_FEE,
process.env.ACCOUNT_PROPERTY_DELETION_FEE,
process.env.NEW_USER_FUNDING_FEE,
process.env.NEW_TABLE_FUNDING_FEE,
process.env.ACCOUNT_RECORD_FEE,
process.env.ORDINARY_PAYMENT_FEE,
process.env.METIS_MESSAGE_FEE
);
module.exports.feeManagerSingleton = new FeeManager();

Loading

0 comments on commit 05de44e

Please sign in to comment.