@morpho-org/blue-sdk 1.0.6 → 1.2.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/README.md +2 -2
- package/lib/addresses.d.ts +34 -20
- package/lib/addresses.js +50 -13
- package/lib/chain.d.ts +30 -0
- package/lib/chain.js +288 -0
- package/lib/chain.test.js +22 -0
- package/lib/constants.d.ts +27 -6
- package/lib/constants.js +28 -8
- package/lib/errors.d.ts +18 -7
- package/lib/errors.js +38 -10
- package/lib/helpers/format/format.js +21 -60
- package/lib/helpers/index.d.ts +0 -2
- package/lib/helpers/index.js +0 -2
- package/lib/holding/Holding.d.ts +3 -4
- package/lib/holding/Holding.js +32 -4
- package/lib/index.d.ts +0 -8
- package/lib/index.js +1 -9
- package/lib/market/Market.d.ts +202 -54
- package/lib/market/Market.js +263 -62
- package/lib/market/MarketConfig.d.ts +17 -9
- package/lib/market/MarketConfig.js +39 -21
- package/lib/market/MarketUtils.d.ts +151 -102
- package/lib/market/MarketUtils.js +91 -39
- package/lib/market/MarketUtils.test.js +1 -2
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +5 -4
- package/lib/maths/AdaptiveCurveIrmLib.js +10 -7
- package/lib/maths/MathLib.d.ts +35 -15
- package/lib/maths/MathLib.js +53 -33
- package/lib/maths/SharesMath.d.ts +3 -3
- package/lib/maths/SharesMath.js +2 -3
- package/lib/maths/index.d.ts +0 -1
- package/lib/maths/index.js +0 -1
- package/lib/position/Position.d.ts +5 -26
- package/lib/position/Position.js +28 -35
- package/lib/tests/mocks/markets.d.ts +1 -0
- package/lib/tests/mocks/markets.js +35 -29
- package/lib/token/Token.d.ts +4 -3
- package/lib/token/Token.js +28 -3
- package/lib/token/WrappedToken.js +12 -6
- package/lib/token/index.d.ts +1 -1
- package/lib/token/index.js +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.js +3 -4
- package/lib/user/User.js +12 -0
- package/lib/vault/Vault.d.ts +12 -12
- package/lib/vault/Vault.js +102 -18
- package/lib/vault/VaultConfig.js +9 -3
- package/lib/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/vault/VaultMarketAllocation.js +30 -0
- package/lib/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/vault/VaultMarketConfig.js +43 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
- package/lib/vault/VaultUtils.d.ts +8 -9
- package/lib/vault/VaultUtils.js +2 -3
- package/lib/vault/index.d.ts +3 -1
- package/lib/vault/index.js +3 -1
- package/package.json +3 -6
- package/lib/chain/chain.constants.d.ts +0 -3
- package/lib/chain/chain.constants.js +0 -232
- package/lib/chain/chain.test.js +0 -37
- package/lib/chain/chain.types.d.ts +0 -20
- package/lib/chain/chain.types.js +0 -30
- package/lib/chain/chain.utils.d.ts +0 -14
- package/lib/chain/chain.utils.js +0 -30
- package/lib/chain/index.d.ts +0 -2
- package/lib/chain/index.js +0 -18
- package/lib/ethers/ethers.test.d.ts +0 -1
- package/lib/ethers/ethers.test.js +0 -11
- package/lib/ethers/index.d.ts +0 -2
- package/lib/ethers/index.js +0 -18
- package/lib/ethers/safeGetAddress.d.ts +0 -1
- package/lib/ethers/safeGetAddress.js +0 -6
- package/lib/ethers/safeParseUnits.d.ts +0 -2
- package/lib/ethers/safeParseUnits.js +0 -25
- package/lib/evm.d.ts +0 -36
- package/lib/evm.js +0 -113
- package/lib/helpers/getChecksumedAddress.d.ts +0 -7
- package/lib/helpers/getChecksumedAddress.js +0 -17
- package/lib/helpers/isZeroAddressOrUnset.d.ts +0 -7
- package/lib/helpers/isZeroAddressOrUnset.js +0 -14
- package/lib/maths/MathUtils.d.ts +0 -15
- package/lib/maths/MathUtils.js +0 -33
- package/lib/notifications.d.ts +0 -98
- package/lib/notifications.js +0 -52
- package/lib/signatures/index.d.ts +0 -12
- package/lib/signatures/index.js +0 -39
- package/lib/signatures/manager.d.ts +0 -10
- package/lib/signatures/manager.js +0 -37
- package/lib/signatures/permit.d.ts +0 -21
- package/lib/signatures/permit.js +0 -101
- package/lib/signatures/permit2.d.ts +0 -20
- package/lib/signatures/permit2.js +0 -91
- package/lib/signatures/types.d.ts +0 -13
- package/lib/signatures/types.js +0 -2
- package/lib/signatures/utils.d.ts +0 -6
- package/lib/signatures/utils.js +0 -44
- package/lib/token/ERC20Metadata.d.ts +0 -249
- package/lib/token/ERC20Metadata.js +0 -81
- package/lib/token/TokenNamespace.d.ts +0 -18
- package/lib/token/TokenNamespace.js +0 -55
- package/lib/vault/VaultAllocation.d.ts +0 -38
- package/lib/vault/VaultAllocation.js +0 -18
- /package/lib/{chain/chain.test.d.ts → chain.test.d.ts} +0 -0
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPermit2Message = exports.getPermit2TransferFromMessage = void 0;
|
|
4
|
-
const addresses_1 = require("../addresses");
|
|
5
|
-
const maths_1 = require("../maths");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
const getPermit2TransferFromMessage = (args, chainId) => {
|
|
8
|
-
const domain = {
|
|
9
|
-
name: "Permit2",
|
|
10
|
-
chainId: chainId.toString(),
|
|
11
|
-
verifyingContract: (0, addresses_1.getChainAddresses)(chainId).permit2,
|
|
12
|
-
};
|
|
13
|
-
const types = {
|
|
14
|
-
PermitTransferFrom: [
|
|
15
|
-
{ name: "permitted", type: "TokenPermissions" },
|
|
16
|
-
{ name: "spender", type: "address" },
|
|
17
|
-
{ name: "nonce", type: "uint256" },
|
|
18
|
-
{ name: "deadline", type: "uint256" },
|
|
19
|
-
],
|
|
20
|
-
TokenPermissions: [
|
|
21
|
-
{ name: "token", type: "address" },
|
|
22
|
-
{ name: "amount", type: "uint256" },
|
|
23
|
-
],
|
|
24
|
-
};
|
|
25
|
-
const value = {
|
|
26
|
-
permitted: {
|
|
27
|
-
token: args.erc20,
|
|
28
|
-
amount: maths_1.MathLib.min(args.allowance, maths_1.MathLib.MAX_UINT_160),
|
|
29
|
-
},
|
|
30
|
-
spender: args.spender,
|
|
31
|
-
nonce: args.nonce,
|
|
32
|
-
deadline: args.deadline,
|
|
33
|
-
};
|
|
34
|
-
return (0, utils_1.getMessage)(domain, types, value);
|
|
35
|
-
};
|
|
36
|
-
exports.getPermit2TransferFromMessage = getPermit2TransferFromMessage;
|
|
37
|
-
const getPermit2Message = (args, chainId) => {
|
|
38
|
-
const domain = {
|
|
39
|
-
name: "Permit2",
|
|
40
|
-
chainId: chainId.toString(),
|
|
41
|
-
verifyingContract: (0, addresses_1.getChainAddresses)(chainId).permit2,
|
|
42
|
-
};
|
|
43
|
-
const types = {
|
|
44
|
-
PermitSingle: [
|
|
45
|
-
{
|
|
46
|
-
name: "details",
|
|
47
|
-
type: "PermitDetails",
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: "spender",
|
|
51
|
-
type: "address",
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: "sigDeadline",
|
|
55
|
-
type: "uint256",
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
PermitDetails: [
|
|
59
|
-
{
|
|
60
|
-
name: "token",
|
|
61
|
-
type: "address",
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: "amount",
|
|
65
|
-
type: "uint160",
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: "expiration",
|
|
69
|
-
type: "uint48",
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: "nonce",
|
|
73
|
-
type: "uint48",
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
};
|
|
77
|
-
const value = {
|
|
78
|
-
details: {
|
|
79
|
-
token: args.erc20,
|
|
80
|
-
amount: maths_1.MathLib.min(args.allowance, maths_1.MathLib.MAX_UINT_160),
|
|
81
|
-
// Use an unlimited expiration because it most
|
|
82
|
-
// closely mimics how a standard approval works.
|
|
83
|
-
expiration: maths_1.MathLib.min(args.expiration ?? maths_1.MathLib.MAX_UINT_48, maths_1.MathLib.MAX_UINT_48),
|
|
84
|
-
nonce: args.nonce,
|
|
85
|
-
},
|
|
86
|
-
spender: args.spender,
|
|
87
|
-
sigDeadline: args.deadline,
|
|
88
|
-
};
|
|
89
|
-
return (0, utils_1.getMessage)(domain, types, value);
|
|
90
|
-
};
|
|
91
|
-
exports.getPermit2Message = getPermit2Message;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TypedDataDomain } from "ethers";
|
|
2
|
-
export interface SignatureData {
|
|
3
|
-
domain: TypedDataDomain;
|
|
4
|
-
types: Record<string, {
|
|
5
|
-
name: string;
|
|
6
|
-
type: string;
|
|
7
|
-
}[]>;
|
|
8
|
-
value: object;
|
|
9
|
-
}
|
|
10
|
-
export interface SignatureMessage {
|
|
11
|
-
hash: string;
|
|
12
|
-
data: SignatureData;
|
|
13
|
-
}
|
package/lib/signatures/types.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Signature, Signer, TypedDataDomain, TypedDataField } from "ethers";
|
|
2
|
-
import { Address } from "../types";
|
|
3
|
-
import { SignatureMessage } from "./types";
|
|
4
|
-
export declare function safeSignTypedData(signer: Signer, domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, any>): Promise<Signature>;
|
|
5
|
-
export declare function verifySignature(signature: Signature, hash: string, signerAddress: Address): void;
|
|
6
|
-
export declare function getMessage(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, any>): SignatureMessage;
|
package/lib/signatures/utils.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMessage = exports.verifySignature = exports.safeSignTypedData = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const errors_1 = require("../errors");
|
|
6
|
-
async function safeSignTypedData(signer, domain, types, value) {
|
|
7
|
-
const populated = await ethers_1.TypedDataEncoder.resolveNames(domain, types, value, (name) => {
|
|
8
|
-
return signer.resolveName(name);
|
|
9
|
-
});
|
|
10
|
-
// Fix the chainId parsing issue
|
|
11
|
-
// Tracking of https://github.com/ethers-io/ethers.js/issues/4649
|
|
12
|
-
const initialPayload = ethers_1.TypedDataEncoder.getPayload(populated.domain, types, populated.value);
|
|
13
|
-
const provider = signer.provider;
|
|
14
|
-
const unsafeChainId = Number(initialPayload.domain.chainId);
|
|
15
|
-
if (provider && "send" in provider && Number.isSafeInteger(unsafeChainId)) {
|
|
16
|
-
const correctedPayload = {
|
|
17
|
-
...initialPayload,
|
|
18
|
-
domain: {
|
|
19
|
-
...initialPayload.domain,
|
|
20
|
-
chainId: unsafeChainId, // that is safe now
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
return ethers_1.Signature.from(
|
|
24
|
-
// @ts-ignore if send is defined in the provider, it accepts raw RPC call args
|
|
25
|
-
await signer.provider.send("eth_signTypedData_v4", [
|
|
26
|
-
// Doing the same thing that inside of the signTypedData function.
|
|
27
|
-
await signer.getAddress().then((r) => r.toLowerCase()),
|
|
28
|
-
JSON.stringify(correctedPayload),
|
|
29
|
-
]));
|
|
30
|
-
}
|
|
31
|
-
return ethers_1.Signature.from(await signer.signTypedData(populated.domain, types, populated.value));
|
|
32
|
-
}
|
|
33
|
-
exports.safeSignTypedData = safeSignTypedData;
|
|
34
|
-
function verifySignature(signature, hash, signerAddress) {
|
|
35
|
-
const recoveredAddress = (0, ethers_1.recoverAddress)(hash, signature);
|
|
36
|
-
if (recoveredAddress === ethers_1.ZeroAddress || recoveredAddress !== signerAddress)
|
|
37
|
-
throw new errors_1.InvalidSignatureError(hash, signerAddress, recoveredAddress);
|
|
38
|
-
}
|
|
39
|
-
exports.verifySignature = verifySignature;
|
|
40
|
-
function getMessage(domain, types, value) {
|
|
41
|
-
const hash = ethers_1.TypedDataEncoder.hash(domain, types, value);
|
|
42
|
-
return { data: { domain, types, value }, hash };
|
|
43
|
-
}
|
|
44
|
-
exports.getMessage = getMessage;
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { ContractRunner } from "ethers";
|
|
2
|
-
import { ERC20, ERC20Interface } from "ethers-types/dist/token/ERC20/ERC20";
|
|
3
|
-
import { ChainId } from "../chain";
|
|
4
|
-
export declare const isBytes32ERC20Metadata: (address: string, chainId: ChainId) => boolean;
|
|
5
|
-
export declare const decodeString: (bytes32OrStr: string) => string;
|
|
6
|
-
export declare class Bytes32ERC20__factory {
|
|
7
|
-
static readonly abi: readonly [...({
|
|
8
|
-
readonly inputs: readonly [{
|
|
9
|
-
readonly internalType: "string";
|
|
10
|
-
readonly name: "name_";
|
|
11
|
-
readonly type: "string";
|
|
12
|
-
}, {
|
|
13
|
-
readonly internalType: "string";
|
|
14
|
-
readonly name: "symbol_";
|
|
15
|
-
readonly type: "string";
|
|
16
|
-
}];
|
|
17
|
-
readonly stateMutability: "nonpayable";
|
|
18
|
-
readonly type: "constructor";
|
|
19
|
-
} | {
|
|
20
|
-
readonly anonymous: false;
|
|
21
|
-
readonly inputs: readonly [{
|
|
22
|
-
readonly indexed: true;
|
|
23
|
-
readonly internalType: "address";
|
|
24
|
-
readonly name: "owner";
|
|
25
|
-
readonly type: "address";
|
|
26
|
-
}, {
|
|
27
|
-
readonly indexed: true;
|
|
28
|
-
readonly internalType: "address";
|
|
29
|
-
readonly name: "spender";
|
|
30
|
-
readonly type: "address";
|
|
31
|
-
}, {
|
|
32
|
-
readonly indexed: false;
|
|
33
|
-
readonly internalType: "uint256";
|
|
34
|
-
readonly name: "value";
|
|
35
|
-
readonly type: "uint256";
|
|
36
|
-
}];
|
|
37
|
-
readonly name: "Approval";
|
|
38
|
-
readonly type: "event";
|
|
39
|
-
} | {
|
|
40
|
-
readonly anonymous: false;
|
|
41
|
-
readonly inputs: readonly [{
|
|
42
|
-
readonly indexed: true;
|
|
43
|
-
readonly internalType: "address";
|
|
44
|
-
readonly name: "from";
|
|
45
|
-
readonly type: "address";
|
|
46
|
-
}, {
|
|
47
|
-
readonly indexed: true;
|
|
48
|
-
readonly internalType: "address";
|
|
49
|
-
readonly name: "to";
|
|
50
|
-
readonly type: "address";
|
|
51
|
-
}, {
|
|
52
|
-
readonly indexed: false;
|
|
53
|
-
readonly internalType: "uint256";
|
|
54
|
-
readonly name: "value";
|
|
55
|
-
readonly type: "uint256";
|
|
56
|
-
}];
|
|
57
|
-
readonly name: "Transfer";
|
|
58
|
-
readonly type: "event";
|
|
59
|
-
} | {
|
|
60
|
-
readonly inputs: readonly [{
|
|
61
|
-
readonly internalType: "address";
|
|
62
|
-
readonly name: "owner";
|
|
63
|
-
readonly type: "address";
|
|
64
|
-
}, {
|
|
65
|
-
readonly internalType: "address";
|
|
66
|
-
readonly name: "spender";
|
|
67
|
-
readonly type: "address";
|
|
68
|
-
}];
|
|
69
|
-
readonly name: "allowance";
|
|
70
|
-
readonly outputs: readonly [{
|
|
71
|
-
readonly internalType: "uint256";
|
|
72
|
-
readonly name: "";
|
|
73
|
-
readonly type: "uint256";
|
|
74
|
-
}];
|
|
75
|
-
readonly stateMutability: "view";
|
|
76
|
-
readonly type: "function";
|
|
77
|
-
} | {
|
|
78
|
-
readonly inputs: readonly [{
|
|
79
|
-
readonly internalType: "address";
|
|
80
|
-
readonly name: "spender";
|
|
81
|
-
readonly type: "address";
|
|
82
|
-
}, {
|
|
83
|
-
readonly internalType: "uint256";
|
|
84
|
-
readonly name: "amount";
|
|
85
|
-
readonly type: "uint256";
|
|
86
|
-
}];
|
|
87
|
-
readonly name: "approve";
|
|
88
|
-
readonly outputs: readonly [{
|
|
89
|
-
readonly internalType: "bool";
|
|
90
|
-
readonly name: "";
|
|
91
|
-
readonly type: "bool";
|
|
92
|
-
}];
|
|
93
|
-
readonly stateMutability: "nonpayable";
|
|
94
|
-
readonly type: "function";
|
|
95
|
-
} | {
|
|
96
|
-
readonly inputs: readonly [{
|
|
97
|
-
readonly internalType: "address";
|
|
98
|
-
readonly name: "account";
|
|
99
|
-
readonly type: "address";
|
|
100
|
-
}];
|
|
101
|
-
readonly name: "balanceOf";
|
|
102
|
-
readonly outputs: readonly [{
|
|
103
|
-
readonly internalType: "uint256";
|
|
104
|
-
readonly name: "";
|
|
105
|
-
readonly type: "uint256";
|
|
106
|
-
}];
|
|
107
|
-
readonly stateMutability: "view";
|
|
108
|
-
readonly type: "function";
|
|
109
|
-
} | {
|
|
110
|
-
readonly inputs: readonly [];
|
|
111
|
-
readonly name: "decimals";
|
|
112
|
-
readonly outputs: readonly [{
|
|
113
|
-
readonly internalType: "uint8";
|
|
114
|
-
readonly name: "";
|
|
115
|
-
readonly type: "uint8";
|
|
116
|
-
}];
|
|
117
|
-
readonly stateMutability: "view";
|
|
118
|
-
readonly type: "function";
|
|
119
|
-
} | {
|
|
120
|
-
readonly inputs: readonly [{
|
|
121
|
-
readonly internalType: "address";
|
|
122
|
-
readonly name: "spender";
|
|
123
|
-
readonly type: "address";
|
|
124
|
-
}, {
|
|
125
|
-
readonly internalType: "uint256";
|
|
126
|
-
readonly name: "subtractedValue";
|
|
127
|
-
readonly type: "uint256";
|
|
128
|
-
}];
|
|
129
|
-
readonly name: "decreaseAllowance";
|
|
130
|
-
readonly outputs: readonly [{
|
|
131
|
-
readonly internalType: "bool";
|
|
132
|
-
readonly name: "";
|
|
133
|
-
readonly type: "bool";
|
|
134
|
-
}];
|
|
135
|
-
readonly stateMutability: "nonpayable";
|
|
136
|
-
readonly type: "function";
|
|
137
|
-
} | {
|
|
138
|
-
readonly inputs: readonly [{
|
|
139
|
-
readonly internalType: "address";
|
|
140
|
-
readonly name: "spender";
|
|
141
|
-
readonly type: "address";
|
|
142
|
-
}, {
|
|
143
|
-
readonly internalType: "uint256";
|
|
144
|
-
readonly name: "addedValue";
|
|
145
|
-
readonly type: "uint256";
|
|
146
|
-
}];
|
|
147
|
-
readonly name: "increaseAllowance";
|
|
148
|
-
readonly outputs: readonly [{
|
|
149
|
-
readonly internalType: "bool";
|
|
150
|
-
readonly name: "";
|
|
151
|
-
readonly type: "bool";
|
|
152
|
-
}];
|
|
153
|
-
readonly stateMutability: "nonpayable";
|
|
154
|
-
readonly type: "function";
|
|
155
|
-
} | {
|
|
156
|
-
readonly inputs: readonly [];
|
|
157
|
-
readonly name: "name";
|
|
158
|
-
readonly outputs: readonly [{
|
|
159
|
-
readonly internalType: "string";
|
|
160
|
-
readonly name: "";
|
|
161
|
-
readonly type: "string";
|
|
162
|
-
}];
|
|
163
|
-
readonly stateMutability: "view";
|
|
164
|
-
readonly type: "function";
|
|
165
|
-
} | {
|
|
166
|
-
readonly inputs: readonly [];
|
|
167
|
-
readonly name: "symbol";
|
|
168
|
-
readonly outputs: readonly [{
|
|
169
|
-
readonly internalType: "string";
|
|
170
|
-
readonly name: "";
|
|
171
|
-
readonly type: "string";
|
|
172
|
-
}];
|
|
173
|
-
readonly stateMutability: "view";
|
|
174
|
-
readonly type: "function";
|
|
175
|
-
} | {
|
|
176
|
-
readonly inputs: readonly [];
|
|
177
|
-
readonly name: "totalSupply";
|
|
178
|
-
readonly outputs: readonly [{
|
|
179
|
-
readonly internalType: "uint256";
|
|
180
|
-
readonly name: "";
|
|
181
|
-
readonly type: "uint256";
|
|
182
|
-
}];
|
|
183
|
-
readonly stateMutability: "view";
|
|
184
|
-
readonly type: "function";
|
|
185
|
-
} | {
|
|
186
|
-
readonly inputs: readonly [{
|
|
187
|
-
readonly internalType: "address";
|
|
188
|
-
readonly name: "to";
|
|
189
|
-
readonly type: "address";
|
|
190
|
-
}, {
|
|
191
|
-
readonly internalType: "uint256";
|
|
192
|
-
readonly name: "amount";
|
|
193
|
-
readonly type: "uint256";
|
|
194
|
-
}];
|
|
195
|
-
readonly name: "transfer";
|
|
196
|
-
readonly outputs: readonly [{
|
|
197
|
-
readonly internalType: "bool";
|
|
198
|
-
readonly name: "";
|
|
199
|
-
readonly type: "bool";
|
|
200
|
-
}];
|
|
201
|
-
readonly stateMutability: "nonpayable";
|
|
202
|
-
readonly type: "function";
|
|
203
|
-
} | {
|
|
204
|
-
readonly inputs: readonly [{
|
|
205
|
-
readonly internalType: "address";
|
|
206
|
-
readonly name: "from";
|
|
207
|
-
readonly type: "address";
|
|
208
|
-
}, {
|
|
209
|
-
readonly internalType: "address";
|
|
210
|
-
readonly name: "to";
|
|
211
|
-
readonly type: "address";
|
|
212
|
-
}, {
|
|
213
|
-
readonly internalType: "uint256";
|
|
214
|
-
readonly name: "amount";
|
|
215
|
-
readonly type: "uint256";
|
|
216
|
-
}];
|
|
217
|
-
readonly name: "transferFrom";
|
|
218
|
-
readonly outputs: readonly [{
|
|
219
|
-
readonly internalType: "bool";
|
|
220
|
-
readonly name: "";
|
|
221
|
-
readonly type: "bool";
|
|
222
|
-
}];
|
|
223
|
-
readonly stateMutability: "nonpayable";
|
|
224
|
-
readonly type: "function";
|
|
225
|
-
})[], {
|
|
226
|
-
readonly inputs: readonly [];
|
|
227
|
-
readonly name: "symbol";
|
|
228
|
-
readonly outputs: readonly [{
|
|
229
|
-
readonly name: "symbol";
|
|
230
|
-
readonly type: "bytes32";
|
|
231
|
-
}];
|
|
232
|
-
readonly stateMutability: "view";
|
|
233
|
-
readonly type: "function";
|
|
234
|
-
}, {
|
|
235
|
-
readonly inputs: readonly [];
|
|
236
|
-
readonly name: "name";
|
|
237
|
-
readonly outputs: readonly [{
|
|
238
|
-
readonly name: "name";
|
|
239
|
-
readonly type: "bytes32";
|
|
240
|
-
}];
|
|
241
|
-
readonly stateMutability: "view";
|
|
242
|
-
readonly type: "function";
|
|
243
|
-
}];
|
|
244
|
-
static createInterface(): ERC20Interface;
|
|
245
|
-
static connect(address: string, runner?: ContractRunner | null): ERC20;
|
|
246
|
-
}
|
|
247
|
-
export declare class ERC20Metadata__factory {
|
|
248
|
-
static connect(address: string, chainId: ChainId, runner?: ContractRunner | null): ERC20;
|
|
249
|
-
}
|
|
@@ -1,81 +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
|
-
exports.ERC20Metadata__factory = exports.Bytes32ERC20__factory = exports.decodeString = exports.isBytes32ERC20Metadata = void 0;
|
|
7
|
-
const ethers_1 = require("ethers");
|
|
8
|
-
const ethers_types_1 = require("ethers-types");
|
|
9
|
-
const addresses_1 = __importDefault(require("../addresses"));
|
|
10
|
-
const chain_1 = require("../chain");
|
|
11
|
-
const isBytes32ERC20Metadata = (address, chainId) => {
|
|
12
|
-
switch (chainId) {
|
|
13
|
-
case chain_1.ChainId.EthMainnet:
|
|
14
|
-
return [addresses_1.default[chain_1.ChainId.EthMainnet].mkr].includes(address);
|
|
15
|
-
default:
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
exports.isBytes32ERC20Metadata = isBytes32ERC20Metadata;
|
|
20
|
-
const decodeString = (bytes32OrStr) => {
|
|
21
|
-
if ((0, ethers_1.isHexString)(bytes32OrStr, 32))
|
|
22
|
-
return (0, ethers_1.decodeBytes32String)(bytes32OrStr);
|
|
23
|
-
return bytes32OrStr;
|
|
24
|
-
};
|
|
25
|
-
exports.decodeString = decodeString;
|
|
26
|
-
const _bytes32ERC20Abi = [
|
|
27
|
-
...ethers_types_1.ERC20__factory.abi.filter((fragment) => !("name" in fragment) ||
|
|
28
|
-
(fragment.name !== "name" && fragment.name !== "symbol")),
|
|
29
|
-
{
|
|
30
|
-
inputs: [],
|
|
31
|
-
name: "symbol",
|
|
32
|
-
outputs: [
|
|
33
|
-
{
|
|
34
|
-
name: "symbol",
|
|
35
|
-
type: "bytes32",
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
stateMutability: "view",
|
|
39
|
-
type: "function",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
inputs: [],
|
|
43
|
-
name: "name",
|
|
44
|
-
outputs: [
|
|
45
|
-
{
|
|
46
|
-
name: "name",
|
|
47
|
-
type: "bytes32",
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
stateMutability: "view",
|
|
51
|
-
type: "function",
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
class Bytes32ERC20__factory {
|
|
55
|
-
static createInterface() {
|
|
56
|
-
return new ethers_1.Interface(_bytes32ERC20Abi);
|
|
57
|
-
}
|
|
58
|
-
static connect(address, runner) {
|
|
59
|
-
const erc20 = new ethers_1.Contract(address, _bytes32ERC20Abi, runner);
|
|
60
|
-
const name = erc20.name.bind(erc20);
|
|
61
|
-
erc20.name = Object.assign((...args) => name(...args).then(exports.decodeString), name);
|
|
62
|
-
const symbol = erc20.symbol.bind(erc20);
|
|
63
|
-
erc20.symbol = Object.assign((...args) => symbol(...args).then(exports.decodeString), symbol);
|
|
64
|
-
return erc20;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.Bytes32ERC20__factory = Bytes32ERC20__factory;
|
|
68
|
-
Bytes32ERC20__factory.abi = _bytes32ERC20Abi;
|
|
69
|
-
class ERC20Metadata__factory {
|
|
70
|
-
static connect(address, chainId, runner) {
|
|
71
|
-
if ((0, exports.isBytes32ERC20Metadata)(address, chainId))
|
|
72
|
-
return Bytes32ERC20__factory.connect(address, runner);
|
|
73
|
-
const erc20 = ethers_types_1.ERC20__factory.connect(address, runner);
|
|
74
|
-
const name = erc20.name.bind(erc20);
|
|
75
|
-
erc20.name = Object.assign((...args) => name(...args).catch(() => Bytes32ERC20__factory.connect(address, runner).name(...args)), name);
|
|
76
|
-
const symbol = erc20.symbol.bind(erc20);
|
|
77
|
-
erc20.symbol = Object.assign((...args) => symbol(...args).catch(() => Bytes32ERC20__factory.connect(address, runner).symbol(...args)), symbol);
|
|
78
|
-
return erc20;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.ERC20Metadata__factory = ERC20Metadata__factory;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Provider } from "ethers";
|
|
2
|
-
import { ViewOverrides } from "ethers-types/dist/common";
|
|
3
|
-
import { ChainId } from "../chain";
|
|
4
|
-
import { Address } from "../types";
|
|
5
|
-
import { Token as TokenClass } from "./Token";
|
|
6
|
-
import { ConstantWrappedToken, ExchangeRateWrappedToken } from "./WrappedToken";
|
|
7
|
-
export declare class Token extends TokenClass {
|
|
8
|
-
}
|
|
9
|
-
export { TokenWithPrice } from "./Token";
|
|
10
|
-
export declare namespace Token {
|
|
11
|
-
function native(chainId: ChainId): Token;
|
|
12
|
-
function fetch(address: Address, runner: {
|
|
13
|
-
provider: Provider;
|
|
14
|
-
}, { chainId, overrides, }?: {
|
|
15
|
-
chainId?: ChainId;
|
|
16
|
-
overrides?: ViewOverrides;
|
|
17
|
-
}): Promise<Token | ConstantWrappedToken | ExchangeRateWrappedToken>;
|
|
18
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenWithPrice = exports.Token = void 0;
|
|
4
|
-
const ethers_types_1 = require("ethers-types");
|
|
5
|
-
const addresses_1 = require("../addresses");
|
|
6
|
-
const chain_1 = require("../chain");
|
|
7
|
-
const ERC20Metadata_1 = require("./ERC20Metadata");
|
|
8
|
-
const Token_1 = require("./Token");
|
|
9
|
-
const WrappedToken_1 = require("./WrappedToken");
|
|
10
|
-
class Token extends Token_1.Token {
|
|
11
|
-
}
|
|
12
|
-
exports.Token = Token;
|
|
13
|
-
var Token_2 = require("./Token");
|
|
14
|
-
Object.defineProperty(exports, "TokenWithPrice", { enumerable: true, get: function () { return Token_2.TokenWithPrice; } });
|
|
15
|
-
(function (Token) {
|
|
16
|
-
function native(chainId) {
|
|
17
|
-
const currency = chain_1.ChainUtils.chainMetadata[chainId].nativeCurrency;
|
|
18
|
-
return new Token({ ...currency, address: addresses_1.NATIVE_ADDRESS });
|
|
19
|
-
}
|
|
20
|
-
Token.native = native;
|
|
21
|
-
async function fetch(address, runner, { chainId, overrides = {}, } = {}) {
|
|
22
|
-
chainId ?? (chainId = chain_1.ChainUtils.parseSupportedChainId((await runner.provider.getNetwork()).chainId));
|
|
23
|
-
if (address === addresses_1.NATIVE_ADDRESS)
|
|
24
|
-
return Token.native(chainId);
|
|
25
|
-
const erc20 = ERC20Metadata_1.ERC20Metadata__factory.connect(address, chainId, runner);
|
|
26
|
-
const [decimals, symbol, name] = await Promise.all([
|
|
27
|
-
erc20.decimals(overrides),
|
|
28
|
-
erc20.symbol(overrides),
|
|
29
|
-
erc20.name(overrides),
|
|
30
|
-
]);
|
|
31
|
-
const token = {
|
|
32
|
-
address,
|
|
33
|
-
decimals: parseInt(decimals.toString()),
|
|
34
|
-
symbol,
|
|
35
|
-
name,
|
|
36
|
-
};
|
|
37
|
-
const { wstEth, stEth } = (0, addresses_1.getChainAddresses)(chainId);
|
|
38
|
-
switch (address) {
|
|
39
|
-
case wstEth: {
|
|
40
|
-
if (stEth) {
|
|
41
|
-
const wstEthToken = ethers_types_1.WStEth__factory.connect(wstEth, runner);
|
|
42
|
-
const stEthPerWstEth = await wstEthToken.stEthPerToken(overrides);
|
|
43
|
-
return new WrappedToken_1.ExchangeRateWrappedToken(token, stEth, stEthPerWstEth);
|
|
44
|
-
}
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const unwrapToken = (0, addresses_1.getUnwrappedToken)(address, chainId);
|
|
49
|
-
if (unwrapToken) {
|
|
50
|
-
return new WrappedToken_1.ConstantWrappedToken(token, unwrapToken, token.decimals); //TODO fetch underlying token's decimals if it can be different form token's decimals
|
|
51
|
-
}
|
|
52
|
-
return new Token(token);
|
|
53
|
-
}
|
|
54
|
-
Token.fetch = fetch;
|
|
55
|
-
})(Token || (exports.Token = Token = {}));
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { AccrualPosition } from "../position";
|
|
2
|
-
import { Pending } from "./Vault";
|
|
3
|
-
/**
|
|
4
|
-
* The vault's configuration of a market on the PublicAllocator.
|
|
5
|
-
*/
|
|
6
|
-
export interface VaultMarketPublicAllocatorConfig {
|
|
7
|
-
maxIn: bigint;
|
|
8
|
-
maxOut: bigint;
|
|
9
|
-
}
|
|
10
|
-
export interface VaultMarketConfig {
|
|
11
|
-
cap: bigint;
|
|
12
|
-
pendingCap: Pending<bigint>;
|
|
13
|
-
removableAt: bigint;
|
|
14
|
-
enabled: boolean;
|
|
15
|
-
readonly publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
|
|
16
|
-
}
|
|
17
|
-
export interface InputVaultAllocation {
|
|
18
|
-
config: VaultMarketConfig;
|
|
19
|
-
position: AccrualPosition;
|
|
20
|
-
proportion: bigint;
|
|
21
|
-
}
|
|
22
|
-
export declare class VaultAllocation implements InputVaultAllocation {
|
|
23
|
-
/**
|
|
24
|
-
* The vault's configuration on the corresponding market.
|
|
25
|
-
*/
|
|
26
|
-
config: VaultMarketConfig;
|
|
27
|
-
/**
|
|
28
|
-
* The vault's position on the corresponding market.
|
|
29
|
-
*/
|
|
30
|
-
readonly position: AccrualPosition;
|
|
31
|
-
/**
|
|
32
|
-
* The vault's proportion of assets supplied on the corresponding market,
|
|
33
|
-
* with regard to the total assets of the vault.
|
|
34
|
-
*/
|
|
35
|
-
readonly proportion: bigint;
|
|
36
|
-
constructor({ config, position, proportion }: InputVaultAllocation);
|
|
37
|
-
get utilization(): bigint;
|
|
38
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultAllocation = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const maths_1 = require("../maths");
|
|
6
|
-
class VaultAllocation {
|
|
7
|
-
constructor({ config, position, proportion }) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
this.position = position;
|
|
10
|
-
this.proportion = proportion;
|
|
11
|
-
}
|
|
12
|
-
get utilization() {
|
|
13
|
-
if (this.config.cap === 0n)
|
|
14
|
-
return ethers_1.MaxUint256;
|
|
15
|
-
return maths_1.MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.VaultAllocation = VaultAllocation;
|
|
File without changes
|