@morpho-dev/router 0.1.10 → 0.1.11
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/drizzle/offers_v1.1/0006_add-callback-amount-to-queues-table.sql +1 -0
- package/dist/drizzle/offers_v1.1/0007_add-index-to-created-at.sql +2 -0
- package/dist/drizzle/offers_v1.1/meta/0006_snapshot.json +884 -0
- package/dist/drizzle/offers_v1.1/meta/0007_snapshot.json +932 -0
- package/dist/drizzle/offers_v1.1/meta/_journal.json +14 -0
- package/dist/index.browser.d.cts +24 -9
- package/dist/index.browser.d.ts +24 -9
- package/dist/index.browser.js +84 -35
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +85 -36
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.cts +42 -9
- package/dist/index.node.d.ts +42 -9
- package/dist/index.node.js +223 -114
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +224 -115
- package/dist/index.node.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -43,6 +43,20 @@
|
|
|
43
43
|
"when": 1758270235112,
|
|
44
44
|
"tag": "0005_add-missing-indices-to-liquidity-tables",
|
|
45
45
|
"breakpoints": true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"idx": 6,
|
|
49
|
+
"version": "7",
|
|
50
|
+
"when": 1758809713216,
|
|
51
|
+
"tag": "0006_add-callback-amount-to-queues-table",
|
|
52
|
+
"breakpoints": true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"idx": 7,
|
|
56
|
+
"version": "7",
|
|
57
|
+
"when": 1758889033235,
|
|
58
|
+
"tag": "0007_add-index-to-created-at",
|
|
59
|
+
"breakpoints": true
|
|
46
60
|
}
|
|
47
61
|
]
|
|
48
62
|
}
|
package/dist/index.browser.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _morpho_dev_mempool from '@morpho-dev/mempool';
|
|
2
|
-
import { Offer, Errors, Format, Maturity, LLTV, Compute
|
|
2
|
+
import { Chain, Offer, Errors, Format, Maturity, LLTV, Compute } from '@morpho-dev/mempool';
|
|
3
3
|
export * from '@morpho-dev/mempool';
|
|
4
4
|
import * as viem from 'viem';
|
|
5
5
|
import { PublicActions, Address, Hex } from 'viem';
|
|
@@ -34,6 +34,7 @@ type LiquidityQueue = {
|
|
|
34
34
|
queueId: string;
|
|
35
35
|
availableLiquidityPoolId: string;
|
|
36
36
|
index: number;
|
|
37
|
+
callbackAmount: string;
|
|
37
38
|
updatedAt: Date;
|
|
38
39
|
};
|
|
39
40
|
type LiquidityPool = {
|
|
@@ -56,7 +57,7 @@ declare function fetch(parameters: {
|
|
|
56
57
|
type: CallbackType;
|
|
57
58
|
pairs: Array<{
|
|
58
59
|
user: Address;
|
|
59
|
-
|
|
60
|
+
loanToken: Address;
|
|
60
61
|
}>;
|
|
61
62
|
options?: {
|
|
62
63
|
batchSize?: number;
|
|
@@ -84,15 +85,29 @@ declare enum CallbackType {
|
|
|
84
85
|
SellWithdrawFromWallet = "sell_withdraw_from_wallet"
|
|
85
86
|
}
|
|
86
87
|
declare const WhitelistedCallbackAddresses: Record<CallbackType, readonly string[]>;
|
|
87
|
-
|
|
88
|
-
type: CallbackType;
|
|
89
|
-
user:
|
|
90
|
-
|
|
91
|
-
chainId:
|
|
92
|
-
amount:
|
|
88
|
+
type BuildLiquidityParameters = {
|
|
89
|
+
type: CallbackType.BuyWithEmptyCallback;
|
|
90
|
+
user: Address;
|
|
91
|
+
loanToken: Address;
|
|
92
|
+
chainId: Chain.Id;
|
|
93
|
+
amount: bigint;
|
|
94
|
+
index?: number;
|
|
95
|
+
updatedAt?: Date;
|
|
96
|
+
} | {
|
|
97
|
+
type: CallbackType.SellWithdrawFromWallet;
|
|
98
|
+
user: Address;
|
|
99
|
+
termId: string;
|
|
100
|
+
chainId: Chain.Id;
|
|
101
|
+
amount: bigint;
|
|
102
|
+
collaterals: Array<{
|
|
103
|
+
collateralAddress: Address;
|
|
104
|
+
balance: bigint;
|
|
105
|
+
callbackAmount: bigint;
|
|
106
|
+
}>;
|
|
93
107
|
index?: number;
|
|
94
108
|
updatedAt?: Date;
|
|
95
|
-
}
|
|
109
|
+
};
|
|
110
|
+
declare function buildLiquidity(parameters: BuildLiquidityParameters): Liquidity;
|
|
96
111
|
declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
|
|
97
112
|
declare function decode$1(parameters: {
|
|
98
113
|
type: CallbackType;
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _morpho_dev_mempool from '@morpho-dev/mempool';
|
|
2
|
-
import { Offer, Errors, Format, Maturity, LLTV, Compute
|
|
2
|
+
import { Chain, Offer, Errors, Format, Maturity, LLTV, Compute } from '@morpho-dev/mempool';
|
|
3
3
|
export * from '@morpho-dev/mempool';
|
|
4
4
|
import * as viem from 'viem';
|
|
5
5
|
import { PublicActions, Address, Hex } from 'viem';
|
|
@@ -34,6 +34,7 @@ type LiquidityQueue = {
|
|
|
34
34
|
queueId: string;
|
|
35
35
|
availableLiquidityPoolId: string;
|
|
36
36
|
index: number;
|
|
37
|
+
callbackAmount: string;
|
|
37
38
|
updatedAt: Date;
|
|
38
39
|
};
|
|
39
40
|
type LiquidityPool = {
|
|
@@ -56,7 +57,7 @@ declare function fetch(parameters: {
|
|
|
56
57
|
type: CallbackType;
|
|
57
58
|
pairs: Array<{
|
|
58
59
|
user: Address;
|
|
59
|
-
|
|
60
|
+
loanToken: Address;
|
|
60
61
|
}>;
|
|
61
62
|
options?: {
|
|
62
63
|
batchSize?: number;
|
|
@@ -84,15 +85,29 @@ declare enum CallbackType {
|
|
|
84
85
|
SellWithdrawFromWallet = "sell_withdraw_from_wallet"
|
|
85
86
|
}
|
|
86
87
|
declare const WhitelistedCallbackAddresses: Record<CallbackType, readonly string[]>;
|
|
87
|
-
|
|
88
|
-
type: CallbackType;
|
|
89
|
-
user:
|
|
90
|
-
|
|
91
|
-
chainId:
|
|
92
|
-
amount:
|
|
88
|
+
type BuildLiquidityParameters = {
|
|
89
|
+
type: CallbackType.BuyWithEmptyCallback;
|
|
90
|
+
user: Address;
|
|
91
|
+
loanToken: Address;
|
|
92
|
+
chainId: Chain.Id;
|
|
93
|
+
amount: bigint;
|
|
94
|
+
index?: number;
|
|
95
|
+
updatedAt?: Date;
|
|
96
|
+
} | {
|
|
97
|
+
type: CallbackType.SellWithdrawFromWallet;
|
|
98
|
+
user: Address;
|
|
99
|
+
termId: string;
|
|
100
|
+
chainId: Chain.Id;
|
|
101
|
+
amount: bigint;
|
|
102
|
+
collaterals: Array<{
|
|
103
|
+
collateralAddress: Address;
|
|
104
|
+
balance: bigint;
|
|
105
|
+
callbackAmount: bigint;
|
|
106
|
+
}>;
|
|
93
107
|
index?: number;
|
|
94
108
|
updatedAt?: Date;
|
|
95
|
-
}
|
|
109
|
+
};
|
|
110
|
+
declare function buildLiquidity(parameters: BuildLiquidityParameters): Liquidity;
|
|
96
111
|
declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
|
|
97
112
|
declare function decode$1(parameters: {
|
|
98
113
|
type: CallbackType;
|
package/dist/index.browser.js
CHANGED
|
@@ -35,46 +35,95 @@ var WhitelistedCallbackAddresses = {
|
|
|
35
35
|
"0x1111111111111111111111111111111111111111",
|
|
36
36
|
"0x2222222222222222222222222222222222222222"
|
|
37
37
|
// @TODO: update once deployed and add mapping per chain if needed
|
|
38
|
-
]
|
|
38
|
+
].map((address) => address.toLowerCase())
|
|
39
39
|
};
|
|
40
40
|
function buildLiquidity(parameters) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
queues: [
|
|
56
|
-
{
|
|
57
|
-
queue: {
|
|
58
|
-
queueId: id,
|
|
59
|
-
availableLiquidityPoolId: id,
|
|
60
|
-
index,
|
|
41
|
+
switch (parameters.type) {
|
|
42
|
+
case "buy_with_empty_callback" /* BuyWithEmptyCallback */: {
|
|
43
|
+
const { user, loanToken, chainId, amount, index = 0, updatedAt = /* @__PURE__ */ new Date() } = parameters;
|
|
44
|
+
const amountStr = amount.toString();
|
|
45
|
+
const id = `${user}-${chainId.toString()}-${parameters.type}-${loanToken}`.toLowerCase();
|
|
46
|
+
const poolId = `${user}-${chainId.toString()}-${loanToken}`.toLowerCase();
|
|
47
|
+
return {
|
|
48
|
+
userPosition: {
|
|
49
|
+
id,
|
|
50
|
+
availableLiquidityQueueId: id,
|
|
51
|
+
user: user.toLowerCase(),
|
|
52
|
+
chainId,
|
|
53
|
+
amount: amountStr,
|
|
61
54
|
updatedAt
|
|
62
55
|
},
|
|
63
|
-
|
|
56
|
+
queues: [
|
|
57
|
+
{
|
|
58
|
+
queue: {
|
|
59
|
+
queueId: id,
|
|
60
|
+
availableLiquidityPoolId: poolId,
|
|
61
|
+
index,
|
|
62
|
+
callbackAmount: "0",
|
|
63
|
+
updatedAt
|
|
64
|
+
},
|
|
65
|
+
pool: {
|
|
66
|
+
id: poolId,
|
|
67
|
+
amount: amountStr,
|
|
68
|
+
updatedAt
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
case "sell_withdraw_from_wallet" /* SellWithdrawFromWallet */: {
|
|
75
|
+
const {
|
|
76
|
+
user,
|
|
77
|
+
termId,
|
|
78
|
+
chainId,
|
|
79
|
+
amount,
|
|
80
|
+
collaterals,
|
|
81
|
+
index = 0,
|
|
82
|
+
updatedAt = /* @__PURE__ */ new Date()
|
|
83
|
+
} = parameters;
|
|
84
|
+
const amountStr = amount.toString();
|
|
85
|
+
const id = `${user}-${chainId.toString()}-${parameters.type}-${termId}`.toLowerCase();
|
|
86
|
+
return {
|
|
87
|
+
userPosition: {
|
|
64
88
|
id,
|
|
89
|
+
availableLiquidityQueueId: id,
|
|
90
|
+
user: user.toLowerCase(),
|
|
91
|
+
chainId,
|
|
65
92
|
amount: amountStr,
|
|
66
93
|
updatedAt
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
94
|
+
},
|
|
95
|
+
queues: collaterals.map((collateral) => {
|
|
96
|
+
const poolId = `${user}-${chainId.toString()}-${collateral.collateralAddress}`.toLowerCase();
|
|
97
|
+
return {
|
|
98
|
+
queue: {
|
|
99
|
+
queueId: id,
|
|
100
|
+
availableLiquidityPoolId: poolId,
|
|
101
|
+
index,
|
|
102
|
+
callbackAmount: collateral.callbackAmount.toString(),
|
|
103
|
+
updatedAt
|
|
104
|
+
},
|
|
105
|
+
pool: {
|
|
106
|
+
id: poolId,
|
|
107
|
+
amount: collateral.balance.toString(),
|
|
108
|
+
updatedAt
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
default: {
|
|
115
|
+
throw new Error(`CallbackType not implemented`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
71
118
|
}
|
|
72
119
|
function getCallbackIdForOffer(offer) {
|
|
73
120
|
if (offer.buy && offer.callback.data === "0x") {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
121
|
+
return `${offer.offering}-${offer.chainId.toString()}-${"buy_with_empty_callback" /* BuyWithEmptyCallback */}-${offer.loanToken}`.toLowerCase();
|
|
122
|
+
}
|
|
123
|
+
if (!offer.buy && offer.callback.data !== "0x" && WhitelistedCallbackAddresses["sell_withdraw_from_wallet" /* SellWithdrawFromWallet */].includes(
|
|
124
|
+
offer.callback.address.toLowerCase()
|
|
125
|
+
)) {
|
|
126
|
+
return `${offer.offering}-${offer.chainId.toString()}-${"sell_withdraw_from_wallet" /* SellWithdrawFromWallet */}-${mempool.Offer.termId(offer)}`.toLowerCase();
|
|
78
127
|
}
|
|
79
128
|
return null;
|
|
80
129
|
}
|
|
@@ -270,20 +319,20 @@ async function fetch2(parameters) {
|
|
|
270
319
|
const map = await fetchBalancesAndAllowances({
|
|
271
320
|
client,
|
|
272
321
|
spender,
|
|
273
|
-
pairs: pairs.map(({ user,
|
|
322
|
+
pairs: pairs.map(({ user, loanToken }) => ({ user, token: loanToken })),
|
|
274
323
|
options
|
|
275
324
|
});
|
|
276
325
|
const out = [];
|
|
277
|
-
for (const [user,
|
|
278
|
-
for (const [
|
|
326
|
+
for (const [user, perLoanToken] of map) {
|
|
327
|
+
for (const [loanToken, { balance, allowance }] of perLoanToken) {
|
|
279
328
|
const amount = balance < allowance ? balance : allowance;
|
|
280
329
|
out.push(
|
|
281
330
|
buildLiquidity({
|
|
282
331
|
type,
|
|
283
332
|
user,
|
|
284
|
-
|
|
333
|
+
loanToken,
|
|
285
334
|
chainId,
|
|
286
|
-
amount
|
|
335
|
+
amount,
|
|
287
336
|
index: 0
|
|
288
337
|
})
|
|
289
338
|
);
|