-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from cd-sigma/main
Build
- Loading branch information
Showing
25 changed files
with
2,982 additions
and
237 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const mongoLib = require("../../lib/mongo.lib"); | ||
const responseLib = require("../../lib/response.lib"); | ||
const validatorUtil = require("../../util/validators.util"); | ||
|
||
const cmtOrderModel = require("../../model/cmt.order.model"); | ||
const resStatusEnum = require("../../enum/res.status.enum"); | ||
|
||
async function addCmtOrder(req, res) { | ||
try { | ||
const {positionId, collateralAddress, collateralAmount} = req.body; | ||
let {address} = req.user.payload; | ||
address = address.toLowerCase(); | ||
|
||
if (validatorUtil.isEmpty(collateralAddress) || validatorUtil.isEmpty(collateralAmount)) { | ||
return responseLib.sendResponse(res, null, `collateralAddress and collateralAmount are required` | ||
, resStatusEnum.VALIDATION_ERROR); | ||
} | ||
|
||
await mongoLib.createDoc(cmtOrderModel, { | ||
ownerAddress: address, | ||
positionId: positionId, | ||
collateralAddress: collateralAddress, | ||
collateralAmount: collateralAmount, | ||
}) | ||
|
||
return responseLib.sendResponse(res, "CMT order added successfully!", null, resStatusEnum.SUCCESS); | ||
} catch (error) { | ||
return responseLib.sendResponse(res, null, error, resStatusEnum.INTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
module.exports = { | ||
addCmtOrder: addCmtOrder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const express = require("express") | ||
const router = express.Router() | ||
|
||
const cmtController = require("../controllers/cmt.controller") | ||
const authMiddleware = require("../../middleware/jwt.auth.middleware") | ||
|
||
router.post("/order/create", authMiddleware.isLoggedIn, cmtController.addCmtOrder); | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
const ERROR_STACK_TRACE_LIMIT = 1000; | ||
const NULL_ADDRESS = "0x0000000000000000000000000000000000000000"; | ||
const AAVE_V2_PRICE_ORACLE_ADDRESS = | ||
"0xa50ba011c48153de246e5192c8f9258a2ba79ca9"; | ||
"0xa50ba011c48153de246e5192c8f9258a2ba79ca9"; | ||
const FINSAFE_EXECUTOR_ADDRESS = "0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9"; //TODO: change this to the actual address | ||
const EMAIL_HOST = "mail.privateemail.com"; | ||
const EMAIL_PORT = 465; | ||
module.exports = { | ||
ERROR_STACK_TRACE_LIMIT: ERROR_STACK_TRACE_LIMIT, | ||
NULL_ADDRESS: NULL_ADDRESS, | ||
AAVE_V2_PRICE_ORACLE_ADDRESS: AAVE_V2_PRICE_ORACLE_ADDRESS, | ||
EMAIL_HOST: EMAIL_HOST, | ||
EMAIL_PORT: EMAIL_PORT, | ||
ERROR_STACK_TRACE_LIMIT: ERROR_STACK_TRACE_LIMIT, | ||
FINSAFE_EXECUTOR_ADDRESS: FINSAFE_EXECUTOR_ADDRESS, | ||
NULL_ADDRESS: NULL_ADDRESS, | ||
AAVE_V2_PRICE_ORACLE_ADDRESS: AAVE_V2_PRICE_ORACLE_ADDRESS, | ||
EMAIL_HOST: EMAIL_HOST, | ||
EMAIL_PORT: EMAIL_PORT, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const globalConst=require("../global.const"); | ||
const errorUtil = require("../util/error.util"); | ||
const validatorUtil = require("../util/validators.util"); | ||
|
||
const finsafeExecutorAbi= require("../abi/finsafe.executor.abi.json"); | ||
|
||
function validateOrder(order) { | ||
try { | ||
if (validatorUtil.isEmpty(order.ownerAddress) || validatorUtil.isEmpty(order.positionId) || validatorUtil.isEmpty(order.timestamp) || validatorUtil.isEmpty(order.collateralAddress) || validatorUtil.isEmpty(order.collateralAmount)) { | ||
return false; | ||
} | ||
return true; | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
|
||
|
||
async function executeOrder(order, web3) { | ||
try { | ||
if(validatorUtil.isEmpty(order) || validatorUtil.isEmpty(web3)) { | ||
errorUtil.throwErr("Invalid order or web3!"); | ||
} | ||
|
||
if(!validateOrder(order)) { | ||
errorUtil.throwErr("Invalid order!"); | ||
} | ||
|
||
const lendingPoolContract= new web3.eth.Contract(finsafeExecutorAbi, globalConst.FINSAFE_EXECUTOR_ADDRESS); | ||
//TODO: execute order | ||
// await lendingPoolContract.methods.executeOrder(order.ownerAddress, order.collateralAddress, order.collateralAmount) | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
|
||
module.exports = { | ||
executeOrder: executeOrder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const mongoose = require("mongoose") | ||
const dbEnum = require("../enum/db.enum") | ||
|
||
const cmtOrderSchema = new mongoose.Schema({ | ||
ownerAddress: { | ||
type: String, | ||
required: true | ||
}, | ||
positionId: { | ||
type: String, | ||
required: true | ||
}, | ||
timestamp: { | ||
type: Number, | ||
required: true | ||
}, | ||
collateralAddress: { | ||
type: String, | ||
required: true | ||
}, | ||
collateralAmount: { | ||
type: Number, | ||
required: true | ||
}, | ||
isExecuted: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
isFailed: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, { | ||
timestamps: true | ||
}) | ||
|
||
module.exports = mongoose.connection.useDb(dbEnum.FINSAFE).model("cmt_order", cmtOrderSchema) |
Oops, something went wrong.