curvance 3.2.4 → 3.3.0
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/abis/ProtocolReader.json +20 -10
- package/dist/chains/index.d.ts +20 -0
- package/dist/chains/index.d.ts.map +1 -1
- package/dist/chains/monad-mainnet.json +11 -1
- package/dist/classes/BorrowableCToken.d.ts.map +1 -1
- package/dist/classes/BorrowableCToken.js +11 -11
- package/dist/classes/BorrowableCToken.js.map +1 -1
- package/dist/classes/CToken.d.ts +12 -8
- package/dist/classes/CToken.d.ts.map +1 -1
- package/dist/classes/CToken.js +78 -90
- package/dist/classes/CToken.js.map +1 -1
- package/dist/classes/DexAggregators/KyberSwap.d.ts +2 -2
- package/dist/classes/DexAggregators/KyberSwap.d.ts.map +1 -1
- package/dist/classes/DexAggregators/KyberSwap.js +6 -10
- package/dist/classes/DexAggregators/KyberSwap.js.map +1 -1
- package/dist/classes/ERC4626.d.ts +2 -0
- package/dist/classes/ERC4626.d.ts.map +1 -1
- package/dist/classes/ERC4626.js +4 -0
- package/dist/classes/ERC4626.js.map +1 -1
- package/dist/classes/FormatConverter.d.ts +99 -0
- package/dist/classes/FormatConverter.d.ts.map +1 -0
- package/dist/classes/FormatConverter.js +151 -0
- package/dist/classes/FormatConverter.js.map +1 -0
- package/dist/classes/Market.d.ts.map +1 -1
- package/dist/classes/Market.js +5 -4
- package/dist/classes/Market.js.map +1 -1
- package/dist/classes/PositionManager.d.ts.map +1 -1
- package/dist/classes/PositionManager.js +3 -2
- package/dist/classes/PositionManager.js.map +1 -1
- package/dist/classes/ProtocolReader.d.ts +3 -2
- package/dist/classes/ProtocolReader.d.ts.map +1 -1
- package/dist/classes/ProtocolReader.js +4 -2
- package/dist/classes/ProtocolReader.js.map +1 -1
- package/dist/helpers.d.ts +10 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/classes/DexAggregators/KuruMainnet.d.ts +0 -1
- package/dist/classes/DexAggregators/KuruMainnet.d.ts.map +0 -1
- package/dist/classes/DexAggregators/KuruMainnet.js +0 -228
- package/dist/classes/DexAggregators/KuruMainnet.js.map +0 -1
- package/dist/classes/Kuru.d.ts +0 -59
- package/dist/classes/Kuru.d.ts.map +0 -1
- package/dist/classes/Kuru.js +0 -167
- package/dist/classes/Kuru.js.map +0 -1
- package/dist/classes/KuruMainnet.d.ts +0 -59
- package/dist/classes/KuruMainnet.d.ts.map +0 -1
- package/dist/classes/KuruMainnet.js +0 -167
- package/dist/classes/KuruMainnet.js.map +0 -1
|
@@ -8,6 +8,7 @@ const helpers_1 = require("../helpers");
|
|
|
8
8
|
const ProtocolReader_json_1 = __importDefault(require("../abis/ProtocolReader.json"));
|
|
9
9
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
10
10
|
const setup_1 = require("../setup");
|
|
11
|
+
const FormatConverter_1 = __importDefault(require("./FormatConverter"));
|
|
11
12
|
var AdaptorTypes;
|
|
12
13
|
(function (AdaptorTypes) {
|
|
13
14
|
AdaptorTypes[AdaptorTypes["CHAINLINK"] = 1] = "CHAINLINK";
|
|
@@ -77,6 +78,8 @@ class ProtocolReader {
|
|
|
77
78
|
tokens: market.tokens.map((token) => ({
|
|
78
79
|
address: token._address,
|
|
79
80
|
totalSupply: BigInt(token.totalSupply),
|
|
81
|
+
totalAssets: BigInt(token.totalAssets),
|
|
82
|
+
exchangeRate: BigInt(token.exchangeRate),
|
|
80
83
|
collateral: BigInt(token.collateral),
|
|
81
84
|
debt: BigInt(token.debt),
|
|
82
85
|
sharePrice: BigInt(token.sharePrice),
|
|
@@ -114,7 +117,6 @@ class ProtocolReader {
|
|
|
114
117
|
userShareBalance: BigInt(token.userShareBalance),
|
|
115
118
|
userUnderlyingBalance: BigInt(token.userUnderlyingBalance),
|
|
116
119
|
userCollateral: BigInt(token.userCollateral),
|
|
117
|
-
exchangeRate: BigInt(token.exchangeRate),
|
|
118
120
|
userDebt: BigInt(token.userDebt),
|
|
119
121
|
liquidationPrice: BigInt(token.liquidationPrice)
|
|
120
122
|
}))
|
|
@@ -130,7 +132,7 @@ class ProtocolReader {
|
|
|
130
132
|
};
|
|
131
133
|
}
|
|
132
134
|
async hypotheticalLeverageOf(account, depositCToken, borrowableCToken, deposit_amount) {
|
|
133
|
-
const assets =
|
|
135
|
+
const assets = FormatConverter_1.default.decimalToBigInt(deposit_amount, depositCToken.asset.decimals);
|
|
134
136
|
const [currentLeverage, adjustMaxLeverage, maxLeverage, maxDebtBorrowable] = await this.contract.hypotheticalLeverageOf(account, depositCToken.address, borrowableCToken.address, assets, 0n);
|
|
135
137
|
return {
|
|
136
138
|
currentLeverage: (0, decimal_js_1.default)(currentLeverage).div(helpers_1.WAD),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolReader.js","sourceRoot":"","sources":["../../src/classes/ProtocolReader.ts"],"names":[],"mappings":";;;;;;AACA,wCAA2D;AAC3D,sFAA6C;AAE7C,4DAAiC;AACjC,oCAAwC;
|
|
1
|
+
{"version":3,"file":"ProtocolReader.js","sourceRoot":"","sources":["../../src/classes/ProtocolReader.ts"],"names":[],"mappings":";;;;;;AACA,wCAA2D;AAC3D,sFAA6C;AAE7C,4DAAiC;AACjC,oCAAwC;AAKxC,wEAAgD;AAEhD,IAAY,YAKX;AALD,WAAY,YAAY;IACpB,yDAAa,CAAA;IACb,iEAAiB,CAAA;IACjB,uEAAoB,CAAA;IACpB,kDAAW,CAAA;AACf,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAqHD,MAAa,cAAc;IACvB,QAAQ,CAAoB;IAC5B,OAAO,CAAU;IACjB,QAAQ,CAA6B;IAErC,YAAY,OAAgB,EAAE,WAA8B,oBAAY,CAAC,QAAQ;QAC7E,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,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@@ -329,6 +329,16 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): {
|
|
|
329
329
|
};
|
|
330
330
|
"WMON-DynamicIRM": string;
|
|
331
331
|
};
|
|
332
|
+
"syzUSD | AUSD": {
|
|
333
|
+
address: string;
|
|
334
|
+
"syzUSD-DynamicIRM": string;
|
|
335
|
+
tokens: {
|
|
336
|
+
syzUSD: string;
|
|
337
|
+
AUSD: string;
|
|
338
|
+
};
|
|
339
|
+
plugins: {};
|
|
340
|
+
"AUSD-DynamicIRM": string;
|
|
341
|
+
};
|
|
332
342
|
};
|
|
333
343
|
ProtocolReader: string;
|
|
334
344
|
"CombinedAggregator-ezETH": string;
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMlC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,MAAM,CAAC;AAEjD,eAAO,MAAM,GAAG,QAAc,CAAC;AAC/B,eAAO,MAAM,WAAW,QAAc,CAAC;AACvC,eAAO,MAAM,GAAG,QAAe,CAAC;AAChC,eAAO,MAAM,OAAO,QAAe,CAAC;AACpC,eAAO,MAAM,GAAG,QAAe,CAAC;AAChC,eAAO,MAAM,WAAW,QAAe,CAAC;AACxC,eAAO,MAAM,oBAAoB,QAAe,CAAC;AACjD,eAAO,MAAM,WAAW,SAAmB,CAAC;AAE5C,eAAO,MA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,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQ1E;AAED,wBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAO7B;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,iBAAiB,GAO7C,eAAe,CACrC;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,QAAQ,GAAG,CAAC,CAM9G;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQzD;AAyCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,aAAa,SAAK,GAAG,CAAC,CA0B1F"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './classes/ProtocolReader';
|
|
2
|
-
export * from './classes/Faucet';
|
|
3
2
|
export * from './classes/OracleManager';
|
|
4
3
|
export * from './classes/Market';
|
|
5
4
|
export * from './classes/CToken';
|
|
@@ -12,6 +11,7 @@ export * from './classes/NativeToken';
|
|
|
12
11
|
export * from './classes/PositionManager';
|
|
13
12
|
export * from './classes/CVE';
|
|
14
13
|
export * from './classes/DexAggregators';
|
|
14
|
+
export * from './classes/FormatConverter';
|
|
15
15
|
export * from './helpers';
|
|
16
16
|
export * from './setup';
|
|
17
17
|
export * from './types';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./classes/ProtocolReader"), exports);
|
|
18
|
-
__exportStar(require("./classes/Faucet"), exports);
|
|
19
18
|
__exportStar(require("./classes/OracleManager"), exports);
|
|
20
19
|
__exportStar(require("./classes/Market"), exports);
|
|
21
20
|
__exportStar(require("./classes/CToken"), exports);
|
|
@@ -28,6 +27,7 @@ __exportStar(require("./classes/NativeToken"), exports);
|
|
|
28
27
|
__exportStar(require("./classes/PositionManager"), exports);
|
|
29
28
|
__exportStar(require("./classes/CVE"), exports);
|
|
30
29
|
__exportStar(require("./classes/DexAggregators"), exports);
|
|
30
|
+
__exportStar(require("./classes/FormatConverter"), exports);
|
|
31
31
|
__exportStar(require("./helpers"), exports);
|
|
32
32
|
__exportStar(require("./setup"), exports);
|
|
33
33
|
__exportStar(require("./types"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,0DAAwC;AACxC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC;AAChC,mDAAiC;AACjC,qDAAmC;AACnC,qDAAmC;AACnC,6DAA2C;AAC3C,wDAAsC;AACtC,4DAA0C;AAC1C,gDAA8B;AAC9B,2DAAyC;AACzC,4DAA0C;AAC1C,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,mDAAiC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "curvance",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"test": "node --test --test-concurrency=1 --require ts-node/register tests/*.test.ts",
|
|
30
30
|
"test:replay": "ts-node tests/replay.test.ts",
|
|
31
31
|
"test:leverage": "ts-node tests/leverage.test.ts",
|
|
32
|
-
"test:zap": "ts-node tests/zap.test.ts"
|
|
32
|
+
"test:zap": "ts-node tests/zap.test.ts",
|
|
33
|
+
"test:conversion": "ts-node tests/conversion.test.ts"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@redstone-finance/sdk": "^0.9.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=KuruMainnet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KuruMainnet.d.ts","sourceRoot":"","sources":["../../../src/classes/DexAggregators/KuruMainnet.ts"],"names":[],"mappings":""}
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import Decimal from "decimal.js";
|
|
3
|
-
// import { address, curvance_provider, TokenInput } from "../../types";
|
|
4
|
-
// import { ERC20 } from "../ERC20";
|
|
5
|
-
// import { toBigInt, toDecimal, validateProviderAsSigner, WAD } from "../../helpers";
|
|
6
|
-
// import { ZapToken } from "../CToken";
|
|
7
|
-
// import { Swap } from "../Zapper";
|
|
8
|
-
// interface KuruJWTResponse {
|
|
9
|
-
// token: string;
|
|
10
|
-
// expires_at: number;
|
|
11
|
-
// rate_limit: {
|
|
12
|
-
// rps: number;
|
|
13
|
-
// burst: number;
|
|
14
|
-
// }
|
|
15
|
-
// }
|
|
16
|
-
// interface KuruQuoteResponse {
|
|
17
|
-
// type: string;
|
|
18
|
-
// status: string;
|
|
19
|
-
// output: string;
|
|
20
|
-
// minOut: string;
|
|
21
|
-
// transaction: {
|
|
22
|
-
// calldata: string;
|
|
23
|
-
// value: string;
|
|
24
|
-
// to: string;
|
|
25
|
-
// };
|
|
26
|
-
// gasPrices: {
|
|
27
|
-
// slow: string;
|
|
28
|
-
// standard: string;
|
|
29
|
-
// fast: string;
|
|
30
|
-
// rapid: string;
|
|
31
|
-
// extreme: string;
|
|
32
|
-
// };
|
|
33
|
-
// }
|
|
34
|
-
// const cached_jwt = new Map<string, KuruJWTResponse>();
|
|
35
|
-
// const cached_requests = new Map<string, number[]>();
|
|
36
|
-
// export default class KuruMainnet {
|
|
37
|
-
// static api = "https://ws.kuru.io/api"
|
|
38
|
-
// static router = "0xb3e6778480b2E488385E8205eA05E20060B813cb" as address; // KuruFlowEntrypoint
|
|
39
|
-
// jwt: string | null = null;
|
|
40
|
-
// rps = 1;
|
|
41
|
-
// dao = "0x0Acb7eF4D8733C719d60e0992B489b629bc55C02" as address;
|
|
42
|
-
// async loadJWT(wallet: string) {
|
|
43
|
-
// if(cached_jwt.has(wallet)) {
|
|
44
|
-
// const cached = cached_jwt.get(wallet)!;
|
|
45
|
-
// const currentTime = KuruMainnet.getCurrentTime();
|
|
46
|
-
// if(cached.expires_at > currentTime) {
|
|
47
|
-
// this.jwt = cached.token;
|
|
48
|
-
// this.rps = cached.rate_limit.rps;
|
|
49
|
-
// return;
|
|
50
|
-
// } else {
|
|
51
|
-
// cached_jwt.delete(wallet);
|
|
52
|
-
// }
|
|
53
|
-
// }
|
|
54
|
-
// const resp = await fetch(`${KuruMainnet.api}/generate-token`, {
|
|
55
|
-
// method: "POST",
|
|
56
|
-
// headers: {
|
|
57
|
-
// "Content-Type": "application/json",
|
|
58
|
-
// },
|
|
59
|
-
// body: JSON.stringify({
|
|
60
|
-
// user_address: wallet,
|
|
61
|
-
// }),
|
|
62
|
-
// keepalive: true
|
|
63
|
-
// });
|
|
64
|
-
// if(!resp.ok) {
|
|
65
|
-
// throw new Error(`Failed to fetch JWT: ${resp.status} ${resp.statusText}`);
|
|
66
|
-
// }
|
|
67
|
-
// const data = await resp.json() as KuruJWTResponse;
|
|
68
|
-
// this.jwt = data.token;
|
|
69
|
-
// this.rps = data.rate_limit.rps;
|
|
70
|
-
// cached_jwt.set(wallet, data);
|
|
71
|
-
// }
|
|
72
|
-
// async rateLimitSleep(wallet: string) {
|
|
73
|
-
// const now = KuruMainnet.getCurrentTime();
|
|
74
|
-
// const requests = cached_requests.get(wallet) || [];
|
|
75
|
-
// const windowStart = now - 2;
|
|
76
|
-
// const recentRequests = requests.filter(timestamp => timestamp > windowStart);
|
|
77
|
-
// if(recentRequests.length >= this.rps) {
|
|
78
|
-
// const earliestRequest = Math.min(...recentRequests);
|
|
79
|
-
// const sleepTime = (earliestRequest + 2) - now;
|
|
80
|
-
// await new Promise(resolve => setTimeout(resolve, sleepTime * 2000));
|
|
81
|
-
// }
|
|
82
|
-
// }
|
|
83
|
-
// static async getAvailableTokens(provider: curvance_provider, query: string | null = null) {
|
|
84
|
-
// const signer = validateProviderAsSigner(provider);
|
|
85
|
-
// const userAddress = signer.address;
|
|
86
|
-
// let endpoint = `https://api.kuru.io/api/v2/tokens/search?limit=20&userAddress=${userAddress}`;
|
|
87
|
-
// if(query) {
|
|
88
|
-
// endpoint += `&q=${encodeURIComponent(query)}`;
|
|
89
|
-
// }
|
|
90
|
-
// const resp = await fetch(endpoint, {
|
|
91
|
-
// method: "GET",
|
|
92
|
-
// headers: {
|
|
93
|
-
// "Content-Type": "application/json",
|
|
94
|
-
// }
|
|
95
|
-
// });
|
|
96
|
-
// if(!resp.ok) {
|
|
97
|
-
// throw new Error(`Failed to fetch available tokens: ${resp.status} ${resp.statusText}`);
|
|
98
|
-
// }
|
|
99
|
-
// const list = await resp.json() as {
|
|
100
|
-
// success: boolean;
|
|
101
|
-
// code: number;
|
|
102
|
-
// timestamp: number;
|
|
103
|
-
// data: {
|
|
104
|
-
// data: Array<{
|
|
105
|
-
// address: string;
|
|
106
|
-
// decimals: number;
|
|
107
|
-
// name: string;
|
|
108
|
-
// ticker: string;
|
|
109
|
-
// imageurl: string,
|
|
110
|
-
// twitter: string,
|
|
111
|
-
// website: string,
|
|
112
|
-
// is_verified: boolean,
|
|
113
|
-
// contract_renounced: boolean,
|
|
114
|
-
// is_erc20: boolean,
|
|
115
|
-
// is_mintable: boolean,
|
|
116
|
-
// is_strict: boolean,
|
|
117
|
-
// balance: string,
|
|
118
|
-
// last_price: string,
|
|
119
|
-
// quote_asset: string,
|
|
120
|
-
// market_address: string,
|
|
121
|
-
// total_supply: string,
|
|
122
|
-
// burned_supply: string
|
|
123
|
-
// }>
|
|
124
|
-
// }
|
|
125
|
-
// };
|
|
126
|
-
// let tokens: ZapToken[] = [];
|
|
127
|
-
// for(const token of list.data.data) {
|
|
128
|
-
// const erc20 = new ERC20(
|
|
129
|
-
// provider,
|
|
130
|
-
// token.address as address,
|
|
131
|
-
// {
|
|
132
|
-
// address: token.address as address,
|
|
133
|
-
// name: token.name,
|
|
134
|
-
// symbol: token.ticker,
|
|
135
|
-
// decimals: BigInt(token.decimals ?? 18),
|
|
136
|
-
// totalSupply: BigInt(token.total_supply ?? 0),
|
|
137
|
-
// balance: BigInt(token.balance ?? 0),
|
|
138
|
-
// image: token.imageurl,
|
|
139
|
-
// price: Decimal(token.last_price).div(WAD)
|
|
140
|
-
// },
|
|
141
|
-
// );
|
|
142
|
-
// tokens.push({
|
|
143
|
-
// interface: erc20,
|
|
144
|
-
// type: 'simple',
|
|
145
|
-
// quote: async(tokenIn: string, tokenOut: string, amount: TokenInput, slippageTolerance: bigint | null = null) => {
|
|
146
|
-
// const raw_amount = toBigInt(amount, 18n);
|
|
147
|
-
// const data = await KuruMainnet.quote(signer.address, tokenIn, tokenOut, raw_amount.toString(), slippageTolerance);
|
|
148
|
-
// return {
|
|
149
|
-
// output: toDecimal(BigInt(data.output ?? 0), BigInt(token.decimals ?? 18)),
|
|
150
|
-
// minOut: toDecimal(BigInt(data.minOut ?? 0), BigInt(token.decimals ?? 18)),
|
|
151
|
-
// max_slippage: data.max_slippage
|
|
152
|
-
// };
|
|
153
|
-
// }
|
|
154
|
-
// });
|
|
155
|
-
// }
|
|
156
|
-
// return tokens;
|
|
157
|
-
// }
|
|
158
|
-
// // Get current time in seconds
|
|
159
|
-
// static getCurrentTime() {
|
|
160
|
-
// return Math.floor(Date.now() / 1000);
|
|
161
|
-
// }
|
|
162
|
-
// static async quoteAction(wallet: string, tokenIn: string, tokenOut: string, amount: string, slippageTolerance: bigint | null = null) {
|
|
163
|
-
// const quote = await KuruMainnet.quote(wallet, tokenIn, tokenOut, amount, slippageTolerance);
|
|
164
|
-
// const action = {
|
|
165
|
-
// inputToken: tokenIn,
|
|
166
|
-
// inputAmount: BigInt(amount),
|
|
167
|
-
// outputToken: tokenOut,
|
|
168
|
-
// target: quote.transaction.to,
|
|
169
|
-
// slippage: slippageTolerance ?? 0n,
|
|
170
|
-
// call: `0x${quote.transaction.calldata}`
|
|
171
|
-
// } as Swap;
|
|
172
|
-
// return { action, quote };
|
|
173
|
-
// }
|
|
174
|
-
// static async quoteMin(wallet: string, tokenIn: string, tokenOut: string, amount: string, slippageTolerance: bigint | null = null) {
|
|
175
|
-
// const quote = await KuruMainnet.quote(wallet, tokenIn, tokenOut, amount, slippageTolerance);
|
|
176
|
-
// return quote.minOut;
|
|
177
|
-
// }
|
|
178
|
-
// static async quote(wallet: string, tokenIn: string, tokenOut: string, amount: string, slippageTolerance: bigint | null = null) {
|
|
179
|
-
// const kuru = new this();
|
|
180
|
-
// await kuru.loadJWT(wallet);
|
|
181
|
-
// await kuru.rateLimitSleep(wallet);
|
|
182
|
-
// const payload: {
|
|
183
|
-
// userAddress: string;
|
|
184
|
-
// tokenIn: string;
|
|
185
|
-
// tokenOut: string;
|
|
186
|
-
// amount: string;
|
|
187
|
-
// referrerAddress?: string;
|
|
188
|
-
// referrerFeeBps?: number;
|
|
189
|
-
// slippage_tolerance?: number;
|
|
190
|
-
// autoSlippage?: boolean;
|
|
191
|
-
// } = {
|
|
192
|
-
// userAddress: wallet,
|
|
193
|
-
// tokenIn: tokenIn,
|
|
194
|
-
// tokenOut: tokenOut,
|
|
195
|
-
// amount: amount,
|
|
196
|
-
// referrerAddress: kuru.dao,
|
|
197
|
-
// referrerFeeBps: 10,
|
|
198
|
-
// };
|
|
199
|
-
// if(!slippageTolerance) {
|
|
200
|
-
// payload.autoSlippage = true;
|
|
201
|
-
// } else {
|
|
202
|
-
// payload.slippage_tolerance = Number(slippageTolerance);
|
|
203
|
-
// }
|
|
204
|
-
// cached_requests.set(wallet, (cached_requests.get(wallet) || []).concat(KuruMainnet.getCurrentTime()));
|
|
205
|
-
// const resp = await fetch(`${KuruMainnet.api}/quote`, {
|
|
206
|
-
// method: "POST",
|
|
207
|
-
// headers: {
|
|
208
|
-
// "Content-Type": "application/json",
|
|
209
|
-
// "Authorization": `Bearer ${kuru.jwt}`
|
|
210
|
-
// },
|
|
211
|
-
// body: JSON.stringify(payload),
|
|
212
|
-
// });
|
|
213
|
-
// if(!resp.ok) {
|
|
214
|
-
// throw new Error(`Failed to fetch quote: ${resp.status} ${resp.statusText}`);
|
|
215
|
-
// }
|
|
216
|
-
// const data = await resp.json() as KuruQuoteResponse;
|
|
217
|
-
// return {
|
|
218
|
-
// ...data,
|
|
219
|
-
// max_slippage: KuruMainnet.getSlippage(BigInt(data.output ?? 0), BigInt(data.minOut ?? 0))
|
|
220
|
-
// };
|
|
221
|
-
// }
|
|
222
|
-
// static getSlippage(output: bigint, min_output: bigint) {
|
|
223
|
-
// const diff = output - min_output;
|
|
224
|
-
// const decimal = Decimal(diff).div(output).mul(100);
|
|
225
|
-
// return decimal ?? Decimal(100);
|
|
226
|
-
// }
|
|
227
|
-
// }
|
|
228
|
-
//# sourceMappingURL=KuruMainnet.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KuruMainnet.js","sourceRoot":"","sources":["../../../src/classes/DexAggregators/KuruMainnet.ts"],"names":[],"mappings":";AAAA,oCAAoC;AACpC,wEAAwE;AACxE,oCAAoC;AACpC,sFAAsF;AACtF,wCAAwC;AACxC,oCAAoC;AAEpC,8BAA8B;AAC9B,qBAAqB;AACrB,0BAA0B;AAC1B,oBAAoB;AACpB,uBAAuB;AACvB,yBAAyB;AACzB,QAAQ;AACR,IAAI;AAEJ,gCAAgC;AAChC,oBAAoB;AACpB,sBAAsB;AACtB,sBAAsB;AACtB,sBAAsB;AACtB,qBAAqB;AACrB,4BAA4B;AAC5B,yBAAyB;AACzB,sBAAsB;AACtB,SAAS;AACT,mBAAmB;AACnB,wBAAwB;AACxB,4BAA4B;AAC5B,wBAAwB;AACxB,yBAAyB;AAC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nC,2CAA2C;AAC3C,mBAAmB;AACnB,sEAAsE;AACtE,YAAY;AAEZ,iHAAiH;AACjH,iEAAiE;AACjE,8BAA8B;AAC9B,yBAAyB;AACzB,sDAAsD;AACtD,wDAAwD;AACxD,iBAAiB;AACjB,6CAA6C;AAC7C,cAAc;AAEd,yBAAyB;AACzB,2FAA2F;AAC3F,YAAY;AAEZ,+DAA+D;AAE/D,mBAAmB;AACnB,uBAAuB;AACvB,wGAAwG;AACxG,aAAa;AACb,QAAQ;AAER,+DAA+D;AAC/D,4CAA4C;AAC5C,8DAA8D;AAC9D,0CAA0C;AAC1C,QAAQ;AACR,IAAI"}
|
package/dist/classes/Kuru.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import Decimal from "decimal.js";
|
|
2
|
-
import { address, curvance_provider } from "../types";
|
|
3
|
-
import { ZapToken } from "./CToken";
|
|
4
|
-
import { Swap } from "./Zapper";
|
|
5
|
-
export default class Kuru {
|
|
6
|
-
api: string;
|
|
7
|
-
static router: address;
|
|
8
|
-
jwt: string | null;
|
|
9
|
-
rps: number;
|
|
10
|
-
dao: address;
|
|
11
|
-
loadJWT(wallet: string): Promise<void>;
|
|
12
|
-
rateLimitSleep(wallet: string): Promise<void>;
|
|
13
|
-
static getAvailableTokens(provider: curvance_provider, query?: string | null): Promise<ZapToken[]>;
|
|
14
|
-
static getCurrentTime(): number;
|
|
15
|
-
static quoteAction(wallet: string, tokenIn: string, tokenOut: string, amount: string, slippageTolerance?: bigint | null): Promise<{
|
|
16
|
-
action: Swap;
|
|
17
|
-
quote: {
|
|
18
|
-
max_slippage: Decimal;
|
|
19
|
-
type: string;
|
|
20
|
-
status: string;
|
|
21
|
-
output: string;
|
|
22
|
-
minOut: string;
|
|
23
|
-
transaction: {
|
|
24
|
-
calldata: string;
|
|
25
|
-
value: string;
|
|
26
|
-
to: string;
|
|
27
|
-
};
|
|
28
|
-
gasPrices: {
|
|
29
|
-
slow: string;
|
|
30
|
-
standard: string;
|
|
31
|
-
fast: string;
|
|
32
|
-
rapid: string;
|
|
33
|
-
extreme: string;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
}>;
|
|
37
|
-
static quoteMin(wallet: string, tokenIn: string, tokenOut: string, amount: string, slippageTolerance?: bigint | null): Promise<string>;
|
|
38
|
-
static quote(wallet: string, tokenIn: string, tokenOut: string, amount: string, slippageTolerance?: bigint | null): Promise<{
|
|
39
|
-
max_slippage: Decimal;
|
|
40
|
-
type: string;
|
|
41
|
-
status: string;
|
|
42
|
-
output: string;
|
|
43
|
-
minOut: string;
|
|
44
|
-
transaction: {
|
|
45
|
-
calldata: string;
|
|
46
|
-
value: string;
|
|
47
|
-
to: string;
|
|
48
|
-
};
|
|
49
|
-
gasPrices: {
|
|
50
|
-
slow: string;
|
|
51
|
-
standard: string;
|
|
52
|
-
fast: string;
|
|
53
|
-
rapid: string;
|
|
54
|
-
extreme: string;
|
|
55
|
-
};
|
|
56
|
-
}>;
|
|
57
|
-
static getSlippage(output: bigint, min_output: bigint): Decimal;
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=Kuru.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Kuru.d.ts","sourceRoot":"","sources":["../../src/classes/Kuru.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAc,MAAM,UAAU,CAAC;AAGlE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAiChC,MAAM,CAAC,OAAO,OAAO,IAAI;IACrB,GAAG,SAAmC;IACtC,MAAM,CAAC,MAAM,EAAmD,OAAO,CAAC;IACxE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,GAAG,SAAK;IACR,GAAG,EAAmD,OAAO,CAAC;IAExD,OAAO,CAAC,MAAM,EAAE,MA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;IA4ND,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKxD"}
|
package/dist/classes/Kuru.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
7
|
-
const ERC20_1 = require("./ERC20");
|
|
8
|
-
const helpers_1 = require("../helpers");
|
|
9
|
-
const cached_jwt = new Map();
|
|
10
|
-
const cached_requests = new Map();
|
|
11
|
-
class Kuru {
|
|
12
|
-
api = "https://ws.staging.kuru.io/api";
|
|
13
|
-
static router = "0x96eaC98928437496DdD0Cd2080E54Fe78BaC99b6"; // KuruFlowEntrypoint
|
|
14
|
-
jwt = null;
|
|
15
|
-
rps = 1;
|
|
16
|
-
dao = "0x0Acb7eF4D8733C719d60e0992B489b629bc55C02";
|
|
17
|
-
async loadJWT(wallet) {
|
|
18
|
-
if (cached_jwt.has(wallet)) {
|
|
19
|
-
const cached = cached_jwt.get(wallet);
|
|
20
|
-
const currentTime = Kuru.getCurrentTime();
|
|
21
|
-
if (cached.expires_at > currentTime) {
|
|
22
|
-
this.jwt = cached.token;
|
|
23
|
-
this.rps = cached.rate_limit.rps;
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
cached_jwt.delete(wallet);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const resp = await fetch(`${this.api}/generate-token`, {
|
|
31
|
-
method: "POST",
|
|
32
|
-
headers: {
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify({
|
|
36
|
-
user_address: wallet,
|
|
37
|
-
}),
|
|
38
|
-
keepalive: true
|
|
39
|
-
});
|
|
40
|
-
if (!resp.ok) {
|
|
41
|
-
throw new Error(`Failed to fetch JWT: ${resp.status} ${resp.statusText}`);
|
|
42
|
-
}
|
|
43
|
-
const data = await resp.json();
|
|
44
|
-
this.jwt = data.token;
|
|
45
|
-
this.rps = data.rate_limit.rps;
|
|
46
|
-
cached_jwt.set(wallet, data);
|
|
47
|
-
}
|
|
48
|
-
async rateLimitSleep(wallet) {
|
|
49
|
-
const now = Kuru.getCurrentTime();
|
|
50
|
-
const requests = cached_requests.get(wallet) || [];
|
|
51
|
-
const windowStart = now - 2;
|
|
52
|
-
const recentRequests = requests.filter(timestamp => timestamp > windowStart);
|
|
53
|
-
if (recentRequests.length >= this.rps) {
|
|
54
|
-
const earliestRequest = Math.min(...recentRequests);
|
|
55
|
-
const sleepTime = (earliestRequest + 2) - now;
|
|
56
|
-
await new Promise(resolve => setTimeout(resolve, sleepTime * 2000));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
static async getAvailableTokens(provider, query = null) {
|
|
60
|
-
const signer = (0, helpers_1.validateProviderAsSigner)(provider);
|
|
61
|
-
const userAddress = signer.address;
|
|
62
|
-
let endpoint = `https://api.kuru.io/api/v2/tokens/search?limit=20&userAddress=${userAddress}`;
|
|
63
|
-
if (query) {
|
|
64
|
-
endpoint += `&q=${encodeURIComponent(query)}`;
|
|
65
|
-
}
|
|
66
|
-
const resp = await fetch(endpoint, {
|
|
67
|
-
method: "GET",
|
|
68
|
-
headers: {
|
|
69
|
-
"Content-Type": "application/json",
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
if (!resp.ok) {
|
|
73
|
-
throw new Error(`Failed to fetch available tokens: ${resp.status} ${resp.statusText}`);
|
|
74
|
-
}
|
|
75
|
-
const list = await resp.json();
|
|
76
|
-
let tokens = [];
|
|
77
|
-
for (const token of list.data.data) {
|
|
78
|
-
const erc20 = new ERC20_1.ERC20(provider, token.address, {
|
|
79
|
-
address: token.address,
|
|
80
|
-
name: token.name,
|
|
81
|
-
symbol: token.ticker,
|
|
82
|
-
decimals: BigInt(token.decimals ?? 18),
|
|
83
|
-
totalSupply: BigInt(token.total_supply ?? 0),
|
|
84
|
-
balance: BigInt(token.balance ?? 0),
|
|
85
|
-
image: token.imageurl,
|
|
86
|
-
price: (0, decimal_js_1.default)(token.last_price).div(helpers_1.WAD)
|
|
87
|
-
});
|
|
88
|
-
tokens.push({
|
|
89
|
-
interface: erc20,
|
|
90
|
-
type: 'simple',
|
|
91
|
-
quote: async (tokenIn, tokenOut, amount, slippageTolerance = null) => {
|
|
92
|
-
const raw_amount = (0, helpers_1.toBigInt)(amount, 18n);
|
|
93
|
-
const data = await Kuru.quote(signer.address, tokenIn, tokenOut, raw_amount.toString(), slippageTolerance);
|
|
94
|
-
return {
|
|
95
|
-
output: (0, helpers_1.toDecimal)(BigInt(data.output ?? 0), BigInt(token.decimals ?? 18)),
|
|
96
|
-
minOut: (0, helpers_1.toDecimal)(BigInt(data.minOut ?? 0), BigInt(token.decimals ?? 18)),
|
|
97
|
-
max_slippage: data.max_slippage
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return tokens;
|
|
103
|
-
}
|
|
104
|
-
// Get current time in seconds
|
|
105
|
-
static getCurrentTime() {
|
|
106
|
-
return Math.floor(Date.now() / 1000);
|
|
107
|
-
}
|
|
108
|
-
static async quoteAction(wallet, tokenIn, tokenOut, amount, slippageTolerance = null) {
|
|
109
|
-
const quote = await Kuru.quote(wallet, tokenIn, tokenOut, amount, slippageTolerance);
|
|
110
|
-
const action = {
|
|
111
|
-
inputToken: tokenIn,
|
|
112
|
-
inputAmount: BigInt(amount),
|
|
113
|
-
outputToken: tokenOut,
|
|
114
|
-
target: quote.transaction.to,
|
|
115
|
-
slippage: slippageTolerance ?? 0n,
|
|
116
|
-
call: `0x${quote.transaction.calldata}`
|
|
117
|
-
};
|
|
118
|
-
return { action, quote };
|
|
119
|
-
}
|
|
120
|
-
static async quoteMin(wallet, tokenIn, tokenOut, amount, slippageTolerance = null) {
|
|
121
|
-
const quote = await Kuru.quote(wallet, tokenIn, tokenOut, amount, slippageTolerance);
|
|
122
|
-
return quote.minOut;
|
|
123
|
-
}
|
|
124
|
-
static async quote(wallet, tokenIn, tokenOut, amount, slippageTolerance = null) {
|
|
125
|
-
const kuru = new this();
|
|
126
|
-
await kuru.loadJWT(wallet);
|
|
127
|
-
await kuru.rateLimitSleep(wallet);
|
|
128
|
-
const payload = {
|
|
129
|
-
userAddress: wallet,
|
|
130
|
-
tokenIn: tokenIn,
|
|
131
|
-
tokenOut: tokenOut,
|
|
132
|
-
amount: amount,
|
|
133
|
-
referrerAddress: kuru.dao,
|
|
134
|
-
referrerFeeBps: 10,
|
|
135
|
-
};
|
|
136
|
-
if (!slippageTolerance) {
|
|
137
|
-
payload.autoSlippage = true;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
payload.slippage_tolerance = Number(slippageTolerance);
|
|
141
|
-
}
|
|
142
|
-
cached_requests.set(wallet, (cached_requests.get(wallet) || []).concat(Kuru.getCurrentTime()));
|
|
143
|
-
const resp = await fetch(`${kuru.api}/quote`, {
|
|
144
|
-
method: "POST",
|
|
145
|
-
headers: {
|
|
146
|
-
"Content-Type": "application/json",
|
|
147
|
-
"Authorization": `Bearer ${kuru.jwt}`
|
|
148
|
-
},
|
|
149
|
-
body: JSON.stringify(payload),
|
|
150
|
-
});
|
|
151
|
-
if (!resp.ok) {
|
|
152
|
-
throw new Error(`Failed to fetch quote: ${resp.status} ${resp.statusText}`);
|
|
153
|
-
}
|
|
154
|
-
const data = await resp.json();
|
|
155
|
-
return {
|
|
156
|
-
...data,
|
|
157
|
-
max_slippage: Kuru.getSlippage(BigInt(data.output ?? 0), BigInt(data.minOut ?? 0))
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
static getSlippage(output, min_output) {
|
|
161
|
-
const diff = output - min_output;
|
|
162
|
-
const decimal = (0, decimal_js_1.default)(diff).div(output).mul(100);
|
|
163
|
-
return decimal ?? (0, decimal_js_1.default)(100);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
exports.default = Kuru;
|
|
167
|
-
//# sourceMappingURL=Kuru.js.map
|