curvance 1.0.14 → 1.0.16
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/README.md +2 -0
- package/dist/abis/ProtocolReader.json +54 -10
- package/dist/abis/RedstoneCoreAdaptor.json +798 -0
- package/dist/chains/index.d.ts +0 -37
- package/dist/chains/index.d.ts.map +1 -1
- package/dist/chains/index.js +1 -2
- package/dist/chains/index.js.map +1 -1
- package/dist/chains/monad-testnet.json +65 -101
- package/dist/classes/CToken.d.ts +57 -23
- package/dist/classes/CToken.d.ts.map +1 -1
- package/dist/classes/CToken.js +122 -54
- package/dist/classes/CToken.js.map +1 -1
- package/dist/classes/ERC20.d.ts +5 -5
- package/dist/classes/ERC20.d.ts.map +1 -1
- package/dist/classes/ERC20.js +4 -4
- package/dist/classes/ERC20.js.map +1 -1
- package/dist/classes/Faucet.d.ts +4 -4
- package/dist/classes/Faucet.d.ts.map +1 -1
- package/dist/classes/Faucet.js +11 -6
- package/dist/classes/Faucet.js.map +1 -1
- package/dist/classes/Market.d.ts +85 -7
- package/dist/classes/Market.d.ts.map +1 -1
- package/dist/classes/Market.js +168 -17
- package/dist/classes/Market.js.map +1 -1
- package/dist/classes/OracleManager.d.ts +3 -3
- package/dist/classes/OracleManager.d.ts.map +1 -1
- package/dist/classes/OracleManager.js +4 -4
- package/dist/classes/OracleManager.js.map +1 -1
- package/dist/classes/ProtocolReader.d.ts +20 -10
- package/dist/classes/ProtocolReader.d.ts.map +1 -1
- package/dist/classes/ProtocolReader.js +23 -12
- package/dist/classes/ProtocolReader.js.map +1 -1
- package/dist/classes/Redstone.d.ts +14 -0
- package/dist/classes/Redstone.d.ts.map +1 -0
- package/dist/classes/Redstone.js +57 -0
- package/dist/classes/Redstone.js.map +1 -0
- package/dist/helpers.d.ts +36 -49
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +119 -18
- package/dist/helpers.js.map +1 -1
- package/dist/setup.d.ts +5 -3
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +16 -8
- package/dist/setup.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -3,17 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ProtocolReader = void 0;
|
|
6
|
+
exports.ProtocolReader = exports.AdaptorTypes = void 0;
|
|
7
7
|
const helpers_1 = require("../helpers");
|
|
8
8
|
const ProtocolReader_json_1 = __importDefault(require("../abis/ProtocolReader.json"));
|
|
9
|
+
var AdaptorTypes;
|
|
10
|
+
(function (AdaptorTypes) {
|
|
11
|
+
AdaptorTypes[AdaptorTypes["CHAINLINK"] = 1] = "CHAINLINK";
|
|
12
|
+
AdaptorTypes[AdaptorTypes["REDSTONE_CORE"] = 2] = "REDSTONE_CORE";
|
|
13
|
+
AdaptorTypes[AdaptorTypes["REDSTONE_CLASSIC"] = 3] = "REDSTONE_CLASSIC";
|
|
14
|
+
AdaptorTypes[AdaptorTypes["MOCK"] = 1337] = "MOCK";
|
|
15
|
+
})(AdaptorTypes || (exports.AdaptorTypes = AdaptorTypes = {}));
|
|
9
16
|
class ProtocolReader {
|
|
10
|
-
|
|
17
|
+
provider;
|
|
11
18
|
address;
|
|
12
19
|
contract;
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
20
|
+
constructor(provider, address) {
|
|
21
|
+
this.provider = provider;
|
|
15
22
|
this.address = address;
|
|
16
|
-
this.contract = (0, helpers_1.contractSetup)(
|
|
23
|
+
this.contract = (0, helpers_1.contractSetup)(provider, address, ProtocolReader_json_1.default);
|
|
17
24
|
}
|
|
18
25
|
async getAllMarketData(account, use_api = true) {
|
|
19
26
|
const all = await Promise.all([
|
|
@@ -34,7 +41,7 @@ class ProtocolReader {
|
|
|
34
41
|
address: market._address,
|
|
35
42
|
tokens: market.tokens.map((token) => ({
|
|
36
43
|
address: token._address,
|
|
37
|
-
|
|
44
|
+
totalSupply: BigInt(token.totalSupply),
|
|
38
45
|
collateral: BigInt(token.collateral),
|
|
39
46
|
debt: BigInt(token.debt),
|
|
40
47
|
sharePrice: BigInt(token.sharePrice),
|
|
@@ -67,17 +74,21 @@ class ProtocolReader {
|
|
|
67
74
|
cooldown: BigInt(market.cooldown),
|
|
68
75
|
tokens: market.tokens.map((token) => ({
|
|
69
76
|
address: token._address,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
userAssetBalance: BigInt(token.userAssetBalance),
|
|
78
|
+
userShareBalance: BigInt(token.userShareBalance),
|
|
79
|
+
userCollateral: BigInt(token.userCollateral),
|
|
80
|
+
userDebt: BigInt(token.userDebt)
|
|
74
81
|
}))
|
|
75
82
|
}))
|
|
76
83
|
};
|
|
77
84
|
return typedData;
|
|
78
85
|
}
|
|
79
|
-
async
|
|
80
|
-
|
|
86
|
+
async previewAssetImpact(user, collateral_ctoken, debt_ctoken, deposit_amount) {
|
|
87
|
+
const data = await this.contract.previewAssetImpact(user, collateral_ctoken, debt_ctoken, deposit_amount);
|
|
88
|
+
return {
|
|
89
|
+
supply: BigInt(data[0]),
|
|
90
|
+
borrow: BigInt(data[1])
|
|
91
|
+
};
|
|
81
92
|
}
|
|
82
93
|
async hypotheticalMaxLeverage(account, borrowableCToken, cToken, assets) {
|
|
83
94
|
const data = await this.contract.hypotheticalMaxLeverage(account, borrowableCToken, cToken, assets);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolReader.js","sourceRoot":"","sources":["../../src/classes/ProtocolReader.ts"],"names":[],"mappings":";;;;;;AACA,wCAA2C;AAC3C,sFAA6C;
|
|
1
|
+
{"version":3,"file":"ProtocolReader.js","sourceRoot":"","sources":["../../src/classes/ProtocolReader.ts"],"names":[],"mappings":";;;;;;AACA,wCAA2C;AAC3C,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,CAAC;aAC/C,CAAC,CAAC;SACN,CAAC,CAAC,CAAC;QACJ,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA/ID,wCA+IC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { address, bytes } from "../types";
|
|
2
|
+
import { TransactionResponse } from "ethers";
|
|
3
|
+
import { BorrowableCToken, CToken, MulticallAction } from "./CToken";
|
|
4
|
+
export interface IRedstoneCoreAdaptor {
|
|
5
|
+
writePrice(asset: address, inUSD: boolean, redstoneTimestamp: bigint): Promise<TransactionResponse>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Redstone {
|
|
8
|
+
static getPayload(symbol: string, log?: boolean): Promise<{
|
|
9
|
+
payload: bytes;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}>;
|
|
12
|
+
static buildMulticallStruct(ctoken: CToken | BorrowableCToken): Promise<MulticallAction>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Redstone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Redstone.d.ts","sourceRoot":"","sources":["../../src/classes/Redstone.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAkB,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGrE,MAAM,WAAW,oBAAoB;IACjC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACvG;AAED,qBAAa,QAAQ;WACJ,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,OAAe;iBAyBzB,KAAK;;;WAM3B,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB;CAkBtE"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
exports.Redstone = void 0;
|
|
7
|
+
const sdk_1 = require("@redstone-finance/sdk");
|
|
8
|
+
const setup_1 = require("../setup");
|
|
9
|
+
const helpers_1 = require("../helpers");
|
|
10
|
+
const ethers_1 = require("ethers");
|
|
11
|
+
const RedstoneCoreAdaptor_json_1 = __importDefault(require("../abis/RedstoneCoreAdaptor.json"));
|
|
12
|
+
class Redstone {
|
|
13
|
+
static async getPayload(symbol, log = false) {
|
|
14
|
+
let payload_params = {
|
|
15
|
+
dataServiceId: "redstone-primary-prod",
|
|
16
|
+
dataPackagesIds: [symbol],
|
|
17
|
+
uniqueSignersCount: 3,
|
|
18
|
+
authorizedSigners: [
|
|
19
|
+
"0x8BB8F32Df04c8b654987DAaeD53D6B6091e3B774",
|
|
20
|
+
"0xdEB22f54738d54976C4c0fe5ce6d408E40d88499",
|
|
21
|
+
"0x51Ce04Be4b3E32572C4Ec9135221d0691Ba7d202",
|
|
22
|
+
"0xDD682daEC5A90dD295d14DA4b0bec9281017b5bE"
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
const response = await (0, sdk_1.requestDataPackages)(payload_params);
|
|
26
|
+
const [payload, timestamp] = await Promise.all([
|
|
27
|
+
(0, sdk_1.convertDataPackagesResponse)(response),
|
|
28
|
+
(0, sdk_1.getResponseTimestamp)(response)
|
|
29
|
+
]);
|
|
30
|
+
if (log) {
|
|
31
|
+
const json = await (0, sdk_1.convertDataPackagesResponse)(response, "json");
|
|
32
|
+
console.log(json);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
payload: `0x${payload}`,
|
|
36
|
+
timestamp
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
static async buildMulticallStruct(ctoken) {
|
|
40
|
+
const adaptor = setup_1.active_contracts.RedstoneCoreAdaptor;
|
|
41
|
+
const contract = (0, helpers_1.contractSetup)(ctoken.provider, adaptor, RedstoneCoreAdaptor_json_1.default);
|
|
42
|
+
const { payload, timestamp } = await Redstone.getPayload(ctoken.asset.symbol);
|
|
43
|
+
const writePrice = contract.interface.encodeFunctionData("writePrice", [
|
|
44
|
+
ctoken.asset.address,
|
|
45
|
+
true,
|
|
46
|
+
timestamp
|
|
47
|
+
]);
|
|
48
|
+
const encodedWritePrice = (0, ethers_1.solidityPacked)(["bytes", "bytes"], [writePrice, payload]);
|
|
49
|
+
return {
|
|
50
|
+
target: adaptor,
|
|
51
|
+
isPriceUpdate: true,
|
|
52
|
+
data: encodedWritePrice
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.Redstone = Redstone;
|
|
57
|
+
//# sourceMappingURL=Redstone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Redstone.js","sourceRoot":"","sources":["../../src/classes/Redstone.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA+G;AAE/G,oCAA4C;AAC5C,wCAA2C;AAC3C,mCAA6D;AAE7D,gGAAmD;AAMnD,MAAa,QAAQ;IACjB,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,MAAe,KAAK;QACxD,IAAI,cAAc,GAAG;YACjB,aAAa,EAAE,uBAAuB;YACtC,eAAe,EAAE,CAAC,MAAM,CAAC;YACzB,kBAAkB,EAAE,CAAC;YACrB,iBAAiB,EAAE;gBACf,4CAA4C;gBAC5C,4CAA4C;gBAC5C,4CAA4C;gBAC5C,4CAA4C;aAC/C;SACJ,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAmB,EAAC,cAAc,CAAC,CAAC;QAC3D,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC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
import { Contract } from "ethers";
|
|
4
2
|
import { Decimal } from "decimal.js";
|
|
5
|
-
import { address } from "./types";
|
|
3
|
+
import { address, curvance_provider, curvance_signer } from "./types";
|
|
6
4
|
import { chains } from "./chains";
|
|
5
|
+
export type ChangeRate = "year" | "month" | "week" | "day";
|
|
6
|
+
export type ChainRpcPrefix = keyof typeof chains;
|
|
7
|
+
export declare const BPS: bigint;
|
|
8
|
+
export declare const BPS_SQUARED: bigint;
|
|
7
9
|
export declare const WAD: bigint;
|
|
10
|
+
export declare const WAD_BPS: bigint;
|
|
11
|
+
export declare const RAY: bigint;
|
|
12
|
+
export declare const WAD_SQUARED: bigint;
|
|
13
|
+
export declare const WAD_CUBED_BPS_OFFSET: bigint;
|
|
8
14
|
export declare const WAD_DECIMAL: Decimal;
|
|
9
|
-
export declare
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function
|
|
15
|
+
export declare const SECONDS_PER_YEAR = 31536000n;
|
|
16
|
+
export declare const SECONDS_PER_MONTH = 2592000n;
|
|
17
|
+
export declare const SECONDS_PER_WEEK = 604800n;
|
|
18
|
+
export declare const SECONDS_PER_DAY = 86400n;
|
|
19
|
+
export declare const UINT256_MAX = 115792089237316195423570985008687907853269984665640564039457584007913129639935n;
|
|
20
|
+
export declare const EMPTY_ADDRESS: address;
|
|
21
|
+
export declare function getRateSeconds(rate: ChangeRate): bigint;
|
|
22
|
+
export declare function toDecimal(value: bigint, decimals: bigint): Decimal;
|
|
23
|
+
export declare function toBigInt(value: number, decimals: bigint): bigint;
|
|
24
|
+
export declare function validateProviderAsSigner(provider: curvance_provider): curvance_signer;
|
|
25
|
+
export declare function contractSetup<I>(provider: curvance_provider, contractAddress: address, abi: any): Contract & I;
|
|
26
|
+
export declare function getContractAddresses(chain: ChainRpcPrefix): {
|
|
17
27
|
CentralRegistry: string;
|
|
18
28
|
OracleManager: string;
|
|
19
29
|
ChainlinkAdaptor: string;
|
|
@@ -33,10 +43,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
33
43
|
"Test WBTC / Test USDC": {
|
|
34
44
|
address: string;
|
|
35
45
|
isMarket: boolean;
|
|
36
|
-
plugins: {
|
|
37
|
-
simplePositionManager: string;
|
|
38
|
-
simpleZapper: string;
|
|
39
|
-
};
|
|
40
46
|
"WBTC-DynamicIRM": string;
|
|
41
47
|
tokens: {
|
|
42
48
|
WBTC: string;
|
|
@@ -47,10 +53,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
47
53
|
"Test LUSD / Test SWETH": {
|
|
48
54
|
address: string;
|
|
49
55
|
isMarket: boolean;
|
|
50
|
-
plugins: {
|
|
51
|
-
simplePositionManager: string;
|
|
52
|
-
simpleZapper: string;
|
|
53
|
-
};
|
|
54
56
|
"LUSD-DynamicIRM": string;
|
|
55
57
|
tokens: {
|
|
56
58
|
LUSD: string;
|
|
@@ -60,10 +62,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
60
62
|
"Test mUSD / Test mETH": {
|
|
61
63
|
address: string;
|
|
62
64
|
isMarket: boolean;
|
|
63
|
-
plugins: {
|
|
64
|
-
simplePositionManager: string;
|
|
65
|
-
simpleZapper: string;
|
|
66
|
-
};
|
|
67
65
|
tokens: {
|
|
68
66
|
mUSD: string;
|
|
69
67
|
mETH: string;
|
|
@@ -73,10 +71,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
73
71
|
"Test DAI / Test mkUSD": {
|
|
74
72
|
address: string;
|
|
75
73
|
isMarket: boolean;
|
|
76
|
-
plugins: {
|
|
77
|
-
simplePositionManager: string;
|
|
78
|
-
simpleZapper: string;
|
|
79
|
-
};
|
|
80
74
|
"DAI-DynamicIRM": string;
|
|
81
75
|
tokens: {
|
|
82
76
|
DAI: string;
|
|
@@ -97,11 +91,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
97
91
|
"Apriori (aprMON) / wMON": {
|
|
98
92
|
address: string;
|
|
99
93
|
isMarket: boolean;
|
|
100
|
-
plugins: {
|
|
101
|
-
simplePositionManager: string;
|
|
102
|
-
simpleZapper: string;
|
|
103
|
-
vaultZapper: string;
|
|
104
|
-
};
|
|
105
94
|
"aprMON-DynamicIRM": string;
|
|
106
95
|
tokens: {
|
|
107
96
|
aprMON: string;
|
|
@@ -112,11 +101,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
112
101
|
"Fastlane (shMON) / wMON": {
|
|
113
102
|
address: string;
|
|
114
103
|
isMarket: boolean;
|
|
115
|
-
plugins: {
|
|
116
|
-
simplePositionManager: string;
|
|
117
|
-
simpleZapper: string;
|
|
118
|
-
vaultZapper: string;
|
|
119
|
-
};
|
|
120
104
|
"shMON-DynamicIRM": string;
|
|
121
105
|
tokens: {
|
|
122
106
|
shMON: string;
|
|
@@ -127,11 +111,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
127
111
|
"Magma (gMON) / wMON": {
|
|
128
112
|
address: string;
|
|
129
113
|
isMarket: boolean;
|
|
130
|
-
plugins: {
|
|
131
|
-
simplePositionManager: string;
|
|
132
|
-
simpleZapper: string;
|
|
133
|
-
vaultZapper: string;
|
|
134
|
-
};
|
|
135
114
|
"gMON-DynamicIRM": string;
|
|
136
115
|
tokens: {
|
|
137
116
|
gMON: string;
|
|
@@ -142,11 +121,6 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
142
121
|
"Kintsu (sMON) / wMON": {
|
|
143
122
|
address: string;
|
|
144
123
|
isMarket: boolean;
|
|
145
|
-
plugins: {
|
|
146
|
-
simplePositionManager: string;
|
|
147
|
-
simpleZapper: string;
|
|
148
|
-
vaultZapper: string;
|
|
149
|
-
};
|
|
150
124
|
"sMON-DynamicIRM": string;
|
|
151
125
|
tokens: {
|
|
152
126
|
sMON: string;
|
|
@@ -156,6 +130,19 @@ export declare function getContractAddresses(chain: ChainRpcPrefix): never[] | {
|
|
|
156
130
|
};
|
|
157
131
|
ProtocolReader: string;
|
|
158
132
|
};
|
|
159
|
-
|
|
160
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Wraps a contract instance so all write actions automatically add a gas buffer.
|
|
135
|
+
*
|
|
136
|
+
* How it works:
|
|
137
|
+
* 1. Creates a proxy around the contract
|
|
138
|
+
* 2. Intercepts all function calls
|
|
139
|
+
* 3. For contract methods that support it, estimates gas usage
|
|
140
|
+
* 4. Adds the specified buffer percentage to the gas limit
|
|
141
|
+
* 5. Calls the original method with the buffered gas limit
|
|
142
|
+
*
|
|
143
|
+
* @param contract The ethers contract instance to wrap
|
|
144
|
+
* @param bufferPercent The percentage buffer to add (default 20%)
|
|
145
|
+
* @returns The same contract but with automatic gas buffering
|
|
146
|
+
*/
|
|
147
|
+
export declare function contractWithGasBuffer<T extends object>(contract: T, bufferPercent?: number): T;
|
|
161
148
|
//# sourceMappingURL=helpers.d.ts.map
|
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,
|
|
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,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,MAAM,CAAC;AAEjD,eAAO,MA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AAE,CAAC,EAAE,aAAa,SAAK,GAAG,CAAC,CAoB1F"}
|
package/dist/helpers.js
CHANGED
|
@@ -1,27 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EMPTY_ADDRESS = exports.UINT256_MAX = exports.SECONDS_PER_DAY = exports.SECONDS_PER_WEEK = exports.SECONDS_PER_MONTH = exports.SECONDS_PER_YEAR = exports.WAD_DECIMAL = exports.WAD_CUBED_BPS_OFFSET = exports.WAD_SQUARED = exports.RAY = exports.WAD_BPS = exports.WAD = exports.BPS_SQUARED = exports.BPS = void 0;
|
|
4
|
+
exports.getRateSeconds = getRateSeconds;
|
|
5
|
+
exports.toDecimal = toDecimal;
|
|
6
|
+
exports.toBigInt = toBigInt;
|
|
7
|
+
exports.validateProviderAsSigner = validateProviderAsSigner;
|
|
4
8
|
exports.contractSetup = contractSetup;
|
|
5
9
|
exports.getContractAddresses = getContractAddresses;
|
|
6
|
-
exports.
|
|
10
|
+
exports.contractWithGasBuffer = contractWithGasBuffer;
|
|
7
11
|
const ethers_1 = require("ethers");
|
|
8
12
|
const decimal_js_1 = require("decimal.js");
|
|
9
13
|
const chains_1 = require("./chains");
|
|
10
|
-
exports.
|
|
14
|
+
exports.BPS = BigInt(1e4);
|
|
15
|
+
exports.BPS_SQUARED = BigInt(1e8);
|
|
16
|
+
exports.WAD = BigInt(1e18);
|
|
17
|
+
exports.WAD_BPS = BigInt(1e22);
|
|
18
|
+
exports.RAY = BigInt(1e27);
|
|
19
|
+
exports.WAD_SQUARED = BigInt(1e36);
|
|
20
|
+
exports.WAD_CUBED_BPS_OFFSET = BigInt(1e50);
|
|
11
21
|
exports.WAD_DECIMAL = new decimal_js_1.Decimal(exports.WAD);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
exports.SECONDS_PER_YEAR = 31536000n;
|
|
23
|
+
exports.SECONDS_PER_MONTH = 2592000n;
|
|
24
|
+
exports.SECONDS_PER_WEEK = 604800n;
|
|
25
|
+
exports.SECONDS_PER_DAY = 86400n;
|
|
26
|
+
exports.UINT256_MAX = 115792089237316195423570985008687907853269984665640564039457584007913129639935n;
|
|
27
|
+
exports.EMPTY_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
28
|
+
function getRateSeconds(rate) {
|
|
29
|
+
switch (rate) {
|
|
30
|
+
case "year":
|
|
31
|
+
return exports.SECONDS_PER_YEAR;
|
|
32
|
+
case "month":
|
|
33
|
+
return exports.SECONDS_PER_MONTH;
|
|
34
|
+
case "week":
|
|
35
|
+
return exports.SECONDS_PER_WEEK;
|
|
36
|
+
case "day":
|
|
37
|
+
return exports.SECONDS_PER_DAY;
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unknown rate: ${rate}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function toDecimal(value, decimals) {
|
|
43
|
+
return new decimal_js_1.Decimal(value).div(new decimal_js_1.Decimal(10).pow(decimals));
|
|
44
|
+
}
|
|
45
|
+
function toBigInt(value, decimals) {
|
|
46
|
+
return (0, ethers_1.parseUnits)(value.toString(), decimals);
|
|
47
|
+
}
|
|
48
|
+
function validateProviderAsSigner(provider) {
|
|
49
|
+
const isSigner = "address" in provider;
|
|
50
|
+
if (!isSigner) {
|
|
51
|
+
throw new Error("Provider is not a signer, therefor this action is not available. Please connect a wallet to execute this action.");
|
|
52
|
+
}
|
|
53
|
+
return provider;
|
|
54
|
+
}
|
|
55
|
+
function contractSetup(provider, contractAddress, abi) {
|
|
56
|
+
const contract = new ethers_1.Contract(contractAddress, abi, provider);
|
|
21
57
|
if (contract == undefined || contract == null) {
|
|
22
58
|
throw new Error(`Failed to load contract at address ${contractAddress}.`);
|
|
23
59
|
}
|
|
24
|
-
return contract;
|
|
60
|
+
return contractWithGasBuffer(contract);
|
|
25
61
|
}
|
|
26
62
|
function getContractAddresses(chain) {
|
|
27
63
|
const config = chains_1.chains[chain];
|
|
@@ -30,11 +66,76 @@ function getContractAddresses(chain) {
|
|
|
30
66
|
}
|
|
31
67
|
return config;
|
|
32
68
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Calculates the gas limit with a buffer percentage added
|
|
71
|
+
* @param estimatedGas The original gas estimate from ethers
|
|
72
|
+
* @param bufferPercent The percentage buffer to add (e.g., 20 for 20%)
|
|
73
|
+
* @returns The gas limit with buffer applied
|
|
74
|
+
*/
|
|
75
|
+
function calculateGasWithBuffer(estimatedGas, bufferPercent) {
|
|
76
|
+
return (estimatedGas * BigInt(100 + bufferPercent)) / BigInt(100);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks if a contract method supports gas estimation
|
|
80
|
+
* @param method The contract method to check
|
|
81
|
+
* @returns true if the method has an estimateGas function
|
|
82
|
+
*/
|
|
83
|
+
function canEstimateGas(method) {
|
|
84
|
+
return typeof method?.estimateGas === 'function';
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Attempts to estimate gas and add buffer to transaction arguments
|
|
88
|
+
* @param method The contract method to estimate gas for
|
|
89
|
+
* @param args The transaction arguments
|
|
90
|
+
* @param bufferPercent The gas buffer percentage
|
|
91
|
+
* @returns true if gas estimation was successful and added to args
|
|
92
|
+
*/
|
|
93
|
+
async function tryAddGasBuffer(method, args, bufferPercent) {
|
|
94
|
+
if (!canEstimateGas(method)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const estimatedGas = await method.estimateGas(...args);
|
|
99
|
+
const gasLimit = calculateGasWithBuffer(estimatedGas, bufferPercent);
|
|
100
|
+
// Add the gas limit as transaction overrides
|
|
101
|
+
args.push({ gasLimit });
|
|
102
|
+
return true;
|
|
37
103
|
}
|
|
38
|
-
|
|
104
|
+
catch (error) {
|
|
105
|
+
// If gas estimation fails, continue without buffer
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Wraps a contract instance so all write actions automatically add a gas buffer.
|
|
111
|
+
*
|
|
112
|
+
* How it works:
|
|
113
|
+
* 1. Creates a proxy around the contract
|
|
114
|
+
* 2. Intercepts all function calls
|
|
115
|
+
* 3. For contract methods that support it, estimates gas usage
|
|
116
|
+
* 4. Adds the specified buffer percentage to the gas limit
|
|
117
|
+
* 5. Calls the original method with the buffered gas limit
|
|
118
|
+
*
|
|
119
|
+
* @param contract The ethers contract instance to wrap
|
|
120
|
+
* @param bufferPercent The percentage buffer to add (default 20%)
|
|
121
|
+
* @returns The same contract but with automatic gas buffering
|
|
122
|
+
*/
|
|
123
|
+
function contractWithGasBuffer(contract, bufferPercent = 10) {
|
|
124
|
+
return new Proxy(contract, {
|
|
125
|
+
get(target, methodName, receiver) {
|
|
126
|
+
const originalMethod = Reflect.get(target, methodName, receiver);
|
|
127
|
+
// Only wrap functions, skip special properties like populateTransaction
|
|
128
|
+
if (typeof originalMethod !== 'function' || methodName === 'populateTransaction') {
|
|
129
|
+
return originalMethod;
|
|
130
|
+
}
|
|
131
|
+
// Return a wrapped version of the method
|
|
132
|
+
return async (...args) => {
|
|
133
|
+
// Try to add gas buffer before calling the method
|
|
134
|
+
await tryAddGasBuffer(originalMethod, args, bufferPercent);
|
|
135
|
+
// Call the original method with potentially modified args
|
|
136
|
+
return originalMethod.apply(target, args);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
});
|
|
39
140
|
}
|
|
40
141
|
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"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AO,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9C,CAAC,CAAC;QACN,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { JsonRpcSigner, Wallet } from "ethers";
|
|
2
|
-
import { ChainRpcPrefix } from "./helpers";
|
|
1
|
+
import { JsonRpcProvider, JsonRpcSigner, Wallet } from "ethers";
|
|
2
|
+
import { ChainRpcPrefix, getContractAddresses } from "./helpers";
|
|
3
3
|
import { Market } from "./classes/Market";
|
|
4
4
|
import { ProtocolReader } from "./classes/ProtocolReader";
|
|
5
5
|
import { Faucet } from "./classes/Faucet";
|
|
6
|
-
export declare
|
|
6
|
+
export declare const backup_providers: Record<ChainRpcPrefix, JsonRpcProvider>;
|
|
7
|
+
export declare let active_contracts: ReturnType<typeof getContractAddresses>;
|
|
8
|
+
export declare function setupChain(chain: ChainRpcPrefix, signer: JsonRpcSigner | Wallet | JsonRpcProvider | null): Promise<{
|
|
7
9
|
markets: Market[];
|
|
8
10
|
faucet: Faucet;
|
|
9
11
|
reader: ProtocolReader;
|
package/dist/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,cAAc,EAAE,eAAe,CAEpE,CAAC;AACF,eAAO,IAAI,gBAAgB,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAErE,wBAAsB,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,GAAG,eAAe,GAAG,IAAI;;;;GAwB9G"}
|
package/dist/setup.js
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.active_contracts = exports.backup_providers = void 0;
|
|
3
4
|
exports.setupChain = setupChain;
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
4
6
|
const helpers_1 = require("./helpers");
|
|
5
7
|
const Market_1 = require("./classes/Market");
|
|
6
8
|
const ProtocolReader_1 = require("./classes/ProtocolReader");
|
|
7
9
|
const Faucet_1 = require("./classes/Faucet");
|
|
8
10
|
const OracleManager_1 = require("./classes/OracleManager");
|
|
11
|
+
exports.backup_providers = {
|
|
12
|
+
"monad-testnet": new ethers_1.JsonRpcProvider("https://rpc.ankr.com/monad_testnet")
|
|
13
|
+
};
|
|
9
14
|
async function setupChain(chain, signer) {
|
|
10
|
-
|
|
11
|
-
if (
|
|
15
|
+
exports.active_contracts = (0, helpers_1.getContractAddresses)(chain);
|
|
16
|
+
if (signer == null) {
|
|
17
|
+
signer = exports.backup_providers[chain];
|
|
18
|
+
}
|
|
19
|
+
if (!("ProtocolReader" in exports.active_contracts)) {
|
|
12
20
|
throw new Error(`Chain configuration for ${chain} is missing ProtocolReader address.`);
|
|
13
21
|
}
|
|
14
|
-
else if (!("Faucet" in
|
|
22
|
+
else if (!("Faucet" in exports.active_contracts)) {
|
|
15
23
|
throw new Error(`Chain configuration for ${chain} is missing Faucet address.`);
|
|
16
24
|
}
|
|
17
|
-
else if (!("OracleManager" in
|
|
25
|
+
else if (!("OracleManager" in exports.active_contracts)) {
|
|
18
26
|
throw new Error(`Chain configuration for ${chain} is missing OracleManager address.`);
|
|
19
27
|
}
|
|
20
|
-
const reader = new ProtocolReader_1.ProtocolReader(signer,
|
|
21
|
-
const faucet = new Faucet_1.Faucet(signer,
|
|
22
|
-
const oracle_manager = new OracleManager_1.OracleManager(signer,
|
|
28
|
+
const reader = new ProtocolReader_1.ProtocolReader(signer, exports.active_contracts.ProtocolReader);
|
|
29
|
+
const faucet = new Faucet_1.Faucet(signer, exports.active_contracts.Faucet);
|
|
30
|
+
const oracle_manager = new OracleManager_1.OracleManager(signer, exports.active_contracts.OracleManager);
|
|
23
31
|
return {
|
|
24
|
-
markets: await Market_1.Market.getAll(signer, reader, oracle_manager),
|
|
32
|
+
markets: await Market_1.Market.getAll(signer, reader, oracle_manager, exports.active_contracts),
|
|
25
33
|
faucet,
|
|
26
34
|
reader,
|
|
27
35
|
};
|
package/dist/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":";;;AAaA,gCAwBC;AArCD,mCAAgE;AAChE,uCAAiE;AACjE,6CAA0C;AAE1C,6DAA0D;AAC1D,6CAA0C;AAC1C,2DAAwD;AAE3C,QAAA,gBAAgB,GAA4C;IACrE,eAAe,EAAE,IAAI,wBAAe,CAAC,oCAAoC,CAAC;CAC7E,CAAC;AAGK,KAAK,UAAU,UAAU,CAAC,KAAqB,EAAE,MAAuD;IAC3G,wBAAgB,GAAG,IAAA,8BAAoB,EAAC,KAAK,CAAC,CAAC;IAE/C,IAAG,MAAM,IAAI,IAAI,EAAE,CAAC;QAChB,MAAM,GAAG,wBAAgB,CAAC,KAAK,CAAE,CAAC;IACtC,CAAC;IAED,IAAG,CAAC,CAAC,gBAAgB,IAAI,wBAAgB,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,qCAAqC,CAAC,CAAC;IAC3F,CAAC;SAAM,IAAI,CAAC,CAAC,QAAQ,IAAI,wBAAgB,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,6BAA6B,CAAC,CAAC;IACnF,CAAC;SAAM,IAAI,CAAC,CAAC,eAAe,IAAI,wBAAgB,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,oCAAoC,CAAC,CAAC;IAC1F,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,+BAAc,CAAC,MAAM,EAAE,wBAAgB,CAAC,cAAyB,CAAC,CAAA;IACrF,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,EAAE,wBAAgB,CAAC,MAAiB,CAAC,CAAC;IACtE,MAAM,cAAc,GAAG,IAAI,6BAAa,CAAC,MAAM,EAAE,wBAAgB,CAAC,aAAwB,CAAC,CAAC;IAE5F,OAAO;QACH,OAAO,EAAE,MAAM,eAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,wBAAgB,CAAC;QAC9E,MAAM;QACN,MAAM;KACT,CAAC;AACN,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import { JsonRpcProvider, JsonRpcSigner, Wallet } from "ethers";
|
|
2
3
|
export type address = `0x${string}`;
|
|
3
4
|
export type bytes = `0x${string}`;
|
|
4
5
|
export type uint = bigint | number;
|
|
@@ -6,5 +7,7 @@ export type uint240 = uint;
|
|
|
6
7
|
export type uint8 = uint;
|
|
7
8
|
export type uint256 = uint;
|
|
8
9
|
export type uint128 = uint;
|
|
10
|
+
export type percentage = Decimal;
|
|
11
|
+
export type curvance_provider = JsonRpcSigner | Wallet | JsonRpcProvider;
|
|
9
12
|
export type curvance_signer = JsonRpcSigner | Wallet;
|
|
10
13
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhE,MAAM,MAAM,OAAO,GAAG,KAAK,MAAM,EAAE,CAAC;AACpC,MAAM,MAAM,KAAK,GAAG,KAAK,MAAM,EAAE,CAAC;AAClC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;AAClC,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC;AAC3B,MAAM,MAAM,KAAK,GAAG,IAAI,CAAC;AACzB,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC;AAC3B,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC;AAC3B,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC;AACjC,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,MAAM,GAAG,eAAe,CAAC;AACzE,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "curvance",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"crypto"
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
|
+
"up": "npm run build && npm publish",
|
|
26
27
|
"fetch": "ts-node fetch-deployment.ts",
|
|
27
28
|
"build": "tsc",
|
|
28
29
|
"test": "node --test --require ts-node/register tests/*.test.ts",
|