@morpho-org/blue-sdk 1.0.1 → 1.0.2

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.
Files changed (151) hide show
  1. package/package.json +10 -6
  2. package/src/addresses.ts +261 -0
  3. package/src/chain/chain.constants.ts +235 -0
  4. package/src/chain/chain.test.ts +51 -0
  5. package/src/chain/chain.types.ts +42 -0
  6. package/src/chain/chain.utils.ts +44 -0
  7. package/src/constants.ts +18 -0
  8. package/src/errors.ts +75 -0
  9. package/src/ethers/ethers.test.ts +17 -0
  10. package/src/ethers/safeGetAddress.ts +4 -0
  11. package/src/ethers/safeParseUnits.ts +29 -0
  12. package/src/evm.ts +172 -0
  13. package/src/helpers/format/format.test.ts +340 -0
  14. package/src/helpers/format/format.ts +416 -0
  15. package/src/helpers/getChecksumedAddress.ts +15 -0
  16. package/{lib/helpers/isZeroAddressOrUnset.d.ts → src/helpers/isZeroAddressOrUnset.ts} +7 -1
  17. package/src/helpers/locale.ts +108 -0
  18. package/src/holding/Holding.ts +109 -0
  19. package/src/market/Market.ts +479 -0
  20. package/src/market/MarketConfig.ts +108 -0
  21. package/src/market/MarketUtils.test.ts +25 -0
  22. package/src/market/MarketUtils.ts +467 -0
  23. package/src/maths/AdaptiveCurveIrmLib.ts +143 -0
  24. package/src/maths/MathLib.ts +208 -0
  25. package/src/maths/MathUtils.ts +31 -0
  26. package/src/maths/SharesMath.ts +40 -0
  27. package/src/notifications.ts +167 -0
  28. package/src/position/Position.ts +251 -0
  29. package/src/signatures/index.ts +18 -0
  30. package/src/signatures/manager.ts +50 -0
  31. package/src/signatures/permit.ts +126 -0
  32. package/src/signatures/permit2.ts +120 -0
  33. package/src/signatures/types.ts +18 -0
  34. package/src/signatures/utils.ts +83 -0
  35. package/src/tests/mocks/markets.ts +110 -0
  36. package/src/token/ERC20Metadata.ts +124 -0
  37. package/src/token/Token.ts +83 -0
  38. package/src/token/TokenNamespace.ts +76 -0
  39. package/src/token/WrappedToken.ts +142 -0
  40. package/src/types.ts +37 -0
  41. package/src/user/User.ts +32 -0
  42. package/src/user/user.types.ts +23 -0
  43. package/src/vault/Vault.ts +370 -0
  44. package/src/vault/VaultAllocation.ts +58 -0
  45. package/src/vault/VaultConfig.ts +55 -0
  46. package/src/vault/VaultUtils.ts +47 -0
  47. package/lib/addresses.d.ts +0 -168
  48. package/lib/addresses.js +0 -169
  49. package/lib/chain/chain.constants.d.ts +0 -3
  50. package/lib/chain/chain.constants.js +0 -232
  51. package/lib/chain/chain.types.d.ts +0 -20
  52. package/lib/chain/chain.types.js +0 -30
  53. package/lib/chain/chain.utils.d.ts +0 -14
  54. package/lib/chain/chain.utils.js +0 -30
  55. package/lib/chain/index.js +0 -18
  56. package/lib/constants.d.ts +0 -8
  57. package/lib/constants.js +0 -13
  58. package/lib/errors.d.ts +0 -37
  59. package/lib/errors.js +0 -71
  60. package/lib/ethers/index.js +0 -18
  61. package/lib/ethers/safeGetAddress.d.ts +0 -1
  62. package/lib/ethers/safeGetAddress.js +0 -6
  63. package/lib/ethers/safeParseUnits.d.ts +0 -2
  64. package/lib/ethers/safeParseUnits.js +0 -25
  65. package/lib/evm.d.ts +0 -36
  66. package/lib/evm.js +0 -113
  67. package/lib/helpers/format/format.d.ts +0 -98
  68. package/lib/helpers/format/format.js +0 -301
  69. package/lib/helpers/format/index.js +0 -17
  70. package/lib/helpers/getChecksumedAddress.d.ts +0 -7
  71. package/lib/helpers/getChecksumedAddress.js +0 -17
  72. package/lib/helpers/index.js +0 -20
  73. package/lib/helpers/isZeroAddressOrUnset.js +0 -14
  74. package/lib/helpers/locale.d.ts +0 -36
  75. package/lib/helpers/locale.js +0 -86
  76. package/lib/holding/Holding.d.ts +0 -60
  77. package/lib/holding/Holding.js +0 -31
  78. package/lib/holding/index.js +0 -17
  79. package/lib/index.d.ts +0 -33
  80. package/lib/index.js +0 -62
  81. package/lib/market/Market.d.ts +0 -159
  82. package/lib/market/Market.js +0 -240
  83. package/lib/market/MarketConfig.d.ts +0 -44
  84. package/lib/market/MarketConfig.js +0 -56
  85. package/lib/market/MarketUtils.d.ts +0 -165
  86. package/lib/market/MarketUtils.js +0 -182
  87. package/lib/market/index.js +0 -19
  88. package/lib/maths/AdaptiveCurveIrmLib.d.ts +0 -37
  89. package/lib/maths/AdaptiveCurveIrmLib.js +0 -116
  90. package/lib/maths/MathLib.d.ts +0 -94
  91. package/lib/maths/MathLib.js +0 -153
  92. package/lib/maths/MathUtils.d.ts +0 -15
  93. package/lib/maths/MathUtils.js +0 -33
  94. package/lib/maths/SharesMath.d.ts +0 -12
  95. package/lib/maths/SharesMath.js +0 -22
  96. package/lib/maths/index.js +0 -20
  97. package/lib/notifications.d.ts +0 -98
  98. package/lib/notifications.js +0 -52
  99. package/lib/position/Position.d.ts +0 -118
  100. package/lib/position/Position.js +0 -145
  101. package/lib/position/index.js +0 -17
  102. package/lib/signatures/index.d.ts +0 -12
  103. package/lib/signatures/index.js +0 -39
  104. package/lib/signatures/manager.d.ts +0 -10
  105. package/lib/signatures/manager.js +0 -37
  106. package/lib/signatures/permit.d.ts +0 -21
  107. package/lib/signatures/permit.js +0 -101
  108. package/lib/signatures/permit2.d.ts +0 -20
  109. package/lib/signatures/permit2.js +0 -91
  110. package/lib/signatures/types.d.ts +0 -13
  111. package/lib/signatures/types.js +0 -2
  112. package/lib/signatures/utils.d.ts +0 -6
  113. package/lib/signatures/utils.js +0 -44
  114. package/lib/tests/mocks/markets.d.ts +0 -17
  115. package/lib/tests/mocks/markets.js +0 -108
  116. package/lib/token/ERC20Metadata.d.ts +0 -249
  117. package/lib/token/ERC20Metadata.js +0 -81
  118. package/lib/token/Token.d.ts +0 -45
  119. package/lib/token/Token.js +0 -39
  120. package/lib/token/TokenNamespace.d.ts +0 -18
  121. package/lib/token/TokenNamespace.js +0 -55
  122. package/lib/token/WrappedToken.d.ts +0 -42
  123. package/lib/token/WrappedToken.js +0 -87
  124. package/lib/token/index.js +0 -18
  125. package/lib/types.d.ts +0 -29
  126. package/lib/types.js +0 -23
  127. package/lib/user/User.d.ts +0 -20
  128. package/lib/user/User.js +0 -11
  129. package/lib/user/index.js +0 -18
  130. package/lib/user/user.types.d.ts +0 -18
  131. package/lib/user/user.types.js +0 -2
  132. package/lib/vault/Vault.d.ts +0 -167
  133. package/lib/vault/Vault.js +0 -156
  134. package/lib/vault/VaultAllocation.d.ts +0 -38
  135. package/lib/vault/VaultAllocation.js +0 -18
  136. package/lib/vault/VaultConfig.d.ts +0 -23
  137. package/lib/vault/VaultConfig.js +0 -26
  138. package/lib/vault/VaultUtils.d.ts +0 -17
  139. package/lib/vault/VaultUtils.js +0 -17
  140. package/lib/vault/index.js +0 -20
  141. /package/{lib/chain/index.d.ts → src/chain/index.ts} +0 -0
  142. /package/{lib/ethers/index.d.ts → src/ethers/index.ts} +0 -0
  143. /package/{lib/helpers/format/index.d.ts → src/helpers/format/index.ts} +0 -0
  144. /package/{lib/helpers/index.d.ts → src/helpers/index.ts} +0 -0
  145. /package/{lib/holding/index.d.ts → src/holding/index.ts} +0 -0
  146. /package/{lib/market/index.d.ts → src/market/index.ts} +0 -0
  147. /package/{lib/maths/index.d.ts → src/maths/index.ts} +0 -0
  148. /package/{lib/position/index.d.ts → src/position/index.ts} +0 -0
  149. /package/{lib/token/index.d.ts → src/token/index.ts} +0 -0
  150. /package/{lib/user/index.d.ts → src/user/index.ts} +0 -0
  151. /package/{lib/vault/index.d.ts → src/vault/index.ts} +0 -0
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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;
@@ -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,17 +0,0 @@
1
- import { MarketConfig } from "../../market";
2
- export declare const MAINNET_MARKETS: {
3
- eth_wstEth: MarketConfig;
4
- eth_rEth: MarketConfig;
5
- usdt_wbtc: MarketConfig;
6
- usdt_wstEth: MarketConfig;
7
- usdc_wbtc: MarketConfig;
8
- usdc_wstEth: MarketConfig;
9
- usdc_sDai: MarketConfig;
10
- idle_usdc: MarketConfig;
11
- crvUsd_stkcvxcrvUSDTWBTCWETH: MarketConfig;
12
- crvUsd_stkcvxcrvUSDCWBTCWETH: MarketConfig;
13
- crvUsd_stkcvxcrvCRVUSDTBTCWSTETH: MarketConfig;
14
- crvUsd_stkcvxTryLSD: MarketConfig;
15
- crvUsd_stkcvxcrvUSDETHCRV: MarketConfig;
16
- usda_re7Eth: MarketConfig;
17
- };
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAINNET_MARKETS = void 0;
4
- const ethers_1 = require("ethers");
5
- const market_1 = require("../../market");
6
- exports.MAINNET_MARKETS = {
7
- eth_wstEth: new market_1.MarketConfig({
8
- loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
9
- collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
10
- oracle: "0x2a01EB9496094dA03c4E364Def50f5aD1280AD72",
11
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
12
- lltv: (0, ethers_1.parseUnits)("0.945"),
13
- }),
14
- eth_rEth: new market_1.MarketConfig({
15
- loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
16
- collateralToken: "0xae78736Cd615f374D3085123A210448E74Fc6393",
17
- oracle: "0x1b4A3F92e5Fffd1d35A98751c9FE4472483579bB",
18
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
19
- lltv: (0, ethers_1.parseUnits)("0.945"),
20
- }),
21
- usdt_wbtc: new market_1.MarketConfig({
22
- loanToken: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
23
- collateralToken: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
24
- oracle: "0x008bF4B1cDA0cc9f0e882E0697f036667652E1ef",
25
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
26
- lltv: (0, ethers_1.parseUnits)("0.86"),
27
- }),
28
- usdt_wstEth: new market_1.MarketConfig({
29
- loanToken: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
30
- collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
31
- oracle: "0x95DB30fAb9A3754e42423000DF27732CB2396992",
32
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
33
- lltv: (0, ethers_1.parseUnits)("0.86"),
34
- }),
35
- usdc_wbtc: new market_1.MarketConfig({
36
- // USDC(wBTC, 86%, Chainlink, AdaptiveCurve)
37
- loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
38
- collateralToken: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
39
- oracle: "0xDddd770BADd886dF3864029e4B377B5F6a2B6b83",
40
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
41
- lltv: (0, ethers_1.parseUnits)("0.86"),
42
- }),
43
- usdc_wstEth: new market_1.MarketConfig({
44
- // USDC(wstETH, 86%, Chainlink, AdaptiveCurve)
45
- loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
46
- collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
47
- oracle: "0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2",
48
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
49
- lltv: (0, ethers_1.parseUnits)("0.86"),
50
- }),
51
- usdc_sDai: new market_1.MarketConfig({
52
- // USDC(wstETH, 86%, Chainlink, AdaptiveCurve)
53
- loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
54
- collateralToken: "0x83F20F44975D03b1b09e64809B757c47f942BEeA",
55
- oracle: "0x6CAFE228eC0B0bC2D076577d56D35Fe704318f6d",
56
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
57
- lltv: (0, ethers_1.parseUnits)("0.965"),
58
- }),
59
- idle_usdc: new market_1.MarketConfig({
60
- loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
61
- collateralToken: ethers_1.ZeroAddress,
62
- oracle: ethers_1.ZeroAddress,
63
- irm: ethers_1.ZeroAddress,
64
- lltv: 0n,
65
- }),
66
- crvUsd_stkcvxcrvUSDTWBTCWETH: new market_1.MarketConfig({
67
- collateralToken: "0xb0Ce26C88e4e7DCa51968b6047f44646f5064278",
68
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
69
- lltv: (0, ethers_1.parseUnits)("0.86"),
70
- loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
71
- oracle: "0x077Af6c2D4A75D4145d141F9e9421864C3940CB3",
72
- }),
73
- crvUsd_stkcvxcrvUSDCWBTCWETH: new market_1.MarketConfig({
74
- collateralToken: "0x0ea1a65A2c255f24Ee8D81eA6AaC54Decd9d269e",
75
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
76
- lltv: (0, ethers_1.parseUnits)("0.86"),
77
- loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
78
- oracle: "0xd2F7C3B2fC97cC7b6AfDd76D163394680EFc35b9",
79
- }),
80
- crvUsd_stkcvxcrvCRVUSDTBTCWSTETH: new market_1.MarketConfig({
81
- collateralToken: "0x3ce8Ec9f3d89aD0A2DdbCC3FDB8991BD241Fc82E",
82
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
83
- lltv: (0, ethers_1.parseUnits)("0.86"),
84
- loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
85
- oracle: "0xa9f7900476F43C45Ebf56cEa669B9c960C176112",
86
- }),
87
- crvUsd_stkcvxTryLSD: new market_1.MarketConfig({
88
- collateralToken: "0x6BA072F0d22806F2C52e9792AF47f2D59103BEBE",
89
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
90
- lltv: (0, ethers_1.parseUnits)("0.86"),
91
- loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
92
- oracle: "0x18B0d7311a97c5377445C80c768ab5201Bb27B5a",
93
- }),
94
- crvUsd_stkcvxcrvUSDETHCRV: new market_1.MarketConfig({
95
- collateralToken: "0xAc904BAfBb5FB04Deb2b6198FdCEedE75a78Ce5a",
96
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
97
- lltv: (0, ethers_1.parseUnits)("0.86"),
98
- loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
99
- oracle: "0xad7e157815df05029125B568E39d5402550d60bb",
100
- }),
101
- usda_re7Eth: new market_1.MarketConfig({
102
- collateralToken: "0x78Fc2c2eD1A4cDb5402365934aE5648aDAd094d0",
103
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
104
- lltv: (0, ethers_1.parseUnits)("0.86"),
105
- loanToken: "0x0000206329b97DB379d5E1Bf586BbDB969C63274",
106
- oracle: "0x76052A2A28fDCB8124f4686C63C68355b142de3B",
107
- }),
108
- };
@@ -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("@morpho-org/blue-sdk/src/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,45 +0,0 @@
1
- import { BigNumberish } from "ethers";
2
- import { RoundingDirection } from "../maths";
3
- import { Address } from "../types";
4
- export interface InputToken {
5
- address: Address;
6
- decimals: number;
7
- symbol: string;
8
- name?: string;
9
- }
10
- export declare class Token implements InputToken {
11
- /**
12
- * The token's address.
13
- */
14
- readonly address: Address;
15
- /**
16
- * The token's number of decimals.
17
- */
18
- readonly decimals: number;
19
- /**
20
- * The token's symbol.
21
- */
22
- readonly symbol: string;
23
- /**
24
- * The name of the token (defaults to the symbol).
25
- */
26
- readonly name: string;
27
- constructor({ address, decimals, symbol, name }: InputToken);
28
- }
29
- export declare class TokenWithPrice extends Token {
30
- /**
31
- * Price of the token in USD (scaled by WAD).
32
- */
33
- price?: bigint;
34
- constructor(token: InputToken, price?: bigint);
35
- /**
36
- * Quotes an amount in USD (scaled by WAD) in this token.
37
- * @param amount The amount of USD to quote.
38
- */
39
- fromUsd(amount: BigNumberish, rounding?: RoundingDirection): bigint | null;
40
- /**
41
- * Quotes an amount of tokens in USD (scaled by WAD).
42
- * @param amount The amount of tokens to quote.
43
- */
44
- toUsd(amount: BigNumberish, rounding?: RoundingDirection): bigint | null;
45
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenWithPrice = exports.Token = void 0;
4
- const ethers_1 = require("ethers");
5
- const maths_1 = require("../maths");
6
- class Token {
7
- constructor({ address, decimals, symbol, name }) {
8
- this.address = address;
9
- this.decimals = decimals;
10
- this.symbol = symbol;
11
- this.name = name ?? symbol;
12
- }
13
- }
14
- exports.Token = Token;
15
- class TokenWithPrice extends Token {
16
- constructor(token, price) {
17
- super(token);
18
- this.price = price;
19
- }
20
- /**
21
- * Quotes an amount in USD (scaled by WAD) in this token.
22
- * @param amount The amount of USD to quote.
23
- */
24
- fromUsd(amount, rounding = "Down") {
25
- if (this.price == null)
26
- return null;
27
- return maths_1.MathLib.mulDiv(amount, (0, ethers_1.parseUnits)("1", this.decimals), this.price, rounding);
28
- }
29
- /**
30
- * Quotes an amount of tokens in USD (scaled by WAD).
31
- * @param amount The amount of tokens to quote.
32
- */
33
- toUsd(amount, rounding = "Down") {
34
- if (this.price == null)
35
- return null;
36
- return maths_1.MathLib.mulDiv(amount, this.price, (0, ethers_1.parseUnits)("1", this.decimals), rounding);
37
- }
38
- }
39
- exports.TokenWithPrice = TokenWithPrice;
@@ -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 = {}));