@morpho-org/blue-sdk 1.0.6 → 1.2.1
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 +6 -11
- 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
package/lib/evm.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signMessage = exports.signMessageWithProducer = exports.sendTransaction = exports.sendTransactionWithProducer = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const maths_1 = require("./maths");
|
|
6
|
-
const notifications_1 = require("./notifications");
|
|
7
|
-
const signatures_1 = require("./signatures");
|
|
8
|
-
/**
|
|
9
|
-
* Sends a transaction via the provided signer, optionnally waiting for the corresponding transaction receipt.
|
|
10
|
-
* @param signer The signer to send the tx with.
|
|
11
|
-
* @param tx The transaction request.
|
|
12
|
-
* @param wait Whether to wait for the transaction receipt. Defaults to true.
|
|
13
|
-
* @param notificationOptions The optional notification options. Warning: if `wait` is set to true, the provided topic will never complete.
|
|
14
|
-
*/
|
|
15
|
-
const sendTransactionWithProducer = async (signer, req, defaultGasLimit, confirms = 1, notificationOptions) => {
|
|
16
|
-
let response;
|
|
17
|
-
try {
|
|
18
|
-
let gasLimit;
|
|
19
|
-
try {
|
|
20
|
-
gasLimit = maths_1.MathLib.wMulUp(await signer.estimateGas(req), (0, ethers_1.parseUnits)("1.1"));
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
if (defaultGasLimit == null)
|
|
24
|
-
throw error;
|
|
25
|
-
gasLimit = defaultGasLimit;
|
|
26
|
-
}
|
|
27
|
-
const tx = { ...req, gasLimit };
|
|
28
|
-
notificationOptions?.producer.next({
|
|
29
|
-
id: notificationOptions.id,
|
|
30
|
-
status: notifications_1.NotificationStatus.signing,
|
|
31
|
-
context: { tx },
|
|
32
|
-
});
|
|
33
|
-
response = await signer.sendTransaction(tx);
|
|
34
|
-
notificationOptions?.producer.next({
|
|
35
|
-
id: notificationOptions.id,
|
|
36
|
-
status: notifications_1.NotificationStatus.pending,
|
|
37
|
-
context: { args: notificationOptions.args, tx, response },
|
|
38
|
-
});
|
|
39
|
-
const receipt = await response.wait(confirms);
|
|
40
|
-
notificationOptions?.producer.next({
|
|
41
|
-
id: notificationOptions.id,
|
|
42
|
-
status: notifications_1.NotificationStatus.success,
|
|
43
|
-
context: { args: notificationOptions.args, tx, response, receipt },
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
notificationOptions?.producer.next({
|
|
48
|
-
id: notificationOptions.id,
|
|
49
|
-
status: notifications_1.NotificationStatus.error,
|
|
50
|
-
context: { args: notificationOptions.args, tx: req, response, error },
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.sendTransactionWithProducer = sendTransactionWithProducer;
|
|
55
|
-
/**
|
|
56
|
-
* Sends a transaction via the provided signer, optionnally waiting for the corresponding transaction receipt.
|
|
57
|
-
* @param signer The signer to send the tx with.
|
|
58
|
-
* @param tx The transaction request.
|
|
59
|
-
* @param wait Whether to wait for the transaction receipt. Defaults to true.
|
|
60
|
-
* @param topic The type of notifications to emit.
|
|
61
|
-
* @param args The optional notification arguments.
|
|
62
|
-
* @return The notification consumer which receives the transaction notifications.
|
|
63
|
-
*/
|
|
64
|
-
const sendTransaction = (signer, tx, defaultGasLimit, confirms, args = {}) => {
|
|
65
|
-
const producer = new notifications_1.NotificationProducer(notifications_1.NotificationTopic.tx);
|
|
66
|
-
(0, exports.sendTransactionWithProducer)(signer, tx, defaultGasLimit, confirms, {
|
|
67
|
-
producer,
|
|
68
|
-
id: Date.now().toString(),
|
|
69
|
-
args,
|
|
70
|
-
});
|
|
71
|
-
return producer.consumer;
|
|
72
|
-
};
|
|
73
|
-
exports.sendTransaction = sendTransaction;
|
|
74
|
-
const signMessageWithProducer = async (signer, message, notificationOptions) => {
|
|
75
|
-
notificationOptions?.producer.next({
|
|
76
|
-
id: notificationOptions.id,
|
|
77
|
-
status: notifications_1.NotificationStatus.signing,
|
|
78
|
-
});
|
|
79
|
-
try {
|
|
80
|
-
const signature = await signatures_1.SignatureUtils.safeSignTypedData(signer, message.data.domain, message.data.types, message.data.value);
|
|
81
|
-
signatures_1.SignatureUtils.verifySignature(signature, message.hash, await signer.getAddress());
|
|
82
|
-
notificationOptions?.producer.next({
|
|
83
|
-
id: notificationOptions.id,
|
|
84
|
-
status: notifications_1.NotificationStatus.success,
|
|
85
|
-
context: { message, args: notificationOptions.args, signature },
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
notificationOptions?.producer.next({
|
|
90
|
-
id: notificationOptions.id,
|
|
91
|
-
status: notifications_1.NotificationStatus.error,
|
|
92
|
-
context: { message, args: notificationOptions.args, error },
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
exports.signMessageWithProducer = signMessageWithProducer;
|
|
97
|
-
/**
|
|
98
|
-
* Sends a signature request to the provided signer.
|
|
99
|
-
* @param signer The signer to send the approval with.
|
|
100
|
-
* @param args The approval parameters.
|
|
101
|
-
* @param encodeMessage The approval encoder to pass the approval parameters to get the approval transactions.
|
|
102
|
-
* @return The notification consumer which receives the transaction notifications.
|
|
103
|
-
*/
|
|
104
|
-
const signMessage = (signer, args, encodeMessage, chainId) => {
|
|
105
|
-
const producer = new notifications_1.NotificationProducer(notifications_1.NotificationTopic.signature);
|
|
106
|
-
(0, exports.signMessageWithProducer)(signer, encodeMessage(args, chainId), {
|
|
107
|
-
producer,
|
|
108
|
-
id: Date.now().toString(),
|
|
109
|
-
args,
|
|
110
|
-
});
|
|
111
|
-
return producer.consumer;
|
|
112
|
-
};
|
|
113
|
-
exports.signMessage = signMessage;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getChecksumedAddress = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
/**
|
|
6
|
-
* Transform an AddressLike into a checksumed address
|
|
7
|
-
*
|
|
8
|
-
* @param address Address to transform
|
|
9
|
-
*/
|
|
10
|
-
const getChecksumedAddress = async (address) => {
|
|
11
|
-
const awaited = await address;
|
|
12
|
-
// Ethers getAddress function is throwing an error if the address is already checksumed
|
|
13
|
-
if (typeof awaited === "string")
|
|
14
|
-
return (0, ethers_1.getAddress)(awaited.toLowerCase());
|
|
15
|
-
return (0, ethers_1.getAddress)((await awaited.getAddress()).toLowerCase());
|
|
16
|
-
};
|
|
17
|
-
exports.getChecksumedAddress = getChecksumedAddress;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if an address is the zero address, null, or undefined.
|
|
3
|
-
*
|
|
4
|
-
* @param address - The address to check, which can be a valid address, null, or undefined.
|
|
5
|
-
* @returns True if the address is zero, null, or undefined; otherwise, false.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isZeroAddressOrUnset(address: string | null | undefined): boolean;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isZeroAddressOrUnset = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
/**
|
|
6
|
-
* Check if an address is the zero address, null, or undefined.
|
|
7
|
-
*
|
|
8
|
-
* @param address - The address to check, which can be a valid address, null, or undefined.
|
|
9
|
-
* @returns True if the address is zero, null, or undefined; otherwise, false.
|
|
10
|
-
*/
|
|
11
|
-
function isZeroAddressOrUnset(address) {
|
|
12
|
-
return address === undefined || address === null || address === ethers_1.ZeroAddress;
|
|
13
|
-
}
|
|
14
|
-
exports.isZeroAddressOrUnset = isZeroAddressOrUnset;
|
package/lib/maths/MathUtils.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Math utilities
|
|
3
|
-
* This library reproduces the behaviour of the solidity library MathUtils
|
|
4
|
-
* TODO: add library link
|
|
5
|
-
* @category Maths
|
|
6
|
-
*/
|
|
7
|
-
export declare class MathUtils {
|
|
8
|
-
static zeroFloorSub(a: bigint, b: bigint): bigint;
|
|
9
|
-
static min(a: bigint, b: bigint): bigint;
|
|
10
|
-
static mins(...args: bigint[]): bigint;
|
|
11
|
-
static max(a: bigint, b: bigint): bigint;
|
|
12
|
-
static pos(a: bigint): bigint;
|
|
13
|
-
static neg(a: bigint): bigint;
|
|
14
|
-
static abs(a: bigint): bigint;
|
|
15
|
-
}
|
package/lib/maths/MathUtils.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MathUtils = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Math utilities
|
|
6
|
-
* This library reproduces the behaviour of the solidity library MathUtils
|
|
7
|
-
* TODO: add library link
|
|
8
|
-
* @category Maths
|
|
9
|
-
*/
|
|
10
|
-
class MathUtils {
|
|
11
|
-
static zeroFloorSub(a, b) {
|
|
12
|
-
return a - b < 0n ? 0n : a - b;
|
|
13
|
-
}
|
|
14
|
-
static min(a, b) {
|
|
15
|
-
return a < b ? a : b;
|
|
16
|
-
}
|
|
17
|
-
static mins(...args) {
|
|
18
|
-
return args.reduce((a, b) => this.min(a, b));
|
|
19
|
-
}
|
|
20
|
-
static max(a, b) {
|
|
21
|
-
return a > b ? a : b;
|
|
22
|
-
}
|
|
23
|
-
static pos(a) {
|
|
24
|
-
return a >= 0n ? a : 0n;
|
|
25
|
-
}
|
|
26
|
-
static neg(a) {
|
|
27
|
-
return a < 0n ? -a : 0n;
|
|
28
|
-
}
|
|
29
|
-
static abs(a) {
|
|
30
|
-
return a >= 0 ? a : -a;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.MathUtils = MathUtils;
|
package/lib/notifications.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Signature, TransactionReceipt, TransactionRequest, TransactionResponse } from "ethers";
|
|
2
|
-
import { Observable, Observer, ReplaySubject } from "rxjs";
|
|
3
|
-
import { SignatureMessage } from "./signatures/types";
|
|
4
|
-
export declare enum NotificationStatus {
|
|
5
|
-
signing = "signing",
|
|
6
|
-
success = "success",
|
|
7
|
-
error = "error",
|
|
8
|
-
pending = "pending"
|
|
9
|
-
}
|
|
10
|
-
export declare enum NotificationTopic {
|
|
11
|
-
tx = "tx",
|
|
12
|
-
signature = "signature"
|
|
13
|
-
}
|
|
14
|
-
export interface NotificationContext {
|
|
15
|
-
[NotificationTopic.tx]: {
|
|
16
|
-
[NotificationStatus.signing]: {
|
|
17
|
-
tx: TransactionRequest;
|
|
18
|
-
};
|
|
19
|
-
[NotificationStatus.pending]: {
|
|
20
|
-
args: Record<PropertyKey, any>;
|
|
21
|
-
tx: TransactionRequest;
|
|
22
|
-
response?: TransactionResponse;
|
|
23
|
-
};
|
|
24
|
-
[NotificationStatus.success]: {
|
|
25
|
-
args: Record<PropertyKey, any>;
|
|
26
|
-
tx: TransactionRequest;
|
|
27
|
-
response?: TransactionResponse;
|
|
28
|
-
receipt: TransactionReceipt | null;
|
|
29
|
-
};
|
|
30
|
-
[NotificationStatus.error]: {
|
|
31
|
-
args: Record<PropertyKey, any>;
|
|
32
|
-
tx: TransactionRequest;
|
|
33
|
-
response?: TransactionResponse;
|
|
34
|
-
error: Error;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
[NotificationTopic.signature]: {
|
|
38
|
-
[NotificationStatus.signing]: never;
|
|
39
|
-
[NotificationStatus.pending]: {
|
|
40
|
-
message: SignatureMessage;
|
|
41
|
-
args: Record<PropertyKey, any>;
|
|
42
|
-
};
|
|
43
|
-
[NotificationStatus.success]: {
|
|
44
|
-
message: SignatureMessage;
|
|
45
|
-
args: Record<PropertyKey, any>;
|
|
46
|
-
signature: Signature;
|
|
47
|
-
};
|
|
48
|
-
[NotificationStatus.error]: {
|
|
49
|
-
message: SignatureMessage;
|
|
50
|
-
args: Record<PropertyKey, any>;
|
|
51
|
-
error: Error;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export interface NotificationBody<Topic extends NotificationTopic = NotificationTopic, Status extends NotificationStatus = NotificationStatus> {
|
|
56
|
-
id: string;
|
|
57
|
-
topic: Topic;
|
|
58
|
-
status: Status;
|
|
59
|
-
}
|
|
60
|
-
export type Notifications = {
|
|
61
|
-
[Topic in NotificationTopic]: {
|
|
62
|
-
[Status in NotificationStatus]: NotificationBody<Topic, Status> & (NotificationContext[Topic][Status] extends never ? unknown : {
|
|
63
|
-
context: NotificationContext[Topic][Status];
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
export type TxNotification = Notifications[NotificationTopic.tx][NotificationStatus];
|
|
68
|
-
export type SignatureNotification = Notifications[NotificationTopic.signature][NotificationStatus];
|
|
69
|
-
export type Notification = Notifications[NotificationTopic][NotificationStatus];
|
|
70
|
-
export type NotificationsWithoutTopic = {
|
|
71
|
-
[Topic in NotificationTopic]: {
|
|
72
|
-
[Status in NotificationStatus]: Omit<NotificationBody<Topic, Status>, "topic"> & (NotificationContext[Topic][Status] extends never ? unknown : {
|
|
73
|
-
context: NotificationContext[Topic][Status];
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
export interface NotificationConsumer<Topic extends NotificationTopic> {
|
|
78
|
-
notifications$: Observable<Notifications[Topic][NotificationStatus]>;
|
|
79
|
-
wait: (observerOrNext?: Partial<Observer<Notifications[Topic][NotificationStatus]>> | ((value: Notifications[Topic][NotificationStatus]) => void)) => Promise<Notifications[Topic][NotificationStatus.success | NotificationStatus.error]>;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* MUST receive a success or error notification at some point to ensure the result promise resolves.
|
|
83
|
-
*/
|
|
84
|
-
export declare class NotificationProducer<Topic extends NotificationTopic> {
|
|
85
|
-
readonly topic: Topic;
|
|
86
|
-
protected readonly _notifications$: ReplaySubject<Notifications[Topic][NotificationStatus]>;
|
|
87
|
-
readonly notifications$: Observable<Notifications[Topic][NotificationStatus]>;
|
|
88
|
-
protected readonly _result: Promise<Notifications[Topic][NotificationStatus]>;
|
|
89
|
-
readonly consumer: NotificationConsumer<Topic>;
|
|
90
|
-
/**
|
|
91
|
-
* Creates a notification producer.
|
|
92
|
-
* MUST receive a success or error notification at some point to ensure the result promise resolves.
|
|
93
|
-
* @param topic The notification topic to populate each notification with.
|
|
94
|
-
*/
|
|
95
|
-
constructor(topic: Topic);
|
|
96
|
-
wait(observerOrNext?: Partial<Observer<Notifications[Topic][NotificationStatus]>> | ((value: Notifications[Topic][NotificationStatus]) => void)): Promise<Notifications[Topic][NotificationStatus.success | NotificationStatus.error]>;
|
|
97
|
-
next(notification: NotificationsWithoutTopic[Topic][NotificationStatus]): void;
|
|
98
|
-
}
|
package/lib/notifications.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotificationProducer = exports.NotificationTopic = exports.NotificationStatus = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
var NotificationStatus;
|
|
6
|
-
(function (NotificationStatus) {
|
|
7
|
-
NotificationStatus["signing"] = "signing";
|
|
8
|
-
NotificationStatus["success"] = "success";
|
|
9
|
-
NotificationStatus["error"] = "error";
|
|
10
|
-
NotificationStatus["pending"] = "pending";
|
|
11
|
-
})(NotificationStatus || (exports.NotificationStatus = NotificationStatus = {}));
|
|
12
|
-
var NotificationTopic;
|
|
13
|
-
(function (NotificationTopic) {
|
|
14
|
-
NotificationTopic["tx"] = "tx";
|
|
15
|
-
NotificationTopic["signature"] = "signature";
|
|
16
|
-
})(NotificationTopic || (exports.NotificationTopic = NotificationTopic = {}));
|
|
17
|
-
/**
|
|
18
|
-
* MUST receive a success or error notification at some point to ensure the result promise resolves.
|
|
19
|
-
*/
|
|
20
|
-
class NotificationProducer {
|
|
21
|
-
/**
|
|
22
|
-
* Creates a notification producer.
|
|
23
|
-
* MUST receive a success or error notification at some point to ensure the result promise resolves.
|
|
24
|
-
* @param topic The notification topic to populate each notification with.
|
|
25
|
-
*/
|
|
26
|
-
constructor(topic) {
|
|
27
|
-
this.topic = topic;
|
|
28
|
-
this._notifications$ = new rxjs_1.ReplaySubject(Infinity);
|
|
29
|
-
this.notifications$ = this._notifications$.asObservable();
|
|
30
|
-
this._result = (0, rxjs_1.lastValueFrom)(this._notifications$);
|
|
31
|
-
this.consumer = {
|
|
32
|
-
notifications$: this.notifications$,
|
|
33
|
-
wait: this.wait.bind(this),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async wait(observerOrNext) {
|
|
37
|
-
const subscription = this.notifications$.subscribe(observerOrNext);
|
|
38
|
-
const notification = (await this._result);
|
|
39
|
-
subscription.unsubscribe();
|
|
40
|
-
return notification;
|
|
41
|
-
}
|
|
42
|
-
next(notification) {
|
|
43
|
-
this._notifications$.next({
|
|
44
|
-
...notification,
|
|
45
|
-
topic: this.topic,
|
|
46
|
-
});
|
|
47
|
-
if (notification.status === NotificationStatus.success ||
|
|
48
|
-
notification.status === NotificationStatus.error)
|
|
49
|
-
this._notifications$.complete();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.NotificationProducer = NotificationProducer;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as _Manager from "./manager";
|
|
2
|
-
import * as _Permit from "./permit";
|
|
3
|
-
import * as _Permit2 from "./permit2";
|
|
4
|
-
import { safeSignTypedData as _safeSignTypedData, verifySignature as _verifySignature, getMessage as _getMessage } from "./utils";
|
|
5
|
-
export declare namespace SignatureUtils {
|
|
6
|
-
export import Permit = _Permit;
|
|
7
|
-
export import Permit2 = _Permit2;
|
|
8
|
-
export import Manager = _Manager;
|
|
9
|
-
const safeSignTypedData: typeof _safeSignTypedData;
|
|
10
|
-
const verifySignature: typeof _verifySignature;
|
|
11
|
-
const getMessage: typeof _getMessage;
|
|
12
|
-
}
|
package/lib/signatures/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.SignatureUtils = void 0;
|
|
27
|
-
const _Manager = __importStar(require("./manager"));
|
|
28
|
-
const _Permit = __importStar(require("./permit"));
|
|
29
|
-
const _Permit2 = __importStar(require("./permit2"));
|
|
30
|
-
const utils_1 = require("./utils");
|
|
31
|
-
var SignatureUtils;
|
|
32
|
-
(function (SignatureUtils) {
|
|
33
|
-
SignatureUtils.Permit = _Permit;
|
|
34
|
-
SignatureUtils.Permit2 = _Permit2;
|
|
35
|
-
SignatureUtils.Manager = _Manager;
|
|
36
|
-
SignatureUtils.safeSignTypedData = utils_1.safeSignTypedData;
|
|
37
|
-
SignatureUtils.verifySignature = utils_1.verifySignature;
|
|
38
|
-
SignatureUtils.getMessage = utils_1.getMessage;
|
|
39
|
-
})(SignatureUtils || (exports.SignatureUtils = SignatureUtils = {}));
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ChainId } from "../chain";
|
|
2
|
-
import { SignatureMessage } from "./types";
|
|
3
|
-
export interface ManagerApprovalSignatureArgs {
|
|
4
|
-
authorizer: string;
|
|
5
|
-
authorized: string;
|
|
6
|
-
isAuthorized: boolean;
|
|
7
|
-
nonce: bigint;
|
|
8
|
-
deadline: bigint;
|
|
9
|
-
}
|
|
10
|
-
export declare const getManagerApprovalMessage: (args: ManagerApprovalSignatureArgs, chainId: ChainId) => SignatureMessage;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getManagerApprovalMessage = void 0;
|
|
4
|
-
const addresses_1 = require("../addresses");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
const getManagerApprovalMessage = (args, chainId) => {
|
|
7
|
-
const domain = {
|
|
8
|
-
chainId: chainId.toString(),
|
|
9
|
-
verifyingContract: (0, addresses_1.getChainAddresses)(chainId).morpho,
|
|
10
|
-
};
|
|
11
|
-
const types = {
|
|
12
|
-
Authorization: [
|
|
13
|
-
{
|
|
14
|
-
name: "authorizer",
|
|
15
|
-
type: "address",
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: "authorized",
|
|
19
|
-
type: "address",
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: "isAuthorized",
|
|
23
|
-
type: "bool",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "nonce",
|
|
27
|
-
type: "uint256",
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: "deadline",
|
|
31
|
-
type: "uint256",
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
return (0, utils_1.getMessage)(domain, types, args);
|
|
36
|
-
};
|
|
37
|
-
exports.getManagerApprovalMessage = getManagerApprovalMessage;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ChainId } from "../chain";
|
|
2
|
-
import { Token } from "../token";
|
|
3
|
-
import { Address } from "../types";
|
|
4
|
-
import { SignatureMessage } from "./types";
|
|
5
|
-
export interface PermitArgs {
|
|
6
|
-
erc20: Token;
|
|
7
|
-
owner: Address;
|
|
8
|
-
spender: Address;
|
|
9
|
-
allowance: bigint;
|
|
10
|
-
nonce: bigint;
|
|
11
|
-
deadline: bigint;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Permit signature for ERC20 tokens, following EIP-2612.
|
|
15
|
-
* Docs: https://eips.ethereum.org/EIPS/eip-2612
|
|
16
|
-
*/
|
|
17
|
-
export declare const getPermitMessage: ({ deadline, owner, nonce, spender, erc20, allowance }: PermitArgs, chainId: ChainId) => SignatureMessage;
|
|
18
|
-
export declare const WITH_SIMPLE_PERMIT: {
|
|
19
|
-
[id in ChainId]: (Address | undefined)[];
|
|
20
|
-
};
|
|
21
|
-
export declare const hasSimplePermit: (chainId: ChainId, address: Address) => boolean;
|
package/lib/signatures/permit.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasSimplePermit = exports.WITH_SIMPLE_PERMIT = exports.getPermitMessage = void 0;
|
|
4
|
-
const addresses_1 = require("../addresses");
|
|
5
|
-
const chain_1 = require("../chain");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
/**
|
|
8
|
-
* Permit signature for ERC20 tokens, following EIP-2612.
|
|
9
|
-
* Docs: https://eips.ethereum.org/EIPS/eip-2612
|
|
10
|
-
*/
|
|
11
|
-
const getPermitMessage = ({ deadline, owner, nonce, spender, erc20, allowance }, chainId) => {
|
|
12
|
-
const { usdc, dai } = (0, addresses_1.getChainAddresses)(chainId);
|
|
13
|
-
const domain = {
|
|
14
|
-
name: erc20.name,
|
|
15
|
-
version: erc20.address === usdc ? "2" : "1",
|
|
16
|
-
chainId: chainId.toString(),
|
|
17
|
-
verifyingContract: erc20.address,
|
|
18
|
-
};
|
|
19
|
-
if (erc20.address === dai)
|
|
20
|
-
return (0, utils_1.getMessage)(domain, {
|
|
21
|
-
Permit: [
|
|
22
|
-
{
|
|
23
|
-
name: "holder",
|
|
24
|
-
type: "address",
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: "spender",
|
|
28
|
-
type: "address",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "nonce",
|
|
32
|
-
type: "uint256",
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "expiry",
|
|
36
|
-
type: "uint256",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "allowed",
|
|
40
|
-
type: "bool",
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
}, {
|
|
44
|
-
holder: owner,
|
|
45
|
-
spender,
|
|
46
|
-
allowed: allowance > 0n,
|
|
47
|
-
nonce,
|
|
48
|
-
expiry: deadline,
|
|
49
|
-
});
|
|
50
|
-
const types = {
|
|
51
|
-
Permit: [
|
|
52
|
-
{
|
|
53
|
-
name: "owner",
|
|
54
|
-
type: "address",
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "spender",
|
|
58
|
-
type: "address",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: "value",
|
|
62
|
-
type: "uint256",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: "nonce",
|
|
66
|
-
type: "uint256",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: "deadline",
|
|
70
|
-
type: "uint256",
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
const value = {
|
|
75
|
-
owner,
|
|
76
|
-
spender,
|
|
77
|
-
value: allowance,
|
|
78
|
-
nonce,
|
|
79
|
-
deadline,
|
|
80
|
-
};
|
|
81
|
-
return (0, utils_1.getMessage)(domain, types, value);
|
|
82
|
-
};
|
|
83
|
-
exports.getPermitMessage = getPermitMessage;
|
|
84
|
-
exports.WITH_SIMPLE_PERMIT = {
|
|
85
|
-
[chain_1.ChainId.EthMainnet]: [
|
|
86
|
-
addresses_1.addresses[chain_1.ChainId.EthMainnet].wbIB01,
|
|
87
|
-
addresses_1.addresses[chain_1.ChainId.EthMainnet].wbC3M,
|
|
88
|
-
addresses_1.addresses[chain_1.ChainId.EthMainnet].wstEth,
|
|
89
|
-
addresses_1.addresses[chain_1.ChainId.EthMainnet].sDai,
|
|
90
|
-
addresses_1.addresses[chain_1.ChainId.EthMainnet].osEth,
|
|
91
|
-
addresses_1.addresses[chain_1.ChainId.EthMainnet].usdc,
|
|
92
|
-
addresses_1.addresses[chain_1.ChainId.EthMainnet].dai,
|
|
93
|
-
],
|
|
94
|
-
[chain_1.ChainId.EthGoerliTestnet]: [
|
|
95
|
-
"0x0aCd15Fb54034492c392596B56ED415bD07e70d7", // Fake DAI
|
|
96
|
-
"0xD8134205b0328F5676aaeFb3B2a0DC15f4029d8C", // Real sDAI
|
|
97
|
-
],
|
|
98
|
-
[chain_1.ChainId.BaseMainnet]: [addresses_1.addresses[chain_1.ChainId.BaseMainnet].usdc],
|
|
99
|
-
};
|
|
100
|
-
const hasSimplePermit = (chainId, address) => exports.WITH_SIMPLE_PERMIT[chainId]?.includes(address);
|
|
101
|
-
exports.hasSimplePermit = hasSimplePermit;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ChainId } from "../chain";
|
|
2
|
-
import { Address } from "../types";
|
|
3
|
-
import { SignatureMessage } from "./types";
|
|
4
|
-
export interface Permit2Args {
|
|
5
|
-
erc20: Address;
|
|
6
|
-
allowance: bigint;
|
|
7
|
-
nonce: bigint;
|
|
8
|
-
deadline: bigint;
|
|
9
|
-
spender: Address;
|
|
10
|
-
expiration?: bigint;
|
|
11
|
-
}
|
|
12
|
-
export interface Permit2TransferFromArgs {
|
|
13
|
-
erc20: Address;
|
|
14
|
-
allowance: bigint;
|
|
15
|
-
spender: Address;
|
|
16
|
-
nonce: bigint;
|
|
17
|
-
deadline: bigint;
|
|
18
|
-
}
|
|
19
|
-
export declare const getPermit2TransferFromMessage: (args: Permit2TransferFromArgs, chainId: ChainId) => SignatureMessage;
|
|
20
|
-
export declare const getPermit2Message: (args: Permit2Args, chainId: ChainId) => SignatureMessage;
|