@dhedge/backend-flatcoin-core 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/enum.d.ts +14 -0
- package/dist/constants/enum.js +26 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +17 -0
- package/dist/contracts/abi/FlatcoinV1.json +95 -0
- package/dist/contracts/abi/Viewer.json +131 -0
- package/dist/contracts/index.d.ts +4 -0
- package/dist/contracts/index.js +30 -0
- package/dist/entity/apy-history.d.ts +6 -0
- package/dist/entity/apy-history.js +41 -0
- package/dist/entity/flatcoin-pnl.d.ts +10 -0
- package/dist/entity/flatcoin-pnl.js +54 -0
- package/dist/entity/index.d.ts +3 -0
- package/dist/entity/index.js +3 -0
- package/dist/entity/period-performance.d.ts +9 -0
- package/dist/entity/period-performance.js +56 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/repository/apy-history.repository.d.ts +7 -0
- package/dist/repository/apy-history.repository.js +38 -0
- package/dist/repository/apy.repository.d.ts +7 -0
- package/dist/repository/apy.repository.js +33 -0
- package/dist/repository/index.d.ts +3 -0
- package/dist/repository/index.js +19 -0
- package/dist/repository/price.repository.d.ts +11 -0
- package/dist/repository/price.repository.js +61 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/price.util.d.ts +3 -0
- package/dist/utils/price.util.js +11 -0
- package/package.json +4 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare enum HistoricalPeriod {
|
|
2
|
+
ONE_DAY = "1d",
|
|
3
|
+
ONE_WEEK = "1w",
|
|
4
|
+
ONE_MONTH = "1m",
|
|
5
|
+
ONE_YEAR = "12m",
|
|
6
|
+
ALL = "all"
|
|
7
|
+
}
|
|
8
|
+
export declare const PERIOD_IN_SECONDS: {
|
|
9
|
+
"1d": number;
|
|
10
|
+
"1w": number;
|
|
11
|
+
"1m": number;
|
|
12
|
+
};
|
|
13
|
+
export { HistoricalPeriod };
|
|
14
|
+
export declare const getChartPeriod: (value: string) => HistoricalPeriod;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChartPeriod = exports.HistoricalPeriod = exports.PERIOD_IN_SECONDS = void 0;
|
|
4
|
+
var HistoricalPeriod;
|
|
5
|
+
(function (HistoricalPeriod) {
|
|
6
|
+
HistoricalPeriod["ONE_DAY"] = "1d";
|
|
7
|
+
HistoricalPeriod["ONE_WEEK"] = "1w";
|
|
8
|
+
HistoricalPeriod["ONE_MONTH"] = "1m";
|
|
9
|
+
HistoricalPeriod["ONE_YEAR"] = "12m";
|
|
10
|
+
HistoricalPeriod["ALL"] = "all";
|
|
11
|
+
})(HistoricalPeriod || (exports.HistoricalPeriod = HistoricalPeriod = {}));
|
|
12
|
+
exports.PERIOD_IN_SECONDS = {
|
|
13
|
+
[HistoricalPeriod.ONE_DAY]: 24 * 60 * 60 * 1000,
|
|
14
|
+
[HistoricalPeriod.ONE_WEEK]: 7 * 24 * 60 * 60 * 1000,
|
|
15
|
+
[HistoricalPeriod.ONE_MONTH]: 30 * 24 * 60 * 60 * 1000,
|
|
16
|
+
};
|
|
17
|
+
const getChartPeriod = (value) => {
|
|
18
|
+
const indexOf = Object.values(HistoricalPeriod).indexOf(value);
|
|
19
|
+
if (indexOf !== undefined) {
|
|
20
|
+
return Object.keys(HistoricalPeriod)[indexOf];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return HistoricalPeriod.ONE_MONTH;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.getChartPeriod = getChartPeriod;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './enum';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./enum"), exports);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "address",
|
|
6
|
+
"name": "account",
|
|
7
|
+
"type": "address"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"name": "balanceOf",
|
|
11
|
+
"outputs": [
|
|
12
|
+
{
|
|
13
|
+
"internalType": "uint256",
|
|
14
|
+
"name": "",
|
|
15
|
+
"type": "uint256"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"stateMutability": "view",
|
|
19
|
+
"type": "function"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"inputs": [
|
|
23
|
+
{
|
|
24
|
+
"internalType": "address",
|
|
25
|
+
"name": "_logic",
|
|
26
|
+
"type": "address"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"internalType": "address",
|
|
30
|
+
"name": "admin_",
|
|
31
|
+
"type": "address"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"internalType": "bytes",
|
|
35
|
+
"name": "_data",
|
|
36
|
+
"type": "bytes"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"stateMutability": "payable",
|
|
40
|
+
"type": "constructor"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"anonymous": false,
|
|
44
|
+
"inputs": [
|
|
45
|
+
{
|
|
46
|
+
"indexed": false,
|
|
47
|
+
"internalType": "address",
|
|
48
|
+
"name": "previousAdmin",
|
|
49
|
+
"type": "address"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"indexed": false,
|
|
53
|
+
"internalType": "address",
|
|
54
|
+
"name": "newAdmin",
|
|
55
|
+
"type": "address"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"name": "AdminChanged",
|
|
59
|
+
"type": "event"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"anonymous": false,
|
|
63
|
+
"inputs": [
|
|
64
|
+
{
|
|
65
|
+
"indexed": true,
|
|
66
|
+
"internalType": "address",
|
|
67
|
+
"name": "beacon",
|
|
68
|
+
"type": "address"
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"name": "BeaconUpgraded",
|
|
72
|
+
"type": "event"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"anonymous": false,
|
|
76
|
+
"inputs": [
|
|
77
|
+
{
|
|
78
|
+
"indexed": true,
|
|
79
|
+
"internalType": "address",
|
|
80
|
+
"name": "implementation",
|
|
81
|
+
"type": "address"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"name": "Upgraded",
|
|
85
|
+
"type": "event"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"stateMutability": "payable",
|
|
89
|
+
"type": "fallback"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"stateMutability": "payable",
|
|
93
|
+
"type": "receive"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "contract IFlatcoinVault",
|
|
6
|
+
"name": "_vault",
|
|
7
|
+
"type": "address"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"stateMutability": "nonpayable",
|
|
11
|
+
"type": "constructor"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"inputs": [
|
|
15
|
+
{
|
|
16
|
+
"internalType": "address",
|
|
17
|
+
"name": "account",
|
|
18
|
+
"type": "address"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"name": "getAccountLeveragePositionData",
|
|
22
|
+
"outputs": [
|
|
23
|
+
{
|
|
24
|
+
"components": [
|
|
25
|
+
{
|
|
26
|
+
"internalType": "uint256",
|
|
27
|
+
"name": "tokenId",
|
|
28
|
+
"type": "uint256"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"internalType": "uint256",
|
|
32
|
+
"name": "entryPrice",
|
|
33
|
+
"type": "uint256"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"internalType": "uint256",
|
|
37
|
+
"name": "marginDeposited",
|
|
38
|
+
"type": "uint256"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"internalType": "uint256",
|
|
42
|
+
"name": "additionalSize",
|
|
43
|
+
"type": "uint256"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"internalType": "int256",
|
|
47
|
+
"name": "entryCumulativeFunding",
|
|
48
|
+
"type": "int256"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"internalType": "int256",
|
|
52
|
+
"name": "profitLoss",
|
|
53
|
+
"type": "int256"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"internalType": "int256",
|
|
57
|
+
"name": "accruedFunding",
|
|
58
|
+
"type": "int256"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"internalType": "int256",
|
|
62
|
+
"name": "marginAfterSettlement",
|
|
63
|
+
"type": "int256"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"internalType": "uint256",
|
|
67
|
+
"name": "liquidationPrice",
|
|
68
|
+
"type": "uint256"
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"internalType": "struct FlatcoinStructs.LeveragePositionData[]",
|
|
72
|
+
"name": "positionData",
|
|
73
|
+
"type": "tuple[]"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"stateMutability": "view",
|
|
77
|
+
"type": "function"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"inputs": [],
|
|
81
|
+
"name": "getFlatcoinPriceInUSD",
|
|
82
|
+
"outputs": [
|
|
83
|
+
{
|
|
84
|
+
"internalType": "uint256",
|
|
85
|
+
"name": "priceInUSD",
|
|
86
|
+
"type": "uint256"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"stateMutability": "view",
|
|
90
|
+
"type": "function"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"inputs": [],
|
|
94
|
+
"name": "getFlatcoinTVL",
|
|
95
|
+
"outputs": [
|
|
96
|
+
{
|
|
97
|
+
"internalType": "uint256",
|
|
98
|
+
"name": "tvl",
|
|
99
|
+
"type": "uint256"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"stateMutability": "view",
|
|
103
|
+
"type": "function"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"inputs": [],
|
|
107
|
+
"name": "getMarketSkewPercentage",
|
|
108
|
+
"outputs": [
|
|
109
|
+
{
|
|
110
|
+
"internalType": "int256",
|
|
111
|
+
"name": "skewPercent",
|
|
112
|
+
"type": "int256"
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
"stateMutability": "view",
|
|
116
|
+
"type": "function"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"inputs": [],
|
|
120
|
+
"name": "vault",
|
|
121
|
+
"outputs": [
|
|
122
|
+
{
|
|
123
|
+
"internalType": "contract IFlatcoinVault",
|
|
124
|
+
"name": "",
|
|
125
|
+
"type": "address"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"stateMutability": "view",
|
|
129
|
+
"type": "function"
|
|
130
|
+
}
|
|
131
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Viewer = exports.FlatcoinV1 = void 0;
|
|
27
|
+
const FlatcoinV1 = __importStar(require("../contracts/abi/FlatcoinV1.json"));
|
|
28
|
+
exports.FlatcoinV1 = FlatcoinV1;
|
|
29
|
+
const Viewer = __importStar(require("../contracts/abi/Viewer.json"));
|
|
30
|
+
exports.Viewer = Viewer;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ApyHistory = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
16
|
+
let ApyHistory = class ApyHistory {
|
|
17
|
+
constructor(daily, timestamp) {
|
|
18
|
+
this.daily = daily;
|
|
19
|
+
this.timestamp = timestamp;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.ApyHistory = ApyHistory;
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, typeorm_1.PrimaryGeneratedColumn)({ name: 'id' }),
|
|
25
|
+
__metadata("design:type", Number)
|
|
26
|
+
], ApyHistory.prototype, "id", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
29
|
+
(0, typeorm_1.Column)({ name: 'daily', type: 'decimal', precision: 30, scale: 2, nullable: false, transformer: utils_1.numericTransformer }),
|
|
30
|
+
__metadata("design:type", Number)
|
|
31
|
+
], ApyHistory.prototype, "daily", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, graphql_1.Field)(() => Number, { nullable: false }),
|
|
34
|
+
(0, typeorm_1.Column)({ name: 'timestamp', type: 'numeric', precision: 25, nullable: false, transformer: utils_1.numericTransformer }),
|
|
35
|
+
__metadata("design:type", Number)
|
|
36
|
+
], ApyHistory.prototype, "timestamp", void 0);
|
|
37
|
+
exports.ApyHistory = ApyHistory = __decorate([
|
|
38
|
+
(0, graphql_1.ObjectType)(),
|
|
39
|
+
(0, typeorm_1.Entity)({ name: 'apy_history' }),
|
|
40
|
+
__metadata("design:paramtypes", [Number, Number])
|
|
41
|
+
], ApyHistory);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FlatcoinPnl = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
16
|
+
const ethers_1 = require("ethers");
|
|
17
|
+
let FlatcoinPnl = class FlatcoinPnl {
|
|
18
|
+
};
|
|
19
|
+
exports.FlatcoinPnl = FlatcoinPnl;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, typeorm_1.PrimaryGeneratedColumn)({ name: 'id' }),
|
|
22
|
+
__metadata("design:type", Number)
|
|
23
|
+
], FlatcoinPnl.prototype, "id", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, graphql_1.Field)(() => String, { nullable: false }),
|
|
26
|
+
(0, typeorm_1.Column)({ name: 'account' }),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], FlatcoinPnl.prototype, "account", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
31
|
+
(0, typeorm_1.Column)({ name: 'pnl_usd_formatted', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
32
|
+
__metadata("design:type", Number)
|
|
33
|
+
], FlatcoinPnl.prototype, "pnlUsdFormatted", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
36
|
+
(0, typeorm_1.Column)({ name: 'pnl_percentage', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
37
|
+
__metadata("design:type", Number)
|
|
38
|
+
], FlatcoinPnl.prototype, "pnlPercentage", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, typeorm_1.Column)({ name: 'unit_amount', type: 'bigint', precision: 30, transformer: utils_1.bigNumberTransformer }),
|
|
41
|
+
__metadata("design:type", ethers_1.BigNumber)
|
|
42
|
+
], FlatcoinPnl.prototype, "unitAmount", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, typeorm_1.Column)({ name: 'unit_average_buy_price', type: 'bigint', precision: 30, transformer: utils_1.bigNumberTransformer }),
|
|
45
|
+
__metadata("design:type", ethers_1.BigNumber)
|
|
46
|
+
], FlatcoinPnl.prototype, "unitAverageBuyPrice", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, typeorm_1.Column)({ name: 'block_updated_at', type: 'numeric', precision: 25, transformer: utils_1.numericTransformer }),
|
|
49
|
+
__metadata("design:type", Number)
|
|
50
|
+
], FlatcoinPnl.prototype, "blockUpdatedAt", void 0);
|
|
51
|
+
exports.FlatcoinPnl = FlatcoinPnl = __decorate([
|
|
52
|
+
(0, graphql_1.ObjectType)(),
|
|
53
|
+
(0, typeorm_1.Entity)({ name: 'flatcoin_pnl' })
|
|
54
|
+
], FlatcoinPnl);
|
package/dist/entity/index.d.ts
CHANGED
|
@@ -5,3 +5,6 @@ export * from './flatcoin.price.one.week';
|
|
|
5
5
|
export * from './flatcoin.price.one.year';
|
|
6
6
|
export * from './flatcoin.price.parent';
|
|
7
7
|
export * from './flatcoin.price';
|
|
8
|
+
export * from './apy-history';
|
|
9
|
+
export * from './flatcoin-pnl';
|
|
10
|
+
export * from './period-performance';
|
package/dist/entity/index.js
CHANGED
|
@@ -21,3 +21,6 @@ __exportStar(require("./flatcoin.price.one.week"), exports);
|
|
|
21
21
|
__exportStar(require("./flatcoin.price.one.year"), exports);
|
|
22
22
|
__exportStar(require("./flatcoin.price.parent"), exports);
|
|
23
23
|
__exportStar(require("./flatcoin.price"), exports);
|
|
24
|
+
__exportStar(require("./apy-history"), exports);
|
|
25
|
+
__exportStar(require("./flatcoin-pnl"), exports);
|
|
26
|
+
__exportStar(require("./period-performance"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PeriodPerformance = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
16
|
+
let PeriodPerformance = class PeriodPerformance {
|
|
17
|
+
};
|
|
18
|
+
exports.PeriodPerformance = PeriodPerformance;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, typeorm_1.PrimaryGeneratedColumn)({ name: 'id' }),
|
|
21
|
+
__metadata("design:type", Number)
|
|
22
|
+
], PeriodPerformance.prototype, "id", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
25
|
+
(0, typeorm_1.Column)({ name: 'day', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
26
|
+
__metadata("design:type", Number)
|
|
27
|
+
], PeriodPerformance.prototype, "day", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
30
|
+
(0, typeorm_1.Column)({ name: 'week', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
31
|
+
__metadata("design:type", Number)
|
|
32
|
+
], PeriodPerformance.prototype, "week", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
35
|
+
(0, typeorm_1.Column)({ name: 'month', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
36
|
+
__metadata("design:type", Number)
|
|
37
|
+
], PeriodPerformance.prototype, "month", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
40
|
+
(0, typeorm_1.Column)({ name: 'half_year', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
41
|
+
__metadata("design:type", Number)
|
|
42
|
+
], PeriodPerformance.prototype, "halfYear", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
45
|
+
(0, typeorm_1.Column)({ name: 'year', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
46
|
+
__metadata("design:type", Number)
|
|
47
|
+
], PeriodPerformance.prototype, "year", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, graphql_1.Field)(() => graphql_1.Float, { nullable: false }),
|
|
50
|
+
(0, typeorm_1.Column)({ name: 'all_time', type: 'decimal', precision: 30, scale: 2, transformer: utils_1.numericTransformer }),
|
|
51
|
+
__metadata("design:type", Number)
|
|
52
|
+
], PeriodPerformance.prototype, "all", void 0);
|
|
53
|
+
exports.PeriodPerformance = PeriodPerformance = __decorate([
|
|
54
|
+
(0, graphql_1.ObjectType)(),
|
|
55
|
+
(0, typeorm_1.Entity)({ name: 'period_performance' })
|
|
56
|
+
], PeriodPerformance);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,3 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./entity"), exports);
|
|
18
18
|
__exportStar(require("./utils"), exports);
|
|
19
|
+
__exportStar(require("./contracts"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
21
|
+
__exportStar(require("./repository"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { ApyHistory } from '../entity';
|
|
3
|
+
export declare class ApyHistoryRepository {
|
|
4
|
+
private readonly repository;
|
|
5
|
+
constructor(repository: Repository<ApyHistory>);
|
|
6
|
+
getAllFromTimestamp(fromTimestamp: number): Promise<ApyHistory[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ApyHistoryRepository = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
+
const typeorm_2 = require("typeorm");
|
|
19
|
+
const entity_1 = require("../entity");
|
|
20
|
+
let ApyHistoryRepository = class ApyHistoryRepository {
|
|
21
|
+
constructor(repository) {
|
|
22
|
+
this.repository = repository;
|
|
23
|
+
}
|
|
24
|
+
async getAllFromTimestamp(fromTimestamp) {
|
|
25
|
+
return await this.repository
|
|
26
|
+
.createQueryBuilder('apy_history')
|
|
27
|
+
.where('timestamp > :fromTimestamp')
|
|
28
|
+
.orderBy('apy_history.timestamp', 'ASC')
|
|
29
|
+
.setParameter('fromTimestamp', fromTimestamp)
|
|
30
|
+
.getMany();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.ApyHistoryRepository = ApyHistoryRepository;
|
|
34
|
+
exports.ApyHistoryRepository = ApyHistoryRepository = __decorate([
|
|
35
|
+
(0, common_1.Injectable)(),
|
|
36
|
+
__param(0, (0, typeorm_1.InjectRepository)(entity_1.ApyHistory)),
|
|
37
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
38
|
+
], ApyHistoryRepository);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ApyRepository = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
+
const typeorm_2 = require("typeorm");
|
|
19
|
+
const entity_1 = require("../entity");
|
|
20
|
+
let ApyRepository = class ApyRepository {
|
|
21
|
+
constructor(repository) {
|
|
22
|
+
this.repository = repository;
|
|
23
|
+
}
|
|
24
|
+
async getApy() {
|
|
25
|
+
return this.repository.createQueryBuilder().getOne();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.ApyRepository = ApyRepository;
|
|
29
|
+
exports.ApyRepository = ApyRepository = __decorate([
|
|
30
|
+
(0, common_1.Injectable)(),
|
|
31
|
+
__param(0, (0, typeorm_1.InjectRepository)(entity_1.Apy)),
|
|
32
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
33
|
+
], ApyRepository);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./apy-history.repository"), exports);
|
|
18
|
+
__exportStar(require("./apy.repository"), exports);
|
|
19
|
+
__exportStar(require("./price.repository"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { FlatcoinPriceOneDay, FlatcoinPriceOneMonth, FlatcoinPriceOneWeek, FlatcoinPriceOneYear, FlatcoinPriceParent } from '../entity';
|
|
3
|
+
export declare class PriceRepository {
|
|
4
|
+
private flatcoinPriceOneDayRepository;
|
|
5
|
+
private flatcoinPriceOneWeekRepository;
|
|
6
|
+
private flatcoinPriceOneMonthRepository;
|
|
7
|
+
private flatcoinPriceOneYearRepository;
|
|
8
|
+
constructor(flatcoinPriceOneDayRepository: Repository<FlatcoinPriceOneDay>, flatcoinPriceOneWeekRepository: Repository<FlatcoinPriceOneWeek>, flatcoinPriceOneMonthRepository: Repository<FlatcoinPriceOneMonth>, flatcoinPriceOneYearRepository: Repository<FlatcoinPriceOneYear>);
|
|
9
|
+
findAllByPeriod(period: string): Promise<FlatcoinPriceParent[]>;
|
|
10
|
+
private getRepository;
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PriceRepository = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
+
const typeorm_2 = require("typeorm");
|
|
19
|
+
const entity_1 = require("../entity");
|
|
20
|
+
const constants_1 = require("../constants");
|
|
21
|
+
let PriceRepository = class PriceRepository {
|
|
22
|
+
constructor(flatcoinPriceOneDayRepository, flatcoinPriceOneWeekRepository, flatcoinPriceOneMonthRepository, flatcoinPriceOneYearRepository) {
|
|
23
|
+
this.flatcoinPriceOneDayRepository = flatcoinPriceOneDayRepository;
|
|
24
|
+
this.flatcoinPriceOneWeekRepository = flatcoinPriceOneWeekRepository;
|
|
25
|
+
this.flatcoinPriceOneMonthRepository = flatcoinPriceOneMonthRepository;
|
|
26
|
+
this.flatcoinPriceOneYearRepository = flatcoinPriceOneYearRepository;
|
|
27
|
+
}
|
|
28
|
+
async findAllByPeriod(period) {
|
|
29
|
+
return this.getRepository(period).find({
|
|
30
|
+
order: {
|
|
31
|
+
timestamp: 'ASC',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getRepository(period) {
|
|
36
|
+
switch (period) {
|
|
37
|
+
case constants_1.HistoricalPeriod.ONE_DAY:
|
|
38
|
+
return this.flatcoinPriceOneDayRepository;
|
|
39
|
+
case constants_1.HistoricalPeriod.ONE_WEEK:
|
|
40
|
+
return this.flatcoinPriceOneWeekRepository;
|
|
41
|
+
case constants_1.HistoricalPeriod.ONE_MONTH:
|
|
42
|
+
return this.flatcoinPriceOneMonthRepository;
|
|
43
|
+
case constants_1.HistoricalPeriod.ONE_YEAR:
|
|
44
|
+
return this.flatcoinPriceOneYearRepository;
|
|
45
|
+
default:
|
|
46
|
+
throw new Error('Invalid period provided.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.PriceRepository = PriceRepository;
|
|
51
|
+
exports.PriceRepository = PriceRepository = __decorate([
|
|
52
|
+
(0, common_1.Injectable)(),
|
|
53
|
+
__param(0, (0, typeorm_1.InjectRepository)(entity_1.FlatcoinPriceOneDay)),
|
|
54
|
+
__param(1, (0, typeorm_1.InjectRepository)(entity_1.FlatcoinPriceOneWeek)),
|
|
55
|
+
__param(2, (0, typeorm_1.InjectRepository)(entity_1.FlatcoinPriceOneMonth)),
|
|
56
|
+
__param(3, (0, typeorm_1.InjectRepository)(entity_1.FlatcoinPriceOneYear)),
|
|
57
|
+
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
58
|
+
typeorm_2.Repository,
|
|
59
|
+
typeorm_2.Repository,
|
|
60
|
+
typeorm_2.Repository])
|
|
61
|
+
], PriceRepository);
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ETHER_UNIT = exports.formatTokenBalance = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const formatTokenBalance = (price, fraction) => {
|
|
6
|
+
const numericValue = parseFloat(price.div(ethers_1.BigNumber.from('1000000000000000000').div(10 ** fraction)).toString()) / 10 ** fraction;
|
|
7
|
+
const formattedValue = numericValue.toFixed(fraction);
|
|
8
|
+
return parseFloat(formattedValue);
|
|
9
|
+
};
|
|
10
|
+
exports.formatTokenBalance = formatTokenBalance;
|
|
11
|
+
exports.ETHER_UNIT = ethers_1.BigNumber.from('1000000000000000000');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhedge/backend-flatcoin-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Backend Flatcoin Core",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"/dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@nestjs/core": "^9.0.0",
|
|
19
|
+
"@nestjs/common": "^9.0.0",
|
|
18
20
|
"@nestjs/graphql": "^12.0.9",
|
|
21
|
+
"@nestjs/typeorm": "^9.0.0",
|
|
19
22
|
"typeorm": "^0.3.17",
|
|
20
23
|
"ethers": "5.7.2"
|
|
21
24
|
},
|