@morpho-dev/router 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.d.cts +9 -84
- package/dist/index.browser.d.ts +9 -84
- package/dist/index.browser.js +17 -145
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +20 -147
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.cts +9 -84
- package/dist/index.node.d.ts +9 -84
- package/dist/index.node.js +17 -145
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +20 -147
- package/dist/index.node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.node.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export * from '@morpho-dev/mempool';
|
|
|
4
4
|
import * as node_modules_zod_openapi_dist_components_DkyUTLcs_js from 'node_modules/zod-openapi/dist/components-DkyUTLcs.js';
|
|
5
5
|
import { z, ZodError } from 'zod/v4';
|
|
6
6
|
import * as viem from 'viem';
|
|
7
|
-
import { Address, Hex
|
|
7
|
+
import { Address, Hex } from 'viem';
|
|
8
8
|
import * as hono_utils_types from 'hono/utils/types';
|
|
9
9
|
import * as hono from 'hono';
|
|
10
10
|
import { Context } from 'hono';
|
|
@@ -162,8 +162,8 @@ declare const consumedEvent: {
|
|
|
162
162
|
* @param input - The router offer to create.
|
|
163
163
|
* @returns The created router offer with its hash.
|
|
164
164
|
*/
|
|
165
|
-
declare function from
|
|
166
|
-
declare namespace from
|
|
165
|
+
declare function from(input: Omit<RouterOffer, "hash">): RouterOffer;
|
|
166
|
+
declare namespace from {
|
|
167
167
|
type ErrorType = InvalidRouterOfferError;
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
@@ -206,12 +206,13 @@ declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
|
|
|
206
206
|
type RouterOffer$1_RouterOffer = RouterOffer;
|
|
207
207
|
declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
|
|
208
208
|
declare const RouterOffer$1_consumedEvent: typeof consumedEvent;
|
|
209
|
+
declare const RouterOffer$1_from: typeof from;
|
|
209
210
|
declare const RouterOffer$1_fromConsumedLog: typeof fromConsumedLog;
|
|
210
211
|
declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
|
|
211
212
|
declare const RouterOffer$1_random: typeof random;
|
|
212
213
|
declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
|
|
213
214
|
declare namespace RouterOffer$1 {
|
|
214
|
-
export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferConsumed as OfferConsumed, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_consumedEvent as consumedEvent,
|
|
215
|
+
export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferConsumed as OfferConsumed, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_consumedEvent as consumedEvent, RouterOffer$1_from as from, RouterOffer$1_fromConsumedLog as fromConsumedLog, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
type OfferResponse = {
|
|
@@ -671,32 +672,6 @@ declare namespace Logger$1 {
|
|
|
671
672
|
export { type Logger$1_LogFn as LogFn, type Logger$1_LogLevel as LogLevel, Logger$1_LogLevelValues as LogLevelValues, type Logger$1_Logger as Logger, Logger$1_defaultLogger as defaultLogger, Logger$1_getLogger as getLogger, Logger$1_runWithLogger as runWithLogger, Logger$1_silentLogger as silentLogger };
|
|
672
673
|
}
|
|
673
674
|
|
|
674
|
-
declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
|
|
675
|
-
type Type = (typeof types)[number];
|
|
676
|
-
type BaseEvent<type extends Type = Type> = {
|
|
677
|
-
readonly id: string;
|
|
678
|
-
readonly type: type;
|
|
679
|
-
};
|
|
680
|
-
type RouterEvent<type extends Type = Type> = type extends "offer_consumed" ? Compute<BaseEvent<type> & {
|
|
681
|
-
readonly offerConsumed: OfferConsumed;
|
|
682
|
-
}> : type extends "offer_created" | "offer_validation" ? Compute<BaseEvent<type> & {
|
|
683
|
-
readonly offer: Offer.Offer;
|
|
684
|
-
}> : never;
|
|
685
|
-
/**
|
|
686
|
-
* Creates a RouterEvent with a deterministic id.
|
|
687
|
-
*/
|
|
688
|
-
declare function from<T extends Type = Type>(base: Omit<RouterEvent<T>, "id" | "type"> & {
|
|
689
|
-
type: T;
|
|
690
|
-
}): Compute<RouterEvent<T>>;
|
|
691
|
-
|
|
692
|
-
type RouterEvent$1_RouterEvent<type extends Type = Type> = RouterEvent<type>;
|
|
693
|
-
type RouterEvent$1_Type = Type;
|
|
694
|
-
declare const RouterEvent$1_from: typeof from;
|
|
695
|
-
declare const RouterEvent$1_types: typeof types;
|
|
696
|
-
declare namespace RouterEvent$1 {
|
|
697
|
-
export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_from as from, RouterEvent$1_types as types };
|
|
698
|
-
}
|
|
699
|
-
|
|
700
675
|
/**
|
|
701
676
|
* Splits an array into batches of a specified size.
|
|
702
677
|
* @param array The array to split.
|
|
@@ -798,11 +773,9 @@ declare function single<Name extends string, T, Ctx = void>(name: Name, run: Sin
|
|
|
798
773
|
*/
|
|
799
774
|
declare function batch<Name extends string, T, Ctx = void>(name: Name, run: Batch<T, Name, Ctx>): Rule<T, Name, Ctx>;
|
|
800
775
|
type MorphoContext = {
|
|
801
|
-
|
|
776
|
+
chain: Chain.Chain;
|
|
802
777
|
};
|
|
803
|
-
declare function morpho(
|
|
804
|
-
whitelistedChains: Chain.Chain[];
|
|
805
|
-
}): (Rule<{
|
|
778
|
+
declare function morpho(): (Rule<{
|
|
806
779
|
readonly offering: Address;
|
|
807
780
|
readonly assets: bigint;
|
|
808
781
|
readonly rate: bigint;
|
|
@@ -898,55 +871,7 @@ declare function morpho(parameters: {
|
|
|
898
871
|
readonly hash: viem.Hex;
|
|
899
872
|
signature?: viem.Hex;
|
|
900
873
|
createdAt?: number;
|
|
901
|
-
}, "empty_callback", MorphoContext>
|
|
902
|
-
readonly offering: Address;
|
|
903
|
-
readonly assets: bigint;
|
|
904
|
-
readonly rate: bigint;
|
|
905
|
-
readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
|
|
906
|
-
readonly expiry: number;
|
|
907
|
-
readonly nonce: bigint;
|
|
908
|
-
readonly buy: boolean;
|
|
909
|
-
readonly chainId: bigint;
|
|
910
|
-
readonly loanToken: Address;
|
|
911
|
-
readonly start: number;
|
|
912
|
-
readonly collaterals: readonly {
|
|
913
|
-
asset: Address;
|
|
914
|
-
oracle: Address;
|
|
915
|
-
lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
|
|
916
|
-
}[];
|
|
917
|
-
readonly callback: {
|
|
918
|
-
readonly address: Address;
|
|
919
|
-
readonly data: viem.Hex;
|
|
920
|
-
readonly gasLimit: bigint;
|
|
921
|
-
};
|
|
922
|
-
readonly hash: viem.Hex;
|
|
923
|
-
signature?: viem.Hex;
|
|
924
|
-
createdAt?: number;
|
|
925
|
-
}, "sell_offers_empty_callback", MorphoContext> | Rule<{
|
|
926
|
-
readonly offering: Address;
|
|
927
|
-
readonly assets: bigint;
|
|
928
|
-
readonly rate: bigint;
|
|
929
|
-
readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
|
|
930
|
-
readonly expiry: number;
|
|
931
|
-
readonly nonce: bigint;
|
|
932
|
-
readonly buy: boolean;
|
|
933
|
-
readonly chainId: bigint;
|
|
934
|
-
readonly loanToken: Address;
|
|
935
|
-
readonly start: number;
|
|
936
|
-
readonly collaterals: readonly {
|
|
937
|
-
asset: Address;
|
|
938
|
-
oracle: Address;
|
|
939
|
-
lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
|
|
940
|
-
}[];
|
|
941
|
-
readonly callback: {
|
|
942
|
-
readonly address: Address;
|
|
943
|
-
readonly data: viem.Hex;
|
|
944
|
-
readonly gasLimit: bigint;
|
|
945
|
-
};
|
|
946
|
-
readonly hash: viem.Hex;
|
|
947
|
-
signature?: viem.Hex;
|
|
948
|
-
createdAt?: number;
|
|
949
|
-
}, "buy_offers_empty_callback", MorphoContext>)[];
|
|
874
|
+
}, "empty_callback", MorphoContext>)[];
|
|
950
875
|
|
|
951
876
|
type ValidationRule_Batch<T, RuleName extends string, Ctx = void> = Batch<T, RuleName, Ctx>;
|
|
952
877
|
type ValidationRule_MorphoContext = MorphoContext;
|
|
@@ -1001,4 +926,4 @@ declare namespace Validation {
|
|
|
1001
926
|
export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
|
|
1002
927
|
}
|
|
1003
928
|
|
|
1004
|
-
export { index$3 as ApiSchema, Logger$1 as Logger, index$2 as OfferStore, index$1 as Router,
|
|
929
|
+
export { index$3 as ApiSchema, Logger$1 as Logger, index$2 as OfferStore, index$1 as Router, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
|
package/dist/index.node.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from '@morpho-dev/mempool';
|
|
|
4
4
|
import * as node_modules_zod_openapi_dist_components_DkyUTLcs_js from 'node_modules/zod-openapi/dist/components-DkyUTLcs.js';
|
|
5
5
|
import { z, ZodError } from 'zod/v4';
|
|
6
6
|
import * as viem from 'viem';
|
|
7
|
-
import { Address, Hex
|
|
7
|
+
import { Address, Hex } from 'viem';
|
|
8
8
|
import * as hono_utils_types from 'hono/utils/types';
|
|
9
9
|
import * as hono from 'hono';
|
|
10
10
|
import { Context } from 'hono';
|
|
@@ -162,8 +162,8 @@ declare const consumedEvent: {
|
|
|
162
162
|
* @param input - The router offer to create.
|
|
163
163
|
* @returns The created router offer with its hash.
|
|
164
164
|
*/
|
|
165
|
-
declare function from
|
|
166
|
-
declare namespace from
|
|
165
|
+
declare function from(input: Omit<RouterOffer, "hash">): RouterOffer;
|
|
166
|
+
declare namespace from {
|
|
167
167
|
type ErrorType = InvalidRouterOfferError;
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
@@ -206,12 +206,13 @@ declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
|
|
|
206
206
|
type RouterOffer$1_RouterOffer = RouterOffer;
|
|
207
207
|
declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
|
|
208
208
|
declare const RouterOffer$1_consumedEvent: typeof consumedEvent;
|
|
209
|
+
declare const RouterOffer$1_from: typeof from;
|
|
209
210
|
declare const RouterOffer$1_fromConsumedLog: typeof fromConsumedLog;
|
|
210
211
|
declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
|
|
211
212
|
declare const RouterOffer$1_random: typeof random;
|
|
212
213
|
declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
|
|
213
214
|
declare namespace RouterOffer$1 {
|
|
214
|
-
export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferConsumed as OfferConsumed, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_consumedEvent as consumedEvent,
|
|
215
|
+
export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferConsumed as OfferConsumed, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_consumedEvent as consumedEvent, RouterOffer$1_from as from, RouterOffer$1_fromConsumedLog as fromConsumedLog, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
type OfferResponse = {
|
|
@@ -671,32 +672,6 @@ declare namespace Logger$1 {
|
|
|
671
672
|
export { type Logger$1_LogFn as LogFn, type Logger$1_LogLevel as LogLevel, Logger$1_LogLevelValues as LogLevelValues, type Logger$1_Logger as Logger, Logger$1_defaultLogger as defaultLogger, Logger$1_getLogger as getLogger, Logger$1_runWithLogger as runWithLogger, Logger$1_silentLogger as silentLogger };
|
|
672
673
|
}
|
|
673
674
|
|
|
674
|
-
declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
|
|
675
|
-
type Type = (typeof types)[number];
|
|
676
|
-
type BaseEvent<type extends Type = Type> = {
|
|
677
|
-
readonly id: string;
|
|
678
|
-
readonly type: type;
|
|
679
|
-
};
|
|
680
|
-
type RouterEvent<type extends Type = Type> = type extends "offer_consumed" ? Compute<BaseEvent<type> & {
|
|
681
|
-
readonly offerConsumed: OfferConsumed;
|
|
682
|
-
}> : type extends "offer_created" | "offer_validation" ? Compute<BaseEvent<type> & {
|
|
683
|
-
readonly offer: Offer.Offer;
|
|
684
|
-
}> : never;
|
|
685
|
-
/**
|
|
686
|
-
* Creates a RouterEvent with a deterministic id.
|
|
687
|
-
*/
|
|
688
|
-
declare function from<T extends Type = Type>(base: Omit<RouterEvent<T>, "id" | "type"> & {
|
|
689
|
-
type: T;
|
|
690
|
-
}): Compute<RouterEvent<T>>;
|
|
691
|
-
|
|
692
|
-
type RouterEvent$1_RouterEvent<type extends Type = Type> = RouterEvent<type>;
|
|
693
|
-
type RouterEvent$1_Type = Type;
|
|
694
|
-
declare const RouterEvent$1_from: typeof from;
|
|
695
|
-
declare const RouterEvent$1_types: typeof types;
|
|
696
|
-
declare namespace RouterEvent$1 {
|
|
697
|
-
export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_from as from, RouterEvent$1_types as types };
|
|
698
|
-
}
|
|
699
|
-
|
|
700
675
|
/**
|
|
701
676
|
* Splits an array into batches of a specified size.
|
|
702
677
|
* @param array The array to split.
|
|
@@ -798,11 +773,9 @@ declare function single<Name extends string, T, Ctx = void>(name: Name, run: Sin
|
|
|
798
773
|
*/
|
|
799
774
|
declare function batch<Name extends string, T, Ctx = void>(name: Name, run: Batch<T, Name, Ctx>): Rule<T, Name, Ctx>;
|
|
800
775
|
type MorphoContext = {
|
|
801
|
-
|
|
776
|
+
chain: Chain.Chain;
|
|
802
777
|
};
|
|
803
|
-
declare function morpho(
|
|
804
|
-
whitelistedChains: Chain.Chain[];
|
|
805
|
-
}): (Rule<{
|
|
778
|
+
declare function morpho(): (Rule<{
|
|
806
779
|
readonly offering: Address;
|
|
807
780
|
readonly assets: bigint;
|
|
808
781
|
readonly rate: bigint;
|
|
@@ -898,55 +871,7 @@ declare function morpho(parameters: {
|
|
|
898
871
|
readonly hash: viem.Hex;
|
|
899
872
|
signature?: viem.Hex;
|
|
900
873
|
createdAt?: number;
|
|
901
|
-
}, "empty_callback", MorphoContext>
|
|
902
|
-
readonly offering: Address;
|
|
903
|
-
readonly assets: bigint;
|
|
904
|
-
readonly rate: bigint;
|
|
905
|
-
readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
|
|
906
|
-
readonly expiry: number;
|
|
907
|
-
readonly nonce: bigint;
|
|
908
|
-
readonly buy: boolean;
|
|
909
|
-
readonly chainId: bigint;
|
|
910
|
-
readonly loanToken: Address;
|
|
911
|
-
readonly start: number;
|
|
912
|
-
readonly collaterals: readonly {
|
|
913
|
-
asset: Address;
|
|
914
|
-
oracle: Address;
|
|
915
|
-
lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
|
|
916
|
-
}[];
|
|
917
|
-
readonly callback: {
|
|
918
|
-
readonly address: Address;
|
|
919
|
-
readonly data: viem.Hex;
|
|
920
|
-
readonly gasLimit: bigint;
|
|
921
|
-
};
|
|
922
|
-
readonly hash: viem.Hex;
|
|
923
|
-
signature?: viem.Hex;
|
|
924
|
-
createdAt?: number;
|
|
925
|
-
}, "sell_offers_empty_callback", MorphoContext> | Rule<{
|
|
926
|
-
readonly offering: Address;
|
|
927
|
-
readonly assets: bigint;
|
|
928
|
-
readonly rate: bigint;
|
|
929
|
-
readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
|
|
930
|
-
readonly expiry: number;
|
|
931
|
-
readonly nonce: bigint;
|
|
932
|
-
readonly buy: boolean;
|
|
933
|
-
readonly chainId: bigint;
|
|
934
|
-
readonly loanToken: Address;
|
|
935
|
-
readonly start: number;
|
|
936
|
-
readonly collaterals: readonly {
|
|
937
|
-
asset: Address;
|
|
938
|
-
oracle: Address;
|
|
939
|
-
lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
|
|
940
|
-
}[];
|
|
941
|
-
readonly callback: {
|
|
942
|
-
readonly address: Address;
|
|
943
|
-
readonly data: viem.Hex;
|
|
944
|
-
readonly gasLimit: bigint;
|
|
945
|
-
};
|
|
946
|
-
readonly hash: viem.Hex;
|
|
947
|
-
signature?: viem.Hex;
|
|
948
|
-
createdAt?: number;
|
|
949
|
-
}, "buy_offers_empty_callback", MorphoContext>)[];
|
|
874
|
+
}, "empty_callback", MorphoContext>)[];
|
|
950
875
|
|
|
951
876
|
type ValidationRule_Batch<T, RuleName extends string, Ctx = void> = Batch<T, RuleName, Ctx>;
|
|
952
877
|
type ValidationRule_MorphoContext = MorphoContext;
|
|
@@ -1001,4 +926,4 @@ declare namespace Validation {
|
|
|
1001
926
|
export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
|
|
1002
927
|
}
|
|
1003
928
|
|
|
1004
|
-
export { index$3 as ApiSchema, Logger$1 as Logger, index$2 as OfferStore, index$1 as Router,
|
|
929
|
+
export { index$3 as ApiSchema, Logger$1 as Logger, index$2 as OfferStore, index$1 as Router, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
|
package/dist/index.node.js
CHANGED
|
@@ -1622,18 +1622,6 @@ function getLogger() {
|
|
|
1622
1622
|
return loggerContext.getStore() ?? defaultLogger();
|
|
1623
1623
|
}
|
|
1624
1624
|
|
|
1625
|
-
// src/RouterEvent.ts
|
|
1626
|
-
var RouterEvent_exports = {};
|
|
1627
|
-
__export(RouterEvent_exports, {
|
|
1628
|
-
from: () => from2,
|
|
1629
|
-
types: () => types
|
|
1630
|
-
});
|
|
1631
|
-
var types = ["offer_created", "offer_consumed", "offer_validation"];
|
|
1632
|
-
function from2(base) {
|
|
1633
|
-
const id = base.type === "offer_consumed" ? `${base.type}:${base.offerConsumed.id}` : `${base.type}:${base.offer.hash.toLowerCase()}`;
|
|
1634
|
-
return { id, ...base };
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
1625
|
// src/Validation.ts
|
|
1638
1626
|
var Validation_exports = {};
|
|
1639
1627
|
__export(Validation_exports, {
|
|
@@ -1694,25 +1682,19 @@ function single(name, run2) {
|
|
|
1694
1682
|
function batch2(name, run2) {
|
|
1695
1683
|
return { kind: "batch", name, run: run2 };
|
|
1696
1684
|
}
|
|
1697
|
-
function morpho(
|
|
1698
|
-
const {
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
new Set(Array.from(chain.whitelistedAssets).map((a) => a.toLowerCase()))
|
|
1704
|
-
])
|
|
1705
|
-
);
|
|
1706
|
-
const morphoPerChain = new Map(
|
|
1707
|
-
whitelistedChains.map((chain) => [chain.id, chain.morpho.toLowerCase()])
|
|
1708
|
-
);
|
|
1709
|
-
const chainId = single("chain_id", (offer, _) => {
|
|
1710
|
-
if (!whitelistedChainIds.has(offer.chainId)) {
|
|
1711
|
-
return { message: `Chain ID ${offer.chainId} is not whitelisted` };
|
|
1685
|
+
function morpho() {
|
|
1686
|
+
const chainId = single("chain_id", (offer, { chain }) => {
|
|
1687
|
+
if (chain.id !== offer.chainId) {
|
|
1688
|
+
return {
|
|
1689
|
+
message: `Chain ID ${offer.chainId} is not the same as the chain ID in the context (${chain.id})`
|
|
1690
|
+
};
|
|
1712
1691
|
}
|
|
1713
1692
|
});
|
|
1714
|
-
const loanToken = single("loan_token", (offer,
|
|
1715
|
-
|
|
1693
|
+
const loanToken = single("loan_token", (offer, { chain }) => {
|
|
1694
|
+
const tokens = new Set(
|
|
1695
|
+
Array.from(chain.whitelistedAssets.values()).map((a) => a.toLowerCase())
|
|
1696
|
+
);
|
|
1697
|
+
if (!tokens.has(offer.loanToken.toLowerCase())) {
|
|
1716
1698
|
return {
|
|
1717
1699
|
message: `Loan token ${offer.loanToken} is not whitelisted on chain ${offer.chainId}`
|
|
1718
1700
|
};
|
|
@@ -1723,127 +1705,18 @@ function morpho(parameters) {
|
|
|
1723
1705
|
return { message: "Expiry mismatch" };
|
|
1724
1706
|
}
|
|
1725
1707
|
});
|
|
1726
|
-
const
|
|
1727
|
-
if (offer.callback.data !== "0x") {
|
|
1728
|
-
return { message: "Callback
|
|
1708
|
+
const callback = single("empty_callback", (offer, _) => {
|
|
1709
|
+
if (!offer.buy || offer.callback.data !== "0x") {
|
|
1710
|
+
return { message: "Callback not supported yet." };
|
|
1729
1711
|
}
|
|
1730
1712
|
});
|
|
1731
|
-
const sellOffersEmptyCallback = single(
|
|
1732
|
-
"sell_offers_empty_callback",
|
|
1733
|
-
(offer, _) => {
|
|
1734
|
-
if (!offer.buy && offer.callback.data === "0x") {
|
|
1735
|
-
return { message: "Sell offers with empty callback are not supported yet." };
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
);
|
|
1739
|
-
const buyOffersEmptyCallback = batch2(
|
|
1740
|
-
"buy_offers_empty_callback",
|
|
1741
|
-
async (offers, { publicClients }) => {
|
|
1742
|
-
const issues = /* @__PURE__ */ new Map();
|
|
1743
|
-
const hashToIndex = /* @__PURE__ */ new Map();
|
|
1744
|
-
for (let i = 0; i < offers.length; i++) {
|
|
1745
|
-
const offer = offers[i];
|
|
1746
|
-
hashToIndex.set(offer.hash, i);
|
|
1747
|
-
}
|
|
1748
|
-
const { buyOffers, sellOffers: _sellOffers } = offers.reduce(
|
|
1749
|
-
(acc, offer) => {
|
|
1750
|
-
offer.buy ? acc.buyOffers.push(offer) : issues.set(hashToIndex.get(offer.hash), {
|
|
1751
|
-
message: "Onchain callback for sell offers is not supported yet."
|
|
1752
|
-
});
|
|
1753
|
-
return acc;
|
|
1754
|
-
},
|
|
1755
|
-
{ buyOffers: [], sellOffers: [] }
|
|
1756
|
-
);
|
|
1757
|
-
const buyOffersPerLoanAsset = /* @__PURE__ */ new Map();
|
|
1758
|
-
for (const offer of buyOffers) {
|
|
1759
|
-
const chainName = mempool.Chain.getChain(offer.chainId)?.name;
|
|
1760
|
-
const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
|
|
1761
|
-
const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
|
|
1762
|
-
offers2.push(offer);
|
|
1763
|
-
loanTokens.set(offer.loanToken.toLowerCase(), offers2);
|
|
1764
|
-
buyOffersPerLoanAsset.set(chainName, loanTokens);
|
|
1765
|
-
}
|
|
1766
|
-
await Promise.all(
|
|
1767
|
-
Array.from(buyOffersPerLoanAsset.entries()).map(async ([name, loanTokens]) => {
|
|
1768
|
-
const chainName = name;
|
|
1769
|
-
const publicClient = publicClients[chainName];
|
|
1770
|
-
const morpho2 = morphoPerChain.get(mempool.Chain.chains[chainName].id);
|
|
1771
|
-
if (!publicClient) {
|
|
1772
|
-
const offers2 = Array.from(loanTokens.values()).flat();
|
|
1773
|
-
for (const offer of offers2) {
|
|
1774
|
-
issues.set(hashToIndex.get(offer.hash), {
|
|
1775
|
-
message: `Public client for chain "${chainName}" is not available`
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
return;
|
|
1779
|
-
}
|
|
1780
|
-
const balances = /* @__PURE__ */ new Map();
|
|
1781
|
-
const allowances = /* @__PURE__ */ new Map();
|
|
1782
|
-
for (const [loanToken2, offers2] of loanTokens) {
|
|
1783
|
-
const data = await Promise.all(
|
|
1784
|
-
offers2.flatMap((offer) => [
|
|
1785
|
-
publicClient.readContract({
|
|
1786
|
-
address: loanToken2,
|
|
1787
|
-
abi: viem.parseAbi([
|
|
1788
|
-
"function balanceOf(address owner) view returns (uint256 balance)"
|
|
1789
|
-
]),
|
|
1790
|
-
functionName: "balanceOf",
|
|
1791
|
-
args: [offer.offering]
|
|
1792
|
-
}),
|
|
1793
|
-
publicClient.readContract({
|
|
1794
|
-
address: loanToken2,
|
|
1795
|
-
abi: viem.parseAbi([
|
|
1796
|
-
"function allowance(address owner, address spender) public view returns (uint256 remaining)"
|
|
1797
|
-
]),
|
|
1798
|
-
functionName: "allowance",
|
|
1799
|
-
args: [offer.offering, morpho2]
|
|
1800
|
-
})
|
|
1801
|
-
])
|
|
1802
|
-
);
|
|
1803
|
-
for (let i = 0; i < offers2.length; i++) {
|
|
1804
|
-
const user = offers2[i].offering.toLowerCase();
|
|
1805
|
-
const balance = data[i * 2] || 0n;
|
|
1806
|
-
const allowance = data[i * 2 + 1] || 0n;
|
|
1807
|
-
const userBalances = balances.get(user) ?? /* @__PURE__ */ new Map();
|
|
1808
|
-
userBalances.set(loanToken2.toLowerCase(), balance);
|
|
1809
|
-
const userAllowances = allowances.get(user) ?? /* @__PURE__ */ new Map();
|
|
1810
|
-
userAllowances.set(loanToken2.toLowerCase(), allowance);
|
|
1811
|
-
balances.set(user, userBalances);
|
|
1812
|
-
allowances.set(user, userAllowances);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
for (const offer of Array.from(loanTokens.values()).flat()) {
|
|
1816
|
-
const user = offer.offering.toLowerCase();
|
|
1817
|
-
const userBalances = balances.get(user);
|
|
1818
|
-
const balance = userBalances?.get(offer.loanToken.toLowerCase());
|
|
1819
|
-
if (balance < offer.assets) {
|
|
1820
|
-
issues.set(hashToIndex.get(offer.hash), {
|
|
1821
|
-
message: `Insufficient balance for ${offer.loanToken} on chain ${offer.chainId} (${balance.toString()} < ${offer.assets.toString()})`
|
|
1822
|
-
});
|
|
1823
|
-
continue;
|
|
1824
|
-
}
|
|
1825
|
-
const userAllowances = allowances.get(user);
|
|
1826
|
-
const allowance = userAllowances?.get(offer.loanToken.toLowerCase());
|
|
1827
|
-
if (allowance < offer.assets) {
|
|
1828
|
-
issues.set(hashToIndex.get(offer.hash), {
|
|
1829
|
-
message: `Insufficient allowance for ${offer.loanToken} on chain ${offer.chainId} (${allowance.toString()} < ${offer.assets.toString()})`
|
|
1830
|
-
});
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
})
|
|
1834
|
-
);
|
|
1835
|
-
return issues;
|
|
1836
|
-
}
|
|
1837
|
-
);
|
|
1838
1713
|
return [
|
|
1839
1714
|
chainId,
|
|
1840
1715
|
loanToken,
|
|
1841
1716
|
expiry,
|
|
1842
|
-
// note: callback
|
|
1843
|
-
// integrators should be able to
|
|
1844
|
-
|
|
1845
|
-
sellOffersEmptyCallback,
|
|
1846
|
-
buyOffersEmptyCallback
|
|
1717
|
+
// note: callback rule should be the last one, since it does not mean that the offer is forever invalid
|
|
1718
|
+
// integrators should be able to choose if they want to keep the offer or not
|
|
1719
|
+
callback
|
|
1847
1720
|
];
|
|
1848
1721
|
}
|
|
1849
1722
|
|
|
@@ -1851,7 +1724,6 @@ exports.ApiSchema = apiSchema_exports;
|
|
|
1851
1724
|
exports.Logger = Logger_exports;
|
|
1852
1725
|
exports.OfferStore = OfferStore_exports;
|
|
1853
1726
|
exports.Router = router_exports;
|
|
1854
|
-
exports.RouterEvent = RouterEvent_exports;
|
|
1855
1727
|
exports.RouterOffer = RouterOffer_exports;
|
|
1856
1728
|
exports.Utils = utils_exports;
|
|
1857
1729
|
exports.Validation = Validation_exports;
|